Module:GeneralPortOperations

From MicrasWiki
Revision as of 01:29, 24 April 2025 by NewZimiaGov (talk | contribs)
Jump to navigationJump to search

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