Skip to content
This repository was archived by the owner on May 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mp/game/neo/scripts/weapon_grenade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ WeaponData

"primary_ammo" "AMMO_GRENADE"
"secondary_ammo" "None"
"autoswitchfrom" "0"
"autoswitchfrom" "1"

"weight" "1"
"item_flags" "18" // ITEM_FLAG_NOAUTORELOAD | ITEM_FLAG_EXHAUSTIBLE
Expand Down
2 changes: 2 additions & 0 deletions mp/game/neo/scripts/weapon_knife.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ WeaponData
"clip_size" "-1"
"primary_ammo" "None"
"secondary_ammo" "None"
"MeleeWeapon" "1"
"autoswitchto" "1"

"weight" "0"
"item_flags" "0"
Expand Down
1 change: 1 addition & 0 deletions mp/game/neo/scripts/weapon_remotedet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WeaponData
"clip_size" "1"
"primary_ammo" "AMMO_DETPACK"
"secondary_ammo" "None"
"autoswitchfrom" "1"

"weight" "1"
"item_flags" "0"
Expand Down
1 change: 1 addition & 0 deletions mp/game/neo/scripts/weapon_smokegrenade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WeaponData

"primary_ammo" "AMMO_SMOKEGRENADE"
"secondary_ammo" "None"
"autoswitchfrom" "1"

"weight" "1"
"item_flags" "18" // ITEM_FLAG_NOAUTORELOAD | ITEM_FLAG_EXHAUSTIBLE
Expand Down
7 changes: 7 additions & 0 deletions mp/src/game/shared/basecombatcharacter_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ bool CBaseCombatCharacter::SwitchToNextBestWeapon(CBaseCombatWeapon *pCurrent)

if ( ( pNewWeapon != NULL ) && ( pNewWeapon != pCurrent ) )
{
#ifndef CLIENT_DLL
// If current weapon is exhaustible, remove it
if ((pCurrent->GetWeaponFlags() & ITEM_FLAG_EXHAUSTIBLE) != false) {
UTIL_Remove(pCurrent);
}
#endif // !CLIENT_DLL

return Weapon_Switch( pNewWeapon );
}

Expand Down
66 changes: 64 additions & 2 deletions mp/src/game/shared/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,74 @@ CGameRules::~CGameRules()

bool CGameRules::SwitchToNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon )
{
return false;
return true;
}

CBaseCombatWeapon *CGameRules::GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon )
{
return NULL;
CBaseCombatWeapon* pCheck;
CBaseCombatWeapon* pBest;// this will be used in the event that we don't find a weapon in the same category.

int iCurrentWeight = -1;
int iBestWeight = -1;// no weapon lower than -1 can be autoswitched to
pBest = NULL;

// If I have a weapon, make sure I'm allowed to holster it
if (pCurrentWeapon)
{
if (!pCurrentWeapon->AllowsAutoSwitchFrom() || !pCurrentWeapon->CanHolster())
{
// Either this weapon doesn't allow autoswitching away from it or I
// can't put this weapon away right now, so I can't switch.
return NULL;
}

iCurrentWeight = pCurrentWeapon->GetWeight();
}

for (int i = 0; i < pPlayer->WeaponCount(); ++i)
{
pCheck = pPlayer->GetWeapon(i);
if (!pCheck)
continue;

// If we have an active weapon and this weapon doesn't allow autoswitching away
// from another weapon, skip it.
if (pCurrentWeapon && !pCheck->AllowsAutoSwitchTo())
continue;

if (pCheck->GetWeight() > -1 && pCheck->GetWeight() == iCurrentWeight && pCheck != pCurrentWeapon)
{
// this weapon is from the same category.
if (pCheck->HasAnyAmmo())
{
if (pPlayer->Weapon_CanSwitchTo(pCheck))
{
return pCheck;
}
}
}
else if (pCheck->GetWeight() > iBestWeight && pCheck != pCurrentWeapon)// don't reselect the weapon we're trying to get rid of
{
//Msg( "Considering %s\n", STRING( pCheck->GetClassname() );
// we keep updating the 'best' weapon just in case we can't find a weapon of the same weight
// that the player was using. This will end up leaving the player with his heaviest-weighted
// weapon.
if (pCheck->HasAnyAmmo())
{
// if this weapon is useable, flag it as the best
iBestWeight = pCheck->GetWeight();
pBest = pCheck;
}
}
}

// if we make it here, we've checked all the weapons and found no useable
// weapon in the same catagory as the current weapon.

// if pBest is null, we didn't find ANYTHING. Shouldn't be possible- should always
// at least get the crowbar, but ya never know.
return pBest;
}

bool CGameRules::ShouldCollide( int collisionGroup0, int collisionGroup1 )
Expand Down