From 4e5d5d0f2e2c252c6003453f1f644b5fdd290c44 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 26 May 2009 17:35:30 +0000 Subject: [PATCH] - Fixed: The Heretic "take weapons" cheat did not remove all the weapons at once. This is because destroying one weapon has a potential to destroy a sister weapon as well. If the sister weapon is the next one in line (as it typically is), it would process that one, not realizing it was no longer part of the inventory, and stop because its Inventory link was NULL. SVN r1610 (trunk) --- src/m_cheat.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 1401cd338..8df4cb1e3 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -391,20 +391,24 @@ void cht_DoCheat (player_t *player, int cheat) { return; } - // Take away all weapons that are either non-wimpy or use ammo. - for (item = player->mo->Inventory; item != NULL; ) { - AInventory *next = item->Inventory; - if (item->IsKindOf (RUNTIME_CLASS(AWeapon))) + // Take away all weapons that are either non-wimpy or use ammo. + AInventory **invp = &player->mo->Inventory, **lastinvp; + for (item = *invp; item != NULL; item = *invp) { - AWeapon *weap = static_cast (item); - if (!(weap->WeaponFlags & WIF_WIMPY_WEAPON) || - weap->AmmoType1 != NULL) + lastinvp = invp; + invp = &(*invp)->Inventory; + if (item->IsKindOf (RUNTIME_CLASS(AWeapon))) { - item->Destroy (); + AWeapon *weap = static_cast (item); + if (!(weap->WeaponFlags & WIF_WIMPY_WEAPON) || + weap->AmmoType1 != NULL) + { + item->Destroy (); + invp = lastinvp; + } } } - item = next; } msg = GStrings("TXT_CHEATIDKFA"); break;