Hooks
static bool BeforeCvMinorCivAI_DoSetBonus(CvMinorCivAI* self, PlayerTypes ePlayer, bool bAdd, bool bFriends, bool bAllies, bool bSuppressNotifications, bool bPassedBySomeone, PlayerTypes eNewAlly);static void AfterCvMinorCivAI_DoSetBonus(CvMinorCivAI* self, PlayerTypes ePlayer, bool bAdd, bool bFriends, bool bAllies, bool bSuppressNotifications, bool bPassedBySomeone, PlayerTypes eNewAlly);static void ReplaceCvMinorCivAI_DoSetBonus(void (*original)(CvMinorCivAI*, PlayerTypes, bool, bool, bool, bool, bool, PlayerTypes), CvMinorCivAI* self, PlayerTypes ePlayer, bool bAdd, bool bFriends, bool bAllies, bool bSuppressNotifications, bool bPassedBySomeone, PlayerTypes eNewAlly);CivRegisterBefore<CivHooks::CvMinorCivAI_DoSetBonus>(host, &BeforeCvMinorCivAI_DoSetBonus);CivRegisterAfter<CivHooks::CvMinorCivAI_DoSetBonus>(host, &AfterCvMinorCivAI_DoSetBonus);CivRegisterReplace<CivHooks::CvMinorCivAI_DoSetBonus>(host, &ReplaceCvMinorCivAI_DoSetBonus);
Code
6935/// Sets a major to get a Bonus (or not) - set both bFriends and bAllies to be true if you're adding/removing both states at once6936void CvMinorCivAI::DoSetBonus(PlayerTypes ePlayer, bool bAdd, bool bFriends, bool bAllies, bool bSuppressNotifications, bool bPassedBySomeone, PlayerTypes eNewAlly)6937{6938 MinorCivTraitTypes eTrait = GetTrait();69396940 // Cultured6941 if(eTrait == MINOR_CIV_TRAIT_CULTURED)6942 {6943 }6944 // Militaristic6945 else if(eTrait == MINOR_CIV_TRAIT_MILITARISTIC)6946 {6947 if(bAdd)6948 {6949 // Seed Counter if it hasn't been done yet in this game. We don't have to undo this at any point because the counter is not processed if we are no longer Friends6950 if(GetUnitSpawnCounter(ePlayer) == -1)6951 DoSeedUnitSpawnCounter(ePlayer, /*bBias*/ true);6952 }6953 }6954 // Maritime6955 else if(eTrait == MINOR_CIV_TRAIT_MARITIME)6956 {6957 int iCapitalFoodTimes100 = 0;6958 int iOtherCitiesFoodTimes100 = 0;69596960 if(bFriends) // Friends bonus6961 {6962 iCapitalFoodTimes100 += GetFriendsCapitalFoodBonus(ePlayer);6963 iOtherCitiesFoodTimes100 += GetFriendsOtherCityFoodBonus(ePlayer);6964 }6965 if(bAllies) // Allies bonus6966 {6967 iCapitalFoodTimes100 += GetAlliesCapitalFoodBonus(ePlayer);6968 iOtherCitiesFoodTimes100 += GetAlliesOtherCityFoodBonus(ePlayer);6969 }69706971 if(!bAdd) // Flip amount of we're taking bonuses away6972 {6973 iCapitalFoodTimes100 = -iCapitalFoodTimes100;6974 iOtherCitiesFoodTimes100 = -iOtherCitiesFoodTimes100;6975 }69766977#if defined(MOD_BUGFIX_MINOR)6978 GET_PLAYER(ePlayer).ChangeCapitalYieldChangeTimes100(YIELD_FOOD, iCapitalFoodTimes100);6979 GET_PLAYER(ePlayer).ChangeCityYieldChangeTimes100(YIELD_FOOD, iOtherCitiesFoodTimes100);6980#else6981 GET_PLAYER(ePlayer).ChangeCapitalYieldChange(YIELD_FOOD, iCapitalFoodTimes100);6982 GET_PLAYER(ePlayer).ChangeCityYieldChange(YIELD_FOOD, iOtherCitiesFoodTimes100);6983#endif6984 }6985 // Mercantile6986 else if(eTrait == MINOR_CIV_TRAIT_MERCANTILE)6987 {6988 GET_PLAYER(ePlayer).DoUpdateHappiness();6989 }6990 // Religious6991 if(eTrait == MINOR_CIV_TRAIT_RELIGIOUS)6992 {6993 }69946995 if(ePlayer == GC.getGame().getActivePlayer())6996 {6997 GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);6998 }69997000 CvString strDetailedInfo = GetStatusChangeDetails(ePlayer, bAdd, bFriends, bAllies);70017002 PlayerTypes eOldAlly = GetAlly();7003 TeamTypes eOldAllyTeam = eOldAlly != NO_PLAYER ? GET_PLAYER(eOldAlly).getTeam() : NO_TEAM;70047005 // Should we remove the Ally bonus from another player?7006 if(bAdd && bAllies)7007 {7008 if(eOldAlly != NO_PLAYER && ePlayer != eOldAlly)7009 {7010 DoSetBonus(eOldAlly, /*bAdd*/ false, /*bFriends*/ false, /*bAllies*/ true, /*bSuppressNotifications*/ false, /*bPassedBySomeone*/ true, ePlayer);7011 }7012 }70137014 // *******************************************7015 // NOTIFICATIONS FOR THIS PLAYER7016 // *******************************************7017 // We're not displaying notifications at all7018 if (IsDisableNotifications())7019 {7020 return;7021 }70227023 if (!bSuppressNotifications)7024 {7025 pair<CvString, CvString> notifStrings = GetStatusChangeNotificationStrings(ePlayer, bAdd, bFriends, bAllies, eOldAlly, (bAdd && bAllies) ? ePlayer : eNewAlly);7026 AddNotification(notifStrings.first, notifStrings.second, ePlayer);7027 }70287029 // *******************************************7030 // NOTIFICATIONS FOR OTHER PLAYERS IN THE GAME7031 // *******************************************7032 Localization::String strMessageOthers;7033 Localization::String strSummaryOthers;70347035 // We need to do this because this function is recursive, and if we're UNDOING someone else, we don't yet know who the new guy is because it hasn't been set yet7036 if(bPassedBySomeone)7037 ePlayer = eNewAlly;70387039 for(int iNotifyLoop = 0; iNotifyLoop < MAX_MAJOR_CIVS; ++iNotifyLoop){7040 PlayerTypes eNotifyPlayer = (PlayerTypes) iNotifyLoop;7041 CvPlayerAI& kCurNotifyPlayer = GET_PLAYER(eNotifyPlayer);7042 CvTeam* pNotifyTeam = &GET_TEAM(kCurNotifyPlayer.getTeam());7043 TeamTypes eNewAllyTeam = GET_PLAYER(ePlayer).getTeam();7044 const char* strNewBestPlayersNameKey;70457046 // Notify player has met the new Ally7047 if(pNotifyTeam->isHasMet(eNewAllyTeam))7048 strNewBestPlayersNameKey = GET_PLAYER(ePlayer).getCivilizationShortDescriptionKey();7049 // Notify player has NOT met the new Ally7050 else7051 strNewBestPlayersNameKey = "TXT_KEY_UNMET_PLAYER";70527053 const char* strOldBestPlayersNameKey = "";70547055 // Someone got passed up7056 if(eOldAlly != NO_PLAYER)7057 {7058 // Notify player has met the old Ally7059 if(pNotifyTeam->isHasMet(eOldAllyTeam))7060 strOldBestPlayersNameKey = GET_PLAYER(eOldAlly).getCivilizationShortDescriptionKey();7061 // Notify player has NOT met the old Ally7062 else7063 strOldBestPlayersNameKey = "TXT_KEY_UNMET_PLAYER";7064 }70657066 const char* strMinorsNameKey = GetPlayer()->getNameKey();7067 TeamTypes eMinorTeam = GetPlayer()->getTeam();70687069 // Adding/Increasing bonus7070 if(bAdd)7071 {7072 // Jumped up to Allies (either from Neutral or from Friends, or passing another player)7073 if(bAllies)7074 {7075 if(ePlayer != eNotifyPlayer)7076 {7077 // Has the notify player met this minor7078 if(pNotifyTeam->isHasMet(eMinorTeam))7079 {7080 // Someone got passed up7081 if(eOldAlly != NO_PLAYER && eOldAlly != ePlayer)7082 {7083 strMessageOthers = Localization::Lookup("TXT_KEY_NTFN_MINOR_NEW_BEST_RELATIONS_ALL");7084 strMessageOthers << strNewBestPlayersNameKey << strOldBestPlayersNameKey << strMinorsNameKey;7085 strSummaryOthers = Localization::Lookup("TXT_KEY_NTFN_SMMRY_MINOR_BEST_RELATIONS_ALL");7086 strSummaryOthers << strMinorsNameKey;7087 }7088 // No one previously had the bonus7089 else7090 {7091 strMessageOthers = Localization::Lookup("TXT_KEY_NTFN_MINOR_NOW_BEST_RELATIONS_ALL");7092 strMessageOthers << strNewBestPlayersNameKey << strMinorsNameKey;7093 strSummaryOthers = Localization::Lookup("TXT_KEY_NTFN_SMMRY_MINOR_NOW_ALLIES_ALL");7094 strSummaryOthers << strMinorsNameKey << strNewBestPlayersNameKey;7095 }70967097 // If we're being passed by someone, then don't display this message... we'll roll it into a later one7098 if(eOldAlly != eNotifyPlayer)7099 AddNotification(strMessageOthers.toUTF8(), strSummaryOthers.toUTF8(), eNotifyPlayer);7100 }7101 }7102 }7103 }7104 // Removing/Reducing bonus7105 else7106 {7107 // Dropped from Allies7108 if(bAllies)7109 {7110 if(ePlayer != eNotifyPlayer)7111 {7112 if(pNotifyTeam->isHasMet(eMinorTeam))7113 {7114 // Only show this message for normal friendship decay7115 if(!bPassedBySomeone)7116 {7117 const char* strOldAllyNameKey;71187119 // Notify player has met the old Ally7120 if(pNotifyTeam->isHasMet(eOldAllyTeam))7121 strOldAllyNameKey = GET_PLAYER(eOldAlly).getCivilizationShortDescriptionKey();7122 // Notify player has NOT met the old Ally7123 else7124 strOldAllyNameKey = "TXT_KEY_UNMET_PLAYER";71257126 strMessageOthers = Localization::Lookup("TXT_KEY_NTFN_MINOR_BEST_RELATIONS_LOST_ALL");7127 strMessageOthers << strOldAllyNameKey << strMinorsNameKey;7128 strSummaryOthers = Localization::Lookup("TXT_KEY_NTFN_SMMRY_MINOR_BEST_RELATIONS_LOST_ALL");7129 strSummaryOthers << strMinorsNameKey << strOldAllyNameKey;71307131 AddNotification(strMessageOthers.toUTF8(), strSummaryOthers.toUTF8(), eNotifyPlayer);7132 }7133 }7134 }7135 }7136 }7137 }7138}