Merge branch 'master' into thunder

This commit is contained in:
Abaresk
2022-10-18 04:37:56 +00:00
17 changed files with 256 additions and 244 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 200 B

View File

@@ -78,6 +78,11 @@
#define BATTLE_TYPE_RECORDED_IS_MASTER (1 << 31) #define BATTLE_TYPE_RECORDED_IS_MASTER (1 << 31)
#define BATTLE_TYPE_FRONTIER (BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE | BATTLE_TYPE_PYRAMID) #define BATTLE_TYPE_FRONTIER (BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE | BATTLE_TYPE_PYRAMID)
#define BATTLE_TYPE_FRONTIER_NO_PYRAMID (BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE) #define BATTLE_TYPE_FRONTIER_NO_PYRAMID (BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_DOME | BATTLE_TYPE_PALACE | BATTLE_TYPE_ARENA | BATTLE_TYPE_FACTORY | BATTLE_TYPE_PIKE)
#define BATTLE_TYPE_RECORDED_INVALID ((BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_FIRST_BATTLE \
| BATTLE_TYPE_WALLY_TUTORIAL | BATTLE_TYPE_ROAMER | BATTLE_TYPE_EREADER_TRAINER \
| BATTLE_TYPE_KYOGRE_GROUDON | BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_REGI \
| BATTLE_TYPE_RECORDED | BATTLE_TYPE_TRAINER_HILL | BATTLE_TYPE_SECRET_BASE \
| BATTLE_TYPE_GROUDON | BATTLE_TYPE_KYOGRE | BATTLE_TYPE_RAYQUAZA))
// Battle Outcome defines // Battle Outcome defines
#define B_OUTCOME_WON 1 #define B_OUTCOME_WON 1

View File

@@ -19,6 +19,8 @@ enum {
PALTAG_WEATHER_2 PALTAG_WEATHER_2
}; };
#define NUM_WEATHER_COLOR_MAPS 19
struct Weather struct Weather
{ {
union union
@@ -39,12 +41,12 @@ struct Weather
struct Sprite *sandstormSprites2[NUM_SWIRL_SANDSTORM_SPRITES]; struct Sprite *sandstormSprites2[NUM_SWIRL_SANDSTORM_SPRITES];
} s2; } s2;
} sprites; } sprites;
u8 gammaShifts[19][32]; u8 darkenedContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32];
u8 altGammaShifts[19][32]; u8 contrastColorMaps[NUM_WEATHER_COLOR_MAPS][32];
s8 gammaIndex; s8 colorMapIndex;
s8 gammaTargetIndex; s8 targetColorMapIndex;
u8 gammaStepDelay; u8 colorMapStepDelay;
u8 gammaStepFrameCounter; u8 colorMapStepCounter;
u16 fadeDestColor; u16 fadeDestColor;
u8 palProcessingState; u8 palProcessingState;
u8 fadeScreenCounter; u8 fadeScreenCounter;
@@ -59,7 +61,7 @@ struct Weather
u8 weatherGfxLoaded; u8 weatherGfxLoaded;
bool8 weatherChangeComplete; bool8 weatherChangeComplete;
u8 weatherPicSpritePalIndex; u8 weatherPicSpritePalIndex;
u8 altGammaSpritePalIndex; u8 contrastColorMapSpritePalIndex;
// Rain // Rain
u16 rainSpriteVisibleCounter; u16 rainSpriteVisibleCounter;
u8 curRainSpriteIndex; u8 curRainSpriteIndex;
@@ -146,12 +148,12 @@ void StartWeather(void);
void SetNextWeather(u8 weather); void SetNextWeather(u8 weather);
void SetCurrentAndNextWeather(u8 weather); void SetCurrentAndNextWeather(u8 weather);
void SetCurrentAndNextWeatherNoDelay(u8 weather); void SetCurrentAndNextWeatherNoDelay(u8 weather);
void ApplyWeatherGammaShiftIfIdle(s8 gammaIndex); void ApplyWeatherColorMapIfIdle(s8 colorMapIndex);
void ApplyWeatherGammaShiftIfIdle_Gradual(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay); void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay);
void FadeScreen(u8 mode, s8 delay); void FadeScreen(u8 mode, s8 delay);
bool8 IsWeatherNotFadingIn(void); bool8 IsWeatherNotFadingIn(void);
void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex); void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex);
void ApplyWeatherGammaShiftToPal(u8 paletteIndex); void ApplyWeatherColorMapToPal(u8 paletteIndex);
void LoadCustomWeatherSpritePalette(const u16 *palette); void LoadCustomWeatherSpritePalette(const u16 *palette);
void ResetDroughtWeatherPaletteLoading(void); void ResetDroughtWeatherPaletteLoading(void);
bool8 LoadDroughtWeatherPalettes(void); bool8 LoadDroughtWeatherPalettes(void);

View File

@@ -36,7 +36,7 @@
#include "constants/trainer_hill.h" #include "constants/trainer_hill.h"
static EWRAM_DATA u8 sWildEncounterImmunitySteps = 0; static EWRAM_DATA u8 sWildEncounterImmunitySteps = 0;
static EWRAM_DATA u16 sPreviousPlayerMetatileBehavior = 0; static EWRAM_DATA u16 sPrevMetatileBehavior = 0;
u8 gSelectedObjectEvent; u8 gSelectedObjectEvent;
@@ -671,18 +671,18 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior)
if (sWildEncounterImmunitySteps < 4) if (sWildEncounterImmunitySteps < 4)
{ {
sWildEncounterImmunitySteps++; sWildEncounterImmunitySteps++;
sPreviousPlayerMetatileBehavior = metatileBehavior; sPrevMetatileBehavior = metatileBehavior;
return FALSE; return FALSE;
} }
if (StandardWildEncounter(metatileBehavior, sPreviousPlayerMetatileBehavior) == TRUE) if (StandardWildEncounter(metatileBehavior, sPrevMetatileBehavior) == TRUE)
{ {
sWildEncounterImmunitySteps = 0; sWildEncounterImmunitySteps = 0;
sPreviousPlayerMetatileBehavior = metatileBehavior; sPrevMetatileBehavior = metatileBehavior;
return TRUE; return TRUE;
} }
sPreviousPlayerMetatileBehavior = metatileBehavior; sPrevMetatileBehavior = metatileBehavior;
return FALSE; return FALSE;
} }

View File

@@ -21,9 +21,9 @@
enum enum
{ {
GAMMA_NONE, COLOR_MAP_NONE,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
}; };
struct RGBColor struct RGBColor
@@ -33,11 +33,6 @@ struct RGBColor
u16 b:5; u16 b:5;
}; };
struct WeatherPaletteData
{
u16 gammaShiftColors[8][0x1000]; // 0x1000 is the number of bytes that make up all palettes.
};
struct WeatherCallbacks struct WeatherCallbacks
{ {
void (*initVars)(void); void (*initVars)(void);
@@ -48,11 +43,11 @@ struct WeatherCallbacks
// This file's functions. // This file's functions.
static bool8 LightenSpritePaletteInFog(u8); static bool8 LightenSpritePaletteInFog(u8);
static void BuildGammaShiftTables(void); static void BuildColorMaps(void);
static void UpdateWeatherGammaShift(void); static void UpdateWeatherColorMap(void);
static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex); static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex);
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor); static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor);
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor); static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor);
static void ApplyFogBlend(u8 blendCoeff, u16 blendColor); static void ApplyFogBlend(u8 blendCoeff, u16 blendColor);
static bool8 FadeInScreen_RainShowShade(void); static bool8 FadeInScreen_RainShowShade(void);
static bool8 FadeInScreen_Drought(void); static bool8 FadeInScreen_Drought(void);
@@ -66,9 +61,9 @@ static void None_Main(void);
static u8 None_Finish(void); static u8 None_Finish(void);
EWRAM_DATA struct Weather gWeather = {0}; EWRAM_DATA struct Weather gWeather = {0};
EWRAM_DATA static u8 sFieldEffectPaletteGammaTypes[32] = {0}; EWRAM_DATA static u8 sFieldEffectPaletteColorMapTypes[32] = {0};
static const u8 *sPaletteGammaTypes; static const u8 *sPaletteColorMapTypes;
// The drought weather effect uses a precalculated color lookup table. Presumably this // The drought weather effect uses a precalculated color lookup table. Presumably this
// is because the underlying color shift calculation is slow. // is because the underlying color shift calculation is slow.
@@ -108,50 +103,50 @@ static const struct WeatherCallbacks sWeatherFuncs[] =
void (*const gWeatherPalStateFuncs[])(void) = void (*const gWeatherPalStateFuncs[])(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_IN] = FadeInScreenWithWeather,
[WEATHER_PAL_STATE_SCREEN_FADING_OUT] = DoNothing, [WEATHER_PAL_STATE_SCREEN_FADING_OUT] = DoNothing,
[WEATHER_PAL_STATE_IDLE] = DoNothing, [WEATHER_PAL_STATE_IDLE] = DoNothing,
}; };
// This table specifies which of the gamma shift tables should be // This table specifies which of the color maps should be
// applied to each of the background and sprite palettes. // applied to each of the background and sprite palettes.
static const u8 sBasePaletteGammaTypes[32] = static const u8 sBasePaletteColorMapTypes[32] =
{ {
// background palettes // background palettes
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NONE, COLOR_MAP_NONE,
GAMMA_NONE, COLOR_MAP_NONE,
// sprite palettes // sprite palettes
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_ALT, COLOR_MAP_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
GAMMA_NORMAL, COLOR_MAP_DARK_CONTRAST,
}; };
const u16 gFogPalette[] = INCBIN_U16("graphics/weather/fog.gbapal"); const u16 gFogPalette[] = INCBIN_U16("graphics/weather/fog.gbapal");
@@ -160,10 +155,10 @@ void StartWeather(void)
{ {
if (!FuncIsActiveTask(Task_WeatherMain)) if (!FuncIsActiveTask(Task_WeatherMain))
{ {
u8 index = AllocSpritePalette(TAG_WEATHER_START); u8 index = AllocSpritePalette(PALTAG_WEATHER);
CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32); CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32);
BuildGammaShiftTables(); BuildColorMaps();
gWeatherPtr->altGammaSpritePalIndex = index; gWeatherPtr->contrastColorMapSpritePalIndex = index;
gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2); gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2);
gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->rainSpriteCount = 0;
gWeatherPtr->curRainSpriteIndex = 0; gWeatherPtr->curRainSpriteIndex = 0;
@@ -238,7 +233,7 @@ static void Task_WeatherMain(u8 taskId)
{ {
// Finished cleaning up previous weather. Now transition to next weather. // Finished cleaning up previous weather. Now transition to next weather.
sWeatherFuncs[gWeatherPtr->nextWeather].initVars(); sWeatherFuncs[gWeatherPtr->nextWeather].initVars();
gWeatherPtr->gammaStepFrameCounter = 0; gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->currWeather = gWeatherPtr->nextWeather; gWeatherPtr->currWeather = gWeatherPtr->nextWeather;
gWeatherPtr->weatherChangeComplete = TRUE; gWeatherPtr->weatherChangeComplete = TRUE;
@@ -254,8 +249,8 @@ static void Task_WeatherMain(u8 taskId)
static void None_Init(void) static void None_Init(void)
{ {
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 0; gWeatherPtr->colorMapStepDelay = 0;
} }
static void None_Main(void) static void None_Main(void)
@@ -267,70 +262,82 @@ static u8 None_Finish(void)
return 0; return 0;
} }
// Builds two tables that contain gamma shifts for palette colors. // Builds two tables that contain color maps, used for directly transforming
// palette colors in weather effects. The colors maps are a spectrum of
// brightness + contrast mappings. By transitioning between the maps, weather
// effects like lightning are created.
// It's unclear why the two tables aren't declared as const arrays, since // It's unclear why the two tables aren't declared as const arrays, since
// this function always builds the same two tables. // this function always builds the same two tables.
static void BuildGammaShiftTables(void) static void BuildColorMaps(void)
{ {
u16 v0; u16 i;
u8 (*gammaTable)[32]; u8 (*colorMaps)[32];
u16 v2; u16 colorVal;
u16 v4; u16 curBrightness;
u16 v5; u16 brightnessDelta;
u16 gammaIndex; u16 colorMapIndex;
u16 v9; u16 baseBrightness;
u32 v10; u32 remainingBrightness;
u16 v11; s16 diff;
s16 dunno;
sPaletteGammaTypes = sBasePaletteGammaTypes; sPaletteColorMapTypes = sBasePaletteColorMapTypes;
for (v0 = 0; v0 <= 1; v0++) for (i = 0; i < 2; i++)
{ {
if (v0 == 0) if (i == 0)
gammaTable = gWeatherPtr->gammaShifts; colorMaps = gWeatherPtr->darkenedContrastColorMaps;
else else
gammaTable = gWeatherPtr->altGammaShifts; colorMaps = gWeatherPtr->contrastColorMaps;
for (v2 = 0; v2 < 32; v2++) for (colorVal = 0; colorVal < 32; colorVal++)
{ {
v4 = v2 << 8; curBrightness = colorVal << 8;
if (v0 == 0) if (i == 0)
v5 = (v2 << 8) / 16; brightnessDelta = (colorVal << 8) / 16;
else else
v5 = 0; brightnessDelta = 0;
for (gammaIndex = 0; gammaIndex <= 2; gammaIndex++)
// First three color mappings are simple brightness modifiers which are
// progressively darker, according to brightnessDelta.
for (colorMapIndex = 0; colorMapIndex < 3; colorMapIndex++)
{ {
v4 = (v4 - v5); curBrightness -= brightnessDelta;
gammaTable[gammaIndex][v2] = v4 >> 8; colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
} }
v9 = v4;
v10 = 0x1f00 - v4; baseBrightness = curBrightness;
if ((0x1f00 - v4) < 0) remainingBrightness = 0x1f00 - curBrightness;
if ((0x1f00 - curBrightness) < 0)
remainingBrightness += 0xf;
brightnessDelta = remainingBrightness / (NUM_WEATHER_COLOR_MAPS - 3);
if (colorVal < 12)
{ {
v10 += 0xf; // For shadows (color values < 12), the remaining color mappings are
} // brightness modifiers, which are increased at a significantly lower rate
v11 = v10 >> 4; // than the midtones and highlights (color values >= 12). This creates a
if (v2 < 12) // high contrast effect, used in the thunderstorm weather.
{ for (; colorMapIndex < NUM_WEATHER_COLOR_MAPS; colorMapIndex++)
for (; gammaIndex < 19; gammaIndex++)
{ {
v4 += v11; curBrightness += brightnessDelta;
dunno = v4 - v9; diff = curBrightness - baseBrightness;
if (dunno > 0) if (diff > 0)
v4 -= (dunno + ((u16)dunno >> 15)) >> 1; curBrightness -= diff / 2;
gammaTable[gammaIndex][v2] = v4 >> 8; colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f) if (colorMaps[colorMapIndex][colorVal] > 31)
gammaTable[gammaIndex][v2] = 0x1f; colorMaps[colorMapIndex][colorVal] = 31;
} }
} }
else else
{ {
for (; gammaIndex < 19; gammaIndex++) // For midtones and highlights (color values >= 12), the remaining
// color mappings are simple brightness modifiers which are
// progressively brighter, hitting exactly 31 at the last mapping.
for (; colorMapIndex < NUM_WEATHER_COLOR_MAPS; colorMapIndex++)
{ {
v4 += v11; curBrightness += brightnessDelta;
gammaTable[gammaIndex][v2] = v4 >> 8; colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f) if (colorMaps[colorMapIndex][colorVal] > 31)
gammaTable[gammaIndex][v2] = 0x1f; colorMaps[colorMapIndex][colorVal] = 31;
} }
} }
} }
@@ -338,26 +345,26 @@ static void BuildGammaShiftTables(void)
} }
// When the weather is changing, it gradually updates the palettes // When the weather is changing, it gradually updates the palettes
// towards the desired gamma shift. // towards the desired color map.
static void UpdateWeatherGammaShift(void) static void UpdateWeatherColorMap(void)
{ {
if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT)
{ {
if (gWeatherPtr->gammaIndex == gWeatherPtr->gammaTargetIndex) if (gWeatherPtr->colorMapIndex == gWeatherPtr->targetColorMapIndex)
{ {
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
} }
else else
{ {
if (++gWeatherPtr->gammaStepFrameCounter >= gWeatherPtr->gammaStepDelay) if (++gWeatherPtr->colorMapStepCounter >= gWeatherPtr->colorMapStepDelay)
{ {
gWeatherPtr->gammaStepFrameCounter = 0; gWeatherPtr->colorMapStepCounter = 0;
if (gWeatherPtr->gammaIndex < gWeatherPtr->gammaTargetIndex) if (gWeatherPtr->colorMapIndex < gWeatherPtr->targetColorMapIndex)
gWeatherPtr->gammaIndex++; gWeatherPtr->colorMapIndex++;
else else
gWeatherPtr->gammaIndex--; gWeatherPtr->colorMapIndex--;
ApplyGammaShift(0, 32, gWeatherPtr->gammaIndex); ApplyColorMap(0, 32, gWeatherPtr->colorMapIndex);
} }
} }
} }
@@ -377,21 +384,21 @@ static void FadeInScreenWithWeather(void)
case WEATHER_SHADE: case WEATHER_SHADE:
if (FadeInScreen_RainShowShade() == FALSE) if (FadeInScreen_RainShowShade() == FALSE)
{ {
gWeatherPtr->gammaIndex = 3; gWeatherPtr->colorMapIndex = 3;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
} }
break; break;
case WEATHER_DROUGHT: case WEATHER_DROUGHT:
if (FadeInScreen_Drought() == FALSE) if (FadeInScreen_Drought() == FALSE)
{ {
gWeatherPtr->gammaIndex = -6; gWeatherPtr->colorMapIndex = -6;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
} }
break; break;
case WEATHER_FOG_HORIZONTAL: case WEATHER_FOG_HORIZONTAL:
if (FadeInScreen_FogHorizontal() == FALSE) if (FadeInScreen_FogHorizontal() == FALSE)
{ {
gWeatherPtr->gammaIndex = 0; gWeatherPtr->colorMapIndex = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
} }
break; break;
@@ -402,7 +409,7 @@ static void FadeInScreenWithWeather(void)
default: default:
if (!gPaletteFade.active) if (!gPaletteFade.active)
{ {
gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex; gWeatherPtr->colorMapIndex = gWeatherPtr->targetColorMapIndex;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
} }
break; break;
@@ -416,12 +423,12 @@ static bool8 FadeInScreen_RainShowShade(void)
if (++gWeatherPtr->fadeScreenCounter >= 16) if (++gWeatherPtr->fadeScreenCounter >= 16)
{ {
ApplyGammaShift(0, 32, 3); ApplyColorMap(0, 32, 3);
gWeatherPtr->fadeScreenCounter = 16; gWeatherPtr->fadeScreenCounter = 16;
return FALSE; return FALSE;
} }
ApplyGammaShiftWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); ApplyColorMapWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE; return TRUE;
} }
@@ -432,12 +439,12 @@ static bool8 FadeInScreen_Drought(void)
if (++gWeatherPtr->fadeScreenCounter >= 16) if (++gWeatherPtr->fadeScreenCounter >= 16)
{ {
ApplyGammaShift(0, 32, -6); ApplyColorMap(0, 32, -6);
gWeatherPtr->fadeScreenCounter = 16; gWeatherPtr->fadeScreenCounter = 16;
return FALSE; return FALSE;
} }
ApplyDroughtGammaShiftWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); ApplyDroughtColorMapWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE; return TRUE;
} }
@@ -454,24 +461,24 @@ static bool8 FadeInScreen_FogHorizontal(void)
static void DoNothing(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 curPalIndex;
u16 palOffset; u16 palOffset;
u8 *gammaTable; u8 *colorMap;
u16 i; u16 i;
if (gammaIndex > 0) if (colorMapIndex > 0)
{ {
gammaIndex--; colorMapIndex--;
palOffset = startPalIndex * 16; palOffset = startPalIndex * 16;
numPalettes += startPalIndex; numPalettes += startPalIndex;
curPalIndex = startPalIndex; curPalIndex = startPalIndex;
// Loop through the speficied palette range and apply necessary gamma shifts to the colors. // Loop through the specified palette range and apply necessary color maps.
while (curPalIndex < numPalettes) while (curPalIndex < numPalettes)
{ {
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{ {
// No palette change. // No palette change.
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16));
@@ -481,18 +488,18 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
{ {
u8 r, g, b; u8 r, g, b;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex) if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_CONTRAST || curPalIndex - 16 == gWeatherPtr->contrastColorMapSpritePalIndex)
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; colorMap = gWeatherPtr->contrastColorMaps[colorMapIndex];
else else
gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
// Apply gamma shift to the original color. // Apply color map to the original color.
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
r = gammaTable[baseColor.r]; r = colorMap[baseColor.r];
g = gammaTable[baseColor.g]; g = colorMap[baseColor.g];
b = gammaTable[baseColor.b]; b = colorMap[baseColor.b];
gPlttBufferFaded[palOffset++] = RGB2(r, g, b); gPlttBufferFaded[palOffset++] = RGB2(r, g, b);
} }
} }
@@ -500,17 +507,17 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
curPalIndex++; 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. // A negative gammIndex value means that the blending will come from the special Drought weather's palette tables.
gammaIndex = -gammaIndex - 1; colorMapIndex = -colorMapIndex - 1;
palOffset = startPalIndex * 16; palOffset = startPalIndex * 16;
numPalettes += startPalIndex; numPalettes += startPalIndex;
curPalIndex = startPalIndex; curPalIndex = startPalIndex;
while (curPalIndex < numPalettes) while (curPalIndex < numPalettes)
{ {
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{ {
// No palette change. // No palette change.
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16));
@@ -520,7 +527,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
{ {
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
gPlttBufferFaded[palOffset] = sDroughtWeatherColors[gammaIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])]; gPlttBufferFaded[palOffset] = sDroughtWeatherColors[colorMapIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])];
palOffset++; palOffset++;
} }
} }
@@ -535,7 +542,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
} }
} }
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor) static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor)
{ {
u16 palOffset; u16 palOffset;
u16 curPalIndex; u16 curPalIndex;
@@ -547,34 +554,34 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
palOffset = startPalIndex * 16; palOffset = startPalIndex * 16;
numPalettes += startPalIndex; numPalettes += startPalIndex;
gammaIndex--; colorMapIndex--;
curPalIndex = startPalIndex; curPalIndex = startPalIndex;
while (curPalIndex < numPalettes) while (curPalIndex < numPalettes)
{ {
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); BlendPalette(palOffset, 16, blendCoeff, blendColor);
palOffset += 16; palOffset += 16;
} }
else else
{ {
u8 *gammaTable; u8 *colorMap;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL) if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_DARK_CONTRAST)
gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex];
else else
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; colorMap = gWeatherPtr->contrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
u8 r = gammaTable[baseColor.r]; u8 r = colorMap[baseColor.r];
u8 g = gammaTable[baseColor.g]; u8 g = colorMap[baseColor.g];
u8 b = gammaTable[baseColor.b]; u8 b = colorMap[baseColor.b];
// Apply gamma shift and target blend color to the original color. // Apply color map and target blend color to the original color.
r += ((rBlend - r) * blendCoeff) >> 4; r += ((rBlend - r) * blendCoeff) >> 4;
g += ((gBlend - g) * blendCoeff) >> 4; g += ((gBlend - g) * blendCoeff) >> 4;
b += ((bBlend - b) * blendCoeff) >> 4; b += ((bBlend - b) * blendCoeff) >> 4;
@@ -586,7 +593,7 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
} }
} }
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor) static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor)
{ {
struct RGBColor color; struct RGBColor color;
u8 rBlend; u8 rBlend;
@@ -596,7 +603,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
u16 palOffset; u16 palOffset;
u16 i; u16 i;
gammaIndex = -gammaIndex - 1; colorMapIndex = -colorMapIndex - 1;
color = *(struct RGBColor *)&blendColor; color = *(struct RGBColor *)&blendColor;
rBlend = color.r; rBlend = color.r;
gBlend = color.g; gBlend = color.g;
@@ -604,9 +611,9 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
palOffset = 0; palOffset = 0;
for (curPalIndex = 0; curPalIndex < 32; curPalIndex++) 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); BlendPalette(palOffset, 16, blendCoeff, blendColor);
palOffset += 16; palOffset += 16;
} }
@@ -626,7 +633,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
b1 = color1.b; b1 = color1.b;
offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1); offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1);
color2 = *(struct RGBColor *)&sDroughtWeatherColors[gammaIndex][offset]; color2 = *(struct RGBColor *)&sDroughtWeatherColors[colorMapIndex][offset];
r2 = color2.r; r2 = color2.r;
g2 = color2.g; g2 = color2.g;
b2 = color2.b; b2 = color2.b;
@@ -710,25 +717,25 @@ static bool8 LightenSpritePaletteInFog(u8 paletteIndex)
return FALSE; return FALSE;
} }
void ApplyWeatherGammaShiftIfIdle(s8 gammaIndex) void ApplyWeatherColorMapIfIdle(s8 colorMapIndex)
{ {
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{ {
ApplyGammaShift(0, 32, gammaIndex); ApplyColorMap(0, 32, colorMapIndex);
gWeatherPtr->gammaIndex = gammaIndex; gWeatherPtr->colorMapIndex = colorMapIndex;
} }
} }
void ApplyWeatherGammaShiftIfIdle_Gradual(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay) void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay)
{ {
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{ {
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->gammaIndex = gammaIndex; gWeatherPtr->colorMapIndex = colorMapIndex;
gWeatherPtr->gammaTargetIndex = gammaTargetIndex; gWeatherPtr->targetColorMapIndex = targetColorMapIndex;
gWeatherPtr->gammaStepFrameCounter = 0; gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->gammaStepDelay = gammaStepDelay; gWeatherPtr->colorMapStepDelay = colorMapStepDelay;
ApplyWeatherGammaShiftIfIdle(gammaIndex); ApplyWeatherColorMapIfIdle(colorMapIndex);
} }
} }
@@ -832,7 +839,7 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex)
default: default:
if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL) if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL)
{ {
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
} }
else else
{ {
@@ -843,9 +850,9 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex)
} }
} }
void ApplyWeatherGammaShiftToPal(u8 paletteIndex) void ApplyWeatherColorMapToPal(u8 paletteIndex)
{ {
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
} }
// Unused // Unused
@@ -886,9 +893,9 @@ bool8 LoadDroughtWeatherPalettes(void)
return FALSE; return FALSE;
} }
static void SetDroughtGamma(s8 gammaIndex) static void SetDroughtColorMap(s8 colorMapIndex)
{ {
ApplyWeatherGammaShiftIfIdle(-gammaIndex - 1); ApplyWeatherColorMapIfIdle(-colorMapIndex - 1);
} }
void DroughtStateInit(void) void DroughtStateInit(void)
@@ -907,7 +914,7 @@ void DroughtStateRun(void)
if (++gWeatherPtr->droughtTimer > 5) if (++gWeatherPtr->droughtTimer > 5)
{ {
gWeatherPtr->droughtTimer = 0; gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage++); SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage++);
if (gWeatherPtr->droughtBrightnessStage > 5) if (gWeatherPtr->droughtBrightnessStage > 5)
{ {
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage; gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
@@ -920,14 +927,14 @@ void DroughtStateRun(void)
gWeatherPtr->droughtTimer = (gWeatherPtr->droughtTimer + 3) & 0x7F; gWeatherPtr->droughtTimer = (gWeatherPtr->droughtTimer + 3) & 0x7F;
gWeatherPtr->droughtBrightnessStage = ((gSineTable[gWeatherPtr->droughtTimer] - 1) >> 6) + 2; gWeatherPtr->droughtBrightnessStage = ((gSineTable[gWeatherPtr->droughtTimer] - 1) >> 6) + 2;
if (gWeatherPtr->droughtBrightnessStage != gWeatherPtr->droughtLastBrightnessStage) if (gWeatherPtr->droughtBrightnessStage != gWeatherPtr->droughtLastBrightnessStage)
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage); SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage);
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage; gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
break; break;
case 2: case 2:
if (++gWeatherPtr->droughtTimer > 5) if (++gWeatherPtr->droughtTimer > 5)
{ {
gWeatherPtr->droughtTimer = 0; gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(--gWeatherPtr->droughtBrightnessStage); SetDroughtColorMap(--gWeatherPtr->droughtBrightnessStage);
if (gWeatherPtr->droughtBrightnessStage == 3) if (gWeatherPtr->droughtBrightnessStage == 3)
gWeatherPtr->droughtState = 0; gWeatherPtr->droughtState = 0;
} }
@@ -1093,12 +1100,12 @@ void SetWeatherPalStateIdle(void)
void PreservePaletteInWeather(u8 preservedPalIndex) void PreservePaletteInWeather(u8 preservedPalIndex)
{ {
CpuCopy16(sBasePaletteGammaTypes, sFieldEffectPaletteGammaTypes, 32); CpuCopy16(sBasePaletteColorMapTypes, sFieldEffectPaletteColorMapTypes, 32);
sFieldEffectPaletteGammaTypes[preservedPalIndex] = GAMMA_NONE; sFieldEffectPaletteColorMapTypes[preservedPalIndex] = COLOR_MAP_NONE;
sPaletteGammaTypes = sFieldEffectPaletteGammaTypes; sPaletteColorMapTypes = sFieldEffectPaletteColorMapTypes;
} }
void ResetPreservedPalettesInWeather(void) void ResetPreservedPalettesInWeather(void)
{ {
sPaletteGammaTypes = sBasePaletteGammaTypes; sPaletteColorMapTypes = sBasePaletteColorMapTypes;
} }

View File

@@ -94,8 +94,8 @@ static const struct SpriteTemplate sCloudSpriteTemplate =
void Clouds_InitVars(void) void Clouds_InitVars(void)
{ {
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
if (gWeatherPtr->cloudSpritesCreated == FALSE) if (gWeatherPtr->cloudSpritesCreated == FALSE)
@@ -152,8 +152,8 @@ bool8 Clouds_Finish(void)
void Sunny_InitVars(void) void Sunny_InitVars(void)
{ {
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
} }
void Sunny_InitAll(void) void Sunny_InitAll(void)
@@ -235,8 +235,8 @@ void Drought_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 0; gWeatherPtr->colorMapStepDelay = 0;
} }
void Drought_InitAll(void) void Drought_InitAll(void)
@@ -476,8 +476,8 @@ void Rain_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 8; gWeatherPtr->rainSpriteVisibleDelay = 8;
gWeatherPtr->isDownpour = FALSE; gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 10; gWeatherPtr->targetRainSpriteCount = 10;
gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
SetRainStrengthFromSoundEffect(SE_RAIN); SetRainStrengthFromSoundEffect(SE_RAIN);
} }
@@ -768,8 +768,8 @@ void Snow_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->targetSnowflakeSpriteCount = 16; gWeatherPtr->targetSnowflakeSpriteCount = 16;
gWeatherPtr->snowflakeVisibleCounter = 0; gWeatherPtr->snowflakeVisibleCounter = 0;
} }
@@ -1042,8 +1042,8 @@ void Thunderstorm_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4; gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = FALSE; gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 16; gWeatherPtr->targetRainSpriteCount = 16;
gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
gWeatherPtr->thunderEnqueued = FALSE; gWeatherPtr->thunderEnqueued = FALSE;
SetRainStrengthFromSoundEffect(SE_THUNDERSTORM); SetRainStrengthFromSoundEffect(SE_THUNDERSTORM);
@@ -1071,8 +1071,8 @@ void Downpour_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4; gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = TRUE; gWeatherPtr->isDownpour = TRUE;
gWeatherPtr->targetRainSpriteCount = 24; gWeatherPtr->targetRainSpriteCount = 24;
gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
SetRainStrengthFromSoundEffect(SE_DOWNPOUR); SetRainStrengthFromSoundEffect(SE_DOWNPOUR);
} }
@@ -1134,7 +1134,7 @@ void Thunderstorm_Main(void)
// fall through // fall through
case THUNDER_STATE_SHORT_BOLT: case THUNDER_STATE_SHORT_BOLT:
// Short bolt of lightning strikes. // Short bolt of lightning strikes.
ApplyWeatherGammaShiftIfIdle(19); ApplyWeatherColorMapIfIdle(19);
// If final lightning bolt, enqueue thunder. // If final lightning bolt, enqueue thunder.
if (!gWeatherPtr->thunderLongBolt && gWeatherPtr->thunderShortBolts == 1) if (!gWeatherPtr->thunderLongBolt && gWeatherPtr->thunderShortBolts == 1)
EnqueueThunder(20); EnqueueThunder(20);
@@ -1146,7 +1146,7 @@ void Thunderstorm_Main(void)
if (--gWeatherPtr->thunderTimer == 0) if (--gWeatherPtr->thunderTimer == 0)
{ {
// Short bolt of lightning ends. // Short bolt of lightning ends.
ApplyWeatherGammaShiftIfIdle(3); ApplyWeatherColorMapIfIdle(3);
gWeatherPtr->thunderAllowEnd = TRUE; gWeatherPtr->thunderAllowEnd = TRUE;
if (--gWeatherPtr->thunderShortBolts != 0) if (--gWeatherPtr->thunderShortBolts != 0)
{ {
@@ -1179,7 +1179,7 @@ void Thunderstorm_Main(void)
{ {
// Do long bolt. Enqueue thunder with a potentially longer delay. // Do long bolt. Enqueue thunder with a potentially longer delay.
EnqueueThunder(100); EnqueueThunder(100);
ApplyWeatherGammaShiftIfIdle(19); ApplyWeatherColorMapIfIdle(19);
gWeatherPtr->thunderTimer = (Random() & 0xF) + 30; gWeatherPtr->thunderTimer = (Random() & 0xF) + 30;
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
} }
@@ -1188,7 +1188,7 @@ void Thunderstorm_Main(void)
if (--gWeatherPtr->thunderTimer == 0) if (--gWeatherPtr->thunderTimer == 0)
{ {
// Fade long bolt out over time. // Fade long bolt out over time.
ApplyWeatherGammaShiftIfIdle_Gradual(19, 3, 5); ApplyWeatherColorMapIfIdle_Gradual(19, 3, 5);
gWeatherPtr->initStep++; gWeatherPtr->initStep++;
} }
break; break;
@@ -1371,8 +1371,8 @@ void FogHorizontal_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
if (gWeatherPtr->fogHSpritesCreated == 0) if (gWeatherPtr->fogHSpritesCreated == 0)
{ {
gWeatherPtr->fogHScrollCounter = 0; gWeatherPtr->fogHScrollCounter = 0;
@@ -1526,8 +1526,8 @@ void Ash_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->ashUnused = 20; // Never read gWeatherPtr->ashUnused = 20; // Never read
if (!gWeatherPtr->ashSpritesCreated) if (!gWeatherPtr->ashSpritesCreated)
{ {
@@ -1736,8 +1736,8 @@ void FogDiagonal_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0; gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->fogHScrollCounter = 0; gWeatherPtr->fogHScrollCounter = 0;
gWeatherPtr->fogHScrollOffset = 1; gWeatherPtr->fogHScrollOffset = 1;
if (!gWeatherPtr->fogDSpritesCreated) if (!gWeatherPtr->fogDSpritesCreated)
@@ -1950,8 +1950,8 @@ void Sandstorm_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0; gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0; gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
if (!gWeatherPtr->sandstormSpritesCreated) if (!gWeatherPtr->sandstormSpritesCreated)
{ {
gWeatherPtr->sandstormXOffset = gWeatherPtr->sandstormYOffset = 0; gWeatherPtr->sandstormXOffset = gWeatherPtr->sandstormYOffset = 0;
@@ -2247,8 +2247,8 @@ static void UpdateSandstormSwirlSprite(struct Sprite *sprite)
void Shade_InitVars(void) void Shade_InitVars(void)
{ {
gWeatherPtr->initStep = 0; gWeatherPtr->initStep = 0;
gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->colorMapStepDelay = 20;
} }
void Shade_InitAll(void) void Shade_InitAll(void)

View File

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

View File

@@ -21,11 +21,6 @@
#include "constants/rgb.h" #include "constants/rgb.h"
#define BATTLER_RECORD_SIZE 664 #define BATTLER_RECORD_SIZE 664
#define ILLEGAL_BATTLE_TYPES ((BATTLE_TYPE_LINK | BATTLE_TYPE_SAFARI | BATTLE_TYPE_FIRST_BATTLE \
| BATTLE_TYPE_WALLY_TUTORIAL | BATTLE_TYPE_ROAMER | BATTLE_TYPE_EREADER_TRAINER \
| BATTLE_TYPE_KYOGRE_GROUDON | BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_REGI \
| BATTLE_TYPE_RECORDED | BATTLE_TYPE_TRAINER_HILL | BATTLE_TYPE_SECRET_BASE \
| BATTLE_TYPE_GROUDON | BATTLE_TYPE_KYOGRE | BATTLE_TYPE_RAYQUAZA))
struct PlayerInfo struct PlayerInfo
{ {
@@ -301,7 +296,7 @@ static bool32 IsRecordedBattleSaveValid(struct RecordedBattleSave *save)
{ {
if (save->battleFlags == 0) if (save->battleFlags == 0)
return FALSE; return FALSE;
if (save->battleFlags & ILLEGAL_BATTLE_TYPES) if (save->battleFlags & BATTLE_TYPE_RECORDED_INVALID)
return FALSE; return FALSE;
if (CalcByteArraySum((void *)(save), sizeof(*save) - 4) != save->checksum) if (CalcByteArraySum((void *)(save), sizeof(*save) - 4) != save->checksum)
return FALSE; return FALSE;

View File

@@ -1264,7 +1264,7 @@ static void Task_SaveAfterLinkBattle(u8 taskId)
} }
else else
{ {
gSoftResetDisabled = 1; gSoftResetDisabled = TRUE;
*state = 1; *state = 1;
} }
break; break;
@@ -1278,7 +1278,7 @@ static void Task_SaveAfterLinkBattle(u8 taskId)
{ {
ClearContinueGameWarpStatus2(); ClearContinueGameWarpStatus2();
*state = 3; *state = 3;
gSoftResetDisabled = 0; gSoftResetDisabled = FALSE;
} }
break; break;
case 3: case 3:

View File

@@ -481,7 +481,7 @@ static bool8 DoMassOutbreakEncounterTest(void)
return FALSE; return FALSE;
} }
static bool8 DoWildEncounterRateDiceRoll(u16 encounterRate) static bool8 EncounterOddsCheck(u16 encounterRate)
{ {
if (Random() % MAX_ENCOUNTER_RATE < encounterRate) if (Random() % MAX_ENCOUNTER_RATE < encounterRate)
return TRUE; return TRUE;
@@ -489,7 +489,8 @@ static bool8 DoWildEncounterRateDiceRoll(u16 encounterRate)
return FALSE; return FALSE;
} }
static bool8 DoWildEncounterRateTest(u32 encounterRate, bool8 ignoreAbility) // Returns true if it will try to create a wild encounter.
static bool8 WildEncounterCheck(u32 encounterRate, bool8 ignoreAbility)
{ {
encounterRate *= 16; encounterRate *= 16;
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE))
@@ -515,10 +516,12 @@ static bool8 DoWildEncounterRateTest(u32 encounterRate, bool8 ignoreAbility)
} }
if (encounterRate > MAX_ENCOUNTER_RATE) if (encounterRate > MAX_ENCOUNTER_RATE)
encounterRate = MAX_ENCOUNTER_RATE; encounterRate = MAX_ENCOUNTER_RATE;
return DoWildEncounterRateDiceRoll(encounterRate); return EncounterOddsCheck(encounterRate);
} }
static bool8 DoGlobalWildEncounterDiceRoll(void) // When you first step on a different type of metatile, there's a 40% chance it
// skips the wild encounter check entirely.
static bool8 AllowWildCheckOnNewMetatile(void)
{ {
if (Random() % 100 >= 60) if (Random() % 100 >= 60)
return FALSE; return FALSE;
@@ -537,7 +540,7 @@ static bool8 AreLegendariesInSootopolisPreventingEncounters(void)
return FlagGet(FLAG_LEGENDARIES_IN_SOOTOPOLIS); return FlagGet(FLAG_LEGENDARIES_IN_SOOTOPOLIS);
} }
bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavior) bool8 StandardWildEncounter(u16 curMetatileBehavior, u16 prevMetatileBehavior)
{ {
u16 headerId; u16 headerId;
struct Roamer *roamer; struct Roamer *roamer;
@@ -551,9 +554,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PIKE_ROOM_WILD_MONS) if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PIKE_ROOM_WILD_MONS)
{ {
headerId = GetBattlePikeWildMonHeaderId(); headerId = GetBattlePikeWildMonHeaderId();
if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile())
return FALSE; return FALSE;
else if (DoWildEncounterRateTest(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) else if (WildEncounterCheck(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE)
return FALSE; return FALSE;
else if (TryGenerateWildMon(gBattlePikeWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE) else if (TryGenerateWildMon(gBattlePikeWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE)
return FALSE; return FALSE;
@@ -566,9 +569,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR) if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR)
{ {
headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum;
if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile())
return FALSE; return FALSE;
else if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) else if (WildEncounterCheck(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE)
return FALSE; return FALSE;
else if (TryGenerateWildMon(gBattlePyramidWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE) else if (TryGenerateWildMon(gBattlePyramidWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE)
return FALSE; return FALSE;
@@ -580,13 +583,13 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
} }
else else
{ {
if (MetatileBehavior_IsLandWildEncounter(currMetaTileBehavior) == TRUE) if (MetatileBehavior_IsLandWildEncounter(curMetatileBehavior) == TRUE)
{ {
if (gWildMonHeaders[headerId].landMonsInfo == NULL) if (gWildMonHeaders[headerId].landMonsInfo == NULL)
return FALSE; return FALSE;
else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) else if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile())
return FALSE; return FALSE;
else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) else if (WildEncounterCheck(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE)
return FALSE; return FALSE;
if (TryStartRoamerEncounter() == TRUE) if (TryStartRoamerEncounter() == TRUE)
@@ -616,16 +619,16 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi
return FALSE; return FALSE;
} }
} }
else if (MetatileBehavior_IsWaterWildEncounter(currMetaTileBehavior) == TRUE else if (MetatileBehavior_IsWaterWildEncounter(curMetatileBehavior) == TRUE
|| (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(currMetaTileBehavior) == TRUE)) || (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(curMetatileBehavior) == TRUE))
{ {
if (AreLegendariesInSootopolisPreventingEncounters() == TRUE) if (AreLegendariesInSootopolisPreventingEncounters() == TRUE)
return FALSE; return FALSE;
else if (gWildMonHeaders[headerId].waterMonsInfo == NULL) else if (gWildMonHeaders[headerId].waterMonsInfo == NULL)
return FALSE; return FALSE;
else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) else if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile())
return FALSE; return FALSE;
else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE) else if (WildEncounterCheck(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE)
return FALSE; return FALSE;
if (TryStartRoamerEncounter() == TRUE) if (TryStartRoamerEncounter() == TRUE)
@@ -665,7 +668,7 @@ void RockSmashWildEncounter(void)
{ {
gSpecialVar_Result = FALSE; gSpecialVar_Result = FALSE;
} }
else if (DoWildEncounterRateTest(wildPokemonInfo->encounterRate, TRUE) == TRUE else if (WildEncounterCheck(wildPokemonInfo->encounterRate, TRUE) == TRUE
&& TryGenerateWildMon(wildPokemonInfo, WILD_AREA_ROCKS, WILD_CHECK_REPEL | WILD_CHECK_KEEN_EYE) == TRUE) && TryGenerateWildMon(wildPokemonInfo, WILD_AREA_ROCKS, WILD_CHECK_REPEL | WILD_CHECK_KEEN_EYE) == TRUE)
{ {
BattleSetup_StartWildBattle(); BattleSetup_StartWildBattle();