aboutsummaryrefslogtreecommitdiff
path: root/advtrains_signals_ks/init_degrotate_nodes.lua
blob: a4380d23b56ed0641590f42abc98bdf8f88ddf31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- Ks Signals for advtrains
-- will implement the advtrains signal API (which does not exist yet)

local function place_degrotate(pos, placer, itemstack, pointed_thing)
	local yaw = placer:get_look_horizontal()
	local param = math.floor(yaw * 90 / math.pi + 0.5)
	local n = minetest.get_node(pos)
	n.param2 = param
	minetest.set_node(pos, n)
end

minetest.register_node("advtrains_signals_ks:mast", {
	drawtype = "mesh",
	paramtype="light",
	paramtype2="degrotate",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
	},
	mesh = "advtrains_signals_ks_mast.obj",
	tiles = {"advtrains_signals_ks_mast.png"},
	description="Ks Signal Mast",
	sunlight_propagates=true,
	groups = {
		cracky=3,
		not_blocking_trains=1,
		--save_in_at_nodedb=2,
	},
	after_place_node = place_degrotate,
})

minetest.register_node("advtrains_signals_ks:head_main", {
	drawtype = "mesh",
	paramtype="light",
	paramtype2="degrotate",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
	},
	mesh = "advtrains_signals_ks_head_main.obj",
	tiles = {"advtrains_signals_ks_mast.png", "advtrains_signals_ks_head.png"},
	description="Ks Main Signal Screen",
	sunlight_propagates=true,
	groups = {
		cracky=3,
		not_blocking_trains=1,
		--save_in_at_nodedb=2,
	},
	after_place_node = place_degrotate,
})

minetest.register_node("advtrains_signals_ks:zs_top", {
	drawtype = "mesh",
	paramtype="light",
	paramtype2="degrotate",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
	},
	mesh = "advtrains_signals_ks_zs_top.obj",
	tiles = {"advtrains_signals_ks_mast.png", "advtrains_signals_ks_head.png"},
	description="Ks Speed Restriction Signal (top)",
	sunlight_propagates=true,
	groups = {
		cracky=3,
		not_blocking_trains=1,
		--save_in_at_nodedb=2,
	},
	after_place_node = place_degrotate,
})

minetest.register_node("advtrains_signals_ks:zs_bottom", {
	drawtype = "mesh",
	paramtype="light",
	paramtype2="degrotate",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-1/4, -1/2, -1/4, 1/4, 1/2, 1/4},
	},
	mesh = "advtrains_signals_ks_zs_bottom.obj",
	tiles = {"advtrains_signals_ks_mast.png", "advtrains_signals_ks_head.png"},
	description="Ks Speed Restriction Signal (bottom)",
	sunlight_propagates=true,
	groups = {
		cracky=3,
		not_blocking_trains=1,
		--save_in_at_nodedb=2,
	},
	after_place_node = place_degrotate,
})
rase this one too atwarn("Duplicate occupation entry at",pos,"for train",train_id,":",t) i = i - 2 end moving = true end if moving then t[i] = t[i+2] t[i+1] = t[i+3] end i = i + 2 end end -- Checks whether some other train (apart from train_id) has it's 0 zone here function o.check_collision(pos, train_id) local npos = advtrains.round_vector_floor_y(pos) local t = occget(npos) if not t then return end local i = 1 while t[i] do local ti = t[i] if ti~=train_id then local idx = t[i+1] local train = advtrains.trains[ti] --atdebug("checking train",t[i],"index",idx,"<>",train.index,train.end_index) if train and idx >= train.end_index and idx <= train.index then --atdebug("collides.") return train -- return train it collided with so we can couple when shunting is enabled end end i = i + 2 end return false end -- Gets a mapping of train id's to indexes of trains that share this path item with this train -- The train itself will not be included. -- If the requested index position is off-track, returns {}. -- returns (table with train_id->index), position function o.get_occupations(train, index) local ppos, ontrack = advtrains.path_get(train, index) if not ontrack then atlog("Train",train.id,"get_occupations requested off-track",index) return {}, ppos end local pos = advtrains.round_vector_floor_y(ppos) local t = occget(pos) if not t then return {} end local r = {} local i = 1 local train_id = train.id while t[i] do if t[i]~=train_id then r[t[i]] = t[i+1] end i = i + 2 end return r, pos end -- Gets a mapping of train id's to indexes of trains that stand or drive over -- returns (table with train_id->index) function o.get_trains_at(ppos) local pos = advtrains.round_vector_floor_y(ppos) local t = occget(pos) if not t then return {} end local r = {} local i = 1 while t[i] do local train = advtrains.trains[t[i]] local idx = t[i+1] if train.end_index - 0.5 <= idx and idx <= train.index + 0.5 then r[t[i]] = idx end i = i + 2 end return r end -- Gets a mapping of train id's to indexes of trains that have a path -- generated over this node -- returns (table with train_id->index) function o.get_trains_over(ppos) local pos = advtrains.round_vector_floor_y(ppos) local t = occget(pos) if not t then return {} end local r = {} local i = 1 while t[i] do local idx = t[i+1] r[t[i]] = idx i = i + 2 end return r end advtrains.occ = o