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 eelThinkTarget(DBloodActor*);
|
|
|
|
static void eelThinkSearch(DBloodActor*);
|
|
|
|
static void eelThinkGoto(DBloodActor*);
|
|
|
|
static void eelThinkPonder(DBloodActor*);
|
|
|
|
static void eelMoveDodgeUp(DBloodActor*);
|
|
|
|
static void eelMoveDodgeDown(DBloodActor*);
|
|
|
|
static void eelThinkChase(DBloodActor*);
|
|
|
|
static void eelMoveForward(DBloodActor*);
|
|
|
|
static void eelMoveSwoop(DBloodActor*);
|
|
|
|
static void eelMoveAscend(DBloodActor* actor);
|
|
|
|
static void eelMoveToCeil(DBloodActor*);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE eelIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, eelThinkTarget, NULL };
|
|
|
|
AISTATE eelFlyIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, eelThinkTarget, NULL };
|
|
|
|
AISTATE eelChase = { kAiStateChase, 0, -1, 0, NULL, eelMoveForward, eelThinkChase, &eelIdle };
|
|
|
|
AISTATE eelPonder = { kAiStateOther, 0, -1, 0, NULL, NULL, eelThinkPonder, NULL };
|
|
|
|
AISTATE eelGoto = { kAiStateMove, 0, -1, 600, NULL, NULL, eelThinkGoto, &eelIdle };
|
|
|
|
AISTATE eelBite = { kAiStateChase, 7, nEelBiteClient, 60, NULL, NULL, NULL, &eelChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE eelRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &eelChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE eelSearch = { kAiStateSearch, 0, -1, 120, NULL, eelMoveForward, eelThinkSearch, &eelIdle };
|
|
|
|
AISTATE eelSwoop = { kAiStateOther, 0, -1, 60, NULL, eelMoveSwoop, eelThinkChase, &eelChase };
|
|
|
|
AISTATE eelFly = { kAiStateMove, 0, -1, 0, NULL, eelMoveAscend, eelThinkChase, &eelChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE eelTurn = { kAiStateMove, 0, -1, 60, NULL, aiMoveTurn, NULL, &eelChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE eelHide = { kAiStateOther, 0, -1, 0, NULL, eelMoveToCeil, eelMoveForward, NULL };
|
|
|
|
AISTATE eelDodgeUp = { kAiStateMove, 0, -1, 120, NULL, eelMoveDodgeUp, NULL, &eelChase };
|
|
|
|
AISTATE eelDodgeUpRight = { kAiStateMove, 0, -1, 90, NULL, eelMoveDodgeUp, NULL, &eelChase };
|
|
|
|
AISTATE eelDodgeUpLeft = { kAiStateMove, 0, -1, 90, NULL, eelMoveDodgeUp, NULL, &eelChase };
|
|
|
|
AISTATE eelDodgeDown = { kAiStateMove, 0, -1, 120, NULL, eelMoveDodgeDown, NULL, &eelChase };
|
|
|
|
AISTATE eelDodgeDownRight = { kAiStateMove, 0, -1, 90, NULL, eelMoveDodgeDown, NULL, &eelChase };
|
|
|
|
AISTATE eelDodgeDownLeft = { kAiStateMove, 0, -1, 90, NULL, eelMoveDodgeDown, NULL, &eelChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void eelBiteSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
/*
|
|
|
|
* workaround for
|
2021-12-22 21:49:50 +00:00
|
|
|
* actor->xspr.target >= 0 in file NBlood/source/blood/src/aiboneel.cpp at line 86
|
|
|
|
* The value of actor->xspr.target is -1.
|
2021-09-16 19:59:39 +00:00
|
|
|
* copied from lines 177:181
|
|
|
|
* resolves this case, but may cause other issues?
|
|
|
|
*/
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &eelSearch);
|
|
|
|
return;
|
|
|
|
}
|
2021-05-05 08:12:31 +00:00
|
|
|
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2022-08-16 21:15:49 +00:00
|
|
|
int dx = bcos(actor->int_ang());
|
|
|
|
int dy = bsin(actor->int_ang());
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2021-12-22 19:02:43 +00:00
|
|
|
DUDEINFO* pDudeInfoT = getDudeInfo(target->spr.type);
|
2021-12-22 19:22:35 +00:00
|
|
|
int height = (actor->spr.yrepeat * pDudeInfo->eyeHeight) << 2;
|
2021-12-22 19:02:43 +00:00
|
|
|
int height2 = (target->spr.yrepeat * pDudeInfoT->eyeHeight) << 2;
|
2021-09-16 19:59:39 +00:00
|
|
|
actFireVector(actor, 0, 0, dx, dy, height2 - height, kVectorBoneelBite);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkTarget(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2021-09-16 19:59:39 +00:00
|
|
|
DUDEEXTRA_STATS* pDudeExtraE = &actor->dudeExtra.stats;
|
|
|
|
if (pDudeExtraE->active && pDudeExtraE->thinkTime < 10)
|
|
|
|
pDudeExtraE->thinkTime++;
|
|
|
|
else if (pDudeExtraE->thinkTime >= 10 && pDudeExtraE->active)
|
|
|
|
{
|
|
|
|
pDudeExtraE->thinkTime = 0;
|
2021-12-22 21:49:50 +00:00
|
|
|
actor->xspr.goalAng += 256;
|
2022-08-10 22:13:36 +00:00
|
|
|
aiSetTarget(actor, actor->basePoint);
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &eelTurn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Chance(pDudeInfo->alertChance))
|
|
|
|
{
|
|
|
|
for (int p = connecthead; p >= 0; p = connectpoint2[p])
|
|
|
|
{
|
|
|
|
PLAYER* pPlayer = &gPlayer[p];
|
2021-12-22 21:49:50 +00:00
|
|
|
if (pPlayer->actor->xspr.health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
continue;
|
2022-08-22 16:35:16 +00:00
|
|
|
auto ppos = pPlayer->actor->spr.pos;
|
2022-01-30 17:09:26 +00:00
|
|
|
int x = pPlayer->actor->int_pos().X;
|
|
|
|
int y = pPlayer->actor->int_pos().Y;
|
|
|
|
int z = pPlayer->actor->int_pos().Z;
|
2021-12-30 15:51:56 +00:00
|
|
|
auto pSector = pPlayer->actor->sector();
|
2022-01-30 17:09:26 +00:00
|
|
|
int dx = x - actor->int_pos().X;
|
|
|
|
int dy = y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist)
|
|
|
|
continue;
|
2022-08-22 16:35:16 +00:00
|
|
|
double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE;
|
|
|
|
if (!cansee(ppos, pSector, actor->spr.pos.plusZ(-height), actor->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
continue;
|
2022-08-16 21:17:01 +00:00
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
pDudeExtraE->thinkTime = 0;
|
2021-12-29 18:41:41 +00:00
|
|
|
aiSetTarget(actor, pPlayer->actor);
|
2021-09-16 19:59:39 +00:00
|
|
|
aiActivateDude(actor);
|
|
|
|
}
|
|
|
|
else if (nDist < pDudeInfo->hearDist)
|
|
|
|
{
|
|
|
|
pDudeExtraE->thinkTime = 0;
|
|
|
|
aiSetTarget(actor, x, y, z);
|
|
|
|
aiActivateDude(actor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkSearch(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 21:49:50 +00:00
|
|
|
aiChooseDirection(actor, actor->xspr.goalAng);
|
2021-09-16 19:59:39 +00:00
|
|
|
eelThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkGoto(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-22 16:31:23 +00:00
|
|
|
int dx = actor->xspr.int_TargetPos().X - actor->int_pos().X;
|
|
|
|
int dy = actor->xspr.int_TargetPos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(actor, nAngle);
|
2022-08-16 21:15:49 +00:00
|
|
|
if (nDist < 512 && abs(actor->int_ang() - nAngle) < pDudeInfo->periphery)
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &eelSearch);
|
|
|
|
eelThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkPonder(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &eelSearch);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-12-29 18:41:41 +00:00
|
|
|
|
2022-01-30 17:09:26 +00:00
|
|
|
int dx = target->int_pos().X - actor->int_pos().X;
|
|
|
|
int dy = target->int_pos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiChooseDirection(actor, getangle(dx, dy));
|
2021-12-22 19:48:11 +00:00
|
|
|
if (target->xspr.health == 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
aiNewState(actor, &eelSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
2022-08-16 21:17:01 +00:00
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-12-22 19:22:35 +00:00
|
|
|
int height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) << 2;
|
2021-12-22 19:02:43 +00:00
|
|
|
int height2 = (getDudeInfo(target->spr.type)->eyeHeight * target->spr.yrepeat) << 2;
|
2021-09-16 19:59:39 +00:00
|
|
|
int top, bottom;
|
|
|
|
GetActorExtents(actor, &top, &bottom);
|
2022-08-22 16:35:16 +00:00
|
|
|
if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height * zinttoworld), actor->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
aiSetTarget(actor, actor->GetTarget());
|
|
|
|
if (height2 - height < -0x2000 && nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelDodgeUp);
|
|
|
|
else if (height2 - height > 0xccc && nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelDodgeDown);
|
|
|
|
else if (height2 - height < 0xccc && nDist < 0x399 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelDodgeUp);
|
|
|
|
else if (height2 - height > 0xccc && nDist < 0x1400 && nDist > 0x800 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelDodgeDown);
|
|
|
|
else if (height2 - height < -0x2000 && nDist < 0x1400 && nDist > 0x800 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelDodgeUp);
|
|
|
|
else if (height2 - height < -0x2000 && abs(nDeltaAngle) < 85 && nDist > 0x1400)
|
|
|
|
aiNewState(actor, &eelDodgeUp);
|
|
|
|
else if (height2 - height > 0xccc)
|
|
|
|
aiNewState(actor, &eelDodgeDown);
|
|
|
|
else
|
|
|
|
aiNewState(actor, &eelDodgeUp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aiNewState(actor, &eelGoto);
|
|
|
|
actor->SetTarget(nullptr);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveDodgeUp(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-16 21:17:01 +00:00
|
|
|
int nAng = ((actor->xspr.goalAng + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nTurnRange = (pDudeInfo->angSpeed << 2) >> 4;
|
2022-08-16 21:20:03 +00:00
|
|
|
actor->set_int_ang((actor->int_ang() + ClipRange(nAng, -nTurnRange, nTurnRange)) & 2047);
|
2022-08-16 21:15:49 +00:00
|
|
|
int nCos = Cos(actor->int_ang());
|
|
|
|
int nSin = Sin(actor->int_ang());
|
2021-12-30 10:15:27 +00:00
|
|
|
int dx = actor->vel.X;
|
2021-12-30 10:16:31 +00:00
|
|
|
int dy = actor->vel.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
2021-12-22 21:49:50 +00:00
|
|
|
if (actor->xspr.dodgeDir > 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-12-30 10:15:27 +00:00
|
|
|
actor->vel.X = DMulScale(t1, nCos, t2, nSin, 30);
|
2021-12-30 10:16:31 +00:00
|
|
|
actor->vel.Y = DMulScale(t1, nSin, -t2, nCos, 30);
|
2021-12-30 10:17:28 +00:00
|
|
|
actor->vel.Z = -0x8000;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveDodgeDown(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-16 21:17:01 +00:00
|
|
|
int nAng = ((actor->xspr.goalAng + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nTurnRange = (pDudeInfo->angSpeed << 2) >> 4;
|
2022-08-16 21:20:03 +00:00
|
|
|
actor->set_int_ang((actor->int_ang() + ClipRange(nAng, -nTurnRange, nTurnRange)) & 2047);
|
2021-12-22 21:49:50 +00:00
|
|
|
if (actor->xspr.dodgeDir == 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
return;
|
2022-08-16 21:15:49 +00:00
|
|
|
int nCos = Cos(actor->int_ang());
|
|
|
|
int nSin = Sin(actor->int_ang());
|
2021-12-30 10:15:27 +00:00
|
|
|
int dx = actor->vel.X;
|
2021-12-30 10:16:31 +00:00
|
|
|
int dy = actor->vel.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
2021-12-22 21:49:50 +00:00
|
|
|
if (actor->xspr.dodgeDir > 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-12-30 10:15:27 +00:00
|
|
|
actor->vel.X = DMulScale(t1, nCos, t2, nSin, 30);
|
2021-12-30 10:16:31 +00:00
|
|
|
actor->vel.Y = DMulScale(t1, nSin, -t2, nCos, 30);
|
2021-12-30 10:17:28 +00:00
|
|
|
actor->vel.Z = 0x44444;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkChase(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &eelGoto);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2021-12-22 19:02:43 +00:00
|
|
|
auto target = actor->GetTarget();
|
2021-12-29 18:41:41 +00:00
|
|
|
|
2022-01-30 17:09:26 +00:00
|
|
|
int dx = target->int_pos().X - actor->int_pos().X;
|
|
|
|
int dy = target->int_pos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiChooseDirection(actor, getangle(dx, dy));
|
2021-12-22 19:48:11 +00:00
|
|
|
if (target->xspr.health == 0)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
aiNewState(actor, &eelSearch);
|
|
|
|
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, &eelSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
2022-08-16 21:17:01 +00:00
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - actor->int_ang()) & 2047) - 1024;
|
2022-08-22 16:35:16 +00:00
|
|
|
double height = (pDudeInfo->eyeHeight * actor->spr.yrepeat) * REPEAT_SCALE;
|
2021-09-16 19:59:39 +00:00
|
|
|
int top, bottom;
|
|
|
|
GetActorExtents(actor, &top, &bottom);
|
|
|
|
int top2, bottom2;
|
2021-12-22 19:02:43 +00:00
|
|
|
GetActorExtents(target, &top2, &bottom2);
|
2022-08-22 16:35:16 +00:00
|
|
|
if (cansee(target->spr.pos, target->sector(), actor->spr.pos.plusZ(-height), actor->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(actor, actor->GetTarget());
|
|
|
|
if (nDist < 0x399 && top2 > top && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelSwoop);
|
|
|
|
else if (nDist <= 0x399 && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelBite);
|
|
|
|
else if (bottom2 > top && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelSwoop);
|
|
|
|
else if (top2 < top && abs(nDeltaAngle) < 85)
|
|
|
|
aiNewState(actor, &eelFly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
actor->SetTarget(nullptr);
|
|
|
|
aiNewState(actor, &eelSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveForward(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-16 21:17:01 +00:00
|
|
|
int nAng = ((actor->xspr.goalAng + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nTurnRange = (pDudeInfo->angSpeed << 2) >> 4;
|
2022-08-16 21:20:03 +00:00
|
|
|
actor->set_int_ang((actor->int_ang() + ClipRange(nAng, -nTurnRange, nTurnRange)) & 2047);
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
|
|
|
|
if (abs(nAng) > 341)
|
|
|
|
return;
|
|
|
|
if (actor->GetTarget() == nullptr)
|
2022-08-21 17:19:47 +00:00
|
|
|
actor->spr.angle += DAngle45;
|
2022-08-22 16:31:23 +00:00
|
|
|
int dx = actor->xspr.int_TargetPos().X - actor->int_pos().X;
|
|
|
|
int dy = actor->xspr.int_TargetPos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= 0x399)
|
|
|
|
return;
|
2022-08-16 21:15:49 +00:00
|
|
|
int nCos = Cos(actor->int_ang());
|
|
|
|
int nSin = Sin(actor->int_ang());
|
2021-12-30 10:15:27 +00:00
|
|
|
int vx = actor->vel.X;
|
2021-12-30 10:16:31 +00:00
|
|
|
int vy = actor->vel.Y;
|
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 >> 1;
|
2021-12-30 10:15:27 +00:00
|
|
|
actor->vel.X = DMulScale(t1, nCos, t2, nSin, 30);
|
2021-12-30 10:16:31 +00:00
|
|
|
actor->vel.Y = DMulScale(t1, nSin, -t2, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveSwoop(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-16 21:17:01 +00:00
|
|
|
int nAng = ((actor->xspr.goalAng + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nTurnRange = (pDudeInfo->angSpeed << 2) >> 4;
|
2022-08-16 21:20:03 +00:00
|
|
|
actor->set_int_ang((actor->int_ang() + ClipRange(nAng, -nTurnRange, nTurnRange)) & 2047);
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
|
|
|
|
if (abs(nAng) > 341)
|
|
|
|
return;
|
2022-08-22 16:31:23 +00:00
|
|
|
int dx = actor->xspr.int_TargetPos().X - actor->int_pos().X;
|
|
|
|
int dy = actor->xspr.int_TargetPos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x8000) && nDist <= 0x399)
|
|
|
|
return;
|
2022-08-16 21:15:49 +00:00
|
|
|
int nCos = Cos(actor->int_ang());
|
|
|
|
int nSin = Sin(actor->int_ang());
|
2021-12-30 10:15:27 +00:00
|
|
|
int vx = actor->vel.X;
|
2021-12-30 10:16:31 +00:00
|
|
|
int vy = actor->vel.Y;
|
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-12-30 10:15:27 +00:00
|
|
|
actor->vel.X = DMulScale(t1, nCos, t2, nSin, 30);
|
2021-12-30 10:16:31 +00:00
|
|
|
actor->vel.Y = DMulScale(t1, nSin, -t2, nCos, 30);
|
2021-12-30 10:17:28 +00:00
|
|
|
actor->vel.Z = 0x22222;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveAscend(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-12-22 19:22:35 +00:00
|
|
|
assert(actor->spr.type >= kDudeBase && actor->spr.type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(actor->spr.type);
|
2022-08-16 21:17:01 +00:00
|
|
|
int nAng = ((actor->xspr.goalAng + 1024 - actor->int_ang()) & 2047) - 1024;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nTurnRange = (pDudeInfo->angSpeed << 2) >> 4;
|
2022-08-16 21:20:03 +00:00
|
|
|
actor->set_int_ang((actor->int_ang() + ClipRange(nAng, -nTurnRange, nTurnRange)) & 2047);
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAccel = (pDudeInfo->frontSpeed - (((4 - gGameOptions.nDifficulty) << 26) / 120) / 120) << 2;
|
|
|
|
if (abs(nAng) > 341)
|
|
|
|
return;
|
2022-08-22 16:31:23 +00:00
|
|
|
int dx = actor->xspr.int_TargetPos().X - actor->int_pos().X;
|
|
|
|
int dy = actor->xspr.int_TargetPos().Y - actor->int_pos().Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x4000) && nDist <= 0x399)
|
|
|
|
return;
|
2022-08-16 21:15:49 +00:00
|
|
|
int nCos = Cos(actor->int_ang());
|
|
|
|
int nSin = Sin(actor->int_ang());
|
2021-12-30 10:15:27 +00:00
|
|
|
int vx = actor->vel.X;
|
2021-12-30 10:16:31 +00:00
|
|
|
int vy = actor->vel.Y;
|
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-12-30 10:15:27 +00:00
|
|
|
actor->vel.X = DMulScale(t1, nCos, t2, nSin, 30);
|
2021-12-30 10:16:31 +00:00
|
|
|
actor->vel.Y = DMulScale(t1, nSin, -t2, nCos, 30);
|
2021-12-30 10:17:28 +00:00
|
|
|
actor->vel.Z = -0x8000;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
void eelMoveToCeil(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2022-01-30 17:09:26 +00:00
|
|
|
int x = actor->int_pos().X;
|
|
|
|
int y = actor->int_pos().Y;
|
|
|
|
int z = actor->int_pos().Z;
|
2022-08-22 16:31:23 +00:00
|
|
|
if (z - actor->xspr.int_TargetPos().Z < 0x1000)
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
DUDEEXTRA_STATS* pDudeExtraE = &actor->dudeExtra.stats;
|
|
|
|
pDudeExtraE->active = 0;
|
2021-12-22 19:22:35 +00:00
|
|
|
actor->spr.flags = 0;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &eelIdle);
|
|
|
|
}
|
|
|
|
else
|
2022-02-02 23:46:04 +00:00
|
|
|
aiSetTarget(actor, x, y, actor->sector()->int_ceilingz());
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|