//----------------------------------------------------------------------------- // Purpose: Called on each respawn //----------------------------------------------------------------------------- void CPlayerClass::RespawnClass( void ) { ResupplyAmmo( 100.0f, RESUPPLY_ALL_FROM_STATION ); GainedNewTechnology( NULL ); SetMaxHealth( GetMaxHealthCVarValue() ); SetMaxSpeed( GetMaxSpeed() ); CheckDeterioratingObjects(); SetupSizeData(); // Refill the clips of all my weapons for (int i = 0; i < MAX_WEAPONS; i++) { CBaseCombatWeapon *pWeapon = m_pPlayer->GetWeapon(i); if ( pWeapon ) { if ( pWeapon->UsesClipsForAmmo1() ) { pWeapon->m_iClip1 = pWeapon->GetDefaultClip1(); } if ( pWeapon->UsesClipsForAmmo2() ) { pWeapon->m_iClip2 = pWeapon->GetDefaultClip2(); } } } }
bool Dota_Resupply::ReSupplyPlayer( CHL2MP_Player * pPlayer ) { CBaseCombatWeapon * weapon; int weaponLevel; int iAmmoIndex; bool gotSomething = false; for ( int i = 1; i < MAX_AMMO_TYPES; i++ ) { Item_t * item = GetItemDef()->GetItemOfIndex(i); if ( item && item->pWeaponNeeded == NULL ) { weapon = pPlayer->Weapon_OwnsThisType( item->pName ); weaponLevel = pPlayer->GetWeaponLevel( item->pName ); if ( weapon && weaponLevel > 0 ) { iAmmoIndex = weapon->GetPrimaryAmmoType(); if ( iAmmoIndex < 0 || iAmmoIndex >= MAX_AMMO_SLOTS ) continue; int iMax = (GetAmmoDef()->MaxCarry(iAmmoIndex) / 4) * weaponLevel; if ( weapon->UsesClipsForAmmo1() ) { int missingFromClip1 = weapon->GetMaxClip1() - weapon->Clip1(); iMax += missingFromClip1; } int iAdd = iMax - pPlayer->GetAmmoCount(iAmmoIndex); if ( iAdd >= 1 ) gotSomething |= (pPlayer->GiveAmmo( iAdd, weapon->GetPrimaryAmmoType() ) != 0); } } } return gotSomething; }
//----------------------------------------------------------------------------- // Purpose: Find the next best weapon to use and return it. //----------------------------------------------------------------------------- CBaseCombatWeapon *CSingleplayRules::GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon ) { if ( pCurrentWeapon && !pCurrentWeapon->AllowsAutoSwitchFrom() ) return NULL; CBaseCombatWeapon *pBestWeapon = NULL; CBaseCombatWeapon *pWeapon; int nBestWeight = -1; //Search for the best weapon to use next based on its weight for ( int i = 0; i < pPlayer->WeaponCount(); i++ ) { pWeapon = pPlayer->GetWeapon(i); if ( pWeapon == NULL ) continue; // If we have an active weapon and this weapon doesn't allow autoswitching away // from another weapon, skip it. if ( pCurrentWeapon && !pWeapon->AllowsAutoSwitchTo() ) continue; // Must be eligible for switching to. if (!pPlayer->Weapon_CanSwitchTo(pWeapon)) continue; // Must be of higher quality. if ( pWeapon->GetWeight() <= nBestWeight ) continue; // We must have primary ammo if ( pWeapon->UsesClipsForAmmo1() && pWeapon->Clip1() <= 0 && !pPlayer->GetAmmoCount( pWeapon->GetPrimaryAmmoType() ) ) continue; // This is a better candidate than what we had. nBestWeight = pWeapon->GetWeight(); pBestWeapon = pWeapon; } return pBestWeapon; }