Bazaar developer reference

CvPreGame::setCivilizationKey(PlayerTypes, const CvString &)

Defined in
CvPreGame.cpp, line 3404
Hook name
CivHooks::CvPreGame_setCivilizationKey

Hooks

static bool BeforeCvPreGame_setCivilizationKey(PlayerTypes p, const CvString& szKey);static void AfterCvPreGame_setCivilizationKey(PlayerTypes p, const CvString& szKey);static void ReplaceCvPreGame_setCivilizationKey(void (*original)(PlayerTypes, const CvString&), PlayerTypes p, const CvString& szKey);CivRegisterBefore<CivHooks::CvPreGame_setCivilizationKey>(host, &BeforeCvPreGame_setCivilizationKey);CivRegisterAfter<CivHooks::CvPreGame_setCivilizationKey>(host, &AfterCvPreGame_setCivilizationKey);CivRegisterReplace<CivHooks::CvPreGame_setCivilizationKey>(host, &ReplaceCvPreGame_setCivilizationKey);

Code

3403// Set the unique key value for the civilization3404void setCivilizationKey(PlayerTypes p, const CvString& szKey)3405{3406	if(p >= 0 && p < MAX_PLAYERS)3407	{3408		s_civilizationKeys[p] = szKey;34093410		// Check to see if this is available, if not, set the index to NO_CIVILIZATION and the package ID to invalid3411		// The key will stay valid3412		bool bFailed = true;3413		if(szKey.length() > 0)3414		{3415			// During the pre-game, we can't be sure the cached *Infos are current, so query the database3416			Database::Connection* pDB = GC.GetGameDatabase();3417			if(pDB)3418			{3419				Database::Results kResults;3420				if(pDB->Execute(kResults, "SELECT ID, PackageID, Playable from Civilizations where Type = ? LIMIT 1"))3421				{3422					kResults.Bind(1, szKey.c_str());3423					if(kResults.Step())3424					{3425						s_civilizations.setAt(p, (CivilizationTypes)kResults.GetInt(0));3426						if(!ExtractGUID(kResults.GetText(1), s_civilizationPackageID[p]))3427							ClearGUID(s_civilizationPackageID[p]);3428						s_civilizationKeysAvailable[p] = true;3429						s_civilizationKeysPlayable[p] = kResults.GetBool(2);3430						bFailed = false;3431					}3432				}3433			}3434		}34353436		if(bFailed)3437		{3438			s_civilizations.setAt(p, NO_CIVILIZATION);3439			ClearGUID(s_civilizationPackageID[p]);3440			s_civilizationKeysAvailable[p] = (szKey.length() == 0);	// If the key was empty, then it is the 'random' state so it is available3441			s_civilizationKeysPlayable[p] = s_civilizationKeysAvailable[p];3442		}3443	}3444}

Calls

Called by