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

490 lines
12 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 "sequence.h"
#include "exhumed.h"
2019-09-21 15:47:55 +00:00
#include "sound.h"
#include <assert.h>
BEGIN_PS_NS
static actionSeq FishSeq[] = {
{8, 0},
{8, 0},
{0, 0},
{24, 0},
{8, 0},
{32, 1},
{33, 1},
{34, 1},
{35, 1},
{39, 1}
};
void BuildFishLimb(DExhumedActor* pActor, int anim)
{
auto pChunkActor = insertActor(pActor->sector(), 99);
2021-10-23 11:02:43 +00:00
pChunkActor->nCount = anim + 40;
pChunkActor->nFrame = RandomSize(3) % SeqSize[SeqOffsets[kSeqFish] + anim + 40];
2022-01-31 22:33:44 +00:00
pChunkActor->set_int_pos(pActor->int_pos());
2021-12-23 16:26:44 +00:00
pChunkActor->spr.cstat = 0;
pChunkActor->spr.shade = -12;
pChunkActor->spr.pal = 0;
pChunkActor->spr.xvel = (RandomSize(5) - 16) << 8;
pChunkActor->spr.yvel = (RandomSize(5) - 16) << 8;
pChunkActor->spr.xrepeat = 64;
pChunkActor->spr.yrepeat = 64;
pChunkActor->spr.xoffset = 0;
pChunkActor->spr.yoffset = 0;
pChunkActor->spr.zvel = (-(RandomByte() + 512)) * 2;
2021-10-23 11:02:43 +00:00
seq_GetSeqPicnum(kSeqFish, pChunkActor->nCount, 0);
2021-12-23 16:26:44 +00:00
pChunkActor->spr.picnum = anim;
pChunkActor->spr.lotag = runlist_HeadRun() + 1;
pChunkActor->spr.clipdist = 0;
// GrabTimeSlot(3);
2021-12-23 16:26:44 +00:00
pChunkActor->spr.extra = -1;
pChunkActor->spr.intowner = runlist_AddRunRec(pChunkActor->spr.lotag - 1, pChunkActor, 0x200000);
2021-12-23 16:26:44 +00:00
pChunkActor->spr.hitag = runlist_AddRunRec(NewRun, pChunkActor, 0x200000);
}
2021-11-22 22:35:11 +00:00
void BuildBlood(int x, int y, int z, sectortype* pSector)
{
2021-11-22 22:35:11 +00:00
BuildAnim(nullptr, kSeqFish, 36, x, y, z, pSector, 75, 128);
}
2021-10-15 19:17:25 +00:00
void AIFishLimb::Tick(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
if (!pActor) return;
int nSeq = SeqOffsets[kSeqFish] + pActor->nCount;
2021-12-23 16:02:47 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-23 11:02:43 +00:00
Gravity(pActor);
2021-10-23 11:02:43 +00:00
pActor->nFrame++;
2021-10-23 11:02:43 +00:00
if (pActor->nFrame >= SeqSize[nSeq])
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
pActor->nFrame = 0;
2021-10-15 19:17:25 +00:00
if (RandomBit()) {
2022-01-31 22:33:44 +00:00
BuildBlood(pActor->int_pos().X, pActor->int_pos().Y, pActor->int_pos().Z, pActor->sector());
2021-10-15 19:17:25 +00:00
}
}
int FloorZ = pActor->sector()->int_floorz();
2022-01-31 22:33:44 +00:00
if (FloorZ <= pActor->int_pos().Z)
2021-10-15 19:17:25 +00:00
{
pActor->add_int_z(256);
2022-01-31 22:33:44 +00:00
if ((pActor->int_pos().Z - FloorZ) > 25600)
2021-10-15 19:17:25 +00:00
{
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = 0;
runlist_DoSubRunRec(pActor->spr.intowner);
2021-12-23 16:02:47 +00:00
runlist_FreeRun(pActor->spr.lotag - 1);
runlist_SubRunRec(pActor->spr.hitag);
2021-10-23 11:02:43 +00:00
DeleteActor(pActor);
2021-10-15 19:17:25 +00:00
}
2022-01-31 22:33:44 +00:00
else if ((pActor->int_pos().Z - FloorZ) > 0)
2021-10-15 19:17:25 +00:00
{
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = 1024;
}
2021-10-15 19:17:25 +00:00
}
else
{
2021-12-23 16:02:47 +00:00
auto coll = movesprite(pActor, pActor->spr.xvel << 8, pActor->spr.yvel << 8, pActor->spr.zvel, 2560, -2560, CLIPMASK1);
2021-10-23 11:02:43 +00:00
if (coll.type != kHitNone)
{
2021-12-23 16:02:47 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
}
}
2021-10-15 19:17:25 +00:00
}
void AIFishLimb::Draw(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
if (pActor == nullptr) return;
int nSeq = SeqOffsets[kSeqFish] + pActor->nCount;
seq_PlotSequence(ev->nParam, nSeq, pActor->nFrame, 1);
2021-10-15 19:17:25 +00:00
}
void BuildFish(DExhumedActor* pActor, int x, int y, int z, sectortype* pSector, int nAngle)
{
2021-10-23 11:02:43 +00:00
if (pActor == nullptr)
{
pActor = insertActor(pSector, 103);
}
else
{
2022-01-31 22:33:44 +00:00
x = pActor->int_pos().X;
y = pActor->int_pos().Y;
z = pActor->int_pos().Z;
2022-08-16 21:17:01 +00:00
nAngle = pActor->int_ang();
2021-10-23 11:02:43 +00:00
ChangeActorStat(pActor, 103);
}
pActor->set_int_pos({ x, y, z });
2021-12-23 16:02:47 +00:00
pActor->spr.cstat = CSTAT_SPRITE_BLOCK_ALL;
pActor->spr.shade = -12;
pActor->spr.clipdist = 80;
pActor->spr.xrepeat = 40;
pActor->spr.yrepeat = 40;
pActor->spr.pal = pActor->sector()->ceilingpal;
2021-12-23 16:02:47 +00:00
pActor->spr.xoffset = 0;
pActor->spr.yoffset = 0;
pActor->spr.picnum = seq_GetSeqPicnum(kSeqFish, FishSeq[0].a, 0);
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
pActor->spr.zvel = 0;
2022-08-16 21:21:10 +00:00
pActor->set_int_ang(nAngle);
2021-12-23 16:02:47 +00:00
pActor->spr.lotag = runlist_HeadRun() + 1;
pActor->spr.hitag = 0;
pActor->spr.extra = -1;
// GrabTimeSlot(3);
pActor->nAction = 0;
pActor->nHealth = 200;
2021-10-23 11:02:43 +00:00
pActor->pTarget = nullptr;
pActor->nCount = 60;
pActor->nFrame = 0;
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x120000);
2021-10-23 11:02:43 +00:00
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x120000);
nCreaturesTotal++;
}
void IdleFish(DExhumedActor* pActor, int edx)
{
2022-08-16 21:15:16 +00:00
pActor->spr.__int_angle += (256 - RandomSize(9)) + 1024;
pActor->spr.__int_angle &= kAngleMask;
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -8);
pActor->spr.yvel = bsin(pActor->int_ang(), -8);
pActor->nAction = 0;
pActor->nFrame = 0;
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = RandomSize(9);
if (!edx)
{
if (RandomBit()) {
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = -pActor->spr.zvel;
}
}
else if (edx < 0)
{
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = -pActor->spr.zvel;
}
}
2021-10-23 11:02:43 +00:00
void DestroyFish(DExhumedActor* pActor)
{
runlist_DoSubRunRec(pActor->spr.intowner);
2021-12-23 16:02:47 +00:00
runlist_FreeRun(pActor->spr.lotag - 1);
runlist_SubRunRec(pActor->nRun);
2021-10-23 11:02:43 +00:00
DeleteActor(pActor);
}
2021-10-15 19:17:25 +00:00
void AIFish::Draw(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
if (pActor == nullptr) return;
int nAction = pActor->nAction;
2021-10-15 19:17:25 +00:00
seq_PlotSequence(ev->nParam, SeqOffsets[kSeqFish] + FishSeq[nAction].a, pActor->nFrame, FishSeq[nAction].b);
ev->pTSprite->ownerActor = nullptr;
2021-10-15 19:17:25 +00:00
return;
}
2021-10-15 19:17:25 +00:00
void AIFish::RadialDamage(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
if (pActor == nullptr) return;
if (pActor->nHealth <= 0) {
2021-10-15 19:17:25 +00:00
return;
}
else
{
2021-10-23 11:02:43 +00:00
ev->nDamage = runlist_CheckRadialDamage(pActor);
2021-10-15 19:17:25 +00:00
if (!ev->nDamage) {
return;
}
pActor->nCount = 10;
2021-10-15 19:17:25 +00:00
}
// fall through
Damage(ev);
}
void AIFish::Damage(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
2021-10-15 19:17:25 +00:00
2021-10-23 11:02:43 +00:00
if (!ev->nDamage || !pActor) {
2021-10-15 19:17:25 +00:00
return;
}
pActor->nHealth -= dmgAdjust(ev->nDamage);
if (pActor->nHealth <= 0)
2021-10-15 19:17:25 +00:00
{
pActor->nHealth = 0;
2021-10-15 19:17:25 +00:00
nCreaturesKilled++;
2021-12-23 16:02:47 +00:00
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2021-10-15 19:17:25 +00:00
if (!ev->isRadialEvent())
{
2021-10-15 19:17:25 +00:00
for (int i = 0; i < 3; i++)
{
2021-10-23 11:02:43 +00:00
BuildFishLimb(pActor, i);
}
2021-10-15 19:17:25 +00:00
2022-01-31 22:33:44 +00:00
PlayFXAtXYZ(StaticSound[kSound40], pActor->int_pos().X, pActor->int_pos().Y, pActor->int_pos().Z);
2021-10-23 11:02:43 +00:00
DestroyFish(pActor);
}
2021-10-15 19:17:25 +00:00
else
{
pActor->nAction = 9;
pActor->nFrame = 0;
2021-10-15 19:17:25 +00:00
}
2021-10-15 19:17:25 +00:00
return;
}
else
{
2021-10-23 11:02:43 +00:00
auto pTarget = ev->pOtherActor;
if (pTarget && pTarget->spr.statnum < 199)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
pActor->pTarget = pTarget;
2021-10-15 19:17:25 +00:00
}
pActor->nAction = 4;
pActor->nFrame = 0;
pActor->nCount += 10;
2021-10-15 19:17:25 +00:00
}
}
2021-10-15 19:17:25 +00:00
void AIFish::Tick(RunListEvent* ev)
{
2021-10-23 11:02:43 +00:00
auto pActor = ev->pObjActor;
if (pActor == nullptr) return;
int nAction = pActor->nAction;
if (!(pActor->sector()->Flag & kSectUnderwater))
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
Gravity(pActor);
2021-10-15 19:17:25 +00:00
}
int nSeq = SeqOffsets[kSeqFish] + FishSeq[nAction].a;
2021-12-23 16:02:47 +00:00
pActor->spr.picnum = seq_GetSeqPicnum2(nSeq, pActor->nFrame);
2021-10-23 11:02:43 +00:00
seq_MoveSequence(pActor, nSeq, pActor->nFrame);
2021-10-15 19:17:25 +00:00
pActor->nFrame++;
if (pActor->nFrame >= SeqSize[nSeq]) {
pActor->nFrame = 0;
2021-10-15 19:17:25 +00:00
}
2021-12-07 17:53:02 +00:00
DExhumedActor* pTargetActor = pActor->pTarget;
2021-10-15 19:17:25 +00:00
switch (nAction)
{
default:
return;
2021-10-15 19:17:25 +00:00
case 0:
{
pActor->nCount--;
if (pActor->nCount <= 0)
{
2021-10-23 11:02:43 +00:00
pTargetActor = FindPlayer(pActor, 60);
if (pTargetActor)
{
2021-10-23 11:02:43 +00:00
pActor->pTarget = pTargetActor;
pActor->nAction = 2;
pActor->nFrame = 0;
2022-01-31 22:33:44 +00:00
int nAngle = GetMyAngle(pTargetActor->int_pos().X - pActor->int_pos().X, pTargetActor->int_pos().Z - pActor->int_pos().Z);
2021-12-23 16:02:47 +00:00
pActor->spr.zvel = bsin(nAngle, -5);
pActor->nCount = RandomSize(6) + 90;
2021-10-15 19:17:25 +00:00
}
else
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 0);
2021-10-15 19:17:25 +00:00
}
}
2021-10-15 19:17:25 +00:00
break;
}
2021-10-15 19:17:25 +00:00
case 1:
return;
2021-10-15 19:17:25 +00:00
case 2:
case 3:
{
pActor->nCount--;
if (pActor->nCount <= 0)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 0);
2021-10-15 19:17:25 +00:00
return;
}
else
{
2021-10-23 11:02:43 +00:00
PlotCourseToSprite(pActor, pTargetActor);
int nHeight = GetActorHeight(pActor) >> 1;
2022-01-31 22:33:44 +00:00
int z = abs(pTargetActor->int_pos().Z - pActor->int_pos().Z);
2021-10-15 19:17:25 +00:00
if (z <= nHeight)
{
2022-08-16 21:17:01 +00:00
pActor->spr.xvel = bcos(pActor->int_ang(), -5) - bcos(pActor->int_ang(), -7);
pActor->spr.yvel = bsin(pActor->int_ang(), -5) - bsin(pActor->int_ang(), -7);
2021-10-15 19:17:25 +00:00
}
else
{
2021-12-23 16:02:47 +00:00
pActor->spr.xvel = 0;
pActor->spr.yvel = 0;
2021-10-15 19:17:25 +00:00
}
2022-01-31 22:33:44 +00:00
pActor->spr.zvel = (pTargetActor->int_pos().Z - pActor->int_pos().Z) >> 3;
2021-10-15 19:17:25 +00:00
}
break;
}
2021-10-15 19:17:25 +00:00
case 4:
{
if (pActor->nFrame == 0)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 0);
2021-10-15 19:17:25 +00:00
}
return;
}
2021-10-15 19:17:25 +00:00
case 8:
{
return;
}
2021-10-15 19:17:25 +00:00
case 9:
{
if (pActor->nFrame == 0)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
DestroyFish(pActor);
2021-10-15 19:17:25 +00:00
}
return;
}
}
2022-01-31 22:33:44 +00:00
int x = pActor->int_pos().X;
int y = pActor->int_pos().Y;
int z = pActor->int_pos().Z;
auto pSector =pActor->sector();
2021-10-15 19:17:25 +00:00
// loc_2EF54
2021-12-23 16:02:47 +00:00
Collision coll = movesprite(pActor, pActor->spr.xvel << 13, pActor->spr.yvel << 13, pActor->spr.zvel << 2, 0, 0, CLIPMASK0);
if (!(pActor->sector()->Flag & kSectUnderwater))
2021-10-15 19:17:25 +00:00
{
2021-11-22 23:13:30 +00:00
ChangeActorSect(pActor, pSector);
pActor->set_int_pos({ x, y, z });
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 0);
2021-10-15 19:17:25 +00:00
return;
}
else
{
if (nAction >= 5) {
return;
}
2021-10-23 11:02:43 +00:00
if (coll.type == kHitNone)
2021-10-15 19:17:25 +00:00
{
if (nAction == 3)
{
pActor->nAction = 2;
pActor->nFrame = 0;
2021-10-15 19:17:25 +00:00
}
return;
}
2021-10-23 11:02:43 +00:00
if (!coll.exbits)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
if (coll.type == kHitWall)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 0);
}
2021-10-23 11:02:43 +00:00
else if (coll.type == kHitSprite)
{
2021-10-23 11:02:43 +00:00
2021-12-23 16:26:44 +00:00
auto pHitAct = coll.actor();
if (pHitAct->spr.statnum == 100)
{
2021-11-26 13:26:03 +00:00
pActor->pTarget = coll.actor();
2022-08-16 21:21:10 +00:00
pActor->set_int_ang(GetMyAngle(pHitAct->int_pos().X - pActor->int_pos().X, pHitAct->int_pos().Y - pActor->int_pos().Y));
2021-10-15 19:17:25 +00:00
if (nAction != 3)
{
pActor->nAction = 3;
pActor->nFrame = 0;
}
if (!pActor->nFrame)
{
2021-11-26 13:26:03 +00:00
runlist_DamageEnemy(coll.actor(), pActor, 2);
}
}
}
2021-10-15 19:17:25 +00:00
}
2021-10-23 11:02:43 +00:00
else if (coll.exbits & kHitAux2)
2021-10-15 19:17:25 +00:00
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, -1);
2021-10-15 19:17:25 +00:00
}
else
{
2021-10-23 11:02:43 +00:00
IdleFish(pActor, 1);
}
}
}
2021-10-15 19:17:25 +00:00
END_PS_NS