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..5604bef2b8 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 (thing->tint_override) + { + return; + } + if (creature_under_spell_effect(thing, CSAfF_Freeze)) { tint_thing(thing, colours[4][4][15], 1); 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..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 uint8_t TbPixel; /** * Stores a 2d coordinate (x,y). * diff --git a/src/lua_api_things.c b/src/lua_api_things.c index 797ef7ec66..0b212bec31 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" @@ -589,6 +590,30 @@ 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); + + 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 = LbPaletteFindColour(engine_palette, R, G, B); + + thing->tint_override = true; + tint_thing(thing, tint, 1); + return 0; +} + +static int lua_unset_tint(lua_State *L) { + struct Thing* thing = luaL_checkThing(L, 1); + + thing->tint_override = false; + untint_thing(thing); + return 0; +} + static int thing_eq(lua_State *L) { if (!lua_istable(L, 1) || !lua_istable(L, 2)) { @@ -659,6 +684,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;