"onGameStart" not executed when reloading the map - how to solve?

Cybah

Emperor
Joined
Jun 22, 2007
Messages
1,481
Need help!

In my mod, some python code is related to the gamestart. For example this:

PHP:
## NO STARTING TECHS START ##

		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_STARTING_TECHS)):

			for iPlayerLoop in xrange(gc.getMAX_CIV_PLAYERS()):

				pPlayer = gc.getPlayer(iPlayerLoop)

				iPlayer = pPlayer.getID()

				# if pPlayer.isAlive():

				iTech1 = gc.getInfoTypeForString("TECH_FISHING")
				iTech2 = gc.getInfoTypeForString("TECH_THE_WHEEL")
				iTech3 = gc.getInfoTypeForString("TECH_AGRICULTURE")
				iTech4 = gc.getInfoTypeForString("TECH_HUNTING")
				iTech5 = gc.getInfoTypeForString("TECH_MINING")
				pTeam = gc.getTeam(pPlayer.getTeam())
				pTeam.setHasTech(iTech1, false, iPlayer, false, false)
				pTeam.setHasTech(iTech2, false, iPlayer, false, false)
				pTeam.setHasTech(iTech3, false, iPlayer, false, false)
				pTeam.setHasTech(iTech4, false, iPlayer, false, false)
				pTeam.setHasTech(iTech5, false, iPlayer, false, false)

## NO STARTING TECHS END ##


Everything what I have added to def onGameStart(self, argsList) in my eventmanager will NOT be executed when reloading the map.

How can I solve this? I cannot find a "on mapreload" event. I need an univeral solution, not a special one for this code (like reset the techs when founding the first city).
 
Do you mean reloading the 4000BC starting save (use onLoad) or regenerating the map (rolling a new random map using the script)? If the latter, what about using onGameBeginTurn? Does it get fired again?

If not, you'll have to add an event to your DLL which is pretty easy.
 
regenerate map, loading a savegame should be no problem right?

onBeginGameTurn is called too late: 'Called at the beginning of the end of each turn'

Well, adding an event... easy for who? :D I'm using a custom dll but I have never added an own event.
 
If you're compiling your own DLL it's super easy. Search the source code (Find in Files) for one of the existing events such as "BeginGameTurn" and copy the code. It's a handful of lines of code to copy, and you just change the name and remove the addition of arguments to the CyArgsList or whatever it's called. You won't need params, the event itself is all you need to know. You'll need to put this in the code that generates the map, after it's all done.

That's it, just call addEventHandler() in Python with the new event type such as "GenerateMap".
 
How can I solve this? I cannot find a "on mapreload" event. I need an univeral solution, not a special one for this code (like reset the techs when founding the first city).

yeah, stupid bug with the onGameStart event. to fix it just add this to CvGame::regenerateMap() before the autosave is made. Then onGamestart is also triggered if the map is regenerated

Code:
/*************************************************************************************************/
/**	ADDON (regenerate Map) Sephi                                             					**/
/*************************************************************************************************/
    CvEventReporter::getInstance().gameStart();
/*************************************************************************************************/
/**	END	                                        												**/
/*************************************************************************************************/
 
I added this to BUG, but then the Dawn of Man screen appears each time. For now I'll leave it out, but in the future it would probably be good to create a new gameRestarted or mapGenerated event so you can initialize player data without showing the DoM screen.
 
Top Bottom