Last active
February 24, 2020 08:35
-
-
Save Slattz/5a8c8ec20277b5e9c2883fbf1df325d7 to your computer and use it in GitHub Desktop.
[ACNL] Weather Stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Weather Values: | |
0: Sky completely clear | |
1: Few Clouds, but clear weather | |
2: Dark sky/clouds to signify rain is coming, clear weather | |
3: Sky completely filled with grey clouds, Light Rain | |
4: Black clouds, Heavy Rain w/ Thunder+Lightning | |
5: Sky completely filled with light grey clouds, Light Snow | |
6: Black clouds, Heavy Snow, looks kinda 'foggy' | |
7+: Invalid, Music doesn't play and weather is always clear | |
Cherry Blossoms and Confetti have no weather ids | |
*/ | |
static const u8 predetermined_weather[52][24] = | |
{ | |
{0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0}, | |
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1}, | |
{1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1}, | |
{1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1}, | |
{1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1}, | |
{2,2,2,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1}, | |
{2,2,2,2,1,1,2,2,2,1,1,2,2,2,2,2,2,1,1,1,1,2,2,2}, | |
{2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2}, | |
{2,2,3,3,3,2,2,2,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2}, | |
{3,2,2,1,2,3,3,3,3,3,3,2,2,2,3,3,3,2,2,2,2,3,3,3}, | |
{3,3,3,2,2,3,3,2,2,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{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, | |
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} | |
}; | |
//off_CurrentTime: pointer for the game's current time. 0xAD56B0 (EUR 1.5) | |
u8 GetCurrentWeather(u32 off_CurrentTime) { | |
/* This is current weather used by the game in the going to/coming from island 'cutscenes'. Uses normal weather values. May be used for other things too. It is usually 0x7 except where it's used.*/ | |
static const u32 off_WeatherForIslandCutscene = 0x95DFB0; //EUR 1.5 | |
u8 weathervalue; | |
u8 savevalue; | |
u8 islandCutsceneWeather; | |
u8 room = GetRoomID(); | |
if (room == 0x5D || room == 0x99 || room == 0x9B) { //if Train, GardenManualImport, or GardenPlusUpdate | |
return 0; //Clear weather | |
} | |
islandCutsceneWeather = *(u8 *)off_WeatherForIslandCutscene; | |
if (islandCutsceneWeather != 7) //If it's not the Invalid ID | |
return islandCutsceneWeather; | |
room = GetRoomID(); | |
if(CheckRoomID(0x20000, room)) //Checks if room >= 0x67 && room <= 0x8D; All Island room ids | |
savevalue = GetIslandWeatherByte(); //Haven't checked what function does, just assumption. Not Re'd | |
else savevalue = GetWeatherByteFromSave(); //Gets weather from save (and other places too?). Not Re'd, has been step throuh | |
weathervalue = *(u8 *)off_WeatherForIslandCutscene; | |
if (weathervalue == 7) | |
{ | |
u8 hour = *(u8 *)(off_CurrentTime+7); //Get hour from u64 time value | |
hour-=6; | |
if (hour<0) //Checks if current time is between 12am and 5am. | |
hour+=24; //If so, add 24 hrs | |
if (savevalue < 52 && hour < 24) { //Checks: 1) weathervalue won't cause read from OOB in array, 2) hour is actually an hour in the day | |
weathervalue = predetermined_weather[savevalue][hour]; | |
} | |
} | |
room = GetRoomID(); | |
if(CheckRoomID(0x20000, room)) //Checks if room >= 0x67 && room <= 0x8D; All Island room ids | |
return weathervalue; | |
/* This isn't a mistake, game checks twice ¯\_(ツ)_/¯ */ | |
room = GetRoomID(); | |
if(CheckRoomID(0x20000, room)) //Checks if room >= 0x67 && room <= 0x8D; All Island room ids | |
return weathervalue; | |
if (GetSeason(8) == 1) { //Checking if season is winter assumably. Not Re'd | |
if (weathervalue == 3) | |
weathervalue = 5; //Changes light rain to light snow | |
else if (weathervalue == 4) | |
weathervalue = 6; //Changes heavy rain to heavy snow | |
} | |
return weathervalue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment