Make "Line" property accessible from OBC and gettable via LATC, change subway wagon texture handling

master
orwell96 2018-11-20 11:57:46 +01:00
parent 8b80742fa5
commit 37166b5c14
6 changed files with 50 additions and 20 deletions

View File

@ -202,7 +202,7 @@ function advtrains.hud_train_format(train, flip)
secondLine = "-!- Safety override -!-"
end
topLine=" ["..mletter[fct].."] {"..levers.."} "..doorstr[(train.door_open or 0) * fct]
topLine=" ["..mletter[fct].."] {"..levers.."} "..doorstr[(train.door_open or 0) * fct].." "..(train.line and "L: "..train.line or "")
firstLine=attrans("Speed:").." |"..string.rep("+", vel)..string.rep("_", res-vel).."|"..string.rep("_", max-res).."> "..vel_kmh.." km/h"
if train.speed_restriction == 0 then
firstLine = "OVERRUN RED SIGNAL! Examine situation and reverse train to move again."

View File

@ -235,10 +235,12 @@ function wagon:on_step(dtime)
if not self.seatpc then
self.seatpc={}
end
local train=self:train()
--custom on_step function
if self.custom_on_step then
self:custom_on_step(self, dtime)
self:custom_on_step(dtime, data, train)
end
--driver control
@ -298,12 +300,12 @@ function wagon:on_step(dtime)
end
--check infotext
local outside=self:train().text_outside or ""
local outside=train.text_outside or ""
if setting_show_ids then
outside = outside .. "\nT:" .. data.train_id .. " W:" .. self.id .. " O:" .. data.owner
end
local train=self:train()
--show off-track information in outside text instead of notifying the whole server about this
if train.off_track then
outside = outside .."\n!!! Train off track !!!"
@ -315,19 +317,7 @@ function wagon:on_step(dtime)
end
local fct=data.wagon_flipped and -1 or 1
--set line number
if self.name == "advtrains:subway_wagon" and train.line and train.line~=self.line_cache then
local new_line_tex="advtrains_subway_wagon.png^advtrains_subway_wagon_line"..train.line..".png"
self.object:set_properties({
textures={new_line_tex},
})
self.line_cache=train.line
elseif self.line_cache~=nil and train.line==nil then
self.object:set_properties({
textures=self.textures,
})
self.line_cache=nil
end
--door animation
if self.doors then
if (self.door_anim_timer or 0)<=0 then
@ -779,6 +769,7 @@ function wagon:show_bordcom(pname)
local form = "size[11,9]label[0.5,0;AdvTrains Boardcom v0.1]"
form=form.."textarea[0.5,1.5;7,1;text_outside;"..attrans("Text displayed outside on train")..";"..(train.text_outside or "").."]"
form=form.."textarea[0.5,3;7,1;text_inside;"..attrans("Text displayed inside train")..";"..(train.text_inside or "").."]"
form=form.."field[7.5,3.2;2,1;line;"..attrans("Line")..";"..(train.line or "").."]"
--row 5 : train overview and autocoupling
if train.velocity==0 then
form=form.."label[0.5,4.5;Train overview /coupling control:]"
@ -864,6 +855,13 @@ function wagon:handle_bordcom_fields(pname, formname, fields)
train.text_inside=nil
end
end
if fields.line then
if fields.line~="" then
train.line=fields.line
else
train.line=nil
end
end
for i, tpid in ipairs(train.trainparts) do
if fields["dcpl_"..i] then
advtrains.safe_decouple_wagon(tpid, pname)

View File

@ -173,8 +173,14 @@ atc_set_text_outside(text)
Set text shown on the outside of the train. Pass nil to show no text.
atc_set_text_inside(text)
Set text shown to train passengers. Pass nil to show no text.
get_line()
Returns the "Line" property of the train (a string).
This can be used to distinguish between trains of different lines and route them appropriately.
The interlocking system also uses this property for Automatic Routesetting.
set_line(number)
Only for subway wagons: Display a line number (1-9) on the train.
Sets the "Line" property of the train (a string).
If the first digit of this string is a number (0-9), any subway wagons on the train will have this one displayed as line number
(where "0" is actually shown as Line 10 on the train)
# Operator panel
This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications.

View File

@ -54,8 +54,14 @@ function r.fire_event(pos, evtdata)
return true
end,
set_line = function(line)
train.line = line
return true
if type(line)~="string" and type(line)~="number" then
return false
end
train.line = line .. ""
return true
end,
get_line = function()
return train.line
end,
atc_reset = function(cmd)
if not train_id then return false end

View File

@ -101,6 +101,26 @@ advtrains.register_wagon("subway_wagon", {
self.sound_loop_tmr=0
end
end,
custom_on_step = function(self, dtime, data, train)
--set line number
local line = nil
if train.line then
line = tonumber(string.sub(train.line, 1, 1))
end
if line and line~=self.line_cache then
local new_line_tex="advtrains_subway_wagon.png^advtrains_subway_wagon_line"..line..".png"
self.object:set_properties({
textures={new_line_tex},
})
self.line_cache=line
elseif self.line_cache~=nil and line==nil then
atdebug("clear line")
self.object:set_properties({
textures=self.textures,
})
self.line_cache=nil
end
end,
}, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png")
--wagons

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB