aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2021-01-19 17:41:09 +0100
committerywang <yw05@forksworld.de>2021-01-20 17:28:01 +0100
commit61d0378ad6b988e6bb1f0ca2766c444bd0afa9ed (patch)
tree39e4a3018f02ad11454a4d3fc43fe2300e533a78
parentef21e70479d31973e47988a2246870ddc429226a (diff)
downloadadvtrains-61d0378ad6b988e6bb1f0ca2766c444bd0afa9ed.tar.gz
advtrains-61d0378ad6b988e6bb1f0ca2766c444bd0afa9ed.tar.bz2
advtrains-61d0378ad6b988e6bb1f0ca2766c444bd0afa9ed.zip
Implement Sifa; add textures for PZB
-rw-r--r--advtrains/textures/advtrains_hud_1000hz.pngbin0 -> 2289 bytes
-rw-r--r--advtrains/textures/advtrains_hud_500hz.pngbin0 -> 1479 bytes
-rw-r--r--advtrains/textures/advtrains_hud_pzb.pngbin0 -> 1088 bytes
-rw-r--r--advtrains/textures/advtrains_hud_sifa.pngbin0 -> 826 bytes
-rw-r--r--advtrains/trainhud.lua18
-rw-r--r--advtrains/trainlogic.lua18
-rw-r--r--advtrains/wagons.lua9
7 files changed, 36 insertions, 9 deletions
diff --git a/advtrains/textures/advtrains_hud_1000hz.png b/advtrains/textures/advtrains_hud_1000hz.png
new file mode 100644
index 0000000..09a9502
--- /dev/null
+++ b/advtrains/textures/advtrains_hud_1000hz.png
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_500hz.png b/advtrains/textures/advtrains_hud_500hz.png
new file mode 100644
index 0000000..bb8225d
--- /dev/null
+++ b/advtrains/textures/advtrains_hud_500hz.png
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_pzb.png b/advtrains/textures/advtrains_hud_pzb.png
new file mode 100644
index 0000000..0ba9bab
--- /dev/null
+++ b/advtrains/textures/advtrains_hud_pzb.png
Binary files differ
diff --git a/advtrains/textures/advtrains_hud_sifa.png b/advtrains/textures/advtrains_hud_sifa.png
new file mode 100644
index 0000000..59299e2
--- /dev/null
+++ b/advtrains/textures/advtrains_hud_sifa.png
Binary files differ
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua
index db32824..35ba718 100644
--- a/advtrains/trainhud.lua
+++ b/advtrains/trainhud.lua
@@ -11,7 +11,7 @@ end)
local mletter={[1]="F", [-1]="R", [0]="N"}
function advtrains.on_control_change(pc, train, flip)
- local maxspeed = train.max_speed or 10
+ local maxspeed = train.max_speed or 10
if pc.sneak then
if pc.up then
train.tarvelocity = maxspeed
@@ -46,13 +46,16 @@ function advtrains.on_control_change(pc, train, flip)
train.ctrl.user = 1
act=true
end
+ if pc.aux1 then
+ train.sifa = 0
+ end
-- If atc command set, only "Jump" key can clear command. To prevent accidental control.
if train.tarvelocity or train.atc_command then
return
end
if pc.up then
- train.ctrl.user=4
- act=true
+ train.ctrl.user=4
+ act=true
end
if pc.down then
if train.velocity>0 then
@@ -99,7 +102,7 @@ function advtrains.set_trainhud(name, text, driver)
local hud = advtrains.hud[name]
local player=minetest.get_player_by_name(name)
if not player then
- return
+ return
end
local driverhud = {
hud_elem_type = "image",
@@ -141,7 +144,7 @@ function advtrains.set_help_hud(name, text)
local hud = advtrains.hhud[name]
local player=minetest.get_player_by_name(name)
if not player then
- return
+ return
end
if not hud then
hud = {}
@@ -187,7 +190,7 @@ function advtrains.hud_train_format(train, flip)
local tlev=train.lever or 1
if train.velocity==0 and not train.active_control then tlev=1 end
- local ht = {"[combine:440x110:0,0=(advtrains_hud_bg.png^[resize\\:440x110)"}
+ local ht = {"[combine:490x110:0,0=(advtrains_hud_bg.png^[resize\\:490x110)"}
local st = {}
if train.debug then st = {train.debug} end
@@ -248,6 +251,9 @@ function advtrains.hud_train_format(train, flip)
if train.ctrl.lzb then
ht[#ht+1] = "50,10=(advtrains_hud_lzb.png^[resize\\:30x30^[multiply\\:red)"
end
+ if train.sifa and train.sifa > 30 then
+ ht[#ht+1] = sformat("440,10=(advtrains_hud_sifa.png^[resize\\:40x40%s)",train.ctrl.sifa and "^[multiply\\:red" or "")
+ end
if train.is_shunt then
ht[#ht+1] = "90,10=(advtrains_hud_shunt.png^[resize\\:30x30^[multiply\\:orange)"
end
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index cc34b4f..6939275 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -300,6 +300,19 @@ function advtrains.train_ensure_init(id, train)
run_callbacks_new_path(id, train)
end
+ -- Check if the train has a driver
+ -- This will be useful for safety systems
+ train.has_driver = false
+ for i = 1, #train.trainparts, 1 do
+ if advtrains.wagons[train.trainparts[i]].has_driver then
+ train.has_driver = true
+ end
+ end
+
+ if not train.sifa then
+ train.sifa = 0
+ end
+
train.dirty = false -- TODO einbauen!
return true
end
@@ -307,6 +320,10 @@ end
function advtrains.train_step_b(id, train, dtime)
if train.no_step or train.wait_for_path or not train.path then return end
+ -- Sifa
+ train.sifa = train.has_driver and (train.sifa+dtime) or 0
+ train.ctrl.sifa = (train.sifa or 0) >=35 and 0 or nil
+
-- in this code, we check variables such as path_trk_? and path_dist. We need to ensure that the path is known for the whole 'Train' zone
advtrains.path_get(train, atfloor(train.index + 2))
advtrains.path_get(train, atfloor(train.end_index - 1))
@@ -352,6 +369,7 @@ function advtrains.train_step_b(id, train, dtime)
lzb = restrictive override from LZB
user = User input from driverstand
atc = ATC command override (determined here)
+ sifa = Sifa (requires driver attention)
}
The code here determines the precedence and writes the final control into train.lever
]]
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 5c8ac25..d70dfb1 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -304,6 +304,8 @@ function wagon:on_step(dtime)
if self.custom_on_step then
self:custom_on_step(dtime, data, train)
end
+
+ data.has_driver = false
--driver control
for seatno, seat in ipairs(self.seats) do
@@ -312,6 +314,7 @@ function wagon:on_step(dtime)
local has_driverstand = pname and advtrains.check_driving_couple_protection(pname, data.owner, data.whitelist)
has_driverstand = has_driverstand and self:is_driver_stand(seat)
if has_driverstand and driver then
+ data.has_driver = true
advtrains.update_driver_hud(driver:get_player_name(), self:train(), data.wagon_flipped)
elseif driver then
--only show the inside text
@@ -330,7 +333,7 @@ function wagon:on_step(dtime)
self:show_bordcom(data.seatp[seatno])
end
--sound horn when required
- if self.horn_sound and pc.aux1 and not pc.sneak and not self.horn_handle then
+ --[[if self.horn_sound and pc.aux1 and not pc.sneak and not self.horn_handle then
self.horn_handle = minetest.sound_play(self.horn_sound, {
object = self.object,
gain = 1.0, -- default
@@ -340,7 +343,7 @@ function wagon:on_step(dtime)
elseif not pc.aux1 and self.horn_handle then
minetest.sound_stop(self.horn_handle)
self.horn_handle = nil
- end
+ end]]
else
-- If on a passenger seat and doors are open, get off when W or D pressed.
local pass = data.seatp[seatno] and minetest.get_player_by_name(data.seatp[seatno])
@@ -349,7 +352,7 @@ function wagon:on_step(dtime)
if pc.up or pc.down then
self:get_off(seatno)
end
- end
+ end
end
if pc.aux1 and pc.sneak then
self:get_off(seatno)