Module:GeneralPortOperations: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) Undo revision 359985 by NewZimiaGov (talk) Tag: Undo |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 4: | Line 4: | ||
-- 1) Date logic | -- 1) Date logic | ||
function p.getCurrentDate() | function p.getCurrentDate() | ||
local start | local start = os.time{year=1999, month=8, day=6} | ||
local elapsed = math.floor((os.time() - start) / 86400) | local elapsed = math.floor((os.time() - start) / 86400) | ||
local year | local year = math.floor(elapsed / 183) | ||
local day | local day = (elapsed % 183) + 1 | ||
return year, day | return year, day | ||
end | end | ||
-- 2) Random | -- 2) Random helpers | ||
local function randomChoice( | local function randomChoice(tbl) | ||
return | return tbl[math.random(#tbl)] | ||
end | |||
local function randomN(tbl, n) | |||
local copy = {table.unpack(tbl)} | |||
local out = {} | |||
for i = 1, n do | |||
if #copy == 0 then break end | |||
local idx = math.random(#copy) | |||
table.insert(out, table.remove(copy, idx)) | |||
end | |||
return out | |||
end | end | ||
-- 3) Home ports | -- 3) Home ports + flags | ||
local cities = { | local cities = {"Aegirheim","Skýrophos","Bjornopolis","Norsolyra","Ephyra", | ||
"Symphonara","Delphica","Vaeringheim","Somniumpolis", | |||
"Keybir-Aviv","Sufriya","Jogi"} | |||
} | |||
local cityFlag = {} | local cityFlag = {} | ||
for _, | for _, name in ipairs(cities) do | ||
local norm = name:gsub("[%s%-%’]", "") | |||
local norm = | norm = norm:gsub("[Áá]","A"):gsub("[Éé]","E") | ||
norm = norm | :gsub("[Íí]","I"):gsub("[Óó]","O") | ||
:gsub("[Úú]","U"):gsub("[Ýý]","Y") | |||
cityFlag[name] = string.format("[[File:%sFlag.png|20px]]", norm) | |||
cityFlag[ | |||
end | end | ||
-- 4) Vessel & | -- 4) Vessel & cargo types | ||
local vesselTypes = {"Cargo","Military","Ritual","Privateer"} | local vesselTypes = {"Cargo", "Military", "Ritual", "Privateer"} | ||
local cargoTypes = {"Agricultural","Mining/Manufacturing","Services","Unspecified" | local cargoTypes = {"Agricultural", "Mining/Manufacturing", "Services", "Unspecified"} | ||
} | |||
-- | -- 5) Owner pools (lists omitted for brevity) | ||
local | local ritualCults = {} -- full list omitted for brevity | ||
local militaryDivs = {} -- full list omitted for brevity | |||
local agriCompanies = {} -- full list omitted for brevity | |||
local miningCompanies = {} -- full list omitted for brevity | |||
local serviceCompanies = {} -- full list omitted for brevity | |||
} | |||
local miningCompanies = { | |||
} | |||
local serviceCompanies = { | |||
} | |||
-- | -- 6) Company logos mapping | ||
local companyLogo = {} | local companyLogo = {} | ||
local function addLogo(name, file) | local function addLogo(name, file) | ||
companyLogo[name] = file | companyLogo[name] = file | ||
end | end | ||
-- addLogo calls for | -- addLogo calls omitted for brevity | ||
-- | -- 7) Privateer helper | ||
local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}} | local privateers = {{first="Talvios", last="Karnis", nick="Erebektos"}} | ||
local function getRandomPrivateer() | local function getRandomPrivateer() | ||
local c = randomChoice(privateers) | local c = randomChoice(privateers) | ||
if c.nick and math.random() < 0.25 then | if c.nick and math.random() < 0.25 then | ||
return string.format("Captain %s ‘%s’ %s", c.first, c.nick, c.last) | return string.format("Captain %s ‘%s’ %s", c.first, c.nick, c.last) | ||
end | end | ||
return string.format("Captain %s %s", c.first, c.last) | |||
end | end | ||
-- | -- 8) Owner selection logic | ||
local function getOwner(vt, ct) | local function getOwner(vt, ct) | ||
if vt == "Ritual" | if vt == "Ritual" then | ||
elseif vt == "Military" then return randomChoice(militaryDivs) | return randomChoice(ritualCults) | ||
elseif vt == "Privateer" then return getRandomPrivateer() | elseif vt == "Military" then | ||
return randomChoice(militaryDivs) | |||
elseif vt == "Privateer" then | |||
return getRandomPrivateer() | |||
elseif vt == "Cargo" then | elseif vt == "Cargo" then | ||
if ct == "Agricultural" then | if ct == "Agricultural" then | ||
| Line 119: | Line 87: | ||
end | end | ||
-- | -- 9) Generate the ship table | ||
function p.generateShipTable() | function p.generateShipTable() | ||
math.randomseed(os.time()) | math.randomseed(os.time()) | ||
local y,d = p.getCurrentDate() | local y, d = p.getCurrentDate() | ||
local poolMap = { | |||
Agricultural = agriCompanies, | |||
["Mining/Manufacturing"] = miningCompanies, | |||
Services = serviceCompanies | |||
} | |||
local ships = {} | local ships = {} | ||
for i=1,math.random(50,80) do | for i = 1, math.random(50, 80) do | ||
local hr,mn = math.random(0,23),math.random(0,59) | local hr, mn = math.random(0,23), math.random(0,59) | ||
local vt,ct = randomChoice(vesselTypes),randomChoice(cargoTypes) | local vt, ct = randomChoice(vesselTypes), randomChoice(cargoTypes) | ||
local owner | local owner = getOwner(vt, ct) | ||
local | local ownerLogo = companyLogo[owner] and string.format("[[File:%s|20px]] ", companyLogo[owner]) or "" | ||
local home | local home = randomChoice(cities) | ||
table.insert(ships,{ | -- pick companies, include owner if Cargo | ||
date | local picks = {} | ||
time | local count = math.random(3, 4) | ||
sort | if vt == "Cargo" and ct ~= "Unspecified" and companyLogo[owner] then | ||
vid | table.insert(picks, owner) | ||
home | local choices = {} | ||
typ | for _, name in ipairs(poolMap[ct] or {}) do | ||
ownerCell | if name ~= owner then table.insert(choices, name) end | ||
cargotype | end | ||
berth | local more = randomN(choices, count - 1) | ||
teus | for _, cname in ipairs(more) do table.insert(picks, cname) end | ||
tonnage | else | ||
queue | local flat = {} | ||
turnaround = string.format("%.2f",math.random()*32+4), | for _, list in pairs(poolMap) do | ||
error | for _, name in ipairs(list) do table.insert(flat, name) end | ||
end | |||
picks = randomN(flat, count) | |||
end | |||
-- build Companies cell | |||
local compCell = "<ul>" | |||
for _, cname in ipairs(picks) do | |||
local logo = companyLogo[cname] and string.format("[[File:%s|20px]] ", companyLogo[cname]) or "" | |||
compCell = compCell .. string.format("<li>%s%s</li>", logo, cname) | |||
end | |||
compCell = compCell .. "</ul>" | |||
-- determine error | |||
local err = (math.random() < 0.2 and randomChoice({ | |||
"Cargo Mislabeling", "Improper Documentation", "Surveillance Anomaly", | |||
"Inspection Failure", "Unregistered Ritual Cargo" | |||
})) or "None" | |||
table.insert(ships, { | |||
date = string.format("Day %d, Y.%d", d, y), | |||
time = string.format("%02d:%02d", hr, mn), | |||
sort = hr * 60 + mn, | |||
vid = "VM-" .. math.random(10000, 99999), | |||
home = cityFlag[home] .. " " .. home, | |||
typ = vt, | |||
ownerCell = ownerLogo .. owner, | |||
cargotype = ct, | |||
cargoCompanies = compCell, | |||
berth = math.random(1,124), | |||
teus = math.random(100,1000), | |||
tonnage = string.format("%.2f", math.random()*19000+1000), | |||
queue = string.format("%.2f", math.random()*5.5+0.5), | |||
turnaround = string.format("%.2f", math.random()*32+4), | |||
error = err | |||
}) | }) | ||
end | end | ||
table.sort(ships, function(a,b) return a.sort < b.sort end) | |||
table | -- build wiki table | ||
local out = { | |||
local out={ | |||
'{| class="wikitable sortable"', | '{| class="wikitable sortable"', | ||
'! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type', | '! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type !! Companies', | ||
'!! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error' | '!! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error' | ||
} | } | ||
for _, s in ipairs(ships) do | |||
for _,s in ipairs(ships) do | local rowDef = s.error ~= "None" and '|- bgcolor="#ffcccc"' or '|-' | ||
table.insert(out,string.format( | table.insert(out, rowDef) | ||
| | table.insert(out, string.format( | ||
| %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s | '| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s', | ||
s.date, s.time, s.vid, s.home, s.typ, | |||
s.date,s.time,s.vid,s.home,s.typ, | s.ownerCell, s.cargotype, s.cargoCompanies, | ||
s.ownerCell,s.cargotype, | s.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error | ||
s.berth,s.teus,s.tonnage,s.queue,s.turnaround,s.error | |||
)) | )) | ||
end | end | ||
table.insert(out, | -- footer | ||
table.insert(out,"* '''Cargo Mislabeling:''' Manifest ≠ actual goods") | table.insert(out, '|}') | ||
table.insert(out,"* '''Improper Documentation:''' Missing or outdated papers") | table.insert(out, "'''Error Key:'''") | ||
table.insert(out,"* '''Surveillance Anomaly:''' Unexpected heat/motion") | table.insert(out, "* '''Cargo Mislabeling:''' Manifest ≠ actual goods") | ||
table.insert(out,"* '''Inspection Failure:''' Customs/hatch failure") | table.insert(out, "* '''Improper Documentation:''' Missing or outdated papers") | ||
table.insert(out,"* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank") | table.insert(out, "* '''Surveillance Anomaly:''' Unexpected heat/motion") | ||
table.insert(out, "* '''Inspection Failure:''' Customs/hatch failure") | |||
table.insert(out, "* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank") | |||
return table.concat(out,"\n") | return table.concat(out, "\n") | ||
end | end | ||
function p.dailyReport() | function p.dailyReport() | ||
local y,d = p.getCurrentDate() | local y, d = p.getCurrentDate() | ||
return string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y) | |||
.. "\n" .. p.generateShipTable() | |||
end | end | ||
return p | return p | ||
Revision as of 19:17, 24 April 2025
Documentation for this module may be created at Module:GeneralPortOperations/doc
-- Module:GeneralPortDailyLog
local p = {}
-- 1) Date logic
function p.getCurrentDate()
local start = os.time{year=1999, month=8, day=6}
local elapsed = math.floor((os.time() - start) / 86400)
local year = math.floor(elapsed / 183)
local day = (elapsed % 183) + 1
return year, day
end
-- 2) Random helpers
local function randomChoice(tbl)
return tbl[math.random(#tbl)]
end
local function randomN(tbl, n)
local copy = {table.unpack(tbl)}
local out = {}
for i = 1, n do
if #copy == 0 then break end
local idx = math.random(#copy)
table.insert(out, table.remove(copy, idx))
end
return out
end
-- 3) Home ports + flags
local cities = {"Aegirheim","Skýrophos","Bjornopolis","Norsolyra","Ephyra",
"Symphonara","Delphica","Vaeringheim","Somniumpolis",
"Keybir-Aviv","Sufriya","Jogi"}
local cityFlag = {}
for _, name in ipairs(cities) do
local norm = name:gsub("[%s%-%’]", "")
norm = norm:gsub("[Áá]","A"):gsub("[Éé]","E")
:gsub("[Íí]","I"):gsub("[Óó]","O")
:gsub("[Úú]","U"):gsub("[Ýý]","Y")
cityFlag[name] = string.format("[[File:%sFlag.png|20px]]", norm)
end
-- 4) Vessel & cargo types
local vesselTypes = {"Cargo", "Military", "Ritual", "Privateer"}
local cargoTypes = {"Agricultural", "Mining/Manufacturing", "Services", "Unspecified"}
-- 5) Owner pools (lists omitted for brevity)
local ritualCults = {} -- full list omitted for brevity
local militaryDivs = {} -- full list omitted for brevity
local agriCompanies = {} -- full list omitted for brevity
local miningCompanies = {} -- full list omitted for brevity
local serviceCompanies = {} -- full list omitted for brevity
-- 6) Company logos mapping
local companyLogo = {}
local function addLogo(name, file)
companyLogo[name] = file
end
-- addLogo calls omitted for brevity
-- 7) Privateer helper
local privateers = {{first="Talvios", last="Karnis", nick="Erebektos"}}
local function getRandomPrivateer()
local c = randomChoice(privateers)
if c.nick and math.random() < 0.25 then
return string.format("Captain %s ‘%s’ %s", c.first, c.nick, c.last)
end
return string.format("Captain %s %s", c.first, c.last)
end
-- 8) Owner selection logic
local function getOwner(vt, ct)
if vt == "Ritual" then
return randomChoice(ritualCults)
elseif vt == "Military" then
return randomChoice(militaryDivs)
elseif vt == "Privateer" then
return getRandomPrivateer()
elseif vt == "Cargo" then
if ct == "Agricultural" then
return randomChoice(agriCompanies)
elseif ct == "Mining/Manufacturing" then
return randomChoice(miningCompanies)
elseif ct == "Services" then
return randomChoice(serviceCompanies)
end
end
return "Independent Consortium"
end
-- 9) Generate the ship table
function p.generateShipTable()
math.randomseed(os.time())
local y, d = p.getCurrentDate()
local poolMap = {
Agricultural = agriCompanies,
["Mining/Manufacturing"] = miningCompanies,
Services = serviceCompanies
}
local ships = {}
for i = 1, math.random(50, 80) do
local hr, mn = math.random(0,23), math.random(0,59)
local vt, ct = randomChoice(vesselTypes), randomChoice(cargoTypes)
local owner = getOwner(vt, ct)
local ownerLogo = companyLogo[owner] and string.format("[[File:%s|20px]] ", companyLogo[owner]) or ""
local home = randomChoice(cities)
-- pick companies, include owner if Cargo
local picks = {}
local count = math.random(3, 4)
if vt == "Cargo" and ct ~= "Unspecified" and companyLogo[owner] then
table.insert(picks, owner)
local choices = {}
for _, name in ipairs(poolMap[ct] or {}) do
if name ~= owner then table.insert(choices, name) end
end
local more = randomN(choices, count - 1)
for _, cname in ipairs(more) do table.insert(picks, cname) end
else
local flat = {}
for _, list in pairs(poolMap) do
for _, name in ipairs(list) do table.insert(flat, name) end
end
picks = randomN(flat, count)
end
-- build Companies cell
local compCell = "<ul>"
for _, cname in ipairs(picks) do
local logo = companyLogo[cname] and string.format("[[File:%s|20px]] ", companyLogo[cname]) or ""
compCell = compCell .. string.format("<li>%s%s</li>", logo, cname)
end
compCell = compCell .. "</ul>"
-- determine error
local err = (math.random() < 0.2 and randomChoice({
"Cargo Mislabeling", "Improper Documentation", "Surveillance Anomaly",
"Inspection Failure", "Unregistered Ritual Cargo"
})) or "None"
table.insert(ships, {
date = string.format("Day %d, Y.%d", d, y),
time = string.format("%02d:%02d", hr, mn),
sort = hr * 60 + mn,
vid = "VM-" .. math.random(10000, 99999),
home = cityFlag[home] .. " " .. home,
typ = vt,
ownerCell = ownerLogo .. owner,
cargotype = ct,
cargoCompanies = compCell,
berth = math.random(1,124),
teus = math.random(100,1000),
tonnage = string.format("%.2f", math.random()*19000+1000),
queue = string.format("%.2f", math.random()*5.5+0.5),
turnaround = string.format("%.2f", math.random()*32+4),
error = err
})
end
table.sort(ships, function(a,b) return a.sort < b.sort end)
-- build wiki table
local out = {
'{| class="wikitable sortable"',
'! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type !! Companies',
'!! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
}
for _, s in ipairs(ships) do
local rowDef = s.error ~= "None" and '|- bgcolor="#ffcccc"' or '|-'
table.insert(out, rowDef)
table.insert(out, string.format(
'| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s',
s.date, s.time, s.vid, s.home, s.typ,
s.ownerCell, s.cargotype, s.cargoCompanies,
s.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error
))
end
-- footer
table.insert(out, '|}')
table.insert(out, "'''Error Key:'''")
table.insert(out, "* '''Cargo Mislabeling:''' Manifest ≠ actual goods")
table.insert(out, "* '''Improper Documentation:''' Missing or outdated papers")
table.insert(out, "* '''Surveillance Anomaly:''' Unexpected heat/motion")
table.insert(out, "* '''Inspection Failure:''' Customs/hatch failure")
table.insert(out, "* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank")
return table.concat(out, "\n")
end
function p.dailyReport()
local y, d = p.getCurrentDate()
return string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y)
.. "\n" .. p.generateShipTable()
end
return p