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

403 lines
9.8 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
DExhumedActor* BuildSpider(DExhumedActor* spp, const DVector3& pos, sectortype* pSector, int nAngle)
{
2021-10-18 18:05:33 +00:00
if (spp == nullptr)
{
2021-11-22 23:35:29 +00:00
spp = insertActor(pSector, 99);
spp->spr.pos = pos;
}
else
{
2021-10-18 18:05:33 +00:00
ChangeActorStat(spp, 99);
spp->spr.pos.Z = spp->sector()->floorz;
2022-08-16 21:17:01 +00:00
nAngle = spp->int_ang();
}
2021-12-23 16:12:23 +00:00
spp->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
spp->spr.shade = -12;
spp->spr.clipdist = 15;
2022-09-03 08:02:25 +00:00
spp->vel.X = 0;
spp->vel.Y = 0;
spp->vel.Z = 0;
2021-12-23 16:12:23 +00:00
spp->spr.xrepeat = 40;
spp->spr.yrepeat = 40;
spp->spr.pal = spp->sector()->ceilingpal;
2021-12-23 16:12:23 +00:00
spp->spr.xoffset = 0;
spp->spr.yoffset = 0;
2022-08-16 21:21:10 +00:00
spp->set_int_ang(nAngle);
2021-12-23 16:12:23 +00:00
spp->spr.picnum = 1;
spp->spr.hitag = 0;
spp->spr.lotag = runlist_HeadRun() + 1;
spp->spr.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]++;
spp->spr.intowner = runlist_AddRunRec(spp->spr.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;
int nAction = spp->nAction;
2021-10-15 21:25:20 +00:00
int nVel = 6;
if (spp->nHealth)
{
2021-12-23 16:12:23 +00:00
if (spp->spr.cstat & CSTAT_SPRITE_YFLIP)
{
2022-08-20 14:38:47 +00:00
spp->spr.pos.Z = spp->sector()->ceilingz + GetActorHeightF(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;
2021-12-23 16:12:23 +00:00
spp->spr.picnum = seq_GetSeqPicnum2(nSeq, spp->nFrame);
2021-10-15 21:25:20 +00:00
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-12-07 17:53:02 +00:00
DExhumedActor* pTarget = spp->pTarget;
2021-10-15 21:25:20 +00:00
if (pTarget == nullptr || pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL)
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
2022-09-01 14:57:55 +00:00
spp->set_int_xvel(bcos(spp->int_ang()));
2022-09-01 15:21:08 +00:00
spp->set_int_yvel(bsin(spp->int_ang()));
2021-10-15 21:25:20 +00:00
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:
auto pSector =spp->sector();
2021-12-23 16:12:23 +00:00
if (spp->spr.cstat & CSTAT_SPRITE_YFLIP)
{
2022-09-03 08:02:25 +00:00
spp->vel.Z = 0;
spp->spr.pos.Z = pSector->ceilingz + (tileHeight(spp->spr.picnum) / 8.); // was << 5 in Build coordinates
2019-12-05 19:40:53 +00:00
if (pSector->ceilingstat & CSTAT_SECTOR_SKY)
2019-12-05 19:40:53 +00:00
{
2021-12-23 16:12:23 +00:00
spp->spr.cstat ^= CSTAT_SPRITE_YFLIP;
2022-08-31 22:28:40 +00:00
spp->set_int_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
{
2022-09-01 14:57:55 +00:00
spp->set_int_xvel(bcos(spp->int_ang()));
2022-09-01 15:21:08 +00:00
spp->set_int_yvel(bsin(spp->int_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
{
2022-09-03 08:02:25 +00:00
spp->vel.X = 0;
spp->vel.Y = 0;
2019-12-05 19:40:53 +00:00
}
2021-10-15 21:25:20 +00:00
if (spp->nAction == 1 && RandomBit())
{
2021-12-23 16:12:23 +00:00
if (spp->spr.cstat & CSTAT_SPRITE_YFLIP)
{
2021-12-23 16:12:23 +00:00
spp->spr.cstat ^= CSTAT_SPRITE_YFLIP;
2022-08-31 22:28:40 +00:00
spp->set_int_zvel(1);
2022-08-20 14:38:47 +00:00
spp->spr.pos.Z = spp->sector()->ceilingz+ GetActorHeightF(spp);
}
2021-10-15 21:25:20 +00:00
else
{
2022-08-31 22:28:40 +00:00
spp->set_int_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(spp->spr.intowner);
2021-12-23 16:12:23 +00:00
runlist_FreeRun(spp->spr.lotag - 1);
2021-10-15 21:25:20 +00:00
runlist_SubRunRec(spp->nRun);
2021-12-23 16:12:23 +00:00
spp->spr.cstat = CSTAT_SPRITE_INVISIBLE;
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;
2022-09-03 08:02:25 +00:00
spp->vel.X = 0;
spp->vel.Y = 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;
2022-09-03 08:02:25 +00:00
spp->vel.X = 0;
spp->vel.Y = 0;
2021-10-15 21:25:20 +00:00
}
2022-09-01 15:24:37 +00:00
auto nMov = movesprite(spp, spp->int_xvel() << nVel, spp->int_yvel() << nVel, spp->int_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
if (nMov.exbits & kHitAux1
&& spp->float_zvel() < 0
2021-10-21 21:41:54 +00:00
&& hiHit.type != kHitSprite
&& !((spp->sector()->ceilingstat) & CSTAT_SECTOR_SKY))
2021-10-15 21:25:20 +00:00
{
2021-12-23 16:12:23 +00:00
spp->spr.cstat |= CSTAT_SPRITE_YFLIP;
2022-08-20 14:38:47 +00:00
spp->spr.pos.Z = spp->sector()->ceilingz + GetActorHeightF(spp);
2022-09-03 08:02:25 +00:00
spp->vel.Z = 0;
2021-10-15 21:25:20 +00:00
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
{
2022-08-16 21:21:10 +00:00
spp->set_int_ang((spp->int_ang() + 256) & 0x7EF);
2022-09-01 14:57:55 +00:00
spp->set_int_xvel(bcos(spp->int_ang()));
2022-09-01 15:21:08 +00:00
spp->set_int_yvel(bsin(spp->int_ang()));
2021-10-15 21:25:20 +00:00
return;
}
2021-10-18 18:05:33 +00:00
case kHitSprite:
2021-10-15 21:25:20 +00:00
{
2021-11-26 13:26:03 +00:00
if (nMov.actor() == pTarget)
2021-10-15 21:25:20 +00:00
{
2022-08-20 14:26:01 +00:00
auto nAngDiff = AngleDiff(spp->spr.angle, VecToAngle(pTarget->spr.pos - spp->spr.pos));
if (nAngDiff < 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;
int 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;
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)
*/
if (pTarget && pTarget->spr.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;
2021-12-23 16:12:23 +00:00
spp->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 21:25:20 +00:00
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
}
}
END_PS_NS