Bazaar developer reference

CvDllDatabaseUtility::PerformDatabasePostProcessing()

Defined in
CvDllDatabaseUtility.cpp, line 203
Class
CvDllDatabaseUtility
Hook name
CivHooks::CvDllDatabaseUtility_PerformDatabasePostProcessing

Hooks

static bool BeforeCvDllDatabaseUtility_PerformDatabasePostProcessing(CvDllDatabaseUtility* self, bool& result);static void AfterCvDllDatabaseUtility_PerformDatabasePostProcessing(CvDllDatabaseUtility* self, bool& result);static bool ReplaceCvDllDatabaseUtility_PerformDatabasePostProcessing(bool (*original)(CvDllDatabaseUtility*), CvDllDatabaseUtility* self);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvDllDatabaseUtility_PerformDatabasePostProcessing::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvDllDatabaseUtility_PerformDatabasePostProcessing);host->RegisterHook(host->pluginIndex, CivHooks::CvDllDatabaseUtility_PerformDatabasePostProcessing::ID, CIV_HOOK_AFTER, (void*)&AfterCvDllDatabaseUtility_PerformDatabasePostProcessing);host->RegisterHook(host->pluginIndex, CivHooks::CvDllDatabaseUtility_PerformDatabasePostProcessing::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvDllDatabaseUtility_PerformDatabasePostProcessing);

Code

203bool CvDllDatabaseUtility::PerformDatabasePostProcessing()204{205	//Insert any database methods that you would like performed after the database206	//has been fully loaded.  This method will execute every single time the game207	//is run.208	//Updates performed here are done AFTER the database has been built or read209	//from cache.210	Database::Connection* db = GC.GetGameDatabase();211212	//Update Defines table from references in PostDefines table213	db->BeginTransaction();214	Database::Results kPostDefines;215216	//Build insertion statement217	Database::Results kInsert;218	db->Execute(kInsert, "INSERT OR REPLACE INTO Defines(Name, Value) VALUES(?, ?)");219220	db->SelectAll(kPostDefines, "PostDefines");221	while(kPostDefines.Step())222	{223		const char* szName = kPostDefines.GetText("Name");224		const char* szKeyName = kPostDefines.GetText("Key");225		const char* szTableName = kPostDefines.GetText("Table");226		char szSQL[512];227228		sprintf_s(szSQL, "select ROWID from %s where Type = '%s' LIMIT 1", szTableName, szKeyName);229230		Database::Results kLookup;231232		//Compile the command.233		if(db->Execute(kLookup, szSQL))234		{235			//Run the command.236			if(kLookup.Step())237			{238				//Perform insertion239				kInsert.Bind(1, szName);240				kInsert.Bind(2, kLookup.GetInt(0));241				kInsert.Step();242				kInsert.Reset();243			}244		}245	}246247	// ** Modify ResourceUsage of Resources table **248	// Set ResourceUsage to 1 if it's referenced in Unit_ResourceQuantityRequirements249	// NOTE: This query could be simplified using the IN operator but when analyzed this250	//			statement generates faster operations.251	const char* szStrategicResource252	    = "UPDATE Resources SET ResourceUsage = 1 WHERE EXISTS (SELECT * FROM Unit_ResourceQuantityRequirements WHERE ResourceType = Type)";253	db->Execute(szStrategicResource);254255	// Set ResourceUsage to 2 if the Resource has a happiness value greater than 0256	const char* szLuxoryResource257	    = "UPDATE Resources SET ResourceUsage = 2 where Happiness > 0";258	db->Execute(szLuxoryResource);259260	//These are hard-coded GameDefines enum values, let's share them with the database so that they261	//get the same amount of love as the DB.262	Database::Results kInsertDefine;263	if(db->Execute(kInsertDefine, "INSERT OR REPLACE INTO Defines(Name, Value) VALUES(?, ?);"))264	{265		InsertGameDefine(kInsertDefine, "MAX_CIV_PLAYERS", MAX_CIV_PLAYERS);266		InsertGameDefine(kInsertDefine, "MAX_CIV_TEAMS", MAX_CIV_TEAMS);267		InsertGameDefine(kInsertDefine, "MAX_MAJOR_CIVS", MAX_MAJOR_CIVS);268		InsertGameDefine(kInsertDefine, "MAX_MINOR_CIVS", MAX_MINOR_CIVS);269		InsertGameDefine(kInsertDefine, "MAX_PLAYERS", MAX_PLAYERS);270		InsertGameDefine(kInsertDefine, "MAX_TEAMS", MAX_TEAMS);271		InsertGameDefine(kInsertDefine, "BARBARIAN_PLAYER", BARBARIAN_PLAYER);272		InsertGameDefine(kInsertDefine, "BARBARIAN_TEAM", BARBARIAN_TEAM);273274#if defined(MOD_GLOBAL_CITY_WORKING)275		InsertGameDefine(kInsertDefine, "NUM_CITY_PLOTS", AVG_CITY_PLOTS);276		InsertGameDefine(kInsertDefine, "MIN_CITY_RADIUS", MIN_CITY_RADIUS);277		InsertGameDefine(kInsertDefine, "MAX_CITY_RADIUS", MAX_CITY_RADIUS);278#else279		InsertGameDefine(kInsertDefine, "NUM_CITY_PLOTS", NUM_CITY_PLOTS);280#endif281		InsertGameDefine(kInsertDefine, "CITY_HOME_PLOT", CITY_HOME_PLOT);282#if defined(MOD_GLOBAL_CITY_WORKING)283		InsertGameDefine(kInsertDefine, "MAX_CITY_RADIUS", MAX_CITY_RADIUS);284		InsertGameDefine(kInsertDefine, "MAX_CITY_DIAMETER", (2*MAX_CITY_RADIUS+1));285#else286		InsertGameDefine(kInsertDefine, "CITY_PLOTS_RADIUS", CITY_PLOTS_RADIUS);287		InsertGameDefine(kInsertDefine, "CITY_PLOTS_DIAMETER", CITY_PLOTS_DIAMETER);288#endif289	}290291	db->EndTransaction();292293	return true;294}

Calls