[Tool] Rudimentary custom map generator

Discussion in 'General Map Discussion' started by cope, Jun 20, 2011.

  1. cope

    cope Green Slime

    Hello everybody!

    Playing Terraria I always kept wondering about how the maps actually are generated and as time passed I decided to take a closer look at the code (which classifies as fair use). I was surprised when I found that there was merely a single class handling all the generation and this class is still used at runtime to represent the world. It all seemed rather messy to me. Of course it is hard to tell whether a piece of code is understandable or not when you do not have the sources yourself - but in this particular case the code itself seems to be okay, the structure on the other hand is not (IMHO it is not only the WorldGen class but the whole game, e.g. having a single item class to represent all kinds of items, using lots of string comparisons to find the right item, lots of special cases [e.g. tree tops] spread all over the rendering code etc.). Nonetheless, I really like the game and so I asked myself what might be the reason for this coding style and I remembered having read that Red used to develop Flash games which usually are somewhat simpler and smaller than projects such as Terraria. Simpler projects normally work perfectly well even if their internal structure is messy; it is the natural product of growing software (instead of constructing it which is not necessary for smaller projects). Another reason, I thought, could be that it is simply impossible to write a proper map generator without throwing it all together into a single class. Please do not get my wrong, I am not trying to 'bash' Red or anything, Terraria is a great game which I really enjoy. I am offering constructive criticism.
    @Red: If you need someone to do a code-review do not hesitate to ask, there are lots of people out there willing to help you (for free!) ;).

    However, I felt I needed to prove that it is possible to do it properly and started a custom map generator. It is not completely finished (far from finished!) yet but until now it worked out rather well. I'm not currently feeling motivated to continue this project which is why I decided to release my current version in order to get some feedback - and maybe a reason to continue this project.

    I'd like to point out that I have read the forum rules and I do not see how such a project could possibly violate them. Reading the forums it seemed to me that even talking about custom map tools is a no-no but they actually don't break any of the rules: Custom map generators are not hacks as hacks normally intend to provide an unfair advantage in multiplayer games which map generators frankly do not; they do not classify as custom clients either as they are completely separate from the client and provide no way of connecting to servers. Finally, they are not mods as they do not modify content from the game, they merely create new 'input' for the game. If you feel that this thread conflicts with the forum rules, feel free to report it.

    Why would anyone use a custom map generator?, you might ask. Terraria already has an inbuilt map generator which creates great worlds. Yes, it does, and I never complaint about the worlds generated by the game's world generator. But custom map generators have some advantages as well: In my case the main advantage is that the user can change a lot of parameters to create a map which is suited to his needs and likings. The map generator itself also is easily expandable which allows for the addition of new content which is not present in the standard Terraria worlds. There is a disadvantage though: My map generator currently only generates surfaces. Depending on the feedback I get I will either continue the project or head off to do something else.

    The world is created by combining chunks of terrain which are randomized to some extent. You can control various parameters allowing you to create very different worlds:

    CliffWorld.png StrangeWorld.png VanillaWorld.png

    These three worlds have all been created using the tool; the first has a lot of cliffs (which doesn't actually look good or realistic but still somebody out there might like it) while the second features steep mountains and plateaus. The third picture shows a mixed map with different kind of features (though it is rather plain). You can change the generator's behavior via map definition files which are in XML-format. These files allow you to change aspects such as resource deposit placement, terrain generation and zone placement (currently only very basic work has been done on Jungle and Desert).

    You can download an early version of the generator here. The download includes a commented map definition file. If the generator should crash, you can always take a look into the logfile (log.txt in the same directory as the generator). The generator itself should be self-explanatory.

  2. Alethium

    Alethium Green Slime

    So if I wanted to make a world with a lot of mountains, I could generate it like that? Or if I wanted a lot of floating islands?
  3. cope

    cope Green Slime

    Yes, that's the idea behind it. (Although I haven't implemented floating islands yet.)
  4. srfk1337

    srfk1337 Cave Bat

    Im having trouble with the map definition file. Im not quite sure what to choose.

    Nevermind I figured it out.

    This project has TONS of potential. It ony makes the top layer and not any caves,jungle,dungeon, or sky islands. If you could work on that I think a lot of people would really use this a lot.
  5. cope

    cope Green Slime

    Choose? I need some more context to understand your problem.

    Yeah, only generating the surface is not what I intended to do. I just want to check back if there is any interest in such a program at all before I invest more time into it.
  6. srfk1337

    srfk1337 Cave Bat

    I wasn't sure what file to choose but I saw the vanillamap.xml in the .zip and I used that. It definitely has a lot of potential though.
  7. Alfblack

    Alfblack Green Slime

    This is awsome! I have been dreaming for something like this but I didnt think it would be possible. In the olden days of terraria. (pre overworld jungle). I had to generate alot of small worlds just to cut trees. With something like this it would be easy to make a grass world with trees. Or maybe I'm in a mood for a desert romp. Or a all Overhead jungle Map! (amazon adventure!)

    Dang how do you guys see the code!! (Rhetorical)

    I hope this is ok for the developers for you to continue or at least integrate some parameter based generation.
    Like this post if you do like this feature. So maybe the devs can put it in or something.

    Please do try to continue. I will eagerly beta test and stuff.
    Downloaded. Will try as soon as I can.
  8. MagusTheGrim

    MagusTheGrim Green Slime

    I really like this tool. It gives the potential for making maps with a higher or lower difficulty level pretty easily. I'm quite interested in seeing the abillity to have it affect lower layers as well. Also, the abillity to have the generator allow ebonstone, meteorite, and demonite as resources would be really cool.
  9. Alethium

    Alethium Green Slime

    Then wouldn't this be ideal for floating island hoarders? Or will it not have any chests?
  10. un7ucky

    un7ucky Green Slime

    please continue your work :):):):):):):):):):):):):):):):):):):):):):):)x 100,000,000
    i cant wait to see a large cave system (not the little paths you get) and floating islands
  11. Alfblack

    Alfblack Green Slime

    Oh yeh. Mega Cave world. Spelunking is one of my favorite things to do in Terraria but sometimes it's not big enough.
  12. cope

    cope Green Slime

    Creating harder worlds was one of my main ideas as well. As most people out there I have a high-level uber-equipped character who can easily take on any enemy in any environment. Admittedly, I can't add new enemies, but I can create more interesting or harder environments.
    The generator actually can create ebonite and meteorite resource deposits already (although the resource type names might change, which is why I won't give you the name of the types before the next version has been released as I plan to settle for the names until then). Demonite is impossible because there's no tile representing demonite ore.

    I can generate whatever I feel like generating. I write all the code from scratch, so I could create floating islands with or without chests or whatever. I am not limited by the original worlds generated by Terraria; I could theoretically create a whole floating world right above a huge lava lake (now that's an idea I actually like). I am not a huge fan of creating worlds specifically made for hoarding or farming as it is the same as cheating to me. On the other hand I do not care if you cheat in your worlds or not, that's none of my business. The same holds true for generating worlds: If you want to create a world with lots of floating islands, go for it, I won't stop you.

    Creating surface/subsurface transitions like caves is the next point on my todo-list. Floating islands are way further down the list as I'd first like to have a working subsurface world.
  13. Can you give the option for replacement sweeps?

    I'm fine with the default terrains appearance, but I'd love the option to have all dirt turned to mud, all grass and corruption grass turned to jungle grass, and finally all vines and corruption vines destroyed.

    Essentially making an entire jungle for a world.
  14. Berserker66

    Berserker66 Umbrella Slime

    Nice - im working on something similar in python, but im by not as far as you yet (only had 30 minutes of time so far..)
    Im more planning to do other set world gens, that differ from the known worlds.
    But first Ill iron out my python based plr and wld reader/writer to publish that one.

    On that note, some tiles have multiple states and stuff.. do you know where a table exists which each id-> tilename
    id -> has multistate
    information? My google-fun is failing me on that one.. of course I could always decompile terraria but I dont like to install yet another software to get a bit of source..
  15. cope

    cope Green Slime

    @Doctor G33K:
    If you're talking about the default terrain generated by Terraria, I won't be able to help you. It is possible to create a tool which modifies existing worlds (e.g. replacing all dirt with mud) but this is not part of this project.

    If by 'multistate' you're referring to the framing, then no, I do not have a list for that. I have some clues, e.g.:

    Plant/Corruption Plant (FrameX)
    0/18/36/54/72/90: different kinds of plants
    108/126: Flowers
    144: Mushroom

    Underground Jungle Plant
    0/18/36/54/72: different plants
    144: Rose
    162: Nature's Gift

    Normally is is sufficient to convert the Tile-graphics into png (there's a tool for that) and count pixels between the different frames of the tilemap. Some other tiles such as trees have various special cases which are spread all over the rendering code.
  16. Cope, I meant an option to have your generator sweep as you did it. Or just flat out, instead of sweep, generate those terrains instead.

    I realize there exist editors to do that manually already, but they're crude and don't work entirely.
  17. MiniManolinho

    MiniManolinho Clinger

    Man, that looks awesome. I mean, like, lol, I'm kinda speechless. Creating New enviroments like a Vulcan or something like that would be extremely awesome! I am loking forward to see you continue working on this. Grats.
    wwortel likes this.
  18. Alethium

    Alethium Green Slime

    Hmm, well if you do add chests there, make sure it doesn't contain any items. Speaking of which, could you make an entire world corrupted? Like all the stone turned into ebstone, and dirt into corrupted dirt?
  19. Actually, the sweep your looking for would be:

    Stone -> Ebonstone
    Grass -> Corrupt Gras
    Vines -> Air

    And probably you'd want to replace some ore with demonite, probably gold above or below a certain height.
  20. Berserker66

    Berserker66 Umbrella Slime

    Ever seen demonity as a tile? No? Guessed so, cause it doesnt exist.

Share This Page