Gameconfig: Allow to overwrite wood type w/ func

master
Wuzzy 2017-12-08 16:17:06 +01:00
parent a6e44526ed
commit a5590a3b46
2 changed files with 35 additions and 16 deletions

View File

@ -19,6 +19,15 @@ tsm_railcorridors.nodes = {
{ wood = "default:pine_wood", post = "default:fence_pine_wood", chance = 3},
{ wood = "default:aspen_wood", post = "default:fence_aspen_wood", chance = 2},
},
-- Alternative to corridor_woods. If specified as a function.
-- this will be called to return the wood type.
-- Parameters:
-- * pos: Position in which the rail corridors start
-- * node: Node table of that position
-- Returns: 2 itemstrings. First one is the wood node, second one is the fence node.
-- Example: "example:wood", "example:fence"
corridor_woods_function = nil,
}
-- List of cart entities. Carts will be placed randomly of the right-hand or left side of

View File

@ -785,6 +785,7 @@ local function place_corridors(main_cave_coords, psra)
if not IsGround(main_cave_coords) then
return
end
local center_node = minetest.get_node(main_cave_coords)
-- Determine if this corridor system is “damaged” (some rails removed) and to which extent
local damage = 0
@ -808,25 +809,34 @@ local function place_corridors(main_cave_coords, psra)
local xs = pr:next(0, 2) < 1
local zs = pr:next(0, 2) < 1;
-- Select random wood type (found in gameconfig.lua)
local rnd = pr:next(1,1000)
-- Get wood and fence post types, using gameconfig.
local woodtype = 1
local accumulated_chance = 0
for w=1, #tsm_railcorridors.nodes.corridor_woods do
local woodtable = tsm_railcorridors.nodes.corridor_woods[w]
accumulated_chance = accumulated_chance + woodtable.chance
if accumulated_chance > 1000 then
minetest.log("warning", "[tsm_railcorridors] Warning: Wood chances add up to over 100%!")
break
end
if rnd <= accumulated_chance then
woodtype = w
break
local wood, post
if tsm_railcorridors.nodes.corridor_woods_function then
-- Get wood type by gameconfig function
wood, post = tsm_railcorridors.nodes.corridor_woods_function(main_cave_coords, center_node)
else
-- Select random wood type (found in gameconfig.lua)
local rnd = pr:next(1,1000)
local woodtype = 1
local accumulated_chance = 0
for w=1, #tsm_railcorridors.nodes.corridor_woods do
local woodtable = tsm_railcorridors.nodes.corridor_woods[w]
accumulated_chance = accumulated_chance + woodtable.chance
if accumulated_chance > 1000 then
minetest.log("warning", "[tsm_railcorridors] Warning: Wood chances add up to over 100%!")
break
end
if rnd <= accumulated_chance then
woodtype = w
break
end
end
wood = tsm_railcorridors.nodes.corridor_woods[woodtype].wood
post = tsm_railcorridors.nodes.corridor_woods[woodtype].post
end
local wood = tsm_railcorridors.nodes.corridor_woods[woodtype].wood
local post = tsm_railcorridors.nodes.corridor_woods[woodtype].post
start_corridor(main_cave_coords, "x", xs, pr:next(way_min,way_max), psra, wood, post, damage, false)
start_corridor(main_cave_coords, "z", zs, pr:next(way_min,way_max), psra, wood, post, damage, false)
-- Auch mal die andere Richtung?