Module:GeneralPortMarketLog

From MicrasWiki
Revision as of 06:19, 26 April 2025 by NewZimiaGov (talk | contribs)
Jump to navigationJump to search

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

-- Module:GeneralPortMarketLog
local p = {}

-- 1) Date logic unchanged...
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

-- 2) Helpers unchanged...
local function randomChoice(t)
    return t[math.random(#t)]
end

-- 3) Global price helpers unchanged...
-- [getGlobalClosePrice(), getInvestorClosingValues() as before]

-- 4) NATIONAL POPULATION CONSTANT
local nationalPopulation = 82,545,451  -- total population of the nation

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

    -- closingData, closePrice, priceChange, regionalReport, stock flows, etc. unchanged...

    -- STIPEND VOUCHERS REDEEMED
    -- Use between 0.05% and 0.20% of the national population each day:
    local minRedemption = math.floor(nationalPopulation * 0.0005)
    local maxRedemption = math.floor(nationalPopulation * 0.0020)
    local stipendRedemption = math.random(minRedemption, maxRedemption)

    -- COMMODITY VOLUME unchanged or adjust similarly if desired
    local commodityVolume = math.random(3000, 4000)

    -- ...rest of your data gathering...

    -- BUILD WIKITABLE
    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)
    -- [and the rest of the table as before]

    return log
end

-- dailyMarketSummary() and return p unchanged