openmohaa/code/game/actor_turret.cpp

1171 lines
19 KiB
C++
Raw Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// actor_turret.cpp
#include "actor.h"
void Actor::InitTurret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
GlobalFuncs_t *func
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
func->ThinkState = &Actor::Think_Turret;
func->BeginState = &Actor::Begin_Turret;
func->EndState = &Actor::End_Turret;
func->SuspendState = &Actor::Suspend_Turret;
2018-08-05 17:56:40 +02:00
func->RestartState = NULL;
2016-03-27 11:49:47 +02:00
func->FinishedAnimation = &Actor::FinishedAnimation_Turret;
func->PassesTransitionConditions = &Actor::PassesTransitionConditions_Attack;
func->PostShoot = &Actor::InterruptPoint_Turret;
func->ReceiveAIEvent = &Actor::ReceiveAIEvent_Turret;
func->IsState = &Actor::IsAttackState;
func->PathnodeClaimRevoked = &Actor::PathnodeClaimRevoked_Turret;
}
void Actor::Begin_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
DoForceActivate();
m_csMood = STRING_ALERT;
ClearPath();
if (m_Enemy)
{
2019-06-30 23:03:24 +02:00
TransitionState(110, 0);
2018-08-29 14:41:48 +02:00
}
else
{
2019-06-30 23:03:24 +02:00
TransitionState(109, (rand() & 0x7FF) + 250);
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
void Actor::End_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (m_pCoverNode && m_State != 111)
{
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
}
2019-06-30 23:03:24 +02:00
TransitionState(-1, 0);
2016-03-27 11:49:47 +02:00
}
void Actor::Suspend_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (!m_Enemy)
{
2019-06-30 23:03:24 +02:00
TransitionState(110, 0);
2018-08-29 14:41:48 +02:00
}
else
{
if (m_State <= 108)
{
SetEnemyPos(m_Enemy->origin);
AimAtEnemyBehavior();
2019-06-30 23:03:24 +02:00
TransitionState(113, 0);
2018-08-29 14:41:48 +02:00
}
}
2016-03-27 11:49:47 +02:00
}
void Actor::Think_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
2018-09-05 16:55:10 +02:00
if (RequireThink())
2018-08-29 14:41:48 +02:00
{
2018-09-05 16:55:10 +02:00
UpdateEyeOrigin();
NoPoint();
UpdateEnemy(200);
2019-07-01 00:53:41 +02:00
2018-09-05 16:55:10 +02:00
if (m_Enemy && m_State == 110)
{
2019-06-30 23:03:24 +02:00
if (!m_bTurretNoInitialCover && Turret_TryToBecomeCoverGuy())
2018-09-05 16:55:10 +02:00
{
m_pszDebugState = "CoverInstead";
CheckUnregister();
UpdateAngles();
DoMove();
UpdateBoneControllers();
UpdateFootsteps();
return;
}
2019-07-01 00:53:41 +02:00
2018-09-05 16:55:10 +02:00
m_bTurretNoInitialCover = false;
Turret_SelectState();
if (m_State == 100 && !CanSeeEnemy(0))
{
2019-06-30 23:03:24 +02:00
Turret_BeginRetarget();
2018-09-05 16:55:10 +02:00
}
SetLeashHome(origin);
if (level.inttime < m_iEnemyChangeTime + 200)
{
if (AttackEntryAnimation())
{
m_bLockThinkState = true;
2019-06-30 23:03:24 +02:00
TransitionState(108, 0);
2018-09-05 16:55:10 +02:00
}
}
}
if (level.inttime > m_iStateTime + 3000)
Turret_SelectState();
if (m_State == 108)
{
m_pszDebugState = "IntroAnim";
2018-09-17 23:50:38 +02:00
AimAtTargetPos();
2018-09-05 16:55:10 +02:00
ContinueAnimation();
}
else
{
m_bLockThinkState = false;
if (!m_Enemy && m_State != 109 && m_State != 104)
{
2019-06-30 23:03:24 +02:00
TransitionState(109, ((rand() + 250) & 0x7FF));
2018-09-05 16:55:10 +02:00
}
if (!m_Enemy)
{
if (m_State != 109)
{
if (m_State != 104
2019-06-29 23:43:30 +02:00
|| (origin - m_vHome).lengthXYSquared() <= 0.64f * m_fLeashSquared + 64.0f
2019-07-01 00:53:41 +02:00
|| !State_Turret_RunHome(false))
2018-09-05 16:55:10 +02:00
{
m_pszDebugState = "Idle";
SetThinkState(THINKSTATE_IDLE, THINKLEVEL_NORMAL);
IdleThink();
}
else
{
m_pszDebugState = "Idle->RunHome";
PostThink(true);
}
return;
}
}
if (m_Enemy && m_State == 109)
{
2019-06-30 23:03:24 +02:00
Turret_BeginRetarget();
2018-09-05 16:55:10 +02:00
}
2018-08-29 14:41:48 +02:00
2018-09-05 16:55:10 +02:00
if (Turret_DecideToSelectState())
Turret_SelectState();
2018-08-29 14:41:48 +02:00
2018-09-05 16:55:10 +02:00
switch (m_State)
{
case 100:
m_pszDebugState = "Combat";
State_Turret_Combat();
break;
case 101:
m_pszDebugState = "Reacquire";
State_Turret_Reacquire();
break;
case 102:
m_pszDebugState = "TakeSniperNode";
if (!PathExists() || PathComplete())
{
AimAtEnemyBehavior();
2019-06-30 23:03:24 +02:00
TransitionState(103, 0);
2018-09-05 16:55:10 +02:00
}
else
{
FaceMotion();
Anim_RunToDanger(3);
}
break;
case 103:
m_pszDebugState = "SniperNode";
State_Turret_SniperNode();
break;
case 104:
m_pszDebugState = "RunHome";
State_Turret_RunHome(true);
break;
case 105:
m_pszDebugState = "RunAway";
State_Turret_RunAway();
break;
case 106:
m_pszDebugState = "Charge";
State_Turret_Charge();
break;
case 107:
m_pszDebugState = "Grenade";
2018-09-17 23:50:38 +02:00
State_Turret_Grenade();
2018-09-05 16:55:10 +02:00
break;
case 109:
m_pszDebugState = "FakeEnemy";
State_Turret_FakeEnemy();
break;
case 111:
m_pszDebugState = "BecomeCover";
ContinueAnimation();
break;
case 112:
m_pszDebugState = "Wait";
State_Turret_Wait();
break;
case 113:
m_pszDebugState = "Retarget_Sniper_Node";
State_Turret_Retarget_Sniper_Node();
break;
case 114:
m_pszDebugState = "Retarget_Step_Side_Small";
State_Turret_Retarget_Step_Side_Small();
break;
case 115:
m_pszDebugState = "Retarget_Path_Exact";
2019-06-30 23:03:24 +02:00
State_Turret_Retarget_Path_Exact();
break;
2018-09-05 16:55:10 +02:00
case 116:
m_pszDebugState = "Retarget_Path_Near";
2019-06-30 23:03:24 +02:00
State_Turret_Retarget_Path_Near();
2018-09-05 16:55:10 +02:00
break;
case 117:
m_pszDebugState = "Retarget_Step_Side_Medium";
State_Turret_Retarget_Step_Side_Medium();
break;
case 118:
m_pszDebugState = "Retarget_Step_Side_Large";
State_Turret_Retarget_Step_Side_Large();
break;
case 119:
m_pszDebugState = "Retarget_Step_Face_Medium";
State_Turret_Retarget_Step_Face_Medium();
break;
case 120:
m_pszDebugState = "Retarget_Step_Face_Large";
State_Turret_Retarget_Step_Face_Large();
break;
default:
Com_Printf("Actor::Think_Turret: invalid think state %i\n", m_State);
assert(!"invalid think state");
break;
}
CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_NORMAL);
}
if (m_State == 112)
{
PostThink(false);
}
else
{
PostThink(true);
}
}
2016-03-27 11:49:47 +02:00
}
void Actor::FinishedAnimation_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (m_State <= 108)
{
Turret_SelectState();
}
2016-03-27 11:49:47 +02:00
}
void Actor::ReceiveAIEvent_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
vec3_t event_origin,
int iType,
Entity *originator,
float fDistSquared,
float fMaxDistSquared
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-09-17 23:50:38 +02:00
if (iType == AI_EVENT_WEAPON_IMPACT)
2018-08-29 14:41:48 +02:00
{
2018-09-17 23:50:38 +02:00
if (m_Enemy && fDistSquared <= Square(128))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
Turret_TryToBecomeCoverGuy();
2018-08-29 14:41:48 +02:00
}
}
else
{
DefaultReceiveAIEvent(
origin,
iType,
originator,
fDistSquared,
fMaxDistSquared);
}
2016-03-27 11:49:47 +02:00
}
void Actor::InterruptPoint_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (m_Enemy && !Turret_TryToBecomeCoverGuy() && m_State == 100)
{
m_iStateTime = level.inttime;
Turret_SelectState();
}
2016-03-27 11:49:47 +02:00
}
void Actor::PathnodeClaimRevoked_Turret
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (m_Enemy == NULL)
{
2019-06-30 23:03:24 +02:00
TransitionState(110, 0);
2018-08-29 14:41:48 +02:00
}
else
{
2019-06-30 23:03:24 +02:00
Turret_BeginRetarget();
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
bool Actor::Turret_IsRetargeting
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
) const
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
return m_State <= 120;
2016-03-27 11:49:47 +02:00
}
bool Actor::Turret_DecideToSelectState
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
switch (m_State)
{
case 100:
if (level.inttime > m_iStateTime + 5000)
{
InterruptPoint_Turret();
}
return false;
case 101:
case 107:
case 102:
case 109:
return false;
}
return !Turret_IsRetargeting();
2016-03-27 11:49:47 +02:00
}
void Actor::Turret_SelectState
2019-06-30 23:03:24 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-06-30 23:03:24 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
vec2_t vDelta;
float fDistSquared;
if (!m_Enemy)
{
2019-06-30 23:03:24 +02:00
TransitionState(109, rand() & 0x7FF + 250);
2018-08-29 14:41:48 +02:00
return;
}
VectorSub2D(origin, m_vHome, vDelta);
fDistSquared = VectorLength2DSquared(vDelta);
2019-06-30 23:03:24 +02:00
2018-08-29 14:41:48 +02:00
if (m_State == 104 && fDistSquared > m_fLeashSquared * 0.64 + 64.0)
{
if (PathExists() && !PathComplete())
return;
}
else if (fDistSquared <= m_fLeashSquared * 1.21 + 256.0)
{
m_iRunHomeTime = 0;
}
2018-09-17 23:50:38 +02:00
else if (m_iRunHomeTime == 0)
2018-08-29 14:41:48 +02:00
{
m_iRunHomeTime = level.inttime + (rand() & 0xFFF) + 1000;
}
else if (level.inttime >= m_iRunHomeTime)
{
m_iRunHomeTime = 0;
ClearPath();
2018-09-17 23:50:38 +02:00
SetPath(m_vHome, NULL, 0, NULL, 0.0);
2018-08-29 14:41:48 +02:00
ShortenPathToAvoidSquadMates();
2019-07-01 00:53:41 +02:00
if (PathExists() && !PathComplete())
2018-08-29 14:41:48 +02:00
{
2019-07-01 00:53:41 +02:00
TransitionState(104, 0);
return;
2018-08-29 14:41:48 +02:00
}
else
{
Com_Printf(
"^~^~^ (entnum %i, radnum %d, targetname '%s') cannot reach his leash home\n",
entnum,
radnum,
targetname.c_str());
}
}
2019-06-30 23:03:24 +02:00
VectorSub2D(origin, m_Enemy->origin, vDelta);
2018-08-29 14:41:48 +02:00
fDistSquared = VectorLength2DSquared(vDelta);
if (m_State == 105)
{
if (m_fMinDistanceSquared * 2.25 > fDistSquared)
return;
}
if (m_fMinDistanceSquared > fDistSquared)
{
ClearPath();
2019-06-30 23:03:24 +02:00
TransitionState(105, 0);
2018-08-29 14:41:48 +02:00
return;
}
if (fDistSquared > m_fMaxDistanceSquared)
{
bool bSmthing = false;
if (m_Team == TEAM_GERMAN)
{
2019-06-30 23:03:24 +02:00
if ((m_Enemy->origin - m_vHome).lengthSquared() >= Square(m_fLeash + m_fMaxDistance) && !CanSeeEnemy(200))
2018-08-29 14:41:48 +02:00
bSmthing = true;
}
if (bSmthing)
{
ClearPath();
2019-07-01 00:53:41 +02:00
TransitionState(112, 0);
2018-08-29 14:41:48 +02:00
}
else
{
if (m_State == 106)
return;
ClearPath();
2019-06-30 23:03:24 +02:00
TransitionState(106, 0);
2018-08-29 14:41:48 +02:00
}
2019-07-01 00:53:41 +02:00
return;
}
2018-08-29 14:41:48 +02:00
2019-07-01 00:53:41 +02:00
if (DecideToThrowGrenade(m_Enemy->velocity + m_vLastEnemyPos, &m_vGrenadeVel, &m_eGrenadeMode))
{
m_bNextForceStart = false;
SetDesiredYawDir(m_vGrenadeVel);
2018-09-05 16:55:10 +02:00
2019-07-01 00:53:41 +02:00
m_eNextAnimMode = 1;
m_csNextAnimString = (m_eGrenadeMode == AI_GREN_TOSS_ROLL) ? STRING_ANIM_GRENADETOSS_SCR : STRING_ANIM_GRENADETHROW_SCR;
TransitionState(107, 0);
return;
}
2018-08-29 14:41:48 +02:00
2019-07-01 00:53:41 +02:00
if (m_State != 100 && m_State != 103 && m_State != 112)
{
ClearPath();
TransitionState(100, 0);
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
bool Actor::Turret_CheckRetarget
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (level.inttime < m_iStateTime + 5000 || level.inttime < m_iLastHitTime + 5000)
return false;
Turret_BeginRetarget();
return true;
2016-03-27 11:49:47 +02:00
}
bool Actor::Turret_TryToBecomeCoverGuy
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2019-07-01 00:53:41 +02:00
PathNode* pOldCover = m_pCoverNode;
2018-08-29 14:41:48 +02:00
Cover_FindCover(true);
if (m_pCoverNode)
{
2019-06-30 23:03:24 +02:00
TransitionState(111, 0);
2018-09-05 16:55:10 +02:00
SetThink(THINKSTATE_ATTACK, THINK_COVER);
2018-08-29 14:41:48 +02:00
return true;
}
else
{
2019-07-01 00:53:41 +02:00
if (pOldCover)
2018-08-29 14:41:48 +02:00
{
2019-07-01 00:53:41 +02:00
m_pCoverNode = pOldCover;
2018-08-29 14:41:48 +02:00
m_pCoverNode->Claim(this);
}
return false;
}
2016-03-27 11:49:47 +02:00
}
void Actor::Turret_BeginRetarget
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
SetEnemyPos(m_Enemy->origin);
AimAtEnemyBehavior();
2019-06-30 23:03:24 +02:00
TransitionState(113, 0);
2018-08-29 14:41:48 +02:00
2016-03-27 11:49:47 +02:00
}
void Actor::Turret_NextRetarget
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
vec2_t vDelta;
float fDistSquared;
m_State++;
2019-08-13 03:12:07 +02:00
if (Turret_IsRetargeting())
{
m_iStateTime = level.inttime;
return;
}
VectorSub2D(origin, m_vHome, vDelta);
fDistSquared = VectorLength2DSquared(vDelta);
if (fDistSquared >= m_fLeashSquared)
{
SetPath(m_vHome, NULL, 0, NULL, 0.0);
ShortenPathToAvoidSquadMates();
if (PathExists() && !PathComplete())
2018-08-29 14:41:48 +02:00
{
2019-08-13 03:12:07 +02:00
TransitionState(104, 0);
State_Turret_RunHome(true);
2018-08-29 14:41:48 +02:00
return;
}
2019-08-13 03:12:07 +02:00
}
if (m_Team == TEAM_AMERICAN)
{
if (!CanSeeEnemy(200))
2018-08-29 14:41:48 +02:00
{
2019-08-13 03:12:07 +02:00
m_PotentialEnemies.FlagBadEnemy(m_Enemy);
UpdateEnemy(-1);
2018-08-29 14:41:48 +02:00
}
2019-08-13 03:12:07 +02:00
if (!m_Enemy)
2018-08-29 14:41:48 +02:00
{
2019-08-13 03:12:07 +02:00
Anim_Stand();
return;
2018-08-29 14:41:48 +02:00
}
2019-08-13 03:12:07 +02:00
TransitionState(100, 0);
State_Turret_Combat();
2018-08-29 14:41:48 +02:00
}
else
{
2019-08-13 03:12:07 +02:00
if (CanSeeEnemy(200))
{
m_pszDebugState = "Retarget->Combat";
TransitionState(100, 0);
State_Turret_Combat();
}
else
{
TransitionState(112, 0);
State_Turret_Wait();
}
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
void Actor::Turret_SideStep
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
int iStepSize,
vec3_t vDir
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
AimAtEnemyBehavior();
//v3 = iStepSize;
StrafeToAttack(iStepSize, vDir);
if ((PathExists()
2018-08-29 14:41:48 +02:00
&& !PathComplete()
&& PathAvoidsSquadMates())
|| ((StrafeToAttack(-iStepSize, vDir),
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Combat
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (CanSeeEnemy(200))
{
ClearPath();
Anim_Attack();
2018-09-17 23:50:38 +02:00
AimAtTargetPos();
2018-08-29 14:41:48 +02:00
Turret_CheckRetarget();
return;
}
if (!PathExists() || PathComplete() || !PathAvoidsSquadMates())
{
2018-09-17 23:50:38 +02:00
SetPathWithLeash(m_vLastEnemyPos, NULL, 0);
2018-08-29 14:41:48 +02:00
ShortenPathToAvoidSquadMates();
}
if (!PathExists() || PathComplete() || !PathAvoidsSquadMates())
{
FindPathNearWithLeash(m_vLastEnemyPos, 4.0 * m_fMinDistanceSquared);
if (!ShortenPathToAttack(0.0))
ClearPath();
ShortenPathToAvoidSquadMates();
}
2019-08-13 03:12:07 +02:00
if (!PathExists()
|| PathComplete()
|| !PathAvoidsSquadMates())
{
m_pszDebugState = "combat->chill";
Turret_BeginRetarget();
}
else
2018-08-29 14:41:48 +02:00
{
m_pszDebugState = "combat->move";
2019-08-13 03:12:07 +02:00
if (!MovePathWithLeash())
{
m_pszDebugState = "combat->move->aim";
Turret_BeginRetarget();
}
else
2018-08-29 14:41:48 +02:00
{
Turret_CheckRetarget();
}
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Reacquire
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2019-06-29 23:43:30 +02:00
/*Sentient *v1; // ecx
2018-08-29 14:41:48 +02:00
float v2; // ST08_4
float v3; // ST0C_4
Sentient *v4; // ecx
float v5; // ST08_4
float v6; // ST0C_4
2019-06-29 23:43:30 +02:00
*/
2018-08-29 14:41:48 +02:00
if (PathExists() && !PathComplete())
{
if (CanMovePathWithLeash())
{
Anim_RunToInOpen(3);
FaceEnemyOrMotion(level.inttime - m_iStateTime);
}
else
{
Turret_BeginRetarget();
}
}
else
{
m_pszDebugState = "Retarget->Cheat";
SetEnemyPos(m_Enemy->origin);
2019-06-30 23:03:24 +02:00
TransitionState(100, 0);
2018-08-29 14:41:48 +02:00
State_Turret_Combat();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_TakeSniperNode
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (PathExists() && !PathComplete())
{
FaceMotion();
Anim_RunToDanger(3);
}
else
{
AimAtEnemyBehavior();
2019-06-30 23:03:24 +02:00
TransitionState(103, 0);
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_SniperNode
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-09-17 23:50:38 +02:00
AimAtTargetPos();
2018-08-29 14:41:48 +02:00
Anim_Sniper();
if (Turret_CheckRetarget())
{
m_pCoverNode->Relinquish();
m_pCoverNode->MarkTemporarilyBad();
m_pCoverNode = NULL;
}
2016-03-27 11:49:47 +02:00
}
bool Actor::State_Turret_RunHome
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
bool bAttackOnFail
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
2018-09-17 23:50:38 +02:00
SetPath(m_vHome, NULL, 0, NULL, 0.0);
2018-08-29 14:41:48 +02:00
ShortenPathToAvoidSquadMates();
if (!PathExists() || PathComplete())
{
Com_Printf(
"^~^~^ (entnum %i, radnum %i, targetname '%s') cannot reach his leash home\n",
entnum,
radnum,
targetname.c_str());
if (bAttackOnFail)
{
m_pszDebugState = "home->combat";
State_Turret_Combat();
}
return false;
}
else
{
FaceMotion();
Anim_RunToInOpen(2);
return true;
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_RunAway
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
if (!PathExists() || PathComplete())
{
2019-07-01 00:53:41 +02:00
FindPathAwayWithLeash(m_vLastEnemyPos, origin - m_Enemy->origin, 1.5 * m_fMinDistance);
2018-08-29 14:41:48 +02:00
}
if (!PathExists() || PathComplete())
{
m_pszDebugState = "runaway->combat";
State_Turret_Combat();
return;
}
if (!CanMovePathWithLeash())
{
m_pszDebugState = "runaway->leash->combat";
State_Turret_Combat();
return;
}
Anim_RunAwayFiring(2);
FaceEnemyOrMotion(level.inttime - m_iStateTime);
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Charge
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-09-17 23:50:38 +02:00
SetPathWithLeash(m_vLastEnemyPos, NULL, 0);
2018-08-29 14:41:48 +02:00
ShortenPathToAvoidSquadMates();
if (!PathExists())
{
m_pszDebugState = "charge->near";
FindPathNearWithLeash(m_vLastEnemyPos, m_fMaxDistanceSquared);
if (!ShortenPathToAttack(0))
ClearPath();
}
if (!PathExists() || PathComplete() || !PathAvoidsSquadMates())
{
ClearPath();
if (CanSeeEnemy(500))
{
m_pszDebugState = "charge->combat";
State_Turret_Combat();
return;
}
m_bHasDesiredLookAngles = false;
m_pszDebugState = "charge->chill";
Anim_Idle();
if (m_Team != TEAM_AMERICAN)
{
//v1 = &this->m_PotentialEnemies;
if (!m_PotentialEnemies.HasAlternateEnemy())
{
if (m_Enemy)
Turret_CheckRetarget();
return;
}
}
m_PotentialEnemies.FlagBadEnemy(m_Enemy);
UpdateEnemy(-1);
if (m_Enemy)
Turret_CheckRetarget();
return;
}
if (!MovePathWithLeash())
{
m_pszDebugState = "charge->leash->combat";
2019-06-30 23:03:24 +02:00
TransitionState(100, 0);
2018-08-29 14:41:48 +02:00
State_Turret_Combat();
return;
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Grenade
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
GenericGrenadeTossThink();
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_FakeEnemy
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-09-17 23:50:38 +02:00
AimAtTargetPos();
2018-08-29 14:41:48 +02:00
Anim_Aim();
if (level.inttime >= m_iStateTime)
2018-09-05 16:55:10 +02:00
SetThinkState(THINKSTATE_IDLE, THINKLEVEL_NORMAL);
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Wait
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
PathNode *pNode;
if (CanSeeEnemy(500) || CanShootEnemy(500))
{
bool bSmth;
pNode = m_pCoverNode;
Cover_FindCover(true);
if (m_pCoverNode)
{
2019-06-30 23:03:24 +02:00
TransitionState(111, 0);
2018-09-05 16:55:10 +02:00
SetThink(THINKSTATE_ATTACK, THINK_COVER);
2018-08-29 14:41:48 +02:00
bSmth = true;
}
else
{
if (pNode)
{
m_pCoverNode = pNode;
m_pCoverNode->Claim(this);
}
bSmth = false;
}
if (bSmth)
{
m_pszDebugState = "Wait->CoverInstead";
ContinueAnimation();
}
else
{
m_pszDebugState = "Wait->Combat";
2019-06-30 23:03:24 +02:00
TransitionState(100, 0);
2018-08-29 14:41:48 +02:00
State_Turret_Combat();
}
}
else
{
if (level.inttime >= m_iLastFaceDecideTime + 1500)
{
2018-09-05 16:55:10 +02:00
m_iLastFaceDecideTime = level.inttime + (rand() & 0x1FF);
2019-07-01 00:53:41 +02:00
2018-08-29 14:41:48 +02:00
pNode = PathManager.FindCornerNodeForExactPath(this, m_Enemy, 0);
if (pNode)
{
if (pNode->m_PathPos - origin != vec_zero)
{
2018-09-17 23:50:38 +02:00
SetDesiredYawDir(pNode->m_PathPos - origin);
2018-08-29 14:41:48 +02:00
}
m_eDontFaceWallMode = 6;
}
else
{
2018-09-17 23:50:38 +02:00
AimAtTargetPos();
2018-08-29 14:41:48 +02:00
DontFaceWall();
}
}
if (m_eDontFaceWallMode > 8)
Anim_Aim();
else
Anim_Stand();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Retarget_Sniper_Node
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
PathNode *pSniperNode;
bool bTryAgain;
AimAtEnemyBehavior();
if (m_pCoverNode)
{
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
}
pSniperNode = FindSniperNodeAndSetPath(&bTryAgain);
if (pSniperNode)
{
m_pCoverNode = pSniperNode;
pSniperNode->Claim(this);
2019-06-30 23:03:24 +02:00
TransitionState(102, 0);
2019-07-01 00:53:41 +02:00
2018-09-05 16:55:10 +02:00
State_Turret_TakeSniperNode();
2018-08-29 14:41:48 +02:00
}
else if (bTryAgain)
{
ContinueAnimation();
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
2018-08-29 14:41:48 +02:00
void Actor::State_Turret_Retarget_Path_Exact
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
AimAtEnemyBehavior();
2018-09-17 23:50:38 +02:00
SetPathWithLeash(m_vLastEnemyPos, NULL, 0);
2019-07-01 00:53:41 +02:00
if (ShortenPathToAttack(128)
&& (ShortenPathToAvoidSquadMates(), PathExists()))
2018-08-29 14:41:48 +02:00
{
2019-07-01 00:53:41 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
2019-07-01 00:53:41 +02:00
Turret_NextRetarget();
2018-08-29 14:41:48 +02:00
}
2016-03-27 11:49:47 +02:00
}
2018-08-29 14:41:48 +02:00
void Actor::State_Turret_Retarget_Path_Near
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
AimAtEnemyBehavior();
FindPathNearWithLeash(m_vLastEnemyPos, m_fMinDistanceSquared);
if (ShortenPathToAttack(128))
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
2018-08-29 14:41:48 +02:00
void Actor::State_Turret_Retarget_Step_Side_Small
(
2016-03-27 11:49:47 +02:00
void
2018-08-29 14:41:48 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
int iRand; // esi
iRand = (rand() & 64) - 32;
AimAtEnemyBehavior();
StrafeToAttack(iRand, orientation[1]);
if ((PathExists() && !PathComplete() && PathAvoidsSquadMates())
|| ((Actor::StrafeToAttack(-iRand, orientation[1]),
2018-08-29 14:41:48 +02:00
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Retarget_Step_Side_Medium
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
int iRand; // esi
iRand = (rand() & 256) - 128;
AimAtEnemyBehavior();
StrafeToAttack(iRand, orientation[1]);
if ((PathExists() && !PathComplete() && PathAvoidsSquadMates())
|| ((Actor::StrafeToAttack(-iRand, orientation[1]),
2018-08-29 14:41:48 +02:00
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Retarget_Step_Side_Large
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
int iRand; // esi
iRand = (rand() & 512) - 256;
AimAtEnemyBehavior();
StrafeToAttack(iRand, orientation[1]);
if ((PathExists() && !PathComplete() && PathAvoidsSquadMates())
|| ((Actor::StrafeToAttack(-iRand, orientation[1]),
2018-08-29 14:41:48 +02:00
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Retarget_Step_Face_Medium
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
int iRand; // esi
iRand = (rand() & 256) - 128;
AimAtEnemyBehavior();
StrafeToAttack(iRand, orientation[0]);
if ((PathExists() && !PathComplete() && PathAvoidsSquadMates())
|| ((Actor::StrafeToAttack(-iRand, orientation[0]),
2018-08-29 14:41:48 +02:00
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}
void Actor::State_Turret_Retarget_Step_Face_Large
2019-07-01 00:53:41 +02:00
(
2016-03-27 11:49:47 +02:00
void
2019-07-01 00:53:41 +02:00
)
2016-03-27 11:49:47 +02:00
{
2018-08-29 14:41:48 +02:00
int iRand; // esi
iRand = (rand() & 512) - 256;
AimAtEnemyBehavior();
StrafeToAttack(iRand, orientation[0]);
if ((PathExists() && !PathComplete() && PathAvoidsSquadMates())
|| ((Actor::StrafeToAttack(-iRand, orientation[0]),
2018-08-29 14:41:48 +02:00
PathExists())
&& !PathComplete()
&& PathAvoidsSquadMates()))
2018-08-29 14:41:48 +02:00
{
2019-06-30 23:03:24 +02:00
TransitionState(101, 0);
2018-08-29 14:41:48 +02:00
}
else
{
Turret_NextRetarget();
}
2016-03-27 11:49:47 +02:00
}