Only call the Lua API for overridden actions

This commit is contained in:
Louis-Antoine 2020-11-15 01:15:58 +01:00
parent 7e7de16e6b
commit 13ba25f4fe
6 changed files with 570 additions and 285 deletions

View file

@ -2897,18 +2897,9 @@ static void readhuditem(MYFILE *f, INT32 num)
Z_Free(s);
}
/** Action pointer for reading actions from Dehacked lumps.
*/
typedef struct
{
actionf_t action; ///< Function pointer corresponding to the actual action.
const char *name; ///< Name of the action in ALL CAPS.
} actionpointer_t;
/** Array mapping action names to action functions.
* Names must be in ALL CAPS for case insensitive comparisons.
*/
static actionpointer_t actionpointers[] =
// IMPORTANT!
// DO NOT FORGET TO SYNC THIS LIST WITH THE ACTIONNUM ENUM IN INFO.H
actionpointer_t actionpointers[] =
{
{{A_Explode}, "A_EXPLODE"},
{{A_Pain}, "A_PAIN"},
@ -11272,3 +11263,12 @@ void LUA_SetActionByName(void *state, const char *actiontocompare)
}
}
}
enum actionnum LUA_GetActionNumByName(const char *actiontocompare)
{
size_t z;
for (z = 0; actionpointers[z].name; z++)
if (fasticmp(actiontocompare, actionpointers[z].name))
return z;
return z;
}

View file

@ -37,6 +37,7 @@ fixed_t get_number(const char *word);
boolean LUA_SetLuaAction(void *state, const char *actiontocompare);
const char *LUA_GetActionName(void *action);
void LUA_SetActionByName(void *state, const char *actiontocompare);
enum actionnum LUA_GetActionNumByName(const char *actiontocompare);
extern boolean deh_loaded;

View file

@ -22,6 +22,287 @@
// dehacked.c now has lists for the more named enums! PLEASE keep them up to date!
// For great modding!!
/** Action pointer for reading actions from Dehacked lumps.
*/
typedef struct
{
actionf_t action; ///< Function pointer corresponding to the actual action.
const char *name; ///< Name of the action in ALL CAPS.
} actionpointer_t;
/** Array mapping action names to action functions.
* Names must be in ALL CAPS for case insensitive comparisons.
*/
extern actionpointer_t actionpointers[];
// IMPORTANT!
// DO NOT FORGET TO SYNC THIS LIST WITH THE ACTIONPOINTERS ARRAY IN DEHACKED.C
enum actionnum
{
A_EXPLODE = 0,
A_PAIN,
A_FALL,
A_MONITORPOP,
A_GOLDMONITORPOP,
A_GOLDMONITORRESTORE,
A_GOLDMONITORSPARKLE,
A_LOOK,
A_CHASE,
A_FACESTABCHASE,
A_FACESTABREV,
A_FACESTABHURL,
A_FACESTABMISS,
A_STATUEBURST,
A_FACETARGET,
A_FACETRACER,
A_SCREAM,
A_BOSSDEATH,
A_CUSTOMPOWER,
A_GIVEWEAPON,
A_RINGBOX,
A_INVINCIBILITY,
A_SUPERSNEAKERS,
A_BUNNYHOP,
A_BUBBLESPAWN,
A_FANBUBBLESPAWN,
A_BUBBLERISE,
A_BUBBLECHECK,
A_AWARDSCORE,
A_EXTRALIFE,
A_GIVESHIELD,
A_GRAVITYBOX,
A_SCORERISE,
A_ATTRACTCHASE,
A_DROPMINE,
A_FISHJUMP,
A_THROWNRING,
A_SETSOLIDSTEAM,
A_UNSETSOLIDSTEAM,
A_SIGNSPIN,
A_SIGNPLAYER,
A_OVERLAYTHINK,
A_JETCHASE,
A_JETBTHINK,
A_JETGTHINK,
A_JETGSHOOT,
A_SHOOTBULLET,
A_MINUSDIGGING,
A_MINUSPOPUP,
A_MINUSCHECK,
A_CHICKENCHECK,
A_MOUSETHINK,
A_DETONCHASE,
A_CAPECHASE,
A_ROTATESPIKEBALL,
A_SLINGAPPEAR,
A_UNIDUSBALL,
A_ROCKSPAWN,
A_SETFUSE,
A_CRAWLACOMMANDERTHINK,
A_SMOKETRAILER,
A_RINGEXPLODE,
A_OLDRINGEXPLODE,
A_MIXUP,
A_RECYCLEPOWERS,
A_BOSS1CHASE,
A_FOCUSTARGET,
A_BOSS2CHASE,
A_BOSS2POGO,
A_BOSSZOOM,
A_BOSSSCREAM,
A_BOSS2TAKEDAMAGE,
A_BOSS7CHASE,
A_GOOPSPLAT,
A_BOSS2POGOSFX,
A_BOSS2POGOTARGET,
A_BOSSJETFUME,
A_EGGMANBOX,
A_TURRETFIRE,
A_SUPERTURRETFIRE,
A_TURRETSTOP,
A_JETJAWROAM,
A_JETJAWCHOMP,
A_POINTYTHINK,
A_CHECKBUDDY,
A_HOODFIRE,
A_HOODTHINK,
A_HOODFALL,
A_ARROWBONKS,
A_SNAILERTHINK,
A_SHARPCHASE,
A_SHARPSPIN,
A_SHARPDECEL,
A_CRUSHSTACEANWALK,
A_CRUSHSTACEANPUNCH,
A_CRUSHCLAWAIM,
A_CRUSHCLAWLAUNCH,
A_VULTUREVTOL,
A_VULTURECHECK,
A_VULTUREHOVER,
A_VULTUREBLAST,
A_VULTUREFLY,
A_SKIMCHASE,
A_1UPTHINKER,
A_SKULLATTACK,
A_LOBSHOT,
A_FIRESHOT,
A_SUPERFIRESHOT,
A_BOSSFIRESHOT,
A_BOSS7FIREMISSILES,
A_BOSS1LASER,
A_BOSS4REVERSE,
A_BOSS4SPEEDUP,
A_BOSS4RAISE,
A_SPARKFOLLOW,
A_BUZZFLY,
A_GUARDCHASE,
A_EGGSHIELD,
A_SETREACTIONTIME,
A_BOSS1SPIKEBALLS,
A_BOSS3TAKEDAMAGE,
A_BOSS3PATH,
A_BOSS3SHOCKTHINK,
A_LINEDEFEXECUTE,
A_PLAYSEESOUND,
A_PLAYATTACKSOUND,
A_PLAYACTIVESOUND,
A_SPAWNOBJECTABSOLUTE,
A_SPAWNOBJECTRELATIVE,
A_CHANGEANGLERELATIVE,
A_CHANGEANGLEABSOLUTE,
A_ROLLANGLE,
A_CHANGEROLLANGLERELATIVE,
A_CHANGEROLLANGLEABSOLUTE,
A_PLAYSOUND,
A_FINDTARGET,
A_FINDTRACER,
A_SETTICS,
A_SETRANDOMTICS,
A_CHANGECOLORRELATIVE,
A_CHANGECOLORABSOLUTE,
A_DYE,
A_MOVERELATIVE,
A_MOVEABSOLUTE,
A_THRUST,
A_ZTHRUST,
A_SETTARGETSTARGET,
A_SETOBJECTFLAGS,
A_SETOBJECTFLAGS2,
A_RANDOMSTATE,
A_RANDOMSTATERANGE,
A_DUALACTION,
A_REMOTEACTION,
A_TOGGLEFLAMEJET,
A_ORBITNIGHTS,
A_GHOSTME,
A_SETOBJECTSTATE,
A_SETOBJECTTYPESTATE,
A_KNOCKBACK,
A_PUSHAWAY,
A_RINGDRAIN,
A_SPLITSHOT,
A_MISSILESPLIT,
A_MULTISHOT,
A_INSTALOOP,
A_CUSTOM3DROTATE,
A_SEARCHFORPLAYERS,
A_CHECKRANDOM,
A_CHECKTARGETRINGS,
A_CHECKRINGS,
A_CHECKTOTALRINGS,
A_CHECKHEALTH,
A_CHECKRANGE,
A_CHECKHEIGHT,
A_CHECKTRUERANGE,
A_CHECKTHINGCOUNT,
A_CHECKAMBUSH,
A_CHECKCUSTOMVALUE,
A_CHECKCUSVALMEMO,
A_SETCUSTOMVALUE,
A_USECUSVALMEMO,
A_RELAYCUSTOMVALUE,
A_CUSVALACTION,
A_FORCESTOP,
A_FORCEWIN,
A_SPIKERETRACT,
A_INFOSTATE,
A_REPEAT,
A_SETSCALE,
A_REMOTEDAMAGE,
A_HOMINGCHASE,
A_TRAPSHOT,
A_VILETARGET,
A_VILEATTACK,
A_VILEFIRE,
A_BRAKCHASE,
A_BRAKFIRESHOT,
A_BRAKLOBSHOT,
A_NAPALMSCATTER,
A_SPAWNFRESHCOPY,
A_FLICKYSPAWN,
A_FLICKYCENTER,
A_FLICKYAIM,
A_FLICKYFLY,
A_FLICKYSOAR,
A_FLICKYCOAST,
A_FLICKYHOP,
A_FLICKYFLOUNDER,
A_FLICKYCHECK,
A_FLICKYHEIGHTCHECK,
A_FLICKYFLUTTER,
A_FLAMEPARTICLE,
A_FADEOVERLAY,
A_BOSS5JUMP,
A_LIGHTBEAMRESET,
A_MINEEXPLODE,
A_MINERANGE,
A_CONNECTTOGROUND,
A_SPAWNPARTICLERELATIVE,
A_MULTISHOTDIST,
A_WHOCARESIFYOURSONISABEE,
A_PARENTTRIESTOSLEEP,
A_CRYINGTOMOMMA,
A_CHECKFLAGS2,
A_BOSS5FINDWAYPOINT,
A_DONPCSKID,
A_DONPCPAIN,
A_PREPAREREPEAT,
A_BOSS5EXTRAREPEAT,
A_BOSS5CALM,
A_BOSS5CHECKONGROUND,
A_BOSS5CHECKFALLING,
A_BOSS5PINCHSHOT,
A_BOSS5MAKEITRAIN,
A_BOSS5MAKEJUNK,
A_LOOKFORBETTER,
A_BOSS5BOMBEXPLODE,
A_DUSTDEVILTHINK,
A_TNTEXPLODE,
A_DEBRISRANDOM,
A_TRAINCAMEO,
A_TRAINCAMEO2,
A_CANARIVOREGAS,
A_KILLSEGMENTS,
A_SNAPPERSPAWN,
A_SNAPPERTHINKER,
A_SALOONDOORSPAWN,
A_MINECARTSPARKTHINK,
A_MODULOTOSTATE,
A_LAVAFALLROCKS,
A_LAVAFALLLAVA,
A_FALLINGLAVACHECK,
A_FIRESHRINK,
A_SPAWNPTERABYTES,
A_PTERABYTEHOVER,
A_ROLLOUTSPAWN,
A_ROLLOUTROCK,
A_DRAGONBOMBERSPAWN,
A_DRAGONWING,
A_DRAGONSEGMENT,
A_CHANGEHEIGHT,
NUMACTIONS
};
// IMPORTANT NOTE: If you add/remove from this list of action
// functions, don't forget to update them in dehacked.c!
void A_Explode();
@ -286,6 +567,8 @@ void A_DragonWing();
void A_DragonSegment();
void A_ChangeHeight();
extern boolean actionsoverridden[NUMACTIONS];
// ratio of states to sprites to mobj types is roughly 6 : 1 : 1
#define NUMMOBJFREESLOTS 512
#define NUMSPRITEFREESLOTS NUMMOBJFREESLOTS

View file

@ -30,7 +30,7 @@
extern CV_PossibleValue_t Color_cons_t[];
extern UINT8 skincolor_modified[];
boolean LUA_CallAction(const char *action, mobj_t *actor);
boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor);
state_t *astate;
enum sfxinfo_read {
@ -63,6 +63,8 @@ const char *const sfxinfo_wopt[] = {
"caption",
NULL};
boolean actionsoverridden[NUMACTIONS] = {false};
//
// Sprite Names
//
@ -816,27 +818,21 @@ boolean LUA_SetLuaAction(void *stv, const char *action)
return true; // action successfully set.
}
boolean LUA_CallAction(const char *csaction, mobj_t *actor)
boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor)
{
I_Assert(csaction != NULL);
I_Assert(actor != NULL);
if (!gL) // Lua isn't loaded,
if (!(gL && actionsoverridden[actionnum])) // Lua isn't loaded, or the action is not overriden,
return false; // action not called.
if (superstack && fasticmp(csaction, superactions[superstack-1])) // the action is calling itself,
if (superstack && fasticmp(actionpointers[actionnum].name, superactions[superstack-1])) // the action is calling itself,
return false; // let it call the hardcoded function instead.
lua_pushcfunction(gL, LUA_GetErrorMessage);
// grab function by uppercase name.
lua_getfield(gL, LUA_REGISTRYINDEX, LREG_ACTIONS);
{
char *action = Z_StrDup(csaction);
strupr(action);
lua_getfield(gL, -1, action);
Z_Free(action);
}
lua_getfield(gL, -1, actionpointers[actionnum].name);
lua_remove(gL, -2); // pop LREG_ACTIONS
if (lua_isnil(gL, -1)) // no match
@ -859,7 +855,7 @@ boolean LUA_CallAction(const char *csaction, mobj_t *actor)
lua_pushinteger(gL, var1);
lua_pushinteger(gL, var2);
superactions[superstack] = csaction;
superactions[superstack] = actionpointers[actionnum].name;
++superstack;
LUA_Call(gL, 3, 0, -(2 + 3));

View file

@ -401,6 +401,7 @@ static int setglobals(lua_State *L)
{
const char *csname;
char *name;
enum actionnum actionnum;
lua_remove(L, 1); // we're not gonna be using _G
csname = lua_tostring(L, 1);
@ -419,6 +420,10 @@ static int setglobals(lua_State *L)
lua_rawset(L, -3); // rawset doesn't trigger this metatable again.
// otherwise we would've used setfield, obviously.
actionnum = LUA_GetActionNumByName(name);
if (actionnum < NUMACTIONS)
actionsoverridden[actionnum] = true;
Z_Free(name);
return 0;
}

File diff suppressed because it is too large Load diff