Module:GeneralPortOperations: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
No edit summary
NewZimiaGov (talk | contribs)
Undo revision 359943 by NewZimiaGov (talk)
Tag: Undo
Line 87: Line 87:
     end
     end
end
end
local cities = {
    Vaeringheim = "[[File:VaeringheimFlag.png|20px]] Vaeringheim",
    Somniumpolis = "[[File:SomniumpolisFlag.png|20px]] Somniumpolis",
    Delphica = "[[File:DelphicaFlag.png|20px]] Delphica",
    Ephyra = "[[File:EphyraFlag.png|20px]] Ephyra",
    Norsolyra = "[[File:NorsolyraFlag.png|20px]] Norsolyra",
    ["Skýrophos"] = "[[File:SkyrophosFlag.png|20px]] Skýrophos",
    Riddersborg = "[[File:VaeringheimFlag.png|20px]] Riddersborg",
    Ardclach = "[[File:VaeringheimFlag.png|20px]] Ardclach",
    Jogi = "[[File:JogiFlag.png|20px]] Jogi",
    Sufriya = "[[File:SufriyaFlag.png|20px]] Sufriya",
    ["Keybir-Aviv"] = "[[File:KeybirAvivFlag.png|20px]] Keybir-Aviv",
    Aegirheim = "[[File:AegirheimFlag.png|20px]] Aegirheim",
    Bjornopolis = "[[File:BjornopolisFlag.png|20px]] Bjornopolis"
}


function p.generateShipTable()
function p.generateShipTable()
Line 101: Line 116:
     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 cityNames = {}
    for cityName in pairs(cities) do
        table.insert(cityNames, cityName)
    end


    local num_ships = math.random(50, 80)
     local ships = {}
     local ships = {}
     for i = 1, math.random(50, 80) do
 
     for i = 1, num_ships do
         local hour = math.random(0, 23)
         local hour = math.random(0, 23)
         local minute = math.random(0, 59)
         local minute = math.random(0, 59)
        local arrivalTime = string.format("%02d:%02d", hour, minute)
         local timeValue = hour * 60 + minute
         local timeValue = hour * 60 + minute
        local cargo = randomChoice(cargoTypes)
 
         local vesselType = randomChoice(vesselTypes)
         local vesselType = randomChoice(vesselTypes)
         if vesselType == "Ritual" then
         if vesselType == "Ritual" then
Line 116: Line 138:
             vesselType = "Privateer - " .. getRandomPrivateerName()
             vesselType = "Privateer - " .. getRandomPrivateerName()
         end
         end
         ships[#ships+1] = {
 
         table.insert(ships, {
             date = dateStr,
             date = dateStr,
             time = string.format("%02d:%02d", hour, minute),
             time = arrivalTime,
             sort = timeValue,
             sort = timeValue,
             vessel_id = "VM-" .. tostring(math.random(10000, 99999)),
             vessel_id = "VM-" .. tostring(math.random(10000, 99999)),
             home_city = "[[File:VaeringheimFlag.png|20px]] Vaeringheim",
             home_city = cities[randomChoice(cityNames)],
             type = vesselType,
             type = vesselType,
             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),
             cargo_type = cargo,
             cargo_type = randomChoice(cargoTypes),
            company = getCompanyForCargo(cargo),
             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 = (math.random() < 0.2) and randomChoice(errorTypes) or "None"
             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"
     local output = "{| class=\"wikitable sortable\"\n! Date !! Time (Arrival) !! Vessel ID !! Home City !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"
 
     for _, ship in ipairs(ships) do
     for _, ship in ipairs(ships) do
         output = output .. string.format("\n|-\n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
         local row = string.format("\n| %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
             ship.date, ship.time, ship.vessel_id, ship.home_city, ship.type, ship.company,
             ship.date, ship.time, ship.vessel_id, ship.home_city, ship.type, ship.berth,
             ship.berth, ship.teus, ship.tonnage, ship.cargo_type, ship.queue, ship.turnaround)
             ship.teus, ship.tonnage, ship.cargo_type, ship.queue, ship.turnaround)
 
         if ship.error ~= "None" then
         if ship.error ~= "None" then
             output = output .. string.format(" || style=\"background-color:#fdd;\" | %s", ship.error)
             output = output .. string.format("\n|- style=\"background-color:#fdd;\"%s || %s", row, ship.error)
         else
         else
             output = output .. string.format(" || %s", ship.error)
             output = output .. string.format("\n|-%s || %s", row, ship.error)
         end
         end
     end
     end


     output = output .. "\n|}"
     output = output .. "\n|}"
    output = output .. [[


'''Error Key:'''
    output = output .. "\n\n'''Error Key:'''\n"
* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods
    output = output .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
* '''Improper Documentation:''' Missing or outdated transit papers
    output = output .. "* '''Improper Documentation:''' Missing or outdated transit papers\n"
* '''Surveillance Anomaly:''' Unexpected heat or movement signature
    output = output .. "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n"
* '''Inspection Failure:''' Failed customs or hatch review
    output = output .. "* '''Inspection Failure:''' Failed customs or hatch review\n"
* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank
    output = output .. "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n"
]]
 
     return output
     return output
end
end

Revision as of 01:15, 24 April 2025

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

-- Module:GeneralPortDailyLog
local p = {}

function p.getCurrentDate()
    local startDate = os.time({year = 1999, month = 8, day = 6})
    local secondsInDay = 86400
    local daysPerYear = 183
    local currentDate = os.time()
    local totalDaysElapsed = math.floor((currentDate - startDate) / secondsInDay)
    local yearFraction = totalDaysElapsed / daysPerYear
    local psscYear = math.floor(yearFraction)
    local dayOfYear = math.floor((yearFraction - psscYear) * daysPerYear) + 1
    return psscYear, dayOfYear
end

local function randomChoice(t)
    return t[math.random(#t)]
end

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 militaryDivisions = {
    "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", "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 function getCompanyForCargo(cargoType)
    if cargoType == "Agricultural" then
        return randomChoice(agriCompanies)
    else
        return "Independent Consortium"
    end
end

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

local function getRandomPrivateerName()
    local cap = randomChoice(privateerCaptains)
    if cap.nickname and math.random() < 0.25 then
        return string.format("Captain %s \"%s\" %s", cap.first, cap.nickname, cap.last)
    else
        return string.format("Captain %s %s", cap.first, cap.last)
    end
end
local cities = {
    Vaeringheim = "[[File:VaeringheimFlag.png|20px]] Vaeringheim",
    Somniumpolis = "[[File:SomniumpolisFlag.png|20px]] Somniumpolis",
    Delphica = "[[File:DelphicaFlag.png|20px]] Delphica",
    Ephyra = "[[File:EphyraFlag.png|20px]] Ephyra",
    Norsolyra = "[[File:NorsolyraFlag.png|20px]] Norsolyra",
    ["Skýrophos"] = "[[File:SkyrophosFlag.png|20px]] Skýrophos",
    Riddersborg = "[[File:VaeringheimFlag.png|20px]] Riddersborg",
    Ardclach = "[[File:VaeringheimFlag.png|20px]] Ardclach",
    Jogi = "[[File:JogiFlag.png|20px]] Jogi",
    Sufriya = "[[File:SufriyaFlag.png|20px]] Sufriya",
    ["Keybir-Aviv"] = "[[File:KeybirAvivFlag.png|20px]] Keybir-Aviv",
    Aegirheim = "[[File:AegirheimFlag.png|20px]] Aegirheim",
    Bjornopolis = "[[File:BjornopolisFlag.png|20px]] Bjornopolis"
}

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 cityNames = {}
    for cityName in pairs(cities) do
        table.insert(cityNames, cityName)
    end

    local num_ships = math.random(50, 80)
    local ships = {}

    for i = 1, num_ships do
        local hour = math.random(0, 23)
        local minute = math.random(0, 59)
        local arrivalTime = string.format("%02d:%02d", hour, minute)
        local timeValue = hour * 60 + minute

        local vesselType = randomChoice(vesselTypes)
        if vesselType == "Ritual" then
            vesselType = "Ritual - " .. randomChoice(ritualCults)
        elseif vesselType == "Military" then
            vesselType = "Military - " .. randomChoice(militaryDivisions)
        elseif vesselType == "Privateer" then
            vesselType = "Privateer - " .. getRandomPrivateerName()
        end

        table.insert(ships, {
            date = dateStr,
            time = arrivalTime,
            sort = timeValue,
            vessel_id = "VM-" .. tostring(math.random(10000, 99999)),
            home_city = cities[randomChoice(cityNames)],
            type = vesselType,
            berth = math.random(1, 124),
            teus = math.random(100, 1000),
            tonnage = string.format("%.2f", math.random() * 19000 + 1000),
            cargo_type = randomChoice(cargoTypes),
            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)

    local output = "{| class=\"wikitable sortable\"\n! Date !! Time (Arrival) !! Vessel ID !! Home City !! Type !! Berth !! TEUs !! Tonnage (tons) !! Cargo Type !! Queue Time (hrs) !! Turnaround Time (hrs) !! Error Type"

    for _, ship in ipairs(ships) do
        local row = string.format("\n| %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
            ship.date, ship.time, ship.vessel_id, ship.home_city, ship.type, ship.berth,
            ship.teus, ship.tonnage, ship.cargo_type, ship.queue, ship.turnaround)

        if ship.error ~= "None" then
            output = output .. string.format("\n|- style=\"background-color:#fdd;\"%s || %s", row, ship.error)
        else
            output = output .. string.format("\n|-%s || %s", row, ship.error)
        end
    end

    output = output .. "\n|}"

    output = output .. "\n\n'''Error Key:'''\n"
    output = output .. "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n"
    output = output .. "* '''Improper Documentation:''' Missing or outdated transit papers\n"
    output = output .. "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n"
    output = output .. "* '''Inspection Failure:''' Failed customs or hatch review\n"
    output = output .. "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n"

    return output
end

function p.dailyReport()
    local year, day = p.getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateShipTable()
end

return p