Module:GeneralPortMarketLog: Difference between revisions

From MicrasWiki
Jump to navigationJump to search
NewZimiaGov (talk | contribs)
Created page with "-- Module:GeneralPortMarketLog local p = {} local function getCurrentDate() local startDate = os.time({year = 1999, month = 8, day = 6}) local currentDate = os.time() local daysPerYear = 183 local totalDaysElapsed = math.floor((currentDate - startDate) / 86400) local year = math.floor(totalDaysElapsed / daysPerYear) local day = (totalDaysElapsed % daysPerYear) + 1 return year, day end local function randomChoice(t) return t[math.random(#..."
 
NewZimiaGov (talk | contribs)
No edit summary
Line 14: Line 14:
local function randomChoice(t)
local function randomChoice(t)
     return t[math.random(#t)]
     return t[math.random(#t)]
end
-- Extract market sentiment from the Vaeringheim regional investor
local function getMarketInfluence()
    local date = os.date("*t")
    local dailySeed = date.year * 1000 + date.yday
    math.randomseed(dailySeed)
    local trend = math.random(1, 100)
    if trend >= 75 then
        return "strong_positive"
    elseif trend >= 50 then
        return "moderate_positive"
    elseif trend >= 25 then
        return "moderate_negative"
    else
        return "strong_negative"
    end
end
end


Line 20: Line 38:
     local dateStr = string.format("Day %d, Y.%d", day, year)
     local dateStr = string.format("Day %d, Y.%d", day, year)


     local stipendRedemption = math.random(10000, 50000)
     local influence = getMarketInfluence()
     local commodityVolume = math.random(1000, 5000)
    local priceShift, redemptionShift, volumeShift = 0, 0, 0
     local priceChange = math.random(-3, 3)
 
    if influence == "strong_positive" then
        priceShift = math.random(2, 4)
        redemptionShift = 20000
        volumeShift = 1500
    elseif influence == "moderate_positive" then
        priceShift = math.random(1, 2)
        redemptionShift = 10000
        volumeShift = 1000
    elseif influence == "moderate_negative" then
        priceShift = -math.random(1, 2)
        redemptionShift = -10000
        volumeShift = -1000
    else -- strong_negative
        priceShift = -math.random(2, 4)
        redemptionShift = -20000
        volumeShift = -1500
    end
 
     local stipendRedemption = math.random(25000, 40000) + redemptionShift
     local commodityVolume = math.random(3000, 4000) + volumeShift
    local priceChange = priceShift


     local regionalReports = {
     local regionalReports = {

Revision as of 22:19, 23 April 2025

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

-- Module:GeneralPortMarketLog
local p = {}

local function getCurrentDate()
    local startDate = os.time({year = 1999, month = 8, day = 6})
    local currentDate = os.time()
    local daysPerYear = 183
    local totalDaysElapsed = math.floor((currentDate - startDate) / 86400)
    local year = math.floor(totalDaysElapsed / daysPerYear)
    local day = (totalDaysElapsed % daysPerYear) + 1
    return year, day
end

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

-- Extract market sentiment from the Vaeringheim regional investor
local function getMarketInfluence()
    local date = os.date("*t")
    local dailySeed = date.year * 1000 + date.yday
    math.randomseed(dailySeed)

    local trend = math.random(1, 100)
    if trend >= 75 then
        return "strong_positive"
    elseif trend >= 50 then
        return "moderate_positive"
    elseif trend >= 25 then
        return "moderate_negative"
    else
        return "strong_negative"
    end
end

function p.generateMarketLog()
    local year, day = getCurrentDate()
    local dateStr = string.format("Day %d, Y.%d", day, year)

    local influence = getMarketInfluence()
    local priceShift, redemptionShift, volumeShift = 0, 0, 0

    if influence == "strong_positive" then
        priceShift = math.random(2, 4)
        redemptionShift = 20000
        volumeShift = 1500
    elseif influence == "moderate_positive" then
        priceShift = math.random(1, 2)
        redemptionShift = 10000
        volumeShift = 1000
    elseif influence == "moderate_negative" then
        priceShift = -math.random(1, 2)
        redemptionShift = -10000
        volumeShift = -1000
    else -- strong_negative
        priceShift = -math.random(2, 4)
        redemptionShift = -20000
        volumeShift = -1500
    end

    local stipendRedemption = math.random(25000, 40000) + redemptionShift
    local commodityVolume = math.random(3000, 4000) + volumeShift
    local priceChange = priceShift

    local regionalReports = {
        "Vaeringheim Regional Investor signals stable growth.",
        "Somniumpolis reports surge in logistics volume.",
        "Delphica trade volumes trending downward slightly.",
        "Keybir-Aviv reports spike in demand for security equipment.",
        "Ephyra surplus noted in cold storage capacity."
    }
    local regionalReport = randomChoice(regionalReports)

    local stockInflows = math.random(2000, 8000)
    local stockOutflows = math.random(2000, 8000)
    local netFlow = stockInflows - stockOutflows
    local tradeStatus = netFlow > 0 and "Surplus" or "Shortage"

    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 exports = {}
    local imports = {}
    for _ = 1, 10 do
        table.insert(exports, randomChoice(companies))
        table.insert(imports, randomChoice(companies))
    end

    local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
    log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Market Activity Log (%s)\n", dateStr)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stipend Vouchers Redeemed''' || %d Poli\n", stipendRedemption)
    log = log .. "|-\n"
    log = log .. string.format("| '''Commodity Redemption Volume''' || %d tons\n", commodityVolume)
    log = log .. "|-\n"
    log = log .. string.format("| '''Pricing Index Change''' || %+d%%\n", priceChange)
    log = log .. "|-\n"
    log = log .. string.format("| '''Regional Investor Report''' || %s\n", regionalReport)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Inflows''' || %d tons\n", stockInflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Stock Outflows''' || %d tons\n", stockOutflows)
    log = log .. "|-\n"
    log = log .. string.format("| '''Net Trade Flow''' || %s (%+d tons)\n", tradeStatus, netFlow)
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Exporters''' || <ol><li>%s</li></ol>\n", table.concat(exports, "</li><li>"))
    log = log .. "|-\n"
    log = log .. string.format("| '''Top 10 Importers''' || <ol><li>%s</li></ol>\n", table.concat(imports, "</li><li>"))
    log = log .. "|}"

    return log
end

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

return p