Archived
Merge branch 'release/v1.0.0'
This commit is contained in:
commit
c021c55e29
7 files changed
+437
-10
No files matched your search
+8
-10
@@ -1,24 +1,26 @@
|
||||
# ---> Lua
|
||||
# Compiled Lua sources
|
||||
.idea
|
||||
|
||||
lib
|
||||
.emmyrc.json
|
||||
.*/
|
||||
*.md
|
||||
!README.md
|
||||
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
@@ -26,18 +28,14 @@ luac.out
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
name=AEBS Misc
|
||||
id=AEBSMisc
|
||||
description=Lets the server choose Imperial or Metric (or Both) units for AEBS radio broadcasts, and adds toggleable Water and Power shutoff warnings to the AEBS feed.
|
||||
author=Overlord_303
|
||||
modversion=1.0.0
|
||||
versionMin=42.0.0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,21 @@
|
||||
AEBSMisc_Options = {}
|
||||
|
||||
---Mirrors the defaults declared in sandbox-options.txt.
|
||||
local DEFAULTS = {
|
||||
Units = 1, -- 1 = Metric, 2 = Imperial, 3 = Both
|
||||
AnnouncePowerShutoff = true,
|
||||
AnnounceWaterShutoff = true,
|
||||
}
|
||||
|
||||
---@param name string an AEBSMisc.* sandbox option name, without the "AEBSMisc." prefix
|
||||
---@return any
|
||||
function AEBSMisc_Options.get(name)
|
||||
local sv = SandboxVars and SandboxVars.AEBSMisc
|
||||
local value = sv and sv[name]
|
||||
|
||||
if value == nil then
|
||||
return DEFAULTS[name]
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
@@ -0,0 +1,363 @@
|
||||
---@diagnostic disable: param-type-mismatch
|
||||
require("AEBSMisc/AEBSMisc_Options")
|
||||
|
||||
--- Forecast types accepted by WeatherChannel.GetForecastString, named
|
||||
--- so call sites don't have to carry the vanilla magic numbers.
|
||||
local FORECAST = {
|
||||
TEMPERATURE = 1,
|
||||
WIND = 2,
|
||||
FOG = 3,
|
||||
WEATHER_START = 4,
|
||||
WEATHER_END = 5,
|
||||
}
|
||||
|
||||
-- Hardcoded rather than routed through getText():
|
||||
-- GameServer.java:562 calls Translator.loadFiles() (which merges each
|
||||
-- mod's Translate/*.json into the running translation tables) BEFORE
|
||||
-- GameServer.java:607 even reads ServerOptions.mods into the active
|
||||
-- mod list, so a dedicated server merges mod translations before it
|
||||
-- knows which mods are active, and never repeats the merge afterward.
|
||||
|
||||
local WATER_SHUTOFF_LINES = {
|
||||
"Knox County Water Authority: Pressure irregularities reported across the grid.",
|
||||
"Knox County Water Authority: Pumping stations offline. Contamination risk.",
|
||||
"Knox County Water Authority: Water supply terminated.",
|
||||
};
|
||||
|
||||
local POWER_SHUTOFF_LINES = {
|
||||
getText("AEBS_Power_1"),
|
||||
getText("AEBS_Power_2"),
|
||||
getText("AEBS_Power_3"),
|
||||
};
|
||||
|
||||
--
|
||||
|
||||
---@param _val number
|
||||
---@return string
|
||||
local function formatRounded(_val)
|
||||
return tostring(ISDebugUtils.roundNum(_val, 2));
|
||||
end
|
||||
|
||||
---@param _val number
|
||||
---@return string
|
||||
local function formatWholeNumber(_val)
|
||||
return tostring(ISDebugUtils.roundNum(_val, 0));
|
||||
end
|
||||
|
||||
--- Renders a Celsius value per the AEBSMisc.Units sandbox option:
|
||||
--- Metric ("20.4 °C"), Imperial ("68.7 °F"), or Both ("20.4 °C (68.7 °F)").
|
||||
--- @param _celsius number
|
||||
--- @return string
|
||||
local function formatTemperature(_celsius)
|
||||
local mode = AEBSMisc_Options.get("Units");
|
||||
local c = tostring(ISDebugUtils.roundNum(_celsius, 1)) .. " " .. Temperature.getCelsiusPostfix();
|
||||
|
||||
if mode == 1 then return c; end
|
||||
|
||||
local f = tostring(
|
||||
ISDebugUtils.roundNum(Temperature.CelsiusToFahrenheit(_celsius), 1)
|
||||
) .. " " .. Temperature.getFahrenheitPostfix();
|
||||
|
||||
if mode == 2 then
|
||||
return f;
|
||||
else
|
||||
return c .. " (" .. f .. ")";
|
||||
end
|
||||
end
|
||||
|
||||
--- Renders a wind-power value per the AEBSMisc.Units sandbox option:
|
||||
--- Metric ("14 km/h"), Imperial ("9 mph"), or Both ("14 km/h (9 MpH)").
|
||||
--- @param _windPower number
|
||||
--- @return string
|
||||
local function formatWindSpeed(_windPower)
|
||||
local mode = AEBSMisc_Options.get("Units");
|
||||
local kph = formatRounded(ClimateManager.ToKph(_windPower)) .. getText("AEBS_KpH");
|
||||
|
||||
if (mode == 1) then return kph; end
|
||||
|
||||
local mph = formatRounded(ClimateManager.ToMph(_windPower)) .. getText("AEBS_MpH");
|
||||
|
||||
if mode == 2 then
|
||||
return mph;
|
||||
else
|
||||
return kph .. " (" .. mph .. ")";
|
||||
end
|
||||
end
|
||||
|
||||
--- Adds the three escalating radio lines (early warning -> critical -> shutoff)
|
||||
--- for a utility's shutoff timeline, based on in-game days remaining until
|
||||
--- _shutDay. Shared by AddPowerNotice and AddWaterNotice.
|
||||
--- @param _lines string[] exactly 3 lines: early warning, critical, final shutoff
|
||||
--- @param _shutDay number sandbox day the shutoff occurs
|
||||
--- @param _c table color {r, g, b}
|
||||
--- @param _bc RadioBroadCast
|
||||
--- @param _force boolean|nil add all three lines regardless of the current day
|
||||
local function addShutoffNotice(_lines, _shutDay, _c, _bc, _force)
|
||||
local day = getGameTime():getWorldAgeHours() / 24 + (getSandboxOptions():getTimeSinceApo() - 1) * 30;
|
||||
|
||||
if _force or (day >= _shutDay-2 and day < _shutDay-1) then
|
||||
_bc:AddRadioLine( RadioLine.new(_lines[1], _c.r, _c.g, _c.b) );
|
||||
end
|
||||
if _force or (day >= _shutDay-1 and day < _shutDay) then
|
||||
_bc:AddRadioLine( RadioLine.new(_lines[2], _c.r, _c.g, _c.b) );
|
||||
end
|
||||
if _force or (day >= _shutDay) then
|
||||
_bc:AddRadioLine( RadioLine.new(_lines[3], _c.r, _c.g, _c.b) );
|
||||
end
|
||||
end
|
||||
|
||||
--- Vanilla override: adds the escalating Knox Power Grid warning lines
|
||||
--- (fluctuations -> failing -> blackout) based on days until the sandbox
|
||||
--- electricity-shutoff day, gated by the AnnouncePowerShutoff sandbox option.
|
||||
--- @param _c table color {r, g, b}
|
||||
--- @param _bc RadioBroadCast
|
||||
--- @param _force boolean|nil add all three lines regardless of the current day
|
||||
function WeatherChannel.AddPowerNotice(_c, _bc, _force)
|
||||
if not AEBSMisc_Options.get("AnnouncePowerShutoff") then return; end
|
||||
|
||||
addShutoffNotice(POWER_SHUTOFF_LINES, getSandboxOptions():getElecShutModifier(), _c, _bc, _force);
|
||||
end
|
||||
|
||||
---New: mirrors AddPowerNotice but for the sandbox water-shutoff day,
|
||||
---gated by the AnnounceWaterShutoff sandbox option.
|
||||
---@param _c table color {r, g, b}
|
||||
---@param _bc RadioBroadCast
|
||||
---@param _force boolean|nil add all three lines regardless of the current day
|
||||
function WeatherChannel.AddWaterNotice(_c, _bc, _force)
|
||||
if not AEBSMisc_Options.get("AnnounceWaterShutoff") then return; end
|
||||
|
||||
addShutoffNotice(WATER_SHUTOFF_LINES, getSandboxOptions():getWaterShutModifier(), _c, _bc, _force);
|
||||
end
|
||||
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function buildTemperatureForecast(_forecast)
|
||||
local v = _forecast:getTemperature();
|
||||
local mean, min, max = v:getTotalMean(), v:getTotalMin(), v:getTotalMax();
|
||||
local humidity = formatWholeNumber(_forecast:getHumidity():getTotalMean()*100);
|
||||
|
||||
return " " .. getText("AEBS_temperature", formatTemperature(mean), formatTemperature(min), formatTemperature(max), humidity);
|
||||
end
|
||||
|
||||
---@param meanWindPower number
|
||||
---@return string
|
||||
local function describeWindStrength(meanWindPower)
|
||||
if meanWindPower > 0.75 then
|
||||
return getText("AEBS_wind_4")
|
||||
elseif meanWindPower > 0.5 then
|
||||
return getText("AEBS_wind_3")
|
||||
elseif meanWindPower > 0.25 then
|
||||
return getText("AEBS_wind_2")
|
||||
else
|
||||
return getText("AEBS_wind_1")
|
||||
end
|
||||
end
|
||||
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function describeCloudiness(_forecast)
|
||||
local cloudiness = _forecast:getCloudiness();
|
||||
local mean, max = cloudiness:getTotalMean(), cloudiness:getTotalMax();
|
||||
local description = getText("AEBS_clouds_0");
|
||||
|
||||
if mean > 0.7 then
|
||||
description = getText("AEBS_clouds_2");
|
||||
elseif mean > 0.4 then
|
||||
description = getText("AEBS_clouds_1");
|
||||
if max > 0.7 then
|
||||
description = description .. " " .. getText("AEBS_clouds_4");
|
||||
end
|
||||
else
|
||||
if max > 0.7 then
|
||||
description = description .. " " .. getText("AEBS_clouds_4");
|
||||
elseif max > 0.4 then
|
||||
description = description .. " " .. getText("AEBS_clouds_3");
|
||||
end
|
||||
end
|
||||
|
||||
return description;
|
||||
end
|
||||
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function buildWindForecast(_forecast)
|
||||
local v = _forecast:getWindPower();
|
||||
local meanPower, maxPower = v:getTotalMean(), v:getTotalMax();
|
||||
local direction = _forecast:getMeanWindAngleString();
|
||||
local directionText = getText("AEBS_zone_name_" .. direction:lower());
|
||||
|
||||
return getText("AEBS_wind_0", describeWindStrength(meanPower), directionText, formatWindSpeed(maxPower), describeCloudiness(_forecast));
|
||||
end
|
||||
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function buildFogForecast(_forecast)
|
||||
local v = _forecast:getFogStrength();
|
||||
if v == 1 then
|
||||
return getText("AEBS_fog_2");
|
||||
elseif v > 0.75 then
|
||||
return getText("AEBS_fog_1");
|
||||
else
|
||||
return getText("AEBS_fog_0");
|
||||
end
|
||||
end
|
||||
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function describePredictedWeatherEvents(_forecast)
|
||||
local t = {};
|
||||
|
||||
if _forecast:isHasHeavyRain() then
|
||||
table.insert(t, getText("AEBS_weather_heavy_rain"));
|
||||
end
|
||||
if _forecast:isHasStorm() then
|
||||
table.insert(t, getText("AEBS_weather_storm"));
|
||||
end
|
||||
if _forecast:isHasTropicalStorm() then
|
||||
table.insert(t, getText("AEBS_weather_tropical"));
|
||||
end
|
||||
if _forecast:isHasBlizzard() then
|
||||
table.insert(t, getText("AEBS_weather_blizzard"));
|
||||
end
|
||||
|
||||
if #t > 0 then
|
||||
if #t == 1 then
|
||||
return getText("AEBS_weather_predicted") .. t[1];
|
||||
else
|
||||
local s = getText("AEBS_weather_predicted");
|
||||
for k, v in ipairs(t) do
|
||||
if k <# t then
|
||||
s = s .. v .. (v ~= #t - 1 and ", " or "");
|
||||
else
|
||||
s = s .. getText("AEBS_weather_and_a") .. v .. "...";
|
||||
end
|
||||
end
|
||||
|
||||
return s;
|
||||
end
|
||||
else
|
||||
return getText("AEBS_weather_light_moderate");
|
||||
end
|
||||
end
|
||||
|
||||
---@param _type integer FORECAST.WEATHER_START or FORECAST.WEATHER_END
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
local function buildWeatherEventForecast(_type, _forecast)
|
||||
local s;
|
||||
if _type == FORECAST.WEATHER_START then
|
||||
s = getText("AEBS_weather_0_a", WeatherChannel.GetDaySegmentForHour(_forecast:getWeatherStartTime()));
|
||||
else
|
||||
local endTime = _forecast:getWeatherEndTime();
|
||||
if endTime >= 22 then
|
||||
s = getText("AEBS_weather_0_b");
|
||||
else
|
||||
s = getText("AEBS_weather_0_c", WeatherChannel.GetDaySegmentForHour(endTime));
|
||||
end
|
||||
end
|
||||
|
||||
s = s .. describePredictedWeatherEvents(_forecast);
|
||||
|
||||
if _forecast:isChanceOnSnow() then
|
||||
s = s..getText("AEBS_weather_snowfall");
|
||||
end
|
||||
|
||||
return s;
|
||||
end
|
||||
|
||||
---Vanilla override: only the temperature and wind-speed builders differ,
|
||||
---rendering via the AEBSMisc.Units sandbox option instead of the client-only
|
||||
---getOptionDisplayAsCelsius().
|
||||
---@param _forecast ClimateForecaster.DayForecast
|
||||
---@return string
|
||||
function WeatherChannel.GetForecastString(_type, _forecast)
|
||||
if _type == FORECAST.TEMPERATURE then
|
||||
return buildTemperatureForecast(_forecast);
|
||||
elseif _type == FORECAST.WIND then
|
||||
return buildWindForecast(_forecast);
|
||||
elseif _type == FORECAST.FOG then
|
||||
return buildFogForecast(_forecast);
|
||||
elseif _type == FORECAST.WEATHER_START or _type == FORECAST.WEATHER_END then
|
||||
return buildWeatherEventForecast(_type, _forecast);
|
||||
else
|
||||
return "";
|
||||
end
|
||||
end
|
||||
|
||||
---Vanilla override: identical structure to the original,
|
||||
---with an added AddWaterNotice call alongside AddPowerNotice.
|
||||
---@param _gametime GameTime
|
||||
---@param _bc RadioBroadCast
|
||||
function WeatherChannel.FillBroadcast(_gametime, _bc)
|
||||
local hour = _gametime:getHour();
|
||||
local c = { r = 1.0, g = 1.0, b = 1.0 };
|
||||
|
||||
_bc:AddRadioLine(RadioLine.new(getText("AEBS_Intro"), c.r, c.g, c.b));
|
||||
|
||||
WeatherChannel.AddFuzz(c, _bc);
|
||||
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
WeatherChannel.AddPowerNotice(c, _bc);
|
||||
WeatherChannel.AddWaterNotice(c, _bc);
|
||||
|
||||
WeatherChannel.GetRandomString(c, _bc, 100);
|
||||
WeatherChannel.AddFuzz(c, _bc);
|
||||
|
||||
WeatherChannel.AddForecasting(c, _bc, hour);
|
||||
WeatherChannel.AddFuzz(c, _bc);
|
||||
|
||||
WeatherChannel.GetRandomString(c, _bc, 100);
|
||||
|
||||
if getGameTime():getNightsSurvived() == getGameTime():getHelicopterDay1() then
|
||||
WeatherChannel.AddFuzz(c, _bc, 6);
|
||||
_bc:AddRadioLine(RadioLine.new(getText("AEBS_Choppah"), c.r, c.g, c.b));
|
||||
end
|
||||
|
||||
WeatherChannel.AddFuzz(c, _bc);
|
||||
end
|
||||
|
||||
--- Vanilla override: identical structure to the original debug broadcast
|
||||
--- (forces 3 days of forecasts, every AEBS_random_* variant, extremes, and an
|
||||
--- outro), with an added forced AddWaterNotice call alongside AddPowerNotice.
|
||||
--- Runs instead of FillBroadcast when WeatherChannel.debugTestAll is true.
|
||||
--- @param _gametime GameTime
|
||||
--- @param _bc RadioBroadCast
|
||||
function WeatherChannel.TestAll(_gametime, _bc)
|
||||
local clim = getClimateManager();
|
||||
local forecaster = clim:getClimateForecaster();
|
||||
|
||||
local c = { r = 1.0, g = 1.0, b = 1.0 };
|
||||
_bc:AddRadioLine(RadioLine.new(getText("AEBS_Intro"), c.r, c.g, c.b));
|
||||
WeatherChannel.AddPowerNotice(c, _bc, true);
|
||||
WeatherChannel.AddWaterNotice(c, _bc, true);
|
||||
|
||||
local forecast = forecaster:getForecast();
|
||||
WeatherChannel.AddForecast(c, _bc, forecast, getText("AEBS_Pre_today"), true);
|
||||
|
||||
forecast = forecaster:getForecast(1);
|
||||
WeatherChannel.AddForecast(c, _bc, forecast, getText("AEBS_Pre_tomorrow"), true);
|
||||
|
||||
forecast = forecaster:getForecast(2);
|
||||
WeatherChannel.AddForecast(c, _bc, forecast, getText("AEBS_Pre_dayafter"), true);
|
||||
|
||||
WeatherChannel.AddExtremesForecasting(c, _bc, 3, 20);
|
||||
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 0);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 500);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 1000);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 1500);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9000);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9001);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9002);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9003);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9004);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9005);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9006);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9007);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9008);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9009);
|
||||
WeatherChannel.GetRandomString(c, _bc, 100, 9010);
|
||||
|
||||
_bc:AddRadioLine(RadioLine.new(getText("AEBS_Choppah"), c.r, c.g, c.b));
|
||||
WeatherChannel.AddFuzz(c, _bc, 6);
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Sandbox_AEBSMisc": "AEBS Misc",
|
||||
"Sandbox_AEBSMisc_Units": "AEBS broadcast units",
|
||||
"Sandbox_AEBSMisc_Units_tooltip": "Which unit system AEBS radio broadcasts (temperature, wind speed) are rendered in for every listener, regardless of each player's own Display options. Both shows both units side by side, useful for mixed-preference audiences.",
|
||||
"Sandbox_AEBSMisc_Units_option1": "Metric",
|
||||
"Sandbox_AEBSMisc_Units_option2": "Imperial",
|
||||
"Sandbox_AEBSMisc_Units_option3": "Both",
|
||||
"Sandbox_AEBSMisc_AnnouncePowerShutoff": "Announce power shutoff",
|
||||
"Sandbox_AEBSMisc_AnnouncePowerShutoff_tooltip": "Whether AEBS broadcasts warn about the power grid failing, based on the Electricity Shutoff Delay sandbox option.",
|
||||
"Sandbox_AEBSMisc_AnnounceWaterShutoff": "Announce water shutoff",
|
||||
"Sandbox_AEBSMisc_AnnounceWaterShutoff_tooltip": "Whether AEBS broadcasts warn about the water supply failing, based on the Water Shutoff Delay sandbox option."
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
VERSION = 1,
|
||||
|
||||
option AEBSMisc.Units
|
||||
{
|
||||
type = enum,
|
||||
numValues = 3,
|
||||
default = 1,
|
||||
page = AEBSMisc,
|
||||
translation = AEBSMisc_Units,
|
||||
valueTranslation = AEBSMisc_Units,
|
||||
}
|
||||
|
||||
option AEBSMisc.AnnouncePowerShutoff
|
||||
{
|
||||
type = boolean,
|
||||
default = true,
|
||||
page = AEBSMisc,
|
||||
translation = AEBSMisc_AnnouncePowerShutoff,
|
||||
}
|
||||
|
||||
option AEBSMisc.AnnounceWaterShutoff
|
||||
{
|
||||
type = boolean,
|
||||
default = true,
|
||||
page = AEBSMisc,
|
||||
translation = AEBSMisc_AnnounceWaterShutoff,
|
||||
}
|
||||
Reference in new issue
Block a user