From bdf761e45707881629d570b6d015152bfd7c1d91 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Mar 2017 21:29:14 +0200 Subject: [PATCH] - moved th player resurrection code into a player_t method. --- src/d_player.h | 1 + src/m_cheat.cpp | 30 +---------------- src/namedef.h | 1 + src/p_user.cpp | 43 +++++++++++++++++++++++++ wadsrc/static/zscript/shared/player.txt | 1 + 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index f9da0d120..dc5f6cd54 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -533,6 +533,7 @@ public: // [Nash] set player FOV void SetFOV(float fov); bool HasWeaponsInSlot(int slot) const; + bool Resurrect(); }; // Bookkeeping on players - state. diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 5c8607308..437e7ff89 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -339,35 +339,7 @@ void cht_DoCheat (player_t *player, int cheat) } else { - player->mo->Revive(); - player->playerstate = PST_LIVE; - player->health = player->mo->health = player->mo->GetDefault()->health; - player->viewheight = ((APlayerPawn *)player->mo->GetDefault())->ViewHeight; - player->mo->renderflags &= ~RF_INVISIBLE; - player->mo->Height = player->mo->GetDefault()->Height; - player->mo->radius = player->mo->GetDefault()->radius; - player->mo->special1 = 0; // required for the Hexen fighter's fist attack. - // This gets set by AActor::Die as flag for the wimpy death and must be reset here. - player->mo->SetState (player->mo->SpawnState); - if (!(player->mo->flags2 & MF2_DONTTRANSLATE)) - { - player->mo->Translation = TRANSLATION(TRANSLATION_Players, uint8_t(player-players)); - } - if (player->ReadyWeapon != nullptr) - { - P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->GetUpState()); - } - - if (player->morphTics) - { - P_UndoPlayerMorph(player, player); - } - - // player is now alive. - // fire E_PlayerRespawned and start the ACS SCRIPT_Respawn. - E_PlayerRespawned(int(player - players)); - // - FBehavior::StaticStartTypedScripts(SCRIPT_Respawn, player->mo, true); + player->Resurrect(); } } diff --git a/src/namedef.h b/src/namedef.h index ca99ff650..a193945de 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -901,3 +901,4 @@ xx(Player5) xx(Player6) xx(Player7) xx(Player8) +xx(PlayerChunk) diff --git a/src/p_user.cpp b/src/p_user.cpp index ae4cfda78..694daffa1 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -62,6 +62,8 @@ #include "g_levellocals.h" #include "actorinlines.h" #include "r_data/r_translate.h" +#include "p_acs.h" +#include "events.h" static FRandom pr_skullpop ("SkullPop"); @@ -725,6 +727,47 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, HasWeaponsInSlot) } +bool player_t::Resurrect() +{ + if (mo == nullptr || mo->IsKindOf(NAME_PlayerChunk)) return false; + mo->Revive(); + playerstate = PST_LIVE; + health = mo->health = mo->GetDefault()->health; + viewheight = ((APlayerPawn *)mo->GetDefault())->ViewHeight; + mo->renderflags &= ~RF_INVISIBLE; + mo->Height = mo->GetDefault()->Height; + mo->radius = mo->GetDefault()->radius; + mo->special1 = 0; // required for the Hexen fighter's fist attack. + // This gets set by AActor::Die as flag for the wimpy death and must be reset here. + mo->SetState(mo->SpawnState); + if (!(mo->flags2 & MF2_DONTTRANSLATE)) + { + mo->Translation = TRANSLATION(TRANSLATION_Players, uint8_t(this - players)); + } + if (ReadyWeapon != nullptr) + { + P_SetPsprite(this, PSP_WEAPON, ReadyWeapon->GetUpState()); + } + + if (morphTics) + { + P_UndoPlayerMorph(this, this); + } + + // player is now alive. + // fire E_PlayerRespawned and start the ACS SCRIPT_Respawn. + E_PlayerRespawned(int(this - players)); + // + FBehavior::StaticStartTypedScripts(SCRIPT_Respawn, mo, true); +} + +DEFINE_ACTION_FUNCTION(_PlayerInfo, Resurrect) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_t); + ACTION_RETURN_BOOL(self->Resurrect()); +} + + DEFINE_ACTION_FUNCTION(_PlayerInfo, GetUserName) { PARAM_SELF_STRUCT_PROLOGUE(player_t); diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 138db474b..67414c542 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -360,6 +360,7 @@ usercmd_t original_cmd; native void SetLogText (String text); native void DropWeapon(); native void BringUpWeapon(); + native bool Resurrect(); native String GetUserName() const; native Color GetColor() const;