📄 tf_class_commando.cpp
字号:
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose: The Commando Player Class
//
// $Workfile: $
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "tf_player.h"
#include "tf_class_commando.h"
#include "tf_vehicle_teleport_station.h"
#include "EntityList.h"
#include "basecombatweapon.h"
#include "weapon_builder.h"
#include "tf_obj.h"
#include "tf_obj_rallyflag.h"
#include "tf_team.h"
#include "order_assist.h"
#include "engine/IEngineSound.h"
#include "weapon_twohandedcontainer.h"
#include "weapon_combatshield.h"
ConVar tf_knockdowntime( "tf_knockdowntime", "3", FCVAR_NONE, "Length of time knocked-down players remain on the ground." );
// Adrenalin
ConVar class_commando_speed( "class_commando_speed","200", FCVAR_NONE, "Commando movement speed." );
ConVar class_commando_rush_length( "class_commando_rush_length","10", FCVAR_NONE, "Commando's adrenalin rush length in seconds." );
ConVar class_commando_rush_recharge( "class_commando_rush_recharge","60", FCVAR_NONE, "Commando's adrenalin rush recharge time in seconds." );
ConVar class_commando_battlecry_radius( "class_commando_battlecry_radius","512", FCVAR_NONE, "Commando's battlecry radius." );
ConVar class_commando_battlecry_length( "class_commando_battlecry_length","10", FCVAR_NONE, "Length of adrenalin rush given by the Commando's battlecry in seconds." );
//=============================================================================
//
// Commando Data Table
//
BEGIN_SEND_TABLE_NOBASE( CPlayerClassCommando, DT_PlayerClassCommandoData )
SendPropInt ( SENDINFO_STRUCTELEM( m_ClassData.m_bCanBullRush ), 1, SPROP_UNSIGNED ),
SendPropInt ( SENDINFO_STRUCTELEM( m_ClassData.m_bBullRush ), 1, SPROP_UNSIGNED ),
SendPropVector ( SENDINFO_STRUCTELEM( m_ClassData.m_vecBullRushDir ), -1, SPROP_COORD ),
SendPropVector ( SENDINFO_STRUCTELEM( m_ClassData.m_vecBullRushViewDir ), -1, SPROP_COORD ),
SendPropVector ( SENDINFO_STRUCTELEM( m_ClassData.m_vecBullRushViewGoalDir ), -1, SPROP_COORD ),
SendPropFloat ( SENDINFO_STRUCTELEM( m_ClassData.m_flBullRushTime ), 32, SPROP_NOSCALE ),
SendPropFloat ( SENDINFO_STRUCTELEM( m_ClassData.m_flDoubleTapForwardTime ), 32, SPROP_NOSCALE ),
END_SEND_TABLE()
//-----------------------------------------------------------------------------
// Purpose:
// Output : const char
//-----------------------------------------------------------------------------
const char *CPlayerClassCommando::GetClassModelString( int nTeam )
{
if (nTeam == TEAM_HUMANS)
return "models/player/human_commando.mdl";
else
return "models/player/alien_commando.mdl";
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CPlayerClassCommando::CPlayerClassCommando( CBaseTFPlayer *pPlayer, TFClass iClass ) : CPlayerClass( pPlayer, iClass )
{
for (int i = 1; i <= MAX_TF_TEAMS; ++i)
{
SetClassModel( MAKE_STRING(GetClassModelString(i)), i );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CPlayerClassCommando::~CPlayerClassCommando()
{
m_aHitPlayers.RemoveAll();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::ClassActivate( void )
{
BaseClass::ClassActivate();
// Setup movement data.
SetupMoveData();
// Initialize the shared class data.
m_ClassData.m_bCanBullRush = false;
m_ClassData.m_bBullRush = false;
m_ClassData.m_vecBullRushDir.Init();
m_ClassData.m_vecBullRushViewDir.Init();
m_ClassData.m_vecBullRushViewGoalDir.Init();
m_ClassData.m_flBullRushTime = COMMANDO_TIME_INVALID;
m_ClassData.m_flDoubleTapForwardTime = COMMANDO_TIME_INVALID;
m_bCanRush = false;
m_bPersonalRush = false;
m_bHasBattlecry = false;
m_bCanBoot = false;
m_flNextBootCheck = 0.0f; // Time at which to recheck for the automatic melee attack
m_bOldBullRush = 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::ClassDeactivate( void )
{
m_hWpnShield = NULL;
m_hWpnPlasma = NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::CreateClass( void )
{
BaseClass::CreateClass();
// Create our two handed weapon layout
m_hWpnShield = m_pPlayer->GetCombatShield();
CWeaponTwoHandedContainer *p = ( CWeaponTwoHandedContainer * )m_pPlayer->Weapon_OwnsThisType( "weapon_twohandedcontainer" );
if ( !p )
{
p = static_cast< CWeaponTwoHandedContainer * >( m_pPlayer->GiveNamedItem( "weapon_twohandedcontainer" ) );
}
if ( p && m_hWpnShield.Get() )
{
m_hWpnShield->SetReflectViewModelAnimations( true );
p->SetWeapons( NULL, m_hWpnShield );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::RespawnClass( void )
{
BaseClass::RespawnClass();
m_flNextBootCheck = 0;
}
//-----------------------------------------------------------------------------
// Purpose: Supply the player with Ammo. Return true if some ammo was given.
//-----------------------------------------------------------------------------
bool CPlayerClassCommando::ResupplyAmmo( float flFraction, ResupplyReason_t reason )
{
bool bGiven = false;
if ((reason == RESUPPLY_ALL_FROM_STATION) || (reason == RESUPPLY_GRENADES_FROM_STATION))
{
if (ResupplyAmmoType( 3 * flFraction, "Grenades" ))
bGiven = true;
if (ResupplyAmmoType( 1, "RallyFlags" ))
bGiven = true;
if (ResupplyAmmoType( 3, "Rockets" ))
bGiven = true;
}
if ((reason == RESUPPLY_ALL_FROM_STATION) || (reason == RESUPPLY_AMMO_FROM_STATION))
{
if (ResupplyAmmoType( 3, "Rockets" ))
bGiven = true;
}
// On respawn, resupply base weapon ammo
if ( reason == RESUPPLY_RESPAWN )
{
}
if ( BaseClass::ResupplyAmmo(flFraction, reason) )
bGiven = true;
return bGiven;
}
//-----------------------------------------------------------------------------
// Purpose: Set commando class specific movement data here.
//-----------------------------------------------------------------------------
void CPlayerClassCommando::SetupMoveData( void )
{
// Setup Class statistics
m_flMaxWalkingSpeed = class_commando_speed.GetFloat();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::SetupSizeData( void )
{
// Initially set the player to the base player class standing hull size.
m_pPlayer->SetCollisionBounds( COMMANDOCLASS_HULL_STAND_MIN, COMMANDOCLASS_HULL_STAND_MAX );
m_pPlayer->SetViewOffset( COMMANDOCLASS_VIEWOFFSET_STAND );
m_pPlayer->m_Local.m_flStepSize = COMMANDOCLASS_STEPSIZE;
}
//-----------------------------------------------------------------------------
// Purpose: Return true if this player's allowed to build another one of the specified objects
//-----------------------------------------------------------------------------
int CPlayerClassCommando::CanBuild( int iObjectType )
{
if ( iObjectType == OBJ_RALLYFLAG )
{
if ( !m_pPlayer->HasNamedTechnology( "com_obj_rallyflag" ) )
return CB_NOT_RESEARCHED;
}
return BaseClass::CanBuild( iObjectType );
}
//-----------------------------------------------------------------------------
// Purpose: Object has been built by this player
//-----------------------------------------------------------------------------
void CPlayerClassCommando::FinishedObject( CBaseObject *pObject )
{
}
//-----------------------------------------------------------------------------
// Purpose: Calculate the Commando's Adrenalin Rush from available technologies
//-----------------------------------------------------------------------------
void CPlayerClassCommando::CalculateRush( void )
{
// Adrenalin Rush
if ( m_pPlayer->HasNamedTechnology( "com_adrenalin_rush" ) )
{
m_bCanRush = true;
}
else
{
m_bCanRush = false;
}
// Battlecry
m_bHasBattlecry = m_pPlayer->HasNamedTechnology( "com_adrenalin_battlecry" );
// Boot
// ROBIN: Removed for now
m_bCanBoot = false;//m_pPlayer->HasNamedTechnology( "com_automatic_boot" );
// Killing Rush
m_pPlayer->SetRampage( m_pPlayer->HasNamedTechnology( "com_adrenalin_rampage" ) );
}
//-----------------------------------------------------------------------------
// Purpose: Return true if the player is bullrushing.
//-----------------------------------------------------------------------------
bool CPlayerClassCommando::InBullRush( void )
{
return m_ClassData.m_bBullRush;
}
//-----------------------------------------------------------------------------
// Purpose: Return true if the player's able to bull rush
//-----------------------------------------------------------------------------
bool CPlayerClassCommando::CanBullRush( void )
{
return m_ClassData.m_bCanBullRush;
}
//-----------------------------------------------------------------------------
// Should we take damage-based force?
//-----------------------------------------------------------------------------
bool CPlayerClassCommando::ShouldApplyDamageForce( const CTakeDamageInfo &info )
{
return !InBullRush();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPlayerClassCommando::BullRushTouch( CBaseEntity *pTouched )
{
if ( pTouched->IsPlayer() && !pTouched->InSameTeam( m_pPlayer ) )
{
// Get the player.
CBaseTFPlayer *pTFPlayer = ( CBaseTFPlayer* )pTouched;
// Check to see if we have "touched" this player already this bullrush cycle.
if ( m_aHitPlayers.Find( pTFPlayer ) != -1 )
return;
// Hitting the player now.
m_aHitPlayers.AddToTail( pTFPlayer );
// ROBIN: Bullrush now instantly kills again
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -