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
|
|
|
|
|
2020-10-11 11:14:32 +00:00
|
|
|
enum { kMaxAnims = 400 };
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
short nMagicSeq = -1;
|
|
|
|
short nPreMagicSeq = -1;
|
|
|
|
short nSavePointSeq = -1;
|
|
|
|
short nAnimsFree = 0;
|
|
|
|
|
|
|
|
short AnimRunRec[kMaxAnims];
|
|
|
|
short AnimsFree[kMaxAnims];
|
|
|
|
Anim AnimList[kMaxAnims];
|
2019-08-31 07:47:15 +00:00
|
|
|
uint8_t AnimFlags[kMaxAnims];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
static SavegameHelper sghanims("anims",
|
2019-12-26 21:00:04 +00:00
|
|
|
SV(nMagicSeq),
|
|
|
|
SV(nPreMagicSeq),
|
|
|
|
SV(nSavePointSeq),
|
|
|
|
SV(nAnimsFree),
|
|
|
|
SA(AnimRunRec),
|
|
|
|
SA(AnimsFree),
|
|
|
|
SA(AnimList),
|
|
|
|
SA(AnimFlags),
|
|
|
|
nullptr);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
void InitAnims()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
for (int i = 0; i < kMaxAnims; i++) {
|
|
|
|
AnimsFree[i] = i;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nAnimsFree = kMaxAnims;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite = AnimList[nAnim].nSprite;
|
|
|
|
|
|
|
|
if (nSprite >= 0)
|
|
|
|
{
|
|
|
|
StopSpriteSound(nSprite);
|
|
|
|
runlist_SubRunRec(AnimRunRec[nAnim]);
|
|
|
|
runlist_DoSubRunRec(sprite[nSprite].extra);
|
|
|
|
runlist_FreeRun(sprite[nSprite].lotag - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimsFree[nAnimsFree] = nAnim;
|
|
|
|
nAnimsFree++;
|
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)
|
|
|
|
{
|
2019-11-14 10:27:34 +00:00
|
|
|
if (!nAnimsFree) {
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nAnimsFree--;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
short nAnim = AnimsFree[nAnimsFree];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nSprite == -1) {
|
|
|
|
nSprite = insertsprite(nSector, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].x = x;
|
|
|
|
sprite[nSprite].y = y;
|
|
|
|
sprite[nSprite].z = z;
|
|
|
|
sprite[nSprite].cstat = 0;
|
|
|
|
|
|
|
|
if (nFlag & 4)
|
|
|
|
{
|
|
|
|
sprite[nSprite].pal = 4;
|
|
|
|
sprite[nSprite].shade = -64;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSprite].pal = 0;
|
|
|
|
sprite[nSprite].shade = -12;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].clipdist = 10;
|
|
|
|
sprite[nSprite].xrepeat = nRepeat;
|
|
|
|
sprite[nSprite].yrepeat = nRepeat;
|
|
|
|
sprite[nSprite].picnum = 1;
|
|
|
|
sprite[nSprite].ang = 0;
|
|
|
|
sprite[nSprite].xoffset = 0;
|
|
|
|
sprite[nSprite].yoffset = 0;
|
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = 0;
|
|
|
|
|
|
|
|
// CHECKME - where is hitag set otherwise?
|
|
|
|
if (sprite[nSprite].statnum < 900) {
|
|
|
|
sprite[nSprite].hitag = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].lotag = runlist_HeadRun() + 1;
|
|
|
|
sprite[nSprite].owner = -1;
|
|
|
|
sprite[nSprite].extra = runlist_AddRunRec(sprite[nSprite].lotag - 1, nAnim | 0x100000);
|
|
|
|
|
|
|
|
AnimRunRec[nAnim] = runlist_AddRunRec(NewRun, nAnim | 0x100000);
|
|
|
|
AnimList[nAnim].nSprite = nSprite;
|
|
|
|
AnimFlags[nAnim] = nFlag;
|
|
|
|
AnimList[nAnim].field_2 = 0;
|
|
|
|
AnimList[nAnim].nSeq = SeqOffsets[val] + val2;
|
|
|
|
AnimList[nAnim].field_4 = 256;
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nFlag & 0x80) {
|
|
|
|
sprite[nSprite].cstat |= 0x2; // set transluscence
|
|
|
|
}
|
|
|
|
|
|
|
|
return nAnim;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short GetAnimSprite(short nAnim)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
return AnimList[nAnim].nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FuncAnim(int a, int, int nRun)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nAnim = RunData[nRun].nVal;
|
|
|
|
assert(nAnim >= 0 && nAnim < kMaxAnims);
|
|
|
|
|
|
|
|
short nSprite = AnimList[nAnim].nSprite;
|
|
|
|
short nSeq = AnimList[nAnim].nSeq;
|
|
|
|
|
|
|
|
assert(nSprite != -1);
|
|
|
|
|
|
|
|
int nMessage = a & 0x7F0000;
|
|
|
|
|
|
|
|
switch (nMessage)
|
|
|
|
{
|
|
|
|
case 0x20000:
|
|
|
|
{
|
|
|
|
short var_1C = AnimList[nAnim].field_2;
|
|
|
|
|
|
|
|
if (!(sprite[nSprite].cstat & 0x8000))
|
|
|
|
{
|
|
|
|
seq_MoveSequence(nSprite, nSeq, var_1C);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sprite[nSprite].statnum == kStatIgnited)
|
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
short nSpriteB = sprite[nSprite].hitag;
|
|
|
|
if (nSpriteB > -1)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
sprite[nSprite].x = sprite[nSpriteB].x;
|
|
|
|
sprite[nSprite].y = sprite[nSpriteB].y;
|
|
|
|
sprite[nSprite].z = sprite[nSpriteB].z;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-30 16:04:59 +00:00
|
|
|
if (sprite[nSpriteB].sectnum != sprite[nSprite].sectnum)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
if (sprite[nSpriteB].sectnum < 0 || sprite[nSpriteB].sectnum >= kMaxSectors)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
mychangespritesect(nSprite, sprite[nSpriteB].sectnum);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!var_1C)
|
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
if (sprite[nSpriteB].cstat != 0x8000)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
short hitag2 = sprite[nSpriteB].hitag;
|
|
|
|
sprite[nSpriteB].hitag--;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (hitag2 >= 15)
|
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
runlist_DamageEnemy(nSpriteB, -1, (sprite[nSpriteB].hitag - 14) * 2);
|
|
|
|
|
|
|
|
if (sprite[nSpriteB].shade < 100)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-30 16:04:59 +00:00
|
|
|
sprite[nSpriteB].pal = 0;
|
|
|
|
sprite[nSpriteB].shade++;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:04:59 +00:00
|
|
|
if (!(sprite[nSpriteB].cstat & 101))
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-30 16:04:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSpriteB].hitag = 1;
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-30 16:04:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSpriteB].hitag = 1;
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimList[nAnim].field_2++;
|
|
|
|
if (AnimList[nAnim].field_2 >= SeqSize[nSeq])
|
|
|
|
{
|
|
|
|
if (AnimFlags[nAnim] & 0x10)
|
|
|
|
{
|
|
|
|
AnimList[nAnim].field_2 = 0;
|
|
|
|
}
|
|
|
|
else if (nSeq == nPreMagicSeq)
|
|
|
|
{
|
|
|
|
AnimList[nAnim].field_2 = 0;
|
|
|
|
AnimList[nAnim].nSeq = nMagicSeq;
|
|
|
|
short nAnimSprite = AnimList[nAnim].nSprite;
|
|
|
|
AnimFlags[nAnim] |= 0x10;
|
|
|
|
sprite[nAnimSprite].cstat |= 2;
|
|
|
|
}
|
|
|
|
else if (nSeq == nSavePointSeq)
|
|
|
|
{
|
|
|
|
AnimList[nAnim].field_2 = 0;
|
|
|
|
AnimList[nAnim].nSeq++;
|
|
|
|
AnimFlags[nAnim] |= 0x10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestroyAnim(nAnim);
|
|
|
|
mydeletesprite(nSprite);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x90000:
|
|
|
|
{
|
|
|
|
seq_PlotSequence(a & 0xFFFF, nSeq, AnimList[nAnim].field_2, 0x101);
|
|
|
|
tsprite[a & 0xFFFF].owner = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0xA0000:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2019-11-24 09:03:19 +00:00
|
|
|
Printf("unknown msg %x for anim\n", a & 0x7F0000);
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BuildExplosion(short nSprite)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSector = sprite[nSprite].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;
|
|
|
|
}
|
|
|
|
else if (sprite[nSprite].z == sector[nSector].floorz)
|
|
|
|
{
|
|
|
|
edx = 34;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
BuildAnim(-1, edx, 0, sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum, sprite[nSprite].xrepeat, 4);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BuildSplash(int nSprite, int nSector)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
int nRepeat, nSound;
|
|
|
|
|
|
|
|
if (sprite[nSprite].statnum != 200)
|
|
|
|
{
|
|
|
|
nRepeat = sprite[nSprite].xrepeat + (RandomWord() % sprite[nSprite].xrepeat);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nAnim = BuildAnim(-1, edx, 0, sprite[nSprite].x, sprite[nSprite].y, sector[nSector].floorz, nSector, nRepeat, nFlag);
|
|
|
|
|
|
|
|
if (!bIsLava)
|
|
|
|
{
|
2019-11-14 16:27:25 +00:00
|
|
|
D3PlayFX(StaticSound[nSound] | 0xa00, AnimList[nAnim].nSprite);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return AnimList[nAnim].nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|