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({year = 1999, month = 8, day = 6})
     local startDate = os.time{year=1999, month=8, day=6}
     local secondsInDay = 86400
     local secondsInDay = 86400
     local daysPerYear = 183
     local daysPerYear = 183
     local currentDate = os.time()
     local now = os.time()
     local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
     local daysElapsed = math.floor((now - startDate) / secondsInDay)
     local yearFraction = totalDaysElapsed / daysPerYear
     local yearFraction = daysElapsed / daysPerYear
     local psscYear = math.floor(yearFraction)
     local y = math.floor(yearFraction)
     local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
     local d = (daysElapsed % daysPerYear) + 1
     return psscYear, dayOfYear
     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",
    "Keepers of the Grove of Zoe Elm", "Sea-Elm Southern Meadery", "Plains of Jogi", "Ale of the Night Central Brewery",
    "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",
    "Grand Cave Bee Meadery", "Cinammon Plains of Roue", "The Velvet Company", "Seamstresses of Rouge",
     "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",
    "Ministers of Mistress Mugwort", "Blood Vineyards of the Far North", "Norsolyrian Wisp Rice Farmers Association",
    "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",
    "Knights Castle Reindeer Herders", "Lindley Whaling Company"
    "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",
    "East Keltian Iron Company", "Mylecian Coal Ports", "Merchants of the Valley of Diamonds",
    "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",
    "Shï Collective", "Order of the Sphinx", "Market Hanavusu", "Somniant Stock Fund"
     "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",
    "Couriers of the Lizard Queen", "Temple University of Delphica", "La Sái Ebile",
    "Temple Bank of the Reformed Stripping Path", "Couriers of the Lizard Queen",
    "Hellhound Breeders of Dragevik"
    "Temple University of Delphica", "La Sái Ebile", "Hellhound Breeders of Dragevik"
}
}


local function getCompanyForCargo(vesselType, cargoType)
local function getCompanyForCargo(cargoType)
     if vesselType == "Cargo" and cargoType == "Agricultural" then
     if cargoType == "Agricultural" then
         return randomChoice(agriCompanies)
         return randomChoice(agriCompanies)
     elseif vesselType == "Cargo" and cargoType == "Mining/Manufacturing" then
     elseif cargoType == "Mining/Manufacturing" then
         return randomChoice(miningCompanies)
         return randomChoice(miningCompanies)
     elseif vesselType == "Cargo" and cargoType == "Services" then
     elseif cargoType == "Services" then
         return randomChoice(serviceCompanies)
         return randomChoice(serviceCompanies)
    else
        return "Independent Consortium"
     end
     end
    return "Independent Consortium"
end
end


local privateerCaptains = {
-- Privateer captains
     {first = "Talvios", last = "Karnis", nickname = "Erebektos"},
local captains = {
     {first = "Mirek", last = "Davros", nickname = "Zammarion"},
     {f="Talvios", l="Karnis", n="Erebektos"},
     {first = "Ilion", last = "Quoros"},
     {f="Mirek", l="Davros", n="Zammarion"},
     {first = "Sevon", last = "Halek", nickname = "Thamuthis"},
     {f="Ilion", l="Quoros"},
     {first = "Caldris", last = "Onir", nickname = "Votharion"},
     {f="Sevon", l="Halek", n="Thamuthis"},
     {first = "Loras", last = "Tarnok"},
     {f="Caldris", l="Onir", n="Votharion"},
     {first = "Vaelen", last = "Koros"},
     {f="Loras", l="Tarnok"},
     {first = "Daskos", last = "Meyron", nickname = "Orontion"},
     {f="Vaelen", l="Koros"},
     {first = "Kyric", last = "Fenros", nickname = "Mekharsan"},
     {f="Daskos", l="Meyron", n="Orontion"},
     {first = "Omir", last = "Thalos"},
     {f="Kyric", l="Fenros", n="Mekharsan"},
     {first = "Baryon", last = "Syrek", nickname = "Satharkon"},
     {f="Omir", l="Thalos"},
     {first = "Orien", last = "Damar"},
     {f="Baryon", l="Syrek", n="Satharkon"},
     {first = "Tharkos", last = "Nyros", nickname = "Vathmenos"},
     {f="Orien", l="Damar"},
     {first = "Halion", last = "Trevik"},
     {f="Tharkos", l="Nyros", n="Vathmenos"},
     {first = "Kelvir", last = "Raan", nickname = "Nabarrion"},
     {f="Halion", l="Trevik"},
     {first = "Lethan", last = "Kohr"},
     {f="Kelvir", l="Raan", n="Nabarrion"},
     {first = "Zarik", last = "Tharn"},
     {f="Lethan", l="Kohr"},
     {first = "Varas", last = "Jorik", nickname = "Tharnukhet"},
     {f="Zarik", l="Tharn"},
     {first = "Yasrek", last = "Tymon"},
     {f="Varas", l="Jorik", n="Tharnukhet"},
     {first = "Aethon", last = "Morvek", nickname = "Vathromen"},
     {f="Yasrek", l="Tymon"},
     {first = "Crivos", last = "Elyen"},
     {f="Aethon", l="Morvek", n="Vathromen"},
     {first = "Saran", last = "Valic"},
     {f="Crivos", l="Elyen"},
     {first = "Drevos", last = "Helkan", nickname = "Khamsuron"},
     {f="Saran", l="Valic"},
     {first = "Nyros", last = "Qalor"},
     {f="Drevos", l="Helkan", n="Khamsuron"},
     {first = "Talen", last = "Vorric", nickname = "Valkhoret"}
     {f="Nyros", l="Qalor"},
     {f="Talen", l="Vorric", n="Valkhoret"}
}
}


local function getRandomPrivateerName()
local function getPrivateerCaptain()
     local cap = randomChoice(privateerCaptains)
     local c = randomChoice(captains)
     if cap.nickname and math.random() < 0.25 then
     if c.n and math.random() < 0.25 then
         return string.format("Captain %s \"%s\" %s", cap.first, cap.nickname, cap.last)
         return string.format('Captain %s "%s" %s', c.f, c.n, c.l)
    else
        return string.format("Captain %s %s", cap.first, cap.last)
     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 = {'Cargo', 'Military', 'Ritual', 'Privateer'}
     local vesselTypes = {"Cargo","Military","Ritual","Privateer"}
     local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'}
     local cargoTypes = {"Agricultural","Mining/Manufacturing","Services"}
     local errorTypes = {
     local errorTypes = {
         "Cargo Mislabeling",
         "Cargo Mislabeling","Improper Documentation",
        "Improper Documentation",
         "Surveillance Anomaly","Inspection Failure",
         "Surveillance Anomaly",
        "Inspection Failure",
         "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


    local ships = {}
         if vtype=="Ritual" then
    for i = 1, math.random(50, 80) do
             displayType = "Ritual – "..randomChoice(ritualCults)
        local hour = math.random(0, 23)
            company    = string.match(displayType, "%–%s*(.+)$")
        local minute = math.random(0, 59)
         elseif vtype=="Military" then
        local timeValue = hour * 60 + minute
             displayType = "Military – "..randomChoice(militaryDivisions)
        local cargo = randomChoice(cargoTypes)
            company    = string.match(displayType, "%–%s*(.+)$")
        local vesselType = randomChoice(vesselTypes)
         elseif vtype=="Privateer" then
        local displayType = vesselType
             displayType = "Privateer – "..getPrivateerCaptain()
         if vesselType == "Ritual" then
            company    = displayType  -- show full Captain text
             displayType = "Ritual - " .. randomChoice(ritualCults)
        else
         elseif vesselType == "Military" then
            displayType = "Cargo"
             displayType = "Military - " .. randomChoice(militaryDivisions)
            company    = getCompanyForCargo(ctype)
         elseif vesselType == "Privateer" then
             displayType = "Privateer - " .. getRandomPrivateerName()
         end
         end
         ships[#ships+1] = {
 
             date = dateStr,
         table.insert(ships, {
             time = string.format("%02d:%02d", hour, minute),
             date       = dateStr,
             sort = timeValue,
             time       = string.format("%02d:%02d",h,m),
             vessel_id = "VM-" .. tostring(math.random(10000, 99999)),
             sort       = tval,
             home_city = "[[File:VaeringheimFlag.png|20px]] Vaeringheim",
             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 = cargo,
             teus       = math.random(100,1000),
            company = getCompanyForCargo(vesselType, cargo),
             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 output = "{| class=\"wikitable sortable\"\n! Date !! Time (Arrival) !! Vessel ID !! Home City !! Type !! Company !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"
    -- build wikitext
     for _, ship in ipairs(ships) do
     local out = '{| class="wikitable sortable"\n' ..
         output = output .. string.format("\n|-\n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
        '! Date !! Time !! Vessel ID !! Home City !! Type !! Company !! Berth !! TEUs !! Tonnage !! Cargo Type !! Queue Time !! Turnaround Time !! Error'
             ship.date, ship.time, ship.vessel_id, ship.home_city, ship.type, ship.company,
     for _,s in ipairs(ships) do
             ship.berth, ship.teus, ship.tonnage, ship.cargo_type, ship.queue, ship.turnaround)
         out = out .. string.format(
         if ship.error ~= "None" then
            '\n|-\n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s',
             output = output .. string.format(" || style=\"background-color:#fdd;\" | %s", ship.error)
             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
             output = output .. string.format(" || %s", ship.error)
             out = out .. ' || None'
         end
         end
     end
     end
 
     out = out .. '\n|}\n\n' ..
     output = output .. "\n|}"
        "'''Error Key:'''<br>" ..
    output = output .. [[
        "* '''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 output
end
end


function p.dailyReport()
function p.dailyReport()
     local year, day = p.getCurrentDate()
     local y,d = p.getCurrentDate()
     local header = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''\n", day, year)
     local hdr = string.format(
     return header .. p.generateShipTable()
      "'''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