View Full Version : [Map Script] Random Script Chooser


Refar
Aug 08, 2007, 05:43 AM
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 (http://forums.civfanatics.com/downloads.php?do=file&id=6610)

Here's is a sample. All maps produced in sequence with ver. 1.0 and without any changes to the scripts default settings.
http://forums.civfanatics.com/downloads/maps_L97.jpg

Refar
Aug 14, 2007, 06:38 AM
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.)

LordGek
Aug 14, 2007, 08:43 PM
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!

Elrikk
Aug 14, 2007, 09:26 PM
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

LordGek
Aug 14, 2007, 09:51 PM
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.

jkp1187
Aug 15, 2007, 10:55 AM
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.

Refar
Aug 16, 2007, 01:29 PM
@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

Refar
Aug 16, 2007, 01:35 PM
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...

LordGek
Aug 16, 2007, 02:13 PM
I am using a number of mods and tweaks, so maybe they're conflicting there to be honest.

Elrikk
Aug 16, 2007, 05:47 PM
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

Refar
Aug 17, 2007, 05:20 PM
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...

didact
Aug 28, 2007, 06:07 PM
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

Refar
Aug 28, 2007, 07:28 PM
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:


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).

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.

def isAdvancedMap():
return 1

jkp1187
Sep 28, 2007, 09:06 AM
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.

jkp1187
Oct 07, 2007, 08:17 PM
EDIT: Nevermind -- I didn't realize that the "end" comments are all classed as comments, so it doesn't matter. Delete this post!

jkp1187
Oct 08, 2007, 06:40 AM
Okay, I actually have a real question this time. I noticed that the original Terra.py script has the following 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

Refar
Oct 08, 2007, 12:33 PM
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:

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]

jkp1187
Oct 08, 2007, 01:55 PM
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 (http://www.sthurlow.com/) now.) As you can tell, I really want to throw a bunch of map scripts in there to make things very randomized.

Refar
Oct 08, 2007, 06:03 PM
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()"

jkp1187
Oct 08, 2007, 06:22 PM
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!

Refar
Oct 08, 2007, 07:12 PM
The other way - with -40 they might start closer than with -20.

When i rmember correctly the value is applied as follows:

Base minimum distance - how many plots must be between two starting plots - is somewhere in xml.

The base is assumed to be 100%, while the value from the method modifies the % value. So at -20 starting plots might be as close as 80% of the base value. At -40 this would be 60%.

Sir Jaref
Oct 21, 2007, 05:46 AM
Great script! I love a bit of randomness in Civ IV, but I found the existing "shuffle" option to be a bit lacking. Now I get tons of random . Nice work

Thanks a lot ^^

JujuLautre
Oct 24, 2007, 07:04 PM
Thanks so much for your script; I was searching for it some time ago, but must have missed it here !

Also, the script does appear (and works well) if I launch a custom game, but does not appear in the map type chooser when I launch "play now"; is this the expected behavior? Not that it bothers me, but just in case... :)

Refar
Oct 25, 2007, 03:42 AM
I have locked it from showing up in the "Play Now" list. I felt those are to many options you are asked for (there will be a extra screen for every custom option)def isAdvancedMap():
"This map should not show up in simple mode"
return 1
Find the code above and change it to "return 0", if you wat it to show up in "Play Now"

JujuLautre
Oct 25, 2007, 04:02 PM
Ok, so this is the expected behavior; and quite justified actually. Thanks ! :)

alexman
Jan 21, 2008, 03:46 PM
Hi Refar,

Would it be OK if we included your Random Script Chooser in a future patch?

Refar
Jan 22, 2008, 12:36 AM
Sure, go ahead. Would be happy to see it happen :D

Here's the latest version. Everything same as above but merged into one file (it's messier to edit than the 2-file version, but i think more end-user friendly, as the 2-file version seem to cause trouble sometims (i.e. Multiplayer)).

EDIT: the one-file-version can is now in the DB. Linked in the first post.

DrJambo
Jan 23, 2008, 03:55 AM
Refar, is it possible to have LDiCesare's Tectonics Maps Script as one of the options of the Random Map Script? It would be cool to interlink them somehow, particularly as both are being requested by Firaxis for the future patch! (asked this question in LDiCesare's thread too).

Regards

Refar
Jan 23, 2008, 05:48 AM
I asked for (and got) LDiCesare's permission a while ago, however did not come to actually merge the scripts...
My only makes land/sea and leaves Terrain/Features to the default, while Tectonics includes functiones for Terrain, Forests, Rivers etc. This is not a real hindrance, however some de-generalization and special case handling might be required...
Also if i merge Tectonics into RMS, all of the user otions Tectonics offers would have to go (hardcoded choices or left to random) and since i did not played many Tectonics games myself, i am not sure what choices would be the best...

Perhaps i should overcome my lazyness and look into it again :D

DrJambo
Jan 24, 2008, 08:39 AM
Fight the sloth! Heh ;)

Seriously, it would obviously be great if you can, but no worries if you can't.

LDiCesare
Jan 26, 2008, 04:07 AM
You could use only the land/sea part form tectonics, with the settings of either 60 or 70% water (or set randomize the number of sea and land plates).
The climate part is neat enough to be bundled if you want to. The rivers part probably not. Features (floodplains, forests...) and resources are standard in Tectonics, except for a minor quirk to correct missing floodplains in deserts.

Mesousa
Jan 29, 2008, 11:11 AM
When this script has decided which map to use, are then the default options for that map type used, or random ones? For example, if it randomly selects a Hemispheres map (or the user selects that), how is the number of continents determined and will there be just 'tiny islands' cause it's the default, or might there be 'islands' too?

Refar
Jan 29, 2008, 12:37 PM
Random, wherever possible, however some options are biased or resrticted.
Hemispheres will have max. 2 - 4 continents.
The Island/Continent shape/size are choosen per area, so the same map might contain one massive and one snaky continent for example.
Few extra patches of tiny islands are added to all map types, as i feel that this makes a map more "natural".

Retrospect
Mar 02, 2008, 04:11 PM
This mod is fantastic, exactly what i've been looking for. Refar you somehow psycicly knew the maps that i wanted to see in this.

Thanks for the great effort :goodjob:

EEE_BOY
Mar 18, 2008, 04:24 AM
file is gone?

Refar
Mar 18, 2008, 06:44 AM
File was lost in the DB. Reuploaded, the DB link in the first post should be working again.

Also made a small update, when i was at it - it comes in one file now - easier to use and safer for MP.

Norvin_Green
Mar 24, 2008, 08:02 AM
thanks for the great work with this. my favorite portion of game is the early exploration phase. i always felt that when you already know what type of map you are playing on it takes away from the game. there is also more of a challenge adapting your strategy when you see the lay of the land. thanks again!

peacenik
Apr 07, 2008, 08:51 AM
This is a great addition to BTS. Thank you for adding a truly random option for us. One question on starting points---specifically 'script default' limitations versus 'none'. Does choosing 'none' mean civs could randomly be started right next to each other, or settlers could land in deserts or mountain ranges? Thanks for your help.

Refar
Apr 07, 2008, 09:09 AM
"Script Default" will make the start plots follow the rules of the chosen script. So for example if you set "Script Default" and a Terra-type map is drawn (or selected) everyone will start in the old world, like on the default terra map.

"No Conditions" merely means that no user set special condition will be enforced.

Those settings do not affect the basic rules of start plot placement - regardles what condition you choose, there will be no "Bad" terrain within the capitals BFC, and the starting plot will match the "Quality Requirement", as it does with the standard scripts.

jkp1187
Jun 23, 2008, 03:08 PM
Refar -- might want to check this report of a bug:

http://forums.civfanatics.com/showthread.php?t=280023

Refar
Jun 23, 2008, 04:03 PM
Thanks for the pointer... I guess now i need to get used to check the Bug-forums from time to time...