本文整理汇总了C++中CvPlot::getBestDefender方法的典型用法代码示例。如果您正苦于以下问题:C++ CvPlot::getBestDefender方法的具体用法?C++ CvPlot::getBestDefender怎么用?C++ CvPlot::getBestDefender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvPlot
的用法示例。
在下文中一共展示了CvPlot::getBestDefender方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DetectNearbyEnemy
CvPlot* CvArmyAI::DetectNearbyEnemy(PlayerTypes eEnemy, bool bNaval)
{
UnitHandle pUnit = GetFirstUnit();
while(pUnit)
{
for(int iDirectionLoop = 0; iDirectionLoop < NUM_DIRECTION_TYPES; ++iDirectionLoop)
{
CvPlot* pAdjacentPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iDirectionLoop));
if(pAdjacentPlot != NULL && pAdjacentPlot->isWater()==bNaval && pAdjacentPlot->getOwner() == eEnemy)
{
UnitHandle pOtherUnit = pAdjacentPlot->getBestDefender(eEnemy);
if(pOtherUnit)
{
if(GC.getLogging() && GC.getAILogging())
{
CvString strMsg;
strMsg.Format("Ran into enemy unit during attack (x=%d y=%d). Need to declare war to continue!", pAdjacentPlot->getX(), pAdjacentPlot->getY());
GET_PLAYER(m_eOwner).getAIOperation(m_iOperationID)->LogOperationSpecialMessage(strMsg);
}
return pAdjacentPlot;
}
}
}
pUnit = GetNextUnit();
}
return NULL;
}
示例2: UpdateDanger
//.........这里部分代码省略.........
for(int iDY = -(iRange); iDY <= iRange; iDY++)
{
pLoopPlot = plotXYWithRangeCheck(pCityPlot->getX(), pCityPlot->getY(), iDX, iDY, iRange);
if(!pLoopPlot || pLoopPlot == pCityPlot)
continue;
#if defined(MOD_EVENTS_CITY_BOMBARD)
if (!bIndirectFireAllowed && !pCityPlot->canSeePlot(pLoopPlot, NO_TEAM, iRange, NO_DIRECTION))
continue;
#endif
AssignCityDangerValue(pLoopCity, pLoopPlot);
}
}
}
}
// now compare the new known units with the previous known units
for (UnitSet::iterator it = previousKnownUnits.begin(); it != previousKnownUnits.end(); ++it)
{
//might have made peace ...
if (ShouldIgnorePlayer(it->first))
continue;
if (m_knownUnits.find(*it) == m_knownUnits.end())
{
CvUnit* pVanishedUnit = GET_PLAYER(it->first).getUnit(it->second);
//it's still there, but moved out of sight - nevertheless count is, a human would do that as well
//do not add it to the known units though, so next turn we will have forgotten about it
if (pVanishedUnit)
UpdateDangerSingleUnit(pVanishedUnit, true, false);
}
}
int iPlotLoop;
CvPlot* pPlot, *pAdjacentPlot;
for(iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)
{
pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);
if(pPlot->isRevealed(thisTeam))
{
//remember the plot based damage, but it depends on the unit's promotions also, so we won't apply it directly
int iPlotDamage = 0;
if (pPlot->getFeatureType() != NO_FEATURE)
iPlotDamage += (GC.getFeatureInfo(pPlot->getFeatureType())->getTurnDamage());
if (pPlot->getTerrainType() != NO_FEATURE)
iPlotDamage += (GC.getTerrainInfo(pPlot->getTerrainType())->getTurnDamage());
m_DangerPlots[iPlotLoop].m_bFlatPlotDamage = (iPlotDamage>0);
ImprovementTypes eImprovement = pPlot->getRevealedImprovementType(thisTeam);
if(eImprovement != NO_IMPROVEMENT && GC.getImprovementInfo(eImprovement)->GetNearbyEnemyDamage() > 0)
{
if(!ShouldIgnoreCitadel(pPlot, bIgnoreVisibility))
{
for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));
if(pAdjacentPlot != NULL)
{
m_DangerPlots[iPlotLoop].m_pCitadel = pPlot;
}
}
}
}
}
}
// testing city danger values
CvCity* pLoopCity;
int iLoopCity = 0;
for(pLoopCity = thisPlayer.firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = thisPlayer.nextCity(&iLoopCity))
{
//adding danger would count each unit multiple times, is biased towards fast units
//so we pretend they would all attack the city and tally up the damage
//question is, what about our own defensive units in the area. should we count those as well?
int iEvalRange = 4;
int iThreatValue = 0;
for(int iX = -iEvalRange; iX <= iEvalRange; iX++)
for(int iY = -iEvalRange; iY <= iEvalRange; iY++)
{
CvPlot* pEvalPlot = plotXYWithRangeCheck(pLoopCity->getX(), pLoopCity->getY(), iX, iY, iEvalRange);
if (pEvalPlot)
{
const CvUnit* pEnemy = pEvalPlot->getBestDefender(NO_PLAYER, thisPlayer.GetID(), NULL, true);
if (pEnemy)
{
int iAttackerDamage = 0; //to be ignored
iThreatValue += TacticalAIHelpers::GetSimulatedDamageFromAttackOnCity(pLoopCity,pEnemy,iAttackerDamage);
}
}
}
pLoopCity->SetThreatValue(iThreatValue);
}
m_bDirty = false;
}