Bazaar developer reference

CvTeam::DoMakePeace(PlayerTypes, bool, TeamTypes, bool, bool)

Defined in
CvTeam.cpp, line 1589
Class
CvTeam
Hook name
CivHooks::CvTeam_DoMakePeace
Lua events
GameEvents.MakePeace

Hooks

static bool BeforeCvTeam_DoMakePeace(CvTeam* self, PlayerTypes eOriginatingPlayer, bool bPacifier, TeamTypes eTeam, bool bBumpUnits, bool bSuppressNotification);static void AfterCvTeam_DoMakePeace(CvTeam* self, PlayerTypes eOriginatingPlayer, bool bPacifier, TeamTypes eTeam, bool bBumpUnits, bool bSuppressNotification);static void ReplaceCvTeam_DoMakePeace(void (*original)(CvTeam*, PlayerTypes, bool, TeamTypes, bool, bool), CvTeam* self, PlayerTypes eOriginatingPlayer, bool bPacifier, TeamTypes eTeam, bool bBumpUnits, bool bSuppressNotification);CivRegisterBefore<CivHooks::CvTeam_DoMakePeace>(host, &BeforeCvTeam_DoMakePeace);CivRegisterAfter<CivHooks::CvTeam_DoMakePeace>(host, &AfterCvTeam_DoMakePeace);CivRegisterReplace<CivHooks::CvTeam_DoMakePeace>(host, &ReplaceCvTeam_DoMakePeace);

Code

1587//	The make peace handler, can be called recursively1588#if defined(MOD_EVENTS_WAR_AND_PEACE)1589void CvTeam::DoMakePeace(PlayerTypes eOriginatingPlayer, bool bPacifier, TeamTypes eTeam, bool bBumpUnits, bool bSuppressNotification)1590#else1591void CvTeam::DoMakePeace(TeamTypes eTeam, bool bBumpUnits, bool bSuppressNotification)1592#endif1593{1594	CvString strBuffer;1595	int iI;15961597	CvAssertMsg(eTeam != NO_TEAM, "eTeam is not assigned a valid value");1598	CvAssertMsg(eTeam != GetID(), "eTeam is not expected to be equal with GetID()");15991600	if(isAtWar(eTeam))1601	{1602#if defined(MOD_EVENTS_WAR_AND_PEACE)1603		setAtWar(eTeam, false, bPacifier);1604		GET_TEAM(eTeam).setAtWar(GetID(), false, !bPacifier);1605#else1606		setAtWar(eTeam, false);1607		GET_TEAM(eTeam).setAtWar(GetID(), false);1608#endif16091610#if defined(MOD_EVENTS_WAR_AND_PEACE)1611		if (MOD_EVENTS_WAR_AND_PEACE) {1612			GAMEEVENTINVOKE_HOOK(GAMEEVENT_MakePeace, eOriginatingPlayer, eTeam, bPacifier);1613		} else {1614#endif1615		ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();1616		if (pkScriptSystem)1617		{1618			CvLuaArgsHandle args;1619			args->Push(GetID());1620			args->Push(eTeam);16211622			bool bResult;1623			LuaSupport::CallHook(pkScriptSystem, "MakePeace", args.get(), bResult);1624		}1625#if defined(MOD_EVENTS_WAR_AND_PEACE)1626		}1627#endif16281629		// One shot things1630		DoNowAtWarOrPeace(eTeam, false);1631		GET_TEAM(eTeam).DoNowAtWarOrPeace(GetID(), false);16321633		// Move Units that shouldn't be in each others' territory any more1634		if(bBumpUnits)1635		{1636			GC.getMap().verifyUnitValidPlot();1637		}16381639		// Both of us have now made a peace treaty.  Keep track of this in case either one breaks the agreement1640		int iCurrentTurn = GC.getGame().getElapsedGameTurns();1641		SetTurnMadePeaceTreatyWithTeam(eTeam, iCurrentTurn);1642		GET_TEAM(eTeam).SetTurnMadePeaceTreatyWithTeam(GetID(), iCurrentTurn);16431644		TeamTypes eTeamWeMadePeaceWith = eTeam;16451646		if(!isMinorCiv())1647		{1648			// Made peace with a minor - see if we have allied minors which should also make peace1649			if(GET_TEAM(eTeamWeMadePeaceWith).isMinorCiv())1650			{1651				PlayerTypes eOurMinor;1652				int iMinorLoop;16531654				PlayerTypes eOurPlayer;1655				int iPlayerLoop;16561657				PlayerTypes eThirdParty;1658				int iThirdPartyLoop;16591660				PlayerTypes eMakingPeaceWithMinor;1661				int iMakingPeaceWithMinorLoop;16621663				bool bPeaceBlocked;16641665				// Loop through all players to see if they're on our team1666				for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)1667				{1668					eOurPlayer = (PlayerTypes) iPlayerLoop;16691670					// Not on this team1671					if(GET_PLAYER(eOurPlayer).getTeam() != GetID())1672						continue;16731674					FStaticVector<PlayerTypes, MAX_CIV_PLAYERS, true, c_eCiv5GameplayDLL, 0> veMinorAllies;16751676					// Loop through minors to see if they're allied with us1677					for(iMinorLoop = MAX_MAJOR_CIVS; iMinorLoop < MAX_CIV_PLAYERS; iMinorLoop++)1678					{1679						eOurMinor = (PlayerTypes) iMinorLoop;16801681						// Minor not alive1682						if(!GET_PLAYER(eOurMinor).isAlive())1683							continue;16841685						// Allied with us1686						if(GET_PLAYER(eOurMinor).GetMinorCivAI()->GetAlly() == eOurPlayer)1687						{1688							bPeaceBlocked = false;16891690							// Now... see if there's another major allied to the minor we just made peace with, which would block OUR allied minor from making peace with him1691							for(iThirdPartyLoop = 0; iThirdPartyLoop < MAX_MAJOR_CIVS; iThirdPartyLoop++)1692							{1693								eThirdParty = (PlayerTypes) iThirdPartyLoop;16941695								for(iMakingPeaceWithMinorLoop = MAX_MAJOR_CIVS; iMakingPeaceWithMinorLoop < MAX_CIV_PLAYERS; iMakingPeaceWithMinorLoop++)1696								{1697									eMakingPeaceWithMinor = (PlayerTypes) iMakingPeaceWithMinorLoop;16981699									// Not on the team we're making peace with1700									if(!GET_PLAYER(eMakingPeaceWithMinor).getTeam() == eTeamWeMadePeaceWith)1701										continue;17021703									// Minor not alive1704									if(!GET_PLAYER(eMakingPeaceWithMinor).isAlive())1705										continue;17061707									if(GET_PLAYER(eMakingPeaceWithMinor).GetMinorCivAI()->GetAlly() == eThirdParty)1708									{1709										if(GET_TEAM(GET_PLAYER(eThirdParty).getTeam()).isAtWar(GET_PLAYER(eOurMinor).getTeam()))1710										{1711											bPeaceBlocked = true;1712											break;1713										}1714									}1715								}1716							}17171718							// Not at permanent war with this team1719							if(!bPeaceBlocked)1720							{1721								if(!GET_PLAYER(eOurMinor).GetMinorCivAI()->IsPermanentWar(eTeamWeMadePeaceWith))1722								{1723#if defined(MOD_EVENTS_WAR_AND_PEACE)1724									GET_TEAM(GET_PLAYER(eOurMinor).getTeam()).DoMakePeace(eOurMinor, bPacifier, eTeamWeMadePeaceWith, /*bBumpUnits*/ true, /*bSuppressNotification*/ true);1725#else1726									GET_TEAM(GET_PLAYER(eOurMinor).getTeam()).DoMakePeace(eTeamWeMadePeaceWith, /*bBumpUnits*/ true, /*bSuppressNotification*/ true);1727#endif1728									veMinorAllies.push_back(eOurMinor);1729								}1730							}1731						}1732					}17331734					// Send out a notification to us telling which of our minor allies made peace1735					if(!veMinorAllies.empty())1736					{1737						Localization::String strTemp = Localization::Lookup("TXT_KEY_MISC_YOUR_MINOR_ALLIES_MADE_PEACE");1738						Localization::String strSummary = Localization::Lookup("TXT_KEY_MISC_YOUR_MINOR_ALLIES_MADE_PEACE_SUMMARY");1739						strTemp << GET_TEAM(eTeam).getName().GetCString();1740						CvString strMessage = strTemp.toUTF8();17411742						for(uint iMinorCivLoop = 0; iMinorCivLoop < veMinorAllies.size(); iMinorCivLoop++)1743						{1744							PlayerTypes eMinor = veMinorAllies[iMinorCivLoop];1745							strTemp = Localization::Lookup(GET_TEAM(GET_PLAYER(eMinor).getTeam()).getName().GetCString());1746							strMessage = strMessage + "[NEWLINE]" + strTemp.toUTF8();1747						}17481749						if(GET_PLAYER(eOurPlayer).GetNotifications())1750							GET_PLAYER(eOurPlayer).GetNotifications()->Add(NOTIFICATION_PEACE, strMessage, strSummary.toUTF8(), -1, -1, veMinorAllies.front(), eTeam);1751					}1752				}1753			}1754		}17551756		// Update Interface1757		if((GetID() == GC.getGame().getActiveTeam()) || (eTeam == GC.getGame().getActiveTeam()))1758		{1759			DLLUI->setDirty(Score_DIRTY_BIT, true);1760			DLLUI->setDirty(CityInfo_DIRTY_BIT, true);1761		}17621763		// What does it mean when we make peace1764		CvPlayer* pOurPlayer;1765		PlayerTypes eOurPlayer;1766		for(int iOurPlayerLoop = 0; iOurPlayerLoop < MAX_CIV_PLAYERS; iOurPlayerLoop++)1767		{1768			eOurPlayer = (PlayerTypes) iOurPlayerLoop;1769			pOurPlayer = &GET_PLAYER(eOurPlayer);17701771			if(pOurPlayer->isAlive())1772			{1773				// Our Team1774				if(pOurPlayer->getTeam() == GetID())1775				{1776					pOurPlayer->GetDiplomacyAI()->DoWeMadePeaceWithSomeone(eTeam);1777					pOurPlayer->GetMilitaryAI()->LogPeace(eTeam);	// This is not quite correct, but it'll work well enough for AI testing1778				}1779				// Their Team1780				else if(pOurPlayer->getTeam() == eTeam)1781				{1782					pOurPlayer->GetDiplomacyAI()->DoWeMadePeaceWithSomeone(GetID());1783					pOurPlayer->GetMilitaryAI()->LogPeace(GetID());	// This is not quite correct, but it'll work well enough for AI testing1784				}1785			}1786		}17871788		Localization::String locString;17891790		// Text stuff1791		if(!bSuppressNotification)1792		{1793			PlayerTypes ePlayer;1794			for(iI = 0; iI < MAX_PLAYERS; iI++)1795			{1796				ePlayer = (PlayerTypes) iI;17971798				if(GET_PLAYER(ePlayer).isAlive())1799				{1800					if(GET_PLAYER(ePlayer).getTeam() == GetID())1801					{1802						if(GET_PLAYER(ePlayer).GetNotifications())1803						{1804							locString = Localization::Lookup("TXT_KEY_MISC_YOU_MADE_PEACE_WITH");1805							locString << GET_TEAM(eTeam).getName().GetCString();1806							GET_PLAYER(ePlayer).GetNotifications()->Add(NOTIFICATION_PEACE_ACTIVE_PLAYER, locString.toUTF8(), locString.toUTF8(), -1, -1, this->getLeaderID());1807						}1808					}1809					else if(GET_PLAYER(ePlayer).getTeam() == eTeam)1810					{1811						if(GET_PLAYER(ePlayer).GetNotifications())1812						{1813							locString = Localization::Lookup("TXT_KEY_MISC_YOU_MADE_PEACE_WITH");1814							locString << getName().GetCString();1815							GET_PLAYER(ePlayer).GetNotifications()->Add(NOTIFICATION_PEACE_ACTIVE_PLAYER, locString.toUTF8(), locString.toUTF8(), -1, -1, this->getLeaderID());1816						}1817					}1818					else if(GET_TEAM(GET_PLAYER(ePlayer).getTeam()).isHasMet(GetID()) && GET_TEAM(GET_PLAYER(ePlayer).getTeam()).isHasMet(eTeam))1819					{1820						if(GET_PLAYER(ePlayer).GetNotifications())1821						{1822							locString = Localization::Lookup("TXT_KEY_MISC_SOMEONE_MADE_PEACE");1823							locString << getName().GetCString() << GET_TEAM(eTeam).getName().GetCString();1824							GET_PLAYER(ePlayer).GetNotifications()->Add(NOTIFICATION_PEACE, locString.toUTF8(), locString.toUTF8(), -1, -1, this->getLeaderID(), eTeam);1825						}1826					}1827				}1828			}1829		}18301831		strBuffer = GetLocalizedText("TXT_KEY_MISC_SOMEONE_MADE_PEACE", getName().GetCString(), GET_TEAM(eTeam).getName().GetCString());1832		GC.getGame().addReplayMessage(REPLAY_MESSAGE_MAJOR_EVENT, getLeaderID(), strBuffer, -1, -1);1833	}1834}

Calls

Called by