--- PerfectWorld2.py	Mon May 21 08:53:11 2012
+++ Totestra-20120505.py	Sat May 12 13:43:36 2012
@@ -166,15 +166,15 @@
 
 class MapConstants :
     def __init__(self):
+        self.totestra = 0 
+        self.hmWidth  = 0
+        self.hmHeight = 0
         return
     def initialize(self):
         print "Initializing map constants"
 ##############################################################################
 ## GLOBAL TUNING VARIABLES: Change these to customize the map results
         
-        #Percent of land vs. water
-        self.landPercent = 0.29
-        
         #If this variable is set to False, a shower of colossal meteors will attempt to
         #break up any pangea-like continents. Setting this variable to True will allow
         #pangeas to sometimes occur and should be greatly favored by any dinosaurs
@@ -306,20 +306,6 @@
         #matches geostrophic uplift.
         self.monsoonUplift = 500.0
         
-        #Height and Width of main climate and height maps. This does not
-        #reflect the resulting map size. Both dimensions( + 1 if wrapping in
-        #that dimension = False) must be evenly divisble by self.hmMaxGrain
-        self.hmWidth = 144
-        self.hmHeight = 97
-
-        #Controls wrapping (not sure if this makes sense yet)
-        self.WrapX = True
-        self.WrapY = False
-        
-        #Size of largest map increment to begin midpoint displacement. Must
-        #be a power of 2.
-        self.hmMaxGrain = 16
-
         #Option to divide map into two continents as far as the midpoint
         #displacement is concerned. For guaranteed continent separation, further
         #steps will be needed but this option will cause more ocean in the
@@ -351,8 +337,6 @@
         #noise(smooth).
         self.hmNoiseLevel = 2.0
 
-        #Number of tectonic plates
-        self.hmNumberOfPlates = int(float(self.hmWidth * self.hmHeight) * 0.0016)
 
         #Influence of the plate map, or how much of it is added to the height map.
         self.plateMapScale = 1.1
@@ -399,22 +383,6 @@
         #shrinking process
         self.minInlandSeaSize = 100
         
-        #After generating the heightmap, bands of ocean can be added to the map
-        #to allow a more consistent climate generation. These bands are useful
-        #if you are generating part of a world where the weather might be coming
-        #in from off the map. These bands can be kept if needed or cropped off
-        #later in the process.
-        self.northWaterBand = 10
-        self.southWaterBand = 10
-        self.eastWaterBand = 0
-        self.westWaterBand = 0
-
-        #These variables are intended for use with the above water band variables
-        #but you can crop the map edge after climate generation for any reason.
-        self.northCrop = 10
-        self.southCrop = 10
-        self.eastCrop = 0
-        self.westCrop = 0
 
         #Too many meteors will simply destroy the Earth, and just
         #in case the meteor shower can't break the pangaea, this will also
@@ -511,18 +479,78 @@
     def initInGameOptions(self):
         gc = CyGlobalContext()
         mmap = gc.getMap()
+
+        # Sea level comes from preferences
+        try:
+            seaLevel = int(mmap.getSeaLevel())
+        except:
+            seaLevel = 1
+        #Percent of land vs. water
+        self.landPercent = 0.29
+        if seaLevel == 0:
+            self.landPercent = 0.43
+        elif seaLevel == 2:
+            self.landPercent = 0.19
+        
+        
         #New World Rules
-        selectionID = mmap.getCustomMapOption(0)
+        selectionID = mmap.getCustomMapOption(1)
         if selectionID == 1:
             self.AllowNewWorld = not self.AllowNewWorld
         #Pangaea Rules
-        selectionID = mmap.getCustomMapOption(1)
+        selectionID = mmap.getCustomMapOption(2)
         if selectionID == 1:
             self.AllowPangeas = not self.AllowPangeas
 
+        # How long are they willing to wait for the map to be made
+        patience = mmap.getCustomMapOption(5)
+
+        # The preset worlds have hard-coded values
+        selectionID = mmap.getCustomMapOption(0)
+        if selectionID != 0:
+            patience = 2
+            if selectionID != 3:
+                self.landPercent = 0.29 # We will force this here too
+
+        self.patience = patience
+        #Size of largest map increment to begin midpoint displacement. Must
+        #be a power of 2.
+        self.hmMaxGrain = 2 ** (2 + patience)
+
+        #Height and Width of main climate and height maps. This does not
+        #reflect the resulting map size. Both dimensions( + 1 if wrapping in
+        #that dimension = False) must be evenly divisble by self.hmMaxGrain
+        # SAM:
+        # Make it easy to change the size while keeping the aspect ratio
+        # The bigger the size factor, the smaller the continents and the
+        # slower the map generation process
+        selectionID = mmap.getCustomMapOption(4)
+        heightmap_size_factor = 3 + selectionID
+        self.hmWidth  = (self.hmMaxGrain * 3 * heightmap_size_factor)
+        self.hmHeight = (self.hmMaxGrain * 2 * heightmap_size_factor) + 1
+         
         #Wrap options
-        selectionID = mmap.getCustomMapOption(2)
+        selectionID = mmap.getCustomMapOption(3)
         wrapString = "Cylindrical"
+	self.WrapX = True
+	self.WrapY = False
+
+        #After generating the heightmap, bands of ocean can be added to the map
+        #to allow a more consistent climate generation. These bands are useful
+        #if you are generating part of a world where the weather might be coming
+        #in from off the map. These bands can be kept if needed or cropped off
+        #later in the process.
+        self.northWaterBand = 10
+        self.southWaterBand = 10
+        self.eastWaterBand = 0
+        self.westWaterBand = 0
+        #These variables are intended for use with the above water band variables
+        #but you can crop the map edge after climate generation for any reason.
+        self.northCrop = 10
+        self.southCrop = 10
+        self.eastCrop = 0
+        self.westCrop = 0
+
         if selectionID == 1: #Toroidal
             self.hmHeight -= 1
             self.WrapY = True
@@ -531,12 +559,61 @@
             self.southWaterBand = 0
             self.southCrop = 0
             wrapString = "Toroidal"
-            
         elif selectionID == 2: #Flat
             self.hmWidth += 1
             self.WrapX = False
             wrapString = "Flat"
-            
+       
+        # Random seed options (fixed or random)
+        selectionID = mmap.getCustomMapOption(0)
+        mapRString = "Random"
+        self.totestra = 0 
+        if selectionID == 1: # Totestra
+            self.totestra = 8885098498360902
+            mapRstring = "Totestra"
+            # Ignore most map parameters
+            self.wrapX = True
+            self.wrapY = False
+            wrapString = "Cylindrical"
+            self.hmWidth = 240
+            self.hmHeight = 161
+            heightmap_size_factor = 5
+            self.AllowPangeas = False
+        elif selectionID == 2: # Cephalo
+            self.totestra = 4316490043753041
+            mapRstring = "Cephalo"
+            # Ignore most map parameters
+            self.wrapX = True
+            self.wrapY = False
+            wrapString = "Cylindrical"
+            self.hmWidth = 144
+            self.hmHeight = 97
+            heightmap_size_factor = 3
+            self.AllowPangeas = False
+        elif selectionID == 3: # Caulixtla
+            self.totestra = 8939185639133313
+            mapRstring = "Caulixtla"
+            # Ignore most map parameters
+            self.wrapX = True
+            self.wrapY = False
+            wrapString = "Cylindrical"
+            self.hmWidth = 144
+            self.hmHeight = 97
+            heightmap_size_factor = 3
+            self.AllowPangeas = False
+
+        #Number of tectonic plates
+        self.hmNumberOfPlates = int(float(self.hmWidth * self.hmHeight) * 0.0016)
+        if patience == 0:
+            self.hmNumberOfPlates = int(
+                float(self.hmWidth * self.hmHeight) * 0.0032)
+        elif patience == 1:
+            self.hmNumberOfPlates = int(
+                float(self.hmWidth * self.hmHeight) * 0.0024)
+        elif patience == 3:
+            self.hmNumberOfPlates = int(
+                float(self.hmWidth * self.hmHeight) * 0.0008)
+
         self.optionsString = "Map Options: \n"
         if self.AllowNewWorld:
             self.optionsString += "AllowNewWorld = true\n"
@@ -547,8 +624,10 @@
         else:
             self.optionsString += "AllowPangeas = false\n"
         self.optionsString += "Wrap Option = " + wrapString + "\n"
-        
+        self.optionsString += "Map world = " + mapRString + "\n" 
+        self.optionsString += "Number continents = " + str(heightmap_size_factor) +"\n" 
 
+        print str(self.optionsString) + "\n" 
         return
     
 mc = MapConstants()
@@ -569,13 +648,14 @@
             # Python 'long' has unlimited precision, while the random generator
             # has 53 bits of precision, so I'm using a 53 bit integer to seed the map!
             seed() #Start with system time
-            seedValue = randint(0,9007199254740991)
+            if(mc.totestra == 0):
+                seedValue = randint(0,9007199254740991)
+                self.seedString = "Random seed (Using Python rands) for this map is %(s)20d" % {"s":seedValue}
+            else:
+                seedValue = mc.totestra
+                self.seedString = "Fixed seed (Using Python rands) for this map is %(s)20d" % {"s":seedValue}
             seed(seedValue)
-            self.seedString = "Random seed (Using Python rands) for this map is %(s)20d" % {"s":seedValue}
             
-##            seedValue = 4316490043753041
-##            seed(seedValue)
-##            self.seedString = "Pre-set seed (Using Pyhon rands) for this map is %(s)20d" % {"s":seedValue}     
         else:
             gc = CyGlobalContext()
             self.mapRand = gc.getGame().getMapRand()
@@ -588,7 +668,7 @@
 ##            self.mapRand.init(seedValue)
 ##            self.seedString = "Pre-set seed (Using getMapRand) for this map is %(s)20d" % {"s":seedValue}
             
-        print self.seedString
+	print str(self.seedString)
         return
     def random(self):
         if self.usePR:
@@ -1006,7 +1086,7 @@
             ok = False
 
         if ok == False:
-            raise ValueError, "height map dimesions not divisible by mc.hmMaxGrain. also check wrapping options"
+            raise ValueError, ("height map dimesions not divisible by mc.hmMaxGrain. also check wrapping options Width %d Height %d w %d h %d %s %s" % (mc.hmWidth , mc.hmHeight, width, height, str(mc.WrapX), str(mc.WrapY)))
             
         return
 
@@ -1422,6 +1502,14 @@
         self.heightMap = newHeightMap
         
     def calculateSeaLevel(self):
+        if mc.patience == 0:
+            mc.landPercent *= 2
+            if mc.landPercent > 1:
+                mc.landPercent = 1
+        if mc.patience == 1:
+            mc.landPercent *= 1.5
+            if mc.landPercent > 1:
+                mc.landPercent = 1
         self.seaLevel = FindValueFromPercent(self.heightMap,mc.hmWidth,mc.hmHeight,mc.landPercent,0.02,True)
         return
     
@@ -5011,7 +5099,7 @@
     Return an integer
     """
     mc.initialize()
-    return 3
+    return 6
 	
 def getCustomMapOptionName(argsList):
         """
@@ -5020,12 +5108,18 @@
         Return a Unicode string
         """
         optionID = argsList[0]
-        if optionID == 0:
-            return "New World Rules"
-        elif optionID == 1:
-            return "Pangaea Rules"
+        if optionID == 1:
+            return "New World Rule"
         elif optionID == 2:
+            return "Pangaea Rule"
+        elif optionID == 3:
             return "Wrap Option"
+        elif optionID == 0:
+            return "Map world"
+        elif optionID == 4:
+            return "Continent amount"
+        elif optionID == 5:
+            return "Patience amount"
 
         return u""
 	
@@ -5036,12 +5130,18 @@
         Return an integer
         """
         optionID = argsList[0]
-        if optionID == 0:
-            return 2
-        elif optionID == 1:
+        if optionID == 1:
             return 2
         elif optionID == 2:
+            return 2
+        elif optionID == 3:
             return 3
+        elif optionID == 0: # Map world
+            return 4
+        elif optionID == 4: # Number continents
+            return 4
+        elif optionID == 5: # Speed/quality tradeoff
+            return 4
         return 0
 	
 def getCustomMapOptionDescAt(argsList):
@@ -5053,7 +5153,7 @@
     """
     optionID = argsList[0]
     selectionID = argsList[1]
-    if optionID == 0:
+    if optionID == 1:
         if selectionID == 0:
             if mc.AllowNewWorld:
                 return "Start in Old World"
@@ -5064,7 +5164,7 @@
                 return "Start Anywhere"
             else:
                 return "Start in Old World"
-    elif optionID == 1:
+    elif optionID == 2:
         if selectionID == 0:
             if mc.AllowPangeas:
                 return "Allow Pangaeas"
@@ -5075,13 +5175,40 @@
                 return "Break Pangaeas"
             else:
                 return "Allow Pangaeas"
-    elif optionID == 2:
+    elif optionID == 3:
         if selectionID == 0:
             return "Cylindrical"
         elif selectionID == 1:
             return "Toroidal"
         elif selectionID == 2:
             return "Flat"
+    elif optionID == 0:
+        if selectionID == 0:
+            return "Random"
+        elif selectionID == 1:
+            return "Totestra"
+        if selectionID == 2:
+            return "Cephalo"
+        elif selectionID == 3:
+            return "Caulixtla"
+    elif optionID == 4:
+        if selectionID == 0:
+            return "Few (faster)"
+        elif selectionID == 1:
+            return "Some"
+        if selectionID == 2:
+            return "Many"
+        elif selectionID == 3:
+            return "Lots (slow)"
+    elif optionID == 5:
+        if selectionID == 0:
+            return "Not very (Faster mapgen)"
+        elif selectionID == 1:
+            return "A little"
+        if selectionID == 2:
+            return "Somewhat"
+        elif selectionID == 3:
+            return "Extremely (nicer map)"
     return u""
 	
 def getCustomMapOptionDefault(argsList):
@@ -5091,7 +5218,11 @@
 	Return an integer
 	"""
 	#Always zero in this case
-	return 0
+	#print argsList[0]
+        if argsList[0] != 5:
+            return 0
+        else:
+            return 2 # Slow speed/quality (Mark's default)
     
 def isRandomCustomMapOption(argsList):
 	"""
@@ -5119,11 +5250,13 @@
     return
 def normalizeRemovePeaks():
     return
+GlobalThisIsAdvanced = 0
 def isAdvancedMap():
 	"""
 	Advanced maps only show up in the map script pulldown on the advanced menu.
 	Return 0 if you want your map to show up in the simple singleplayer menu
 	"""
+        GlobalThisIsAdvanced = 1
 	return 0
 def isClimateMap():
 	"""
@@ -5135,7 +5268,7 @@
 	"""
 	Uses the Sea Level options
 	"""
-	return 0
+	return 1
     
 def getTopLatitude():
 	"Default is 90. 75 is past the Arctic Circle"
@@ -5648,7 +5781,8 @@
     FORESTEVERGREEN = 1
     FORESTSNOWY = 2
 
-    createIce()
+    if mc.WrapY == False:
+        createIce()
     #Now plant forest or jungle
 ##    PrintTempMap(tm,tm.tempMap)
 ##    PrintRainMap(rm,rm.rainMap,False)
@@ -5750,8 +5884,8 @@
     spf.SetStartingPlots()
 def beforeInit():
     print "Initializing Custom Map Options"
-    mc.initialize()
     mc.initInGameOptions()
+    mc.initialize()
 
 ##mc.initialize()
 ##PRand.seed()
