Bazaar developer reference

CvPreGame::setLeaderKey(PlayerTypes, const CvString &)

Defined in
CvPreGame.cpp, line 2658
Hook name
CivHooks::CvPreGame_setLeaderKey

Hooks

static bool BeforeCvPreGame_setLeaderKey(PlayerTypes p, const CvString& szKey);static void AfterCvPreGame_setLeaderKey(PlayerTypes p, const CvString& szKey);static void ReplaceCvPreGame_setLeaderKey(void (*original)(PlayerTypes, const CvString&), PlayerTypes p, const CvString& szKey);CivRegisterBefore<CivHooks::CvPreGame_setLeaderKey>(host, &BeforeCvPreGame_setLeaderKey);CivRegisterAfter<CivHooks::CvPreGame_setLeaderKey>(host, &AfterCvPreGame_setLeaderKey);CivRegisterReplace<CivHooks::CvPreGame_setLeaderKey>(host, &ReplaceCvPreGame_setLeaderKey);

Code

2658void setLeaderKey(PlayerTypes p, const CvString& szKey)2659{2660	if(p >= 0 && p < MAX_PLAYERS)2661	{2662		s_leaderKeys[p] = szKey;2663		// Check to see if this is available, if not, set the index to NO_LEADER and the package ID to invalid2664		// The key will stay valid2665		bool bFailed = true;2666		if(szKey.length() > 0)2667		{2668			// During the pre-game, we can't be sure the cached *Infos are current, so query the database2669			Database::Connection* pDB = GC.GetGameDatabase();2670			if(pDB)2671			{2672				Database::Results kResults;2673				if(pDB->Execute(kResults, "SELECT ID, PackageID from Leaders where Type = ? LIMIT 1"))2674				{2675					kResults.Bind(1, szKey.c_str());2676					if(kResults.Step())2677					{2678						s_leaderHeads.setAt(p, (LeaderHeadTypes)kResults.GetInt(0));2679						if(!ExtractGUID(kResults.GetText(1), s_leaderPackageID[p]))2680							ClearGUID(s_leaderPackageID[p]);2681						s_leaderKeysAvailable[p] = true;2682						bFailed = false;2683					}2684				}2685			}2686		}26872688		if(bFailed)2689		{2690			s_leaderHeads.setAt(p, NO_LEADER);2691			ClearGUID(s_leaderPackageID[p]);2692			s_leaderKeysAvailable[p] = (szKey.length() == 0);	// If the key was empty, then it is the 'random' state so it is available2693		}2694	}2695}

Calls

Called by