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 2: | Line 2: | ||
local p = {} | local p = {} | ||
-- 1) PSSC Date | |||
function p.getCurrentDate() | function p.getCurrentDate() | ||
local startDate = os.time | local startDate = os.time{year=1999, month=8, day=6} | ||
local secondsInDay = 86400 | local secondsInDay = 86400 | ||
local daysPerYear = 183 | local daysPerYear = 183 | ||
local | local now = os.time() | ||
local | local daysElapsed = math.floor((now - startDate) / secondsInDay) | ||
local yearFraction = | local yearFraction = daysElapsed / daysPerYear | ||
local | local y = math.floor(yearFraction) | ||
local | local d = (daysElapsed % daysPerYear) + 1 | ||
return | return y, d | ||
end | end | ||
| Line 18: | Line 19: | ||
end | end | ||
-- Ritual cults | |||
local ritualCults = { | local ritualCults = { | ||
"Ordo Solis Invicti", "Order of Aurora Mystica", "Harmony Sanctum", "Ignis Aeternum", | "Ordo Solis Invicti", "Order of Aurora Mystica", "Harmony Sanctum", "Ignis Aeternum", | ||
| Line 27: | Line 29: | ||
} | } | ||
-- Military divisions | |||
local militaryDivisions = { | local militaryDivisions = { | ||
"Alpazkigz Division", "Odiferia Division", "Vaeringheim Division", "Haifa Division", | "Alpazkigz Division", "Odiferia Division", "Vaeringheim Division", "Haifa Division", | ||
| Line 32: | Line 35: | ||
} | } | ||
-- Cargo companies by type | |||
local agriCompanies = { | local agriCompanies = { | ||
"Gladeseed Farmers' Union", "Atterian Cattle Drivers", "Noctic Fleet", "Jogiani Merchants of Manwine", | "Gladeseed Farmers' Union", "Atterian Cattle Drivers", "Noctic Fleet", | ||
"Jogiani Merchants of Manwine", "Keepers of the Grove of Zoe Elm", | |||
"Camel Herders of the Jangsong Province", "Anterran Imports and Services", "Merchant Guild of the Poppy Goddess", | "Sea-Elm Southern Meadery", "Plains of Jogi", "Ale of the Night Central Brewery", | ||
"Camel Herders of the Jangsong Province", "Anterran Imports and Services", | |||
"Salurian Temple of Sacred Horehound", "Bulhanu Ranchers' Association", "Suncliff Fisheries", | "Merchant Guild of the Poppy Goddess", "Grand Cave Bee Meadery", | ||
"Cinammon Plains of Roue", "The Velvet Company", "Seamstresses of Rouge", | |||
"Giid Lisea Ranching Import Company", "Bird Keepers of Saluria", "Hunters of the Giant Fanged Penguin", | "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" | |||
} | } | ||
local miningCompanies = { | local miningCompanies = { | ||
"Baratar Corporation", "Roving Wind Farm Corporation", "Thalassian Temples Granite Export Cooperative", | "Baratar Corporation", "Roving Wind Farm Corporation", | ||
"Thalassian Temples Granite Export Cooperative", "East Keltian Iron Company", | |||
"East Keltian Timber Company", "Onceanic Boot Company", "Commune of the Garganid Apostles", | "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 = { | local serviceCompanies = { | ||
"Lake Morovia Blockade Fund", "Court of the Dark Harpy", "Hatch Ministry", | "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", | "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" | |||
} | } | ||
local function getCompanyForCargo( | local function getCompanyForCargo(cargoType) | ||
if | if cargoType == "Agricultural" then | ||
return randomChoice(agriCompanies) | return randomChoice(agriCompanies) | ||
elseif | elseif cargoType == "Mining/Manufacturing" then | ||
return randomChoice(miningCompanies) | return randomChoice(miningCompanies) | ||
elseif | elseif cargoType == "Services" then | ||
return randomChoice(serviceCompanies) | return randomChoice(serviceCompanies) | ||
end | end | ||
return "Independent Consortium" | |||
end | end | ||
local | -- Privateer captains | ||
{ | local captains = { | ||
{ | {f="Talvios", l="Karnis", n="Erebektos"}, | ||
{ | {f="Mirek", l="Davros", n="Zammarion"}, | ||
{ | {f="Ilion", l="Quoros"}, | ||
{ | {f="Sevon", l="Halek", n="Thamuthis"}, | ||
{ | {f="Caldris", l="Onir", n="Votharion"}, | ||
{ | {f="Loras", l="Tarnok"}, | ||
{ | {f="Vaelen", l="Koros"}, | ||
{ | {f="Daskos", l="Meyron", n="Orontion"}, | ||
{ | {f="Kyric", l="Fenros", n="Mekharsan"}, | ||
{ | {f="Omir", l="Thalos"}, | ||
{ | {f="Baryon", l="Syrek", n="Satharkon"}, | ||
{ | {f="Orien", l="Damar"}, | ||
{ | {f="Tharkos", l="Nyros", n="Vathmenos"}, | ||
{ | {f="Halion", l="Trevik"}, | ||
{ | {f="Kelvir", l="Raan", n="Nabarrion"}, | ||
{ | {f="Lethan", l="Kohr"}, | ||
{ | {f="Zarik", l="Tharn"}, | ||
{ | {f="Varas", l="Jorik", n="Tharnukhet"}, | ||
{ | {f="Yasrek", l="Tymon"}, | ||
{ | {f="Aethon", l="Morvek", n="Vathromen"}, | ||
{ | {f="Crivos", l="Elyen"}, | ||
{ | {f="Saran", l="Valic"}, | ||
{ | {f="Drevos", l="Helkan", n="Khamsuron"}, | ||
{ | {f="Nyros", l="Qalor"}, | ||
{f="Talen", l="Vorric", n="Valkhoret"} | |||
} | } | ||
local function | local function getPrivateerCaptain() | ||
local | local c = randomChoice(captains) | ||
if | if c.n and math.random() < 0.25 then | ||
return string.format( | return string.format('Captain %s "%s" %s', c.f, c.n, c.l) | ||
end | end | ||
return string.format("Captain %s %s", c.f, c.l) | |||
end | end | ||
-- City flags (always Vaeringheim for simplicity) | |||
local homeCity = "[[File:VaeringheimFlag.png|20px]] Vaeringheim" | |||
function p.generateShipTable() | function p.generateShipTable() | ||
local vesselTypes = { | local vesselTypes = {"Cargo","Military","Ritual","Privateer"} | ||
local cargoTypes = { | local cargoTypes = {"Agricultural","Mining/Manufacturing","Services"} | ||
local errorTypes = { | local errorTypes = { | ||
"Cargo Mislabeling", | "Cargo Mislabeling","Improper Documentation", | ||
"Surveillance Anomaly","Inspection Failure", | |||
"Surveillance Anomaly", | |||
"Unregistered Ritual Cargo" | "Unregistered Ritual Cargo" | ||
} | } | ||
| Line 120: | Line 129: | ||
local year, day = p.getCurrentDate() | local year, day = p.getCurrentDate() | ||
local dateStr = string.format("Day %d, Y.%d", day, year) | local dateStr = string.format("Day %d, Y.%d", day, year) | ||
local ships = {} | |||
-- generate | |||
for i=1, math.random(50,80) do | |||
local h,m = math.random(0,23), math.random(0,59) | |||
local tval = h*60 + m | |||
local vtype = randomChoice(vesselTypes) | |||
local ctype = randomChoice(cargoTypes) | |||
local displayType, company | |||
if vtype=="Ritual" then | |||
displayType = "Ritual – "..randomChoice(ritualCults) | |||
company = string.match(displayType, "%–%s*(.+)$") | |||
elseif vtype=="Military" then | |||
displayType = "Military – "..randomChoice(militaryDivisions) | |||
company = string.match(displayType, "%–%s*(.+)$") | |||
elseif vtype=="Privateer" then | |||
displayType = "Privateer – "..getPrivateerCaptain() | |||
if | company = displayType -- show full Captain text | ||
displayType = "Ritual | else | ||
elseif | displayType = "Cargo" | ||
displayType = "Military | company = getCompanyForCargo(ctype) | ||
elseif | |||
displayType = "Privateer | |||
end | end | ||
ships | |||
date = dateStr, | table.insert(ships, { | ||
time = string.format("%02d:%02d", | date = dateStr, | ||
sort = | time = string.format("%02d:%02d",h,m), | ||
vessel_id = "VM-" .. | sort = tval, | ||
home_city = | vessel_id = "VM-"..math.random(10000,99999), | ||
type = displayType, | home_city = homeCity, | ||
berth = math.random(1, 124), | type = displayType, | ||
teus = math.random(100, 1000), | company = company, | ||
tonnage = string.format("%.2f", math.random() * 19000 + 1000), | berth = math.random(1,124), | ||
cargo_type = | teus = math.random(100,1000), | ||
tonnage = string.format("%.2f", math.random()*19000+1000), | |||
queue = string.format("%.2f", math.random() * 5.5 + 0.5), | cargo_type = ctype, | ||
turnaround = string.format("%.2f", math.random() * 32 + 4), | queue = string.format("%.2f", math.random()*5.5+0.5), | ||
error = (math.random() < 0.2) and randomChoice(errorTypes) or "None" | turnaround = string.format("%.2f", math.random()*32+4), | ||
} | error = (math.random()<0.2) and randomChoice(errorTypes) or "None" | ||
}) | |||
end | end | ||
table.sort(ships, function(a, b) return a.sort < b.sort end) | table.sort(ships, function(a,b) return a.sort<b.sort end) | ||
local | -- build wikitext | ||
for _, | local out = '{| class="wikitable sortable"\n' .. | ||
'! Date !! Time !! Vessel ID !! Home City !! Type !! Company !! Berth !! TEUs !! Tonnage !! Cargo Type !! Queue Time !! Turnaround Time !! Error' | |||
for _,s in ipairs(ships) do | |||
out = out .. string.format( | |||
if | '\n|-\n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s', | ||
s.date, s.time, s.vessel_id, s.home_city, s.type, s.company, | |||
s.berth, s.teus, s.tonnage, s.cargo_type, s.queue, s.turnaround | |||
) | |||
if s.error~="None" then | |||
out = out .. string.format(' || style="background-color:#fdd;" | %s', s.error) | |||
else | else | ||
out = out .. ' || None' | |||
end | end | ||
end | end | ||
out = out .. '\n|}\n\n' .. | |||
"'''Error Key:'''<br>" .. | |||
"* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods<br>" .. | |||
"* '''Improper Documentation:''' Missing or outdated transit papers<br>" .. | |||
'''Error Key:''' | "* '''Surveillance Anomaly:''' Unexpected heat or movement signature<br>" .. | ||
* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods | "* '''Inspection Failure:''' Failed customs or hatch review<br>" .. | ||
* '''Improper Documentation:''' Missing or outdated transit papers | "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank" | ||
* '''Surveillance Anomaly:''' Unexpected heat or movement signature | return out | ||
* '''Inspection Failure:''' Failed customs or hatch review | |||
* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank | |||
return | |||
end | end | ||
function p.dailyReport() | function p.dailyReport() | ||
local | local y,d = p.getCurrentDate() | ||
local | local hdr = string.format( | ||
return | "'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''<br>", | ||
d, y | |||
) | |||
return hdr .. p.generateShipTable() | |||
end | end | ||
return p | return p | ||
Revision as of 01:29, 24 April 2025
Documentation for this module may be created at Module:GeneralPortOperations/doc
-- Module:GeneralPortDailyLog
local p = {}
-- 1) PSSC Date
function p.getCurrentDate()
local startDate = os.time{year=1999, month=8, day=6}
local secondsInDay = 86400
local daysPerYear = 183
local now = os.time()
local daysElapsed = math.floor((now - startDate) / secondsInDay)
local yearFraction = daysElapsed / daysPerYear
local y = math.floor(yearFraction)
local d = (daysElapsed % daysPerYear) + 1
return y, d
end
local function randomChoice(t)
return t[math.random(#t)]
end
-- Ritual cults
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"
}
-- Military divisions
local militaryDivisions = {
"Alpazkigz Division", "Odiferia Division", "Vaeringheim Division", "Haifa Division",
"Jeseri Division", "Hatch Ministry Division", "New South Jangsong Division", "Haifan Bassaridia Division"
}
-- Cargo companies by type
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 Roue", "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"
}
local miningCompanies = {
"Baratar Corporation", "Roving Wind Farm Corporation",
"Thalassian Temples 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"
}
local function getCompanyForCargo(cargoType)
if cargoType == "Agricultural" then
return randomChoice(agriCompanies)
elseif cargoType == "Mining/Manufacturing" then
return randomChoice(miningCompanies)
elseif cargoType == "Services" then
return randomChoice(serviceCompanies)
end
return "Independent Consortium"
end
-- Privateer captains
local captains = {
{f="Talvios", l="Karnis", n="Erebektos"},
{f="Mirek", l="Davros", n="Zammarion"},
{f="Ilion", l="Quoros"},
{f="Sevon", l="Halek", n="Thamuthis"},
{f="Caldris", l="Onir", n="Votharion"},
{f="Loras", l="Tarnok"},
{f="Vaelen", l="Koros"},
{f="Daskos", l="Meyron", n="Orontion"},
{f="Kyric", l="Fenros", n="Mekharsan"},
{f="Omir", l="Thalos"},
{f="Baryon", l="Syrek", n="Satharkon"},
{f="Orien", l="Damar"},
{f="Tharkos", l="Nyros", n="Vathmenos"},
{f="Halion", l="Trevik"},
{f="Kelvir", l="Raan", n="Nabarrion"},
{f="Lethan", l="Kohr"},
{f="Zarik", l="Tharn"},
{f="Varas", l="Jorik", n="Tharnukhet"},
{f="Yasrek", l="Tymon"},
{f="Aethon", l="Morvek", n="Vathromen"},
{f="Crivos", l="Elyen"},
{f="Saran", l="Valic"},
{f="Drevos", l="Helkan", n="Khamsuron"},
{f="Nyros", l="Qalor"},
{f="Talen", l="Vorric", n="Valkhoret"}
}
local function getPrivateerCaptain()
local c = randomChoice(captains)
if c.n and math.random() < 0.25 then
return string.format('Captain %s "%s" %s', c.f, c.n, c.l)
end
return string.format("Captain %s %s", c.f, c.l)
end
-- City flags (always Vaeringheim for simplicity)
local homeCity = "[[File:VaeringheimFlag.png|20px]] Vaeringheim"
function p.generateShipTable()
local vesselTypes = {"Cargo","Military","Ritual","Privateer"}
local cargoTypes = {"Agricultural","Mining/Manufacturing","Services"}
local errorTypes = {
"Cargo Mislabeling","Improper Documentation",
"Surveillance Anomaly","Inspection Failure",
"Unregistered Ritual Cargo"
}
local year, day = p.getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local ships = {}
-- generate
for i=1, math.random(50,80) do
local h,m = math.random(0,23), math.random(0,59)
local tval = h*60 + m
local vtype = randomChoice(vesselTypes)
local ctype = randomChoice(cargoTypes)
local displayType, company
if vtype=="Ritual" then
displayType = "Ritual – "..randomChoice(ritualCults)
company = string.match(displayType, "%–%s*(.+)$")
elseif vtype=="Military" then
displayType = "Military – "..randomChoice(militaryDivisions)
company = string.match(displayType, "%–%s*(.+)$")
elseif vtype=="Privateer" then
displayType = "Privateer – "..getPrivateerCaptain()
company = displayType -- show full Captain text
else
displayType = "Cargo"
company = getCompanyForCargo(ctype)
end
table.insert(ships, {
date = dateStr,
time = string.format("%02d:%02d",h,m),
sort = tval,
vessel_id = "VM-"..math.random(10000,99999),
home_city = homeCity,
type = displayType,
company = company,
berth = math.random(1,124),
teus = math.random(100,1000),
tonnage = string.format("%.2f", math.random()*19000+1000),
cargo_type = ctype,
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(errorTypes) or "None"
})
end
table.sort(ships, function(a,b) return a.sort<b.sort end)
-- build wikitext
local out = '{| class="wikitable sortable"\n' ..
'! Date !! Time !! Vessel ID !! Home City !! Type !! Company !! Berth !! TEUs !! Tonnage !! Cargo Type !! Queue Time !! Turnaround Time !! Error'
for _,s in ipairs(ships) do
out = out .. string.format(
'\n|-\n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s',
s.date, s.time, s.vessel_id, s.home_city, s.type, s.company,
s.berth, s.teus, s.tonnage, s.cargo_type, s.queue, s.turnaround
)
if s.error~="None" then
out = out .. string.format(' || style="background-color:#fdd;" | %s', s.error)
else
out = out .. ' || None'
end
end
out = out .. '\n|}\n\n' ..
"'''Error Key:'''<br>" ..
"* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods<br>" ..
"* '''Improper Documentation:''' Missing or outdated transit papers<br>" ..
"* '''Surveillance Anomaly:''' Unexpected heat or movement signature<br>" ..
"* '''Inspection Failure:''' Failed customs or hatch review<br>" ..
"* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank"
return out
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'''<br>",
d, y
)
return hdr .. p.generateShipTable()
end
return p