当前位置: 首页>>代码示例>>C++>>正文


C++ CTFPlayer::GetMaxAmmo方法代码示例

本文整理汇总了C++中CTFPlayer::GetMaxAmmo方法的典型用法代码示例。如果您正苦于以下问题:C++ CTFPlayer::GetMaxAmmo方法的具体用法?C++ CTFPlayer::GetMaxAmmo怎么用?C++ CTFPlayer::GetMaxAmmo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CTFPlayer的用法示例。


在下文中一共展示了CTFPlayer::GetMaxAmmo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MyTouch

//-----------------------------------------------------------------------------
// Purpose: MyTouch function for the ammopack
//-----------------------------------------------------------------------------
bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
{
	bool bSuccess = false;

	if ( ValidTouch( pPlayer ) )
	{
		CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
		if ( !pTFPlayer )
			return false;

		int iMaxPrimary = pTFPlayer->GetMaxAmmo( TF_AMMO_PRIMARY );
		if ( pPlayer->GiveAmmo( ceil( iMaxPrimary * PackRatios[GetPowerupSize()] ), TF_AMMO_PRIMARY, true ) )
		{
			bSuccess = true;
		}

		int iMaxSecondary = pTFPlayer->GetMaxAmmo( TF_AMMO_SECONDARY );
		if ( pPlayer->GiveAmmo( ceil( iMaxSecondary * PackRatios[GetPowerupSize()] ), TF_AMMO_SECONDARY, true ) )
		{
			bSuccess = true;
		}

		int iMaxMetal = pTFPlayer->GetMaxAmmo( TF_AMMO_METAL );
		if ( pPlayer->GiveAmmo( ceil( iMaxMetal * PackRatios[GetPowerupSize()] ), TF_AMMO_METAL, true ) )
		{
			bSuccess = true;
		}

		float flCloak = pTFPlayer->m_Shared.GetSpyCloakMeter();
		if ( flCloak < 100.0f )
		{
			pTFPlayer->m_Shared.SetSpyCloakMeter( min( 100.0f, flCloak + 100.0f * PackRatios[GetPowerupSize()] ) );
			bSuccess = true;
		}

		// did we give them anything?
		if ( bSuccess )
		{
			CSingleUserRecipientFilter filter( pPlayer );
			EmitSound( filter, entindex(), TF_AMMOPACK_PICKUP_SOUND );
		}
	}

	return bSuccess;
}
开发者ID:Deathreus,项目名称:TF2Classic,代码行数:48,代码来源:entity_ammopack.cpp

示例2: ReapplyProvision


//.........这里部分代码省略.........
				if (weapon == nullptr) {
					continue;
				}
				
				/* BUG: as soon as this loop hits a weapon which is completely
				 * devoid of ammo (clip 0, reserve 0), it will
				 * (a) fail to refill the clip for that weapon, and
				 * (b) fail to refill the clip for any weapons in later slots
				 * NOTE: for the purposes of this, energy weapons are treated as
				 * if their reserve ammo is always empty
				 */
				if (TFGameRules() != nullptr && TFGameRules()->IsMannVsMachineMode() &&
					((weapon->UsesPrimaryAmmo() && !weapon->HasPrimaryAmmo()) ||
					(weapon->UsesSecondaryAmmo() && !weapon->HasSecondaryAmmo()))) {
					player->AwardAchievement(TF_MVM_USE_AMMO_BOTTLE);
					break;
				}
				
				/* BUG: doesn't refill clip of energy weapons
				 * (should vcall weapon->IsEnergyWeapon,
				 * then call weapon->Energy_Recharge
				 * until weapon->Energy_FullyCharged) */
				
				
				// CBaseCombatWeapon::UsesPrimaryAmmo:
				// - if m_iPrimaryAmmoType < 0: return false
				// - else:                      return true
				// CBaseCombatWeapon::UsesSecondaryAmmo:
				// - if m_iSecondaryAmmoType < 0: return false
				// - else:                        return true
				
				// CTFWeaponBaseGun::HasPrimaryAmmo:
				// - there's a special case if m_iPrimaryAmmoType == TF_AMMO_METAL (e.g. Widowmaker)
				// - if UsesClipsForAmmo1(): return (m_iClip1 > 0) || (pOwner->GetAmmoCount(m_iPrimaryAmmoType) > 0)
				// - else:                   return (pOwner->GetAmmoCount(m_iPrimaryAmmoType) > 0)
				// CBaseCombatWeapon::HasSecondaryAmmo:
				// - if UsesClipsForAmmo1(): return (m_iClip2 > 0) || (pOwner->GetAmmoCount(m_iSecondaryAmmoType) > 0)
				// - else:                   return (pOwner->GetAmmoCount(m_iSecondaryAmmoType) > 0)
				
			
				weapon->GiveDefaultAmmo();
				
				if (share_with != nullptr && share_attr != 0) {
					CBaseCombatWeapon *share_weapon = share_with->GetWeapon(i);
					if (share_weapon != nullptr) {
						share_weapon->GiveDefaultAmmo();
						did_share = true;
					}
				}
			}
			
			/* NOTE: invented TF_AMMO_SOURCE_RESUPPLY for (EAmmoSource)1 */
			if (share_with != nullptr && share_attr != 0) {
				for (int i = 0; i < TF_AMMO_COUNT; ++i) {
					player->GiveAmmo(player->GetMaxAmmo(i), i, true,
						TF_AMMO_SOURCE_RESUPPLY);
					share_with->GiveAmmo(share_with->GetMaxAmmo(i), i, true,
						TF_AMMO_SOURCE_RESUPPLY);
				}
				did_share = true;
			} else {
				for (int i = 0; i < TF_AMMO_COUNT; ++i) {
					player->GiveAmmo(player->GetMaxAmmo(i), i, true,
						TF_AMMO_SOURCE_RESUPPLY);
				}
			}
		}
	}
	
	if (CAttributeManager::AttribHookValue<int>(0, "building_instant_upgrade",
		this, nullptr, true) != 0) {
		if (this->m_bActive) {
			int obj_count = player->GetObjectCount();
			if (obj_count > 0) {
				for (int i = obj_count - 1; i != -1; --i) {
					CBaseObject *obj = player->GetObject(i);
					if (obj != nullptr) {
						int max_level = obj->GetMaxUpgradeLevel();
						
						if (obj->m_bCarried) {
							/* BUG: this can't possibly be right */
							obj->m_iHighestUpgradeLevel = obj->GetMaxUpgradeLevel();
						} else if (obj->GetUpgradeLevel() == max_level) {
							obj->SetHealth(obj->GetMaxHealth());
						} else {
							if (TFGameRules() && TFGameRules()->IsMannVsMachineMode()) {
								// TODO: event mvm_quick_sentry_upgrade
							}
							obj->DoQuickBuild(true);
						}
					}
				}
			}
		}
	}
	
	if (did_share) {
		// TODO: event mvm_medic_powerup_shared
	}
}
开发者ID:Msalinas2877,项目名称:mvm-reversed,代码行数:101,代码来源:tf_item_powerup_bottle.cpp


注:本文中的CTFPlayer::GetMaxAmmo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。