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
|
|
|
|
|
2020-11-06 21:48:22 +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
|
|
|
{
|
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);
|
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);
|
|
|
|
DUDEINFO *pDudeInfoT = getDudeInfo(pTarget->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int height = (pSprite->yrepeat*pDudeInfo->eyeHeight)<<2;
|
|
|
|
int height2 = (pTarget->yrepeat*pDudeInfoT->eyeHeight)<<2;
|
|
|
|
/*
|
|
|
|
* workaround for
|
|
|
|
* pXSprite->target >= 0 && pXSprite->target < kMaxSprites in file NBlood/source/blood/src/aiboneel.cpp at line 86
|
|
|
|
* The value of pXSprite->target is -1.
|
|
|
|
* copied from lines 177:181
|
|
|
|
* resolves this case, but may cause other issues?
|
|
|
|
*/
|
|
|
|
if (pXSprite->target == -1)
|
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSearch);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
|
2021-08-30 18:28:24 +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
|
|
|
{
|
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);
|
2020-12-04 22:21:42 +00:00
|
|
|
DUDEEXTRA_at6_u1 *pDudeExtraE = &actor->dudeExtra.at6.u1;
|
2020-11-21 22:40:33 +00:00
|
|
|
if (pDudeExtraE->xval3 && pDudeExtraE->xval2 < 10)
|
|
|
|
pDudeExtraE->xval2++;
|
|
|
|
else if (pDudeExtraE->xval2 >= 10 && pDudeExtraE->xval3)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-21 22:40:33 +00:00
|
|
|
pDudeExtraE->xval2 = 0;
|
2019-09-19 22:42:45 +00:00
|
|
|
pXSprite->goalAng += 256;
|
|
|
|
POINT3D *pTarget = &baseSprite[pSprite->index];
|
|
|
|
aiSetTarget(pXSprite, pTarget->x, pTarget->y, pTarget->z);
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelTurn);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Chance(pDudeInfo->alertChance))
|
|
|
|
{
|
|
|
|
for (int p = connecthead; p >= 0; p = connectpoint2[p])
|
|
|
|
{
|
|
|
|
PLAYER *pPlayer = &gPlayer[p];
|
2019-10-19 19:11:39 +00:00
|
|
|
if (pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
|
2019-09-19 22:42:45 +00:00
|
|
|
continue;
|
|
|
|
int x = pPlayer->pSprite->x;
|
|
|
|
int y = pPlayer->pSprite->y;
|
|
|
|
int z = pPlayer->pSprite->z;
|
|
|
|
int nSector = pPlayer->pSprite->sectnum;
|
|
|
|
int dx = x-pSprite->x;
|
|
|
|
int dy = y-pSprite->y;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist)
|
|
|
|
continue;
|
|
|
|
if (!cansee(x, y, z, nSector, pSprite->x, pSprite->y, pSprite->z-((pDudeInfo->eyeHeight*pSprite->yrepeat)<<2), pSprite->sectnum))
|
|
|
|
continue;
|
|
|
|
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
|
2021-01-04 12:02:00 +00:00
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-11-21 22:40:33 +00:00
|
|
|
pDudeExtraE->xval2 = 0;
|
2019-10-21 19:46:41 +00:00
|
|
|
aiSetTarget(pXSprite, pPlayer->nSprite);
|
2020-11-06 21:48:22 +00:00
|
|
|
aiActivateDude(&bloodActors[pXSprite->reference]);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else if (nDist < pDudeInfo->hearDist)
|
|
|
|
{
|
2020-11-21 22:40:33 +00:00
|
|
|
pDudeExtraE->xval2 = 0;
|
2019-09-19 22:42:45 +00:00
|
|
|
aiSetTarget(pXSprite, x, y, z);
|
2020-11-06 21:48:22 +00:00
|
|
|
aiActivateDude(&bloodActors[pXSprite->reference]);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelThinkSearch(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();
|
2021-09-15 22:17:37 +00:00
|
|
|
aiChooseDirection(actor,pXSprite->goalAng);
|
2020-11-06 21:48:22 +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
|
|
|
{
|
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);
|
2021-09-15 22:17:37 +00:00
|
|
|
aiChooseDirection(actor,nAngle);
|
2021-01-04 12:02:00 +00:00
|
|
|
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSearch);
|
2020-11-06 21:48:22 +00:00
|
|
|
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
|
|
|
{
|
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, &eelSearch);
|
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;
|
2021-09-15 22:17:37 +00:00
|
|
|
aiChooseDirection(actor,getangle(dx, dy));
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSearch);
|
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;
|
2020-02-05 21:17:05 +00:00
|
|
|
int height2 = (getDudeInfo(pTarget->type)->eyeHeight*pTarget->yrepeat)<<2;
|
2019-09-19 22:42:45 +00:00
|
|
|
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))
|
|
|
|
{
|
|
|
|
aiSetTarget(pXSprite, pXSprite->target);
|
2021-01-04 12:02:00 +00:00
|
|
|
if (height2-height < -0x2000 && nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeUp);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (height2-height > 0xccc && nDist < 0x1800 && nDist > 0xc00 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeDown);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (height2-height < 0xccc && nDist < 0x399 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeUp);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (height2-height > 0xccc && nDist < 0x1400 && nDist > 0x800 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeDown);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (height2-height < -0x2000 && nDist < 0x1400 && nDist > 0x800 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeUp);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (height2-height < -0x2000 && abs(nDeltaAngle) < 85 && nDist > 0x1400)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeUp);
|
2019-09-19 22:42:45 +00:00
|
|
|
else if (height2-height > 0xccc)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeDown);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelDodgeUp);
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelGoto);
|
2019-09-19 22:42:45 +00:00
|
|
|
pXSprite->target = -1;
|
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void eelMoveDodgeUp(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 nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2020-11-06 21:48:22 +00:00
|
|
|
int dx = actor->xvel();
|
|
|
|
int dy = actor->yvel();
|
2021-01-04 10:40:08 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSprite->dodgeDir > 0)
|
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
|
|
|
|
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() = -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
|
|
|
{
|
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 (pXSprite->dodgeDir == 0)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2020-11-06 21:48:22 +00:00
|
|
|
int dx = actor->xvel();
|
|
|
|
int dy = actor->yvel();
|
2021-01-04 10:40:08 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXSprite->dodgeDir > 0)
|
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
|
|
|
|
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() = 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
|
|
|
{
|
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, &eelGoto);
|
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;
|
2021-09-15 22:17:37 +00:00
|
|
|
aiChooseDirection(actor,getangle(dx, dy));
|
2019-09-19 22:42:45 +00:00
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSearch);
|
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, &eelSearch);
|
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;
|
|
|
|
int top, bottom;
|
|
|
|
GetSpriteExtents(pSprite, &top, &bottom);
|
|
|
|
int top2, bottom2;
|
|
|
|
GetSpriteExtents(pTarget, &top2, &bottom2);
|
|
|
|
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
|
|
|
|
{
|
2021-01-04 12:02:00 +00:00
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
aiSetTarget(pXSprite, pXSprite->target);
|
2021-01-04 12:02:00 +00:00
|
|
|
if (nDist < 0x399 && top2 > top && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSwoop);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (nDist <= 0x399 && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelBite);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (bottom2 > top && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelSwoop);
|
2021-01-04 12:02:00 +00:00
|
|
|
else if (top2 < top && abs(nDeltaAngle) < 85)
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelFly);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pXSprite->target = -1;
|
2020-11-07 12:46:03 +00:00
|
|
|
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
|
|
|
{
|
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-(((4-gGameOptions.nDifficulty)<<26)/120)/120)<<2;
|
2021-01-04 12:02:00 +00:00
|
|
|
if (abs(nAng) > 341)
|
2019-09-19 22:42:45 +00:00
|
|
|
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 (nDist <= 0x399)
|
|
|
|
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>>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);
|
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
|
|
|
{
|
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-(((4-gGameOptions.nDifficulty)<<26)/120)/120)<<2;
|
2021-01-04 12:02:00 +00:00
|
|
|
if (abs(nAng) > 341)
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x8000) && nDist <= 0x399)
|
|
|
|
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() = 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
|
|
|
{
|
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-(((4-gGameOptions.nDifficulty)<<26)/120)/120)<<2;
|
2021-01-04 12:02:00 +00:00
|
|
|
if (abs(nAng) > 341)
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (Chance(0x4000) && nDist <= 0x399)
|
|
|
|
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() = -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
|
|
|
{
|
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 x = pSprite->x;
|
|
|
|
int y = pSprite->y;
|
|
|
|
int z = pSprite->z;
|
|
|
|
int nSector = pSprite->sectnum;
|
|
|
|
if (z - pXSprite->targetZ < 0x1000)
|
|
|
|
{
|
2020-12-04 22:21:42 +00:00
|
|
|
DUDEEXTRA_at6_u1 *pDudeExtraE = &actor->dudeExtra.at6.u1;
|
2020-11-21 22:40:33 +00:00
|
|
|
pDudeExtraE->xval3 = 0;
|
2019-09-30 07:18:01 +00:00
|
|
|
pSprite->flags = 0;
|
2020-11-07 12:46:03 +00:00
|
|
|
aiNewState(actor, &eelIdle);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
aiSetTarget(pXSprite, x, y, sector[nSector].ceilingz);
|
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|