mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-07 08:52:01 +00:00
BotRespawn hook
Lets you force when and when not to respawn the bot
This commit is contained in:
parent
d8793ce579
commit
934808ef62
3 changed files with 63 additions and 0 deletions
15
src/b_bot.c
15
src/b_bot.c
|
@ -463,6 +463,21 @@ boolean B_CheckRespawn(player_t *player)
|
||||||
if (!sonic || sonic->health <= 0)
|
if (!sonic || sonic->health <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
#ifdef HAVE_BLUA
|
||||||
|
// B_RespawnBot doesn't do anything if the condition above this isn't met
|
||||||
|
{
|
||||||
|
UINT8 shouldForce = LUAh_BotRespawn(sonic, tails);
|
||||||
|
|
||||||
|
if (P_MobjWasRemoved(sonic) || P_MobjWasRemoved(tails))
|
||||||
|
return (shouldForce == 1); // mobj was removed
|
||||||
|
|
||||||
|
if (shouldForce == 1)
|
||||||
|
return true;
|
||||||
|
else if (shouldForce == 2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check if Sonic is busy first.
|
// Check if Sonic is busy first.
|
||||||
// If he's doing any of these things, he probably doesn't want to see us.
|
// If he's doing any of these things, he probably doesn't want to see us.
|
||||||
if (sonic->player->pflags & (PF_GLIDING|PF_SLIDING|PF_BOUNCING)
|
if (sonic->player->pflags & (PF_GLIDING|PF_SLIDING|PF_BOUNCING)
|
||||||
|
|
|
@ -42,6 +42,7 @@ enum hook {
|
||||||
hook_JumpSpinSpecial,
|
hook_JumpSpinSpecial,
|
||||||
hook_BotTiccmd,
|
hook_BotTiccmd,
|
||||||
hook_BotAI,
|
hook_BotAI,
|
||||||
|
hook_BotRespawn,
|
||||||
hook_LinedefExecute,
|
hook_LinedefExecute,
|
||||||
hook_PlayerMsg,
|
hook_PlayerMsg,
|
||||||
hook_HurtMsg,
|
hook_HurtMsg,
|
||||||
|
@ -92,6 +93,7 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8
|
||||||
#define LUAh_JumpSpinSpecial(player) LUAh_PlayerHook(player, hook_JumpSpinSpecial) // Hook for P_DoJumpStuff (Spin button effect (mid-air))
|
#define LUAh_JumpSpinSpecial(player) LUAh_PlayerHook(player, hook_JumpSpinSpecial) // Hook for P_DoJumpStuff (Spin button effect (mid-air))
|
||||||
boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd); // Hook for B_BuildTiccmd
|
boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd); // Hook for B_BuildTiccmd
|
||||||
boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_BuildTailsTiccmd by skin name
|
boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_BuildTailsTiccmd by skin name
|
||||||
|
boolean LUAh_BotRespawn(mobj_t *sonic, mobj_t *tails); // Hook for B_CheckRespawn
|
||||||
boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors
|
boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors
|
||||||
boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages
|
boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages
|
||||||
boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); // Hook for hurt messages
|
boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); // Hook for hurt messages
|
||||||
|
|
|
@ -53,6 +53,7 @@ const char *const hookNames[hook_MAX+1] = {
|
||||||
"JumpSpinSpecial",
|
"JumpSpinSpecial",
|
||||||
"BotTiccmd",
|
"BotTiccmd",
|
||||||
"BotAI",
|
"BotAI",
|
||||||
|
"BotRespawn",
|
||||||
"LinedefExecute",
|
"LinedefExecute",
|
||||||
"PlayerMsg",
|
"PlayerMsg",
|
||||||
"HurtMsg",
|
"HurtMsg",
|
||||||
|
@ -1122,6 +1123,51 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
|
||||||
return hooked;
|
return hooked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hook for B_CheckRespawn
|
||||||
|
boolean LUAh_BotRespawn(mobj_t *sonic, mobj_t *tails)
|
||||||
|
{
|
||||||
|
hook_p hookp;
|
||||||
|
UINT8 shouldRespawn = 0; // 0 = default, 1 = force yes, 2 = force no.
|
||||||
|
if (!gL || !(hooksAvailable[hook_BotRespawn/8] & (1<<(hook_BotRespawn%8))))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua_settop(gL, 0);
|
||||||
|
|
||||||
|
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||||
|
{
|
||||||
|
if (hookp->type != hook_BotRespawn)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (lua_gettop(gL) == 0)
|
||||||
|
{
|
||||||
|
LUA_PushUserdata(gL, sonic, META_MOBJ);
|
||||||
|
LUA_PushUserdata(gL, tails, META_MOBJ);
|
||||||
|
}
|
||||||
|
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||||
|
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||||
|
lua_pushvalue(gL, -3);
|
||||||
|
lua_pushvalue(gL, -3);
|
||||||
|
if (lua_pcall(gL, 2, 1, 0)) {
|
||||||
|
if (!hookp->error || cv_debug & DBG_LUA)
|
||||||
|
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
|
||||||
|
lua_pop(gL, 1);
|
||||||
|
hookp->error = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!lua_isnil(gL, -1))
|
||||||
|
{
|
||||||
|
if (lua_toboolean(gL, -1))
|
||||||
|
shouldRespawn = 1; // Force yes
|
||||||
|
else
|
||||||
|
shouldRespawn = 2; // Force no
|
||||||
|
}
|
||||||
|
lua_pop(gL, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_settop(gL, 0);
|
||||||
|
return shouldRespawn;
|
||||||
|
}
|
||||||
|
|
||||||
// Hook for linedef executors
|
// Hook for linedef executors
|
||||||
boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
|
boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue