本文整理汇总了C++中CBaseCombatWeapon::AllowsAutoSwitchTo方法的典型用法代码示例。如果您正苦于以下问题:C++ CBaseCombatWeapon::AllowsAutoSwitchTo方法的具体用法?C++ CBaseCombatWeapon::AllowsAutoSwitchTo怎么用?C++ CBaseCombatWeapon::AllowsAutoSwitchTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBaseCombatWeapon
的用法示例。
在下文中一共展示了CBaseCombatWeapon::AllowsAutoSwitchTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//-----------------------------------------------------------------------------
// 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;
}
示例2: if
//-----------------------------------------------------------------------------
// Purpose: Returns the weapon in the player's inventory that would be better than
// the given weapon.
//-----------------------------------------------------------------------------
CBaseCombatWeapon *CMultiplayRules::GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon )
{
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;
}