From 15aded75f9991d2c3507b107e9ebe613b57a9743 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 2 Oct 2025 15:12:49 -0400 Subject: [PATCH] Split battlebox respawning into its own function --- src/k_battle.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/k_battle.h | 1 + src/p_mobj.c | 41 ---------------------------------------- src/p_tick.c | 1 + 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/k_battle.c b/src/k_battle.c index faf892c31..044930e29 100644 --- a/src/k_battle.c +++ b/src/k_battle.c @@ -527,3 +527,54 @@ afteritembreaker: } } } + +// Handle respawning the battle boxes. +void K_RespawnBattleBoxes(void) +{ + if (!(gametyperules & GTR_BATTLEBOXES)) + return; + + if (itembreaker) + return; + + if (numgotboxes < (4*nummapboxes/5)) + return; + + thinker_t *th; + + for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) + { + mobj_t *box; + mobj_t *newmobj; + + if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) + continue; + + box = (mobj_t *)th; + + if (box->type != MT_RANDOMITEM || box->threshold != 68 || box->fuse) // only popped items + continue; + + // Respawn from mapthing if you have one! + if (box->spawnpoint) + { + P_SpawnMapThing(box->spawnpoint); + newmobj = box->spawnpoint->mobj; // this is set to the new mobj in P_SpawnMapThing + P_SpawnMobj(box->spawnpoint->mobj->x, box->spawnpoint->mobj->y, box->spawnpoint->mobj->z, MT_EXPLODE); // poof into existance + } + else + { + newmobj = P_SpawnMobj(box->x, box->y, box->z, box->type); + P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_EXPLODE); // poof into existance + } + + // Transfer flags2 (strongbox, objectflip) + newmobj->flags2 = box->flags2; + P_RemoveMobj(box); // make sure they disappear + numgotboxes--; // you've restored a box, remove it from the count + //continue; -- irrelevant? + } + + if (numgotboxes < 0) + numgotboxes = 0; +} diff --git a/src/k_battle.h b/src/k_battle.h index b0dd90bd9..e38f42060 100644 --- a/src/k_battle.h +++ b/src/k_battle.h @@ -22,6 +22,7 @@ UINT8 K_NumEmeralds(player_t *player); void K_RunPaperItemSpawners(void); void K_SpawnPlayerBattleBumpers(player_t *p); void K_BattleInit(void); +void K_RespawnBattleBoxes(void); #ifdef __cplusplus } // extern "C" diff --git a/src/p_mobj.c b/src/p_mobj.c index b51e206f2..53d735643 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12267,47 +12267,6 @@ void P_RespawnSpecials(void) INT32 time = 30*TICRATE; // Respawn things in empty dedicated servers mapthing_t *mthing = NULL; - if ((gametyperules & GTR_BATTLEBOXES) && !itembreaker && numgotboxes >= (4*nummapboxes/5)) // Battle Mode respawns all boxes in a different way - { - thinker_t *th; - - for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next) - { - mobj_t *box; - mobj_t *newmobj; - - if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed) - continue; - - box = (mobj_t *)th; - - if (box->type != MT_RANDOMITEM || box->threshold != 68 || box->fuse) // only popped items - continue; - - // Respawn from mapthing if you have one! - if (box->spawnpoint) - { - P_SpawnMapThing(box->spawnpoint); - newmobj = box->spawnpoint->mobj; // this is set to the new mobj in P_SpawnMapThing - P_SpawnMobj(box->spawnpoint->mobj->x, box->spawnpoint->mobj->y, box->spawnpoint->mobj->z, MT_EXPLODE); // poof into existance - } - else - { - newmobj = P_SpawnMobj(box->x, box->y, box->z, box->type); - P_SpawnMobj(newmobj->x, newmobj->y, newmobj->z, MT_EXPLODE); // poof into existance - } - - // Transfer flags2 (strongbox, objectflip) - newmobj->flags2 = box->flags2; - P_RemoveMobj(box); // make sure they disappear - numgotboxes--; // you've restored a box, remove it from the count - //continue; -- irrelevant? - } - - if (numgotboxes < 0) - numgotboxes = 0; - } - // wait time depends on player count for (p = 0; p < MAXPLAYERS; p++) { diff --git a/src/p_tick.c b/src/p_tick.c index a90673af9..6d3407e1e 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -889,6 +889,7 @@ void P_Ticker(boolean run) P_UpdateSpecials(); P_RespawnSpecials(); + K_RespawnBattleBoxes(); // Lightning, rain sounds, etc. P_PrecipitationEffects();