added drought, aligned with emerald

This commit is contained in:
cawtds
2024-11-18 10:48:31 +01:00
parent 66761306aa
commit e3242907b0
11 changed files with 299 additions and 274 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,6 +8,7 @@
#define NUM_FOG_DIAGONAL_SPRITES 20
#define NUM_SANDSTORM_SPRITES 20
#define NUM_SWIRL_SANDSTORM_SPRITES 5
#define NUM_SNOWFLAKE_SPRITES 16
// Controls how the weather should be changing the screen palettes.
#define WEATHER_PAL_STATE_CHANGING_WEATHER 0

View File

@@ -18,6 +18,8 @@ enum {
PALTAG_WEATHER = TAG_WEATHER_START,
};
#define NUM_WEATHER_COLOR_MAPS 19
struct Weather
{
union
@@ -38,12 +40,10 @@ struct Weather
struct Sprite *sandstormSprites2[NUM_SWIRL_SANDSTORM_SPRITES];
} s2;
} sprites;
u8 gammaShifts[19][32];
u8 altGammaShifts[19][32];
s8 gammaIndex;
s8 gammaTargetIndex;
u8 gammaStepDelay;
u8 gammaStepFrameCounter;
s8 colorMapIndex;
s8 targetColorMapIndex;
u8 colorMapStepDelay;
u8 colorMapStepCounter;
u16 fadeDestColor;
u8 palProcessingState;
u8 fadeScreenCounter;
@@ -58,7 +58,8 @@ struct Weather
u8 weatherGfxLoaded;
bool8 weatherChangeComplete;
u8 weatherPicSpritePalIndex;
u8 altGammaSpritePalIndex;
u8 contrastColorMapSpritePalIndex;
// Rain
u16 rainSpriteVisibleCounter;
u8 curRainSpriteIndex;
u8 targetRainSpriteCount;
@@ -67,34 +68,40 @@ struct Weather
u8 isDownpour;
u8 rainStrength;
bool8 cloudSpritesCreated;
// Snow
u16 snowflakeVisibleCounter;
u16 snowflakeTimer;
u8 snowflakeSpriteCount;
u8 targetSnowflakeSpriteCount;
u16 thunderDelay;
u16 thunderCounter;
// Thunderstorm
u16 thunderTimer;
u16 thunderSETimer;
bool8 thunderAllowEnd;
bool8 thunderSkipShort;
u8 thunderShortRetries;
bool8 thunderTriggered;
bool8 thunderLongBolt;
u8 thunderShortBolts;
bool8 thunderEnqueued;
// Horizontal fog
u16 fogHScrollPosX;
u16 fogHScrollCounter;
u16 fogHScrollOffset;
u8 lightenedFogSpritePals[6];
u8 lightenedFogSpritePalsCount;
bool8 fogHSpritesCreated;
// Ash
u16 ashBaseSpritesX;
u16 ashUnused;
bool8 ashSpritesCreated;
// Sandstorm
u32 sandstormXOffset;
u32 sandstormYOffset;
u8 filler_70C[2];
u16 sandstormUnused;
u16 sandstormBaseSpritesX;
u16 sandstormPosY;
u16 sandstormWaveIndex;
u16 sandstormWaveCounter;
bool8 sandstormSpritesCreated;
bool8 sandstormSwirlSpritesCreated;
// Diagonal fog
u16 fogDBaseSpritesX;
u16 fogDPosY;
u16 fogDScrollXCounter;
@@ -102,11 +109,13 @@ struct Weather
u16 fogDXOffset;
u16 fogDYOffset;
bool8 fogDSpritesCreated;
// Bubbles
u16 bubblesDelayCounter;
u16 bubblesDelayIndex;
u16 bubblesCoordsIndex;
u16 bubblesSpriteCount;
bool8 bubblesSpritesCreated;
u16 currBlendEVA;
u16 currBlendEVB;
u16 targetBlendEVA;
@@ -114,11 +123,12 @@ struct Weather
u8 blendUpdateCounter;
u8 blendFrameCounter;
u8 blendDelay;
// Drought
s16 droughtBrightnessStage;
s16 droughtLastBrightnessStage;
s16 droughtTimer;
s16 droughtState;
u8 filler_744[9];
u8 droughtUnused[9];
u8 loadDroughtPalsIndex;
u8 loadDroughtPalsOffset;
};
@@ -155,9 +165,9 @@ bool8 LoadDroughtWeatherPalettes(void);
void DroughtStateInit(void);
void DroughtStateRun(void);
void SetRainStrengthFromSoundEffect(u16 soundEffect);
void WeatherShiftGammaIfPalStateIdle(s8 gammaIndex);
void WeatherBeginGammaFade(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay);
void ApplyWeatherGammaShiftToPal(u8 paletteIndex);
void ApplyWeatherColorMapIfIdle(s8 colorMapIndex);
void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay);
void ApplyWeatherColorMapToPal(u8 paletteIndex);
void StartWeather(void);
void ResumePausedWeather(void);
void FadeSelectedPals(u8 mode, s8 delay, u32 selectedPalettes);

View File

@@ -19,9 +19,9 @@
enum
{
GAMMA_NONE,
GAMMA_NORMAL,
GAMMA_ALT,
COLOR_MAP_NONE,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_CONTRAST,
};
struct RGBColor
@@ -31,11 +31,6 @@ struct RGBColor
u16 b:5;
};
struct WeatherPaletteData
{
u16 gammaShiftColors[8][0x1000]; // 0x1000 is the number of bytes that make up all palettes.
};
struct WeatherCallbacks
{
void (*initVars)(void);
@@ -44,9 +39,9 @@ struct WeatherCallbacks
bool8 (*finish)(void);
};
static EWRAM_DATA struct Weather sWeather = {};
static EWRAM_DATA u8 sFieldEffectPaletteGammaTypes[32] = {};
static EWRAM_DATA const u8 *sPaletteGammaTypes = NULL;
static EWRAM_DATA struct Weather gWeather = {};
static EWRAM_DATA u8 sFieldEffectPaletteColorMapTypes[32] = {};
static EWRAM_DATA const u8 *sPaletteColorMapTypes = NULL;
static EWRAM_DATA u16 sDroughtFrameDelay = 0;
static void Task_WeatherMain(u8 taskId);
@@ -54,11 +49,10 @@ static void Task_WeatherInit(u8 taskId);
static void None_Init(void);
static void None_Main(void);
static bool8 None_Finish(void);
static void BuildGammaShiftTables(void);
static void UpdateWeatherGammaShift(void);
static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex);
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u32 blendColor);
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u32 blendColor);
static void UpdateWeatherColorMap(void);
static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex);
static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u32 blendColor);
static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u32 blendColor);
static void FadeInScreenWithWeather(void);
static bool8 FadeInScreen_RainShowShade(void);
static bool8 FadeInScreen_Drought(void);
@@ -67,7 +61,64 @@ static void DoNothing(void);
static void ApplyFogBlend(u8 blendCoeff, u32 blendColor);
static bool8 LightenSpritePaletteInFog(u8 paletteIndex);
struct Weather *const gWeatherPtr = &sWeather;
static const u8 sDarkenedContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32] =
{
{0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29},
{0, 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 26, 27},
{0, 0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25},
{0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 11, 11, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 24, 24, 25},
{1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 9, 12, 13, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 25},
{1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 13, 14, 15, 15, 16, 17, 17, 18, 19, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25, 26},
{1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 15, 15, 16, 16, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 26, 26},
{1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 16, 16, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 19, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 27, 27},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 26, 27, 27, 28},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 27, 27, 27, 28, 28},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 25, 25, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 29, 29, 29},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30},
{1, 2, 3, 4, 4, 5, 6, 7, 8, 8, 9, 10, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31}
};
static const u8 sContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32] =
{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 18, 19, 20, 21, 22, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 25, 25, 26, 27, 28, 28, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 17, 18, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 19, 19, 20, 21, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 27, 27, 27, 28, 28, 29, 29, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 23, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 27, 27, 27, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31}
};
// The drought weather effect uses a precalculated color lookup table. Presumably this
// is because the underlying color shift calculation is slow.
static const u16 sDroughtWeatherColors[][0x1000] = {
INCBIN_U16("graphics/weather/drought/colors_0.bin"),
INCBIN_U16("graphics/weather/drought/colors_1.bin"),
INCBIN_U16("graphics/weather/drought/colors_2.bin"),
INCBIN_U16("graphics/weather/drought/colors_3.bin"),
INCBIN_U16("graphics/weather/drought/colors_4.bin"),
INCBIN_U16("graphics/weather/drought/colors_5.bin"),
};
struct Weather *const gWeatherPtr = &gWeather;
static const struct WeatherCallbacks sWeatherFuncs[] =
{
@@ -89,47 +140,47 @@ static const struct WeatherCallbacks sWeatherFuncs[] =
};
static void (*const sWeatherPalStateFuncs[])(void) = {
[WEATHER_PAL_STATE_CHANGING_WEATHER] = UpdateWeatherGammaShift,
[WEATHER_PAL_STATE_CHANGING_WEATHER] = UpdateWeatherColorMap,
[WEATHER_PAL_STATE_SCREEN_FADING_IN] = FadeInScreenWithWeather,
[WEATHER_PAL_STATE_SCREEN_FADING_OUT] = DoNothing,
[WEATHER_PAL_STATE_IDLE] = DoNothing,
};
static const u8 sBasePaletteGammaTypes[32] = {
static const u8 sBasePaletteColorMapTypes[32] = {
// background palettes
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NONE,
GAMMA_NONE,
GAMMA_NONE,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_NONE,
COLOR_MAP_NONE,
COLOR_MAP_NONE,
// sprite palettes
GAMMA_ALT,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
COLOR_MAP_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
};
const u16 gDefaultWeatherSpritePalette[] = INCBIN_U16("graphics/weather/default.gbapal");
@@ -150,11 +201,13 @@ void StartWeather(void)
{
if (!FuncIsActiveTask(Task_WeatherMain))
{
u8 index = AllocSpritePalette(0x1200);
u8 index = AllocSpritePalette(PALTAG_WEATHER);
CpuCopy32(gDefaultWeatherSpritePalette, &gPlttBufferUnfaded[OBJ_PLTT_ID(index)], PLTT_SIZE_4BPP);
ApplyGlobalFieldPaletteTint(index);
BuildGammaShiftTables();
gWeatherPtr->altGammaSpritePalIndex = index;
sPaletteColorMapTypes = sBasePaletteColorMapTypes;
gWeatherPtr->contrastColorMapSpritePalIndex = index;
gWeatherPtr->weatherPicSpritePalIndex = index;
gWeatherPtr->rainSpriteCount = 0;
gWeatherPtr->curRainSpriteIndex = 0;
@@ -230,7 +283,7 @@ static void Task_WeatherMain(u8 taskId)
{
// Finished cleaning up previous weather. Now transition to next weather.
sWeatherFuncs[gWeatherPtr->nextWeather].initVars();
gWeatherPtr->gammaStepFrameCounter = 0;
gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->currWeather = gWeatherPtr->nextWeather;
gWeatherPtr->weatherChangeComplete = TRUE;
@@ -247,8 +300,8 @@ static void Task_WeatherMain(u8 taskId)
static void None_Init(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 0;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 0;
}
static void None_Main(void)
@@ -260,95 +313,25 @@ static u8 None_Finish(void)
return 0;
}
// Builds two tables that contain gamma shifts for palette colors.
// It's unclear why the two tables aren't declared as const arrays, since
// this function always builds the same two tables.
static void BuildGammaShiftTables(void)
{
u16 v0;
u8 (*gammaTable)[32];
u16 v2;
u16 v4;
u16 v5;
u16 gammaIndex;
u16 v9;
u32 v10;
u16 v11;
s16 dunno;
sPaletteGammaTypes = sBasePaletteGammaTypes;
for (v0 = 0; v0 <= 1; v0++)
{
if (v0 == 0)
gammaTable = gWeatherPtr->gammaShifts;
else
gammaTable = gWeatherPtr->altGammaShifts;
for (v2 = 0; v2 < 32; v2++)
{
v4 = v2 << 8;
if (v0 == 0)
v5 = (v2 << 8) / 16;
else
v5 = 0;
for (gammaIndex = 0; gammaIndex <= 2; gammaIndex++)
{
v4 = (v4 - v5);
gammaTable[gammaIndex][v2] = v4 >> 8;
}
v9 = v4;
v10 = 0x1f00 - v4;
if ((0x1f00 - v4) < 0)
{
v10 += 0xf;
}
v11 = v10 >> 4;
if (v2 < 12)
{
for (; gammaIndex < 19; gammaIndex++)
{
v4 += v11;
dunno = v4 - v9;
if (dunno > 0)
v4 -= (dunno + ((u16)dunno >> 15)) >> 1;
gammaTable[gammaIndex][v2] = v4 >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f)
gammaTable[gammaIndex][v2] = 0x1f;
}
}
else
{
for (; gammaIndex < 19; gammaIndex++)
{
v4 += v11;
gammaTable[gammaIndex][v2] = v4 >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f)
gammaTable[gammaIndex][v2] = 0x1f;
}
}
}
}
}
// When the weather is changing, it gradually updates the palettes
// towards the desired gamma shift.
static void UpdateWeatherGammaShift(void)
// towards the desired color map.
static void UpdateWeatherColorMap(void)
{
if (gWeatherPtr->gammaIndex == gWeatherPtr->gammaTargetIndex)
if (gWeatherPtr->colorMapIndex == gWeatherPtr->targetColorMapIndex)
{
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
else
{
if (++gWeatherPtr->gammaStepFrameCounter >= gWeatherPtr->gammaStepDelay)
if (++gWeatherPtr->colorMapStepCounter >= gWeatherPtr->colorMapStepDelay)
{
gWeatherPtr->gammaStepFrameCounter = 0;
if (gWeatherPtr->gammaIndex < gWeatherPtr->gammaTargetIndex)
gWeatherPtr->gammaIndex++;
gWeatherPtr->colorMapStepCounter = 0;
if (gWeatherPtr->colorMapIndex < gWeatherPtr->targetColorMapIndex)
gWeatherPtr->colorMapIndex++;
else
gWeatherPtr->gammaIndex--;
gWeatherPtr->colorMapIndex--;
ApplyGammaShift(0, 32, gWeatherPtr->gammaIndex);
ApplyColorMap(0, 32, gWeatherPtr->colorMapIndex);
}
}
}
@@ -367,21 +350,21 @@ static void FadeInScreenWithWeather(void)
case WEATHER_SHADE:
if (FadeInScreen_RainShowShade() == FALSE)
{
gWeatherPtr->gammaIndex = 3;
gWeatherPtr->colorMapIndex = 3;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
case WEATHER_DROUGHT:
if (FadeInScreen_Drought() == FALSE)
{
gWeatherPtr->gammaIndex = -6;
gWeatherPtr->colorMapIndex = -6;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
case WEATHER_FOG_HORIZONTAL:
if (FadeInScreen_FogHorizontal() == FALSE)
{
gWeatherPtr->gammaIndex = 0;
gWeatherPtr->colorMapIndex = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
@@ -392,7 +375,7 @@ static void FadeInScreenWithWeather(void)
default:
if (!gPaletteFade.active)
{
gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex;
gWeatherPtr->colorMapIndex = gWeatherPtr->targetColorMapIndex;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
@@ -406,12 +389,12 @@ static bool8 FadeInScreen_RainShowShade(void)
if (++gWeatherPtr->fadeScreenCounter >= 16)
{
ApplyGammaShift(0, 32, 3);
ApplyColorMap(0, 32, 3);
gWeatherPtr->fadeScreenCounter = 16;
return FALSE;
}
ApplyGammaShiftWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
ApplyColorMapWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE;
}
@@ -422,12 +405,12 @@ static bool8 FadeInScreen_Drought(void)
if (++gWeatherPtr->fadeScreenCounter >= 16)
{
ApplyGammaShift(0, 32, -6);
ApplyColorMap(0, 32, -6);
gWeatherPtr->fadeScreenCounter = 16;
return FALSE;
}
ApplyDroughtGammaShiftWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
ApplyDroughtColorMapWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE;
}
@@ -444,14 +427,14 @@ static bool8 FadeInScreen_FogHorizontal(void)
static void DoNothing(void)
{ }
static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex)
{
u16 curPalIndex;
u16 palOffset;
u8 *gammaTable;
const u8 *colorMap;
u16 i;
if (gammaIndex > 0)
if (colorMapIndex > 0)
{
// Create the palette mask
u32 palettes = PALETTES_ALL;
@@ -460,11 +443,11 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
palettes = (palettes << (32-numPalettes)) >> (32-numPalettes);
numPalettes -= startPalIndex;
gammaIndex--;
colorMapIndex--;
palOffset = PLTT_ID(startPalIndex);
UpdateAltBgPalettes(palettes & PALETTES_BG);
// Thunder gamma-shift looks bad on night-blended palettes, so ignore time blending in some situations
if (!(gammaIndex > 3) && MapHasNaturalLight(gMapHeader.mapType))
if (!(colorMapIndex > 3) && MapHasNaturalLight(gMapHeader.mapType))
UpdatePalettesWithTime(palettes);
else
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, PLTT_SIZE_4BPP * numPalettes);
@@ -475,7 +458,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
// Loop through the speficied palette range and apply necessary gamma shifts to the colors.
while (curPalIndex < numPalettes)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE ||
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE ||
(curPalIndex >= 16 && IS_BLEND_IMMUNE_TAG(GetSpritePaletteTagByPaletteNum(curPalIndex - 16))))
{
// No palette change.
@@ -486,18 +469,18 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
{
u8 r, g, b;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex)
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex];
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_CONTRAST || curPalIndex - 16 == gWeatherPtr->contrastColorMapSpritePalIndex)
colorMap = sContrastColorMaps[colorMapIndex];
else
gammaTable = gWeatherPtr->gammaShifts[gammaIndex];
colorMap = sDarkenedContrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++)
{
// Apply gamma shift to the original color.
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
r = gammaTable[baseColor.r];
g = gammaTable[baseColor.g];
b = gammaTable[baseColor.b];
r = colorMap[baseColor.r];
g = colorMap[baseColor.g];
b = colorMap[baseColor.b];
gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r;
}
}
@@ -505,10 +488,33 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
curPalIndex++;
}
}
else if (gammaIndex < 0)
else if (colorMapIndex < 0)
{
// A negative gammIndex value means that the blending will come from the special Drought weather's palette tables.
// Dummied out in FRLG
colorMapIndex = -colorMapIndex - 1;
palOffset = PLTT_ID(startPalIndex);
numPalettes += startPalIndex;
curPalIndex = startPalIndex;
while (curPalIndex < numPalettes)
{
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{
// No palette change.
CpuFastCopy(&gPlttBufferUnfaded[palOffset], &gPlttBufferFaded[palOffset], PLTT_SIZE_4BPP);
palOffset += 16;
}
else
{
for (i = 0; i < 16; i++)
{
gPlttBufferFaded[palOffset] = sDroughtWeatherColors[colorMapIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])];
palOffset++;
}
}
curPalIndex++;
}
}
else
{
@@ -527,7 +533,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
}
}
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u32 blendColor)
static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u32 blendColor)
{
u16 palOffset;
u16 curPalIndex;
@@ -539,7 +545,7 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
palOffset = PLTT_ID(startPalIndex);
numPalettes += startPalIndex;
gammaIndex--;
colorMapIndex--;
curPalIndex = startPalIndex;
while (curPalIndex < numPalettes)
@@ -547,7 +553,7 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
UpdateAltBgPalettes((1 << (palOffset >> 4)) & PALETTES_BG);
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16));
UpdatePalettesWithTime(1 << (palOffset >> 4)); // Apply TOD blend
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{
// No gamma shift. Simply blend the colors.
BlendPalette(palOffset, 16, blendCoeff, blendColor);
@@ -555,19 +561,19 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
}
else
{
u8 *gammaTable;
const u8 *colorMap;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL)
gammaTable = gWeatherPtr->gammaShifts[gammaIndex];
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_DARK_CONTRAST)
colorMap = sDarkenedContrastColorMaps[colorMapIndex];
else
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex];
colorMap = sContrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++)
{
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
u8 r = gammaTable[baseColor.r];
u8 g = gammaTable[baseColor.g];
u8 b = gammaTable[baseColor.b];
u8 r = colorMap[baseColor.r];
u8 g = colorMap[baseColor.g];
u8 b = colorMap[baseColor.b];
// Apply gamma shift and target blend color to the original color.
r += ((rBlend - r) * blendCoeff) >> 4;
@@ -581,7 +587,7 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
}
}
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u32 blendColor)
static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u32 blendColor)
{
struct RGBColor color;
u8 rBlend;
@@ -591,7 +597,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u32 bl
u16 palOffset;
u16 i;
gammaIndex = -gammaIndex - 1;
colorMapIndex = -colorMapIndex - 1;
color = *(struct RGBColor *)&blendColor;
rBlend = color.r;
gBlend = color.g;
@@ -599,9 +605,9 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u32 bl
palOffset = 0;
for (curPalIndex = 0; curPalIndex < 32; curPalIndex++)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{
// No gamma shift. Simply blend the colors.
// No color map. Simply blend the colors.
BlendPalette(palOffset, 16, blendCoeff, blendColor);
palOffset += 16;
}
@@ -609,19 +615,28 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u32 bl
{
for (i = 0; i < 16; i++)
{
u32 offset;
struct RGBColor color1;
struct RGBColor color2;
u8 r1, g1, b1;
u8 r2, g2, b2;
color1 = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
r1 = color1.r;
g1 = color1.g;
b1 = color1.b;
r1 += ((rBlend - r1) * blendCoeff) >> 4;
g1 += ((gBlend - g1) * blendCoeff) >> 4;
b1 += ((bBlend - b1) * blendCoeff) >> 4;
offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1);
color2 = *(struct RGBColor *)&sDroughtWeatherColors[colorMapIndex][offset];
r2 = color2.r;
g2 = color2.g;
b2 = color2.b;
gPlttBufferFaded[palOffset++] = (b1 << 10) | (g1 << 5) | r1;
r2 += ((rBlend - r2) * blendCoeff) >> 4;
g2 += ((gBlend - g2) * blendCoeff) >> 4;
b2 += ((bBlend - b2) * blendCoeff) >> 4;
gPlttBufferFaded[palOffset++] = RGB2(r2, g2, b2);
}
}
}
@@ -671,25 +686,25 @@ static bool8 LightenSpritePaletteInFog(u8 paletteIndex)
return FALSE;
}
void WeatherShiftGammaIfPalStateIdle(s8 gammaIndex)
void ApplyWeatherColorMapIfIdle(s8 colorMapIndex)
{
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{
ApplyGammaShift(0, 32, gammaIndex);
gWeatherPtr->gammaIndex = gammaIndex;
ApplyColorMap(0, 32, colorMapIndex);
gWeatherPtr->colorMapIndex = colorMapIndex;
}
}
void WeatherBeginGammaFade(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay)
void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay)
{
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->gammaIndex = gammaIndex;
gWeatherPtr->gammaTargetIndex = gammaTargetIndex;
gWeatherPtr->gammaStepFrameCounter = 0;
gWeatherPtr->gammaStepDelay = gammaStepDelay;
WeatherShiftGammaIfPalStateIdle(gammaIndex);
gWeatherPtr->colorMapIndex = colorMapIndex;
gWeatherPtr->targetColorMapIndex = targetColorMapIndex;
gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->colorMapStepDelay = colorMapStepDelay;
ApplyWeatherColorMapIfIdle(colorMapIndex);
}
}
@@ -873,8 +888,8 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool32 allowFog)
default:
if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL)
{
if (gWeatherPtr->gammaIndex)
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex);
if (gWeatherPtr->colorMapIndex)
ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
else
UpdateSpritePaletteWithTime(spritePaletteIndex);
}
@@ -901,9 +916,9 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool32 allowFog)
}
}
void ApplyWeatherGammaShiftToPal(u8 paletteIndex)
void ApplyWeatherColorMapToPal(u8 paletteIndex)
{
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex);
ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
}
void LoadCustomWeatherSpritePalette(const u16 *palette)
@@ -912,11 +927,10 @@ void LoadCustomWeatherSpritePalette(const u16 *palette)
UpdateSpritePaletteWithWeather(gWeatherPtr->weatherPicSpritePalIndex, TRUE);
}
static void LoadDroughtWeatherPalette(u8 *gammaIndexPtr, u8 *a1)
static void LoadDroughtWeatherPalette(u8 *palsIndex, u8 *palsOffset)
{
// Dummied out in FRLG
// *gammaIndexPtr = 0x20;
// *a1 = 0x20;
*palsIndex = 0x20;
*palsOffset = 0x20;
}
void ResetDroughtWeatherPaletteLoading(void)
@@ -936,9 +950,9 @@ bool8 LoadDroughtWeatherPalettes(void)
return FALSE;
}
static void SetDroughtGamma(s8 gammaIndex)
static void SetDroughtColorMap(s8 colorMapIndex)
{
WeatherShiftGammaIfPalStateIdle(-gammaIndex - 1);
ApplyWeatherColorMapIfIdle(-colorMapIndex - 1);
}
void DroughtStateInit(void)
@@ -959,7 +973,7 @@ void DroughtStateRun(void)
if (++gWeatherPtr->droughtTimer > sDroughtFrameDelay)
{
gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage++);
SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage++);
if (gWeatherPtr->droughtBrightnessStage > 5)
{
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
@@ -973,7 +987,7 @@ void DroughtStateRun(void)
gWeatherPtr->droughtTimer = (gWeatherPtr->droughtTimer + 3) & 0x7F;
gWeatherPtr->droughtBrightnessStage = ((gSineTable[gWeatherPtr->droughtTimer] - 1) >> 6) + 2;
if (gWeatherPtr->droughtBrightnessStage != gWeatherPtr->droughtLastBrightnessStage)
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage);
SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage);
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
break;
case 2:
@@ -981,7 +995,7 @@ void DroughtStateRun(void)
if (++gWeatherPtr->droughtTimer > sDroughtFrameDelay)
{
gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(--gWeatherPtr->droughtBrightnessStage);
SetDroughtColorMap(--gWeatherPtr->droughtBrightnessStage);
if (gWeatherPtr->droughtBrightnessStage == 3)
gWeatherPtr->droughtState = 0;
}
@@ -1109,14 +1123,14 @@ void WeatherProcessingIdle(void)
void PreservePaletteInWeather(u8 preservedPalIndex)
{
CpuCopy16(sBasePaletteGammaTypes, sFieldEffectPaletteGammaTypes, 32);
sFieldEffectPaletteGammaTypes[preservedPalIndex] = GAMMA_NONE;
sPaletteGammaTypes = sFieldEffectPaletteGammaTypes;
CpuCopy16(sBasePaletteColorMapTypes, sFieldEffectPaletteColorMapTypes, 32);
sFieldEffectPaletteColorMapTypes[preservedPalIndex] = COLOR_MAP_NONE;
sPaletteColorMapTypes = sFieldEffectPaletteColorMapTypes;
}
void ResetPreservedPalettesInWeather(void)
{
sPaletteGammaTypes = sBasePaletteGammaTypes;
sPaletteColorMapTypes = sBasePaletteColorMapTypes;
}
void SlightlyDarkenPalsInWeather(u16 *palbuf, u16 *unused, u32 size)

View File

@@ -70,8 +70,8 @@ static const struct SpriteTemplate sCloudSpriteTemplate = {
void Clouds_InitVars(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->initStep = 0;
if (!gWeatherPtr->cloudSpritesCreated)
@@ -128,8 +128,8 @@ bool8 Clouds_Finish(void)
void Sunny_InitVars(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
}
void Sunny_InitAll(void)
@@ -211,8 +211,8 @@ void Drought_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 0;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 0;
}
void Drought_InitAll(void)
@@ -442,8 +442,8 @@ void Rain_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 8;
gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 10;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
SetRainStrengthFromSoundEffect(SE_RAIN);
}
@@ -734,9 +734,9 @@ void Snow_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetSnowflakeSpriteCount = 16;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->targetSnowflakeSpriteCount = NUM_SNOWFLAKE_SPRITES;
gWeatherPtr->snowflakeVisibleCounter = 0;
}
@@ -1002,10 +1002,10 @@ void Thunderstorm_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 16;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
gWeatherPtr->thunderTriggered = FALSE;
gWeatherPtr->thunderEnqueued = FALSE;
SetRainStrengthFromSoundEffect(SE_THUNDERSTORM);
}
@@ -1031,8 +1031,8 @@ void Downpour_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = TRUE;
gWeatherPtr->targetRainSpriteCount = 24;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
SetRainStrengthFromSoundEffect(SE_DOWNPOUR);
}
@@ -1070,43 +1070,43 @@ void Thunderstorm_Main(void)
break;
case TSTORM_STATE_LOOP_START:
gWeatherPtr->thunderAllowEnd = TRUE;
gWeatherPtr->thunderDelay = (Random() % 360) + 360;
gWeatherPtr->thunderTimer = (Random() % 360) + 360;
gWeatherPtr->initStep++;
// fall through
case TSTORM_STATE_LOOP_WAIT:
// Wait between 360-720 frames before trying thunder again
if (--gWeatherPtr->thunderDelay == 0)
if (--gWeatherPtr->thunderTimer == 0)
gWeatherPtr->initStep++;
break;
case TSTORM_STATE_INIT_THUNDER_SHORT_1:
gWeatherPtr->thunderAllowEnd = TRUE;
gWeatherPtr->thunderSkipShort = Random() % 2;
gWeatherPtr->thunderLongBolt = Random() % 2;
gWeatherPtr->initStep++;
break;
case TSTORM_STATE_INIT_THUNDER_SHORT_2:
gWeatherPtr->thunderShortRetries = (Random() & 1) + 1;
gWeatherPtr->thunderShortBolts = (Random() & 1) + 1;
gWeatherPtr->initStep++;
// fall through
case TSTORM_STATE_TRY_THUNDER_SHORT:
WeatherShiftGammaIfPalStateIdle(19);
if (!gWeatherPtr->thunderSkipShort && gWeatherPtr->thunderShortRetries == 1)
ApplyWeatherColorMapIfIdle(19);
if (!gWeatherPtr->thunderLongBolt && gWeatherPtr->thunderShortBolts == 1)
SetThunderCounter(20); // Do short thunder
gWeatherPtr->thunderDelay = (Random() % 3) + 6;
gWeatherPtr->thunderTimer = (Random() % 3) + 6;
gWeatherPtr->initStep++;
break;
case TSTORM_STATE_TRY_NEW_THUNDER:
if (--gWeatherPtr->thunderDelay == 0)
if (--gWeatherPtr->thunderTimer == 0)
{
WeatherShiftGammaIfPalStateIdle(3);
ApplyWeatherColorMapIfIdle(3);
gWeatherPtr->thunderAllowEnd = TRUE;
if (--gWeatherPtr->thunderShortRetries != 0)
if (--gWeatherPtr->thunderShortBolts != 0)
{
// Try a short thunder again
gWeatherPtr->thunderDelay = (Random() % 16) + 60;
gWeatherPtr->thunderTimer = (Random() % 16) + 60;
gWeatherPtr->initStep = TSTORM_STATE_WAIT_THUNDER_SHORT;
}
else if (!gWeatherPtr->thunderSkipShort)
else if (!gWeatherPtr->thunderLongBolt)
{
// No more thunder, restart loop
gWeatherPtr->initStep = TSTORM_STATE_LOOP_START;
@@ -1119,27 +1119,27 @@ void Thunderstorm_Main(void)
}
break;
case TSTORM_STATE_WAIT_THUNDER_SHORT:
if (--gWeatherPtr->thunderDelay == 0)
if (--gWeatherPtr->thunderTimer == 0)
gWeatherPtr->initStep = TSTORM_STATE_TRY_THUNDER_SHORT;
break;
case TSTORM_STATE_INIT_THUNDER_LONG:
gWeatherPtr->thunderDelay = (Random() % 16) + 60;
gWeatherPtr->thunderTimer = (Random() % 16) + 60;
gWeatherPtr->initStep++;
break;
case TSTORM_STATE_WAIT_THUNDER_LONG:
if (--gWeatherPtr->thunderDelay == 0)
if (--gWeatherPtr->thunderTimer == 0)
{
// Do long thunder
SetThunderCounter(100);
WeatherShiftGammaIfPalStateIdle(19);
gWeatherPtr->thunderDelay = (Random() & 0xF) + 30;
ApplyWeatherColorMapIfIdle(19);
gWeatherPtr->thunderTimer = (Random() & 0xF) + 30;
gWeatherPtr->initStep++;
}
break;
case TSTORM_STATE_FADE_THUNDER_LONG:
if (--gWeatherPtr->thunderDelay == 0)
if (--gWeatherPtr->thunderTimer == 0)
{
WeatherBeginGammaFade(19, 3, 5);
ApplyWeatherColorMapIfIdle_Gradual(19, 3, 5);
gWeatherPtr->initStep++;
}
break;
@@ -1178,7 +1178,7 @@ bool8 Thunderstorm_Finish(void)
if (!UpdateVisibleRainSprites())
{
DestroyRainSprites();
gWeatherPtr->thunderTriggered = FALSE;
gWeatherPtr->thunderEnqueued = FALSE;
gWeatherPtr->finishStep++;
return FALSE;
}
@@ -1191,18 +1191,18 @@ bool8 Thunderstorm_Finish(void)
static void SetThunderCounter(u16 max)
{
if (!gWeatherPtr->thunderTriggered)
if (!gWeatherPtr->thunderEnqueued)
{
gWeatherPtr->thunderCounter = Random() % max;
gWeatherPtr->thunderTriggered = TRUE;
gWeatherPtr->thunderSETimer = Random() % max;
gWeatherPtr->thunderEnqueued = TRUE;
}
}
static void UpdateThunderSound(void)
{
if (gWeatherPtr->thunderTriggered == TRUE)
if (gWeatherPtr->thunderEnqueued == TRUE)
{
if (gWeatherPtr->thunderCounter == 0)
if (gWeatherPtr->thunderSETimer == 0)
{
if (IsSEPlaying())
return;
@@ -1212,11 +1212,11 @@ static void UpdateThunderSound(void)
else
PlaySE(SE_THUNDER2);
gWeatherPtr->thunderTriggered = FALSE;
gWeatherPtr->thunderEnqueued = FALSE;
}
else
{
gWeatherPtr->thunderCounter--;
gWeatherPtr->thunderSETimer--;
}
}
}
@@ -1309,8 +1309,8 @@ void FogHorizontal_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
if (!gWeatherPtr->fogHSpritesCreated)
{
gWeatherPtr->fogHScrollCounter = 0;
@@ -1464,8 +1464,8 @@ void Ash_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->ashUnused = 20; // Never read
if (!gWeatherPtr->ashSpritesCreated)
{
@@ -1669,8 +1669,8 @@ void FogDiagonal_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->fogHScrollCounter = 0;
gWeatherPtr->fogHScrollOffset = 1;
if (!gWeatherPtr->fogDSpritesCreated)
@@ -1878,8 +1878,8 @@ void Sandstorm_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
if (!gWeatherPtr->sandstormSpritesCreated)
{
gWeatherPtr->sandstormXOffset = gWeatherPtr->sandstormYOffset = 0;
@@ -2169,8 +2169,8 @@ static void UpdateSandstormSwirlSprite(struct Sprite *sprite)
void Shade_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
}
void Shade_InitAll(void)

View File

@@ -789,8 +789,8 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
InitMap();
CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout);
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
for (paletteIndex = 7; paletteIndex < 13; paletteIndex++)
ApplyWeatherGammaShiftToPal(paletteIndex);
for (paletteIndex = NUM_PALS_IN_PRIMARY; paletteIndex < NUM_PALS_TOTAL; paletteIndex++)
ApplyWeatherColorMapToPal(paletteIndex);
InitSecondaryTilesetAnimation();
UpdateLocationHistoryForRoamer();
RoamerMove();