Hooks
static bool BeforeCvMinorCivAI_DoChangeProtectionFromMajor(CvMinorCivAI* self, PlayerTypes eMajor, bool bProtect, bool bPledgeNowBroken);static void AfterCvMinorCivAI_DoChangeProtectionFromMajor(CvMinorCivAI* self, PlayerTypes eMajor, bool bProtect, bool bPledgeNowBroken);static void ReplaceCvMinorCivAI_DoChangeProtectionFromMajor(void (*original)(CvMinorCivAI*, PlayerTypes, bool, bool), CvMinorCivAI* self, PlayerTypes eMajor, bool bProtect, bool bPledgeNowBroken);CivRegisterBefore<CivHooks::CvMinorCivAI_DoChangeProtectionFromMajor>(host, &BeforeCvMinorCivAI_DoChangeProtectionFromMajor);CivRegisterAfter<CivHooks::CvMinorCivAI_DoChangeProtectionFromMajor>(host, &AfterCvMinorCivAI_DoChangeProtectionFromMajor);CivRegisterReplace<CivHooks::CvMinorCivAI_DoChangeProtectionFromMajor>(host, &ReplaceCvMinorCivAI_DoChangeProtectionFromMajor);
Code
7363void CvMinorCivAI::DoChangeProtectionFromMajor(PlayerTypes eMajor, bool bProtect, bool bPledgeNowBroken)7364{7365 CvAssertMsg(eMajor >= 0, "eMajor is expected to be non-negative (invalid Index)");7366 CvAssertMsg(eMajor < MAX_MAJOR_CIVS, "eMajor is expected to be within maximum bounds (invalid Index)");7367 if(eMajor < 0 || eMajor >= MAX_MAJOR_CIVS) return;73687369 if(bProtect == IsProtectedByMajor(eMajor)) return;73707371 if(bProtect)7372 {7373 if(!CanMajorProtect(eMajor))7374 {7375 return;7376 }7377 SetTurnLastPledgedProtectionByMajor(eMajor, GC.getGame().getGameTurn());7378 7379#if defined(MOD_EVENTS_MINORS_INTERACTION)7380 if (MOD_EVENTS_MINORS_INTERACTION) {7381 GAMEEVENTINVOKE_HOOK(GAMEEVENT_PlayerProtected, eMajor, GetPlayer()->GetID());7382 }7383#endif7384 }7385 else7386 {7387 if(bPledgeNowBroken)7388 {7389 SetTurnLastPledgeBrokenByMajor(eMajor, GC.getGame().getGameTurn());7390 ChangeFriendshipWithMajorTimes100(eMajor, GC.getMINOR_FRIENDSHIP_DROP_DISHONOR_PLEDGE_TO_PROTECT());7391 }7392 7393#if defined(MOD_EVENTS_MINORS_INTERACTION)7394 if (MOD_EVENTS_MINORS_INTERACTION) {7395 GAMEEVENTINVOKE_HOOK(GAMEEVENT_PlayerRevoked, eMajor, GetPlayer()->GetID(), bPledgeNowBroken);7396 }7397#endif7398 }73997400 m_abPledgeToProtect[eMajor] = bProtect;74017402 // In case we had a Pledge to Protect quest active, complete it now7403 DoTestActiveQuestsForPlayer(eMajor, /*bTestComplete*/ true, /*bTestObsolete*/ false, MINOR_CIV_QUEST_PLEDGE_TO_PROTECT);74047405 GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);7406 GC.GetEngineUserInterface()->setDirty(CityInfo_DIRTY_BIT, true);7407}