Module:GeneralPortWeather
From MicrasWiki
Documentation for this module may be created at Module:GeneralPortWeather/doc
-- Module:GeneralPortWeatherLog
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
function p.generateWeatherLog()
local year, day = getCurrentDate()
local dateStr = string.format("Day %d, Y.%d", day, year)
local conditions = randomChoice({"Clear", "Partly Cloudy", "Overcast", "Rain", "Storm", "Drizzle"})
local wind = randomChoice({"Calm", "Breezy", "Moderate", "Strong", "Gusty"})
local precipitationImpact = (conditions == "Rain" or conditions == "Storm" or conditions == "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
function p.dailyWeatherSummary()
local year, day = 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