Bazaar developer reference

CultureHelpers::GetArtifact(CvPlot *)

Defined in
CvCultureClasses.cpp, line 5442
Hook name
CivHooks::CultureHelpers_GetArtifact

Hooks

static bool BeforeCultureHelpers_GetArtifact(CvPlot * pPlot, GreatWorkType& result);static void AfterCultureHelpers_GetArtifact(CvPlot * pPlot, GreatWorkType& result);static GreatWorkType ReplaceCultureHelpers_GetArtifact(GreatWorkType (*original)(CvPlot *), CvPlot * pPlot);CivRegisterBefore<CivHooks::CultureHelpers_GetArtifact>(host, &BeforeCultureHelpers_GetArtifact);CivRegisterAfter<CivHooks::CultureHelpers_GetArtifact>(host, &AfterCultureHelpers_GetArtifact);CivRegisterReplace<CivHooks::CultureHelpers_GetArtifact>(host, &ReplaceCultureHelpers_GetArtifact);

Code

5441/// Build a name for this artifact5442GreatWorkType CultureHelpers::GetArtifact(CvPlot *pPlot)5443{5444	CvArchaeologyData archData = pPlot->GetArchaeologicalRecord();54455446	// Writing?  If so we already know which one it is5447	if (archData.m_eArtifactType == CvTypes::getARTIFACT_WRITING())5448	{5449		return archData.m_eWork;5450	}54515452	// Otherwise normal retrieval of Great Work5453	GreatWorkType eGreatWork = NO_GREAT_WORK;54545455	//Developer Note:5456	//This could probably be shrunk down into a single SQL query but for now I'll leave it as 2.5457	//The idea here is that we grab all possible items for a specific era and then pick 1 at random.5458	//If there are no items for that era, we use NULL and grab those items.5459	//Since era-agnostic and era-specific items are mutually exclusive, we must first check for the the 5460	//existence of era-specific items.5461	const char* szSql = "SELECT gw.ID FROM GreatWorks as gw "5462						"left outer join Eras on gw.EraType == Eras.Type "5463						"inner join GreatWorkArtifactClasses on gw.ArtifactClassType == GreatWorkArtifactClasses.Type "5464						"where gw.GreatWorkClassType = 'GREAT_WORK_ARTIFACT' and Eras.ID is ? and GreatWorkArtifactClasses.ID == ? "5465						"order by Random() limit 1;";54665467	const char* szExistsSQL =	"select 1 from GreatWorks as gw "5468								"inner join Eras on gw.EraType == Eras.Type "5469								"inner join GreatWorkArtifactClasses on gw.ArtifactClassType == GreatWorkArtifactClasses.Type "5470								"where gw.GreatWorkClassType = 'GREAT_WORK_ARTIFACT' and Eras.ID = ? and GreatWorkArtifactClasses.ID == ? Limit 1;";54715472	Database::Connection* db = GC.GetGameDatabase();54735474	bool bHasEraSpecificItems = false;54755476	if(archData.m_eEra != NO_ERA)5477	{5478		Database::Results kEraItemsExistQ;5479		if(db->Execute(kEraItemsExistQ, szExistsSQL))5480		{5481			kEraItemsExistQ.Bind(1, archData.m_eEra);5482			kEraItemsExistQ.Bind(2, archData.m_eArtifactType);54835484			if(kEraItemsExistQ.Step())5485			{5486				bHasEraSpecificItems = true;	5487			}5488		}5489	}54905491	Database::Results kQuery;5492	if(db->Execute(kQuery, szSql))5493	{5494		if(bHasEraSpecificItems == true)5495			kQuery.Bind(1, archData.m_eEra);5496		else5497			kQuery.BindNULL(1);54985499		kQuery.Bind(2, archData.m_eArtifactType);55005501		if(kQuery.Step())5502		{5503			eGreatWork = static_cast<GreatWorkType>(kQuery.GetInt(0));5504		}5505	}55065507	return eGreatWork;5508}

Calls

Called by