-
Notifications
You must be signed in to change notification settings - Fork 0
Create a new landform
LandformTemplateRandomPoints, LandformTemplateSpreadPoints
Let's create a new landform called "Rocks" for this example which depends on Mountains (meaning, it's not possible to have rocks without mountains). Our new landform will be based on the LandformTemplateRandomPoints
(derived of LandformQuantity
).
Create a new C# Script wherever you want inside your project called LandformRocks
and open it for edition.
Add a new using directive at the top of the file using Hexamap;
and make your class derives from the class LandformTemplateRandomPoints
.
We now add 2 attributes to our class : LandformName
and LandformDependency
(class attributes have to go before the class declaration) in order to specify the name and the dependency of our landform. After that we add the constructor of the landform based on the constructor of the template.
using Hexamap;
using System.Collections.Generic;
[LandformName("Rocks")]
[LandformDependency(typeof(LandformMountains))]
public class LandformRocks : LandformTemplateRandomPoints
{
public LandformRocks(Biome biome, IEnumerable<Coords> allocatedCoords, int maxQuantity)
: base(biome, allocatedCoords, maxQuantity)
{
}
}
Note : here we could also define the value of the MinSize
property in the constructor but there is no point to do it for our example.
That's it ! Go back to the settings of the map and you will be able to select your new landform.
This is, of course, a basic example of how to start making your own landforms with Hexamap. Creating landforms from template should always be this simple.
LandformTemplateConnection, LandformTemplateNoiseCubic, LandformTemplateNoisePerlin
When working with these templates you will notice they are actually generic classes. The procedure is the same as above for simple templates, we are going to address the specific part of each one.
The <T>
of the base class is the type of the landform you want to connect.
[LandformName("Rivers")]
[LandformDependency(typeof(LandformLake))]
public class LandformRiver : LandformTemplateConnection<LandformLake>
{
public LandformRiver(Biome biome, IEnumerable<Coords> allocatedCoords)
: base(biome, allocatedCoords)
{
RandomFunction = () => Map.RandomObject.Next(0, 100);
}
}
For example, for the river landform, we connect lakes together. When using this template this is also possible to define a RandomFunction
, it will be used by the A* algorithm when calculating the weight of each node on the path. Adding a random factor to weights provides more naturally looking path but less optimal.
The <T>
of the base class is the type of your landform.
[LandformName("Mountains")]
public class LandformMountains : LandformTemplateNoisePerlin<LandformMountains>
{
public LandformMountains(Biome biome, IEnumerable<Coords> allocatedCoords, int maxSize)
: base(biome, allocatedCoords, maxSize)
{
MinSize = (int)(biome.Size * 0.0015);
NoiseFrequency = 0.12f;
}
}
Notice you can also specify 2 options :
-
MinSize
: the minimum size of the landform, if the landform generated is smaller, it will be discarded -
NoiseFrequency
: the frequency of the noise