- backported Zandronum's MaxHealth base class for the MaxHealthBonus item.

This commit is contained in:
Christoph Oelckers 2017-03-02 11:39:52 +01:00
parent 00dc59ebdc
commit b194ba205a
6 changed files with 39 additions and 6 deletions

View file

@ -125,6 +125,8 @@ public:
int crouchsprite;
int MaxHealth;
int BonusHealth;
int MugShotMaxHealth;
int RunHealth;
int PlayerFlags;

View file

@ -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<APlayerPawn *>(activator)->MaxHealth;
return static_cast<APlayerPawn *>(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<APlayerPawn *>(actor)->MaxHealth;
return static_cast<APlayerPawn *>(actor)->GetMaxHealth();
}
else
{

View file

@ -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;
}
}
}

View file

@ -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)

View file

@ -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

View file

@ -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;