Module:HatchMinistryNarrative
From MicrasWiki
Documentation for this module may be created at Module:HatchMinistryNarrative/doc
local p = {}
local ops = require("Module:HatchMinistryDailyOps")
local cal = require("Module:BassaridianCalendar")
local function cityLink(name)
return string.format("[[List_of_cities_in_Bassaridia_Vaeringheim#%s|%s]]", name, name)
end
local function captainLink(data)
local page = string.format("Captain_%s_%s", data.captain.first, data.captain.last)
if data.captain.nick and tostring(data.captain.nick) ~= "" then
return string.format("[[%s|Captain %s ''‘%s’'' %s]]", page, data.captain.first, data.captain.nick, data.captain.last)
end
return string.format("[[%s|Captain %s %s]]", page, data.captain.first, data.captain.last)
end
local function sevPhrase(sev)
sev = tostring(sev or ""):lower()
if sev == "red" then
return "under a red operations posture"
elseif sev == "yellow" then
return "under a yellow operations posture"
end
return "under a green operations posture"
end
local function domainPhrase(domain)
domain = tostring(domain or ""):lower()
if domain == "rail" then
return "rail-domain operations"
elseif domain == "sea" then
return "sea-domain operations"
end
return "corridor operations"
end
local function weatherSentence(weather)
if not weather or not weather.alert then
return ""
end
local label = weather.alert.label or "Green"
local hazard = weather.alert.hazard or weather.condition or ""
local condition = weather.condition or ""
if label == "Green" and condition == "" and hazard == "" then
return ""
end
local bits = {}
if label and label ~= "" then
table.insert(bits, label .. " weather posture")
end
if hazard and hazard ~= "" then
table.insert(bits, hazard)
elseif condition and condition ~= "" then
table.insert(bits, condition)
end
if #bits == 0 then
return ""
end
return " Local weather conditions are reported as " .. table.concat(bits, ", ") .. "."
end
local function taskSentence(task)
task = tostring(task or "")
if task == "" then
return ""
end
return " Her reported activity for the day centers on " .. mw.text.trim(task) .. "."
end
function p.captainParagraph(frame)
local args = (frame and frame.args) or {}
local captain = args.captain
local year = args.year
local day = args.day
local data = ops.getCaptainAssignmentData(captain, year, day)
if not data then
return "No matching captain assignment could be found."
end
local calPart = ""
if data.calendar and data.calendar ~= "" then
calPart = string.format(" (%s)", data.calendar)
end
local parts = {}
table.insert(
parts,
string.format(
"On %d/%d PSSC%s, %s is operating out of %s, away from her home base in %s, %s and conducting %s along the Caledonian reaches of the [[Trans-Morovian Express]].",
data.day,
data.year,
calPart,
captainLink(data),
cityLink(data.station),
cityLink(data.home),
sevPhrase(data.severity),
domainPhrase(data.domain)
)
)
local taskPart = taskSentence(data.task)
if taskPart ~= "" then
table.insert(parts, taskPart)
end
if tonumber(data.dayInBlock) and tonumber(data.blockLen) then
table.insert(
parts,
string.format(
"This places her on day %d of a %d-day rotational block within the wider Hatch Ministry security circuit.",
tonumber(data.dayInBlock),
tonumber(data.blockLen)
)
)
end
local wxPart = weatherSentence(data.weather)
if wxPart ~= "" then
table.insert(parts, wxPart)
end
return table.concat(parts, " ")
end
return p