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 "build.h"
|
|
|
|
|
|
|
|
#include "blood.h"
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2021-09-16 19:59:39 +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
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
AISTATE beastIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
|
|
|
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 };
|
2021-09-16 19:59:39 +00:00
|
|
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
spritetype* pSprite = &actor->s();
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-10-30 06:22:27 +00:00
|
|
|
int dx = bcos(pSprite->ang);
|
2021-10-30 06:22:17 +00:00
|
|
|
int dy = bsin(pSprite->ang);
|
2021-09-16 19:59:39 +00:00
|
|
|
// Correct ?
|
2021-12-22 19:02:43 +00:00
|
|
|
int dz = pSprite->pos.Z - target->spr.pos.Z;
|
2021-09-16 19:59:39 +00:00
|
|
|
dx += Random3(4000 - 700 * gGameOptions.nDifficulty);
|
|
|
|
dy += Random3(4000 - 700 * gGameOptions.nDifficulty);
|
|
|
|
actFireVector(actor, 0, 0, dx, dy, dz, kVectorGargSlash);
|
|
|
|
actFireVector(actor, 0, 0, dx, dy, dz, kVectorGargSlash);
|
|
|
|
actFireVector(actor, 0, 0, dx, dy, dz, kVectorGargSlash);
|
|
|
|
sfxPlay3DSound(actor, 9012 + Random(2), -1, 0);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 17:00:07 +00:00
|
|
|
void StompSeqCallback(int, DBloodActor* actor1)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
spritetype* pSprite = &actor1->s();
|
2021-10-30 06:22:27 +00:00
|
|
|
int dx = bcos(pSprite->ang);
|
2021-10-30 06:22:17 +00:00
|
|
|
int dy = bsin(pSprite->ang);
|
2021-12-22 10:57:10 +00:00
|
|
|
int x = pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int y = pSprite->pos.Y;
|
2021-12-22 11:29:00 +00:00
|
|
|
int z = pSprite->pos.Z;
|
2021-09-16 19:59:39 +00:00
|
|
|
int vc = 400;
|
2021-11-23 23:47:05 +00:00
|
|
|
auto pSector = pSprite->sector();
|
2021-09-16 19:59:39 +00:00
|
|
|
int v1c = 5 + 2 * gGameOptions.nDifficulty;
|
|
|
|
int v10 = 25 + 30 * gGameOptions.nDifficulty;
|
|
|
|
const bool newSectCheckMethod = !cl_bloodvanillaenemies && !VanillaMode(); // use new sector checking logic
|
2021-11-23 23:47:05 +00:00
|
|
|
auto sectorMap = GetClosestSpriteSectors(pSector, x, y, vc, nullptr, newSectCheckMethod);
|
2021-12-22 11:29:00 +00:00
|
|
|
int hit = HitScan(actor1, pSprite->pos.Z, dx, dy, 0, CLIPMASK1, 0);
|
2021-09-16 19:59:39 +00:00
|
|
|
DBloodActor* actor2 = nullptr;
|
|
|
|
actHitcodeToData(hit, &gHitInfo, &actor2);
|
2021-11-16 17:30:23 +00:00
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
vc <<= 4;
|
|
|
|
BloodStatIterator it1(kStatDude);
|
|
|
|
while (auto actor2 = it1.Next())
|
|
|
|
{
|
2021-11-16 17:30:23 +00:00
|
|
|
if (actor1 != actor2)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
spritetype* pSprite2 = &actor2->s();
|
2021-09-05 07:59:10 +00:00
|
|
|
if (actor2->hasX())
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (pSprite2->type == kDudeBeast)
|
|
|
|
continue;
|
|
|
|
if (pSprite2->flags & 32)
|
|
|
|
continue;
|
2021-12-22 14:40:15 +00:00
|
|
|
if (CheckSector(sectorMap, actor2) && CheckProximity(actor2, x, y, z, pSector, vc))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
int top, bottom;
|
|
|
|
GetActorExtents(actor1, &top, &bottom);
|
2021-11-24 00:05:17 +00:00
|
|
|
if (abs(bottom - pSector->floorz) == 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = abs(pSprite->pos.X - pSprite2->pos.X);
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = abs(pSprite->pos.Y - pSprite2->pos.Y);
|
2021-09-16 19:59:39 +00:00
|
|
|
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))
|
|
|
|
gPlayer[pSprite2->type - kDudePlayer1].quakeEffect += nDamage * 4;
|
|
|
|
actDamageSprite(actor1, actor2, kDamageFall, nDamage << 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it1.Reset(kStatThing);
|
|
|
|
while (auto actor2 = it1.Next())
|
|
|
|
{
|
|
|
|
spritetype* pSprite2 = &actor2->s();
|
|
|
|
if (pSprite2->flags & 32)
|
|
|
|
continue;
|
2021-12-22 14:40:15 +00:00
|
|
|
if (CheckSector(sectorMap, actor2) && CheckProximity(actor2, x, y, z, pSector, vc))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
XSPRITE* pXSprite = &actor2->x();
|
|
|
|
if (pXSprite->locked)
|
|
|
|
continue;
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = abs(pSprite->pos.X - pSprite2->pos.X);
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = abs(pSprite->pos.Y - pSprite2->pos.Y);
|
2021-09-16 19:59:39 +00:00
|
|
|
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))
|
|
|
|
gPlayer[pSprite2->type - kDudePlayer1].quakeEffect += nDamage * 4;
|
|
|
|
actDamageSprite(actor1, actor2, kDamageFall, nDamage << 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sfxPlay3DSound(actor1, 9015 + Random(2), -1, 0);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void MorphToBeast(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pSprite = &actor->s();
|
|
|
|
actHealDude(actor, dudeInfo[51].startHealth, dudeInfo[51].startHealth);
|
|
|
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
aiChooseDirection(actor, pXSprite->goalAng);
|
|
|
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
2021-11-19 17:35:55 +00:00
|
|
|
auto pSector = pSprite->sector();
|
|
|
|
auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr;
|
|
|
|
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(actor, nAngle);
|
|
|
|
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSearch);
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-11-19 17:35:55 +00:00
|
|
|
auto const pSprite = &actor->s();
|
2021-09-16 19:59:39 +00:00
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
2021-11-19 17:35:55 +00:00
|
|
|
auto pSector = pSprite->sector();
|
|
|
|
auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr;
|
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-09-16 19:59:39 +00:00
|
|
|
XSPRITE* pXTarget = &actor->GetTarget()->x();
|
2021-12-22 19:02:43 +00:00
|
|
|
int dx = target->spr.pos.X - pSprite->pos.X;
|
|
|
|
int dy = target->spr.pos.Y - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiChooseDirection(actor, getangle(dx, dy));
|
2021-11-19 17:35:55 +00:00
|
|
|
|
|
|
|
auto pSector = pSprite->sector();
|
|
|
|
auto pXSector = pSector->hasX() ? &pSector->xs() : nullptr;
|
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSearch);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 19:02:43 +00:00
|
|
|
if (target->IsPlayerActor() && powerupCheck(&gPlayer[target->spr.type - kDudePlayer1], kPwUpShadowCloak) > 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSearch);
|
|
|
|
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;
|
2021-12-22 19:02:43 +00:00
|
|
|
if (cansee(target->spr.pos.X, target->spr.pos.Y, target->spr.pos.Z, target->spr.sector(), pSprite->pos.X, pSprite->pos.Y, pSprite->pos.Z - height, pSprite->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(actor, actor->GetTarget());
|
2021-12-22 19:02:43 +00:00
|
|
|
actor->dudeSlope = nDist == 0? 0 : DivScale(target->spr.pos.Z - pSprite->pos.Z, nDist, 10);
|
|
|
|
if (nDist < 0x1400 && nDist > 0xa00 && abs(nDeltaAngle) < 85 && (target->spr.flags & 2)
|
|
|
|
&& target->IsPlayerActor() && Chance(0x8000))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
2021-12-22 11:29:00 +00:00
|
|
|
int hit = HitScan(actor, pSprite->pos.Z, dx, dy, 0, CLIPMASK1, 0);
|
2021-09-16 19:59:39 +00:00
|
|
|
if (pXTarget->health > (unsigned)gPlayerTemplate[0].startHealth / 2)
|
|
|
|
{
|
|
|
|
switch (hit)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastStomp);
|
|
|
|
break;
|
|
|
|
case 3:
|
2021-12-21 22:18:23 +00:00
|
|
|
if (pSprite->type != gHitInfo.actor()->spr.type)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastStomp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimDodge);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastDodge);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!pXSector || !pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastStomp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nDist < 921 && abs(nDeltaAngle) < 28)
|
|
|
|
{
|
2021-12-22 11:29:00 +00:00
|
|
|
int hit = HitScan(actor, pSprite->pos.Z, dx, dy, 0, CLIPMASK1, 0);
|
2021-09-16 19:59:39 +00:00
|
|
|
switch (hit)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSlash);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSlash);
|
|
|
|
break;
|
|
|
|
case 3:
|
2021-12-21 22:18:23 +00:00
|
|
|
if (pSprite->type != gHitInfo.actor()->spr.type)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSlash);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSlash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimDodge);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastDodge);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimSlash);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastSlash);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
if (pXSector && pXSector->Underwater)
|
|
|
|
aiNewState(actor, &beastSwimGoto);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beastGoto);
|
|
|
|
actor->SetTarget(nullptr);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastThinkSwimGoto(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(actor, nAngle);
|
|
|
|
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pSprite = &actor->s();
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &beastSwimGoto);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-09-16 19:59:39 +00:00
|
|
|
XSPRITE* pXTarget = &actor->GetTarget()->x();
|
2021-12-22 19:02:43 +00:00
|
|
|
int dx = target->spr.pos.X - pSprite->pos.X;
|
|
|
|
int dy = target->spr.pos.Y - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiChooseDirection(actor, getangle(dx, dy));
|
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 19:02:43 +00:00
|
|
|
if (target->IsPlayerActor() && powerupCheck(&gPlayer[target->spr.type - kDudePlayer1], kPwUpShadowCloak) > 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
aiNewState(actor, &beastSwimSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - pSprite->ang) & 2047) - 1024;
|
2021-12-22 11:29:00 +00:00
|
|
|
int height = pDudeInfo->eyeHeight + pSprite->pos.Z;
|
2021-09-16 19:59:39 +00:00
|
|
|
int top, bottom;
|
|
|
|
GetActorExtents(actor, &top, &bottom);
|
2021-12-22 19:02:43 +00:00
|
|
|
if (cansee(target->spr.pos.X, target->spr.pos.Y, target->spr.pos.Z, target->spr.sector(), pSprite->pos.X, pSprite->pos.Y, pSprite->pos.Z - height, pSprite->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(actor, actor->GetTarget());
|
|
|
|
if (nDist < 0x400 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &beastSwimSlash);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aiPlay3DSound(actor, 9009 + Random(2), AI_SFX_PRIORITY_1, -1);
|
|
|
|
aiNewState(actor, &beast138FD0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aiNewState(actor, &beast138FD0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aiNewState(actor, &beastSwimGoto);
|
|
|
|
actor->SetTarget(nullptr);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void beastMoveForward(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
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 (abs(nAng) > 341)
|
|
|
|
return;
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= 0x400 && Random(64) < 32)
|
|
|
|
return;
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->xvel += MulScale(pDudeInfo->frontSpeed, Cos(pSprite->ang), 30);
|
|
|
|
actor->yvel += MulScale(pDudeInfo->frontSpeed, Sin(pSprite->ang), 30);
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
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 (abs(nAng) > 341)
|
|
|
|
return;
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
pSprite->ang = (pSprite->ang + 256) & 2047;
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Random(64) < 32 && nDist <= 0x400)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2021-09-04 10:52:02 +00:00
|
|
|
int vx = actor->xvel;
|
|
|
|
int vy = actor->yvel;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
t1 += nAccel;
|
|
|
|
else
|
|
|
|
t1 += nAccel >> 2;
|
2021-09-04 10:52:02 +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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-12-22 11:29:00 +00:00
|
|
|
int z = pSprite->pos.Z + getDudeInfo(pSprite->type)->eyeHeight;
|
2021-12-22 19:02:43 +00:00
|
|
|
int z2 = target->spr.pos.Z + getDudeInfo(target->spr.type)->eyeHeight;
|
2021-09-16 19:59:39 +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 (abs(nAng) > 341)
|
|
|
|
{
|
|
|
|
pXSprite->goalAng = (pSprite->ang + 512) & 2047;
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
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);
|
2021-09-04 10:52:02 +00:00
|
|
|
int vx = actor->xvel;
|
|
|
|
int vy = actor->yvel;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
|
|
|
t1 += nAccel;
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->xvel = DMulScale(t1, nCos, t2, nSin, 30);
|
|
|
|
actor->yvel = DMulScale(t1, nSin, -t2, nCos, 30);
|
|
|
|
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
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-12-22 11:29:00 +00:00
|
|
|
int z = pSprite->pos.Z + getDudeInfo(pSprite->type)->eyeHeight;
|
2021-12-22 19:02:43 +00:00
|
|
|
int z2 = target->spr.pos.Z + getDudeInfo(target->spr.type)->eyeHeight;
|
2021-09-16 19:59:39 +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 (abs(nAng) > 341)
|
|
|
|
{
|
|
|
|
pSprite->ang = (pSprite->ang + 512) & 2047;
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
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);
|
2021-09-04 10:52:02 +00:00
|
|
|
int vx = actor->xvel;
|
|
|
|
int vy = actor->yvel;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
|
|
|
|
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
|
|
|
|
t1 += nAccel >> 1;
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->xvel = DMulScale(t1, nCos, t2, nSin, 30);
|
|
|
|
actor->yvel = DMulScale(t1, nSin, -t2, nCos, 30);
|
|
|
|
actor->zvel = dz;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|