2018-12-08 19:05:03 +01:00
|
|
|
#include "global.h"
|
2019-04-03 01:28:56 +02:00
|
|
|
#include "battle_anim.h"
|
2018-12-08 19:05:03 +01:00
|
|
|
#include "event_object_movement.h"
|
2021-10-09 18:12:18 +02:00
|
|
|
#include "fieldmap.h"
|
2018-12-08 19:05:03 +01:00
|
|
|
#include "field_weather.h"
|
|
|
|
#include "overworld.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "constants/weather.h"
|
|
|
|
#include "constants/songs.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "trig.h"
|
|
|
|
#include "gpu_regs.h"
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
// EWRAM
|
2019-12-02 01:19:47 +01:00
|
|
|
EWRAM_DATA static u8 gCurrentAbnormalWeather = 0;
|
2019-02-23 04:20:42 +01:00
|
|
|
EWRAM_DATA static u16 gUnusedWeatherRelated = 0;
|
2018-12-08 19:43:21 +01:00
|
|
|
|
|
|
|
// CONST
|
2019-04-03 01:28:56 +02:00
|
|
|
const u16 gCloudsWeatherPalette[] = INCBIN_U16("graphics/weather/cloud.gbapal");
|
|
|
|
const u16 gSandstormWeatherPalette[] = INCBIN_U16("graphics/weather/sandstorm.gbapal");
|
2019-12-06 19:25:45 +01:00
|
|
|
const u8 gWeatherFogDiagonalTiles[] = INCBIN_U8("graphics/weather/fog_diagonal.4bpp");
|
|
|
|
const u8 gWeatherFogHorizontalTiles[] = INCBIN_U8("graphics/weather/fog_horizontal.4bpp");
|
2018-12-08 19:05:03 +01:00
|
|
|
const u8 gWeatherCloudTiles[] = INCBIN_U8("graphics/weather/cloud.4bpp");
|
|
|
|
const u8 gWeatherSnow1Tiles[] = INCBIN_U8("graphics/weather/snow0.4bpp");
|
|
|
|
const u8 gWeatherSnow2Tiles[] = INCBIN_U8("graphics/weather/snow1.4bpp");
|
|
|
|
const u8 gWeatherBubbleTiles[] = INCBIN_U8("graphics/weather/bubble.4bpp");
|
|
|
|
const u8 gWeatherAshTiles[] = INCBIN_U8("graphics/weather/ash.4bpp");
|
|
|
|
const u8 gWeatherRainTiles[] = INCBIN_U8("graphics/weather/rain.4bpp");
|
|
|
|
const u8 gWeatherSandstormTiles[] = INCBIN_U8("graphics/weather/sandstorm.4bpp");
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_SUNNY_CLOUDS
|
2019-04-01 04:07:29 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void CreateCloudSprites(void);
|
|
|
|
static void DestroyCloudSprites(void);
|
|
|
|
static void UpdateCloudSprite(struct Sprite *);
|
2019-04-01 04:07:29 +02:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
// The clouds are positioned on the map's grid.
|
|
|
|
// These coordinates are for the lower half of Route 120.
|
|
|
|
static const struct Coords16 sCloudSpriteMapCoords[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
{ 0, 66},
|
|
|
|
{ 5, 73},
|
|
|
|
{10, 78},
|
|
|
|
};
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static const struct SpriteSheet sCloudSpriteSheet =
|
|
|
|
{
|
|
|
|
.data = gWeatherCloudTiles,
|
|
|
|
.size = sizeof(gWeatherCloudTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_CLOUD
|
2019-04-01 04:07:29 +02:00
|
|
|
};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const struct OamData sCloudSpriteOamData =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
2019-04-02 03:04:23 +02:00
|
|
|
.objMode = ST_OAM_OBJ_BLEND,
|
2018-12-08 19:05:03 +01:00
|
|
|
.mosaic = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 3,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd sCloudSpriteAnimCmd[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd *const sCloudSpriteAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sCloudSpriteAnimCmd,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static const struct SpriteTemplate sCloudSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_CLOUD,
|
|
|
|
.paletteTag = PALTAG_WEATHER_2,
|
2019-04-02 03:04:23 +02:00
|
|
|
.oam = &sCloudSpriteOamData,
|
|
|
|
.anims = sCloudSpriteAnimCmds,
|
2018-12-08 19:05:03 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-04-02 03:04:23 +02:00
|
|
|
.callback = UpdateCloudSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void Clouds_InitVars(void)
|
|
|
|
{
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
if (gWeatherPtr->cloudSpritesCreated == FALSE)
|
|
|
|
Weather_SetBlendCoeffs(0, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clouds_InitAll(void)
|
|
|
|
{
|
|
|
|
Clouds_InitVars();
|
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
|
|
|
Clouds_Main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clouds_Main(void)
|
|
|
|
{
|
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
CreateCloudSprites();
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Weather_SetTargetBlendCoeffs(12, 8, 1);
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Clouds_Finish(void)
|
|
|
|
{
|
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Weather_SetTargetBlendCoeffs(0, 16, 1);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
return TRUE;
|
|
|
|
case 1:
|
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
DestroyCloudSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
void Sunny_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
void Sunny_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
Sunny_InitVars();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
void Sunny_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
bool8 Sunny_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
return FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void CreateCloudSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
2019-04-02 03:04:23 +02:00
|
|
|
u8 spriteId;
|
|
|
|
struct Sprite *sprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
|
|
|
if (gWeatherPtr->cloudSpritesCreated == TRUE)
|
|
|
|
return;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
LoadSpriteSheet(&sCloudSpriteSheet);
|
2019-04-03 01:28:56 +02:00
|
|
|
LoadCustomWeatherSpritePalette(gCloudsWeatherPalette);
|
2019-04-02 03:04:23 +02:00
|
|
|
for (i = 0; i < NUM_CLOUD_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
spriteId = CreateSprite(&sCloudSpriteTemplate, 0, 0, 0xFF);
|
2018-12-09 12:16:01 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s1.cloudSprites[i] = &gSprites[spriteId];
|
|
|
|
sprite = gWeatherPtr->sprites.s1.cloudSprites[i];
|
2021-10-09 18:12:18 +02:00
|
|
|
SetSpritePosToMapCoords(sCloudSpriteMapCoords[i].x + MAP_OFFSET, sCloudSpriteMapCoords[i].y + MAP_OFFSET, &sprite->x, &sprite->y);
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->coordOffsetEnabled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s1.cloudSprites[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->cloudSpritesCreated = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void DestroyCloudSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
if (!gWeatherPtr->cloudSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
return;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_CLOUD_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
if (gWeatherPtr->sprites.s1.cloudSprites[i] != NULL)
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s1.cloudSprites[i]);
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_CLOUD);
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->cloudSpritesCreated = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void UpdateCloudSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
// Move 1 pixel left every 2 frames.
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->data[0] = (sprite->data[0] + 1) & 1;
|
2019-04-02 03:04:23 +02:00
|
|
|
if (sprite->data[0])
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x--;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_DROUGHT
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateDroughtBlend(u8);
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
void Drought_InitVars(void)
|
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drought_InitAll(void)
|
|
|
|
{
|
|
|
|
Drought_InitVars();
|
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
|
|
|
Drought_Main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drought_Main(void)
|
|
|
|
{
|
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER)
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ResetDroughtWeatherPaletteLoading();
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (LoadDroughtWeatherPalettes() == FALSE)
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 3:
|
2021-04-04 04:47:58 +02:00
|
|
|
DroughtStateInit();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 4:
|
2021-04-04 04:47:58 +02:00
|
|
|
DroughtStateRun();
|
|
|
|
if (gWeatherPtr->droughtBrightnessStage == 6)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-04-04 04:47:58 +02:00
|
|
|
DroughtStateRun();
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
bool8 Drought_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
return FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
void StartDroughtWeatherBlend(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
CreateTask(UpdateDroughtBlend, 80);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define tState data[0]
|
|
|
|
#define tBlendY data[1]
|
|
|
|
#define tBlendDelay data[2]
|
|
|
|
#define tWinRange data[3]
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateDroughtBlend(u8 taskId)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
struct Task *task = &gTasks[taskId];
|
|
|
|
|
|
|
|
switch (task->tState)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
task->tBlendY = 0;
|
|
|
|
task->tBlendDelay = 0;
|
|
|
|
task->tWinRange = REG_WININ;
|
2021-04-15 08:43:09 +02:00
|
|
|
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_ALL | WININ_WIN1_ALL);
|
2018-12-08 19:05:03 +01:00
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_TGT1_BG3 | BLDCNT_TGT1_OBJ | BLDCNT_EFFECT_LIGHTEN);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDY, 0);
|
|
|
|
task->tState++;
|
|
|
|
// fall through
|
|
|
|
case 1:
|
|
|
|
task->tBlendY += 3;
|
|
|
|
if (task->tBlendY > 16)
|
|
|
|
task->tBlendY = 16;
|
|
|
|
SetGpuReg(REG_OFFSET_BLDY, task->tBlendY);
|
|
|
|
if (task->tBlendY >= 16)
|
|
|
|
task->tState++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
task->tBlendDelay++;
|
|
|
|
if (task->tBlendDelay > 9)
|
|
|
|
{
|
|
|
|
task->tBlendDelay = 0;
|
|
|
|
task->tBlendY--;
|
|
|
|
if (task->tBlendY <= 0)
|
|
|
|
{
|
|
|
|
task->tBlendY = 0;
|
|
|
|
task->tState++;
|
|
|
|
}
|
|
|
|
SetGpuReg(REG_OFFSET_BLDY, task->tBlendY);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
SetGpuReg(REG_OFFSET_BLDCNT, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_BLDY, 0);
|
|
|
|
SetGpuReg(REG_OFFSET_WININ, task->tWinRange);
|
|
|
|
task->tState++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
EnableBothScriptContexts();
|
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef tState
|
|
|
|
#undef tBlendY
|
|
|
|
#undef tBlendDelay
|
|
|
|
#undef tWinRange
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_RAIN
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void LoadRainSpriteSheet(void);
|
|
|
|
static bool8 CreateRainSprite(void);
|
|
|
|
static void UpdateRainSprite(struct Sprite *sprite);
|
|
|
|
static bool8 UpdateVisibleRainSprites(void);
|
|
|
|
static void DestroyRainSprites(void);
|
|
|
|
|
|
|
|
static const struct Coords16 sRainSpriteCoords[] =
|
|
|
|
{
|
|
|
|
{ 0, 0},
|
|
|
|
{ 0, 160},
|
|
|
|
{ 0, 64},
|
|
|
|
{144, 224},
|
|
|
|
{144, 128},
|
|
|
|
{ 32, 32},
|
|
|
|
{ 32, 192},
|
|
|
|
{ 32, 96},
|
|
|
|
{ 72, 128},
|
|
|
|
{ 72, 32},
|
|
|
|
{ 72, 192},
|
|
|
|
{216, 96},
|
|
|
|
{216, 0},
|
|
|
|
{104, 160},
|
|
|
|
{104, 64},
|
|
|
|
{104, 224},
|
|
|
|
{144, 0},
|
|
|
|
{144, 160},
|
|
|
|
{144, 64},
|
|
|
|
{ 32, 224},
|
|
|
|
{ 32, 128},
|
|
|
|
{ 72, 32},
|
|
|
|
{ 72, 192},
|
|
|
|
{ 48, 96},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct OamData sRainSpriteOamData =
|
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2019-04-01 04:07:29 +02:00
|
|
|
.mosaic = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-04-01 04:07:29 +02:00
|
|
|
.shape = SPRITE_SHAPE(16x32),
|
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
|
|
|
.size = SPRITE_SIZE(16x32),
|
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.paletteNum = 2,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sRainSpriteFallAnimCmd[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_JUMP(0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sRainSpriteSplashAnimCmd[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(8, 3),
|
|
|
|
ANIMCMD_FRAME(32, 2),
|
|
|
|
ANIMCMD_FRAME(40, 2),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sRainSpriteHeavySplashAnimCmd[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(8, 3),
|
|
|
|
ANIMCMD_FRAME(16, 3),
|
|
|
|
ANIMCMD_FRAME(24, 4),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd *const sRainSpriteAnimCmds[] =
|
|
|
|
{
|
|
|
|
sRainSpriteFallAnimCmd,
|
|
|
|
sRainSpriteSplashAnimCmd,
|
|
|
|
sRainSpriteHeavySplashAnimCmd,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct SpriteTemplate sRainSpriteTemplate =
|
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_RAIN,
|
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2019-04-01 04:07:29 +02:00
|
|
|
.oam = &sRainSpriteOamData,
|
|
|
|
.anims = sRainSpriteAnimCmds,
|
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
|
|
|
.callback = UpdateRainSprite,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Q28.4 fixed-point format values
|
|
|
|
static const s16 sRainSpriteMovement[][2] =
|
|
|
|
{
|
|
|
|
{-0x68, 0xD0},
|
|
|
|
{-0xA0, 0x140},
|
|
|
|
};
|
|
|
|
|
|
|
|
// First byte is the number of frames a raindrop falls before it splashes.
|
|
|
|
// Second byte is the maximum number of frames a raindrop can "wait" before
|
|
|
|
// it appears and starts falling. (This is only for the initial raindrop spawn.)
|
|
|
|
static const u16 sRainSpriteFallingDurations[][2] =
|
|
|
|
{
|
|
|
|
{18, 7},
|
|
|
|
{12, 10},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct SpriteSheet sRainSpriteSheet =
|
|
|
|
{
|
|
|
|
.data = gWeatherRainTiles,
|
|
|
|
.size = sizeof(gWeatherRainTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_RAIN,
|
2019-04-01 04:07:29 +02:00
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Rain_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->rainSpriteVisibleCounter = 0;
|
|
|
|
gWeatherPtr->rainSpriteVisibleDelay = 8;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->isDownpour = FALSE;
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetRainSpriteCount = 10;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->gammaTargetIndex = 3;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2020-08-21 00:02:00 +02:00
|
|
|
SetRainStrengthFromSoundEffect(SE_RAIN);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Rain_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
Rain_InitVars();
|
2019-04-01 04:07:29 +02:00
|
|
|
while (!gWeatherPtr->weatherGfxLoaded)
|
2019-12-06 19:25:45 +01:00
|
|
|
Rain_Main();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Rain_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
LoadRainSpriteSheet();
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-04-01 04:07:29 +02:00
|
|
|
if (!CreateRainSprite())
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-04-01 04:07:29 +02:00
|
|
|
if (!UpdateVisibleRainSprites())
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
bool8 Rain_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-12-02 01:19:47 +01:00
|
|
|
if (gWeatherPtr->nextWeather == WEATHER_RAIN
|
|
|
|
|| gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM
|
|
|
|
|| gWeatherPtr->nextWeather == WEATHER_DOWNPOUR)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->finishStep = 0xFF;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetRainSpriteCount = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case 1:
|
2019-04-01 04:07:29 +02:00
|
|
|
if (!UpdateVisibleRainSprites())
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
DestroyRainSprites();
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
#define tCounter data[0]
|
|
|
|
#define tRandom data[1]
|
|
|
|
#define tPosX data[2]
|
|
|
|
#define tPosY data[3]
|
|
|
|
#define tState data[4]
|
|
|
|
#define tActive data[5]
|
|
|
|
#define tWaiting data[6]
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void StartRainSpriteFall(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
u32 rand;
|
|
|
|
u16 numFallingFrames;
|
|
|
|
int tileX;
|
|
|
|
int tileY;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (sprite->tRandom == 0)
|
|
|
|
sprite->tRandom = 361;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2020-02-14 22:12:35 +01:00
|
|
|
rand = ISO_RANDOMIZE2(sprite->tRandom);
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tRandom = ((rand & 0x7FFF0000) >> 16) % 600;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0];
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
tileX = sprite->tRandom % 30;
|
|
|
|
sprite->tPosX = tileX * 8; // Useless assignment, leftover from before fixed-point values were used
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
tileY = sprite->tRandom / 30;
|
|
|
|
sprite->tPosY = tileY * 8; // Useless assignment, leftover from before fixed-point values were used
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tPosX = tileX;
|
|
|
|
sprite->tPosX <<= 7; // This is tileX * 8, using a fixed-point value with 4 decimal places
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tPosY = tileY;
|
|
|
|
sprite->tPosY <<= 7; // This is tileX * 8, using a fixed-point value with 4 decimal places
|
|
|
|
|
|
|
|
// "Rewind" the rain sprites, from their ending position.
|
2019-12-06 19:25:45 +01:00
|
|
|
sprite->tPosX -= sRainSpriteMovement[gWeatherPtr->isDownpour][0] * numFallingFrames;
|
|
|
|
sprite->tPosY -= sRainSpriteMovement[gWeatherPtr->isDownpour][1] * numFallingFrames;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
|
|
|
StartSpriteAnim(sprite, 0);
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tState = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->coordOffsetEnabled = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tCounter = numFallingFrames;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void UpdateRainSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
if (sprite->tState == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
// Raindrop is in its "falling" motion.
|
2019-12-06 19:25:45 +01:00
|
|
|
sprite->tPosX += sRainSpriteMovement[gWeatherPtr->isDownpour][0];
|
|
|
|
sprite->tPosY += sRainSpriteMovement[gWeatherPtr->isDownpour][1];
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = sprite->tPosX >> 4;
|
|
|
|
sprite->y = sprite->tPosY >> 4;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (sprite->tActive
|
2021-07-07 15:11:52 +02:00
|
|
|
&& (sprite->x >= -8 && sprite->x <= 248)
|
|
|
|
&& sprite->y >= -16 && sprite->y <= 176)
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->invisible = FALSE;
|
|
|
|
else
|
|
|
|
sprite->invisible = TRUE;
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (--sprite->tCounter == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
// Make raindrop splash on the ground
|
2019-12-06 19:25:45 +01:00
|
|
|
StartSpriteAnim(sprite, gWeatherPtr->isDownpour + 1);
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tState = 1;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x -= gSpriteCoordOffsetX;
|
|
|
|
sprite->y -= gSpriteCoordOffsetY;
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->coordOffsetEnabled = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sprite->animEnded)
|
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
// The splashing animation ended.
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->invisible = TRUE;
|
2019-04-01 04:07:29 +02:00
|
|
|
StartRainSpriteFall(sprite);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void WaitRainSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
if (sprite->tCounter == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
StartRainSpriteFall(sprite);
|
|
|
|
sprite->callback = UpdateRainSprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tCounter--;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void InitRainSpriteMovement(struct Sprite *sprite, u16 val)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
u16 numFallingFrames = sRainSpriteFallingDurations[gWeatherPtr->isDownpour][0];
|
|
|
|
u16 numAdvanceRng = val / (sRainSpriteFallingDurations[gWeatherPtr->isDownpour][1] + numFallingFrames);
|
|
|
|
u16 frameVal = val % (sRainSpriteFallingDurations[gWeatherPtr->isDownpour][1] + numFallingFrames);
|
2019-04-01 04:07:29 +02:00
|
|
|
|
|
|
|
while (--numAdvanceRng != 0xFFFF)
|
|
|
|
StartRainSpriteFall(sprite);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (frameVal < numFallingFrames)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
while (--frameVal != 0xFFFF)
|
|
|
|
UpdateRainSprite(sprite);
|
|
|
|
|
|
|
|
sprite->tWaiting = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tCounter = frameVal - numFallingFrames;
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->invisible = TRUE;
|
2019-04-01 04:07:29 +02:00
|
|
|
sprite->tWaiting = 1;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void LoadRainSpriteSheet(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
LoadSpriteSheet(&sRainSpriteSheet);
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static bool8 CreateRainSprite(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
u8 spriteIndex;
|
|
|
|
u8 spriteId;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (gWeatherPtr->rainSpriteCount == MAX_RAIN_SPRITES)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
spriteIndex = gWeatherPtr->rainSpriteCount;
|
|
|
|
spriteId = CreateSpriteAtEnd(&sRainSpriteTemplate,
|
|
|
|
sRainSpriteCoords[spriteIndex].x, sRainSpriteCoords[spriteIndex].y, 78);
|
|
|
|
|
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
gSprites[spriteId].tActive = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
gSprites[spriteId].tRandom = spriteIndex * 145;
|
|
|
|
while (gSprites[spriteId].tRandom >= 600)
|
|
|
|
gSprites[spriteId].tRandom -= 600;
|
|
|
|
|
|
|
|
StartRainSpriteFall(&gSprites[spriteId]);
|
|
|
|
InitRainSpriteMovement(&gSprites[spriteId], spriteIndex * 9);
|
|
|
|
gSprites[spriteId].invisible = TRUE;
|
|
|
|
gWeatherPtr->sprites.s1.rainSprites[spriteIndex] = &gSprites[spriteId];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s1.rainSprites[spriteIndex] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++gWeatherPtr->rainSpriteCount == MAX_RAIN_SPRITES)
|
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
for (i = 0; i < MAX_RAIN_SPRITES; i++)
|
|
|
|
{
|
|
|
|
if (gWeatherPtr->sprites.s1.rainSprites[i])
|
|
|
|
{
|
|
|
|
if (!gWeatherPtr->sprites.s1.rainSprites[i]->tWaiting)
|
|
|
|
gWeatherPtr->sprites.s1.rainSprites[i]->callback = UpdateRainSprite;
|
|
|
|
else
|
|
|
|
gWeatherPtr->sprites.s1.rainSprites[i]->callback = WaitRainSprite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool8 UpdateVisibleRainSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->curRainSpriteIndex == gWeatherPtr->targetRainSpriteCount)
|
2019-04-01 04:07:29 +02:00
|
|
|
return FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
if (++gWeatherPtr->rainSpriteVisibleCounter > gWeatherPtr->rainSpriteVisibleDelay)
|
|
|
|
{
|
|
|
|
gWeatherPtr->rainSpriteVisibleCounter = 0;
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->curRainSpriteIndex < gWeatherPtr->targetRainSpriteCount)
|
2019-04-01 04:07:29 +02:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->sprites.s1.rainSprites[gWeatherPtr->curRainSpriteIndex++]->tActive = TRUE;
|
2019-04-01 04:07:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->curRainSpriteIndex--;
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->sprites.s1.rainSprites[gWeatherPtr->curRainSpriteIndex]->tActive = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->sprites.s1.rainSprites[gWeatherPtr->curRainSpriteIndex]->invisible = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DestroyRainSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
u16 i;
|
|
|
|
|
|
|
|
for (i = 0; i < gWeatherPtr->rainSpriteCount; i++)
|
|
|
|
{
|
|
|
|
if (gWeatherPtr->sprites.s1.rainSprites[i] != NULL)
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s1.rainSprites[i]);
|
|
|
|
}
|
|
|
|
gWeatherPtr->rainSpriteCount = 0;
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_RAIN);
|
2019-04-01 04:07:29 +02:00
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
#undef tCounter
|
|
|
|
#undef tRandom
|
|
|
|
#undef tPosX
|
|
|
|
#undef tPosY
|
|
|
|
#undef tState
|
|
|
|
#undef tActive
|
|
|
|
#undef tWaiting
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Snow
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void UpdateSnowflakeSprite(struct Sprite *);
|
|
|
|
static bool8 UpdateVisibleSnowflakeSprites(void);
|
|
|
|
static bool8 CreateSnowflakeSprite(void);
|
|
|
|
static bool8 DestroySnowflakeSprite(void);
|
|
|
|
static void InitSnowflakeSpriteMovement(struct Sprite *);
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
void Snow_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 3;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetSnowflakeSpriteCount = 16;
|
|
|
|
gWeatherPtr->snowflakeVisibleCounter = 0;
|
2019-04-01 04:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Snow_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
u16 i;
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
Snow_InitVars();
|
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
|
|
|
{
|
|
|
|
Snow_Main();
|
|
|
|
for (i = 0; i < gWeatherPtr->snowflakeSpriteCount; i++)
|
2019-04-02 03:04:23 +02:00
|
|
|
UpdateSnowflakeSprite(gWeatherPtr->sprites.s1.snowflakeSprites[i]);
|
2019-04-01 04:07:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Snow_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->initStep == 0 && !UpdateVisibleSnowflakeSprites())
|
2019-04-01 04:07:29 +02:00
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
bool8 Snow_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-01 04:07:29 +02:00
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetSnowflakeSpriteCount = 0;
|
|
|
|
gWeatherPtr->snowflakeVisibleCounter = 0;
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
// fall through
|
|
|
|
case 1:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (!UpdateVisibleSnowflakeSprites())
|
2019-04-01 04:07:29 +02:00
|
|
|
{
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static bool8 UpdateVisibleSnowflakeSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->snowflakeSpriteCount == gWeatherPtr->targetSnowflakeSpriteCount)
|
2019-04-01 04:07:29 +02:00
|
|
|
return FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
if (++gWeatherPtr->snowflakeVisibleCounter > 36)
|
2019-04-01 04:07:29 +02:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->snowflakeVisibleCounter = 0;
|
|
|
|
if (gWeatherPtr->snowflakeSpriteCount < gWeatherPtr->targetSnowflakeSpriteCount)
|
2019-04-01 04:07:29 +02:00
|
|
|
CreateSnowflakeSprite();
|
|
|
|
else
|
2019-04-02 03:04:23 +02:00
|
|
|
DestroySnowflakeSprite();
|
2019-04-01 04:07:29 +02:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
return gWeatherPtr->snowflakeSpriteCount != gWeatherPtr->targetSnowflakeSpriteCount;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const struct OamData sSnowflakeSpriteOamData =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
2018-12-08 19:05:03 +01:00
|
|
|
.mosaic = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(8x8),
|
2018-12-08 19:05:03 +01:00
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(8x8),
|
2018-12-08 19:05:03 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const struct SpriteFrameImage sSnowflakeSpriteImages[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
{gWeatherSnow1Tiles, sizeof(gWeatherSnow1Tiles)},
|
|
|
|
{gWeatherSnow2Tiles, sizeof(gWeatherSnow2Tiles)},
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd sSnowflakeAnimCmd0[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd sSnowflakeAnimCmd1[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(1, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd *const sSnowflakeAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sSnowflakeAnimCmd0,
|
|
|
|
sSnowflakeAnimCmd1,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static const struct SpriteTemplate sSnowflakeSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-09-14 19:14:14 +02:00
|
|
|
.tileTag = TAG_NONE,
|
2021-04-04 04:47:58 +02:00
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2019-04-02 03:04:23 +02:00
|
|
|
.oam = &sSnowflakeSpriteOamData,
|
|
|
|
.anims = sSnowflakeAnimCmds,
|
|
|
|
.images = sSnowflakeSpriteImages,
|
2018-12-08 19:05:03 +01:00
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-04-02 03:04:23 +02:00
|
|
|
.callback = UpdateSnowflakeSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#define tPosY data[0]
|
|
|
|
#define tDeltaY data[1]
|
|
|
|
#define tWaveDelta data[2]
|
|
|
|
#define tWaveIndex data[3]
|
|
|
|
#define tSnowflakeId data[4]
|
|
|
|
#define tFallCounter data[5]
|
|
|
|
#define tFallDuration data[6]
|
|
|
|
#define tDeltaY2 data[7]
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static bool8 CreateSnowflakeSprite(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u8 spriteId = CreateSpriteAtEnd(&sSnowflakeSpriteTemplate, 0, 0, 78);
|
2018-12-09 12:16:01 +01:00
|
|
|
if (spriteId == MAX_SPRITES)
|
2018-12-08 19:05:03 +01:00
|
|
|
return FALSE;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
|
|
|
gSprites[spriteId].tSnowflakeId = gWeatherPtr->snowflakeSpriteCount;
|
|
|
|
InitSnowflakeSpriteMovement(&gSprites[spriteId]);
|
2018-12-08 19:05:03 +01:00
|
|
|
gSprites[spriteId].coordOffsetEnabled = TRUE;
|
|
|
|
gWeatherPtr->sprites.s1.snowflakeSprites[gWeatherPtr->snowflakeSpriteCount++] = &gSprites[spriteId];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static bool8 DestroySnowflakeSprite(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->snowflakeSpriteCount)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s1.snowflakeSprites[--gWeatherPtr->snowflakeSpriteCount]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void InitSnowflakeSpriteMovement(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
u16 rand;
|
|
|
|
u16 x = ((sprite->tSnowflakeId * 5) & 7) * 30 + (Random() % 30);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = -3 - (gSpriteCoordOffsetY + sprite->centerToCornerVecY);
|
|
|
|
sprite->x = x - (gSpriteCoordOffsetX + sprite->centerToCornerVecX);
|
|
|
|
sprite->tPosY = sprite->y * 128;
|
|
|
|
sprite->x2 = 0;
|
2019-04-02 03:04:23 +02:00
|
|
|
rand = Random();
|
|
|
|
sprite->tDeltaY = (rand & 3) * 5 + 64;
|
|
|
|
sprite->tDeltaY2 = sprite->tDeltaY;
|
|
|
|
StartSpriteAnim(sprite, (rand & 1) ? 0 : 1);
|
|
|
|
sprite->tWaveIndex = 0;
|
|
|
|
sprite->tWaveDelta = ((rand & 3) == 0) ? 2 : 1;
|
|
|
|
sprite->tFallDuration = (rand & 0x1F) + 210;
|
|
|
|
sprite->tFallCounter = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void WaitSnowflakeSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:52:17 +02:00
|
|
|
// Timer is never incremented
|
|
|
|
if (gWeatherPtr->snowflakeTimer > 18)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
sprite->invisible = FALSE;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->callback = UpdateSnowflakeSprite;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 250 - (gSpriteCoordOffsetY + sprite->centerToCornerVecY);
|
|
|
|
sprite->tPosY = sprite->y * 128;
|
2021-04-04 06:52:17 +02:00
|
|
|
gWeatherPtr->snowflakeTimer = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void UpdateSnowflakeSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
s16 x;
|
|
|
|
s16 y;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->tPosY += sprite->tDeltaY;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = sprite->tPosY >> 7;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->tWaveIndex += sprite->tWaveDelta;
|
|
|
|
sprite->tWaveIndex &= 0xFF;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x2 = gSineTable[sprite->tWaveIndex] / 64;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
x = (sprite->x + sprite->centerToCornerVecX + gSpriteCoordOffsetX) & 0x1FF;
|
2019-04-02 03:04:23 +02:00
|
|
|
if (x & 0x100)
|
|
|
|
x |= -0x100;
|
|
|
|
|
|
|
|
if (x < -3)
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = 242 - (gSpriteCoordOffsetX + sprite->centerToCornerVecX);
|
2019-04-02 03:04:23 +02:00
|
|
|
else if (x > 242)
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = -3 - (gSpriteCoordOffsetX + sprite->centerToCornerVecX);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
y = (sprite->y + sprite->centerToCornerVecY + gSpriteCoordOffsetY) & 0xFF;
|
2019-04-02 03:04:23 +02:00
|
|
|
if (y > 163 && y < 171)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 250 - (gSpriteCoordOffsetY + sprite->centerToCornerVecY);
|
|
|
|
sprite->tPosY = sprite->y * 128;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->tFallCounter = 0;
|
|
|
|
sprite->tFallDuration = 220;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
else if (y > 242 && y < 250)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 163;
|
|
|
|
sprite->tPosY = sprite->y * 128;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->tFallCounter = 0;
|
|
|
|
sprite->tFallDuration = 220;
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->invisible = TRUE;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->callback = WaitSnowflakeSprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
if (++sprite->tFallCounter == sprite->tFallDuration)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
InitSnowflakeSpriteMovement(sprite);
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 250;
|
2018-12-08 19:05:03 +01:00
|
|
|
sprite->invisible = TRUE;
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->callback = WaitSnowflakeSprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#undef tPosY
|
|
|
|
#undef tDeltaY
|
|
|
|
#undef tWaveDelta
|
|
|
|
#undef tWaveIndex
|
|
|
|
#undef tSnowflakeId
|
|
|
|
#undef tFallCounter
|
|
|
|
#undef tFallDuration
|
|
|
|
#undef tDeltaY2
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_RAIN_THUNDERSTORM
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2021-04-04 06:23:06 +02:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Thunderstorm_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_LOAD_RAIN;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->rainSpriteVisibleCounter = 0;
|
|
|
|
gWeatherPtr->rainSpriteVisibleDelay = 4;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->isDownpour = FALSE;
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetRainSpriteCount = 16;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->gammaTargetIndex = 3;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderTriggered = FALSE;
|
2020-08-21 00:02:00 +02:00
|
|
|
SetRainStrengthFromSoundEffect(SE_THUNDERSTORM);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Thunderstorm_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
Thunderstorm_InitVars();
|
2018-12-08 19:05:03 +01:00
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
2019-12-06 19:25:45 +01:00
|
|
|
Thunderstorm_Main();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_DOWNPOUR
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void UpdateThunderSound(void);
|
|
|
|
static void SetThunderCounter(u16);
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Downpour_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_LOAD_RAIN;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
2019-04-01 04:07:29 +02:00
|
|
|
gWeatherPtr->rainSpriteVisibleCounter = 0;
|
|
|
|
gWeatherPtr->rainSpriteVisibleDelay = 4;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->isDownpour = TRUE;
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->targetRainSpriteCount = 24;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->gammaTargetIndex = 3;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
|
2020-08-21 00:02:00 +02:00
|
|
|
SetRainStrengthFromSoundEffect(SE_DOWNPOUR);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Downpour_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
Downpour_InitVars();
|
2018-12-08 19:05:03 +01:00
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
2019-12-06 19:25:45 +01:00
|
|
|
Thunderstorm_Main();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void Thunderstorm_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
UpdateThunderSound();
|
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_LOAD_RAIN:
|
2018-12-08 19:05:03 +01:00
|
|
|
LoadRainSpriteSheet();
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_CREATE_RAIN:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (!CreateRainSprite())
|
|
|
|
gWeatherPtr->initStep++;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_INIT_RAIN:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (!UpdateVisibleRainSprites())
|
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_WAIT_CHANGE:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER)
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_INIT_THUNDER_SHORT_1;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_LOOP_START:
|
|
|
|
gWeatherPtr->thunderAllowEnd = TRUE;
|
|
|
|
gWeatherPtr->thunderDelay = (Random() % 360) + 360;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
// fall through
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_LOOP_WAIT:
|
|
|
|
// Wait between 360-720 frames before trying thunder again
|
|
|
|
if (--gWeatherPtr->thunderDelay == 0)
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->initStep++;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_INIT_THUNDER_SHORT_1:
|
|
|
|
gWeatherPtr->thunderAllowEnd = TRUE;
|
|
|
|
gWeatherPtr->thunderSkipShort = Random() % 2;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_INIT_THUNDER_SHORT_2:
|
|
|
|
gWeatherPtr->thunderShortRetries = (Random() & 1) + 1;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
// fall through
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_TRY_THUNDER_SHORT:
|
|
|
|
ApplyWeatherGammaShiftIfIdle(19);
|
|
|
|
if (!gWeatherPtr->thunderSkipShort && gWeatherPtr->thunderShortRetries == 1)
|
|
|
|
SetThunderCounter(20); // Do short thunder
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderDelay = (Random() % 3) + 6;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_TRY_NEW_THUNDER:
|
|
|
|
if (--gWeatherPtr->thunderDelay == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
ApplyWeatherGammaShiftIfIdle(3);
|
|
|
|
gWeatherPtr->thunderAllowEnd = TRUE;
|
|
|
|
if (--gWeatherPtr->thunderShortRetries != 0)
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
// Try a short thunder again
|
|
|
|
gWeatherPtr->thunderDelay = (Random() % 16) + 60;
|
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_WAIT_THUNDER_SHORT;
|
2019-04-02 03:04:23 +02:00
|
|
|
}
|
2021-04-04 06:23:06 +02:00
|
|
|
else if (!gWeatherPtr->thunderSkipShort)
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
// No more thunder, restart loop
|
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_LOOP_START;
|
2019-04-02 03:04:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
// Set up long thunder
|
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_INIT_THUNDER_LONG;
|
2019-04-02 03:04:23 +02:00
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_WAIT_THUNDER_SHORT:
|
|
|
|
if (--gWeatherPtr->thunderDelay == 0)
|
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_TRY_THUNDER_SHORT;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_INIT_THUNDER_LONG:
|
|
|
|
gWeatherPtr->thunderDelay = (Random() % 16) + 60;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_WAIT_THUNDER_LONG:
|
|
|
|
if (--gWeatherPtr->thunderDelay == 0)
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
// Do long thunder
|
2019-04-02 03:04:23 +02:00
|
|
|
SetThunderCounter(100);
|
2021-04-04 06:23:06 +02:00
|
|
|
ApplyWeatherGammaShiftIfIdle(19);
|
|
|
|
gWeatherPtr->thunderDelay = (Random() & 0xF) + 30;
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_FADE_THUNDER_LONG:
|
|
|
|
if (--gWeatherPtr->thunderDelay == 0)
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-11-01 23:06:15 +01:00
|
|
|
ApplyWeatherGammaShiftIfIdle_Gradual(19, 3, 5);
|
2019-04-02 03:04:23 +02:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
2021-04-04 06:23:06 +02:00
|
|
|
case TSTORM_STATE_END_THUNDER_LONG:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
|
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderAllowEnd = TRUE;
|
|
|
|
gWeatherPtr->initStep = TSTORM_STATE_LOOP_START;
|
2019-04-02 03:04:23 +02:00
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
bool8 Thunderstorm_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderAllowEnd = FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
// fall through
|
|
|
|
case 1:
|
2019-12-06 19:25:45 +01:00
|
|
|
Thunderstorm_Main();
|
2021-04-04 06:23:06 +02:00
|
|
|
if (gWeatherPtr->thunderAllowEnd)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
if (gWeatherPtr->nextWeather == WEATHER_RAIN
|
|
|
|
|| gWeatherPtr->nextWeather == WEATHER_RAIN_THUNDERSTORM
|
|
|
|
|| gWeatherPtr->nextWeather == WEATHER_DOWNPOUR)
|
2018-12-08 19:05:03 +01:00
|
|
|
return FALSE;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
|
|
|
gWeatherPtr->targetRainSpriteCount = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (!UpdateVisibleRainSprites())
|
|
|
|
{
|
|
|
|
DestroyRainSprites();
|
|
|
|
gWeatherPtr->thunderTriggered = 0;
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2018-12-08 19:05:03 +01:00
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void SetThunderCounter(u16 max)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
if (!gWeatherPtr->thunderTriggered)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->thunderCounter = Random() % max;
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderTriggered = TRUE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 04:07:29 +02:00
|
|
|
static void UpdateThunderSound(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 06:23:06 +02:00
|
|
|
if (gWeatherPtr->thunderTriggered == TRUE)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
if (gWeatherPtr->thunderCounter == 0)
|
|
|
|
{
|
|
|
|
if (IsSEPlaying())
|
|
|
|
return;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
if (Random() & 1)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_THUNDER);
|
2018-12-08 19:05:03 +01:00
|
|
|
else
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_THUNDER2);
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-04 06:23:06 +02:00
|
|
|
gWeatherPtr->thunderTriggered = FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->thunderCounter--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_FOG_HORIZONTAL and WEATHER_UNDERWATER
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const u16 sUnusedData[] = {0, 6, 6, 12, 18, 42, 300, 300};
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const struct OamData sOamData_FogH =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
2019-12-05 03:00:45 +01:00
|
|
|
.objMode = ST_OAM_OBJ_BLEND,
|
2019-04-02 03:04:23 +02:00
|
|
|
.mosaic = 0,
|
2019-12-04 21:25:13 +01:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-04-02 03:04:23 +02:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
|
|
|
.size = SPRITE_SIZE(64x64),
|
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 2,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_0[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_1[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(32, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_2[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(64, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_3[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(96, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_4[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(128, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd sAnim_FogH_5[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(160, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AnimCmd *const sAnims_FogH[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-06 23:05:38 +02:00
|
|
|
sAnim_FogH_0,
|
|
|
|
sAnim_FogH_1,
|
|
|
|
sAnim_FogH_2,
|
|
|
|
sAnim_FogH_3,
|
|
|
|
sAnim_FogH_4,
|
|
|
|
sAnim_FogH_5,
|
2019-04-02 03:04:23 +02:00
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AffineAnimCmd sAffineAnim_FogH[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME(0x200, 0x200, 0, 0),
|
|
|
|
AFFINEANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2021-04-06 23:05:38 +02:00
|
|
|
static const union AffineAnimCmd *const sAffineAnims_FogH[] =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-06 23:05:38 +02:00
|
|
|
sAffineAnim_FogH,
|
2019-04-02 03:04:23 +02:00
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void FogHorizontalSpriteCallback(struct Sprite *);
|
|
|
|
static const struct SpriteTemplate sFogHorizontalSpriteTemplate =
|
2019-04-02 03:04:23 +02:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_FOG_H,
|
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2021-04-06 23:05:38 +02:00
|
|
|
.oam = &sOamData_FogH,
|
|
|
|
.anims = sAnims_FogH,
|
2019-04-02 03:04:23 +02:00
|
|
|
.images = NULL,
|
2021-04-06 23:05:38 +02:00
|
|
|
.affineAnims = sAffineAnims_FogH,
|
2019-12-06 19:25:45 +01:00
|
|
|
.callback = FogHorizontalSpriteCallback,
|
2019-04-02 03:04:23 +02:00
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogHorizontal_Main(void);
|
|
|
|
static void CreateFogHorizontalSprites(void);
|
|
|
|
static void DestroyFogHorizontalSprites(void);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogHorizontal_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2019-12-06 19:25:45 +01:00
|
|
|
if (gWeatherPtr->fogHSpritesCreated == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollCounter = 0;
|
|
|
|
gWeatherPtr->fogHScrollOffset = 0;
|
|
|
|
gWeatherPtr->fogHScrollPosX = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
Weather_SetBlendCoeffs(0, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogHorizontal_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
FogHorizontal_InitVars();
|
2018-12-08 19:05:03 +01:00
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
2019-12-06 19:25:45 +01:00
|
|
|
FogHorizontal_Main();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogHorizontal_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollPosX = (gSpriteCoordOffsetX - gWeatherPtr->fogHScrollOffset) & 0xFF;
|
|
|
|
if (++gWeatherPtr->fogHScrollCounter > 3)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollCounter = 0;
|
|
|
|
gWeatherPtr->fogHScrollOffset++;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-12-06 19:25:45 +01:00
|
|
|
CreateFogHorizontalSprites();
|
2019-12-02 01:19:47 +01:00
|
|
|
if (gWeatherPtr->currWeather == WEATHER_FOG_HORIZONTAL)
|
2018-12-08 19:05:03 +01:00
|
|
|
Weather_SetTargetBlendCoeffs(12, 8, 3);
|
|
|
|
else
|
|
|
|
Weather_SetTargetBlendCoeffs(4, 16, 0);
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
bool8 FogHorizontal_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollPosX = (gSpriteCoordOffsetX - gWeatherPtr->fogHScrollOffset) & 0xFF;
|
|
|
|
if (++gWeatherPtr->fogHScrollCounter > 3)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollCounter = 0;
|
|
|
|
gWeatherPtr->fogHScrollOffset++;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Weather_SetTargetBlendCoeffs(0, 16, 3);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
gWeatherPtr->finishStep++;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-12-06 19:25:45 +01:00
|
|
|
DestroyFogHorizontalSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#define tSpriteColumn data[0]
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void FogHorizontalSpriteCallback(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = (u8)gSpriteCoordOffsetY;
|
|
|
|
sprite->x = gWeatherPtr->fogHScrollPosX + 32 + sprite->tSpriteColumn * 64;
|
|
|
|
if (sprite->x > 271)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = 480 + gWeatherPtr->fogHScrollPosX - (4 - sprite->tSpriteColumn) * 64;
|
|
|
|
sprite->x &= 0x1FF;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void CreateFogHorizontalSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
2019-04-02 03:04:23 +02:00
|
|
|
u8 spriteId;
|
|
|
|
struct Sprite *sprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
if (!gWeatherPtr->fogHSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
struct SpriteSheet fogHorizontalSpriteSheet = {
|
|
|
|
.data = gWeatherFogHorizontalTiles,
|
|
|
|
.size = sizeof(gWeatherFogHorizontalTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_FOG_H,
|
2019-04-02 03:04:23 +02:00
|
|
|
};
|
2019-12-06 19:25:45 +01:00
|
|
|
LoadSpriteSheet(&fogHorizontalSpriteSheet);
|
|
|
|
for (i = 0; i < NUM_FOG_HORIZONTAL_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
spriteId = CreateSpriteAtEnd(&sFogHorizontalSpriteTemplate, 0, 0, 0xFF);
|
2018-12-08 19:05:03 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite = &gSprites[spriteId];
|
|
|
|
sprite->tSpriteColumn = i % 5;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = (i % 5) * 64 + 32;
|
|
|
|
sprite->y = (i / 5) * 64 + 32;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->sprites.s2.fogHSprites[i] = sprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->sprites.s2.fogHSprites[i] = NULL;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHSpritesCreated = TRUE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void DestroyFogHorizontalSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
if (gWeatherPtr->fogHSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
for (i = 0; i < NUM_FOG_HORIZONTAL_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
if (gWeatherPtr->sprites.s2.fogHSprites[i] != NULL)
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s2.fogHSprites[i]);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_FOG_H);
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHSpritesCreated = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#undef tSpriteColumn
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_VOLCANIC_ASH
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void LoadAshSpriteSheet(void);
|
|
|
|
static void CreateAshSprites(void);
|
|
|
|
static void DestroyAshSprites(void);
|
|
|
|
static void UpdateAshSprite(struct Sprite *);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
|
|
|
void Ash_InitVars(void)
|
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = FALSE;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2021-04-04 06:52:17 +02:00
|
|
|
gWeatherPtr->ashUnused = 20; // Never read
|
2018-12-08 19:05:03 +01:00
|
|
|
if (!gWeatherPtr->ashSpritesCreated)
|
|
|
|
{
|
|
|
|
Weather_SetBlendCoeffs(0, 16);
|
2019-04-02 03:04:23 +02:00
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(64, 63)); // These aren't valid blend coefficients!
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ash_InitAll(void)
|
|
|
|
{
|
|
|
|
Ash_InitVars();
|
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
|
|
|
Ash_Main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ash_Main(void)
|
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->ashBaseSpritesX = gSpriteCoordOffsetX & 0x1FF;
|
2021-04-15 08:04:01 +02:00
|
|
|
while (gWeatherPtr->ashBaseSpritesX >= DISPLAY_WIDTH)
|
|
|
|
gWeatherPtr->ashBaseSpritesX -= DISPLAY_WIDTH;
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
LoadAshSpriteSheet();
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!gWeatherPtr->ashSpritesCreated)
|
|
|
|
CreateAshSprites();
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
Weather_SetTargetBlendCoeffs(16, 0, 1);
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Weather_UpdateBlend();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Ash_Finish(void)
|
|
|
|
{
|
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Weather_SetTargetBlendCoeffs(0, 16, 1);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-04-02 03:04:23 +02:00
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
|
|
|
DestroyAshSprites();
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const struct SpriteSheet sAshSpriteSheet =
|
|
|
|
{
|
|
|
|
.data = gWeatherAshTiles,
|
|
|
|
.size = sizeof(gWeatherAshTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_ASH,
|
2019-04-02 03:04:23 +02:00
|
|
|
};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void LoadAshSpriteSheet(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
LoadSpriteSheet(&sAshSpriteSheet);
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const struct OamData sAshSpriteOamData =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-04-02 00:31:10 +02:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
2019-04-02 03:04:23 +02:00
|
|
|
.objMode = ST_OAM_OBJ_BLEND,
|
2019-04-02 00:31:10 +02:00
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.x = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.paletteNum = 15,
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd sAshSpriteAnimCmd0[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 60),
|
|
|
|
ANIMCMD_FRAME(64, 60),
|
|
|
|
ANIMCMD_JUMP(0),
|
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static const union AnimCmd *const sAshSpriteAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sAshSpriteAnimCmd0,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static const struct SpriteTemplate sAshSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_ASH,
|
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2019-04-02 03:04:23 +02:00
|
|
|
.oam = &sAshSpriteOamData,
|
|
|
|
.anims = sAshSpriteAnimCmds,
|
2018-12-08 19:05:03 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-04-02 03:04:23 +02:00
|
|
|
.callback = UpdateAshSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#define tOffsetY data[0]
|
|
|
|
#define tCounterY data[1]
|
|
|
|
#define tSpriteColumn data[2]
|
|
|
|
#define tSpriteRow data[3]
|
|
|
|
|
|
|
|
static void CreateAshSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u8 i;
|
2019-04-02 03:04:23 +02:00
|
|
|
u8 spriteId;
|
|
|
|
struct Sprite *sprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
|
|
|
if (!gWeatherPtr->ashSpritesCreated)
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
for (i = 0; i < NUM_ASH_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
spriteId = CreateSpriteAtEnd(&sAshSpriteTemplate, 0, 0, 0x4E);
|
2018-12-08 19:05:03 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite = &gSprites[spriteId];
|
|
|
|
sprite->tCounterY = 0;
|
|
|
|
sprite->tSpriteColumn = (u8)(i % 5);
|
|
|
|
sprite->tSpriteRow = (u8)(i / 5);
|
|
|
|
sprite->tOffsetY = sprite->tSpriteRow * 64 + 32;
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->sprites.s2.ashSprites[i] = sprite;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s2.ashSprites[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->ashSpritesCreated = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void DestroyAshSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
if (gWeatherPtr->ashSpritesCreated)
|
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
for (i = 0; i < NUM_ASH_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
if (gWeatherPtr->sprites.s2.ashSprites[i] != NULL)
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s2.ashSprites[i]);
|
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_ASH);
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->ashSpritesCreated = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
static void UpdateAshSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
if (++sprite->tCounterY > 5)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-02 03:04:23 +02:00
|
|
|
sprite->tCounterY = 0;
|
|
|
|
sprite->tOffsetY++;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-02 03:04:23 +02:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = gSpriteCoordOffsetY + sprite->tOffsetY;
|
|
|
|
sprite->x = gWeatherPtr->ashBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
|
|
|
|
if (sprite->x > 271)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = gWeatherPtr->ashBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64;
|
|
|
|
sprite->x &= 0x1FF;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 03:04:23 +02:00
|
|
|
#undef tOffsetY
|
|
|
|
#undef tCounterY
|
|
|
|
#undef tSpriteColumn
|
|
|
|
#undef tSpriteRow
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_FOG_DIAGONAL
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void UpdateFogDiagonalMovement(void);
|
|
|
|
static void CreateFogDiagonalSprites(void);
|
|
|
|
static void DestroyFogDiagonalSprites(void);
|
|
|
|
static void UpdateFogDiagonalSprite(struct Sprite *);
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogDiagonal_InitVars(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = 0;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogHScrollCounter = 0;
|
|
|
|
gWeatherPtr->fogHScrollOffset = 1;
|
|
|
|
if (!gWeatherPtr->fogDSpritesCreated)
|
|
|
|
{
|
|
|
|
gWeatherPtr->fogDScrollXCounter = 0;
|
|
|
|
gWeatherPtr->fogDScrollYCounter = 0;
|
|
|
|
gWeatherPtr->fogDXOffset = 0;
|
|
|
|
gWeatherPtr->fogDYOffset = 0;
|
|
|
|
gWeatherPtr->fogDBaseSpritesX = 0;
|
|
|
|
gWeatherPtr->fogDPosY = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
Weather_SetBlendCoeffs(0, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogDiagonal_InitAll(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
FogDiagonal_InitVars();
|
2018-12-08 19:05:03 +01:00
|
|
|
while (gWeatherPtr->weatherGfxLoaded == FALSE)
|
2019-12-06 19:25:45 +01:00
|
|
|
FogDiagonal_Main();
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
void FogDiagonal_Main(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
UpdateFogDiagonalMovement();
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-12-06 19:25:45 +01:00
|
|
|
CreateFogDiagonalSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Weather_SetTargetBlendCoeffs(12, 8, 8);
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!Weather_UpdateBlend())
|
|
|
|
break;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
bool8 FogDiagonal_Finish(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
UpdateFogDiagonalMovement();
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Weather_SetTargetBlendCoeffs(0, 16, 1);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!Weather_UpdateBlend())
|
|
|
|
break;
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-12-06 19:25:45 +01:00
|
|
|
DestroyFogDiagonalSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void UpdateFogDiagonalMovement(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
if (++gWeatherPtr->fogDScrollXCounter > 2)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogDXOffset++;
|
|
|
|
gWeatherPtr->fogDScrollXCounter = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
if (++gWeatherPtr->fogDScrollYCounter > 4)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogDYOffset++;
|
|
|
|
gWeatherPtr->fogDScrollYCounter = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogDBaseSpritesX = (gSpriteCoordOffsetX - gWeatherPtr->fogDXOffset) & 0xFF;
|
|
|
|
gWeatherPtr->fogDPosY = gSpriteCoordOffsetY + gWeatherPtr->fogDYOffset;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static const struct SpriteSheet gFogDiagonalSpriteSheet =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
.data = gWeatherFogDiagonalTiles,
|
|
|
|
.size = sizeof(gWeatherFogDiagonalTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_FOG_D,
|
2019-04-03 01:28:56 +02:00
|
|
|
};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static const struct OamData sFogDiagonalSpriteOamData =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-04-02 00:31:10 +02:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_BLEND,
|
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.x = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 2,
|
|
|
|
.paletteNum = 0,
|
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static const union AnimCmd sFogDiagonalSpriteAnimCmd0[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static const union AnimCmd *const sFogDiagonalSpriteAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
sFogDiagonalSpriteAnimCmd0,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static const struct SpriteTemplate sFogDiagonalSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_FOG_D,
|
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2019-12-06 19:25:45 +01:00
|
|
|
.oam = &sFogDiagonalSpriteOamData,
|
|
|
|
.anims = sFogDiagonalSpriteAnimCmds,
|
2018-12-08 19:05:03 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-12-06 19:25:45 +01:00
|
|
|
.callback = UpdateFogDiagonalSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
#define tSpriteColumn data[0]
|
|
|
|
#define tSpriteRow data[1]
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void CreateFogDiagonalSprites(void)
|
2019-04-03 01:28:56 +02:00
|
|
|
{
|
|
|
|
u16 i;
|
2019-12-06 19:25:45 +01:00
|
|
|
struct SpriteSheet fogDiagonalSpriteSheet;
|
2019-04-03 01:28:56 +02:00
|
|
|
u8 spriteId;
|
|
|
|
struct Sprite *sprite;
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
if (!gWeatherPtr->fogDSpritesCreated)
|
2019-04-03 01:28:56 +02:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
fogDiagonalSpriteSheet = gFogDiagonalSpriteSheet;
|
|
|
|
LoadSpriteSheet(&fogDiagonalSpriteSheet);
|
|
|
|
for (i = 0; i < NUM_FOG_DIAGONAL_SPRITES; i++)
|
2019-04-03 01:28:56 +02:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
spriteId = CreateSpriteAtEnd(&sFogDiagonalSpriteTemplate, 0, (i / 5) * 64, 0xFF);
|
2019-04-03 01:28:56 +02:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
|
|
|
sprite = &gSprites[spriteId];
|
|
|
|
sprite->tSpriteColumn = i % 5;
|
|
|
|
sprite->tSpriteRow = i / 5;
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->sprites.s2.fogDSprites[i] = sprite;
|
2019-04-03 01:28:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->sprites.s2.fogDSprites[i] = NULL;
|
2019-04-03 01:28:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogDSpritesCreated = TRUE;
|
2019-04-03 01:28:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void DestroyFogDiagonalSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
if (gWeatherPtr->fogDSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
for (i = 0; i < NUM_FOG_DIAGONAL_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
if (gWeatherPtr->sprites.s2.fogDSprites[i])
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s2.fogDSprites[i]);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_FOG_D);
|
2019-12-06 19:25:45 +01:00
|
|
|
gWeatherPtr->fogDSpritesCreated = FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:25:45 +01:00
|
|
|
static void UpdateFogDiagonalSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = gWeatherPtr->fogDPosY;
|
|
|
|
sprite->x = gWeatherPtr->fogDBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
|
|
|
|
if (sprite->x > 271)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = gWeatherPtr->fogDBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64;
|
|
|
|
sprite->x &= 0x1FF;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
#undef tSpriteColumn
|
|
|
|
#undef tSpriteRow
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_SANDSTORM
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateSandstormWaveIndex(void);
|
|
|
|
static void UpdateSandstormMovement(void);
|
|
|
|
static void CreateSandstormSprites(void);
|
|
|
|
static void CreateSwirlSandstormSprites(void);
|
|
|
|
static void DestroySandstormSprites(void);
|
|
|
|
static void UpdateSandstormSprite(struct Sprite *);
|
|
|
|
static void WaitSandSwirlSpriteEntrance(struct Sprite *);
|
|
|
|
static void UpdateSandstormSwirlSprite(struct Sprite *);
|
|
|
|
|
|
|
|
#define MIN_SANDSTORM_WAVE_INDEX 0x20
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
void Sandstorm_InitVars(void)
|
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->weatherGfxLoaded = 0;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 0;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
2019-04-03 01:28:56 +02:00
|
|
|
if (!gWeatherPtr->sandstormSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sandstormXOffset = gWeatherPtr->sandstormYOffset = 0;
|
|
|
|
gWeatherPtr->sandstormWaveIndex = 8;
|
|
|
|
gWeatherPtr->sandstormWaveCounter = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
// Dead code. How does the compiler not optimize this out?
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->sandstormWaveIndex >= 0x80 - MIN_SANDSTORM_WAVE_INDEX)
|
|
|
|
gWeatherPtr->sandstormWaveIndex = 0x80 - gWeatherPtr->sandstormWaveIndex;
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
Weather_SetBlendCoeffs(0, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sandstorm_InitAll(void)
|
|
|
|
{
|
|
|
|
Sandstorm_InitVars();
|
2019-04-03 01:28:56 +02:00
|
|
|
while (!gWeatherPtr->weatherGfxLoaded)
|
2018-12-08 19:05:03 +01:00
|
|
|
Sandstorm_Main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sandstorm_Main(void)
|
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
UpdateSandstormMovement();
|
|
|
|
UpdateSandstormWaveIndex();
|
|
|
|
if (gWeatherPtr->sandstormWaveIndex >= 0x80 - MIN_SANDSTORM_WAVE_INDEX)
|
|
|
|
gWeatherPtr->sandstormWaveIndex = MIN_SANDSTORM_WAVE_INDEX;
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->initStep)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-04-03 01:28:56 +02:00
|
|
|
CreateSandstormSprites();
|
|
|
|
CreateSwirlSandstormSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Weather_SetTargetBlendCoeffs(16, 0, 0);
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-04-03 01:28:56 +02:00
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
{
|
|
|
|
gWeatherPtr->weatherGfxLoaded = TRUE;
|
|
|
|
gWeatherPtr->initStep++;
|
|
|
|
}
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Sandstorm_Finish(void)
|
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
UpdateSandstormMovement();
|
|
|
|
UpdateSandstormWaveIndex();
|
2018-12-08 19:05:03 +01:00
|
|
|
switch (gWeatherPtr->finishStep)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Weather_SetTargetBlendCoeffs(0, 16, 0);
|
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
case 1:
|
2019-04-03 01:28:56 +02:00
|
|
|
if (Weather_UpdateBlend())
|
|
|
|
gWeatherPtr->finishStep++;
|
2018-12-08 19:05:03 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-04-03 01:28:56 +02:00
|
|
|
DestroySandstormSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
gWeatherPtr->finishStep++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateSandstormWaveIndex(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->sandstormWaveCounter++ > 4)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sandstormWaveIndex++;
|
|
|
|
gWeatherPtr->sandstormWaveCounter = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateSandstormMovement(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sandstormXOffset -= gSineTable[gWeatherPtr->sandstormWaveIndex] * 4;
|
|
|
|
gWeatherPtr->sandstormYOffset -= gSineTable[gWeatherPtr->sandstormWaveIndex];
|
|
|
|
gWeatherPtr->sandstormBaseSpritesX = (gSpriteCoordOffsetX + (gWeatherPtr->sandstormXOffset >> 8)) & 0xFF;
|
|
|
|
gWeatherPtr->sandstormPosY = gSpriteCoordOffsetY + (gWeatherPtr->sandstormYOffset >> 8);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void DestroySandstormSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->sandstormSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
for (i = 0; i < NUM_SANDSTORM_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->sprites.s2.sandstormSprites1[i])
|
2018-12-08 19:05:03 +01:00
|
|
|
DestroySprite(gWeatherPtr->sprites.s2.sandstormSprites1[i]);
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
|
|
|
gWeatherPtr->sandstormSpritesCreated = FALSE;
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_SANDSTORM);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->sandstormSwirlSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
for (i = 0; i < NUM_SWIRL_SANDSTORM_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
if (gWeatherPtr->sprites.s2.sandstormSprites2[i] != NULL)
|
|
|
|
DestroySprite(gWeatherPtr->sprites.s2.sandstormSprites2[i]);
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
|
|
|
gWeatherPtr->sandstormSwirlSpritesCreated = FALSE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const struct OamData sSandstormSpriteOamData =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
.y = 0,
|
2019-04-02 00:31:10 +02:00
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_BLEND,
|
|
|
|
.bpp = ST_OAM_4BPP,
|
2019-03-11 08:12:15 +01:00
|
|
|
.shape = SPRITE_SHAPE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.x = 0,
|
2019-03-11 08:12:15 +01:00
|
|
|
.size = SPRITE_SIZE(64x64),
|
2018-12-08 19:05:03 +01:00
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 1,
|
|
|
|
.paletteNum = 0,
|
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const union AnimCmd sSandstormSpriteAnimCmd0[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 3),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const union AnimCmd sSandstormSpriteAnimCmd1[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(64, 3),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const union AnimCmd *const sSandstormSpriteAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
sSandstormSpriteAnimCmd0,
|
|
|
|
sSandstormSpriteAnimCmd1,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const struct SpriteTemplate sSandstormSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_SANDSTORM,
|
|
|
|
.paletteTag = PALTAG_WEATHER_2,
|
2019-04-03 01:28:56 +02:00
|
|
|
.oam = &sSandstormSpriteOamData,
|
|
|
|
.anims = sSandstormSpriteAnimCmds,
|
2018-12-08 19:05:03 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-04-03 01:28:56 +02:00
|
|
|
.callback = UpdateSandstormSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const struct SpriteSheet sSandstormSpriteSheet =
|
|
|
|
{
|
|
|
|
.data = gWeatherSandstormTiles,
|
|
|
|
.size = sizeof(gWeatherSandstormTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_SANDSTORM,
|
2019-04-03 01:28:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Regular sandstorm sprites
|
|
|
|
#define tSpriteColumn data[0]
|
|
|
|
#define tSpriteRow data[1]
|
|
|
|
|
|
|
|
// Swirly sandstorm sprites
|
|
|
|
#define tRadius data[0]
|
|
|
|
#define tWaveIndex data[1]
|
|
|
|
#define tRadiusCounter data[2]
|
|
|
|
#define tEntranceDelay data[3]
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void CreateSandstormSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
2019-04-03 01:28:56 +02:00
|
|
|
u8 spriteId;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
if (!gWeatherPtr->sandstormSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
LoadSpriteSheet(&sSandstormSpriteSheet);
|
2019-04-03 01:28:56 +02:00
|
|
|
LoadCustomWeatherSpritePalette(gSandstormWeatherPalette);
|
|
|
|
for (i = 0; i < NUM_SANDSTORM_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
spriteId = CreateSpriteAtEnd(&sSandstormSpriteTemplate, 0, (i / 5) * 64, 1);
|
2018-12-08 19:05:03 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites1[i] = &gSprites[spriteId];
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites1[i]->tSpriteColumn = i % 5;
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites1[i]->tSpriteRow = i / 5;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites1[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
|
|
|
gWeatherPtr->sandstormSpritesCreated = TRUE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const u16 sSwirlEntranceDelays[] = {0, 120, 80, 160, 40, 0};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void CreateSwirlSandstormSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
2019-04-03 01:28:56 +02:00
|
|
|
u8 spriteId;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
if (!gWeatherPtr->sandstormSwirlSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
for (i = 0; i < NUM_SWIRL_SANDSTORM_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
spriteId = CreateSpriteAtEnd(&sSandstormSpriteTemplate, i * 48 + 24, 208, 1);
|
2018-12-08 19:05:03 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i] = &gSprites[spriteId];
|
2019-12-05 03:00:45 +01:00
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->oam.size = ST_OAM_SIZE_2;
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->tSpriteRow = i * 51;
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->tRadius = 8;
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->tRadiusCounter = 0;
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->data[4] = 0x6730; // unused value
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->tEntranceDelay = sSwirlEntranceDelays[i];
|
2018-12-08 19:05:03 +01:00
|
|
|
StartSpriteAnim(gWeatherPtr->sprites.s2.sandstormSprites2[i], 1);
|
2019-12-05 03:00:45 +01:00
|
|
|
CalcCenterToCornerVec(gWeatherPtr->sprites.s2.sandstormSprites2[i], SPRITE_SHAPE(32x32), SPRITE_SIZE(32x32), ST_OAM_AFFINE_OFF);
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i]->callback = WaitSandSwirlSpriteEntrance;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gWeatherPtr->sprites.s2.sandstormSprites2[i] = NULL;
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
|
|
|
gWeatherPtr->sandstormSwirlSpritesCreated = TRUE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateSandstormSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = gWeatherPtr->sandstormPosY;
|
|
|
|
sprite->x = gWeatherPtr->sandstormBaseSpritesX + 32 + sprite->tSpriteColumn * 64;
|
|
|
|
if (sprite->x > 271)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x = gWeatherPtr->sandstormBaseSpritesX + 480 - (4 - sprite->tSpriteColumn) * 64;
|
|
|
|
sprite->x &= 0x1FF;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void WaitSandSwirlSpriteEntrance(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
if (--sprite->tEntranceDelay == -1)
|
|
|
|
sprite->callback = UpdateSandstormSwirlSprite;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateSandstormSwirlSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
u32 x, y;
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
if (--sprite->y < -48)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y = 208;
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tRadius = 4;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
|
|
|
x = sprite->tRadius * gSineTable[sprite->tWaveIndex];
|
|
|
|
y = sprite->tRadius * gSineTable[sprite->tWaveIndex + 0x40];
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->x2 = x >> 8;
|
|
|
|
sprite->y2 = y >> 8;
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tWaveIndex = (sprite->tWaveIndex + 10) & 0xFF;
|
|
|
|
if (++sprite->tRadiusCounter > 8)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tRadiusCounter = 0;
|
|
|
|
sprite->tRadius++;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
#undef tSpriteColumn
|
|
|
|
#undef tSpriteRow
|
|
|
|
|
|
|
|
#undef tRadius
|
|
|
|
#undef tWaveIndex
|
|
|
|
#undef tRadiusCounter
|
|
|
|
#undef tEntranceDelay
|
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_SHADE
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Shade_InitVars(void)
|
|
|
|
{
|
|
|
|
gWeatherPtr->initStep = 0;
|
|
|
|
gWeatherPtr->gammaTargetIndex = 3;
|
|
|
|
gWeatherPtr->gammaStepDelay = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shade_InitAll(void)
|
|
|
|
{
|
|
|
|
Shade_InitVars();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shade_Main(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Shade_Finish(void)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2019-12-06 19:25:45 +01:00
|
|
|
// WEATHER_UNDERWATER_BUBBLES
|
2018-12-08 19:05:03 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void CreateBubbleSprite(u16);
|
|
|
|
static void DestroyBubbleSprites(void);
|
|
|
|
static void UpdateBubbleSprite(struct Sprite *);
|
|
|
|
|
|
|
|
static const u8 sBubbleStartDelays[] = {40, 90, 60, 90, 2, 60, 40, 30};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const struct SpriteSheet sWeatherBubbleSpriteSheet =
|
|
|
|
{
|
|
|
|
.data = gWeatherBubbleTiles,
|
|
|
|
.size = sizeof(gWeatherBubbleTiles),
|
2021-04-04 04:47:58 +02:00
|
|
|
.tag = GFXTAG_BUBBLE,
|
2019-04-03 01:28:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const s16 sBubbleStartCoords[][2] =
|
|
|
|
{
|
|
|
|
{120, 160},
|
|
|
|
{376, 160},
|
|
|
|
{ 40, 140},
|
|
|
|
{296, 140},
|
|
|
|
{180, 130},
|
|
|
|
{436, 130},
|
|
|
|
{ 60, 160},
|
|
|
|
{436, 160},
|
|
|
|
{220, 180},
|
|
|
|
{476, 180},
|
|
|
|
{ 10, 90},
|
|
|
|
{266, 90},
|
|
|
|
{256, 160},
|
|
|
|
};
|
2018-12-08 19:05:03 +01:00
|
|
|
|
|
|
|
void Bubbles_InitVars(void)
|
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
FogHorizontal_InitVars();
|
2019-04-03 01:28:56 +02:00
|
|
|
if (!gWeatherPtr->bubblesSpritesCreated)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
LoadSpriteSheet(&sWeatherBubbleSpriteSheet);
|
|
|
|
gWeatherPtr->bubblesDelayIndex = 0;
|
|
|
|
gWeatherPtr->bubblesDelayCounter = sBubbleStartDelays[0];
|
|
|
|
gWeatherPtr->bubblesCoordsIndex = 0;
|
|
|
|
gWeatherPtr->bubblesSpriteCount = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bubbles_InitAll(void)
|
|
|
|
{
|
|
|
|
Bubbles_InitVars();
|
2019-04-03 01:28:56 +02:00
|
|
|
while (!gWeatherPtr->weatherGfxLoaded)
|
2018-12-08 19:05:03 +01:00
|
|
|
Bubbles_Main();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bubbles_Main(void)
|
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
FogHorizontal_Main();
|
2019-04-03 01:28:56 +02:00
|
|
|
if (++gWeatherPtr->bubblesDelayCounter > sBubbleStartDelays[gWeatherPtr->bubblesDelayIndex])
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->bubblesDelayCounter = 0;
|
|
|
|
if (++gWeatherPtr->bubblesDelayIndex > ARRAY_COUNT(sBubbleStartDelays) - 1)
|
|
|
|
gWeatherPtr->bubblesDelayIndex = 0;
|
|
|
|
|
|
|
|
CreateBubbleSprite(gWeatherPtr->bubblesCoordsIndex);
|
|
|
|
if (++gWeatherPtr->bubblesCoordsIndex > ARRAY_COUNT(sBubbleStartCoords) - 1)
|
|
|
|
gWeatherPtr->bubblesCoordsIndex = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 Bubbles_Finish(void)
|
|
|
|
{
|
2019-12-06 19:25:45 +01:00
|
|
|
if (!FogHorizontal_Finish())
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
DestroyBubbleSprites();
|
2018-12-08 19:05:03 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2018-12-08 19:05:03 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const union AnimCmd sBubbleSpriteAnimCmd0[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 16),
|
|
|
|
ANIMCMD_FRAME(1, 16),
|
|
|
|
ANIMCMD_END,
|
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const union AnimCmd *const sBubbleSpriteAnimCmds[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
sBubbleSpriteAnimCmd0,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static const struct SpriteTemplate sBubbleSpriteTemplate =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-04-04 04:47:58 +02:00
|
|
|
.tileTag = GFXTAG_BUBBLE,
|
|
|
|
.paletteTag = PALTAG_WEATHER,
|
2019-10-15 01:26:47 +02:00
|
|
|
.oam = &gOamData_AffineOff_ObjNormal_8x8,
|
2019-04-03 01:28:56 +02:00
|
|
|
.anims = sBubbleSpriteAnimCmds,
|
2018-12-08 19:05:03 +01:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
2019-04-03 01:28:56 +02:00
|
|
|
.callback = UpdateBubbleSprite,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
#define tScrollXCounter data[0]
|
|
|
|
#define tScrollXDir data[1]
|
|
|
|
#define tCounter data[2]
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void CreateBubbleSprite(u16 coordsIndex)
|
|
|
|
{
|
|
|
|
s16 x = sBubbleStartCoords[coordsIndex][0];
|
|
|
|
s16 y = sBubbleStartCoords[coordsIndex][1] - gSpriteCoordOffsetY;
|
|
|
|
u8 spriteId = CreateSpriteAtEnd(&sBubbleSpriteTemplate, x, y, 0);
|
2018-12-08 19:05:03 +01:00
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
|
|
|
gSprites[spriteId].oam.priority = 1;
|
|
|
|
gSprites[spriteId].coordOffsetEnabled = TRUE;
|
2019-04-03 01:28:56 +02:00
|
|
|
gSprites[spriteId].tScrollXCounter = 0;
|
|
|
|
gSprites[spriteId].tScrollXDir = 0;
|
|
|
|
gSprites[spriteId].tCounter = 0;
|
|
|
|
gWeatherPtr->bubblesSpriteCount++;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void DestroyBubbleSprites(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gWeatherPtr->bubblesSpriteCount)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
for (i = 0; i < MAX_SPRITES; i++)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
if (gSprites[i].template == &sBubbleSpriteTemplate)
|
2018-12-08 19:05:03 +01:00
|
|
|
DestroySprite(&gSprites[i]);
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2021-04-04 04:47:58 +02:00
|
|
|
FreeSpriteTilesByTag(GFXTAG_BUBBLE);
|
2019-04-03 01:28:56 +02:00
|
|
|
gWeatherPtr->bubblesSpriteCount = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
static void UpdateBubbleSprite(struct Sprite *sprite)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
++sprite->tScrollXCounter;
|
|
|
|
if (++sprite->tScrollXCounter > 8) // double increment
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tScrollXCounter = 0;
|
|
|
|
if (sprite->tScrollXDir == 0)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
if (++sprite->x2 > 4)
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tScrollXDir = 1;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
if (--sprite->x2 <= 0)
|
2019-04-03 01:28:56 +02:00
|
|
|
sprite->tScrollXDir = 0;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-03 01:28:56 +02:00
|
|
|
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y -= 3;
|
2019-04-03 01:28:56 +02:00
|
|
|
if (++sprite->tCounter >= 120)
|
2018-12-08 19:05:03 +01:00
|
|
|
DestroySprite(sprite);
|
|
|
|
}
|
|
|
|
|
2019-04-03 01:28:56 +02:00
|
|
|
#undef tScrollXCounter
|
|
|
|
#undef tScrollXDir
|
|
|
|
#undef tCounter
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-02-23 04:20:42 +01:00
|
|
|
// Unused function.
|
2019-12-02 01:19:47 +01:00
|
|
|
static void UnusedSetCurrentAbnormalWeather(u32 a0, u32 a1)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
gCurrentAbnormalWeather = a0;
|
2019-02-23 04:20:42 +01:00
|
|
|
gUnusedWeatherRelated = a1;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 01:19:47 +01:00
|
|
|
static void Task_DoAbnormalWeather(u8 taskId)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
switch (data[0])
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (data[15]-- <= 0)
|
|
|
|
{
|
2019-02-23 04:20:42 +01:00
|
|
|
SetNextWeather(data[1]);
|
2019-12-02 01:19:47 +01:00
|
|
|
gCurrentAbnormalWeather = data[1];
|
2018-12-08 19:05:03 +01:00
|
|
|
data[15] = 600;
|
|
|
|
data[0]++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (data[15]-- <= 0)
|
|
|
|
{
|
2019-02-23 04:20:42 +01:00
|
|
|
SetNextWeather(data[2]);
|
2019-12-02 01:19:47 +01:00
|
|
|
gCurrentAbnormalWeather = data[2];
|
2018-12-08 19:05:03 +01:00
|
|
|
data[15] = 600;
|
|
|
|
data[0] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 01:19:47 +01:00
|
|
|
static void CreateAbnormalWeatherTask(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
u8 taskId = CreateTask(Task_DoAbnormalWeather, 0);
|
2018-12-08 19:05:03 +01:00
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
data[15] = 600;
|
2019-12-02 01:19:47 +01:00
|
|
|
if (gCurrentAbnormalWeather == WEATHER_DOWNPOUR)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2018-12-08 19:43:21 +01:00
|
|
|
data[1] = WEATHER_DROUGHT;
|
2019-12-02 01:19:47 +01:00
|
|
|
data[2] = WEATHER_DOWNPOUR;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-12-02 01:19:47 +01:00
|
|
|
else if (gCurrentAbnormalWeather == WEATHER_DROUGHT)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
data[1] = WEATHER_DOWNPOUR;
|
2018-12-08 19:43:21 +01:00
|
|
|
data[2] = WEATHER_DROUGHT;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
gCurrentAbnormalWeather = WEATHER_DOWNPOUR;
|
2018-12-08 19:43:21 +01:00
|
|
|
data[1] = WEATHER_DROUGHT;
|
2019-12-02 01:19:47 +01:00
|
|
|
data[2] = WEATHER_DOWNPOUR;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static u8 TranslateWeatherNum(u8);
|
|
|
|
static void UpdateRainCounter(u8, u8);
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2021-11-16 23:12:16 +01:00
|
|
|
void SetSavedWeather(u32 weather)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u8 oldWeather = gSaveBlock1Ptr->weather;
|
|
|
|
gSaveBlock1Ptr->weather = TranslateWeatherNum(weather);
|
|
|
|
UpdateRainCounter(gSaveBlock1Ptr->weather, oldWeather);
|
|
|
|
}
|
|
|
|
|
2021-11-16 23:12:16 +01:00
|
|
|
u8 GetSavedWeather(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
return gSaveBlock1Ptr->weather;
|
|
|
|
}
|
|
|
|
|
2021-11-16 23:12:16 +01:00
|
|
|
void SetSavedWeatherFromCurrMapHeader(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
u8 oldWeather = gSaveBlock1Ptr->weather;
|
|
|
|
gSaveBlock1Ptr->weather = TranslateWeatherNum(gMapHeader.weather);
|
|
|
|
UpdateRainCounter(gSaveBlock1Ptr->weather, oldWeather);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetWeather(u32 weather)
|
|
|
|
{
|
2021-11-16 23:12:16 +01:00
|
|
|
SetSavedWeather(weather);
|
|
|
|
SetNextWeather(GetSavedWeather());
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetWeather_Unused(u32 weather)
|
|
|
|
{
|
2021-11-16 23:12:16 +01:00
|
|
|
SetSavedWeather(weather);
|
|
|
|
SetCurrentAndNextWeather(GetSavedWeather());
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoCurrentWeather(void)
|
|
|
|
{
|
2021-11-16 23:12:16 +01:00
|
|
|
u8 weather = GetSavedWeather();
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-02 01:19:47 +01:00
|
|
|
if (weather == WEATHER_ABNORMAL)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
if (!FuncIsActiveTask(Task_DoAbnormalWeather))
|
|
|
|
CreateAbnormalWeatherTask();
|
|
|
|
weather = gCurrentAbnormalWeather;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
if (FuncIsActiveTask(Task_DoAbnormalWeather))
|
|
|
|
DestroyTask(FindTaskIdByFunc(Task_DoAbnormalWeather));
|
|
|
|
gCurrentAbnormalWeather = WEATHER_DOWNPOUR;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-02-23 04:20:42 +01:00
|
|
|
SetNextWeather(weather);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 08:28:41 +01:00
|
|
|
void ResumePausedWeather(void)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2021-11-16 23:12:16 +01:00
|
|
|
u8 weather = GetSavedWeather();
|
2018-12-08 19:05:03 +01:00
|
|
|
|
2019-12-02 01:19:47 +01:00
|
|
|
if (weather == WEATHER_ABNORMAL)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
if (!FuncIsActiveTask(Task_DoAbnormalWeather))
|
|
|
|
CreateAbnormalWeatherTask();
|
|
|
|
weather = gCurrentAbnormalWeather;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
if (FuncIsActiveTask(Task_DoAbnormalWeather))
|
|
|
|
DestroyTask(FindTaskIdByFunc(Task_DoAbnormalWeather));
|
|
|
|
gCurrentAbnormalWeather = WEATHER_DOWNPOUR;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
2019-02-23 04:20:42 +01:00
|
|
|
SetCurrentAndNextWeather(weather);
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static const u8 sWeatherCycleRoute119[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
WEATHER_SUNNY,
|
2019-12-02 01:19:47 +01:00
|
|
|
WEATHER_RAIN,
|
|
|
|
WEATHER_RAIN_THUNDERSTORM,
|
|
|
|
WEATHER_RAIN,
|
2018-12-08 19:05:03 +01:00
|
|
|
};
|
2018-12-08 19:43:21 +01:00
|
|
|
static const u8 sWeatherCycleRoute123[] =
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
WEATHER_SUNNY,
|
|
|
|
WEATHER_SUNNY,
|
2019-12-02 01:19:47 +01:00
|
|
|
WEATHER_RAIN,
|
2018-12-08 19:05:03 +01:00
|
|
|
WEATHER_SUNNY,
|
|
|
|
};
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static u8 TranslateWeatherNum(u8 weather)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
switch (weather)
|
|
|
|
{
|
2019-12-02 01:19:47 +01:00
|
|
|
case WEATHER_NONE: return WEATHER_NONE;
|
|
|
|
case WEATHER_SUNNY_CLOUDS: return WEATHER_SUNNY_CLOUDS;
|
|
|
|
case WEATHER_SUNNY: return WEATHER_SUNNY;
|
|
|
|
case WEATHER_RAIN: return WEATHER_RAIN;
|
|
|
|
case WEATHER_SNOW: return WEATHER_SNOW;
|
|
|
|
case WEATHER_RAIN_THUNDERSTORM: return WEATHER_RAIN_THUNDERSTORM;
|
|
|
|
case WEATHER_FOG_HORIZONTAL: return WEATHER_FOG_HORIZONTAL;
|
|
|
|
case WEATHER_VOLCANIC_ASH: return WEATHER_VOLCANIC_ASH;
|
|
|
|
case WEATHER_SANDSTORM: return WEATHER_SANDSTORM;
|
|
|
|
case WEATHER_FOG_DIAGONAL: return WEATHER_FOG_DIAGONAL;
|
|
|
|
case WEATHER_UNDERWATER: return WEATHER_UNDERWATER;
|
2019-12-06 08:27:58 +01:00
|
|
|
case WEATHER_SHADE: return WEATHER_SHADE;
|
2019-12-02 01:19:47 +01:00
|
|
|
case WEATHER_DROUGHT: return WEATHER_DROUGHT;
|
|
|
|
case WEATHER_DOWNPOUR: return WEATHER_DOWNPOUR;
|
|
|
|
case WEATHER_UNDERWATER_BUBBLES: return WEATHER_UNDERWATER_BUBBLES;
|
|
|
|
case WEATHER_ABNORMAL: return WEATHER_ABNORMAL;
|
|
|
|
case WEATHER_ROUTE119_CYCLE: return sWeatherCycleRoute119[gSaveBlock1Ptr->weatherCycleStage];
|
|
|
|
case WEATHER_ROUTE123_CYCLE: return sWeatherCycleRoute123[gSaveBlock1Ptr->weatherCycleStage];
|
|
|
|
default: return WEATHER_NONE;
|
2018-12-08 19:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateWeatherPerDay(u16 increment)
|
|
|
|
{
|
|
|
|
u16 weatherStage = gSaveBlock1Ptr->weatherCycleStage + increment;
|
|
|
|
weatherStage %= 4;
|
|
|
|
gSaveBlock1Ptr->weatherCycleStage = weatherStage;
|
|
|
|
}
|
|
|
|
|
2018-12-08 19:43:21 +01:00
|
|
|
static void UpdateRainCounter(u8 newWeather, u8 oldWeather)
|
2018-12-08 19:05:03 +01:00
|
|
|
{
|
|
|
|
if (newWeather != oldWeather
|
2019-12-02 01:19:47 +01:00
|
|
|
&& (newWeather == WEATHER_RAIN || newWeather == WEATHER_RAIN_THUNDERSTORM))
|
2018-12-08 19:05:03 +01:00
|
|
|
IncrementGameStat(GAME_STAT_GOT_RAINED_ON);
|
|
|
|
}
|
2019-04-02 00:31:10 +02:00
|
|
|
|
|
|
|
|