Hooks
static bool BeforeCvMinorCivQuest_DoStartQuest(CvMinorCivQuest* self, int iStartTurn);static void AfterCvMinorCivQuest_DoStartQuest(CvMinorCivQuest* self, int iStartTurn);static void ReplaceCvMinorCivQuest_DoStartQuest(void (*original)(CvMinorCivQuest*, int), CvMinorCivQuest* self, int iStartTurn);CivRegisterBefore<CivHooks::CvMinorCivQuest_DoStartQuest>(host, &BeforeCvMinorCivQuest_DoStartQuest);CivRegisterAfter<CivHooks::CvMinorCivQuest_DoStartQuest>(host, &AfterCvMinorCivQuest_DoStartQuest);CivRegisterReplace<CivHooks::CvMinorCivQuest_DoStartQuest>(host, &ReplaceCvMinorCivQuest_DoStartQuest);
Code
973// Initializes data to track quest progress and sends notification to player.974// NOTE: Some types initialize data using randomness here. So two otherwise equivalent quests may be initialized with different data.975// NOTE: Should only be called once.976void CvMinorCivQuest::DoStartQuest(int iStartTurn)977{978 m_iStartTurn = iStartTurn;979980 CvPlayer* pMinor = &GET_PLAYER(m_eMinor);981 CvPlayer* pAssignedPlayer = &GET_PLAYER(m_eAssignedPlayer);982983 Localization::String strMessage;984 Localization::String strSummary;985 int iNotificationX = -1;986 int iNotificationY = -1;987988#if defined(MOD_EVENTS_QUESTS)989 if (UseEvents() && !IsInternal()) {990 // Tell the player the quest is starting991 GAMEEVENTINVOKE_HOOK(GAMEEVENT_QuestStart, m_eAssignedPlayer, m_eMinor, m_eType, true, m_iStartTurn, NO_QUEST_DATA, NO_QUEST_DATA);992993 // Get back any data they may want to save994 int iData1 = 0;995 if (GAMEEVENTINVOKE_VALUE(iData1, GAMEEVENT_QuestGetData, m_eAssignedPlayer, m_eMinor, m_eType, true) == GAMEEVENTRETURN_VALUE) {996 m_iData1 = iData1;997 } else {998 m_iData1 = NO_QUEST_DATA;999 }10001001 int iData2 = 0;1002 if (GAMEEVENTINVOKE_VALUE(iData2, GAMEEVENT_QuestGetData, m_eAssignedPlayer, m_eMinor, m_eType, false) == GAMEEVENTRETURN_VALUE) {1003 m_iData2 = iData2;1004 } else {1005 m_iData2 = NO_QUEST_DATA;1006 }10071008 if (!m_pQuestInfo->getStartMessage().IsEmpty() && !m_pQuestInfo->getStartSummary().IsEmpty()) {1009 strMessage = Localization::Lookup(m_pQuestInfo->getStartMessage().c_str());1010 strSummary = Localization::Lookup(m_pQuestInfo->getStartSummary().c_str());1011 } else {1012 if (GET_PLAYER(m_eAssignedPlayer).GetNotifications()) {1013 GAMEEVENTINVOKE_HOOK(GAMEEVENT_QuestSendNotification, m_eAssignedPlayer, m_eMinor, m_eType, GetStartTurn(), GetEndTurn(), m_iData1, m_iData2, true, false, "");1014 }10151016 return;1017 }1018 } else {1019#endif1020 // Build a Route1021 if(m_eType == MINOR_CIV_QUEST_ROUTE)1022 {1023 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_START_ROUTE");1024 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_START_ROUTE");1025 }1026 // Kill a Camp1027 else if(m_eType == MINOR_CIV_QUEST_KILL_CAMP)1028 {1029 CvPlot* pPlot = pMinor->GetMinorCivAI()->GetBestNearbyCampToKill();10301031 FAssertMsg(pPlot != NULL, "MINOR CIV AI: Somehow we're starting a quest to kill a barb camp but we can't find one nearby. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Oh, and you're about to crash.");10321033 m_iData1 = pPlot->getX();1034 m_iData2 = pPlot->getY();10351036 pPlot->setRevealed(pAssignedPlayer->getTeam(), true);1037 pPlot->setRevealedImprovementType(pAssignedPlayer->getTeam(), pPlot->getImprovementType());10381039 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_KILL_CAMP");1040 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_KILL_CAMP");1041 iNotificationX = pPlot->getX();1042 iNotificationY = pPlot->getY();1043 }1044 // Connect a Resource1045 else if(m_eType == MINOR_CIV_QUEST_CONNECT_RESOURCE)1046 {1047 ResourceTypes eResource = pMinor->GetMinorCivAI()->GetNearbyResourceForQuest(m_eAssignedPlayer);10481049 FAssertMsg(eResource != NO_RESOURCE, "MINOR CIV AI: For some reason we got NO_RESOURCE when starting a quest for a major to find a Resource. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Bad things are probably going to happen.");10501051 m_iData1 = eResource;10521053 const char* strResourceName = GC.getResourceInfo(eResource)->GetDescriptionKey();10541055 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_CONNECT_RESOURCE");1056 strMessage << strResourceName;1057 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_CONNECT_RESOURCE");1058 strSummary << strResourceName;1059 }1060 // Construct a Wonder1061 else if(m_eType == MINOR_CIV_QUEST_CONSTRUCT_WONDER)1062 {1063 BuildingTypes eWonder = pMinor->GetMinorCivAI()->GetBestWonderForQuest(m_eAssignedPlayer);10641065 FAssertMsg(eWonder != NO_BUILDING, "MINOR CIV AI: For some reason we got NO_BUILDING when starting a quest for a major to find a Wonder. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Bad things are probably going to happen.");10661067 m_iData1 = eWonder;10681069 const char* strBuildingName = GC.getBuildingInfo(eWonder)->GetDescriptionKey();10701071 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_CONSTRUCT_WONDER");1072 strMessage << strBuildingName;1073 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_CONSTRUCT_WONDER");1074 strSummary << strBuildingName;1075 }1076 // Great Person1077 else if(m_eType == MINOR_CIV_QUEST_GREAT_PERSON)1078 {1079 UnitTypes eUnit = pMinor->GetMinorCivAI()->GetBestGreatPersonForQuest(m_eAssignedPlayer);10801081 FAssertMsg(eUnit != NO_UNIT, "MINOR CIV AI: For some reason we got NO_UNIT when starting a quest for a major to find a Great Person. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Bad things are probably going to happen.");10821083 m_iData1 = eUnit;10841085 const char* strUnitName = GC.getUnitInfo(eUnit)->GetDescriptionKey();10861087 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_GREAT_PERSON");1088 strMessage << strUnitName;1089 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_GREAT_PERSON");1090 strSummary << strUnitName;1091 }1092 // Kill another City State1093 else if(m_eType == MINOR_CIV_QUEST_KILL_CITY_STATE)1094 {1095 PlayerTypes eTargetCityState = pMinor->GetMinorCivAI()->GetBestCityStateTarget(m_eAssignedPlayer);10961097 FAssertMsg(eTargetCityState != NO_PLAYER, "MINOR CIV AI: For some reason we got NO_PLAYER when starting a quest for a major to kill a City State. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Bad things are probably going to happen.");10981099 m_iData1 = eTargetCityState;11001101 const char* strTargetNameKey = GET_PLAYER(eTargetCityState).getNameKey();11021103 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_KILL_CITY_STATE");1104 strMessage << strTargetNameKey;1105 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_KILL_CITY_STATE");1106 strSummary << strTargetNameKey;1107 }1108 // Find another player's territory1109 else if(m_eType == MINOR_CIV_QUEST_FIND_PLAYER)1110 {1111 PlayerTypes ePlayerToFind = pMinor->GetMinorCivAI()->GetBestPlayerToFind(m_eAssignedPlayer);11121113 FAssertMsg(ePlayerToFind != NO_PLAYER, "MINOR CIV AI: For some reason we got NO_PLAYER when starting a quest for a major to find a player. Please send Jon this with your last 5 autosaves and what changelist # you're playing. Bad things are probably going to happen.");11141115 m_iData1 = ePlayerToFind;11161117 const char* strCivKey = GET_PLAYER(ePlayerToFind).getCivilizationShortDescriptionKey();11181119 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_FIND_PLAYER");1120 strMessage << strCivKey;1121 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_FIND_PLAYER");1122 strSummary << strCivKey;1123 }1124 // Find a Natural Wonder1125 else if(m_eType == MINOR_CIV_QUEST_FIND_NATURAL_WONDER)1126 {1127 int iNumWondersAlreadyFound = GET_TEAM(pAssignedPlayer->getTeam()).GetNumNaturalWondersDiscovered();11281129 m_iData1 = iNumWondersAlreadyFound;11301131 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_FIND_NATURAL_WONDER");1132 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_FIND_NATURAL_WONDER");1133 }1134 // Give a gift of gold1135 else if(m_eType == MINOR_CIV_QUEST_GIVE_GOLD)1136 {1137 PlayerTypes eMostRecentBully = pMinor->GetMinorCivAI()->GetMostRecentBullyForQuest();1138 int iGoldAlreadyGiven = pMinor->GetMinorCivAI()->GetNumGoldGifted(m_eAssignedPlayer);11391140 CvAssertMsg(eMostRecentBully != NO_PLAYER, "MINOR CIV AI: eMostRecentBully should not be NO_PLAYER when giving a Give Gold quest! Please send Anton your save file and version.");11411142 m_iData1 = eMostRecentBully;1143 m_iData2 = iGoldAlreadyGiven;11441145 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_GIVE_GOLD");1146 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_GIVE_GOLD");11471148 if(eMostRecentBully != NO_PLAYER)1149 {1150 const char* strCivKey = GET_PLAYER(eMostRecentBully).getCivilizationShortDescriptionKey();1151 strMessage << strCivKey;1152 }1153 else1154 {1155 const char* strCivKey = "Nobody";1156 strMessage << strCivKey;1157 }1158 }1159 // Pledge to protect them1160 else if(m_eType == MINOR_CIV_QUEST_PLEDGE_TO_PROTECT)1161 {1162 PlayerTypes eMostRecentBully = pMinor->GetMinorCivAI()->GetMostRecentBullyForQuest();11631164 CvAssertMsg(eMostRecentBully != NO_PLAYER, "MINOR CIV AI: eMostRecentBully should not be NO_PLAYER when giving a Pledge to Protect quest! Please send Anton your save file and version.");11651166 m_iData1 = eMostRecentBully;11671168 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_PLEDGE_TO_PROTECT");1169 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_PLEDGE_TO_PROTECT");11701171 if(eMostRecentBully != NO_PLAYER)1172 {1173 const char* strCivKey = GET_PLAYER(eMostRecentBully).getCivilizationShortDescriptionKey();1174 strMessage << strCivKey;1175 }1176 else1177 {1178 const char* strCivKey = "Nobody";1179 strMessage << strCivKey;1180 }1181 }1182 // Culture contest1183 else if(m_eType == MINOR_CIV_QUEST_CONTEST_CULTURE)1184 {1185 int iStartingCulture = pAssignedPlayer->GetJONSCultureEverGenerated();11861187 m_iData1 = iStartingCulture;11881189 int iTurnsRemaining = GetEndTurn() - GC.getGame().getGameTurn();1190 int iTurnsDuration = GetEndTurn() - GetStartTurn();11911192 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_CONTEST_CULTURE");1193 strMessage << iTurnsRemaining;1194 strMessage << iTurnsDuration;1195 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_CONTEST_CULTURE");1196 }1197 // Faith contest1198 else if(m_eType == MINOR_CIV_QUEST_CONTEST_FAITH)1199 {1200 int iStartingFaith = pAssignedPlayer->GetFaithEverGenerated();12011202 m_iData1 = iStartingFaith;12031204 int iTurnsRemaining = GetEndTurn() - GC.getGame().getGameTurn();1205 int iTurnsDuration = GetEndTurn() - GetStartTurn();12061207 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_CONTEST_FAITH");1208 strMessage << iTurnsRemaining;1209 strMessage << iTurnsDuration;1210 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_CONTEST_FAITH");1211 }1212 // Techs contest1213 else if(m_eType == MINOR_CIV_QUEST_CONTEST_TECHS)1214 {1215 int iStartingTechs = GET_TEAM(pAssignedPlayer->getTeam()).GetTeamTechs()->GetNumTechsKnown();12161217 m_iData1 = iStartingTechs;12181219 int iTurnsRemaining = GetEndTurn() - GC.getGame().getGameTurn();1220 int iTurnsDuration = GetEndTurn() - GetStartTurn();12211222 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_CONTEST_TECHS");1223 strMessage << iTurnsRemaining;1224 strMessage << iTurnsDuration;1225 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_CONTEST_TECHS");1226 }1227 // Invest1228 else if(m_eType == MINOR_CIV_QUEST_INVEST)1229 {1230 int iGoldAlreadyGiven = pMinor->GetMinorCivAI()->GetNumGoldGifted(m_eAssignedPlayer);12311232 m_iData1 = iGoldAlreadyGiven;12331234 int iTurnsRemaining = GetEndTurn() - GC.getGame().getGameTurn();1235 int iBoostPercentage = 50;//antonjs: todo: XML12361237 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_INVEST");1238 strMessage << iTurnsRemaining;1239 strMessage << iBoostPercentage;1240 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_INVEST");1241 }1242 // Bully target City-State1243 else if(m_eType == MINOR_CIV_QUEST_BULLY_CITY_STATE)1244 {1245 PlayerTypes eTargetMinor = pMinor->GetMinorCivAI()->GetBestCityStateTarget(m_eAssignedPlayer);1246 CvAssertMsg(eTargetMinor != NO_PLAYER, "MINOR CIV AI: eTargetMinor should not be NO_PLAYER when giving a Bully CS quest! Please send Anton your save file and version.");1247 int iLastBullyTurn = GET_PLAYER(eTargetMinor).GetMinorCivAI()->GetTurnLastBulliedByMajor(m_eAssignedPlayer);12481249 m_iData1 = eTargetMinor;1250 m_iData2 = iLastBullyTurn;12511252 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_BULLY_CITY_STATE");1253 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_BULLY_CITY_STATE");12541255 if(eTargetMinor != NO_PLAYER)1256 {1257 const char* strCivKey = GET_PLAYER(eTargetMinor).getCivilizationShortDescriptionKey();1258 strMessage << strCivKey;1259 strSummary << strCivKey;1260 }1261 else1262 {1263 const char* strCivKey = "Nobody";1264 strMessage << strCivKey;1265 strSummary << strCivKey;1266 }1267 }1268 // Denounce target Major1269 else if(m_eType == MINOR_CIV_QUEST_DENOUNCE_MAJOR)1270 {1271 PlayerTypes eMostRecentBully = pMinor->GetMinorCivAI()->GetMostRecentBullyForQuest();12721273 CvAssertMsg(eMostRecentBully != NO_PLAYER, "MINOR CIV AI: eMostRecentBully should not be NO_PLAYER when giving a Denounce Major quest! Please send Anton your save file and version.");12741275 m_iData1 = eMostRecentBully;12761277 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_DENOUNCE_MAJOR");1278 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_DENOUNCE_MAJOR");12791280 if(eMostRecentBully != NO_PLAYER)1281 {1282 const char* strCivKey = GET_PLAYER(eMostRecentBully).getCivilizationShortDescriptionKey();1283 strMessage << strCivKey;1284 strSummary << strCivKey;1285 }1286 else1287 {1288 const char* strCivKey = "Nobody";1289 strMessage << strCivKey;1290 strSummary << strCivKey;1291 }1292 }1293 // Spread your religion to us1294 else if(m_eType == MINOR_CIV_QUEST_SPREAD_RELIGION)1295 {1296 ReligionTypes eReligion = GC.getGame().GetGameReligions()->GetReligionCreatedByPlayer(m_eAssignedPlayer);12971298 CvAssertMsg(eReligion != NO_RELIGION, "MINOR CIV AI: eReligion should not be NO_RELIGION when giving a Spread Religion quest! Please send Anton your save file and version.");12991300 m_iData1 = eReligion;13011302 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_SPREAD_RELIGION");1303 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_SPREAD_RELIGION");13041305 if(eReligion != NO_RELIGION)1306 {1307 const CvReligion* pkReligion = GC.getGame().GetGameReligions()->GetReligion(eReligion, NO_PLAYER);1308 CvString strReligion = pkReligion->GetName(); // Not a key, already localized (may be custom name)1309 strMessage << strReligion;1310 strSummary << strReligion;1311 }1312 else1313 {1314 const char* strReligion = "No Religion";1315 strMessage << strReligion;1316 strSummary << strReligion;1317 }1318 }1319 // Connect a trade Route1320 else if(m_eType == MINOR_CIV_QUEST_TRADE_ROUTE)1321 {1322 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_START_TRADE_ROUTE");1323 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_START_TRADE_ROUTE");1324 }13251326 strMessage << pMinor->getNameKey();1327 strSummary << pMinor->getNameKey();1328 pMinor->GetMinorCivAI()->AddQuestNotification(strMessage.toUTF8(), strSummary.toUTF8(), m_eAssignedPlayer, iNotificationX, iNotificationY);1329#if defined(MOD_EVENTS_QUESTS)1330 }1331#endif1332}