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

465 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 "engine.h"
#include "exhumed.h"
#include "sequence.h"
#include "sound.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq ScorpSeq[] = {
{0, 0},
{8, 0},
{29, 0},
{19, 0},
{45, 1},
{46, 1},
{47, 1},
{48, 1},
{50, 1},
{53, 1}
};
void BuildScorp(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, int nAngle, int nChannel)
{
if (pActor == nullptr)
{
pActor = insertActor(pSector, 122);
pActor->spr.pos = pos;
}
else
{
ChangeActorStat(pActor, 122);
pActor->spr.pos.Z = pActor->sector()->floorz;
nAngle = pActor->int_ang();
}
2021-12-23 16:08:24 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.clipdist = 70;
pActor->spr.shade = -12;
pActor->spr.xrepeat = 80;
pActor->spr.yrepeat = 80;
pActor->spr.picnum = 1;
pActor->spr.pal = pActor->sector()->ceilingpal;
2021-12-23 16:08:24 +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:08:24 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.zvel = 0;
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.extra = -1;
pActor->spr.hitag = 0;
2021-10-15 21:13:28 +00:00
// GrabTimeSlot(3);
2021-10-24 10:20:26 +00:00
pActor->nHealth = 20000;
pActor->nFrame = 0;
pActor->nAction = 0;
2021-10-18 16:57:16 +00:00
pActor->pTarget = nullptr;
2021-10-24 10:20:26 +00:00
pActor->nCount = 0;
pActor->nIndex2 = 1;
2021-10-18 16:57:16 +00:00
pActor->nPhase = Counters[kCountScorp]++;
2021-10-24 10:20:26 +00:00
pActor->nChannel = nChannel;
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x220000);
2021-10-18 16:57:16 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x220000);
nCreaturesTotal++;
}
2021-10-15 21:13:28 +00:00
void AIScorp::Draw(RunListEvent* ev)
{
2021-10-18 16:57:16 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 21:13:28 +00:00
2021-10-24 10:20:26 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqScorp] + ScorpSeq[nAction].a, pActor->nFrame, ScorpSeq[nAction].b);
2021-10-15 21:13:28 +00:00
}
2021-10-15 21:13:28 +00:00
void AIScorp::RadialDamage(RunListEvent* ev)
{
2021-10-18 16:57:16 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:13:28 +00:00
2021-10-18 16:57:16 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 21:13:28 +00:00
if (ev->nDamage) Damage(ev);
}
void AIScorp::Damage(RunListEvent* ev)
{
2021-10-18 16:57:16 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
2021-10-15 21:13:28 +00:00
2021-10-18 16:57:16 +00:00
DExhumedActor* pTarget = nullptr;
2021-10-24 10:20:26 +00:00
if (pActor->nHealth <= 0) {
2021-10-15 21:13:28 +00:00
return;
}
2021-10-24 10:20:26 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
2021-10-15 21:13:28 +00:00
2021-10-24 10:20:26 +00:00
if (pActor->nHealth <= 0)
{
2021-10-24 10:20:26 +00:00
pActor->nHealth = 0;
pActor->nAction = 4;
pActor->nFrame = 0;
pActor->nCount = 10;
2021-12-23 16:08:24 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.zvel = 0;
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 21:13:28 +00:00
nCreaturesKilled++;
return;
}
else
{
2021-10-18 16:57:16 +00:00
pTarget = ev->pOtherActor;
2021-10-18 16:57:16 +00:00
if (pTarget)
{
2021-12-23 16:08:24 +00:00
if (pActor->spr.statnum == 100 || (pActor->spr.statnum < 199 && !RandomSize(5)))
2021-10-15 21:13:28 +00:00
{
2021-10-18 16:57:16 +00:00
pActor->pTarget = pTarget;
}
}
2021-10-15 21:13:28 +00:00
if (!RandomSize(5))
{
2021-10-24 10:20:26 +00:00
pActor->nAction = RandomSize(2) + 4;
pActor->nFrame = 0;
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
if (RandomSize(2)) {
return;
}
2021-10-18 16:57:16 +00:00
D3PlayFX(StaticSound[kSound41], pActor);
Effect(ev, pTarget, 0);
2021-10-15 21:13:28 +00:00
}
}
2021-10-15 21:13:28 +00:00
void AIScorp::Tick(RunListEvent* ev)
{
2021-10-18 16:57:16 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 21:13:28 +00:00
bool bVal = false;
2021-10-18 16:57:16 +00:00
DExhumedActor* pTarget = nullptr;
2021-10-24 10:20:26 +00:00
if (pActor->nHealth) {
2021-10-18 16:57:16 +00:00
Gravity(pActor);
2021-10-15 21:13:28 +00:00
}
2021-10-15 21:13:28 +00:00
int nSeq = SeqOffsets[kSeqScorp] + ScorpSeq[nAction].a;
2021-12-23 16:08:24 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-18 16:57:16 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-24 10:20:26 +00:00
pActor->nFrame++;
2021-10-24 10:20:26 +00:00
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nFrame = 0;
2021-10-15 21:13:28 +00:00
bVal = true;
}
2021-10-24 10:20:26 +00:00
int nFlag = FrameFlag[SeqBase[nSeq] + pActor->nFrame];
2021-10-18 16:57:16 +00:00
pTarget = pActor->pTarget;
2021-10-15 21:13:28 +00:00
switch (nAction)
{
default:
return;
2021-10-15 21:13:28 +00:00
case 0:
{
2021-10-24 10:20:26 +00:00
if (pActor->nCount > 0)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nCount--;
2021-10-15 21:13:28 +00:00
return;
}
2021-10-18 16:57:16 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
2021-10-15 21:13:28 +00:00
{
2021-10-18 16:57:16 +00:00
if (pTarget == nullptr)
{
2021-10-18 16:57:16 +00:00
pTarget = FindPlayer(pActor, 500);
2021-10-18 16:57:16 +00:00
if (pTarget)
{
2021-10-18 16:57:16 +00:00
D3PlayFX(StaticSound[kSound41], pActor);
2021-10-24 10:20:26 +00:00
pActor->nFrame = 0;
2022-08-16 21:15:49 +00:00
pActor->spr.xvel = bcos(pActor->int_ang());
pActor->spr.yvel = bsin(pActor->int_ang());
2021-10-24 10:20:26 +00:00
pActor->nAction = 1;
2021-10-18 16:57:16 +00:00
pActor->pTarget = pTarget;
}
2021-10-15 21:13:28 +00:00
}
}
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
case 1:
{
2021-10-24 10:20:26 +00:00
pActor->nIndex2--;
2021-10-24 10:20:26 +00:00
if (pActor->nIndex2 <= 0)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nIndex2 = RandomSize(5);
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 0);
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-18 16:57:16 +00:00
auto nMov = MoveCreatureWithCaution(pActor);
if (nMov.type == kHitSprite)
2021-10-15 21:13:28 +00:00
{
2021-11-26 13:26:03 +00:00
if (pTarget == nMov.actor())
{
2022-08-20 14:26:01 +00:00
auto nAngDiff = AngleDiff(pActor->spr.angle, VecToAngle(pTarget->spr.pos - pActor->spr.pos));
if (nAngDiff < 64)
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
}
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 2);
}
2021-10-15 21:13:28 +00:00
else
{
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 0);
2021-10-15 21:13:28 +00:00
}
return;
}
2021-10-18 16:57:16 +00:00
else if (nMov.type == kHitWall)
2021-10-15 21:13:28 +00:00
{
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 0);
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 1);
2021-10-15 21:13:28 +00:00
}
}
return;
}
2021-10-15 21:13:28 +00:00
case 2:
{
2021-10-18 16:57:16 +00:00
if (pTarget == nullptr)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 0;
pActor->nCount = 5;
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-18 16:57:16 +00:00
if (PlotCourseToSprite(pActor, pTarget) >= 768)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 1;
2021-10-15 21:13:28 +00:00
}
else if (nFlag & 0x80)
{
2021-10-18 16:57:16 +00:00
runlist_DamageEnemy(pTarget, pActor, 7);
2021-10-15 21:13:28 +00:00
}
}
2021-10-18 16:57:16 +00:00
Effect(ev, pTarget, 2);
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
case 3:
{
if (bVal)
{
2021-10-24 10:20:26 +00:00
pActor->nIndex--;
if (pActor->nIndex <= 0)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 1;
2022-08-16 21:15:49 +00:00
pActor->spr.xvel = bcos(pActor->int_ang());
pActor->spr.yvel = bsin(pActor->int_ang());
2021-10-24 10:20:26 +00:00
pActor->nFrame = 0;
2021-10-15 21:13:28 +00:00
return;
}
}
2021-10-15 21:13:28 +00:00
if (!(nFlag & 0x80)) {
return;
}
2022-08-16 21:17:01 +00:00
auto nBulletSprite = BuildBullet(pActor, 16, -1, pActor->int_ang(), pTarget, 1);
2021-10-18 16:57:16 +00:00
if (nBulletSprite)
2021-10-15 21:13:28 +00:00
{
2021-10-18 16:57:16 +00:00
PlotCourseToSprite(nBulletSprite, pTarget);
2021-10-15 21:13:28 +00:00
}
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
case 4:
case 5:
case 6:
case 7:
{
if (!bVal) {
return;
}
2021-10-24 10:20:26 +00:00
if (pActor->nHealth > 0)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 1;
pActor->nFrame = 0;
pActor->nCount = 0;
2021-10-15 21:13:28 +00:00
return;
}
2021-10-24 10:20:26 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 21:13:28 +00:00
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 8;
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-24 10:20:26 +00:00
pActor->nAction = RandomBit() + 6;
2021-10-15 21:13:28 +00:00
}
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
case 8:
{
if (bVal)
{
2021-10-24 10:20:26 +00:00
pActor->nAction++; // set to 9
pActor->nFrame = 0;
2021-10-24 10:20:26 +00:00
runlist_ChangeChannel(pActor->nChannel, 1);
2021-10-15 21:13:28 +00:00
return;
}
auto pSpiderActor = BuildSpider(nullptr, pActor->spr.pos, pActor->sector(), pActor->int_ang());
2021-10-18 16:57:16 +00:00
if (pSpiderActor)
2021-10-15 21:13:28 +00:00
{
2022-08-16 21:21:10 +00:00
pSpiderActor->set_int_ang(RandomSize(11));
2021-10-15 21:13:28 +00:00
int nVel = RandomSize(5) + 1;
2022-08-16 21:17:01 +00:00
pSpiderActor->spr.xvel = bcos(pSpiderActor->int_ang(), -8) * nVel;
pSpiderActor->spr.yvel = bsin(pSpiderActor->int_ang(), -8) * nVel;
2021-12-23 16:19:21 +00:00
pSpiderActor->spr.zvel = (-(RandomSize(5) + 3)) << 8;
2021-10-15 21:13:28 +00:00
}
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
case 9:
{
2021-12-23 16:08:24 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 21:13:28 +00:00
if (bVal)
{
2021-10-24 10:20:26 +00:00
runlist_SubRunRec(pActor->nRun);
runlist_DoSubRunRec(pActor->spr.intowner);
2021-12-23 16:08:24 +00:00
runlist_FreeRun(pActor->spr.lotag - 1);
2021-10-18 16:57:16 +00:00
DeleteActor(pActor);
}
2021-10-15 21:13:28 +00:00
return;
}
2021-10-15 21:13:28 +00:00
}
}
2021-10-18 16:57:16 +00:00
void AIScorp::Effect(RunListEvent* ev, DExhumedActor* pTarget, int mode)
2021-10-15 21:13:28 +00:00
{
2021-10-18 16:57:16 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-15 21:13:28 +00:00
if (mode == 0)
{
2021-10-18 16:57:16 +00:00
PlotCourseToSprite(pActor, pTarget);
2022-08-16 21:26:39 +00:00
pActor->add_int_ang(RandomSize(7) - 63);
2022-08-16 21:27:44 +00:00
pActor->norm_ang();
2021-10-15 21:13:28 +00:00
2022-08-16 21:15:49 +00:00
pActor->spr.xvel = bcos(pActor->int_ang());
pActor->spr.yvel = bsin(pActor->int_ang());
}
2021-10-15 21:13:28 +00:00
if (mode <= 1)
{
2021-10-24 10:20:26 +00:00
if (pActor->nCount)
{
2021-10-24 10:20:26 +00:00
pActor->nCount--;
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-24 10:20:26 +00:00
pActor->nCount = 45;
2022-08-20 14:38:47 +00:00
if (cansee(pActor->spr.pos.plusZ(-GetActorHeightF(pActor)), pActor->sector(),
pTarget->spr.pos.plusZ(-GetActorHeightF(pTarget)), pTarget->sector()))
{
2021-12-23 16:08:24 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->set_int_ang(getangle(pTarget->int_pos().X - pActor->int_pos().X, pTarget->int_pos().Y - pActor->int_pos().Y));
2021-10-15 21:13:28 +00:00
2021-10-24 10:20:26 +00:00
pActor->nIndex = RandomSize(2) + RandomSize(3);
2021-10-15 21:13:28 +00:00
2021-10-24 10:20:26 +00:00
if (!pActor->nIndex) {
pActor->nCount = RandomSize(5);
2021-10-15 21:13:28 +00:00
}
else
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
2021-10-15 21:13:28 +00:00
}
}
}
}
2021-10-18 16:57:16 +00:00
if (!nAction || pTarget == nullptr) {
return;
}
if (!(pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL))
{
2021-10-24 10:20:26 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
pActor->nCount = 30;
2021-10-18 16:57:16 +00:00
pActor->pTarget = nullptr;
2021-12-23 16:08:24 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
}
}
2021-10-15 21:13:28 +00:00
END_PS_NS