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

367 lines
8.1 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 <assert.h>
BEGIN_PS_NS
static actionSeq WaspSeq[] = {
{0, 0},
{0, 0},
{9, 0},
{18, 0},
{27, 1},
{28, 1},
{29, 1}
};
2021-10-24 11:20:50 +00:00
void SetWaspVel(spritetype* pSprite)
2020-11-29 20:09:41 +00:00
{
pSprite->xvel = bcos(pSprite->ang);
pSprite->yvel = bsin(pSprite->ang);
}
DExhumedActor* BuildWasp(DExhumedActor* pActor, int x, int y, int z, sectortype* pSector, int nAngle, bool bEggWasp)
{
2021-10-24 11:20:50 +00:00
spritetype* pSprite;
if (pActor == nullptr)
{
pActor = insertActor(pSector, 107);
2021-10-24 11:20:50 +00:00
pSprite = &pActor->s();
pSprite->x = x;
pSprite->y = y;
pSprite->z = z;
}
else
{
2021-10-24 11:20:50 +00:00
pSprite = &pActor->s();
nAngle = pSprite->ang;
2021-10-24 11:20:50 +00:00
ChangeActorStat(pActor, 107);
}
pSprite->shade = -12;
pSprite->cstat = 0x101;
pSprite->pal = pSprite->sector()->ceilingpal;
pSprite->clipdist = 70;
if (bEggWasp)
{
pSprite->xrepeat = 20;
pSprite->yrepeat = 20;
}
else
{
pSprite->xrepeat = 50;
pSprite->yrepeat = 50;
}
pSprite->xoffset = 0;
pSprite->yoffset = 0;
pSprite->picnum = 1;
pSprite->ang = nAngle;
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
pSprite->hitag = 0;
pSprite->lotag = runlist_HeadRun() + 1;
pSprite->extra = -1;
2021-10-15 21:29:25 +00:00
// GrabTimeSlot(3);
2021-10-24 11:15:40 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
2021-10-24 11:20:50 +00:00
pActor->pTarget = nullptr;
2021-10-24 11:15:40 +00:00
pActor->nHealth = 800;
pActor->nDamage = 10;
2021-10-24 11:20:50 +00:00
pActor->nPhase = Counters[kCountWasp]++;
if (bEggWasp)
{
2021-10-24 11:15:40 +00:00
pActor->nCount = 60;
pActor->nDamage /= 2;
}
else
{
2021-10-24 11:15:40 +00:00
pActor->nCount = RandomSize(5);
}
2021-10-24 11:15:40 +00:00
pActor->nAngle = 0;
pActor->nVel = 0;
pActor->nAngle2 = RandomSize(7) + 127;
2021-10-24 11:20:50 +00:00
pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, pActor, 0x1E0000);
2021-10-24 11:20:50 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x1E0000);
nCreaturesTotal++;
2021-10-24 11:20:50 +00:00
return pActor;
}
2021-10-15 21:29:25 +00:00
void AIWasp::Draw(RunListEvent* ev)
{
2021-10-24 11:20:50 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 21:29:25 +00:00
2021-10-24 11:15:40 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqWasp] + WaspSeq[nAction].a, pActor->nFrame, WaspSeq[nAction].b);
2021-10-15 21:29:25 +00:00
return;
}
void AIWasp::RadialDamage(RunListEvent* ev)
{
2021-10-24 11:20:50 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
auto pSprite = &pActor->s();
2021-10-15 21:29:25 +00:00
if (!(pSprite->cstat & 0x101))
return;
2021-10-24 11:20:50 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 21:29:25 +00:00
Damage(ev);
}
void AIWasp::Damage(RunListEvent* ev)
{
2021-10-24 11:20:50 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
auto pSprite = &pActor->s();
2021-10-15 21:29:25 +00:00
if (!ev->nDamage) {
return;
}
2021-10-24 11:15:40 +00:00
if (pActor->nHealth > 0)
2021-10-15 21:29:25 +00:00
{
2021-10-24 11:15:40 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage, 3);
2021-10-15 21:29:25 +00:00
2021-10-24 11:15:40 +00:00
if (pActor->nHealth > 0)
2021-10-15 21:29:25 +00:00
{
if (!RandomSize(4))
{
2021-10-24 11:15:40 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
2021-10-15 21:29:25 +00:00
}
2021-10-24 11:15:40 +00:00
pActor->nAction = 1;
2021-10-15 21:29:25 +00:00
pSprite->ang += RandomSize(9) + 768;
pSprite->ang &= kAngleMask;
2021-10-24 11:15:40 +00:00
pActor->nVel = 3000;
2021-10-15 21:29:25 +00:00
pSprite->zvel = (-20) - RandomSize(6);
}
else
{
// Wasp is dead
2021-10-24 11:15:40 +00:00
pActor->nAction = 4;
pActor->nFrame = 0;
2021-10-15 21:29:25 +00:00
pSprite->cstat = 0;
pSprite->ang = (pSprite->ang + 1024) & kAngleMask;
2021-10-24 11:20:50 +00:00
SetWaspVel(pSprite);
2021-10-15 21:29:25 +00:00
pSprite->zvel = 512;
nCreaturesKilled++;
}
}
return;
}
void AIWasp::Tick(RunListEvent* ev)
{
2021-10-24 11:20:50 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
auto pSprite = &pActor->s();
int nAction = pActor->nAction;
2021-10-24 11:20:50 +00:00
DExhumedActor* pTarget = nullptr;
bool bVal = false;
int nSeq = SeqOffsets[kSeqWasp] + WaspSeq[nAction].a;
2021-10-15 21:29:25 +00:00
2021-10-24 11:15:40 +00:00
pSprite->picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-15 21:29:25 +00:00
2021-10-24 11:20:50 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-15 21:29:25 +00:00
2021-10-24 11:15:40 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 21:29:25 +00:00
{
2021-10-24 11:15:40 +00:00
pActor->nFrame = 0;
2021-10-15 21:29:25 +00:00
bVal = true;
}
2021-10-24 11:15:40 +00:00
if (pActor->nHealth > 0)
{
2021-10-24 11:20:50 +00:00
pTarget = pActor->pTarget;
2021-10-15 21:29:25 +00:00
if (pTarget && (!(pTarget->s().cstat & 0x101) || (pTarget->s().sector()->Flag & kSectUnderwater)))
{
2021-10-15 21:29:25 +00:00
// goto pink
2021-10-24 11:20:50 +00:00
pActor->pTarget = nullptr;
2021-10-24 11:15:40 +00:00
pActor->nAction = 0;
pActor->nCount = RandomSize(6);
return;
}
2021-10-15 21:29:25 +00:00
}
2021-10-15 21:29:25 +00:00
switch (nAction)
{
default:
return;
2021-10-15 21:29:25 +00:00
case 0:
{
2021-10-24 11:15:40 +00:00
pSprite->zvel = bsin(pActor->nAngle, -4);
2021-10-24 11:15:40 +00:00
pActor->nAngle += pActor->nAngle2;
pActor->nAngle &= kAngleMask;
2021-10-15 21:29:25 +00:00
2021-10-24 11:20:50 +00:00
MoveCreature(pActor);
2021-10-15 21:29:25 +00:00
2021-10-24 11:20:50 +00:00
if (pTarget)
{
2021-10-24 11:15:40 +00:00
pActor->nCount--;
if (pActor->nCount > 0)
2021-10-15 21:29:25 +00:00
{
2021-10-24 11:20:50 +00:00
PlotCourseToSprite(pActor, pTarget);
}
2021-10-15 21:29:25 +00:00
else
{
2021-10-15 21:29:25 +00:00
pSprite->zvel = 0;
2021-10-24 11:15:40 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
pActor->nVel = 1500;
pActor->nCount = RandomSize(5) + 60;
2021-10-15 21:29:25 +00:00
}
}
else
{
2021-10-24 11:20:50 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F)) {
pActor->pTarget = FindPlayer(pActor, 60);
2021-10-15 21:29:25 +00:00
}
}
2021-10-15 21:29:25 +00:00
return;
}
2021-10-15 21:29:25 +00:00
case 1:
{
2021-10-24 11:15:40 +00:00
pActor->nCount--;
2021-10-24 11:15:40 +00:00
if (pActor->nCount <= 0)
2021-10-15 21:29:25 +00:00
{
2021-10-24 11:15:40 +00:00
pActor->nAction = 0;
pActor->nCount = RandomSize(6);
2021-10-15 21:29:25 +00:00
return;
}
2021-10-24 11:20:50 +00:00
auto nChaseVal = AngleChase(pActor, pTarget, pActor->nVel, 0, 16);
2021-10-24 11:20:50 +00:00
switch (nChaseVal.type)
2021-10-15 21:29:25 +00:00
{
default:
return;
2021-10-24 11:20:50 +00:00
case kHitWall:
2021-10-15 21:29:25 +00:00
{
return;
}
2021-10-24 11:20:50 +00:00
case kHitSprite:
2021-10-15 21:29:25 +00:00
{
2021-11-26 13:26:03 +00:00
if (nChaseVal.actor() == pTarget)
2021-10-15 21:29:25 +00:00
{
pSprite->xvel = 0;
pSprite->yvel = 0;
2021-10-24 11:20:50 +00:00
runlist_DamageEnemy(pTarget, pActor, pActor->nDamage);
2021-10-24 11:15:40 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
}
return;
}
2021-10-15 21:29:25 +00:00
}
return;
}
2021-10-15 21:29:25 +00:00
case 2:
case 3:
{
if (bVal)
{
2021-10-15 21:29:25 +00:00
pSprite->ang += RandomSize(9) + 768;
pSprite->ang &= kAngleMask;
pSprite->zvel = (-20) - RandomSize(6);
2021-10-24 11:15:40 +00:00
pActor->nAction = 1;
pActor->nVel = 3000;
2021-10-15 21:29:25 +00:00
}
return;
}
case 4:
{
2021-10-24 11:20:50 +00:00
auto nMove = MoveCreature(pActor);
2021-10-24 11:20:50 +00:00
//if (nMove.type != kHitNone) // The code messed up the return value so this check always was true.
2021-10-15 21:29:25 +00:00
{
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 1024;
2021-10-24 11:15:40 +00:00
pActor->nAction = 5;
pActor->nFrame = 0;
2021-10-15 21:29:25 +00:00
}
2021-10-15 21:29:25 +00:00
return;
}
case 5:
{
2021-11-22 21:38:27 +00:00
auto pSector =pSprite->sector();
2021-10-15 21:29:25 +00:00
pSprite->z += pSprite->zvel;
2021-11-22 21:38:27 +00:00
if (pSprite->z >= pSector->floorz)
2021-10-15 21:29:25 +00:00
{
2021-11-22 22:05:48 +00:00
if (pSector->pBelow != nullptr)
{
2021-11-22 21:38:27 +00:00
BuildSplash(pActor, pSector);
2021-10-15 21:29:25 +00:00
pSprite->cstat |= 0x8000;
}
2021-10-15 21:29:25 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
2021-10-24 11:15:40 +00:00
pActor->nAction = 6;
pActor->nFrame = 0;
runlist_SubRunRec(pActor->nRun);
}
2021-10-15 21:29:25 +00:00
return;
}
2021-10-15 21:29:25 +00:00
}
}
END_PS_NS