diff --git a/graphics/rotating_gates/l1.png b/graphics/rotating_gates/l1.png index 93680dbfb..e2f4779e3 100644 Binary files a/graphics/rotating_gates/l1.png and b/graphics/rotating_gates/l1.png differ diff --git a/graphics/rotating_gates/l2.png b/graphics/rotating_gates/l2.png index 1d320ed77..78bfe902f 100644 Binary files a/graphics/rotating_gates/l2.png and b/graphics/rotating_gates/l2.png differ diff --git a/graphics/rotating_gates/l3.png b/graphics/rotating_gates/l3.png index 6e43079d0..28aa331b4 100644 Binary files a/graphics/rotating_gates/l3.png and b/graphics/rotating_gates/l3.png differ diff --git a/graphics/rotating_gates/l4.png b/graphics/rotating_gates/l4.png index 77c269dc5..c1e68ccbc 100644 Binary files a/graphics/rotating_gates/l4.png and b/graphics/rotating_gates/l4.png differ diff --git a/graphics/rotating_gates/t1.png b/graphics/rotating_gates/t1.png index d8a0889b1..bbc851731 100644 Binary files a/graphics/rotating_gates/t1.png and b/graphics/rotating_gates/t1.png differ diff --git a/graphics/rotating_gates/t2.png b/graphics/rotating_gates/t2.png index 668feebfb..6e13aefda 100644 Binary files a/graphics/rotating_gates/t2.png and b/graphics/rotating_gates/t2.png differ diff --git a/graphics/rotating_gates/t3.png b/graphics/rotating_gates/t3.png index d92ae872c..694c9ed05 100644 Binary files a/graphics/rotating_gates/t3.png and b/graphics/rotating_gates/t3.png differ diff --git a/graphics/rotating_gates/t4.png b/graphics/rotating_gates/t4.png index 5e3a947c5..fa3a77e38 100644 Binary files a/graphics/rotating_gates/t4.png and b/graphics/rotating_gates/t4.png differ diff --git a/include/constants/battle.h b/include/constants/battle.h index cbc6c5adc..b4f3a4d9b 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -78,6 +78,11 @@ #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_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 #define B_OUTCOME_WON 1 diff --git a/include/field_weather.h b/include/field_weather.h index 922922e42..8ce0cc9e5 100644 --- a/include/field_weather.h +++ b/include/field_weather.h @@ -19,6 +19,8 @@ enum { PALTAG_WEATHER_2 }; +#define NUM_WEATHER_COLOR_MAPS 19 + struct Weather { union @@ -39,12 +41,12 @@ 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; + u8 darkenedContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32]; + u8 contrastColorMaps[NUM_WEATHER_COLOR_MAPS][32]; + s8 colorMapIndex; + s8 targetColorMapIndex; + u8 colorMapStepDelay; + u8 colorMapStepCounter; u16 fadeDestColor; u8 palProcessingState; u8 fadeScreenCounter; @@ -59,7 +61,7 @@ struct Weather u8 weatherGfxLoaded; bool8 weatherChangeComplete; u8 weatherPicSpritePalIndex; - u8 altGammaSpritePalIndex; + u8 contrastColorMapSpritePalIndex; // Rain u16 rainSpriteVisibleCounter; u8 curRainSpriteIndex; @@ -146,12 +148,12 @@ void StartWeather(void); void SetNextWeather(u8 weather); void SetCurrentAndNextWeather(u8 weather); void SetCurrentAndNextWeatherNoDelay(u8 weather); -void ApplyWeatherGammaShiftIfIdle(s8 gammaIndex); -void ApplyWeatherGammaShiftIfIdle_Gradual(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay); +void ApplyWeatherColorMapIfIdle(s8 colorMapIndex); +void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay); void FadeScreen(u8 mode, s8 delay); bool8 IsWeatherNotFadingIn(void); void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex); -void ApplyWeatherGammaShiftToPal(u8 paletteIndex); +void ApplyWeatherColorMapToPal(u8 paletteIndex); void LoadCustomWeatherSpritePalette(const u16 *palette); void ResetDroughtWeatherPaletteLoading(void); bool8 LoadDroughtWeatherPalettes(void); diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 2ba4c29cd..1b907f3d2 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -36,7 +36,7 @@ #include "constants/trainer_hill.h" static EWRAM_DATA u8 sWildEncounterImmunitySteps = 0; -static EWRAM_DATA u16 sPreviousPlayerMetatileBehavior = 0; +static EWRAM_DATA u16 sPrevMetatileBehavior = 0; u8 gSelectedObjectEvent; @@ -671,18 +671,18 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior) if (sWildEncounterImmunitySteps < 4) { sWildEncounterImmunitySteps++; - sPreviousPlayerMetatileBehavior = metatileBehavior; + sPrevMetatileBehavior = metatileBehavior; return FALSE; } - if (StandardWildEncounter(metatileBehavior, sPreviousPlayerMetatileBehavior) == TRUE) + if (StandardWildEncounter(metatileBehavior, sPrevMetatileBehavior) == TRUE) { sWildEncounterImmunitySteps = 0; - sPreviousPlayerMetatileBehavior = metatileBehavior; + sPrevMetatileBehavior = metatileBehavior; return TRUE; } - sPreviousPlayerMetatileBehavior = metatileBehavior; + sPrevMetatileBehavior = metatileBehavior; return FALSE; } diff --git a/src/field_weather.c b/src/field_weather.c index f7a7f8129..891dbb1d1 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -21,9 +21,9 @@ enum { - GAMMA_NONE, - GAMMA_NORMAL, - GAMMA_ALT, + COLOR_MAP_NONE, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_CONTRAST, }; struct RGBColor @@ -33,11 +33,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); @@ -48,11 +43,11 @@ struct WeatherCallbacks // This file's functions. static bool8 LightenSpritePaletteInFog(u8); -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, u16 blendColor); -static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor); +static void BuildColorMaps(void); +static void UpdateWeatherColorMap(void); +static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex); +static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor); +static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor); static void ApplyFogBlend(u8 blendCoeff, u16 blendColor); static bool8 FadeInScreen_RainShowShade(void); static bool8 FadeInScreen_Drought(void); @@ -66,9 +61,9 @@ static void None_Main(void); static u8 None_Finish(void); 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 // is because the underlying color shift calculation is slow. @@ -108,50 +103,50 @@ static const struct WeatherCallbacks sWeatherFuncs[] = 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_OUT] = 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. -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_NORMAL, - 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_DARK_CONTRAST, + COLOR_MAP_NONE, + COLOR_MAP_NONE, // sprite palettes - GAMMA_ALT, - GAMMA_NORMAL, - GAMMA_ALT, - GAMMA_ALT, - GAMMA_ALT, - GAMMA_ALT, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_ALT, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_NORMAL, - GAMMA_NORMAL, + COLOR_MAP_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_CONTRAST, + COLOR_MAP_CONTRAST, + COLOR_MAP_CONTRAST, + COLOR_MAP_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, + COLOR_MAP_DARK_CONTRAST, }; const u16 gFogPalette[] = INCBIN_U16("graphics/weather/fog.gbapal"); @@ -160,10 +155,10 @@ void StartWeather(void) { if (!FuncIsActiveTask(Task_WeatherMain)) { - u8 index = AllocSpritePalette(TAG_WEATHER_START); + u8 index = AllocSpritePalette(PALTAG_WEATHER); CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32); - BuildGammaShiftTables(); - gWeatherPtr->altGammaSpritePalIndex = index; + BuildColorMaps(); + gWeatherPtr->contrastColorMapSpritePalIndex = index; gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2); gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->curRainSpriteIndex = 0; @@ -238,7 +233,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; @@ -254,8 +249,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) @@ -267,70 +262,82 @@ static u8 None_Finish(void) 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 // this function always builds the same two tables. -static void BuildGammaShiftTables(void) +static void BuildColorMaps(void) { - u16 v0; - u8 (*gammaTable)[32]; - u16 v2; - u16 v4; - u16 v5; - u16 gammaIndex; - u16 v9; - u32 v10; - u16 v11; - s16 dunno; + u16 i; + u8 (*colorMaps)[32]; + u16 colorVal; + u16 curBrightness; + u16 brightnessDelta; + u16 colorMapIndex; + u16 baseBrightness; + u32 remainingBrightness; + s16 diff; - sPaletteGammaTypes = sBasePaletteGammaTypes; - for (v0 = 0; v0 <= 1; v0++) + sPaletteColorMapTypes = sBasePaletteColorMapTypes; + for (i = 0; i < 2; i++) { - if (v0 == 0) - gammaTable = gWeatherPtr->gammaShifts; + if (i == 0) + colorMaps = gWeatherPtr->darkenedContrastColorMaps; else - gammaTable = gWeatherPtr->altGammaShifts; + colorMaps = gWeatherPtr->contrastColorMaps; - for (v2 = 0; v2 < 32; v2++) + for (colorVal = 0; colorVal < 32; colorVal++) { - v4 = v2 << 8; - if (v0 == 0) - v5 = (v2 << 8) / 16; + curBrightness = colorVal << 8; + if (i == 0) + brightnessDelta = (colorVal << 8) / 16; else - v5 = 0; - for (gammaIndex = 0; gammaIndex <= 2; gammaIndex++) + brightnessDelta = 0; + + // First three color mappings are simple brightness modifiers which are + // progressively darker, according to brightnessDelta. + for (colorMapIndex = 0; colorMapIndex < 3; colorMapIndex++) { - v4 = (v4 - v5); - gammaTable[gammaIndex][v2] = v4 >> 8; + curBrightness -= brightnessDelta; + colorMaps[colorMapIndex][colorVal] = curBrightness >> 8; } - v9 = v4; - v10 = 0x1f00 - v4; - if ((0x1f00 - v4) < 0) + + baseBrightness = curBrightness; + remainingBrightness = 0x1f00 - curBrightness; + if ((0x1f00 - curBrightness) < 0) + remainingBrightness += 0xf; + + brightnessDelta = remainingBrightness / (NUM_WEATHER_COLOR_MAPS - 3); + if (colorVal < 12) { - v10 += 0xf; - } - v11 = v10 >> 4; - if (v2 < 12) - { - for (; gammaIndex < 19; gammaIndex++) + // For shadows (color values < 12), the remaining color mappings are + // brightness modifiers, which are increased at a significantly lower rate + // than the midtones and highlights (color values >= 12). This creates a + // high contrast effect, used in the thunderstorm weather. + for (; colorMapIndex < NUM_WEATHER_COLOR_MAPS; colorMapIndex++) { - 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; + curBrightness += brightnessDelta; + diff = curBrightness - baseBrightness; + if (diff > 0) + curBrightness -= diff / 2; + colorMaps[colorMapIndex][colorVal] = curBrightness >> 8; + if (colorMaps[colorMapIndex][colorVal] > 31) + colorMaps[colorMapIndex][colorVal] = 31; } } 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; - gammaTable[gammaIndex][v2] = v4 >> 8; - if (gammaTable[gammaIndex][v2] > 0x1f) - gammaTable[gammaIndex][v2] = 0x1f; + curBrightness += brightnessDelta; + colorMaps[colorMapIndex][colorVal] = curBrightness >> 8; + if (colorMaps[colorMapIndex][colorVal] > 31) + colorMaps[colorMapIndex][colorVal] = 31; } } } @@ -338,26 +345,26 @@ static void BuildGammaShiftTables(void) } // 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->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) { - 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); } } } @@ -377,21 +384,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; @@ -402,7 +409,7 @@ static void FadeInScreenWithWeather(void) default: if (!gPaletteFade.active) { - gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex; + gWeatherPtr->colorMapIndex = gWeatherPtr->targetColorMapIndex; gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; @@ -416,12 +423,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; } @@ -432,12 +439,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; } @@ -454,24 +461,24 @@ 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; + u8 *colorMap; u16 i; - if (gammaIndex > 0) + if (colorMapIndex > 0) { - gammaIndex--; + colorMapIndex--; palOffset = startPalIndex * 16; numPalettes += 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) { - if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) + if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE) { // No palette change. 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; - if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex) - gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; + if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_CONTRAST || curPalIndex - 16 == gWeatherPtr->contrastColorMapSpritePalIndex) + colorMap = gWeatherPtr->contrastColorMaps[colorMapIndex]; else - gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; + colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex]; 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]; - 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++] = RGB2(r, g, b); } } @@ -500,17 +507,17 @@ 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. - gammaIndex = -gammaIndex - 1; + colorMapIndex = -colorMapIndex - 1; palOffset = startPalIndex * 16; numPalettes += startPalIndex; curPalIndex = startPalIndex; while (curPalIndex < numPalettes) { - if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) + if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE) { // No palette change. 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++) { - gPlttBufferFaded[palOffset] = sDroughtWeatherColors[gammaIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])]; + gPlttBufferFaded[palOffset] = sDroughtWeatherColors[colorMapIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[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 curPalIndex; @@ -547,34 +554,34 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI palOffset = startPalIndex * 16; numPalettes += startPalIndex; - gammaIndex--; + colorMapIndex--; curPalIndex = startPalIndex; 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); palOffset += 16; } else { - u8 *gammaTable; + u8 *colorMap; - if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL) - gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; + if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_DARK_CONTRAST) + colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex]; else - gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; + colorMap = gWeatherPtr->contrastColorMaps[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. + // Apply color map and target blend color to the original color. r += ((rBlend - r) * blendCoeff) >> 4; g += ((gBlend - g) * 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; u8 rBlend; @@ -596,7 +603,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl u16 palOffset; u16 i; - gammaIndex = -gammaIndex - 1; + colorMapIndex = -colorMapIndex - 1; color = *(struct RGBColor *)&blendColor; rBlend = color.r; gBlend = color.g; @@ -604,9 +611,9 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 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; } @@ -626,7 +633,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl b1 = color1.b; 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; g2 = color2.g; b2 = color2.b; @@ -710,25 +717,25 @@ static bool8 LightenSpritePaletteInFog(u8 paletteIndex) return FALSE; } -void ApplyWeatherGammaShiftIfIdle(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 ApplyWeatherGammaShiftIfIdle_Gradual(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; - ApplyWeatherGammaShiftIfIdle(gammaIndex); + gWeatherPtr->colorMapIndex = colorMapIndex; + gWeatherPtr->targetColorMapIndex = targetColorMapIndex; + gWeatherPtr->colorMapStepCounter = 0; + gWeatherPtr->colorMapStepDelay = colorMapStepDelay; + ApplyWeatherColorMapIfIdle(colorMapIndex); } } @@ -832,7 +839,7 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex) default: if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL) { - ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); + ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex); } 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 @@ -886,9 +893,9 @@ bool8 LoadDroughtWeatherPalettes(void) return FALSE; } -static void SetDroughtGamma(s8 gammaIndex) +static void SetDroughtColorMap(s8 colorMapIndex) { - ApplyWeatherGammaShiftIfIdle(-gammaIndex - 1); + ApplyWeatherColorMapIfIdle(-colorMapIndex - 1); } void DroughtStateInit(void) @@ -907,7 +914,7 @@ void DroughtStateRun(void) if (++gWeatherPtr->droughtTimer > 5) { gWeatherPtr->droughtTimer = 0; - SetDroughtGamma(gWeatherPtr->droughtBrightnessStage++); + SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage++); if (gWeatherPtr->droughtBrightnessStage > 5) { gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage; @@ -920,14 +927,14 @@ 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: if (++gWeatherPtr->droughtTimer > 5) { gWeatherPtr->droughtTimer = 0; - SetDroughtGamma(--gWeatherPtr->droughtBrightnessStage); + SetDroughtColorMap(--gWeatherPtr->droughtBrightnessStage); if (gWeatherPtr->droughtBrightnessStage == 3) gWeatherPtr->droughtState = 0; } @@ -1093,12 +1100,12 @@ void SetWeatherPalStateIdle(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; } diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index 42ab084dd..05eae421e 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -94,8 +94,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 == FALSE) @@ -152,8 +152,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) @@ -235,8 +235,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) @@ -476,8 +476,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); } @@ -768,8 +768,8 @@ void Snow_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->gammaTargetIndex = 3; - gWeatherPtr->gammaStepDelay = 20; + gWeatherPtr->targetColorMapIndex = 3; + gWeatherPtr->colorMapStepDelay = 20; gWeatherPtr->targetSnowflakeSpriteCount = 16; gWeatherPtr->snowflakeVisibleCounter = 0; } @@ -1042,8 +1042,8 @@ 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->thunderEnqueued = FALSE; SetRainStrengthFromSoundEffect(SE_THUNDERSTORM); @@ -1071,8 +1071,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); } @@ -1134,7 +1134,7 @@ void Thunderstorm_Main(void) // fall through case THUNDER_STATE_SHORT_BOLT: // Short bolt of lightning strikes. - ApplyWeatherGammaShiftIfIdle(19); + ApplyWeatherColorMapIfIdle(19); // If final lightning bolt, enqueue thunder. if (!gWeatherPtr->thunderLongBolt && gWeatherPtr->thunderShortBolts == 1) EnqueueThunder(20); @@ -1146,7 +1146,7 @@ void Thunderstorm_Main(void) if (--gWeatherPtr->thunderTimer == 0) { // Short bolt of lightning ends. - ApplyWeatherGammaShiftIfIdle(3); + ApplyWeatherColorMapIfIdle(3); gWeatherPtr->thunderAllowEnd = TRUE; if (--gWeatherPtr->thunderShortBolts != 0) { @@ -1179,7 +1179,7 @@ void Thunderstorm_Main(void) { // Do long bolt. Enqueue thunder with a potentially longer delay. EnqueueThunder(100); - ApplyWeatherGammaShiftIfIdle(19); + ApplyWeatherColorMapIfIdle(19); gWeatherPtr->thunderTimer = (Random() & 0xF) + 30; gWeatherPtr->initStep++; } @@ -1188,7 +1188,7 @@ void Thunderstorm_Main(void) if (--gWeatherPtr->thunderTimer == 0) { // Fade long bolt out over time. - ApplyWeatherGammaShiftIfIdle_Gradual(19, 3, 5); + ApplyWeatherColorMapIfIdle_Gradual(19, 3, 5); gWeatherPtr->initStep++; } break; @@ -1371,8 +1371,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 == 0) { gWeatherPtr->fogHScrollCounter = 0; @@ -1526,8 +1526,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) { @@ -1736,8 +1736,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) @@ -1950,8 +1950,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; @@ -2247,8 +2247,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) diff --git a/src/overworld.c b/src/overworld.c index 4c4dd5217..6db90b66e 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -812,8 +812,8 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout); LoadSecondaryTilesetPalette(gMapHeader.mapLayout); - for (paletteIndex = 6; paletteIndex < 13; paletteIndex++) - ApplyWeatherGammaShiftToPal(paletteIndex); + for (paletteIndex = NUM_PALS_IN_PRIMARY; paletteIndex < NUM_PALS_TOTAL; paletteIndex++) + ApplyWeatherColorMapToPal(paletteIndex); InitSecondaryTilesetAnimation(); UpdateLocationHistoryForRoamer(); diff --git a/src/recorded_battle.c b/src/recorded_battle.c index dead1dd7e..33228255d 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -21,11 +21,6 @@ #include "constants/rgb.h" #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 { @@ -301,7 +296,7 @@ static bool32 IsRecordedBattleSaveValid(struct RecordedBattleSave *save) { if (save->battleFlags == 0) return FALSE; - if (save->battleFlags & ILLEGAL_BATTLE_TYPES) + if (save->battleFlags & BATTLE_TYPE_RECORDED_INVALID) return FALSE; if (CalcByteArraySum((void *)(save), sizeof(*save) - 4) != save->checksum) return FALSE; diff --git a/src/start_menu.c b/src/start_menu.c index 2a45f8d69..7489f09d6 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -1264,7 +1264,7 @@ static void Task_SaveAfterLinkBattle(u8 taskId) } else { - gSoftResetDisabled = 1; + gSoftResetDisabled = TRUE; *state = 1; } break; @@ -1278,7 +1278,7 @@ static void Task_SaveAfterLinkBattle(u8 taskId) { ClearContinueGameWarpStatus2(); *state = 3; - gSoftResetDisabled = 0; + gSoftResetDisabled = FALSE; } break; case 3: diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 01161e6cc..eb42cd7bd 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -481,7 +481,7 @@ static bool8 DoMassOutbreakEncounterTest(void) return FALSE; } -static bool8 DoWildEncounterRateDiceRoll(u16 encounterRate) +static bool8 EncounterOddsCheck(u16 encounterRate) { if (Random() % MAX_ENCOUNTER_RATE < encounterRate) return TRUE; @@ -489,7 +489,8 @@ static bool8 DoWildEncounterRateDiceRoll(u16 encounterRate) 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; 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) 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) return FALSE; @@ -537,7 +540,7 @@ static bool8 AreLegendariesInSootopolisPreventingEncounters(void) return FlagGet(FLAG_LEGENDARIES_IN_SOOTOPOLIS); } -bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavior) +bool8 StandardWildEncounter(u16 curMetatileBehavior, u16 prevMetatileBehavior) { u16 headerId; struct Roamer *roamer; @@ -551,9 +554,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PIKE_ROOM_WILD_MONS) { headerId = GetBattlePikeWildMonHeaderId(); - if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile()) return FALSE; - else if (DoWildEncounterRateTest(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (WildEncounterCheck(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; else if (TryGenerateWildMon(gBattlePikeWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE) return FALSE; @@ -566,9 +569,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR) { headerId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile()) return FALSE; - else if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (WildEncounterCheck(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; else if (TryGenerateWildMon(gBattlePyramidWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE) != TRUE) return FALSE; @@ -580,13 +583,13 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi } else { - if (MetatileBehavior_IsLandWildEncounter(currMetaTileBehavior) == TRUE) + if (MetatileBehavior_IsLandWildEncounter(curMetatileBehavior) == TRUE) { if (gWildMonHeaders[headerId].landMonsInfo == NULL) return FALSE; - else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + else if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile()) return FALSE; - else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (WildEncounterCheck(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; if (TryStartRoamerEncounter() == TRUE) @@ -616,16 +619,16 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi return FALSE; } } - else if (MetatileBehavior_IsWaterWildEncounter(currMetaTileBehavior) == TRUE - || (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(currMetaTileBehavior) == TRUE)) + else if (MetatileBehavior_IsWaterWildEncounter(curMetatileBehavior) == TRUE + || (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING) && MetatileBehavior_IsBridgeOverWater(curMetatileBehavior) == TRUE)) { if (AreLegendariesInSootopolisPreventingEncounters() == TRUE) return FALSE; else if (gWildMonHeaders[headerId].waterMonsInfo == NULL) return FALSE; - else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + else if (prevMetatileBehavior != curMetatileBehavior && !AllowWildCheckOnNewMetatile()) return FALSE; - else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE) + else if (WildEncounterCheck(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; if (TryStartRoamerEncounter() == TRUE) @@ -665,7 +668,7 @@ void RockSmashWildEncounter(void) { 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) { BattleSetup_StartWildBattle();