[Map Script] Random Script Chooser

Refar

Deity
Joined
Apr 10, 2005
Messages
4,608
This is a Suffle-script, that will actually choose at random from a list of different map scripts. This way we can expect good results, by choosing which scripts to include in the list, but without knowing for sure what the map will look like.

Scripts Included are:
Archipelago, Fractal, Pangaea, Hemispheres, Big&Small, Medium&Small and Terra.
I wrote none of the included scripts - i only did some tweaking and provided the 'shell'.

In addition to the shuffling i also made various tweaks to the included maps to increase diversity, credibility and playability of the scripts. This includes variations of size and location of landmasses, additional island regions, custom rules for starting plots, preventing peaks from bisecting land and some other map specific tweaks.

The Terrain Generator is adjusted to produce rather coherent desert regions but having less deser in total. I also pushed the polar snow limits a little bit, to reduce the amount of useless tiles. For Ressources and Features the default method is used.

No changes to the Placement of features, goodies and ressources have been made.

It is possible to set different Start Plot rules for Human Players. Like requesting the Human Player to start near coast (I hate starting a game as Viknigs to find out, that the next see is 2 opponents away...). This does Not affect the overall quality of the spot (Ressources nearbye etc.).

While it is possibly to control the probability of choosing different scripts or remove scripts from the rotation, there is no easy way to add a new script. A map always needs to be edited to be compartible with RandomScriptMap. I included a explanation of what has to be done, but it might be more or less difficult with different maps.

NOTE: The games original scripts will be not overwritten nor changed. I copied/subclassed them for use with the script.

Current Version is 1.25 from 18.03.2008
Merged into a single file.

This is the same version, that came with BTS patch 3.17.
You do not need these files, if you have the patch.



NOTE on Installation:
RandomScriptMap.py -> PublicMaps.
If upgrading from a earlier version, which came as 2 files, please remove both old files first.

NOTE on Customizing Map Rotation
You can exclude up to 3 Maps from menu when generating a custom world. If this is not enought or you wish to remove something permanently, open RandomScriptMap.py with Notepad. The header contains some constants the Player might want to change (and the explanations needed). I.e. the weights (probabilities) of different maps. Weight 0 is allowed and meant the map will be never chosen. It is also possible too choose explicitely, what map to play. This kind of defies the purpose of the script, but might still be useful at times.
And finally, if you enable logging, some information about the created map will be written in the PythonDBG.log.

Get it from the download database

Here's is a sample. All maps produced in sequence with ver. 1.0 and without any changes to the scripts default settings.
 
After playing a game i made some adjustments for my next game.

The version 1.1 in the Download Database now includes:
- More coherent Desert regions
- Possiblilty to request special start conditions for the Human Player (Like getting a coastal plot)
- Some Tweaks aimed towards smaller maps (i play huge my self, but while testing i seen some minor glitches on Tiny and Duell - those shall be fixed now.)
 
After playing a game i made some adjustments for my next game.

The version 1.1 in the Download Database now includes:
- More coherent Desert regions
- Possiblilty to request special start conditions for the Human Player (Like getting a coastal plot)
- Some Tweaks aimed towards smaller maps (i play huge my self, but while testing i seen some minor glitches on Tiny and Duell - those shall be fixed now.)

Hey Refar,
Is it just me installing it wrong or is this latest release FUBAR? v1.0 worked like a charm but v1.1 is creating me maps of ALL grassland (wall to wall grassland, no ocean, lakes, plains, deserts, or any other base terrains) with maybe a few hills, forests, and rivers thrown in the ENDLESS fields of green.

Thanks in Advance!
 
Hey Refar,
Is it just me installing it wrong or is this latest release FUBAR? v1.0 worked like a charm but v1.1 is creating me maps of ALL grassland (wall to wall grassland, no ocean, lakes, plains, deserts, or any other base terrains) with maybe a few hills, forests, and rivers thrown in the ENDLESS fields of green.

Thanks in Advance!


This happened to me also.

What I did was to move the RandomScriptUtil.py file from the customAssets\Python dir into the PublicMaps dir with the main .py file.

Has worked since then.


Elrikk
 
This happened to me also.

What I did was to move the RandomScriptUtil.py file from the customAssets\Python dir into the PublicMaps dir with the main .py file.

Has worked since then.


Elrikk

That did the trick! So, Refar, you may want to change up your installation instructions since its now pretty clear putting RandomScriptUtil.py in the root of the Python directory (Custom or Primary) doesn't work quite right.
 
This looks good. I will give it a try tonight.

Just from glancing at it, it looks like you copied the entire script for the various options into the RandomScriptUtil.py file, and just have links (so to speak) to those scripts in the RandomScriptMap.py file. I'd like to add Tectonics and Medium_and_Small to the randomizer, and perhaps remove Pangaea....can I pick your brain a little bit on how to do this? Is it just a matter of cutting and pasting, and maybe adding the link to the RandoMScriptMap file?

Thanks.
 
@Elrikk & LordGekOdd... I tried it and for me it does work :confused: It is CustomAssets/Python however, not just CustomAssets - probably your zipper skiped the subfolder ?
And yes it does work as well, when both files are in PublicMaps - then the "Util"-Thingie will show up in the Custom Game menu as well - but this is just a little flaw...

@jkp1187... yes basicly it is cut&paste. When i was at it, i also adjusted some little things, but this is not necessary.

The only thing you actually must take care of, are the user inputs... Many scripts will read out user inputs within the main controll method... You will find someting like self.map.getCustomMapOption(0)
... those are for the choices you have in the custom game menu - like World Wrap, Number of Continents etc. This you need to avoid somehow - hardcode or replace with a random number...

If the original script does not have any user input, and you do not wish to change nothing else, you not even need to copy and paste - you could just link to the original sctipt via import... something like:
import TerraMultilayeredFractal from Terra

To remove Pangaea you can exclude it, when making a map. Or set c_pangWeight = 0 in the header of my script - a map having the weight 0 will never be choosen.

/Edit.
I will add Madium_and_small und perhaps some more comment, so you can see what is happening - kind of before/after
 
PS>

@ Elrikk & LordGek
Are you using any mods ? I mean the kind mod that has to be activated in the game menu... I am not much of a modder, so i just do not know, what happens with the CustomAssets if a mod is active...
 
I am using a number of mods and tweaks, so maybe they're conflicting there to be honest.
 
PS>

@ Elrikk & LordGek
Are you using any mods ? I mean the kind mod that has to be activated in the game menu... I am not much of a modder, so i just do not know, what happens with the CustomAssets if a mod is active...



Just Blue Marble.


Elrikk
 
I uploaded the Version 1.2. The changes are:
- Medium and Small map icluded
- Some changes to the internal structure, to make adding new scripts easier.

@jkp1187 (and others who might be interested): I also included a reference in the archive, on what has to be done, to add a new script (using M&S as example). The reference is aimed towards non-programer and is - so i hope - easy to understand. How hard it will be, to reproduce the procedure with other maps, depends on the map you are trying to include.

I am considering adding Tectonics as well, but at this moment i am not sure if the author will permit this and if and when it will happen

@Elrikk: I use BlueMarble myself, so i guess it is not the problem. I cant reproduce the problem here however, so i am not really sure what went wrong for you... If you wish, you could enable the logfiles in the Civ4.ini:
; Enable the logging system
LoggingEnabled = 1

its very near end of the file. Then send me the PythonDBG.log and PythonERR.log from your BTS\Logs folder...
 
I've got the RandomScriptMap.py by Oleg/Refar, thanks.

I'm trying to customize it to work with the PITBOSS for BTS. When loaded via PITBOSS most of the options are NOT accessable, which is fine as I can edit the script and put in the constants which is basically exclude archipeligo and make everything else random. I'm an OK scripter/programmer, but can someone maybe point out an example of what I might want to change ? Or let me know if this is compatible with PITBOSS?

Didact
 
I never tired pitboss (do not actually know what it is). From what i read...

If you open the RandomScriptMap.py you will find a bunch of constants right in the beginning. The stuff is commented... There you can set c_archiWeight = 0 to sort out the archipelago.
All custom options are allways assigned defaults (which you can also set in the header). So if just the menu is not accessible there should be no problem.

If you need to actually remove the custom options, you need to edit a couple of methods:

Code:
def getNumCustomMapOptions():
	return 6

def getCustomMapOptionName(argsList):
def getNumCustomMapOptionValues(argsList):
def getCustomMapOptionDescAt(argsList):
def isRandomCustomMapOption(argsList):
def getCustomMapOptionDefault(argsList):

Set number of custom options to 0 and delete or void (just return) the other methods.

Then edit the beforeGeneration() method, to remove the readouts for custom options. Just hardcode them with defaults (you can see the meaning of the options and the defaults in the header comments).
Code:
genMethod = map.getCustomMapOption(0)
aiStartMethod = map.getCustomMapOption(1)
plStartMethod = map.getCustomMapOption(2)
exclude1 = map.getCustomMapOption(3)		
exclude2 = map.getCustomMapOption(4)
exclude3 = map.getCustomMapOption(5)

This should eliminate all custom options.

You might also want to change the map to not being 'advanced' (return 0) since the '1' is preventing the script from showing up in some menus.
Code:
def isAdvancedMap():
	return 1
 
Refar,

Kudos again for this script. I played a couple of games with it recently, and ended up with some truly unexpected maps with settings that it never occurs to me to pick. Really kept me on my toes.

THanks again.
 
Okay, I actually have a real question this time. I noticed that the original Terra.py script has the following code:

Code:
def getGridSize(argsList):
    "Enlarge the grids! According to Soren, Earth-type maps are usually huge anyway."
    grid_sizes = {
        WorldSizeTypes.WORLDSIZE_DUEL:        (13,8),
        WorldSizeTypes.WORLDSIZE_TINY:        (16,10),
        WorldSizeTypes.WORLDSIZE_SMALL:        (21,13),
        WorldSizeTypes.WORLDSIZE_STANDARD:    (26,16),
        WorldSizeTypes.WORLDSIZE_LARGE:        (32,20),
        WorldSizeTypes.WORLDSIZE_HUGE:        (38,24)
    }

    if (argsList[0] == -1): # (-1,) is passed to function on loads
        return []
    [eWorldSize] = argsList
    return grid_sizes[eWorldSize]

It looks like you removed this from the terra script included in RandomScriptUtil.py. Why is that?

Does this mean that the Terra map included in your Random Script will not be larger that 'normal', like the default terra script is?

Reason I'm asking is that I'm trying to add both the original Terra.py and the Earth2.py script (made by another modder in this forum that piggybacked off of the original Terra.py script) to RandomScriptUtil.py. (I do not want to remove the Terra script that you modified -- these would just be additional choices.) If there was a reason (other than personal preference) that you removed it, I will remove it from
 
You can put the getGridSize methode in RandomMapScript.py (not in Util).

However if you just use the unchanged methode from Terra.py, you will end up having all your maps bigger, not just Terra. If this is ok for you, just copy the method over.

It should be possible, to make getGridSize() deliver different grids, depending on what script will be used. Since i can not play to large maps anyway, i decided not to bother. Also i not sure, at what time the getGridSize() is actually called. If it is called before beforeGeneration() method, then the code below will allways deliver the default grid from the last 'else'.

The method needed would be something like this:

Code:
def getGridSize():
        if (argsList[0] == -1): # (-1,) is passed to function on loads
              return []

	if ( gl_mapType == MAP_TERRA ) : # Terra
             grid_sizes = {
                 WorldSizeTypes.WORLDSIZE_DUEL:        (13,8),
                 ....
                 ....
             }
             [eWorldSize] = argsList
             return grid_sizes[eWorldSize]

	elif ( gl_mapType == MAP_HEMIS ) : # Hemispheres
             grid_sizes = {
                 WorldSizeTypes.WORLDSIZE_DUEL:        (x,y),
                 .... # GridSizes you want for this script
                 ....
             }
             [eWorldSize] = argsList
             return grid_sizes[eWorldSize]

	elif ( .... ) : # Other Custom Sizes
	    ....
            ....
	else : # Default Sizes for everything not listed above
             grid_sizes = {
                 WorldSizeTypes.WORLDSIZE_DUEL:        (x,y),
                 .... 
                 ....
             }
             [eWorldSize] = argsList
             return grid_sizes[eWorldSize]
 
Actually, I like the idea of using terra.py map sizes for my maps. So all I have to do for that is to add the getGridSize code in the RandomScriptMap.py file? Does it have to go in a specific location?

I might try your suggested code after I've had a chance to learn a little more Python. (I'm still working through the tutorial now.) As you can tell, I really want to throw a bunch of map scripts in there to make things very randomized.
 
Yes, if you are ok with all maps being larger, you can just copy the whole method without any change.

I believe the location does not really matter, but why not put it same place it is in Terra.py, which is right after "minStartingDistanceModifier()"
 
Yes, if you are ok with all maps being larger, you can just copy the whole method without any change.

I believe the location does not really matter, but why not put it same place it is in Terra.py, which is right after "minStartingDistanceModifier()"

Cool.

Last question -- what does the value after MinStartingDistanceModifier() mean? I noticed it was "-20" for Terra, but something like "-8" for Big and Small. Does a 'higher' value mean civs will start closer together? So map scripts with -20 will start civs closer together than map scripts with -40?

Thanks again for your help!
 
Top Bottom