From c2ddac2c1eb1365aadd21a160543c6fa1a7947df Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 28 Nov 2023 01:46:28 +0300 Subject: [PATCH] Allow using localskins for any kind of mobj from lua --- src/hardware/hw_main.c | 2 +- src/lua_mobjlib.c | 41 ++++++++++++++++++++++++++++++++++------- src/r_things.c | 2 +- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2ce496ae1..de4ddc765 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5558,7 +5558,7 @@ void HWR_ProjectSprite(mobj_t *thing) rot = thing->frame&FF_FRAMEMASK; //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if (thing->skin && thing->sprite == SPR_PLAY) + if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index cfc5c8e5f..06c56645f 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -217,7 +217,7 @@ UNIMPLEMENTED(mobjnum) // For some dumb reason it is valid to set sloperoll, even though it is read // only -int mobj_sloperoll_noop(lua_State *L) { return 0; } +int mobj_sloperoll_noop(lua_State *L) { (void)L; return 0; } // Now other getters/setters with arbitary logic @@ -415,13 +415,40 @@ int mobj_localskin_setter(lua_State *L) { mobj_t *mo = GETMO(); - // TODO - add ability to set localskin to non-player mobjs - // Will probably just need to reimplement SetLocalPlayerSkin as something - // like SetLocalObjectSkin - if (!mo->player) - return luaL_error(L, "mobj.localskin can't be set for non-player mobjs!"); + if (mo->player) + { + SetLocalPlayerSkin(mo->player - players, luaL_checkstring(L, 2), NULL); + } + else + { + INT32 i; + char skin[SKINNAMESIZE+1]; // all skin names are limited to this length + strlcpy(skin, luaL_checkstring(L, 2), sizeof skin); + strlwr(skin); // all skin names are lowercase + + // Try localskins + for (i = 0; i < numlocalskins; i++) + { + if (stricmp(localskins[i].name, skin) == 0) + { + mo->localskin = &localskins[i]; + mo->skinlocal = true; + return 0; + } + } + + // Try other skins + for (i = 0; i < numskins; i++) + { + if (fastcmp(skins[i].name, skin)) + { + mo->localskin = &skins[i]; + mo->skinlocal = false; + return 0; + } + } + } - SetLocalPlayerSkin(mo->player - players, luaL_checkstring(L, 2), NULL); return 0; } diff --git a/src/r_things.c b/src/r_things.c index d08b57501..6334716ce 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1399,7 +1399,7 @@ static void R_ProjectSprite(mobj_t *thing) rot = thing->frame&FF_FRAMEMASK; //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if (thing->skin && thing->sprite == SPR_PLAY) + if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE