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) Current PSSC date
-- 1) Date logic
function p.getCurrentDate()
function p.getCurrentDate()
     local start = os.time{year=1999,month=8,day=6}
     local startDate = os.time{year=1999, month=8, day=6}
     local now  = os.time()
     local secs, daysecs = os.time() - startDate, 86400
     local secPerDay, daysPerYear = 86400, 183
     local daysPerYear = 183
     local elapsed = math.floor((now - start) / secPerDay)
     local totalDays = math.floor(secs/ daysecs)
     local yearFrac = elapsed / daysPerYear
     local year = math.floor(totalDays / daysPerYear)
    local y = math.floor(yearFrac)
     local day = (totalDays % daysPerYear) + 1
     local d = math.floor((yearFrac - y) * daysPerYear) + 1
     return year, day
     return y, d
end
end


-- 2) Random helper
-- 2) Helpers
local function randomChoice(t)
local function randomChoice(t) return t[math.random(#t)] end
    return t[math.random(#t)]
end


-- 3) Home‐port cities & flags
-- 3) Fixed data sets
local cities = {
local cities = {
     Vaeringheim    = "[[File:VaeringheimFlag.png|20px]] Vaeringheim",
     "Vaeringheim","Somniumpolis","Delphica","Ephyra","Norsolyra",
     Somniumpolis   = "[[File:SomniumpolisFlag.png|20px]] Somniumpolis",
     "Skýrophos","Riddersborg","Ardclach","Jogi","Sufriya",
     Delphica       = "[[File:DelphicaFlag.png|20px]] Delphica",
    "Keybir-Aviv","Aegirheim","Bjornopolis"
     Ephyra         = "[[File:EphyraFlag.png|20px]] Ephyra",
}
     Norsolyra       = "[[File:NorsolyraFlag.png|20px]] Norsolyra",
local cityFlags = {
     Skyrophos      = "[[File:SkyrophosFlag.png|20px]] Skyrophos",
    Vaeringheim="[[File:VaeringheimFlag.png|20px]] Vaeringheim",
     Riddersborg     = "[[File:RiddersborgFlag.png|20px]] Riddersborg",
     Somniumpolis="[[File:SomniumpolisFlag.png|20px]] Somniumpolis",
     Ardclach       = "[[File:ArdclachFlag.png|20px]] Ardclach",
     Delphica="[[File:DelphicaFlag.png|20px]] Delphica",
     Jogi           = "[[File:JogiFlag.png|20px]] Jogi",
     Ephyra="[[File:EphyraFlag.png|20px]] Ephyra",
     Sufriya         = "[[File:SufriyaFlag.png|20px]] Sufriya",
     Norsolyra="[[File:NorsolyraFlag.png|20px]] Norsolyra",
     ["Keybir-Aviv"] = "[[File:KeybirAvivFlag.png|20px]] Keybir-Aviv",
     ["Skýrophos"]="[[File:SkyrophosFlag.png|20px]] Skýrophos",
     Aegirheim       = "[[File:AegirheimFlag.png|20px]] Aegirheim",
     Riddersborg="[[File:RiddersborgFlag.png|20px]] Riddersborg",
     Bjornopolis     = "[[File:BjornopolisFlag.png|20px]] Bjornopolis"
     Ardclach="[[File:ArdclachFlag.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",
}
}


-- 4) Owner/Operator pools
local vesselTypes    = { "Cargo", "Military", "Ritual", "Privateer" }
local ritualCults = {
local cargoTypes      = { "Agricultural", "Mining/Manufacturing", "Services", "Unspecified" }
  "Ordo Solis Invicti","Order of Aurora Mystica","Harmony Sanctum","Ignis Aeternum",
local ritualCults     = {
  "Celestial Harmony Sect","Guild of Golden Shadows","Azure Sentinel Sect","Reverie Nebulous",
    "Ordo Solis Invicti","Order of Aurora Mystica","Harmony Sanctum","Ignis Aeternum",
  "Eon Fellowship","Order of the Umbral Oracle","Mystery of the Verdant Embrace","Conclave Illuminara",
    "Celestial Harmony Sect","Guild of Golden Shadows","Azure Sentinel Sect","Reverie Nebulous",
  "Sanctum Vitalis","Temple Alabaster","Court of the Ironclad","Accord Concordia",
    "Eon Fellowship","Order of the Umbral Oracle","Mystery of the Verdant Embrace","Conclave Illuminara",
  "Mystery of the Stygian Veil","Sylvan Fellowship","Mystery of Red Mirth","Rex Catonis",
    "Sanctum Vitalis","Temple Alabaster","Court of the Ironclad","Accord Concordia",
  "Sanctum Delphica","Ordo Amicitia","Temple Illuminata"
    "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 militaryDivs = {
local privateerCaptains = {
   "Alpazkigz Division","Odiferia Division","Vaeringheim Division","Haifa Division",
    {first="Talvios", last="Karnis",    nick="Erebektos"},
   "Jeseri Division","Hatch Ministry Division","New South Jangsong Division","Haifan Bassaridia Division"
    {first="Mirek",  last="Davros",    nick="Zammarion"},
    {first="Ilion",  last="Quoros"},
    {first="Sevon",   last="Halek",     nick="Thamuthis"},
    {first="Caldris", last="Onir",     nick="Votharion"},
    {first="Loras",   last="Tarnok"},
    {first="Vaelen", last="Koros"},
    {first="Daskos", last="Meyron",    nick="Orontion"},
    {first="Kyric",  last="Fenros",    nick="Mekharsan"},
    {first="Omir",    last="Thalos"},
    {first="Baryon",  last="Syrek",    nick="Satharkon"},
    {first="Orien",  last="Damar"},
    {first="Tharkos", last="Nyros",    nick="Vathmenos"},
    {first="Halion",  last="Trevik"},
    {first="Kelvir",  last="Raan",      nick="Nabarrion"},
    {first="Lethan",  last="Kohr"},
    {first="Zarik",  last="Tharn"},
    {first="Varas",  last="Jorik",    nick="Tharnukhet"},
    {first="Yasrek",  last="Tymon"},
    {first="Aethon",  last="Morvek",    nick="Vathromen"},
    {first="Crivos",  last="Elyen"},
    {first="Saran",  last="Valic"},
    {first="Drevos",  last="Helkan",    nick="Khamsuron"},
    {first="Nyros",  last="Qalor"},
    {first="Talen",  last="Vorric",    nick="Valkhoret"}
}
}
local function randCaptain()
  local caps = {
    {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 c = randomChoice(caps)
  if c.n and math.random()<0.25 then
    return ("Captain %s \"%s\" %s"):format(c.f,c.n,c.l)
  else
    return ("Captain %s %s"):format(c.f,c.l)
  end
end


-- 5) Cargo‐company lists
-- 4) master product lists
local agriProducts = {
local agriProducts = {
  "Rice","Edible Algae","Shrimp","Anterran Spicy Onion","Queen's Garlic",
    "Rice — Gladeseed Farmers' Union",
  "Morovian Water Buffalo","Morovian Water Buffalo Beef",
    "Edible Algae — Gladeseed Farmers' Union",
  "Unprocessed Noctic-Rabrev Flower","Processed Noctic Rabrev Flower","Noctic-Rabrev Flower Concentrate",
    "Shrimp — Gladeseed Farmers' Union",
  "Unprocessed Noctic-Rabrev Leaf","Processed Noctic-Rabrev Leaf",
    "Anterran Spicy Onion — Gladeseed Farmers' Union",
  "Unprocessed Noctic-Rabrev Leaf Concentrate","Processed Noctic-Rabrev Leaf Concentrate",
    "Queen's Garlic — Gladeseed Farmers' Union",
  "Manwine","Milkwine","Zoe Elm Resin (Unrefined)","Zoe Elm Resin (Refined)",
    "Morovian Water Buffalo — Atterian Cattle Drivers",
  "Sea Elm Flavored Mead","Wheat","Oats","Cereal","Hay",
    "Morovian Water Buffalo Beef — Atterian Cattle Drivers",
  "Ale of the Night","Camels","Camel Meat","Camel Milk","Camel Hump Water","Camel Hump Water Tea",
    "Unprocessed Noctic-Rabrev Flower — Noctic Fleet",
  "Pearls","Abalone","Opium","Hash","Mead","Cinammon",
    "Processed Noctic Rabrev Flower — Noctic Fleet",
  "Velvet Worm Meat","Velvet Worm Eggs","Silk","Horehound Mead","Horehound Beer",
    "Noctic-Rabrev Flower Concentrate — Noctic Fleet",
  "Sea Cow Beef","Atterian Armored Pufferfish","Morovian Saucer Eyed Giant Eel","Amina Crab",
    "Unprocessed Noctic-Rabrev Leaf — Noctic Fleet",
  "Mugwort Oil","Ground Mugwort","Mugwort Tincture","Blood Infused Red Wine",
    "Processed Noctic-Rabrev Leaf — Noctic Fleet",
  "Wisp Rice","Giid-Lisea-Eda","Giid-Lisea-Eda Beef","Vaeringheim Turkey Meat",
    "Unprocessed Noctic-Rabrev Leaf Concentrate — Noctic Fleet",
  "Salurian Swamp Quail Eggs","Giant Fanged Penguin Blubber","Giant Fanged Penguin Blubber Oil Extract",
    "Processed Noctic-Rabrev Leaf Concentrate — Noctic Fleet",
  "Coffee"
    "Manwine — Jogiani Merchants of Manwine",
    "Milkwine — Jogiani Merchants of Manwine",
    "Zoe Elm Resin (Unrefined) — Keepers of the Grove of Zoe Elm",
    "Zoe Elm Resin (Refined) — Keepers of the Grove of Zoe Elm",
    "Sea Elm Flavored Mead — Sea-Elm Southern Meadery",
    "Wheat — Plains of Jogi",
    "Oats — Plains of Jogi",
    "Cereal — Plains of Jogi",
    "Hay — Plains of Jogi",
    "Ale of the Night — Ale of the Night Central Brewery",
    "Camels — Camel Herders of the Jangsong Province",
    "Camel Meat — Camel Herders of the Jangsong Province",
    "Camel Milk — Camel Herders of the Jangsong Province",
    "Camel Hump Water — Camel Herders of the Jangsong Province",
    "Camel Hump Water Tea — Camel Herders of the Jangsong Province",
    "Pearls — Anterran Imports and Services",
    "Abalone — Anterran Imports and Services",
    "Opium — Merchant Guild of the Poppy Goddess",
    "Hash — Merchant Guild of the Poppy Goddess",
    "Mead — Grand Cave Bee Meadery",
    "Cinammon — Cinammon Plains of Roue",
    "Velvet Worm Meat — The Velvet Company",
    "Velvet Worm Eggs — The Velvet Company",
    "Silk — Seamstresses of Rouge",
    "Horehound Mead — Salurian Temple of Sacred Horehound",
    "Horehound Beer — Salurian Temple of Sacred Horehound",
    "Sea Cow Beef — Bulhanu Ranchers' Association",
    "Atterian Armored Pufferfish — Suncliff Fisheries",
    "Morovian Saucer Eyed Giant Eel — Suncliff Fisheries",
    "Amina Crab — Suncliff Fisheries",
    "Mugwort Oil — Ministers of Mistress Mugwort",
    "Ground Mugwort — Ministers of Mistress Mugwort",
    "Mugwort Tincture — Ministers of Mistress Mugwort",
    "Blood InfusedRed Wine — Blood Vineyards of the Far North",
    "Wisp Rice — Norsolyrian Wisp Rice Farmers Association",
    "Giid-Lisea-Eda — Giid Lisea Ranching Import Company",
    "Giid-Lisea-Eda Beef — Giid Lisea Ranching Import Company",
    "Vaeringheim Turkey Meat — Bird Keepers of Saluria",
    "Salurian Swamp Quail Eggs — Bird Keepers of Saluria",
    "Giant Fanged Penguin Blubber — Hunters of the Giant Fanged Penguin",
    "Giant Fanged Penguin Blubber Oil Extract — Hunters of the Giant Fanged Penguin",
    "Coffee — Aminian Coffee Company"
}
}
local mineProducts = {
local miningProducts = {
  "Purple Granite","Iron","Steel","Concrete","Coal","Diamonds","Timber",
    "Purple Granite — Thalassian Temples Granite Export Cooperative",
  "Mens' Boots","Womens' Boots","Garganram Sign Plains Fertilizer",
    "Iron — East Keltian Iron Company",
  "Gold Necklaces","Gold Rings","Gold Bracelets","Gold Earrings",
    "Steel — East Keltian Iron Company",
  "Robes","Dresses","Tarnkappes","Coats","Perfume","Cologne","Incense","Candles"
    "Concrete — East Keltian Iron Company",
    "Coal — Mylecian Coal Ports",
    "Diamonds — Merchants of the Valley of Diamonds",
    "Timber — East Keltian Timber Company",
    "Men’s Boots — Onceanic Boot Company",
    "Women’s Boots — Onceanic Boot Company",
    "Garganram Sign Plains Fertilizer — Commune of the Garganid Apostles",
    "Gold Necklaces — Shï Collective",
    "Gold Rings — Shï Collective",
    "Gold Bracelets — Shï Collective",
    "Gold Earrings — Shï Collective",
    "Robes — Order of the Sphinx",
    "Dresses — Order of the Sphinx",
    "Tarnkappes — Order of the Sphinx",
    "Coats — Order of the Sphinx",
    "Perfume — Market Hanavusu",
    "Cologne — Market Hanavusu",
    "Incense — Market Hanavusu",
    "Candles — Market Hanavusu"
}
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) Choose operator and inventory
-- 5) Pick a random privateer name
local function getOperator(vt)
local function getRandomPrivateer()
     if vt=="Ritual"    then return randomChoice(ritualCults) end
     local c= randomChoice(privateerCaptains)
     if vt=="Military"  then return randomChoice(militaryDivs) end
     if c.nick and math.random()<0.25 then
    if vt=="Privateer" then return randCaptain() end
        return string.format("Captain %s “%s” %s",c.first,c.nick,c.last)
     return nil
     else
end
        return string.format("Captain %s %s",c.first,c.last)
local function getOperatorOrCargoCo(vt,ct)
     end
    local op = getOperator(vt)
     if op then return op end
    -- cargo operators were baked into company lists before; here we just show the cargo pool
    return "Independent Consortium"
end
end


local function getInventoryHtml(ct)
-- 6) Attach Owner/Operator
     if ct=="Agricultural" then
local function getOwner(vtype, cargotype)
        -- pick 3–5 random distinct products
     if vtype=="Ritual"   then return randomChoice(ritualCults) end
        local pick,used = {},{}
    if vtype=="Military"  then return randomChoice(militaryDivs) end
        for _=1,math.random(3,5) do
    if vtype=="Privateer" then return getRandomPrivateer() end
            local p
    -- Cargo
            repeat p = randomChoice(agriProducts) until not used[p]
    if cargotype=="Agricultural" then return randomChoice(serviceCompanies) end
            used[p]=true; pick[#pick+1]=p
    if cargotype=="Agricultural" then return "Gladeseed Farmers' Union" end
        end
     if cargotype=="Mining/Manufacturing" then
        local html = "<ul>"
         return randomChoice{ "Baratar Corporation","Roving Wind Farm Corporation",
        for _,i in ipairs(pick) do html = html.."<li>"..i.."</li>" end
            "Thalassian Temples Granite Export Cooperative","East Keltian Iron Company",
        return html.."</ul>"
             "Mylecian Coal Ports","Merchants of the Valley of Diamonds",
     elseif ct=="Mining/Manufacturing" then
             "East Keltian Timber Company","Onceanic Boot Company","Commune of the Garganid Apostles",
         local pick,used = {},{}
            "Shï Collective","Order of the Sphinx","Market Hanavusu","Somniant Stock Fund" }
        for _=1,math.random(3,5) do
             local p
             repeat p = randomChoice(mineProducts) until not used[p]
            used[p]=true; pick[#pick+1]=p
        end
        local html = "<ul>"
        for _,i in ipairs(pick) do html = html.."<li>"..i.."</li>" end
        return html.."</ul>"
    else
        return ""
     end
     end
    if cargotype=="Services" then return randomChoice(serviceCompanies) end
    return "Independent Consortium"
end
end


-- 7) Main table generation
-- 7) Build the table
function p.generateShipTable()
function p.generateShipTable()
    local vesselTypes = {'Cargo','Military','Ritual','Privateer'}
    local cargoCats    = {'Agricultural','Mining/Manufacturing','Services'}
    local allCats      = {'Agricultural','Mining/Manufacturing','Services','Unspecified'}
    local errorTypes  = {
      "Cargo Mislabeling","Improper Documentation",
      "Surveillance Anomaly","Inspection Failure","Unregistered Ritual Cargo"
    }
    -- collect city keys
    local cityKeys = {}
    for k in pairs(cities) do cityKeys[#cityKeys+1]=k end
    -- seed & date
    local y,d = p.getCurrentDate()
    local dateStr = ("Day %d, Y.%d"):format(d,y)
    -- build ships
     local ships = {}
     local ships = {}
     for i=1,math.random(50,80) do
     for i=1,math.random(50,80) do
         local h,m = math.random(0,23), math.random(0,59)
         local hr, mn = math.random(0,23), math.random(0,59)
         local vt = randomChoice(vesselTypes)
        local t = hr*60+mn
         local ct = (vt=="Cargo") and randomChoice(cargoCats) or randomChoice(allCats)
         local vt= randomChoice(vesselTypes)
         ships[#ships+1] = {
         local ct= randomChoice(cargoTypes)
             date = dateStr,
        local prodList={}
             time = ("%02d:%02d"):format(h,m),
        if ct=="Agricultural" then
             sort = h*60 + m,
            for _=1,math.random(1,3) do
             id  = "VM-"..math.random(10000,99999),
                prodList[#prodList+1]=randomChoice(agriProducts)
             home = cities[randomChoice(cityKeys)],
            end
             type = vt,
        elseif ct=="Mining/Manufacturing" then
             op  = getOperatorOrCargoCo(vt,ct),
            for _=1,math.random(1,3) do
             berth= math.random(1,124),
                prodList[#prodList+1]=randomChoice(miningProducts)
             teus = math.random(100,1000),
            end
             tonnage = ("%.2f"):format(math.random()*19000+1000),
        end
            cat  = ct,
         ships[#ships+1]={
            inv  = getInventoryHtml(ct),
             date       = string.format("Day %d, Y.%d",p.getCurrentDate()),
             queue     = ("%.2f"):format(math.random()*5.5+0.5),
             time       = string.format("%02d:%02d",hr,mn),
             turnaround= ("%.2f"):format(math.random()*32+4),
             sort       = t,
             err = (math.random()<0.2) and randomChoice(errorTypes) or "None"
             vid        = "VM-"..math.random(10000,99999),
             home       = cityFlags[randomChoice(cities)],
             type       = vt,
             owner      = getOwner(vt,ct),
            cargotype  = ct,
            products    = prodList,
             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      = (math.random()<0.2 and randomChoice{
                "Cargo Mislabeling","Improper Documentation",
                "Surveillance Anomaly","Inspection Failure",
                "Unregistered Ritual Cargo"
            }) 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 out = {
 
        '{| class="wikitable sortable"',
    -- assemble wikitext
         '! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type !! Products !! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
     local out = "{| class=\"wikitable sortable\"\n" ..
    }
         "! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Berth !! TEUs !! Tonnage !! Cargo Type !! Queue (hrs) !! Turnaround (hrs) !! Error"
     for _,s in ipairs(ships) do
     for _,s in ipairs(ships) do
        -- cargo cell with embedded inventory
         local prodCell = "#N/A"
         local cargoCell = s.cat .. s.inv
         if #s.products>0 then
        out = out .. ("\n|- \n| %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s")
            prodCell = "<ul>"
          :format(s.date, s.time, s.id, s.home, s.type, s.op,
             for _,p in ipairs(s.products) do prodCell=prodCell.."<li>"..p.."</li>" end
                  s.berth, s.teus, s.tonnage, cargoCell, s.queue, s.turnaround)
             prodCell = prodCell.."</ul>"
         if s.err ~= "None" then
             out = out .. (" || style=\"background-color:#fdd;\" | %s"):format(s.err)
        else
             out = out .. " || None"
         end
         end
        out[#out+1] = string.format(
            "|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
            s.date,s.time,s.vid,s.home,s.type,s.owner,s.cargotype,
            prodCell,s.berth,s.teus,s.tonnage,s.queue,s.turnaround,s.error
        )
     end
     end
     out = out .. "\n|}\n\n'''Error Key:'''\n" ..
     out[#out+1] = "|}\n\n'''Error Key:'''"
        "* '''Cargo Mislabeling:''' Mismatch between manifest and actual goods\n" ..
    out[#out+1] = "* '''Cargo Mislabeling:''' Manifest ≠ actual goods"
        "* '''Improper Documentation:''' Missing or outdated transit papers\n" ..
    out[#out+1] = "* '''Improper Documentation:''' Missing/outdated papers"
        "* '''Surveillance Anomaly:''' Unexpected heat or movement signature\n" ..
    out[#out+1] = "* '''Surveillance Anomaly:''' Odd heat/motion signature"
        "* '''Inspection Failure:''' Failed customs or hatch review\n" ..
    out[#out+1] = "* '''Inspection Failure:''' Customs/hatch failure"
        "* '''Unregistered Ritual Cargo:''' Religious items not pre-cleared by the Temple Bank\n"
    out[#out+1] = "* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank"
     return out
     return table.concat(out,"\n")
end
end


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


return p
return p

Revision as of 02:02, 24 April 2025

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

-- Module:GeneralPortDailyLog
local p = {}

-- 1) Date logic
function p.getCurrentDate()
    local startDate = os.time{year=1999, month=8, day=6}
    local secs, daysecs = os.time() - startDate, 86400
    local daysPerYear = 183
    local totalDays = math.floor(secs/ daysecs)
    local year = math.floor(totalDays / daysPerYear)
    local day = (totalDays % daysPerYear) + 1
    return year, day
end

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

-- 3) Fixed data sets
local cities = {
    "Vaeringheim","Somniumpolis","Delphica","Ephyra","Norsolyra",
    "Skýrophos","Riddersborg","Ardclach","Jogi","Sufriya",
    "Keybir-Aviv","Aegirheim","Bjornopolis"
}
local cityFlags = {
    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:RiddersborgFlag.png|20px]] Riddersborg",
    Ardclach="[[File:ArdclachFlag.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",
}

local vesselTypes     = { "Cargo", "Military", "Ritual", "Privateer" }
local cargoTypes      = { "Agricultural", "Mining/Manufacturing", "Services", "Unspecified" }
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 privateerCaptains = {
    {first="Talvios", last="Karnis",    nick="Erebektos"},
    {first="Mirek",   last="Davros",    nick="Zammarion"},
    {first="Ilion",   last="Quoros"},
    {first="Sevon",   last="Halek",     nick="Thamuthis"},
    {first="Caldris", last="Onir",      nick="Votharion"},
    {first="Loras",   last="Tarnok"},
    {first="Vaelen",  last="Koros"},
    {first="Daskos",  last="Meyron",    nick="Orontion"},
    {first="Kyric",   last="Fenros",    nick="Mekharsan"},
    {first="Omir",    last="Thalos"},
    {first="Baryon",  last="Syrek",     nick="Satharkon"},
    {first="Orien",   last="Damar"},
    {first="Tharkos", last="Nyros",     nick="Vathmenos"},
    {first="Halion",  last="Trevik"},
    {first="Kelvir",  last="Raan",      nick="Nabarrion"},
    {first="Lethan",  last="Kohr"},
    {first="Zarik",   last="Tharn"},
    {first="Varas",   last="Jorik",     nick="Tharnukhet"},
    {first="Yasrek",  last="Tymon"},
    {first="Aethon",  last="Morvek",    nick="Vathromen"},
    {first="Crivos",  last="Elyen"},
    {first="Saran",   last="Valic"},
    {first="Drevos",  last="Helkan",    nick="Khamsuron"},
    {first="Nyros",   last="Qalor"},
    {first="Talen",   last="Vorric",    nick="Valkhoret"}
}

-- 4) master product lists
local agriProducts = {
    "Rice — Gladeseed Farmers' Union",
    "Edible Algae — Gladeseed Farmers' Union",
    "Shrimp — Gladeseed Farmers' Union",
    "Anterran Spicy Onion — Gladeseed Farmers' Union",
    "Queen's Garlic — Gladeseed Farmers' Union",
    "Morovian Water Buffalo — Atterian Cattle Drivers",
    "Morovian Water Buffalo Beef — Atterian Cattle Drivers",
    "Unprocessed Noctic-Rabrev Flower — Noctic Fleet",
    "Processed Noctic Rabrev Flower — Noctic Fleet",
    "Noctic-Rabrev Flower Concentrate — Noctic Fleet",
    "Unprocessed Noctic-Rabrev Leaf — Noctic Fleet",
    "Processed Noctic-Rabrev Leaf — Noctic Fleet",
    "Unprocessed Noctic-Rabrev Leaf Concentrate — Noctic Fleet",
    "Processed Noctic-Rabrev Leaf Concentrate — Noctic Fleet",
    "Manwine — Jogiani Merchants of Manwine",
    "Milkwine — Jogiani Merchants of Manwine",
    "Zoe Elm Resin (Unrefined) — Keepers of the Grove of Zoe Elm",
    "Zoe Elm Resin (Refined) — Keepers of the Grove of Zoe Elm",
    "Sea Elm Flavored Mead — Sea-Elm Southern Meadery",
    "Wheat — Plains of Jogi",
    "Oats — Plains of Jogi",
    "Cereal — Plains of Jogi",
    "Hay — Plains of Jogi",
    "Ale of the Night — Ale of the Night Central Brewery",
    "Camels — Camel Herders of the Jangsong Province",
    "Camel Meat — Camel Herders of the Jangsong Province",
    "Camel Milk — Camel Herders of the Jangsong Province",
    "Camel Hump Water — Camel Herders of the Jangsong Province",
    "Camel Hump Water Tea — Camel Herders of the Jangsong Province",
    "Pearls — Anterran Imports and Services",
    "Abalone — Anterran Imports and Services",
    "Opium — Merchant Guild of the Poppy Goddess",
    "Hash — Merchant Guild of the Poppy Goddess",
    "Mead — Grand Cave Bee Meadery",
    "Cinammon — Cinammon Plains of Roue",
    "Velvet Worm Meat — The Velvet Company",
    "Velvet Worm Eggs — The Velvet Company",
    "Silk — Seamstresses of Rouge",
    "Horehound Mead — Salurian Temple of Sacred Horehound",
    "Horehound Beer — Salurian Temple of Sacred Horehound",
    "Sea Cow Beef — Bulhanu Ranchers' Association",
    "Atterian Armored Pufferfish — Suncliff Fisheries",
    "Morovian Saucer Eyed Giant Eel — Suncliff Fisheries",
    "Amina Crab — Suncliff Fisheries",
    "Mugwort Oil — Ministers of Mistress Mugwort",
    "Ground Mugwort — Ministers of Mistress Mugwort",
    "Mugwort Tincture — Ministers of Mistress Mugwort",
    "Blood InfusedRed Wine — Blood Vineyards of the Far North",
    "Wisp Rice — Norsolyrian Wisp Rice Farmers Association",
    "Giid-Lisea-Eda — Giid Lisea Ranching Import Company",
    "Giid-Lisea-Eda Beef — Giid Lisea Ranching Import Company",
    "Vaeringheim Turkey Meat — Bird Keepers of Saluria",
    "Salurian Swamp Quail Eggs — Bird Keepers of Saluria",
    "Giant Fanged Penguin Blubber — Hunters of the Giant Fanged Penguin",
    "Giant Fanged Penguin Blubber Oil Extract — Hunters of the Giant Fanged Penguin",
    "Coffee — Aminian Coffee Company"
}
local miningProducts = {
    "Purple Granite — Thalassian Temples Granite Export Cooperative",
    "Iron — East Keltian Iron Company",
    "Steel — East Keltian Iron Company",
    "Concrete — East Keltian Iron Company",
    "Coal — Mylecian Coal Ports",
    "Diamonds — Merchants of the Valley of Diamonds",
    "Timber — East Keltian Timber Company",
    "Men’s Boots — Onceanic Boot Company",
    "Women’s Boots — Onceanic Boot Company",
    "Garganram Sign Plains Fertilizer — Commune of the Garganid Apostles",
    "Gold Necklaces — Shï Collective",
    "Gold Rings — Shï Collective",
    "Gold Bracelets — Shï Collective",
    "Gold Earrings — Shï Collective",
    "Robes — Order of the Sphinx",
    "Dresses — Order of the Sphinx",
    "Tarnkappes — Order of the Sphinx",
    "Coats — Order of the Sphinx",
    "Perfume — Market Hanavusu",
    "Cologne — Market Hanavusu",
    "Incense — Market Hanavusu",
    "Candles — Market Hanavusu"
}
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"
}

-- 5) Pick a random privateer name
local function getRandomPrivateer()
    local c= randomChoice(privateerCaptains)
    if c.nick and math.random()<0.25 then
        return string.format("Captain %s “%s” %s",c.first,c.nick,c.last)
    else
        return string.format("Captain %s %s",c.first,c.last)
    end
end

-- 6) Attach Owner/Operator
local function getOwner(vtype, cargotype)
    if vtype=="Ritual"    then return randomChoice(ritualCults) end
    if vtype=="Military"  then return randomChoice(militaryDivs) end
    if vtype=="Privateer" then return getRandomPrivateer() end
    -- Cargo
    if cargotype=="Agricultural" then return randomChoice(serviceCompanies) end
    if cargotype=="Agricultural" then return "Gladeseed Farmers' Union" end
    if cargotype=="Mining/Manufacturing" then
        return randomChoice{ "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" }
    end
    if cargotype=="Services" then return randomChoice(serviceCompanies) end
    return "Independent Consortium"
end

-- 7) Build the table
function p.generateShipTable()
    local ships = {}
    for i=1,math.random(50,80) do
        local hr, mn = math.random(0,23), math.random(0,59)
        local t = hr*60+mn
        local vt= randomChoice(vesselTypes)
        local ct= randomChoice(cargoTypes)
        local prodList={}
        if ct=="Agricultural" then
            for _=1,math.random(1,3) do
                prodList[#prodList+1]=randomChoice(agriProducts)
            end
        elseif ct=="Mining/Manufacturing" then
            for _=1,math.random(1,3) do
                prodList[#prodList+1]=randomChoice(miningProducts)
            end
        end
        ships[#ships+1]={
            date        = string.format("Day %d, Y.%d",p.getCurrentDate()),
            time        = string.format("%02d:%02d",hr,mn),
            sort        = t,
            vid         = "VM-"..math.random(10000,99999),
            home        = cityFlags[randomChoice(cities)],
            type        = vt,
            owner       = getOwner(vt,ct),
            cargotype   = ct,
            products    = prodList,
            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       = (math.random()<0.2 and randomChoice{
                "Cargo Mislabeling","Improper Documentation",
                "Surveillance Anomaly","Inspection Failure",
                "Unregistered Ritual Cargo"
            }) or "None"
        }
    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 !! Products !! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
    }
    for _,s in ipairs(ships) do
        local prodCell = "#N/A"
        if #s.products>0 then
            prodCell = "<ul>"
            for _,p in ipairs(s.products) do prodCell=prodCell.."<li>"..p.."</li>" end
            prodCell = prodCell.."</ul>"
        end
        out[#out+1] = string.format(
            "|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
            s.date,s.time,s.vid,s.home,s.type,s.owner,s.cargotype,
            prodCell,s.berth,s.teus,s.tonnage,s.queue,s.turnaround,s.error
        )
    end
    out[#out+1] = "|}\n\n'''Error Key:'''"
    out[#out+1] = "* '''Cargo Mislabeling:''' Manifest ≠ actual goods"
    out[#out+1] = "* '''Improper Documentation:''' Missing/outdated papers"
    out[#out+1] = "* '''Surveillance Anomaly:''' Odd heat/motion signature"
    out[#out+1] = "* '''Inspection Failure:''' Customs/hatch failure"
    out[#out+1] = "* '''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'''","\n"
    )..p.generateShipTable()
end

return p