Generate carts

master
Wuzzy 2017-08-14 15:03:32 +02:00
parent 064c3821c2
commit 74693ac4d5
3 changed files with 45 additions and 4 deletions

View File

@ -21,6 +21,12 @@ tsm_railcorridors.nodes = {
},
}
-- List of cart entities. Carts will be placed randomly of the right-hand or left side of
-- the main rail.
tsm_railcorridors.carts = {
"carts:cart",
}
if minetest.get_modpath("mobs_monster") then
tsm_railcorridors.nodes.cobweb = "mobs:cobweb"

View File

@ -65,6 +65,13 @@ if setting then
probability_chest = P(setting)
end
-- Probability for every part of a corridor to contain a cart
local probability_cart = P(0.025)
setting = tonumber(minetest.settings:get("tsm_railcorridors_probability_cart"))
if setting then
probability_cart = P(setting)
end
-- Probability for a rail corridor system to be damaged
local probability_damage = P(0.55)
setting = tonumber(minetest.settings:get("tsm_railcorridors_probability_damage"))
@ -505,9 +512,16 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
vek.y = -1
end
end
-- Calculate chest and cart position
local chestplace = -1
if corridor_dug and not up_or_down and pr:next() < probability_chest then
chestplace = pr:next(1,segcount+1)
local cartplace = -1
if corridor_dug and not up_or_down then
if pr:next() < probability_chest then
chestplace = pr:next(1,segcount+1)
end
if tsm_railcorridors.carts and #tsm_railcorridors.carts > 0 and pr:next() < probability_cart then
cartplace = pr:next(1,segcount+1)
end
end
local railsegcount
if not chaos_mode and not corridor_dug then
@ -518,24 +532,42 @@ local function corridor_func(waypoint, coord, sign, up_or_down, up_or_down_next,
railsegcount = segcount
end
for i=1,railsegcount do
-- Precalculate chest position
local p = {x=waypoint.x+vek.x*i, y=waypoint.y+vek.y*i-1, z=waypoint.z+vek.z*i}
if (minetest.get_node({x=p.x,y=p.y-1,z=p.z}).name=="air" and minetest.get_node({x=p.x,y=p.y-3,z=p.z}).name~=tsm_railcorridors.nodes.rail) then
p.y = p.y - 1;
if i == chestplace then
chestplace = chestplace + 1
end
if i == cartplace then
cartplace = cartplace + 1
end
end
-- Chest
if i == chestplace then
if minetest.get_node({x=p.x+vek.z,y=p.y-1,z=p.z-vek.x}).name == post then
if minetest.get_node({x=p.x+vek.z,y=p.y,z=p.z-vek.x}).name == post then
chestplace = chestplace + 1
else
PlaceChest({x=p.x+vek.z,y=p.y,z=p.z-vek.x}, minetest.dir_to_facedir(vek))
end
end
-- Rail and cart
if i == cartplace then
if minetest.get_node({x=p.x+vek.z,y=p.y,z=p.z-vek.x}).name == post then
cartplace = cartplace + 1
else
local cpos = {x=p.x+vek.z,y=p.y,z=p.z-vek.x}
local placed = PlaceRail(cpos)
if placed then
local cart_type = pr:next(1, #tsm_railcorridors.carts)
-- FIXME: The cart sometimes fails to spawn
minetest.add_entity(cpos, tsm_railcorridors.carts[cart_type])
end
end
end
-- Mob spawner (at center)
if place_mob_spawners and tsm_railcorridors.nodes.spawner and not no_spawner and
webperlin_major:get3d(p) > 0.3 and webperlin_minor:get3d(p) > 0.5 then

View File

@ -20,6 +20,9 @@ tsm_railcorridors_probability_fork (Fork probability) float 0.04 0.0 1.0
#Probability (0.0 to 1.0) for every part of a rail corridor to contain a treasure chest.
tsm_railcorridors_probability_chest (Chest probability) float 0.05 0.0 1.0
#Probability (0.0 to 1.0) for every part of a rail corridor to include a cart.
tsm_railcorridors_probability_cart (Cart probability) float 0.025 0.0 1.0
#If enabled, cobwebs may be placed in some corridors.
#Currently, cobwebs are only supported with the Mobs Redo mod.
tsm_railcorridors_place_cobwebs (Cobwebs) bool true