More detailed description of wagon span and max speed

This commit is contained in:
Y. Wang 2023-01-15 22:21:49 +01:00
parent 16bb2a3cbb
commit 0f2542a287

View File

@ -60,6 +60,29 @@ doc.add_category("advtrains_wagons", {
build_formspec = doc.entry_builders.formspec,
})
local function describe_length(x)
local inch = math.floor(x/0.0254)
local ft = math.floor(inch/12)
inch = inch%12
local st = {}
if ft > 0 then
table.insert(st, ft .. "'")
end
if inch > 0 then
table.insert(st, inch .. '"')
end
if not next(st) then
st = '0"'
end
return string.format("%.2f m (%s)", x, table.concat(st))
end
local function describe_speed(x)
local kmph = advtrains.ms_to_kmh(x)
local mph = kmph/1.609344
return string.format("%.2f m/s (%.2f km/h; %.2f mph)", x, kmph, mph)
end
local function addlist(lst, tbl, title, fallback1, fallback2, mapf)
if not tbl then
if fallback2 then
@ -136,8 +159,8 @@ local function doc_register_wagon(itemname)
addlist(desctext, prototype.drives_on, S("Drives on:"))
addlist(desctext, prototype.coupler_types_front, S("Compatible front couplers:"), S2("Front coupler: @1", "Absent"), S2("Front coupler: @1", "Universal"), get_coupler_name)
addlist(desctext, prototype.coupler_types_back, S("Compatible rear couplers:"), S2("Rear coupler: @1", "Absent"), S2("Rear coupler: @1", "Universal"), get_coupler_name)
table.insert(desctext, S("Wagon span: @1", prototype.wagon_span and 2*prototype.wagon_span or S("Undefined")))
table.insert(desctext, S("Maximum speed: @1", prototype.max_speed or S("Undefined")))
table.insert(desctext, S("Wagon span: @1", prototype.wagon_span and describe_length(2*prototype.wagon_span) or S("Undefined")))
table.insert(desctext, S("Maximum speed: @1", prototype.max_speed and describe_speed(prototype.max_speed) or S("Undefined")))
table.insert(desctext, S2("Motive power: @1", prototype.is_locomotive and "Present" or "Absent"))
local hornsound = prototype.horn_sound
if type(hornsound) == "table" then