Module:GeneralPortOperations: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
Undo revision 359978 by NewZimiaGov (talk)
Tag: Undo
NewZimiaGov (talk | contribs)
No edit summary
Line 4: Line 4:
-- 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)
     local day   = (elapsed % 183) + 1
     local day     = (elapsed % 183) + 1
     return year, day
     return year, day
end
end
Line 52: Line 52:


-- 6) Company pools
-- 6) Company pools
local agriCompanies = {
local agriCompanies = { -- agricultural cargo owners
     "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",
Line 66: Line 66:
     "Lindley Whaling Company","Aminian Coffee Company"
     "Lindley Whaling Company","Aminian Coffee Company"
}
}
local miningCompanies = {
local miningCompanies = { -- mining/manufacturing cargo owners
     "Baratar Corporation","Roving Wind Farm Corporation",
     "Baratar Corporation","Roving Wind Farm Corporation",
     "Thalassian Temple Granite Export Cooperative","East Keltian Iron Company",
     "Thalassian Temple Granite Export Cooperative","East Keltian Iron Company",
Line 74: Line 74:
     "Market Hanavusu","Somniant Stock Fund"
     "Market Hanavusu","Somniant Stock Fund"
}
}
local serviceCompanies = {
local serviceCompanies = { -- services cargo owners
     "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",
     "Maritime Guild of the Cult of Maskmakers","Ergonian Spy Agency",
Line 82: Line 82:


-- 7) Logos per company
-- 7) Logos per company
local companyLogo = {}
local companyLogo = {}
local function addLogo(name,file) companyLogo[name]=file end
local function addLogo(name,file) companyLogo[name] = file end
-- (Add all logos exactly as before; omitted here for brevity)
-- (Add your addLogo calls here exactly as before)


-- 8) Product lists
-- 8) Product lists
local agriProducts = { -- “Name — Company”
local agriProducts = {
   "Rice — Gladeseed Farmers' Union","Edible Algae — Gladeseed Farmers' Union",
   "Rice — Gladeseed Farmers' Union","Edible Algae — Gladeseed Farmers' Union",
   -- ...etc (as before)
   -- etc
   "Coffee — Aminian Coffee Company"
   "Coffee — Aminian Coffee Company"
}
}
local miningProducts = {
local miningProducts = {
   "Purple Granite — Thalassian Temple Granite Export Cooperative","Iron — East Keltian Iron Company",
   "Purple Granite — Thalassian Temple Granite Export Cooperative","Iron — East Keltian Iron Company",
   -- ...etc (as before)
   -- etc
   "Candles — Market Hanavusu"
   "Candles — Market Hanavusu"
}
}


-- 9) Privateer captains
-- 9) Privateer captains helper
local privateers = {
local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}}
  {first="Talvios",last="Karnis",nick="Erebektos"},
  -- ...etc
}
local function getRandomPrivateer()
local function getRandomPrivateer()
  local c=randomChoice(privateers)
    local c = randomChoice(privateers)
  if c.nick and math.random()<0.25 then
    if 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)
  else
    else
    return string.format("Captain %s %s",c.first,c.last)
        return string.format("Captain %s %s",c.first,c.last)
  end
    end
end
end


-- 10) Determine Owner/Operator
-- 10) Determine Owner/Operator
local function getOwner(vt,ct)
local function getOwner(vt,ct)
  if     vt=="Ritual"    then return randomChoice(ritualCults)
    if vt == "Ritual"    then return randomChoice(ritualCults)
  elseif vt=="Military"  then return randomChoice(militaryDivs)
    elseif vt == "Military"  then return randomChoice(militaryDivs)
  elseif vt=="Privateer" then return getRandomPrivateer()
    elseif vt == "Privateer" then return getRandomPrivateer()
  elseif vt=="Cargo"    then
    elseif vt == "Cargo"    then
    if     ct=="Agricultural"        then return randomChoice(agriCompanies)
        if ct == "Agricultural"        then return randomChoice(agriCompanies)
    elseif ct=="Mining/Manufacturing" then return randomChoice(miningCompanies)
        elseif ct == "Mining/Manufacturing" then return randomChoice(miningCompanies)
    elseif ct=="Services"            then return randomChoice(serviceCompanies)
        elseif ct == "Services"            then return randomChoice(serviceCompanies)
        end
     end
     end
  end
    return "Independent Consortium"
  return "Independent Consortium"
end
end


-- 11) Build the table
-- 11) Build the ship table
function p.generateShipTable()
function p.generateShipTable()
  math.randomseed(os.time())
    math.randomseed(os.time())
  local y,d = p.getCurrentDate()
    local y,d = p.getCurrentDate()
  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=randomChoice(vesselTypes)
        local vt, ct = randomChoice(vesselTypes), randomChoice(cargoTypes)
    local ct=randomChoice(cargoTypes)
        local prods = {}
    local prods={}
        if ct == "Agricultural" then
            for _=1,math.random(1,3) do table.insert(prods, randomChoice(agriProducts)) end
        elseif ct == "Mining/Manufacturing" then
            for _=1,math.random(1,3) do table.insert(prods, randomChoice(miningProducts)) end
        end


    -- ** Now list products for ANY ship if ct is Agricultural or Mining **
        local owner = getOwner(vt,ct)
    if    ct=="Agricultural"         then
        local logo  = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or ""
       for _=1,math.random(1,3) do
        local home  = randomChoice(cities)
        table.insert(prods, randomChoice(agriProducts))
 
       end
        table.insert(ships, {
    elseif ct=="Mining/Manufacturing" then
            date      = string.format("Day %d, Y.%d", d, y),
      for _=1,math.random(1,3) do
            time      = string.format("%02d:%02d", hr, mn),
        table.insert(prods, randomChoice(miningProducts))
            sort       = hr*60+mn,
      end
            vid        = "VM-"..math.random(10000,99999),
            home      = cityFlag[home].." "..home,
            typ        = vt,
            ownerCell  = logo..owner,
            cargotype  = ct,
            products  = prods,
            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


     local owner = getOwner(vt,ct)
     table.sort(ships, function(a,b) return a.sort < b.sort end)
    local logo  = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or ""
    local home  = randomChoice(cities)


     table.insert(ships,{
     local out = {
      date      =string.format("Day %d, Y.%d",d,y),
        '{| class="wikitable sortable"',
      time      =string.format("%02d:%02d",hr,mn),
        '! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type !! Products !! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
      sort      =hr*60+mn,
     }
      vid        ="VM-"..math.random(10000,99999),
      home      =cityFlag[home].." "..home,
      typ        =vt,
      ownerCell  =logo..owner,
      cargotype  =ct,
      products  =prods,
      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)
    for _,s in ipairs(ships) do
 
        local prodCell = "#N/A"
  local out = {
        if #s.products > 0 then
    '{| class="wikitable sortable"',
            prodCell = "<ul>"
    '! Date !! Time !! Vessel ID !! Home City !! Type !! Owner/Operator !! Cargo Type !! Products !! Berth !! TEUs !! Tonnage (t) !! Queue (hrs) !! Turnaround (hrs) !! Error'
            for _,pr in ipairs(s.products) do
  }
                local name,comp = pr:match("^(.-) %— (.+)$")
                if comp and companyLogo[comp] then
                    prodCell = prodCell .. string.format(
                        "<li>[[File:%s|20px]] %s — %s</li>",
                        companyLogo[comp], name, comp
                    )
                else
                    prodCell = prodCell .. "<li>"..pr.."</li>"
                end
            end
            prodCell = prodCell .. "</ul>"
        end


  for _,s in ipairs(ships) do
        table.insert(out, string.format([[
    local prodCell = "#N/A"
|-
    if #s.products>0 then
| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s
      prodCell = "<ul>"
]],
      for _,pr in ipairs(s.products) do
             s.date, s.time, s.vid, s.home, s.typ,
        local name,comp = pr:match("^(.-) %— (.+)$")
            s.ownerCell, s.cargotype, prodCell,
        if comp and companyLogo[comp] then
            s.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error
          prodCell = prodCell..string.format(
         ))
            "<li>[[File:%s|20px]] %s — %s</li>",
             companyLogo[comp], name, comp
          )
        else
          prodCell = prodCell.."<li>"..pr.."</li>"
         end
      end
      prodCell = prodCell.."</ul>"
     end
     end


     table.insert(out, string.format(
     table.insert(out, "|}\n\n'''Error Key:'''" )
      "|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s",
    table.insert(out, "* '''Cargo Mislabeling:''' Manifest ≠ actual goods")
      s.date,s.time,s.vid,s.home,s.typ,
    table.insert(out, "* '''Improper Documentation:''' Missing or outdated papers")
      s.ownerCell,s.cargotype,prodCell,
    table.insert(out, "* '''Surveillance Anomaly:''' Unexpected heat/motion")
      s.berth,s.teus,s.tonnage,s.queue,s.turnaround,s.error
    table.insert(out, "* '''Inspection Failure:''' Customs/hatch failure")
    ))
    table.insert(out, "* '''Unregistered Ritual Cargo:''' Not pre-cleared by Temple Bank")
  end
 
  table.insert(out,"|}\n\n'''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")
    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 = string.format(
    local hdr = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y)
    "'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y
    return hdr .. "\n" .. p.generateShipTable()
  )
  return hdr.."\n"..p.generateShipTable()
end
end


return p
return p

Revision as of 02:40, 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 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 helper
local function randomChoice(t) return t[math.random(#t)] end

-- 3) City list + flags
local cities = {
    "Vaeringheim","Somniumpolis","Delphica","Ephyra","Norsolyra",
    "Skýrophos","Riddersborg","Ardclach","Jogi","Sufriya",
    "Keybir-Aviv","Aegirheim","Bjornopolis","Luminaria","Serena",
    "Lunalis Sancta","Sylvapolis","Symphonara","Aurelia","Ferrum Citadel",
    "Catonis Atrium","Pyralis","Nexa","Acheron","Saluria","Erythros",
    "Aetherium","Koinonía","Aureum","Odiferia","Odiferian Tribes",
    "Hafaan","Jeseri","New South Jangsong Division","Hatch Ministry Division",
    "Alpazkigz Division","Haifan Bassaridia Division","Thorsalon",
    "Pelagia","Myrene","Thyrea","Halicarn","Tel-Amin","Diamandis",
    "Lewisburg","Thermosalem","Akróstadium","Lykopolis"
}
local cityFlag = {}
for _,c in ipairs(cities) do
    local norm = c:gsub("[%s%-’]",""):gsub("ó","o"):gsub("í","i"):gsub("á","a")
    cityFlag[c] = string.format("[[File:%sFlag.png|20px]]", norm)
end

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

-- 5) Ritual cults & military divisions
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"
}

-- 6) Company pools
local agriCompanies = { -- agricultural cargo owners
    "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 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 = { -- mining/manufacturing cargo owners
    "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 = { -- services cargo owners
    "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"
}

-- 7) Logos per company
local companyLogo = {}
local function addLogo(name,file) companyLogo[name] = file end
-- (Add your addLogo calls here exactly as before)

-- 8) Product lists
local agriProducts = {
  "Rice — Gladeseed Farmers' Union","Edible Algae — Gladeseed Farmers' Union",
  -- etc
  "Coffee — Aminian Coffee Company"
}
local miningProducts = {
  "Purple Granite — Thalassian Temple Granite Export Cooperative","Iron — East Keltian Iron Company",
  -- etc
  "Candles — Market Hanavusu"
}

-- 9) Privateer captains helper
local privateers = {{first="Talvios",last="Karnis",nick="Erebektos"}}
local function getRandomPrivateer()
    local c = randomChoice(privateers)
    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

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

-- 11) Build the ship table
function p.generateShipTable()
    math.randomseed(os.time())
    local y,d = p.getCurrentDate()
    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 prods = {}
        if ct == "Agricultural" then
            for _=1,math.random(1,3) do table.insert(prods, randomChoice(agriProducts)) end
        elseif ct == "Mining/Manufacturing" then
            for _=1,math.random(1,3) do table.insert(prods, randomChoice(miningProducts)) end
        end

        local owner = getOwner(vt,ct)
        local logo  = companyLogo[owner] and ("[[File:"..companyLogo[owner].."|20px]] ") or ""
        local home  = randomChoice(cities)

        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  = logo..owner,
            cargotype  = ct,
            products   = prods,
            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 _,pr in ipairs(s.products) do
                local name,comp = pr:match("^(.-) %— (.+)$")
                if comp and companyLogo[comp] then
                    prodCell = prodCell .. string.format(
                        "<li>[[File:%s|20px]] %s — %s</li>",
                        companyLogo[comp], name, comp
                    )
                else
                    prodCell = prodCell .. "<li>"..pr.."</li>"
                end
            end
            prodCell = prodCell .. "</ul>"
        end

        table.insert(out, string.format([[
|-
| %s || %s || %s || %s || %s || %s || %s || %s || %d || %d || %s || %s || %s || %s
]],
            s.date, s.time, s.vid, s.home, s.typ,
            s.ownerCell, s.cargotype, prodCell,
            s.berth, s.teus, s.tonnage, s.queue, s.turnaround, s.error
        ))
    end

    table.insert(out, "|}\n\n'''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()
    local hdr = string.format("'''General Port of Lake Morovia: Operational Log – Day %d, Year %d PSSC'''", d, y)
    return hdr .. "\n" .. p.generateShipTable()
end

return p