From 2b009e91e601ff87d0b0a7c03c659c2e976296d0 Mon Sep 17 00:00:00 2001 From: PieterVdc Date: Wed, 27 May 2026 10:06:38 +0200 Subject: [PATCH 1/3] Lua: add set_tint --- config/fxdata/lua/classes/Thing.lua | 9 +++++++ src/creature_graphics.c | 6 +++++ src/lua_api_things.c | 38 +++++++++++++++++++++++++++++ src/thing_data.h | 1 + 4 files changed, 54 insertions(+) diff --git a/config/fxdata/lua/classes/Thing.lua b/config/fxdata/lua/classes/Thing.lua index 290c098fa3..faeac3ff01 100644 --- a/config/fxdata/lua/classes/Thing.lua +++ b/config/fxdata/lua/classes/Thing.lua @@ -59,3 +59,12 @@ function Thing:delete() end ---@param orientation? integer 0-2047, the angle to move in the X/Y plane. ---@param pitch? integer 0-2047, the angle to move in the Z plane function Thing:set_velocity(speed,orientation,pitch) end + +---tints the thing with a color +---@param R integer Red tint value, 0-255 +---@param G integer Green tint value, 0-255 +---@param B integer Blue tint value, 0-255 +function Thing:set_tint(R, G, B) end + +---clears the tint set by set_tint +function Thing:unset_tint() end \ No newline at end of file diff --git a/src/creature_graphics.c b/src/creature_graphics.c index a6c59f7cc9..d4fcaf6a47 100644 --- a/src/creature_graphics.c +++ b/src/creature_graphics.c @@ -582,6 +582,12 @@ void update_creature_graphic_anim(struct Thing *thing) void update_creature_graphic_tint(struct Thing *thing) { struct CreatureControl* cctrl = creature_control_get_from_thing(thing); + + if (cctrl->tint_override) + { + return; + } + if (creature_under_spell_effect(thing, CSAfF_Freeze)) { tint_thing(thing, colours[4][4][15], 1); diff --git a/src/lua_api_things.c b/src/lua_api_things.c index 797ef7ec66..6ab93a97ee 100644 --- a/src/lua_api_things.c +++ b/src/lua_api_things.c @@ -589,6 +589,42 @@ static int lua_is_in_enemy_custody(lua_State *L) { return 1; } +static int lua_set_tint(lua_State *L) { + struct Thing* thing = luaL_checkThing(L, 1); + + char R = luaL_checkinteger(L, 2); + char G = luaL_checkinteger(L, 3); + char B = luaL_checkinteger(L, 4); + if (R < 0 || R > 255 || G < 0 || G > 255 || B < 0 || B > 255) { + return luaL_error(L, "RGB values must be between 0 and 255"); + } + TbPixel tint = colours[R/4][G/4][B/4]; + + if (thing_is_creature(thing)) { + struct CreatureControl* cctrl = creature_control_get_from_thing(thing); + if (creature_control_invalid(cctrl)) { + return luaL_error(L, "Invalid creature control block"); + } + cctrl->override_tint = true; + } + tint_thing(thing, tint, 1); + return 0; +} + +static int lua_unset_tint(lua_State *L) { + struct Thing* thing = luaL_checkThing(L, 1); + + if (thing_is_creature(thing)) { + struct CreatureControl* cctrl = creature_control_get_from_thing(thing); + if (creature_control_invalid(cctrl)) { + return luaL_error(L, "Invalid creature control block"); + } + cctrl->override_tint = false; + } + untint_thing(thing); + return 0; +} + static int thing_eq(lua_State *L) { if (!lua_istable(L, 1) || !lua_istable(L, 2)) { @@ -659,6 +695,8 @@ static const struct luaL_Reg thing_methods[] = { {"get_annoyance" ,lua_get_creature_annoyance }, {"set_annoyance" ,lua_set_creature_annoyance }, {"in_enemy_custody" ,lua_is_in_enemy_custody }, + {"set_tint" ,lua_set_tint }, + {"unset_tint" ,lua_unset_tint }, {NULL, NULL} }; diff --git a/src/thing_data.h b/src/thing_data.h index 0cef64a96a..0fe6a9a5b2 100644 --- a/src/thing_data.h +++ b/src/thing_data.h @@ -286,6 +286,7 @@ struct Thing { unsigned char draw_class; /**< See enum ObjectsDrawClasses for valid values. */ unsigned char size_change; /**< See enum ThingSizeChange for valid values. */ unsigned char tint_colour; + TbBool tint_override; short move_angle_xy; short move_angle_z; unsigned short clipbox_size_xy; From 4f0f8a3c29c3253f9a9d5e1510b685296d30d2d8 Mon Sep 17 00:00:00 2001 From: qqluqq Date: Wed, 27 May 2026 18:00:17 +0200 Subject: [PATCH 2/3] . --- src/creature_graphics.c | 2 +- src/creature_graphics.h | 3 +++ src/globals.h | 2 +- src/lua_api_things.c | 24 ++++++------------------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/creature_graphics.c b/src/creature_graphics.c index d4fcaf6a47..5604bef2b8 100644 --- a/src/creature_graphics.c +++ b/src/creature_graphics.c @@ -583,7 +583,7 @@ void update_creature_graphic_tint(struct Thing *thing) { struct CreatureControl* cctrl = creature_control_get_from_thing(thing); - if (cctrl->tint_override) + if (thing->tint_override) { return; } diff --git a/src/creature_graphics.h b/src/creature_graphics.h index 535519215c..bff6ae79c1 100644 --- a/src/creature_graphics.h +++ b/src/creature_graphics.h @@ -126,6 +126,9 @@ void update_creature_rendering_flags(struct Thing *thing); size_t creature_table_load_get_size(size_t disk_size); void creature_table_load_unpack(unsigned char *src, size_t disk_size); + +void untint_thing(struct Thing *thing); +void tint_thing(struct Thing *thing, TbPixel colour, unsigned char tint); /******************************************************************************/ #ifdef __cplusplus } diff --git a/src/globals.h b/src/globals.h index 1089dac40e..5d3be44a97 100644 --- a/src/globals.h +++ b/src/globals.h @@ -324,7 +324,7 @@ typedef int16_t FuncIdx; typedef uint32_t TbMapLocation; /** Controller buttons state. flags field, each bit represents a button */ typedef uint64_t TbControllerButtons; - +typedef unsigned char TbPixel; /** * Stores a 2d coordinate (x,y). * diff --git a/src/lua_api_things.c b/src/lua_api_things.c index 6ab93a97ee..49bc34157c 100644 --- a/src/lua_api_things.c +++ b/src/lua_api_things.c @@ -26,6 +26,7 @@ #include "magic_powers.h" #include "config_crtrstates.h" #include "creature_states_mood.h" +#include "vidfade.h" #include "lua_base.h" #include "lua_params.h" @@ -592,21 +593,14 @@ static int lua_is_in_enemy_custody(lua_State *L) { static int lua_set_tint(lua_State *L) { struct Thing* thing = luaL_checkThing(L, 1); - char R = luaL_checkinteger(L, 2); - char G = luaL_checkinteger(L, 3); - char B = luaL_checkinteger(L, 4); + int32_t R = luaL_checkinteger(L, 2); + int32_t G = luaL_checkinteger(L, 3); + int32_t B = luaL_checkinteger(L, 4); if (R < 0 || R > 255 || G < 0 || G > 255 || B < 0 || B > 255) { return luaL_error(L, "RGB values must be between 0 and 255"); } TbPixel tint = colours[R/4][G/4][B/4]; - - if (thing_is_creature(thing)) { - struct CreatureControl* cctrl = creature_control_get_from_thing(thing); - if (creature_control_invalid(cctrl)) { - return luaL_error(L, "Invalid creature control block"); - } - cctrl->override_tint = true; - } + thing->tint_override = true; tint_thing(thing, tint, 1); return 0; } @@ -614,13 +608,7 @@ static int lua_set_tint(lua_State *L) { static int lua_unset_tint(lua_State *L) { struct Thing* thing = luaL_checkThing(L, 1); - if (thing_is_creature(thing)) { - struct CreatureControl* cctrl = creature_control_get_from_thing(thing); - if (creature_control_invalid(cctrl)) { - return luaL_error(L, "Invalid creature control block"); - } - cctrl->override_tint = false; - } + thing->tint_override = false; untint_thing(thing); return 0; } From b820a6fed82fc3484b81f90463df5587c5e03014 Mon Sep 17 00:00:00 2001 From: qqluqq Date: Wed, 27 May 2026 19:49:21 +0200 Subject: [PATCH 3/3] . --- src/globals.h | 2 +- src/lua_api_things.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/globals.h b/src/globals.h index 5d3be44a97..1b50d118ca 100644 --- a/src/globals.h +++ b/src/globals.h @@ -324,7 +324,7 @@ typedef int16_t FuncIdx; typedef uint32_t TbMapLocation; /** Controller buttons state. flags field, each bit represents a button */ typedef uint64_t TbControllerButtons; -typedef unsigned char TbPixel; +typedef uint8_t TbPixel; /** * Stores a 2d coordinate (x,y). * diff --git a/src/lua_api_things.c b/src/lua_api_things.c index 49bc34157c..0b212bec31 100644 --- a/src/lua_api_things.c +++ b/src/lua_api_things.c @@ -599,7 +599,8 @@ static int lua_set_tint(lua_State *L) { if (R < 0 || R > 255 || G < 0 || G > 255 || B < 0 || B > 255) { return luaL_error(L, "RGB values must be between 0 and 255"); } - TbPixel tint = colours[R/4][G/4][B/4]; + TbPixel tint = LbPaletteFindColour(engine_palette, R, G, B); + thing->tint_override = true; tint_thing(thing, tint, 1); return 0;