From 633a2d313eb3461463f53dc30273d2f007a4ef85 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:43:49 +0100 Subject: [PATCH] weather coord events --- asm/macros/map.inc | 1 - src/coord_event_weather.c | 141 ++++++++++++++++++++++++++++---------- 2 files changed, 105 insertions(+), 37 deletions(-) diff --git a/asm/macros/map.inc b/asm/macros/map.inc index e688160c7..95b64beed 100644 --- a/asm/macros/map.inc +++ b/asm/macros/map.inc @@ -78,7 +78,6 @@ .endm @ Defines a weather coord event for map data. Any coord event is treated as a weather coord event if its script is NULL. - @ NOTE: In FRLG, the weather handling functions are dummied out. See src/coord_event_weather.c .macro coord_weather_event x:req, y:req, elevation:req, weather:req coord_event \x, \y, \elevation, \weather, 0, NULL .endm diff --git a/src/coord_event_weather.c b/src/coord_event_weather.c index ca1da728d..5f6af6d5e 100644 --- a/src/coord_event_weather.c +++ b/src/coord_event_weather.c @@ -1,48 +1,117 @@ #include "global.h" +#include "field_weather.h" #include "constants/weather.h" -// These were all dummied out because it's always sunny in Viridian -void WeatherCoordEvent_SunnyClouds(void) {} -void WeatherCoordEvent_Sunny(void) {} -void WeatherCoordEvent_Rain(void) {} -void WeatherCoordEvent_Snow(void) {} -void WeatherCoordEvent_RainThunderstorm(void) {} -void WeatherCoordEvent_FogHorizontal(void) {} -void WeatherCoordEvent_VolcanicAsh(void) {} -void WeatherCoordEvent_Sandstorm(void) {} -void WeatherCoordEvent_FogDiagonal(void) {} -void WeatherCoordEvent_Underwater(void) {} -void WeatherCoordEvent_Shade(void) {} -void WeatherCoordEvent_Route119Cycle(void) {} -void WeatherCoordEvent_Route123Cycle(void) {} - -static struct { - u8 weatherId; - void (*callback)(void); -} const sWeatherCoordEventFuncs[] = { - {WEATHER_SUNNY_CLOUDS, WeatherCoordEvent_SunnyClouds }, - {WEATHER_SUNNY, WeatherCoordEvent_Sunny }, - {WEATHER_RAIN, WeatherCoordEvent_Rain }, - {WEATHER_SNOW, WeatherCoordEvent_Snow }, - {WEATHER_RAIN_THUNDERSTORM, WeatherCoordEvent_RainThunderstorm}, - {WEATHER_FOG_HORIZONTAL, WeatherCoordEvent_FogHorizontal }, - {WEATHER_VOLCANIC_ASH, WeatherCoordEvent_VolcanicAsh }, - {WEATHER_SANDSTORM, WeatherCoordEvent_Sandstorm }, - {WEATHER_FOG_DIAGONAL, WeatherCoordEvent_FogDiagonal }, - {WEATHER_UNDERWATER, WeatherCoordEvent_Underwater }, - {WEATHER_SHADE, WeatherCoordEvent_Shade }, - {WEATHER_ROUTE119_CYCLE, WeatherCoordEvent_Route119Cycle }, - {WEATHER_ROUTE123_CYCLE, WeatherCoordEvent_Route123Cycle } +struct CoordEventWeather +{ + u8 coordEventWeather; + void (*func)(void); }; -void DoCoordEventWeather(u8 weatherId) +static void CoordEventWeather_Clouds(void); +static void CoordEventWeather_Sunny(void); +static void CoordEventWeather_Rain(void); +static void CoordEventWeather_Snow(void); +static void CoordEventWeather_Thunderstorm(void); +static void CoordEventWeather_HorizontalFog(void); +static void CoordEventWeather_DiagonalFog(void); +static void CoordEventWeather_Ash(void); +static void CoordEventWeather_Sandstorm(void); +static void CoordEventWeather_Shade(void); +static void CoordEventWeather_Drought(void); +static void CoordEventWeather_Route119Cycle(void); +static void CoordEventWeather_Route123Cycle(void); + +static const struct CoordEventWeather sCoordEventWeatherFuncs[] = +{ + { COORD_EVENT_WEATHER_SUNNY_CLOUDS, CoordEventWeather_Clouds }, + { COORD_EVENT_WEATHER_SUNNY, CoordEventWeather_Sunny }, + { COORD_EVENT_WEATHER_RAIN, CoordEventWeather_Rain }, + { COORD_EVENT_WEATHER_SNOW, CoordEventWeather_Snow }, + { COORD_EVENT_WEATHER_RAIN_THUNDERSTORM, CoordEventWeather_Thunderstorm }, + { COORD_EVENT_WEATHER_FOG_HORIZONTAL, CoordEventWeather_HorizontalFog }, + { COORD_EVENT_WEATHER_FOG_DIAGONAL, CoordEventWeather_DiagonalFog }, + { COORD_EVENT_WEATHER_VOLCANIC_ASH, CoordEventWeather_Ash }, + { COORD_EVENT_WEATHER_SANDSTORM, CoordEventWeather_Sandstorm }, + { COORD_EVENT_WEATHER_SHADE, CoordEventWeather_Shade }, + { COORD_EVENT_WEATHER_DROUGHT, CoordEventWeather_Drought }, + { COORD_EVENT_WEATHER_ROUTE119_CYCLE, CoordEventWeather_Route119Cycle }, + { COORD_EVENT_WEATHER_ROUTE123_CYCLE, CoordEventWeather_Route123Cycle }, +}; + +static void CoordEventWeather_Clouds(void) +{ + SetWeather(WEATHER_SUNNY_CLOUDS); +} + +static void CoordEventWeather_Sunny(void) +{ + SetWeather(WEATHER_SUNNY); +} + +static void CoordEventWeather_Rain(void) +{ + SetWeather(WEATHER_RAIN); +} + +static void CoordEventWeather_Snow(void) +{ + SetWeather(WEATHER_SNOW); +} + +static void CoordEventWeather_Thunderstorm(void) +{ + SetWeather(WEATHER_RAIN_THUNDERSTORM); +} + +static void CoordEventWeather_HorizontalFog(void) +{ + SetWeather(WEATHER_FOG_HORIZONTAL); +} + +static void CoordEventWeather_DiagonalFog(void) +{ + SetWeather(WEATHER_FOG_DIAGONAL); +} + +static void CoordEventWeather_Ash(void) +{ + SetWeather(WEATHER_VOLCANIC_ASH); +} + +static void CoordEventWeather_Sandstorm(void) +{ + SetWeather(WEATHER_SANDSTORM); +} + +static void CoordEventWeather_Shade(void) +{ + SetWeather(WEATHER_SHADE); +} + +static void CoordEventWeather_Drought(void) +{ + SetWeather(WEATHER_DROUGHT); +} + +static void CoordEventWeather_Route119Cycle(void) +{ + SetWeather(WEATHER_ROUTE119_CYCLE); +} + +static void CoordEventWeather_Route123Cycle(void) +{ + SetWeather(WEATHER_ROUTE123_CYCLE); +} + +void DoCoordEventWeather(u8 coordEventWeather) { u8 i; - for (i = 0; i < NELEMS(sWeatherCoordEventFuncs); i++) + for (i = 0; i < ARRAY_COUNT(sCoordEventWeatherFuncs); i++) { - if (sWeatherCoordEventFuncs[i].weatherId == weatherId) + if (sCoordEventWeatherFuncs[i].coordEventWeather == coordEventWeather) { - sWeatherCoordEventFuncs[i].callback(); + sCoordEventWeatherFuncs[i].func(); return; } }