Two turn zeros

The Great Apple

Big Cheese
Joined
Mar 24, 2002
Messages
3,361
Location
Oxford, England
That's right. Two. The first turn is turn zero, and so is the second turn. Anybody any idea why? It's really quite frustrating, as I'm trying to write a script to restart the game at the first turn (the first turn zero), but CvGame::setGameTurn(int iNewValue) sets the turn to, you guessed it, the second turn zero. I would really much prefer to be on the first turn zero. Anybody any idea how to accomplish this?
 
The Great Apple said:
That's right. Two. The first turn is turn zero, and so is the second turn. Anybody any idea why? It's really quite frustrating, as I'm trying to write a script to restart the game at the first turn (the first turn zero), but CvGame::setGameTurn(int iNewValue) sets the turn to, you guessed it, the second turn zero. I would really much prefer to be on the first turn zero. Anybody any idea how to accomplish this?

Could it be an issue switching from BC to AD?

I notice I never have the problem when I start at year 1.
 
So when you start at year 1 CyGame().getGameTurn() returns 0 on the first turn, and 0 on the second turn (just to confirm this).
 
The Great Apple said:
So when you start at year 1 CyGame().getGameTurn() returns 0 on the first turn, and 0 on the second turn (just to confirm this).


Are you looking at turns, or years? Because for me, on the first turn, CyGame().getGameTurn() returns 0, and on the second turn it returns 1.
 
Really? I'll just check again... Ok. You're right. I'm sure it didn't used to do that...

I know that CvGame::setGameTurn(0) shoves me back to 3940 BC however. This might stick on extra turn on at the end. I dunno. 1 turn either way isn't that much of a big deal - I just want it to look neat ;)
 
The Great Apple said:
Really? I'll just check again... Ok. You're right. I'm sure it didn't used to do that...

I know that CvGame::setGameTurn(0) shoves me back to 3940 BC however. This might stick on extra turn on at the end. I dunno. 1 turn either way isn't that much of a big deal - I just want it to look neat ;)

CvGame::setGameTurn(0) brings me back to 4000 BC. It's interesting that you get 3940, because typically it goes 4000 -> 4960 ->4920, doesn't it? Unless I changed the way years are calculated without realizing it using Civcraft without realizing it. Are you calling this within a script, or just from the console inside Civ? I'm using the console.
 
A script - the same one as I posted in the other post. I must admit that I didn't completely confim this as I came accross it before in a previous patch version.

3940 is because I have the gamespeed set on "quick".
 
The Great Apple said:
A script - the same one as I posted in the other post. I must admit that I didn't completely confim this as I came accross it before in a previous patch version.

3940 is because I have the gamespeed set on "quick".

Oh yeah, forgot about that :P

The reason I was wondering about the script is that I didn't know if perhaps the event that the script is making the code run later on would increment the turn anyway, so after the script sets it to turn 0, more events happen and then the turn increments to 1 before the interface even has a chance to update.
 
I have tested, and it is something do with my script. I thought it was slightly crazy, but I thought I remembered the behaviour from a previous, completely different, experiment.
 
The Great Apple said:
I have tested, and it is something do with my script. I thought it was slightly crazy, but I thought I remembered the behaviour from a previous, completely different, experiment.

I realized I forgot to post this in the other thread (i had it in the box, but forgot to put it back in when I accidently closed my browser). Not sure if you're still suffering the problem:

The hooks onBeginPlayerTurn, onEndPlayerTurn, onBeginGameTurn, and onEndGameTurn are all called at some point within the CvGame::doTurn function. The problem is that they all get called before the game increments the turn. The game doesn't increment what turn it is at the beginning of a turn, but at the end of the previous turn. I'd recommend perhaps throwing down another hook similar to onEndGameTurn that allows you to make a newGame after the game increments the turn.

Code:
void CvGame::doTurn()
{
	PROFILE_BEGIN("CvGame::doTurn()");

	int aiShuffle[MAX_PLAYERS];
	int iLoopPlayer;
	int iI;

	// END OF TURN
	[b] // I'm not sure what's up with that above comment, but this is the onBeginGameTurn hook [/b]
	gDLL->getEventReporterIFace()->beginGameTurn( getGameTurn() );

	updateScore();

	doDeals();

	for (iI = 0; iI < MAX_TEAMS; iI++)
	{
		if (GET_TEAM((TeamTypes)iI).isAlive())
		{
			[b] // onBeginPlayerTurn and onEndPlayerTurn are in this call.[/b]
			GET_TEAM((TeamTypes)iI).doTurn();
		}
	}

	GC.getMapINLINE().doTurn();

	createBarbarianCities();

	createBarbarianUnits();

	doGlobalWarming();

	doHolyCity();

	doDiploVote();

	gDLL->getInterfaceIFace()->setEndTurnMessage(false);
	gDLL->getInterfaceIFace()->setHasMovedUnit(false);

	if (getAIAutoPlay() > 0)
	{
		changeAIAutoPlay(-1);

		if (getAIAutoPlay() == 0)
		{
			reviveActivePlayer();
		}
	}

	// XXX
#ifdef _DEBUG
	if (!isGameMultiPlayer() && (getActivePlayer() != NO_PLAYER))
	{
		if (!(GET_PLAYER(getActivePlayer()).isAlive()))
		{
			if (getGameTurnYear() == 2000)
			{
				reviveActivePlayer();

				if (!isDebugMode())
				{
					toggleDebugMode();
				}
			}
		}
	}
#endif
	// XXX

	[b]// onEndGameTurn here. [/b]
	gDLL->getEventReporterIFace()->endGameTurn(getGameTurn());

	[b] // Where the turn is actually incremented [/b]
	incrementGameTurn();
	incrementElapsedGameTurns();

	if (isMPOption(MPOPTION_SIMULTANEOUS_TURNS))
	{
		shuffleArray(aiShuffle, MAX_PLAYERS, GC.getGameINLINE().getSorenRand());

		for (iI = 0; iI < MAX_PLAYERS; iI++)
		{
			iLoopPlayer = aiShuffle[iI];

			if (GET_PLAYER((PlayerTypes)iLoopPlayer).isAlive())
			{
				GET_PLAYER((PlayerTypes)iLoopPlayer).setTurnActive(true);
			}
		}
	}
	else
	{
		for (iI = 0; iI < MAX_PLAYERS; iI++)
		{
			if (GET_PLAYER((PlayerTypes)iI).isAlive())
			{
				if (isPbem() && GET_PLAYER((PlayerTypes)iI).isHuman())
				{
					if (iI == getActivePlayer())
					{
						// Nobody else left alive
						GC.getInitCore().setType(GAME_HOTSEAT_NEW);
						GET_PLAYER((PlayerTypes)iI).setTurnActive(true);
					}
					else if (!getPbemTurnSent())
					{
						gDLL->sendPbemTurn((PlayerTypes)iI);
					}
				}
				else
				{
					GET_PLAYER((PlayerTypes)iI).setTurnActive(true);
					FAssert(getNumGameTurnActive() == 1);
				}

				break;
			}
		}
	}

	testVictory();

	gDLL->getEngineIFace()->SetDirty(GlobePartialTexture_DIRTY_BIT, true);

	PROFILE_END();

	stopProfilingDLL();

	gDLL->getEngineIFace()->AutoSave();

	[b]// Maybe add this?
	CyArgsList pyArgs;
	pyArgs.add(getGameTurn() - 1);
	gDLL->getEventReporterIFace()->genericEvent("realEndGameTurn", pyArgs.makeFunctionArgs());[/b]

}

Then, you can have the newGame code running within the realEndGameTurn, and when you pop out it wouldn't increment the turn. I'm not sure what problems you might experience with the MP, but since this is designed to help you test AI I'm assuming you're not going to be taking it online any time soon :P
 
Back
Top Bottom