Python: Stop function for scenario maps

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
How do I stop a function from being performed if the map is a scenario (any scenario), but still allow it to occur for randomly generated maps in python? I've checked the Python API but can't find anything that looks like it works.

For context, this is for the Start as Minors game option in RevolutionDCM. The function I specifically want to stop being run on scenario maps is the free defensive unit that is given to the players at game start when Start as Minors is selected (it messes up big time on scenarios, plus I'd rather keep the starting units in a scenario to be defined by the scenario maker). I've tried this:

Original code:
Code:
            if( game.isFinalInitialized() and game.getGameTurn() < 2 and pPlayer.isMinorCiv() ) :
                if( pPlayer.isAlive() and not pPlayer.isBarbarian() ) :
                    #phungus AI defensive unit start
...do stuff
Looking in the Python API, the only thing I could find that looked promising was the getMapScript call. So I defined map as gc.getMap(), and then tried this code:
Code:
            if( game.isFinalInitialized() and game.getGameTurn() < 2 and pPlayer.isMinorCiv() and map.getMapScriptName() != NONE ) :
                if( pPlayer.isAlive() and not pPlayer.isBarbarian() ) :
                    #phungus AI defensive unit start
...do stuff
But I get a python exception "Type 'NONE' is not defined". Anyone have any ideas?
 
Well, I realized that it's None in python and not NONE, but that does not help. It still runs the function for scenario maps. Anyone have any good ideas how to check if the map is a scenario and not a randomly generated map?
 
If you load a scenario, CyMap().getMapScriptName() evidently still returns a value - it returns the name of the WBS file.

Final Frontier detects whether it is running as a scenario via
Code:
		# Is this a scenario file?
		if ('.CivBeyondSwordWBSave' in CyMap().getMapScriptName()):
and it appears to work correctly.
 
Thanks for the tips guys. Especially useful since it's not clear at all how to do this. Unfortanetly I've found I can't simply block this function for all scenarios, since the "clean" scenarios don't have units placed yet, so it needs this. I have figured out a way to handle this in the Scenario scripts themselves that were having a problem.
 
Top Bottom