Module:GeneralPortOperations
From MicrasWiki
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 now = os.time()
local days = math.floor((now - start) / 86400)
local year = math.floor(days / 183)
local day = (days % 183) + 1
return year, day
end
-- 2) Helpers
local function randomChoice(t) return t[math.random(#t)] end
-- 3) All data tables
local cities = {
"Vaeringheim","Somniumpolis","Delphica","Ephyra","Norsolyra",
"Skýrophos","Riddersborg","Ardclach","Jogi","Sufriya",
"Keybir-Aviv","Aegirheim","Bjornopolis"
}
local cityFlag = {
Vaeringheim="[[File:VaeringheimFlag.png|20px]]",
Somniumpolis="[[File:SomniumpolisFlag.png|20px]]",
Delphica="[[File:DelphicaFlag.png|20px]]",
Ephyra="[[File:EphyraFlag.png|20px]]",
Norsolyra="[[File:NorsolyraFlag.png|20px]]",
["Skýrophos"]="[[File:SkyrophosFlag.png|20px]]",
Riddersborg="[[File:RiddersborgFlag.png|20px]]",
Ardclach="[[File:ArdclachFlag.png|20px]]",
Jogi="[[File:JogiFlag.png|20px]]",
Sufriya="[[File:SufriyaFlag.png|20px]]",
["Keybir-Aviv"]="[[File:KeybirAvivFlag.png|20px]]",
Aegirheim="[[File:AegirheimFlag.png|20px]]",
Bjornopolis="[[File:BjornopolisFlag.png|20px]]"
}
local vesselTypes = {"Cargo","Military","Ritual","Privateer"}
local cargoTypes = {"Agricultural","Mining/Manufacturing","Services","Unspecified"}
local ritualCults = {
"Ordo Solis Invicti","Order of Aurora Mystica","Harmony Sanctum","Ignis Aeternum",
"Celestial Harmony Sect","Guild of Golden Shadows","Azure Sentinel Sect","Reverie Nebulous",
"Eon Fellowship","Order of the Umbral Oracle","Mystery of the Verdant Embrace","Conclave Illuminara",
"Sanctum Vitalis","Temple Alabaster","Court of the Ironclad","Accord Concordia",
"Mystery of the Stygian Veil","Sylvan Fellowship","Mystery of Red Mirth","Rex Catonis",
"Sanctum Delphica","Ordo Amicitia","Temple Illuminata"
}
local militaryDivs = {
"Alpazkigz Division","Odiferia Division","Vaeringheim Division","Haifa Division",
"Jeseri Division","Hatch Ministry Division","New South Jangsong Division","Haifan Bassaridia Division"
}
-- 3a) Company pools
local agriCompanies = {
"Gladeseed Farmers' Union","Atterian Cattle Drivers","Noctic Fleet",
"Jogiani Merchants of Manwine","Keepers of the Grove of Zoe Elm",
"Sea-Elm Southern Meadery","Plains of Jogi","Ale of the Night Central Brewery",
"Camel Herders of the Jangsong Province","Anterran Imports and Services",
"Merchant Guild of the Poppy Goddess","Grand Cave Bee Meadery",
"Cinammon Plains of Rouge","The Velvet Company","Seamstresses of Rouge",
"Salurian Temple of Sacred Horehound","Bulhanu Ranchers' Association",
"Suncliff Fisheries","Ministers of Mistress Mugwort",
"Blood Vineyards of the Far North","Norsolyrian Wisp Rice Farmers Association",
"Giid-Lisea Ranching Import Company","Bird Keepers of Saluria",
"Hunters of the Giant Fanged Penguin","Knights Castle Reindeer Herders",
"Lindley Whaling Company","Copper Mines of Southern Jogi"
}
local miningCompanies = {
"Baratar Corporation","Roving Wind Farm Corporation",
"Thalassian Temple Granite Export Cooperative","East Keltian Iron Company",
"Mylecian Coal Ports","Merchants of the Valley of Diamonds",
"East Keltian Timber Company","Onceanic Boot Company",
"Commune of the Garganid Apostles","Shï Collective","Order of the Sphinx",
"Market Hanavusu","Somniant Stock Fund"
}
local serviceCompanies = {
"Lake Morovia Blockade Fund","Court of the Dark Harpy","Hatch Ministry",
"Maritime Guild of the Cult of Maskmakers","Ergonian Spy Agency",
"Temple Bank of the Reformed Stripping Path","Couriers of the Lizard Queen",
"Temple University of Delphica","La Sái Ebile","Hellhound Breeders of Dragevik"
}
-- 3b) Logo filenames for every company
local companyLogo = {
["Gladeseed Farmers' Union"] = "Gladeseed420.png",
["Atterian Cattle Drivers"] = "Atterian420.png",
["Noctic Fleet"] = "Noctic420.png",
["Jogiani Merchants of Manwine"] = "Jogiani420.png",
["Keepers of the Grove of Zoe Elm"] = "KeepersoftheGrove.png",
["Sea-Elm Southern Meadery"] = "SeaElm420.png",
["Plains of Jogi"] = "PlainsofJogi.png",
["Ale of the Night Central Brewery"] = "AleofNight420.png",
["Camel Herders of the Jangsong Province"] = "CamelHerders420.png",
["Anterran Imports and Services"] = "AnterranImports420.png",
["Merchant Guild of the Poppy Goddess"] = "PoppyGoddess420.png",
["Grand Cave Bee Meadery"] = "GrandCave420.png",
["Cinammon Plains of Rouge"] = "CinammonPlains420.png",
["The Velvet Company"] = "VelvetHome420.png",
["Seamstresses of Rouge"] = "Seamstresses420.png",
["Salurian Temple of Sacred Horehound"] = "SalurianTemple421.png",
["Bulhanu Ranchers' Association"] = "Bulhanu421.png",
["Suncliff Fisheries"] = "Suncliff421.png",
["Ministers of Mistress Mugwort"] = "Mugwort421.png",
["Blood Vineyards of the Far North"] = "BloodVineyards421.png",
["Norsolyrian Wisp Rice Farmers Association"] = "Norsolyrian421.png",
["Giid-Lisea Ranching Import Company"] = "GiidLisea421.png",
["Bird Keepers of Saluria"] = "SaluriaBK421.png",
["Hunters of the Giant Fanged Penguin"] = "FangedPenguin421.png",
["Knights Castle Reindeer Herders"] = "KnightsCastle421.png",
["Lindley Whaling Company"] = "LindleyWhalingCompany.png",
["Copper Mines of Southern Jogi"] = "CopperMinesLogoC.png",
["Baratar Corporation"] = "Baratar420.png",
["Roving Wind Farm Corporation"] = "RovingWind420.png",
["Thalassian Temple Granite Export Cooperative"]= "ThalassianGranite420.png",
["East Keltian Iron Company"] = "EKIron420.png",
["Mylecian Coal Ports"] = "CoalPorts420.png",
["Merchants of the Valley of Diamonds"] = "ValleyofDiamonds420.png",
["East Keltian Timber Company"] = "EKTimber420.png",
["Onceanic Boot Company"] = "OnceanicBoot421.png",
["Commune of the Garganid Apostles"] = "Garganid421.png",
["Shï Collective"] = "ShiCollective421.png",
["Order of the Sphinx"] = "OrderofSphinx421.png",
["Market Hanavusu"] = "MarketHanavusu421.png",
["Somniant Stock Fund"] = "SomniantStockFund.png",
["Lake Morovia Blockade Fund"] = "BlockadeFund420.png",
["Court of the Dark Harpy"] = "CourtDarkHarpy.png",
["Hatch Ministry"] = "HatchMinistry420.png",
["Maritime Guild of the Cult of Maskmakers"] = "MaritimeGuild420.png",
["Ergonian Spy Agency"] = "ErgonianSpy421.png",
["Temple Bank of the Reformed Stripping Path"] = "TempleBankCrest.png",
["Couriers of the Lizard Queen"] = "LizardQueen421.png",
["Temple University of Delphica"] = "TempleUniversity421.png",
["La Sái Ebile"] = "LaSie421.png",
["Hellhound Breeders of Dragevik"] = "Dragevik421.png"
}
-- 4) Random privateer names
local privateers = {
{first="Talvios", last="Karnis", nick="Erebektos"},
{first="Mirek", last="Davros", nick="Zammarion"},
-- …etc., full list as before…
}
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
-- 5) Pick Owner/Operator
local function getOwner(vt, ct)
if vt=="Ritual" then return randomChoice(ritualCults) end
if vt=="Military" then return randomChoice(militaryDivs) end
if vt=="Privateer" then return getRandomPrivateer() end
if vt=="Cargo" then
if ct=="Agricultural" then return randomChoice(agriCompanies) end
if ct=="Mining/Manufacturing" then return randomChoice(miningCompanies) end
if ct=="Services" then return randomChoice(serviceCompanies)end
end
return "Independent Consortium"
end
-- 6) Build the table
function p.generateShipTable()
math.randomseed(os.time())
local ships = {}
for i=1,math.random(50,80) do
local year, day = p.getCurrentDate()
local hr, mn = math.random(0,23), math.random(0,59)
local vt = randomChoice(vesselTypes)
local ct = randomChoice(cargoTypes)
local prods = {}
if vt=="Cargo" and ct=="Agricultural" then
for _=1,math.random(1,3) do
prods[#prods+1] = randomChoice(agriProducts)
end
elseif vt=="Cargo" and ct=="Mining/Manufacturing" then
for _=1,math.random(1,3) do
prods[#prods+1] = randomChoice(miningProducts)
end
end
local owner = getOwner(vt,ct)
local logo = companyLogo[owner]
and string.format("[[File:%s|20px]] ", companyLogo[owner])
or ""
ships[#ships+1] = {
date = string.format("Day %d, Y.%d", day, year),
time = string.format("%02d:%02d",hr,mn),
sort = hr*60 + mn,
vid = "VM-"..math.random(10000,99999),
home = cityFlag[randomChoice(cities)],
type = vt,
ownerCell = logo..owner,
cargotype = ct,
products = prods,
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 !! Products !! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
}
for _, s in ipairs(ships) do
local prodCell = "#N/A"
if #s.products>0 then
prodCell = "<ul>"
for _,pr in ipairs(s.products) do
prodCell = prodCell .. "<li>"..pr.."</li>"
end
prodCell = prodCell .. "</ul>"
end
out[#out+1] = string.format(
"|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
s.date, s.time, s.vid, s.home, s.type,
s.ownerCell, s.cargotype, prodCell,
s.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error
)
end
out[#out+1] = "|}\n\n'''Error Key:'''"
out[#out+1] = "* '''Cargo Mislabeling:''' Manifest ≠ actual goods"
out[#out+1] = "* '''Improper Documentation:''' Missing/outdated papers"
out[#out+1] = "* '''Surveillance Anomaly:''' Odd heat/motion signature"
out[#out+1] = "* '''Inspection Failure:''' Customs/hatch failure"
out[#out+1] = "* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank"
return table.concat(out, "\n")
end
function p.dailyReport()
local y,d = p.getCurrentDate()
local header = string.format(
"'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y
)
return header.."\n"..p.generateShipTable()
end
return p