本文整理汇总了C++中CvUnit::IsCanAttack方法的典型用法代码示例。如果您正苦于以下问题:C++ CvUnit::IsCanAttack方法的具体用法?C++ CvUnit::IsCanAttack怎么用?C++ CvUnit::IsCanAttack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvUnit
的用法示例。
在下文中一共展示了CvUnit::IsCanAttack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildEnemyUnitList
// Find all our enemies (combat units)
void CvTacticalAnalysisMap::BuildEnemyUnitList()
{
m_EnemyUnits.clear();
m_EnemyCities.clear();
TeamTypes ourTeam = GET_PLAYER(m_ePlayer).getTeam();
for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
{
const PlayerTypes ePlayer = (PlayerTypes)iPlayer;
CvPlayer& kPlayer = GET_PLAYER(ePlayer);
const TeamTypes eTeam = kPlayer.getTeam();
// for each opposing civ
if(kPlayer.isAlive() && GET_TEAM(eTeam).isAtWar(ourTeam))
{
int iLoop;
CvUnit* pLoopUnit = NULL;
CvCity* pLoopCity;
for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))
if (pLoopCity->plot()->isRevealed(ourTeam))
m_EnemyCities.push_back(pLoopCity->GetIDInfo());
for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))
if(pLoopUnit->IsCanAttack() && pLoopUnit->plot()->isVisible(ourTeam))
m_EnemyUnits.push_back(pLoopUnit->GetIDInfo());
}
}
}
示例2: BuildEnemyUnitList
// Find all our enemies (combat units)
void CvTacticalAnalysisMap::BuildEnemyUnitList()
{
CvTacticalAnalysisEnemy enemy;
m_EnemyUnits.clear();
for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
{
const PlayerTypes ePlayer = (PlayerTypes)iPlayer;
CvPlayer& kPlayer = GET_PLAYER(ePlayer);
const TeamTypes eTeam = kPlayer.getTeam();
// for each opposing civ
if(kPlayer.isAlive() && GET_TEAM(eTeam).isAtWar(m_pPlayer->getTeam()))
{
int iLoop;
CvUnit* pLoopUnit = NULL;
for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))
{
// Make sure this unit can attack
if(pLoopUnit->IsCanAttack())
{
m_EnemyUnits.push_back(pLoopUnit);
}
}
}
}
}
示例3: GetDanger
// Get the maximum damage unit could receive at this plot in the next turn (update this with CvUnitCombat changes!)
int CvDangerPlotContents::GetDanger(const CvUnit* pUnit, AirActionType iAirAction)
{
if (!m_pPlot || !pUnit)
return 0;
// Air units only take damage from interceptions
if (pUnit->getDomainType() == DOMAIN_AIR)
return GetAirUnitDamage(pUnit, iAirAction);
//simple caching for speedup
SUnitStats unitStats(pUnit);
if (unitStats==m_lastUnit)
return m_lastResult;
//otherwise calculate from scratch
int iPlotDamage = 0;
CvCity* pFriendlyCity = NULL;
if ( m_pPlot->isFriendlyCity(*pUnit,true) )
pFriendlyCity = m_pPlot->getPlotCity();
// Civilians can be captured - unless they would need to be embarked on this plot
if (!pUnit->IsCombatUnit() && pUnit->isNativeDomain(m_pPlot))
{
// If plot contains an enemy unit, mark it as max danger
if (m_pPlot->getBestDefender(NO_PLAYER, pUnit->getOwner(), NULL, true))
{
return MAX_INT;
}
for (DangerUnitVector::iterator it = m_apUnits.begin(); it < m_apUnits.end(); ++it)
{
CvUnit* pAttacker = GET_PLAYER(it->first).getUnit(it->second);
if ( pAttacker && !pAttacker->isDelayedDeath() && !pAttacker->IsDead())
{
// If in a city and the city can be captured, we are in highest danger
if (pFriendlyCity)
{
if (GetDanger(pFriendlyCity) + pFriendlyCity->getDamage() > pFriendlyCity->GetMaxHitPoints())
{
return MAX_INT;
}
}
// Look for a possible plot defender
else
{
IDInfo* pUnitNode = m_pPlot->headUnitNode();
CvUnit* pBestDefender = NULL;
while (pUnitNode != NULL)
{
pBestDefender = ::getUnit(*pUnitNode);
pUnitNode = m_pPlot->nextUnitNode(pUnitNode);
if (pBestDefender && pBestDefender->getOwner() == pUnit->getOwner())
{
//fix endless recursion with stacked embarked civilians: defender must also be able to attack
if (pBestDefender->IsCanDefend() && pBestDefender->IsCanAttack())
{
if (pBestDefender != pUnit)
{
if (pBestDefender->isWaiting() || !(pBestDefender->canMove()))
{
break;
}
}
}
}
pBestDefender = NULL;
}
// If there is a defender and it might be killed, high danger
if (pBestDefender && (pBestDefender->isWaiting() || !pBestDefender->canMove()))
{
if (GetDanger(pBestDefender) > pBestDefender->GetCurrHitPoints())
{
return INT_MAX;
}
}
else if (pBestDefender==NULL)
{
//Civilian could be captured on this tile
return MAX_INT;
}
}
}
}
// Damage from features (citadel)
iPlotDamage += GetDamageFromFeatures(pUnit->getOwner());
iPlotDamage += m_bFlatPlotDamage ? m_pPlot->getTurnDamage(pUnit->ignoreTerrainDamage(), pUnit->ignoreFeatureDamage(), pUnit->extraTerrainDamage(), pUnit->extraFeatureDamage()) : 0;
// Damage from cities
for (DangerCityVector::iterator it = m_apCities.begin(); it < m_apCities.end(); ++it)
{
CvCity* pCity = GET_PLAYER(it->first).getCity(it->second);
if (!pCity || pCity->getTeam() == pUnit->getTeam())
continue;
iPlotDamage += pCity->rangeCombatDamage(pUnit, NULL, false, m_pPlot);
//.........这里部分代码省略.........