From b194ba205ac8752593b4101bc3c7cbd0e9f72a99 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 2 Mar 2017 11:39:52 +0100 Subject: [PATCH] - backported Zandronum's MaxHealth base class for the MaxHealthBonus item. --- src/d_player.h | 2 ++ src/p_acs.cpp | 4 +-- src/p_mobj.cpp | 4 +-- src/p_user.cpp | 4 ++- wadsrc/static/zscript/inventory/health.txt | 30 +++++++++++++++++++++- wadsrc/static/zscript/shared/player.txt | 1 + 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 2787df231d..379265cab1 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -125,6 +125,8 @@ public: int crouchsprite; int MaxHealth; + int BonusHealth; + int MugShotMaxHealth; int RunHealth; int PlayerFlags; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 5ea7dfa075..4e1b7a026b 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1330,7 +1330,7 @@ static int CheckInventory (AActor *activator, const char *type, bool max) if (max) { if (activator->IsKindOf (RUNTIME_CLASS (APlayerPawn))) - return static_cast(activator)->MaxHealth; + return static_cast(activator)->GetMaxHealth(); else return activator->SpawnHealth(); } @@ -3939,7 +3939,7 @@ int DLevelScript::GetActorProperty (int tid, int property) case APROP_Dormant: return !!(actor->flags2 & MF2_DORMANT); case APROP_SpawnHealth: if (actor->IsKindOf (RUNTIME_CLASS (APlayerPawn))) { - return static_cast(actor)->MaxHealth; + return static_cast(actor)->GetMaxHealth(); } else { diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index db8964ef4f..99f48a702c 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1340,7 +1340,7 @@ bool P_GiveBody(AActor *actor, int num, int max) { if (!(player->MorphStyle & MORPH_ADDSTAMINA)) { - max -= player->mo->stamina; + max -= player->mo->stamina + player->mo->BonusHealth; } } else // old health behaviour @@ -1348,7 +1348,7 @@ bool P_GiveBody(AActor *actor, int num, int max) max = MAXMORPHHEALTH; if (player->MorphStyle & MORPH_ADDSTAMINA) { - max += player->mo->stamina; + max += player->mo->stamina + player->mo->BonusHealth; } } } diff --git a/src/p_user.cpp b/src/p_user.cpp index ab4390ba2c..9b65b559f8 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -781,6 +781,7 @@ void APlayerPawn::Serialize(FSerializer &arc) arc("jumpz", JumpZ, def->JumpZ) ("maxhealth", MaxHealth, def->MaxHealth) + ("bonushealth", BonusHealth, def->BonusHealth) ("runhealth", RunHealth, def->RunHealth) ("spawnmask", SpawnMask, def->SpawnMask) ("forwardmove1", ForwardMove1, def->ForwardMove1) @@ -1353,7 +1354,7 @@ const char *APlayerPawn::GetSoundClass() const int APlayerPawn::GetMaxHealth(bool withupgrades) const { int ret = MaxHealth > 0? MaxHealth : ((i_compatflags&COMPATF_DEHHEALTH)? 100 : deh.MaxHealth); - if (withupgrades) ret += stamina; + if (withupgrades) ret += stamina + BonusHealth; return ret; } @@ -3345,6 +3346,7 @@ bool P_IsPlayerTotallyFrozen(const player_t *player) DEFINE_FIELD(APlayerPawn, crouchsprite) DEFINE_FIELD(APlayerPawn, MaxHealth) +DEFINE_FIELD(APlayerPawn, BonusHealth) DEFINE_FIELD(APlayerPawn, MugShotMaxHealth) DEFINE_FIELD(APlayerPawn, RunHealth) DEFINE_FIELD(APlayerPawn, PlayerFlags) diff --git a/wadsrc/static/zscript/inventory/health.txt b/wadsrc/static/zscript/inventory/health.txt index e64bbfd4a9..986dc7069f 100644 --- a/wadsrc/static/zscript/inventory/health.txt +++ b/wadsrc/static/zscript/inventory/health.txt @@ -86,8 +86,36 @@ class Health : Inventory } return false; } +} - +class MaxHealth : Health +{ + //=========================================================================== + // + // TryPickup + // + //=========================================================================== + + override bool TryPickup (in out Actor other) + { + bool success = false; + int savedAmount = MaxAmount; + let player = PlayerPawn(other); + MaxAmount = Health; + if (player) + { + if (player.BonusHealth < savedAmount) + { + player.BonusHealth = min(player.BonusHealth + Amount, savedAmount); + success = true; + } + MaxAmount += player.BonusHealth; + } + success |= Super.TryPickup(other); + MaxAmount = saved; + if (success) GoAwayAndDie(); + return success; + } } class HealthPickup : Inventory diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 97e065c2ab..a802107141 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -3,6 +3,7 @@ class PlayerPawn : Actor native native int crouchsprite; native int MaxHealth; + native int BonusHealth; native int MugShotMaxHealth; native int RunHealth; native int PlayerFlags;