From be84cdb1bb877a2c58b309102332568dc0ce15d0 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 8 Mar 2026 11:00:07 +0100 Subject: [PATCH] Rename Climate to Weather where appropriate (#26163) * Introduce OpenRCT2::Weather namespace * Rename Climate.h/cpp to Weather.h/cpp * Rename ScClimate.hpp to ScWeather.hpp * Rename drawing/Weather.h to drawing/WeatherDrawer.h --- .../engines/opengl/OpenGLDrawingEngine.cpp | 6 +- src/openrct2-ui/windows/GameBottomToolbar.cpp | 6 +- src/openrct2-ui/windows/Transparency.cpp | 2 +- src/openrct2/Cheats.cpp | 2 +- src/openrct2/Editor.cpp | 4 +- src/openrct2/Game.cpp | 2 +- src/openrct2/GameState.cpp | 6 +- src/openrct2/GameState.h | 6 +- src/openrct2/actions/GameActionRunner.cpp | 4 +- .../actions/cheats/CheatSetAction.cpp | 6 +- src/openrct2/audio/Audio.cpp | 6 +- src/openrct2/drawing/Drawing.cpp | 16 +- src/openrct2/drawing/IDrawingEngine.h | 2 +- src/openrct2/drawing/LightFX.cpp | 2 +- .../{Weather.cpp => WeatherDrawer.cpp} | 8 +- .../drawing/{Weather.h => WeatherDrawer.h} | 0 src/openrct2/drawing/X8DrawingEngine.cpp | 2 +- src/openrct2/entity/Guest.cpp | 10 +- src/openrct2/entity/Peep.cpp | 2 +- src/openrct2/interface/Screenshot.cpp | 6 +- src/openrct2/interface/Screenshot.h | 4 +- src/openrct2/interface/Viewport.cpp | 4 +- src/openrct2/libopenrct2.vcxproj | 10 +- src/openrct2/object/ClimateObject.cpp | 18 +- src/openrct2/object/ClimateObject.h | 10 +- src/openrct2/paint/Paint.Entity.cpp | 2 +- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 14 +- src/openrct2/rct2/S6Importer.cpp | 14 +- src/openrct2/ride/Ride.cpp | 4 +- src/openrct2/ride/RideConstruction.cpp | 2 +- src/openrct2/scenario/Scenario.cpp | 2 +- src/openrct2/scripting/ScriptEngine.cpp | 6 +- .../world/{ScClimate.hpp => ScWeather.hpp} | 32 +- src/openrct2/world/Climate.cpp | 503 ----------------- src/openrct2/world/Climate.h | 101 ---- src/openrct2/world/Map.cpp | 2 +- src/openrct2/world/Scenery.cpp | 2 +- src/openrct2/world/Weather.cpp | 504 ++++++++++++++++++ src/openrct2/world/Weather.h | 104 ++++ 40 files changed, 722 insertions(+), 716 deletions(-) rename src/openrct2/drawing/{Weather.cpp => WeatherDrawer.cpp} (96%) rename src/openrct2/drawing/{Weather.h => WeatherDrawer.h} (100%) rename src/openrct2/scripting/bindings/world/{ScClimate.hpp => ScWeather.hpp} (80%) delete mode 100644 src/openrct2/world/Climate.cpp delete mode 100644 src/openrct2/world/Climate.h create mode 100644 src/openrct2/world/Weather.cpp create mode 100644 src/openrct2/world/Weather.h diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 93d25ac655..8308099295 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -35,10 +35,10 @@ #include #include #include - #include + #include #include #include - #include + #include using namespace OpenRCT2; using namespace OpenRCT2::Drawing; @@ -368,7 +368,7 @@ public: void PaintWindows() override { - if (ClimateHasWeatherEffect() || gPaintForceRedraw) + if (Weather::hasWeatherEffect() || gPaintForceRedraw) { WindowUpdateAllViewports(); // OpenGL doesn't support restoring pixels, always redraw. diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index c15b4eef9a..e965191281 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -215,7 +215,7 @@ namespace OpenRCT2::Ui::Windows StringId format = STR_CELSIUS_VALUE; if (Config::Get().general.temperatureFormat == TemperatureUnit::Fahrenheit) { - temperature = ClimateCelsiusToFahrenheit(temperature); + temperature = Weather::celsiusToFahrenheit(temperature); format = STR_FAHRENHEIT_VALUE; } ft = Formatter(); @@ -224,11 +224,11 @@ namespace OpenRCT2::Ui::Windows screenCoords.x += 30; // Current weather - auto currentWeatherSpriteId = ClimateGetWeatherSpriteId(getGameState().weatherCurrent.weatherType); + auto currentWeatherSpriteId = Weather::getWeatherSpriteId(getGameState().weatherCurrent.weatherType); GfxDrawSprite(rt, ImageId(currentWeatherSpriteId), screenCoords); // Next weather - auto nextWeatherSpriteId = ClimateGetWeatherSpriteId(getGameState().weatherNext.weatherType); + auto nextWeatherSpriteId = Weather::getWeatherSpriteId(getGameState().weatherNext.weatherType); if (currentWeatherSpriteId != nextWeatherSpriteId) { if (getGameState().weatherUpdateTimer < 960) diff --git a/src/openrct2-ui/windows/Transparency.cpp b/src/openrct2-ui/windows/Transparency.cpp index a5896d6339..af27647988 100644 --- a/src/openrct2-ui/windows/Transparency.cpp +++ b/src/openrct2-ui/windows/Transparency.cpp @@ -25,8 +25,8 @@ #include #include #include -#include #include +#include namespace OpenRCT2::Ui::Windows { diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 2f6595a0a5..e3f5d2d6e2 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -16,10 +16,10 @@ #include "core/DataSerialiser.h" #include "network/Network.h" #include "ride/Ride.h" -#include "world/Climate.h" #include "world/Footpath.h" #include "world/Park.h" #include "world/Scenery.h" +#include "world/Weather.h" using namespace OpenRCT2; diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index e7c2f5ea1d..2f6d57895f 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -43,13 +43,13 @@ #include "scripting/ScriptEngine.h" #include "ui/WindowManager.h" #include "windows/Intent.h" -#include "world/Climate.h" #include "world/Entrance.h" #include "world/Footpath.h" #include "world/Map.h" #include "world/MapLimits.h" #include "world/Park.h" #include "world/Scenery.h" +#include "world/Weather.h" #include #include @@ -341,7 +341,7 @@ namespace OpenRCT2::Editor park.bankLoanInterestRate = std::clamp(park.bankLoanInterestRate, 5, kMaxBankLoanInterestRate); } - ClimateReset(); + Weather::reset(); News::InitQueue(gameState); } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index a904b64fe2..f5f28ebea7 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -66,13 +66,13 @@ #include "ui/WindowManager.h" #include "windows/Intent.h" #include "world/Banner.h" -#include "world/Climate.h" #include "world/Entrance.h" #include "world/Footpath.h" #include "world/Map.h" #include "world/MapAnimation.h" #include "world/Park.h" #include "world/Scenery.h" +#include "world/Weather.h" #include "world/tile_element/SurfaceElement.h" #include diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 90c0beb3ae..d1e9c1495b 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -68,7 +68,7 @@ namespace OpenRCT2 gameState.entities.ResetAllEntities(); UpdateConsolidatedPatrolAreas(); ResetDate(); - ClimateReset(); + Weather::reset(); News::InitQueue(gameState); gInMapInitCode = false; @@ -307,7 +307,7 @@ namespace OpenRCT2 DateUpdate(gameState); ScenarioUpdate(gameState); - ClimateUpdate(); + Weather::update(); MapUpdateTiles(); // Temporarily remove provisional paths to prevent peep from interacting with them @@ -336,7 +336,7 @@ namespace OpenRCT2 MapAnimations::InvalidateAndUpdateAll(); VehicleSoundsUpdate(); PeepUpdateCrowdNoise(); - ClimateUpdateSound(); + Weather::updateSound(); EditorOpenWindowsForCurrentStep(); // Update windows diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 06ff802749..a69cddc337 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -22,10 +22,10 @@ #include "ride/RideRatings.h" #include "scenario/ScenarioOptions.h" #include "world/Banner.h" -#include "world/Climate.h" #include "world/Location.hpp" #include "world/ParkData.h" #include "world/ScenerySelection.h" +#include "world/Weather.h" #include #include @@ -43,8 +43,8 @@ namespace OpenRCT2 uint32_t currentTicks{}; Date date; - WeatherState weatherCurrent; - WeatherState weatherNext; + Weather::State weatherCurrent; + Weather::State weatherNext; uint16_t weatherUpdateTimer; uint32_t nextGuestNumber; diff --git a/src/openrct2/actions/GameActionRunner.cpp b/src/openrct2/actions/GameActionRunner.cpp index 1ac05000ac..3d73dfea26 100644 --- a/src/openrct2/actions/GameActionRunner.cpp +++ b/src/openrct2/actions/GameActionRunner.cpp @@ -140,10 +140,10 @@ namespace OpenRCT2::GameActions } GameAction* action = queued.action.get(); - action->SetFlags(action->GetFlags().with(CommandFlag::networked)); - Guard::Assert(action != nullptr); + action->SetFlags(action->GetFlags().with(CommandFlag::networked)); + Result result = Execute(action, gameState); if (result.error == Status::ok && Network::GetMode() == Network::Mode::server) { diff --git a/src/openrct2/actions/cheats/CheatSetAction.cpp b/src/openrct2/actions/cheats/CheatSetAction.cpp index abd3ab86ff..6fa4727cab 100644 --- a/src/openrct2/actions/cheats/CheatSetAction.cpp +++ b/src/openrct2/actions/cheats/CheatSetAction.cpp @@ -34,10 +34,10 @@ #include "../../ui/WindowManager.h" #include "../../util/Util.h" #include "../../windows/Intent.h" -#include "../../world/Climate.h" #include "../../world/Location.hpp" #include "../../world/Map.h" #include "../../world/Park.h" +#include "../../world/Weather.h" #include "../../world/tile_element/PathElement.h" #include "../../world/tile_element/SmallSceneryElement.h" #include "../../world/tile_element/SurfaceElement.h" @@ -219,7 +219,7 @@ namespace OpenRCT2::GameActions break; case CheatType::forceWeather: // Todo - make sure this is safe - ClimateForceWeather(WeatherType{ static_cast(_param1) }); + Weather::forceWeather(Weather::Type{ static_cast(_param1) }); break; case CheatType::freezeWeather: gameState.cheats.freezeWeather = _param1 != 0; @@ -390,7 +390,7 @@ namespace OpenRCT2::GameActions case CheatType::setStaffSpeed: return { { 0, 255 }, { 0, 0 } }; case CheatType::forceWeather: - return { { 0, EnumValue(WeatherType::Count) - 1 }, { 0, 0 } }; + return { { 0, EnumValue(Weather::Type::Count) - 1 }, { 0, 0 } }; case CheatType::setForcedParkRating: return { { -1, 999 }, { 0, 0 } }; case CheatType::createDucks: diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index 59ff957b2c..39034f4116 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -29,8 +29,8 @@ #include "../scenes/intro/IntroScene.h" #include "../ui/WindowManager.h" #include "../util/Util.h" -#include "../world/Climate.h" #include "../world/Map.h" +#include "../world/Weather.h" #include "../world/tile_element/SurfaceElement.h" #include "AudioChannel.h" #include "AudioContext.h" @@ -326,7 +326,7 @@ namespace OpenRCT2::Audio { StopVehicleSounds(); PeepStopCrowdNoise(); - ClimateStopWeatherSound(); + Weather::stopWeatherSound(); } void StopAll() @@ -399,7 +399,7 @@ namespace OpenRCT2::Audio PeepStopCrowdNoise(); StopTitleMusic(); RideAudio::StopAllChannels(); - ClimateStopWeatherSound(); + Weather::stopWeatherSound(); _currentAudioDevice = -1; } diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 2e8072fc8b..7fb33acbcc 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -21,8 +21,8 @@ #include "../object/WaterEntry.h" #include "../platform/Platform.h" #include "../util/Util.h" -#include "../world/Climate.h" #include "../world/Location.hpp" +#include "../world/Weather.h" #include "LightFX.h" #include "Rectangle.h" @@ -716,7 +716,7 @@ void UpdatePalette(std::span palette, PaletteIndex startIndex, else { float night = gDayNightCycle; - if (night >= 0 && gClimateLightningFlash == 0) + if (night >= 0 && Weather::gLightningFlash == 0) { r = Lerp(r, SoftLight(r, 8), night); g = Lerp(g, SoftLight(g, 8), night); @@ -750,7 +750,7 @@ void UpdatePaletteEffects() { auto water_type = OpenRCT2::ObjectManager::GetObjectEntry(0); - if (gClimateLightningFlash == 1) + if (Weather::gLightningFlash == 1) { // Change palette to lighter colour during lightning int32_t palette = SPR_GAME_DEFAULT_PALETTE; @@ -775,11 +775,11 @@ void UpdatePaletteEffects() UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); } - gClimateLightningFlash++; + Weather::gLightningFlash++; } else { - if (gClimateLightningFlash == 2) + if (Weather::gLightningFlash == 2) { // Change palette back to normal after lightning int32_t palette = SPR_GAME_DEFAULT_PALETTE; @@ -809,7 +809,7 @@ void UpdatePaletteEffects() uint32_t shade = 0; if (Config::Get().general.renderWeatherGloom) { - auto paletteId = ClimateGetWeatherGloomPaletteId(getGameState().weatherCurrent); + auto paletteId = Weather::getWeatherGloomPaletteId(getGameState().weatherCurrent); if (paletteId != FilterPaletteID::paletteNull) { shade = 1; @@ -892,10 +892,10 @@ void UpdatePaletteEffects() } UpdatePalette(gGamePalette, kPaletteOffsetAnimated, kPaletteLengthAnimated); - if (gClimateLightningFlash == 2) + if (Weather::gLightningFlash == 2) { UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); - gClimateLightningFlash = 0; + Weather::gLightningFlash = 0; } } } diff --git a/src/openrct2/drawing/IDrawingEngine.h b/src/openrct2/drawing/IDrawingEngine.h index 6a418eadb1..16118dc2d0 100644 --- a/src/openrct2/drawing/IDrawingEngine.h +++ b/src/openrct2/drawing/IDrawingEngine.h @@ -11,7 +11,7 @@ #include "../core/FlagHolder.hpp" #include "ColourPalette.h" -#include "Weather.h" +#include "WeatherDrawer.h" #include #include diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 9925588b72..66ff55d180 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -956,7 +956,7 @@ namespace OpenRCT2::Drawing::LightFx float wetnessBoost = 1.0f; // 1.0f + wetness * wetness * 0.1f; - if (night >= 0 && gClimateLightningFlash != 1) + if (night >= 0 && Weather::gLightningFlash != 1) { *r = Lerp(*r, SoftLight(*r, 8), night); *g = Lerp(*g, SoftLight(*g, 8), night); diff --git a/src/openrct2/drawing/Weather.cpp b/src/openrct2/drawing/WeatherDrawer.cpp similarity index 96% rename from src/openrct2/drawing/Weather.cpp rename to src/openrct2/drawing/WeatherDrawer.cpp index b7662c04bb..69801dd6f6 100644 --- a/src/openrct2/drawing/Weather.cpp +++ b/src/openrct2/drawing/WeatherDrawer.cpp @@ -7,7 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "Weather.h" +#include "WeatherDrawer.h" #include "../Game.h" #include "../GameState.h" @@ -15,7 +15,7 @@ #include "../interface/Viewport.h" #include "../ride/TrackDesign.h" #include "../ui/UiContext.h" -#include "../world/Climate.h" +#include "../world/Weather.h" #include "Drawing.h" #include "IDrawingEngine.h" @@ -63,12 +63,12 @@ void DrawWeather(RenderTarget& rt, IWeatherDrawer* weatherDrawer) viewFlags = viewport->flags; auto weatherLevel = getGameState().weatherCurrent.level; - if (weatherLevel == WeatherLevel::None || gTrackDesignSaveMode || (viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) + if (weatherLevel == Weather::Level::None || gTrackDesignSaveMode || (viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES)) return; // Get weather draw function and draw weather auto drawFunc = DrawRainFunctions[EnumValue(weatherLevel)]; - if (ClimateIsSnowing() || ClimateTransitioningToSnow()) + if (Weather::isSnowing() || Weather::isTransitioningToSnow()) { drawFunc = DrawSnowFunctions[EnumValue(weatherLevel)]; } diff --git a/src/openrct2/drawing/Weather.h b/src/openrct2/drawing/WeatherDrawer.h similarity index 100% rename from src/openrct2/drawing/Weather.h rename to src/openrct2/drawing/WeatherDrawer.h diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index 3476565bc1..00c60ae11b 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -25,7 +25,7 @@ #include "IDrawingEngine.h" #include "InvalidationGrid.h" #include "LightFX.h" -#include "Weather.h" +#include "WeatherDrawer.h" #include #include diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index e7fc989717..a397142999 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -58,13 +58,13 @@ #include "../ui/WindowManager.h" #include "../util/Util.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/Footpath.h" #include "../world/Location.hpp" #include "../world/Map.h" #include "../world/Park.h" #include "../world/Scenery.h" #include "../world/TileElementsView.h" +#include "../world/Weather.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/LargeSceneryElement.h" #include "../world/tile_element/PathElement.h" @@ -1529,7 +1529,7 @@ static money64 getItemValue(const ShopItemDescriptor& shopItemDescriptor) */ static bool GuestDecideAndBuyItem(Guest& guest, Ride& ride, const ShopItem shopItem, money64 price) { - const bool isPrecipitating = ClimateIsPrecipitating(); + const bool isPrecipitating = Weather::isPrecipitating(); const bool isPrecipitatingAndUmbrella = isPrecipitating && (shopItem == ShopItem::umbrella); bool hasVoucher = false; @@ -2106,7 +2106,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b } else { - const bool isPrecipitating = ClimateIsPrecipitating(); + const bool isPrecipitating = Weather::isPrecipitating(); if (isPrecipitating && !GuestShouldRideWhileRaining(*this, ride)) { if (peepAtRide) @@ -4962,7 +4962,7 @@ void Guest::UpdateRideMazePathfinding() if (IsActionInterruptable()) { - if (Energy > 80 && !(PeepFlags & PEEP_FLAGS_SLOW_WALK) && !ClimateIsPrecipitating() + if (Energy > 80 && !(PeepFlags & PEEP_FLAGS_SLOW_WALK) && !Weather::isPrecipitating() && (ScenarioRand() & 0xFFFF) <= 2427) { Action = PeepActionType::jump; @@ -6947,7 +6947,7 @@ void Guest::UpdateAnimationGroup() WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY; } - if (ClimateIsPrecipitating() && (HasItem(ShopItem::umbrella)) && x != kLocationNull) + if (Weather::isPrecipitating() && (HasItem(ShopItem::umbrella)) && x != kLocationNull) { CoordsXY loc = { x, y }; if (MapIsLocationValid(loc.ToTileStart())) diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 9d2519015e..a48eb62ffd 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -51,7 +51,6 @@ #include "../ui/WindowManager.h" #include "../util/Util.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/ConstructionClearance.h" #include "../world/Entrance.h" #include "../world/Footpath.h" @@ -59,6 +58,7 @@ #include "../world/Park.h" #include "../world/QuarterTile.h" #include "../world/Scenery.h" +#include "../world/Weather.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" #include "../world/tile_element/SurfaceElement.h" diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 7b4d503e98..570d6ceffa 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -30,9 +30,9 @@ #include "../paint/Painter.h" #include "../paint/tile_element/Paint.TileElement.h" #include "../platform/Platform.h" -#include "../world/Climate.h" #include "../world/Map.h" #include "../world/Park.h" +#include "../world/Weather.h" #include "../world/tile_element/SurfaceElement.h" #include "Viewport.h" @@ -379,9 +379,9 @@ void ScreenshotGiant() static void ApplyOptions(const ScreenshotOptions* options, Viewport& viewport) { - if (options->weather != WeatherType::Sunny && options->weather != WeatherType::Count) + if (options->weather != Weather::Type::Sunny && options->weather != Weather::Type::Count) { - ClimateForceWeather(WeatherType{ static_cast(EnumValue(options->weather) - 1) }); + Weather::forceWeather(Weather::Type{ static_cast(EnumValue(options->weather) - 1) }); } if (options->hide_guests) diff --git a/src/openrct2/interface/Screenshot.h b/src/openrct2/interface/Screenshot.h index ee1bbf3537..d9d4f22194 100644 --- a/src/openrct2/interface/Screenshot.h +++ b/src/openrct2/interface/Screenshot.h @@ -10,8 +10,8 @@ #pragma once #include "../core/FileSystem.hpp" -#include "../world/Climate.h" #include "../world/Location.hpp" +#include "../world/Weather.h" #include "ZoomLevel.h" #include @@ -21,7 +21,7 @@ extern uint8_t gScreenshotCountdown; struct ScreenshotOptions { - WeatherType weather = WeatherType::Sunny; + OpenRCT2::Weather::Type weather = OpenRCT2::Weather::Type::Sunny; bool hide_guests = false; bool hide_sprites = false; bool clear_grass = false; diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 00bb36bf7a..a1fb5917b0 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -34,8 +34,8 @@ #include "../ride/TrackDesign.h" #include "../ride/Vehicle.h" #include "../ui/WindowManager.h" -#include "../world/Climate.h" #include "../world/Map.h" +#include "../world/Weather.h" #include "../world/tile_element/LargeSceneryElement.h" #include "../world/tile_element/SmallSceneryElement.h" #include "../world/tile_element/TileElement.h" @@ -1001,7 +1001,7 @@ namespace OpenRCT2 static void ViewportPaintWeatherGloom(RenderTarget& rt) { - auto paletteId = ClimateGetWeatherGloomPaletteId(getGameState().weatherCurrent); + auto paletteId = Weather::getWeatherGloomPaletteId(getGameState().weatherCurrent); if (paletteId != FilterPaletteID::paletteNull) { auto x = rt.x; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index db7c7c59fd..7b96bbefb7 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -268,10 +268,10 @@ - + @@ -632,7 +632,6 @@ - @@ -641,6 +640,7 @@ + @@ -657,7 +657,6 @@ - @@ -676,6 +675,7 @@ + @@ -866,7 +866,6 @@ - @@ -875,6 +874,7 @@ + @@ -1208,7 +1208,6 @@ - @@ -1220,6 +1219,7 @@ + diff --git a/src/openrct2/object/ClimateObject.cpp b/src/openrct2/object/ClimateObject.cpp index 1100f80a39..a0d94ad6d1 100644 --- a/src/openrct2/object/ClimateObject.cpp +++ b/src/openrct2/object/ClimateObject.cpp @@ -22,6 +22,8 @@ namespace OpenRCT2 { + using namespace OpenRCT2::Weather; + struct RawClimateMonth { int8_t baseTemperature; @@ -59,10 +61,10 @@ namespace OpenRCT2 const auto dist = getYearlyDistribution(); const auto totalSize = kNumClimateMonths * kWeatherDistSize; - for (auto i = 0u; i < EnumValue(WeatherType::Count); i++) + for (auto i = 0u; i < EnumValue(Weather::Type::Count); i++) { - auto type = WeatherType(i); - auto imageId = ImageId(ClimateGetWeatherSpriteId(type)); + auto type = Weather::Type(i); + auto imageId = ImageId(Weather::getWeatherSpriteId(type)); auto coords = ScreenCoordsXY(8 + (i % 3) * 35, 3 + (i / 3) * 37); GfxDrawSprite(rt, imageId, coords); @@ -95,7 +97,7 @@ namespace OpenRCT2 return _climate.itemThresholds; } - const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month) const + const Pattern& ClimateObject::getPatternForMonth(uint8_t month) const { return _climate.patterns[month]; } @@ -107,7 +109,7 @@ namespace OpenRCT2 YearlyDistribution ClimateObject::getYearlyDistribution() const { - auto weatherTypeCount = [](const WeatherPattern& pattern, const WeatherType target) { + auto weatherTypeCount = [](const Weather::Pattern& pattern, const Weather::Type target) { auto count = 0u; for (auto type : pattern.distribution) { @@ -121,8 +123,8 @@ namespace OpenRCT2 for (auto m = 0; m < kNumClimateMonths; m++) { auto& pattern = getPatternForMonth(m); - for (auto i = 0u; i < EnumValue(WeatherType::Count); i++) - dist[i] += weatherTypeCount(pattern, WeatherType(i)); + for (auto i = 0u; i < EnumValue(Weather::Type::Count); i++) + dist[i] += weatherTypeCount(pattern, Weather::Type(i)); } return dist; @@ -148,7 +150,7 @@ namespace OpenRCT2 for (auto k = 0u; k < srcMonth.distribution[w]; k++) { - dstMonth.distribution[i] = WeatherType(w); + dstMonth.distribution[i] = Weather::Type(w); i++; } } diff --git a/src/openrct2/object/ClimateObject.h b/src/openrct2/object/ClimateObject.h index 0d754c203b..362deb584b 100644 --- a/src/openrct2/object/ClimateObject.h +++ b/src/openrct2/object/ClimateObject.h @@ -9,19 +9,19 @@ #pragma once -#include "../world/Climate.h" +#include "../world/Weather.h" #include "Object.h" namespace OpenRCT2 { struct IReadObjectContext; - using YearlyDistribution = std::array; + using YearlyDistribution = std::array; class ClimateObject final : public Object { private: - Climate _climate; + Weather::Climate _climate; std::string _scriptName; public: @@ -33,8 +33,8 @@ namespace OpenRCT2 void DrawPreview(Drawing::RenderTarget& rt, int32_t width, int32_t height) const override; - const TemperatureThresholds& getItemThresholds() const; - const WeatherPattern& getPatternForMonth(uint8_t month) const; + const Weather::TemperatureThresholds& getItemThresholds() const; + const Weather::Pattern& getPatternForMonth(uint8_t month) const; std::string getScriptName() const; YearlyDistribution getYearlyDistribution() const; }; diff --git a/src/openrct2/paint/Paint.Entity.cpp b/src/openrct2/paint/Paint.Entity.cpp index 0c762aa3ed..15781fc47d 100644 --- a/src/openrct2/paint/Paint.Entity.cpp +++ b/src/openrct2/paint/Paint.Entity.cpp @@ -24,9 +24,9 @@ #include "../ride/RideData.h" #include "../ride/TrackDesign.h" #include "../ride/Vehicle.h" -#include "../world/Climate.h" #include "../world/Map.h" #include "../world/Park.h" +#include "../world/Weather.h" #include "Paint.h" #include "entity/Paint.Guest.h" #include "entity/Paint.Staff.h" diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index a92028abf9..d1f8a8167d 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -54,11 +54,11 @@ #include "../scenario/ScenarioRepository.h" #include "../scripting/ScriptEngine.h" #include "../ui/WindowManager.h" -#include "../world/Climate.h" #include "../world/Entrance.h" #include "../world/Map.h" #include "../world/Park.h" #include "../world/Scenery.h" +#include "../world/Weather.h" #include "../world/tile_element/PathElement.h" #include "../world/tile_element/SmallSceneryElement.h" #include "../world/tile_element/TrackElement.h" diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 6012543b42..95f98d6aa0 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -58,13 +58,13 @@ #include "../scenario/ScenarioObjective.h" #include "../scenario/ScenarioRepository.h" #include "../scenario/ScenarioSources.h" -#include "../world/Climate.h" #include "../world/Map.h" #include "../world/MapAnimation.h" #include "../world/Park.h" #include "../world/Scenery.h" #include "../world/TilePointerIndex.hpp" #include "../world/Wall.h" +#include "../world/Weather.h" #include "../world/tile_element/BannerElement.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/LargeSceneryElement.h" @@ -2383,18 +2383,18 @@ namespace OpenRCT2::RCT1 { gameState.weatherUpdateTimer = _s4.WeatherUpdateTimer; gameState.weatherCurrent = { - .weatherType = WeatherType{ _s4.Weather }, + .weatherType = Weather::Type{ _s4.Weather }, .temperature = static_cast(_s4.Temperature), - .weatherEffect = WeatherEffectType::None, + .weatherEffect = Weather::EffectType::None, .weatherGloom = _s4.WeatherGloom, - .level = static_cast(_s4.Rain), + .level = static_cast(_s4.Rain), }; gameState.weatherNext = { - .weatherType = WeatherType{ _s4.TargetWeather }, + .weatherType = Weather::Type{ _s4.TargetWeather }, .temperature = static_cast(_s4.TargetTemperature), - .weatherEffect = WeatherEffectType::None, + .weatherEffect = Weather::EffectType::None, .weatherGloom = _s4.TargetWeatherGloom, - .level = static_cast(_s4.TargetRain), + .level = static_cast(_s4.TargetRain), }; } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 6690440c18..6c70ebdb6e 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -44,13 +44,13 @@ #include "../scenario/Scenario.h" #include "../scenario/ScenarioRepository.h" #include "../scenario/ScenarioSources.h" -#include "../world/Climate.h" #include "../world/Entrance.h" #include "../world/Map.h" #include "../world/MapAnimation.h" #include "../world/Park.h" #include "../world/Scenery.h" #include "../world/TilePointerIndex.hpp" +#include "../world/Weather.h" #include "../world/tile_element/BannerElement.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/LargeSceneryElement.h" @@ -575,18 +575,18 @@ namespace OpenRCT2::RCT2 // Pad013CA747 gameState.weatherUpdateTimer = _s6.WeatherUpdateTimer; gameState.weatherCurrent = { - .weatherType = WeatherType{ _s6.CurrentWeather }, + .weatherType = Weather::Type{ _s6.CurrentWeather }, .temperature = static_cast(_s6.Temperature), - .weatherEffect = WeatherEffectType{ _s6.CurrentWeatherEffect }, + .weatherEffect = Weather::EffectType{ _s6.CurrentWeatherEffect }, .weatherGloom = _s6.CurrentWeatherGloom, - .level = static_cast(_s6.CurrentWeatherLevel), + .level = static_cast(_s6.CurrentWeatherLevel), }; gameState.weatherNext = { - .weatherType = WeatherType{ _s6.NextWeather }, + .weatherType = Weather::Type{ _s6.NextWeather }, .temperature = static_cast(_s6.NextTemperature), - .weatherEffect = WeatherEffectType{ _s6.NextWeatherEffect }, + .weatherEffect = Weather::EffectType{ _s6.NextWeatherEffect }, .weatherGloom = _s6.NextWeatherGloom, - .level = static_cast(_s6.NextWeatherLevel), + .level = static_cast(_s6.NextWeatherLevel), }; // News items diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index a46e1a922c..34e56996f6 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -49,13 +49,13 @@ #include "../ui/WindowManager.h" #include "../util/Util.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/Entrance.h" #include "../world/Footpath.h" #include "../world/Location.hpp" #include "../world/Map.h" #include "../world/Park.h" #include "../world/TileElementsView.h" +#include "../world/Weather.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" #include "../world/tile_element/TrackElement.h" @@ -1468,7 +1468,7 @@ static void RideBreakdownUpdate(Ride& ride) static Breakdown RideGetNewBreakdownProblem(const Ride& ride) { // Brake failure is more likely when it's raining or heavily snowing (HeavySnow and Blizzard) - _breakdownProblemProbabilities[EnumValue(Breakdown::brakesFailure)] = ClimateIsPrecipitating() ? 20 : 3; + _breakdownProblemProbabilities[EnumValue(Breakdown::brakesFailure)] = Weather::isPrecipitating() ? 20 : 3; if (!ride.canBreakDown()) return Breakdown::none; diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index e864030b89..8769b0831b 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -26,7 +26,6 @@ #include "../network/Network.h" #include "../ui/WindowManager.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/Entrance.h" #include "../world/Footpath.h" #include "../world/Location.hpp" @@ -35,6 +34,7 @@ #include "../world/Park.h" #include "../world/Scenery.h" #include "../world/TileElementsView.h" +#include "../world/Weather.h" #include "../world/tile_element/EntranceElement.h" #include "../world/tile_element/PathElement.h" #include "../world/tile_element/TileElement.h" diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 86eb89d904..94c35b94ca 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -55,11 +55,11 @@ #include "../ui/WindowManager.h" #include "../util/Util.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/Entrance.h" #include "../world/Map.h" #include "../world/Park.h" #include "../world/Scenery.h" +#include "../world/Weather.h" #include "../world/tile_element/TileElement.h" #include "../world/tile_element/TrackElement.h" #include "ScenarioRepository.h" diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index f9a4336fd2..90d48e3b07 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -53,7 +53,6 @@ #include "bindings/ride/ScRide.hpp" #include "bindings/ride/ScRideStation.hpp" #include "bindings/world/ScAward.hpp" - #include "bindings/world/ScClimate.hpp" #include "bindings/world/ScDate.hpp" #include "bindings/world/ScMap.hpp" #include "bindings/world/ScPark.hpp" @@ -62,6 +61,7 @@ #include "bindings/world/ScScenario.hpp" #include "bindings/world/ScTile.hpp" #include "bindings/world/ScTileElement.hpp" + #include "bindings/world/ScWeather.hpp" #include #include @@ -410,7 +410,7 @@ void ScriptEngine::Initialise() auto ctx = static_cast(_context); ScAward::Register(ctx); ScCheats::Register(ctx); - ScClimate::Register(ctx); + ScWeather::Register(ctx); ScWeatherState::Register(ctx); ScConfiguration::Register(ctx); ScConsole::Register(ctx); @@ -467,7 +467,7 @@ void ScriptEngine::Initialise() ScPlugin::Register(ctx); dukglue_register_global(ctx, std::make_shared(), "cheats"); - dukglue_register_global(ctx, std::make_shared(), "climate"); + dukglue_register_global(ctx, std::make_shared(), "climate"); dukglue_register_global(ctx, std::make_shared(_console), "console"); dukglue_register_global(ctx, std::make_shared(_execInfo, _hookEngine), "context"); dukglue_register_global(ctx, std::make_shared(), "date"); diff --git a/src/openrct2/scripting/bindings/world/ScClimate.hpp b/src/openrct2/scripting/bindings/world/ScWeather.hpp similarity index 80% rename from src/openrct2/scripting/bindings/world/ScClimate.hpp rename to src/openrct2/scripting/bindings/world/ScWeather.hpp index 2944a8b5e9..d6f4ee47a3 100644 --- a/src/openrct2/scripting/bindings/world/ScClimate.hpp +++ b/src/openrct2/scripting/bindings/world/ScWeather.hpp @@ -16,7 +16,7 @@ #include "../../../core/StringTypes.h" #include "../../../object/ClimateObject.h" #include "../../../object/ObjectManager.h" - #include "../../../world/Climate.h" + #include "../../../world/Weather.h" #include "../../Duktape.hpp" #include "../../ScriptEngine.h" @@ -52,32 +52,32 @@ namespace OpenRCT2::Scripting } }; - class ScClimate + class ScWeather { public: - static std::string WeatherTypeToString(WeatherType token) + static std::string WeatherTypeToString(Weather::Type token) { switch (token) { - case WeatherType::Sunny: + case Weather::Type::Sunny: return "sunny"; - case WeatherType::PartiallyCloudy: + case Weather::Type::PartiallyCloudy: return "partiallyCloudy"; - case WeatherType::Cloudy: + case Weather::Type::Cloudy: return "cloudy"; - case WeatherType::Rain: + case Weather::Type::Rain: return "rain"; - case WeatherType::HeavyRain: + case Weather::Type::HeavyRain: return "heavyRain"; - case WeatherType::Thunder: + case Weather::Type::Thunder: return "thunder"; - case WeatherType::Snow: + case Weather::Type::Snow: return "snow"; - case WeatherType::HeavySnow: + case Weather::Type::HeavySnow: return "heavySnow"; - case WeatherType::Blizzard: + case Weather::Type::Blizzard: return "blizzard"; - case WeatherType::Count: + case Weather::Type::Count: return {}; } return {}; @@ -109,9 +109,9 @@ namespace OpenRCT2::Scripting static void Register(duk_context* ctx) { - dukglue_register_property(ctx, &ScClimate::type_get, nullptr, "type"); - dukglue_register_property(ctx, &ScClimate::current_get, nullptr, "current"); - dukglue_register_property(ctx, &ScClimate::future_get, nullptr, "future"); + dukglue_register_property(ctx, &ScWeather::type_get, nullptr, "type"); + dukglue_register_property(ctx, &ScWeather::current_get, nullptr, "current"); + dukglue_register_property(ctx, &ScWeather::future_get, nullptr, "future"); } }; diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp deleted file mode 100644 index e6e3823d5b..0000000000 --- a/src/openrct2/world/Climate.cpp +++ /dev/null @@ -1,503 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2026 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "Climate.h" - -#include "../Context.h" -#include "../Game.h" -#include "../GameState.h" -#include "../OpenRCT2.h" -#include "../SpriteIds.h" -#include "../audio/Audio.h" -#include "../audio/AudioChannel.h" -#include "../audio/AudioMixer.h" -#include "../config/Config.h" -#include "../core/EnumUtils.hpp" -#include "../drawing/Drawing.h" -#include "../object/ClimateObject.h" -#include "../object/ObjectManager.h" -#include "../profiling/Profiling.h" -#include "../scenario/Scenario.h" -#include "../util/Util.h" -#include "../windows/Intent.h" - -#include -#include - -using namespace OpenRCT2; -using namespace OpenRCT2::Drawing; -using namespace OpenRCT2::Audio; - -struct WeatherTrait -{ - int8_t temperatureDelta; - WeatherEffectType effectLevel; - int8_t gloomLevel; - WeatherLevel level; - uint32_t spriteId; -}; - -// clang-format off -constexpr std::array kClimateWeatherTraits = { { - { 10, WeatherEffectType::None, 0, WeatherLevel::None, SPR_WEATHER_SUN }, // Sunny - { 5, WeatherEffectType::None, 0, WeatherLevel::None, SPR_WEATHER_SUN_CLOUD }, // Partially Cloudy - { 0, WeatherEffectType::None, 0, WeatherLevel::None, SPR_WEATHER_CLOUD }, // Cloudy - { -2, WeatherEffectType::Rain, 1, WeatherLevel::Light, SPR_WEATHER_LIGHT_RAIN }, // Rain - { -4, WeatherEffectType::Rain, 2, WeatherLevel::Heavy, SPR_WEATHER_HEAVY_RAIN }, // Heavy Rain - { 2, WeatherEffectType::Storm, 2, WeatherLevel::Heavy, SPR_WEATHER_STORM }, // Thunderstorm - { -10, WeatherEffectType::Snow, 1, WeatherLevel::Light, SPR_G2_WEATHER_SNOW }, // Snow - { -15, WeatherEffectType::Snow, 2, WeatherLevel::Heavy, SPR_G2_WEATHER_HEAVY_SNOW}, // Heavy Snow - { -20, WeatherEffectType::Blizzard, 2, WeatherLevel::Heavy, SPR_G2_WEATHER_BLIZZARD }, // Blizzard -} }; -// clang-format on - -constexpr int32_t kMaxThunderInstances = 2; - -enum class ThunderStatus -{ - none, - playing, -}; - -// Climate data -uint16_t gClimateLightningFlash; - -// Sound data -static int32_t _weatherVolume = 1; -static uint32_t _lightningTimer; -static uint32_t _thunderTimer; -static std::shared_ptr _thunderSoundChannels[kMaxThunderInstances]; -static ThunderStatus _thunderStatus[kMaxThunderInstances] = { - ThunderStatus::none, - ThunderStatus::none, -}; -static SoundId _thunderSoundId; -static int32_t _thunderVolume; -static int32_t _thunderStereoEcho = 0; -static std::shared_ptr _weatherSoundChannel; - -constexpr FilterPaletteID kClimateWeatherGloomColours[4] = { - FilterPaletteID::paletteNull, - FilterPaletteID::paletteDarken1, - FilterPaletteID::paletteDarken2, - FilterPaletteID::paletteDarken3, -}; - -static int8_t ClimateStepWeatherLevel(int8_t currentWeatherLevel, int8_t nextWeatherLevel); -static void ClimateDetermineFutureWeather(uint32_t randomValue); -static void ClimateUpdateWeatherSound(); -static void ClimateUpdateThunderSound(); -static void ClimateUpdateLightning(); -static void ClimateUpdateThunder(); -static void ClimatePlayThunder(int32_t instanceIndex, SoundId soundId, int32_t volume, int32_t pan); - -int32_t ClimateCelsiusToFahrenheit(int32_t celsius) -{ - return (celsius * 29) / 16 + 32; -} - -/** - * Set climate and determine start weather. - */ -void ClimateReset() -{ - auto& objManager = GetContext()->GetObjectManager(); - auto* climateObj = objManager.GetLoadedObject(0); - if (climateObj == nullptr) - return; - - int32_t month = GetDate().GetMonth(); - const WeatherPattern& pattern = climateObj->getPatternForMonth(month); - - auto weather = WeatherType::PartiallyCloudy; - const WeatherTrait& trait = kClimateWeatherTraits[EnumValue(weather)]; - - auto& gameState = getGameState(); - gameState.weatherCurrent.weatherType = weather; - gameState.weatherCurrent.temperature = pattern.baseTemperature + trait.temperatureDelta; - gameState.weatherCurrent.weatherEffect = trait.effectLevel; - gameState.weatherCurrent.weatherGloom = trait.gloomLevel; - gameState.weatherCurrent.level = trait.level; - - _lightningTimer = 0; - _thunderTimer = 0; - if (_weatherVolume != 1) - { - ClimateStopWeatherSound(); - _weatherVolume = 1; - } - - ClimateDetermineFutureWeather(ScenarioRand()); -} - -/** - * Weather & climate update iteration. - * Gradually changes the weather parameters towards their determined next values. - */ -void ClimateUpdate() -{ - PROFILED_FUNCTION(); - - auto& gameState = getGameState(); - - // Only do climate logic if playing (not in scenario editor or title screen) - if (gLegacyScene != LegacyScene::playing) - return; - - if (!getGameState().cheats.freezeWeather) - { - if (gameState.weatherUpdateTimer) - { - if (gameState.weatherUpdateTimer == 960) - { - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - ContextBroadcastIntent(&intent); - } - gameState.weatherUpdateTimer--; - } - else if (!(gameState.currentTicks & 0x7F)) - { - if (gameState.weatherCurrent.temperature == gameState.weatherNext.temperature) - { - if (gameState.weatherCurrent.weatherGloom == gameState.weatherNext.weatherGloom) - { - gameState.weatherCurrent.weatherEffect = gameState.weatherNext.weatherEffect; - _thunderTimer = 0; - _lightningTimer = 0; - - if (gameState.weatherCurrent.level == gameState.weatherNext.level) - { - gameState.weatherCurrent.weatherType = gameState.weatherNext.weatherType; - ClimateDetermineFutureWeather(ScenarioRand()); - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - ContextBroadcastIntent(&intent); - } - else if (gameState.weatherNext.level <= WeatherLevel::Heavy) - { - gameState.weatherCurrent.level = static_cast(ClimateStepWeatherLevel( - static_cast(gameState.weatherCurrent.level), - static_cast(gameState.weatherNext.level))); - } - } - else - { - gameState.weatherCurrent.weatherGloom = ClimateStepWeatherLevel( - gameState.weatherCurrent.weatherGloom, gameState.weatherNext.weatherGloom); - GfxInvalidateScreen(); - } - } - else - { - gameState.weatherCurrent.temperature = ClimateStepWeatherLevel( - gameState.weatherCurrent.temperature, gameState.weatherNext.temperature); - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - ContextBroadcastIntent(&intent); - } - } - } - - if (_thunderTimer != 0) - { - ClimateUpdateLightning(); - ClimateUpdateThunder(); - } - else - { - uint32_t thunderChance; - if (gameState.weatherCurrent.weatherEffect == WeatherEffectType::Storm) - thunderChance = 0x1B4; - else if (gameState.weatherCurrent.weatherEffect == WeatherEffectType::Blizzard) - thunderChance = 0x6D; - else - return; - // Create new thunder and lightning. Their amount is scaled inversely proportional - // to the game speed, otherwise they become annoying at very high speeds - if (uint32_t randomNumber = UtilRand(); (randomNumber & 0xFFFF) <= (thunderChance >> (gGameSpeed - 1))) - { - randomNumber >>= 16; - _thunderTimer = 43 + (randomNumber % 64); - _lightningTimer = randomNumber % 32; - } - } -} - -void ClimateForceWeather(WeatherType weather) -{ - auto& objManager = GetContext()->GetObjectManager(); - auto* climateObj = objManager.GetLoadedObject(0); - if (climateObj == nullptr) - return; - - int32_t month = GetDate().GetMonth(); - const WeatherPattern& pattern = climateObj->getPatternForMonth(month); - - const auto& trait = kClimateWeatherTraits[EnumValue(weather)]; - - auto& gameState = getGameState(); - gameState.weatherCurrent.weatherType = weather; - gameState.weatherCurrent.weatherGloom = trait.gloomLevel; - gameState.weatherCurrent.level = trait.level; - gameState.weatherCurrent.weatherEffect = trait.effectLevel; - gameState.weatherCurrent.temperature = pattern.baseTemperature + trait.temperatureDelta; - gameState.weatherUpdateTimer = 1920; - - ClimateDetermineFutureWeather(ScenarioRand()); - - // In case of change in gloom level force a complete redraw - GfxInvalidateScreen(); -} - -void ClimateUpdateSound() -{ - PROFILED_FUNCTION(); - - if (!IsAvailable()) - return; - - if (gLegacyScene == LegacyScene::titleSequence) - return; - - ClimateUpdateWeatherSound(); - ClimateUpdateThunderSound(); -} - -bool ClimateIsRaining() -{ - auto& weather = getGameState().weatherCurrent.weatherType; - return weather == WeatherType::Rain || weather == WeatherType::HeavyRain || weather == WeatherType::Thunder; -} - -bool ClimateIsSnowing() -{ - auto& weather = getGameState().weatherCurrent.weatherType; - return weather == WeatherType::Snow || weather == WeatherType::HeavySnow || weather == WeatherType::Blizzard; -} - -bool ClimateTransitioningToSnow() -{ - auto& weather = getGameState().weatherNext.weatherType; - return weather == WeatherType::Snow || weather == WeatherType::HeavySnow || weather == WeatherType::Blizzard; -} - -bool ClimateIsSnowingHeavily() -{ - auto& weather = getGameState().weatherCurrent.weatherType; - return weather == WeatherType::HeavySnow || weather == WeatherType::Blizzard; -} - -bool ClimateIsPrecipitating() -{ - return ClimateIsRaining() || ClimateIsSnowingHeavily(); -} - -bool WeatherIsDry(WeatherType weather) -{ - return weather == WeatherType::Sunny || weather == WeatherType::PartiallyCloudy || weather == WeatherType::Cloudy; -} - -bool ClimateHasWeatherEffect() -{ - const auto& weatherCurrent = getGameState().weatherCurrent; - // The game starts drawing rain whenever this level is not none. - return weatherCurrent.level != WeatherLevel::None; -} - -FilterPaletteID ClimateGetWeatherGloomPaletteId(const WeatherState& state) -{ - auto paletteId = FilterPaletteID::paletteNull; - auto gloom = state.weatherGloom; - if (gloom < std::size(kClimateWeatherGloomColours)) - { - paletteId = kClimateWeatherGloomColours[gloom]; - } - return paletteId; -} - -uint32_t ClimateGetWeatherSpriteId(const WeatherType weatherType) -{ - return kClimateWeatherTraits[EnumValue(weatherType)].spriteId; -} - -static int8_t ClimateStepWeatherLevel(int8_t currentWeatherLevel, int8_t nextWeatherLevel) -{ - if (nextWeatherLevel > currentWeatherLevel) - { - return currentWeatherLevel + 1; - } - - return currentWeatherLevel - 1; -} - -/** - * Calculates future weather development. - * RCT2 implements this as discrete probability distributions dependent on month and climate - * for nextWeather. The other weather parameters are then looked up depending only on the - * next weather. - */ -static void ClimateDetermineFutureWeather(uint32_t randomValue) -{ - auto& objManager = GetContext()->GetObjectManager(); - auto* climateObj = objManager.GetLoadedObject(0); - if (climateObj == nullptr) - return; - - int32_t month = GetDate().GetMonth(); - const WeatherPattern& pattern = climateObj->getPatternForMonth(month); - - // Generate a random index with values 0 up to randomBias-1 - // and choose weather from the distribution table accordingly - const auto randomIndex = ((randomValue % 256) * pattern.randomBias) / 256; - const auto nextWeather = pattern.distribution[randomIndex]; - - auto& gameState = getGameState(); - gameState.weatherNext.weatherType = nextWeather; - - const auto& nextWeatherTrait = kClimateWeatherTraits[EnumValue(nextWeather)]; - gameState.weatherNext.temperature = pattern.baseTemperature + nextWeatherTrait.temperatureDelta; - gameState.weatherNext.weatherEffect = nextWeatherTrait.effectLevel; - gameState.weatherNext.weatherGloom = nextWeatherTrait.gloomLevel; - gameState.weatherNext.level = nextWeatherTrait.level; - - gameState.weatherUpdateTimer = 1920; -} - -static void ClimateUpdateWeatherSound() -{ - if (getGameState().weatherCurrent.weatherEffect == WeatherEffectType::Rain - || getGameState().weatherCurrent.weatherEffect == WeatherEffectType::Storm) - { - // Start playing the weather sound - if (_weatherSoundChannel == nullptr || _weatherSoundChannel->IsDone()) - { - _weatherSoundChannel = CreateAudioChannel(SoundId::rain, true, DStoMixerVolume(-4000)); - } - if (_weatherVolume == 1) - { - _weatherVolume = -4000; - } - else - { - // Increase weather sound - _weatherVolume = std::min(-1400, _weatherVolume + 80); - if (_weatherSoundChannel != nullptr) - { - _weatherSoundChannel->SetVolume(DStoMixerVolume(_weatherVolume)); - } - } - } - else if (_weatherVolume != 1) - { - // Decrease weather sound - _weatherVolume -= 80; - if (_weatherVolume > -4000) - { - if (_weatherSoundChannel != nullptr) - { - _weatherSoundChannel->SetVolume(DStoMixerVolume(_weatherVolume)); - } - } - else - { - ClimateStopWeatherSound(); - _weatherVolume = 1; - } - } -} - -void ClimateStopWeatherSound() -{ - if (_weatherSoundChannel != nullptr) - { - _weatherSoundChannel->Stop(); - _weatherSoundChannel = nullptr; - } -} - -static void ClimateUpdateThunderSound() -{ - if (_thunderStereoEcho) - { - // Play thunder on right side - _thunderStereoEcho = 0; - ClimatePlayThunder(1, _thunderSoundId, _thunderVolume, 10000); - } - - // Stop thunder sounds if they have finished - for (int32_t i = 0; i < kMaxThunderInstances; i++) - { - if (_thunderStatus[i] != ThunderStatus::none) - { - auto& channel = _thunderSoundChannels[i]; - if (!channel->IsPlaying()) - { - channel->Stop(); - _thunderStatus[i] = ThunderStatus::none; - } - } - } -} - -static void ClimateUpdateLightning() -{ - if (_lightningTimer == 0) - return; - if (Config::Get().general.disableLightningEffect) - return; - if (!Config::Get().general.renderWeatherEffects && !Config::Get().general.renderWeatherGloom) - return; - - _lightningTimer--; - if (gClimateLightningFlash == 0) - { - if ((UtilRand() & 0xFFFF) <= 0x2000) - { - gClimateLightningFlash = 1; - } - } -} - -static void ClimateUpdateThunder() -{ - _thunderTimer--; - if (_thunderTimer == 0) - { - uint32_t randomNumber = UtilRand(); - if (randomNumber & 0x10000) - { - if (_thunderStatus[0] == ThunderStatus::none && _thunderStatus[1] == ThunderStatus::none) - { - // Play thunder on left side - _thunderSoundId = (randomNumber & 0x20000) ? SoundId::thunder1 : SoundId::thunder2; - _thunderVolume = (-(static_cast((randomNumber >> 18) & 0xFF))) * 8; - ClimatePlayThunder(0, _thunderSoundId, _thunderVolume, -10000); - - // Let thunder play on right side - _thunderStereoEcho = 1; - } - } - else - { - if (_thunderStatus[0] == ThunderStatus::none) - { - _thunderSoundId = (randomNumber & 0x20000) ? SoundId::thunder1 : SoundId::thunder2; - int32_t pan = (((randomNumber >> 18) & 0xFF) - 128) * 16; - ClimatePlayThunder(0, _thunderSoundId, 0, pan); - } - } - } -} - -static void ClimatePlayThunder(int32_t instanceIndex, SoundId soundId, int32_t volume, int32_t pan) -{ - _thunderSoundChannels[instanceIndex] = CreateAudioChannel(soundId, false, DStoMixerVolume(volume), DStoMixerPan(pan)); - if (_thunderSoundChannels[instanceIndex] != nullptr) - { - _thunderStatus[instanceIndex] = ThunderStatus::playing; - } -} diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h deleted file mode 100644 index db4c3d303b..0000000000 --- a/src/openrct2/world/Climate.h +++ /dev/null @@ -1,101 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2026 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#pragma once - -#include "../core/EnumUtils.hpp" - -#include -#include - -enum class WeatherType : uint8_t -{ - Sunny, - PartiallyCloudy, - Cloudy, - Rain, - HeavyRain, - Thunder, - Snow, - HeavySnow, - Blizzard, - Count -}; - -static constexpr auto kNumWeatherTypes = EnumValue(WeatherType::Count); -static constexpr auto kNumClimateMonths = 8; -static constexpr auto kWeatherDistSize = 23; - -struct WeatherPattern -{ - int8_t baseTemperature; - int8_t randomBias; - WeatherType distribution[kWeatherDistSize]; -}; - -struct TemperatureThresholds -{ - int8_t cold; - int8_t warm; -}; - -struct Climate -{ - std::array patterns; - TemperatureThresholds itemThresholds; -}; - -enum class WeatherEffectType : uint8_t -{ - None, - Rain, - Storm, - Snow, - Blizzard, -}; - -enum class WeatherLevel -{ - None, - Light, - Heavy, -}; - -struct WeatherState -{ - WeatherType weatherType; - int8_t temperature; - WeatherEffectType weatherEffect; - uint8_t weatherGloom; - WeatherLevel level; -}; - -extern uint16_t gClimateLightningFlash; - -int32_t ClimateCelsiusToFahrenheit(int32_t celsius); -void ClimateReset(); -void ClimateUpdate(); -void ClimateUpdateSound(); -void ClimateStopWeatherSound(); -void ClimateForceWeather(WeatherType weather); - -namespace OpenRCT2::Drawing -{ - enum class FilterPaletteID : int32_t; -} - -bool ClimateIsRaining(); -bool ClimateTransitioningToSnow(); -bool ClimateIsSnowing(); -bool ClimateIsSnowingHeavily(); -bool ClimateIsPrecipitating(); -bool WeatherIsDry(WeatherType); -bool ClimateHasWeatherEffect(); -OpenRCT2::Drawing::FilterPaletteID ClimateGetWeatherGloomPaletteId(const WeatherState& state); -uint32_t ClimateGetWeatherSpriteId(WeatherType weatherType); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 94dad74f34..68bb7141eb 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -48,7 +48,6 @@ #include "../windows/Intent.h" #include "../world/TilePointerIndex.hpp" #include "Banner.h" -#include "Climate.h" #include "Entrance.h" #include "Footpath.h" #include "MapAnimation.h" @@ -56,6 +55,7 @@ #include "Scenery.h" #include "TileElementsView.h" #include "TileInspector.h" +#include "Weather.h" #include "tile_element/BannerElement.h" #include "tile_element/EntranceElement.h" #include "tile_element/LargeSceneryElement.h" diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index bca7b96133..70367cdf11 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -183,7 +183,7 @@ void SmallSceneryElement::UpdateAge(const CoordsXY& sceneryPos) return; } - if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED) || WeatherIsDry(gameState.weatherCurrent.weatherType) + if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED) || Weather::isDry(gameState.weatherCurrent.weatherType) || GetAge() < 5) { IncreaseAge(sceneryPos); diff --git a/src/openrct2/world/Weather.cpp b/src/openrct2/world/Weather.cpp new file mode 100644 index 0000000000..8fd17ea512 --- /dev/null +++ b/src/openrct2/world/Weather.cpp @@ -0,0 +1,504 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "Weather.h" + +#include "../Context.h" +#include "../Game.h" +#include "../GameState.h" +#include "../OpenRCT2.h" +#include "../SpriteIds.h" +#include "../audio/Audio.h" +#include "../audio/AudioChannel.h" +#include "../audio/AudioMixer.h" +#include "../config/Config.h" +#include "../core/EnumUtils.hpp" +#include "../drawing/Drawing.h" +#include "../object/ClimateObject.h" +#include "../object/ObjectManager.h" +#include "../profiling/Profiling.h" +#include "../scenario/Scenario.h" +#include "../util/Util.h" +#include "../windows/Intent.h" + +#include +#include + +namespace OpenRCT2::Weather +{ + using namespace OpenRCT2::Drawing; + using namespace OpenRCT2::Audio; + + struct Trait + { + int8_t temperatureDelta; + EffectType effectLevel; + int8_t gloomLevel; + Level level; + uint32_t spriteId; + }; + + // clang-format off + constexpr std::array kWeatherTraits = { { + { 10, EffectType::None, 0, Level::None, SPR_WEATHER_SUN }, // Sunny + { 5, EffectType::None, 0, Level::None, SPR_WEATHER_SUN_CLOUD }, // Partially Cloudy + { 0, EffectType::None, 0, Level::None, SPR_WEATHER_CLOUD }, // Cloudy + { -2, EffectType::Rain, 1, Level::Light, SPR_WEATHER_LIGHT_RAIN }, // Rain + { -4, EffectType::Rain, 2, Level::Heavy, SPR_WEATHER_HEAVY_RAIN }, // Heavy Rain + { 2, EffectType::Storm, 2, Level::Heavy, SPR_WEATHER_STORM }, // Thunderstorm + { -10, EffectType::Snow, 1, Level::Light, SPR_G2_WEATHER_SNOW }, // Snow + { -15, EffectType::Snow, 2, Level::Heavy, SPR_G2_WEATHER_HEAVY_SNOW}, // Heavy Snow + { -20, EffectType::Blizzard, 2, Level::Heavy, SPR_G2_WEATHER_BLIZZARD }, // Blizzard + } }; + // clang-format on + + constexpr int32_t kMaxThunderInstances = 2; + + enum class ThunderStatus + { + none, + playing, + }; + + uint16_t gLightningFlash; + + // Sound data + static int32_t _weatherVolume = 1; + static uint32_t _lightningTimer; + static uint32_t _thunderTimer; + static std::shared_ptr _thunderSoundChannels[kMaxThunderInstances]; + static ThunderStatus _thunderStatus[kMaxThunderInstances] = { + ThunderStatus::none, + ThunderStatus::none, + }; + static SoundId _thunderSoundId; + static int32_t _thunderVolume; + static int32_t _thunderStereoEcho = 0; + static std::shared_ptr _weatherSoundChannel; + + constexpr FilterPaletteID kWeatherGloomColours[4] = { + FilterPaletteID::paletteNull, + FilterPaletteID::paletteDarken1, + FilterPaletteID::paletteDarken2, + FilterPaletteID::paletteDarken3, + }; + + static int8_t stepWeatherLevel(int8_t currentWeatherLevel, int8_t nextWeatherLevel); + static void determineFutureWeather(uint32_t randomValue); + static void updateWeatherSound(); + static void updateThunderSound(); + static void updateLightning(); + static void updateThunder(); + static void playThunder(int32_t instanceIndex, SoundId soundId, int32_t volume, int32_t pan); + + int32_t celsiusToFahrenheit(int32_t celsius) + { + return (celsius * 29) / 16 + 32; + } + + /** + * Set climate and determine start weather. + */ + void reset() + { + auto& objManager = GetContext()->GetObjectManager(); + auto* climateObj = objManager.GetLoadedObject(0); + if (climateObj == nullptr) + return; + + int32_t month = GetDate().GetMonth(); + const Weather::Pattern& pattern = climateObj->getPatternForMonth(month); + + auto weather = Weather::Type::PartiallyCloudy; + const Weather::Trait& trait = kWeatherTraits[EnumValue(weather)]; + + auto& gameState = getGameState(); + gameState.weatherCurrent.weatherType = weather; + gameState.weatherCurrent.temperature = pattern.baseTemperature + trait.temperatureDelta; + gameState.weatherCurrent.weatherEffect = trait.effectLevel; + gameState.weatherCurrent.weatherGloom = trait.gloomLevel; + gameState.weatherCurrent.level = trait.level; + + _lightningTimer = 0; + _thunderTimer = 0; + if (_weatherVolume != 1) + { + stopWeatherSound(); + _weatherVolume = 1; + } + + determineFutureWeather(ScenarioRand()); + } + + /** + * Weather & climate update iteration. + * Gradually changes the weather parameters towards their determined next values. + */ + void update() + { + PROFILED_FUNCTION(); + + auto& gameState = getGameState(); + + // Only do climate logic if playing (not in scenario editor or title screen) + if (gLegacyScene != LegacyScene::playing) + return; + + if (!getGameState().cheats.freezeWeather) + { + if (gameState.weatherUpdateTimer) + { + if (gameState.weatherUpdateTimer == 960) + { + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + ContextBroadcastIntent(&intent); + } + gameState.weatherUpdateTimer--; + } + else if (!(gameState.currentTicks & 0x7F)) + { + if (gameState.weatherCurrent.temperature == gameState.weatherNext.temperature) + { + if (gameState.weatherCurrent.weatherGloom == gameState.weatherNext.weatherGloom) + { + gameState.weatherCurrent.weatherEffect = gameState.weatherNext.weatherEffect; + _thunderTimer = 0; + _lightningTimer = 0; + + if (gameState.weatherCurrent.level == gameState.weatherNext.level) + { + gameState.weatherCurrent.weatherType = gameState.weatherNext.weatherType; + determineFutureWeather(ScenarioRand()); + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + ContextBroadcastIntent(&intent); + } + else if (gameState.weatherNext.level <= Weather::Level::Heavy) + { + gameState.weatherCurrent.level = static_cast(stepWeatherLevel( + static_cast(gameState.weatherCurrent.level), + static_cast(gameState.weatherNext.level))); + } + } + else + { + gameState.weatherCurrent.weatherGloom = stepWeatherLevel( + gameState.weatherCurrent.weatherGloom, gameState.weatherNext.weatherGloom); + GfxInvalidateScreen(); + } + } + else + { + gameState.weatherCurrent.temperature = stepWeatherLevel( + gameState.weatherCurrent.temperature, gameState.weatherNext.temperature); + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + ContextBroadcastIntent(&intent); + } + } + } + + if (_thunderTimer != 0) + { + updateLightning(); + updateThunder(); + } + else + { + uint32_t thunderChance; + if (gameState.weatherCurrent.weatherEffect == EffectType::Storm) + thunderChance = 0x1B4; + else if (gameState.weatherCurrent.weatherEffect == EffectType::Blizzard) + thunderChance = 0x6D; + else + return; + // Create new thunder and lightning. Their amount is scaled inversely proportional + // to the game speed, otherwise they become annoying at very high speeds + if (uint32_t randomNumber = UtilRand(); (randomNumber & 0xFFFF) <= (thunderChance >> (gGameSpeed - 1))) + { + randomNumber >>= 16; + _thunderTimer = 43 + (randomNumber % 64); + _lightningTimer = randomNumber % 32; + } + } + } + + void forceWeather(Type weather) + { + auto& objManager = GetContext()->GetObjectManager(); + auto* climateObj = objManager.GetLoadedObject(0); + if (climateObj == nullptr) + return; + + int32_t month = GetDate().GetMonth(); + const Pattern& pattern = climateObj->getPatternForMonth(month); + + const auto& trait = kWeatherTraits[EnumValue(weather)]; + + auto& gameState = getGameState(); + gameState.weatherCurrent.weatherType = weather; + gameState.weatherCurrent.weatherGloom = trait.gloomLevel; + gameState.weatherCurrent.level = trait.level; + gameState.weatherCurrent.weatherEffect = trait.effectLevel; + gameState.weatherCurrent.temperature = pattern.baseTemperature + trait.temperatureDelta; + gameState.weatherUpdateTimer = 1920; + + determineFutureWeather(ScenarioRand()); + + // In case of change in gloom level force a complete redraw + GfxInvalidateScreen(); + } + + void updateSound() + { + PROFILED_FUNCTION(); + + if (!IsAvailable()) + return; + + if (gLegacyScene == LegacyScene::titleSequence) + return; + + updateWeatherSound(); + updateThunderSound(); + } + + bool isRaining() + { + auto& weather = getGameState().weatherCurrent.weatherType; + return weather == Type::Rain || weather == Type::HeavyRain || weather == Type::Thunder; + } + + bool isSnowing() + { + auto& weather = getGameState().weatherCurrent.weatherType; + return weather == Type::Snow || weather == Type::HeavySnow || weather == Type::Blizzard; + } + + bool isTransitioningToSnow() + { + auto& weather = getGameState().weatherNext.weatherType; + return weather == Type::Snow || weather == Type::HeavySnow || weather == Type::Blizzard; + } + + bool isSnowingHeavily() + { + auto& weather = getGameState().weatherCurrent.weatherType; + return weather == Type::HeavySnow || weather == Type::Blizzard; + } + + bool isPrecipitating() + { + return isRaining() || isSnowingHeavily(); + } + + bool isDry(Type weather) + { + return weather == Type::Sunny || weather == Type::PartiallyCloudy || weather == Type::Cloudy; + } + + bool hasWeatherEffect() + { + const auto& weatherCurrent = getGameState().weatherCurrent; + // The game starts drawing rain whenever this level is not none. + return weatherCurrent.level != Weather::Level::None; + } + + FilterPaletteID getWeatherGloomPaletteId(const State& state) + { + auto paletteId = FilterPaletteID::paletteNull; + auto gloom = state.weatherGloom; + if (gloom < std::size(kWeatherGloomColours)) + { + paletteId = kWeatherGloomColours[gloom]; + } + return paletteId; + } + + uint32_t getWeatherSpriteId(const Type weatherType) + { + return kWeatherTraits[EnumValue(weatherType)].spriteId; + } + + static int8_t stepWeatherLevel(int8_t currentWeatherLevel, int8_t nextWeatherLevel) + { + if (nextWeatherLevel > currentWeatherLevel) + { + return currentWeatherLevel + 1; + } + + return currentWeatherLevel - 1; + } + + /** + * Calculates future weather development. + * RCT2 implements this as discrete probability distributions dependent on month and climate + * for nextWeather. The other weather parameters are then looked up depending only on the + * next weather. + */ + static void determineFutureWeather(uint32_t randomValue) + { + auto& objManager = GetContext()->GetObjectManager(); + auto* climateObj = objManager.GetLoadedObject(0); + if (climateObj == nullptr) + return; + + int32_t month = GetDate().GetMonth(); + const Pattern& pattern = climateObj->getPatternForMonth(month); + + // Generate a random index with values 0 up to randomBias-1 + // and choose weather from the distribution table accordingly + const auto randomIndex = ((randomValue % 256) * pattern.randomBias) / 256; + const auto nextWeather = pattern.distribution[randomIndex]; + + auto& gameState = getGameState(); + gameState.weatherNext.weatherType = nextWeather; + + const auto& nextWeatherTrait = kWeatherTraits[EnumValue(nextWeather)]; + gameState.weatherNext.temperature = pattern.baseTemperature + nextWeatherTrait.temperatureDelta; + gameState.weatherNext.weatherEffect = nextWeatherTrait.effectLevel; + gameState.weatherNext.weatherGloom = nextWeatherTrait.gloomLevel; + gameState.weatherNext.level = nextWeatherTrait.level; + + gameState.weatherUpdateTimer = 1920; + } + + static void updateWeatherSound() + { + if (getGameState().weatherCurrent.weatherEffect == EffectType::Rain + || getGameState().weatherCurrent.weatherEffect == EffectType::Storm) + { + // Start playing the weather sound + if (_weatherSoundChannel == nullptr || _weatherSoundChannel->IsDone()) + { + _weatherSoundChannel = CreateAudioChannel(SoundId::rain, true, DStoMixerVolume(-4000)); + } + if (_weatherVolume == 1) + { + _weatherVolume = -4000; + } + else + { + // Increase weather sound + _weatherVolume = std::min(-1400, _weatherVolume + 80); + if (_weatherSoundChannel != nullptr) + { + _weatherSoundChannel->SetVolume(DStoMixerVolume(_weatherVolume)); + } + } + } + else if (_weatherVolume != 1) + { + // Decrease weather sound + _weatherVolume -= 80; + if (_weatherVolume > -4000) + { + if (_weatherSoundChannel != nullptr) + { + _weatherSoundChannel->SetVolume(DStoMixerVolume(_weatherVolume)); + } + } + else + { + stopWeatherSound(); + _weatherVolume = 1; + } + } + } + + void stopWeatherSound() + { + if (_weatherSoundChannel != nullptr) + { + _weatherSoundChannel->Stop(); + _weatherSoundChannel = nullptr; + } + } + + static void updateThunderSound() + { + if (_thunderStereoEcho) + { + // Play thunder on right side + _thunderStereoEcho = 0; + playThunder(1, _thunderSoundId, _thunderVolume, 10000); + } + + // Stop thunder sounds if they have finished + for (int32_t i = 0; i < kMaxThunderInstances; i++) + { + if (_thunderStatus[i] != ThunderStatus::none) + { + auto& channel = _thunderSoundChannels[i]; + if (!channel->IsPlaying()) + { + channel->Stop(); + _thunderStatus[i] = ThunderStatus::none; + } + } + } + } + + static void updateLightning() + { + if (_lightningTimer == 0) + return; + if (Config::Get().general.disableLightningEffect) + return; + if (!Config::Get().general.renderWeatherEffects && !Config::Get().general.renderWeatherGloom) + return; + + _lightningTimer--; + if (gLightningFlash == 0) + { + if ((UtilRand() & 0xFFFF) <= 0x2000) + { + gLightningFlash = 1; + } + } + } + + static void updateThunder() + { + _thunderTimer--; + if (_thunderTimer == 0) + { + uint32_t randomNumber = UtilRand(); + if (randomNumber & 0x10000) + { + if (_thunderStatus[0] == ThunderStatus::none && _thunderStatus[1] == ThunderStatus::none) + { + // Play thunder on left side + _thunderSoundId = (randomNumber & 0x20000) ? SoundId::thunder1 : SoundId::thunder2; + _thunderVolume = (-(static_cast((randomNumber >> 18) & 0xFF))) * 8; + playThunder(0, _thunderSoundId, _thunderVolume, -10000); + + // Let thunder play on right side + _thunderStereoEcho = 1; + } + } + else + { + if (_thunderStatus[0] == ThunderStatus::none) + { + _thunderSoundId = (randomNumber & 0x20000) ? SoundId::thunder1 : SoundId::thunder2; + int32_t pan = (((randomNumber >> 18) & 0xFF) - 128) * 16; + playThunder(0, _thunderSoundId, 0, pan); + } + } + } + } + + static void playThunder(int32_t instanceIndex, SoundId soundId, int32_t volume, int32_t pan) + { + _thunderSoundChannels[instanceIndex] = CreateAudioChannel(soundId, false, DStoMixerVolume(volume), DStoMixerPan(pan)); + if (_thunderSoundChannels[instanceIndex] != nullptr) + { + _thunderStatus[instanceIndex] = ThunderStatus::playing; + } + } +} // namespace OpenRCT2::Weather diff --git a/src/openrct2/world/Weather.h b/src/openrct2/world/Weather.h new file mode 100644 index 0000000000..121e686e93 --- /dev/null +++ b/src/openrct2/world/Weather.h @@ -0,0 +1,104 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../core/EnumUtils.hpp" + +#include +#include + +namespace OpenRCT2::Drawing +{ + enum class FilterPaletteID : int32_t; +} + +namespace OpenRCT2::Weather +{ + enum class Type : uint8_t + { + Sunny, + PartiallyCloudy, + Cloudy, + Rain, + HeavyRain, + Thunder, + Snow, + HeavySnow, + Blizzard, + Count + }; + + static constexpr auto kNumWeatherTypes = EnumValue(Type::Count); + static constexpr auto kNumClimateMonths = 8; + static constexpr auto kWeatherDistSize = 23; + + struct Pattern + { + int8_t baseTemperature; + int8_t randomBias; + Type distribution[kWeatherDistSize]; + }; + + struct TemperatureThresholds + { + int8_t cold; + int8_t warm; + }; + + struct Climate + { + std::array patterns; + TemperatureThresholds itemThresholds; + }; + + enum class EffectType : uint8_t + { + None, + Rain, + Storm, + Snow, + Blizzard, + }; + + enum class Level + { + None, + Light, + Heavy, + }; + + struct State + { + Type weatherType; + int8_t temperature; + EffectType weatherEffect; + uint8_t weatherGloom; + Level level; + }; + + extern uint16_t gLightningFlash; + + int32_t celsiusToFahrenheit(int32_t celsius); + void reset(); + void update(); + void updateSound(); + void stopWeatherSound(); + void forceWeather(Type weather); + + bool isRaining(); + bool isTransitioningToSnow(); + bool isSnowing(); + bool isSnowingHeavily(); + bool isPrecipitating(); + bool isDry(Type); + bool hasWeatherEffect(); + Drawing::FilterPaletteID getWeatherGloomPaletteId(const State& state); + uint32_t getWeatherSpriteId(Type weatherType); +} // namespace OpenRCT2::Weather