diff --git a/mp/game/neo/scripts/weapon_grenade.txt b/mp/game/neo/scripts/weapon_grenade.txt index c029b89d3..cfeb5c838 100644 --- a/mp/game/neo/scripts/weapon_grenade.txt +++ b/mp/game/neo/scripts/weapon_grenade.txt @@ -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 diff --git a/mp/game/neo/scripts/weapon_knife.txt b/mp/game/neo/scripts/weapon_knife.txt index 88af742de..3f1eb60f0 100644 --- a/mp/game/neo/scripts/weapon_knife.txt +++ b/mp/game/neo/scripts/weapon_knife.txt @@ -14,6 +14,8 @@ WeaponData "clip_size" "-1" "primary_ammo" "None" "secondary_ammo" "None" + "MeleeWeapon" "1" + "autoswitchto" "1" "weight" "0" "item_flags" "0" diff --git a/mp/game/neo/scripts/weapon_remotedet.txt b/mp/game/neo/scripts/weapon_remotedet.txt index 4f08789a0..f514b4e48 100644 --- a/mp/game/neo/scripts/weapon_remotedet.txt +++ b/mp/game/neo/scripts/weapon_remotedet.txt @@ -18,6 +18,7 @@ WeaponData "clip_size" "1" "primary_ammo" "AMMO_DETPACK" "secondary_ammo" "None" + "autoswitchfrom" "1" "weight" "1" "item_flags" "0" diff --git a/mp/game/neo/scripts/weapon_smokegrenade.txt b/mp/game/neo/scripts/weapon_smokegrenade.txt index 4e58f51ad..b558655cd 100644 --- a/mp/game/neo/scripts/weapon_smokegrenade.txt +++ b/mp/game/neo/scripts/weapon_smokegrenade.txt @@ -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 diff --git a/mp/src/game/shared/basecombatcharacter_shared.cpp b/mp/src/game/shared/basecombatcharacter_shared.cpp index 9ca08da16..13e83f547 100644 --- a/mp/src/game/shared/basecombatcharacter_shared.cpp +++ b/mp/src/game/shared/basecombatcharacter_shared.cpp @@ -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 ); } diff --git a/mp/src/game/shared/gamerules.cpp b/mp/src/game/shared/gamerules.cpp index 81fa7bfa1..acf8df991 100644 --- a/mp/src/game/shared/gamerules.cpp +++ b/mp/src/game/shared/gamerules.cpp @@ -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 )