cl_dll/weapon_selection.cpp
131415161718
#include
#include "filesystem.h"
#include "iinput.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
13141516171819
#include
#include "filesystem.h"
#include "iinput.h"
#include "c_ff_hint_timers.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
1920212223242526
#define HISTORY_DRAW_TIME "5"
ConVar hud_drawhistory_time( "hud_drawhistory_time", HISTORY_DRAW_TIME, 0 );
ConVar hud_fastswitch( "hud_fastswitch", "0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX );
//-----------------------------------------------------------------------------
// Purpose: Weapon Selection commands
2021222324252627
#define HISTORY_DRAW_TIME "5"
ConVar hud_drawhistory_time( "hud_drawhistory_time", HISTORY_DRAW_TIME, FCVAR_ARCHIVE );
ConVar hud_fastswitch( "hud_fastswitch", "0", FCVAR_ARCHIVE, "0 = none | 1 = keyboard & mouse | 2 = keyboard only (old HL/TFC style)" );
//-----------------------------------------------------------------------------
// Purpose: Weapon Selection commands
88899091929394
// Initialise the weapons resource
gWR.Init();
m_flSelectionTime = gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
89909192939495
// Initialise the weapons resource
gWR.Init();
m_flSelectionTime = gpGlobals->curtime - 10.0f; // |-- Mirv: Make sure starts in past
}
//-----------------------------------------------------------------------------
100101102103104105106
// Start hidden
m_bSelectionVisible = false;
m_flSelectionTime = gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
101102103104105106107
// Start hidden
m_bSelectionVisible = false;
m_flSelectionTime = gpGlobals->curtime - 10.0f; // |-- Mirv: Make sure starts in past
}
//-----------------------------------------------------------------------------
134135136137138139140141142143144145146147148
//-----------------------------------------------------------------------------
void CBaseHudWeaponSelection::OnThink( void )
{
// Don't allow weapon selection if we're frozen in place
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( pPlayer->GetFlags() & FL_FROZEN || pPlayer->IsPlayerDead() )
{
if ( IsInSelectionMode() )
{
CancelWeaponSelection();
}
}
}
//-----------------------------------------------------------------------------
135136137138139140
//-----------------------------------------------------------------------------
void CBaseHudWeaponSelection::OnThink( void )
{
}
//-----------------------------------------------------------------------------
160161162163164165166167168169170171
// If so, close weapon selection when they press fire
if ( gHUD.m_iKeyBits & IN_ATTACK )
{
if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() )
{
// Swallow the button
gHUD.m_iKeyBits &= ~IN_ATTACK;
input->ClearInputButton( IN_ATTACK );
}
engine->ClientCmd( "cancelselect\n" );
}
152153154155156157158159160
// If so, close weapon selection when they press fire
if ( gHUD.m_iKeyBits & IN_ATTACK )
{
// Swallow the button
gHUD.m_iKeyBits &= ~IN_ATTACK;
input->ClearInputButton( IN_ATTACK );
engine->ClientCmd( "cancelselect\n" );
}
177178179180181182183184185186187188189
{
if ( IsWeaponSelectable() )
{
if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() )
{
// Swallow the button
gHUD.m_iKeyBits &= ~(IN_ATTACK | IN_ATTACK2);
input->ClearInputButton( IN_ATTACK );
input->ClearInputButton( IN_ATTACK2 );
}
// select weapon
SelectWeapon();
166167168169170171172173174175
{
if ( IsWeaponSelectable() )
{
// Swallow the button
gHUD.m_iKeyBits &= ~(IN_ATTACK | IN_ATTACK2);
input->ClearInputButton( IN_ATTACK );
input->ClearInputButton( IN_ATTACK2 );
// select weapon
SelectWeapon();
215216217218219220221222223224225226227228229230231232233234235
m_bSelectionVisible = false;
}
//-----------------------------------------------------------------------------
// Purpose: Returns whether a weapon can be selected in the HUD, based on hud type
//-----------------------------------------------------------------------------
bool CBaseHudWeaponSelection::CanBeSelectedInHUD( C_BaseCombatWeapon *pWeapon )
{
// Xbox: In plus type, weapons without ammo can still be selected in the HUD
if( HUDTYPE_PLUS == hud_fastswitch.GetInt() )
{
return pWeapon->VisibleInWeaponSelection();
}
// All other current hud types
return pWeapon->CanBeSelected();
}
//-----------------------------------------------------------------------------
// Purpose: handles keyboard input
//-----------------------------------------------------------------------------
201202203204205206207
m_bSelectionVisible = false;
}
//-----------------------------------------------------------------------------
// Purpose: handles keyboard input
//-----------------------------------------------------------------------------
266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
//------------------------------------------------------------------------
void CBaseHudWeaponSelection::UserCmd_Slot1(void)
{
if( HUDTYPE_CAROUSEL == hud_fastswitch.GetInt() )
{
UserCmd_LastWeapon();
}
else
{
SelectSlot( 1 );
}
}
void CBaseHudWeaponSelection::UserCmd_Slot2(void)
{
if( HUDTYPE_CAROUSEL == hud_fastswitch.GetInt() )
{
UserCmd_NextWeapon();
}
else
{
SelectSlot( 2 );
}
}
void CBaseHudWeaponSelection::UserCmd_Slot3(void)
{
if( HUDTYPE_CAROUSEL == hud_fastswitch.GetInt() )
{
engine->ClientCmd( "phys_swap" );
}
else
{
SelectSlot( 3 );
}
}
void CBaseHudWeaponSelection::UserCmd_Slot4(void)
{
if( HUDTYPE_CAROUSEL == hud_fastswitch.GetInt() )
{
UserCmd_PrevWeapon();
}
else
{
SelectSlot( 4 );
}
}
void CBaseHudWeaponSelection::UserCmd_Slot5(void)
238239240241242243244245246247248249250251252253254255256257258259
//------------------------------------------------------------------------
void CBaseHudWeaponSelection::UserCmd_Slot1(void)
{
SelectSlot( 1 );
}
void CBaseHudWeaponSelection::UserCmd_Slot2(void)
{
SelectSlot( 2 );
}
void CBaseHudWeaponSelection::UserCmd_Slot3(void)
{
SelectSlot( 3 );
}
void CBaseHudWeaponSelection::UserCmd_Slot4(void)
{
SelectSlot( 4 );
}
void CBaseHudWeaponSelection::UserCmd_Slot5(void)
362363364365366367368369370371372
//-----------------------------------------------------------------------------
bool CBaseHudWeaponSelection::IsHudMenuPreventingWeaponSelection()
{
// Don't allow weapon selection if we're frozen in place
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( pPlayer->GetFlags() & FL_FROZEN || pPlayer->IsPlayerDead() )
return true;
return IsHudMenuTakingInput();
}
306307308309310311
//-----------------------------------------------------------------------------
bool CBaseHudWeaponSelection::IsHudMenuPreventingWeaponSelection()
{
return IsHudMenuTakingInput();
}
378379380381382383
return false;
}
return BaseClass::ShouldDraw();
}
317318319320321322323324325326327328329
return false;
}
// --> Mirv: Not while dead
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if (!player || !player->IsAlive() || player->GetTeamNumber() < TEAM_BLUE)
return false;
// <-- Mirv: Not while dead
return BaseClass::ShouldDraw();
}
400401402403404405406407
return;
}
UpdateSelectionTime();
SelectWeaponSlot( iSlot );
}
//-----------------------------------------------------------------------------
346347348349350351352353354355356357
return;
}
SelectWeaponSlot( iSlot );
// --> Mirv: On fast switch don't let this re-show the weapon select
if( hud_fastswitch.GetInt() == 0 )
UpdateSelectionTime();
// <-- Mirv: On fast switch don't let this re-show the weapon select
}
//-----------------------------------------------------------------------------
426427428429430431432433434435436437
return;
}
CycleToNextWeapon();
if( hud_fastswitch.GetInt() > 0 )
{
SelectWeapon();
}
UpdateSelectionTime();
}
//-----------------------------------------------------------------------------
376377378379380381382383384385386387388389390391392393394395396397398399400401402403
return;
}
// --> Mirv: Not while dead
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if (!player || !player->IsAlive() || player->GetTeamNumber() < TEAM_BLUE)
return;
// <-- Mirv: Not while dead
CycleToNextWeapon();
// --> Mirv: hud_fastswitch 1 will automatically change on prev/next
//#ifdef HL2MP
if( hud_fastswitch.GetInt() == 1 )
{
SelectWeapon();
m_flSelectionTime = gpGlobals->curtime - 4.0f;
}
else
//#endif
// <-- Mirv
{
UpdateSelectionTime();
}
}
//-----------------------------------------------------------------------------
448449450451452453454455456457458459460461
return;
}
CycleToPrevWeapon();
if( hud_fastswitch.GetInt() > 0 )
{
SelectWeapon();
}
UpdateSelectionTime();
}
//-----------------------------------------------------------------------------
414415416417418419420421422423424425426427428429430431432433434435436437438439440441
return;
}
// --> Mirv: Not while dead
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if (!player || !player->IsAlive() || player->GetTeamNumber() < TEAM_BLUE)
return;
// <-- Mirv: Not while dead
CycleToPrevWeapon();
// --> Mirv: hud_fastswitch 1 will automatically change on prev/next
//#ifdef HL2MP
if( hud_fastswitch.GetInt() == 1 )
{
SelectWeapon();
m_flSelectionTime = gpGlobals->curtime - 4.0f;
}
else
//#endif
// <-- Mirv
{
UpdateSelectionTime();
}
}
//-----------------------------------------------------------------------------
482483484485486487488489490491
{
// Get the player's last weapon
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if ( !player )
return;
input->MakeWeaponSelection( player->GetLastWeapon() );
}
//-----------------------------------------------------------------------------
462463464465466467468469470471472473474475476477
{
// Get the player's last weapon
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
// --> Mirv: Don't select while dead
if (!player || !player->IsAlive() || player->GetTeamNumber() < TEAM_BLUE)
return;
// <-- Mirv: Don't select while dead
input->MakeWeaponSelection( player->GetLastWeapon() );
// Jiggles: The player used the Last Inventory key! Good for him/her!
g_FFHintTimers.DeleteTimer( "LI" );
}
//-----------------------------------------------------------------------------
510511512513514515516517518519
return;
}
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if ( !player )
return;
// Don't allow selections of weapons that can't be selected (out of ammo, etc)
if ( !GetSelectedWeapon()->CanBeSelected() )
{
496497498499500501502503504505506507508509
return;
}
// --> Mirv: Not while dead
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if (!player || !player->IsAlive() || player->GetTeamNumber() < TEAM_BLUE)
return;
// <-- Mirv: Not while dead
// Don't allow selections of weapons that can't be selected (out of ammo, etc)
if ( !GetSelectedWeapon()->CanBeSelected() )
{
611612613614615616617
if ( !pWeapon )
continue;
if ( CanBeSelectedInHUD( pWeapon ) && pWeapon->GetSlot() == iSlot )
{
// If this weapon is lower in the slot than the current lowest, and above our desired position, it's our new winner
if ( pWeapon->GetPosition() <= iLowestPosition && pWeapon->GetPosition() >= iSlotPos )
601602603604605606607
if ( !pWeapon )
continue;
if ( pWeapon->CanBeSelected() && pWeapon->GetSlot() == iSlot )
{
// If this weapon is lower in the slot than the current lowest, and above our desired position, it's our new winner
if ( pWeapon->GetPosition() <= iLowestPosition && pWeapon->GetPosition() >= iSlotPos )