1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Totestra: A new PerfectWorld2 fork

Discussion in 'Civ4 - Map Scripts' started by vktj, May 8, 2012.

  1. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    Cephalo already made it possible to edit the amount of rivers by editing one of the numeric parameters. If you're comfortable using a text editor, you can edit the following line in Totestra.py:

    Code:
            #This value is used to decide if enough water has accumulated to form a river.
            #A lower value creates more rivers over the entire map.
            [B]self.RiverThreshold = 4[/B]
    
    Try making this 3 or 2.

    Totestra.py can not be edited using Notepad (it uses UNIX line feeds) [1], but can be edited using notepad++ or wordpad/word if one is careful to save the edited file as a text document.

    - Sam

    [1] Since you asked: Msys 1.0.10, the last version of msys with vi, uses an old minimal version of vim without DOS line feed support.
     
  2. En_Dotter

    En_Dotter Prince

    Joined:
    Jul 15, 2010
    Messages:
    337
    Location:
    Serbia
    Oh! Tnx. Im using Notepad++ for editing. I might do it today.
     
  3. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    In today's update, I have added an error checking code to the service tag, which will catch 75% of transcription errors.
     
  4. En_Dotter

    En_Dotter Prince

    Joined:
    Jul 15, 2010
    Messages:
    337
    Location:
    Serbia
    I havent meddled with the code to add more rivers and im still using the previous version (the one before the one mentioned in the previous post) and i can say that there are enough rivers. Since i played a decent amount of games using ur script i can only say those maps i complained about were some kind of a statistical error. Im enjoying the script to be honest ;).
     
  5. AncientPlayer

    AncientPlayer Warlord

    Joined:
    Jan 20, 2004
    Messages:
    181
    Location:
    Northern Virginia
    Sam -- downloaded the python file and took a look at it. Impressive amount of work in there to craft the maps. Generated 6-10 maps and looked them over. Overall, I like the result, but they seem, to me, to end up with an rather large number of mountain peaks in E-W lines along a coast and an occasional big block of peaks generally right near/or on the coast as well.

    This created at least one, sometimes several, blocked areas which I would rather not have. It also sometime created areas along the coast that were 'walled off' for quite a few squares--not necessarily bad if it happens occasionally, but it seemed to me like it was happening pretty frequently.

    I looked at the code but didn't see an obvious spot that would determine the number of peaks allowed on the map or a plate. If there's code to break up blocks of peaks I missed it. I did tweak a couple constants that seemed like they might influence it, but I'm not convinced it did anything much.

    Could you tell me how I'd go about reducing the peaks? A simple mapwide reduction by maybe 30% might work.

    Thanks.
     
  6. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    Please give us some service tags showing the problem; the very first post in this thread tells you how to get one. I'll get back to you once you have your service tags ready.

    - Sam
     
  7. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    Final update: I have fixed the issue with large continents being split at the international date line (we now place the international date line where there is the most ocean) and have added an option to remove coastal mountains and reduce other mountains.

    I have finished my Totestra fork at this point. I hope people enjoy the maps it generates.
     
  8. AncientPlayer

    AncientPlayer Warlord

    Joined:
    Jan 20, 2004
    Messages:
    181
    Location:
    Northern Virginia
    The only one I've got saved has a tag
    40491445fcdc6f76b8c1b

    That one I played on and it worked but it does show some of what I referred to.

    Dick
     
  9. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    You might like today's update to Totestra, then. Cephalo, many moons ago, wrote some code to reduce the number of mountains. Unfortunately, due to a typo, this code never ran. I have updated that bit of code to run again, and have added some code that further reduces mountains and removes all coastal mountains.

    Then name of this option is "reduce mountains" and here's a screenshot of a landform in your map showing what the change does.

    I think you will like this change.
     

    Attached Files:

  10. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    Here's some of what the code looks like:

    Code:
            #In addition to the relative peak and hill generation, there is also a
            #process that changes flats to hills or peaks based on altitude. This tends
            #to randomize the high altitude areas somewhat and improve their appearance.
            #These variables control the frequency of hills and peaks at the highest altitude.
            self.HillChanceAtOne = .50
            [B]self.PeakChanceAtOne = .27[/B]
    
    I had to move it down from where Cephalo had it near the top because these values change on rocky maps.

    You can also further reduce peaks with the newly activated "reduce mountain peak" code:

    Code:
                    if self.plotMap[i] == mc.PEAK and mc.smoothPeaks == 1:
                        allPeaks = True
    		    peakCount = 0
    		    nextToOcean = False
    		    #print "peak at %d %d" % (x,y) #DEBUG
    		    # While we're here, let's eliminate seaside peaks
                        for direction in range(1,9,1):
                            xx,yy = GetXYFromDirection(x,y,direction)
                            ii = GetIndex(xx,yy)
                            if self.plotMap[ii] != mc.PEAK:
                                allPeaks = False
    			else:
    			    peakCount += 1
                            if self.plotMap[ii] == mc.OCEAN:
    			    #print "nextToOcean %d %d" % (x,y) #DEBUG
                                nextToOcean = True
                        if allPeaks == True or peakCount > [B]3[/B]:
                            self.plotMap[i] = mc.HILLS
    		    if nextToOcean == True:
    			self.plotMap[i] = mc.HILLS
    
    What this code does is as follows:

    • If a given point on the map is a mountain peak and we're smoothing peaks then:
    • Count the number of mountain peak squares next to this square
    • See if there are any water squares next to the mountain peak (they are mc.OCEAN squares right now because PW/Totestra makes them coastal squares later on)
    • If there are 4 or more mountain squares next to this square, make the mountain a hill
    • If there are any water squares next to this square, make the mountain a hill

    Reduce peakCount > 3 to a lower number to get even fewer mountains on the map.

    - Sam
     
  11. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    Now that I have finished Totestra, let me briefly summarize how Perfect World/Totestra makes a map. Here is the "main loop" which does the majority of the map rendering in Totestra:

    Code:
    def generatePlotTypes():
        # Core height map generator
        gc = CyGlobalContext()
        mmap = gc.getMap()
        mc.width = mmap.getGridWidth()
        mc.height = mmap.getGridHeight()
        mc.minimumMeteorSize = (1 + int(round(float(mc.hmWidth)/float(mc.width)))) * 3
        PRand.seed()
        hm.performTectonics()
        hm.generateHeightMap()
        hm.combineMaps()
        hm.calculateSeaLevel()
        hm.fillInLakes()
        pb.breakPangaeas()
    ##    hm.Erode()
    ##    hm.printHeightMap()
        hm.rotateMap()
        hm.addWaterBands()
    ##    hm.printHeightMap()
        cm.createClimateMaps()
        sm.initialize()
        rm.generateRiverMap()
    
    (Note that, in Python, lines that begin with '#' are ignored. So Cephalo's code doesn't actually perform erosion; he decided he didn't like the way it looks)

    To understand Perfect World's code, an important idea to understand is the "height map". This is a square grid of numbers; each square in the grid has a number between 0 and 1 that represents the height at that point. It represents, if you will, a sandbox where a given point in the sandbox has a level of sand.

    What Perfect World does is perform simulated plate tectonics to this abstract height map which doesn't have any real water or land yet. It then adds water to the map; the amount of water added depends on the "ocean level" setting on Totestra. PW/Totestra then throws simulated meteors at the land (the simulated meteor in Cephalo's code acts more like a variable sized circular stamp, actually) in an attempt to break up large land masses (this is what pb.breakPangaeas() does), then Totestra performs some code I wrote which performs a circular rotate on the height map. I do this rotate so continents are less likely to be split at the international date line (the edge of the map where it wraps).

    After rotating the map, Cephalo's code does a lot of simulated weather to determine whether a given square should be a desert, plains, grassland, with a river, and so on. All of this information is combined and finally converted in to a Civ4-compatible map.

    Cephalo feels that just putting hills once an elevation reaches a certain value, followed by putting mountains at an even higher elevation doesn't make sense for a Civilization map, so his code determines the altitude change and adds hills and mountains based on that information.

    At the default "islands" and "map ratio" settings for Totestra, a 144x96 height map is generated. This is scaled down using ShrinkMap() in to the desired size. ShrinkMap() only scales down; it does not effectively scale up, so the maximum size of a default map is 144x96.

    The "islands" ("Continent amount") option in Totestra increases the size of the underlying height map. This results in the map having more islands, since the tectonic plates on the height map stay the same size, and the map ends up having more plates on it. This is why it takes more time for Totestra to make a map with more islands on it.

    "map ratio" not only changes the size of the resulting map, it also scales the height map as needed so that the land forms on the final map continue to look natural.

    Cephalo goes in to a lot of detail explaining what Perfect World does in the Perfect World thread.

    I hope this information gives people who wish to continue making changes to Perfect World/Totestra guidance on where to start.

    - Sam
     
  12. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
  13. En_Dotter

    En_Dotter Prince

    Joined:
    Jul 15, 2010
    Messages:
    337
    Location:
    Serbia
    I think you can safely add K-Mod. I played a lot of K-Mod games using this script and it works. I dont know why it shouldnt work anyway since K-Mod just fixes AI and some basic mechanics to make the game more challenging and fun.
     
  14. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    I have added K-Mod to the list of compatible mods. I will test some others and add even more results.

    Also, I have no idea if Mars, Now! is playable with so much water on the map and with resources becoming other things on the map, but the map does generate and the player does start.
     
  15. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    32,018
    Location:
    DE/NL/FR
    mmhh...playable...yes, but it's not very flavourful in regards to the scenario ^^.
    Just checked one map, looks interesting, but I'd not consider playing it with my mod (but I think if I get the Civ4 fever again, that I'll then have to test it with BtS :)).
     
  16. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    I am impressed with Mars, Now because its code is clean enough that it doesn't barf on a map script for Factory Civ4/Warlords/BtS.

    Of course, so people don't get the wrong idea, I've downgraded Mars Now and FutureMod from "YES" to "MAYBE"; yes, they make a map that the player starts in. No, it may not the best gaming experience for that mod to actually play out such a map.
     
  17. Matty R

    Matty R Veteran Newbie

    Joined:
    Jun 17, 2006
    Messages:
    416
    Location:
    Bolton, England
    This looks great.

    Thank you very much for your effort. I'll be trying this when I start my next game. :goodjob:
     
  18. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    32,018
    Location:
    DE/NL/FR
    The exact opposite is the case ;)...:blush:.
    I was lazy and did not change any internal names, so in the XML it's still TERRAIN_GRASS, FEATURE_FOREST and BONUS_WHEAT, etc. :blush:.
    That's why it works, but it's definitely not clean.


    Good decision :yup:.
     
  19. AncientPlayer

    AncientPlayer Warlord

    Joined:
    Jan 20, 2004
    Messages:
    181
    Location:
    Northern Virginia
    You are correct -- I like that very much. :) Still has some mountains but the coastal chains aren't there and the big blocks are broken up. Excellent job -- than you very kindly for the quick response! :thumbsup:

    I noticed the
    self.PeakChanceAtOne = .27
    parameter and tried fiddling with it but I couldn't convince myself I was really seeing a lot of change in the maps, maybe because I didn't take it to any kind of extreme.

    In any case, I think the addition you made really helps tune Totestra to whatever tastes the player might want -- and makes it the best overall script/map code out there.

    Thanks again for all the hard work with this! :goodjob:

    Dick
     
  20. vktj

    vktj Warlord

    Joined:
    May 6, 2012
    Messages:
    212
    This mainly affects areas where the height field is high. Other areas have mountains not because the sea level is high, but because the change in altitude is higher in that area (usually where two tectonic plates met).
     

Share This Page