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

401 lines
9.2 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 "exhumed.h"
#include "engine.h"
#include "sequence.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq RoachSeq[] = {
{24, 0},
{0, 0},
{0, 0},
{16, 0},
{8, 0},
{32, 1},
{42, 1}
};
struct Roach
{
short nHealth;
2020-11-29 19:47:55 +00:00
short nFrame;
short nAction;
short nSprite;
short nTarget;
2020-11-29 19:47:55 +00:00
short nRun;
short nCount;
short nIndex;
};
// TODO - make nType a bool?
2021-10-18 16:54:35 +00:00
void BuildRoach(int nType, DExhumedActor* pActor, int x, int y, int z, short nSector, int angle)
{
2021-10-18 16:54:35 +00:00
spritetype* pSprite;
if (pActor == nullptr)
{
2021-10-18 16:54:35 +00:00
pActor = insertActor(nSector, 105);
pSprite = &pActor->s();
}
else
{
2021-10-18 16:54:35 +00:00
ChangeActorStat(pActor, 105);
pSprite = &pActor->s();
x = pSprite->x;
y = pSprite->y;
z = sector[pSprite->sectnum].floorz;
angle = pSprite->ang;
}
pSprite->x = x;
pSprite->y = y;
pSprite->z = z;
pSprite->cstat = 0x101;
pSprite->shade = -12;
pSprite->xoffset = 0;
pSprite->yoffset = 0;
pSprite->picnum = 1;
pSprite->pal = sector[pSprite->sectnum].ceilingpal;
pSprite->clipdist = 60;
pSprite->ang = angle;
pSprite->xrepeat = 40;
pSprite->yrepeat = 40;
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
pSprite->hitag = 0;
pSprite->lotag = runlist_HeadRun() + 1;
pSprite->extra = -1;
// GrabTimeSlot(3);
if (nType)
{
2021-10-18 16:54:35 +00:00
pActor->nAction = 0;
}
else
{
2021-10-18 16:54:35 +00:00
pActor->nAction = 1;
}
2021-10-18 16:54:35 +00:00
pActor->nFrame = 0;
pActor->nCount = 0;
pActor->pTarget = nullptr;
pActor->nHealth = 600;
pActor->nPhase = Counters[kCountRoach]++;
2021-10-18 16:54:35 +00:00
pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, pActor, 0x1C0000);
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x1C0000);
nCreaturesTotal++;
}
2021-10-18 16:54:35 +00:00
void GoRoach(spritetype* pSprite)
{
pSprite->xvel = bcos(pSprite->ang, -1) - bcos(pSprite->ang, -3);
pSprite->yvel = bsin(pSprite->ang, -1) - bsin(pSprite->ang, -3);
}
2021-10-15 21:07:38 +00:00
void AIRoach::Draw(RunListEvent* ev)
{
2021-10-18 16:54:35 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-24 10:10:18 +00:00
short nAction = pActor->nAction;
2021-10-24 10:10:18 +00:00
seq_PlotSequence(ev->nParam, RoachSeq[nAction].a + SeqOffsets[kSeqRoach], pActor->nFrame, RoachSeq[nAction].b);
2021-10-15 21:07:38 +00:00
return;
}
void AIRoach::RadialDamage(RunListEvent* ev)
{
2021-10-18 16:54:35 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 21:07:38 +00:00
Damage(ev);
}
void AIRoach::Damage(RunListEvent* ev)
{
2021-10-18 16:54:35 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:07:38 +00:00
2021-10-18 16:54:35 +00:00
auto pSprite = &pActor->s();
2021-10-24 10:10:18 +00:00
short nAction = pActor->nAction;
2021-10-15 21:07:38 +00:00
if (ev->nDamage)
{
2021-10-24 10:10:18 +00:00
if (pActor->nHealth <= 0) {
return;
}
2021-10-24 10:10:18 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
if (pActor->nHealth <= 0)
{
2021-10-15 21:07:38 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
pSprite->cstat &= 0xFEFE;
2021-10-24 10:10:18 +00:00
pActor->nHealth = 0;
2021-10-15 21:07:38 +00:00
if (nAction < 5)
{
2021-10-18 16:54:35 +00:00
DropMagic(pActor);
2021-10-24 10:10:18 +00:00
pActor->nAction = 5;
pActor->nFrame = 0;
2021-10-15 21:07:38 +00:00
}
nCreaturesKilled++; // NOTE: This was incrementing in original code. Bug?
}
2021-10-15 21:07:38 +00:00
else
{
2021-10-18 16:54:35 +00:00
auto pSprite2 = ev->pOtherActor;
if (pSprite2)
{
2021-10-18 16:54:35 +00:00
if (pSprite2->s().statnum < 199) {
pActor->pTarget = pSprite2;
}
2021-10-15 21:07:38 +00:00
if (nAction == 0)
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 2;
2021-10-18 16:54:35 +00:00
GoRoach(pSprite);
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
}
else
{
2021-10-15 21:07:38 +00:00
if (!RandomSize(4))
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 4;
pActor->nFrame = 0;
}
}
}
}
2021-10-15 21:07:38 +00:00
}
}
2021-10-15 21:07:38 +00:00
void AIRoach::Tick(RunListEvent* ev)
{
2021-10-18 16:54:35 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:07:38 +00:00
2021-10-18 16:54:35 +00:00
auto pSprite = &pActor->s();
2021-10-24 10:10:18 +00:00
short nAction = pActor->nAction;
2021-10-15 21:07:38 +00:00
bool bVal = false;
2021-10-18 16:54:35 +00:00
Gravity(pActor);
2021-10-15 21:07:38 +00:00
2021-10-24 10:10:18 +00:00
int nSeq = SeqOffsets[kSeqRoach] + RoachSeq[pActor->nAction].a;
2021-10-15 21:07:38 +00:00
2021-10-24 10:10:18 +00:00
pSprite->picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-18 16:54:35 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-15 21:07:38 +00:00
2021-10-24 10:10:18 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 21:07:38 +00:00
{
bVal = true;
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
2021-10-15 21:07:38 +00:00
}
2021-10-24 10:10:18 +00:00
int nFlag = FrameFlag[SeqBase[nSeq] + pActor->nFrame];
2021-10-18 16:54:35 +00:00
auto pTarget = pActor->pTarget;
2021-10-15 21:07:38 +00:00
if (nAction > 5) {
return;
}
2021-10-15 21:07:38 +00:00
switch (nAction)
{
case 0:
{
2021-10-24 10:10:18 +00:00
if (pActor->nFrame == 1)
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nCount = RandomSize(6);
2021-10-15 21:07:38 +00:00
}
else
{
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
}
2021-10-15 21:07:38 +00:00
}
2021-10-18 16:54:35 +00:00
if (((pActor->nPhase & 0xF) == (totalmoves & 0xF)) && pTarget == nullptr)
2021-10-15 21:07:38 +00:00
{
2021-10-18 16:54:35 +00:00
auto pTarget = FindPlayer(pActor, 50);
if (pTarget)
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-18 16:54:35 +00:00
pActor->pTarget = pTarget;
GoRoach(pSprite);
}
2021-10-15 21:07:38 +00:00
}
return;
}
2021-10-15 21:07:38 +00:00
case 1:
{
// partly the same as case 0.
2021-10-18 16:54:35 +00:00
if (((pActor->nPhase & 0xF) == (totalmoves & 0xF)) && pTarget == nullptr)
2021-10-15 21:07:38 +00:00
{
2021-10-18 16:54:35 +00:00
auto pTarget = FindPlayer(pActor, 100);
if (pTarget)
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-18 16:54:35 +00:00
pActor->pTarget = pTarget;
GoRoach(pSprite);
2021-10-15 21:07:38 +00:00
}
}
2021-10-15 21:07:38 +00:00
return;
}
2021-10-15 21:07:38 +00:00
case 2:
{
2021-10-18 16:54:35 +00:00
if ((totalmoves & 0xF) == (pActor->nPhase & 0xF))
2021-10-15 21:07:38 +00:00
{
2021-10-18 16:54:35 +00:00
PlotCourseToSprite(pActor, pTarget);
GoRoach(pSprite);
2021-10-15 21:07:38 +00:00
}
2021-10-18 16:54:35 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
2021-10-18 16:54:35 +00:00
if (nMov.type == kHitSprite)
2021-10-15 21:07:38 +00:00
{
2021-10-18 16:54:35 +00:00
if (nMov.actor == pTarget)
2021-10-15 21:07:38 +00:00
{
// repeated below
2021-10-24 10:10:18 +00:00
pActor->nIndex = RandomSize(2) + 1;
pActor->nAction = 3;
2021-10-15 21:07:38 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
2021-10-18 16:54:35 +00:00
pSprite->ang = GetMyAngle(pTarget->s().x - pSprite->x, pTarget->s().y - pSprite->y);
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
2021-10-15 21:07:38 +00:00
}
else
{
pSprite->ang = (pSprite->ang + 256) & kAngleMask;
2021-10-18 16:54:35 +00:00
GoRoach(pSprite);
2021-10-15 21:07:38 +00:00
}
}
2021-10-18 16:54:35 +00:00
else if (nMov.type == kHitWall)
2021-10-15 21:07:38 +00:00
{
pSprite->ang = (pSprite->ang + 256) & kAngleMask;
2021-10-18 16:54:35 +00:00
GoRoach(pSprite);
2021-10-15 21:07:38 +00:00
}
else
{
2021-10-24 10:10:18 +00:00
if (pActor->nCount != 0)
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nCount--;
2021-10-15 21:07:38 +00:00
}
else
{
// same as above
2021-10-24 10:10:18 +00:00
pActor->nIndex = RandomSize(2) + 1;
pActor->nAction = 3;
2021-10-15 21:07:38 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
2021-10-18 16:54:35 +00:00
pSprite->ang = GetMyAngle(pTarget->s().x - pSprite->x, pTarget->s().y - pSprite->y);
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
2021-10-15 21:07:38 +00:00
}
}
2021-10-18 16:54:35 +00:00
if (pTarget && !(pTarget->s().cstat & 0x101))
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
pActor->nCount = 100;
2021-10-18 16:54:35 +00:00
pActor->pTarget = nullptr;
2021-10-15 21:07:38 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
}
2021-10-15 21:07:38 +00:00
return;
}
2021-10-15 21:07:38 +00:00
case 3:
{
if (bVal)
{
2021-10-24 10:10:18 +00:00
pActor->nIndex--;
if (pActor->nIndex <= 0)
2021-10-15 21:07:38 +00:00
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 2;
2021-10-18 16:54:35 +00:00
GoRoach(pSprite);
2021-10-24 10:10:18 +00:00
pActor->nFrame = 0;
pActor->nCount = RandomSize(7);
2021-10-15 21:07:38 +00:00
}
}
else
{
if (nFlag & 0x80)
{
2021-10-18 16:54:35 +00:00
BuildBullet(pActor, 13, -1, pSprite->ang, pTarget, 1);
2021-10-15 21:07:38 +00:00
}
}
2021-10-15 21:07:38 +00:00
return;
}
2021-10-15 21:07:38 +00:00
case 4:
{
if (bVal)
{
2021-10-24 10:10:18 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 21:07:38 +00:00
}
2021-10-15 21:07:38 +00:00
return;
}
2021-10-15 21:07:38 +00:00
case 5:
{
if (bVal)
{
pSprite->cstat = 0;
2021-10-24 10:10:18 +00:00
pActor->nAction = 6;
pActor->nFrame = 0;
}
2021-10-15 21:07:38 +00:00
return;
}
}
}
2021-10-15 21:07:38 +00:00
void FuncRoach(int nObject, int nMessage, int nDamage, int nRun)
{
AIRoach ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
END_PS_NS