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

464 lines
11 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 "player.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq RexSeq[] = {
{29, 0},
{0, 0},
{0, 0},
{37, 0},
{9, 0},
{18, 0},
{27, 1},
{28, 1}
};
2021-10-17 22:28:59 +00:00
void BuildRex(DExhumedActor* pActor, int x, int y, int z, short nSector, short nAngle, int nChannel)
2020-11-29 19:43:35 +00:00
{
2021-10-17 22:28:59 +00:00
spritetype* pSprite;
if (pActor == nullptr)
2020-11-29 19:43:35 +00:00
{
2021-10-17 22:28:59 +00:00
pActor = insertActor(nSector, 119);
pSprite = &pActor->s();
}
else
{
2021-10-17 22:28:59 +00:00
pSprite = &pActor->s();
x = pSprite->x;
y = pSprite->y;
z = sector[pSprite->sectnum].floorz;
nAngle = pSprite->ang;
2021-10-17 22:28:59 +00:00
ChangeActorStat(pActor, 119);
}
pSprite->x = x;
pSprite->y = y;
pSprite->z = z;
pSprite->cstat = 0x101;
pSprite->clipdist = 80;
pSprite->shade = -12;
pSprite->xrepeat = 64;
pSprite->yrepeat = 64;
pSprite->picnum = 1;
pSprite->pal = sector[pSprite->sectnum].ceilingpal;
pSprite->xoffset = 0;
pSprite->yoffset = 0;
pSprite->ang = nAngle;
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
pSprite->lotag = runlist_HeadRun() + 1;
pSprite->extra = -1;
pSprite->hitag = 0;
GrabTimeSlot(3);
2021-10-24 08:58:27 +00:00
pActor->nAction = 0;
pActor->nHealth = 4000;
pActor->nFrame = 0;
2021-10-17 22:28:59 +00:00
pActor->pTarget = nullptr;
2021-10-24 08:58:27 +00:00
pActor->nCount = 0;
2021-10-17 22:28:59 +00:00
pActor->nPhase = Counters[kCountRex]++;
2021-10-17 22:28:59 +00:00
pActor->nRun = nChannel;
2021-10-17 22:28:59 +00:00
pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, pActor, 0x180000);
// this isn't stored anywhere.
2021-10-17 22:28:59 +00:00
runlist_AddRunRec(NewRun, pActor, 0x180000);
nCreaturesTotal++;
}
2021-10-15 21:03:09 +00:00
void AIRex::RadialDamage(RunListEvent* ev)
{
2021-10-17 22:28:59 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-24 08:58:27 +00:00
short nAction = pActor->nAction;
2021-10-15 21:03:09 +00:00
if (nAction == 5)
{
2021-10-17 22:28:59 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 21:03:09 +00:00
}
Damage(ev);
}
void AIRex::Damage(RunListEvent* ev)
{
2021-10-17 22:28:59 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
short nAction = pActor->nAction;
2021-10-17 22:28:59 +00:00
auto pSprite = &pActor->s();
2021-10-15 21:03:09 +00:00
if (ev->nDamage)
{
2021-10-17 22:28:59 +00:00
auto pTarget = ev->pOtherActor;
if (pTarget && pTarget->s().statnum == 100)
{
2021-10-17 22:28:59 +00:00
pActor->pTarget = pTarget;
}
2021-10-24 08:58:27 +00:00
if (pActor->nAction == 5 && pActor->nHealth > 0)
{
2021-10-24 08:58:27 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
if (pActor->nHealth <= 0)
{
2021-10-15 21:03:09 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
pSprite->zvel = 0;
pSprite->cstat &= 0xFEFE;
2021-10-24 08:58:27 +00:00
pActor->nHealth = 0;
2021-10-15 21:03:09 +00:00
nCreaturesKilled++;
if (nAction < 6)
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 6;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
}
}
}
2021-10-15 21:03:09 +00:00
}
}
void AIRex::Draw(RunListEvent* ev)
{
2021-10-17 22:28:59 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
short nAction = pActor->nAction;
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqRex] + RexSeq[nAction].a, pActor->nFrame, RexSeq[nAction].b);
2021-10-15 21:03:09 +00:00
return;
}
void AIRex::Tick(RunListEvent* ev)
{
2021-10-17 22:28:59 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
short nAction = pActor->nAction;
2021-10-17 22:28:59 +00:00
auto pSprite = &pActor->s();
2021-10-15 21:03:09 +00:00
bool bVal = false;
2021-10-17 22:28:59 +00:00
Gravity(pActor);
2021-10-15 21:03:09 +00:00
int nSeq = SeqOffsets[kSeqRex] + RexSeq[nAction].a;
2021-10-24 08:58:27 +00:00
pSprite->picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-15 21:03:09 +00:00
int ecx = 2;
if (nAction != 2) {
ecx = 1;
}
// moves the mouth open and closed as it's idle?
while (--ecx != -1)
{
2021-10-17 22:28:59 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-15 21:03:09 +00:00
2021-10-24 08:58:27 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 21:03:09 +00:00
{
2021-10-24 08:58:27 +00:00
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
bVal = true;
}
}
2021-10-24 08:58:27 +00:00
int nFlag = FrameFlag[SeqBase[nSeq] + pActor->nFrame];
2021-10-15 21:03:09 +00:00
2021-10-17 22:28:59 +00:00
auto pTarget = pActor->pTarget;
2021-10-15 21:03:09 +00:00
switch (nAction)
{
default:
return;
case 0:
{
2021-10-24 08:58:27 +00:00
if (!pActor->nCount)
{
2021-10-17 22:28:59 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
{
2021-10-17 22:28:59 +00:00
if (pTarget == nullptr)
{
2021-10-15 21:03:09 +00:00
short nAngle = pSprite->ang; // make backup of this variable
2021-10-17 22:28:59 +00:00
pActor->pTarget = FindPlayer(pActor, 60);
2021-10-15 21:03:09 +00:00
pSprite->ang = nAngle;
}
2021-10-15 21:03:09 +00:00
else
{
2021-10-24 08:58:27 +00:00
pActor->nCount = 60;
}
}
}
2021-10-15 21:03:09 +00:00
else
{
2021-10-24 08:58:27 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 21:03:09 +00:00
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
pSprite->xvel = bcos(pSprite->ang, -2);
pSprite->yvel = bsin(pSprite->ang, -2);
2021-10-17 22:28:59 +00:00
D3PlayFX(StaticSound[kSound48], pActor);
2021-10-24 08:58:27 +00:00
pActor->nCount = 30;
2021-10-15 21:03:09 +00:00
}
}
2021-10-15 21:03:09 +00:00
return;
}
2021-10-15 21:03:09 +00:00
case 1:
{
2021-10-24 08:58:27 +00:00
if (pActor->nCount > 0)
2021-10-15 21:03:09 +00:00
{
2021-10-24 08:58:27 +00:00
pActor->nCount--;
2021-10-15 21:03:09 +00:00
}
2021-10-17 22:28:59 +00:00
if ((pActor->nPhase & 0x0F) == (totalmoves & 0x0F))
2021-10-15 21:03:09 +00:00
{
if (!RandomSize(1))
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 5;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
return;
}
else
{
2021-10-17 22:28:59 +00:00
if (((PlotCourseToSprite(pActor, pTarget) >> 8) >= 60) || pActor->nCount > 0)
2021-10-15 21:03:09 +00:00
{
int nAngle = pSprite->ang & 0xFFF8;
pSprite->xvel = bcos(nAngle, -2);
pSprite->yvel = bsin(nAngle, -2);
}
else
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 2;
pActor->nCount = 240;
2021-10-17 22:28:59 +00:00
D3PlayFX(StaticSound[kSound48], pActor);
2021-10-24 08:58:27 +00:00
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
return;
}
2019-11-16 13:29:18 +00:00
}
2021-10-15 21:03:09 +00:00
}
2021-10-17 22:28:59 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
2021-10-17 22:28:59 +00:00
switch (nMov.type)
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
case kHitSprite:
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
if (nMov.actor == pTarget)
{
2021-10-17 22:28:59 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-24 08:58:27 +00:00
pActor->nAction = 4;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
break;
}
2021-10-17 22:28:59 +00:00
[[fallthrough]];
2021-10-15 21:03:09 +00:00
}
2021-10-17 22:28:59 +00:00
case kHitWall:
2021-10-15 21:03:09 +00:00
{
pSprite->ang = (pSprite->ang + 256) & kAngleMask;
pSprite->xvel = bcos(pSprite->ang, -2);
pSprite->yvel = bsin(pSprite->ang, -2);
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
nAction = 1;
break;
}
}
2021-10-15 21:03:09 +00:00
break;
}
2021-10-15 21:03:09 +00:00
case 2:
{
2021-10-24 08:58:27 +00:00
pActor->nCount--;
if (pActor->nCount > 0)
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-15 21:03:09 +00:00
pSprite->xvel = bcos(pSprite->ang, -1);
pSprite->yvel = bsin(pSprite->ang, -1);
2021-10-17 22:28:59 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
2021-10-17 22:28:59 +00:00
switch (nMov.type)
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
case kHitWall:
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
SetQuake(pActor, 25);
2021-10-24 08:58:27 +00:00
pActor->nCount = 60;
2021-10-15 21:03:09 +00:00
pSprite->ang = (pSprite->ang + 256) & kAngleMask;
pSprite->xvel = bcos(pSprite->ang, -2);
pSprite->yvel = bsin(pSprite->ang, -2);
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
2021-10-15 21:03:09 +00:00
nAction = 1;
break;
}
2021-10-17 22:28:59 +00:00
case kHitSprite:
2021-10-15 21:03:09 +00:00
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
2021-10-17 22:28:59 +00:00
auto pSprite2 = &nMov.actor->s();
2021-10-17 22:28:59 +00:00
if (pSprite2->statnum && pSprite2->statnum < 107)
2021-10-15 21:03:09 +00:00
{
short nAngle = pSprite->ang;
2021-10-17 22:28:59 +00:00
runlist_DamageEnemy(nMov.actor, pActor, 15);
2021-10-15 21:03:09 +00:00
int xVel = bcos(nAngle) * 15;
int yVel = bsin(nAngle) * 15;
2021-10-17 22:28:59 +00:00
if (pSprite2->statnum == 100)
{
2021-10-17 22:28:59 +00:00
auto nPlayer = GetPlayerFromActor(nMov.actor);
PlayerList[nPlayer].nXDamage += (xVel << 4);
PlayerList[nPlayer].nYDamage += (yVel << 4);
2021-10-17 22:28:59 +00:00
pSprite2->zvel = -3584;
}
else
{
2021-10-17 22:28:59 +00:00
pSprite2->xvel += (xVel >> 3);
pSprite2->yvel += (yVel >> 3);
pSprite2->zvel = -2880;
}
}
2021-10-24 08:58:27 +00:00
pActor->nCount >>= 2;
2021-10-15 21:03:09 +00:00
return;
}
}
}
else
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
pActor->nCount = 90;
2021-10-15 21:03:09 +00:00
}
2021-10-15 21:03:09 +00:00
return;
}
2021-10-15 21:03:09 +00:00
case 3:
{
if (bVal)
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 2;
2021-10-15 21:03:09 +00:00
}
return;
}
2021-10-15 21:03:09 +00:00
case 4:
{
2021-10-17 22:28:59 +00:00
if (pTarget != nullptr)
2021-10-15 21:03:09 +00:00
{
2021-10-17 22:28:59 +00:00
if (PlotCourseToSprite(pActor, pTarget) < 768)
2021-10-15 21:03:09 +00:00
{
if (nFlag & 0x80)
{
2021-10-17 22:28:59 +00:00
runlist_DamageEnemy(pTarget, pActor, 15);
}
2021-10-15 21:03:09 +00:00
break;
}
2021-10-15 21:03:09 +00:00
}
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
2021-10-15 21:03:09 +00:00
break;
}
case 5:
{
if (bVal)
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 1;
pActor->nCount = 15;
2021-10-15 21:03:09 +00:00
}
return;
}
case 6:
{
if (bVal)
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 7;
pActor->nFrame = 0;
2021-10-17 22:28:59 +00:00
runlist_ChangeChannel(pActor->nRun, 1);
2021-10-15 21:03:09 +00:00
}
return;
}
case 7:
{
pSprite->cstat &= 0xFEFE;
return;
}
}
// break-ed
if (nAction > 0)
{
2021-10-17 22:28:59 +00:00
if ((pTarget != nullptr) && (!(pTarget->s().cstat & 0x101)))
2021-10-15 21:03:09 +00:00
{
2021-10-24 08:58:27 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
pActor->nCount = 0;
2021-10-17 22:28:59 +00:00
pActor->pTarget = nullptr;
2021-10-15 21:03:09 +00:00
pSprite->xvel = 0;
pSprite->yvel = 0;
}
}
2021-10-15 21:03:09 +00:00
return;
}
void FuncRex(int nObject, int nMessage, int nDamage, int nRun)
{
AIRex ai;
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
}
END_PS_NS