Difference between revisions of "Terrain Generation"

From LugdunonWiki
Jump to: navigation, search
 
Line 1: Line 1:
 +
{{engine}}
 +
 
==Terrain Generation from Images==
 
==Terrain Generation from Images==
  
Line 97: Line 99:
  
 
That is all there is to it!
 
That is all there is to it!
 +
 +
[[Category:Modding|Terrain Generation]]

Latest revision as of 16:54, 15 February 2015

Engine Content: This information applies to the engine and therefore to all servers.

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.                 "preset" :"overWorld",
  7.                 "image"  :"./512",
  8.                 "mapping":
  9.                 {
  10.                         "000000": 0,
  11.                         "9B9B9B": 1,
  12.                         "BA871E": 2,
  13.                         "EDEB3F": 3,
  14.                         "644702": 4,
  15.                         "1B8720": 5,
  16.                         "896716": 6,
  17.                         "BFE1F2": 7,
  18.                         "FF0000": 8,
  19.                         "0012FF": 9,
  20.                         "99BBCD":10
  21.                 },
  22.                 "elevationMapping":
  23.                 {
  24.                         "000000": 0,
  25.                         "404040": 1,
  26.                         "808080": 2,
  27.                         "A0A0A0": 3,
  28.                         "F0F0F0": 4,
  29.                         "400000": 5,
  30.                         "800000": 6,
  31.                         "A00000": 7,
  32.                         "C00000": 8
  33.                 }
  34.         }
  35. }


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!