aboutsummaryrefslogtreecommitdiff
path: root/advtrains_signals_ks/init.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,
})
span class="hl opt">) > 0 then -- by here, we know that no other protection callback has this protected, we can safely pass "false". -- hope this doesn't lead to bugs! return not advtrains.check_track_protection(pos, pname, nil, false) end local nodes = minetest.find_nodes_in_area( {x = pos.x - npr_r, y = pos.y - npr_vr, z = pos.z - npr_r}, {x = pos.x + npr_r, y = pos.y + npr_vrd, z = pos.z + npr_r}, {"group:advtrains_track"}) for _,npos in ipairs(nodes) do if not advtrains.check_track_protection(npos, pname, pos) then return true end end nocheck=false return false end -- Check whether the player is permitted to modify this track -- Shall be called only for nodes that are or are about to become tracks. -- The range check from is_track_near_protected is disabled here. -- this splits in 1. track_builder privilege and 2. is_protected -- also respects the allow_build_to_owner property. --WARN: true means here that the action is allowed! function advtrains.check_track_protection(pos, pname, near, prot_p) -- Parameter "near" is an optional position, the original node that the player -- was about to affect, while "pos" represents the checked rail node -- if "near" is not set, pos is the same node. local nears = near and "near " or "" local apos = near or pos -- note that having protection_bypass implicitly implies having track_builder, because else it would be possible to dig rails -- (only checked by is_protected, which is not respected) but not place them. -- We won't impose restrictions on protection_bypass owners. if minetest.check_player_privs(pname, {protection_bypass = true}) then return true end nocheck = true local priv = minetest.check_player_privs(pname, {track_builder = true}) -- note: is_protected above already checks the is_protected value against the current player, so checking it again is useless. local prot = prot_p if prot==nil then prot = advtrains.is_protected(pos, pname) end local dprot = minetest.is_protected(pos, "*dummy*") nocheck = false --atdebug("CTP: ",pos,pname,near,prot_p,"priv=",priv,"prot=",prot,"dprot=",dprot) if not priv and (not boo or prot or not dprot) then minetest.chat_send_player(pname, "You are not allowed to build "..nears.."tracks without track_builder privilege") minetest.log("action", pname.." tried to modify terrain "..nears.."track at "..minetest.pos_to_string(apos).." but is not permitted to (no privilege)") return false end if prot then minetest.chat_send_player(pname, "You are not allowed to build "..nears.."tracks at protected position!") minetest.record_protection_violation(pos, pname) minetest.log("action", pname.." tried to modify "..nears.."track at "..minetest.pos_to_string(apos).." but position is protected!") return false end return true end --WARN: true means here that the action is allowed! function advtrains.check_driving_couple_protection(pname, owner, whitelist) if minetest.check_player_privs(pname, {train_admin = true}) then return true end if not minetest.check_player_privs(pname, {train_operator = true}) then return false end if not owner or owner == pname then return true end if whitelist and string.find(" "..whitelist.." ", " "..pname.." ", nil, true) then return true end return false end function advtrains.check_turnout_signal_protection(pos, pname) nocheck=true if not minetest.check_player_privs(pname, {railway_operator = true}) then if boo and not advtrains.is_protected(pos, pname) and minetest.is_protected(pos, "*dummy*") then nocheck=false return true else minetest.chat_send_player(pname, "You are not allowed to operate turnouts and signals (missing railway_operator privilege)") minetest.log("action", pname.." tried to operate turnout/signal at "..minetest.pos_to_string(pos).." but does not have railway_operator") nocheck=false return false end end if advtrains.is_protected(pos, pname) then minetest.record_protection_violation(pos, pname) nocheck=false return false end nocheck=false return true end