aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/helpers.lua8
-rw-r--r--advtrains/init.lua10
-rw-r--r--advtrains/signals.lua3
-rw-r--r--advtrains/wagons.lua69
4 files changed, 73 insertions, 17 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua
index 172cf07..e58625f 100644
--- a/advtrains/helpers.lua
+++ b/advtrains/helpers.lua
@@ -474,7 +474,13 @@ end
local active_node_range = tonumber(minetest.settings:get("active_block_range"))*16 + 16
-- Function to check whether node at position(pos) is "loaded"/"active"
-- That is, whether it is within the active_block_range to a player
-if minetest.is_block_active then -- define function differently whether minetest.is_block_active is available or not
+if core.compare_block_status then
+ -- latest API
+ function advtrains.is_node_loaded(pos)
+ return core.compare_block_status(pos, "active")
+ end
+elseif minetest.is_block_active then -- define function differently whether minetest.is_block_active is available or not
+ -- API added by my PR but later superseded by the above and now removed
advtrains.is_node_loaded = minetest.is_block_active
else
function advtrains.is_node_loaded(pos)
diff --git a/advtrains/init.lua b/advtrains/init.lua
index fe29260..0d76ec0 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -427,6 +427,16 @@ function advtrains.load_version_4()
if il_save then
advtrains.interlocking.db.load(il_save)
end
+
+ -- TODO 2.5.0 backwards compatibility fallback: Store the pre-v2.5.0 save file so that it can be reverted to if needed
+ local fallback_file = advtrains.fpath.."_interlocking.ls.pre250"
+ local file = io.open(fallback_file, "rb")
+ if file then
+ io.close(file)
+ else
+ atwarn("Backing up pre-2.5.0 version of Interlocking save file to",fallback_file," for potential downgrade to older versions")
+ os.rename(advtrains.fpath.."_interlocking.ls", fallback_file)
+ end
end
--== load lines ==
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index e3d75c3..2b7362e 100644
--- a/advtrains/signals.lua
+++ b/advtrains/signals.lua
@@ -102,6 +102,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
main_aspects = main_aspects,
apply_aspect = simple_apply_aspect("advtrains:retrosignal_off"..rotation, "advtrains:retrosignal_on"..rotation),
get_aspect_info = function() return aspect(r=="on") end,
+ route_role = "main",
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
@@ -153,6 +154,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
main_aspects = main_aspects,
apply_aspect = simple_apply_aspect("advtrains:signal_off"..rotation, "advtrains:signal_on"..rotation),
get_aspect_info = function() return aspect(r=="on") end,
+ route_role = "main",
node_state = f.ls,
node_state_map = { red = "advtrains:signal_off"..rotation, green = "advtrains:signal_on"..rotation},
node_on_switch_state = function(pos, new_node, old_state, new_state)
@@ -224,6 +226,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
main_aspects = main_aspects,
apply_aspect = simple_apply_aspect("advtrains:signal_wall_"..loc.."_off", "advtrains:signal_wall_"..loc.."_on"),
get_aspect_info = function() return aspect(r=="on") end,
+ route_role = "main",
node_state = f.ls,
node_state_map = { red = "advtrains:signal_wall_"..loc.."_off", green = "advtrains:signal_wall_"..loc.."_on" },
node_on_switch_state = function(pos, new_node, old_state, new_state)
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 01c60ec..10576c3 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -461,26 +461,34 @@ function wagon:on_step(dtime)
--needs to know index and path
if train.velocity==0 and self.door_entry and train.door_open and train.door_open~=0 then
--using the mapping created by the trainlogic globalstep
+ local platform_offset = math.floor(self.wagon_width / 2)
for i, ino in ipairs(self.door_entry) do
--fct is the flipstate flag from door animation above
local aci = advtrains.path_get_index_by_offset(train, index, ino*fct)
local ix1, ix2 = advtrains.path_get_adjacent(train, aci)
-- the two wanted positions are ix1 and ix2 + (2nd-1st rotated by 90deg)
-- (x z) rotated by 90deg is (-z x) (http://stackoverflow.com/a/4780141)
- local add = { x = (ix2.z-ix1.z)*train.door_open, y = 0, z = (ix1.x-ix2.x)*train.door_open }
- local pts1=vector.round(vector.add(ix1, add))
- local pts2=vector.round(vector.add(ix2, add))
- if minetest.get_item_group(minetest.get_node(pts1).name, "platform")>0 then
- local ckpts={
- pts1,
- pts2,
- vector.add(pts1, {x=0, y=1, z=0}),
- vector.add(pts2, {x=0, y=1, z=0}),
- }
- for _,ckpos in ipairs(ckpts) do
- local cpp=minetest.pos_to_string(ckpos)
- if advtrains.playersbypts[cpp] then
- self:on_rightclick(advtrains.playersbypts[cpp])
+ local add = {
+ x = atround((ix2.z-ix1.z)*train.door_open),
+ y = 0,
+ z = atround((ix1.x-ix2.x)*train.door_open)
+ }
+ for offset = (platform_offset == 0 and 0 or 1), platform_offset do
+ local scaled_add = vector.multiply(add, offset)
+ local pts1=vector.add(ix1, scaled_add)
+ local pts2=vector.add(ix2, scaled_add)
+ if minetest.get_item_group(minetest.get_node(pts1).name, "platform")>0 then
+ local ckpts={
+ pts1,
+ pts2,
+ vector.add(pts1, {x=0, y=1, z=0}),
+ vector.add(pts2, {x=0, y=1, z=0}),
+ }
+ for _,ckpos in ipairs(ckpts) do
+ local cpp=minetest.pos_to_string(ckpos)
+ if advtrains.playersbypts[cpp] then
+ self:on_rightclick(advtrains.playersbypts[cpp])
+ end
end
end
end
@@ -873,8 +881,8 @@ function wagon:show_wagon_properties(pname)
button: save
]]
local data = advtrains.wagons[self.id]
- local form="size[5,5]"
- form=form.."label[0.2,0;"..attrans("This Wagon ID")..": "..self.id.."]"
+ local form = "size[5,5]"
+ form = form.."label[0.2,0;"..attrans("This Wagon ID")..": "..self.id.." ("..data.owner..")]"
form = form .. "field[0.5,1;4.5,1;whitelist;Allow these players to access your wagon:;"..minetest.formspec_escape(data.whitelist or "").."]"
form = form .. "field[0.5,2;4.5,1;roadnumber;Wagon road number:;"..minetest.formspec_escape(data.roadnumber or "").."]"
local fc = ""
@@ -1557,3 +1565,32 @@ function advtrains.wagon_entity_pairs_in_train(train_id)
if not train then return function() end end
return advtrains.next_wagon_entity_in_train, train, 0
end
+
+minetest.register_chatcommand("at_chown", {
+ params = "<wagon_id> <player_name>",
+ description = "Change the owner of an advtrains wagon",
+ privs = {train_admin=true},
+ func = function(name, param)
+ local params = string.split(param," ")
+ local wid = params[1]
+ local new_owner = params[2]
+ if not wid then return false end --no params added
+ --player name checks
+ if not new_owner then return false, attrans("Please specify a player name to transfer ownership to.") end --no player name argument
+ if not core.player_exists(new_owner) then return false, attrans("That player does not exist!") end --is a valid player
+ --wagon id checks
+ if not wid:match("%d%d%d%d%d%d") then return false, attrans("Not a valid wagon id.") end -- invalid wagon id
+ local w_data = advtrains.wagons[wid]
+ if not w_data then return false, attrans("That wagon does not exist!") end
+ -- actually chown the wagon
+ local curr_owner = w_data.owner
+ w_data.owner = new_owner
+ advtrains.wagons[wid] = w_data
+ advtrains.log("Chown", name, core.get_player_by_name(name):get_pos(), "wid="..wid..", from="..curr_owner..", to="..new_owner)
+
+ if name ~= new_owner then
+ core.chat_send_player(new_owner, attrans("You have been given ownership of wagon @1", wid))
+ end
+ return true, attrans("Wagon @1 ownership changed from @2 to @3", wid, curr_owner, new_owner)
+ end
+}) \ No newline at end of file