Module:GeneralPortWeather
From MicrasWiki
Jump to navigationJump to search
Documentation for this module may be created at Module:GeneralPortWeather/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 selection utility
local function randomChoice(t)
return t[math.random(#t)]
end
-- Forecast string based on daily seed
local function getVaeringheimForecastString()
local date = os.date("*t")
local seed = date.year * 1000 + date.yday
math.randomseed(seed)
local climateEvents = {
"Morning drizzle and warm afternoon sunshine",
"Mild thunderstorm building by midday",
"Patchy fog at dawn, clearing toward lunch",
"Light rain with sunny breaks after noon",
"Gentle breezes, blossoming warmth, low humidity",
"Scattered clouds with a brief shower by dusk",
"Humid sunrise, comfortable high around midday",
"Overcast for part of the day, mild temperatures",
"Warm breezes carrying faint floral scents",
"Partial sun, warm with a slight chance of rain",
"Early morning seasonal storms and lake-driven floods may develop"
}
return climateEvents[math.random(#climateEvents)]
end
-- Generate the weather log table
function p.generateWeatherLog()
local year, day = p.getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local conditions = getVaeringheimForecastString()
local wind = randomChoice({ "Calm", "Breezy", "Moderate", "Strong", "Gusty" })
local precipitationImpact =
(conditions:lower():find("rain") or conditions:lower():find("storm") or conditions:lower():find("drizzle"))
and "Delays in loading/unloading" or "No significant impact"
local fog = randomChoice({ "None", "Light Haze", "Heavy Fog" })
local navalImpact = (fog == "Heavy Fog") and "Severe restrictions on naval operations"
or (fog == "Light Haze" and "Caution advised for navigation" or "Clear visibility")
local hazard = randomChoice({ "None", "Toxic Algae Bloom Detected", "Industrial Runoff Warning", "Oil Slick Monitored", "Chemical Discharge Alert" })
local toxicBloom = (hazard == "Toxic Algae Bloom Detected") and "Active bloom in Lake Morovia. Environmental control in effect." or "No bloom present"
local containment = randomChoice({ "None", "Activated containment barriers", "Limited zone quarantines", "Full spill containment deployed" })
local log = "{| class=\"wikitable\" style=\"width:100%\"\n"
log = log .. string.format("! colspan=2 | General Port of Lake Morovia – Environmental Conditions Log (%s)\n", dateStr)
log = log .. "|-\n"
log = log .. string.format("| '''General Conditions''' || %s\n", conditions)
log = log .. "|-\n"
log = log .. string.format("| '''Wind Speed''' || %s\n", wind)
log = log .. "|-\n"
log = log .. string.format("| '''Precipitation Impact''' || %s\n", precipitationImpact)
log = log .. "|-\n"
log = log .. string.format("| '''Fog / Haze''' || %s\n", fog)
log = log .. "|-\n"
log = log .. string.format("| '''Naval Visibility Conditions''' || %s\n", navalImpact)
log = log .. "|-\n"
log = log .. string.format("| '''Environmental Hazard Alert''' || %s\n", hazard)
log = log .. "|-\n"
log = log .. string.format("| '''Toxic Bloom Status''' || %s\n", toxicBloom)
log = log .. "|-\n"
log = log .. string.format("| '''Containment Protocols''' || %s\n", containment)
log = log .. "|}"
return log
end
-- Entry point for daily output
function p.dailyWeatherSummary()
local year, day = p.getCurrentDate()
local header = string.format("'''General Port of Lake Morovia: Environmental Log – Day %d, Year %d PSSC'''\n", day, year)
return header .. p.generateWeatherLog()
end
return p