Hooks
static bool BeforeCvMinorCivAI_DoFriendshipChangeEffects(CvMinorCivAI* self, PlayerTypes ePlayer, int iOldFriendship, int iNewFriendship, bool bFromQuest, bool bIgnoreMinorDeath);static void AfterCvMinorCivAI_DoFriendshipChangeEffects(CvMinorCivAI* self, PlayerTypes ePlayer, int iOldFriendship, int iNewFriendship, bool bFromQuest, bool bIgnoreMinorDeath);static void ReplaceCvMinorCivAI_DoFriendshipChangeEffects(void (*original)(CvMinorCivAI*, PlayerTypes, int, int, bool, bool), CvMinorCivAI* self, PlayerTypes ePlayer, int iOldFriendship, int iNewFriendship, bool bFromQuest, bool bIgnoreMinorDeath);CivRegisterBefore<CivHooks::CvMinorCivAI_DoFriendshipChangeEffects>(host, &BeforeCvMinorCivAI_DoFriendshipChangeEffects);CivRegisterAfter<CivHooks::CvMinorCivAI_DoFriendshipChangeEffects>(host, &AfterCvMinorCivAI_DoFriendshipChangeEffects);CivRegisterReplace<CivHooks::CvMinorCivAI_DoFriendshipChangeEffects>(host, &ReplaceCvMinorCivAI_DoFriendshipChangeEffects);
Code
6740/// What happens when Friendship changes?6741void CvMinorCivAI::DoFriendshipChangeEffects(PlayerTypes ePlayer, int iOldFriendship, int iNewFriendship, bool bFromQuest, bool bIgnoreMinorDeath)6742{6743 // Can't give out bonuses if we're dead!6744 if(!bIgnoreMinorDeath && !GetPlayer()->isAlive())6745 return;67466747 Localization::String strMessage;6748 Localization::String strSummary;67496750 bool bAdd = false;6751 bool bFriends = false;6752 bool bAllies = false;67536754 bool bWasAboveFriendsThreshold = IsFriendshipAboveFriendsThreshold(iOldFriendship);6755 bool bNowAboveFriendsThreshold = IsFriendshipAboveFriendsThreshold(iNewFriendship);67566757 // If we are Friends now, mark that we've been Friends at least once this game6758 if(bNowAboveFriendsThreshold)6759 SetEverFriends(ePlayer, true);67606761 // Add Friends Bonus6762 if(!bWasAboveFriendsThreshold && bNowAboveFriendsThreshold)6763 {6764 bAdd = true;6765 bFriends = true;67666767#if defined(MOD_EVENTS_MINORS)6768 if (MOD_EVENTS_MINORS) {6769 GAMEEVENTINVOKE_HOOK(GAMEEVENT_MinorFriendsChanged, m_pPlayer->GetID(), ePlayer, true, iOldFriendship, iNewFriendship);6770 } else {6771#endif6772 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();6773 if (pkScriptSystem) 6774 {6775 CvLuaArgsHandle args;6776 args->Push(m_pPlayer->GetID());6777 args->Push(ePlayer);6778 args->Push(true);6779 args->Push(iOldFriendship);6780 args->Push(iNewFriendship);67816782 bool bResult;6783 LuaSupport::CallHook(pkScriptSystem, "MinorFriendsChanged", args.get(), bResult);6784 }6785#if defined(MOD_EVENTS_MINORS)6786 }6787#endif6788 }6789 // Remove Friends bonus6790 else if(bWasAboveFriendsThreshold && !bNowAboveFriendsThreshold)6791 {6792 bAdd = false;6793 bFriends = true;67946795#if defined(MOD_EVENTS_MINORS)6796 if (MOD_EVENTS_MINORS) {6797 GAMEEVENTINVOKE_HOOK(GAMEEVENT_MinorFriendsChanged, m_pPlayer->GetID(), ePlayer, false, iOldFriendship, iNewFriendship);6798 } else {6799#endif6800 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();6801 if (pkScriptSystem) 6802 {6803 CvLuaArgsHandle args;6804 args->Push(m_pPlayer->GetID());6805 args->Push(ePlayer);6806 args->Push(false);6807 args->Push(iOldFriendship);6808 args->Push(iNewFriendship);68096810 bool bResult;6811 LuaSupport::CallHook(pkScriptSystem, "MinorFriendsChanged", args.get(), bResult);6812 }6813#if defined(MOD_EVENTS_MINORS)6814 }6815#endif6816 }68176818 // Resolve Allies status6819 bool bWasAboveAlliesThreshold = IsFriendshipAboveAlliesThreshold(iOldFriendship);6820 bool bNowAboveAlliesThreshold = IsFriendshipAboveAlliesThreshold(iNewFriendship);6821 PlayerTypes eOldAlly = GetAlly();68226823 // No old ally and our friendship is now above the threshold, OR our friendship is now higher than a previous ally6824 if((eOldAlly == NO_PLAYER && bNowAboveAlliesThreshold)6825 || (eOldAlly != NO_PLAYER && GetEffectiveFriendshipWithMajor(ePlayer) > GetEffectiveFriendshipWithMajor(eOldAlly)))6826 {6827 bAdd = true;6828 bAllies = true;68296830#if defined(MOD_EVENTS_MINORS)6831 if (MOD_EVENTS_MINORS) {6832 GAMEEVENTINVOKE_HOOK(GAMEEVENT_MinorAlliesChanged, m_pPlayer->GetID(), ePlayer, true, iOldFriendship, iNewFriendship);6833 } else {6834#endif6835 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();6836 if (pkScriptSystem) 6837 {6838 CvLuaArgsHandle args;6839 args->Push(m_pPlayer->GetID());6840 args->Push(ePlayer);6841 args->Push(true);6842 args->Push(iOldFriendship);6843 args->Push(iNewFriendship);68446845 bool bResult;6846 LuaSupport::CallHook(pkScriptSystem, "MinorAlliesChanged", args.get(), bResult);6847 }6848#if defined(MOD_EVENTS_MINORS)6849 }6850#endif6851 }6852 // Remove Allies bonus6853 else if(eOldAlly == ePlayer && bWasAboveAlliesThreshold && !bNowAboveAlliesThreshold)6854 {6855 bAdd = false;6856 bAllies = true;68576858#if defined(MOD_EVENTS_MINORS)6859 if (MOD_EVENTS_MINORS) {6860 GAMEEVENTINVOKE_HOOK(GAMEEVENT_MinorAlliesChanged, m_pPlayer->GetID(), ePlayer, false, iOldFriendship, iNewFriendship);6861 } else {6862#endif6863 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();6864 if (pkScriptSystem)6865 {6866 CvLuaArgsHandle args;6867 args->Push(m_pPlayer->GetID());6868 args->Push(ePlayer);6869 args->Push(false);6870 args->Push(iOldFriendship);6871 args->Push(iNewFriendship);68726873 bool bResult;6874 LuaSupport::CallHook(pkScriptSystem, "MinorAlliesChanged", args.get(), bResult);6875 }6876#if defined(MOD_EVENTS_MINORS)6877 }6878#endif6879 }68806881 // Make changes to bonuses here. Only send notifications if this change is not related to quests (otherwise it is rolled into quest notification)6882 if(bFriends || bAllies)6883 DoSetBonus(ePlayer, bAdd, bFriends, bAllies, /*bSuppressNotifications*/ bFromQuest);68846885 // Now actually changed Allied status, since we needed the old player in effect to create the notifications in the function above us6886 if(bAllies)6887 {6888 if(bAdd)6889 SetAlly(ePlayer);6890 else6891 SetAlly(NO_PLAYER); // We KNOW no one else can be higher, so set the Ally to NO_PLAYER6892 }6893}