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 handThinkSearch(DBloodActor*);
|
|
|
|
static void handThinkGoto(DBloodActor*);
|
|
|
|
static void handThinkChase(DBloodActor*);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
AISTATE handIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
|
|
|
AISTATE hand13A3B4 = { kAiStateOther, 0, -1, 0, NULL, NULL, NULL, NULL };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE handSearch = { kAiStateMove, 6, -1, 600, NULL, aiMoveForward, handThinkSearch, &handIdle };
|
|
|
|
AISTATE handChase = { kAiStateChase, 6, -1, 0, NULL, aiMoveForward, handThinkChase, NULL };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE handRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &handSearch };
|
2020-10-11 09:56:27 +00:00
|
|
|
AISTATE handGoto = { kAiStateMove, 6, -1, 1800, NULL, aiMoveForward, handThinkGoto, &handIdle };
|
2019-09-19 22:42:45 +00:00
|
|
|
AISTATE handJump = { kAiStateChase, 7, nJumpClient, 120, NULL, NULL, NULL, &handChase };
|
|
|
|
|
2020-11-07 14:16:12 +00:00
|
|
|
void HandJumpSeqCallback(int, DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
|
|
|
spritetype* pTarget = &actor->GetTarget()->s();
|
|
|
|
if (IsPlayerSprite(pTarget))
|
|
|
|
{
|
|
|
|
PLAYER* pPlayer = &gPlayer[pTarget->type - kDudePlayer1];
|
|
|
|
if (!pPlayer->hand)
|
|
|
|
{
|
|
|
|
pPlayer->hand = 1;
|
|
|
|
actPostSprite(actor, kStatFree);
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void handThinkSearch(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 handThinkGoto(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pXSprite = &actor->x();
|
|
|
|
auto pSprite = &actor->s();
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
2021-12-22 10:57:10 +00:00
|
|
|
int dx = pXSprite->targetX - pSprite->pos.X;
|
2021-12-22 11:17:17 +00:00
|
|
|
int dy = pXSprite->targetY - pSprite->pos.Y;
|
2021-09-16 19:59:39 +00:00
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(actor, nAngle);
|
|
|
|
if (nDist < 512 && abs(pSprite->ang - nAngle) < pDudeInfo->periphery)
|
|
|
|
aiNewState(actor, &handSearch);
|
|
|
|
aiThinkTarget(actor);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 21:48:22 +00:00
|
|
|
static void handThinkChase(DBloodActor* actor)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-09-16 19:59:39 +00:00
|
|
|
auto pSprite = &actor->s();
|
|
|
|
if (actor->GetTarget() == nullptr)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &handGoto);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
|
|
|
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
|
|
|
|
if (!actor->ValidateTarget(__FUNCTION__)) return;
|
|
|
|
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, &handSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (IsPlayerSprite(pTarget) && powerupCheck(&gPlayer[pTarget->type - kDudePlayer1], kPwUpShadowCloak) > 0)
|
|
|
|
{
|
|
|
|
aiNewState(actor, &handSearch);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
|
|
|
int nDeltaAngle = ((getangle(dx, dy) + 1024 - pSprite->ang) & 2047) - 1024;
|
|
|
|
int height = (pDudeInfo->eyeHeight * pSprite->yrepeat) << 2;
|
2021-12-22 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());
|
|
|
|
if (nDist < 0x233 && abs(nDeltaAngle) < 85 && gGameOptions.nGameType == 0)
|
|
|
|
aiNewState(actor, &handJump);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aiNewState(actor, &handGoto);
|
|
|
|
actor->SetTarget(nullptr);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|