2006-02-24 04:48:15 +00:00
|
|
|
#include "info.h"
|
|
|
|
#include "a_pickups.h"
|
|
|
|
#include "a_artifacts.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "a_sharedglobal.h"
|
2008-04-05 12:14:33 +00:00
|
|
|
#include "sbar.h"
|
2008-04-08 08:53:42 +00:00
|
|
|
#include "a_morph.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "doomstat.h"
|
|
|
|
#include "g_level.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
#include "farchive.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_morphmonst ("MorphMonster");
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_MorphPlayer
|
|
|
|
//
|
|
|
|
// Returns true if the player gets turned into a chicken/pig.
|
|
|
|
//
|
2009-03-15 01:41:53 +00:00
|
|
|
// TODO: Allow morphed players to receive weapon sets (not just one weapon),
|
|
|
|
// since they have their own weapon slots now.
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-04-12 15:31:18 +00:00
|
|
|
bool P_MorphPlayer (player_t *activator, player_t *p, const PClass *spawntype, int duration, int style, const PClass *enter_flash, const PClass *exit_flash)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AInventory *item;
|
|
|
|
APlayerPawn *morphed;
|
|
|
|
APlayerPawn *actor;
|
|
|
|
|
|
|
|
actor = p->mo;
|
|
|
|
if (actor == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (actor->flags3 & MF3_DONTMORPH)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-12 15:31:18 +00:00
|
|
|
if ((p->mo->flags2 & MF2_INVULNERABLE) && ((p != activator) || (!(style & MORPH_WHENINVULNERABLE))))
|
|
|
|
{ // Immune when invulnerable unless this is a power we activated
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p->morphTics)
|
|
|
|
{ // Player is already a beast
|
2012-07-15 03:10:00 +00:00
|
|
|
if ((p->mo->GetClass() == spawntype)
|
|
|
|
&& (p->mo->PlayerFlags & PPF_CANSUPERMORPH)
|
|
|
|
&& (p->morphTics < (((duration) ? duration : MORPHTICS) - TICRATE))
|
|
|
|
&& (p->mo->FindInventory (RUNTIME_CLASS(APowerWeaponLevel2), true) == NULL))
|
|
|
|
{ // Make a super chicken
|
|
|
|
p->mo->GiveInventoryType (RUNTIME_CLASS(APowerWeaponLevel2));
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p->health <= 0)
|
|
|
|
{ // Dead players cannot morph
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (spawntype == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-10-27 03:03:34 +00:00
|
|
|
if (!spawntype->IsDescendantOf (RUNTIME_CLASS(APlayerPawn)))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-05 12:14:33 +00:00
|
|
|
if (spawntype == p->mo->GetClass())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-07-16 09:10:45 +00:00
|
|
|
morphed = static_cast<APlayerPawn *>(Spawn (spawntype, actor->x, actor->y, actor->z, NO_REPLACE));
|
2008-03-12 16:27:47 +00:00
|
|
|
DObject::StaticPointerSubstitution (actor, morphed);
|
2008-05-22 19:35:38 +00:00
|
|
|
if ((actor->tid != 0) && (style & MORPH_NEWTIDBEHAVIOUR))
|
|
|
|
{
|
|
|
|
morphed->tid = actor->tid;
|
|
|
|
morphed->AddToHash ();
|
|
|
|
actor->RemoveFromHash ();
|
|
|
|
actor->tid = 0;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
morphed->angle = actor->angle;
|
|
|
|
morphed->target = actor->target;
|
|
|
|
morphed->tracer = actor;
|
2012-03-18 01:56:48 +00:00
|
|
|
morphed->Score = actor->Score;
|
2006-02-24 04:48:15 +00:00
|
|
|
p->PremorphWeapon = p->ReadyWeapon;
|
|
|
|
morphed->special2 = actor->flags & ~MF_JUSTHIT;
|
|
|
|
morphed->player = p;
|
|
|
|
if (actor->renderflags & RF_INVISIBLE)
|
|
|
|
{
|
|
|
|
morphed->special2 |= MF_JUSTHIT;
|
|
|
|
}
|
2008-05-21 01:30:00 +00:00
|
|
|
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();
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
morphed->flags |= actor->flags & (MF_SHADOW|MF_NOGRAVITY);
|
|
|
|
morphed->flags2 |= actor->flags2 & MF2_FLY;
|
|
|
|
morphed->flags3 |= actor->flags3 & MF3_GHOST;
|
2008-04-08 08:53:42 +00:00
|
|
|
Spawn(((enter_flash) ? enter_flash : RUNTIME_CLASS(ATeleportFog)), actor->x, actor->y, actor->z + TELEFOGHEIGHT, ALLOW_REPLACE);
|
2006-02-24 04:48:15 +00:00
|
|
|
actor->player = NULL;
|
|
|
|
actor->flags &= ~(MF_SOLID|MF_SHOOTABLE);
|
|
|
|
actor->flags |= MF_UNMORPHED;
|
|
|
|
actor->renderflags |= RF_INVISIBLE;
|
2008-04-08 08:53:42 +00:00
|
|
|
p->morphTics = (duration) ? duration : MORPHTICS;
|
2008-04-05 12:14:33 +00:00
|
|
|
|
|
|
|
// [MH] Used by SBARINFO to speed up face drawing
|
2010-04-17 02:06:26 +00:00
|
|
|
p->MorphedPlayerClass = spawntype;
|
2008-04-08 08:53:42 +00:00
|
|
|
|
|
|
|
p->MorphStyle = style;
|
|
|
|
p->MorphExitFlash = (exit_flash) ? exit_flash : RUNTIME_CLASS(ATeleportFog);
|
2006-02-24 04:48:15 +00:00
|
|
|
p->health = morphed->health;
|
2006-07-13 10:17:56 +00:00
|
|
|
p->mo = morphed;
|
2009-06-30 20:57:51 +00:00
|
|
|
p->velx = p->vely = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
morphed->ObtainInventory (actor);
|
|
|
|
// Remove all armor
|
2006-04-11 16:27:41 +00:00
|
|
|
for (item = morphed->Inventory; item != NULL; )
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AInventory *next = item->Inventory;
|
|
|
|
if (item->IsKindOf (RUNTIME_CLASS(AArmor)))
|
|
|
|
{
|
2007-03-14 01:48:19 +00:00
|
|
|
if (item->IsKindOf (RUNTIME_CLASS(AHexenArmor)))
|
|
|
|
{
|
|
|
|
// Set the HexenArmor slots to 0, except the class slot.
|
|
|
|
AHexenArmor *hxarmor = static_cast<AHexenArmor *>(item);
|
|
|
|
hxarmor->Slots[0] = 0;
|
|
|
|
hxarmor->Slots[1] = 0;
|
|
|
|
hxarmor->Slots[2] = 0;
|
|
|
|
hxarmor->Slots[3] = 0;
|
|
|
|
hxarmor->Slots[4] = spawntype->Meta.GetMetaFixed (APMETA_Hexenarmor0);
|
|
|
|
}
|
|
|
|
else if (item->ItemFlags & IF_KEEPDEPLETED)
|
|
|
|
{
|
|
|
|
// Set depletable armor to 0 (this includes BasicArmor).
|
|
|
|
item->Amount = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->Destroy ();
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
morphed->ActivateMorphWeapon ();
|
|
|
|
if (p->camera == actor)
|
|
|
|
{
|
|
|
|
p->camera = morphed;
|
|
|
|
}
|
2006-07-13 10:17:56 +00:00
|
|
|
morphed->ScoreIcon = actor->ScoreIcon; // [GRB]
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_UndoPlayerMorph
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2009-09-18 05:46:15 +00:00
|
|
|
bool P_UndoPlayerMorph (player_t *activator, player_t *player, int unmorphflag, bool force)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AWeapon *beastweap;
|
|
|
|
APlayerPawn *mo;
|
2009-11-28 07:46:30 +00:00
|
|
|
APlayerPawn *pmo;
|
2006-02-24 04:48:15 +00:00
|
|
|
angle_t angle;
|
|
|
|
|
|
|
|
pmo = player->mo;
|
2008-04-14 18:51:05 +00:00
|
|
|
// [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.
|
|
|
|
if (pmo == NULL || pmo->tracer == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-22 19:35:38 +00:00
|
|
|
|
2009-12-28 22:41:14 +00:00
|
|
|
bool DeliberateUnmorphIsOkay = !!(MORPH_STANDARDUNDOING & unmorphflag);
|
2009-09-18 05:46:15 +00:00
|
|
|
|
|
|
|
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),
|
2009-09-17 20:58:43 +00:00
|
|
|
{ // Then the player is immune to the unmorph.
|
2008-05-22 19:35:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-12 02:56:11 +00:00
|
|
|
mo = barrier_cast<APlayerPawn *>(pmo->tracer);
|
2006-02-24 04:48:15 +00:00
|
|
|
mo->SetOrigin (pmo->x, pmo->y, pmo->z);
|
|
|
|
mo->flags |= MF_SOLID;
|
|
|
|
pmo->flags &= ~MF_SOLID;
|
2008-05-22 19:35:38 +00:00
|
|
|
if (!force && !P_TestMobjLocation (mo))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // Didn't fit
|
|
|
|
mo->flags &= ~MF_SOLID;
|
|
|
|
pmo->flags |= MF_SOLID;
|
|
|
|
player->morphTics = 2*TICRATE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pmo->player = NULL;
|
|
|
|
|
2006-06-27 23:49:45 +00:00
|
|
|
mo->ObtainInventory (pmo);
|
2008-03-12 16:27:47 +00:00
|
|
|
DObject::StaticPointerSubstitution (pmo, mo);
|
2008-10-14 01:24:27 +00:00
|
|
|
// Remove the morph power if the morph is being undone prematurely.
|
|
|
|
for (AInventory *item = mo->Inventory, *next = NULL; item != NULL; item = next)
|
|
|
|
{
|
|
|
|
next = item->Inventory;
|
|
|
|
if (item->IsKindOf(RUNTIME_CLASS(APowerMorph)))
|
|
|
|
{
|
2012-05-01 03:43:14 +00:00
|
|
|
static_cast<APowerMorph *>(item)->SetNoCallUndoMorph();
|
2008-10-14 01:24:27 +00:00
|
|
|
item->Destroy();
|
|
|
|
}
|
|
|
|
}
|
2008-05-22 19:35:38 +00:00
|
|
|
if ((pmo->tid != 0) && (player->MorphStyle & MORPH_NEWTIDBEHAVIOUR))
|
|
|
|
{
|
|
|
|
mo->tid = pmo->tid;
|
|
|
|
mo->AddToHash ();
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
mo->angle = pmo->angle;
|
|
|
|
mo->player = player;
|
|
|
|
mo->reactiontime = 18;
|
|
|
|
mo->flags = pmo->special2 & ~MF_JUSTHIT;
|
2009-06-30 20:57:51 +00:00
|
|
|
mo->velx = 0;
|
|
|
|
mo->vely = 0;
|
|
|
|
player->velx = 0;
|
|
|
|
player->vely = 0;
|
|
|
|
mo->velz = pmo->velz;
|
2006-02-24 04:48:15 +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);
|
2012-03-18 01:56:48 +00:00
|
|
|
mo->Score = pmo->Score;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-08 08:53:42 +00:00
|
|
|
const PClass *exit_flash = player->MorphExitFlash;
|
2008-04-15 23:03:28 +00:00
|
|
|
bool correctweapon = !!(player->MorphStyle & MORPH_LOSEACTUALWEAPON);
|
2008-05-22 19:35:38 +00:00
|
|
|
bool undobydeathsaves = !!(player->MorphStyle & MORPH_UNDOBYDEATHSAVES);
|
2008-04-08 08:53:42 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
player->morphTics = 0;
|
2008-04-06 17:33:43 +00:00
|
|
|
player->MorphedPlayerClass = 0;
|
2008-04-08 08:53:42 +00:00
|
|
|
player->MorphStyle = 0;
|
|
|
|
player->MorphExitFlash = NULL;
|
2006-07-13 10:17:56 +00:00
|
|
|
player->viewheight = mo->ViewHeight;
|
2011-11-07 00:43:41 +00:00
|
|
|
AInventory *level2 = mo->FindInventory (RUNTIME_CLASS(APowerWeaponLevel2), true);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (level2 != NULL)
|
|
|
|
{
|
|
|
|
level2->Destroy ();
|
|
|
|
}
|
2008-05-22 19:35:38 +00:00
|
|
|
|
|
|
|
if ((player->health > 0) || undobydeathsaves)
|
|
|
|
{
|
2009-07-24 20:25:19 +00:00
|
|
|
player->health = mo->health = mo->SpawnHealth();
|
2008-05-22 19:35:38 +00:00
|
|
|
}
|
|
|
|
else // killed when morphed so stay dead
|
|
|
|
{
|
|
|
|
mo->health = player->health;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
player->mo = mo;
|
|
|
|
if (player->camera == pmo)
|
|
|
|
{
|
|
|
|
player->camera = mo;
|
|
|
|
}
|
2008-04-05 12:14:33 +00:00
|
|
|
|
|
|
|
// [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.
|
2012-03-18 01:56:48 +00:00
|
|
|
if (player == &players[consoleplayer])
|
2008-04-05 12:14:33 +00:00
|
|
|
{
|
2008-08-05 16:04:37 +00:00
|
|
|
const char *face = pmo->GetClass()->Meta.GetMetaString (APMETA_Face);
|
|
|
|
if (face != NULL && strcmp(face, "None") != 0)
|
2008-04-05 12:14:33 +00:00
|
|
|
{
|
2008-08-05 16:04:37 +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.skin >= PlayerClasses.Size () &&
|
|
|
|
(size_t)player->userinfo.skin < numskins)
|
|
|
|
{
|
2011-11-07 00:43:41 +00:00
|
|
|
|
2008-08-05 16:04:37 +00:00
|
|
|
skinindex = player->userinfo.skin;
|
|
|
|
}
|
|
|
|
else if (PlayerClasses.Size () > 1)
|
2008-04-05 12:14:33 +00:00
|
|
|
{
|
2008-08-05 16:04:37 +00:00
|
|
|
const PClass *whatami = player->mo->GetClass();
|
|
|
|
for (unsigned int i = 0; i < PlayerClasses.Size (); ++i)
|
2008-04-05 12:14:33 +00:00
|
|
|
{
|
2008-08-05 16:04:37 +00:00
|
|
|
if (PlayerClasses[i].Type == whatami)
|
|
|
|
{
|
|
|
|
skinindex = i;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-05 12:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
angle = mo->angle >> ANGLETOFINESHIFT;
|
2009-10-09 20:18:31 +00:00
|
|
|
if (exit_flash != NULL)
|
|
|
|
{
|
|
|
|
Spawn(exit_flash, pmo->x + 20*finecosine[angle], pmo->y + 20*finesine[angle], pmo->z + TELEFOGHEIGHT, ALLOW_REPLACE);
|
|
|
|
}
|
2009-03-13 03:18:06 +00:00
|
|
|
mo->SetupWeaponSlots(); // Use original class's weapon slots.
|
2006-02-24 04:48:15 +00:00
|
|
|
beastweap = player->ReadyWeapon;
|
|
|
|
if (player->PremorphWeapon != NULL)
|
|
|
|
{
|
|
|
|
player->PremorphWeapon->PostMorphWeapon ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->ReadyWeapon = player->PendingWeapon = NULL;
|
|
|
|
}
|
2008-04-15 22:17:30 +00:00
|
|
|
if (correctweapon)
|
|
|
|
{ // Better "lose morphed weapon" semantics
|
2009-11-28 07:46:30 +00:00
|
|
|
const PClass *morphweapon = PClass::FindClass (pmo->MorphWeapon);
|
2008-04-15 22:17:30 +00:00
|
|
|
if (morphweapon != NULL && morphweapon->IsDescendantOf (RUNTIME_CLASS(AWeapon)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-15 22:17:30 +00:00
|
|
|
AWeapon *OriginalMorphWeapon = static_cast<AWeapon *>(mo->FindInventory (morphweapon));
|
|
|
|
if ((OriginalMorphWeapon != NULL) && (OriginalMorphWeapon->GivenAsMorphWeapon))
|
|
|
|
{ // You don't get to keep your morphed weapon.
|
|
|
|
if (OriginalMorphWeapon->SisterWeapon != NULL)
|
|
|
|
{
|
|
|
|
OriginalMorphWeapon->SisterWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
OriginalMorphWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // old behaviour (not really useful now)
|
|
|
|
{ // Assumptions made here are no longer valid
|
|
|
|
if (beastweap != NULL)
|
|
|
|
{ // You don't get to keep your morphed weapon.
|
|
|
|
if (beastweap->SisterWeapon != NULL)
|
|
|
|
{
|
|
|
|
beastweap->SisterWeapon->Destroy ();
|
|
|
|
}
|
|
|
|
beastweap->Destroy ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pmo->tracer = NULL;
|
|
|
|
pmo->Destroy ();
|
2007-03-14 01:48:19 +00:00
|
|
|
// Restore playerclass armor to its normal amount.
|
|
|
|
AHexenArmor *hxarmor = mo->FindInventory<AHexenArmor>();
|
|
|
|
if (hxarmor != NULL)
|
|
|
|
{
|
|
|
|
hxarmor->Slots[4] = mo->GetClass()->Meta.GetMetaFixed (APMETA_Hexenarmor0);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FUNC P_MorphMonster
|
|
|
|
//
|
|
|
|
// Returns true if the monster gets turned into a chicken/pig.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-04-08 08:53:42 +00:00
|
|
|
bool P_MorphMonster (AActor *actor, const PClass *spawntype, int duration, int style, const PClass *enter_flash, const PClass *exit_flash)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-08-17 00:19:26 +00:00
|
|
|
AMorphedMonster *morphed;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-08-17 00:19:26 +00:00
|
|
|
if (actor->player || spawntype == NULL ||
|
2006-02-24 04:48:15 +00:00
|
|
|
actor->flags3 & MF3_DONTMORPH ||
|
2006-08-17 00:19:26 +00:00
|
|
|
!(actor->flags3 & MF3_ISMONSTER) ||
|
|
|
|
!spawntype->IsDescendantOf (RUNTIME_CLASS(AMorphedMonster)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-17 00:19:26 +00:00
|
|
|
morphed = static_cast<AMorphedMonster *>(Spawn (spawntype, actor->x, actor->y, actor->z, NO_REPLACE));
|
2008-03-12 16:27:47 +00:00
|
|
|
DObject::StaticPointerSubstitution (actor, morphed);
|
2006-02-24 04:48:15 +00:00
|
|
|
morphed->tid = actor->tid;
|
|
|
|
morphed->angle = actor->angle;
|
2006-08-17 00:19:26 +00:00
|
|
|
morphed->UnmorphedMe = actor;
|
2006-04-11 16:27:41 +00:00
|
|
|
morphed->alpha = actor->alpha;
|
|
|
|
morphed->RenderStyle = actor->RenderStyle;
|
2012-03-18 01:56:48 +00:00
|
|
|
morphed->Score = actor->Score;
|
2006-04-11 16:27:41 +00:00
|
|
|
|
2008-04-08 08:53:42 +00:00
|
|
|
morphed->UnmorphTime = level.time + ((duration) ? duration : MORPHTICS) + pr_morphmonst();
|
|
|
|
morphed->MorphStyle = style;
|
|
|
|
morphed->MorphExitFlash = (exit_flash) ? exit_flash : RUNTIME_CLASS(ATeleportFog);
|
2006-08-17 00:19:26 +00:00
|
|
|
morphed->FlagsSave = actor->flags & ~MF_JUSTHIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
//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)
|
|
|
|
{
|
2006-08-17 00:19:26 +00:00
|
|
|
morphed->FlagsSave |= MF_JUSTHIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
morphed->AddToHash ();
|
|
|
|
actor->RemoveFromHash ();
|
|
|
|
actor->tid = 0;
|
|
|
|
actor->flags &= ~(MF_SOLID|MF_SHOOTABLE);
|
|
|
|
actor->flags |= MF_UNMORPHED;
|
|
|
|
actor->renderflags |= RF_INVISIBLE;
|
2008-04-08 08:53:42 +00:00
|
|
|
Spawn(((enter_flash) ? enter_flash : RUNTIME_CLASS(ATeleportFog)), actor->x, actor->y, actor->z + TELEFOGHEIGHT, ALLOW_REPLACE);
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
2008-05-22 19:35:38 +00:00
|
|
|
// FUNC P_UndoMonsterMorph
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
|
|
|
// Returns true if the monster unmorphs.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2008-05-22 19:35:38 +00:00
|
|
|
bool P_UndoMonsterMorph (AMorphedMonster *beast, bool force)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AActor *actor;
|
|
|
|
|
2008-05-22 19:35:38 +00:00
|
|
|
if (beast->UnmorphTime == 0 ||
|
2006-08-17 00:19:26 +00:00
|
|
|
beast->UnmorphedMe == NULL ||
|
2006-02-24 04:48:15 +00:00
|
|
|
beast->flags3 & MF3_STAYMORPHED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-17 00:19:26 +00:00
|
|
|
actor = beast->UnmorphedMe;
|
2006-02-24 04:48:15 +00:00
|
|
|
actor->SetOrigin (beast->x, beast->y, beast->z);
|
|
|
|
actor->flags |= MF_SOLID;
|
|
|
|
beast->flags &= ~MF_SOLID;
|
2008-05-22 19:35:38 +00:00
|
|
|
if (!force && !P_TestMobjLocation (actor))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // Didn't fit
|
|
|
|
actor->flags &= ~MF_SOLID;
|
|
|
|
beast->flags |= MF_SOLID;
|
2006-08-17 00:19:26 +00:00
|
|
|
beast->UnmorphTime = level.time + 5*TICRATE; // Next try in 5 seconds
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
actor->angle = beast->angle;
|
|
|
|
actor->target = beast->target;
|
|
|
|
actor->FriendPlayer = beast->FriendPlayer;
|
2006-08-17 00:19:26 +00:00
|
|
|
actor->flags = beast->FlagsSave & ~MF_JUSTHIT;
|
2006-02-24 04:48:15 +00:00
|
|
|
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);
|
2006-08-17 00:19:26 +00:00
|
|
|
if (!(beast->FlagsSave & MF_JUSTHIT))
|
2006-02-24 04:48:15 +00:00
|
|
|
actor->renderflags &= ~RF_INVISIBLE;
|
2009-07-04 18:17:44 +00:00
|
|
|
actor->health = actor->SpawnHealth();
|
2009-06-30 20:57:51 +00:00
|
|
|
actor->velx = beast->velx;
|
|
|
|
actor->vely = beast->vely;
|
|
|
|
actor->velz = beast->velz;
|
2006-02-24 04:48:15 +00:00
|
|
|
actor->tid = beast->tid;
|
|
|
|
actor->special = beast->special;
|
2012-03-18 01:56:48 +00:00
|
|
|
actor->Score = beast->Score;
|
2006-02-24 04:48:15 +00:00
|
|
|
memcpy (actor->args, beast->args, sizeof(actor->args));
|
|
|
|
actor->AddToHash ();
|
2006-08-17 00:19:26 +00:00
|
|
|
beast->UnmorphedMe = NULL;
|
2008-03-12 16:27:47 +00:00
|
|
|
DObject::StaticPointerSubstitution (beast, actor);
|
2008-04-08 08:53:42 +00:00
|
|
|
const PClass *exit_flash = beast->MorphExitFlash;
|
2006-02-24 04:48:15 +00:00
|
|
|
beast->Destroy ();
|
2008-04-08 08:53:42 +00:00
|
|
|
Spawn(exit_flash, beast->x, beast->y, beast->z + TELEFOGHEIGHT, ALLOW_REPLACE);
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-22 19:35:38 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// 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
|
2008-06-01 07:52:33 +00:00
|
|
|
// health (of the AActor, not the player_t) they last had before unmorphing.
|
2008-05-22 19:35:38 +00:00
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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) &&
|
|
|
|
(actor->player->mo->tracer))
|
|
|
|
{
|
|
|
|
AActor *realme = actor->player->mo->tracer;
|
|
|
|
int realstyle = actor->player->MorphStyle;
|
|
|
|
int realhealth = actor->health;
|
|
|
|
if (P_UndoPlayerMorph(actor->player, actor->player, !!(actor->player->MorphStyle & MORPH_UNDOBYDEATHFORCED)))
|
|
|
|
{
|
|
|
|
*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);
|
|
|
|
if ((fakeme->UnmorphTime) &&
|
|
|
|
(fakeme->MorphStyle & MORPH_UNDOBYDEATH) &&
|
|
|
|
(fakeme->UnmorphedMe))
|
|
|
|
{
|
|
|
|
AActor *realme = fakeme->UnmorphedMe;
|
|
|
|
int realstyle = fakeme->MorphStyle;
|
|
|
|
int realhealth = fakeme->health;
|
|
|
|
if (P_UndoMonsterMorph(fakeme, !!(fakeme->MorphStyle & MORPH_UNDOBYDEATHFORCED)))
|
|
|
|
{
|
|
|
|
*morphed = realme;
|
|
|
|
*morphedstyle = realstyle;
|
|
|
|
*morphedhealth = realhealth;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fakeme->flags3 |= MF3_STAYMORPHED; // moved here from AMorphedMonster::Die()
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not a morphed player or monster
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-17 09:54:42 +00:00
|
|
|
// Base class for morphing projectiles --------------------------------------
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-09 11:35:42 +00:00
|
|
|
IMPLEMENT_CLASS(AMorphProjectile)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2012-06-29 04:21:31 +00:00
|
|
|
int AMorphProjectile::DoSpecialDamage (AActor *target, int damage, FName damagetype)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-08 08:53:42 +00:00
|
|
|
const PClass *morph_flash = PClass::FindClass (MorphFlash);
|
|
|
|
const PClass *unmorph_flash = PClass::FindClass (UnMorphFlash);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (target->player)
|
|
|
|
{
|
2008-04-08 08:53:42 +00:00
|
|
|
const PClass *player_class = PClass::FindClass (PlayerClass);
|
2008-04-12 15:31:18 +00:00
|
|
|
P_MorphPlayer (NULL, target->player, player_class, Duration, MorphStyle, morph_flash, unmorph_flash);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-08 08:53:42 +00:00
|
|
|
const PClass *monster_class = PClass::FindClass (MonsterClass);
|
|
|
|
P_MorphMonster (target, monster_class, Duration, MorphStyle, morph_flash, unmorph_flash);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-08-17 09:54:42 +00:00
|
|
|
void AMorphProjectile::Serialize (FArchive &arc)
|
2006-08-17 00:19:26 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2008-04-08 08:53:42 +00:00
|
|
|
arc << PlayerClass << MonsterClass << Duration << MorphStyle << MorphFlash << UnMorphFlash;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-17 00:19:26 +00:00
|
|
|
// Morphed Monster (you must subclass this to do something useful) ---------
|
|
|
|
|
|
|
|
IMPLEMENT_POINTY_CLASS (AMorphedMonster)
|
|
|
|
DECLARE_POINTER (UnmorphedMe)
|
|
|
|
END_POINTERS
|
|
|
|
|
|
|
|
void AMorphedMonster::Serialize (FArchive &arc)
|
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2008-04-08 08:53:42 +00:00
|
|
|
arc << UnmorphedMe << UnmorphTime << MorphStyle << MorphExitFlash << FlagsSave;
|
2006-08-17 00:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMorphedMonster::Destroy ()
|
|
|
|
{
|
|
|
|
if (UnmorphedMe != NULL)
|
|
|
|
{
|
|
|
|
UnmorphedMe->Destroy ();
|
|
|
|
}
|
|
|
|
Super::Destroy ();
|
|
|
|
}
|
|
|
|
|
2012-05-13 07:54:44 +00:00
|
|
|
void AMorphedMonster::Die (AActor *source, AActor *inflictor, int dmgflags)
|
2006-08-17 00:19:26 +00:00
|
|
|
{
|
|
|
|
// Dead things don't unmorph
|
2008-05-22 19:35:38 +00:00
|
|
|
// 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.
|
2012-05-13 07:54:44 +00:00
|
|
|
Super::Die (source, inflictor, dmgflags);
|
2006-08-17 00:19:26 +00:00
|
|
|
if (UnmorphedMe != NULL && (UnmorphedMe->flags & MF_UNMORPHED))
|
|
|
|
{
|
|
|
|
UnmorphedMe->health = health;
|
2012-05-13 07:54:44 +00:00
|
|
|
UnmorphedMe->Die (source, inflictor, dmgflags);
|
2006-08-17 00:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMorphedMonster::Tick ()
|
|
|
|
{
|
|
|
|
if (!P_UpdateMorphedMonster (this))
|
|
|
|
{
|
|
|
|
Super::Tick ();
|
|
|
|
}
|
|
|
|
}
|