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_machinegunner.cpp
|
|
|
|
|
|
|
|
#include "actor.h"
|
2018-08-02 15:12:07 +02:00
|
|
|
#include "weapturret.h"
|
2016-03-27 11:49:47 +02:00
|
|
|
|
2018-09-05 16:55:10 +02:00
|
|
|
extern Vector MINS;
|
|
|
|
extern Vector MAXS;
|
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
void Actor::InitMachineGunner
|
|
|
|
(
|
|
|
|
GlobalFuncs_t *func
|
|
|
|
)
|
|
|
|
{
|
|
|
|
func->BeginState = &Actor::Begin_MachineGunner;
|
|
|
|
func->EndState = &Actor::End_MachineGunner;
|
|
|
|
func->ThinkState = &Actor::Think_MachineGunner;
|
|
|
|
func->IsState = &Actor::IsMachineGunnerState;
|
|
|
|
func->FinishedAnimation = &Actor::FinishedAnimation_MachineGunner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Actor::Begin_MachineGunner
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-09-05 16:55:10 +02:00
|
|
|
m_csMood = STRING_ALERT;
|
|
|
|
m_csIdleMood = STRING_NERVOUS;
|
|
|
|
|
|
|
|
if (m_pTurret)
|
|
|
|
{
|
|
|
|
Sentient *pOwner;
|
|
|
|
m_pTurret->m_bHadOwner = true;
|
|
|
|
pOwner = m_pTurret->GetOwner();
|
|
|
|
if (pOwner)
|
|
|
|
{
|
|
|
|
Com_Printf(
|
|
|
|
"^~^~^ Actor (entnum %d, radnum %d, targetname '%s') cannot use turret (entnum %d, radnum %d, targetname '%s')"
|
|
|
|
" since it is already being used by Actor (entnum %d, radnum %d, targetname '%s')\n",
|
|
|
|
entnum,
|
|
|
|
radnum,
|
|
|
|
targetname.c_str(),
|
|
|
|
m_pTurret->entnum,
|
|
|
|
m_pTurret->radnum,
|
|
|
|
m_pTurret->TargetName().c_str(),
|
|
|
|
pOwner->entnum,
|
|
|
|
pOwner->radnum,
|
|
|
|
pOwner->TargetName().c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Holster();
|
|
|
|
|
|
|
|
m_pTurret->TurretBeginUsed(this);
|
2019-06-30 23:03:24 +02:00
|
|
|
TransitionState(1200, 0);
|
2018-09-05 16:55:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Com_Printf(
|
|
|
|
"^~^~^ Actor (entnum %d, radnum %d, targetname '%s') has no turret specified\n",
|
|
|
|
entnum,
|
|
|
|
radnum,
|
|
|
|
targetname.c_str());
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
void Actor::End_MachineGunner
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-09-05 16:55:10 +02:00
|
|
|
if (!GetWeapon(WEAPON_MAIN))
|
2018-08-29 14:41:48 +02:00
|
|
|
giveItem("models/weapons/mp40.tik");
|
|
|
|
|
|
|
|
Unholster();
|
|
|
|
if (m_pTurret)
|
|
|
|
{
|
|
|
|
if (m_pTurret->GetOwner() == this)
|
|
|
|
{
|
|
|
|
m_pTurret->TurretEndUsed();
|
|
|
|
}
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
void Actor::BecomeTurretGuy
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-09-05 16:55:10 +02:00
|
|
|
SetThinkIdle(THINK_IDLE);
|
2018-08-19 08:26:59 +02:00
|
|
|
|
2018-09-05 16:55:10 +02:00
|
|
|
SetThink(THINKSTATE_ATTACK, THINK_TURRET);
|
|
|
|
SetThink(THINKSTATE_DISGUISE, THINK_DISGUISE_SALUTE);
|
|
|
|
SetThink(THINKSTATE_GRENADE, THINK_GRENADE);
|
2018-08-19 08:26:59 +02:00
|
|
|
|
2018-09-05 16:55:10 +02:00
|
|
|
if (CurrentThink() == THINK_IDLE && Turret_DecideToSelectState())
|
2018-08-19 08:26:59 +02:00
|
|
|
{
|
2019-06-30 23:03:24 +02:00
|
|
|
TransitionState(100, 0);
|
2018-08-19 08:26:59 +02:00
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
2018-09-05 16:55:10 +02:00
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
void Actor::Think_MachineGunner
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-09-05 16:55:10 +02:00
|
|
|
if (RequireThink())
|
|
|
|
{
|
|
|
|
if (m_pTurret && m_pTurret->GetOwner() == this && !m_bNoPlayerCollision)
|
|
|
|
{
|
|
|
|
if (!m_bEnableEnemy)
|
|
|
|
{
|
|
|
|
ThinkHoldGun();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level.inttime < m_iEnemyCheckTime + 200)
|
|
|
|
{
|
|
|
|
ThinkHoldGun();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_iEnemyCheckTime = level.inttime;
|
|
|
|
|
|
|
|
if (m_pTurret->CanTarget(G_GetEntity(0)->centroid))
|
|
|
|
{
|
|
|
|
ThinkHoldGun();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_pGrenade || m_fGrenadeAwareness < rand() * 0.000000046566129)
|
|
|
|
{
|
|
|
|
if (!G_SightTrace(
|
|
|
|
EyePosition(),
|
|
|
|
vec_zero,
|
|
|
|
vec_zero,
|
|
|
|
G_GetEntity(0)->centroid,
|
|
|
|
this,
|
|
|
|
G_GetEntity(0),
|
|
|
|
33819417,
|
|
|
|
qfalse,
|
|
|
|
"Actor::Think_MachineGunner"))
|
|
|
|
{
|
|
|
|
ThinkHoldGun();
|
|
|
|
return;
|
|
|
|
}
|
2019-06-29 23:43:30 +02:00
|
|
|
if (m_ThinkStates[THINKLEVEL_NORMAL] != THINKSTATE_IDLE)
|
2018-09-05 16:55:10 +02:00
|
|
|
{
|
|
|
|
BecomeTurretGuy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Enemy && !m_Enemy->IsSubclassOfActor() && !EnemyIsDisguised() && m_PotentialEnemies.GetCurrentVisibility() >= 1)
|
|
|
|
{
|
|
|
|
BecomeTurretGuy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_Enemy || !m_Enemy->IsSubclassOfActor() || EnemyIsDisguised() || m_PotentialEnemies.GetCurrentVisibility() > 1)
|
|
|
|
{
|
|
|
|
ThinkHoldGun();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCuriousAnimHint(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BecomeTurretGuy();
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
2018-09-05 16:55:10 +02:00
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
void Actor::ThinkHoldGun
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-09-05 16:55:10 +02:00
|
|
|
Vector end;
|
|
|
|
trace_t trace;
|
|
|
|
float temp;
|
|
|
|
float temp2;
|
|
|
|
float machine_gunner_hands_up_stand;
|
|
|
|
float heightDiff;
|
|
|
|
float right;
|
2019-06-29 23:43:30 +02:00
|
|
|
//vec3_t newOrigin;
|
2018-09-05 16:55:10 +02:00
|
|
|
Vector offset;
|
|
|
|
Vector start;
|
2019-06-29 23:43:30 +02:00
|
|
|
//vec3_t new_angles;
|
2018-09-05 16:55:10 +02:00
|
|
|
Vector vForward;
|
|
|
|
|
|
|
|
UpdateEyeOrigin();
|
|
|
|
m_pszDebugState = "";
|
|
|
|
if (m_State == 1200)
|
|
|
|
{
|
|
|
|
if (m_pTurret->IsFiring())
|
|
|
|
{
|
|
|
|
if (m_pTurret->aim_target == G_GetEntity(0))
|
|
|
|
{
|
|
|
|
m_bNoSurprise = true;
|
|
|
|
}
|
|
|
|
m_csNextAnimString = STRING_ANIM_MG42_SHOOT_SCR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_csNextAnimString = STRING_ANIM_MG42_IDLE_SCR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_csNextAnimString = STRING_ANIM_MG42_RELOAD_SCR;
|
|
|
|
m_bAnimScriptSet = false;
|
|
|
|
}
|
|
|
|
m_eNextAnimMode = 8;
|
|
|
|
m_bNextForceStart = false;
|
|
|
|
|
|
|
|
CheckUnregister();
|
|
|
|
|
2019-08-18 22:06:49 +02:00
|
|
|
StopTurning();
|
2018-09-05 16:55:10 +02:00
|
|
|
|
|
|
|
setAngles(Vector(0,m_pTurret->angles[1],0));
|
|
|
|
|
|
|
|
vForward = Vector(m_pTurret->orientation[0]) * -39 + m_pTurret->origin;
|
|
|
|
|
|
|
|
if (m_State == 1201)
|
|
|
|
{
|
2019-06-29 23:43:30 +02:00
|
|
|
heightDiff = 71.6f;
|
2018-09-05 16:55:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-29 23:43:30 +02:00
|
|
|
heightDiff = 71.8f;
|
2018-09-05 16:55:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
machine_gunner_hands_up_stand = origin[2] - (m_pTurret->origin[2] - heightDiff);
|
|
|
|
|
|
|
|
|
|
|
|
if (machine_gunner_hands_up_stand < 0)
|
|
|
|
{
|
|
|
|
if (m_State == 1201)
|
|
|
|
{
|
|
|
|
temp = (machine_gunner_hands_up_stand - m_pTurret->origin[2]) / 39;
|
|
|
|
if (temp >= -1.0 && temp <= 1.0)
|
|
|
|
{
|
|
|
|
right = atan2(temp / sqrt(temp*-temp + 1), 1) * 180 / M_PI;
|
|
|
|
m_pTurret->setAngles(Vector(right, m_pTurret->angles[1], m_pTurret->angles[2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fCrouchWeight = machine_gunner_hands_up_stand / 17.1;
|
|
|
|
if (m_fCrouchWeight < -1.0)
|
|
|
|
{
|
|
|
|
m_fCrouchWeight = -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
temp2 = m_fCrouchWeight * 2.6;
|
|
|
|
offset.x = (-(-9.3*m_fCrouchWeight + 23.4)) * orientation[0][0] + vForward.x;
|
|
|
|
offset.y = (-(-9.3*m_fCrouchWeight + 23.4)) * orientation[0][0] + vForward.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fCrouchWeight = machine_gunner_hands_up_stand / (heightDiff - 38.7);
|
|
|
|
if (m_fCrouchWeight > 1.0)
|
|
|
|
{
|
|
|
|
m_fCrouchWeight = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp2 = m_fCrouchWeight * -1.6;
|
|
|
|
offset.x = (-(-3*m_fCrouchWeight + 23.4)) * orientation[0][0] + vForward.x;
|
|
|
|
offset.y = (-(-3*m_fCrouchWeight + 23.4)) * orientation[0][0] + vForward.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
start.x = (temp2 + 10.3) * orientation[1][0] + offset.x;
|
|
|
|
start.y = (temp2 + 10.3) * orientation[1][1] + offset.y;
|
|
|
|
|
|
|
|
if (m_fCrouchWeight >= 0.5)
|
|
|
|
m_csCurrentPosition = STRING_CROUCH;
|
|
|
|
else
|
|
|
|
m_csCurrentPosition = STRING_STAND;
|
|
|
|
|
|
|
|
UpdateAimMotion();
|
|
|
|
UpdateAnim();
|
|
|
|
start.z = origin.z + 18.0;
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
end.z = origin.z - 94.0;
|
|
|
|
|
|
|
|
trace = G_Trace(start, MINS, MAXS, end, this, 1107437825, qfalse, "Actor::ThinkHoldGun");
|
|
|
|
|
|
|
|
if (trace.fraction != 1.0 && !trace.startsolid && !trace.allsolid && trace.ent)
|
|
|
|
SafeSetOrigin(trace.endpos);
|
|
|
|
|
|
|
|
velocity = vec_zero;
|
|
|
|
|
|
|
|
UpdateBoneControllers();
|
|
|
|
UpdateFootsteps();
|
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
2018-09-05 16:55:10 +02:00
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
void Actor::FinishedAnimation_MachineGunner
|
|
|
|
(
|
|
|
|
void
|
|
|
|
)
|
|
|
|
{
|
2018-08-29 14:41:48 +02:00
|
|
|
if (!m_bAnimScriptSet && m_State == 1201)
|
|
|
|
{
|
2019-06-30 23:03:24 +02:00
|
|
|
TransitionState(1200, 0);
|
2018-08-29 14:41:48 +02:00
|
|
|
Unregister(STRING_ANIMDONE);
|
|
|
|
}
|
2016-03-27 11:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Actor::MachineGunner_CanSee
|
|
|
|
(
|
2018-08-02 15:12:07 +02:00
|
|
|
Entity *ent,
|
2016-03-27 11:49:47 +02:00
|
|
|
float fov,
|
|
|
|
float vision_distance
|
|
|
|
)
|
|
|
|
{
|
2018-08-02 15:12:07 +02:00
|
|
|
float delta[2];
|
|
|
|
|
|
|
|
delta[0] = ent->centroid[0] - centroid[0];
|
|
|
|
delta[1] = ent->centroid[1] - centroid[1];
|
|
|
|
if ((vision_distance <= 0.0f) || (delta[0] * delta[0] + delta[1] * delta[1]) <= (vision_distance * vision_distance))
|
|
|
|
{
|
|
|
|
if (gi.AreasConnected(edict->r.areanum, ent->edict->r.areanum) &&
|
|
|
|
((fov <= 0.0f || fov >= 360.0f) ||
|
|
|
|
(FovCheck(delta, cos(fov * (0.5 * M_PI / 180.0))))))
|
|
|
|
{
|
|
|
|
return G_SightTrace(centroid,
|
|
|
|
vec_zero,
|
|
|
|
vec_zero,
|
|
|
|
ent->centroid,
|
|
|
|
m_pTurret,
|
|
|
|
ent,
|
|
|
|
MASK_CANSEE,
|
|
|
|
0,
|
|
|
|
"Actor::MachineGunner_CanSee");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-27 11:49:47 +02:00
|
|
|
return false;
|
|
|
|
}
|