Bazaar developer reference

CvGame::InitPlayers()

Defined in
CvGame.cpp, line 566
Class
CvGame
Hook name
CivHooks::CvGame_InitPlayers

Hooks

static bool BeforeCvGame_InitPlayers(CvGame* self);static void AfterCvGame_InitPlayers(CvGame* self);static void ReplaceCvGame_InitPlayers(void (*original)(CvGame*), CvGame* self);CivRegisterBefore<CivHooks::CvGame_InitPlayers>(host, &BeforeCvGame_InitPlayers);CivRegisterAfter<CivHooks::CvGame_InitPlayers>(host, &AfterCvGame_InitPlayers);CivRegisterReplace<CivHooks::CvGame_InitPlayers>(host, &ReplaceCvGame_InitPlayers);

Code

566void CvGame::InitPlayers()567{568	PlayerColorTypes aePlayerColors[REALLY_MAX_PLAYERS];569	bool bValid;570	int iI, iJ, iK, iL;571572	for(iI = 0; iI < MAX_TEAMS; iI++)573	{574		const TeamTypes eTeam(static_cast<TeamTypes>(iI));575		CvTeam& kTeam = GET_TEAM(eTeam);576		kTeam.init(eTeam);577	}578579	for(iI = 0; iI < REALLY_MAX_PLAYERS; iI++)580	{581		aePlayerColors[iI] = NO_PLAYERCOLOR;582	}583584	for(iI = 0; iI < MAX_MAJOR_CIVS; iI++)585	{586		const PlayerTypes eLoopPlayer(static_cast<PlayerTypes>(iI));587		aePlayerColors[iI] = CvPreGame::playerColor(eLoopPlayer);588589		if(aePlayerColors[iI] == NO_PLAYERCOLOR)590		{591			SlotStatus eStatus = CvPreGame::slotStatus(eLoopPlayer);592			if(eStatus == SS_TAKEN || eStatus == SS_COMPUTER || eStatus == SS_OBSERVER)593			{594				CvCivilizationInfo* pCivilizationInfo = GC.getCivilizationInfo(CvPreGame::civilization(eLoopPlayer));595				aePlayerColors[iI] = ((PlayerColorTypes)(pCivilizationInfo->getDefaultPlayerColor()));596			}597		}598	}599600	CivilizationTypes eBarbCiv = (CivilizationTypes)GC.getBARBARIAN_CIVILIZATION();601	CivilizationTypes eMinorCiv = (CivilizationTypes)GC.getMINOR_CIVILIZATION();602603	CvCivilizationInfo* pBarbarianCivilizationInfo = GC.getCivilizationInfo(eBarbCiv);604	int barbarianPlayerColor = pBarbarianCivilizationInfo->getDefaultPlayerColor();605606	const int iNumPlayerColorInfos = GC.GetNumPlayerColorInfos();607	for(iI = 0; iI < MAX_MAJOR_CIVS; iI++)608	{609		if(aePlayerColors[iI] != NO_PLAYERCOLOR)610		{611			for(iJ = 0; iJ < iI; iJ++)612			{613				if(aePlayerColors[iI] == aePlayerColors[iJ])614				{615					for(iK = 0; iK < iNumPlayerColorInfos; iK++)616					{617						if(iK != barbarianPlayerColor)618						{619							bValid = true;620621							for(iL = 0; iL < MAX_MAJOR_CIVS; iL++)622							{623								if(aePlayerColors[iL] == iK)624								{625									bValid = false;626									break;627								}628							}629630							if(bValid)631							{632								aePlayerColors[iI] = ((PlayerColorTypes)iK);633							}634						}635					}636637					break;638				}639			}640		}641	}642643	int iNumMinors = CvPreGame::numMinorCivs();644645	// TODO: this is needed till we have a screen to push this data646	if(iNumMinors < 0)647	{648		const CvWorldInfo& kWorldInfo = CvPreGame::worldInfo();649		iNumMinors = kWorldInfo.getDefaultMinorCivs();650	}651652	PlayerTypes eMinorPlayer;653654	// Players655	for(iI = 0; iI < MAX_PLAYERS; iI++)656	{657		// init Barbarian slot658		if(iI == BARBARIAN_PLAYER)659		{660			CvPreGame::setTeamType(BARBARIAN_PLAYER, BARBARIAN_TEAM);661			CvPreGame::setSlotStatus(BARBARIAN_PLAYER, SS_COMPUTER);662			CvPreGame::setNetID(BARBARIAN_PLAYER, -1);663			CvPreGame::setHandicap(BARBARIAN_PLAYER, (HandicapTypes)GC.getBARBARIAN_HANDICAP());664			CvPreGame::setCivilization(BARBARIAN_PLAYER, eBarbCiv);665			CvPreGame::setLeaderHead(BARBARIAN_PLAYER, (LeaderHeadTypes)GC.getBARBARIAN_LEADER());666			CvPreGame::setPlayerColor(BARBARIAN_PLAYER, ((PlayerColorTypes)barbarianPlayerColor));667			CvPreGame::setMinorCiv(BARBARIAN_PLAYER, false);668		}669		// Major Civs670		else if(iI < MAX_MAJOR_CIVS)671		{672			CvPreGame::setPlayerColor((PlayerTypes)iI, aePlayerColors[iI]);673			// Make sure the AI has the proper handicap.674			if(CvPreGame::slotStatus((PlayerTypes)iI) == SS_COMPUTER)675			{676				CvPreGame::setHandicap((PlayerTypes)iI, (HandicapTypes)GC.getAI_HANDICAP());677			}678			else if(CvPreGame::slotStatus((PlayerTypes)iI) == SS_OBSERVER)679			{//make all observers be on the observer team.680				CvPreGame::setTeamType((PlayerTypes)iI, OBSERVER_TEAM);681			}682		}683		// Minor civs684		else if(iI < MAX_CIV_PLAYERS)685		{686			eMinorPlayer = (PlayerTypes) iI;687688			if(iI < MAX_MAJOR_CIVS + iNumMinors)689			{690#if defined(MOD_GLOBAL_MAX_MAJOR_CIVS)691				CvMinorCivInfo* pMinorCivInfo = GC.getMinorCivInfo(CvPreGame::minorCivType((PlayerTypes) (eMinorPlayer + (MAX_PREGAME_MAJOR_CIVS - MAX_MAJOR_CIVS))));692#else693				CvMinorCivInfo* pMinorCivInfo = GC.getMinorCivInfo(CvPreGame::minorCivType(eMinorPlayer));694#endif695696				CvPreGame::setSlotStatus(eMinorPlayer, SS_COMPUTER);697				CvPreGame::setNetID(eMinorPlayer, -1);698				CvPreGame::setHandicap(eMinorPlayer, (HandicapTypes)GC.getMINOR_CIV_HANDICAP());699				CvPreGame::setCivilization(eMinorPlayer, eMinorCiv);700				CvPreGame::setLeaderHead(eMinorPlayer, (LeaderHeadTypes)GC.getBARBARIAN_LEADER());701				CvPreGame::setPlayerColor(eMinorPlayer, (PlayerColorTypes)pMinorCivInfo->getDefaultPlayerColor());702				CvPreGame::setMinorCiv(eMinorPlayer, true);703			}704		}705	}706707	for(iI = 0; iI < MAX_PLAYERS; iI++)708	{709		const PlayerTypes ePlayer = static_cast<PlayerTypes>(iI);710		CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);711712		kPlayer.init(ePlayer);713	}714}

Calls

Called by