diff --git a/constants/flags.inc b/constants/flags.inc index 2e4b60d73..66663cb65 100644 --- a/constants/flags.inc +++ b/constants/flags.inc @@ -80,7 +80,7 @@ .equiv FLAG_0x050, 0x50 .equiv FLAG_0x051, 0x51 .equiv FLAG_0x052, 0x52 - .equiv FLAG_0x053, 0x53 + .equiv FLAG_LEGENDARIES_IN_SOOTOPOLIS, 0x53 .equiv FLAG_0x054, 0x54 .equiv FLAG_0x055, 0x55 .equiv FLAG_0x056, 0x56 diff --git a/constants/variables.inc b/constants/variables.inc index e2719e10c..47748891b 100644 --- a/constants/variables.inc +++ b/constants/variables.inc @@ -60,7 +60,7 @@ .equiv VAR_0x403B, 0x403B .equiv VAR_0x403C, 0x403C .equiv VAR_0x403D, 0x403D - .equiv VAR_0x403E, 0x403E + .equiv VAR_ALTERING_CAVE_WILD_SET, 0x403E .equiv VAR_0x403F, 0x403F .equiv VAR_DAYS, 0x4040 .equiv VAR_0x4041, 0x4041 diff --git a/data/scripts/maps/SeafloorCavern_Room9.inc b/data/scripts/maps/SeafloorCavern_Room9.inc index 6f968b4d0..984d53295 100644 --- a/data/scripts/maps/SeafloorCavern_Room9.inc +++ b/data/scripts/maps/SeafloorCavern_Room9.inc @@ -127,7 +127,7 @@ SeafloorCavern_Room9_EventScript_234DC9:: @ 8234DC9 clearflag FLAG_0x3E6 clearflag FLAG_0x3E5 setflag FLAG_0x347 - setflag FLAG_0x053 + setflag FLAG_LEGENDARIES_IN_SOOTOPOLIS clearflag FLAG_0x3B0 clearflag FLAG_0x3B1 setflag FLAG_SYS_WEATHER_CTRL diff --git a/data/scripts/maps/SootopolisCity.inc b/data/scripts/maps/SootopolisCity.inc index 33b65714b..d9eaee6eb 100644 --- a/data/scripts/maps/SootopolisCity.inc +++ b/data/scripts/maps/SootopolisCity.inc @@ -545,7 +545,7 @@ SootopolisCity_EventScript_1E5C1E:: @ 81E5C1E waitstate clearflag FLAG_SYS_WEATHER_CTRL setvar VAR_0x40CA, 3 - clearflag FLAG_0x053 + clearflag FLAG_LEGENDARIES_IN_SOOTOPOLIS fadenewbgm BGM_RUNECITY delay 120 clearflag FLAG_SPECIAL_FLAG_0x4000 @@ -598,7 +598,7 @@ SootopolisCity_EventScript_1E5CCE:: @ 81E5CCE waitstate clearflag FLAG_SYS_WEATHER_CTRL setvar VAR_0x40CA, 2 - clearflag FLAG_0x053 + clearflag FLAG_LEGENDARIES_IN_SOOTOPOLIS fadenewbgm BGM_NAMINORI delay 120 clearflag FLAG_SPECIAL_FLAG_0x4000 diff --git a/src/wild_encounter.c b/src/wild_encounter.c index b4095aa17..ce1e02e5e 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -81,7 +81,7 @@ static bool8 CheckFeebas(void) u16 feebasSpots[NUM_FEEBAS_SPOTS]; s16 x; s16 y; - u8 route119section = 0; + u8 route119Section = 0; u16 waterTileNum; if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP_ROUTE119 @@ -93,16 +93,16 @@ static bool8 CheckFeebas(void) #ifdef NONMATCHING if (y >= gRoute119WaterTileData[3 * 1 + 0] && y <= gRoute119WaterTileData[3 * 1 + 1]) - route119section = 1; + route119Section = 1; if (y >= gRoute119WaterTileData[3 * 2 + 0] && y <= gRoute119WaterTileData[3 * 2 + 1]) - route119section = 2; + route119Section = 2; #else { register const u16 *arr asm("r0"); if (y >= (arr = gRoute119WaterTileData)[3 * 1 + 0] && y <= arr[3 * 1 + 1]) - route119section = 1; + route119Section = 1; if (y >= arr[3 * 2 + 0] && y <= arr[3 * 2 + 1]) - route119section = 2; + route119Section = 2; } #endif @@ -118,7 +118,7 @@ static bool8 CheckFeebas(void) if (feebasSpots[i] < 1 || feebasSpots[i] >= 4) i++; } - waterTileNum = GetRoute119WaterTileNum(x, y, route119section); + waterTileNum = GetRoute119WaterTileNum(x, y, route119Section); for (i = 0; i < NUM_FEEBAS_SPOTS; i++) { if (waterTileNum == feebasSpots[i]) @@ -128,9 +128,12 @@ static bool8 CheckFeebas(void) return FALSE; } +// The number 1103515245 comes from the example implementation of rand and srand +// in the ISO C standard. + static u16 FeebasRandom(void) { - sFeebasRngValue = 12345 + 0x41C64E6D * sFeebasRngValue; + sFeebasRngValue = (1103515245 * sFeebasRngValue) + 12345; return sFeebasRngValue >> 16; } @@ -145,25 +148,25 @@ static u8 ChooseWildMonIndex_Land(void) if (rand < 20) // 20% chance return 0; - if (rand >= 20 && rand < 40) // 20% chance + else if (rand >= 20 && rand < 40) // 20% chance return 1; - if (rand >= 40 && rand < 50) // 10% chance + else if (rand >= 40 && rand < 50) // 10% chance return 2; - if (rand >= 50 && rand < 60) // 10% chance + else if (rand >= 50 && rand < 60) // 10% chance return 3; - if (rand >= 60 && rand < 70) // 10% chance + else if (rand >= 60 && rand < 70) // 10% chance return 4; - if (rand >= 70 && rand < 80) // 10% chance + else if (rand >= 70 && rand < 80) // 10% chance return 5; - if (rand >= 80 && rand < 85) // 5% chance + else if (rand >= 80 && rand < 85) // 5% chance return 6; - if (rand >= 85 && rand < 90) // 5% chance + else if (rand >= 85 && rand < 90) // 5% chance return 7; - if (rand >= 90 && rand < 94) // 4% chance + else if (rand >= 90 && rand < 94) // 4% chance return 8; - if (rand >= 94 && rand < 98) // 4% chance + else if (rand >= 94 && rand < 98) // 4% chance return 9; - if (rand == 98) // 1% chance + else if (rand == 98) // 1% chance return 10; else // 1% chance return 11; @@ -175,11 +178,11 @@ static u8 ChooseWildMonIndex_WaterRock(void) if (rand < 60) // 60% chance return 0; - if (rand >= 60 && rand < 90) // 30% chance + else if (rand >= 60 && rand < 90) // 30% chance return 1; - if (rand >= 90 && rand < 95) // 5% chance + else if (rand >= 90 && rand < 95) // 5% chance return 2; - if (rand >= 95 && rand < 99) // 4% chance + else if (rand >= 95 && rand < 99) // 4% chance return 3; else // 1% chance return 4; @@ -535,11 +538,11 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi headerId = GetBattlePikeWildMonHeaderId(); if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) return FALSE; - if (DoWildEncounterRateTest(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (DoWildEncounterRateTest(gBattlePikeWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; - 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; - if (!TryGenerateBattlePikeWildMon(TRUE)) + else if (!TryGenerateBattlePikeWildMon(TRUE)) return FALSE; BattleSetup_StartBattlePikeWildBattle(); @@ -550,9 +553,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi headerId = gSaveBlock2Ptr->battlePyramidWildHeaderId; if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) return FALSE; - if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (DoWildEncounterRateTest(gBattlePyramidWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; - 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; GenerateBattlePyramidWildMon(); @@ -566,9 +569,9 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi { if (gWildMonHeaders[headerId].landMonsInfo == NULL) return FALSE; - if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) return FALSE; - if (DoWildEncounterRateTest(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) + else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].landMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; if (TryStartRoamerEncounter() == TRUE) @@ -603,11 +606,11 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi { if (AreLegendariesInSootopolisPreventingEncounters() == TRUE) return FALSE; - if (gWildMonHeaders[headerId].waterMonsInfo == NULL) + else if (gWildMonHeaders[headerId].waterMonsInfo == NULL) return FALSE; - if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) + else if (previousMetaTileBehavior != currMetaTileBehavior && !DoGlobalWildEncounterDiceRoll()) return FALSE; - if (DoWildEncounterRateTest(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE) + else if (DoWildEncounterRateTest(gWildMonHeaders[headerId].waterMonsInfo->encounterRate, FALSE) != TRUE) return FALSE; if (TryStartRoamerEncounter() == TRUE) @@ -783,10 +786,10 @@ u16 GetLocalWildMon(bool8 *isWaterMon) if (landMonsInfo == NULL && waterMonsInfo == NULL) return SPECIES_NONE; // Land Pokemon - if (landMonsInfo != NULL && waterMonsInfo == NULL) + else if (landMonsInfo != NULL && waterMonsInfo == NULL) return landMonsInfo->wildPokemon[ChooseWildMonIndex_Land()].species; // Water Pokemon - if (landMonsInfo == NULL && waterMonsInfo != NULL) + else if (landMonsInfo == NULL && waterMonsInfo != NULL) { *isWaterMon = TRUE; return waterMonsInfo->wildPokemon[ChooseWildMonIndex_WaterRock()].species; @@ -907,9 +910,9 @@ static bool8 TryGetAbilityInfluencedWildMonIndex(const struct WildPokemon *wildM { if (GetMonData(&gPlayerParty[0], MON_DATA_SANITY_BIT3)) return FALSE; - if (GetMonAbility(&gPlayerParty[0]) != ability) + else if (GetMonAbility(&gPlayerParty[0]) != ability) return FALSE; - if (Random() % 2 != 0) + else if (Random() % 2 != 0) return FALSE; return TryGetRandomWildMonIndexByType(wildMon, type, LAND_WILD_COUNT, monIndex);