2017-04-17 10:27:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright 1994-1996 Raven Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2002-2016 Christoph Oelckers
|
|
|
|
// Copyright 2005-2008 Martin Howe
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "info.h"
|
|
|
|
#include "a_pickups.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "a_morph.h"
|
|
|
|
#include "doomstat.h"
|
2016-09-19 13:07:53 +00:00
|
|
|
#include "serializer.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "p_enemy.h"
|
|
|
|
#include "d_player.h"
|
2016-09-19 13:07:53 +00:00
|
|
|
#include "r_data/sprites.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2017-04-12 23:12:04 +00:00
|
|
|
#include "vm.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
static FRandom pr_morphmonst ("MorphMonster");
|
|
|
|
|
|
|
|
void EndAllPowerupEffects(AInventory *item);
|
|
|
|
void InitAllPowerupEffects(AInventory *item);
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_MorphPlayer
|
|
|
|
//
|
|
|
|
// Returns true if the player gets turned into a chicken/pig.
|
|
|
|
//
|
|
|
|
// TODO: Allow morphed players to receive weapon sets (not just one weapon),
|
|
|
|
// since they have their own weapon slots now.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2017-02-08 18:42:24 +00:00
|
|
|
bool P_MorphPlayer (player_t *activator, player_t *p, PClassActor *spawntype, int duration, int style, PClassActor *enter_flash, PClassActor *exit_flash)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
AInventory *item;
|
|
|
|
APlayerPawn *morphed;
|
|
|
|
APlayerPawn *actor;
|
|
|
|
|
|
|
|
actor = p->mo;
|
2016-09-01 18:49:58 +00:00
|
|
|
if (actor == nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (actor->flags3 & MF3_DONTMORPH)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((p->mo->flags2 & MF2_INVULNERABLE) && ((p != activator) || (!(style & MORPH_WHENINVULNERABLE))))
|
|
|
|
{ // Immune when invulnerable unless this is a power we activated
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p->morphTics)
|
|
|
|
{ // Player is already a beast
|
|
|
|
if ((p->mo->GetClass() == spawntype)
|
|
|
|
&& (p->mo->PlayerFlags & PPF_CANSUPERMORPH)
|
|
|
|
&& (p->morphTics < (((duration) ? duration : MORPHTICS) - TICRATE))
|
2017-01-15 22:21:38 +00:00
|
|
|
&& (p->mo->FindInventory (PClass::FindActor(NAME_PowerWeaponLevel2), true) == nullptr))
|
2016-03-01 15:47:10 +00:00
|
|
|
{ // Make a super chicken
|
2017-01-15 22:21:38 +00:00
|
|
|
p->mo->GiveInventoryType (PClass::FindActor(NAME_PowerWeaponLevel2));
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p->health <= 0)
|
|
|
|
{ // Dead players cannot morph
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-01 18:49:58 +00:00
|
|
|
if (spawntype == nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!spawntype->IsDescendantOf (RUNTIME_CLASS(APlayerPawn)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (spawntype == p->mo->GetClass())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
morphed = static_cast<APlayerPawn *>(Spawn (spawntype, actor->Pos(), NO_REPLACE));
|
|
|
|
EndAllPowerupEffects(actor->Inventory);
|
|
|
|
DObject::StaticPointerSubstitution (actor, morphed);
|
2016-07-22 13:21:15 +00:00
|
|
|
if ((style & MORPH_TRANSFERTRANSLATION) && !(morphed->flags2 & MF2_DONTTRANSLATE))
|
|
|
|
{
|
|
|
|
morphed->Translation = actor->Translation;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
if ((actor->tid != 0) && (style & MORPH_NEWTIDBEHAVIOUR))
|
|
|
|
{
|
|
|
|
morphed->tid = actor->tid;
|
|
|
|
morphed->AddToHash ();
|
|
|
|
actor->RemoveFromHash ();
|
|
|
|
actor->tid = 0;
|
|
|
|
}
|
2016-03-16 11:41:26 +00:00
|
|
|
morphed->Angles.Yaw = actor->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->target = actor->target;
|
2016-09-01 18:49:58 +00:00
|
|
|
morphed->tracer = actor->tracer;
|
|
|
|
morphed->alternative = actor;
|
2016-04-18 13:28:45 +00:00
|
|
|
morphed->FriendPlayer = actor->FriendPlayer;
|
|
|
|
morphed->DesignatedTeam = actor->DesignatedTeam;
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->Score = actor->Score;
|
|
|
|
p->PremorphWeapon = p->ReadyWeapon;
|
|
|
|
morphed->special2 = actor->flags & ~MF_JUSTHIT;
|
|
|
|
morphed->player = p;
|
|
|
|
if (actor->renderflags & RF_INVISIBLE)
|
|
|
|
{
|
|
|
|
morphed->special2 |= MF_JUSTHIT;
|
|
|
|
}
|
|
|
|
if (morphed->ViewHeight > p->viewheight && p->deltaviewheight == 0)
|
|
|
|
{ // If the new view height is higher than the old one, start moving toward it.
|
|
|
|
p->deltaviewheight = p->GetDeltaViewHeight();
|
|
|
|
}
|
|
|
|
morphed->flags |= actor->flags & (MF_SHADOW|MF_NOGRAVITY);
|
|
|
|
morphed->flags2 |= actor->flags2 & MF2_FLY;
|
|
|
|
morphed->flags3 |= actor->flags3 & MF3_GHOST;
|
2017-01-13 22:17:04 +00:00
|
|
|
AActor *eflash = Spawn(((enter_flash) ? enter_flash : PClass::FindActor("TeleportFog")), actor->PosPlusZ(TELEFOGHEIGHT), ALLOW_REPLACE);
|
2016-09-01 18:49:58 +00:00
|
|
|
actor->player = nullptr;
|
|
|
|
actor->alternative = morphed;
|
2016-03-01 15:47:10 +00:00
|
|
|
actor->flags &= ~(MF_SOLID|MF_SHOOTABLE);
|
|
|
|
actor->flags |= MF_UNMORPHED;
|
|
|
|
actor->renderflags |= RF_INVISIBLE;
|
|
|
|
p->morphTics = (duration) ? duration : MORPHTICS;
|
|
|
|
|
|
|
|
// [MH] Used by SBARINFO to speed up face drawing
|
|
|
|
p->MorphedPlayerClass = spawntype;
|
|
|
|
|
|
|
|
p->MorphStyle = style;
|
2017-01-13 22:17:04 +00:00
|
|
|
p->MorphExitFlash = (exit_flash) ? exit_flash : PClass::FindActor("TeleportFog");
|
2016-03-01 15:47:10 +00:00
|
|
|
p->health = morphed->health;
|
|
|
|
p->mo = morphed;
|
2016-03-19 23:54:18 +00:00
|
|
|
p->Vel.X = p->Vel.Y = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->ObtainInventory (actor);
|
|
|
|
// Remove all armor
|
2016-09-01 18:49:58 +00:00
|
|
|
for (item = morphed->Inventory; item != nullptr; )
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
AInventory *next = item->Inventory;
|
2017-01-18 22:46:19 +00:00
|
|
|
if (item->IsKindOf (PClass::FindActor(NAME_Armor)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-11-30 14:54:01 +00:00
|
|
|
item->DepleteOrDestroy();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
InitAllPowerupEffects(morphed->Inventory);
|
|
|
|
morphed->ActivateMorphWeapon ();
|
|
|
|
if (p->camera == actor)
|
|
|
|
{
|
|
|
|
p->camera = morphed;
|
|
|
|
}
|
|
|
|
morphed->ScoreIcon = actor->ScoreIcon; // [GRB]
|
|
|
|
if (eflash)
|
|
|
|
eflash->target = p->mo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-01 18:23:43 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(_PlayerInfo, MorphPlayer)
|
|
|
|
{
|
|
|
|
PARAM_SELF_STRUCT_PROLOGUE(player_t);
|
2017-01-20 00:11:36 +00:00
|
|
|
PARAM_POINTER(activator, player_t);
|
2017-01-01 18:23:43 +00:00
|
|
|
PARAM_CLASS(spawntype, APlayerPawn);
|
|
|
|
PARAM_INT(duration);
|
|
|
|
PARAM_INT(style);
|
|
|
|
PARAM_CLASS_DEF(enter_flash, AActor);
|
|
|
|
PARAM_CLASS_DEF(exit_flash, AActor);
|
2017-01-20 00:11:36 +00:00
|
|
|
ACTION_RETURN_BOOL(P_MorphPlayer(activator, self, spawntype, duration, style, enter_flash, exit_flash));
|
2017-01-01 18:23:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_UndoPlayerMorph
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag, bool force)
|
|
|
|
{
|
|
|
|
AWeapon *beastweap;
|
|
|
|
APlayerPawn *mo;
|
|
|
|
APlayerPawn *pmo;
|
|
|
|
|
|
|
|
pmo = player->mo;
|
|
|
|
// [MH]
|
|
|
|
// Checks pmo as well; the PowerMorph destroyer will
|
|
|
|
// try to unmorph the player; if the destroyer runs
|
|
|
|
// because the level or game is ended while morphed,
|
|
|
|
// by the time it gets executed the morphed player
|
|
|
|
// pawn instance may have already been destroyed.
|
2016-09-01 18:49:58 +00:00
|
|
|
if (pmo == nullptr || pmo->alternative == nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeliberateUnmorphIsOkay = !!(MORPH_STANDARDUNDOING & unmorphflag);
|
|
|
|
|
|
|
|
if ((pmo->flags2 & MF2_INVULNERABLE) // If the player is invulnerable
|
|
|
|
&& ((player != activator) // and either did not decide to unmorph,
|
|
|
|
|| (!((player->MorphStyle & MORPH_WHENINVULNERABLE) // or the morph style does not allow it
|
|
|
|
|| (DeliberateUnmorphIsOkay))))) // (but standard morph styles always allow it),
|
|
|
|
{ // Then the player is immune to the unmorph.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:49:58 +00:00
|
|
|
mo = barrier_cast<APlayerPawn *>(pmo->alternative);
|
2016-03-01 15:47:10 +00:00
|
|
|
mo->SetOrigin (pmo->Pos(), false);
|
|
|
|
mo->flags |= MF_SOLID;
|
|
|
|
pmo->flags &= ~MF_SOLID;
|
|
|
|
if (!force && !P_TestMobjLocation (mo))
|
|
|
|
{ // Didn't fit
|
|
|
|
mo->flags &= ~MF_SOLID;
|
|
|
|
pmo->flags |= MF_SOLID;
|
|
|
|
player->morphTics = 2*TICRATE;
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-01 18:49:58 +00:00
|
|
|
// No longer using tracer as morph storage. That is what 'alternative' is for.
|
|
|
|
// If the tracer has changed on the morph, change the original too.
|
|
|
|
mo->target = pmo->target;
|
|
|
|
mo->tracer = pmo->tracer;
|
|
|
|
pmo->player = nullptr;
|
2017-01-01 18:23:43 +00:00
|
|
|
mo->alternative = pmo->alternative = nullptr;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Remove the morph power if the morph is being undone prematurely.
|
2017-01-01 18:23:43 +00:00
|
|
|
auto pmtype = PClass::FindActor("PowerMorph");
|
2016-09-01 18:49:58 +00:00
|
|
|
for (AInventory *item = pmo->Inventory, *next = nullptr; item != nullptr; item = next)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
next = item->Inventory;
|
2017-01-01 18:23:43 +00:00
|
|
|
if (item->IsKindOf(pmtype))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
item->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EndAllPowerupEffects(pmo->Inventory);
|
|
|
|
mo->ObtainInventory (pmo);
|
|
|
|
DObject::StaticPointerSubstitution (pmo, mo);
|
|
|
|
if ((pmo->tid != 0) && (player->MorphStyle & MORPH_NEWTIDBEHAVIOUR))
|
|
|
|
{
|
|
|
|
mo->tid = pmo->tid;
|
|
|
|
mo->AddToHash ();
|
|
|
|
}
|
2016-03-16 11:41:26 +00:00
|
|
|
mo->Angles.Yaw = pmo->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
mo->player = player;
|
|
|
|
mo->reactiontime = 18;
|
|
|
|
mo->flags = ActorFlags::FromInt (pmo->special2) & ~MF_JUSTHIT;
|
2016-03-19 23:54:18 +00:00
|
|
|
mo->Vel.X = mo->Vel.Y = 0;
|
|
|
|
player->Vel.Zero();
|
|
|
|
mo->Vel.Z = pmo->Vel.Z;
|
2017-05-02 14:22:50 +00:00
|
|
|
mo->floorz = pmo->floorz;
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!(pmo->special2 & MF_JUSTHIT))
|
|
|
|
{
|
|
|
|
mo->renderflags &= ~RF_INVISIBLE;
|
|
|
|
}
|
|
|
|
mo->flags = (mo->flags & ~(MF_SHADOW|MF_NOGRAVITY)) | (pmo->flags & (MF_SHADOW|MF_NOGRAVITY));
|
|
|
|
mo->flags2 = (mo->flags2 & ~MF2_FLY) | (pmo->flags2 & MF2_FLY);
|
|
|
|
mo->flags3 = (mo->flags3 & ~MF3_GHOST) | (pmo->flags3 & MF3_GHOST);
|
|
|
|
mo->Score = pmo->Score;
|
|
|
|
InitAllPowerupEffects(mo->Inventory);
|
|
|
|
|
|
|
|
PClassActor *exit_flash = player->MorphExitFlash;
|
|
|
|
bool correctweapon = !!(player->MorphStyle & MORPH_LOSEACTUALWEAPON);
|
|
|
|
bool undobydeathsaves = !!(player->MorphStyle & MORPH_UNDOBYDEATHSAVES);
|
|
|
|
|
|
|
|
player->morphTics = 0;
|
|
|
|
player->MorphedPlayerClass = 0;
|
|
|
|
player->MorphStyle = 0;
|
2016-09-01 18:49:58 +00:00
|
|
|
player->MorphExitFlash = nullptr;
|
2016-03-01 15:47:10 +00:00
|
|
|
player->viewheight = mo->ViewHeight;
|
2017-01-15 22:21:38 +00:00
|
|
|
AInventory *level2 = mo->FindInventory (PClass::FindActor(NAME_PowerWeaponLevel2), true);
|
2016-09-01 18:49:58 +00:00
|
|
|
if (level2 != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
level2->Destroy ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((player->health > 0) || undobydeathsaves)
|
|
|
|
{
|
|
|
|
player->health = mo->health = mo->SpawnHealth();
|
|
|
|
}
|
|
|
|
else // killed when morphed so stay dead
|
|
|
|
{
|
|
|
|
mo->health = player->health;
|
|
|
|
}
|
|
|
|
|
|
|
|
player->mo = mo;
|
|
|
|
if (player->camera == pmo)
|
|
|
|
{
|
|
|
|
player->camera = mo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [MH]
|
|
|
|
// If the player that was morphed is the one
|
|
|
|
// taking events, reset up the face, if any;
|
|
|
|
// this is only needed for old-skool skins
|
|
|
|
// and for the original DOOM status bar.
|
|
|
|
if (player == &players[consoleplayer])
|
|
|
|
{
|
2017-02-08 15:42:13 +00:00
|
|
|
FName face = pmo->Face;
|
|
|
|
if (face != NAME_None)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// Assume root-level base skin to begin with
|
|
|
|
size_t skinindex = 0;
|
|
|
|
// If a custom skin was in use, then reload it
|
|
|
|
// or else the base skin for the player class.
|
|
|
|
if ((unsigned int)player->userinfo.GetSkin() >= PlayerClasses.Size () &&
|
2017-02-17 20:51:23 +00:00
|
|
|
(unsigned)player->userinfo.GetSkin() < Skins.Size())
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
skinindex = player->userinfo.GetSkin();
|
|
|
|
}
|
|
|
|
else if (PlayerClasses.Size () > 1)
|
|
|
|
{
|
|
|
|
const PClass *whatami = player->mo->GetClass();
|
|
|
|
for (unsigned int i = 0; i < PlayerClasses.Size (); ++i)
|
|
|
|
{
|
|
|
|
if (PlayerClasses[i].Type == whatami)
|
|
|
|
{
|
|
|
|
skinindex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:49:58 +00:00
|
|
|
AActor *eflash = nullptr;
|
|
|
|
if (exit_flash != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-22 11:42:27 +00:00
|
|
|
eflash = Spawn(exit_flash, pmo->Vec3Angle(20., mo->Angles.Yaw, TELEFOGHEIGHT), ALLOW_REPLACE);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (eflash) eflash->target = mo;
|
|
|
|
}
|
|
|
|
mo->SetupWeaponSlots(); // Use original class's weapon slots.
|
|
|
|
beastweap = player->ReadyWeapon;
|
2016-09-01 18:49:58 +00:00
|
|
|
if (player->PremorphWeapon != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
player->PremorphWeapon->PostMorphWeapon ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-01 18:49:58 +00:00
|
|
|
player->ReadyWeapon = player->PendingWeapon = nullptr;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
if (correctweapon)
|
|
|
|
{ // Better "lose morphed weapon" semantics
|
|
|
|
PClassActor *morphweapon = PClass::FindActor(pmo->MorphWeapon);
|
2017-02-08 14:47:22 +00:00
|
|
|
if (morphweapon != nullptr && morphweapon->IsDescendantOf(NAME_Weapon))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
AWeapon *OriginalMorphWeapon = static_cast<AWeapon *>(mo->FindInventory (morphweapon));
|
2016-09-01 18:49:58 +00:00
|
|
|
if ((OriginalMorphWeapon != nullptr) && (OriginalMorphWeapon->GivenAsMorphWeapon))
|
2016-03-01 15:47:10 +00:00
|
|
|
{ // You don't get to keep your morphed weapon.
|
2016-09-01 18:49:58 +00:00
|
|
|
if (OriginalMorphWeapon->SisterWeapon != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
OriginalMorphWeapon->SisterWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
OriginalMorphWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // old behaviour (not really useful now)
|
|
|
|
{ // Assumptions made here are no longer valid
|
2016-09-01 18:49:58 +00:00
|
|
|
if (beastweap != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{ // You don't get to keep your morphed weapon.
|
2016-09-01 18:49:58 +00:00
|
|
|
if (beastweap->SisterWeapon != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
beastweap->SisterWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
beastweap->Destroy ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pmo->Destroy ();
|
|
|
|
// Restore playerclass armor to its normal amount.
|
2017-01-18 22:42:08 +00:00
|
|
|
auto hxarmor = mo->FindInventory(NAME_HexenArmor);
|
2016-09-01 18:49:58 +00:00
|
|
|
if (hxarmor != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-18 22:42:08 +00:00
|
|
|
double *Slots = (double*)hxarmor->ScriptVar(NAME_Slots, nullptr);
|
2017-02-08 15:42:13 +00:00
|
|
|
Slots[4] = mo->HexenArmor[0];
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-25 17:41:00 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(_PlayerInfo, UndoPlayerMorph)
|
|
|
|
{
|
|
|
|
PARAM_SELF_STRUCT_PROLOGUE(player_t);
|
2016-12-02 11:06:49 +00:00
|
|
|
PARAM_POINTER_NOT_NULL(player, player_t);
|
2016-11-25 17:41:00 +00:00
|
|
|
PARAM_INT_DEF(unmorphflag);
|
|
|
|
PARAM_BOOL_DEF(force);
|
|
|
|
ACTION_RETURN_BOOL(P_UndoPlayerMorph(self, player, unmorphflag, force));
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_MorphMonster
|
|
|
|
//
|
|
|
|
// Returns true if the monster gets turned into a chicken/pig.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool P_MorphMonster (AActor *actor, PClassActor *spawntype, int duration, int style, PClassActor *enter_flash, PClassActor *exit_flash)
|
|
|
|
{
|
|
|
|
AMorphedMonster *morphed;
|
|
|
|
|
|
|
|
if (actor == NULL || actor->player || spawntype == NULL ||
|
|
|
|
actor->flags3 & MF3_DONTMORPH ||
|
|
|
|
!(actor->flags3 & MF3_ISMONSTER) ||
|
2017-01-20 00:11:36 +00:00
|
|
|
!spawntype->IsDescendantOf (PClass::FindActor(NAME_MorphedMonster)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
morphed = static_cast<AMorphedMonster *>(Spawn (spawntype, actor->Pos(), NO_REPLACE));
|
|
|
|
DObject::StaticPointerSubstitution (actor, morphed);
|
2016-07-22 13:21:15 +00:00
|
|
|
if ((style & MORPH_TRANSFERTRANSLATION) && !(morphed->flags2 & MF2_DONTTRANSLATE))
|
|
|
|
{
|
|
|
|
morphed->Translation = actor->Translation;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->tid = actor->tid;
|
2016-03-16 11:41:26 +00:00
|
|
|
morphed->Angles.Yaw = actor->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->UnmorphedMe = actor;
|
2016-03-21 11:18:46 +00:00
|
|
|
morphed->Alpha = actor->Alpha;
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->RenderStyle = actor->RenderStyle;
|
|
|
|
morphed->Score = actor->Score;
|
|
|
|
|
|
|
|
morphed->UnmorphTime = level.time + ((duration) ? duration : MORPHTICS) + pr_morphmonst();
|
|
|
|
morphed->MorphStyle = style;
|
2017-01-13 22:17:04 +00:00
|
|
|
morphed->MorphExitFlash = (exit_flash) ? exit_flash : PClass::FindActor("TeleportFog");
|
2016-03-01 15:47:10 +00:00
|
|
|
morphed->FlagsSave = actor->flags & ~MF_JUSTHIT;
|
|
|
|
morphed->special = actor->special;
|
|
|
|
memcpy (morphed->args, actor->args, sizeof(actor->args));
|
|
|
|
morphed->CopyFriendliness (actor, true);
|
|
|
|
morphed->flags |= actor->flags & MF_SHADOW;
|
|
|
|
morphed->flags3 |= actor->flags3 & MF3_GHOST;
|
|
|
|
if (actor->renderflags & RF_INVISIBLE)
|
|
|
|
{
|
|
|
|
morphed->FlagsSave |= MF_JUSTHIT;
|
|
|
|
}
|
|
|
|
morphed->AddToHash ();
|
|
|
|
actor->RemoveFromHash ();
|
|
|
|
actor->special = 0;
|
|
|
|
actor->tid = 0;
|
|
|
|
actor->flags &= ~(MF_SOLID|MF_SHOOTABLE);
|
|
|
|
actor->flags |= MF_UNMORPHED;
|
|
|
|
actor->renderflags |= RF_INVISIBLE;
|
2017-01-13 22:17:04 +00:00
|
|
|
AActor *eflash = Spawn(((enter_flash) ? enter_flash : PClass::FindActor("TeleportFog")), actor->PosPlusZ(TELEFOGHEIGHT), ALLOW_REPLACE);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (eflash)
|
|
|
|
eflash->target = morphed;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:11:36 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AActor, MorphMonster)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
2017-01-20 16:20:50 +00:00
|
|
|
PARAM_CLASS(spawntype, AActor);
|
2017-01-20 00:11:36 +00:00
|
|
|
PARAM_INT(duration);
|
|
|
|
PARAM_INT(style);
|
|
|
|
PARAM_CLASS_DEF(enter_flash, AActor);
|
|
|
|
PARAM_CLASS_DEF(exit_flash, AActor);
|
|
|
|
ACTION_RETURN_BOOL(P_MorphMonster(self, spawntype, duration, style, enter_flash, exit_flash));
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_UndoMonsterMorph
|
|
|
|
//
|
|
|
|
// Returns true if the monster unmorphs.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool P_UndoMonsterMorph (AMorphedMonster *beast, bool force)
|
|
|
|
{
|
|
|
|
AActor *actor;
|
|
|
|
|
|
|
|
if (beast->UnmorphTime == 0 ||
|
|
|
|
beast->UnmorphedMe == NULL ||
|
|
|
|
beast->flags3 & MF3_STAYMORPHED ||
|
|
|
|
beast->UnmorphedMe->flags3 & MF3_STAYMORPHED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
actor = beast->UnmorphedMe;
|
|
|
|
actor->SetOrigin (beast->Pos(), false);
|
|
|
|
actor->flags |= MF_SOLID;
|
|
|
|
beast->flags &= ~MF_SOLID;
|
|
|
|
ActorFlags6 beastflags6 = beast->flags6;
|
|
|
|
beast->flags6 &= ~MF6_TOUCHY;
|
|
|
|
if (!force && !P_TestMobjLocation (actor))
|
|
|
|
{ // Didn't fit
|
|
|
|
actor->flags &= ~MF_SOLID;
|
|
|
|
beast->flags |= MF_SOLID;
|
|
|
|
beast->flags6 = beastflags6;
|
|
|
|
beast->UnmorphTime = level.time + 5*TICRATE; // Next try in 5 seconds
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-16 11:41:26 +00:00
|
|
|
actor->Angles.Yaw = beast->Angles.Yaw;
|
2016-03-01 15:47:10 +00:00
|
|
|
actor->target = beast->target;
|
|
|
|
actor->FriendPlayer = beast->FriendPlayer;
|
|
|
|
actor->flags = beast->FlagsSave & ~MF_JUSTHIT;
|
|
|
|
actor->flags = (actor->flags & ~(MF_FRIENDLY|MF_SHADOW)) | (beast->flags & (MF_FRIENDLY|MF_SHADOW));
|
|
|
|
actor->flags3 = (actor->flags3 & ~(MF3_NOSIGHTCHECK|MF3_HUNTPLAYERS|MF3_GHOST))
|
|
|
|
| (beast->flags3 & (MF3_NOSIGHTCHECK|MF3_HUNTPLAYERS|MF3_GHOST));
|
|
|
|
actor->flags4 = (actor->flags4 & ~MF4_NOHATEPLAYERS) | (beast->flags4 & MF4_NOHATEPLAYERS);
|
|
|
|
if (!(beast->FlagsSave & MF_JUSTHIT))
|
|
|
|
actor->renderflags &= ~RF_INVISIBLE;
|
|
|
|
actor->health = actor->SpawnHealth();
|
2016-03-19 23:54:18 +00:00
|
|
|
actor->Vel = beast->Vel;
|
2016-03-01 15:47:10 +00:00
|
|
|
actor->tid = beast->tid;
|
|
|
|
actor->special = beast->special;
|
|
|
|
actor->Score = beast->Score;
|
|
|
|
memcpy (actor->args, beast->args, sizeof(actor->args));
|
|
|
|
actor->AddToHash ();
|
|
|
|
beast->UnmorphedMe = NULL;
|
|
|
|
DObject::StaticPointerSubstitution (beast, actor);
|
|
|
|
PClassActor *exit_flash = beast->MorphExitFlash;
|
|
|
|
beast->Destroy ();
|
|
|
|
AActor *eflash = Spawn(exit_flash, beast->PosPlusZ(TELEFOGHEIGHT), ALLOW_REPLACE);
|
|
|
|
if (eflash)
|
|
|
|
eflash->target = actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_UpdateMorphedMonster
|
|
|
|
//
|
|
|
|
// Returns true if the monster unmorphs.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool P_UpdateMorphedMonster (AMorphedMonster *beast)
|
|
|
|
{
|
|
|
|
if (beast->UnmorphTime > level.time)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return P_UndoMonsterMorph (beast);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_MorphedDeath
|
|
|
|
//
|
|
|
|
// Unmorphs the actor if possible.
|
|
|
|
// Returns the unmorphed actor, the style with which they were morphed and the
|
|
|
|
// health (of the AActor, not the player_t) they last had before unmorphing.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool P_MorphedDeath(AActor *actor, AActor **morphed, int *morphedstyle, int *morphedhealth)
|
|
|
|
{
|
|
|
|
// May be a morphed player
|
|
|
|
if ((actor->player) &&
|
|
|
|
(actor->player->morphTics) &&
|
|
|
|
(actor->player->MorphStyle & MORPH_UNDOBYDEATH) &&
|
|
|
|
(actor->player->mo) &&
|
2016-09-01 18:49:58 +00:00
|
|
|
(actor->player->mo->alternative))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-01 18:49:58 +00:00
|
|
|
AActor *realme = actor->player->mo->alternative;
|
2016-03-01 15:47:10 +00:00
|
|
|
int realstyle = actor->player->MorphStyle;
|
|
|
|
int realhealth = actor->health;
|
2016-04-20 20:59:57 +00:00
|
|
|
if (P_UndoPlayerMorph(actor->player, actor->player, 0, !!(actor->player->MorphStyle & MORPH_UNDOBYDEATHFORCED)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
*morphed = realme;
|
|
|
|
*morphedstyle = realstyle;
|
|
|
|
*morphedhealth = realhealth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// May be a morphed monster
|
|
|
|
if (actor->GetClass()->IsDescendantOf(RUNTIME_CLASS(AMorphedMonster)))
|
|
|
|
{
|
|
|
|
AMorphedMonster *fakeme = static_cast<AMorphedMonster *>(actor);
|
|
|
|
AActor *realme = fakeme->UnmorphedMe;
|
|
|
|
if (realme != NULL)
|
|
|
|
{
|
|
|
|
if ((fakeme->UnmorphTime) &&
|
|
|
|
(fakeme->MorphStyle & MORPH_UNDOBYDEATH))
|
|
|
|
{
|
|
|
|
int realstyle = fakeme->MorphStyle;
|
|
|
|
int realhealth = fakeme->health;
|
|
|
|
if (P_UndoMonsterMorph(fakeme, !!(fakeme->MorphStyle & MORPH_UNDOBYDEATHFORCED)))
|
|
|
|
{
|
|
|
|
*morphed = realme;
|
|
|
|
*morphedstyle = realstyle;
|
|
|
|
*morphedhealth = realhealth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (realme->flags4 & MF4_BOSSDEATH)
|
|
|
|
{
|
|
|
|
realme->health = 0; // make sure that A_BossDeath considers it dead.
|
|
|
|
A_BossDeath(realme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fakeme->flags3 |= MF3_STAYMORPHED; // moved here from AMorphedMonster::Die()
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a morphed player or monster
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// EndAllPowerupEffects
|
|
|
|
//
|
|
|
|
// Calls EndEffect() on every Powerup in the inventory list.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void EndAllPowerupEffects(AInventory *item)
|
|
|
|
{
|
2017-01-17 23:11:04 +00:00
|
|
|
auto ptype = PClass::FindActor(NAME_Powerup);
|
2016-03-01 15:47:10 +00:00
|
|
|
while (item != NULL)
|
|
|
|
{
|
2017-01-17 23:11:04 +00:00
|
|
|
if (item->IsKindOf(ptype))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-17 23:11:04 +00:00
|
|
|
IFVIRTUALPTRNAME(item, NAME_Powerup, EndEffect)
|
2017-01-17 00:50:31 +00:00
|
|
|
{
|
|
|
|
VMValue params[1] = { item };
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
2017-01-17 00:50:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
item = item->Inventory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// InitAllPowerupEffects
|
|
|
|
//
|
|
|
|
// Calls InitEffect() on every Powerup in the inventory list.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void InitAllPowerupEffects(AInventory *item)
|
|
|
|
{
|
2017-01-17 23:11:04 +00:00
|
|
|
auto ptype = PClass::FindActor(NAME_Powerup);
|
2016-03-01 15:47:10 +00:00
|
|
|
while (item != NULL)
|
|
|
|
{
|
2017-01-17 23:11:04 +00:00
|
|
|
if (item->IsKindOf(ptype))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-04-10 12:46:30 +00:00
|
|
|
IFVIRTUALPTRNAME(item, NAME_Powerup, InitEffect)
|
2017-01-17 00:50:31 +00:00
|
|
|
{
|
|
|
|
VMValue params[1] = { item };
|
2017-04-12 23:12:04 +00:00
|
|
|
VMCall(func, params, 1, nullptr, 0);
|
2017-01-17 00:50:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
item = item->Inventory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Morphed Monster (you must subclass this to do something useful) ---------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(AMorphedMonster, false, true)
|
2016-11-05 16:08:54 +00:00
|
|
|
|
|
|
|
IMPLEMENT_POINTERS_START(AMorphedMonster)
|
|
|
|
IMPLEMENT_POINTER(UnmorphedMe)
|
|
|
|
IMPLEMENT_POINTERS_END
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-11-23 22:28:03 +00:00
|
|
|
DEFINE_FIELD(AMorphedMonster, UnmorphedMe)
|
|
|
|
DEFINE_FIELD(AMorphedMonster, UnmorphTime)
|
|
|
|
DEFINE_FIELD(AMorphedMonster, MorphStyle)
|
|
|
|
DEFINE_FIELD(AMorphedMonster, MorphExitFlash)
|
|
|
|
|
2016-09-19 13:07:53 +00:00
|
|
|
void AMorphedMonster::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 13:07:53 +00:00
|
|
|
arc("unmorphedme", UnmorphedMe)
|
|
|
|
("unmorphtime", UnmorphTime)
|
|
|
|
("morphstyle", MorphStyle)
|
|
|
|
("morphexitflash", MorphExitFlash)
|
|
|
|
("flagsave", FlagsSave);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 21:49:18 +00:00
|
|
|
void AMorphedMonster::OnDestroy ()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (UnmorphedMe != NULL)
|
|
|
|
{
|
|
|
|
UnmorphedMe->Destroy ();
|
|
|
|
}
|
2017-01-12 21:49:18 +00:00
|
|
|
Super::OnDestroy();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 19:26:05 +00:00
|
|
|
void AMorphedMonster::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOfDeath)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
// Dead things don't unmorph
|
|
|
|
// flags3 |= MF3_STAYMORPHED;
|
|
|
|
// [MH]
|
|
|
|
// But they can now, so that line above has been
|
|
|
|
// moved into P_MorphedDeath() and is now set by
|
|
|
|
// that function if and only if it is needed.
|
2018-04-23 19:26:05 +00:00
|
|
|
Super::Die (source, inflictor, dmgflags, MeansOfDeath);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (UnmorphedMe != NULL && (UnmorphedMe->flags & MF_UNMORPHED))
|
|
|
|
{
|
|
|
|
UnmorphedMe->health = health;
|
2018-04-23 19:26:05 +00:00
|
|
|
UnmorphedMe->CallDie (source, inflictor, dmgflags, MeansOfDeath);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMorphedMonster::Tick ()
|
|
|
|
{
|
|
|
|
if (!P_UpdateMorphedMonster (this))
|
|
|
|
{
|
|
|
|
Super::Tick ();
|
|
|
|
}
|
|
|
|
}
|
2017-02-26 20:20:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION(AActor, A_Morph)
|
|
|
|
{
|
|
|
|
PARAM_SELF_PROLOGUE(AActor);
|
|
|
|
PARAM_CLASS(type, AActor);
|
|
|
|
PARAM_INT_DEF(duration);
|
|
|
|
PARAM_INT_DEF(flags);
|
|
|
|
PARAM_CLASS_DEF(enter_flash, AActor);
|
|
|
|
PARAM_CLASS_DEF(exit_flash, AActor);
|
|
|
|
bool res = false;
|
|
|
|
if (self->player)
|
|
|
|
{
|
2017-04-11 23:29:51 +00:00
|
|
|
if (type->IsDescendantOf(RUNTIME_CLASS(APlayerPawn)))
|
2017-02-26 20:20:47 +00:00
|
|
|
{
|
|
|
|
res = P_MorphPlayer(self->player, self->player, type, duration, flags, enter_flash, exit_flash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-11 23:29:51 +00:00
|
|
|
if (type->IsDescendantOf(RUNTIME_CLASS(AMorphedMonster)))
|
2017-02-26 20:20:47 +00:00
|
|
|
{
|
|
|
|
res = P_MorphMonster(self, type, duration, flags, enter_flash, exit_flash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ACTION_RETURN_BOOL(res);
|
|
|
|
}
|