summaryrefslogtreecommitdiff
path: root/src/KingSystem/World/worldWeatherMgr.cpp
diff options
context:
space:
mode:
authorsavage13 <savage13@gmail.com>2022-08-08 06:35:44 -0400
committerGitHub <noreply@github.com>2022-08-08 11:35:44 +0100
commit42e87bb99247789fb1bbeae4e33510a20d692ecf (patch)
tree32192fbf69eacded284ad57dcb6c628e24e75c18 /src/KingSystem/World/worldWeatherMgr.cpp
parentcef9c4a1b8f8f588ddc1528f89297e1036b45207 (diff)
Added WeatherMgr::rollNewWeather (#100)
Diffstat (limited to 'src/KingSystem/World/worldWeatherMgr.cpp')
-rw-r--r--src/KingSystem/World/worldWeatherMgr.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/KingSystem/World/worldWeatherMgr.cpp b/src/KingSystem/World/worldWeatherMgr.cpp
index d43706ba..d3407a83 100644
--- a/src/KingSystem/World/worldWeatherMgr.cpp
+++ b/src/KingSystem/World/worldWeatherMgr.cpp
@@ -1 +1,39 @@
#include "KingSystem/World/worldWeatherMgr.h"
+#include <random/seadGlobalRandom.h>
+#include "KingSystem/GameData/gdtManager.h"
+#include "KingSystem/World/worldManager.h"
+
+namespace ksys::world {
+
+WeatherType WeatherMgr::rollNewWeather(Climate climate) {
+ auto* wm = Manager::instance();
+ int random = sead::GlobalRandom::instance()->getU32(99);
+ WeatherType weather = [&] {
+ const std::pair<WeatherType, int> rates[] = {
+ {WeatherType::Bluesky, wm->getWeatherBlueskyRate(climate) - 1},
+ {WeatherType::Cloudy, wm->getWeatherCloudyRate(climate)},
+ {WeatherType::Rain, wm->getWeatherRainRate(climate)},
+ {WeatherType::HeavyRain, wm->getWeatherHeavyRainRate(climate)},
+ };
+ for (auto [type, rate] : rates) {
+ if (random <= rate)
+ return type;
+ random -= rate;
+ }
+ return WeatherType::ThunderRain;
+ }();
+
+ if (wm->getEnvMgr()->isWaterRelicRainOn(climate))
+ weather = WeatherType::Bluesky;
+
+ bool plateau_done = false;
+ auto glider_handle = Manager::instance()->getTimeMgr()->isGetPlayerStole2Flag();
+ if (glider_handle != gdt::InvalidHandle) {
+ gdt::Manager::instance()->getBool(glider_handle, &plateau_done, true);
+ }
+
+ if (plateau_done || weather == WeatherType::Bluesky || weather == WeatherType::Cloudy)
+ return weather;
+ return WeatherType::Bluesky;
+}
+} // namespace ksys::world