From 23146f1af29c44206044edfa01664957c1be36f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 3 Jan 2019 13:04:48 +0100 Subject: [PATCH] - scriptified PlayerPawn.ResetAirSupply. --- src/d_player.h | 6 +++-- src/p_mobj.cpp | 8 +++++-- src/p_user.cpp | 30 ------------------------- wadsrc/static/zscript/shared/player.txt | 25 ++++++++++++++++++++- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 50b6e96c8..500a4098a 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -92,7 +92,6 @@ public: virtual void BeginPlay () override; virtual bool UpdateWaterLevel (bool splash) override; - bool ResetAirSupply (bool playgasp = true); int GetMaxHealth(bool withupgrades = false) const; void GiveDeathmatchInventory (); @@ -131,15 +130,18 @@ public: FName MorphWeapon; double AttackZOffset; // attack height, relative to player center double UseRange; // [NS] Distance at which player can +use - double AirCapacity; // Multiplier for air supply underwater. // Everything below this point is only used by scripted code or through the scripted variable interface. int RunHealth; TObjPtr InvFirst; // first inventory item displayed on inventory bar + + // [GRB] Player class properties double ForwardMove1, ForwardMove2; double SideMove1, SideMove2; + double AirCapacity; // Multiplier for air supply underwater. double HexenArmor[5]; + // [CW] Fades for when you are being damaged. PalEntry DamageFade; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 61d4ff5d7..63c8926cb 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5045,14 +5045,18 @@ APlayerPawn *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) p->multicount = 0; p->lastkilltime = 0; p->BlendR = p->BlendG = p->BlendB = p->BlendA = 0.f; - p->mo->ResetAirSupply(false); p->Uncrouch(); p->MinPitch = p->MaxPitch = 0.; // will be filled in by PostBeginPlay()/netcode p->MUSINFOactor = NULL; p->MUSINFOtics = -1; - p->Vel.Zero(); // killough 10/98: initialize bobbing to 0. + IFVIRTUALPTR(p->mo, APlayerPawn, ResetAirSupply) + { + VMValue params[] = { p->mo, false }; + VMCall(func, params, 2, nullptr, 0); + } + for (int ii = 0; ii < MAXPLAYERS; ++ii) { if (playeringame[ii] && players[ii].camera == oldactor) diff --git a/src/p_user.cpp b/src/p_user.cpp index ba7912bda..29243fb48 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -1017,36 +1017,6 @@ bool APlayerPawn::UpdateWaterLevel (bool splash) return retval; } -//=========================================================================== -// -// APlayerPawn :: ResetAirSupply -// -// Gives the player a full "tank" of air. If they had previously completely -// run out of air, also plays the *gasp sound. Returns true if the player -// was drowning. -// -//=========================================================================== - -bool APlayerPawn::ResetAirSupply (bool playgasp) -{ - bool wasdrowning = (player->air_finished < level.time); - - if (playgasp && wasdrowning) - { - S_Sound (this, CHAN_VOICE, "*gasp", 1, ATTN_NORM); - } - if (level.airsupply> 0 && player->mo->AirCapacity > 0) player->air_finished = level.time + int(level.airsupply * player->mo->AirCapacity); - else player->air_finished = INT_MAX; - return wasdrowning; -} - -DEFINE_ACTION_FUNCTION(APlayerPawn, ResetAirSupply) -{ - PARAM_SELF_PROLOGUE(APlayerPawn); - PARAM_BOOL(playgasp); - ACTION_RETURN_BOOL(self->ResetAirSupply(playgasp)); -} - //=========================================================================== // // Animations diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index c5441ed68..0484193a8 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -2317,6 +2317,30 @@ class PlayerPawn : Actor native return painFlash; } + //=========================================================================== + // + // APlayerPawn :: ResetAirSupply + // + // Gives the player a full "tank" of air. If they had previously completely + // run out of air, also plays the *gasp sound. Returns true if the player + // was drowning. + // + //=========================================================================== + + virtual bool ResetAirSupply (bool playgasp = true) + { + let player = self.player; + bool wasdrowning = (player.air_finished < level.time); + + if (playgasp && wasdrowning) + { + A_PlaySound("*gasp", CHAN_VOICE); + } + if (level.airsupply > 0 && AirCapacity > 0) player.air_finished = level.time + int(level.airsupply * AirCapacity); + else player.air_finished = int.max; + return wasdrowning; + } + //---------------------------------------------------------------------------- // // @@ -2324,7 +2348,6 @@ class PlayerPawn : Actor native //---------------------------------------------------------------------------- native clearscope int GetMaxHealth(bool withupgrades = false) const; - native bool ResetAirSupply (bool playgasp = true); native clearscope static String GetPrintableDisplayName(Class cls); native void CheckMusicChange(); native void CheckEnvironment();