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

464 lines
11 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 "aistuff.h"
#include "sequence.h"
#include "sound.h"
#include "exhumed.h"
#include <assert.h>
#include "engine.h"
BEGIN_PS_NS
static actionSeq MummySeq[] = {
{8, 0},
{0, 0},
{16, 0},
{24, 0},
{32, 1},
{40, 1},
{48, 1},
{50, 0}
};
void BuildMummy(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, int nAngle)
{
2021-10-17 23:05:38 +00:00
if (pActor == nullptr)
{
pActor = insertActor(pSector, 102);
pActor->spr.pos = pos;
}
else
{
2022-08-16 21:17:01 +00:00
nAngle = pActor->int_ang();
2021-10-17 23:05:38 +00:00
ChangeActorStat(pActor, 102);
}
2021-12-23 16:04:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.shade = -12;
pActor->spr.clipdist = 32;
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
2022-08-31 22:50:13 +00:00
pActor->clear_zvel();
2021-12-23 16:04:37 +00:00
pActor->spr.xrepeat = 42;
pActor->spr.yrepeat = 42;
pActor->spr.pal = pActor->sector()->ceilingpal;
2021-12-23 16:04:37 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
2022-08-16 21:21:10 +00:00
pActor->set_int_ang(nAngle);
2021-12-23 16:04:37 +00:00
pActor->spr.picnum = 1;
pActor->spr.hitag = 0;
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.extra = -1;
// GrabTimeSlot(3);
2021-10-23 18:06:48 +00:00
pActor->nAction = 0;
pActor->nHealth = 640;
pActor->nFrame = 0;
2021-10-17 23:05:38 +00:00
pActor->pTarget = nullptr;
2021-10-23 18:06:48 +00:00
pActor->nCount = 0;
2021-10-17 23:05:38 +00:00
pActor->nPhase = Counters[kCountMummy]++;
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0xE0000);
2021-10-17 23:05:38 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0xE0000);
nCreaturesTotal++;
}
2021-10-17 23:05:38 +00:00
void CheckMummyRevive(DExhumedActor* pActor)
{
2021-10-17 23:05:38 +00:00
ExhumedStatIterator it(102);
while (auto pOther = it.Next())
{
2021-10-17 23:05:38 +00:00
if (pOther != pActor)
{
2021-10-17 23:05:38 +00:00
if (pOther->nAction != 5) {
continue;
}
2022-08-22 16:40:37 +00:00
double x = abs(pOther->spr.pos.X - pActor->spr.pos.X);
double y = abs(pOther->spr.pos.Y - pActor->spr.pos.Y);
2022-08-22 16:40:37 +00:00
if (x <= 320 && y <= 320)
{
2022-08-22 16:40:37 +00:00
if (cansee(pActor->spr.pos.plusZ(-32), pActor->sector(), pOther->spr.pos.plusZ(-32), pOther->sector()))
{
2021-12-23 16:26:44 +00:00
pOther->spr.cstat = 0;
2021-10-17 23:05:38 +00:00
pOther->nAction = 6;
pOther->nFrame = 0;
}
}
}
}
}
2021-10-15 20:02:06 +00:00
void AIMummy::Tick(RunListEvent* ev)
{
2021-10-17 23:05:38 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-12-07 17:53:02 +00:00
DExhumedActor* targ = pActor->pTarget;
auto pTarget = UpdateEnemy(&targ);
pActor->pTarget = targ;
int nAction = pActor->nAction;
2021-10-17 23:05:38 +00:00
Gravity(pActor);
2021-10-15 20:02:06 +00:00
int nSeq = SeqOffsets[kSeqMummy] + MummySeq[nAction].a;
2021-12-23 16:04:37 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
int nFrame = SeqBase[nSeq] + pActor->nFrame;
int nFrameFlag = FrameFlag[nFrame];
2021-10-17 23:05:38 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-15 20:02:06 +00:00
bool bVal = false;
2021-10-23 18:06:48 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
bVal = true;
}
2021-10-17 23:05:38 +00:00
if (pTarget != nullptr && nAction < 4)
2021-10-15 20:02:06 +00:00
{
if ((!pTarget->spr.cstat) && nAction)
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
2021-10-15 20:02:06 +00:00
}
}
2021-10-17 23:05:38 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
2021-10-15 20:02:06 +00:00
if (nAction > 7)
return;
2021-10-15 20:02:06 +00:00
switch (nAction)
{
case 0:
{
2021-10-17 23:05:38 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
2021-10-15 20:02:06 +00:00
{
2021-12-23 16:04:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 20:02:06 +00:00
2021-10-17 23:05:38 +00:00
if (pTarget == nullptr)
{
pTarget = FindPlayer(pActor, 100);
if (pTarget != nullptr)
{
2021-10-17 23:05:38 +00:00
D3PlayFX(StaticSound[kSound7], pActor);
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
2021-10-17 23:05:38 +00:00
pActor->pTarget = pTarget;
2021-10-23 18:06:48 +00:00
pActor->nAction = 1;
pActor->nCount = 90;
2021-10-15 20:02:06 +00:00
2022-09-01 14:57:55 +00:00
pActor->set_int_xvel(bcos(pActor->int_ang(), -2));
2022-08-16 21:17:01 +00:00
pActor->spr.yvel = bsin(pActor->int_ang(), -2);
}
}
2021-10-15 20:02:06 +00:00
}
return;
}
2021-10-15 20:02:06 +00:00
case 1:
{
2021-10-23 18:06:48 +00:00
if (pActor->nCount > 0)
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nCount--;
2021-10-15 20:02:06 +00:00
}
2021-10-17 23:05:38 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
2021-10-15 20:02:06 +00:00
{
2021-12-23 16:04:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2021-10-17 23:05:38 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-23 18:06:48 +00:00
if (pActor->nAction == 1)
2021-10-15 20:02:06 +00:00
{
2021-10-17 23:05:38 +00:00
if (RandomBit() && pTarget)
{
2022-08-20 14:38:47 +00:00
if (cansee(pActor->spr.pos.plusZ(-GetActorHeightF(pActor)), pActor->sector(),
pTarget->spr.pos.plusZ(-GetActorHeightF(pTarget)), pTarget->sector()))
{
2021-10-23 18:06:48 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
2021-10-15 20:02:06 +00:00
return;
}
2021-10-15 20:02:06 +00:00
}
}
}
2021-10-15 20:02:06 +00:00
// loc_2B5A8
2021-10-23 18:06:48 +00:00
if (!pActor->nFrame)
2021-10-15 20:02:06 +00:00
{
2022-09-01 14:57:55 +00:00
pActor->set_int_xvel(bcos(pActor->int_ang(), -1));
2022-08-16 21:17:01 +00:00
pActor->spr.yvel = bsin(pActor->int_ang(), -1);
2021-10-15 20:02:06 +00:00
}
2021-12-23 16:04:37 +00:00
if (pActor->spr.xvel || pActor->spr.yvel)
2021-10-15 20:02:06 +00:00
{
2022-09-01 14:48:02 +00:00
if (pActor->int_xvel() > 0)
2021-10-15 20:02:06 +00:00
{
2022-09-01 15:06:17 +00:00
pActor->add_int_xvel(-1024);
2022-09-01 14:48:02 +00:00
if (pActor->int_xvel() < 0) {
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
}
2021-10-15 20:02:06 +00:00
}
2022-09-01 14:48:02 +00:00
else if (pActor->int_xvel() < 0)
2021-10-15 20:02:06 +00:00
{
2022-09-01 15:02:38 +00:00
pActor->add_int_xvel( 1024);
2022-09-01 14:48:02 +00:00
if (pActor->int_xvel() > 0) {
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
}
2021-10-15 20:02:06 +00:00
}
2021-12-23 16:04:37 +00:00
if (pActor->spr.yvel > 0)
2021-10-15 20:02:06 +00:00
{
2021-12-23 16:04:37 +00:00
pActor->spr.yvel -= 1024;
if (pActor->spr.yvel < 0) {
pActor->spr.yvel = 0;
}
2021-10-15 20:02:06 +00:00
}
2021-12-23 16:04:37 +00:00
else if (pActor->spr.yvel < 0)
2021-10-15 20:02:06 +00:00
{
2021-12-23 16:04:37 +00:00
pActor->spr.yvel += 1024;
if (pActor->spr.yvel > 0) {
pActor->spr.yvel = 0;
2021-10-15 20:02:06 +00:00
}
}
}
2021-10-17 23:05:38 +00:00
switch (nMov.type)
2021-10-15 20:02:06 +00:00
{
2021-10-17 23:05:38 +00:00
case kHitWall:
{
2022-08-16 21:21:10 +00:00
pActor->set_int_ang((pActor->int_ang() + ((RandomWord() & 0x3FF) + 1024)) & kAngleMask);
2022-09-01 14:57:55 +00:00
pActor->set_int_xvel(bcos(pActor->int_ang(), -2));
2022-08-16 21:17:01 +00:00
pActor->spr.yvel = bsin(pActor->int_ang(), -2);
2021-10-17 23:05:38 +00:00
return;
}
2021-10-15 20:02:06 +00:00
2021-10-17 23:05:38 +00:00
case kHitSprite:
{
2021-11-26 13:26:03 +00:00
if (nMov.actor() == pTarget)
2021-10-15 20:02:06 +00:00
{
2022-08-20 14:26:01 +00:00
auto nAngDiff = AngleDiff(pActor->spr.angle, VecToAngle(pTarget->spr.pos - pActor->spr.pos));
if (nAngDiff < 64)
{
2021-10-17 23:05:38 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
}
2021-10-15 20:02:06 +00:00
}
2021-10-17 23:05:38 +00:00
return;
}
2021-10-15 20:02:06 +00:00
}
2021-10-15 20:02:06 +00:00
break;
}
2021-10-15 20:02:06 +00:00
case 2:
{
2021-10-17 23:05:38 +00:00
if (pTarget == nullptr)
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
}
else
{
2021-10-17 23:05:38 +00:00
if (PlotCourseToSprite(pActor, pTarget) >= 1024)
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
}
else if (nFrameFlag & 0x80)
{
2021-10-17 23:05:38 +00:00
runlist_DamageEnemy(pTarget, pActor, 5);
2021-10-15 20:02:06 +00:00
}
}
return;
}
2021-10-15 20:02:06 +00:00
case 3:
{
if (bVal)
{
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
pActor->nAction = 0;
pActor->nCount = 100;
2021-10-17 23:05:38 +00:00
pActor->pTarget = nullptr;
2021-10-15 20:02:06 +00:00
return;
}
else if (nFrameFlag & 0x80)
{
2021-10-17 23:05:38 +00:00
SetQuake(pActor, 100);
2021-10-15 20:02:06 +00:00
// low 16 bits of returned var contains the sprite index, the high 16 the bullet number
2022-08-16 21:17:01 +00:00
auto pBullet = BuildBullet(pActor, 9, -15360, pActor->int_ang(), pTarget, 1);
2021-10-17 23:05:38 +00:00
CheckMummyRevive(pActor);
2021-10-17 23:05:38 +00:00
if (pBullet)
2021-10-15 20:02:06 +00:00
{
if (!RandomSize(3))
{
2021-10-16 20:04:21 +00:00
SetBulletEnemy(pBullet->nPhase, pTarget);
pBullet->spr.pal = 5;
}
}
}
2021-10-15 20:02:06 +00:00
return;
}
2021-10-15 20:02:06 +00:00
case 4:
{
if (bVal)
{
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
pActor->nAction = 5;
}
2021-10-15 20:02:06 +00:00
return;
}
2021-10-15 20:02:06 +00:00
case 5:
{
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
return;
}
case 6:
{
if (bVal)
{
2021-12-23 16:04:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2021-10-23 18:06:48 +00:00
pActor->nAction = 0;
pActor->nHealth = 300;
2021-10-17 23:05:38 +00:00
pActor->pTarget = nullptr;
2021-10-15 20:02:06 +00:00
nCreaturesTotal++;
}
2021-10-15 20:02:06 +00:00
return;
}
case 7:
{
2021-10-17 23:05:38 +00:00
if (nMov.exbits)
{
2021-12-23 16:04:37 +00:00
pActor->spr.xvel >>= 1;
pActor->spr.yvel >>= 1;
2021-10-15 20:02:06 +00:00
}
2021-10-15 20:02:06 +00:00
if (bVal)
{
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
2021-10-23 18:06:48 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
2021-10-17 23:05:38 +00:00
pActor->pTarget = nullptr;
2021-10-15 20:02:06 +00:00
}
2021-10-15 20:02:06 +00:00
return;
}
}
}
2021-10-15 20:02:06 +00:00
void AIMummy::Draw(RunListEvent* ev)
{
2021-10-17 23:05:38 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-23 18:06:48 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqMummy] + MummySeq[nAction].a, pActor->nFrame, MummySeq[nAction].b);
2021-10-15 20:02:06 +00:00
return;
}
2021-10-15 20:02:06 +00:00
void AIMummy::RadialDamage(RunListEvent* ev)
{
2021-10-17 23:05:38 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-23 18:06:48 +00:00
if (pActor->nHealth <= 0)
2021-10-15 20:02:06 +00:00
return;
2021-10-17 23:05:38 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 20:02:06 +00:00
Damage(ev);
}
void AIMummy::Damage(RunListEvent* ev)
{
2021-10-17 23:05:38 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 20:02:06 +00:00
if (ev->nDamage <= 0)
return;
2021-10-23 18:06:48 +00:00
if (pActor->nHealth <= 0) {
2021-10-15 20:02:06 +00:00
return;
}
2021-10-23 18:06:48 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
2021-10-15 20:02:06 +00:00
2021-10-23 18:06:48 +00:00
if (pActor->nHealth <= 0)
2021-10-15 20:02:06 +00:00
{
2021-10-23 18:06:48 +00:00
pActor->nHealth = 0;
2021-12-23 16:04:37 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 20:02:06 +00:00
nCreaturesKilled++;
2021-10-17 23:05:38 +00:00
DropMagic(pActor);
2021-10-15 20:02:06 +00:00
2021-10-23 18:06:48 +00:00
pActor->nFrame = 0;
pActor->nAction = 4;
2021-10-15 20:02:06 +00:00
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
2022-08-31 22:50:13 +00:00
pActor->clear_zvel();
pActor->spr.pos.Z = pActor->sector()->floorz;
2021-10-15 20:02:06 +00:00
}
else
{
if (!RandomSize(2))
{
2021-10-23 18:06:48 +00:00
pActor->nAction = 7;
pActor->nFrame = 0;
2021-10-15 20:02:06 +00:00
2022-09-01 14:35:47 +00:00
pActor->clear_xvel();
2021-12-23 16:04:37 +00:00
pActor->spr.yvel = 0;
}
2021-10-15 20:02:06 +00:00
}
return;
}
END_PS_NS