diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-01-18 19:03:27 +0100 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-01-18 19:03:27 +0100 |
commit | f52b67a37c766529e637550b94296c92b954b496 (patch) | |
tree | 3b1c69d5dcf4b0adcf719eb444f1bc30b0c1fb5d /advtrains | |
parent | d73289237e91acb6a55f3b4408649e1076b05a3b (diff) | |
download | advtrains-f52b67a37c766529e637550b94296c92b954b496.tar.gz advtrains-f52b67a37c766529e637550b94296c92b954b496.tar.bz2 advtrains-f52b67a37c766529e637550b94296c92b954b496.zip |
Add door controls and ATC commands
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/advtrains/atc.lua | 8 | ||||
-rw-r--r-- | advtrains/advtrains/trainhud.lua | 17 | ||||
-rw-r--r-- | advtrains/advtrains/wagons.lua | 44 | ||||
-rw-r--r-- | advtrains/advtrains_train_subway/init.lua | 10 |
4 files changed, 71 insertions, 8 deletions
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua index 2a4d226..7117a9a 100644 --- a/advtrains/advtrains/atc.lua +++ b/advtrains/advtrains/atc.lua @@ -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) diff --git a/advtrains/advtrains/trainhud.lua b/advtrains/advtrains/trainhud.lua index e69f04a..3830b65 100644 --- a/advtrains/advtrains/trainhud.lua +++ b/advtrains/advtrains/trainhud.lua @@ -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)..">" diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index 13811ad..f164335 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -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
@@ -286,7 +289,36 @@ function wagon:on_step(dtime) end
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
diff --git a/advtrains/advtrains_train_subway/init.lua b/advtrains/advtrains_train_subway/init.lua index b105f1a..85bd28f 100644 --- a/advtrains/advtrains_train_subway/init.lua +++ b/advtrains/advtrains_train_subway/init.lua @@ -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}, |