Bazaar developer reference

CvGame::countSeqHumanTurnsUntilPlayerTurn(PlayerTypes) const

Defined in
CvGame.cpp, line 3926
Class
CvGame
Hook name
CivHooks::CvGame_countSeqHumanTurnsUntilPlayerTurn

Hooks

static bool BeforeCvGame_countSeqHumanTurnsUntilPlayerTurn(const CvGame* self, PlayerTypes playerID, int& result);static void AfterCvGame_countSeqHumanTurnsUntilPlayerTurn(const CvGame* self, PlayerTypes playerID, int& result);static int ReplaceCvGame_countSeqHumanTurnsUntilPlayerTurn(int (*original)(const CvGame*, PlayerTypes), const CvGame* self, PlayerTypes playerID);CivRegisterBefore<CivHooks::CvGame_countSeqHumanTurnsUntilPlayerTurn>(host, &BeforeCvGame_countSeqHumanTurnsUntilPlayerTurn);CivRegisterAfter<CivHooks::CvGame_countSeqHumanTurnsUntilPlayerTurn>(host, &AfterCvGame_countSeqHumanTurnsUntilPlayerTurn);CivRegisterReplace<CivHooks::CvGame_countSeqHumanTurnsUntilPlayerTurn>(host, &ReplaceCvGame_countSeqHumanTurnsUntilPlayerTurn);

Code

3926int CvGame::countSeqHumanTurnsUntilPlayerTurn( PlayerTypes playerID ) const3927{//This function counts the number of sequential human player turns that remain before this player's turn.3928	int humanTurnsUntilMe = 0;3929	bool startCountingPlayers = false;3930	CvPlayer& targetPlayer = GET_PLAYER(playerID);3931	if(targetPlayer.isSimultaneousTurns())3932	{//target player is playing simultaneous turns and is not actually in the sequential turn sequence.3933		//Count every human player in sequential turn mode who is taking or hasn't taken their turn.3934		for(int i = 0; i < MAX_PLAYERS; ++i)3935		{3936			CvPlayer& kCurrentPlayer = GET_PLAYER((PlayerTypes)i);3937			if(kCurrentPlayer.isHuman() 3938				&& kCurrentPlayer.isAlive() 3939				&& !kCurrentPlayer.isSimultaneousTurns())3940			{//another human player who is playing sequential turns.3941				if(kCurrentPlayer.isTurnActive())3942				{//This player is currently playing their turn. Start counting human players after this point.3943					startCountingPlayers = true;3944					humanTurnsUntilMe++;3945				}3946				else if(startCountingPlayers)3947				{//This is a human player who's before us in line.3948					humanTurnsUntilMe++;3949				}3950			}3951		}	3952	}3953	else3954	{//target player is playing sequential turns.  3955		//Our next turn will begin after every sequential player has finished this turn 3956		//AND everyone ahead of us in the sequence has finished their turn for the NEXT turn.39573958		//Starting after us, count every player who's playing sequential turns.3959		startCountingPlayers = false;3960		int curPlayerIdx = (targetPlayer.GetID()+1)%MAX_PLAYERS;3961		for(int i = 0; i < MAX_PLAYERS; curPlayerIdx = ++curPlayerIdx%MAX_PLAYERS, ++i)3962		{3963			CvPlayer& kCurrentPlayer = GET_PLAYER((PlayerTypes)curPlayerIdx);3964			if(kCurrentPlayer.GetID() == targetPlayer.GetID())3965			{//This is us.  We've looped back to ourself.  We're done.3966				break;3967			}3968			else if(kCurrentPlayer.isHuman() 3969				&& kCurrentPlayer.isAlive() 3970				&& !kCurrentPlayer.isSimultaneousTurns())3971			{//another human player who is playing sequential turns.3972				if(kCurrentPlayer.isTurnActive())3973				{//This player is currently playing their turn. Start counting human players after this point.3974					startCountingPlayers = true;3975					humanTurnsUntilMe++;3976				}3977				else if(startCountingPlayers)3978				{//This is a human player who's before us in line.3979					humanTurnsUntilMe++;3980				}3981			}3982		}	3983	}39843985	return humanTurnsUntilMe;3986}

Calls

Called by