From 9b4e10d5d77d4695513fa33a811eafe08d092762 Mon Sep 17 00:00:00 2001 From: Sally Cochenour Date: Thu, 9 Apr 2020 22:56:31 -0400 Subject: [PATCH 1/2] Item dropping code cleanup --- src/k_kart.c | 111 ++++++++++++++++++++++++-------------------------- src/k_kart.h | 2 +- src/p_inter.c | 2 +- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 3342b809b..4cddcee1d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1434,7 +1434,7 @@ static void K_DebtStingPlayer(player_t *player, INT32 length) if (player->mo->state != &states[S_KART_SPIN]) P_SetPlayerMobjState(player->mo, S_KART_SPIN); - K_DropHnextList(player); + K_DropHnextList(player, false); return; } @@ -2875,7 +2875,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto if (cv_kartdebughuddrop.value && !modeattacking) K_DropItems(player); else - K_DropHnextList(player); + K_DropHnextList(player, false); return; } @@ -3020,7 +3020,7 @@ void K_SquishPlayer(player_t *player, mobj_t *source, mobj_t *inflictor) if (cv_kartdebughuddrop.value && !modeattacking) K_DropItems(player); else - K_DropHnextList(player); + K_DropHnextList(player, false); return; } @@ -3226,7 +3226,7 @@ void K_StealBumper(player_t *player, player_t *victim, boolean force) if (cv_kartdebughuddrop.value && !modeattacking) K_DropItems(victim); else - K_DropHnextList(victim); + K_DropHnextList(victim, false); return; } @@ -4689,54 +4689,51 @@ void K_UpdateHnextList(player_t *player, boolean clean) nextwork = work->hnext; - while ((work = nextwork) && !P_MobjWasRemoved(work)) + while ((work = nextwork) && !(work == NULL || P_MobjWasRemoved(work))) { nextwork = work->hnext; if (!clean && (!work->movedir || work->movedir <= (UINT16)player->kartstuff[k_itemamount])) + { continue; + } P_RemoveMobj(work); } } // For getting hit! -void K_DropHnextList(player_t *player) +void K_DropHnextList(player_t *player, boolean keepshields) { mobj_t *work = player->mo, *nextwork, *dropwork; INT32 flip; mobjtype_t type; boolean orbit, ponground, dropall = true; + INT32 shield = K_GetShieldFromItem(player->kartstuff[k_itemtype]); - if (!work || P_MobjWasRemoved(work)) + if (work == NULL || P_MobjWasRemoved(work)) + { return; + } flip = P_MobjFlip(player->mo); ponground = P_IsObjectOnGround(player->mo); - if (player->kartstuff[k_itemtype] == KITEM_THUNDERSHIELD) + if (shield != KSHIELD_NONE && !keepshields) { - K_DoThunderShield(player); - player->kartstuff[k_itemtype] = KITEM_NONE; - player->kartstuff[k_itemamount] = 0; + if (shield == KSHIELD_THUNDER) + { + K_DoThunderShield(player); + } + player->kartstuff[k_curshield] = KSHIELD_NONE; - } - else if (player->kartstuff[k_itemtype] == KITEM_BUBBLESHIELD) - { player->kartstuff[k_itemtype] = KITEM_NONE; - player->kartstuff[k_itemamount] = 0; - player->kartstuff[k_curshield] = KSHIELD_NONE; - } - else if (player->kartstuff[k_itemtype] == KITEM_FLAMESHIELD) - { - player->kartstuff[k_itemtype] = KITEM_NONE; - player->kartstuff[k_itemamount] = 0; - player->kartstuff[k_curshield] = KSHIELD_NONE; + player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; } nextwork = work->hnext; - while ((work = nextwork) && !P_MobjWasRemoved(work)) + while ((work = nextwork) && !(work == NULL || P_MobjWasRemoved(work))) { nextwork = work->hnext; @@ -4765,20 +4762,20 @@ void K_DropHnextList(player_t *player) orbit = false; type = MT_EGGMANITEM; break; - // intentionally do nothing - case MT_SINK_SHIELD: - case MT_ROCKETSNEAKER: - return; default: continue; } dropwork = P_SpawnMobj(work->x, work->y, work->z, type); + P_SetTarget(&dropwork->target, player->mo); - P_AddKartItem(dropwork); // needs to be called here so shrink can bust items off players in front of the user. + P_AddKartItem(dropwork); // needs to be called here so shrink can bust items off players in front of the user. + dropwork->angle = work->angle; - dropwork->flags2 = work->flags2; + dropwork->flags |= MF_NOCLIPTHING; + dropwork->flags2 = work->flags2; + dropwork->floorz = work->floorz; dropwork->ceilingz = work->ceilingz; @@ -4807,19 +4804,29 @@ void K_DropHnextList(player_t *player) if (orbit) // splay out { dropwork->flags2 |= MF2_AMBUSH; + dropwork->z += flip; + dropwork->momx = player->mo->momx>>1; dropwork->momy = player->mo->momy>>1; dropwork->momz = 3*flip*mapobjectscale; + if (dropwork->eflags & MFE_UNDERWATER) dropwork->momz = (117 * dropwork->momz) / 200; + P_Thrust(dropwork, work->angle - ANGLE_90, 6*mapobjectscale); + dropwork->movecount = 2; dropwork->movedir = work->angle - ANGLE_90; + P_SetMobjState(dropwork, dropwork->info->deathstate); + dropwork->tics = -1; + if (type == MT_JAWZ_DUD) + { dropwork->z += 20*flip*dropwork->scale; + } else { dropwork->color = work->color; @@ -4835,39 +4842,33 @@ void K_DropHnextList(player_t *player) P_RemoveMobj(work); } + // we need this here too because this is done in afterthink - pointers are cleaned up at the START of each tic... + P_SetTarget(&player->mo->hnext, NULL); + + player->kartstuff[k_bananadrag] = 0; + + if (player->kartstuff[k_eggmanheld]) { - // we need this here too because this is done in afterthink - pointers are cleaned up at the START of each tic... - P_SetTarget(&player->mo->hnext, NULL); - player->kartstuff[k_bananadrag] = 0; - if (player->kartstuff[k_eggmanheld]) - player->kartstuff[k_eggmanheld] = 0; - else if (player->kartstuff[k_itemheld] - && (dropall || (--player->kartstuff[k_itemamount] <= 0))) - { - player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; - player->kartstuff[k_itemtype] = KITEM_NONE; - } + player->kartstuff[k_eggmanheld] = 0; + } + else if (player->kartstuff[k_itemheld] + && (dropall || (--player->kartstuff[k_itemamount] <= 0))) + { + player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; + player->kartstuff[k_itemtype] = KITEM_NONE; } } // For getting EXTRA hit! void K_DropItems(player_t *player) { - INT32 shieldhack = 0; + K_DropHnextList(player, true); - if (player->kartstuff[k_curshield]) - shieldhack = K_GetShieldFromItem(player->kartstuff[k_itemtype]); - - if (shieldhack) - player->kartstuff[k_itemtype] = KITEM_NONE; - - K_DropHnextList(player); - - if (player->mo && !P_MobjWasRemoved(player->mo) && player->kartstuff[k_itemamount]) + if (player->mo && !P_MobjWasRemoved(player->mo) && player->kartstuff[k_itemamount] > 0) { mobj_t *drop = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z + player->mo->height/2, MT_FLOATINGITEM); P_SetScale(drop, drop->scale>>4); - drop->destscale = (3*drop->destscale)/2;; + drop->destscale = (3*drop->destscale)/2; drop->angle = player->mo->angle + ANGLE_90; P_Thrust(drop, @@ -4877,13 +4878,7 @@ void K_DropItems(player_t *player) if (drop->eflags & MFE_UNDERWATER) drop->momz = (117 * drop->momz) / 200; - switch (shieldhack) - { - case KSHIELD_THUNDER: drop->threshold = KITEM_THUNDERSHIELD; break; - case KSHIELD_BUBBLE: drop->threshold = KITEM_BUBBLESHIELD; break; - case KSHIELD_FLAME: drop->threshold = KITEM_FLAMESHIELD; break; - default: drop->threshold = player->kartstuff[k_itemtype]; break; - } + drop->threshold = player->kartstuff[k_itemtype]; drop->movecount = player->kartstuff[k_itemamount]; drop->flags |= MF_NOCLIPTHING; diff --git a/src/k_kart.h b/src/k_kart.h index 8dc5604b8..4053e687c 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -56,7 +56,7 @@ void K_DoSneaker(player_t *player, INT32 type); void K_DoPogoSpring(mobj_t *mo, fixed_t vertispeed, UINT8 sound); void K_KillBananaChain(mobj_t *banana, mobj_t *inflictor, mobj_t *source); void K_UpdateHnextList(player_t *player, boolean clean); -void K_DropHnextList(player_t *player); +void K_DropHnextList(player_t *player, boolean keepshields); void K_RepairOrbitChain(mobj_t *orbit); player_t *K_FindJawzTarget(mobj_t *actor, player_t *source); boolean K_CheckPlayersRespawnColliding(INT32 playernum, fixed_t x, fixed_t y); diff --git a/src/p_inter.c b/src/p_inter.c index 8cc307571..1451e4b6d 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -542,7 +542,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (player->kartstuff[k_bubbleblowup] > 0) { - K_DropHnextList(player); + K_DropHnextList(player, false); special->extravalue1 = 2; // WAIT... special->extravalue2 = 52; // Slightly over the respawn timer length return; From 8b5bd645ca5d8ef9269aa6ccf4375337bd0c1672 Mon Sep 17 00:00:00 2001 From: Sally Cochenour Date: Thu, 9 Apr 2020 22:57:05 -0400 Subject: [PATCH 2/2] See if cleaning the pointer here fixes shrink/eggbox syncbombs --- src/k_kart.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 4cddcee1d..865ee11cb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -4700,6 +4700,13 @@ void K_UpdateHnextList(player_t *player, boolean clean) P_RemoveMobj(work); } + + if (player->mo->hnext == NULL || P_MobjWasRemoved(player->mo->hnext)) + { + // Like below, try to clean up the pointer if it's NULL. + // Maybe this was a cause of the shrink/eggbox fails? + P_SetTarget(&player->mo->hnext, NULL); + } } // For getting hit!