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

418 lines
9.6 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 "sound.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq SpiderSeq[] = {
{16, 0},
{8, 0},
{32, 0},
{24, 0},
{0, 0},
{40, 1},
{41, 1}
};
2019-12-05 19:40:53 +00:00
2021-10-18 18:05:33 +00:00
DExhumedActor* BuildSpider(DExhumedActor* spp, int x, int y, int z, short nSector, int nAngle)
{
spritetype* sp;
2021-10-18 18:05:33 +00:00
if (spp == nullptr)
{
2021-10-18 18:05:33 +00:00
spp = insertActor(nSector, 99);
sp = &spp->s();
}
else
{
2021-10-18 18:05:33 +00:00
ChangeActorStat(spp, 99);
sp = &spp->s();
x = sp->x;
y = sp->y;
z = sector[sp->sectnum].floorz;
nAngle = sp->ang;
}
sp->x = x;
sp->y = y;
sp->z = z;
sp->cstat = 0x101;
sp->shade = -12;
sp->clipdist = 15;
sp->xvel = 0;
sp->yvel = 0;
sp->zvel = 0;
sp->xrepeat = 40;
sp->yrepeat = 40;
sp->pal = sector[sp->sectnum].ceilingpal;
sp->xoffset = 0;
sp->yoffset = 0;
sp->ang = nAngle;
sp->picnum = 1;
sp->hitag = 0;
sp->lotag = runlist_HeadRun() + 1;
sp->extra = -1;
2019-12-05 19:40:53 +00:00
// GrabTimeSlot(3);
spp->nAction = 0;
spp->nFrame = 0;
2021-10-18 18:05:33 +00:00
spp->pTarget = nullptr;
spp->nHealth = 160;
2021-10-18 18:05:33 +00:00
spp->nPhase = Counters[kCountSpider]++;
2021-10-18 18:05:33 +00:00
sp->owner = runlist_AddRunRec(sp->lotag - 1, spp, 0xC0000);
2021-10-18 18:05:33 +00:00
spp->nRun = runlist_AddRunRec(NewRun, spp, 0xC0000);
nCreaturesTotal++;
2021-10-18 18:05:33 +00:00
return spp;
}
2021-10-15 21:25:20 +00:00
void AISpider::Tick(RunListEvent* ev)
{
2021-10-18 18:05:33 +00:00
auto spp = ev->pObjActor;
if (!spp) return;
2021-10-18 18:05:33 +00:00
auto sp = &spp->s();
short nAction = spp->nAction;
2021-10-15 21:25:20 +00:00
int nVel = 6;
if (spp->nHealth)
{
2021-10-15 21:25:20 +00:00
if (sp->cstat & 8)
{
2021-10-18 18:05:33 +00:00
sp->z = sector[sp->sectnum].ceilingz + GetActorHeight(spp);
2021-10-15 21:25:20 +00:00
}
else
{
2021-10-18 18:05:33 +00:00
Gravity(spp);
}
2021-10-15 21:25:20 +00:00
}
int nSeq = SeqOffsets[kSeqSpider] + SpiderSeq[nAction].a;
sp->picnum = seq_GetSeqPicnum2(nSeq, spp->nFrame);
2021-10-18 18:05:33 +00:00
seq_MoveSequence(spp, nSeq, spp->nFrame);
2021-10-15 21:25:20 +00:00
int nFrameFlag = FrameFlag[SeqBase[nSeq] + spp->nFrame];
2021-10-15 21:25:20 +00:00
spp->nFrame++;
if (spp->nFrame >= SeqSize[nSeq]) {
spp->nFrame = 0;
}
2021-10-18 18:05:33 +00:00
auto pTarget = spp->pTarget;
2021-10-15 21:25:20 +00:00
2021-10-18 18:05:33 +00:00
if (pTarget == nullptr || pTarget->s().cstat & 0x101)
2021-10-15 21:25:20 +00:00
{
switch (nAction)
{
2021-10-15 21:25:20 +00:00
default:
return;
2021-10-15 21:25:20 +00:00
case 0:
{
2021-10-18 18:05:33 +00:00
if ((spp->nPhase & 0x1F) == (totalmoves & 0x1F))
{
2021-10-18 18:05:33 +00:00
if (pTarget == nullptr) {
pTarget = FindPlayer(spp, 100);
}
2021-10-15 21:25:20 +00:00
2021-10-18 18:05:33 +00:00
if (pTarget)
{
2021-10-15 21:25:20 +00:00
spp->nAction = 1;
spp->nFrame = 0;
2021-10-18 18:05:33 +00:00
spp->pTarget = pTarget;
2021-10-15 21:25:20 +00:00
sp->xvel = bcos(sp->ang);
sp->yvel = bsin(sp->ang);
return;
}
}
2021-10-15 21:25:20 +00:00
break;
}
case 1:
{
2021-10-18 18:05:33 +00:00
if (pTarget) {
2021-10-15 21:25:20 +00:00
nVel++;
}
goto case_3;
break;
}
case 4:
{
if (!spp->nFrame)
{
spp->nFrame = 0;
2021-10-15 21:25:20 +00:00
spp->nAction = 1;
}
2021-10-18 18:05:33 +00:00
[[fallthrough]];
2021-10-15 21:25:20 +00:00
}
case 3:
{
case_3:
short nSector = sp->sectnum;
2021-10-15 21:25:20 +00:00
if (sp->cstat & 8)
{
2021-10-15 21:25:20 +00:00
sp->zvel = 0;
sp->z = sector[nSector].ceilingz + (tileHeight(sp->picnum) << 5);
2019-12-05 19:40:53 +00:00
2021-10-15 21:25:20 +00:00
if (sector[nSector].ceilingstat & 1)
2019-12-05 19:40:53 +00:00
{
2021-10-15 21:25:20 +00:00
sp->cstat ^= 8;
sp->zvel = 1;
2021-10-15 21:25:20 +00:00
spp->nAction = 3;
spp->nFrame = 0;
2019-12-05 19:40:53 +00:00
}
2021-10-15 21:25:20 +00:00
}
2021-10-18 18:05:33 +00:00
if ((totalmoves & 0x1F) == (spp->nPhase & 0x1F))
2021-10-15 21:25:20 +00:00
{
2021-10-18 18:05:33 +00:00
PlotCourseToSprite(spp, pTarget);
2021-10-15 21:25:20 +00:00
if (RandomSize(3))
2019-12-05 19:40:53 +00:00
{
2021-10-15 21:25:20 +00:00
sp->xvel = bcos(sp->ang);
sp->yvel = bsin(sp->ang);
2019-12-05 19:40:53 +00:00
}
2021-10-15 21:25:20 +00:00
else
2019-12-05 19:40:53 +00:00
{
2021-10-15 21:25:20 +00:00
sp->xvel = 0;
sp->yvel = 0;
2019-12-05 19:40:53 +00:00
}
2021-10-15 21:25:20 +00:00
if (spp->nAction == 1 && RandomBit())
{
if (sp->cstat & 8)
{
2021-10-15 21:25:20 +00:00
sp->cstat ^= 8;
sp->zvel = 1;
2021-10-18 18:05:33 +00:00
sp->z = sector[nSector].ceilingz + GetActorHeight(spp);
}
2021-10-15 21:25:20 +00:00
else
{
2021-10-15 21:25:20 +00:00
sp->zvel = -5120;
}
2019-12-05 19:40:53 +00:00
2021-10-15 21:25:20 +00:00
spp->nAction = 3;
spp->nFrame = 0;
2021-10-15 21:25:20 +00:00
if (!RandomSize(3)) {
2021-10-18 18:05:33 +00:00
D3PlayFX(StaticSound[kSound29], spp);
2019-12-05 19:40:53 +00:00
}
}
2021-10-15 21:25:20 +00:00
}
break;
}
case 5:
{
if (!spp->nFrame)
{
runlist_DoSubRunRec(sp->owner);
runlist_FreeRun(sp->lotag - 1);
runlist_SubRunRec(spp->nRun);
sp->cstat = 0x8000;
2021-10-18 18:05:33 +00:00
DeleteActor(spp);
2021-10-15 21:25:20 +00:00
}
return;
}
case 2:
{
2021-10-18 18:05:33 +00:00
if (pTarget)
2021-10-15 21:25:20 +00:00
{
if (nFrameFlag & 0x80)
{
2021-10-18 18:05:33 +00:00
runlist_DamageEnemy(pTarget, spp, 3);
D3PlayFX(StaticSound[kSound38], spp);
2021-10-15 21:25:20 +00:00
}
2021-10-18 18:05:33 +00:00
if (PlotCourseToSprite(spp, pTarget) < 1024) {
2021-10-15 21:25:20 +00:00
return;
}
2021-10-15 21:25:20 +00:00
spp->nAction = 1;
}
else
{
spp->nAction = 0;
sp->xvel = 0;
sp->yvel = 0;
}
2021-10-15 21:25:20 +00:00
spp->nFrame = 0;
break;
}
}
}
else
{
2021-10-18 18:05:33 +00:00
spp->pTarget = nullptr;
2021-10-15 21:25:20 +00:00
spp->nAction = 0;
spp->nFrame = 0;
2021-10-15 21:25:20 +00:00
sp->xvel = 0;
sp->yvel = 0;
}
2021-10-18 18:05:33 +00:00
auto nMov = movesprite(spp, sp->xvel << nVel, sp->yvel << nVel, sp->zvel, 1280, -1280, CLIPMASK0);
2021-10-18 18:05:33 +00:00
if (nMov.type == kHitNone && nMov.exbits == 0)
2021-10-15 21:25:20 +00:00
return;
2021-10-18 18:05:33 +00:00
Collision HiHit(hihit); // fixme
if (nMov.exbits & kHitAux1
2021-10-15 21:25:20 +00:00
&& sp->zvel < 0
2021-10-18 18:05:33 +00:00
&& HiHit.type != kHitSprite
2021-10-15 21:25:20 +00:00
&& !((sector[sp->sectnum].ceilingstat) & 1))
{
sp->cstat |= 8;
2021-10-18 18:05:33 +00:00
sp->z = GetActorHeight(spp) + sector[sp->sectnum].ceilingz;
2021-10-15 21:25:20 +00:00
sp->zvel = 0;
spp->nAction = 1;
spp->nFrame = 0;
return;
}
else
{
2021-10-18 18:05:33 +00:00
switch (nMov.type)
2021-10-15 21:25:20 +00:00
{
2021-10-18 18:05:33 +00:00
case kHitWall:
2021-10-15 21:25:20 +00:00
{
sp->ang = (sp->ang + 256) & 0x7EF;
sp->xvel = bcos(sp->ang);
sp->yvel = bsin(sp->ang);
return;
}
2021-10-18 18:05:33 +00:00
case kHitSprite:
2021-10-15 21:25:20 +00:00
{
2021-10-18 18:05:33 +00:00
if (nMov.actor == pTarget)
2021-10-15 21:25:20 +00:00
{
2021-10-18 18:05:33 +00:00
int nAng = getangle(pTarget->s().x - sp->x, pTarget->s().y - sp->y);
2021-10-15 21:25:20 +00:00
if (AngleDiff(sp->ang, nAng) < 64)
{
2021-10-15 21:25:20 +00:00
spp->nAction = 2;
spp->nFrame = 0;
}
}
return;
}
2021-10-15 21:25:20 +00:00
default:
break;
}
2021-10-15 21:25:20 +00:00
if (spp->nAction == 3)
{
2021-10-15 21:25:20 +00:00
spp->nAction = 1;
spp->nFrame = 0;
}
2021-10-15 21:25:20 +00:00
return;
}
2021-10-15 21:25:20 +00:00
return;
}
2021-10-15 21:25:20 +00:00
void AISpider::Draw(RunListEvent* ev)
{
2021-10-18 18:05:33 +00:00
auto spp = ev->pObjActor;
if (!spp) return;
2021-10-15 21:25:20 +00:00
short nAction = spp->nAction;
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqSpider] + SpiderSeq[nAction].a, spp->nFrame, SpiderSeq[nAction].b);
2021-10-15 21:25:20 +00:00
}
2021-10-15 21:25:20 +00:00
void AISpider::RadialDamage(RunListEvent* ev)
{
2021-10-18 18:05:33 +00:00
auto spp = ev->pObjActor;
if (!spp) return;
2019-12-05 19:40:53 +00:00
2021-10-15 21:25:20 +00:00
if (spp->nHealth <= 0)
return;
2019-12-05 19:40:53 +00:00
2021-10-18 18:05:33 +00:00
ev->nDamage = runlist_CheckRadialDamage(spp);
2021-10-15 21:25:20 +00:00
Damage(ev);
}
2021-10-15 21:25:20 +00:00
void AISpider::Damage(RunListEvent* ev)
{
2021-10-18 18:05:33 +00:00
auto spp = ev->pObjActor;
if (!spp) return;
auto sp = &spp->s();
2021-10-15 21:25:20 +00:00
if (!ev->nDamage)
return;
2021-10-18 18:05:33 +00:00
DExhumedActor* pTarget = ev->pOtherActor;
2021-10-15 21:25:20 +00:00
spp->nHealth -= dmgAdjust(ev->nDamage);
if (spp->nHealth > 0)
{
/*
NOTE:
nTarget check was added, but should we return if it's invalid instead
or should code below (action set, b set) happen?
Other AI doesn't show consistency in this regard (see Scorpion code)
*/
2021-10-18 18:05:33 +00:00
if (pTarget && pTarget->s().statnum == 100)
2021-10-15 21:25:20 +00:00
{
2021-10-18 18:05:33 +00:00
spp->pTarget = pTarget;
}
2021-10-15 21:25:20 +00:00
spp->nAction = 4;
spp->nFrame = 0;
}
else
{
// creature is dead, make some chunks
spp->nHealth = 0;
spp->nAction = 5;
spp->nFrame = 0;
sp->cstat &= 0xFEFE;
nCreaturesKilled++;
for (int i = 0; i < 7; i++)
{
2021-10-26 19:15:07 +00:00
BuildCreatureChunk(spp, seq_GetSeqPicnum(kSeqSpider, i + 41, 0));
}
2021-10-15 21:25:20 +00:00
}
}
void FuncSpider(int nObject, int nMessage, int nDamage, int nRun)
{
AISpider ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
END_PS_NS