[Mod] Structures [git] [minetest_mods_structures]

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Wed Jul 10, 2013 18:44

A few more changes today. I added a 'bury' mapgen parameter which allows structures to be spawned that many nodes into the ground (when negative above it). This allows buildings to have basements or other areas hidden underground.

Also separated building-specific functions from the base mapgen file. When roads will be implemented the same will be done for them.
Last edited by MirceaKitsune on Wed Jul 10, 2013 18:44, edited 1 time in total.
 

User avatar
Inocudom
Member
 
Posts: 3051
Joined: Sat Sep 29, 2012 01:14
IRC: Inocudom
In-game: Inocudom

by Inocudom » Wed Jul 10, 2013 19:44

This sounds like it is coming along nicely. I think this would be a great basis for spawning alien ruins in paramat's titan realm.
The comedic value of my videos is how abysmal they are: https://www.youtube.com/channel/UC5cyeM ... YTfYFlih_A
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Thu Jul 11, 2013 23:32

Added a fun little system today. Since node metadata isn't saved with structures, signs are set to have the address of each home. So if any structure contains a sign, its text will be the number (in reality the position of the loop iteration). Signs were added to the houses and tower for this purpose.

Also limited the amount of retries on unloaded areas, so if a place never loads don't keep trying to create a group there forever.

Image

Image

Image

Image
Last edited by MirceaKitsune on Thu Jul 11, 2013 23:33, edited 1 time in total.
 

User avatar
Jordach
Member
 
Posts: 4521
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Fri Jul 12, 2013 04:37

MirceaKitsune: Disable the filtering if youre using a 16x pack...
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Fri Jul 12, 2013 09:59

Jordach wrote:MirceaKitsune: Disable the filtering if youre using a 16x pack...


I usually do that, but temporarily had a HD pack and forgot to.
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Fri Jul 12, 2013 13:08

Today I fixed the terrain corner skip issue (allowed buildings to be supported by air in some cases). Some Lua functionality with tables got me very confused and it took a while until I figured it out. Also converted table.getn(t) to #t which is the correct name now and needed for Lua 5.2 compatibility. This mod is relatively bug-free now, except for some buildings occasionally cutting into each other for a reason not known yet.
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Sat Jul 13, 2013 19:23

Major new feature added today, as an expansion to the address signs. There's now a metadata text file, containing metadata instructions which are applied to nodes in structures that are naturally spawned. The format is:

Code: Select all
name [1], field [2], value [3], probability [4]


For all nodes of type 'name' the 'field' is set to 'value' if 'probability' is true. There can be any number of such lines in the metadata file, and each line is shuffled to eliminate ordering influence to probabilities. The 'value' can also contain expressions which are replaced inside the code (eg: $NAME is converted to the name of the structure).

Currently this is used for address signs. I'm planning to use them to add random inventory to chests, but due to the complex node inventory system it's a bit difficult to (since this only works with meta:set_string commands). If anyone figures out how to set the inventory of a chest using only meta:set_string that would be highly appreciated! Till then this system should be good for several things, and the system will prolly help with features like technic_game's where newly spawned machines can be already functional.
 

Exilyth
Member
 
Posts: 71
Joined: Sun Jul 28, 2013 18:46
Location: Earth

by Exilyth » Sat Aug 03, 2013 18:22

Looks nice, downloading now...

As I said about street generation on the screenshot thread (were I found out about this mod):
"Most cities have a motorway/highway; from which main streets branch off; from which side streets branch off; from which back alleys branch off...

If you look at it like that, you could (ab-)use L-Systems for streets. The hard part would then be assigning buildings to the space between the streets."


Also, there's http://vterrain.org/, which imho is a great source for everything terrain generation related (although it links mostly to academic sources, which tend to be heavy on theory).


Edit:
Finally found this article again - http://procworld.blogspot.de/2012/03/building-rooms.html.
That would be a nice method to get different room layouts for the same building.
Last edited by Exilyth on Mon Aug 05, 2013 10:49, edited 1 time in total.
I'm running 0.4.13 stable with [technic][carts][farming_plus][biome_lib][unified_inventory] and a few other mods.
 

Exilyth
Member
 
Posts: 71
Joined: Sun Jul 28, 2013 18:46
Location: Earth

by Exilyth » Sat Aug 03, 2013 21:29

So, I walked away far enough to generate a chunk with structures in an already existing world...

Code: Select all
...
23:15:17: ACTION[ServerThread]: singleplayer places node default:cobble at (-177,28,853)
23:15:28: ACTION[ServerThread]: singleplayer damaged by 2 hp at (-169.793,21.3,855.318)
23:15:57: ERROR[EmergeThread0]: ERROR: An unhandled exception occurred: LuaError: error: ...\minetest-0.4.7\bin\..\mods\structures/structures_io.lua:29: bad argument #1 to 'byte' (string expected, got nil)
23:15:57: ERROR[EmergeThread0]: stack traceback:

In thread 9b4:
..\..\src\minetest\src\emerge.cpp:472: EmergeThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 9b4:
#0  EmergeThread::Thread
(Leftover data: #1  ServerMap::emergeBlock: p=(-17,3,68), create_blank=0)
(Leftover data: #2  ServerMap::createSector: p2d=(-17,68))
(Leftover data: #3  ServerMap::loadBlock)
DEBUG STACK FOR THREAD 9fc:
#0  main
#1  ClientMap::renderMap
(Leftover data: #2  ClientEnvironment::step)
(Leftover data: #3  Client::Receive)
(Leftover data: #4  Client::ProcessData)
(Leftover data: #5  MeshUpdateQueue::addBlock)
DEBUG STACK FOR THREAD a40:
#0  MeshUpdateThread::Thread
DEBUG STACK FOR THREAD c70:
#0  ServerThread::Thread
#1  Server::Receive
(Leftover data: #2  ServerEnvironment::step)
(Leftover data: #3  Server::SendBlockNoLock)
(Leftover data: #4  Server::SendHP)
(Leftover data: #5  ServerMap::loadBlock)
(Leftover data: #6  ItemStack::deSerialize)


Does this mod require a version of minetest newer than 0.4.7?
I'm running 0.4.13 stable with [technic][carts][farming_plus][biome_lib][unified_inventory] and a few other mods.
 

User avatar
Inocudom
Member
 
Posts: 3051
Joined: Sat Sep 29, 2012 01:14
IRC: Inocudom
In-game: Inocudom

by Inocudom » Sat Aug 03, 2013 23:26

Exilyth wrote:So, I walked away far enough to generate a chunk with structures in an already existing world...

Code: Select all
...
23:15:17: ACTION[ServerThread]: singleplayer places node default:cobble at (-177,28,853)
23:15:28: ACTION[ServerThread]: singleplayer damaged by 2 hp at (-169.793,21.3,855.318)
23:15:57: ERROR[EmergeThread0]: ERROR: An unhandled exception occurred: LuaError: error: ...\minetest-0.4.7\bin\..\mods\structures/structures_io.lua:29: bad argument #1 to 'byte' (string expected, got nil)
23:15:57: ERROR[EmergeThread0]: stack traceback:

In thread 9b4:
..\..\src\minetest\src\emerge.cpp:472: EmergeThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 9b4:
#0  EmergeThread::Thread
(Leftover data: #1  ServerMap::emergeBlock: p=(-17,3,68), create_blank=0)
(Leftover data: #2  ServerMap::createSector: p2d=(-17,68))
(Leftover data: #3  ServerMap::loadBlock)
DEBUG STACK FOR THREAD 9fc:
#0  main
#1  ClientMap::renderMap
(Leftover data: #2  ClientEnvironment::step)
(Leftover data: #3  Client::Receive)
(Leftover data: #4  Client::ProcessData)
(Leftover data: #5  MeshUpdateQueue::addBlock)
DEBUG STACK FOR THREAD a40:
#0  MeshUpdateThread::Thread
DEBUG STACK FOR THREAD c70:
#0  ServerThread::Thread
#1  Server::Receive
(Leftover data: #2  ServerEnvironment::step)
(Leftover data: #3  Server::SendBlockNoLock)
(Leftover data: #4  Server::SendHP)
(Leftover data: #5  ServerMap::loadBlock)
(Leftover data: #6  ItemStack::deSerialize)


Does this mod require a version of minetest newer than 0.4.7?


It is very likely that it does. Try using the latest development build from either PilzAdam, Sfan5, or Fess.
The comedic value of my videos is how abysmal they are: https://www.youtube.com/channel/UC5cyeM ... YTfYFlih_A
 

Nore
Developer
 
Posts: 501
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Tue Aug 06, 2013 08:45

You could try to make a flat area for the village using code similar to this one (this one is only a proof-of-concept for smoothing the terrain around the flat area, and you will need to run it in a new world because it changes the mapgen to a very simple one).
Code: Select all
local DMAX = 20
local AREA_SIZE = 80

minetest.register_on_mapgen_init(function(mgparams)
        minetest.set_mapgen_params({mgname="singlenode", flags="nolight", flagmask="nolight"})
end)

local cache = {}


local function get_base_surface_at_point(x, z, noise)
    local index = 65536*x+z
    if cache[index] ~= nil then return cache[index] end
    cache[index] = 20*noise:get2d({x=x, y=z})
    return cache[index]
end

local function surface_at_point(x, z, noise)
    if -AREA_SIZE<x and x<AREA_SIZE and -AREA_SIZE<z and z<AREA_SIZE then
        if flat_height~=nil then return flat_height end
        local s=0
        local n=0
        for x1=-AREA_SIZE, AREA_SIZE do
            n=n+2
            s=s+get_base_surface_at_point(x1, -AREA_SIZE, noise)+get_base_surface_at_point(x1, AREA_SIZE, noise)
        end
        for y1=-AREA_SIZE+1, AREA_SIZE-1 do
            n=n+2
            s=s+get_base_surface_at_point(-AREA_SIZE, y1, noise)+get_base_surface_at_point(AREA_SIZE, y1, noise)
        end
        flat_height = s/n
        return s/n
    end
    return get_base_surface_at_point(x, z, noise)
end

local SMOOTHED = AREA_SIZE+2*DMAX
local HSMOOTHED = AREA_SIZE+DMAX
local INSIDE = AREA_SIZE-DMAX

local function smooth(x, z, noise)
    local s=0
    local w=0
    for xi=-DMAX, DMAX do
    for zi=-DMAX, DMAX do
        local d2=xi*xi+zi*zi
        if d2<DMAX*DMAX then
            local w1 = 1-d2/(DMAX*DMAX)
            local w2 = 15/16*w1*w1
            w = w+w2
            s=s+w2*surface_at_point(x+xi, z+zi, noise)
        end
    end
    end
    return s/w
end

local function smooth_surface(x, z, noise)
    if -SMOOTHED>x or x>SMOOTHED or -SMOOTHED>z or z>SMOOTHED then return surface_at_point(x, z, noise) end
    if -INSIDE<x and x<INSIDE and -INSIDE<z and z<INSIDE then return surface_at_point(x, z, noise) end
    if -HSMOOTHED>x or x>HSMOOTHED or -HSMOOTHED>z or z>HSMOOTHED then
        local s = surface_at_point(x, z, noise)
        local s1 = smooth(x, z, noise)
        local m = math.max(math.abs(x), math.abs(z))
        return ((m-HSMOOTHED)*s+(SMOOTHED-m)*s1)/DMAX
    end
    return smooth(x, z, noise)
end


minetest.register_on_generated(function(minp, maxp, seed)
    local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
        local a = VoxelArea:new{
                MinEdge={x=emin.x, y=emin.y, z=emin.z},
                MaxEdge={x=emax.x, y=emax.y, z=emax.z},
        }
 
        local data = vm:get_data()
 
        local c_grass  = minetest.get_content_id("default:dirt_with_grass")
       
        local noise = minetest.get_perlin(12345, 6, 0.5, 256)
       
        local ni = 1
        for z = minp.z, maxp.z do
        for x = minp.x, maxp.x do
            local y=math.floor(smooth_surface(x, z, noise))
            if y<=maxp.y and y>=minp.y then
                local vi = a:index(x, y, z)
                data[vi] = c_grass
            end
        end
        end
       
        vm:set_data(data)
       
        vm:calc_lighting(
                {x=minp.x-16, y=minp.y, z=minp.z-16},
                {x=maxp.x+16, y=maxp.y, z=maxp.z+16}
        )
 
        vm:write_to_map(data)
end)


License of the code: WTFPL
 

Sokomine
Member
 
Posts: 3765
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

by Sokomine » Tue Aug 06, 2013 15:15

Nore wrote:You could try to make a flat area for the village using code similar to this one (this one is only a proof-of-concept for smoothing the terrain around the flat area, and you will need to run it in a new world because it changes the mapgen to a very simple one).

I'm using a flat terrain for the villages mod I'm working on. Skipping height issues and concentrating on village planning in 2d is a great step forward towards realistic-looking villages with roads. I can only recommend it! Since the villages are later on supposed to "work" on a normal map, I'll have to flatten the land manually. This will most likely be a job for voxelmanip.
A list of my mods can be found here.
 

Nore
Developer
 
Posts: 501
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Tue Aug 06, 2013 15:20

So on a normal map, you will need to flatten the land in the area the village will be. The code I posted should help you to smooth around to avoid edge effects.
 

User avatar
Inocudom
Member
 
Posts: 3051
Joined: Sat Sep 29, 2012 01:14
IRC: Inocudom
In-game: Inocudom

by Inocudom » Mon Aug 19, 2013 03:26

https://forum.minetest.net/viewtopic.php?pid=106250#p106250
The above link leads to a new mod that could be of great assistance.
The comedic value of my videos is how abysmal they are: https://www.youtube.com/channel/UC5cyeM ... YTfYFlih_A
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Fri Oct 25, 2013 14:17

I am happy to announce the next version of the Structures mod, with some of the biggest changes since its creation. After nearly two weeks of intensive coding, many components were entirely reformed and a load of new features was added. This is the primary change log:

- Road support is here! Roads use a point branching formula, which starts with one point that randomly branches into other points and so on. Roads are defined as sets of 5 schematics (P, I, L, T, X) which are segment and intersection types. All segments must be square and have the same size horizontally.

- Support for floors. When enabled, buildings are composed of 3 schematics (start, middle, end). Start is placed at floor level, middle is looped upward as the "floors" option specifies, end is placed at the top. This allows the creation of tall apartments, skyscrapers, etc.

- Terrain roughness check and floor creation are now group actions rather than structure actions. The area towns take up is now flattened, and all buildings and roads are aligned to the same height.

- Metadata is now a group option rather than global, allowing each town to define its own metadata settings for any node.

- Completely new sorting and alignment pattern for buildings, which uses space more efficiently via bounding box detection.

- Numeric properties of buildings and roads in mapgen.txt accept a space separated list, allowing artists to specify a minimum and maximum value that will be randomized. This means that for each instance, structures can have a random count, height offset, and number of floors. It's also possible to specify multiple trigger nodes and floor nodes for groups.

- Heavy remake of the default town. Several new structures were added, all old ones were replaced or remade. Houses now have gardens as well as basements. Roads have street lights, as well as underground sewer systems which players can navigate and explore. The town floor is randomly composed of either dirt with grass, or cobble for a paved area. The new town feels much more colorful and complete now.

[spoiler=screenshots]Image

Image

Image

Image

Image

Image

Image

Image[/spoiler]

Unfortunately, the mod is not ready to spawn large cities yet. Its architecture still requires the area to have been explored, building the group afterward. Structures are also placed all at once, making the server lag a LOT at spawn time. For this reason, it's not ready for stable use yet. I need to integrate a flatten mod or Lua mapgen, then have structures spawn progressively with on_generate. Till then, feel free to test and let me know what you think.
 

User avatar
webdesigner97
Member
 
Posts: 1325
Joined: Mon Jul 30, 2012 19:16
Location: Bergisch Gladbach, Germany
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97
 

User avatar
paramat
Developer
 
Posts: 3357
Joined: Sun Oct 28, 2012 00:05
Location: UK
GitHub: paramat
IRC: paramat

by paramat » Fri Oct 25, 2013 22:10

Very cool, is that a sewer level below the roads in the last screenshot?
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

by MirceaKitsune » Sat Oct 26, 2013 00:45

paramat wrote:Very cool, is that a sewer level below the roads in the last screenshot?


Yes. The bury option exists for both buildings and roads, so with it one can create tunnels under roads like sewers. The new town's road segments all have a sewer system, manholes available at the ends of roads.
 

Azuna
Member
 
Posts: 89
Joined: Fri Sep 27, 2013 22:50

by Azuna » Thu Jan 09, 2014 22:27

i wil try it for ya and write what i see :D i need small village for my game
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Re: [Mod] Structure I/O & mapgen mod

by MirceaKitsune » Sun Jun 14, 2015 00:00

It's been quite a while since I've last updated this mod, or this thread has been active. I'm pushing forward to begin creating my game, and one of the things it will absolutely need are large towns and villages. I've looked into various methods of implementing such, but nothing so far seems to fit what I need by far as much as this mod. I want to get back into working on it.

As it's probably been said last time, most of the basics are ready. There's only one major problem: The entire area the city goes in must be loaded and active, so the ground can be scanned. After that, a huge zone is virtually deleted and hundreds of schematics are placed at once. Needless to say, this makes it impossible to create large cities, and also freezes the Minetest server for quite a few seconds during the process.

My plan is to use virtual boxes representing a city's area, each box becoming activated and planning the city the moment it's "touched" by the first on_generate function in that area. That way, a list of buildings can be persisted instead, and each individual schematic will be placed by the first on_generate function that touches it. It will be tricky, but I think I'll find some way of pulling it off.

For now, the mod is still working perfectly with latest Minetest GIT, and usable as is for medium sized towns. If you like its idea and want to suggest more changes, feel free to try it out and let me know what you think! Looking back at the Lua code I wrote those two years ago, I'm certainly happy with what I managed to do and how it's worked until now.
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Re: [Mod] Structure I/O & mapgen mod

by MirceaKitsune » Sun Jun 14, 2015 23:16

The magic has happened today! Or at least the main part of it. I've almost entirely rewritten the basic mapgen system, going for a completely new and different approach, aimed at allowing colossally large cities to be created.

Cities are generated based on a grid representing virtual cubes, currently defaulted to 500 nodes horizontally and 100 vertically. There can only be one city per cube, and cities may not be larger than cubes. Each cube is activated when the first mapblock inside it is generated. When the cube initialized, a structure group is randomly chosen. If successful, the city is planned and a list of all the group's structures is generated for that cube. Each on_generate function will only spawn those buildings within its area, no more spawning everything in one go. To reduce server stress, a random delay is applied to each schematic after on_generate has executed, currently ranging from 5 to 10 seconds.

Of course, there are upsides and downsides. The upside is that cities of virtually any size can be generated, for the same lag level as the previous mechanism. The downside is that all buildings are planned before any area in the cube loads, meaning you can no longer measure any nodes before the city is created. For this reason, cities are currently generated either floating or buried underground, without a proper way to build a floor or cut the surrounding area... I do not know how I will find a proper solution to this.

Here's a screenshot of an enormous town, planned in one go but spawned across multiple mapblocks (on_generate events). It's somewhat less than 500 x 500 nodes... my ultimate aim is a town of 1000 x 1000 nodes (one kilometer). The experimental code can be found in this Github branch, where it will stay until I can get it working decently enough for master.

Image
 

Sokomine
Member
 
Posts: 3765
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

Re: [Mod] Structure I/O & mapgen mod

by Sokomine » Mon Jun 15, 2015 03:10

MirceaKitsune wrote:Cities are generated based on a grid representing virtual cubes, currently defaulted to 500 nodes horizontally and 100 vertically. There can only be one city per cube, and cities may not be larger than cubes. Each cube is activated when the first mapblock inside it is generated.

Nores mapgen works with noise for the villages. That does have a number of advantages later on - in particular when adjusting the sourrounding terrain. It also helps in other situations.

MirceaKitsune wrote:When the cube initialized, a structure group is randomly chosen. If successful, the city is planned and a list of all the group's structures is generated for that cube. Each on_generate function will only spawn those buildings within its area, no more spawning everything in one go. To reduce server stress, a random delay is applied to each schematic after on_generate has executed, currently ranging from 5 to 10 seconds.

There's no need for that delay. The "list of all group's structures" is very intresting of course. In effect, that's what a village from mg_villages consists of as well.

MirceaKitsune wrote:Of course, there are upsides and downsides. The upside is that cities of virtually any size can be generated, for the same lag level as the previous mechanism. The downside is that all buildings are planned before any area in the cube loads, meaning you can no longer measure any nodes before the city is created. For this reason, cities are currently generated either floating or buried underground, without a proper way to build a floor or cut the surrounding area... I do not know how I will find a proper solution to this.

It's best to pretend the area your city spawned in had always been at that height and just make it look convincing. There needs to be a mechanism for smoothening the borders - where the city intersects with the rest of the terrain.

MirceaKitsune wrote:Here's a screenshot of an enormous town, planned in one go but spawned across multiple mapblocks (on_generate events). It's somewhat less than 500 x 500 nodes... my ultimate aim is a town of 1000 x 1000 nodes (one kilometer). The experimental code can be found in this Github branch, where it will stay until I can get it working decently enough for master.

That size is bigger than what can currently be done with mg_villages, but that has other reasons. The search range for any nearby villages is limited. If a village size (or, in your case, a town) exceeds this range, those parts that are too far away will not be generated.

It's understandable if you want to do it your own way and in the process learn more about mapgen. But you'll run into the same problems I've encountered and arrive - in most cases - at a similar solution. Therefore, it would be nice if you could do that part that is really diffrent from the villages and leave the rest (at least for now) to an existing mod that can handle it. You're creating a town - not a village. The buildings will be diffrent (closer together - even multiple-story, if I remember your plans correctly), the streets will be diffrent (schematics instead of gravel paths). You might even wish for each building to be diffrent.

Your current town generator may already be sufficiently similar to the village generator. The later one can be found in villages.lua in the function mg_villages.generate_village. Said function generates the entire village - including name, replacements etc. The function generate_bpos( village, pseudo_random_generator, village_noise, space_between_buildings) has the job of deciding which building will be placed where, and how it will be rotated. generate_bpos needs to return a table (as a list) containing all structures that are to be placed. Each entry in the table returned needs to have the following internal structure:
Code: Select all
{x=pos.x, y=pos.y, z=pos.z, btype=btype, bsizex=bsizex, bsizez=bsizez, brotate = rotation, o=orient1, mirror=mirror }

...for building "btype" to be placed at (absolute) position pos. "btype" is the id of the schematic. A list of suitable ids can be obtained through mg_villages.village_type_data[ village_type ][ 'building_list'] . bsizex and bsizez show how far the building extends in each direction. Both depend on the schematic size and rotation and are included for convenience. brotate is the rotation of the building, and o the orientation of the plot of land the house is built on - which is relevant for the plotmarker that later on allows to buy the house. mirror can be set to true in order to get the house mirrored. Mirroring does not work perfect with nodebox-like nodes. Further information about a building (size, possible rotations) can be obtained through mg_villages.BUILDINGS[btype], which contains entries like sizex, sizez, ysize and orients (indicating which orientation is acceptable for that building). Those building-specific values are read from the schematic file when the building is registered. The village_gambit mod shows how a new village type can be regisered, complete with its own buildings.
A list of my mods can be found here.
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Re: [Mod] Structure I/O & mapgen mod

by MirceaKitsune » Mon Jun 15, 2015 12:22

Sokomine wrote:


Your villages mod sounds very interesting too! Sorry I didn't get to try it out and look more into how it works. Some things are probably better in its case, as this mod has its fair share of bottlenecks. A combination between the two might be interesting as well... for now however, I want to finish this mod the way I intended it and see where I get.

In any case, this mod was designed to be very flexible; The functions that generate the road and building lists are separated into their own files, and can easily be called to get a list of schematics. This is basically the bit of code responsible for fetching the structure list:

Code: Select all
   -- get the the buildings and roads lists
   local schemes_roads, rectangles_roads = mapgen_roads_get(pos, scale.h, group)
   local schemes_buildings = mapgen_buildings_get(pos, scale.h, rectangles_roads, group)
   -- add everything to one scheme
   -- buildings should be first, so they're represented most accurately by metadata numbers
   local schemes = schemes_buildings
   for w, road in ipairs(schemes_roads) do
      table.insert(schemes, road)
   end


Simply use the schemes table and that's it. Of course there is a lot more going on to get there, such as translating the structures text file into a table.
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Re: [Mod] Structure I/O & mapgen mod

by MirceaKitsune » Mon Jun 15, 2015 22:52

Today's changes represent a great step toward readying the new mapgen system. Changes include:

First of all, towns are no longer defined in a text file under a poor and confusing format, but directly in Lua as tables (a similar format to my Creatures mod). This is both faster, easier to maintain (add or remove properties) and will allow implementing custom functions which can run at generation time.

Next, town height is now determined by a 2D perlin map. You can also define the biomes that a town will spawn in (only works with mgv5 or mgv7). The issue of floating / buried towns can now be somewhat fixed, by synchronizing this with the perlin map of the biome the town spawns in, which should cause the town to be placed at the highest spot. However this must be done manually, as there is no way to know the perlin map of each terrain automatically.

Other improvements and cleanups were made. Town sizes are now calculated when the server starts, not every time a virtual cube is activated and we plan a town, which was a great waste of performance.

Also, since we now know the size of each town straight away, the scale of the virtual cube is automatically determined, and is basically the scale of the largest town. Additional multipliers are in place, which can be used to allow the largest town to have more room to randomly appear in (especially important for height).
 

User avatar
MirceaKitsune
Member
 
Posts: 852
Joined: Sat May 21, 2011 22:31
Location: Romania, Bucharest
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune

Re: [Mod] Structure I/O & mapgen mod

by MirceaKitsune » Tue Jun 16, 2015 23:06

Today has been a blast for this mod! I've done a great amount of improvements and fixes, as well as adding crucial new features. The new system is now stable and very close to being ready. A list of everything that has been changed today:

- Perlin noise no longer determines a global height for the group. Individual structures now have their own height, determined by the perlin noise at their exact position! Yes... this means that there are now bumpy roads (deviated by 1 node by default) and each building should be possible to align with the terrain (as long as you're using the exact same perlin noise parameters at the biome the structure is spawning on). You can optionally specify how centered each structure should be, between the minimum and maximum values determined by the noise.

- Layers have been at last implemented! Each structure can be assigned to a layer (number) or to none so it affects all layers. Structures will only check for collisions against other structures on the same layer, and will cut through structures on a different layer. This means that you can now create underground tunnels or suspended highways, which will not avoid the roads and buildings at ground level... you can also make some roads cut through other roads.

- Custom spawn functions are here, three in total: The first runs after the group is chosen and before the town is planned, and can return false to abort creating that town. The second and third run with each structure that is being spawned, one before the schematic is placed and one afterward... the first can also return false to abort creating that structure. The old metadata system (used to put addresses on signs) was removed with this, and address mechanics are now set by the town definition.

- Fix the structure spawning delay, heavily reducing lag. It was delaying chunks instead of individual schematics... now each schematic will be placed after (delay x number) seconds, where delay is a configurable value (by default 0.1) and number is the position of the structure in the table. This means that if the delay is 0.1 and a town has 1000 structures, the town will finish spawning in 100 seconds... granted all of it was generated on a single chunk.

- The virtual cubes are now persisted after server shutdown, in a text file in the world directory. This allows towns to be remembered after you restart the server, and let buildings who weren't spawned (because their chunk wasn't explored yet) resume spawning.

- A new property was added for roads, which lets you specify the minimum number of segments after which it branches. Can be used to specify how often that type of road can steer.

Here are a few new screenshots. The first four show bumpy roads and offset buildings, which were enabled for the default town. The last is me testing a suspended road system using the new layers.

+ Spoiler
 

PreviousNext

Return to Mod Releases



Who is online

Users browsing this forum: PolySaken and 5 guests