raze/source/games/exhumed/src/anims.cpp

339 lines
8.9 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 sirlemonhead, Nuke.YKT
This file is part of PCExhumed.
PCExhumed is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "engine.h"
#include "aistuff.h"
#include "sequence.h"
#include "exhumed.h"
#include "sound.h"
#include <assert.h>
BEGIN_PS_NS
int nMagicSeq = -1;
int nPreMagicSeq = -1;
int nSavePointSeq = -1;
2020-11-29 23:47:53 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-11-29 23:47:53 +00:00
void SerializeAnim(FSerializer& arc)
{
if (arc.BeginObject("anims"))
{
arc("magic", nMagicSeq)
("premagic", nPreMagicSeq)
("savepoint", nSavePointSeq)
.EndObject();
}
}
2020-11-29 23:47:53 +00:00
void InitAnims()
{
nMagicSeq = SeqOffsets[kSeqItems] + 21;
nPreMagicSeq = SeqOffsets[kSeqMagic2];
nSavePointSeq = SeqOffsets[kSeqItems] + 12;
}
/*
Use when deleting an ignited actor to check if any actors reference it.
Will remove the actor's anim loop flag and set the source (the ignited actor's) actor target to null.
FuncAnim() will then delete the actor on next call for this actor.
Without this, the actor will hold reference to an actor which will prevent the GC from deleting it properly.
Specifically needed for IgniteSprite() anims which can become orphaned from the source sprite (e.g a bullet)
when the bullet sprite is deleted.
*/
void UnlinkIgnitedAnim(DExhumedActor* pActor)
{
ExhumedStatIterator it(kStatIgnited);
while (auto itActor = it.Next())
{
// .pTarget holds the actor pointer of the source 'actor that's on fire' actor
if (pActor == itActor->pTarget)
{
itActor->nAction &= ~kAnimLoop; // clear the animation loop flag
itActor->pTarget = nullptr; // set the actor target to null
}
}
}
2021-10-24 18:21:27 +00:00
void DestroyAnim(DExhumedActor* pActor)
{
2021-10-24 18:21:27 +00:00
if (pActor)
{
2021-10-24 18:21:27 +00:00
StopActorSound(pActor);
runlist_SubRunRec(pActor->nRun);
2021-12-23 16:02:05 +00:00
runlist_DoSubRunRec(pActor->spr.extra);
runlist_FreeRun(pActor->spr.lotag - 1);
2021-10-24 18:21:27 +00:00
DeleteActor(pActor);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
DExhumedActor* BuildAnim(DExhumedActor* pActor, int nSeq, int nOffset, const DVector3& pos, sectortype* pSector, double nScale, int nFlag)
{
if (pActor == nullptr)
2021-11-22 22:35:11 +00:00
pActor = insertActor(pSector, 500);
if (nFlag & 4)
{
2021-12-23 16:02:05 +00:00
pActor->spr.pal = 4;
pActor->spr.shade = -64;
}
else
{
2021-12-23 16:02:05 +00:00
pActor->spr.pal = 0;
pActor->spr.shade = -12;
}
// CHECKME - where is hitag set otherwise?
if (pActor->spr.statnum < 900)
pActor->spr.hitag = -1;
if (nFlag & 0x80)
pActor->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT; // set transluscence
pActor->spr.pos = pos;
pActor->spr.cstat = 0;
pActor->clipdist = 2.5;
pActor->spr.scale = DVector2(nScale, nScale);
2021-12-23 16:02:05 +00:00
pActor->spr.picnum = 1;
pActor->spr.Angles.Yaw = nullAngle;
2021-12-23 16:02:05 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
pActor->vel.Z = 0;
2021-12-23 16:02:05 +00:00
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.intowner = -1;
2021-12-23 16:02:05 +00:00
pActor->spr.extra = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x100000);
2021-10-24 18:21:27 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x100000);
pActor->nAction = nFlag;
pActor->nIndex = 0;
pActor->nIndex2 = SeqOffsets[nSeq] + nOffset;
2021-10-24 18:21:27 +00:00
pActor->pTarget = nullptr;
pActor->nDamage = pActor->nRun;
pActor->nPhase = ITEM_MAGIC;
pActor->backuppos();
2021-10-24 18:21:27 +00:00
return pActor;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-10-15 19:06:53 +00:00
void AIAnim::Tick(RunListEvent* ev)
{
2021-10-24 18:21:27 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nIndex2 = pActor->nIndex2;
int nIndex = pActor->nIndex;
2021-10-15 19:06:53 +00:00
2021-12-23 16:02:05 +00:00
if (!(pActor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
{
2021-10-24 18:21:27 +00:00
seq_MoveSequence(pActor, nIndex2, nIndex);
2021-10-15 19:06:53 +00:00
}
2021-12-23 16:02:05 +00:00
if (pActor->spr.statnum == kStatIgnited)
2021-10-15 19:06:53 +00:00
{
2021-12-07 17:53:02 +00:00
DExhumedActor* pIgniter = pActor->pTarget;
2021-10-24 18:21:27 +00:00
if (pIgniter)
{
2022-08-16 21:46:18 +00:00
pActor->spr.pos = pIgniter->spr.pos;
if (pIgniter->sector() != pActor->sector())
{
if (!pIgniter->sector())
2021-10-15 19:06:53 +00:00
{
2021-10-24 18:21:27 +00:00
DestroyAnim(pActor);
2021-10-15 19:06:53 +00:00
return;
}
else
{
ChangeActorSect(pActor, pIgniter->sector());
2021-10-15 19:06:53 +00:00
}
}
2021-10-24 18:21:27 +00:00
if (!nIndex)
{
2021-12-23 16:26:44 +00:00
if (pIgniter->spr.cstat != CSTAT_SPRITE_INVISIBLE)
{
2021-12-23 16:26:44 +00:00
int hitag2 = pIgniter->spr.hitag;
pIgniter->spr.hitag--;
2021-10-15 19:06:53 +00:00
if (hitag2 >= 15)
{
2021-12-23 16:26:44 +00:00
runlist_DamageEnemy(pIgniter, nullptr, (pIgniter->spr.hitag - 14) * 2);
2021-12-23 16:26:44 +00:00
if (pIgniter->spr.shade < 100)
{
2021-12-23 16:26:44 +00:00
pIgniter->spr.pal = 0;
pIgniter->spr.shade++;
}
2021-10-15 19:06:53 +00:00
2021-12-23 16:26:44 +00:00
if (!(pIgniter->spr.cstat & CSTAT_SPRITE_BLOCK_ALL)) // was 101 (decimal), GDX had 0x101 which appears to be correct.
2019-11-30 16:04:59 +00:00
{
2021-10-24 18:21:27 +00:00
DestroyAnim(pActor);
2021-10-15 19:06:53 +00:00
return;
2019-11-30 16:04:59 +00:00
}
}
2021-10-15 19:06:53 +00:00
else
{
2021-12-23 16:26:44 +00:00
pIgniter->spr.hitag = 1;
2021-10-24 18:21:27 +00:00
DestroyAnim(pActor);
2021-10-15 19:06:53 +00:00
}
}
else
{
2021-12-23 16:26:44 +00:00
pIgniter->spr.hitag = 1;
2021-10-24 18:21:27 +00:00
DestroyAnim(pActor);
}
}
}
2021-10-15 19:06:53 +00:00
}
pActor->nIndex++;
2021-10-24 18:21:27 +00:00
if (pActor->nIndex >= SeqSize[nIndex2])
2021-10-15 19:06:53 +00:00
{
if (pActor->nAction & 0x10)
{
pActor->nIndex = 0;
}
2021-10-24 18:21:27 +00:00
else if (nIndex2 == nPreMagicSeq)
{
pActor->nIndex = 0;
pActor->nIndex2 = nMagicSeq;
pActor->nAction |= 0x10;
2021-12-23 16:02:05 +00:00
pActor->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT;
}
2021-10-24 18:21:27 +00:00
else if (nIndex2 == nSavePointSeq)
2021-10-15 19:06:53 +00:00
{
pActor->nIndex = 0;
pActor->nIndex2++;
pActor->nAction |= 0x10;
2021-10-15 19:06:53 +00:00
}
else
{
2021-10-24 18:21:27 +00:00
DestroyAnim(pActor);
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-10-15 19:06:53 +00:00
void AIAnim::Draw(RunListEvent* ev)
{
2021-10-24 18:21:27 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nIndex2 = pActor->nIndex2;
2021-10-15 19:06:53 +00:00
2021-10-24 18:21:27 +00:00
seq_PlotSequence(ev->nParam, nIndex2, pActor->nIndex, 0x101);
ev->pTSprite->ownerActor = nullptr;
2021-10-15 19:06:53 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-10-24 17:18:11 +00:00
void BuildExplosion(DExhumedActor* pActor)
{
auto pSector = pActor->sector();
int edx = 36;
2021-11-22 22:16:21 +00:00
if (pSector->Flag & kSectUnderwater)
{
edx = 75;
}
2022-08-20 15:17:50 +00:00
else if (pActor->spr.pos.Z == pActor->sector()->floorz)
{
edx = 34;
}
BuildAnim(nullptr, edx, 0, pActor->spr.pos, pActor->sector(), pActor->spr.scale.X, 4);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void BuildSplash(DExhumedActor* pActor, sectortype* pSector)
{
2022-10-07 17:40:27 +00:00
int nSound;
double nScale;
2021-12-23 16:02:05 +00:00
if (pActor->spr.statnum != 200)
{
double rep = pActor->spr.scale.X;
2022-10-07 17:40:27 +00:00
nScale = rep + RandomFloat(rep);
nSound = kSound0;
}
else
{
2022-10-07 17:40:27 +00:00
nScale = 0.3125;
nSound = kSound1;
}
2021-11-22 21:38:27 +00:00
int bIsLava = pSector->Flag & kSectLava;
int edx, nFlag;
if (bIsLava)
{
edx = 43;
nFlag = 4;
}
else
{
edx = 35;
nFlag = 0;
}
2022-10-07 17:40:27 +00:00
auto pSpawned = BuildAnim(nullptr, edx, 0, DVector3(pActor->spr.pos.XY(), pSector->floorz), pSector, nScale, nFlag);
if (!bIsLava)
{
2021-12-23 16:02:05 +00:00
D3PlayFX(StaticSound[nSound] | 0xa00, pSpawned);
}
}
END_PS_NS