raze/source/games/blood/src/aicaleb.cpp

425 lines
16 KiB
C++
Raw Normal View History

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.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
2019-09-19 22:42:45 +00:00
#include "compat.h"
#include "build.h"
#include "blood.h"
BEGIN_BLD_NS
static void calebThinkSearch(DBloodActor *);
static void calebThinkGoto(DBloodActor *);
static void calebThinkChase(DBloodActor *);
static void calebThinkSwimGoto(DBloodActor *);
static void calebThinkSwimChase(DBloodActor *);
static void sub_65D04(DBloodActor *);
static void sub_65F44(DBloodActor *);
static void sub_661E0(DBloodActor *);
2019-09-19 22:42:45 +00:00
AISTATE tinycalebIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
AISTATE tinycalebChase = { kAiStateChase, 6, -1, 0, NULL, aiMoveForward, calebThinkChase, NULL };
2019-09-19 22:42:45 +00:00
AISTATE tinycalebDodge = { kAiStateMove, 6, -1, 90, NULL, aiMoveDodge, NULL, &tinycalebChase };
AISTATE tinycalebGoto = { kAiStateMove, 6, -1, 600, NULL, aiMoveForward, calebThinkGoto, &tinycalebIdle };
2019-09-19 22:42:45 +00:00
AISTATE tinycalebAttack = { kAiStateChase, 0, nAttackClient, 120, NULL, NULL, NULL, &tinycalebChase };
AISTATE tinycalebSearch = { kAiStateSearch, 6, -1, 120, NULL, aiMoveForward, calebThinkSearch, &tinycalebIdle };
2019-09-19 22:42:45 +00:00
AISTATE tinycalebRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &tinycalebDodge };
AISTATE tinycalebTeslaRecoil = { kAiStateRecoil, 4, -1, 0, NULL, NULL, NULL, &tinycalebDodge };
AISTATE tinycalebSwimIdle = { kAiStateIdle, 10, -1, 0, NULL, NULL, aiThinkTarget, NULL };
AISTATE tinycalebSwimChase = { kAiStateChase, 8, -1, 0, NULL, sub_65D04, calebThinkSwimChase, NULL };
2019-09-19 22:42:45 +00:00
AISTATE tinycalebSwimDodge = { kAiStateMove, 8, -1, 90, NULL, aiMoveDodge, NULL, &tinycalebSwimChase };
AISTATE tinycalebSwimGoto = { kAiStateMove, 8, -1, 600, NULL, aiMoveForward, calebThinkSwimGoto, &tinycalebSwimIdle };
AISTATE tinycalebSwimSearch = { kAiStateSearch, 8, -1, 120, NULL, aiMoveForward, calebThinkSearch, &tinycalebSwimIdle };
2019-09-19 22:42:45 +00:00
AISTATE tinycalebSwimAttack = { kAiStateChase, 10, nAttackClient, 0, NULL, NULL, NULL, &tinycalebSwimChase };
AISTATE tinycalebSwimRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &tinycalebSwimDodge };
AISTATE tinycaleb139660 = { kAiStateOther, 8, -1, 120, NULL, sub_65F44, calebThinkSwimChase, &tinycalebSwimChase };
AISTATE tinycaleb13967C = { kAiStateOther, 8, -1, 0, NULL, sub_661E0, calebThinkSwimChase, &tinycalebSwimChase };
2019-09-19 22:42:45 +00:00
AISTATE tinycaleb139698 = { kAiStateOther, 8, -1, 120, NULL, aiMoveTurn, NULL, &tinycalebSwimChase };
void SeqAttackCallback(int, DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
spritetype *pSprite = &actor->s();
int dx = CosScale16(pSprite->ang);
int dy = SinScale16(pSprite->ang);
int dz = actor->dudeSlope;
2019-09-19 22:42:45 +00:00
dx += Random2(1500);
dy += Random2(1500);
dz += Random2(1500);
for (int i = 0; i < 2; i++)
{
int r1 = Random3(500);
int r2 = Random3(1000);
int r3 = Random3(1000);
actFireVector(pSprite, 0, 0, dx+r3, dy+r2, dz+r1, VECTOR_TYPE_1);
}
if (Chance(0x8000))
sfxPlay3DSound(pSprite, 10000+Random(5), -1, 0);
if (Chance(0x8000))
sfxPlay3DSound(pSprite, 1001, -1, 0);
else
sfxPlay3DSound(pSprite, 1002, -1, 0);
}
static void calebThinkSearch(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng);
aiThinkTarget(actor);
2019-09-19 22:42:45 +00:00
}
static void calebThinkGoto(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
2019-09-19 22:42:45 +00:00
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int dx = pXSprite->targetX-pSprite->x;
int dy = pXSprite->targetY-pSprite->y;
int nAngle = getangle(dx, dy);
int nDist = approxDist(dx, dy);
aiChooseDirection(pSprite, pXSprite, nAngle);
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
2019-09-19 22:42:45 +00:00
{
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebSearch);
2019-09-19 22:42:45 +00:00
}
aiThinkTarget(actor);
2019-09-19 22:42:45 +00:00
}
static void calebThinkChase(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
if (pXSprite->target == -1)
{
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebSearch);
2019-09-19 22:42:45 +00:00
return;
}
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
2019-09-19 22:42:45 +00:00
spritetype *pTarget = &sprite[pXSprite->target];
XSPRITE *pXTarget = &xsprite[pTarget->extra];
int dx = pTarget->x-pSprite->x;
int dy = pTarget->y-pSprite->y;
aiChooseDirection(pSprite, pXSprite, getangle(dx, dy));
if (pXTarget->health == 0)
{
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
else
{
aiPlay3DSound(pSprite, 11000+Random(4), AI_SFX_PRIORITY_1, -1);
aiNewState(actor, &tinycalebSearch);
2019-09-19 22:42:45 +00:00
}
return;
}
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type-kDudePlayer1], kPwUpShadowCloak) > 0)
2019-09-19 22:42:45 +00:00
{
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebSearch);
2019-09-19 22:42:45 +00:00
return;
}
int nDist = approxDist(dx, dy);
if (nDist <= pDudeInfo->seeDist)
{
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
int height = (pDudeInfo->eyeHeight*pSprite->yrepeat)<<2;
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
{
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
2019-09-19 22:42:45 +00:00
{
aiSetTarget(pXSprite, pXSprite->target);
actor->dudeSlope = DivScale(pTarget->z-pSprite->z, nDist, 10);
if (nDist < 0x599 && abs(nDeltaAngle) < 28)
2019-09-19 22:42:45 +00:00
{
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
int hit = HitScan(pSprite, pSprite->z, dx, dy, 0, CLIPMASK1, 0);
switch (hit)
{
case -1:
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimAttack);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebAttack);
2019-09-19 22:42:45 +00:00
break;
case 3:
if (pSprite->type != sprite[gHitInfo.hitsprite].type)
{
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimAttack);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebAttack);
2019-09-19 22:42:45 +00:00
}
else
{
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimDodge);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebDodge);
2019-09-19 22:42:45 +00:00
}
break;
default:
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimAttack);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebAttack);
2019-09-19 22:42:45 +00:00
break;
}
}
}
return;
}
}
XSECTOR *pXSector;
int nXSector = sector[pSprite->sectnum].extra;
if (nXSector > 0)
pXSector = &xsector[nXSector];
else
pXSector = NULL;
if (pXSector && pXSector->Underwater)
aiNewState(actor, &tinycalebSwimGoto);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycalebGoto);
2019-09-19 22:42:45 +00:00
if (Chance(0x2000))
sfxPlay3DSound(pSprite, 10000 + Random(5), -1, 0);
pXSprite->target = -1;
}
static void calebThinkSwimGoto(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
2019-09-19 22:42:45 +00:00
int dx = pXSprite->targetX-pSprite->x;
int dy = pXSprite->targetY-pSprite->y;
int nAngle = getangle(dx, dy);
int nDist = approxDist(dx, dy);
aiChooseDirection(pSprite, pXSprite, nAngle);
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
aiNewState(actor, &tinycalebSwimSearch);
aiThinkTarget(actor);
2019-09-19 22:42:45 +00:00
}
static void calebThinkSwimChase(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
if (pXSprite->target == -1)
{
aiNewState(actor, &tinycalebSwimGoto);
2019-09-19 22:42:45 +00:00
return;
}
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
2019-09-19 22:42:45 +00:00
spritetype *pTarget = &sprite[pXSprite->target];
XSPRITE *pXTarget = &xsprite[pTarget->extra];
int dx = pTarget->x-pSprite->x;
int dy = pTarget->y-pSprite->y;
aiChooseDirection(pSprite, pXSprite, getangle(dx, dy));
if (pXTarget->health == 0)
{
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
return;
}
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type-kDudePlayer1], kPwUpShadowCloak) > 0)
2019-09-19 22:42:45 +00:00
{
aiNewState(actor, &tinycalebSwimSearch);
2019-09-19 22:42:45 +00:00
return;
}
int nDist = approxDist(dx, dy);
if (nDist <= pDudeInfo->seeDist)
{
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
int height = pDudeInfo->eyeHeight+pSprite->z;
int top, bottom;
GetSpriteExtents(pSprite, &top, &bottom);
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
{
if (nDist < pDudeInfo->seeDist && abs(nDeltaAngle) <= pDudeInfo->periphery)
2019-09-19 22:42:45 +00:00
{
aiSetTarget(pXSprite, pXSprite->target);
if (nDist < 0x400 && abs(nDeltaAngle) < 85)
aiNewState(actor, &tinycalebSwimAttack);
2019-09-19 22:42:45 +00:00
else
aiNewState(actor, &tinycaleb13967C);
2019-09-19 22:42:45 +00:00
}
}
return;
}
aiNewState(actor, &tinycalebSwimGoto);
2019-09-19 22:42:45 +00:00
pXSprite->target = -1;
}
static void sub_65D04(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
int nSprite = pSprite->index;
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
2019-09-19 22:42:45 +00:00
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
int nAccel = pDudeInfo->frontSpeed<<2;
if (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 (Random(64) < 32 && nDist <= 0x400)
return;
int nCos = Cos(pSprite->ang);
int nSin = Sin(pSprite->ang);
int vx = xvel[nSprite];
int vy = yvel[nSprite];
int t1 = DMulScale(vx, nCos, vy, nSin, 30);
int t2 = DMulScale(vx, nSin, -vy, nCos, 30);
2019-09-19 22:42:45 +00:00
if (pXSprite->target == -1)
t1 += nAccel;
else
t1 += nAccel>>2;
xvel[nSprite] = DMulScale(t1, nCos, t2, nSin, 30);
yvel[nSprite] = DMulScale(t1, nSin, -t2, nCos, 30);
2019-09-19 22:42:45 +00:00
}
static void sub_65F44(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
int nSprite = pSprite->index;
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
2019-09-19 22:42:45 +00:00
spritetype *pTarget = &sprite[pXSprite->target];
int z = pSprite->z + getDudeInfo(pSprite->type)->eyeHeight;
int z2 = pTarget->z + getDudeInfo(pTarget->type)->eyeHeight;
2019-09-19 22:42:45 +00:00
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
int nAccel = pDudeInfo->frontSpeed<<2;
if (abs(nAng) > 341)
2019-09-19 22:42:45 +00:00
{
pXSprite->goalAng = (pSprite->ang+512)&2047;
return;
}
int dx = pXSprite->targetX-pSprite->x;
int dy = pXSprite->targetY-pSprite->y;
int dz = z2 - z;
int nDist = approxDist(dx, dy);
if (Chance(0x600) && nDist <= 0x400)
return;
int nCos = Cos(pSprite->ang);
int nSin = Sin(pSprite->ang);
int vx = xvel[nSprite];
int vy = yvel[nSprite];
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;
xvel[nSprite] = DMulScale(t1, nCos, t2, nSin, 30);
yvel[nSprite] = DMulScale(t1, nSin, -t2, nCos, 30);
2019-09-19 22:42:45 +00:00
zvel[nSprite] = -dz;
}
static void sub_661E0(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pXSprite = &actor->x();
auto pSprite = &actor->s();
2019-09-19 22:42:45 +00:00
int nSprite = pSprite->index;
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
2019-09-19 22:42:45 +00:00
spritetype *pTarget = &sprite[pXSprite->target];
int z = pSprite->z + getDudeInfo(pSprite->type)->eyeHeight;
int z2 = pTarget->z + getDudeInfo(pTarget->type)->eyeHeight;
2019-09-19 22:42:45 +00:00
int nAng = ((pXSprite->goalAng+1024-pSprite->ang)&2047)-1024;
int nTurnRange = (pDudeInfo->angSpeed<<2)>>4;
pSprite->ang = (pSprite->ang+ClipRange(nAng, -nTurnRange, nTurnRange))&2047;
int nAccel = pDudeInfo->frontSpeed<<2;
if (abs(nAng) > 341)
2019-09-19 22:42:45 +00:00
{
pSprite->ang = (pSprite->ang+512)&2047;
return;
}
int dx = pXSprite->targetX-pSprite->x;
int dy = pXSprite->targetY-pSprite->y;
int dz = (z2 - z)<<3;
int nDist = approxDist(dx, dy);
if (Chance(0x4000) && nDist <= 0x400)
return;
int nCos = Cos(pSprite->ang);
int nSin = Sin(pSprite->ang);
int vx = xvel[nSprite];
int vy = yvel[nSprite];
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;
xvel[nSprite] = DMulScale(t1, nCos, t2, nSin, 30);
yvel[nSprite] = DMulScale(t1, nSin, -t2, nCos, 30);
2019-09-19 22:42:45 +00:00
zvel[nSprite] = dz;
}
END_BLD_NS