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

432 lines
10 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, DAngle 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;
nAngle = spp->spr.Angles.Yaw;
}
2021-12-23 16:12:23 +00:00
spp->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
spp->spr.shade = -12;
spp->clipdist = 3.75;
2022-09-03 08:02:25 +00:00
spp->vel.X = 0;
spp->vel.Y = 0;
spp->vel.Z = 0;
spp->spr.scale = DVector2(0.625, 0.625);
spp->spr.pal = spp->sector()->ceilingpal;
2021-12-23 16:12:23 +00:00
spp->spr.xoffset = 0;
spp->spr.yoffset = 0;
spp->spr.Angles.Yaw = nAngle;
setvalidpic(spp);
2021-12-23 16:12:23 +00:00
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);
spp->nSeqFile = "spider";
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;
double nVel = 0.25;
2021-10-15 21:25:20 +00:00
if (spp->nHealth)
{
2021-12-23 16:12:23 +00:00
if (spp->spr.cstat & CSTAT_SPRITE_YFLIP)
{
spp->spr.pos.Z = spp->sector()->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
}
const auto spiderSeq = getSequence(spp->nSeqFile, SpiderSeq[nAction].nSeqId);
const auto& seqFrame = spiderSeq->frames[spp->nFrame];
2021-10-15 21:25:20 +00:00
spp->spr.setspritetexture(seqFrame.getFirstChunkTexture());
2021-10-15 21:25:20 +00:00
seqFrame.playSound(spp);
2021-10-15 21:25:20 +00:00
spp->nFrame++;
if (spp->nFrame >= spiderSeq->frames.Size()) {
2021-10-15 21:25:20 +00:00
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
spp->VelFromAngle();
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) {
nVel *= 2;
2021-10-15 21:25:20 +00:00
}
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;
auto tex = TexMan.GetGameTexture(spp->spr.spritetexture());
spp->spr.pos.Z = pSector->ceilingz + (tex->GetDisplayHeight() / 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-09-09 17:29:11 +00:00
spp->vel.Z = 1./256.;
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
{
spp->VelFromAngle();
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-09-09 17:29:11 +00:00
spp->vel.Z = 1./256.;
spp->spr.pos.Z = spp->sector()->ceilingz+ GetActorHeight(spp);
}
2021-10-15 21:25:20 +00:00
else
{
2022-09-09 17:29:11 +00:00
spp->vel.Z = -20;
}
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 (seqFrame.flags & 0x80)
2021-10-15 21:25:20 +00:00
{
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
}
if (PlotCourseToSprite(spp, pTarget) < 64) {
2021-10-15 21:25:20 +00:00
return;
}
2021-10-15 21:25:20 +00:00
spp->nAction = 1;
spp->nFrame = 0;
}
else
{
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
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
}
auto nMov = movespritevel(spp, spp->vel, nVel, -5, 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->vel.Z < 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;
spp->spr.pos.Z = spp->sector()->ceilingz + GetActorHeight(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
{
spp->spr.Angles.Yaw += DAngle45;
spp->VelFromAngle();
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
{
auto nAngDiff = absangle(spp->spr.Angles.Yaw, (pTarget->spr.pos - spp->spr.pos).Angle());
2022-09-10 22:18:09 +00:00
if (nAngDiff < DAngle22_5 / 2)
{
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)
{
if (const auto spp = ev->pObjActor)
{
const auto spiderSeq = &SpiderSeq[spp->nAction];
seq_PlotSequence(ev->nParam, spp->nSeqFile, spiderSeq->nSeqId, spp->nFrame, spiderSeq->nFlags);
}
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++;
const auto spiderSeqs = getFileSeqs("spider");
2021-10-15 21:25:20 +00:00
for (int i = 0; i < 7; i++)
{
BuildCreatureChunk(spp, spiderSeqs->Data(i + 41)->getFirstFrameTexture());
}
2021-10-15 21:25:20 +00:00
}
}
END_PS_NS