Hooks
static bool BeforeCvDiplomacyAIHelpers_ApplyWarmongerPenalties(PlayerTypes eConqueror, PlayerTypes eConquered, bool bIsCapital);static void AfterCvDiplomacyAIHelpers_ApplyWarmongerPenalties(PlayerTypes eConqueror, PlayerTypes eConquered, bool bIsCapital);static void ReplaceCvDiplomacyAIHelpers_ApplyWarmongerPenalties(void (*original)(PlayerTypes, PlayerTypes, bool), PlayerTypes eConqueror, PlayerTypes eConquered, bool bIsCapital);CivRegisterBefore<CivHooks::CvDiplomacyAIHelpers_ApplyWarmongerPenalties>(host, &BeforeCvDiplomacyAIHelpers_ApplyWarmongerPenalties);CivRegisterAfter<CivHooks::CvDiplomacyAIHelpers_ApplyWarmongerPenalties>(host, &AfterCvDiplomacyAIHelpers_ApplyWarmongerPenalties);CivRegisterReplace<CivHooks::CvDiplomacyAIHelpers_ApplyWarmongerPenalties>(host, &ReplaceCvDiplomacyAIHelpers_ApplyWarmongerPenalties);
Code
28537#if defined(MOD_CONFIG_AI_IN_XML)28538void CvDiplomacyAIHelpers::ApplyWarmongerPenalties(PlayerTypes eConqueror, PlayerTypes eConquered, bool bIsCapital)28539#else28540void CvDiplomacyAIHelpers::ApplyWarmongerPenalties(PlayerTypes eConqueror, PlayerTypes eConquered)28541#endif28542{28543 CvPlayer &kConqueringPlayer = GET_PLAYER(eConqueror);28544#if defined(MOD_CONFIG_AI_IN_XML)28545 CvPlayer &kConqueredPlayer = GET_PLAYER(eConquered);28546#endif2854728548 for(int iMajorLoop = 0; iMajorLoop < MAX_MAJOR_CIVS; iMajorLoop++)28549 {28550 PlayerTypes eMajor = (PlayerTypes)iMajorLoop;28551 if (eConqueror != eMajor && GET_PLAYER(eMajor).isAlive())28552 {28553 // Have I met the player who conquered the city?28554 CvTeam &kAffectedTeam = GET_TEAM(GET_PLAYER(eMajor).getTeam());28555#if defined(MOD_CONFIG_AI_IN_XML)28556 // ... or the owner of the conquered city?28557 if (kAffectedTeam.isHasMet(kConqueringPlayer.getTeam()) || kAffectedTeam.isHasMet(kConqueredPlayer.getTeam()))28558#else28559 if (kAffectedTeam.isHasMet(kConqueringPlayer.getTeam()))28560#endif28561 {28562#if defined(MOD_API_EXTENSIONS)28563 int iWarmongerModifier = 100;2856428565#if defined(MOD_CONFIG_AI_IN_XML)28566 if (eMajor == eConquered)28567 {28568 // The conquered city owner ALWAYS gets the full warmonger value28569 }28570 else28571 {28572 if (GC.getWARMONGER_THREAT_DEF_PACT_ENABLED() != 0 && kAffectedTeam.IsHasDefensivePact(kConqueredPlayer.getTeam()))28573 {28574 // Any DefPact allies of the conquered city owner also get the full warmonger value28575 CUSTOMLOG("Warmonger: Bystander has a Def Pact with the defender");28576 }28577 else28578 {28579 int iWarmongerCoopWarPercent = GC.getWARMONGER_THREAT_COOP_WAR_PERCENT();28580 bool bCoopWarChecks = (iWarmongerCoopWarPercent != 100);28581 bool bCoopWarWithAttacker = bCoopWarChecks && (GET_PLAYER(eMajor).GetDiplomacyAI()->GetCoopWarAcceptedState(eConqueror, eConquered) == COOP_WAR_STATE_ACCEPTED);28582 bool bCoopWarWithDefender = bCoopWarChecks && (GET_PLAYER(eMajor).GetDiplomacyAI()->GetCoopWarAcceptedState(eConquered, eConqueror) == COOP_WAR_STATE_ACCEPTED);2858328584 if (bCoopWarWithAttacker)28585 {28586 // The affected player is in a co-op war with the attacker against the defender - this trumps everything!28587 iWarmongerModifier = iWarmongerCoopWarPercent;28588 CUSTOMLOG("Warmonger: Bystander is in a co-op war with the attacker");2858928590 if (bCoopWarWithDefender)28591 {28592 CUSTOMLOG("Warmonger: Bystander is ALSO in a co-op war with the defender!!!");28593 }28594 }28595 else if (bCoopWarWithDefender)28596 {28597 // The affected player is in a co-op war with the defender against the attacker - we treat his loss as our own28598 CUSTOMLOG("Warmonger: Bystander is in a co-op war with the defender");28599 }28600 else28601 {28602 // Do we know the defender?28603 if (kAffectedTeam.isHasMet(kConqueredPlayer.getTeam()))28604 {28605 iWarmongerModifier = GC.getWARMONGER_THREAT_KNOWS_DEFENDER_PERCENT();28606 CUSTOMLOG("Warmonger: Bystander has met the attacker");28607 }2860828609 // Do we know the attacker?28610 if (kAffectedTeam.isHasMet(kConqueringPlayer.getTeam()))28611 {28612 // We may know both, so take the larger modifier28613 iWarmongerModifier = std::max(iWarmongerModifier, GC.getWARMONGER_THREAT_KNOWS_ATTACKER_PERCENT());28614 CUSTOMLOG("Warmonger: Bystander has met the defender");28615 }28616 }28617 }28618 }28619#endif2862028621 if (iWarmongerModifier == 0) continue;28622#endif2862328624#if defined(MOD_CONFIG_AI_IN_XML)28625 int iWarmongerApproachModifier = 100;2862628627 if (eMajor == eConquered || (GC.getWARMONGER_THREAT_DEF_PACT_ENABLED() != 0 && kAffectedTeam.IsHasDefensivePact(kConqueredPlayer.getTeam())))28628 {28629 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_HOSTILE();28630 }28631 else28632 {28633 // INCREASE if we don't like the attacker28634 switch (GET_PLAYER(eMajor).GetDiplomacyAI()->GetMajorCivApproach(eConqueror, false))28635 {28636 case MAJOR_CIV_APPROACH_WAR:28637 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_HOSTILE();28638 break;28639 case MAJOR_CIV_APPROACH_HOSTILE:28640 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_HOSTILE();28641 break;28642 case MAJOR_CIV_APPROACH_DECEPTIVE:28643 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_GUARDED();28644 break;28645 case MAJOR_CIV_APPROACH_GUARDED:28646 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_GUARDED();28647 break;28648 case MAJOR_CIV_APPROACH_AFRAID:28649 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_AFRAID();28650 break;28651 case MAJOR_CIV_APPROACH_NEUTRAL:28652 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_NEUTRAL();28653 break;28654 case MAJOR_CIV_APPROACH_FRIENDLY:28655 iWarmongerApproachModifier += GC.getWARMONGER_THREAT_APPROACH_PERCENT_FRIENDLY();28656 break;28657 default:28658 break;28659 }2866028661 // DECREASE if we don't like the defender28662 switch (GET_PLAYER(eMajor).GetDiplomacyAI()->GetMajorCivApproach(eConquered, false))28663 {28664 case MAJOR_CIV_APPROACH_WAR:28665 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_HOSTILE();28666 break;28667 case MAJOR_CIV_APPROACH_HOSTILE:28668 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_HOSTILE();28669 break;28670 case MAJOR_CIV_APPROACH_DECEPTIVE:28671 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_GUARDED();28672 break;28673 case MAJOR_CIV_APPROACH_GUARDED:28674 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_GUARDED();28675 break;28676 case MAJOR_CIV_APPROACH_AFRAID:28677 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_AFRAID();28678 break;28679 case MAJOR_CIV_APPROACH_NEUTRAL:28680 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_NEUTRAL();28681 break;28682 case MAJOR_CIV_APPROACH_FRIENDLY:28683 iWarmongerApproachModifier -= GC.getWARMONGER_THREAT_APPROACH_PERCENT_FRIENDLY();28684 break;28685 default:28686 break;28687 }28688 }28689#endif2869028691#if defined(MOD_CONFIG_AI_IN_XML)28692 int iWarmongerOffset = CvDiplomacyAIHelpers::GetWarmongerOffset(eConquered, bIsCapital);2869328694 int iWarmongerAggrievedModifier = 100;28695 if (GET_TEAM(kConqueringPlayer.getTeam()).isAggressor(kConqueredPlayer.getTeam()))28696 {28697 iWarmongerAggrievedModifier = GC.getWARMONGER_THREAT_AGGRIEVED_PERCENT();28698 }28699#else28700 int iNumCities = max(GET_PLAYER(eConquered).getNumCities(), 1);28701 int iWarmongerOffset = CvDiplomacyAIHelpers::GetWarmongerOffset(iNumCities, GET_PLAYER(eConquered).isMinorCiv());28702#endif2870328704 // Half penalty if I'm also at war with conquered civ28705 if (kAffectedTeam.isAtWar(GET_PLAYER(eConquered).getTeam()))28706 {28707 iWarmongerOffset /= 2;28708 }2870928710#if defined(MOD_API_EXTENSIONS)28711 CUSTOMLOG("WarmongerTimes100: Att=%i, Def=%i, 3rd=%i, Off=%i, Mod%%=%i, Agg%%=%i, App%%=%i, Total=%i", eConqueror, eConquered, eMajor, iWarmongerOffset, iWarmongerModifier, iWarmongerAggrievedModifier, iWarmongerApproachModifier, (iWarmongerOffset * iWarmongerModifier * iWarmongerAggrievedModifier * (100 + iWarmongerApproachModifier) / 10000));28712 GET_PLAYER(eMajor).GetDiplomacyAI()->ChangeOtherPlayerWarmongerAmountTimes100(eConqueror, iWarmongerOffset * iWarmongerModifier * iWarmongerAggrievedModifier * (100 + iWarmongerApproachModifier) / 10000);28713#else28714 GET_PLAYER(eMajor).GetDiplomacyAI()->ChangeOtherPlayerWarmongerAmount(eConqueror, iWarmongerOffset);28715#endif28716 }28717 }28718 }28719}