diff options
-rw-r--r-- | advtrains.zip | bin | 4810179 -> 4710913 bytes | |||
-rw-r--r-- | advtrains/advtrains/atc.lua | 8 | ||||
-rw-r--r-- | advtrains/advtrains/init.lua | 6 | ||||
-rw-r--r-- | advtrains/advtrains/settingtypes.txt | 2 | ||||
-rw-r--r-- | advtrains/advtrains/signals.lua | 8 | ||||
-rw-r--r-- | advtrains/advtrains/trainhud.lua | 17 | ||||
-rw-r--r-- | advtrains/advtrains/wagons.lua | 61 | ||||
-rw-r--r-- | advtrains/advtrains_train_subway/init.lua | 10 | ||||
-rw-r--r-- | advtrains/atc_command.txt | 15 | ||||
-rw-r--r-- | advtrains/manual.pdf | bin | 1037362 -> 927667 bytes | |||
-rw-r--r-- | assets/manual.odt | bin | 0 -> 1047714 bytes |
11 files changed, 110 insertions, 17 deletions
diff --git a/advtrains.zip b/advtrains.zip Binary files differindex 3eafd1a..ec54042 100644 --- a/advtrains.zip +++ b/advtrains.zip 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/init.lua b/advtrains/advtrains/init.lua index c8c4b56..11824f7 100644 --- a/advtrains/advtrains/init.lua +++ b/advtrains/advtrains/init.lua @@ -34,8 +34,10 @@ local function print_concat_table(a) end return str end ---atprint=function() end -atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end +atprint=function() end +if minetest.setting_getbool("advtrains_debug") then + atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({t, ...})) end +end sid=function(id) return string.sub(id, -4) end dofile(advtrains.modpath.."/helpers.lua"); diff --git a/advtrains/advtrains/settingtypes.txt b/advtrains/advtrains/settingtypes.txt new file mode 100644 index 0000000..74a775e --- /dev/null +++ b/advtrains/advtrains/settingtypes.txt @@ -0,0 +1,2 @@ +# Whether to print debug information on advtrains to chat and debug.txt +advtrains_debug (Print advtrains debug messages) bool false
\ No newline at end of file diff --git a/advtrains/advtrains/signals.lua b/advtrains/advtrains/signals.lua index 59c5af1..1a5a2b0 100644 --- a/advtrains/advtrains/signals.lua +++ b/advtrains/advtrains/signals.lua @@ -33,11 +33,11 @@ for r,f in pairs({on="off", off="on"}) do }, mesecons = {effector = { ["action_"..f] = function (pos, node) - advtrains.np.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2}) + advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2}) end }}, on_rightclick=function(pos, node, clicker) - advtrains.np.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2}) + advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2}) end, }) advtrains.trackplacer.add_worked("advtrains:retrosignal", r, rotation, nil) @@ -66,11 +66,11 @@ for r,f in pairs({on="off", off="on"}) do sunlight_propagates=true, mesecons = {effector = { ["action_"..f] = function (pos, node) - minetest.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2}) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2}) end }}, on_rightclick=function(pos, node, clicker) - minetest.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2}) + advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2}) end, }) advtrains.trackplacer.add_worked("advtrains:signal", r, rotation, nil) 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 029d2d1..b46ed81 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -32,7 +32,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())
@@ -78,10 +78,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()
@@ -158,6 +154,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
@@ -295,7 +298,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
@@ -354,9 +386,20 @@ function wagon:on_step(dtime) end
end
if collides then
- gp.recently_collided_with_env=true
- gp.velocity=-0.5*gp.velocity
- gp.tarvelocity=0
+ if self.collision_count and self.collision_count>10 then
+ --enable collision mercy to get trains stuck in walls out of walls
+ --actually do nothing except limiting the velocity to 1
+ gp.velocity=math.min(gp.velocity, 1)
+ gp.tarvelocity=math.min(gp.tarvelocity, 1)
+ else
+ gp.recently_collided_with_env=true
+ gp.velocity=2*gp.velocity
+ gp.movedir=-gp.movedir
+ gp.tarvelocity=0
+ self.collision_count=(self.collision_count or 0)+1
+ end
+ else
+ self.collision_count=nil
end
end
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}, diff --git a/advtrains/atc_command.txt b/advtrains/atc_command.txt index fa846e3..3df60c8 100644 --- a/advtrains/atc_command.txt +++ b/advtrains/atc_command.txt @@ -33,6 +33,19 @@ Examples: B0 W R D10 SM Subway train stopping in dead end station and returning in opposite direction +OL +Open left doors +OR +Open right doors +OC +Close Doors +All door commands are relative to the arrow direction, so if a train drives to opposite arrow direction, L will open its right doors from driver perspective. +Execution continues immediately, there is no way to wait for all doors to be opened/closed. + +Example: +B0 W OL D10 OC D1 SM +Subway train: stop in station and open doors, depart after 10 seconds. + # conditional statements: I<condition><code>; @@ -56,8 +69,10 @@ If the train is slower than 8, accelerate to 8. # ATC controller operation modes static: Only give 1 static command. + mesecon: Give 2 different commands depending on if the controller is mesecon-powered or not digiline: Don't give any commands by itself. When a train passes, a digiline message in the form of "[+/-][speed]" is sent on the set channel (where +/- means the same as with conditions). Any digiline message sent to the controller will be interpreted as ATC command and sent to the train. +** the latter two are not yet implemented. # Persistence ATC controllers that are configured as 'static' or 'mesecon' are persistent over mapblock unloads and will even command the train when the mapblock is unloaded. This is not possible with digilines since these do not work in unloaded mapchunks. diff --git a/advtrains/manual.pdf b/advtrains/manual.pdf Binary files differindex e8c6380..6f9fe84 100644 --- a/advtrains/manual.pdf +++ b/advtrains/manual.pdf diff --git a/assets/manual.odt b/assets/manual.odt Binary files differnew file mode 100644 index 0000000..e4ca357 --- /dev/null +++ b/assets/manual.odt |