本文整理汇总了C++中CvUnit::IsDead方法的典型用法代码示例。如果您正苦于以下问题:C++ CvUnit::IsDead方法的具体用法?C++ CvUnit::IsDead怎么用?C++ CvUnit::IsDead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvUnit
的用法示例。
在下文中一共展示了CvUnit::IsDead方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsUnderImmediateThreat
// Can this tile be attacked by an enemy unit or city next turn?
bool CvDangerPlotContents::IsUnderImmediateThreat(const CvUnit* pUnit)
{
if (!m_pPlot || !pUnit)
return false;
// Air units operate off of intercepts instead of units/cities that can attack them
if (pUnit->getDomainType() == DOMAIN_AIR)
{
if (pUnit->GetBestInterceptor(*m_pPlot))
{
return true;
}
}
else
{
// Cities in range
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())
{
return true;
}
}
// Units in range
for (DangerUnitVector::iterator it = m_apUnits.begin(); it < m_apUnits.end(); ++it)
{
CvUnit* pUnit = GET_PLAYER(it->first).getUnit(it->second);
if (pUnit && !pUnit->isDelayedDeath() && !pUnit->IsDead())
{
return true;
}
}
// Citadel etc in range
if (GetDamageFromFeatures(pUnit->getOwner()) > 0)
{
return true;
}
}
// Terrain damage is greater than heal rate
int iMinimumDamage = m_bFlatPlotDamage ? m_pPlot->getTurnDamage(pUnit->ignoreTerrainDamage(), pUnit->ignoreFeatureDamage(), pUnit->extraTerrainDamage(), pUnit->extraFeatureDamage()) : 0;
if (pUnit->canHeal(m_pPlot))
{
iMinimumDamage -= pUnit->healRate(m_pPlot);
}
return (iMinimumDamage > 0);
}
示例2: 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);
//.........这里部分代码省略.........
示例3: GetAirUnitDamage
int CvDangerPlotContents::GetAirUnitDamage(const CvUnit* pUnit, AirActionType iAirAction)
{
if (pUnit->getDomainType() != DOMAIN_AIR)
return 0;
if (iAirAction == AIR_ACTION_INTERCEPT) // Max damage from a potential air sweep against our intercept
{
int iBestAirSweepDamage = 0;
int iCurrentAirSweepDamage = 0;
for (DangerUnitVector::iterator it = m_apUnits.begin(); it < m_apUnits.end(); ++it)
{
CvUnit* pAttacker = GET_PLAYER(it->first).getUnit(it->second);
if (!pAttacker || !pAttacker->canAirSweep() || pAttacker->isDelayedDeath() || pAttacker->IsDead())
{
continue;
}
int iAttackerStrength = pAttacker->GetMaxRangedCombatStrength(pUnit, /*pCity*/ NULL, true, false);
iAttackerStrength *= (100 + pAttacker->GetAirSweepCombatModifier());
iAttackerStrength /= 100;
int iDefenderStrength = pUnit->GetMaxRangedCombatStrength(pUnit, /*pCity*/ NULL, false, false);
iCurrentAirSweepDamage = pUnit->getCombatDamage(iDefenderStrength, iAttackerStrength,
pUnit->getDamage(), /*bIncludeRand*/ false, /*bAttackerIsCity*/ false, /*bDefenderIsCity*/ false);
// It's a slower to have this in the unit loop instead of after the best damage has been calculated, but it's also more accurate
if (iCurrentAirSweepDamage >= pAttacker->GetCurrHitPoints())
{
int iReceiverDamage = pAttacker->getCombatDamage(iAttackerStrength, iDefenderStrength,
pAttacker->getDamage(), /*bIncludeRand*/ false, /*bAttackerIsCity*/ false, /*bDefenderIsCity*/ false);
if (iReceiverDamage >= pUnit->GetCurrHitPoints())
{
if (iReceiverDamage + pUnit->getDamage() > iCurrentAirSweepDamage + pAttacker->getDamage())
{
iCurrentAirSweepDamage = pUnit->GetCurrHitPoints() - 1;
}
}
}
if (iCurrentAirSweepDamage > iBestAirSweepDamage)
{
iBestAirSweepDamage = iCurrentAirSweepDamage;
}
}
return iBestAirSweepDamage;
}
else
{
CvUnit* pInterceptor = pUnit->GetBestInterceptor(*m_pPlot);
if (pInterceptor)
{
// Air sweeps take modified damage from interceptors
if (iAirAction == AIR_ACTION_SWEEP)
{
if (pInterceptor->getDomainType() != DOMAIN_AIR)
{
return (pInterceptor->GetInterceptionDamage(pUnit, false) * (100+GC.getAIR_SWEEP_INTERCEPTION_DAMAGE_MOD()))/100;
}
else
{
int iAttackerStrength = pUnit->GetMaxRangedCombatStrength(pInterceptor, /*pCity*/ NULL, true, false);
iAttackerStrength *= (100 + pUnit->GetAirSweepCombatModifier());
iAttackerStrength /= 100;
int iDefenderStrength = pInterceptor->GetMaxRangedCombatStrength(pUnit, /*pCity*/ NULL, false, false);
int iReceiveDamage = pInterceptor->getCombatDamage(iDefenderStrength, iAttackerStrength,
pInterceptor->getDamage(), /*bIncludeRand*/ false, /*bAttackerIsCity*/ false, /*bDefenderIsCity*/ false);
if (iReceiveDamage >= pUnit->GetCurrHitPoints())
{
int iDamageDealt = pUnit->getCombatDamage(iAttackerStrength, iDefenderStrength,
pUnit->getDamage(), /*bIncludeRand*/ false, /*bAttackerIsCity*/ false, /*bDefenderIsCity*/ false);
if (iDamageDealt >= pInterceptor->GetCurrHitPoints())
{
if (iDamageDealt + pInterceptor->getDamage() > iReceiveDamage + pUnit->getDamage())
{
iReceiveDamage = pUnit->GetCurrHitPoints() - 1;
}
}
}
return iReceiveDamage;
}
}
else
{
// Always assume interception is successful
return pInterceptor->GetInterceptionDamage(pUnit, false);
}
}
}
return 0;
}