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
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
short nMagicSeq = -1;
|
|
|
|
short nPreMagicSeq = -1;
|
|
|
|
short nSavePointSeq = -1;
|
2020-11-29 23:47:53 +00:00
|
|
|
FreeListArray<Anim, kMaxAnims> AnimList;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-29 23:47:53 +00:00
|
|
|
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, Anim& w, Anim* def)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2020-11-29 23:47:53 +00:00
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
2021-10-24 18:13:17 +00:00
|
|
|
arc("seq", w.nIndex2)
|
|
|
|
("val1", w.nIndex)
|
2020-11-29 23:47:53 +00:00
|
|
|
("val2", w.field_4)
|
|
|
|
("sprite", w.nSprite)
|
2021-10-24 18:13:17 +00:00
|
|
|
("runrec", w.nRun)
|
|
|
|
("flags", w.nAction)
|
2020-11-29 23:47:53 +00:00
|
|
|
.EndObject();
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2020-11-29 23:47:53 +00:00
|
|
|
return arc;
|
|
|
|
}
|
2019-08-26 03:59:14 +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)
|
|
|
|
("list", AnimList)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-29 23:47:53 +00:00
|
|
|
void InitAnims()
|
|
|
|
{
|
|
|
|
AnimList.Clear();
|
2019-08-31 07:47:15 +00:00
|
|
|
nMagicSeq = SeqOffsets[kSeqItems] + 21;
|
|
|
|
nPreMagicSeq = SeqOffsets[kSeqMagic2];
|
|
|
|
nSavePointSeq = SeqOffsets[kSeqItems] + 12;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyAnim(int nAnim)
|
|
|
|
{
|
2021-10-24 18:06:46 +00:00
|
|
|
auto pActor = &AnimList[nAnim];
|
|
|
|
short nSprite = pActor->nSprite;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (nSprite >= 0)
|
|
|
|
{
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-31 07:47:15 +00:00
|
|
|
StopSpriteSound(nSprite);
|
2021-10-24 18:13:17 +00:00
|
|
|
runlist_SubRunRec(pActor->nRun);
|
2021-09-06 06:33:02 +00:00
|
|
|
runlist_DoSubRunRec(pSprite->extra);
|
|
|
|
runlist_FreeRun(pSprite->lotag - 1);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 23:47:53 +00:00
|
|
|
AnimList.Release(nAnim);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BuildAnim(int nSprite, int val, int val2, int x, int y, int z, int nSector, int nRepeat, int nFlag)
|
|
|
|
{
|
2020-11-29 23:47:53 +00:00
|
|
|
int nAnim = AnimList.Get();
|
|
|
|
if (nAnim < 0) {
|
2019-11-14 10:27:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-10-24 18:06:46 +00:00
|
|
|
auto pActor = &AnimList[nAnim];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nSprite == -1) {
|
|
|
|
nSprite = insertsprite(nSector, 500);
|
|
|
|
}
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->x = x;
|
|
|
|
pSprite->y = y;
|
|
|
|
pSprite->z = z;
|
|
|
|
pSprite->cstat = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (nFlag & 4)
|
|
|
|
{
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->pal = 4;
|
|
|
|
pSprite->shade = -64;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->pal = 0;
|
|
|
|
pSprite->shade = -12;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->clipdist = 10;
|
|
|
|
pSprite->xrepeat = nRepeat;
|
|
|
|
pSprite->yrepeat = nRepeat;
|
|
|
|
pSprite->picnum = 1;
|
|
|
|
pSprite->ang = 0;
|
|
|
|
pSprite->xoffset = 0;
|
|
|
|
pSprite->yoffset = 0;
|
|
|
|
pSprite->xvel = 0;
|
|
|
|
pSprite->yvel = 0;
|
|
|
|
pSprite->zvel = 0;
|
|
|
|
pSprite->backuppos();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
// CHECKME - where is hitag set otherwise?
|
2021-09-06 06:33:02 +00:00
|
|
|
if (pSprite->statnum < 900) {
|
|
|
|
pSprite->hitag = -1;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->lotag = runlist_HeadRun() + 1;
|
|
|
|
pSprite->owner = -1;
|
2021-10-15 16:37:39 +00:00
|
|
|
pSprite->extra = runlist_AddRunRec(pSprite->lotag - 1, nAnim, 0x100000);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nRun = runlist_AddRunRec(NewRun, nAnim, 0x100000);
|
2021-10-24 18:06:46 +00:00
|
|
|
pActor->nSprite = nSprite;
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nAction = nFlag;
|
|
|
|
pActor->nIndex = 0;
|
|
|
|
pActor->nIndex2 = SeqOffsets[val] + val2;
|
2021-10-24 18:06:46 +00:00
|
|
|
pActor->field_4 = 256;
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nFlag & 0x80) {
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->cstat |= 0x2; // set transluscence
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nAnim;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short GetAnimSprite(short nAnim)
|
|
|
|
{
|
2021-10-24 18:06:46 +00:00
|
|
|
auto pActor = &AnimList[nAnim];
|
|
|
|
return pActor->nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
void AIAnim::Tick(RunListEvent* ev)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-17 14:22:25 +00:00
|
|
|
short nAnim = RunData[ev->nRun].nObjIndex;
|
2019-08-31 07:47:15 +00:00
|
|
|
assert(nAnim >= 0 && nAnim < kMaxAnims);
|
2021-10-24 18:06:46 +00:00
|
|
|
auto pActor = &AnimList[nAnim];
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-24 18:06:46 +00:00
|
|
|
short nSprite = pActor->nSprite;
|
2021-10-24 18:13:17 +00:00
|
|
|
short nSeq = pActor->nIndex2;
|
2021-10-15 19:06:53 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
assert(nSprite != -1);
|
|
|
|
|
2021-10-24 18:13:17 +00:00
|
|
|
short var_1C = pActor->nIndex;
|
2021-10-15 19:06:53 +00:00
|
|
|
|
|
|
|
if (!(pSprite->cstat & 0x8000))
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
seq_MoveSequence(nSprite, nSeq, var_1C);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pSprite->statnum == kStatIgnited)
|
|
|
|
{
|
|
|
|
short nSpriteB = pSprite->hitag;
|
|
|
|
if (nSpriteB > -1)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
auto pSpriteB = &sprite[nSpriteB];
|
|
|
|
pSprite->x = pSpriteB->x;
|
|
|
|
pSprite->y = pSpriteB->y;
|
|
|
|
pSprite->z = pSpriteB->z;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
if (pSpriteB->sectnum != pSprite->sectnum)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
if (pSpriteB->sectnum < 0 || pSpriteB->sectnum >= kMaxSectors)
|
|
|
|
{
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mychangespritesect(nSprite, pSpriteB->sectnum);
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
if (!var_1C)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
if (pSpriteB->cstat != 0x8000)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
short hitag2 = pSpriteB->hitag;
|
|
|
|
pSpriteB->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-10-15 19:06:53 +00:00
|
|
|
runlist_DamageEnemy(nSpriteB, -1, (pSpriteB->hitag - 14) * 2);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
if (pSpriteB->shade < 100)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
pSpriteB->pal = 0;
|
|
|
|
pSpriteB->shade++;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 19:06:53 +00:00
|
|
|
|
|
|
|
if (!(pSpriteB->cstat & 101))
|
2019-11-30 16:04:59 +00:00
|
|
|
{
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
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
|
|
|
|
{
|
|
|
|
pSpriteB->hitag = 1;
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-15 19:06:53 +00:00
|
|
|
pSpriteB->hitag = 1;
|
2019-08-31 07:47:15 +00:00
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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++;
|
|
|
|
if (pActor->nIndex >= SeqSize[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
|
|
|
}
|
2021-10-15 19:06:53 +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;
|
2021-10-24 18:06:46 +00:00
|
|
|
short nAnimSprite = pActor->nSprite;
|
2021-10-24 18:13:17 +00:00
|
|
|
pActor->nAction |= 0x10;
|
2021-10-15 19:06:53 +00:00
|
|
|
sprite[nAnimSprite].cstat |= 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 19:06:53 +00:00
|
|
|
else if (nSeq == nSavePointSeq)
|
|
|
|
{
|
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-15 19:06:53 +00:00
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 19:06:53 +00:00
|
|
|
void AIAnim::Draw(RunListEvent* ev)
|
|
|
|
{
|
2021-10-17 14:22:25 +00:00
|
|
|
short nAnim = RunData[ev->nRun].nObjIndex;
|
2021-10-15 19:06:53 +00:00
|
|
|
assert(nAnim >= 0 && nAnim < kMaxAnims);
|
2021-10-24 18:06:46 +00:00
|
|
|
auto pActor = &AnimList[nAnim];
|
2021-10-24 18:13:17 +00:00
|
|
|
short nSeq = pActor->nIndex2;
|
2021-10-15 19:06:53 +00:00
|
|
|
|
2021-10-24 18:13:17 +00:00
|
|
|
seq_PlotSequence(ev->nParam, nSeq, pActor->nIndex, 0x101);
|
2021-10-15 19:06:53 +00:00
|
|
|
ev->pTSprite->owner = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FuncAnim(int nObject, int nMessage, int nDamage, int nRun)
|
|
|
|
{
|
|
|
|
AIAnim ai;
|
|
|
|
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
|
|
|
|
}
|
|
|
|
|
2021-10-24 17:18:11 +00:00
|
|
|
void BuildExplosion(DExhumedActor* pActor)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-24 17:18:11 +00:00
|
|
|
auto pSprite = &pActor->s();
|
2021-09-06 06:33:02 +00:00
|
|
|
|
|
|
|
short nSector = pSprite->sectnum;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
int edx = 36;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (SectFlag[nSector] & kSectUnderwater)
|
|
|
|
{
|
|
|
|
edx = 75;
|
|
|
|
}
|
2021-09-06 06:33:02 +00:00
|
|
|
else if (pSprite->z == sector[nSector].floorz)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
edx = 34;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-24 17:11:04 +00:00
|
|
|
BuildAnim(nullptr, edx, 0, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, pSprite->xrepeat, 4);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 17:18:11 +00:00
|
|
|
void BuildSplash(DExhumedActor* actor, int nSector)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-24 17:18:11 +00:00
|
|
|
auto pSprite = &actor->s();
|
2019-08-31 07:47:15 +00:00
|
|
|
int nRepeat, nSound;
|
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
if (pSprite->statnum != 200)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-09-06 06:33:02 +00:00
|
|
|
nRepeat = pSprite->xrepeat + (RandomWord() % pSprite->xrepeat);
|
2019-08-31 07:47:15 +00:00
|
|
|
nSound = kSound0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nRepeat = 20;
|
|
|
|
nSound = kSound1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bIsLava = SectFlag[nSector] & kSectLava;
|
|
|
|
|
|
|
|
int edx, nFlag;
|
|
|
|
|
|
|
|
if (bIsLava)
|
|
|
|
{
|
|
|
|
edx = 43;
|
|
|
|
nFlag = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edx = 35;
|
|
|
|
nFlag = 0;
|
|
|
|
}
|
|
|
|
|
2021-10-24 17:11:04 +00:00
|
|
|
auto pActor = BuildAnim(nullptr, edx, 0, pSprite->x, pSprite->y, sector[nSector].floorz, nSector, nRepeat, nFlag);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (!bIsLava)
|
|
|
|
{
|
2021-10-24 17:11:04 +00:00
|
|
|
D3PlayFX(StaticSound[nSound] | 0xa00, pActor);
|
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
|