Module:GeneralPortLabor

From MicrasWiki
Revision as of 22:59, 23 April 2025 by NewZimiaGov (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:GeneralPortLabor/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 utility
local function randomChoice(t)
    return t[math.random(#t)]
end

-- Generate the labor log
function p.generateLaborLog()
    local year, day = p.getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)

    local dockhands = math.random(300, 500)
    local inspectors = math.random(40, 80)
    local culticAgents = math.random(10, 30)

    local hiring = math.random(0, 25)
    local layoffs = math.random(0, 15)
    local employmentChange = hiring - layoffs
    local employmentSummary = string.format("%+d workers (%d hired, %d laid off)", employmentChange, hiring, layoffs)

    local disruptions = randomChoice({
        "None", "Minor Strike", "Major Strike",
        "Cult Ceremony", "Equipment Malfunction", "Political Protest"
    })

    local companies = {
        "Lake Morovia Blockade Fund", "Gladeseed Farmers' Union", "Atterian Cattle Drivers Company",
        "Roving Wind Farm Corporation", "Baratar Corporation", "Noctic Fleet", "Keepers of the Bloodbaths of Laprind",
        "Jogiani Merchants of Manwine", "Keepers of the Grove of Zoe Elm", "Plains of Jogi", "Ale of the Night Central Brewery",
        "Camel Herders of the Jangsong Province", "Thalassian Temple Granite Export Cooperative", "East Keltian Iron Company",
        "Mylecian Coal Ports", "Merchants of the Valley of Diamonds", "Maritime Guild of the Cult of Maskmakers",
        "Hatch Ministry", "Anterran Imports and Services", "East Keltian Timber Company", "Grand Cave Bee Meadery",
        "Merchant Guild of the Poppy Goddess", "Cinnamon Plains of Rouge", "Velvet Homestead", "Seamstresses of Rouge",
        "Ergonian Spy Agency", "Commune of the Garganid Apostles", "Oceanic Boot Company",
        "Temple Bank of the Reformed Stripping Path", "Salurian Temple of Sacred Horehound", "Couriers of the Lizard Queen",
        "Temple University of Delphica", "Shï Collective", "Bulhanu Ranchers' Association", "Suncliff Fisheries",
        "Order of the Sphinx", "Ministers of Mistress Mugwort", "Blood Vineyards of the Far North",
        "Norsolyrian Wisp Rice Farmers Association", "La Sái Ebile", "Market Hanavusu",
        "Giid-Lisea Ranching Import Company", "Bird Keepers of Saluria", "Trans-Morovian Railway Company",
        "Hunters of the Giant Fanged Penguin", "Hellhound Breeders of Dragevik", "Somniant Stock Fund",
        "Aminian Coffee Company", "Knights Castle Reindeer Herders", "Lindley Whaling Company",
        "Copper Mines of Southern Jogi"
    }

    local rotations = {}
    for _ = 1, math.random(4, 6) do
        local companyFrom = randomChoice(companies)
        local companyTo = randomChoice(companies)
        while companyFrom == companyTo do
            companyTo = randomChoice(companies)
        end
        table.insert(rotations, string.format("Shifted labor from %s to %s", companyFrom, companyTo))
    end

    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Labor Activity Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''Dockhands Scheduled''' || %d\n", dockhands)
    log = log .. "|-\n"
    log = log .. string.format("| '''Inspectors on Duty''' || %d\n", inspectors)
    log = log .. "|-\n"
    log = log .. string.format("| '''Cultic Agents Active''' || %d\n", culticAgents)
    log = log .. "|-\n"
    log = log .. string.format("| '''Employment Summary''' || %s\n", employmentSummary)
    log = log .. "|-\n"
    log = log .. string.format("| '''Disruptions Noted''' || %s\n", disruptions)
    log = log .. "|-\n"
    log = log .. string.format("| '''Labor Rotations''' || <ul><li>%s</li></ul>\n", table.concat(rotations, "</li><li>"))
    log = log .. "|}"

    return log
end

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

return p