Fix map, fix train placing
This commit is contained in:
parent
bc8c04d146
commit
8371d8496a
|
@ -267,7 +267,8 @@ function ildb.check_and_repair_ts_at_pos(pos, tcb_connid)
|
||||||
if ildb.get_tcb(pos) then
|
if ildb.get_tcb(pos) then
|
||||||
if not tcb_connid then error("check_and_repair_ts_at_pos: Startpoint is TCB, must provide tcb_connid!") end
|
if not tcb_connid then error("check_and_repair_ts_at_pos: Startpoint is TCB, must provide tcb_connid!") end
|
||||||
else
|
else
|
||||||
if tcb_connid then error("check_and_repair_ts_at_pos: Startpoint is not TCB, must not provide tcb_connid!") end
|
--if tcb_connid then error("check_and_repair_ts_at_pos: Startpoint is not TCB, must not provide tcb_connid!") end
|
||||||
|
-- do not give error here, for some applications do not require it
|
||||||
end
|
end
|
||||||
-- STEP 1: Ensure that only one section is at this place
|
-- STEP 1: Ensure that only one section is at this place
|
||||||
-- get all TCBs adjacent to this
|
-- get all TCBs adjacent to this
|
||||||
|
|
|
@ -167,13 +167,13 @@ advtrains.te_register_on_create(function(id, train)
|
||||||
-- let's see what track sections we find here
|
-- let's see what track sections we find here
|
||||||
local index = atround(train.index)
|
local index = atround(train.index)
|
||||||
local pos = advtrains.path_get(train, index)
|
local pos = advtrains.path_get(train, index)
|
||||||
local ts_id, origin = ildb.get_ts_at_pos(pos)
|
local ts_id = ildb.check_and_repair_ts_at_pos(pos, 1) -- passing connid 1 - that always exists
|
||||||
if ts_id then
|
if ts_id then
|
||||||
local ts = ildb.get_ts(ts_id)
|
local ts = ildb.get_ts(ts_id)
|
||||||
if ts then
|
if ts then
|
||||||
setsection(id, train, ts_id, ts, origin)
|
setsection(id, train, ts_id, ts, origin)
|
||||||
else
|
else
|
||||||
atwarn("ILDB corruption: TCB",origin," has invalid TS reference")
|
atwarn("While placing train, TS didnt exist ",ts_id)
|
||||||
end
|
end
|
||||||
-- Make train a shunt move
|
-- Make train a shunt move
|
||||||
train.is_shunt = true
|
train.is_shunt = true
|
||||||
|
|
|
@ -10,9 +10,9 @@ local TS_MAX_SCAN = 1000
|
||||||
-- The characters will be chosen from the unicode frame set if appropriate
|
-- The characters will be chosen from the unicode frame set if appropriate
|
||||||
-- valid character classes -, =, |
|
-- valid character classes -, =, |
|
||||||
local char_equiv = {
|
local char_equiv = {
|
||||||
["-"] = {"│", "/", "─", "\\"}, -- single-line
|
["-"] = {"│", "/", "─", "\\\\"}, -- single-line
|
||||||
["="] = {"║", "/", "═", "\\"}, -- double-line
|
["="] = {"║", "/", "═", "\\\\"}, -- double-line
|
||||||
["|"] = {"─", "\\", "│", "/"}, -- break (i.e. TCB, perpendicular to orientation)
|
["|"] = {"─", "\\\\", "│", "/"}, -- break (i.e. TCB, perpendicular to orientation)
|
||||||
}
|
}
|
||||||
local dir_to_charmap = {
|
local dir_to_charmap = {
|
||||||
[15] = 1,
|
[15] = 1,
|
||||||
|
@ -33,6 +33,7 @@ local dir_to_charmap = {
|
||||||
[14] = 4,
|
[14] = 4,
|
||||||
}
|
}
|
||||||
function tm.rotate_char_class_by_conn(chr, conndir)
|
function tm.rotate_char_class_by_conn(chr, conndir)
|
||||||
|
atdebug("rotatechar", chr, conndir, "dircharmap", dir_to_charmap[conndir], "charequiv", char_equiv[chr])
|
||||||
return char_equiv[chr][dir_to_charmap[conndir]]
|
return char_equiv[chr][dir_to_charmap[conndir]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,14 +63,16 @@ function tm.generate_grid_map(start_pos, node_callback)
|
||||||
local ok, conns = advtrains.get_rail_info_at(pos)
|
local ok, conns = advtrains.get_rail_info_at(pos)
|
||||||
local c = node_callback(pos, conns, connid)
|
local c = node_callback(pos, conns, connid)
|
||||||
local chr = c and c.char
|
local chr = c and c.char
|
||||||
|
atdebug("init",pos.x,pos.z,chr,"")
|
||||||
if not chr then
|
if not chr then
|
||||||
chr = tm.rotate_char_class_by_conn("=", conns[connid])
|
chr = tm.rotate_char_class_by_conn("=", conns[connid].c)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add the char to the grid
|
-- add the char to the grid
|
||||||
if not grid[pos.x] then
|
if not grid[pos.x] then
|
||||||
grid[pos.x] = {}
|
grid[pos.x] = {}
|
||||||
end
|
end
|
||||||
|
atdebug("final",pos.x,pos.z,chr,"")
|
||||||
grid[pos.x][pos.z] = chr
|
grid[pos.x][pos.z] = chr
|
||||||
|
|
||||||
gminx = math.min(gminx, pos.x)
|
gminx = math.min(gminx, pos.x)
|
||||||
|
|
|
@ -15,7 +15,7 @@ local function node_left_click(pos, pname)
|
||||||
end
|
end
|
||||||
|
|
||||||
local gridtbl = tm.generate_grid_map(pos, node_callback)
|
local gridtbl = tm.generate_grid_map(pos, node_callback)
|
||||||
local fslabel = tm.render_grid(gridtbl.grid, gridtbl.min_pos, 100, 100)
|
local fslabel = tm.render_grid(gridtbl.grid, {x=pos.x-30, z=pos.z-25}, 60, 50)
|
||||||
|
|
||||||
minetest.show_formspec(pname, "advtrains_trackmap:test", "size[20,20]"..fslabel)
|
minetest.show_formspec(pname, "advtrains_trackmap:test", "size[20,20]"..fslabel)
|
||||||
end
|
end
|
||||||
|
@ -32,10 +32,6 @@ minetest.register_craftitem("advtrains_trackmap:tool",{
|
||||||
if not pname then
|
if not pname then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not minetest.check_player_privs(pname, {interlocking=true}) then
|
|
||||||
minetest.chat_send_player(pname, "Insufficient privileges to use this!")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if pointed_thing.type=="node" then
|
if pointed_thing.type=="node" then
|
||||||
local pos=pointed_thing.under
|
local pos=pointed_thing.under
|
||||||
node_left_click(pos, pname)
|
node_left_click(pos, pname)
|
||||||
|
|
Loading…
Reference in New Issue