SRB2 2.1.9 release

This commit is contained in:
Alam Ed Arias 2014-08-03 23:49:33 -04:00
parent ab9934932e
commit c028c83235
67 changed files with 4007 additions and 4977 deletions

View file

@ -44,10 +44,15 @@ const char *const hookNames[hook_MAX+1] = {
"MobjDeath",
"BossDeath",
"MobjRemoved",
"JumpSpecial",
"AbilitySpecial",
"SpinSpecial",
"JumpSpinSpecial",
"BotTiccmd",
"BotAI",
"LinedefExecute",
"PlayerMsg",
"HurtMsg",
NULL
};
@ -321,6 +326,42 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
return hooked;
}
boolean LUAh_PlayerHook(player_t *plr, enum hook which)
{
boolean hooked = false;
if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
return false;
// clear the stack (just in case)
lua_pop(gL, -1);
// hook table
lua_getfield(gL, LUA_REGISTRYINDEX, "hook");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, which);
lua_remove(gL, -2);
I_Assert(lua_istable(gL, -1));
LUA_PushUserdata(gL, plr, META_PLAYER);
lua_pushnil(gL);
while (lua_next(gL, -3) != 0) {
lua_pushvalue(gL, -3); // player
if (lua_pcall(gL, 1, 1, 0)) { // pops hook function, player, pushes 1 return result
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL, 1);
continue;
}
if (lua_toboolean(gL, -1)) // if return true,
hooked = true; // override vanilla behavior
lua_pop(gL, 1); // pop return value
}
lua_pop(gL, -1);
lua_gc(gL, LUA_GCSTEP, 1);
return hooked;
}
// Hook for map change (before load)
void LUAh_MapChange(void)
{
@ -918,4 +959,45 @@ boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg)
return handled;
}
// Hook for hurt messages -Red
// The internal name is DeathMsg, but the API name is "HurtMsg". Keep that in mind. (Should this be fixed at some point?)
// @TODO This hook should be fixed to take mobj type at the addHook parameter to compare to inflictor. (I couldn't get this to work without crashing)
boolean LUAh_DeathMsg(player_t *player, mobj_t *inflictor, mobj_t *source)
{
boolean handled = false;
if (!gL || !(hooksAvailable[hook_DeathMsg/8] & (1<<(hook_DeathMsg%8))))
return false;
lua_getfield(gL, LUA_REGISTRYINDEX, "hook");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, hook_DeathMsg);
lua_remove(gL, -2);
I_Assert(lua_istable(gL, -1));
LUA_PushUserdata(gL, player, META_PLAYER); // Player
LUA_PushUserdata(gL, inflictor, META_MOBJ); // Inflictor
LUA_PushUserdata(gL, source, META_MOBJ); // Source
lua_pushnil(gL);
while (lua_next(gL, -5)) {
lua_pushvalue(gL, -5); // player
lua_pushvalue(gL, -5); // inflictor
lua_pushvalue(gL, -5); // source
if (lua_pcall(gL, 3, 1, 0)) {
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL, 1);
continue;
}
if (lua_toboolean(gL, -1))
handled = true;
lua_pop(gL, 1); // pop return value
}
lua_pop(gL, 3); // pop arguments and mobjtype table
lua_gc(gL, LUA_GCSTEP, 1);
return handled;
}
#endif