Hooks
static bool BeforeCvMinorCivQuest_DoStartQuestUsingExistingData(CvMinorCivQuest* self, CvMinorCivQuest* pExistingQuest);static void AfterCvMinorCivQuest_DoStartQuestUsingExistingData(CvMinorCivQuest* self, CvMinorCivQuest* pExistingQuest);static void ReplaceCvMinorCivQuest_DoStartQuestUsingExistingData(void (*original)(CvMinorCivQuest*, CvMinorCivQuest*), CvMinorCivQuest* self, CvMinorCivQuest* pExistingQuest);CivRegisterBefore<CivHooks::CvMinorCivQuest_DoStartQuestUsingExistingData>(host, &BeforeCvMinorCivQuest_DoStartQuestUsingExistingData);CivRegisterAfter<CivHooks::CvMinorCivQuest_DoStartQuestUsingExistingData>(host, &AfterCvMinorCivQuest_DoStartQuestUsingExistingData);CivRegisterReplace<CivHooks::CvMinorCivQuest_DoStartQuestUsingExistingData>(host, &ReplaceCvMinorCivQuest_DoStartQuestUsingExistingData);
Code
1334// Begins the quest, but with client-provided data rather than initializing data internally.1335// Should only be called when starting a quest for a player that has an equivalent quest which already exists for a different player (global quests).1336void CvMinorCivQuest::DoStartQuestUsingExistingData(CvMinorCivQuest* pExistingQuest)1337{1338 CvPlayer* pMinor = &GET_PLAYER(m_eMinor);1339 CvPlayer* pAssignedPlayer = &GET_PLAYER(m_eAssignedPlayer);13401341 CvAssertMsg(pMinor != NULL, "pMinor should not be NULL. Please send Anton your save file and version.");1342 CvAssertMsg(pAssignedPlayer != NULL, "pAssignedPlayer should not be NULL. Please send Anton your save file and version.");1343 CvAssertMsg(pExistingQuest != NULL, "pExistingQuest should not be NULL. Please send Anton your save file and version.");1344 if(pMinor == NULL || pAssignedPlayer == NULL || pExistingQuest == NULL) return;13451346 Localization::String strMessage;1347 Localization::String strSummary;1348 int iNotificationX = -1;1349 int iNotificationY = -1;13501351#if defined(MOD_EVENTS_QUESTS)1352 if (UseEvents() && !IsInternal()) {1353 m_iStartTurn = pExistingQuest->GetStartTurn();1354 m_iData1 = pExistingQuest->GetPrimaryData();1355 m_iData2 = pExistingQuest->GetSecondaryData();13561357 // Tell the player they are joining an existing quest1358 GAMEEVENTINVOKE_HOOK(GAMEEVENT_QuestStart, m_eAssignedPlayer, m_eMinor, m_eType, false, m_iStartTurn, m_iData1, m_iData2);1359 // We're using the existing data, so do NOT send the QuestGetData events!13601361 // Send a notification1362 if (!m_pQuestInfo->getStartMessage().IsEmpty() && !m_pQuestInfo->getStartSummary().IsEmpty()) {1363 strMessage = Localization::Lookup(m_pQuestInfo->getStartMessage().c_str());1364 strSummary = Localization::Lookup(m_pQuestInfo->getStartSummary().c_str());1365 }1366 else {1367 if (GET_PLAYER(m_eAssignedPlayer).GetNotifications()) {1368 GAMEEVENTINVOKE_HOOK(GAMEEVENT_QuestSendNotification, m_eAssignedPlayer, m_eMinor, m_eType, GetStartTurn(), GetEndTurn(), m_iData1, m_iData2, true, false, "");1369 }13701371 return;1372 }1373 } else {1374#endif1375 // Kill a Camp - This quest needs to have the data for the same camp as the existing quest1376 if(m_eType == MINOR_CIV_QUEST_KILL_CAMP)1377 {1378 m_iStartTurn = pExistingQuest->GetStartTurn();13791380 int iCampX = pExistingQuest->GetPrimaryData();1381 int iCampY = pExistingQuest->GetSecondaryData();13821383 CvPlot* pPlot = GC.getMap().plot(iCampX, iCampY);13841385 if(!pPlot)1386 {1387 CvAssertMsg(false, "We're starting a quest to kill a barb camp using an existing quest's barb camp data, but the data is bad. Please send Anton your save file and version.");1388 return;1389 }1390 if(pPlot->getImprovementType() != GC.getBARBARIAN_CAMP_IMPROVEMENT())1391 {1392 CvAssertMsg(false, "We're starting a quest to kill a barb camp using an existing quest's barb camp data, but there's no camp there anymore. Please send Anton your save file and version.");1393 return;1394 }13951396 m_iData1 = iCampX;1397 m_iData2 = iCampY;13981399 pPlot->setRevealed(pAssignedPlayer->getTeam(), true);1400 pPlot->setRevealedImprovementType(pAssignedPlayer->getTeam(), pPlot->getImprovementType());14011402 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_KILL_CAMP");1403 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_KILL_CAMP");1404 iNotificationX = pPlot->getX();1405 iNotificationY = pPlot->getY();14061407 strMessage << pMinor->getNameKey();1408 strSummary << pMinor->getNameKey();1409 pMinor->GetMinorCivAI()->AddQuestNotification(strMessage.toUTF8(), strSummary.toUTF8(), m_eAssignedPlayer, iNotificationX, iNotificationY);1410 }14111412 // Other global quests (ie. contests) - Quest data is initialized as normal except for the start turn, which was in the past1413 else if(pMinor->GetMinorCivAI()->IsGlobalQuest(pExistingQuest->GetType()))1414 {1415 DoStartQuest(pExistingQuest->GetStartTurn());1416 }14171418 // Personal quests - Should not be started from an existing quest's data!!1419 else1420 {1421 CvAssertMsg(false, "Trying to start a personal quest using existing quest data. This should not be done. Please send Anton your save file and version.");1422 DoStartQuest(pExistingQuest->GetStartTurn());1423 }1424#if defined(MOD_EVENTS_QUESTS)1425 }1426#endif1427}