openmohaa/code/fgame/actor_weaponless.cpp

152 lines
4.4 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_weaponless.cpp
#include "actor.h"
2023-10-12 18:19:22 +02:00
void Actor::InitWeaponless(GlobalFuncs_t *func)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
func->ThinkState = &Actor::Think_Weaponless;
func->BeginState = &Actor::Begin_Weaponless;
func->SuspendState = &Actor::Suspend_Weaponless;
func->PassesTransitionConditions = &Actor::PassesTransitionConditions_Attack;
func->FinishedAnimation = &Actor::FinishedAnimation_Weaponless;
func->IsState = &Actor::IsAttackState;
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::Begin_Weaponless(void)
2016-03-27 11:49:47 +02:00
{
2023-10-12 18:19:22 +02:00
DoForceActivate();
2018-08-29 14:41:48 +02:00
2023-10-12 18:19:22 +02:00
m_csMood = STRING_ALERT;
m_csIdleMood = STRING_NERVOUS;
2018-08-29 14:41:48 +02:00
2023-10-12 18:19:22 +02:00
if (level.inttime < m_iEnemyChangeTime + 200) {
SetLeashHome(origin);
if (AttackEntryAnimation()) {
m_bLockThinkState = true;
2018-08-29 14:41:48 +02:00
2023-10-22 16:34:15 +02:00
TransitionState(ACTOR_STATE_WEAPONLESS_LOOP, 0);
2023-10-12 18:19:22 +02:00
}
}
2023-10-22 16:34:15 +02:00
TransitionState(ACTOR_STATE_WEAPONLESS_START, 0);
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::Suspend_Weaponless(void)
2016-03-27 11:49:47 +02:00
{
2023-10-22 16:34:15 +02:00
if (m_State == ACTOR_STATE_WEAPONLESS_GRENADE || m_State == ACTOR_STATE_WEAPONLESS_LOOP) {
TransitionState(ACTOR_STATE_WEAPONLESS_START, 0);
2023-10-12 18:19:22 +02:00
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 20:17:09 +02:00
void Actor::State_Weaponless_Normal(void)
{
int iStateTime;
if (m_bScriptGoalValid) {
SetPath(m_vScriptGoal, NULL, 0, NULL, 0);
}
2023-10-22 16:34:15 +02:00
2023-10-12 20:17:09 +02:00
if (PathExists() && !PathComplete()) {
FaceMotion();
2023-10-22 16:34:15 +02:00
Anim_RunToDanger(ANIM_MODE_PATH_GOAL);
return;
}
m_bScriptGoalValid = false;
AimAtTargetPos();
Anim_Stand();
if (level.inttime < m_iStateTime) {
return;
}
if (DecideToThrowGrenade(m_Enemy->origin + m_Enemy->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_WEAPONLESS_GRENADE);
2023-10-12 20:17:09 +02:00
} else {
2023-10-22 16:34:15 +02:00
TransitionState(ACTOR_STATE_WEAPONLESS_START, 1000);
2023-10-12 20:17:09 +02:00
}
}
2023-10-12 18:19:22 +02:00
void Actor::Think_Weaponless(void)
2016-03-27 11:49:47 +02:00
{
2023-10-22 16:34:15 +02:00
if (!RequireThink()) {
return;
}
UpdateEyeOrigin();
NoPoint();
UpdateEnemy(500);
2023-10-12 18:19:22 +02:00
2023-10-22 16:34:15 +02:00
if (m_State == ACTOR_STATE_WEAPONLESS_LOOP) {
ContinueAnimation();
} else {
m_bLockThinkState = false;
if (!m_Enemy) {
SetThinkState(THINKSTATE_IDLE, THINKLEVEL_IDLE);
IdleThink();
return;
}
if (m_State == ACTOR_STATE_WEAPONLESS_START) {
State_Weaponless_Normal();
} else if (m_State == ACTOR_STATE_WEAPONLESS_GRENADE) {
State_Weaponless_Grenade();
2023-10-12 18:19:22 +02:00
} else {
2023-10-22 16:34:15 +02:00
Com_Printf("Think_Weaponless: invalid think state %i\n", m_State);
char assertStr[16317] = {0};
strcpy(assertStr, "\"invalid think state\"\n\tMessage: ");
Q_strcat(assertStr, sizeof(assertStr), DumpCallTrace("thinkstate = %i", m_State));
assert(!assertStr);
2023-10-12 18:19:22 +02:00
}
2023-10-22 16:34:15 +02:00
if (!CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_IDLE)) {
CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_IDLE);
2023-10-12 18:19:22 +02:00
}
}
2023-10-22 16:34:15 +02:00
PostThink(true);
if (GetWeapon(WEAPON_MAIN)) {
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
}
2016-03-27 11:49:47 +02:00
}
2023-10-12 18:19:22 +02:00
void Actor::FinishedAnimation_Weaponless(void)
2016-03-27 11:49:47 +02:00
{
2023-10-22 16:34:15 +02:00
if (m_State == ACTOR_STATE_WEAPONLESS_GRENADE || m_State == ACTOR_STATE_WEAPONLESS_LOOP) {
TransitionState(ACTOR_STATE_WEAPONLESS_NORMAL, 4000);
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_Weaponless_Grenade(void)
2018-09-17 23:50:38 +02:00
{
2023-10-12 18:19:22 +02:00
GenericGrenadeTossThink();
2018-09-17 23:50:38 +02:00
}