aboutsummaryrefslogtreecommitdiff
path: root/advtrains/atc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/atc.lua')
-rw-r--r--advtrains/atc.lua37
1 files changed, 25 insertions, 12 deletions
diff --git a/advtrains/atc.lua b/advtrains/atc.lua
index 64cdcec..b572cdc 100644
--- a/advtrains/atc.lua
+++ b/advtrains/atc.lua
@@ -93,6 +93,7 @@ function atc.train_reset_command(train, keep_tarvel)
train.atc_delay=nil
train.atc_brake_target=nil
train.atc_wait_finish=nil
+ train.atc_wait_autocouple=nil
train.atc_arrow=nil
if not keep_tarvel then
train.tarvelocity=nil
@@ -105,7 +106,7 @@ local apn_func=function(pos)
-- FIX for long-persisting ndb bug: there's no node in parameter 2 of this function!
local meta=minetest.get_meta(pos)
if meta then
- meta:set_string("infotext", attrans("ATC controller, unconfigured."))
+ meta:set_string("infotext", attrans("Unconfigured ATC controller"))
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
end
end
@@ -199,10 +200,16 @@ local matchptn={
return #match+1
end,
["B([0-9]+)"]=function(id, train, match)
- if train.velocity>tonumber(match) then
- train.atc_brake_target=tonumber(match)
- if not train.tarvelocity or train.tarvelocity>train.atc_brake_target then
- train.tarvelocity=train.atc_brake_target
+ local btar = tonumber(match)
+ if train.velocity>btar then
+ train.atc_brake_target=btar
+ if not train.tarvelocity or train.tarvelocity>btar then
+ train.tarvelocity=btar
+ end
+ else
+ -- independent of brake target, must make sure that tarvelocity is not greater than it
+ if train.tarvelocity and train.tarvelocity>btar then
+ train.tarvelocity=btar
end
end
return #match+1
@@ -226,7 +233,7 @@ local matchptn={
advtrains.train_ensure_init(id, train)
-- no one minds if this failed... this shouldn't even be called without train being initialized...
else
- atwarn(sid(id), attrans("ATC Reverse command warning: didn't reverse train, train moving!"))
+ atwarn(sid(id), attrans("ATC Reverse command warning: didn't reverse train, train moving."))
end
return 1
end,
@@ -238,11 +245,11 @@ local matchptn={
end,
["K"] = function(id, train)
if train.door_open == 0 then
- atwarn(sid(id), attrans("ATC Kick command warning: Doors closed"))
+ atwarn(sid(id), attrans("ATC Kick command warning: doors are closed."))
return 1
end
if train.velocity > 0 then
- atwarn(sid(id), attrans("ATC Kick command warning: Train moving"))
+ atwarn(sid(id), attrans("ATC Kick command warning: train moving."))
return 1
end
local tp = train.trainparts
@@ -267,6 +274,10 @@ local matchptn={
advtrains.interlocking.ars_set_disable(train, match=="0")
return 2
end,
+ ["Cpl"]=function(id, train)
+ train.atc_wait_autocouple=true
+ return 3
+ end,
}
eval_conditional = function(command, arrow, speed)
@@ -358,11 +369,13 @@ function atc.execute_atc_command(id, train)
local match=string.match(command, "^"..pattern)
if match then
local patlen=func(id, train, match)
-
- atprint("Executing: "..string.sub(command, 1, patlen))
-
+ --atdebug("Executing: "..string.sub(command, 1, patlen))
+ --atdebug("Train ATC State: tvel=",train.tarvelocity,"brktar=",train.atc_brake_target,"delay=",train.atc_delay,"wfinish=",train.atc_wait_finish,"wacpl=",train.atc_wait_autocouple)
+
train.atc_command=string.sub(command, patlen+1)
- if train.atc_delay<=0 and not train.atc_wait_finish then
+ if train.atc_delay<=0
+ and not train.atc_wait_finish
+ and not train.atc_wait_autocouple then
--continue (recursive, cmds shouldn't get too long, and it's a end-recursion.)
atc.execute_atc_command(id, train)
end