openmohaa/code/fgame/actor_cover.cpp

733 lines
19 KiB
C++
Raw Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
2023-10-12 18:19:22 +02:00
Copyright (C) 2023 the OpenMoHAA team
2016-03-27 11:49:47 +02:00
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_cover.cpp
#include "actor.h"
2023-10-21 17:18:49 +02:00
static int Cover_HideTime(int iTeam)
2023-10-12 20:17:09 +02:00
{
2023-10-21 17:18:49 +02:00
if (iTeam == TEAM_AMERICAN) {
return rand() % 2001 + 2000;
2023-10-12 20:17:09 +02:00
} else {
2023-10-21 17:18:49 +02:00
return rand() % 11001 + 4000;
2023-10-12 20:17:09 +02:00
}
}
2023-10-21 17:18:49 +02:00
bool Actor::Cover_IsValid(PathNode *node)
2023-10-12 20:17:09 +02:00
{
2023-10-21 17:18:49 +02:00
Vector sight_origin = node->origin + eyeposition;
2023-10-21 17:18:49 +02:00
if (node->IsClaimedByOther(this)) {
return false;
}
2023-10-12 20:17:09 +02:00
2023-11-13 00:35:11 +01:00
if (node->nodeflags & (AI_CONCEALMENT | AI_LOW_WALL_ARC)) {
2023-10-21 17:18:49 +02:00
return true;
}
if (!CanSeeFrom(sight_origin, m_Enemy)) {
return true;
}
if (!(node->nodeflags & AI_DUCK)) {
2023-10-12 20:17:09 +02:00
return false;
}
2023-10-21 17:18:49 +02:00
if (CanSee(sight_origin - Vector(0, 0, 32), 0, 0, false)) {
return false;
}
return true;
}
bool Actor::Cover_SetPath(PathNode *node)
{
2023-10-12 20:17:09 +02:00
float origin_ratio;
Vector enemy_offset;
PathInfo *current_node;
Vector enemy_origin;
2023-10-21 17:18:49 +02:00
vec2_t vDelta;
2023-10-12 20:17:09 +02:00
float fMinDistSquared;
float fPathDist;
2023-10-21 17:18:49 +02:00
SetPathWithLeash(node, NULL, 0);
if (!PathExists()) {
return false;
}
2023-10-12 20:17:09 +02:00
fPathDist = PathDist();
2023-10-21 17:18:49 +02:00
fMinDistSquared = Square(fPathDist);
2023-10-12 20:17:09 +02:00
2024-02-14 20:32:57 +01:00
if ((node->origin - origin).lengthSquared() * 4 <= fMinDistSquared && fPathDist > 128.0f) {
2023-10-21 17:18:49 +02:00
return false;
}
if (PathComplete()) {
return true;
2023-10-12 20:17:09 +02:00
}
2023-10-21 17:18:49 +02:00
enemy_origin = m_Enemy->origin;
VectorSub2D(enemy_origin, origin, vDelta);
2023-10-23 17:28:36 +02:00
origin_ratio = VectorLength2DSquared(vDelta) * 0.64f;
if (origin_ratio > Square(192)) {
2023-10-21 17:18:49 +02:00
origin_ratio = Square(192);
}
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
for (current_node = CurrentPathNode() - 1; current_node >= LastPathNode(); current_node--) {
VectorSub2D(enemy_origin, current_node->point, enemy_offset);
if (VectorLength2DSquared(enemy_offset) <= origin_ratio) {
return false;
2023-10-12 20:17:09 +02:00
}
2023-10-21 17:18:49 +02:00
if (DotProduct2D(enemy_offset, current_node->dir) >= 0) {
continue;
}
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
if (DotProduct2D(enemy_offset, current_node->dir) < -current_node->dist) {
continue;
}
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
if (Square(CrossProduct2D(enemy_offset, current_node->dir)) <= origin_ratio) {
return false;
2023-10-12 20:17:09 +02:00
}
}
2023-10-21 17:18:49 +02:00
return PathAvoidsSquadMates() != false;
2023-10-12 20:17:09 +02:00
}
void Actor::Cover_FindCover(bool bCheckAll)
{
if (m_pCoverNode) {
if (Cover_IsValid(m_pCoverNode) && Cover_SetPath(m_pCoverNode)) {
return;
}
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
}
if (!m_iPotentialCoverCount) {
m_iPotentialCoverCount =
PathManager.FindPotentialCover(this, origin, m_Enemy, m_pPotentialCoverNode, MAX_COVER_NODES);
2023-10-12 20:17:09 +02:00
}
2023-10-21 17:18:49 +02:00
if (!m_iPotentialCoverCount) {
return;
}
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
PathNode *pNode;
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
while (m_iPotentialCoverCount) {
m_iPotentialCoverCount--;
pNode = m_pPotentialCoverNode[m_iPotentialCoverCount];
m_pPotentialCoverNode[m_iPotentialCoverCount] = NULL;
2023-10-12 20:17:09 +02:00
2023-10-21 17:18:49 +02:00
if (Cover_IsValid(pNode) && Cover_SetPath(pNode)) {
break;
2023-10-12 20:17:09 +02:00
}
2023-10-21 17:18:49 +02:00
if (!bCheckAll || !m_iPotentialCoverCount) {
return;
}
2023-10-12 20:17:09 +02:00
}
2023-10-21 17:18:49 +02:00
m_pCoverNode = pNode;
m_pCoverNode->Claim(this);
memset(m_pPotentialCoverNode, 0, sizeof(m_pPotentialCoverNode));
m_iPotentialCoverCount = 0;
2023-10-12 20:17:09 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::InitCover(GlobalFuncs_t *func)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
func->ThinkState = &Actor::Think_Cover;
func->BeginState = &Actor::Begin_Cover;
func->EndState = &Actor::End_Cover;
func->SuspendState = &Actor::Suspend_Cover;
func->FinishedAnimation = &Actor::FinishedAnimation_Cover;
func->PassesTransitionConditions = &Actor::PassesTransitionConditions_Attack;
func->IsState = &Actor::IsAttackState;
func->PathnodeClaimRevoked = &Actor::PathnodeClaimRevoked_Cover;
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::Begin_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
DoForceActivate();
m_csIdleMood = STRING_NERVOUS;
m_csMood = STRING_ALERT;
if (m_pCoverNode) {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_TAKE_COVER, 0);
2023-10-12 18:19:22 +02:00
return;
}
TransitionState(ACTOR_STATE_COVER_NEW_ENEMY, 0);
2023-10-12 18:19:22 +02:00
if (level.inttime < m_iEnemyChangeTime + 200) {
SetLeashHome(origin);
if (AttackEntryAnimation()) {
m_bLockThinkState = true;
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_LOOP, 0);
2023-10-12 18:19:22 +02:00
}
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::End_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
m_pszDebugState = "";
2016-03-27 11:49:47 +02:00
2023-10-12 18:19:22 +02:00
if (m_pCoverNode) {
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
}
2016-03-27 11:49:47 +02:00
2023-10-12 18:19:22 +02:00
TransitionState(-1, 0);
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::Suspend_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
if (m_pCoverNode) {
m_pCoverNode->Relinquish();
m_pCoverNode->MarkTemporarilyBad();
m_pCoverNode = NULL;
}
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_NewEnemy(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
ForwardLook();
2023-10-12 18:19:22 +02:00
Cover_FindCover(true);
2023-10-21 17:18:49 +02:00
if (m_pCoverNode && PathExists() && !PathComplete()) {
Anim_RunToCover(ANIM_MODE_PATH_GOAL);
TransitionState(ACTOR_STATE_COVER_TAKE_COVER, 0);
2023-10-12 18:19:22 +02:00
} else {
Anim_Aim();
AimAtTargetPos();
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_TARGET, 0);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_FindCover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
Anim_Aim();
AimAtTargetPos();
Cover_FindCover(false);
2023-11-13 00:35:11 +01:00
if (m_pCoverNode) {
if (PathExists() && !PathComplete()) {
Anim_RunToCover(ANIM_MODE_PATH_GOAL);
TransitionState(ACTOR_STATE_COVER_TAKE_COVER, 0);
} else {
TransitionState(ACTOR_STATE_COVER_TARGET, 0);
}
} else if (!m_iPotentialCoverCount) {
2023-10-21 17:18:49 +02:00
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_TakeCover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
if (PathExists() && !PathComplete()) {
FaceEnemyOrMotion(level.inttime - m_iStateTime);
2023-10-21 17:18:49 +02:00
Anim_RunToCover(ANIM_MODE_PATH_GOAL);
SetPathGoalEndAnim(m_bInReload ? STRING_ANIM_RUNTO_COVER_SCR : STRING_ANIM_IDLE_SCR);
2023-10-12 18:19:22 +02:00
} else {
ClearPath();
2023-10-14 14:10:16 +02:00
m_eAnimMode = ANIM_MODE_NORMAL;
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FINISH_RELOADING, 0);
2023-10-12 18:19:22 +02:00
State_Cover_FinishReloading();
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_FinishReloading(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
Weapon *pWeapon;
firetype_t eFireType;
2023-10-12 18:19:22 +02:00
if (m_bInReload) {
ContinueAnimation();
AimAtTargetPos();
return;
}
2023-10-21 17:18:49 +02:00
pWeapon = GetWeapon(WEAPON_MAIN);
if (pWeapon) {
eFireType = pWeapon->GetFireType(FIRE_PRIMARY);
}
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (pWeapon && eFireType != FT_PROJECTILE && eFireType != FT_SPECIAL_PROJECTILE
&& (m_csSpecialAttack = m_pCoverNode->GetSpecialAttack(this)) != 0) {
SetDesiredYaw(m_pCoverNode->angles.yaw());
SafeSetOrigin(m_pCoverNode->origin);
DesiredAnimation(ANIM_MODE_NORMAL, m_csSpecialAttack);
TransitionState(ACTOR_STATE_COVER_SPECIAL_ATTACK, 0);
} else {
2023-10-12 18:19:22 +02:00
if (m_pCoverNode->nodeflags & AI_DUCK) {
Anim_Crouch();
} else {
Anim_Stand();
}
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_HIDE, Cover_HideTime(m_Team));
2023-10-12 18:19:22 +02:00
Anim_Aim();
AimAtTargetPos();
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_Target(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
DontFaceWall();
2023-10-21 17:18:49 +02:00
if (AvoidingFacingWall()) {
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, 0);
2023-10-12 18:19:22 +02:00
State_Cover_FindEnemy();
return;
}
Anim_Aim();
AimAtTargetPos();
if (level.inttime <= m_iStateTime + 300) {
2023-10-21 17:18:49 +02:00
return;
}
if (fabs(m_DesiredYaw - angles[1]) >= 0.001f) {
return;
}
if (DecideToThrowGrenade(m_vLastEnemyPos + velocity, &m_vGrenadeVel, &m_eGrenadeMode, false)) {
SetDesiredYawDir(m_vGrenadeVel);
DesiredAnimation(
ANIM_MODE_NORMAL,
m_eGrenadeMode == AI_GREN_TOSS_ROLL ? STRING_ANIM_GRENADETOSS_SCR : STRING_ANIM_GRENADETHROW_SCR
);
TransitionState(ACTOR_STATE_COVER_GRENADE);
} else if (CanSeeEnemy(500) && CanShootEnemy(500)) {
TransitionState(ACTOR_STATE_COVER_SHOOT, 0);
} else {
TransitionState(ACTOR_STATE_COVER_HIDE, Cover_HideTime(m_Team));
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_Hide(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
PathNode *pNode;
trace_t trace;
bool bCanShoot, bCanSee;
2023-10-12 18:19:22 +02:00
if (m_Enemy) {
2024-02-14 20:32:57 +01:00
SetEnemyPos(m_Enemy->origin);
2023-10-12 18:19:22 +02:00
}
if (!m_pCoverNode) {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2023-10-12 18:19:22 +02:00
State_Cover_FindCover();
return;
}
m_csSpecialAttack = m_pCoverNode->GetSpecialAttack(this);
MPrintf("special: %d", m_csSpecialAttack);
if (m_csSpecialAttack) {
2023-10-21 17:18:49 +02:00
SetDesiredYaw(m_pCoverNode->angles.yaw());
2023-10-12 18:19:22 +02:00
SafeSetOrigin(m_pCoverNode->origin);
2023-10-21 17:18:49 +02:00
DesiredAnimation(ANIM_MODE_NORMAL, m_csSpecialAttack);
TransitionState(ACTOR_STATE_COVER_SPECIAL_ATTACK, 0);
2023-10-12 18:19:22 +02:00
return;
}
2023-10-21 17:18:49 +02:00
bCanSee = CanSeeEnemy(500);
bCanShoot = CanShootEnemy(500);
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (bCanSee && bCanShoot) {
vec2_t vDelta;
VectorSub2D(m_Enemy->origin, origin, vDelta);
if (VectorLength2DSquared(vDelta) * 0.75f > Square(DotProduct2D(vDelta, orientation[0]))) {
TransitionState(ACTOR_STATE_COVER_SHOOT);
} else {
TransitionState(ACTOR_STATE_COVER_TARGET);
2023-10-12 18:19:22 +02:00
}
2023-10-21 17:18:49 +02:00
State_Cover_Shoot();
2023-10-12 18:19:22 +02:00
return;
}
2023-10-21 17:18:49 +02:00
if (bCanShoot || bCanShoot) {
2023-10-12 18:19:22 +02:00
m_pCoverNode->Relinquish();
m_pCoverNode->MarkTemporarilyBad();
m_pCoverNode = NULL;
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY);
2023-10-12 18:19:22 +02:00
State_Cover_FindEnemy();
return;
}
if (m_Team == TEAM_AMERICAN) {
if (level.inttime >= m_iLastFaceDecideTime + 1000) {
m_iLastFaceDecideTime = level.inttime;
2023-10-21 17:18:49 +02:00
pNode = PathManager.FindCornerNodeForExactPath(this, m_Enemy, m_fLeash + m_fMaxDistance);
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (!pNode) {
ForwardLook();
2023-10-12 18:19:22 +02:00
Anim_Stand();
m_PotentialEnemies.FlagBadEnemy(m_Enemy);
UpdateEnemy(-1);
return;
}
2023-10-21 17:18:49 +02:00
SetDesiredYawDest(pNode->m_PathPos);
2023-10-12 18:19:22 +02:00
}
Anim_Aim();
} else {
if (level.inttime >= m_iLastFaceDecideTime + 1000) {
m_iLastFaceDecideTime = level.inttime;
2023-10-21 17:18:49 +02:00
trace = G_Trace(
EyePosition(), vec_zero, vec_zero, m_vLastEnemyPos + eyeposition, this, MASK_LOOK, false, "State_Cover"
);
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
pNode = PathManager.FindCornerNodeForWall(origin, m_vLastEnemyPos, this, 0.0f, trace.plane.normal);
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (pNode) {
SetDesiredYawDest(pNode->m_PathPos);
2023-10-12 18:19:22 +02:00
m_eDontFaceWallMode = 6;
} else {
AimAtTargetPos();
DontFaceWall();
}
}
2023-10-21 17:18:49 +02:00
if (m_eDontFaceWallMode == 7 || m_eDontFaceWallMode == 8) {
2023-10-12 18:19:22 +02:00
Anim_Stand();
} else {
Anim_Aim();
}
}
if (level.inttime <= m_iStateTime) {
return;
}
2023-10-21 17:18:49 +02:00
pNode = (PathNode *)G_FindRandomSimpleTarget(m_pCoverNode->Target());
2023-10-12 18:19:22 +02:00
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
if (!pNode) {
Anim_Stand();
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, rand() & 0x7FF);
2023-10-12 18:19:22 +02:00
return;
}
assert(pNode->IsSubclassOfPathNode());
2023-10-21 17:18:49 +02:00
if (pNode->IsSubclassOfPathNode() && !pNode->IsClaimedByOther(this)) {
SetPath(pNode, "Actor::State_Cover_Target", 0);
if (PathExists()) {
m_pCoverNode = pNode;
pNode->Claim(this);
Anim_RunToDanger(ANIM_MODE_PATH_GOAL);
TransitionState(ACTOR_STATE_COVER_SEARCH_NODE, 0);
2023-10-12 18:19:22 +02:00
}
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_Shoot(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
if (m_bNeedReload) {
Cover_FindCover(true);
if (m_pCoverNode) {
2023-10-21 17:18:49 +02:00
Anim_RunToCover(ANIM_MODE_PATH_GOAL);
2023-10-12 18:19:22 +02:00
FaceEnemyOrMotion(0);
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_TAKE_COVER, 0);
2023-10-12 18:19:22 +02:00
return;
}
}
Anim_Shoot();
AimAtTargetPos();
// FIXME: debug build only?
2023-10-12 18:19:22 +02:00
if (level.inttime > m_iStateTime + 10000) {
gi.cvar_set("g_monitornum", va("%i", entnum));
assert(!"anim/shoot.scr took over 10 seconds");
Com_Error(
2023-10-21 17:18:49 +02:00
ERR_DROP, "anim/shoot.scr took over 10 seconds, entnum = %i, targetname = %s", entnum, TargetName().c_str()
2023-10-12 18:19:22 +02:00
);
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_Grenade(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
GenericGrenadeTossThink();
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_SpecialAttack(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
ForwardLook();
2023-10-12 18:19:22 +02:00
assert(m_pCoverNode);
if (!m_pCoverNode) {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, 0);
2023-10-12 18:19:22 +02:00
State_Cover_FindEnemy();
return;
}
if (mbBreakSpecialAttack) {
if (m_pCoverNode) {
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
}
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, 0);
2023-10-12 18:19:22 +02:00
State_Cover_FindEnemy();
return;
}
if (level.inttime >= m_iLastEnemyPosChangeTime + level.intframetime || !m_csSpecialAttack) {
m_csSpecialAttack = m_pCoverNode->GetSpecialAttack(this);
2023-10-21 17:18:49 +02:00
}
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (!m_csSpecialAttack) {
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, 0);
State_Cover_FindEnemy();
return;
2023-10-12 18:19:22 +02:00
}
2023-10-21 17:18:49 +02:00
if (m_csSpecialAttack > STRING_ANIM_HIGHWALL_SCR || m_csSpecialAttack < STRING_ANIM_LOWWALL_SCR) {
SetDesiredYaw(m_pCoverNode->angles.yaw());
} else {
AimAtTargetPos();
}
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
DesiredAnimation(ANIM_MODE_NORMAL, m_csSpecialAttack);
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_FindEnemy(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
if (m_Team == TEAM_AMERICAN) {
2023-10-21 17:18:49 +02:00
ForwardLook();
2023-10-12 18:19:22 +02:00
Anim_Stand();
2023-10-21 17:18:49 +02:00
} else {
AimAtTargetPos();
Anim_Aim();
DontFaceWall();
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
if (CanSeeEnemy(200) && !AvoidingFacingWall()) {
TransitionState(ACTOR_STATE_COVER_TARGET);
} else if (!AvoidingFacingWall() && level.inttime <= m_iStateTime + 500) {
return;
2023-10-12 18:19:22 +02:00
}
}
2023-10-21 17:18:49 +02:00
SetPathWithLeash(m_vLastEnemyPos, NULL, 0);
ShortenPathToAvoidSquadMates();
if (PathExists() && !PathComplete() && PathAvoidsSquadMates()) {
TransitionState(ACTOR_STATE_COVER_HUNT_ENEMY);
} else {
m_bTurretNoInitialCover = true;
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_SearchNode(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
ForwardLook();
2023-10-12 18:19:22 +02:00
if (CanSeeEnemy(200)) {
Anim_Aim();
AimAtTargetPos();
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_TARGET, 0);
2023-10-12 18:19:22 +02:00
return;
}
if (PathExists() && !PathComplete()) {
FaceEnemyOrMotion(level.inttime - m_iStateTime);
2023-10-21 17:18:49 +02:00
Anim_RunToDanger(ANIM_MODE_PATH_GOAL);
return;
}
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
Anim_Aim();
AimAtTargetPos();
if (level.inttime > m_iStateTime + 3000) {
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_HuntEnemy(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
FaceEnemyOrMotion(level.inttime - m_iStateTime);
MovePathWithLeash();
if (PathExists() && !PathComplete()) {
if (CanSeeEnemy(300)) {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_TARGET, 0);
2023-10-12 18:19:22 +02:00
}
2023-10-21 17:18:49 +02:00
return;
}
2023-10-12 18:19:22 +02:00
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_ENEMY, rand() & 0x7FF);
if (m_pCoverNode) {
m_pCoverNode->Relinquish();
m_pCoverNode = NULL;
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::State_Cover_FakeEnemy(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
AimAtTargetPos();
Anim_Aim();
2016-03-27 11:49:47 +02:00
2023-10-12 18:19:22 +02:00
if (level.inttime >= m_iStateTime) {
SetThinkState(THINKSTATE_IDLE, THINKLEVEL_IDLE);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::Think_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
if (!RequireThink()) {
return;
}
UpdateEyeOrigin();
NoPoint();
UpdateEnemy(500);
2023-10-21 17:18:49 +02:00
if (m_State == ACTOR_STATE_COVER_LOOP) {
2023-10-12 18:19:22 +02:00
ContinueAnimation();
} else {
m_bLockThinkState = false;
if (m_Enemy) {
2023-10-21 17:18:49 +02:00
if (m_State == ACTOR_STATE_COVER_FAKE_ENEMY) {
TransitionState(ACTOR_STATE_COVER_NEW_ENEMY, 0);
2023-10-12 18:19:22 +02:00
}
} else {
2023-10-21 17:18:49 +02:00
if (m_State != ACTOR_STATE_COVER_FAKE_ENEMY) {
TransitionState(ACTOR_STATE_COVER_FAKE_ENEMY, (rand() & 0x7FF) + 1000);
2023-10-12 18:19:22 +02:00
}
}
switch (m_State) {
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_START:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "NewEnemy";
State_Cover_NewEnemy();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_FIND_COVER:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "FindCover";
State_Cover_FindCover();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_TAKE_COVER:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "TakeCover";
State_Cover_TakeCover();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_FINISH_RELOADING:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "FinishReloading";
State_Cover_FinishReloading();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_SPECIAL_ATTACK:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "SpecialAttack";
State_Cover_SpecialAttack();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_FIND_ENEMY:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "FindEnemy";
State_Cover_FindEnemy();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_SEARCH_NODE:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "SearchNode";
State_Cover_SearchNode();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_TARGET:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "Target";
State_Cover_Target();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_HIDE:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "Hide";
State_Cover_Hide();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_SHOOT:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "Shoot";
State_Cover_Shoot();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_GRENADE:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "Grenade";
State_Cover_Grenade();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_HUNT_ENEMY:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "HuntEnemy";
State_Cover_HuntEnemy();
break;
2023-10-21 17:18:49 +02:00
case ACTOR_STATE_COVER_FAKE_ENEMY:
2023-10-12 18:19:22 +02:00
m_pszDebugState = "FakeEnemy";
State_Cover_FakeEnemy();
break;
default:
Com_Printf("Actor::Think_Cover: invalid think state %i\n", m_State);
assert(0);
break;
}
2023-10-21 17:18:49 +02:00
if (!CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_IDLE)) {
CheckForTransition(THINKSTATE_BADPLACE, THINKLEVEL_IDLE);
}
2023-10-12 18:19:22 +02:00
}
2023-10-21 17:18:49 +02:00
if (m_State == ACTOR_STATE_COVER_HIDE || m_State == ACTOR_STATE_COVER_FIND_ENEMY
|| m_State == ACTOR_STATE_COVER_TARGET || m_State == ACTOR_STATE_COVER_SHOOT) {
2023-10-12 18:19:22 +02:00
PostThink(false);
2023-10-21 17:18:49 +02:00
} else {
PostThink(true);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::FinishedAnimation_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
if (m_State == ACTOR_STATE_COVER_SHOOT) {
2023-10-12 18:19:22 +02:00
if (m_Enemy && !m_Enemy->IsDead() && CanSeeEnemy(500) && CanShootEnemy(500)) {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_SHOOT, 0);
2023-10-12 18:19:22 +02:00
} else {
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2023-10-12 18:19:22 +02:00
}
2023-10-21 17:18:49 +02:00
} else if (m_State == ACTOR_STATE_COVER_GRENADE || m_State == ACTOR_STATE_COVER_LOOP) {
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::PathnodeClaimRevoked_Cover(void)
2016-03-27 11:49:47 +02:00
{
2023-10-21 17:18:49 +02:00
TransitionState(ACTOR_STATE_COVER_FIND_COVER, 0);
2016-03-27 11:49:47 +02:00
}