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

656 lines
16 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 SetSeq[] = {
{0, 0},
{77, 1},
{78, 1},
{0, 0},
{9, 0},
{63, 0},
{45, 0},
{18, 0},
{27, 0},
{36, 0},
{72, 1},
{74, 1}
};
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void BuildSet(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, DAngle nAngle, int nChannel)
{
2021-10-19 17:53:42 +00:00
if (pActor == nullptr)
{
pActor = insertActor(pSector, 120);
pActor->spr.pos = pos;
}
else
{
2021-10-19 17:53:42 +00:00
ChangeActorStat(pActor, 120);
pActor->spr.pos.Z = pActor->sector()->floorz;
nAngle = pActor->spr.Angles.Yaw;
}
2021-12-23 16:08:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.shade = -12;
pActor->clipdist = 27.5;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
pActor->vel.Z = 0;
pActor->spr.scale = DVector2(1.359375, 1.5);
pActor->spr.pal = pActor->sector()->ceilingpal;
2021-12-23 16:08:37 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
pActor->spr.Angles.Yaw = nAngle;
2021-12-23 16:08:37 +00:00
pActor->spr.picnum = 1;
pActor->spr.hitag = 0;
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.extra = -1;
// GrabTimeSlot(3);
2021-10-25 16:57:10 +00:00
pActor->nAction = 1;
pActor->nHealth = 8000;
pActor->nFrame = 0;
2021-10-19 17:53:42 +00:00
pActor->pTarget = nullptr;
2021-10-25 16:57:10 +00:00
pActor->nCount = 90;
pActor->nIndex = 0;
pActor->nIndex2 = 0;
2021-10-19 17:53:42 +00:00
pActor->nPhase = Counters[kCountSet]++;
2021-10-25 16:57:10 +00:00
pActor->nChannel = nChannel;
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x190000);
// this isn't stored anywhere.
2021-10-19 17:53:42 +00:00
runlist_AddRunRec(NewRun, pActor, 0x190000);
nCreaturesTotal++;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-10-19 17:53:42 +00:00
void BuildSoul(DExhumedActor* pSet)
{
auto pActor = insertActor(pSet->sector(), 0);
2021-12-23 16:08:37 +00:00
pActor->spr.cstat = CSTAT_SPRITE_INVISIBLE;
pActor->spr.shade = -127;
pActor->spr.scale = DVector2(REPEAT_SCALE, REPEAT_SCALE);
2021-12-23 16:08:37 +00:00
pActor->spr.pal = 0;
pActor->clipdist = 1.25;
2021-12-23 16:08:37 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
pActor->spr.picnum = seq_GetSeqPicnum(kSeqSet, 75, 0);
pActor->spr.Angles.Yaw = RandomAngle();
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
2022-09-09 17:29:11 +00:00
pActor->vel.Z = -1 - RandomSize(10) / 256.;
pActor->spr.pos = DVector3(pSet->spr.pos.XY(), RandomSize(8) + 32 + pActor->sector()->ceilingz - GetActorHeight(pActor));
2021-12-23 16:08:37 +00:00
//pActor->spr.hitag = nSet;
2021-10-19 17:53:42 +00:00
pActor->pTarget = pSet;
pActor->nPhase = Counters[kCountSoul]++;
2021-12-23 16:08:37 +00:00
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.extra = 0;
// GrabTimeSlot(3);
pActor->spr.intowner = runlist_AddRunRec(NewRun, pActor, 0x230000);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void AISoul::Tick(RunListEvent* ev)
{
2021-10-19 17:53:42 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
seq_MoveSequence(pActor, SeqOffsets[kSeqSet] + 75, 0);
if (pActor->spr.scale.X < 0.5)
{
2022-10-07 21:44:21 +00:00
pActor->spr.scale.X += (REPEAT_SCALE);
pActor->spr.scale.Y += (REPEAT_SCALE);
}
2021-12-23 16:08:37 +00:00
pActor->spr.extra += (pActor->nPhase & 0x0F) + 5;
pActor->spr.extra &= kAngleMask;
double nVel = mapangle(pActor->spr.extra).Cos();
auto vect = pActor->spr.Angles.Yaw.ToVector() * nVel * 8;
2022-09-10 21:43:54 +00:00
auto coll = movesprite(pActor,vect, pActor->vel.Z, 0, CLIPMASK0);
2021-10-19 17:53:42 +00:00
if (coll.exbits & 0x10000)
{
2021-12-07 17:53:02 +00:00
DExhumedActor* pSet = pActor->pTarget;
2021-10-19 17:53:42 +00:00
if (!pSet) return;
2021-12-23 16:08:37 +00:00
pActor->spr.cstat = 0;
pActor->spr.scale = DVector2(REPEAT_SCALE, REPEAT_SCALE);
pActor->spr.pos = pSet->spr.pos.plusZ(-GetActorHeight(pSet) * 0.5);
ChangeActorSect(pActor, pSet->sector());
return;
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void AISet::RadialDamage(RunListEvent* ev)
{
2021-10-19 17:53:42 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
if (nAction == 5)
{
2021-10-19 17:53:42 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
// fall through to case 0x80000
}
Damage(ev);
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void AISet::Damage(RunListEvent* ev)
{
2021-10-19 17:53:42 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-25 16:57:10 +00:00
if (ev->nDamage && pActor->nHealth > 0)
{
if (nAction != 1)
{
2021-10-25 16:57:10 +00:00
pActor->nHealth -= dmgAdjust(ev->nDamage);
}
2021-10-25 16:57:10 +00:00
if (pActor->nHealth <= 0)
{
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
pActor->vel.Z = 0;
2021-12-23 16:08:37 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-25 16:57:10 +00:00
pActor->nHealth = 0;
nCreaturesKilled++;
if (nAction < 10)
{
2021-10-25 16:57:10 +00:00
pActor->nFrame = 0;
pActor->nAction = 10;
}
}
else if (nAction == 1)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
}
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void AISet::Draw(RunListEvent* ev)
{
2021-10-19 17:53:42 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
2021-10-25 16:57:10 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqSet] + SetSeq[nAction].a, pActor->nFrame, SetSeq[nAction].b);
return;
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void AISet::Tick(RunListEvent* ev)
{
2021-10-19 17:53:42 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nAction = pActor->nAction;
bool bVal = false;
2021-10-19 17:53:42 +00:00
Gravity(pActor);
int nSeq = SeqOffsets[kSeqSet] + SetSeq[pActor->nAction].a;
2021-12-23 16:08:37 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-19 17:53:42 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
if (nAction == 3)
{
2021-10-25 16:57:10 +00:00
if (pActor->nIndex2) {
pActor->nFrame++;
}
}
2021-10-25 16:57:10 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq])
{
2021-10-25 16:57:10 +00:00
pActor->nFrame = 0;
bVal = true;
}
int nFlag = FrameFlag[SeqBase[nSeq] + pActor->nFrame];
2021-12-07 17:53:02 +00:00
DExhumedActor* pTarget = pActor->pTarget;
2021-10-19 17:53:42 +00:00
if (pTarget && nAction < 10)
{
if (!(pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL))
{
2021-10-19 17:53:42 +00:00
pActor->pTarget = nullptr;
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
2021-10-19 17:53:42 +00:00
pTarget = nullptr;
}
}
2021-10-19 17:53:42 +00:00
auto nMov = MoveCreature(pActor);
auto sect = pActor->sector();
pushmove(pActor->spr.pos, &sect, pActor->clipdist, 20, -20, CLIPMASK0);
pActor->setsector(sect);
if (pActor->vel.Z > 4000/256.)
{
2021-10-19 17:53:42 +00:00
if (nMov.exbits & kHitAux2)
{
2021-10-19 17:53:42 +00:00
SetQuake(pActor, 100);
}
}
switch (nAction)
{
default:
return;
case 0:
{
2021-10-19 17:53:42 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
{
2021-10-19 17:53:42 +00:00
if (pTarget == nullptr)
{
2021-10-19 17:53:42 +00:00
pTarget = FindPlayer(pActor, 1000);
}
2021-10-19 17:53:42 +00:00
if (pTarget)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 3;
pActor->nFrame = 0;
2021-10-19 17:53:42 +00:00
pActor->pTarget = pTarget;
pActor->VelFromAngle(-1);
}
}
return;
}
case 1:
{
2021-10-19 17:53:42 +00:00
if (FindPlayer(pActor, 1000))
{
2021-10-25 16:57:10 +00:00
pActor->nCount--;
if (pActor->nCount <= 0)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 2;
pActor->nFrame = 0;
}
}
return;
}
case 2:
{
if (bVal)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 7;
pActor->nIndex = 0;
pActor->nFrame = 0;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
2021-10-19 17:53:42 +00:00
pActor->pTarget = FindPlayer(pActor, 1000);
}
return;
}
case 3:
{
2021-10-19 17:53:42 +00:00
if (pTarget != nullptr)
{
2021-10-19 17:53:42 +00:00
if ((nFlag & 0x10) && (nMov.exbits & kHitAux2))
{
2021-10-19 17:53:42 +00:00
SetQuake(pActor, 100);
}
double nCourse = PlotCourseToSprite(pActor, pTarget);
2021-10-19 17:53:42 +00:00
if ((pActor->nPhase & 0x1F) == (totalmoves & 0x1F))
{
int nRand = RandomSize(3);
switch (nRand)
{
case 0:
case 2:
{
2021-10-25 16:57:10 +00:00
pActor->nIndex = 0;
pActor->nAction = 7;
pActor->nFrame = 0;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
return;
}
case 1:
{
2021-10-19 17:53:42 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-25 16:57:10 +00:00
pActor->nAction = 6;
pActor->nFrame = 0;
pActor->nRun = 5;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
return;
}
default:
{
if (nCourse <= 100/16.)
{
2021-10-25 16:57:10 +00:00
pActor->nIndex2 = 0;
}
else
{
2021-10-25 16:57:10 +00:00
pActor->nIndex2 = 1;
}
break;
}
}
}
// loc_338E2
pActor->vel.XY() = pActor->spr.Angles.Yaw.ToVector() * 512;
2021-10-25 16:57:10 +00:00
if (pActor->nIndex2)
{
2022-09-03 08:04:16 +00:00
pActor->vel.X *= 2;
pActor->vel.Y *= 2;
}
2021-10-19 17:53:42 +00:00
if (nMov.type == kHitWall)
{
2021-11-26 13:26:03 +00:00
auto pSector = nMov.hitWall->nextSector();
2021-11-22 21:20:53 +00:00
if (pSector)
{
2022-08-20 18:25:38 +00:00
if ((pActor->spr.pos.Z - pSector->floorz) < (55000/256.))
{
2022-08-20 18:25:38 +00:00
if (pActor->spr.pos.Z > pSector->ceilingz)
{
2021-10-25 16:57:10 +00:00
pActor->nIndex = 1;
pActor->nAction = 7;
pActor->nFrame = 0;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
return;
}
}
}
pActor->spr.Angles.Yaw += DAngle45;
pActor->VelFromAngle(-1);
break;
}
2021-10-19 17:53:42 +00:00
else if (nMov.type == kHitSprite)
{
2021-11-26 13:26:03 +00:00
if (pTarget == nMov.actor())
{
auto nAngDiff = absangle(pActor->spr.Angles.Yaw, (pTarget->spr.pos - pActor->spr.pos).Angle());
2022-09-10 22:18:09 +00:00
if (nAngDiff < DAngle22_5 / 2)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 4;
pActor->nFrame = 0;
}
break;
}
else
{
2021-10-25 16:57:10 +00:00
pActor->nIndex = 1;
pActor->nAction = 7;
pActor->nFrame = 0;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
return;
}
}
break;
}
else
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
return;
}
}
case 4:
{
2021-10-19 17:53:42 +00:00
if (pTarget == nullptr)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nCount = 50;
}
else
{
if (PlotCourseToSprite(pActor, pTarget) >= 48)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 3;
}
else if (nFlag & 0x80)
{
2021-10-19 17:53:42 +00:00
runlist_DamageEnemy(pTarget, pActor, 5);
}
}
break;
}
case 5:
{
if (bVal)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nCount = 15;
}
return;
}
case 6:
{
if (nFlag & 0x80)
{
auto pBullet = BuildBullet(pActor, 11, INT_MAX, pActor->spr.Angles.Yaw, pTarget, 1);
2021-10-19 17:53:42 +00:00
if (pBullet)
2021-10-16 20:04:21 +00:00
SetBulletEnemy(pBullet->nPhase, pTarget);
2021-10-25 16:57:10 +00:00
pActor->nRun--;
if (pActor->nRun <= 0 || !RandomBit())
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
}
}
return;
}
case 7:
{
if (bVal)
{
2021-10-25 16:57:10 +00:00
if (pActor->nIndex)
{
2022-09-09 17:29:11 +00:00
pActor->vel.Z = -10000 / 256.;
}
else
{
pActor->vel.Z = -(PlotCourseToSprite(pActor, pTarget)) / 16.;
}
2021-10-25 16:57:10 +00:00
pActor->nAction = 8;
pActor->nFrame = 0;
pActor->VelFromAngle();
}
return;
}
case 8:
{
if (bVal)
{
2021-10-25 16:57:10 +00:00
pActor->nFrame = SeqSize[nSeq] - 1;
}
2021-10-19 17:53:42 +00:00
if (nMov.exbits & kHitAux2)
{
2021-10-19 17:53:42 +00:00
SetQuake(pActor, 200);
2021-10-25 16:57:10 +00:00
pActor->nAction = 9;
pActor->nFrame = 0;
}
return;
}
case 9:
{
2022-09-03 08:04:16 +00:00
pActor->vel.X *= 0.5;
pActor->vel.Y *= 0.5;
if (bVal)
{
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
2021-10-19 17:53:42 +00:00
PlotCourseToSprite(pActor, pTarget);
2021-10-25 16:57:10 +00:00
pActor->nAction = 6;
pActor->nFrame = 0;
pActor->nRun = 5;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
}
return;
}
case 10:
{
if (nFlag & 0x80)
{
pActor->spr.pos.Z -= GetActorHeight(pActor);
2021-10-26 19:15:07 +00:00
BuildCreatureChunk(pActor, seq_GetSeqPicnum(kSeqSet, 76, 0));
pActor->spr.pos.Z += GetActorHeight(pActor);
}
if (bVal)
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 11;
pActor->nFrame = 0;
2021-10-25 16:57:10 +00:00
runlist_ChangeChannel(pActor->nChannel, 1);
for (int i = 0; i < 20; i++)
{
2021-10-19 17:53:42 +00:00
BuildSoul(pActor);
}
}
return;
}
case 11:
{
2021-12-23 16:08:37 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
return;
}
}
// loc_33AE3: ?
if (nAction)
{
2021-10-19 17:53:42 +00:00
if (pTarget)
{
if (!(pTarget->spr.cstat & CSTAT_SPRITE_BLOCK_ALL))
{
2021-10-25 16:57:10 +00:00
pActor->nAction = 0;
pActor->nFrame = 0;
pActor->nCount = 100;
2021-10-19 17:53:42 +00:00
pActor->pTarget = nullptr;
2022-09-03 08:02:25 +00:00
pActor->vel.X = 0;
pActor->vel.Y = 0;
}
}
}
return;
}
END_PS_NS