From: 1F616EMO <root@1f616emo.xyz>
This patch de-hardcodes that speed limit. To adapt the changes,
the following changes are made:
1. Added a setting key: advtrains_max_speed, acceppting integers from 1 to 99.
Any values beyond the limit wil be capped.
2. Added max_speed = 20 m/s to the wagon metatable, so wagons not specifying a
maximum speed continues to use 20 m/s.
3. Adjusted the train HUD so trains with maximum speed more than 20 m/s
uses each segment to represent max / 20 m/s.
4. Adjusted speed target / limit / LZB indicators so they work well on the new
segment bar
5. (Not so related) Out-of-bound LZB limitations are marked with a
red arrow pointing right at where 20 m/s were.
---
advtrains/init.lua | 7 ++++++advtrains/settingtypes.txt | 3 +++advtrains/trainhud.lua | 45 +++++++++++++++++++++++++++++++++-----advtrains/trainlogic.lua | 2 +-advtrains/wagons.lua | 1 +
5 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/advtrains/init.lua b/advtrains/init.lua
index 06e456f..ba62c4a 100644
--- a/advtrains/init.lua+++ b/advtrains/init.lua
@@ -66,6 +66,13 @@ if not advtrains.wagon_load_range then
advtrains.wagon_load_range = tonumber(minetest.settings:get("active_block_range"))*16
end
+-- Maximum speed of trains+-- The real maximum speed is the minimum value of all wagon's max speed and this value+-- Default: 20; Min: 1; Max: 99+-- Max. 99 because of the train HUD 7-seg display+advtrains.TRAIN_MAX_SPEED = tonumber(minetest.settings:get("advtrains_max_speed")) or 20+advtrains.TRAIN_MAX_SPEED = math.max(math.min(advtrains.TRAIN_MAX_SPEED, 99), 1)+--pcall
local no_action=false
diff --git a/advtrains/settingtypes.txt b/advtrains/settingtypes.txt
index 2b627cb..55da09a 100644
--- a/advtrains/settingtypes.txt+++ b/advtrains/settingtypes.txt
@@ -61,3 +61,6 @@ advtrains_save_interval (Save Interval) int 60 20 3600
# If enabled, trains only collide with nodes with "normal" drawtype.
advtrains_forgiving_collision (Forgiving Collision mode) bool false
+# Maximum speed of all trains+# The real maximum speed is the minimum value of all wagon's max speed and this value+advtrains_max_speed (Maximum Train Speed) int 20 1 99
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua
index f9f4876..fc0f083 100644
--- a/advtrains/trainhud.lua+++ b/advtrains/trainhud.lua
@@ -220,12 +220,35 @@ function advtrains.hud_train_format(train, flip)
hud:add_fill(215, 10, 15, 30, train.door_open==1 and "white" or "darkslategray"):add_fill(217, 12, 11, 11, "black")
-- speed indication(s)
hud:add_n7seg(320, 10, 110, 90, vel, 2, "red")
- hud:add_segmentbar_leftright(10, 65, 217, 20, 3, 20, max, 20, "darkslategray", 0, vel, "white")- if res and res > 0 then- hud:add_fill(7+res*11, 60, 3, 30, "red")+ do+ local segbar_pos+ if max > 20 then+ segbar_pos = math.floor(vel * 20 / max)+ else+ segbar_pos = vel+ end+ hud:add_segmentbar_leftright(10, 65, 217, 20, 3, 20, math.min(max, 20), 20, "darkslategray", 0, segbar_pos, "white")+ end+ if res and res > 0 and res <= max then+ print(res)+ local indi_pos+ if max > 20 then+ indi_pos = 7 + math.floor(res * 220 / max)+ else+ indi_pos = 7 + res * 11+ end+ hud:add_fill(indi_pos, 60, 3, 30, "red") end
if train.tarvelocity then
- hud:add(1+train.tarvelocity*11, 85, T"advtrains_hud_arrow.png":transform"FY":multiply"cyan")+ do+ local arrow_pos+ if max > 20 then+ arrow_pos = 1 + train.tarvelocity * 220 / max+ else+ arrow_pos = 1 + train.tarvelocity * 11+ end+ hud:add(arrow_pos, 85, T"advtrains_hud_arrow.png":transform"FY":multiply"cyan")+ end end
local lzbdisp
local lzb = train.lzb
@@ -250,7 +273,19 @@ function advtrains.hud_train_format(train, flip)
local c = not spd and "lime" or (type(spd) == "number" and (spd == 0) and "red" or "orange") or nil
if c then
if spd and spd~=0 then
- hud:add(1+spd*11, 50, T"advtrains_hud_arrow.png":multiply"red")+ do+ local texture = T"advtrains_hud_arrow.png":multiply"red"+ local arrow_pos+ if spd > math.max(max, 20) then+ texture = texture:transform"R90"+ arrow_pos = 221 -- 20+ elseif max > 20 then+ arrow_pos = 1 + math.floor(spd * 220 / max)+ else+ arrow_pos = 1 + spd * 11+ end+ hud:add(arrow_pos, 50, texture)+ end end
local dist = math.floor(((oc[i].index or train.index)-train.index))
dist = math.max(0, math.min(999, dist))
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index f136577..0a3c6fe 100644
--- a/advtrains/trainlogic.lua+++ b/advtrains/trainlogic.lua
@@ -1039,7 +1039,7 @@ function advtrains.update_trainpart_properties(train_id, invert_flipstate)
local train=advtrains.trains[train_id]
train.drives_on=advtrains.merge_tables(advtrains.all_tracktypes)
--FIX: deep-copy the table!!!
- train.max_speed=20+ train.max_speed=advtrains.TRAIN_MAX_SPEED train.extent_h = 0;
local rel_pos=0
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 536c8d4..156db06 100644
--- a/advtrains/wagons.lua+++ b/advtrains/wagons.lua
@@ -68,6 +68,7 @@ local wagon={
wagon_width=3, -- Wagon width in meters
has_inventory=false,
static_save=false,
+ max_speed = 20, -- Default value}
--
2.46.0