Sync field weather effects

This commit is contained in:
GriffinR
2022-09-06 15:14:27 -04:00
parent b3c7b9e09f
commit 212e455aae
2 changed files with 167 additions and 126 deletions
+20 -6
View File
@@ -4,6 +4,20 @@
#include "global.h" #include "global.h"
#include "constants/field_weather.h" #include "constants/field_weather.h"
#define TAG_WEATHER_START 0x1200
enum {
GFXTAG_CLOUD = TAG_WEATHER_START,
GFXTAG_FOG_H,
GFXTAG_ASH,
GFXTAG_FOG_D,
GFXTAG_SANDSTORM,
GFXTAG_BUBBLE,
GFXTAG_RAIN,
};
enum {
PALTAG_WEATHER = TAG_WEATHER_START,
};
struct Weather struct Weather
{ {
union union
@@ -54,14 +68,14 @@ struct Weather
u8 rainStrength; u8 rainStrength;
bool8 cloudSpritesCreated; bool8 cloudSpritesCreated;
u16 snowflakeVisibleCounter; u16 snowflakeVisibleCounter;
u16 unknown_6E2; u16 snowflakeTimer;
u8 snowflakeSpriteCount; u8 snowflakeSpriteCount;
u8 targetSnowflakeSpriteCount; u8 targetSnowflakeSpriteCount;
u16 unknown_6E6; u16 thunderDelay;
u16 thunderCounter; u16 thunderCounter;
u8 unknown_6EA; bool8 thunderAllowEnd;
u8 unknown_6EB; bool8 thunderSkipShort;
u8 unknown_6EC; u8 thunderShortRetries;
bool8 thunderTriggered; bool8 thunderTriggered;
u16 fogHScrollPosX; u16 fogHScrollPosX;
u16 fogHScrollCounter; u16 fogHScrollCounter;
@@ -70,7 +84,7 @@ struct Weather
u8 lightenedFogSpritePalsCount; u8 lightenedFogSpritePalsCount;
bool8 fogHSpritesCreated; bool8 fogHSpritesCreated;
u16 ashBaseSpritesX; u16 ashBaseSpritesX;
u16 unknown_6FE; u16 ashUnused;
bool8 ashSpritesCreated; bool8 ashSpritesCreated;
u32 sandstormXOffset; u32 sandstormXOffset;
u32 sandstormYOffset; u32 sandstormYOffset;
+147 -120
View File
@@ -30,7 +30,7 @@ static const struct Coords16 sCloudSpriteMapCoords[] = {
static const struct SpriteSheet sCloudSpriteSheet = { static const struct SpriteSheet sCloudSpriteSheet = {
.data = gWeatherCloudTiles, .data = gWeatherCloudTiles,
.size = 0x0800, .size = 0x0800,
.tag = 0x1200 .tag = GFXTAG_CLOUD
}; };
static const struct OamData sCloudSpriteOamData = { static const struct OamData sCloudSpriteOamData = {
@@ -59,8 +59,8 @@ static const union AnimCmd *const sCloudSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sCloudSpriteTemplate = { static const struct SpriteTemplate sCloudSpriteTemplate = {
.tileTag = 0x1200, .tileTag = GFXTAG_CLOUD,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sCloudSpriteOamData, .oam = &sCloudSpriteOamData,
.anims = sCloudSpriteAnimCmds, .anims = sCloudSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -189,7 +189,7 @@ static void DestroyCloudSprites(void)
DestroySprite(gWeatherPtr->sprites.s1.cloudSprites[i]); DestroySprite(gWeatherPtr->sprites.s1.cloudSprites[i]);
} }
FreeSpriteTilesByTag(0x1200); FreeSpriteTilesByTag(GFXTAG_CLOUD);
gWeatherPtr->cloudSpritesCreated = FALSE; gWeatherPtr->cloudSpritesCreated = FALSE;
} }
@@ -405,8 +405,8 @@ static const union AnimCmd *const sRainSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sRainSpriteTemplate = { static const struct SpriteTemplate sRainSpriteTemplate = {
.tileTag = 0x1206, .tileTag = GFXTAG_RAIN,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sRainSpriteOamData, .oam = &sRainSpriteOamData,
.anims = sRainSpriteAnimCmds, .anims = sRainSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -431,7 +431,7 @@ static const u16 sRainSpriteFallingDurations[][2] = {
static const struct SpriteSheet sRainSpriteSheet = { static const struct SpriteSheet sRainSpriteSheet = {
.data = gWeatherRainTiles, .data = gWeatherRainTiles,
.size = 0x0600, .size = 0x0600,
.tag = 0x1206, .tag = GFXTAG_RAIN,
}; };
void Rain_InitVars(void) void Rain_InitVars(void)
@@ -482,8 +482,8 @@ bool8 Rain_Finish(void)
{ {
case 0: case 0:
if (gWeatherPtr->nextWeather == WEATHER_RAIN if (gWeatherPtr->nextWeather == WEATHER_RAIN
|| gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM || gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM
|| gWeatherPtr->nextWeather == WEATHER_DOWNPOUR) || gWeatherPtr->nextWeather == WEATHER_DOWNPOUR)
{ {
gWeatherPtr->finishStep = 0xFF; gWeatherPtr->finishStep = 0xFF;
return FALSE; return FALSE;
@@ -524,8 +524,7 @@ static void StartRainSpriteFall(struct Sprite *sprite)
if (sprite->tRandom == 0) if (sprite->tRandom == 0)
sprite->tRandom = 361; sprite->tRandom = 361;
// Standard RNG sequence. rand = ISO_RANDOMIZE2(sprite->tRandom);
rand = sprite->tRandom * 1103515245 + 12345;
sprite->tRandom = ((rand & 0x7FFF0000) >> 16) % 600; sprite->tRandom = ((rand & 0x7FFF0000) >> 16) % 600;
numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0]; numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0];
@@ -563,8 +562,8 @@ static void UpdateRainSprite(struct Sprite *sprite)
sprite->y = sprite->tPosY >> 4; sprite->y = sprite->tPosY >> 4;
if (sprite->tActive if (sprite->tActive
&& (sprite->x >= -8 && sprite->x <= 248) && (sprite->x >= -8 && sprite->x <= DISPLAY_WIDTH + 8)
&& sprite->y >= -16 && sprite->y <= 176) && sprite->y >= -16 && sprite->y <= DISPLAY_HEIGHT + 16)
sprite->invisible = FALSE; sprite->invisible = FALSE;
else else
sprite->invisible = TRUE; sprite->invisible = TRUE;
@@ -643,7 +642,7 @@ static bool8 CreateRainSprite(void)
if (spriteId != MAX_SPRITES) if (spriteId != MAX_SPRITES)
{ {
gSprites[spriteId].tActive = 0; gSprites[spriteId].tActive = FALSE;
gSprites[spriteId].tRandom = spriteIndex * 145; gSprites[spriteId].tRandom = spriteIndex * 145;
while (gSprites[spriteId].tRandom >= 600) while (gSprites[spriteId].tRandom >= 600)
gSprites[spriteId].tRandom -= 600; gSprites[spriteId].tRandom -= 600;
@@ -710,7 +709,7 @@ static void DestroyRainSprites(void)
DestroySprite(gWeatherPtr->sprites.s1.rainSprites[i]); DestroySprite(gWeatherPtr->sprites.s1.rainSprites[i]);
} }
gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->rainSpriteCount = 0;
FreeSpriteTilesByTag(0x1206); FreeSpriteTilesByTag(GFXTAG_RAIN);
} }
#undef tCounter #undef tCounter
@@ -838,8 +837,8 @@ static const union AnimCmd *const sSnowflakeAnimCmds[] = {
}; };
static const struct SpriteTemplate sSnowflakeSpriteTemplate = { static const struct SpriteTemplate sSnowflakeSpriteTemplate = {
.tileTag = 0xFFFF, .tileTag = TAG_NONE,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sSnowflakeSpriteOamData, .oam = &sSnowflakeSpriteOamData,
.anims = sSnowflakeAnimCmds, .anims = sSnowflakeAnimCmds,
.images = sSnowflakeSpriteImages, .images = sSnowflakeSpriteImages,
@@ -901,13 +900,14 @@ static void InitSnowflakeSpriteMovement(struct Sprite *sprite)
static void WaitSnowflakeSprite(struct Sprite *sprite) static void WaitSnowflakeSprite(struct Sprite *sprite)
{ {
if (gWeatherPtr->unknown_6E2 > 18) // Timer is never incremented
if (gWeatherPtr->snowflakeTimer > 18)
{ {
sprite->invisible = FALSE; sprite->invisible = FALSE;
sprite->callback = UpdateSnowflakeSprite; sprite->callback = UpdateSnowflakeSprite;
sprite->y = 250 - (gSpriteCoordOffsetY + sprite->centerToCornerVecY); sprite->y = 250 - (gSpriteCoordOffsetY + sprite->centerToCornerVecY);
sprite->tPosY = sprite->y * 128; sprite->tPosY = sprite->y * 128;
gWeatherPtr->unknown_6E2 = 0; gWeatherPtr->snowflakeTimer = 0;
} }
} }
@@ -971,9 +971,32 @@ static void UpdateSnowflakeSprite(struct Sprite *sprite)
// WEATHER_RAIN_THUNDERSTORM // WEATHER_RAIN_THUNDERSTORM
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
enum {
// This block of states is run only once
// when first setting up the thunderstorm
TSTORM_STATE_LOAD_RAIN,
TSTORM_STATE_CREATE_RAIN,
TSTORM_STATE_INIT_RAIN,
TSTORM_STATE_WAIT_CHANGE,
// The thunderstorm loops through these states,
// not necessarily in order.
TSTORM_STATE_LOOP_START,
TSTORM_STATE_LOOP_WAIT,
TSTORM_STATE_INIT_THUNDER_SHORT_1,
TSTORM_STATE_INIT_THUNDER_SHORT_2,
TSTORM_STATE_TRY_THUNDER_SHORT,
TSTORM_STATE_TRY_NEW_THUNDER,
TSTORM_STATE_WAIT_THUNDER_SHORT,
TSTORM_STATE_INIT_THUNDER_LONG,
TSTORM_STATE_WAIT_THUNDER_LONG,
TSTORM_STATE_FADE_THUNDER_LONG,
TSTORM_STATE_END_THUNDER_LONG,
};
void Thunderstorm_InitVars(void) void Thunderstorm_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = TSTORM_STATE_LOAD_RAIN;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->rainSpriteVisibleCounter = 0; gWeatherPtr->rainSpriteVisibleCounter = 0;
gWeatherPtr->rainSpriteVisibleDelay = 4; gWeatherPtr->rainSpriteVisibleDelay = 4;
@@ -1002,7 +1025,7 @@ static void SetThunderCounter(u16);
void Downpour_InitVars(void) void Downpour_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = TSTORM_STATE_LOAD_RAIN;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->rainSpriteVisibleCounter = 0; gWeatherPtr->rainSpriteVisibleCounter = 0;
gWeatherPtr->rainSpriteVisibleDelay = 4; gWeatherPtr->rainSpriteVisibleDelay = 4;
@@ -1026,100 +1049,105 @@ void Thunderstorm_Main(void)
UpdateThunderSound(); UpdateThunderSound();
switch (gWeatherPtr->initStep) switch (gWeatherPtr->initStep)
{ {
case 0: case TSTORM_STATE_LOAD_RAIN:
LoadRainSpriteSheet(); LoadRainSpriteSheet();
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 1: case TSTORM_STATE_CREATE_RAIN:
if (!CreateRainSprite()) if (!CreateRainSprite())
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 2: case TSTORM_STATE_INIT_RAIN:
if (!UpdateVisibleRainSprites()) if (!UpdateVisibleRainSprites())
{ {
gWeatherPtr->weatherGfxLoaded = TRUE; gWeatherPtr->weatherGfxLoaded = TRUE;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
} }
break; break;
case 3: case TSTORM_STATE_WAIT_CHANGE:
if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER) if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER)
gWeatherPtr->initStep = 6; gWeatherPtr->initStep = TSTORM_STATE_INIT_THUNDER_SHORT_1;
break; break;
case 4: case TSTORM_STATE_LOOP_START:
gWeatherPtr->unknown_6EA = 1; gWeatherPtr->thunderAllowEnd = TRUE;
gWeatherPtr->unknown_6E6 = (Random() % 360) + 360; gWeatherPtr->thunderDelay = (Random() % 360) + 360;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
// fall through // fall through
case 5: case TSTORM_STATE_LOOP_WAIT:
if (--gWeatherPtr->unknown_6E6 == 0) // Wait between 360-720 frames before trying thunder again
if (--gWeatherPtr->thunderDelay == 0)
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 6: case TSTORM_STATE_INIT_THUNDER_SHORT_1:
gWeatherPtr->unknown_6EA = 1; gWeatherPtr->thunderAllowEnd = TRUE;
gWeatherPtr->unknown_6EB = Random() % 2; gWeatherPtr->thunderSkipShort = Random() % 2;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 7: case TSTORM_STATE_INIT_THUNDER_SHORT_2:
gWeatherPtr->unknown_6EC = (Random() & 1) + 1; gWeatherPtr->thunderShortRetries = (Random() & 1) + 1;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
// fall through // fall through
case 8: case TSTORM_STATE_TRY_THUNDER_SHORT:
WeatherShiftGammaIfPalStateIdle(19); WeatherShiftGammaIfPalStateIdle(19);
if (gWeatherPtr->unknown_6EB == 0 && gWeatherPtr->unknown_6EC == 1) if (!gWeatherPtr->thunderSkipShort && gWeatherPtr->thunderShortRetries == 1)
SetThunderCounter(20); SetThunderCounter(20); // Do short thunder
gWeatherPtr->unknown_6E6 = (Random() % 3) + 6; gWeatherPtr->thunderDelay = (Random() % 3) + 6;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 9: case TSTORM_STATE_TRY_NEW_THUNDER:
if (--gWeatherPtr->unknown_6E6 == 0) if (--gWeatherPtr->thunderDelay == 0)
{ {
WeatherShiftGammaIfPalStateIdle(3); WeatherShiftGammaIfPalStateIdle(3);
gWeatherPtr->unknown_6EA = 1; gWeatherPtr->thunderAllowEnd = TRUE;
if (--gWeatherPtr->unknown_6EC != 0) if (--gWeatherPtr->thunderShortRetries != 0)
{ {
gWeatherPtr->unknown_6E6 = (Random() % 16) + 60; // Try a short thunder again
gWeatherPtr->initStep = 10; gWeatherPtr->thunderDelay = (Random() % 16) + 60;
gWeatherPtr->initStep = TSTORM_STATE_WAIT_THUNDER_SHORT;
} }
else if (gWeatherPtr->unknown_6EB == 0) else if (!gWeatherPtr->thunderSkipShort)
{ {
gWeatherPtr->initStep = 4; // No more thunder, restart loop
gWeatherPtr->initStep = TSTORM_STATE_LOOP_START;
} }
else else
{ {
gWeatherPtr->initStep = 11; // Set up long thunder
gWeatherPtr->initStep = TSTORM_STATE_INIT_THUNDER_LONG;
} }
} }
break; break;
case 10: case TSTORM_STATE_WAIT_THUNDER_SHORT:
if (--gWeatherPtr->unknown_6E6 == 0) if (--gWeatherPtr->thunderDelay == 0)
gWeatherPtr->initStep = 8; gWeatherPtr->initStep = TSTORM_STATE_TRY_THUNDER_SHORT;
break; break;
case 11: case TSTORM_STATE_INIT_THUNDER_LONG:
gWeatherPtr->unknown_6E6 = (Random() % 16) + 60; gWeatherPtr->thunderDelay = (Random() % 16) + 60;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
break; break;
case 12: case TSTORM_STATE_WAIT_THUNDER_LONG:
if (--gWeatherPtr->unknown_6E6 == 0) if (--gWeatherPtr->thunderDelay == 0)
{ {
// Do long thunder
SetThunderCounter(100); SetThunderCounter(100);
WeatherShiftGammaIfPalStateIdle(19); WeatherShiftGammaIfPalStateIdle(19);
gWeatherPtr->unknown_6E6 = (Random() & 0xF) + 30; gWeatherPtr->thunderDelay = (Random() & 0xF) + 30;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
} }
break; break;
case 13: case TSTORM_STATE_FADE_THUNDER_LONG:
if (--gWeatherPtr->unknown_6E6 == 0) if (--gWeatherPtr->thunderDelay == 0)
{ {
WeatherBeginGammaFade(19, 3, 5); WeatherBeginGammaFade(19, 3, 5);
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
} }
break; break;
case 14: case TSTORM_STATE_END_THUNDER_LONG:
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{ {
gWeatherPtr->unknown_6EA = 1; gWeatherPtr->thunderAllowEnd = TRUE;
gWeatherPtr->initStep = 4; gWeatherPtr->initStep = TSTORM_STATE_LOOP_START;
} }
break; break;
} }
@@ -1130,16 +1158,16 @@ bool8 Thunderstorm_Finish(void)
switch (gWeatherPtr->finishStep) switch (gWeatherPtr->finishStep)
{ {
case 0: case 0:
gWeatherPtr->unknown_6EA = 0; gWeatherPtr->thunderAllowEnd = FALSE;
gWeatherPtr->finishStep++; gWeatherPtr->finishStep++;
// fall through // fall through
case 1: case 1:
Thunderstorm_Main(); Thunderstorm_Main();
if (gWeatherPtr->unknown_6EA) if (gWeatherPtr->thunderAllowEnd)
{ {
if (gWeatherPtr->nextWeather == WEATHER_RAIN if (gWeatherPtr->nextWeather == WEATHER_RAIN
|| gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM || gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM
|| gWeatherPtr->nextWeather == WEATHER_DOWNPOUR) || gWeatherPtr->nextWeather == WEATHER_DOWNPOUR)
return FALSE; return FALSE;
gWeatherPtr->targetRainSpriteCount = 0; gWeatherPtr->targetRainSpriteCount = 0;
@@ -1197,10 +1225,9 @@ static void UpdateThunderSound(void)
// WEATHER_FOG_HORIZONTAL and WEATHER_UNDERWATER // WEATHER_FOG_HORIZONTAL and WEATHER_UNDERWATER
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// unused data static const u16 sUnusedData[] = {0, 6, 6, 12, 18, 42, 300, 300};
static const u16 unusedData_839AB1C[] = {0, 6, 6, 12, 18, 42, 300, 300};
static const struct OamData gOamData_839AB2C = { static const struct OamData sOamData_FogH = {
.y = 0, .y = 0,
.affineMode = ST_OAM_AFFINE_OFF, .affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_BLEND, .objMode = ST_OAM_OBJ_BLEND,
@@ -1216,62 +1243,62 @@ static const struct OamData gOamData_839AB2C = {
.affineParam = 0, .affineParam = 0,
}; };
static const union AnimCmd gSpriteAnim_839AB34[] = { static const union AnimCmd sAnim_FogH_0[] = {
ANIMCMD_FRAME(0, 16), ANIMCMD_FRAME(0, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd gSpriteAnim_839AB3C[] = { static const union AnimCmd sAnim_FogH_1[] = {
ANIMCMD_FRAME(32, 16), ANIMCMD_FRAME(32, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd gSpriteAnim_839AB44[] = { static const union AnimCmd sAnim_FogH_2[] = {
ANIMCMD_FRAME(64, 16), ANIMCMD_FRAME(64, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd gSpriteAnim_839AB4C[] = { static const union AnimCmd sAnim_FogH_3[] = {
ANIMCMD_FRAME(96, 16), ANIMCMD_FRAME(96, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd gSpriteAnim_839AB54[] = { static const union AnimCmd sAnim_FogH_4[] = {
ANIMCMD_FRAME(128, 16), ANIMCMD_FRAME(128, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd gSpriteAnim_839AB5C[] = { static const union AnimCmd sAnim_FogH_5[] = {
ANIMCMD_FRAME(160, 16), ANIMCMD_FRAME(160, 16),
ANIMCMD_END, ANIMCMD_END,
}; };
static const union AnimCmd *const gSpriteAnimTable_839AB64[] = { static const union AnimCmd *const sAnims_FogH[] = {
gSpriteAnim_839AB34, sAnim_FogH_0,
gSpriteAnim_839AB3C, sAnim_FogH_1,
gSpriteAnim_839AB44, sAnim_FogH_2,
gSpriteAnim_839AB4C, sAnim_FogH_3,
gSpriteAnim_839AB54, sAnim_FogH_4,
gSpriteAnim_839AB5C, sAnim_FogH_5,
}; };
static const union AffineAnimCmd gSpriteAffineAnim_839AB7C[] = { static const union AffineAnimCmd sAffineAnim_FogH[] = {
AFFINEANIMCMD_FRAME(0x200, 0x200, 0, 0), AFFINEANIMCMD_FRAME(0x200, 0x200, 0, 0),
AFFINEANIMCMD_END, AFFINEANIMCMD_END,
}; };
static const union AffineAnimCmd *const gSpriteAffineAnimTable_839AB8C[] = { static const union AffineAnimCmd *const sAffineAnims_FogH[] = {
gSpriteAffineAnim_839AB7C, sAffineAnim_FogH,
}; };
static void FogHorizontalSpriteCallback(struct Sprite *); static void FogHorizontalSpriteCallback(struct Sprite *);
static const struct SpriteTemplate sFogHorizontalSpriteTemplate = { static const struct SpriteTemplate sFogHorizontalSpriteTemplate = {
.tileTag = 0x1201, .tileTag = GFXTAG_FOG_H,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &gOamData_839AB2C, .oam = &sOamData_FogH,
.anims = gSpriteAnimTable_839AB64, .anims = sAnims_FogH,
.images = NULL, .images = NULL,
.affineAnims = gSpriteAffineAnimTable_839AB8C, .affineAnims = sAffineAnims_FogH,
.callback = FogHorizontalSpriteCallback, .callback = FogHorizontalSpriteCallback,
}; };
@@ -1363,9 +1390,9 @@ static void FogHorizontalSpriteCallback(struct Sprite *sprite)
{ {
sprite->y2 = (u8)gSpriteCoordOffsetY; sprite->y2 = (u8)gSpriteCoordOffsetY;
sprite->x = gWeatherPtr->fogHScrollPosX + 32 + sprite->tSpriteColumn * 64; sprite->x = gWeatherPtr->fogHScrollPosX + 32 + sprite->tSpriteColumn * 64;
if (sprite->x > 271) if (sprite->x >= DISPLAY_WIDTH + 32)
{ {
sprite->x = 480 + gWeatherPtr->fogHScrollPosX - (4 - sprite->tSpriteColumn) * 64; sprite->x = (DISPLAY_WIDTH * 2) + gWeatherPtr->fogHScrollPosX - (4 - sprite->tSpriteColumn) * 64;
sprite->x &= 0x1FF; sprite->x &= 0x1FF;
} }
} }
@@ -1381,7 +1408,7 @@ static void CreateFogHorizontalSprites(void)
struct SpriteSheet fogHorizontalSpriteSheet = { struct SpriteSheet fogHorizontalSpriteSheet = {
.data = gWeatherFogHorizontalTiles, .data = gWeatherFogHorizontalTiles,
.size = 0x0800, .size = 0x0800,
.tag = 0x1201, .tag = GFXTAG_FOG_H,
}; };
LoadSpriteSheet(&fogHorizontalSpriteSheet); LoadSpriteSheet(&fogHorizontalSpriteSheet);
for (i = 0; i < NUM_FOG_HORIZONTAL_SPRITES; i++) for (i = 0; i < NUM_FOG_HORIZONTAL_SPRITES; i++)
@@ -1417,7 +1444,7 @@ static void DestroyFogHorizontalSprites(void)
DestroySprite(gWeatherPtr->sprites.s2.fogHSprites[i]); DestroySprite(gWeatherPtr->sprites.s2.fogHSprites[i]);
} }
FreeSpriteTilesByTag(0x1201); FreeSpriteTilesByTag(GFXTAG_FOG_H);
gWeatherPtr->fogHSpritesCreated = FALSE; gWeatherPtr->fogHSpritesCreated = FALSE;
} }
} }
@@ -1439,7 +1466,7 @@ void Ash_InitVars(void)
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->unknown_6FE = 20; gWeatherPtr->ashUnused = 20; // Never read
if (!gWeatherPtr->ashSpritesCreated) if (!gWeatherPtr->ashSpritesCreated)
{ {
Weather_SetBlendCoeffs(0, 16); Weather_SetBlendCoeffs(0, 16);
@@ -1457,8 +1484,8 @@ void Ash_InitAll(void)
void Ash_Main(void) void Ash_Main(void)
{ {
gWeatherPtr->ashBaseSpritesX = gSpriteCoordOffsetX & 0x1FF; gWeatherPtr->ashBaseSpritesX = gSpriteCoordOffsetX & 0x1FF;
while (gWeatherPtr->ashBaseSpritesX >= 240) while (gWeatherPtr->ashBaseSpritesX >= DISPLAY_WIDTH)
gWeatherPtr->ashBaseSpritesX -= 240; gWeatherPtr->ashBaseSpritesX -= DISPLAY_WIDTH;
switch (gWeatherPtr->initStep) switch (gWeatherPtr->initStep)
{ {
@@ -1514,7 +1541,7 @@ bool8 Ash_Finish(void)
static const struct SpriteSheet sAshSpriteSheet = { static const struct SpriteSheet sAshSpriteSheet = {
.data = gWeatherAshTiles, .data = gWeatherAshTiles,
.size = 0x1000, .size = 0x1000,
.tag = 0x1202, .tag = GFXTAG_ASH,
}; };
static void LoadAshSpriteSheet(void) static void LoadAshSpriteSheet(void)
@@ -1546,8 +1573,8 @@ static const union AnimCmd *const sAshSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sAshSpriteTemplate = { static const struct SpriteTemplate sAshSpriteTemplate = {
.tileTag = 0x1202, .tileTag = GFXTAG_ASH,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sAshSpriteOamData, .oam = &sAshSpriteOamData,
.anims = sAshSpriteAnimCmds, .anims = sAshSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -1602,7 +1629,7 @@ static void DestroyAshSprites(void)
DestroySprite(gWeatherPtr->sprites.s2.ashSprites[i]); DestroySprite(gWeatherPtr->sprites.s2.ashSprites[i]);
} }
FreeSpriteTilesByTag(0x1202); FreeSpriteTilesByTag(GFXTAG_ASH);
gWeatherPtr->ashSpritesCreated = FALSE; gWeatherPtr->ashSpritesCreated = FALSE;
} }
} }
@@ -1617,9 +1644,9 @@ static void UpdateAshSprite(struct Sprite *sprite)
sprite->y = gSpriteCoordOffsetY + sprite->tOffsetY; sprite->y = gSpriteCoordOffsetY + sprite->tOffsetY;
sprite->x = gWeatherPtr->ashBaseSpritesX + 32 + sprite->tSpriteColumn * 64; sprite->x = gWeatherPtr->ashBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
if (sprite->x > 271) if (sprite->x >= DISPLAY_WIDTH + 32)
{ {
sprite->x = gWeatherPtr->ashBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64; sprite->x = gWeatherPtr->ashBaseSpritesX + (DISPLAY_WIDTH * 2) - (4 - sprite->tSpriteColumn) * 64;
sprite->x &= 0x1FF; sprite->x &= 0x1FF;
} }
} }
@@ -1732,7 +1759,7 @@ static void UpdateFogDiagonalMovement(void)
static const struct SpriteSheet gFogDiagonalSpriteSheet = { static const struct SpriteSheet gFogDiagonalSpriteSheet = {
.data = gWeatherFogDiagonalTiles, .data = gWeatherFogDiagonalTiles,
.size = 0x0800, .size = 0x0800,
.tag = 0x1203, .tag = GFXTAG_FOG_D,
}; };
static const struct OamData sFogDiagonalSpriteOamData = { static const struct OamData sFogDiagonalSpriteOamData = {
@@ -1758,8 +1785,8 @@ static const union AnimCmd *const sFogDiagonalSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sFogDiagonalSpriteTemplate = { static const struct SpriteTemplate sFogDiagonalSpriteTemplate = {
.tileTag = 0x1203, .tileTag = GFXTAG_FOG_D,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sFogDiagonalSpriteOamData, .oam = &sFogDiagonalSpriteOamData,
.anims = sFogDiagonalSpriteAnimCmds, .anims = sFogDiagonalSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -1813,7 +1840,7 @@ static void DestroyFogDiagonalSprites(void)
DestroySprite(gWeatherPtr->sprites.s2.fogDSprites[i]); DestroySprite(gWeatherPtr->sprites.s2.fogDSprites[i]);
} }
FreeSpriteTilesByTag(0x1203); FreeSpriteTilesByTag(GFXTAG_FOG_D);
gWeatherPtr->fogDSpritesCreated = FALSE; gWeatherPtr->fogDSpritesCreated = FALSE;
} }
} }
@@ -1822,9 +1849,9 @@ static void UpdateFogDiagonalSprite(struct Sprite *sprite)
{ {
sprite->y2 = gWeatherPtr->fogDPosY; sprite->y2 = gWeatherPtr->fogDPosY;
sprite->x = gWeatherPtr->fogDBaseSpritesX + 32 + sprite->tSpriteColumn * 64; sprite->x = gWeatherPtr->fogDBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
if (sprite->x > 271) if (sprite->x >= DISPLAY_WIDTH + 32)
{ {
sprite->x = gWeatherPtr->fogDBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64; sprite->x = gWeatherPtr->fogDBaseSpritesX + (DISPLAY_WIDTH * 2) - (4 - sprite->tSpriteColumn) * 64;
sprite->x &= 0x1FF; sprite->x &= 0x1FF;
} }
} }
@@ -1956,7 +1983,7 @@ static void DestroySandstormSprites(void)
} }
gWeatherPtr->sandstormSpritesCreated = FALSE; gWeatherPtr->sandstormSpritesCreated = FALSE;
FreeSpriteTilesByTag(0x1204); FreeSpriteTilesByTag(GFXTAG_SANDSTORM);
} }
if (gWeatherPtr->sandstormSwirlSpritesCreated) if (gWeatherPtr->sandstormSwirlSpritesCreated)
@@ -2000,8 +2027,8 @@ static const union AnimCmd *const sSandstormSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sSandstormSpriteTemplate = { static const struct SpriteTemplate sSandstormSpriteTemplate = {
.tileTag = 0x1204, .tileTag = GFXTAG_SANDSTORM,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &sSandstormSpriteOamData, .oam = &sSandstormSpriteOamData,
.anims = sSandstormSpriteAnimCmds, .anims = sSandstormSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -2012,7 +2039,7 @@ static const struct SpriteTemplate sSandstormSpriteTemplate = {
static const struct SpriteSheet sSandstormSpriteSheet = { static const struct SpriteSheet sSandstormSpriteSheet = {
.data = gWeatherSandstormTiles, .data = gWeatherSandstormTiles,
.size = 0x0a00, .size = 0x0a00,
.tag = 0x1204, .tag = GFXTAG_SANDSTORM,
}; };
// Regular sandstorm sprites // Regular sandstorm sprites
@@ -2092,9 +2119,9 @@ static void UpdateSandstormSprite(struct Sprite *sprite)
{ {
sprite->y2 = gWeatherPtr->sandstormPosY; sprite->y2 = gWeatherPtr->sandstormPosY;
sprite->x = gWeatherPtr->sandstormBaseSpritesX + 32 + sprite->tSpriteColumn * 64; sprite->x = gWeatherPtr->sandstormBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
if (sprite->x > 271) if (sprite->x >= DISPLAY_WIDTH + 32)
{ {
sprite->x = gWeatherPtr->sandstormBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64; sprite->x = gWeatherPtr->sandstormBaseSpritesX + (DISPLAY_WIDTH * 2) - (4 - sprite->tSpriteColumn) * 64;
sprite->x &= 0x1FF; sprite->x &= 0x1FF;
} }
} }
@@ -2111,7 +2138,7 @@ static void UpdateSandstormSwirlSprite(struct Sprite *sprite)
if (--sprite->y < -48) if (--sprite->y < -48)
{ {
sprite->y = 208; sprite->y = DISPLAY_HEIGHT + 48;
sprite->tRadius = 4; sprite->tRadius = 4;
} }
@@ -2173,7 +2200,7 @@ static const u8 sBubbleStartDelays[] = {40, 90, 60, 90, 2, 60, 40, 30};
static const struct SpriteSheet sWeatherBubbleSpriteSheet = { static const struct SpriteSheet sWeatherBubbleSpriteSheet = {
.data = gWeatherBubbleTiles, .data = gWeatherBubbleTiles,
.size = 0x0040, .size = 0x0040,
.tag = 0x1205, .tag = GFXTAG_BUBBLE,
}; };
static const s16 sBubbleStartCoords[][2] = { static const s16 sBubbleStartCoords[][2] = {
@@ -2249,8 +2276,8 @@ static const union AnimCmd *const sBubbleSpriteAnimCmds[] = {
}; };
static const struct SpriteTemplate sBubbleSpriteTemplate = { static const struct SpriteTemplate sBubbleSpriteTemplate = {
.tileTag = 0x1205, .tileTag = GFXTAG_BUBBLE,
.paletteTag = 0x1200, .paletteTag = PALTAG_WEATHER,
.oam = &gOamData_AffineOff_ObjNormal_8x8, .oam = &gOamData_AffineOff_ObjNormal_8x8,
.anims = sBubbleSpriteAnimCmds, .anims = sBubbleSpriteAnimCmds,
.images = NULL, .images = NULL,
@@ -2288,7 +2315,7 @@ static void DestroyBubbleSprites(void)
DestroySprite(&gSprites[i]); DestroySprite(&gSprites[i]);
} }
FreeSpriteTilesByTag(0x1205); FreeSpriteTilesByTag(GFXTAG_BUBBLE);
} }
static void UpdateBubbleSprite(struct Sprite *sprite) static void UpdateBubbleSprite(struct Sprite *sprite)