2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "engine.h"
|
2020-08-18 07:52:08 +00:00
|
|
|
#include "aistuff.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "sequence.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2021-11-21 19:13:19 +00:00
|
|
|
int nMagicSeq = -1;
|
|
|
|
int nPreMagicSeq = -1;
|
|
|
|
int nSavePointSeq = -1;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-29 23:47:53 +00:00
|
|
|
|
2022-09-11 06:09:26 +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();
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-29 23:47:53 +00:00
|
|
|
void InitAnims()
|
|
|
|
{
|
2023-04-06 09:19:23 +00:00
|
|
|
nMagicSeq = getSeqFromId(kSeqItems, 21);
|
|
|
|
nPreMagicSeq = getSeqFromId(kSeqMagic2);
|
|
|
|
nSavePointSeq = getSeqFromId(kSeqItems, 12);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 20:28:41 +00:00
|
|
|
/*
|
2023-03-15 11:52:14 +00:00
|
|
|
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.
|
2022-05-19 20:28:41 +00:00
|
|
|
|
2023-03-15 11:52:14 +00:00
|
|
|
Without this, the actor will hold reference to an actor which will prevent the GC from deleting it properly.
|
2022-05-19 20:28:41 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
Specifically needed for IgniteSprite() anims which can become orphaned from the source actor (e.g a bullet)
|
|
|
|
when the bullet actor is deleted.
|
2022-05-19 20:28:41 +00:00
|
|
|
*/
|
|
|
|
void UnlinkIgnitedAnim(DExhumedActor* pActor)
|
|
|
|
{
|
2023-03-15 11:52:14 +00:00
|
|
|
ExhumedStatIterator it(kStatIgnited);
|
2022-05-19 20:28:41 +00:00
|
|
|
while (auto itActor = it.Next())
|
|
|
|
{
|
2023-03-15 11:52:14 +00:00
|
|
|
if (pActor == itActor->pTarget)
|
2022-05-19 20:28:41 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
itActor->nAction &= ~kAnimLoop;
|
|
|
|
itActor->pTarget = nullptr;
|
2022-05-19 20:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-24 18:21:27 +00:00
|
|
|
void DestroyAnim(DExhumedActor* pActor)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-24 18:21:27 +00:00
|
|
|
if (pActor)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-24 18:21:27 +00:00
|
|
|
StopActorSound(pActor);
|
2021-10-24 18:13:17 +00:00
|
|
|
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);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 06:09:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-28 05:21:03 +00:00
|
|
|
DExhumedActor* BuildAnim(DExhumedActor* pActor, int nSeq, int nOffset, const DVector3& pos, sectortype* pSector, double nScale, int nFlag)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2023-03-28 05:21:03 +00:00
|
|
|
if (pActor == nullptr)
|
2021-11-22 22:35:11 +00:00
|
|
|
pActor = insertActor(pSector, 500);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (nFlag & 4)
|
|
|
|
{
|
2021-12-23 16:02:05 +00:00
|
|
|
pActor->spr.pal = 4;
|
|
|
|
pActor->spr.shade = -64;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-23 16:02:05 +00:00
|
|
|
pActor->spr.pal = 0;
|
|
|
|
pActor->spr.shade = -12;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 05:21:03 +00:00
|
|
|
// 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;
|
2022-10-04 17:13:26 +00:00
|
|
|
pActor->clipdist = 2.5;
|
2022-10-07 21:52:29 +00:00
|
|
|
pActor->spr.scale = DVector2(nScale, nScale);
|
2021-12-23 16:02:05 +00:00
|
|
|
pActor->spr.picnum = 1;
|
2022-11-25 12:13:50 +00:00
|
|
|
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;
|
2022-05-23 22:30:41 +00:00
|
|
|
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);
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nAction = nFlag;
|
|
|
|
pActor->nIndex = 0;
|
2023-04-06 09:19:23 +00:00
|
|
|
pActor->nIndex2 = getSeqFromId(nSeq, nOffset);
|
2021-10-24 18:21:27 +00:00
|
|
|
pActor->pTarget = nullptr;
|
2021-11-08 00:13:54 +00:00
|
|
|
pActor->nDamage = pActor->nRun;
|
|
|
|
pActor->nPhase = ITEM_MAGIC;
|
2023-03-28 05:21:03 +00:00
|
|
|
pActor->backuppos();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-24 18:21:27 +00:00
|
|
|
return pActor;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 06:09:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
void AIAnim::Tick(RunListEvent* ev)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
const auto pActor = ev->pObjActor;
|
2021-10-24 18:21:27 +00:00
|
|
|
if (!pActor) return;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
const int nSeq = pActor->nIndex2;
|
|
|
|
const int nFrame = 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))
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
seq_MoveSequence(pActor, nSeq, nFrame);
|
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)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2022-08-16 21:46:18 +00:00
|
|
|
pActor->spr.pos = pIgniter->spr.pos;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-12-30 15:51:56 +00:00
|
|
|
if (pIgniter->sector() != pActor->sector())
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-12-30 15:51:56 +00:00
|
|
|
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
|
|
|
|
{
|
2021-12-30 15:51:56 +00:00
|
|
|
ChangeActorSect(pActor, pIgniter->sector());
|
2021-10-15 19:06:53 +00:00
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
if (!nFrame)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-12-23 16:26:44 +00:00
|
|
|
if (pIgniter->spr.cstat != CSTAT_SPRITE_INVISIBLE)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-12-23 16:26:44 +00:00
|
|
|
int hitag2 = pIgniter->spr.hitag;
|
|
|
|
pIgniter->spr.hitag--;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
if (hitag2 >= 15)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-12-23 16:26:44 +00:00
|
|
|
runlist_DamageEnemy(pIgniter, nullptr, (pIgniter->spr.hitag - 14) * 2);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-12-23 16:26:44 +00:00
|
|
|
if (pIgniter->spr.shade < 100)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-12-23 16:26:44 +00:00
|
|
|
pIgniter->spr.pal = 0;
|
|
|
|
pIgniter->spr.shade++;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
2019-08-31 07:47:15 +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
|
|
|
}
|
2019-08-31 07:47:15 +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);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-15 19:06:53 +00:00
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nIndex++;
|
2023-04-06 08:51:39 +00:00
|
|
|
if (pActor->nIndex >= getSeqFrameCount(nSeq))
|
2021-10-15 19:06:53 +00:00
|
|
|
{
|
2021-10-24 18:13:17 +00:00
|
|
|
if (pActor->nAction & 0x10)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nIndex = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2023-03-28 05:25:43 +00:00
|
|
|
else if (nSeq == nPreMagicSeq)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nIndex = 0;
|
|
|
|
pActor->nIndex2 = nMagicSeq;
|
|
|
|
pActor->nAction |= 0x10;
|
2021-12-23 16:02:05 +00:00
|
|
|
pActor->spr.cstat |= CSTAT_SPRITE_TRANSLUCENT;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2023-03-28 05:25:43 +00:00
|
|
|
else if (nSeq == nSavePointSeq)
|
2021-10-15 19:06:53 +00:00
|
|
|
{
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nIndex = 0;
|
|
|
|
pActor->nIndex2++;
|
|
|
|
pActor->nAction |= 0x10;
|
2021-10-15 19:06:53 +00:00
|
|
|
}
|
|
|
|
else
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-24 18:21:27 +00:00
|
|
|
DestroyAnim(pActor);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 06:09:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
void AIAnim::Draw(RunListEvent* ev)
|
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
const auto pActor = ev->pObjActor;
|
2021-10-24 18:21:27 +00:00
|
|
|
if (!pActor) return;
|
2021-10-15 19:06:53 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
seq_PlotSequence(ev->nParam, pActor->nIndex2, pActor->nIndex, 0x101);
|
2021-12-04 18:08:50 +00:00
|
|
|
ev->pTSprite->ownerActor = nullptr;
|
2021-10-15 19:06:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 06:09:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-10-24 17:18:11 +00:00
|
|
|
void BuildExplosion(DExhumedActor* pActor)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
const auto pSector = pActor->sector();
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
int nSeq = 36;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-11-22 22:16:21 +00:00
|
|
|
if (pSector->Flag & kSectUnderwater)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
nSeq = 75;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2023-03-28 05:25:43 +00:00
|
|
|
else if (pActor->spr.pos.Z == pSector->floorz)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
nSeq = 34;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
BuildAnim(nullptr, nSeq, 0, pActor->spr.pos, pSector, pActor->spr.scale.X, 4);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 06:09:26 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-12-23 15:44:43 +00:00
|
|
|
void BuildSplash(DExhumedActor* pActor, sectortype* pSector)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2022-10-07 17:40:27 +00:00
|
|
|
int nSound;
|
|
|
|
double nScale;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-12-23 16:02:05 +00:00
|
|
|
if (pActor->spr.statnum != 200)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
const double rep = pActor->spr.scale.X;
|
2022-10-07 17:40:27 +00:00
|
|
|
nScale = rep + RandomFloat(rep);
|
2019-08-31 07:47:15 +00:00
|
|
|
nSound = kSound0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-07 17:40:27 +00:00
|
|
|
nScale = 0.3125;
|
2019-08-31 07:47:15 +00:00
|
|
|
nSound = kSound1;
|
|
|
|
}
|
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
const int bIsLava = pSector->Flag & kSectLava;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
int nSeq, nFlag;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (bIsLava)
|
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
nSeq = 43;
|
2019-08-31 07:47:15 +00:00
|
|
|
nFlag = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-28 05:25:43 +00:00
|
|
|
nSeq = 35;
|
2019-08-31 07:47:15 +00:00
|
|
|
nFlag = 0;
|
|
|
|
}
|
|
|
|
|
2023-03-28 05:25:43 +00:00
|
|
|
const auto pSpawned = BuildAnim(nullptr, nSeq, 0, DVector3(pActor->spr.pos.XY(), pSector->floorz), pSector, nScale, nFlag);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (!bIsLava)
|
|
|
|
{
|
2021-12-23 16:02:05 +00:00
|
|
|
D3PlayFX(StaticSound[nSound] | 0xa00, pSpawned);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|