Module:GeneralPortOperations: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
Undo revision 360019 by NewZimiaGov (talk)
Tag: Undo
NewZimiaGov (talk | contribs)
No edit summary
Line 7: Line 7:
-- 1) Date logic
-- 1) Date logic
function p.getCurrentDate()
function p.getCurrentDate()
     local start  = os.time{ year=1999, month=8, day=6 }
     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    = math.floor(elapsed / 183)
     local year    = math.floor(elapsed / 183)
Line 22: Line 22:
local function randomN(tbl, n)
local function randomN(tbl, n)
     if type(tbl) ~= "table" or n < 1 then return {} end
     if type(tbl) ~= "table" or n < 1 then return {} end
     local copy = { unpack(tbl) }
     local copy, out = {unpack(tbl)}, {}
    local out  = {}
     for i = 1, math.min(n, #copy) do
     for i = 1, math.min(n, #copy) do
         local idx = math.random(#copy)
         local idx = math.random(#copy)
Line 46: Line 45:
     cityFlag[name] = string.format("[[File:%sFlag.png|20px]]", norm)
     cityFlag[name] = string.format("[[File:%sFlag.png|20px]]", norm)
end
end
 
-- override for Skýrophos
-- override for Skýrophos to use the provided SkyrophosFlag.png
cityFlag["Skýrophos"] = "[[File:SkyrophosFlag.png|20px]]"
cityFlag["Skýrophos"] = "[[File:SkyrophosFlag.png|20px]]"


-- 4) Vessel & cargo types
-- 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
-- 5) Owner pools
local ritualCults = {
local ritualCults = {
     "Ordo Solis Invicti","Order of Aurora Mystica","Harmony Sanctum","Ignis Aeternum",
     "Ordo Solis Invicti","Order of Aurora Mystica","Harmony Sanctum",
    "Celestial Harmony Sect","Guild of Golden Shadows","Azure Sentinel Sect","Reverie Nebulous",
    "Ignis Aeternum","Celestial Harmony Sect","Guild of Golden Shadows",
    "Eon Fellowship","Order of the Umbral Oracle","Mystery of the Verdant Embrace","Conclave Illuminara",
    "Azure Sentinel Sect","Reverie Nebulous","Eon Fellowship",
    "Sanctum Vitalis","Temple Alabaster","Court of the Ironclad","Accord Concordia",
    "Order of the Umbral Oracle","Mystery of the Verdant Embrace",
    "Mystery of the Stygian Veil","Sylvan Fellowship","Mystery of Red Mirth","Rex Catonis",
    "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"
     "Sanctum Delphica","Ordo Amicitia","Temple Illuminata"
}
}
local militaryDivs = {
local militaryDivs = {
     "Alpazkigz Division","Odiferia Division","Vaeringheim Division","Haifa Division",
     "Alpazkigz Division","Odiferia Division","Vaeringheim Division",
    "Jeseri Division","Hatch Ministry Division","New South Jangsong Division","Haifan Bassaridia Division"
    "Haifa Division","Jeseri Division","Hatch Ministry Division",
    "New South Jangsong Division","Haifan Bassaridia Division"
}
}
local agriCompanies = {
local agriCompanies = {
     "Gladeseed Farmers' Union","Atterian Cattle Drivers","Noctic Fleet",
     "Gladeseed Farmers' Union","Atterian Cattle Drivers","Noctic Fleet",
     "Jogiani Merchants of Manwine","Keepers of the Grove of Zoe Elm",
     "Jogiani Merchants of Manwine","Keepers of the Grove of Zoe Elm",
     "Plains of Jogi","Ale of the Night Central Brewery","Camel Herders of the Jangsong Province",
     "Plains of Jogi","Ale of the Night Central Brewery",
    "Anterran Imports and Services","Merchant Guild of the Poppy Goddess","Grand Cave Bee Meadery",
    "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",
     "Cinammon Plains of Rouge","The Velvet Company","Seamstresses of Rouge",
     "Salurian Temple of Sacred Horehound","Bulhanu Ranchers' Association","Suncliff Fisheries",
     "Salurian Temple of Sacred Horehound","Bulhanu Ranchers' Association",
    "Ministers of Mistress Mugwort","Blood Vineyards of the Far North",
    "Suncliff Fisheries","Ministers of Mistress Mugwort",
     "Norsolyrian Wisp Rice Farmers Association","Giid-Lisea Ranching Import Company",
    "Blood Vineyards of the Far North",
    "Bird Keepers of Saluria","Hunters of the Giant Fanged Penguin",
     "Norsolyrian Wisp Rice Farmers Association",
    "Knights Castle Reindeer Herders","Lindley Whaling Company","Aminian Coffee Company"
    "Giid-Lisea Ranching Import Company","Bird Keepers of Saluria",
    "Hunters of the Giant Fanged Penguin","Knights Castle Reindeer Herders",
    "Lindley Whaling Company","Aminian Coffee Company"
}
}
local miningCompanies = {
local miningCompanies = {
     "Baratar Corporation","Roving Wind Farm Corporation",
     "Baratar Corporation","Roving Wind Farm Corporation",
     "Thalassian Temple Granite Export Cooperative","East Keltian Iron Company","Mylecian Coal Ports",
     "Thalassian Temple Granite Export Cooperative","East Keltian Iron Company",
    "Merchants of the Valley of Diamonds","East Keltian Timber Company","Onceanic Boot 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",
     "Commune of the Garganid Apostles","Shï Collective","Order of the Sphinx",
     "Market Hanavusu","Somniant Stock Fund"
     "Market Hanavusu","Somniant Stock Fund"
Line 90: Line 95:
     "Maritime Guild of the Cult of Maskmakers","Ergonian Spy Agency",
     "Maritime Guild of the Cult of Maskmakers","Ergonian Spy Agency",
     "Temple Bank of the Reformed Stripping Path","Couriers of the Lizard Queen",
     "Temple Bank of the Reformed Stripping Path","Couriers of the Lizard Queen",
     "Temple University of Delphica","La Sái Ebile","Hellhound Breeders of Dragevik"
     "Temple University of Delphica","La Sái Ebile",
    "Hellhound Breeders of Dragevik"
}
}


-- 6) Company logos mapping
-- 6) Company logos mapping
local companyLogo = {}
local companyLogo = {}
local function addLogo(name,file) companyLogo[name]=file end
local function addLogo(name,file) companyLogo[name] = file end
addLogo("Lake Morovia Blockade Fund","BlockadeFund420.png")
-- ... all your addLogo() calls here ...
addLogo("Gladeseed Farmers' Union","Gladeseed420.png")
addLogo("Atterian Cattle Drivers","Atterian420.png")
addLogo("Noctic Fleet","Noctic420.png")
addLogo("Jogiani Merchants of Manwine","Jogiani420.png")
addLogo("Keepers of the Grove of Zoe Elm","KeepersoftheGrove.png")
addLogo("Plains of Jogi","PlainsofJogi.png")
addLogo("Ale of the Night Central Brewery","AleofNight420.png")
addLogo("Camel Herders of the Jangsong Province","CamelHerders420.png")
addLogo("Thalassian Temple Granite Export Cooperative","ThalassianGranite420.png")
addLogo("East Keltian Iron Company","EKIron420.png")
addLogo("Mylecian Coal Ports","CoalPorts420.png")
addLogo("Merchants of the Valley of Diamonds","ValleyofDiamonds420.png")
addLogo("Baratar Corporation","Baratar420.png")
addLogo("Roving Wind Farm Corporation","RovingWind420.png")
addLogo("Grand Cave Bee Meadery","GrandCave420.png")
addLogo("Merchant Guild of the Poppy Goddess","PoppyGoddess420.png")
addLogo("Cinammon Plains of Rouge","CinammonPlains420.png")
addLogo("The Velvet Company","VelvetHome420.png")
addLogo("Seamstresses of Rouge","Seamstresses420.png")
addLogo("Salurian Temple of Sacred Horehound","SalurianTemple421.png")
addLogo("Bulhanu Ranchers' Association","Bulhanu421.png")
addLogo("Suncliff Fisheries","Suncliff421.png")
addLogo("Ministers of Mistress Mugwort","Mugwort421.png")
addLogo("Blood Vineyards of the Far North","BloodVineyards421.png")
addLogo("Norsolyrian Wisp Rice Farmers Association","Norsolyrian421.png")
addLogo("Giid-Lisea Ranching Import Company","GiidLisea421.png")
addLogo("Bird Keepers of Saluria","SaluriaBK421.png")
addLogo("Knights Castle Reindeer Herders","KnightsCastle421.png")
addLogo("Lindley Whaling Company","LindleyWhalingCompany.png")
addLogo("Aminian Coffee Company","Aminian421.png")
addLogo("Commune of the Garganid Apostles","Garganid421.png")
addLogo("Onceanic Boot Company","OnceanicBoot421.png")
addLogo("Maritime Guild of the Cult of Maskmakers","MaritimeGuild420.png")
addLogo("Ergonian Spy Agency","ErgonianSpy421.png")
addLogo("Temple Bank of the Reformed Stripping Path","TempleBankCrest.png")
addLogo("Couriers of the Lizard Queen","LizardQueen421.png")
addLogo("Temple University of Delphica","TempleUniversity421.png")
addLogo("Shï Collective","ShiCollective421.png")
addLogo("Order of the Sphinx","OrderofSphinx421.png")
addLogo("Market Hanavusu","MarketHanavusu421.png")
addLogo("Somniant Stock Fund","SomniantStockFund.png")
addLogo("Hatch Ministry","HatchMinistry420.png")
addLogo("Anterran Imports and Services","AnterranImports420.png")
addLogo("East Keltian Timber Company","EKTimber420.png")
addLogo("Hellhound Breeders of Dragevik","Dragevik421.png")


-- 7) Privateer helper
-- 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 and c.nick and math.random()<0.25 then
     if c and 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)
     elseif c then
     elseif c then
Line 157: Line 118:
-- 8) Determine Owner/Operator
-- 8) Determine Owner/Operator
local function getOwner(vt, ct)
local function getOwner(vt, ct)
     if     vt=="Ritual"   then return randomChoice(ritualCults)
     if vt == "Ritual" then
     elseif vt=="Military" then return randomChoice(militaryDivs)
        return randomChoice(ritualCults)
     elseif vt=="Privateer" then return getRandomPrivateer()
     elseif vt == "Military" then
     elseif vt=="Cargo"     then
        return randomChoice(militaryDivs)
         if     ct=="Agricultural"         then return randomChoice(agriCompanies)
     elseif vt == "Privateer" then
         elseif ct=="Mining/Manufacturing" then return randomChoice(miningCompanies)
        return getRandomPrivateer()
         elseif ct=="Services"            then return randomChoice(serviceCompanies)
     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
     end
     end
Line 173: Line 140:
     math.randomseed(os.time())
     math.randomseed(os.time())
     local y, d = p.getCurrentDate()
     local y, d = p.getCurrentDate()
    -- pools
     local poolMap = {
     local poolMap = {
         Agricultural         = agriCompanies,
         Agricultural = agriCompanies,
         ["Mining/Manufacturing"] = miningCompanies,
         ["Mining/Manufacturing"] = miningCompanies,
         Services             = serviceCompanies
         Services = serviceCompanies
     }
     }
    local allPools = {}
    for _, list in pairs(poolMap) do
        for _, name in ipairs(list) do
            table.insert(allPools, name)
        end
    end
     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   = getOwner(vt, ct)
         local owner = getOwner(vt, ct) or "Independent Consortium"
         local ownerLogo = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or ""
         local ownerLogo = companyLogo[owner] and ("[[File:" .. companyLogo[owner] .. "|20px]] ") or ""
         local home   = randomChoice(cities)
         local home = randomChoice(cities)


         local count = math.random(3,4)
        -- select companies
         local count = math.random(3, 4)
         local picks = {}
         local picks = {}
         if vt=="Cargo" and ct~="Unspecified" and companyLogo[owner] then
         if ct == "Unspecified" then
             picks = { owner }
             picks = randomN(allPools, count)
            local rest = {}
            for _, nm in ipairs(poolMap[ct] or {}) do
                if nm~=owner then table.insert(rest, nm) end
            end
            for _, nm in ipairs(randomN(rest, count-1)) do table.insert(picks, nm) end
         else
         else
            local flat = {}
             picks = randomN(poolMap[ct] or {}, count)
            for _, list in pairs(poolMap) do
                for _, nm in ipairs(list) do table.insert(flat, nm) end
            end
             picks = randomN(flat, count)
         end
         end


         local compCell = "<ul>"
         local compCell = "<ul>"
         for _, nm in ipairs(picks) do
         for _, nm in ipairs(picks) do
             local logo = companyLogo[nm] and ("[[File:"..companyLogo[nm].."|20px]] ") or ""
             local logo = companyLogo[nm] and ("[[File:" .. companyLogo[nm] .. "|20px]] ") or ""
             compCell = compCell..string.format("<li>%s%s</li>", logo, nm)
             compCell = compCell .. string.format("<li>%s%s</li>", logo, nm)
         end
         end
         compCell = compCell.."</ul>"
         compCell = compCell .. "</ul>"


         local errList = {
         local errList = {
             "Cargo Mislabeling","Improper Documentation","Surveillance Anomaly",
             "Cargo Mislabeling","Improper Documentation",
            "Inspection Failure","Unregistered Ritual Cargo"
            "Surveillance Anomaly","Inspection Failure",
            "Unregistered Ritual Cargo"
         }
         }
         local err = math.random()<0.2 and randomChoice(errList) or "None"
         local err = math.random() < 0.2 and randomChoice(errList) or "None"


         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,
             typ            = vt,
             typ            = vt,
             ownerCell      = ownerLogo..owner,
             ownerCell      = ownerLogo .. owner,
             cargotype      = ct,
             cargotype      = ct,
             cargoCompanies = compCell,
             cargoCompanies = compCell,
             berth          = math.random(1,124),
             berth          = math.random(1, 124),
             teus          = math.random(100,1000),
             teus          = math.random(100, 1000),
             tonnage        = string.format("%.2f",math.random()*19000+1000),
             tonnage        = string.format("%.2f", math.random() * 19000 + 1000),
             queue          = string.format("%.2f",math.random()*5.5+0.5),
             queue          = string.format("%.2f", math.random() * 5.5 + 0.5),
             turnaround    = string.format("%.2f",math.random()*32+4),
             turnaround    = string.format("%.2f", math.random() * 32 + 4),
             error          = err
             error          = err
         })
         })
     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 out = {
     local out = {
Line 244: Line 212:
     }
     }
     for _, s in ipairs(ships) do
     for _, s in ipairs(ships) do
         local row = s.error~="None" and '|- bgcolor="#ffcccc"' or '|-'
         local row = (s.error ~= "None") and '|- bgcolor="#ffcccc"' or '|-'
         table.insert(out, row)
         table.insert(out, row)
         table.insert(out, table.concat({
         table.insert(out, table.concat({

Revision as of 20:25, 24 April 2025

Documentation for this module may be created at Module:GeneralPortOperations/doc

-- Module:GeneralPortDailyLog
local p = {}

-- compatibility shim for unpack
local unpack = table.unpack or unpack

-- 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)
    if type(tbl) ~= "table" or #tbl == 0 then return nil end
    return tbl[math.random(#tbl)]
end

local function randomN(tbl, n)
    if type(tbl) ~= "table" or n < 1 then return {} end
    local copy, out = {unpack(tbl)}, {}
    for i = 1, math.min(n, #copy) do
        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%-’]", "")
        :gsub("[Áá]", "A"):gsub("[Éé]", "E")
        :gsub("[Íí]", "I"):gsub("[Óó]", "O")
        :gsub("[Úú]", "U"):gsub("[Ýý]", "Y")
    cityFlag[name] = string.format("[[File:%sFlag.png|20px]]", norm)
end
-- override for Skýrophos
cityFlag["Skýrophos"] = "[[File:SkyrophosFlag.png|20px]]"

-- 4) Vessel & cargo types
local vesselTypes = {"Cargo","Military","Ritual","Privateer"}
local cargoTypes  = {"Agricultural","Mining/Manufacturing","Services","Unspecified"}

-- 5) Owner pools
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"
}
local agriCompanies = {
    "Gladeseed Farmers' Union","Atterian Cattle Drivers","Noctic Fleet",
    "Jogiani Merchants of Manwine","Keepers of the Grove of Zoe Elm",
    "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","Aminian Coffee Company"
}
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"
}

-- 6) Company logos mapping
local companyLogo = {}
local function addLogo(name,file) companyLogo[name] = file end
-- ... all your addLogo() calls here ...

-- 7) Privateer helper
local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}}
local function getRandomPrivateer()
    local c = randomChoice(privateers)
    if c and c.nick and math.random() < 0.25 then
        return string.format("Captain %s ‘%s’ %s", c.first, c.nick, c.last)
    elseif c then
        return string.format("Captain %s %s", c.first, c.last)
    end
    return "Captain"
end

-- 8) 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

-- 9) Build the table
function p.generateShipTable()
    math.randomseed(os.time())
    local y, d = p.getCurrentDate()

    -- pools
    local poolMap = {
        Agricultural = agriCompanies,
        ["Mining/Manufacturing"] = miningCompanies,
        Services = serviceCompanies
    }
    local allPools = {}
    for _, list in pairs(poolMap) do
        for _, name in ipairs(list) do
            table.insert(allPools, name)
        end
    end

    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) or "Independent Consortium"
        local ownerLogo = companyLogo[owner] and ("[[File:" .. companyLogo[owner] .. "|20px]] ") or ""
        local home = randomChoice(cities)

        -- select companies
        local count = math.random(3, 4)
        local picks = {}
        if ct == "Unspecified" then
            picks = randomN(allPools, count)
        else
            picks = randomN(poolMap[ct] or {}, count)
        end

        local compCell = "<ul>"
        for _, nm in ipairs(picks) do
            local logo = companyLogo[nm] and ("[[File:" .. companyLogo[nm] .. "|20px]] ") or ""
            compCell = compCell .. string.format("<li>%s%s</li>", logo, nm)
        end
        compCell = compCell .. "</ul>"

        local errList = {
            "Cargo Mislabeling","Improper Documentation",
            "Surveillance Anomaly","Inspection Failure",
            "Unregistered Ritual Cargo"
        }
        local err = math.random() < 0.2 and randomChoice(errList) 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)

    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 row = (s.error ~= "None") and '|- bgcolor="#ffcccc"' or '|-'
        table.insert(out, row)
        table.insert(out, table.concat({
            '|', 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
    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