Terrain Generation

From LugdunonWiki
Revision as of 18:31, 13 October 2013 by Lugdunon (Talk | contribs)

Jump to: navigation, search

Terrain Generation from Images

Lugdunon provides a simple method of generating terrain data from an image file. All you need is the latest lugdunon-server.jar, a suitable image, and a config file. A few things about the terrain data need to be understood beforehand.

  • Worlds are sized as a power of two. This means that both the width and height of your terrain image needs to be a power of two. 512, 1024, and 2048 are popular sizes for getting started experimenting.
  • The terrains in Lugdunon are constructed of layers of terrain types. These are defined in the tileset definition. The default tileset definition defines them like so:
  1. ...
  2. layers:
  3. [
  4.         {name:"Bedrock",  x: 0,y:10,cost:1, elevation:{x: 0,y:24}                },
  5.         {name:"Granite",  x: 3,y:10,cost:1, elevation:{x: 5,y:24}                },
  6.         {name:"Sandstone",x: 6,y:10,cost:5, elevation:{x:10,y:24}                },
  7.         {name:"Sand",     x: 9,y:10,cost:5, elevation:{x:15,y:24}                },
  8.         {name:"Dirt",     x:12,y:10,cost:5, elevation:{x:20,y:24}                },
  9.         {name:"Grass",    x:15,y:10,cost:5, elevation:{x:25,y:24}                },
  10.         {name:"Tilled",   x:18,y:10,cost:10,                      overlays  :5   },
  11.         {name:"Snow",     x:21,y:10,cost:10,elevation:{x:30,y:24},melts     :true},
  12.         {name:"Lava",     x: 0,y:17,cost:5,                       impassable:true},
  13.         {name:"Water",    x: 3,y:17,cost:5,                       impassable:true},
  14.         {name:"Ice",      x: 6,y:17,cost:15                                      }
  15. ],
  16. ...
  • Each terrain layer has an index. That index is the order in which it is defined in the above layers array and it determines which layers physically cover others.
  • Terrain data encapsulates both the terrain layer and the terrain elevation information. At this time, only the terrain layer information is generated by this tool. In the future, support will be added for generating elevation data as well.


For the purposes of this example, we are going to be using the following image:

512x512 Sample Terrain Source
512x512 Sample Terrain Source


If you look closely you can see that there are some roads laid out using the granite layer, paths laid out using the dirt layer, and a few farm plots among the snow, grass, sand, water, lava, and bedrock.


We will also be using the following configuration file:

  1. {
  2.         "tileset":"net.lugdunon.world.defaults.Tileset",
  3.         "seed"   :0,
  4.         "terrain":
  5.         {
  6.                 "image"  :"./512.png",
  7.                 "mapping":
  8.                 {
  9.                         "000000": 0,
  10.                         "9B9B9B": 1,
  11.                         "BA871E": 2,
  12.                         "EDEB3F": 3,
  13.                         "644702": 4,
  14.                         "1B8720": 5,
  15.                         "896716": 6,
  16.                         "BFE1F2": 7,
  17.                         "FF0000": 8,
  18.                         "0012FF": 9,
  19.                         "99BBCD":10
  20.                 }
  21.         }
  22. }


The two most important things in the configuration file are the terrain.image and terrain.mapping entries. Usually tileset and seed should not need changing unless you are looking at more advanced customization, which will soon be discussed in the Custom Config section. terrain.image is the image to be used as input and the terrain.mapping object is used to map the colors in the image to their corresponding layers.


Copy the above configuration entry into a plain text file named 512.json and place it into the same directory as the lugdunon-server.jar and 512.png.


Putting all this together, you should have a folder somewhere on your system that looks something like this:

Expected Terrain Gen Utility File Structure
Expected Terrain Gen Utility File Structure


Now, from the command line, type: java -cp lugdunon-server.jar net.lugdunon.world.terrain.Terrain 512.json 512.dat


The configuration file is supplied as the first argument and the resulting terrain.dat file is supplied as the second argument.


If everything went smoothly, you should have a 512.dat file in your directory. To use your newly generated terrain, first stop your server, place the 512.dat file (renamed to terrain.dat) in your server’s current world/etc/instances/0 directory, and restart your server.


That is all there is to it!