View Full Version : Selective Old World


lumpthing
Jan 04, 2008, 03:36 AM
I know I can use the code below to force all civs to start on the biggest continent, but is there a way to make this rule apply to only certain civs. For example, to say that the English, Dutch and Spanish must start on the biggest continent, but all the other civs can start anywhere?

def isValidOldW(playerID, x, y):
map = CyMap()
if (map.plot(x, y).getArea() != map.findBiggestArea(False).getID()):
return False
return True

def findStartingPlot(argsList):
[playerID] = argsList
return CvMapGeneratorUtil.findStartingPlot(playerID, isValidOldW)

Refar
Jan 04, 2008, 05:47 AM
make two different "isValid" methods (one of which might be just the default implementation for civs starting where-ever...), then choose which one to pass to CvMapGeneratorUtil.findStartingPlot(Player, isValid)...

lumpthing
Jan 05, 2008, 10:42 AM
i wish that made sense to me :/

Refar
Jan 05, 2008, 03:09 PM
Uh... Sorry...

Well... I dont know how to handle civ's names in map generation. I think: gc.getPlayer(playerID).getCivilizationType() == "CIVILIZATION_JAPAN" is close, to waht it will look like

As you worked on that "Earth Flavour Script" i assume you do know how the condition has to look like... So the code below is to demonstrate how to bind the usage of multiple different isValid() methods to a condition, but you will need to provide the right conditions for the if's...

# Validity Function for Old World Civ
def isValidOldW(playerID, x, y):
map = CyMap()
if (map.plot(x, y).getArea() != map.findBiggestArea(False).getID()):
return False
return True

#Validity funciton forciang a civ to start anywhere BUT old world
def def isValid_NOT_OldW(playerID, x, y):
map = CyMap()
if (map.plot(x, y).getArea() == map.findBiggestArea(False).getID()):
return False
return True

def findStartingPlot(argsList):
[playerID] = argsList

#Old World Civs
if ( gc.getPlayer(playerID).getCivilizationType() == "CIVILIZATION_ENGLAND" ) :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValidOldW)
#Not Old World Civs
elif ( gc.getPlayer(playerID).getCivilizationType() == "CIVILIZATION_JAPAN" ) :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValid_NOT_OldW)
#Everyone not covered above. None passes no special isValid() method, so the default implementation will be used.
else :
return CvMapGeneratorUtil.findStartingPlot(playerID, None)

Sto
Jan 05, 2008, 03:29 PM
Uh... Sorry...

Well... I dont know how to handle civ's names in map generation. I think: gc.getPlayer(playerID).getCivilizationType() == "CIVILIZATION_JAPAN" is close, to waht it will look like



this is :
gc.getCivilizationInfo(gc.getPlayer(playerID).getC ivilizationType()).getType() == "CIVILIZATION_JAPAN"

or
gc.getPlayer(playerID).getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_JAPAN")


Tcho !

lumpthing
Jan 06, 2008, 05:12 AM
Thanks very much for your help both of you

I slapped in the following code:


# Validity Function for Old World Civ
def isValidOldW(playerID, x, y):
map = CyMap()
if (map.plot(x, y).getArea() != map.findBiggestArea(False).getID()):
return False
return True

#Validity funciton forciang a civ to start anywhere BUT old world
def isValid_NOT_OldW(playerID, x, y):
map = CyMap()
if (map.plot(x, y).getArea() == map.findBiggestArea(False).getID()):
return False
return True

def findStartingPlot(argsList):
[playerID] = argsList

#Old World Civs
if ( gc.getPlayer(playerID).getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_ENGLAND") ) or ( gc.getPlayer(playerID).getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_FRANCE") ) :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValidOldW)
#Not Old World Civs
elif ( gc.getPlayer(playerID).getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_JAPAN") ) :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValid_NOT_OldW)
#Everyone not covered above. None passes no special isValid() method, so the default implementation will be used.
else :
return CvMapGeneratorUtil.findStartingPlot(playerID, None)


...and tested it on a duel-sized map with France, England and Japan. Unfortunately it does not seem to work. I only tested it three or four times but there was always one big continent with two civs and one little continent with one civ with Japan always on the biggest continent!

Refar
Jan 06, 2008, 05:22 AM
That's odd, as in theory it looks good... Tho i never tried exactly this code before, i had used similar snipplets to make different rules apply to AI and human civs...

Do you use it together with the "Earth Flavour" thingie of yours ? becausse i think the Flavour code reshuflles the starting plots in the end... (To match the flavour selections...)

lumpthing
Jan 06, 2008, 05:53 AM
yeah i used it with the earth flavour thing so i expect its that. I'll test it without earth flavour some time to make sure.

incidentally, all the proper code for earth flavour mod is taken from dreiche2's script for Fall From Heaven. I just changed the settings to work for standard Earth civs. So that's why I'm clueless about the code :)

Refar
Jan 06, 2008, 06:06 AM
I dont understand it completely either, so unfortunately i cant help you merge thise two... tho i think it should be possible somehow.

lumpthing
Jan 06, 2008, 06:12 AM
I added the script in post 6 to the continents map script, without earth flavour having any involvement, and it still didnt work :(

Refar
Jan 06, 2008, 06:26 AM
Hmmm :( I am a bit confused then... It must be something about the

gc.getPlayer(playerID).getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_JAPAN")

statement i think... Perhaps the civs are not yet determined at that point ?

Do you have logging enabled ? (can be anabled via the .ini, at the end of the file LoggingEnabled = 1) If so can you prehaps look if the PythonErr.log file has some error messages ?

Refar
Jan 06, 2008, 06:38 AM
Uh... my bad... I Copy-Pasted-Edited the code from another script where GC was defined globally... Sorry. :blush: You need to put this
gc = CyGlobalContext()

in the beginning of the findStartingPlot() method... Just below the [playerID] = argsList line

Sto
Jan 06, 2008, 06:50 AM
... Perhaps the civs are not yet determined at that point ?


All the game infos are enabled "onSetPlayerAlive" before "beforeInit" except the map scripts settings like grid size , wrap etc ...

Here the code rewritten to be easy to change :

def findStartingPlot(argsList):
[playerID] = argsList
gc = CyGlobalContext()

oldCivList = ["CIVILIZATION_ENGLAND", "CIVILIZATION_FRANCE"]
notOldCivList = ["CIVILIZATION_JAPAN"]

oldCivList = [gc.getInfoTypeForString(item) for item in oldCivList]
notOldCivList = [gc.getInfoTypeForString(item) for item in notOldCivList]
iPlayerCiv = gc.getPlayer(playerID).getCivilizationType()

#Old World Civs
if iPlayerCiv in oldCivList :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValidOldW)
#Not Old World Civs
elif iPlayerCiv in notOldCivList :
return CvMapGeneratorUtil.findStartingPlot(playerID, isValid_NOT_OldW)
#Everyone not covered above. None passes no special isValid() method, so the default implementation will be used.
else :
return CvMapGeneratorUtil.findStartingPlot(playerID, None)



Tcho !

jkp1187
Jan 07, 2008, 10:55 AM
This looks good. I hope you don't mind me stealing this code to use in some of my own map scripts.

One question though -- one of the scripts I was planning to use it in was the Earth3/Terra2 maps, which are variations on the basic Terra script. Now, if I use this code, I might end up with a situation where every civ in a game is an "old world" team...or, worse, where every civ but one is an old world team, and as a result, one civ has free run of the new world for most of the game.

Is there an easy way to set up the script such that unless there are specific civs forced via the interface, that the game will always have a minimum of two new world civs? Or are the civs included in the game randomly determined PRIOR to map generation?

Thanks.

Refar
Jan 07, 2008, 11:01 AM
Is there an easy way to set up the script such that unless there are specific civs forced via the interface, that the game will always have a minimum of two new world civs? Or are the civs included in the game randomly determined PRIOR to map generation?

I think there is no way to know if a civ was forced or choosen at random from within the map script...

You could however just count old/new world teams, and - if the distribution is to unbalanced, relocate some... Perhaps relocating the last civs in the list - as those are unlikely to be human...

lumpthing
Jan 08, 2008, 02:23 AM
Thanks very much for the tidied-up script, I'm looking forward to having a spare moment to implement it

lumpthing
Jan 12, 2008, 05:16 AM
Finally tested it: it works very well, except that it seems to override my original 'earth flavour' mod

Refar
Jan 12, 2008, 05:28 AM
Yes, i had expected something like that...

What you would need to do, is somehow merging those conditions from the diffrent "isValid" methods into the process used by the flavour mod.

I do not understand the code of the flavour mod, so i cant help you merge.

Perhaps the author of the original flavour location code can give some hints, on how to merge additional conditions in.