Bazaar developer reference

CvPlayerCulture::ThemeEqualArtArtifact(CvGreatWorkBuildingInMyEmpire, int, int, vector<CvGreatWorkInMyEmpire> &, vector<CvGreatWorkInMyEmpire> &, bool)

Defined in
CvCultureClasses.cpp, line 1579
Class
CvPlayerCulture
Hook name
CivHooks::CvPlayerCulture_ThemeEqualArtArtifact

Hooks

static bool BeforeCvPlayerCulture_ThemeEqualArtArtifact(CvPlayerCulture* self, CvGreatWorkBuildingInMyEmpire kBldg, int iThemingBonusIndex, int iNumSlots, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, bool arg5, bool& result);static void AfterCvPlayerCulture_ThemeEqualArtArtifact(CvPlayerCulture* self, CvGreatWorkBuildingInMyEmpire kBldg, int iThemingBonusIndex, int iNumSlots, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, bool arg5, bool& result);static bool ReplaceCvPlayerCulture_ThemeEqualArtArtifact(bool (*original)(CvPlayerCulture*, CvGreatWorkBuildingInMyEmpire, int, int, vector<CvGreatWorkInMyEmpire> &, vector<CvGreatWorkInMyEmpire> &, bool), CvPlayerCulture* self, CvGreatWorkBuildingInMyEmpire kBldg, int iThemingBonusIndex, int iNumSlots, vector<CvGreatWorkInMyEmpire> & works1, vector<CvGreatWorkInMyEmpire> & works2, bool arg5);CivRegisterBefore<CivHooks::CvPlayerCulture_ThemeEqualArtArtifact>(host, &BeforeCvPlayerCulture_ThemeEqualArtArtifact);CivRegisterAfter<CivHooks::CvPlayerCulture_ThemeEqualArtArtifact>(host, &AfterCvPlayerCulture_ThemeEqualArtArtifact);CivRegisterReplace<CivHooks::CvPlayerCulture_ThemeEqualArtArtifact>(host, &ReplaceCvPlayerCulture_ThemeEqualArtArtifact);

Code

1578/// Specialized version of ThemeBuilding() that handles those buildings that are split between Art and Artifact1579bool CvPlayerCulture::ThemeEqualArtArtifact(CvGreatWorkBuildingInMyEmpire kBldg, int iThemingBonusIndex, int iNumSlots, vector<CvGreatWorkInMyEmpire> &works1, vector<CvGreatWorkInMyEmpire> &works2, bool /*bConsiderOtherPlayers*/)1580{1581	CvGameCulture *pkGameCulture = GC.getGame().GetGameCulture();15821583	vector<CvGreatWorkInMyEmpire>::const_iterator it;1584	vector<CvGreatWorkInMyEmpire>::iterator it5;1585	vector<CvGreatWorkInMyEmpire> tempWorks;15861587	vector<int> aArtifactsChosen;1588	vector<PlayerTypes> aArtifactsPlayersSeen;1589	vector<EraTypes> aArtifactsErasSeen;15901591	int iWorksInHalf = iNumSlots / 2;1592	if (iWorksInHalf % 2 != 0 || (int)works1.size() < iWorksInHalf || (int)works2.size() < iWorksInHalf)1593	{1594		return false;1595	}15961597	CvBuildingEntry *pkEntry = GC.getBuildingInfo(kBldg.m_eBuilding);1598	if (!pkEntry || pkEntry->GetGreatWorkCount() < 2)1599	{1600		return false;1601	}16021603	CvThemingBonusInfo *pkBonusInfo = pkEntry->GetThemingBonusInfo(iThemingBonusIndex);16041605	// Try each of the Artifacts as the starter1606	for (it = works2.begin(); it != works2.end(); it++)1607	{1608		// First, make sure this "starter" is valid1609		if (pkBonusInfo->IsRequiresOwner() && it->m_ePlayer != m_pPlayer->GetID())1610		{1611			continue;1612		}1613		if (pkBonusInfo->IsRequiresAnyButOwner() && it->m_ePlayer == m_pPlayer->GetID())1614		{1615			continue;1616		}16171618		aArtifactsChosen.clear();1619		aArtifactsPlayersSeen.clear();1620		aArtifactsErasSeen.clear();16211622		aArtifactsChosen.push_back(it->m_iGreatWorkIndex);1623		aArtifactsPlayersSeen.push_back(it->m_ePlayer);1624		aArtifactsErasSeen.push_back(it->m_eEra);16251626		// Loop through the rest looking for works that will match up1627		vector<CvGreatWorkInMyEmpire>::const_iterator it2 = it;1628		for (it2++; it2 != works2.end() && aArtifactsChosen.size() < (unsigned int)iWorksInHalf; it2++)1629		{1630			if (CultureHelpers::IsValidForThemingBonus(pkBonusInfo, it2->m_eEra, aArtifactsErasSeen, it2->m_ePlayer, aArtifactsPlayersSeen, m_pPlayer->GetID()))1631			{1632				aArtifactsChosen.push_back(it2->m_iGreatWorkIndex);1633				aArtifactsPlayersSeen.push_back(it2->m_ePlayer);1634				aArtifactsErasSeen.push_back(it2->m_eEra);1635			}1636		}16371638		// Do we have the right amount of art?1639		if (aArtifactsChosen.size() == iWorksInHalf)1640		{1641			vector<int> aWorksChosen;1642			vector<PlayerTypes> aPlayersSeen;1643			vector<EraTypes> aErasSeen;16441645			// Now see if we can get the right number of art works to work as well1646			vector<CvGreatWorkInMyEmpire>::const_iterator it3;1647			for (it3 = works1.begin(); it3 != works1.end() && aWorksChosen.size() < (unsigned int)iNumSlots; it3++)1648			{1649				// First, make sure this "starter" is valid1650				if (pkBonusInfo->IsRequiresOwner() && it3->m_ePlayer != m_pPlayer->GetID())1651				{1652					continue;1653				}1654				if (pkBonusInfo->IsRequiresAnyButOwner() && it3->m_ePlayer == m_pPlayer->GetID())1655				{1656					continue;1657				}1658				if (pkBonusInfo->IsSameEra() && it3->m_eEra != aArtifactsErasSeen[0])1659				{1660					continue;1661				}1662				if (pkBonusInfo->IsUniqueEras() && find(aArtifactsErasSeen.begin(), aArtifactsErasSeen.end(), it3->m_eEra) != aArtifactsErasSeen.end())1663				{1664					continue;1665				}1666#if defined(MOD_API_EXTENSIONS)1667				// ConsecutiveEras implies UniqueEras, so we don't need any tests in addition to those for UniqueEras1668#endif16691670				aWorksChosen = aArtifactsChosen;1671				aPlayersSeen = aArtifactsPlayersSeen;1672				aErasSeen = aArtifactsErasSeen;16731674				aWorksChosen.push_back(it3->m_iGreatWorkIndex);1675				aPlayersSeen.push_back(it3->m_ePlayer);1676				aErasSeen.push_back(it3->m_eEra);16771678				// Loop through the rest looking for works that will match up1679				vector<CvGreatWorkInMyEmpire>::const_iterator it4 = it3;1680				for (it4++; it4 != works1.end() && aWorksChosen.size() < (unsigned int)iNumSlots; it4++)1681				{1682					if (CultureHelpers::IsValidForThemingBonus(pkBonusInfo, it4->m_eEra, aErasSeen, it4->m_ePlayer, aPlayersSeen, m_pPlayer->GetID()))1683					{1684						aWorksChosen.push_back(it4->m_iGreatWorkIndex);1685						aPlayersSeen.push_back(it4->m_ePlayer);1686						aErasSeen.push_back(it4->m_eEra);1687					}1688				}16891690				// Did we theme it properly?1691				bool bThemedProperly = false;1692				if (aWorksChosen.size() == iNumSlots && CultureHelpers::GetThemingBonusIndex(m_pPlayer->GetID(), pkEntry, aWorksChosen) == iThemingBonusIndex)1693				{1694					bThemedProperly = true;1695				}16961697				// If we are one work short, let's look to other players for a last piece of art1698				else if (aWorksChosen.size() == (iNumSlots - 1))1699				{1700					for (int iLoopPlayer = 0; iLoopPlayer < MAX_MAJOR_CIVS; iLoopPlayer++)1701					{1702						CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iLoopPlayer);1703						if (kPlayer.isAlive() && m_pPlayer->GetDiplomacyAI()->IsPlayerValid((PlayerTypes)iLoopPlayer))1704						{1705							int iToBeAcquiredWorkIndex = kPlayer.GetCulture()->GetSwappableArtIndex();1706							int iToBeDiscardedWorkIndex = CultureHelpers::FindWorkNotChosen(works1, aWorksChosen);17071708							// Does this work fit?1709							if (iToBeAcquiredWorkIndex != NO_GREAT_WORK && iToBeDiscardedWorkIndex != NO_GREAT_WORK)1710							{1711								EraTypes eEra = pkGameCulture->m_CurrentGreatWorks[iToBeAcquiredWorkIndex].m_eEra;1712								PlayerTypes ePlayer = pkGameCulture->GetGreatWorkCreator(iToBeAcquiredWorkIndex);1713								if (CultureHelpers::IsValidForThemingBonus(pkBonusInfo, eEra, aErasSeen, ePlayer, aPlayersSeen, m_pPlayer->GetID()))1714								{1715									aWorksChosen.push_back(iToBeAcquiredWorkIndex);1716									if (CultureHelpers::GetThemingBonusIndex(m_pPlayer->GetID(), pkEntry, aWorksChosen) == iThemingBonusIndex)1717									{1718										bool bSwapSuccessful = pkGameCulture->SwapGreatWorks(m_pPlayer->GetID(), iToBeDiscardedWorkIndex, ePlayer, iToBeAcquiredWorkIndex);1719										if (bSwapSuccessful)1720										{1721											bThemedProperly = true;17221723											// Update works list1724											tempWorks.clear();1725											for (it5 = works1.begin(); it5 != works1.end(); it5++)1726											{1727												if (it5->m_iGreatWorkIndex == iToBeDiscardedWorkIndex)1728												{1729													it5->m_iGreatWorkIndex = iToBeAcquiredWorkIndex;1730													GetGreatWorkLocation(it5->m_iGreatWorkIndex, it5->m_iCityID, it5->m_eBuilding, it5->m_iSlot);1731												}1732												tempWorks.push_back(*it5);1733											}1734											works1 = tempWorks;17351736											CultureHelpers::SendArtSwapNotification(pkEntry->GetGreatWorkSlotType(), pkBonusInfo->IsMustBeArt(), m_pPlayer->GetID(), ePlayer, iToBeDiscardedWorkIndex, iToBeAcquiredWorkIndex);1737											break;  // Themed it through acquisition1738										}1739									}1740								}1741							}1742						}1743					}1744				}17451746				if (bThemedProperly)1747				{1748					for (int jJ = 0; jJ < (int)aWorksChosen.size(); jJ++)1749					{1750						for (int kK = 0; kK < (int)works1.size(); kK++)1751						{1752							if (works1[kK].m_iGreatWorkIndex == aWorksChosen[jJ])1753							{1754								MoveWorkIntoSlot(works1[kK], kBldg.m_iCityID, kBldg.m_eBuilding, jJ);1755								break;1756							}1757						}1758						for (int kK = 0; kK < (int)works2.size(); kK++)1759						{1760							if (works2[kK].m_iGreatWorkIndex == aWorksChosen[jJ])1761							{1762								MoveWorkIntoSlot(works2[kK], kBldg.m_iCityID, kBldg.m_eBuilding, jJ);1763								break;1764							}1765						}1766					}17671768					// Remove these works from those to consider later1769					tempWorks.clear();1770					for (it5 = works1.begin(); it5 != works1.end(); it5++)1771					{1772						// Copy it over if not chosen, updating its location1773						if (find(aWorksChosen.begin(), aWorksChosen.end(), it5->m_iGreatWorkIndex) == aWorksChosen.end())1774						{1775							GetGreatWorkLocation(it5->m_iGreatWorkIndex, it5->m_iCityID, it5->m_eBuilding, it5->m_iSlot);1776							tempWorks.push_back(*it5);1777						}1778					}1779					works1 = tempWorks;17801781					tempWorks.clear();1782					for (it5 = works2.begin(); it5 != works2.end(); it5++)1783					{1784						// Copy it over if not chosen, updating its location1785						if (find(aWorksChosen.begin(), aWorksChosen.end(), it5->m_iGreatWorkIndex) == aWorksChosen.end())1786						{1787							GetGreatWorkLocation(it5->m_iGreatWorkIndex, it5->m_iCityID, it5->m_eBuilding, it5->m_iSlot);1788							tempWorks.push_back(*it5);1789						}1790					}1791					works2 = tempWorks;17921793					// All done1794					LogThemedBuilding(kBldg.m_iCityID, kBldg.m_eBuilding, pkBonusInfo->GetBonus());1795					return true;1796				}1797			}1798		}1799	}1800	return false;1801}

Calls

Called by