Add door controls and ATC commands
This commit is contained in:
parent
d73289237e
commit
f52b67a37c
|
@ -8,7 +8,7 @@ function atc.load_data(data)
|
|||
atc.controllers = data and data.controllers or {}
|
||||
end
|
||||
function atc.save_data()
|
||||
return atc.controllers
|
||||
return {controllers = atc.controllers}
|
||||
end
|
||||
--contents: {command="...", arrowconn=0-15 where arrow points}
|
||||
|
||||
|
@ -172,6 +172,12 @@ local matchptn={
|
|||
end
|
||||
return 1
|
||||
end,
|
||||
["O([LRC])"]=function(id, train, match)
|
||||
local tt={L=-1, R=1, C=0}
|
||||
local arr=train.atc_arrow and 1 or -1
|
||||
train.door_open = tt[match]*arr*train.movedir
|
||||
return 2
|
||||
end,
|
||||
}
|
||||
|
||||
function atc.execute_atc_command(id, train)
|
||||
|
|
|
@ -7,6 +7,7 @@ advtrains.hud[player:get_player_name()] = nil
|
|||
end)
|
||||
|
||||
local mletter={[1]="F", [-1]="R", [0]="N"}
|
||||
local doorstr={[-1]="|<>| >|<", [0]=">|< >|<", [1]=">|< |<>|"}
|
||||
|
||||
function advtrains.on_control_change(pc, train, flip)
|
||||
if pc.sneak then
|
||||
|
@ -48,6 +49,20 @@ function advtrains.on_control_change(pc, train, flip)
|
|||
train.movedir = -train.movedir
|
||||
end
|
||||
end
|
||||
if pc.left then
|
||||
if train.door_open ~= 0 then
|
||||
train.door_open = 0
|
||||
else
|
||||
train.door_open = -train.movedir
|
||||
end
|
||||
end
|
||||
if pc.right then
|
||||
if train.door_open ~= 0 then
|
||||
train.door_open = 0
|
||||
else
|
||||
train.door_open = train.movedir
|
||||
end
|
||||
end
|
||||
if train.brake_hold_state~=2 then
|
||||
train.brake = false
|
||||
end
|
||||
|
@ -101,7 +116,7 @@ function advtrains.hud_train_format(train, flip)
|
|||
local tvel=advtrains.abs_ceil(train.tarvelocity)
|
||||
local topLine, firstLine, secondLine
|
||||
|
||||
topLine="Train".." ["..mletter[fct*train.movedir].."] "..(train.brake and "="..( train.brake_hold_state==2 and "^" or "" ).."B=" or "")
|
||||
topLine=" ["..mletter[fct*train.movedir].."] "..doorstr[(train.door_open or 0) * train.movedir].." "..(train.brake and "="..( train.brake_hold_state==2 and "^" or "" ).."B=" or "")
|
||||
firstLine="Speed: |"..string.rep("+", vel)..string.rep("_", max-vel)..">"
|
||||
secondLine="Target: |"..string.rep("+", tvel)..string.rep("_", max-tvel)..">"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function wagon:on_rightclick(clicker)
|
|||
--advtrains.dumppath(self:train().path)
|
||||
--minetest.chat_send_all("at index "..(self:train().index or "nil"))
|
||||
--advtrains.invert_train(self.train_id)
|
||||
minetest.chat_send_all(dump(self:train()))
|
||||
atprint(dump(self))
|
||||
return
|
||||
end
|
||||
local no=self:get_seatno(clicker:get_player_name())
|
||||
|
@ -69,10 +69,6 @@ function wagon:on_activate(sd_uid, dtime_s)
|
|||
return
|
||||
end
|
||||
end
|
||||
|
||||
if self.custom_on_activate then
|
||||
self:custom_on_activate(dtime_s)
|
||||
end
|
||||
end
|
||||
|
||||
function wagon:get_staticdata()
|
||||
|
@ -149,6 +145,13 @@ function wagon:init_shared()
|
|||
end
|
||||
end
|
||||
end
|
||||
if self.doors then
|
||||
self.door_anim_timer=0
|
||||
self.door_state=0
|
||||
end
|
||||
if self.custom_on_activate then
|
||||
self:custom_on_activate(dtime_s)
|
||||
end
|
||||
end
|
||||
function wagon:ensure_init()
|
||||
if self.initialized then
|
||||
|
@ -287,6 +290,35 @@ function wagon:on_step(dtime)
|
|||
|
||||
local gp=self:train()
|
||||
|
||||
--door animation
|
||||
if self.doors then
|
||||
if (self.door_anim_timer or 0)<=0 then
|
||||
local fct=self.wagon_flipped and -1 or 1
|
||||
local dstate = (gp.door_open or 0) * fct
|
||||
if dstate ~= self.door_state then
|
||||
local at
|
||||
--meaning of the train.door_open field:
|
||||
-- -1: left doors (rel. to train orientation)
|
||||
-- 0: closed
|
||||
-- 1: right doors
|
||||
--this code produces the following behavior:
|
||||
-- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close.
|
||||
-- if changed from +-1 to -+1, first close and set 0, then it will detect state change again and run open.
|
||||
if self.door_state == 0 then
|
||||
at=self.doors.open[dstate]
|
||||
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
||||
self.door_state = dstate
|
||||
else
|
||||
at=self.doors.close[self.door_state or 1]--in case it has not been set yet
|
||||
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
|
||||
self.door_state = 0
|
||||
end
|
||||
self.door_anim_timer = at.time
|
||||
end
|
||||
else
|
||||
self.door_anim_timer = (self.door_anim_timer or 0) - dtime
|
||||
end
|
||||
end
|
||||
--DisCouple
|
||||
if self.pos_in_trainparts and self.pos_in_trainparts>1 then
|
||||
if gp.velocity==0 then
|
||||
|
|
|
@ -12,6 +12,16 @@ advtrains.register_wagon("subway_wagon", {
|
|||
driving_ctrl_access=true,
|
||||
},
|
||||
},
|
||||
doors={
|
||||
open={
|
||||
[-1]={frames={x=0, y=19}, time=1},
|
||||
[1]={frames={x=40, y=59}, time=1}
|
||||
},
|
||||
close={
|
||||
[-1]={frames={x=20, y=39}, time=1},
|
||||
[1]={frames={x=60, y=81}, time=1}
|
||||
}
|
||||
},
|
||||
visual_size = {x=1, y=1},
|
||||
wagon_span=2,
|
||||
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
|
||||
|
|
Loading…
Reference in New Issue