CvTacticalAI::ScoreGreatGeneralPlot(UnitHandle, CvPlot *, CvArmyAI *)
- Defined in
- CvTacticalAI.cpp, line 11355
- Class
- CvTacticalAI
- Hook name
CivHooks::CvTacticalAI_ScoreGreatGeneralPlot
Hooks
static bool BeforeCvTacticalAI_ScoreGreatGeneralPlot(CvTacticalAI* self, UnitHandle pGeneral, CvPlot* pTarget, CvArmyAI* pArmyAI, int& result);static void AfterCvTacticalAI_ScoreGreatGeneralPlot(CvTacticalAI* self, UnitHandle pGeneral, CvPlot* pTarget, CvArmyAI* pArmyAI, int& result);static int ReplaceCvTacticalAI_ScoreGreatGeneralPlot(int (*original)(CvTacticalAI*, UnitHandle, CvPlot*, CvArmyAI*), CvTacticalAI* self, UnitHandle pGeneral, CvPlot* pTarget, CvArmyAI* pArmyAI);CivRegisterBefore<CivHooks::CvTacticalAI_ScoreGreatGeneralPlot>(host, &BeforeCvTacticalAI_ScoreGreatGeneralPlot);CivRegisterAfter<CivHooks::CvTacticalAI_ScoreGreatGeneralPlot>(host, &AfterCvTacticalAI_ScoreGreatGeneralPlot);CivRegisterReplace<CivHooks::CvTacticalAI_ScoreGreatGeneralPlot>(host, &ReplaceCvTacticalAI_ScoreGreatGeneralPlot);
Code
11354/// Support function to pick best hex for a great general to move to11355int CvTacticalAI::ScoreGreatGeneralPlot(UnitHandle pGeneral, CvPlot* pTarget, CvArmyAI* pArmyAI)11356{11357 // Returned value11358 int iScore = 0;1135911360 UnitHandle pBestDefender;11361 PlayerTypes ePlayer = m_pPlayer->GetID();1136211363 // Variables going into score11364 bool bFriendlyCity = false;11365 int iNearbyQueuedAttacks = 0;11366 int iDangerValue = 0;11367 int iDangerDivisor = 1;11368 int iDistToOperationCenter = MAX_INT;11369 int iFriendlyUnitBasePower = 0;11370 int iFriendlyUnitFinalPower = 0;11371 int iFriendlyCityStrength = 0;1137211373 // GATHER DATA1137411375 // Non-friendly city here?11376 if(pTarget->isCity() && pTarget->getOwner() != ePlayer)11377 {11378 return 0;11379 }1138011381 // Another player's unit here?11382 CvUnit* pUnit = pTarget->getUnitByIndex(0);11383 if(pUnit && pUnit->getOwner() != ePlayer)11384 {11385 return 0;11386 }1138711388 // Another civilian of mine that has finished its moves?11389 else if (pUnit && pUnit->GetID() != pGeneral->GetID() && !pUnit->IsCanAttack() && pUnit->hasMoved())11390 {11391 return 0;11392 }1139311394 // Danger value11395 iDangerValue = m_pPlayer->GetPlotDanger(*pTarget);11396 pBestDefender = pTarget->getBestDefender(m_pPlayer->GetID());1139711398 // Friendly city here?11399 if(pTarget->isCity())11400 {11401 bFriendlyCity = true;11402 CvCity* pCity = pTarget->getPlotCity();1140311404 iFriendlyCityStrength = pCity->getStrengthValue() * 100;11405 iFriendlyCityStrength *= (pCity->GetMaxHitPoints() - pCity->getDamage());11406 iFriendlyCityStrength /= pCity->GetMaxHitPoints();1140711408 if(iDangerValue > (iFriendlyCityStrength * 2))11409 {11410 iDangerDivisor = 5;11411 }11412 else if(iDangerValue > iFriendlyCityStrength)11413 {11414 iDangerDivisor = 3;11415 }11416 else if(iDangerValue > (iFriendlyCityStrength / 2))11417 {11418 iDangerDivisor = 2;11419 }11420 }1142111422 // Friendly unit here?11423 else if(pBestDefender && pBestDefender->GetID() != pGeneral->GetID())11424 {11425 iFriendlyUnitBasePower = pBestDefender->GetBaseCombatStrengthConsideringDamage() * 250;1142611427 if(iDangerValue > (iFriendlyUnitBasePower * 2))11428 {11429 iDangerDivisor = 5;11430 }11431 else if(iDangerValue > iFriendlyUnitBasePower)11432 {11433 iDangerDivisor = 3;11434 }11435 else if(iDangerValue > (iFriendlyUnitBasePower / 2))11436 {11437 iDangerDivisor = 2;11438 }1143911440 iFriendlyUnitFinalPower = iFriendlyUnitBasePower;1144111442 // Deemphasize if hasn't finished moves yet11443 if(IsInQueuedAttack(pBestDefender.pointer()) && !pBestDefender->isRanged())11444 {11445 // Melee unit: might take losses attacking, so reduce the desirability11446 iFriendlyUnitFinalPower /= 3;11447 }1144811449 else if(pBestDefender->getMoves() > 0)11450 {11451 // Could move anywhere, not a good place to go11452 iFriendlyUnitFinalPower /= 25;11453 }1145411455 // Emphasize member of this operation11456 if(pArmyAI && (pBestDefender->getArmyID() != -1) &&(pBestDefender->getArmyID() == pArmyAI->GetID()))11457 {11458 iFriendlyUnitFinalPower *= 5;11459 }11460 }1146111462 // No friendly city or unit11463 else11464 { 11465 iDangerDivisor = 1000;11466 }1146711468 // Distance to center of army (if still under operational AI)11469 if(pArmyAI)11470 {11471 CvPlot* pCOM = pArmyAI->GetCenterOfMass(NO_DOMAIN);11472 if(pCOM)11473 {11474 iDistToOperationCenter = plotDistance(pTarget->getX(), pTarget->getY(), pCOM->getX(), pCOM->getY());11475 }11476 }1147711478 // Near an attack we already have planned?11479 iNearbyQueuedAttacks = NearXQueuedAttacks(pTarget, 2);1148011481 // COMPUTE SCORE11482 // Entering a city11483 if(bFriendlyCity)11484 {11485 iScore = iFriendlyCityStrength;1148611487 // If part of an army moving to target, don't hide in a city11488 if(pArmyAI)11489 {11490 iScore = 1000;11491 }11492 }11493 // Stacking with a unit11494 else if(iFriendlyUnitFinalPower > 0)11495 {11496 iScore = iFriendlyUnitFinalPower;11497 }11498 // Moving to an empty tile11499 else11500 {11501 iScore = 10;11502 }1150311504 if(iNearbyQueuedAttacks > 0)11505 {11506 iScore *= (5 * iNearbyQueuedAttacks);11507 }1150811509 if(iDistToOperationCenter < 20 && (iFriendlyUnitFinalPower > 0 || bFriendlyCity || iDangerValue == 0))11510 {11511 // Anywhere near center is really good11512 if(iDistToOperationCenter <= 3)11513 {11514 iScore += 5000000;11515 }1151611517 // Sliding scale further off11518 else11519 {11520 iScore += (250000 * (20 - iDistToOperationCenter));11521 }11522 }1152311524 if(iDangerValue > 0)11525 {11526 iScore /= iDangerDivisor;11527 }1152811529 return iScore;11530}
Calls
- CvArmyAI::GetCenterOfMass(DomainTypes)
- CvArmyAI::GetID()
- CvCity::getDamage() const
- CvCity::GetMaxHitPoints() const
- CvCity::getStrengthValue(bool) const
- CvPlayer::GetID() const
- CvPlayer::GetPlotDanger(CvPlot &) const
- CvPlot::getBestDefender(PlayerTypes, PlayerTypes, const CvUnit *, bool, bool, bool, bool)
- CvPlot::getOwner() const
- CvPlot::getPlotCity() const
- CvPlot::getUnitByIndex(int) const
- CvPlot::getX() const
- CvPlot::getY() const
- CvPlot::isCity() const
- CvTacticalAI::IsInQueuedAttack(const CvUnit *)
- CvTacticalAI::NearXQueuedAttacks(const CvPlot *, const int)
- CvUnit::getArmyID() const
- CvUnit::GetBaseCombatStrengthConsideringDamage() const
- CvUnit::GetID() const
- CvUnit::getMoves() const
- CvUnit::getOwner() const
- CvUnit::hasMoved() const
- CvUnit::IsCanAttack() const
- CvUnit::isRanged() const
FObjectHandle::FObjectHandleFObjectHandle::operator boolFObjectHandle::operator->FObjectHandle::operator=FObjectHandle::pointer- plotDistance(int, int, int, int)