Module:GeneralPortOperations

From MicrasWiki
Revision as of 15:30, 23 April 2025 by NewZimiaGov (talk | contribs) (Created page with "-- Module:GeneralPortDailyLog local p = {} -- Date generation logic 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((...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

-- Module:GeneralPortDailyLog
local p = {}

-- Date generation logic
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

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

-- Generate simulated ship operations
function p.generateShipOperations()
    local vesselTypes = {'Cargo', 'Military', 'Ritual', 'Privateer'}
    local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'}
    local output = "" .. "\n== Ship Operations ==\n"

    for i = 1, 10 do
        local vessel = string.format("* Vessel %d (%s): Berth %d, Cargo: %d TEUs, %.2f tons (%s), Queue: %.2f hrs, Turnaround: %.2f hrs",
            1000 + i,
            randomChoice(vesselTypes),
            math.random(1, 124),
            math.random(100, 1000),
            math.random(1000, 20000),
            randomChoice(cargoTypes),
            math.random() * 6,
            math.random() * 36)
        output = output .. vessel .. "\n"
    end
    return output
end

-- Energy simulation
function p.generateEnergySystems()
    local wind = math.random(50, 200)
    local fusion = 600
    local geo = math.random(100, 200)
    local demand = math.random(700, 1000)
    local surplus = wind + fusion + geo - demand
    return string.format("\n== Energy Systems ==\n* Wind Farms: %d MW\n* Fusion: %d MW\n* Geothermal: %d MW\n* Demand: %d MW\n* Surplus/Deficit: %+d MW",
        wind, fusion, geo, demand, surplus)
end

-- Customs simulation
function p.generateCustoms()
    local cargoTypes = {'Agricultural', 'Mining/Manufacturing', 'Services'}
    local output = "\n== Customs & Financial Oversight ==\n"
    for _, c in ipairs(cargoTypes) do
        output = output .. string.format("* %s clearance time: %.2f hrs\n", c, math.random() * 3 + 1)
    end
    output = output .. string.format("* Inspections today: %d\n* Face-alteration approvals: %d\n* Ritual blessings: %d\n",
        math.random(3, 10), math.random(2, 8), math.random(1, 6))
    return output
end

-- Security simulation
function p.generateSecurity()
    local output = "\n== Security & Surveillance ==\n"
    output = output .. string.format("* Hatch Ministry Patrols: %d\n* Naval Exercises: %s\n",
        math.random(2, 6), tostring(math.random() > 0.5))
    local threats = {"None", "Pirate Suspect", "Smuggling", "Unauthorized Entry"}
    output = output .. string.format("* Threats Detected: %s, %s, %s\n",
        randomChoice(threats), randomChoice(threats), randomChoice(threats))
    return output
end

-- Market simulation
function p.generateMarket()
    local output = "\n== Economic Activity ==\n"
    output = output .. string.format("* Redemption Volume: %.2f Poli\n* Price Index Change: %.2f%%\n",
        math.random() * 40000 + 10000, (math.random() * 6 - 3))
    return output
end

-- Personnel simulation
function p.generatePersonnel()
    return string.format("\n== Labor Force ==\n* Dockhands: %d\n* Inspectors: %d\n* Cultic Agents: %d\n* Disruptions: %s\n",
        math.random(300, 500), math.random(50, 100), math.random(10, 30), randomChoice({'None', 'Minor Strike', 'Ceremony Delay'}))
end

-- Environment simulation
function p.generateEnvironment()
    return string.format("\n== Environmental Conditions ==\n* Weather: %s\n* Hazard: %s\n",
        randomChoice({'Clear', 'Rain', 'Fog', 'Storm'}), randomChoice({'None', 'Toxic Bloom', 'Contaminant Spill'}))
end

-- Main report
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.generateShipOperations()
        .. p.generateEnergySystems()
        .. p.generateCustoms()
        .. p.generateSecurity()
        .. p.generateMarket()
        .. p.generatePersonnel()
        .. p.generateEnvironment()
end

return p