Hooks
static bool BeforeCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture(CvDiplomacyAI* self, PlayerTypes ePlayer);static void AfterCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture(CvDiplomacyAI* self, PlayerTypes ePlayer);static void ReplaceCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture(void (*original)(CvDiplomacyAI*, PlayerTypes), CvDiplomacyAI* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture>(host, &BeforeCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture>(host, &AfterCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture>(host, &ReplaceCvDiplomacyAI_DoUpdateOnePlayerExpansionAggressivePosture);
Code
8446/// Updates how aggressively this player's Units are positioned in relation to us8447void CvDiplomacyAI::DoUpdateOnePlayerExpansionAggressivePosture(PlayerTypes ePlayer)8448{8449 CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");8450 CvAssertMsg(ePlayer < MAX_CIV_PLAYERS, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");84518452 if(GetPlayer()->getCapitalCity() == NULL)8453 return;84548455 if(!IsPlayerValid(ePlayer))8456 return;84578458 // Irrelevant if we can't declare war on these guys8459 CvTeam &kMyTeam = GET_TEAM(GetPlayer()->getTeam());8460#if defined(MOD_EVENTS_WAR_AND_PEACE)8461 if (!kMyTeam.isAtWar(GET_PLAYER(ePlayer).getTeam()) && !kMyTeam.canDeclareWar(GET_PLAYER(ePlayer).getTeam(), GetPlayer()->GetID()))8462#else8463 if (!kMyTeam.isAtWar(GET_PLAYER(ePlayer).getTeam()) && !kMyTeam.canDeclareWar(GET_PLAYER(ePlayer).getTeam()))8464#endif8465 {8466 return;8467 }84688469 int iMyCapitalX = GetPlayer()->getCapitalCity()->getX();8470 int iMyCapitalY = GetPlayer()->getCapitalCity()->getY();84718472 AggressivePostureTypes eAggressivePosture;84738474 CvCity* pLoopCity;8475 int iCityLoop;84768477 AggressivePostureTypes eMostAggressiveCityPosture;8478 int iNumMostAggressiveCities;84798480 int iDistanceUsToThem, iDistanceThemToTheirCapital, iDistanceCapitals;8481 int iTheirCapitalX, iTheirCapitalY;8482 int iCityX, iCityY;84838484 // If they have no capital then, uh... just stop I guess8485 if(GET_PLAYER(ePlayer).getCapitalCity() == NULL)8486 return;84878488 iTheirCapitalX = GET_PLAYER(ePlayer).getCapitalCity()->getX();8489 iTheirCapitalY = GET_PLAYER(ePlayer).getCapitalCity()->getY();84908491 iDistanceCapitals = plotDistance(iTheirCapitalX, iTheirCapitalY, iMyCapitalX, iMyCapitalY);84928493 eMostAggressiveCityPosture = AGGRESSIVE_POSTURE_NONE;8494 iNumMostAggressiveCities = 0;84958496 // Loop through all of this player's Cities8497 for(pLoopCity = GET_PLAYER(ePlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(ePlayer).nextCity(&iCityLoop))8498 {8499 // Don't look at their capital8500 if(pLoopCity->isCapital())8501 continue;85028503 // Don't look at Cities they've captured8504 if(pLoopCity->getOriginalOwner() != pLoopCity->getOwner())8505 continue;85068507 eAggressivePosture = AGGRESSIVE_POSTURE_NONE;85088509 iCityX = pLoopCity->getX();8510 iCityY = pLoopCity->getY();85118512 // First calculate distances8513 iDistanceUsToThem = plotDistance(iMyCapitalX, iMyCapitalY, iCityX, iCityY);8514 iDistanceThemToTheirCapital = plotDistance(iTheirCapitalX, iTheirCapitalY, iCityX, iCityY);85158516 if(iDistanceUsToThem <= /*3*/ GC.getEXPANSION_CAPITAL_DISTANCE_AGGRESSIVE_POSTURE_HIGH())8517 eAggressivePosture = AGGRESSIVE_POSTURE_HIGH;8518 else if(iDistanceUsToThem <= /*5*/ GC.getEXPANSION_CAPITAL_DISTANCE_AGGRESSIVE_POSTURE_MEDIUM())8519 eAggressivePosture = AGGRESSIVE_POSTURE_MEDIUM;8520 else if(iDistanceUsToThem <= /*9*/ GC.getEXPANSION_CAPITAL_DISTANCE_AGGRESSIVE_POSTURE_LOW())8521 eAggressivePosture = AGGRESSIVE_POSTURE_LOW;85228523 // If this City is closer to our capital than the other player's then it's immediately at least Mediumly aggressive8524 if(eAggressivePosture == AGGRESSIVE_POSTURE_LOW)8525 {8526 if(iDistanceUsToThem < iDistanceThemToTheirCapital)8527 eAggressivePosture = AGGRESSIVE_POSTURE_MEDIUM;8528 }85298530 // If this City is further from their capital then our capitals are then it's super-aggressive8531 if(eAggressivePosture >= AGGRESSIVE_POSTURE_MEDIUM)8532 {8533 if(iDistanceCapitals < iDistanceThemToTheirCapital)8534 eAggressivePosture = AGGRESSIVE_POSTURE_INCREDIBLE;8535 }85368537 // Increase number of Cities at this Aggressiveness level8538 if(eAggressivePosture == eMostAggressiveCityPosture)8539 iNumMostAggressiveCities++;85408541 // If this City is the most aggressive one yet, replace the old record8542 else if(eAggressivePosture > eMostAggressiveCityPosture)8543 {8544 eMostAggressiveCityPosture = eAggressivePosture;8545 iNumMostAggressiveCities = 0;8546 }85478548 // If we're already at the max aggression level we don't need to look at more Cities8549 if(eMostAggressiveCityPosture == AGGRESSIVE_POSTURE_INCREDIBLE)8550 break;8551 }85528553 // If we have multiple Cities that tie for being the highest then bump us up a level8554 if(iNumMostAggressiveCities > 1)8555 {8556 // If every City is low then we don't care that much, and if we're already at the highest level we can't go higher8557 if(eMostAggressiveCityPosture > AGGRESSIVE_POSTURE_LOW && eMostAggressiveCityPosture < AGGRESSIVE_POSTURE_INCREDIBLE)8558 {8559 eMostAggressiveCityPosture = AggressivePostureTypes(eMostAggressiveCityPosture + 1);8560 }8561 }85628563 SetExpansionAggressivePosture(ePlayer, eMostAggressiveCityPosture);8564}