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

547 lines
14 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 "engine.h"
#include "exhumed.h"
#include "sequence.h"
#include "sound.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq LionSeq[] = {
{54, 1},
{18, 0},
{0, 0},
{10, 0},
{44, 0},
{18, 0},
{26, 0},
{34, 0},
{8, 1},
{9, 1},
{52, 1},
{53, 1}
};
void BuildLion(DExhumedActor* pActor, int x, int y, int z, sectortype* pSector, int nAngle)
{
2021-10-17 20:03:08 +00:00
if (pActor == nullptr)
{
pActor = insertActor(pSector, 104);
}
else
{
2021-10-17 20:03:08 +00:00
ChangeActorStat(pActor, 104);
2021-12-23 16:04:12 +00:00
x = pActor->spr.pos.X;
y = pActor->spr.pos.Y;
z = pActor->spr.sector()->floorz;
nAngle = pActor->spr.ang;
}
2021-12-23 16:04:12 +00:00
pActor->spr.pos.X = x;
pActor->spr.pos.Y = y;
pActor->spr.pos.Z = z;
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.clipdist = 60;
pActor->spr.shade = -12;
pActor->spr.xrepeat = 40;
pActor->spr.yrepeat = 40;
pActor->spr.picnum = 1;
pActor->spr.pal = pActor->spr.sector()->ceilingpal;
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
pActor->spr.ang = nAngle;
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.zvel = 0;
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.hitag = 0;
pActor->spr.extra = -1;
// GrabTimeSlot(3);
2021-10-23 17:31:53 +00:00
pActor->nAction = 0;
pActor->nHealth = 500;
pActor->nFrame = 0;
2021-10-17 20:03:08 +00:00
pActor->pTarget = nullptr;
2021-10-23 17:31:53 +00:00
pActor->nCount = 0;
2021-10-17 20:03:08 +00:00
pActor->nPhase = Counters[kCountLion]++;
2021-12-23 16:04:12 +00:00
pActor->spr.owner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x130000);
2021-10-17 20:03:08 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x130000);
nCreaturesTotal++;
}
2021-10-15 19:29:24 +00:00
void AILion::Draw(RunListEvent* ev)
{
2021-10-17 20:03:08 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 19:29:24 +00:00
2021-10-23 17:31:53 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqLion] + LionSeq[nAction].a, pActor->nFrame, LionSeq[nAction].b);
2021-10-15 19:29:24 +00:00
}
void AILion::RadialDamage(RunListEvent* ev)
{
2021-10-17 20:03:08 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-17 20:03:08 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 19:29:24 +00:00
Damage(ev);
}
void AILion::Damage(RunListEvent* ev)
{
2021-10-17 20:03:08 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 19:29:24 +00:00
2021-10-23 17:31:53 +00:00
if (ev->nDamage && pActor->nHealth > 0)
{
2021-10-23 17:31:53 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
if (pActor->nHealth <= 0)
{
2021-10-15 19:29:24 +00:00
// R.I.P.
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.zvel = 0;
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-23 17:31:53 +00:00
pActor->nHealth = 0;
2021-10-15 19:29:24 +00:00
nCreaturesKilled++;
if (nAction < 10)
{
2021-10-17 20:03:08 +00:00
DropMagic(pActor);
2021-10-15 19:29:24 +00:00
if (ev->isRadialEvent())
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 11;
2021-10-15 19:29:24 +00:00
}
else
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 10;
2021-10-15 19:29:24 +00:00
}
2021-10-23 17:31:53 +00:00
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
return;
}
}
else
{
2021-10-17 20:03:08 +00:00
auto pTarget = ev->pOtherActor;
2021-10-17 20:03:08 +00:00
if (pTarget)
2021-10-15 19:29:24 +00:00
{
if (pTarget->spr.statnum < 199) {
2021-10-17 20:03:08 +00:00
pActor->pTarget = pTarget;
2021-10-15 19:29:24 +00:00
}
2021-10-15 19:29:24 +00:00
if (nAction != 6)
{
2021-10-23 17:31:53 +00:00
if (RandomSize(8) <= (pActor->nHealth >> 2))
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 4;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
}
2021-10-15 19:29:24 +00:00
else if (RandomSize(1))
{
2021-10-17 20:03:08 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-23 17:31:53 +00:00
pActor->nAction = 5;
pActor->nCount = RandomSize(3);
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (pActor->spr.ang - (RandomSize(1) << 8)) + (RandomSize(1) << 8); // NOTE: no angle mask in original code
}
2021-10-15 19:29:24 +00:00
else
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 8;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 19:29:24 +00:00
}
2021-10-23 17:31:53 +00:00
pActor->nFrame = 0;
}
}
}
2021-10-15 19:29:24 +00:00
}
}
2021-10-15 19:29:24 +00:00
void AILion::Tick(RunListEvent* ev)
{
2021-10-17 20:03:08 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 19:29:24 +00:00
bool bVal = false;
2021-10-15 19:29:24 +00:00
if (nAction != 7) {
2021-10-17 20:03:08 +00:00
Gravity(pActor);
2021-10-15 19:29:24 +00:00
}
int nSeq = SeqOffsets[kSeqLion] + LionSeq[nAction].a;
2021-12-23 16:04:12 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-17 20:03:08 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-23 17:31:53 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
bVal = true;
}
int nFlag = FrameFlag[SeqBase[nSeq] + pActor->nFrame];
2021-12-07 17:53:02 +00:00
DExhumedActor* pTarget = pActor->pTarget;
2021-10-15 19:29:24 +00:00
2021-10-17 20:03:08 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
2021-10-15 19:29:24 +00:00
switch (nAction)
{
default:
return;
case 0:
case 1:
{
2021-10-17 20:03:08 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
2021-10-15 19:29:24 +00:00
{
2021-10-17 20:03:08 +00:00
if (pTarget == nullptr)
2021-10-15 19:29:24 +00:00
{
2021-10-17 20:03:08 +00:00
pTarget = FindPlayer(pActor, 40);
if (pTarget)
2021-10-15 19:29:24 +00:00
{
2021-10-17 20:03:08 +00:00
D3PlayFX(StaticSound[kSound24], pActor);
2021-10-23 17:31:53 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = bcos(pActor->spr.ang, -1);
pActor->spr.yvel = bsin(pActor->spr.ang, -1);
2021-10-17 20:03:08 +00:00
pActor->pTarget = pTarget;
return;
}
2021-10-15 19:29:24 +00:00
}
}
2021-10-15 19:29:24 +00:00
if (nAction && !easy())
{
2021-10-23 17:31:53 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 19:29:24 +00:00
{
if (RandomBit())
{
2021-12-23 16:04:12 +00:00
pActor->spr.ang = RandomWord() & kAngleMask;
pActor->spr.xvel = bcos(pActor->spr.ang, -1);
pActor->spr.yvel = bsin(pActor->spr.ang, -1);
2021-10-15 19:29:24 +00:00
}
else
{
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2021-10-15 19:29:24 +00:00
}
2021-10-23 17:31:53 +00:00
pActor->nCount = 100;
2021-10-15 19:29:24 +00:00
}
}
2021-10-15 19:29:24 +00:00
return;
}
2021-10-15 19:29:24 +00:00
case 2:
{
2021-10-17 20:03:08 +00:00
if ((totalmoves & 0x1F) == (pActor->nPhase & 0x1F))
2021-10-15 19:29:24 +00:00
{
2021-10-17 20:03:08 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-12-23 16:04:12 +00:00
int nAng = pActor->spr.ang & 0xFFF8;
2021-12-23 16:04:12 +00:00
if (pActor->spr.cstat & CSTAT_SPRITE_INVISIBLE)
2021-10-15 19:29:24 +00:00
{
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = bcos(nAng, 1);
pActor->spr.yvel = bsin(nAng, 1);
2021-10-15 19:29:24 +00:00
}
else
{
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = bcos(nAng, -1);
pActor->spr.yvel = bsin(nAng, -1);
2021-10-15 19:29:24 +00:00
}
}
2021-10-17 20:03:08 +00:00
if (nMov.type == kHitWall)
2021-10-15 19:29:24 +00:00
{
// loc_378FA:
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (pActor->spr.ang + 256) & kAngleMask;
pActor->spr.xvel = bcos(pActor->spr.ang, -1);
pActor->spr.yvel = bsin(pActor->spr.ang, -1);
2021-10-15 19:29:24 +00:00
break;
}
2021-10-17 20:03:08 +00:00
else if (nMov.type == kHitSprite)
2021-10-15 19:29:24 +00:00
{
2021-11-26 13:26:03 +00:00
if (nMov.actor() == pTarget)
2021-10-15 19:29:24 +00:00
{
2021-12-23 16:04:12 +00:00
if (pActor->spr.cstat & CSTAT_SPRITE_INVISIBLE)
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 9;
pActor->spr.cstat &= ~CSTAT_SPRITE_INVISIBLE;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2021-10-15 19:29:24 +00:00
}
else
{
2021-12-23 16:04:12 +00:00
int nAng = getangle(pTarget->spr.pos.X - pActor->spr.pos.X, pTarget->spr.pos.Y - pActor->spr.pos.Y);
2021-12-23 16:04:12 +00:00
if (AngleDiff(pActor->spr.ang, nAng) < 64)
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 3;
}
}
2021-10-23 17:31:53 +00:00
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
break;
}
else
{
// loc_378FA:
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (pActor->spr.ang + 256) & kAngleMask;
pActor->spr.xvel = bcos(pActor->spr.ang, -1);
pActor->spr.yvel = bsin(pActor->spr.ang, -1);
2021-10-15 19:29:24 +00:00
break;
}
}
2021-10-15 19:29:24 +00:00
break;
}
2021-10-15 19:29:24 +00:00
case 3:
{
2021-10-17 20:03:08 +00:00
if (pTarget == nullptr)
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 1;
pActor->nCount = 50;
2021-10-15 19:29:24 +00:00
}
else
{
2021-10-17 20:03:08 +00:00
if (PlotCourseToSprite(pActor, pTarget) >= 768)
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 2;
2021-10-15 19:29:24 +00:00
}
else if (nFlag & 0x80)
{
2021-10-17 20:03:08 +00:00
runlist_DamageEnemy(pTarget, pActor, 10);
2021-10-15 19:29:24 +00:00
}
}
2021-10-15 19:29:24 +00:00
break;
}
case 4:
{
if (bVal)
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
}
2021-10-17 20:03:08 +00:00
if (nMov.exbits & kHitAux2)
2021-10-15 19:29:24 +00:00
{
2021-12-23 16:04:12 +00:00
pActor->spr.xvel >>= 1;
pActor->spr.yvel >>= 1;
2021-10-15 19:29:24 +00:00
}
2021-10-15 19:29:24 +00:00
return;
}
2021-10-15 19:29:24 +00:00
case 5: // Jump away when damaged
{
2021-10-23 17:31:53 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 19:29:24 +00:00
{
2021-12-23 16:04:12 +00:00
pActor->spr.zvel = -4000;
2021-10-23 17:31:53 +00:00
pActor->nCount = 0;
2021-12-23 16:04:12 +00:00
int x = pActor->spr.pos.X;
int y = pActor->spr.pos.Y;
int z = pActor->spr.pos.Z - (GetActorHeight(pActor) >> 1);
2021-10-15 19:29:24 +00:00
int nCheckDist = 0x7FFFFFFF;
2021-12-23 16:04:12 +00:00
int nAngle = pActor->spr.ang;
int nScanAngle = (pActor->spr.ang - 512) & kAngleMask;
2021-10-15 19:29:24 +00:00
for (int i = 0; i < 5; i++)
{
HitInfo hit{};
2021-12-23 16:04:12 +00:00
hitscan({ x, y, z }, pActor->spr.sector(), { bcos(nScanAngle), bsin(nScanAngle), 0 }, hit, CLIPMASK1);
2021-11-25 23:25:28 +00:00
if (hit.hitWall)
{
2021-12-22 09:36:09 +00:00
int theX = abs(hit.hitpos.X - x);
2021-12-22 09:40:26 +00:00
int theY = abs(hit.hitpos.Y - y);
2021-10-15 19:29:24 +00:00
if ((theX + theY) < nCheckDist)
{
2021-10-15 19:29:24 +00:00
nCheckDist = theX;
nAngle = nScanAngle;
}
}
2021-10-15 19:29:24 +00:00
nScanAngle += 256;
nScanAngle &= kAngleMask;
}
2021-12-23 16:04:12 +00:00
pActor->spr.ang = nAngle;
2021-10-23 17:31:53 +00:00
pActor->nAction = 6;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = bcos(pActor->spr.ang) - bcos(pActor->spr.ang, -3);
pActor->spr.yvel = bsin(pActor->spr.ang) - bsin(pActor->spr.ang, -3);
2021-10-17 20:03:08 +00:00
D3PlayFX(StaticSound[kSound24], pActor);
2021-10-15 19:29:24 +00:00
}
2021-10-15 19:29:24 +00:00
return;
}
2021-10-15 19:29:24 +00:00
case 6:
{
2021-10-17 20:03:08 +00:00
if (nMov.exbits)
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 19:29:24 +00:00
return;
}
2021-10-17 20:03:08 +00:00
if (nMov.type == kHitWall)
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 7;
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (GetWallNormal(nMov.hitWall) + 1024) & kAngleMask;
2021-10-23 17:31:53 +00:00
pActor->nCount = RandomSize(4);
2021-10-15 19:29:24 +00:00
return;
}
2021-10-17 20:03:08 +00:00
else if (nMov.type == kHitSprite)
2021-10-15 19:29:24 +00:00
{
2021-11-26 13:26:03 +00:00
if (nMov.actor() == pTarget)
2021-10-15 19:29:24 +00:00
{
2021-12-23 16:04:12 +00:00
int nAng = getangle(pTarget->spr.pos.X - pActor->spr.pos.X, pTarget->spr.pos.Y - pActor->spr.pos.Y);
if (AngleDiff(pActor->spr.ang, nAng) < 64)
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
}
}
2021-10-15 19:29:24 +00:00
else
{
// loc_378FA:
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (pActor->spr.ang + 256) & kAngleMask;
pActor->spr.xvel = bcos(pActor->spr.ang, -1);
pActor->spr.yvel = bsin(pActor->spr.ang, -1);
2021-10-15 19:29:24 +00:00
break;
}
}
return;
}
case 7:
{
2021-10-23 17:31:53 +00:00
pActor->nCount--;
2021-10-23 17:31:53 +00:00
if (pActor->nCount <= 0)
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nCount = 0;
2021-10-17 20:03:08 +00:00
if (pTarget)
{
2021-10-17 20:03:08 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-15 19:29:24 +00:00
}
else
{
2021-12-23 16:04:12 +00:00
pActor->spr.ang = (RandomSize(9) + (pActor->spr.ang + 768)) & kAngleMask;
}
2021-12-23 16:04:12 +00:00
pActor->spr.zvel = -1000;
2021-10-15 19:29:24 +00:00
2021-10-23 17:31:53 +00:00
pActor->nAction = 6;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = bcos(pActor->spr.ang) - bcos(pActor->spr.ang, -3);
pActor->spr.yvel = bsin(pActor->spr.ang) - bsin(pActor->spr.ang, -3);
2021-10-17 20:03:08 +00:00
D3PlayFX(StaticSound[kSound24], pActor);
2021-10-15 19:29:24 +00:00
}
return;
}
case 8:
{
if (bVal)
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-12-23 16:04:12 +00:00
pActor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
2021-10-15 19:29:24 +00:00
}
return;
}
case 9:
{
if (bVal)
{
2021-10-23 17:31:53 +00:00
pActor->nFrame = 0;
pActor->nAction = 2;
2021-12-23 16:04:12 +00:00
pActor->spr.cstat |= CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 19:29:24 +00:00
}
return;
}
case 10:
case 11:
{
if (bVal)
{
2021-12-23 16:04:12 +00:00
runlist_SubRunRec(pActor->spr.owner);
2021-10-23 17:31:53 +00:00
runlist_SubRunRec(pActor->nRun);
2021-12-23 16:04:12 +00:00
pActor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
2021-10-15 19:29:24 +00:00
}
return;
}
}
// loc_379AD: ?
2021-10-17 20:03:08 +00:00
if (nAction != 1 && pTarget != nullptr)
2021-10-15 19:29:24 +00:00
{
if (!(pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL))
2021-10-15 19:29:24 +00:00
{
2021-10-23 17:31:53 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
pActor->nCount = 100;
2021-10-17 20:03:08 +00:00
pActor->pTarget = nullptr;
2021-12-23 16:04:12 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
}
}
}
2021-10-15 19:29:24 +00:00
END_PS_NS