Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/fxdata/lua/classes/Thing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/creature_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/creature_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
27 changes: 27 additions & 0 deletions src/lua_api_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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}
};

Expand Down
1 change: 1 addition & 0 deletions src/thing_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down