2023-10-14 00:54:52 +02:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 2023 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_runandshoot.cpp
|
2024-08-26 23:42:31 +02:00
|
|
|
//
|
|
|
|
// Added in 2.30
|
|
|
|
//
|
2023-10-14 00:54:52 +02:00
|
|
|
|
|
|
|
#include "actor.h"
|
|
|
|
|
|
|
|
void Actor::InitRunAndShoot(GlobalFuncs_t *func)
|
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
func->ThinkState = &Actor::Think_RunAndShoot;
|
|
|
|
func->BeginState = &Actor::Begin_RunAndShoot;
|
|
|
|
func->EndState = &Actor::End_RunAndShoot;
|
|
|
|
func->ResumeState = &Actor::Resume_RunAndShoot;
|
|
|
|
func->PassesTransitionConditions = &Actor::PassesTransitionConditions_Attack;
|
|
|
|
func->ShowInfo = &Actor::ShowInfo_RunAndShoot;
|
|
|
|
func->IsState = &Actor::IsAttackState;
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::Begin_RunAndShoot(void)
|
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
if (m_patrolCurrentNode) {
|
|
|
|
m_State = ACTOR_STATE_RUN_AND_SHOOT_RUNNING;
|
2024-08-26 23:42:31 +02:00
|
|
|
} else {
|
|
|
|
m_State = ACTOR_STATE_RUN_AND_SHOOT_RUN;
|
2023-10-15 21:53:15 +02:00
|
|
|
}
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::End_RunAndShoot(void)
|
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
m_vHome = origin;
|
|
|
|
m_pTetherEnt = NULL;
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-15 21:53:15 +02:00
|
|
|
void Actor::Resume_RunAndShoot(void) {}
|
2023-10-14 00:54:52 +02:00
|
|
|
|
|
|
|
void Actor::Think_RunAndShoot(void)
|
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
if (m_State == ACTOR_STATE_RUN_AND_SHOOT_RUNNING) {
|
|
|
|
State_RunAndShoot_Running();
|
|
|
|
} else if (m_State == ACTOR_STATE_RUN_AND_SHOOT_RUN) {
|
|
|
|
SetThink(THINKSTATE_ATTACK, THINK_COVER);
|
|
|
|
}
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-15 21:53:15 +02:00
|
|
|
void Actor::ShowInfo_RunAndShoot(void) {}
|
2023-10-14 00:54:52 +02:00
|
|
|
|
|
|
|
void Actor::State_RunAndShoot_Running(void)
|
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
Entity *player;
|
|
|
|
bool bMoveDone;
|
|
|
|
|
|
|
|
if (!RequireThink()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parm.movefail = false;
|
|
|
|
UpdateEyeOrigin();
|
|
|
|
NoPoint();
|
|
|
|
|
|
|
|
m_pszDebugState = "";
|
|
|
|
bMoveDone = RunAndShoot_MoveToPatrolCurrentNode();
|
|
|
|
|
|
|
|
CheckForThinkStateTransition();
|
|
|
|
player = G_GetEntity(0);
|
|
|
|
if (player) {
|
|
|
|
vec2_t delta;
|
|
|
|
|
|
|
|
VectorSub2D(player->origin, origin, delta);
|
|
|
|
|
|
|
|
if (VectorLength2DSquared(delta) < Square(150)) {
|
|
|
|
ClearPatrolCurrentNode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_patrolCurrentNode) {
|
|
|
|
if (m_Enemy) {
|
|
|
|
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
|
|
|
|
} else {
|
|
|
|
SetThinkIdle(THINK_IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bScriptGoalValid = false;
|
|
|
|
parm.movedone = true;
|
|
|
|
|
|
|
|
Unregister(STRING_MOVEDONE);
|
|
|
|
} else if (bMoveDone) {
|
|
|
|
ClearPatrolCurrentNode();
|
|
|
|
|
|
|
|
if (m_Enemy) {
|
|
|
|
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
|
|
|
|
} else {
|
|
|
|
SetThinkIdle(THINK_IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
parm.movedone = true;
|
|
|
|
|
|
|
|
Unregister(STRING_MOVEDONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Unregister(STRING_MOVE);
|
|
|
|
|
2023-10-16 23:32:59 +02:00
|
|
|
CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_IDLE);
|
2023-10-15 21:53:15 +02:00
|
|
|
PostThink(true);
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-15 21:53:15 +02:00
|
|
|
bool Actor::RunAndShoot_MoveToPatrolCurrentNode(void)
|
2023-10-14 00:54:52 +02:00
|
|
|
{
|
2023-10-15 21:53:15 +02:00
|
|
|
UpdatePatrolCurrentNode();
|
|
|
|
|
2024-02-19 23:25:39 +01:00
|
|
|
if (!m_patrolCurrentNode || m_bPatrolWaitTrigger) {
|
2023-10-15 21:53:15 +02:00
|
|
|
IdleLook();
|
|
|
|
Anim_Idle();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetPath(m_patrolCurrentNode->origin, "Actor::RunAndShoot_MoveToPatrolCurrentNode", 0, NULL, 0);
|
|
|
|
|
|
|
|
if (!PathExists()) {
|
|
|
|
IdleLook();
|
|
|
|
Anim_Idle();
|
|
|
|
|
|
|
|
parm.movefail = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MoveOnPathWithSquad()) {
|
|
|
|
if (m_Enemy) {
|
2024-08-26 23:42:31 +02:00
|
|
|
DesiredAnimation(ANIM_MODE_PATH, STRING_ANIM_RUNTO_INOPEN_SCR);
|
|
|
|
AimAtTargetPos();
|
2023-10-15 21:53:15 +02:00
|
|
|
} else {
|
2024-08-26 23:42:31 +02:00
|
|
|
DesiredAnimation(ANIM_MODE_PATH, STRING_ANIM_CROUCH_RUN_SCR);
|
2023-10-15 21:53:15 +02:00
|
|
|
FaceMotion();
|
|
|
|
}
|
|
|
|
} else if (m_Enemy) {
|
2024-08-26 23:42:31 +02:00
|
|
|
AimAtTargetPos();
|
2023-10-15 21:53:15 +02:00
|
|
|
Anim_Attack();
|
|
|
|
} else {
|
|
|
|
Anim_Stand();
|
|
|
|
IdleLook();
|
|
|
|
}
|
|
|
|
|
2024-08-26 23:42:31 +02:00
|
|
|
if (m_fMoveDoneRadiusSquared) {
|
|
|
|
if (PathComplete()) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-10-15 21:53:15 +02:00
|
|
|
|
2024-08-26 23:42:31 +02:00
|
|
|
if (m_Path.HasCompleteLookahead() && !m_patrolCurrentNode->Next()) {
|
|
|
|
return VectorLength2DSquared(PathDelta()) <= m_fMoveDoneRadiusSquared;
|
|
|
|
}
|
2023-10-15 21:53:15 +02:00
|
|
|
}
|
|
|
|
|
2024-08-26 23:42:31 +02:00
|
|
|
return false;
|
2023-10-14 00:54:52 +02:00
|
|
|
}
|