Module:GeneralPortSecurityLog

From MicrasWiki
Jump to navigationJump to search

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

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 choice utility
local function randomChoice(t)
    return t[math.random(#t)]
end

-- Security log generation
function p.generateSecurityLog()
    local year, day = p.getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)

    local patrolRotations = math.random(3, 8)
    local navalEvent = randomChoice({
        "None",
        "Live-Fire Exercise",
        "Sonar Calibration Run",
        "Emergency Recall: Cultic Violation",
        "Naval Formation Drill"
    })
    local surveillanceStatus = randomChoice({
        "Standard Sweep",
        "Heightened Alert",
        "Grid Lockdown – Suspicious Contact",
        "Night Watch Routine"
    })

    local threats = {}
    for _ = 1, math.random(0, 3) do
        table.insert(threats, randomChoice({
            "Suspected Pirate Vessel",
            "Cargo Smuggler Identified",
            "Illicit Ritual Materials Detected",
            "Unknown Submersible"
        }))
    end

    local interdictions = math.random(0, 4)
    local reinspections = math.random(0, 6)

    local restrictedEntries = {}
    for _ = 1, math.random(1, 5) do
        table.insert(restrictedEntries,
            string.format("%s vessel granted access to high-security zone",
            randomChoice({"Naval", "Cultic"}))
        )
    end

    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Security Operations Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''Hatch Ministry Patrol Rotations''' || %d\n", patrolRotations)
    log = log .. "|-\n"
    log = log .. string.format("| '''Naval Activity''' || %s\n", navalEvent)
    log = log .. "|-\n"
    log = log .. string.format("| '''Surveillance Grid Status''' || %s\n", surveillanceStatus)
    log = log .. "|-\n"
    log = log .. string.format("| '''Detected Threats''' || %s\n", (#threats > 0 and table.concat(threats, ", ") or "None"))
    log = log .. "|-\n"
    log = log .. string.format("| '''Interdictions Conducted''' || %d\n", interdictions)
    log = log .. "|-\n"
    log = log .. string.format("| '''Customs Reinspections''' || %d\n", reinspections)
    log = log .. "|-\n"
    log = log .. string.format("| '''Restricted Zone Access''' || <ul><li>%s</li></ul>\n", table.concat(restrictedEntries, "</li><li>"))
    log = log .. "|}"

    return log
end

-- Display full daily security summary
function p.dailySecuritySummary()
    local year, day = p.getCurrentDate()
    local header = string.format("'''General Port of Lake Morovia: Security Log – Day %d, Year %d PSSC'''\n", day, year)
    return header .. p.generateSecurityLog()
end

return p