2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood 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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-09-21 18:59:54 +00:00
|
|
|
|
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "pragmas.h"
|
|
|
|
#include "mmulti.h"
|
|
|
|
|
|
|
|
#include "blood.h"
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void MorphToBeast(DBloodActor *);
|
|
|
|
static void beastThinkSearch(DBloodActor *);
|
|
|
|
static void beastThinkGoto(DBloodActor *);
|
|
|
|
static void beastThinkChase(DBloodActor *);
|
|
|
|
static void beastThinkSwimGoto(DBloodActor *);
|
|
|
|
static void beastThinkSwimChase(DBloodActor *);
|
|
|
|
static void beastMoveForward(DBloodActor *);
|
|
|
|
static void sub_628A0(DBloodActor *);
|
|
|
|
static void sub_62AE0(DBloodActor *);
|
|
|
|
static void sub_62D7C(DBloodActor *);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
AISTATE beastIdle = {kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beastChase = {kAiStateChase, 8, -1, 0, NULL, beastMoveForward, beastThinkChase, NULL };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beastDodge = { kAiStateMove, 8, -1, 60, NULL, aiMoveDodge, NULL, &beastChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beastGoto = { kAiStateMove, 8, -1, 600, NULL, beastMoveForward, beastThinkGoto, &beastIdle };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beastSlash = { kAiStateChase, 6, nSlashClient, 120, NULL, NULL, NULL, &beastChase };
|
|
|
|
AISTATE beastStomp = { kAiStateChase, 7, nStompClient, 120, NULL, NULL, NULL, &beastChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beastSearch = { kAiStateSearch, 8, -1, 120, NULL, beastMoveForward, beastThinkSearch, &beastIdle };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beastRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &beastDodge };
|
|
|
|
AISTATE beastTeslaRecoil = { kAiStateRecoil, 4, -1, 0, NULL, NULL, NULL, &beastDodge };
|
|
|
|
AISTATE beastSwimIdle = {kAiStateIdle, 9, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beastSwimChase = { kAiStateChase, 9, -1, 0, NULL, sub_628A0, beastThinkSwimChase, NULL };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beastSwimDodge = { kAiStateMove, 9, -1, 90, NULL, aiMoveDodge, NULL, &beastSwimChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beastSwimGoto = { kAiStateMove, 9, -1, 600, NULL, beastMoveForward, beastThinkSwimGoto, &beastSwimIdle };
|
|
|
|
AISTATE beastSwimSearch = { kAiStateSearch, 9, -1, 120, NULL, beastMoveForward, beastThinkSearch, &beastSwimIdle };
|
|
|
|
AISTATE beastSwimSlash = { kAiStateChase, 9, nSlashClient, 0, NULL, NULL, beastThinkSwimChase, &beastSwimChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beastSwimRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &beastSwimDodge };
|
|
|
|
AISTATE beastMorphToBeast = { kAiStateOther, -1, -1, 0, MorphToBeast, NULL, NULL, &beastIdle };
|
|
|
|
AISTATE beastMorphFromCultist = { kAiStateOther, 2576, -1, 0, NULL, NULL, NULL, &beastMorphToBeast };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE beast138FB4 = { kAiStateOther, 9, -1, 120, NULL, sub_62AE0, beastThinkSwimChase, &beastSwimChase };
|
|
|
|
AISTATE beast138FD0 = { kAiStateOther, 9, -1, 0, NULL, sub_62D7C, beastThinkSwimChase, &beastSwimChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE beast138FEC = { kAiStateOther, 9, -1, 120, NULL, aiMoveTurn, NULL, &beastSwimChase };
|
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void SlashSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-07 14:16:12 +00:00
|
|
|
XSPRITE* pXSprite = &actor->x();
|
|
|
|
spritetype *pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
2020-09-01 13:00:35 +00:00
|
|
|
int dx = CosScale16(pSprite->ang);
|
|
|
|
int dy = SinScale16(pSprite->ang);
|
2019-09-19 22:42:45 +00:00
|
|
|
// Correct ?
|
|
|
|
int dz = pSprite->z-pTarget->z;
|
|
|
|
dx += Random3(4000-700*gGameOptions.nDifficulty);
|
|
|
|
dy += Random3(4000-700*gGameOptions.nDifficulty);
|
|
|
|
actFireVector(pSprite, 0, 0, dx, dy, dz, VECTOR_TYPE_13);
|
|
|
|
actFireVector(pSprite, 0, 0, dx, dy, dz, VECTOR_TYPE_13);
|
|
|
|
actFireVector(pSprite, 0, 0, dx, dy, dz, VECTOR_TYPE_13);
|
|
|
|
sfxPlay3DSound(pSprite, 9012+Random(2), -1, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void StompSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-10-15 15:08:21 +00:00
|
|
|
uint8_t vb8[(kMaxSectors+7)>>3];
|
2020-11-07 14:16:12 +00:00
|
|
|
XSPRITE* pXSprite = &actor->x();
|
2019-09-19 22:42:45 +00:00
|
|
|
int nSprite = pXSprite->reference;
|
2020-11-07 14:16:12 +00:00
|
|
|
spritetype *pSprite = &actor->s();
|
2020-09-01 13:00:35 +00:00
|
|
|
int dx = CosScale16(pSprite->ang);
|
|
|
|
int dy = SinScale16(pSprite->ang);
|
2019-09-19 22:42:45 +00:00
|
|
|
int x = pSprite->x;
|
|
|
|
int y = pSprite->y;
|
|
|
|
int z = pSprite->z;
|
|
|
|
int vc = 400;
|
|
|
|
int nSector = pSprite->sectnum;
|
|
|
|
int v1c = 5+2*gGameOptions.nDifficulty;
|
|
|
|
int v10 = 25+30*gGameOptions.nDifficulty;
|
2020-11-21 20:31:50 +00:00
|
|
|
GetClosestSpriteSectors(nSector, x, y, vc, vb8);
|
2019-09-19 22:42:45 +00:00
|
|
|
char v4 = 0;
|
|
|
|
int v34 = -1;
|
|
|
|
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
|
|
|
|
actHitcodeToData(hit, &gHitInfo, &v34, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
if (hit == 3 && v34 >= 0)
|
|
|
|
{
|
2019-10-07 19:29:52 +00:00
|
|
|
if (sprite[v34].statnum == kStatDude)
|
2019-09-19 22:42:45 +00:00
|
|
|
v4 = 0;
|
|
|
|
}
|
|
|
|
vc <<= 4;
|
2020-10-15 15:15:45 +00:00
|
|
|
int nSprite2;
|
|
|
|
StatIterator it1(kStatDude);
|
|
|
|
while ((nSprite2 = it1.NextIndex()) >= 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
if (nSprite != nSprite2 || v4)
|
|
|
|
{
|
|
|
|
spritetype *pSprite2 = &sprite[nSprite2];
|
|
|
|
if (pSprite2->extra > 0 && pSprite2->extra < kMaxXSprites)
|
|
|
|
{
|
2019-10-11 21:59:39 +00:00
|
|
|
if (pSprite2->type == kDudeBeast)
|
2019-09-19 22:42:45 +00:00
|
|
|
continue;
|
2019-09-30 07:18:01 +00:00
|
|
|
if (pSprite2->flags&32)
|
2019-09-19 22:42:45 +00:00
|
|
|
continue;
|
|
|
|
if (TestBitString(vb8, pSprite2->sectnum) && CheckProximity(pSprite2, x, y, z, nSector, vc))
|
|
|
|
{
|
|
|
|
int top, bottom;
|
|
|
|
GetSpriteExtents(pSprite, &top, &bottom);
|
|
|
|
if (klabs(bottom-sector[nSector].floorz) == 0)
|
|
|
|
{
|
|
|
|
int dx = klabs(pSprite->x-pSprite2->x);
|
|
|
|
int dy = klabs(pSprite->y-pSprite2->y);
|
|
|
|
int nDist2 = ksqrt(dx*dx + dy*dy);
|
|
|
|
if (nDist2 <= vc)
|
|
|
|
{
|
|
|
|
int nDamage;
|
|
|
|
if (!nDist2)
|
|
|
|
nDamage = v1c + v10;
|
|
|
|
else
|
|
|
|
nDamage = v1c + ((vc-nDist2)*v10)/vc;
|
|
|
|
if (IsPlayerSprite(pSprite2))
|
2019-10-21 19:46:41 +00:00
|
|
|
gPlayer[pSprite2->type-kDudePlayer1].quakeEffect += nDamage*4;
|
2019-09-19 22:42:45 +00:00
|
|
|
actDamageSprite(nSprite, pSprite2, DAMAGE_TYPE_0, nDamage<<4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-15 15:15:45 +00:00
|
|
|
it1.Reset(kStatThing);
|
|
|
|
while ((nSprite2 = it1.NextIndex()) >= 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
spritetype *pSprite2 = &sprite[nSprite2];
|
2019-09-30 07:18:01 +00:00
|
|
|
if (pSprite2->flags&32)
|
2019-09-19 22:42:45 +00:00
|
|
|
continue;
|
|
|
|
if (TestBitString(vb8, pSprite2->sectnum) && CheckProximity(pSprite2, x, y, z, nSector, vc))
|
|
|
|
{
|
|
|
|
XSPRITE *pXSprite = &xsprite[pSprite2->extra];
|
|
|
|
if (pXSprite->locked)
|
|
|
|
continue;
|
|
|
|
int dx = klabs(pSprite->x-pSprite2->x);
|
|
|
|
int dy = klabs(pSprite->y-pSprite2->y);
|
|
|
|
int nDist2 = ksqrt(dx*dx + dy*dy);
|
|
|
|
if (nDist2 <= vc)
|
|
|
|
{
|
|
|
|
int nDamage;
|
|
|
|
if (!nDist2)
|
|
|
|
nDamage = v1c + v10;
|
|
|
|
else
|
|
|
|
nDamage = v1c + ((vc-nDist2)*v10)/vc;
|
|
|
|
if (IsPlayerSprite(pSprite2))
|
2019-10-21 19:46:41 +00:00
|
|
|
gPlayer[pSprite2->type-kDudePlayer1].quakeEffect += nDamage*4;
|
2019-09-19 22:42:45 +00:00
|
|
|
actDamageSprite(nSprite, pSprite2, DAMAGE_TYPE_0, nDamage<<4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sfxPlay3DSound(pSprite, 9015+Random(2), -1, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void MorphToBeast(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
actHealDude(pXSprite, dudeInfo[51].startHealth, dudeInfo[51].startHealth);
|
2019-10-11 21:59:39 +00:00
|
|
|
pSprite->type = kDudeBeast;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkSearch(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng);
|
2020-11-06 21:48:22 +00:00
|
|
|
aiThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkGoto(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(pSprite, pXSprite, nAngle);
|
|
|
|
if (nDist < 512 && klabs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2020-11-06 21:48:22 +00:00
|
|
|
aiThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkChase(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSprite->target == -1)
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
|
|
|
XSPRITE *pXTarget = &xsprite[pTarget->extra];
|
|
|
|
int dx = pTarget->x-pSprite->x;
|
|
|
|
int dy = pTarget->y-pSprite->y;
|
|
|
|
aiChooseDirection(pSprite, pXSprite, getangle(dx, dy));
|
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-10-19 19:11:39 +00:00
|
|
|
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type-kDudePlayer1], kPwUpShadowCloak) > 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
|
|
|
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int height = (pDudeInfo->eyeHeight*pSprite->yrepeat)<<2;
|
|
|
|
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
|
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(pXSprite, pXSprite->target);
|
2020-11-07 15:26:14 +00:00
|
|
|
actor->dudeSlope = divscale(pTarget->z-pSprite->z, nDist, 10);
|
2019-09-30 07:18:01 +00:00
|
|
|
if (nDist < 0x1400 && nDist > 0xa00 && klabs(nDeltaAngle) < 85 && (pTarget->flags&2)
|
2019-09-19 22:42:45 +00:00
|
|
|
&& IsPlayerSprite(pTarget) && Chance(0x8000))
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
|
|
|
|
if (pXTarget->health > gPlayerTemplate[0].startHealth/2)
|
|
|
|
{
|
|
|
|
switch (hit)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastStomp);
|
2019-09-19 22:42:45 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (pSprite->type != sprite[gHitInfo.hitsprite].type)
|
|
|
|
{
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastStomp);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimDodge);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastDodge);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastStomp);
|
2019-09-19 22:42:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nDist < 921 && klabs(nDeltaAngle) < 28)
|
|
|
|
{
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
|
|
|
|
switch (hit)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (pSprite->type != sprite[gHitInfo.hitsprite].type)
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimDodge);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastDodge);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XSECTOR *pXSector;
|
|
|
|
int nXSector = sector[pSprite->sectnum].extra;
|
|
|
|
if (nXSector > 0)
|
|
|
|
pXSector = &xsector[nXSector];
|
|
|
|
else
|
|
|
|
pXSector = NULL;
|
|
|
|
if (pXSector && pXSector->Underwater)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimGoto);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastGoto);
|
2019-09-19 22:42:45 +00:00
|
|
|
pXSprite->target = -1;
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkSwimGoto(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(pSprite, pXSprite, nAngle);
|
|
|
|
if (nDist < 512 && klabs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2020-11-06 21:48:22 +00:00
|
|
|
aiThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkSwimChase(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSprite->target == -1)
|
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimGoto);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
|
|
|
XSPRITE *pXTarget = &xsprite[pTarget->extra];
|
|
|
|
int dx = pTarget->x-pSprite->x;
|
|
|
|
int dy = pTarget->y-pSprite->y;
|
|
|
|
aiChooseDirection(pSprite, pXSprite, getangle(dx, dy));
|
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-10-19 19:11:39 +00:00
|
|
|
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type-kDudePlayer1], kPwUpShadowCloak) > 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
|
|
|
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int height = pDudeInfo->eyeHeight+pSprite->z;
|
|
|
|
int top, bottom;
|
|
|
|
GetSpriteExtents(pSprite, &top, &bottom);
|
|
|
|
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
|
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(pXSprite, pXSprite->target);
|
|
|
|
if (nDist < 0x400 && klabs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimSlash);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
aiPlay3DSound(pSprite, 9009+Random(2), AI_SFX_PRIORITY_1, -1);
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beast138FD0);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beast138FD0);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &beastSwimGoto);
|
2019-09-19 22:42:45 +00:00
|
|
|
pXSprite->target = -1;
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastMoveForward(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
|
|
|
|
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
|
|
|
|
if (klabs(nAng) > 341)
|
|
|
|
return;
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= 0x400 && Random(64) < 32)
|
|
|
|
return;
|
2020-11-06 21:48:22 +00:00
|
|
|
actor->xvel() += mulscale30(pDudeInfo->frontSpeed, Cos(pSprite->ang));
|
|
|
|
actor->yvel() += mulscale30(pDudeInfo->frontSpeed, Sin(pSprite->ang));
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void sub_628A0(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
|
|
|
|
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
|
|
|
|
int nAccel = pDudeInfo->frontSpeed<<2;
|
|
|
|
if (klabs(nAng) > 341)
|
|
|
|
return;
|
|
|
|
if (pXSprite->target == -1)
|
|
|
|
pSprite->ang = (pSprite->ang+256)&2047;
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Random(64) < 32 && nDist <= 0x400)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2020-11-06 21:48:22 +00:00
|
|
|
int vx = actor->xvel();
|
|
|
|
int vy = actor->yvel();
|
2021-01-04 10:40:08 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSprite->target == -1)
|
|
|
|
t1 += nAccel;
|
|
|
|
else
|
|
|
|
t1 += nAccel>>2;
|
2021-01-04 10:40:08 +00:00
|
|
|
actor->xvel() = DMulScale(t1, nCos, t2, nSin, 30);
|
|
|
|
actor->yvel() = DMulScale(t1, nSin, -t2, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void sub_62AE0(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
2020-02-05 21:17:05 +00:00
|
|
|
int z = pSprite->z + getDudeInfo(pSprite->type)->eyeHeight;
|
|
|
|
int z2 = pTarget->z + getDudeInfo(pTarget->type)->eyeHeight;
|
2019-09-19 22:42:45 +00:00
|
|
|
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
|
|
|
|
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
|
|
|
|
int nAccel = pDudeInfo->frontSpeed<<2;
|
|
|
|
if (klabs(nAng) > 341)
|
|
|
|
{
|
|
|
|
pXSprite->goalAng = (pSprite->ang+512)&2047;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int dz = z2 - z;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x600) && nDist <= 0x400)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2020-11-06 21:48:22 +00:00
|
|
|
int vx = actor->xvel();
|
|
|
|
int vy = actor->yvel();
|
2021-01-04 10:40:08 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
t1 += nAccel;
|
2021-01-04 10:40:08 +00:00
|
|
|
actor->xvel() = DMulScale(t1, nCos, t2, nSin, 30);
|
|
|
|
actor->yvel() = DMulScale(t1, nSin, -t2, nCos, 30);
|
2020-11-06 21:48:22 +00:00
|
|
|
actor->zvel() = -dz;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void sub_62D7C(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-06 21:48:22 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
2019-09-19 22:42:45 +00:00
|
|
|
int nSprite = pSprite->index;
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
2020-02-05 21:17:05 +00:00
|
|
|
int z = pSprite->z + getDudeInfo(pSprite->type)->eyeHeight;
|
|
|
|
int z2 = pTarget->z + getDudeInfo(pTarget->type)->eyeHeight;
|
2019-09-19 22:42:45 +00:00
|
|
|
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
|
|
|
|
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
|
|
|
|
int nAccel = pDudeInfo->frontSpeed<<2;
|
|
|
|
if (klabs(nAng) > 341)
|
|
|
|
{
|
|
|
|
pSprite->ang = (pSprite->ang+512)&2047;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int dz = (z2 - z)<<3;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x4000) && nDist <= 0x400)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2020-11-06 21:48:22 +00:00
|
|
|
int vx = actor->xvel();
|
|
|
|
int vy = actor->yvel();
|
2021-01-04 10:40:08 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
t1 += nAccel>>1;
|
2021-01-04 10:40:08 +00:00
|
|
|
actor->xvel() = DMulScale(t1, nCos, t2, nSin, 30);
|
|
|
|
actor->yvel() = DMulScale(t1, nSin, -t2, nCos, 30);
|
2020-11-06 21:48:22 +00:00
|
|
|
actor->zvel() = dz;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|