Module:GeneralPortOperations: Difference between revisions
From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs) No edit summary |
NewZimiaGov (talk | contribs) No edit summary |
||
| Line 14: | Line 14: | ||
local function randomChoice(t) return t[math.random(#t)] end | local function randomChoice(t) return t[math.random(#t)] end | ||
-- 3) | -- 3) Home ports list + flags | ||
local cities = { | local cities = { | ||
" | "Aegirheim","Skýrophos","Bjornopolis","Norsolyra","Ephyra", | ||
"Symphonara","Delphica","Vaeringheim","Somniumpolis", | |||
"Keybir-Aviv","Sufriya","Jogi" | |||
" | |||
} | } | ||
local cityFlag = {} | local cityFlag = {} | ||
| Line 37: | Line 30: | ||
local cargoTypes = {"Agricultural","Mining/Manufacturing","Services","Unspecified"} | local cargoTypes = {"Agricultural","Mining/Manufacturing","Services","Unspecified"} | ||
-- 5) Ritual cults & military divisions | -- 5) Ritual cults & military divisions (placeholder lists) | ||
local ritualCults = { | local ritualCults = {} -- define as needed | ||
local militaryDivs = {} -- define as needed | |||
} | |||
local militaryDivs = { | |||
} | |||
-- 6) Company pools | -- 6) Company pools (placeholder lists) | ||
local agriCompanies = { | local agriCompanies = {} | ||
local miningCompanies = {} | |||
local serviceCompanies = {} | |||
} | |||
local miningCompanies = { | |||
} | |||
local serviceCompanies = { | |||
} | |||
-- 7) Logos per company | -- 7) Logos per company | ||
local companyLogo = {} | local companyLogo = {} | ||
local function addLogo(name,file) companyLogo[name] = file end | local function addLogo(name,file) companyLogo[name] = file end | ||
-- | -- TODO: addLogo calls for each company logo here | ||
-- | -- 8) Privateer captains helper | ||
local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}} | local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}} | ||
local function getRandomPrivateer() | local function getRandomPrivateer() | ||
| Line 109: | Line 55: | ||
end | end | ||
-- | -- 9) Determine Owner/Operator | ||
local function getOwner(vt,ct) | local function getOwner(vt,ct) | ||
if vt == "Ritual" then return randomChoice(ritualCults) | if vt == "Ritual" then return randomChoice(ritualCults) | ||
elseif vt == "Military" then return randomChoice(militaryDivs) | elseif vt == "Military" then return randomChoice(militaryDivs) | ||
elseif vt == "Privateer" then return getRandomPrivateer() | elseif vt == "Privateer" then return getRandomPrivateer() | ||
| Line 123: | Line 69: | ||
end | end | ||
-- | -- 10) Build the ship table without Products column | ||
function p.generateShipTable() | function p.generateShipTable() | ||
math.randomseed(os.time()) | math.randomseed(os.time()) | ||
| Line 132: | Line 78: | ||
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 = getOwner(vt,ct) | |||
local logo = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or "" | |||
local home = randomChoice(cities) | |||
local owner = getOwner(vt,ct) | |||
local logo | |||
local home | |||
table.insert(ships, { | table.insert(ships, { | ||
date = string.format("Day %d, Y.%d", d, y), | date = string.format("Day %d, Y.%d", d, y), | ||
time = string.format("%02d:%02d", hr, mn), | time = string.format("%02d:%02d", hr, mn), | ||
sort = hr*60+mn, | sort = hr*60 + mn, | ||
vid = "VM-"..math.random(10000,99999), | vid = "VM-"..math.random(10000,99999), | ||
home = cityFlag[home].." "..home, | home = cityFlag[home].." "..home, | ||
| Line 152: | Line 91: | ||
ownerCell = logo..owner, | ownerCell = logo..owner, | ||
cargotype = ct, | cargotype = ct, | ||
berth = math.random(1,124), | berth = math.random(1,124), | ||
teus = math.random(100,1000), | teus = math.random(100,1000), | ||
| Line 170: | Line 108: | ||
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', | ||
'!! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error' | |||
} | } | ||
for _,s in ipairs(ships) do | for _,s in ipairs(ships) do | ||
table.insert(out, string.format([[ | table.insert(out, string.format([[ | ||
|- | |- | ||
| %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.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 | ||
)) | )) | ||
Revision as of 02:45, 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 helper
local function randomChoice(t) return t[math.random(#t)] end
-- 3) Home ports list + flags
local cities = {
"Aegirheim","Skýrophos","Bjornopolis","Norsolyra","Ephyra",
"Symphonara","Delphica","Vaeringheim","Somniumpolis",
"Keybir-Aviv","Sufriya","Jogi"
}
local cityFlag = {}
for _,c in ipairs(cities) do
local norm = c:gsub("[%s%-’]",""):gsub("ó","o"):gsub("í","i"):gsub("á","a")
cityFlag[c] = 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) Ritual cults & military divisions (placeholder lists)
local ritualCults = {} -- define as needed
local militaryDivs = {} -- define as needed
-- 6) Company pools (placeholder lists)
local agriCompanies = {}
local miningCompanies = {}
local serviceCompanies = {}
-- 7) Logos per company
local companyLogo = {}
local function addLogo(name,file) companyLogo[name] = file end
-- TODO: addLogo calls for each company logo here
-- 8) Privateer captains 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)
else
return string.format("Captain %s %s",c.first,c.last)
end
end
-- 9) Determine Owner/Operator
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
-- 10) Build the ship table without Products column
function p.generateShipTable()
math.randomseed(os.time())
local y,d = p.getCurrentDate()
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 logo = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or ""
local home = randomChoice(cities)
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 = logo..owner,
cargotype = ct,
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 = (math.random()<0.2 and randomChoice{
"Cargo Mislabeling","Improper Documentation",
"Surveillance Anomaly","Inspection Failure",
"Unregistered Ritual Cargo"
}) or "None"
})
end
table.sort(ships, function(a,b) return a.sort < b.sort end)
local out = {
'{| class="wikitable sortable"',
'! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type',
'!! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
}
for _,s in ipairs(ships) do
table.insert(out, string.format([[
|-
| %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.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error
))
end
table.insert(out, "|}\n\n'''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()
local hdr = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y)
return hdr .. "\n" .. p.generateShipTable()
end
return p