Bazaar developer reference

CvMinorCivQuest::DoFinishQuest()

Defined in
CvMinorCivAI.cpp, line 1431
Class
CvMinorCivQuest
Hook name
CivHooks::CvMinorCivQuest_DoFinishQuest
Lua events
GameEvents.QuestSendNotification

Hooks

static bool BeforeCvMinorCivQuest_DoFinishQuest(CvMinorCivQuest* self, bool& result);static void AfterCvMinorCivQuest_DoFinishQuest(CvMinorCivQuest* self, bool& result);static bool ReplaceCvMinorCivQuest_DoFinishQuest(bool (*original)(CvMinorCivQuest*), CvMinorCivQuest* self);CivRegisterBefore<CivHooks::CvMinorCivQuest_DoFinishQuest>(host, &BeforeCvMinorCivQuest_DoFinishQuest);CivRegisterAfter<CivHooks::CvMinorCivQuest_DoFinishQuest>(host, &AfterCvMinorCivQuest_DoFinishQuest);CivRegisterReplace<CivHooks::CvMinorCivQuest_DoFinishQuest>(host, &ReplaceCvMinorCivQuest_DoFinishQuest);

Code

1429// Awards influence and sends notification to player.1430// Should only be called once.1431bool CvMinorCivQuest::DoFinishQuest()1432{1433	if (!IsComplete())1434		return false;14351436	if (IsHandled())1437		return false;14381439	SetHandled(true); // We are handling the end of the quest, and this should only happen once14401441	CvPlayer* pMinor = &GET_PLAYER(m_eMinor);14421443	bool bWasFriends = pMinor->GetMinorCivAI()->IsFriends(m_eAssignedPlayer);1444	bool bWasAllies = pMinor->GetMinorCivAI()->IsAllies(m_eAssignedPlayer);1445	PlayerTypes eOldAlly = pMinor->GetMinorCivAI()->GetAlly();1446	int iOldInf = pMinor->GetMinorCivAI()->GetEffectiveFriendshipWithMajor(m_eAssignedPlayer);14471448	pMinor->GetMinorCivAI()->ChangeFriendshipWithMajor(m_eAssignedPlayer, GetInfluenceReward(), /*bFromQuest*/ true);1449	1450	bool bNowFriends = pMinor->GetMinorCivAI()->IsFriends(m_eAssignedPlayer);1451	bool bNowAllies = pMinor->GetMinorCivAI()->IsAllies(m_eAssignedPlayer);1452	PlayerTypes eNewAlly = pMinor->GetMinorCivAI()->GetAlly();1453	int iNewInf = pMinor->GetMinorCivAI()->GetEffectiveFriendshipWithMajor(m_eAssignedPlayer);1454	int iInfChange = iNewInf - iOldInf;14551456	Localization::String strMessage;1457	Localization::String strSummary;1458	CivsList veNamesToShow;14591460#if defined(MOD_EVENTS_QUESTS)1461	if (UseEvents() && !IsInternal()) {1462		if (m_pQuestInfo->isContest()) {1463			veNamesToShow = GetContestLeaders();1464		}14651466		if (!m_pQuestInfo->getFinishMessage().IsEmpty() && !m_pQuestInfo->getFinishSummary().IsEmpty()) {1467			strMessage = Localization::Lookup(m_pQuestInfo->getFinishMessage().c_str());1468			strSummary = Localization::Lookup(m_pQuestInfo->getFinishSummary().c_str());1469		} else {1470			CvString sNames = "";1471			if(veNamesToShow.size() > 0) {1472				sNames = GET_PLAYER(GetMinor()).GetMinorCivAI()->GetNamesListAsString(veNamesToShow);1473			}1474			1475			if (GET_PLAYER(m_eAssignedPlayer).GetNotifications()) {1476				GAMEEVENTINVOKE_HOOK(GAMEEVENT_QuestSendNotification, m_eAssignedPlayer, m_eMinor, m_eType, GetStartTurn(), GetEndTurn(), m_iData1, m_iData2, false, true, sNames.c_str());1477			}14781479			// Update the UI with the changed data, in case it is open1480			if(m_eAssignedPlayer == GC.getGame().getActivePlayer()) {1481				GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);1482			}1483			1484			return true;1485		}1486	} else {1487#endif1488	// BUILD A ROUTE1489	if(m_eType == MINOR_CIV_QUEST_ROUTE)1490	{1491		// Route exists!1492		pMinor->GetMinorCivAI()->SetRouteConnectionEstablished(m_eAssignedPlayer, true);14931494		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_MINOR_ROUTE_CONNECTION");1495		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_MINOR_ROUTE_CONNECTION");1496	}14971498	// KILL A CAMP1499	else if(m_eType == MINOR_CIV_QUEST_KILL_CAMP)1500	{1501		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_KILL_CAMP");1502		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_KILL_CAMP");1503	}15041505	// CONNECT A RESOURCE1506	else if(m_eType == MINOR_CIV_QUEST_CONNECT_RESOURCE)1507	{1508		ResourceTypes eResource = (ResourceTypes) GetPrimaryData();1509		const char* strResourceName = GC.getResourceInfo(eResource)->GetDescriptionKey();15101511		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_CONNECT_RESOURCE");1512		strMessage << strResourceName;1513		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_CONNECT_RESOURCE");1514		strSummary << strResourceName;1515	}15161517	// CONSTRUCT A WONDER1518	else if(m_eType == MINOR_CIV_QUEST_CONSTRUCT_WONDER)1519	{1520		BuildingTypes eWonder = (BuildingTypes) GetPrimaryData();1521		const char* strBuildingName = GC.getBuildingInfo(eWonder)->GetDescriptionKey();15221523		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_CONSTRUCT_WONDER");1524		strMessage << strBuildingName;1525		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_CONSTRUCT_WONDER");1526		strSummary << strBuildingName;1527	}15281529	// GREAT PERSON1530	else if(m_eType == MINOR_CIV_QUEST_GREAT_PERSON)1531	{1532		UnitTypes eUnit = (UnitTypes) GetPrimaryData();1533		const char* strUnitName = GC.getUnitInfo(eUnit)->GetDescriptionKey();15341535		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_GREAT_PERSON");1536		strMessage << strUnitName;1537		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_GREAT_PERSON");1538		strSummary << strUnitName;1539	}15401541	// KILL ANOTHER CITY STATE1542	else if(m_eType == MINOR_CIV_QUEST_KILL_CITY_STATE)1543	{1544		PlayerTypes eTargetCityState = (PlayerTypes) GetPrimaryData();1545		const char* strTargetNameKey = GET_PLAYER(eTargetCityState).getNameKey();15461547		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_KILL_CITY_STATE");1548		strMessage << strTargetNameKey;1549		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_KILL_CITY_STATE");1550		strSummary << strTargetNameKey;1551	}15521553	// FIND ANOTHER PLAYER1554	else if(m_eType == MINOR_CIV_QUEST_FIND_PLAYER)1555	{1556		PlayerTypes ePlayerFound = (PlayerTypes) GetPrimaryData();1557		const char* strCivKey = GET_PLAYER(ePlayerFound).getCivilizationShortDescriptionKey();15581559		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_FIND_PLAYER");1560		strMessage << strCivKey;1561		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_FIND_PLAYER");1562		strSummary << strCivKey;1563	}15641565	// FIND NATURAL WONDER1566	else if(m_eType == MINOR_CIV_QUEST_FIND_NATURAL_WONDER)1567	{1568		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_FIND_NATURAL_WONDER");1569		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_FIND_NATURAL_WONDER");1570	}15711572	// Give gold1573	else if(m_eType == MINOR_CIV_QUEST_GIVE_GOLD)1574	{1575		PlayerTypes eMostRecentBully = (PlayerTypes) GetPrimaryData();1576		const char* strCivKey = "Nobody";1577		if(eMostRecentBully != NO_PLAYER)1578			strCivKey = GET_PLAYER(eMostRecentBully).getCivilizationShortDescriptionKey();15791580		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_GIVE_GOLD");1581		strMessage << strCivKey;1582		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_GIVE_GOLD");1583	}15841585	// Pledge to protect1586	else if(m_eType == MINOR_CIV_QUEST_PLEDGE_TO_PROTECT)1587	{1588		PlayerTypes eMostRecentBully = (PlayerTypes) GetPrimaryData();1589		const char* strCivKey = "Nobody";1590		if(eMostRecentBully != NO_PLAYER)1591			strCivKey = GET_PLAYER(eMostRecentBully).getCivilizationShortDescriptionKey();15921593		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_PLEDGE_TO_PROTECT");1594		strMessage << strCivKey;1595		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_PLEDGE_TO_PROTECT");1596	}15971598	// Culture contest1599	else if(m_eType == MINOR_CIV_QUEST_CONTEST_CULTURE)1600	{1601		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_CONTEST_CULTURE");1602		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_CONTEST_CULTURE");1603		veNamesToShow = GetContestLeaders();1604	}16051606	// Faith contest1607	else if(m_eType == MINOR_CIV_QUEST_CONTEST_FAITH)1608	{1609		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_CONTEST_FAITH");1610		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_CONTEST_FAITH");1611		veNamesToShow = GetContestLeaders();1612	}16131614	// Techs contest1615	else if(m_eType == MINOR_CIV_QUEST_CONTEST_TECHS)1616	{1617		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_CONTEST_TECHS");1618		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_CONTEST_TECHS");1619		veNamesToShow = GetContestLeaders();1620	}16211622	// Invest1623	else if(m_eType == MINOR_CIV_QUEST_INVEST)1624	{1625		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_INVEST");1626		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_INVEST");1627	}16281629	// Bully target City-State1630	else if(m_eType == MINOR_CIV_QUEST_BULLY_CITY_STATE)1631	{1632		PlayerTypes eTargetMinor = (PlayerTypes) GetPrimaryData();1633		const char* strCivKey = "Nobody";1634		if(eTargetMinor != NO_PLAYER)1635			strCivKey = GET_PLAYER(eTargetMinor).getCivilizationShortDescriptionKey();16361637		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_BULLY_CITY_STATE");1638		strMessage << strCivKey;1639		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_BULLY_CITY_STATE");1640		strSummary << strCivKey;1641	}16421643	// Denounce target Major1644	else if(m_eType == MINOR_CIV_QUEST_DENOUNCE_MAJOR)1645	{1646		PlayerTypes eTargetMajor = (PlayerTypes) GetPrimaryData();1647		const char* strCivKey = "Nobody";1648		if(eTargetMajor != NO_PLAYER)1649			strCivKey = GET_PLAYER(eTargetMajor).getCivilizationShortDescriptionKey();16501651		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_DENOUNCE_MAJOR");1652		strMessage << strCivKey;1653		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_DENOUNCE_MAJOR");1654		strSummary << strCivKey;1655	}16561657	// Spread your religion to us1658	else if(m_eType == MINOR_CIV_QUEST_SPREAD_RELIGION)1659	{1660		ReligionTypes eReligion = (ReligionTypes) GetPrimaryData();1661		CvString strReligionKey = "Atheism";1662		if(eReligion != NO_RELIGION)1663		{1664			const CvReligion* pReligion = GC.getGame().GetGameReligions()->GetReligion(eReligion, NO_PLAYER);1665			if(pReligion != NULL)1666			{1667				strReligionKey = pReligion->GetName();1668			}	1669		}16701671		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_SPREAD_RELIGION");1672		strMessage << strReligionKey.c_str();1673		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_SPREAD_RELIGION");1674		strSummary << strReligionKey.c_str();1675	}16761677	// Connect A Trade Route1678	if(m_eType == MINOR_CIV_QUEST_TRADE_ROUTE)1679	{1680		strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_QUEST_COMPLETE_TRADE_ROUTE");1681		strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SUMMARY_QUEST_COMPLETE_TRADE_ROUTE");1682	}1683#if defined(MOD_EVENTS_QUESTS)1684	}1685#endif16861687	// Update the UI with the changed data, in case it is open1688	if(m_eAssignedPlayer == GC.getGame().getActivePlayer())1689	{1690		GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);1691	}16921693	strMessage << pMinor->getNameKey();1694	strMessage << iInfChange;1695	strSummary << pMinor->getNameKey();16961697	CvString sMessage = strMessage.toUTF8();1698	CvString sSummary = strSummary.toUTF8();16991700	// This quest involved multiple minors, so grab their names for the notification1701	if(veNamesToShow.size() > 0)1702	{1703		sMessage = sMessage + pMinor->GetMinorCivAI()->GetNamesListAsString(veNamesToShow);1704	}17051706	// This quest reward changed our status, so grab that info for the notification1707	if ((!bWasFriends && bNowFriends) || (!bWasAllies && bNowAllies))1708	{1709		pair<CvString, CvString> statusChangeStrings = pMinor->GetMinorCivAI()->GetStatusChangeNotificationStrings(m_eAssignedPlayer, /*bAdd*/true, bNowFriends, bNowAllies, eOldAlly, eNewAlly);1710		sMessage = sMessage + "[NEWLINE][NEWLINE]" + statusChangeStrings.first;1711	}17121713	pMinor->GetMinorCivAI()->AddQuestNotification(sMessage, sSummary, m_eAssignedPlayer);17141715	return true;1716}

Calls

Called by