From f218e95c4d53b22295c9ae697709ec43985ee3c8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Nov 2018 01:26:19 +0100 Subject: [PATCH] - scriptified cht_Takeweaps. --- src/g_game.cpp | 32 ++++++++++-------- src/m_cheat.cpp | 33 ++++++------------- src/m_cheat.h | 1 + wadsrc/static/zscript/shared/player_cheat.txt | 24 ++++++++++++++ 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index e8bddf230..eff1b7a3c 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -793,19 +793,28 @@ void G_BuildTiccmd (ticcmd_t *cmd) //[Graf Zahl] This really helps if the mouse update rate can't be increased! CVAR (Bool, smooth_mouse, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) +static int LookAdjust(int look) +{ + look <<= 16; + if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead. + players[consoleplayer].ReadyWeapon != NULL) // No adjustment if no weapon. + { + auto scale = players[consoleplayer].ReadyWeapon->FOVScale; + if (scale > 0) // No adjustment if it is non-positive. + { + look = int(look * scale); + } + } + return look; +} + void G_AddViewPitch (int look, bool mouse) { if (gamestate == GS_TITLELEVEL) { return; } - look <<= 16; - if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead. - players[consoleplayer].ReadyWeapon != NULL && // No adjustment if no weapon. - players[consoleplayer].ReadyWeapon->FOVScale > 0) // No adjustment if it is non-positive. - { - look = int(look * players[consoleplayer].ReadyWeapon->FOVScale); - } + look = LookAdjust(look); if (!level.IsFreelookAllowed()) { LocalViewPitch = 0; @@ -845,14 +854,9 @@ void G_AddViewAngle (int yaw, bool mouse) if (gamestate == GS_TITLELEVEL) { return; + } - yaw <<= 16; - if (players[consoleplayer].playerstate != PST_DEAD && // No adjustment while dead. - players[consoleplayer].ReadyWeapon != NULL && // No adjustment if no weapon. - players[consoleplayer].ReadyWeapon->FOVScale > 0) // No adjustment if it is non-positive. - { - yaw = int(yaw * players[consoleplayer].ReadyWeapon->FOVScale); - } + yaw = LookAdjust(yaw); LocalViewAngle -= yaw; if (yaw != 0) { diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index bcaccc6fb..2935605a2 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -416,29 +416,7 @@ void cht_DoCheat (player_t *player, int cheat) break; case CHT_TAKEWEAPS: - if (player->morphTics || player->mo == NULL || player->mo->health <= 0) - { - return; - } - { - // 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) - { - lastinvp = invp; - invp = &(*invp)->Inventory; - if (item->IsKindOf(NAME_Weapon)) - { - AWeapon *weap = static_cast (item); - if (!(weap->WeaponFlags & WIF_WIMPY_WEAPON) || - weap->AmmoType1 != NULL) - { - item->Destroy (); - invp = lastinvp; - } - } - } - } + cht_Takeweaps(player); msg = GStrings("TXT_CHEATIDKFA"); break; @@ -613,6 +591,15 @@ void cht_Take (player_t *player, const char *name, int amount) } } +void cht_Takeweaps(player_t *player) +{ + IFVIRTUALPTR(player->mo, APlayerPawn, CheatTakeWeaps) + { + VMValue params[3] = { player->mo }; + VMCall(func, params, 1, nullptr, 0); + } +} + class DSuicider : public DThinker { DECLARE_CLASS(DSuicider, DThinker) diff --git a/src/m_cheat.h b/src/m_cheat.h index 6701bddc4..a6bb5ab68 100644 --- a/src/m_cheat.h +++ b/src/m_cheat.h @@ -16,5 +16,6 @@ void cht_Take (player_t *player, const char *item, int amount=1); void cht_SetInv(player_t *player, const char *item, int amount = 1, bool beyondMax = false); void cht_Suicide (player_t *player); FString cht_Morph (player_t *player, PClassActor *morphclass, bool quickundo); +void cht_Takeweaps(player_t *player); #endif diff --git a/wadsrc/static/zscript/shared/player_cheat.txt b/wadsrc/static/zscript/shared/player_cheat.txt index 1a222386e..8c10b5898 100644 --- a/wadsrc/static/zscript/shared/player_cheat.txt +++ b/wadsrc/static/zscript/shared/player_cheat.txt @@ -426,4 +426,28 @@ extend class PlayerPawn return ""; } + virtual void CheatTakeWeaps() + { + if (player.morphTics || health <= 0) + { + return; + } + // Do not mass-delete directly from the linked list. That can cause problems. + Array collect; + // Take away all weapons that are either non-wimpy or use ammo. + for(let item = Inv; item; item = item.Inv) + { + let weap = Weapon(item); + if (weap && (!weap.bWimpy_Weapon || weap.AmmoType1 != null)) + { + collect.Push(item); + } + } + // Destroy them in a second loop. We have to look out for indirect destructions here as will happen with powered up weapons. + for(int i = 0; i < collect.Size(); i++) + { + let item = collect[i]; + if (item) item.Destroy(); + } + } }