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 ghostThinkTarget(DBloodActor*);
|
|
|
|
static void ghostThinkSearch(DBloodActor*);
|
|
|
|
static void ghostThinkGoto(DBloodActor*);
|
|
|
|
static void ghostMoveDodgeUp(DBloodActor*);
|
|
|
|
static void ghostMoveDodgeDown(DBloodActor*);
|
|
|
|
static void ghostThinkChase(DBloodActor*);
|
|
|
|
static void ghostMoveForward(DBloodActor*);
|
|
|
|
static void ghostMoveSlow(DBloodActor*);
|
|
|
|
static void ghostMoveSwoop(DBloodActor*);
|
|
|
|
static void ghostMoveFly(DBloodActor*);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE ghostIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, ghostThinkTarget, NULL };
|
|
|
|
AISTATE ghostChase = { kAiStateChase, 0, -1, 0, NULL, ghostMoveForward, ghostThinkChase, &ghostIdle };
|
|
|
|
AISTATE ghostGoto = { kAiStateMove, 0, -1, 600, NULL, ghostMoveForward, ghostThinkGoto, &ghostIdle };
|
|
|
|
AISTATE ghostSlash = { kAiStateChase, 6, nGhostSlashClient, 120, NULL, NULL, NULL, &ghostChase };
|
|
|
|
AISTATE ghostThrow = { kAiStateChase, 6, nGhostThrowClient, 120, NULL, NULL, NULL, &ghostChase };
|
|
|
|
AISTATE ghostBlast = { kAiStateChase, 6, nGhostBlastClient, 120, NULL, ghostMoveSlow, NULL, &ghostChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE ghostRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &ghostChase };
|
|
|
|
AISTATE ghostTeslaRecoil = { kAiStateRecoil, 4, -1, 0, NULL, NULL, NULL, &ghostChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE ghostSearch = { kAiStateSearch, 0, -1, 120, NULL, ghostMoveForward, ghostThinkSearch, &ghostIdle };
|
|
|
|
AISTATE ghostSwoop = { kAiStateOther, 0, -1, 120, NULL, ghostMoveSwoop, ghostThinkChase, &ghostChase };
|
|
|
|
AISTATE ghostFly = { kAiStateMove, 0, -1, 0, NULL, ghostMoveFly, ghostThinkChase, &ghostChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE ghostTurn = { kAiStateMove, 0, -1, 120, NULL, aiMoveTurn, NULL, &ghostChase };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE ghostDodgeUp = { kAiStateMove, 0, -1, 60, NULL, ghostMoveDodgeUp, NULL, &ghostChase };
|
|
|
|
AISTATE ghostDodgeUpRight = { kAiStateMove, 0, -1, 90, NULL, ghostMoveDodgeUp, NULL, &ghostChase };
|
|
|
|
AISTATE ghostDodgeUpLeft = { kAiStateMove, 0, -1, 90, NULL, ghostMoveDodgeUp, NULL, &ghostChase };
|
|
|
|
AISTATE ghostDodgeDown = { kAiStateMove, 0, -1, 120, NULL, ghostMoveDodgeDown, NULL, &ghostChase };
|
|
|
|
AISTATE ghostDodgeDownRight = { kAiStateMove, 0, -1, 90, NULL, ghostMoveDodgeDown, NULL, &ghostChase };
|
|
|
|
AISTATE ghostDodgeDownLeft = { kAiStateMove, 0, -1, 90, NULL, ghostMoveDodgeDown, NULL, &ghostChase };
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void ghostSlashSeqCallback(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;
|
|
|
|
spritetype* pTarget = &actor->GetTarget()->s();
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
DUDEINFO* pDudeInfoT = getDudeInfo(pTarget->type);
|
|
|
|
int height = (pSprite->yrepeat * pDudeInfo->eyeHeight) << 2;
|
|
|
|
int height2 = (pTarget->yrepeat * pDudeInfoT->eyeHeight) << 2;
|
|
|
|
int dz = height - height2;
|
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
|
|
|
sfxPlay3DSound(actor, 1406, 0, 0);
|
|
|
|
actFireVector(actor, 0, 0, dx, dy, dz, kVectorGhost);
|
|
|
|
int r1 = Random(50);
|
|
|
|
int r2 = Random(50);
|
|
|
|
actFireVector(actor, 0, 0, dx + r2, dy - r1, dz, kVectorGhost);
|
|
|
|
r1 = Random(50);
|
|
|
|
r2 = Random(50);
|
|
|
|
actFireVector(actor, 0, 0, dx - r2, dy + r1, dz, kVectorGhost);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void ghostThrowSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
actFireThing(actor, 0, 0, actor->dudeSlope - 7500, kThingBone, 0xeeeee);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void ghostBlastSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
XSPRITE* pXSprite = &actor->x();
|
|
|
|
spritetype* pSprite = &actor->s();
|
|
|
|
wrand(); // ???
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
|
|
|
spritetype* pTarget = &actor->GetTarget()->s();
|
|
|
|
int height = (pSprite->yrepeat * getDudeInfo(pSprite->type)->eyeHeight) << 2;
|
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-09-16 19:59:39 +00:00
|
|
|
int z = height;
|
|
|
|
TARGETTRACK tt = { 0x10000, 0x10000, 0x100, 0x55, 0x1aaaaa };
|
|
|
|
Aim aim;
|
2021-10-30 06:22:27 +00:00
|
|
|
aim.dx = bcos(pSprite->ang);
|
2021-10-30 06:22:17 +00:00
|
|
|
aim.dy = bsin(pSprite->ang);
|
2021-09-16 19:59:39 +00:00
|
|
|
aim.dz = actor->dudeSlope;
|
|
|
|
int nClosest = 0x7fffffff;
|
|
|
|
BloodStatIterator it(kStatDude);
|
|
|
|
while (auto actor2 = it.Next())
|
|
|
|
{
|
|
|
|
spritetype* pSprite2 = &actor2->s();
|
|
|
|
if (pSprite == pSprite2 || !(pSprite2->flags & 8))
|
|
|
|
continue;
|
2021-12-22 10:57:10 +00:00
|
|
|
int x2 = pSprite2->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int y2 = pSprite2->pos.Y;
|
2021-12-22 11:29:00 +00:00
|
|
|
int z2 = pSprite2->pos.Z;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(x2 - x, y2 - y);
|
|
|
|
if (nDist == 0 || nDist > 0x2800)
|
|
|
|
continue;
|
|
|
|
if (tt.at10)
|
|
|
|
{
|
|
|
|
int t = DivScale(nDist, tt.at10, 12);
|
2021-09-04 10:52:02 +00:00
|
|
|
x2 += (actor->xvel * t) >> 12;
|
|
|
|
y2 += (actor->yvel * t) >> 12;
|
|
|
|
z2 += (actor->zvel * t) >> 8;
|
2021-09-16 19:59:39 +00:00
|
|
|
}
|
|
|
|
int tx = x + MulScale(Cos(pSprite->ang), nDist, 30);
|
|
|
|
int ty = y + MulScale(Sin(pSprite->ang), nDist, 30);
|
|
|
|
int tz = z + MulScale(actor->dudeSlope, nDist, 10);
|
|
|
|
int tsr = MulScale(9460, nDist, 10);
|
|
|
|
int top, bottom;
|
|
|
|
GetSpriteExtents(pSprite2, &top, &bottom);
|
|
|
|
if (tz - tsr > bottom || tz + tsr < top)
|
|
|
|
continue;
|
|
|
|
int dx = (tx - x2) >> 4;
|
|
|
|
int dy = (ty - y2) >> 4;
|
|
|
|
int dz = (tz - z2) >> 8;
|
|
|
|
int nDist2 = ksqrt(dx * dx + dy * dy + dz * dz);
|
|
|
|
if (nDist2 < nClosest)
|
|
|
|
{
|
|
|
|
int nAngle = getangle(x2 - x, y2 - y);
|
|
|
|
int nDeltaAngle = ((nAngle - pSprite->ang + 1024) & 2047) - 1024;
|
|
|
|
if (abs(nDeltaAngle) <= tt.at8)
|
|
|
|
{
|
2021-12-22 11:29:00 +00:00
|
|
|
int tz = pSprite2->pos.Z - pSprite->pos.Z;
|
2021-11-23 23:35:46 +00:00
|
|
|
if (cansee(x, y, z, pSprite->sector(), x2, y2, z2, pSprite2->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
{
|
|
|
|
nClosest = nDist2;
|
2021-10-30 06:22:27 +00:00
|
|
|
aim.dx = bcos(nAngle);
|
2021-10-30 06:22:17 +00:00
|
|
|
aim.dy = bsin(nAngle);
|
2021-09-16 19:59:39 +00:00
|
|
|
aim.dz = DivScale(tz, nDist, 10);
|
|
|
|
if (tz > -0x333)
|
|
|
|
aim.dz = DivScale(tz, nDist, 10);
|
|
|
|
else if (tz < -0x333 && tz > -0xb33)
|
|
|
|
aim.dz = DivScale(tz, nDist, 10) + 9460;
|
|
|
|
else if (tz < -0xb33 && tz > -0x3000)
|
|
|
|
aim.dz = DivScale(tz, nDist, 10) + 9460;
|
|
|
|
else if (tz < -0x3000)
|
|
|
|
aim.dz = DivScale(tz, nDist, 10) - 7500;
|
|
|
|
else
|
|
|
|
aim.dz = DivScale(tz, nDist, 10);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aim.dz = DivScale(tz, nDist, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef NOONE_EXTENSIONS
|
|
|
|
// allow fire missile in non-player targets if not a demo
|
|
|
|
if (IsPlayerSprite(pTarget) || gModernMap) {
|
|
|
|
sfxPlay3DSound(actor, 489, 0, 0);
|
2020-12-05 20:23:53 +00:00
|
|
|
actFireMissile(actor, 0, 0, aim.dx, aim.dy, aim.dz, kMissileEctoSkull);
|
2021-09-16 19:59:39 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (IsPlayerSprite(pTarget)) {
|
|
|
|
sfxPlay3DSound(actor, 489, 0, 0);
|
2020-12-05 20:23:53 +00:00
|
|
|
actFireMissile(actor, 0, 0, aim.dx, aim.dy, aim.dz, kMissileEctoSkull);
|
2021-09-16 19:59:39 +00:00
|
|
|
}
|
|
|
|
#endif
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostThinkTarget(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
DUDEEXTRA_STATS* pDudeExtraE = &actor->dudeExtra.stats;
|
|
|
|
if (pDudeExtraE->active && pDudeExtraE->thinkTime < 10)
|
|
|
|
pDudeExtraE->thinkTime++;
|
|
|
|
else if (pDudeExtraE->thinkTime >= 10 && pDudeExtraE->active)
|
|
|
|
{
|
|
|
|
pXSprite->goalAng += 256;
|
2021-09-04 10:23:36 +00:00
|
|
|
POINT3D* pTarget = &actor->basePoint;
|
2021-12-22 09:41:47 +00:00
|
|
|
aiSetTarget(actor, pTarget->X, pTarget->Y, pTarget->Z);
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &ghostTurn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Chance(pDudeInfo->alertChance))
|
|
|
|
{
|
|
|
|
for (int p = connecthead; p >= 0; p = connectpoint2[p])
|
|
|
|
{
|
|
|
|
PLAYER* pPlayer = &gPlayer[p];
|
|
|
|
if (pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
|
|
|
|
continue;
|
2021-12-22 10:57:10 +00:00
|
|
|
int x = pPlayer->pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int y = pPlayer->pSprite->pos.Y;
|
2021-12-22 11:29:00 +00:00
|
|
|
int z = pPlayer->pSprite->pos.Z;
|
2021-11-23 23:35:46 +00:00
|
|
|
auto pSector = pPlayer->pSprite->sector();
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = x - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = y - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist > pDudeInfo->seeDist && nDist > pDudeInfo->hearDist)
|
|
|
|
continue;
|
2021-12-22 11:29:00 +00:00
|
|
|
if (!cansee(x, y, z, pSector, pSprite->pos.X, pSprite->pos.Y, pSprite->pos.Z - ((pDudeInfo->eyeHeight * pSprite->yrepeat) << 2), pSprite->sector()))
|
2021-09-16 19:59:39 +00:00
|
|
|
continue;
|
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - pSprite->ang) & 2047) - 1024;
|
|
|
|
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
pDudeExtraE->thinkTime = 0;
|
2021-09-05 07:53:06 +00:00
|
|
|
aiSetTarget(actor, pPlayer->actor);
|
2021-09-16 19:59:39 +00:00
|
|
|
aiActivateDude(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (nDist < pDudeInfo->hearDist)
|
|
|
|
{
|
|
|
|
pDudeExtraE->thinkTime = 0;
|
|
|
|
aiSetTarget(actor, x, y, z);
|
|
|
|
aiActivateDude(actor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostThinkSearch(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 ghostThinkGoto(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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, &ghostSearch);
|
|
|
|
aiThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveDodgeUp(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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 nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2021-09-04 10:52:02 +00:00
|
|
|
int dx = actor->xvel;
|
|
|
|
int dy = actor->yvel;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
|
|
|
if (pXSprite->dodgeDir > 0)
|
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
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 = -0x1d555;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveDodgeDown(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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 (pXSprite->dodgeDir == 0)
|
|
|
|
return;
|
|
|
|
int nCos = Cos(pSprite->ang);
|
|
|
|
int nSin = Sin(pSprite->ang);
|
2021-09-04 10:52:02 +00:00
|
|
|
int dx = actor->xvel;
|
|
|
|
int dy = actor->yvel;
|
2021-09-16 19:59:39 +00:00
|
|
|
int t1 = DMulScale(dx, nCos, dy, nSin, 30);
|
|
|
|
int t2 = DMulScale(dx, nSin, -dy, nCos, 30);
|
|
|
|
if (pXSprite->dodgeDir > 0)
|
|
|
|
t2 += pDudeInfo->sideSpeed;
|
|
|
|
else
|
|
|
|
t2 -= pDudeInfo->sideSpeed;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
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 = 0x44444;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostThinkChase(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();
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &ghostGoto);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
///assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
spritetype* pTarget = &actor->GetTarget()->s();
|
|
|
|
XSPRITE* pXTarget = &actor->GetTarget()->x();
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pTarget->pos.X - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pTarget->pos.Y - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
aiChooseDirection(actor, getangle(dx, dy));
|
|
|
|
if (pXTarget->health == 0)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &ghostSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type - kDudePlayer1], kPwUpShadowCloak) > 0)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &ghostSearch);
|
|
|
|
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;
|
|
|
|
// Should be dudeInfo[pTarget->type-kDudeBase]
|
|
|
|
int height2 = (pDudeInfo->eyeHeight * pTarget->yrepeat) << 2;
|
|
|
|
int top, bottom;
|
|
|
|
GetActorExtents(actor, &top, &bottom);
|
2021-12-22 11:29:00 +00:00
|
|
|
if (cansee(pTarget->pos.X, pTarget->pos.Y, pTarget->pos.Z, pTarget->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 11:17:17 +00:00
|
|
|
int floorZ = getflorzofslopeptr(pSprite->sector(), pSprite->pos.X, pSprite->pos.Y);
|
2021-09-16 19:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePhantasm:
|
|
|
|
if (nDist < 0x2000 && nDist > 0x1000 && abs(nDeltaAngle) < 85) {
|
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:
|
|
|
|
aiNewState(actor, &ghostBlast);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
case 3:
|
2021-12-21 22:18:23 +00:00
|
|
|
if (pSprite->type != gHitInfo.actor()->spr.type && gHitInfo.actor()->spr.type != kDudePhantasm)
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &ghostBlast);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aiNewState(actor, &ghostBlast);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nDist < 0x400 && abs(nDeltaAngle) < 85)
|
|
|
|
{
|
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:
|
|
|
|
aiNewState(actor, &ghostSlash);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
break;
|
|
|
|
case 3:
|
2021-12-21 22:18:23 +00:00
|
|
|
if (pSprite->type != gHitInfo.actor()->spr.type && gHitInfo.actor()->spr.type != kDudePhantasm)
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &ghostSlash);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aiNewState(actor, &ghostSlash);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((height2 - height > 0x2000 || floorZ - bottom > 0x2000) && nDist < 0x1400 && nDist > 0x800)
|
|
|
|
{
|
|
|
|
aiPlay3DSound(actor, 1600, AI_SFX_PRIORITY_1, -1);
|
|
|
|
aiNewState(actor, &ghostSwoop);
|
|
|
|
}
|
|
|
|
else if ((height2 - height < 0x2000 || floorZ - bottom < 0x2000) && abs(nDeltaAngle) < 85)
|
|
|
|
aiPlay3DSound(actor, 1600, AI_SFX_PRIORITY_1, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aiNewState(actor, &ghostFly);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-09-16 19:59:39 +00:00
|
|
|
aiNewState(actor, &ghostGoto);
|
|
|
|
actor->SetTarget(nullptr);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveForward(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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 ((unsigned int)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 >> 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);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveSlow(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 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 >> 1;
|
|
|
|
t2 >>= 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);
|
2021-09-16 19:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePhantasm:
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->zvel = 0x44444;
|
2021-09-16 19:59:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveSwoop(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 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 >> 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);
|
2021-09-16 19:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePhantasm:
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->zvel = t1;
|
2021-09-16 19:59:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void ghostMoveFly(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);
|
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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 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);
|
2021-09-16 19:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePhantasm:
|
2021-09-04 10:52:02 +00:00
|
|
|
actor->zvel = -t1;
|
2021-09-16 19:59:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|