Compare commits

...

5 Commits

Author SHA1 Message Date
Andrey01 16c48c7629
Added the folder "sounds" 2017-12-09 17:58:05 +03:00
Andrey01 0fd637b72c
Update p_display.lua 2017-12-09 17:56:37 +03:00
Andrey01 39d1be79ab
Added p_display.lua 2017-12-09 17:56:18 +03:00
Andrey01 d8caf32604
Added loading.lua 2017-12-09 17:54:11 +03:00
Andrey01 d455d5a648
Added the folder "sounds", debugringbuffer.lua and digtron.lua 2017-12-09 17:51:50 +03:00
6 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,44 @@
--so, some ringbuffers one for each train
local ringbuflen=1000
local ringbufs={}
local ringbufcnt={}
function advtrains.drb_record(tid, msg)
if not ringbufs[tid] then
ringbufs[tid]={}
ringbufcnt[tid]=0
end
ringbufs[tid][ringbufcnt[tid]]=msg
ringbufcnt[tid]=ringbufcnt[tid]+1
if ringbufcnt[tid] > ringbuflen then
ringbufcnt[tid]=0
end
end
function advtrains.drb_dump(tid)
atdebug("Debug ring buffer output for '"..tid.."':")
local stopcnt=ringbufcnt[tid]
if not stopcnt then
atdebug("ID unknown!")
return
end
repeat
atdebug(ringbufs[tid][ringbufcnt[tid]])
ringbufcnt[tid]=ringbufcnt[tid]+1
if ringbufcnt[tid] > ringbuflen then
ringbufcnt[tid]=0
end
until ringbufcnt[tid]==stopcnt
end
minetest.register_chatcommand("atdebug_show",
{
params = "train sid", -- Short parameter description
description = "Dump debug log", -- Full description
privs = {train_operator=true}, -- Require the "privs" privilege to run
func = function(name, param)
advtrains.drb_dump(param)
end, -- Called when command is run.
-- Returns boolean success and text output.
})

25
advtrains/digtron.lua Normal file
View File

@ -0,0 +1,25 @@
--digtron.lua
--make tracks placeable by digtrons by overriding the place function.
local old_item_place = digtron.item_place_node
digtron.item_place_node = function(itemstack, placer, place_to, param2)
if minetest.get_item_group(itemstack:get_name(), "advtrains_trackplacer")>0 then
return advtrains.pcall(function()
local def = minetest.registered_items[itemstack:get_name()]
if not def then return itemstack, false end
local pointed_thing = {}
pointed_thing.type = "node"
pointed_thing.above = {x=place_to.x, y=place_to.y, z=place_to.z}
pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z}
--call the on_rightclick callback
local success
itemstack, success = def.on_place(itemstack, placer, pointed_thing)
return itemstack, success
end)
else
return old_item_place(itemstack, placer, place_to, param2)
end
end

46
advtrains/loading.lua Normal file
View File

@ -0,0 +1,46 @@
-- Tracks for loading and unloading trains
-- Copyright (C) 2017 Gabriel Pérez-Cerezo <gabriel@gpcf.eu>
local function get_far_node(pos)
local node = minetest.get_node(pos)
if node.name == "ignore" then
minetest.get_voxel_manip():read_from_map(pos, pos)
node = minetest.get_node(pos)
end
return node
end
local function train_load(pos, train_id, unload)
local train=advtrains.trains[train_id]
local below = get_far_node({x=pos.x, y=pos.y-1, z=pos.z})
if not string.match(below.name, "chest") then
atprint("this is not a chest! at "..minetest.pos_to_string(pos))
return
end
local inv = minetest.get_inventory({type="node", pos={x=pos.x, y=pos.y-1, z=pos.z}})
if inv and train.velocity < 2 then
for k, v in ipairs(train.trainparts) do
local i=minetest.get_inventory({type="detached", name="advtrains_wgn_"..v})
if i then
if not unload then
for _, item in ipairs(inv:get_list("main")) do
if i:get_list("box") and i:room_for_item("box", item) then
i:add_item("box", item)
inv:remove_item("main", item)
end
end
else
for _, item in ipairs(i:get_list("box")) do
if inv:get_list("main") and inv:room_for_item("main", item) then
i:remove_item("box", item)
inv:add_item("main", item)
end
end
end
end
end
end
end

Binary file not shown.

View File

@ -0,0 +1 @@