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

449 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}
};
void BuildRex(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, int nAngle, int nChannel)
2020-11-29 19:43:35 +00:00
{
2021-10-17 22:28:59 +00:00
if (pActor == nullptr)
2020-11-29 19:43:35 +00:00
{
pActor = insertActor(pSector, 119);
pActor->spr.pos = pos;
}
else
{
nAngle = pActor->int_ang();
pActor->spr.pos.Z = pActor->sector()->floorz;
2021-10-17 22:28:59 +00:00
ChangeActorStat(pActor, 119);
}
2021-12-23 16:07:42 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.clipdist = 80;
pActor->spr.shade = -12;
pActor->spr.xrepeat = 64;
pActor->spr.yrepeat = 64;
pActor->spr.picnum = 1;
pActor->spr.pal = pActor->sector()->ceilingpal;
2021-12-23 16:07:42 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
2022-08-16 21:21:10 +00:00
pActor->set_int_ang(nAngle);
2021-12-23 16:07:42 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2022-08-31 21:57:15 +00:00
pActor->set_int_zvel(0);
2021-12-23 16:07:42 +00:00
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.extra = -1;
pActor->spr.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;
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.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;
int 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
int nAction = pActor->nAction;
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->spr.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-12-23 16:07:42 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2022-08-31 21:57:15 +00:00
pActor->set_int_zvel(0);
2021-12-23 16:07:42 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 21:03:09 +00:00
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
int 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
int nAction = pActor->nAction;
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-12-23 16:07:42 +00:00
pActor->spr.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-12-07 17:53:02 +00:00
DExhumedActor* 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)
{
2022-08-16 21:17:01 +00:00
auto nAngle = pActor->int_ang(); // make backup of this variable
2021-10-17 22:28:59 +00:00
pActor->pTarget = FindPlayer(pActor, 60);
2022-08-16 21:21:10 +00:00
pActor->set_int_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;
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -2);
pActor->spr.yvel = bsin(pActor->int_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-12-23 16:07:42 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2021-10-15 21:03:09 +00:00
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
{
2022-08-16 21:25:11 +00:00
int nAngle = pActor->int_ang() & 0xFFF8;
2021-12-23 16:07:42 +00:00
pActor->spr.xvel = bcos(nAngle, -2);
pActor->spr.yvel = bsin(nAngle, -2);
2021-10-15 21:03:09 +00:00
}
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-11-26 13:26:03 +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
{
2022-08-16 21:21:10 +00:00
pActor->set_int_ang((pActor->int_ang() + 256) & kAngleMask);
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -2);
pActor->spr.yvel = bsin(pActor->int_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);
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -1);
pActor->spr.yvel = bsin(pActor->int_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
2022-08-16 21:21:10 +00:00
pActor->set_int_ang((pActor->int_ang() + 256) & kAngleMask);
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -2);
pActor->spr.yvel = bsin(pActor->int_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-12-23 16:26:44 +00:00
auto pHitActor = nMov.actor();
2021-12-23 16:26:44 +00:00
if (pHitActor->spr.statnum && pHitActor->spr.statnum < 107)
2021-10-15 21:03:09 +00:00
{
2022-08-16 21:17:01 +00:00
int nAngle = pActor->int_ang();
2021-11-26 13:26:03 +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-12-23 16:26:44 +00:00
if (pHitActor->spr.statnum == 100)
{
2021-11-26 13:26:03 +00:00
auto nPlayer = GetPlayerFromActor(nMov.actor());
PlayerList[nPlayer].nDamage.X += (xVel << 4);
PlayerList[nPlayer].nDamage.Y += (yVel << 4);
2021-12-23 16:26:44 +00:00
pHitActor->spr.zvel = -3584;
}
else
{
2021-12-23 16:26:44 +00:00
pHitActor->spr.xvel += (xVel >> 3);
pHitActor->spr.yvel += (yVel >> 3);
pHitActor->spr.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:
{
2021-12-23 16:07:42 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 21:03:09 +00:00
return;
}
}
// break-ed
if (nAction > 0)
{
if ((pTarget != nullptr) && (!(pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL)))
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-12-23 16:07:42 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
}
}
2021-10-15 21:03:09 +00:00
return;
}
END_PS_NS