Bazaar developer reference

CvTacticalAI::ScoreDeploymentPlots(CvPlot *, CvArmyAI *, int, int, int)

Defined in
CvTacticalAI.cpp, line 5359
Class
CvTacticalAI
Hook name
CivHooks::CvTacticalAI_ScoreDeploymentPlots

Hooks

static bool BeforeCvTacticalAI_ScoreDeploymentPlots(CvTacticalAI* self, CvPlot* pTarget, CvArmyAI* pArmy, int iNumMeleeUnits, int iNumRangedUnits, int iRange, bool& result);static void AfterCvTacticalAI_ScoreDeploymentPlots(CvTacticalAI* self, CvPlot* pTarget, CvArmyAI* pArmy, int iNumMeleeUnits, int iNumRangedUnits, int iRange, bool& result);static bool ReplaceCvTacticalAI_ScoreDeploymentPlots(bool (*original)(CvTacticalAI*, CvPlot*, CvArmyAI*, int, int, int), CvTacticalAI* self, CvPlot* pTarget, CvArmyAI* pArmy, int iNumMeleeUnits, int iNumRangedUnits, int iRange);CivRegisterBefore<CivHooks::CvTacticalAI_ScoreDeploymentPlots>(host, &BeforeCvTacticalAI_ScoreDeploymentPlots);CivRegisterAfter<CivHooks::CvTacticalAI_ScoreDeploymentPlots>(host, &AfterCvTacticalAI_ScoreDeploymentPlots);CivRegisterReplace<CivHooks::CvTacticalAI_ScoreDeploymentPlots>(host, &ReplaceCvTacticalAI_ScoreDeploymentPlots);

Code

5358/// Pick best hexes for deploying our army (based on safety, terrain, and keeping a tight formation). Returns false if insufficient free plots.5359bool CvTacticalAI::ScoreDeploymentPlots(CvPlot* pTarget, CvArmyAI* pArmy, int iNumMeleeUnits, int iNumRangedUnits, int iRange)5360{5361	int iDX, iDY;5362	int iScore;5363	CvPlot* pPlot;5364	CvTacticalAnalysisCell* pCell;5365	bool bSafeForDeployment;5366	bool bForcedToUseWater;5367	int iNumSafePlotsFound = 0;5368	int iNumDeployPlotsFound = 0;5369	CvTacticalTarget target;53705371	// We'll store the hexes we've found here5372	m_TempTargets.clear();53735374	for(iDX = -(iRange); iDX <= iRange; iDX++)5375	{5376		for(iDY = -(iRange); iDY <= iRange; iDY++)5377		{5378			pPlot = plotXY(pTarget->getX(), pTarget->getY(), iDX, iDY);5379			if(pPlot != NULL)5380			{5381				bSafeForDeployment = true;5382				bForcedToUseWater = false;53835384				int iPlotDistance = plotDistance(pPlot->getX(), pPlot->getY(), pTarget->getX(), pTarget->getY());5385				if(iPlotDistance <= iRange)5386				{5387					int iPlotIndex = GC.getMap().plotNum(pPlot->getX(), pPlot->getY());5388					pCell = m_pMap->GetCell(iPlotIndex);5389					CvAIOperation* pOperation = m_pPlayer->getAIOperation(pArmy->GetOperationID());53905391					bool bValid = false;5392					if(pOperation->IsMixedLandNavalOperation() && pCell->CanUseForOperationGatheringCheckWater(true /*bWater*/))5393					{5394						bValid = true;5395					}53965397					else if(pOperation->IsAllNavalOperation() && pCell->CanUseForOperationGatheringCheckWater(true /*bWater*/))5398					{5399						bValid = true;5400					}54015402					else if((!pOperation->IsAllNavalOperation() && !pOperation->IsMixedLandNavalOperation()) && (pCell->CanUseForOperationGatheringCheckWater(false /*bWater*/) || GC.getMap().GetAIMapHint() & 1))5403					{5404						bValid = true;5405						if (pCell->IsWater())5406						{5407							bForcedToUseWater = true;5408						}5409					}54105411					if(pOperation->IsMixedLandNavalOperation() || pOperation->IsAllNavalOperation())5412					{5413						if(!pArmy->IsAllOceanGoing() && pCell->IsOcean())5414						{5415							bValid = false;5416						}5417					}54185419					if(bValid)5420					{5421						// Skip this plot if friendly unit that isn't in this army5422						CvUnit* pFriendlyUnit;5423						pFriendlyUnit = pCell->GetFriendlyMilitaryUnit();5424						if(pFriendlyUnit != NULL)5425						{5426							if(pFriendlyUnit->getArmyID() != pArmy->GetID())5427							{5428								continue;5429							}5430						}54315432						iNumDeployPlotsFound++;5433						iScore = 600 - (iPlotDistance * 100);5434						if(pCell->IsSubjectToAttack())5435						{5436							iScore -= 100;5437							bSafeForDeployment = false;5438						}5439						else5440						{5441							iNumSafePlotsFound++;5442						}5443						if(pCell->IsEnemyCanMovePast())5444						{5445							iScore -= 100;5446						}5447						if(pPlot->isCity() && pPlot->getOwner() == m_pPlayer->GetID())5448						{5449							iScore += 100;5450						}5451						else5452						{5453							iScore += pCell->GetDefenseModifier() * 2;5454						}5455						if (bForcedToUseWater)5456						{5457							iScore = 10;5458						}54595460						pCell->SetSafeForDeployment(bSafeForDeployment);5461						pCell->SetDeploymentScore(iScore);54625463						// Save this in our list of potential targets5464						target.SetTargetX(pPlot->getX());5465						target.SetTargetY(pPlot->getY());5466						target.SetAuxIntData(iScore);54675468						// A bit of a hack -- use high priority targets to indicate safe plots for ranged units5469						if(bSafeForDeployment)5470						{5471							target.SetTargetType(AI_TACTICAL_TARGET_HIGH_PRIORITY_UNIT);5472						}5473						else5474						{5475							target.SetTargetType(AI_TACTICAL_TARGET_LOW_PRIORITY_UNIT);5476						}54775478						m_TempTargets.push_back(target);5479					}5480				}5481			}5482		}5483	}54845485	// Make sure we found enough5486	if(iNumSafePlotsFound < iNumRangedUnits || iNumDeployPlotsFound < (iNumMeleeUnits + iNumRangedUnits))5487	{5488		return false;5489	}54905491	return true;5492}

Calls

Called by