diff options
Diffstat (limited to 'src')
52 files changed, 1206 insertions, 957 deletions
diff --git a/src/battle_arena.c b/src/battle_arena.c index 8a993f770..f744a3b2b 100644 --- a/src/battle_arena.c +++ b/src/battle_arena.c @@ -798,7 +798,7 @@ static void InitArenaChallenge(void) if (!isCurrent) gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] = 0; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_dome.c b/src/battle_dome.c index 1b067924f..293662985 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2099,7 +2099,7 @@ static void InitDomeChallenge(void) if (!(gSaveBlock2Ptr->frontier.winStreakActiveFlags & sWinStreakFlags[battleMode][lvlMode])) gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode] = 0; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_factory.c b/src/battle_factory.c index 8f1001e9c..23fa664f3 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -217,7 +217,7 @@ static void InitFactoryChallenge(void) for (i = 0; i < FRONTIER_PARTY_SIZE; i++) gFrontierTempParty[i] = 0xFFFF; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_palace.c b/src/battle_palace.c index c4e48a4b2..0fa65200a 100644 --- a/src/battle_palace.c +++ b/src/battle_palace.c @@ -93,7 +93,7 @@ static void InitPalaceChallenge(void) if (!(gSaveBlock2Ptr->frontier.winStreakActiveFlags & sWinStreakFlags[battleMode][lvlMode])) gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode] = 0; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 48155c833..b10690ce4 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -34,7 +34,6 @@ #include "constants/frontier_util.h" #include "constants/items.h" #include "constants/layouts.h" -#include "constants/maps.h" #include "constants/metatile_labels.h" #include "constants/moves.h" #include "constants/trainers.h" diff --git a/src/battle_setup.c b/src/battle_setup.c index a9d4eeddf..f928cf3f9 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -43,7 +43,6 @@ #include "constants/items.h" #include "constants/songs.h" #include "constants/map_types.h" -#include "constants/maps.h" #include "constants/trainers.h" #include "constants/trainer_hill.h" #include "constants/weather.h" @@ -687,7 +686,7 @@ u8 BattleSetup_GetTerrainId(void) } if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE113) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE113)) return BATTLE_TERRAIN_SAND; - if (GetSav1Weather() == WEATHER_SANDSTORM) + if (GetSavedWeather() == WEATHER_SANDSTORM) return BATTLE_TERRAIN_SAND; return BATTLE_TERRAIN_PLAIN; @@ -700,7 +699,7 @@ static u8 GetBattleTransitionTypeByMap(void) PlayerGetDestCoords(&x, &y); tileBehavior = MapGridGetMetatileBehaviorAt(x, y); - if (Overworld_GetFlashLevel()) + if (GetFlashLevel()) return TRANSITION_TYPE_FLASH; if (!MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) { diff --git a/src/battle_tent.c b/src/battle_tent.c index 26b2e8bb1..53c91c871 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -114,7 +114,7 @@ static void InitVerdanturfTentChallenge(void) gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.challengePaused = FALSE; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); } static void GetVerdanturfTentPrize(void) @@ -176,7 +176,7 @@ static void InitFallarborTentChallenge(void) gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.challengePaused = FALSE; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); } static void GetFallarborTentPrize(void) @@ -231,7 +231,7 @@ static void InitSlateportTentChallenge(void) gSaveBlock2Ptr->frontier.challengeStatus = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.challengePaused = FALSE; - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); } static void GetSlateportTentPrize(void) diff --git a/src/battle_tower.c b/src/battle_tower.c index d9bd18bf7..accdca3b4 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -918,7 +918,7 @@ static void InitTowerChallenge(void) gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] = 0; ValidateBattleTowerRecordChecksums(); - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); gTrainerBattleOpponent_A = 0; } diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index 61fab39e2..26caa830d 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -6,7 +6,6 @@ #include "sound.h" #include "task.h" #include "constants/field_effects.h" -#include "constants/maps.h" #include "constants/songs.h" #include "constants/metatile_labels.h" #include "fieldmap.h" diff --git a/src/cable_club.c b/src/cable_club.c index 1f943b03a..4ee2797f4 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -1031,7 +1031,7 @@ void CleanupLinkRoomState(void) LoadPlayerParty(); SavePlayerBag(); } - SetWarpDestinationToDynamicWarp(0x7F); + SetWarpDestinationToDynamicWarp(WARP_ID_DYNAMIC); } void ExitLinkRoom(void) diff --git a/src/contest_util.c b/src/contest_util.c index 6fd74a68a..7533d4349 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -2256,7 +2256,7 @@ void Task_LinkContest_FinalizeConnection(u8 taskId) StringGetEnd10(gContestMons[i].nickname); DestroyTask(taskId); - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); ScriptContext2_Disable(); EnableBothScriptContexts(); } diff --git a/src/data/lilycove_lady.h b/src/data/lilycove_lady.h index 1f1caa35f..dd0885ff8 100644 --- a/src/data/lilycove_lady.h +++ b/src/data/lilycove_lady.h @@ -5,11 +5,11 @@ static const u16 sContestLadyMonGfxId[] = { - OBJ_EVENT_GFX_ZIGZAGOON_1, - OBJ_EVENT_GFX_SKITTY, - OBJ_EVENT_GFX_POOCHYENA, - OBJ_EVENT_GFX_KECLEON, - OBJ_EVENT_GFX_PIKACHU + [CONTEST_CATEGORY_COOL] = OBJ_EVENT_GFX_ZIGZAGOON_1, + [CONTEST_CATEGORY_BEAUTY] = OBJ_EVENT_GFX_SKITTY, + [CONTEST_CATEGORY_CUTE] = OBJ_EVENT_GFX_POOCHYENA, + [CONTEST_CATEGORY_SMART] = OBJ_EVENT_GFX_KECLEON, + [CONTEST_CATEGORY_TOUGH] = OBJ_EVENT_GFX_PIKACHU }; static const u16 sLilycoveLadyGfxId[] = @@ -434,36 +434,36 @@ static const u16 sFavorLadyPrizes[] = static const u8 *const sContestLadyMonNames[] = { - gText_ContestLady_Handsome, - gText_ContestLady_Vinny, - gText_ContestLady_Moreme, - gText_ContestLady_Ironhard, - gText_ContestLady_Muscle + [CONTEST_CATEGORY_COOL] = gText_ContestLady_Handsome, + [CONTEST_CATEGORY_BEAUTY] = gText_ContestLady_Vinny, + [CONTEST_CATEGORY_CUTE] = gText_ContestLady_Moreme, + [CONTEST_CATEGORY_SMART] = gText_ContestLady_Ironhard, + [CONTEST_CATEGORY_TOUGH] = gText_ContestLady_Muscle }; static const u8 *const sContestLadyCategoryNames[] = { - gText_ContestLady_Coolness, - gText_ContestLady_Beauty, - gText_ContestLady_Cuteness, - gText_ContestLady_Smartness, - gText_ContestLady_Toughness + [CONTEST_CATEGORY_COOL] = gText_ContestLady_Coolness, + [CONTEST_CATEGORY_BEAUTY] = gText_ContestLady_Beauty, + [CONTEST_CATEGORY_CUTE] = gText_ContestLady_Cuteness, + [CONTEST_CATEGORY_SMART] = gText_ContestLady_Smartness, + [CONTEST_CATEGORY_TOUGH] = gText_ContestLady_Toughness }; static const u8 *const sContestNames[] = { - gText_CoolnessContest, - gText_BeautyContest, - gText_CutenessContest, - gText_SmartnessContest, - gText_ToughnessContest + [CONTEST_CATEGORY_COOL] = gText_CoolnessContest, + [CONTEST_CATEGORY_BEAUTY] = gText_BeautyContest, + [CONTEST_CATEGORY_CUTE] = gText_CutenessContest, + [CONTEST_CATEGORY_SMART] = gText_SmartnessContest, + [CONTEST_CATEGORY_TOUGH] = gText_ToughnessContest }; static const u16 sContestLadyMonSpecies[] = { - SPECIES_ZIGZAGOON, - SPECIES_SKITTY, - SPECIES_POOCHYENA, - SPECIES_KECLEON, - SPECIES_PIKACHU + [CONTEST_CATEGORY_COOL] = SPECIES_ZIGZAGOON, + [CONTEST_CATEGORY_BEAUTY] = SPECIES_SKITTY, + [CONTEST_CATEGORY_CUTE] = SPECIES_POOCHYENA, + [CONTEST_CATEGORY_SMART] = SPECIES_KECLEON, + [CONTEST_CATEGORY_TOUGH] = SPECIES_PIKACHU }; diff --git a/src/decoration.c b/src/decoration.c index bb2dea7f9..9aa4bdf4d 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1175,7 +1175,7 @@ static void SetInitialPositions(u8 taskId) static void WarpToInitialPosition(u8 taskId) { DrawWholeMapView(); - SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gTasks[taskId].tInitialX, gTasks[taskId].tInitialY); + SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE, gTasks[taskId].tInitialX, gTasks[taskId].tInitialY); WarpIntoMap(); } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 107ee47ab..b9a8fe3a7 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -26,7 +26,6 @@ #include "constants/event_objects.h" #include "constants/field_effects.h" #include "constants/items.h" -#include "constants/maps.h" #include "constants/mauville_old_man.h" #include "constants/trainer_types.h" #include "constants/union_room.h" @@ -1141,7 +1140,7 @@ static const u8 sPlayerDirectionToCopyDirection[][4] = { static void ClearObjectEvent(struct ObjectEvent *objectEvent) { *objectEvent = (struct ObjectEvent){}; - objectEvent->localId = 0xFF; + objectEvent->localId = OBJ_EVENT_ID_PLAYER; objectEvent->mapNum = MAP_NUM(UNDEFINED); objectEvent->mapGroup = MAP_GROUP(UNDEFINED); objectEvent->movementActionId = MOVEMENT_ACTION_NONE; @@ -1916,7 +1915,7 @@ void AllowObjectAtPosTriggerGroundEffects(s16 x, s16 y) } } -void SetObjectPriority(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) +void SetObjectSubpriority(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) { u8 objectEventId; struct ObjectEvent *objectEvent; @@ -1931,7 +1930,7 @@ void SetObjectPriority(u8 localId, u8 mapNum, u8 mapGroup, u8 subpriority) } } -void ResetObjectPriority(u8 localId, u8 mapNum, u8 mapGroup) +void ResetObjectSubpriority(u8 localId, u8 mapNum, u8 mapGroup) { u8 objectEventId; struct ObjectEvent *objectEvent; diff --git a/src/faraway_island.c b/src/faraway_island.c index 3927d9ad5..9ddb66de5 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -7,7 +7,6 @@ #include "sprite.h" #include "constants/event_objects.h" #include "constants/field_effects.h" -#include "constants/maps.h" #include "constants/metatile_behaviors.h" static u8 GetValidMewMoveDirection(u8); diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 6d338c06d..8d6b564d2 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -32,7 +32,6 @@ #include "constants/event_objects.h" #include "constants/field_poison.h" #include "constants/map_types.h" -#include "constants/maps.h" #include "constants/songs.h" #include "constants/trainer_hill.h" @@ -691,7 +690,7 @@ static bool8 TryArrowWarp(struct MapPosition *position, u16 metatileBehavior, u8 { s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); - if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE && warpEventId != -1) + if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE && warpEventId != WARP_ID_NONE) { StoreInitialPlayerAvatarState(); SetupWarp(&gMapHeader, warpEventId, position); @@ -705,7 +704,7 @@ static bool8 TryStartWarpEventScript(struct MapPosition *position, u16 metatileB { s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); - if (warpEventId != -1 && IsWarpMetatileBehavior(metatileBehavior) == TRUE) + if (warpEventId != WARP_ID_NONE && IsWarpMetatileBehavior(metatileBehavior) == TRUE) { StoreInitialPlayerAvatarState(); SetupWarp(&gMapHeader, warpEventId, position); @@ -847,7 +846,7 @@ static bool8 TryDoorWarp(struct MapPosition *position, u16 metatileBehavior, u8 if (MetatileBehavior_IsWarpDoor(metatileBehavior) == TRUE) { warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); - if (warpEventId != -1 && IsWarpMetatileBehavior(metatileBehavior) == TRUE) + if (warpEventId != WARP_ID_NONE && IsWarpMetatileBehavior(metatileBehavior) == TRUE) { StoreInitialPlayerAvatarState(); SetupWarp(&gMapHeader, warpEventId, position); @@ -873,7 +872,7 @@ static s8 GetWarpEventAtPosition(struct MapHeader *mapHeader, u16 x, u16 y, u8 e return i; } } - return -1; + return WARP_ID_NONE; } static u8 *TryRunCoordEventScript(struct CoordEvent *coordEvent) diff --git a/src/field_door.c b/src/field_door.c index f53e83d7a..988ea615d 100644 --- a/src/field_door.c +++ b/src/field_door.c @@ -5,7 +5,6 @@ #include "fieldmap.h" #include "metatile_behavior.h" #include "task.h" -#include "constants/maps.h" #include "constants/songs.h" #include "constants/metatile_labels.h" diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 9e54823a6..6cf468b3e 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -26,7 +26,6 @@ #include "constants/event_object_movement.h" #include "constants/field_effects.h" #include "constants/items.h" -#include "constants/maps.h" #include "constants/moves.h" #include "constants/songs.h" #include "constants/trainer_types.h" diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 0cf5e4145..9155903af 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -35,7 +35,6 @@ #include "trainer_hill.h" #include "fldeff.h" -// This file's functions. static void Task_ExitNonAnimDoor(u8); static void Task_ExitNonDoor(u8); static void Task_DoContestHallWarp(u8); @@ -50,9 +49,9 @@ static void Task_EnableScriptAfterMusicFade(u8 taskId); // data[0] is used universally by tasks in this file as a state for switches #define tState data[0] -// const -static const u16 sFlashLevelPixelRadii[] = { 200, 72, 64, 56, 48, 40, 32, 24, 0 }; -const s32 gMaxFlashLevel = ARRAY_COUNT(sFlashLevelPixelRadii) - 1; +// Smaller flash level -> larger flash radius +static const u16 sFlashLevelToRadius[] = { 200, 72, 64, 56, 48, 40, 32, 24, 0 }; +const s32 gMaxFlashLevel = ARRAY_COUNT(sFlashLevelToRadius) - 1; const struct ScanlineEffectParams sFlashEffectParams = { @@ -971,14 +970,14 @@ static u8 StartUpdateOrbFlashEffect(s32 centerX, s32 centerY, s32 initialFlashRa #undef tFlashRadiusDelta #undef tClearScanlineEffect -// A higher flashLevel value is a smaller flash radius (more darkness). 0 is full brightness -void AnimateFlash(u8 flashLevel) +// A higher flash level is a smaller flash radius (more darkness). 0 is full brightness +void AnimateFlash(u8 newFlashLevel) { - u8 curFlashLevel = Overworld_GetFlashLevel(); + u8 curFlashLevel = GetFlashLevel(); bool8 fullBrightness = FALSE; - if (!flashLevel) + if (newFlashLevel == 0) fullBrightness = TRUE; - StartUpdateFlashLevelEffect(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelPixelRadii[curFlashLevel], sFlashLevelPixelRadii[flashLevel], fullBrightness, 1); + StartUpdateFlashLevelEffect(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelToRadius[curFlashLevel], sFlashLevelToRadius[newFlashLevel], fullBrightness, 1); StartWaitForFlashUpdate(); ScriptContext2_Enable(); } @@ -987,7 +986,7 @@ void WriteFlashScanlineEffectBuffer(u8 flashLevel) { if (flashLevel) { - SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelPixelRadii[flashLevel]); + SetFlashScanlineEffectWindowBoundaries(&gScanlineEffectRegBuffers[0][0], DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, sFlashLevelToRadius[flashLevel]); CpuFastSet(&gScanlineEffectRegBuffers[0], &gScanlineEffectRegBuffers[1], 480); } } diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 39e5d6698..b7c93e510 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -349,7 +349,7 @@ void LookThroughPorthole(void) FlagSet(FLAG_SYS_CRUISE_MODE); FlagSet(FLAG_DONT_TRANSITION_MUSIC); FlagSet(FLAG_HIDE_MAP_NAME_POPUP); - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); TrySetPortholeWarpDestination(); DoPortholeWarp(); } diff --git a/src/field_specials.c b/src/field_specials.c index ef569ca00..96eb949e5 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -55,7 +55,6 @@ #include "constants/items.h" #include "constants/heal_locations.h" #include "constants/map_types.h" -#include "constants/maps.h" #include "constants/mystery_gift.h" #include "constants/script_menu.h" #include "constants/slot_machine.h" @@ -960,13 +959,9 @@ u8 GetBattleOutcome(void) void CableCarWarp(void) { if (gSpecialVar_0x8004 != 0) - { - SetWarpDestination(MAP_GROUP(ROUTE112_CABLE_CAR_STATION), MAP_NUM(ROUTE112_CABLE_CAR_STATION), -1, 6, 4); - } + SetWarpDestination(MAP_GROUP(ROUTE112_CABLE_CAR_STATION), MAP_NUM(ROUTE112_CABLE_CAR_STATION), WARP_ID_NONE, 6, 4); else - { - SetWarpDestination(MAP_GROUP(MT_CHIMNEY_CABLE_CAR_STATION), MAP_NUM(MT_CHIMNEY_CABLE_CAR_STATION), -1, 6, 4); - } + SetWarpDestination(MAP_GROUP(MT_CHIMNEY_CABLE_CAR_STATION), MAP_NUM(MT_CHIMNEY_CABLE_CAR_STATION), WARP_ID_NONE, 6, 4); } void SetHiddenItemFlag(void) @@ -1335,15 +1330,40 @@ void BufferEReaderTrainerName(void) u16 GetSlotMachineId(void) { - static const u8 sSlotMachineRandomSeeds[] = {12, 2, 4, 5, 1, 8, 7, 11, 3, 10, 9, 6}; - static const u8 sSlotMachineIds[] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5}; - static const u8 sSlotMachineServiceDayIds[] = {3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5}; + static const u8 sSlotMachineRandomSeeds[SLOT_MACHINE_COUNT] = {12, 2, 4, 5, 1, 8, 7, 11, 3, 10, 9, 6}; + static const u8 sSlotMachineIds[SLOT_MACHINE_COUNT] = { + SLOT_MACHINE_UNLUCKIEST, + SLOT_MACHINE_UNLUCKIER, + SLOT_MACHINE_UNLUCKIER, + SLOT_MACHINE_UNLUCKY, + SLOT_MACHINE_UNLUCKY, + SLOT_MACHINE_UNLUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIEST + }; + static const u8 sSlotMachineServiceDayIds[SLOT_MACHINE_COUNT] = { + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKY, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIER, + SLOT_MACHINE_LUCKIEST, + SLOT_MACHINE_LUCKIEST + }; u32 rnd = gSaveBlock1Ptr->dewfordTrends[0].trendiness + gSaveBlock1Ptr->dewfordTrends[0].rand + sSlotMachineRandomSeeds[gSpecialVar_0x8004]; - if (GetPriceReduction(POKENEWS_GAME_CORNER)) - { + if (IsPokeNewsActive(POKENEWS_GAME_CORNER)) return sSlotMachineServiceDayIds[rnd % SLOT_MACHINE_COUNT]; - } + return sSlotMachineIds[rnd % SLOT_MACHINE_COUNT]; } @@ -1550,17 +1570,13 @@ bool8 FoundBlackGlasses(void) void SetRoute119Weather(void) { if (IsMapTypeOutdoors(GetLastUsedWarpMapType()) != TRUE) - { - SetSav1Weather(WEATHER_ROUTE119_CYCLE); - } + SetSavedWeather(WEATHER_ROUTE119_CYCLE); } void SetRoute123Weather(void) { if (IsMapTypeOutdoors(GetLastUsedWarpMapType()) != TRUE) - { - SetSav1Weather(WEATHER_ROUTE123_CYCLE); - } + SetSavedWeather(WEATHER_ROUTE123_CYCLE); } u8 GetLeadMonIndex(void) @@ -3029,6 +3045,8 @@ void CloseFrontierExchangeCornerItemIconWindow(void) RemoveWindow(sFrontierExchangeCorner_ItemIconWindowId); } +#define TAG_ITEM_ICON 5500 + static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection) { #include "data/battle_frontier/battle_frontier_exchange_corner.h" @@ -3046,9 +3064,9 @@ static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection) } else { - FreeSpriteTilesByTag(5500); - FreeSpritePaletteByTag(5500); - sScrollableMultichoice_ItemSpriteId = AddDecorationIconObject(sFrontierExchangeCorner_Decor1[selection], 33, 88, 0, 5500, 5500); + FreeSpriteTilesByTag(TAG_ITEM_ICON); + FreeSpritePaletteByTag(TAG_ITEM_ICON); + sScrollableMultichoice_ItemSpriteId = AddDecorationIconObject(sFrontierExchangeCorner_Decor1[selection], 33, 88, 0, TAG_ITEM_ICON, TAG_ITEM_ICON); } break; case SCROLL_MULTI_BF_EXCHANGE_CORNER_DECOR_VENDOR_2: @@ -3059,9 +3077,9 @@ static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection) } else { - FreeSpriteTilesByTag(5500); - FreeSpritePaletteByTag(5500); - sScrollableMultichoice_ItemSpriteId = AddDecorationIconObject(sFrontierExchangeCorner_Decor2[selection], 33, 88, 0, 5500, 5500); + FreeSpriteTilesByTag(TAG_ITEM_ICON); + FreeSpritePaletteByTag(TAG_ITEM_ICON); + sScrollableMultichoice_ItemSpriteId = AddDecorationIconObject(sFrontierExchangeCorner_Decor2[selection], 33, 88, 0, TAG_ITEM_ICON, TAG_ITEM_ICON); } break; case SCROLL_MULTI_BF_EXCHANGE_CORNER_VITAMIN_VENDOR: @@ -3078,9 +3096,9 @@ static void FillFrontierExchangeCornerWindowAndItemIcon(u16 menu, u16 selection) static void ShowFrontierExchangeCornerItemIcon(u16 item) { - FreeSpriteTilesByTag(5500); - FreeSpritePaletteByTag(5500); - sScrollableMultichoice_ItemSpriteId = AddItemIconSprite(5500, 5500, item); + FreeSpriteTilesByTag(TAG_ITEM_ICON); + FreeSpritePaletteByTag(TAG_ITEM_ICON); + sScrollableMultichoice_ItemSpriteId = AddItemIconSprite(TAG_ITEM_ICON, TAG_ITEM_ICON, item); if (sScrollableMultichoice_ItemSpriteId != MAX_SPRITES) { @@ -3416,7 +3434,7 @@ static void ChangeDeoxysRockLevel(u8 rockLevel) gFieldEffectArguments[5] = 5; FieldEffectStart(FLDEFF_MOVE_DEOXYS_ROCK); - Overworld_SetObjEventTemplateCoords(1, sDeoxysRockCoords[rockLevel][0], sDeoxysRockCoords[rockLevel][1]); + SetObjEventTemplateCoords(LOCALID_BIRTH_ISLAND_EXTERIOR_ROCK, sDeoxysRockCoords[rockLevel][0], sDeoxysRockCoords[rockLevel][1]); } static void WaitForDeoxysRockMovement(u8 taskId) diff --git a/src/field_tasks.c b/src/field_tasks.c index 187270f7a..760d85369 100644 --- a/src/field_tasks.c +++ b/src/field_tasks.c @@ -21,20 +21,40 @@ #include "constants/songs.h" #include "constants/metatile_labels.h" +/* This file handles some persistent tasks that run in the overworld. + * - Task_RunTimeBasedEvents: Periodically updates local time and RTC events. Also triggers ambient cries. + * - Task_MuddySlope: Handles the metatile animation when the player steps on muddy slopes. + * - Task_RunPerStepCallback: Calls one of the functions in sPerStepCallbacks, listed below... + * . DummyPerStepCallback: Default, does nothing + * . AshGrassPerStepCallback: Removes the ash from ash-covered grass that the player steps on. + * . FortreeBridgePerStepCallback: Depresses Fortree log bridges that the player steps on. + * . PacifidlogBridgePerStepCallback: Submerges Pacifidlog log bridges that the player steps on. + * . SootopolisGymIcePerStepCallback: Cracks/breaks ice in Sootopolis Gym that the player steps on. + * . EndTruckSequence: Sets the moving truck boxes to their final position when the truck sequence ends. + * . SecretBasePerStepCallback: Records the decorations in a friend's secret base that the player steps on. + * . CrackedFloorPerStepCallback: Breaks cracked floors that the player steps on. + * + * NOTE: "PerStep" is perhaps misleading. One function in sPerStepCallbacks is called + * every frame while in the overworld by Task_RunPerStepCallback regardless of + * whether or not steps are being taken. However, nearly all of the functions in + * the table check if the player has moved from their previous position before + * doing anything else. + */ + struct PacifidlogMetatileOffsets { s8 x; s8 y; - u16 tileId; + u16 metatileId; }; -static void DummyPerStepCallback(u8 taskId); -static void AshGrassPerStepCallback(u8 taskId); -static void FortreeBridgePerStepCallback(u8 taskId); -static void PacifidlogBridgePerStepCallback(u8 taskId); -static void SootopolisGymIcePerStepCallback(u8 taskId); -static void CrackedFloorPerStepCallback(u8 taskId); -static void Task_MuddySlope(u8 taskId); +static void DummyPerStepCallback(u8); +static void AshGrassPerStepCallback(u8); +static void FortreeBridgePerStepCallback(u8); +static void PacifidlogBridgePerStepCallback(u8); +static void SootopolisGymIcePerStepCallback(u8); +static void CrackedFloorPerStepCallback(u8); +static void Task_MuddySlope(u8); static const TaskFunc sPerStepCallbacks[] = { @@ -48,29 +68,35 @@ static const TaskFunc sPerStepCallbacks[] = [STEP_CB_CRACKED_FLOOR] = CrackedFloorPerStepCallback }; -// they are in pairs but declared as 1D array +// Each array has 4 pairs of data, each pair representing two metatiles of a log and their relative position. +// The 4 pairs are for: +// 0: If the player is standing on the top of a vertical log +// 1: If the player is standing on the bottom of a vertical log +// 2: If the player is standing on the left of a horizontal log +// 3: If the player is standing on the right of a horizontal log +// i.e. the element with an offset of 0,0 is the one the player is standing on. static const struct PacifidlogMetatileOffsets sHalfSubmergedBridgeMetatileOffsets[] = { - { 0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Vertical0}, {0, 1, METATILE_Pacifidlog_HalfSubmergedLogs_Vertical1}, - { 0, -1, METATILE_Pacifidlog_HalfSubmergedLogs_Vertical0}, {0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Vertical1}, - { 0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Horizontal0}, {1, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Horizontal1}, - {-1, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Horizontal0}, {0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_Horizontal1} + { 0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_VerticalTop}, {0, 1, METATILE_Pacifidlog_HalfSubmergedLogs_VerticalBottom}, + { 0, -1, METATILE_Pacifidlog_HalfSubmergedLogs_VerticalTop}, {0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_VerticalBottom}, + { 0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_HorizontalLeft}, {1, 0, METATILE_Pacifidlog_HalfSubmergedLogs_HorizontalRight}, + {-1, 0, METATILE_Pacifidlog_HalfSubmergedLogs_HorizontalLeft}, {0, 0, METATILE_Pacifidlog_HalfSubmergedLogs_HorizontalRight} }; static const struct PacifidlogMetatileOffsets sFullySubmergedBridgeMetatileOffsets[] = { - { 0, 0, METATILE_Pacifidlog_SubmergedLogs_Vertical0}, {0, 1, METATILE_Pacifidlog_SubmergedLogs_Vertical1}, - { 0, -1, METATILE_Pacifidlog_SubmergedLogs_Vertical0}, {0, 0, METATILE_Pacifidlog_SubmergedLogs_Vertical1}, - { 0, 0, METATILE_Pacifidlog_SubmergedLogs_Horizontal0}, {1, 0, METATILE_Pacifidlog_SubmergedLogs_Horizontal1}, - {-1, 0, METATILE_Pacifidlog_SubmergedLogs_Horizontal0}, {0, 0, METATILE_Pacifidlog_SubmergedLogs_Horizontal1} + { 0, 0, METATILE_Pacifidlog_SubmergedLogs_VerticalTop}, {0, 1, METATILE_Pacifidlog_SubmergedLogs_VerticalBottom}, + { 0, -1, METATILE_Pacifidlog_SubmergedLogs_VerticalTop}, {0, 0, METATILE_Pacifidlog_SubmergedLogs_VerticalBottom}, + { 0, 0, METATILE_Pacifidlog_SubmergedLogs_HorizontalLeft}, {1, 0, METATILE_Pacifidlog_SubmergedLogs_HorizontalRight}, + {-1, 0, METATILE_Pacifidlog_SubmergedLogs_HorizontalLeft}, {0, 0, METATILE_Pacifidlog_SubmergedLogs_HorizontalRight} }; static const struct PacifidlogMetatileOffsets sFloatingBridgeMetatileOffsets[] = { - { 0, 0, METATILE_Pacifidlog_FloatingLogs_Vertical0}, {0, 1, METATILE_Pacifidlog_FloatingLogs_Vertical1}, - { 0, -1, METATILE_Pacifidlog_FloatingLogs_Vertical0}, {0, 0, METATILE_Pacifidlog_FloatingLogs_Vertical1}, - { 0, 0, METATILE_Pacifidlog_FloatingLogs_Horizontal0}, {1, 0, METATILE_Pacifidlog_FloatingLogs_Horizontal1}, - {-1, 0, METATILE_Pacifidlog_FloatingLogs_Horizontal0}, {0, 0, METATILE_Pacifidlog_FloatingLogs_Horizontal1} + { 0, 0, METATILE_Pacifidlog_FloatingLogs_VerticalTop}, {0, 1, METATILE_Pacifidlog_FloatingLogs_VerticalBottom}, + { 0, -1, METATILE_Pacifidlog_FloatingLogs_VerticalTop}, {0, 0, METATILE_Pacifidlog_FloatingLogs_VerticalBottom}, + { 0, 0, METATILE_Pacifidlog_FloatingLogs_HorizontalLeft}, {1, 0, METATILE_Pacifidlog_FloatingLogs_HorizontalRight}, + {-1, 0, METATILE_Pacifidlog_FloatingLogs_HorizontalLeft}, {0, 0, METATILE_Pacifidlog_FloatingLogs_HorizontalRight} }; // Each element corresponds to a y coordinate row in the sootopolis gym 1F map. @@ -104,16 +130,11 @@ static const u16 sSootopolisGymIceRowVars[] = 0 }; -static const u16 sMuddySlopeMetatiles[] = { - METATILE_General_MuddySlope_Frame0, - METATILE_General_MuddySlope_Frame3, - METATILE_General_MuddySlope_Frame2, - METATILE_General_MuddySlope_Frame1 -}; +#define tCallbackId data[0] static void Task_RunPerStepCallback(u8 taskId) { - int idx = gTasks[taskId].data[0]; + int idx = gTasks[taskId].tCallbackId; sPerStepCallbacks[idx](taskId); } @@ -121,23 +142,23 @@ static void Task_RunPerStepCallback(u8 taskId) #define tAmbientCryState data[1] #define tAmbientCryDelay data[2] +#define TIME_UPDATE_INTERVAL (1 << 12) + static void RunTimeBasedEvents(s16 *data) { switch (tState) { - case 0: - if (gMain.vblankCounter1 & 0x1000) - { - DoTimeBasedEvents(); - tState++; - } - break; - case 1: - if (!(gMain.vblankCounter1 & 0x1000)) - { - tState--; - } - break; + case 0: + if (gMain.vblankCounter1 & TIME_UPDATE_INTERVAL) + { + DoTimeBasedEvents(); + tState++; + } + break; + case 1: + if (!(gMain.vblankCounter1 & TIME_UPDATE_INTERVAL)) + tState--; + break; } } @@ -153,22 +174,20 @@ static void Task_RunTimeBasedEvents(u8 taskId) } #undef tState -#undef tAmbientCryState -#undef tAmbientCryDelay void SetUpFieldTasks(void) { if (!FuncIsActiveTask(Task_RunPerStepCallback)) { - u8 taskId = CreateTask(Task_RunPerStepCallback, 0x50); - gTasks[taskId].data[0] = 0; + u8 taskId = CreateTask(Task_RunPerStepCallback, 80); + gTasks[taskId].tCallbackId = STEP_CB_DUMMY; } if (!FuncIsActiveTask(Task_MuddySlope)) - CreateTask(Task_MuddySlope, 0x50); + CreateTask(Task_MuddySlope, 80); if (!FuncIsActiveTask(Task_RunTimeBasedEvents)) - CreateTask(Task_RunTimeBasedEvents, 0x50); + CreateTask(Task_RunTimeBasedEvents, 80); } void ActivatePerStepCallback(u8 callbackId) @@ -179,17 +198,13 @@ void ActivatePerStepCallback(u8 callbackId) s32 i; s16 *data = gTasks[taskId].data; - for (i = 0; i < 16; i++) + for (i = 0; i < NUM_TASK_DATA; i++) data[i] = 0; if (callbackId >= ARRAY_COUNT(sPerStepCallbacks)) - { - data[0] = 0; - } + tCallbackId = STEP_CB_DUMMY; else - { - data[0] = callbackId; - } + tCallbackId = callbackId; } } @@ -200,18 +215,20 @@ void ResetFieldTasksArgs(void) taskId = FindTaskIdByFunc(Task_RunPerStepCallback); if (taskId != TASK_NONE) - { data = gTasks[taskId].data; - } + taskId = FindTaskIdByFunc(Task_RunTimeBasedEvents); if (taskId != TASK_NONE) { data = gTasks[taskId].data; - data[1] = 0; - data[2] = 0; + tAmbientCryState = 0; + tAmbientCryDelay = 0; } } +#undef tAmbientCryState +#undef tAmbientCryDelay + static void DummyPerStepCallback(u8 taskId) { @@ -219,282 +236,377 @@ static void DummyPerStepCallback(u8 taskId) static const struct PacifidlogMetatileOffsets *GetPacifidlogBridgeMetatileOffsets(const struct PacifidlogMetatileOffsets *offsets, u16 metatileBehavior) { - if (MetatileBehavior_IsPacifidlogVerticalLog1(metatileBehavior)) + if (MetatileBehavior_IsPacifidlogVerticalLogTop(metatileBehavior)) return &offsets[0 * 2]; - else if (MetatileBehavior_IsPacifidlogVerticalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogVerticalLogBottom(metatileBehavior)) return &offsets[1 * 2]; - else if (MetatileBehavior_IsPacifidlogHorizontalLog1(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogLeft(metatileBehavior)) return &offsets[2 * 2]; - else if (MetatileBehavior_IsPacifidlogHorizontalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogRight(metatileBehavior)) return &offsets[3 * 2]; else return NULL; } -static void SetPacifidlogBridgeMetatiles(const struct PacifidlogMetatileOffsets *offsets, s16 x, s16 y, bool32 redrawMap) +static void TrySetPacifidlogBridgeMetatiles(const struct PacifidlogMetatileOffsets *offsets, s16 x, s16 y, bool32 redrawMap) { offsets = GetPacifidlogBridgeMetatileOffsets(offsets, MapGridGetMetatileBehaviorAt(x, y)); + + // If offsets is NULL, position is not a log (don't set it) if (offsets) { - MapGridSetMetatileIdAt(x + offsets[0].x, y + offsets[0].y, offsets[0].tileId); + // Set both metatiles of the log + MapGridSetMetatileIdAt(x + offsets[0].x, y + offsets[0].y, offsets[0].metatileId); if (redrawMap) CurrentMapDrawMetatileAt(x + offsets[0].x, y + offsets[0].y); - MapGridSetMetatileIdAt(x + offsets[1].x, y + offsets[1].y, offsets[1].tileId); + MapGridSetMetatileIdAt(x + offsets[1].x, y + offsets[1].y, offsets[1].metatileId); if (redrawMap) CurrentMapDrawMetatileAt(x + offsets[1].x, y + offsets[1].y); } } -static void UpdateHalfSubmergedBridgeMetatiles(s16 x, s16 y, bool32 redrawMap) +static void TrySetLogBridgeHalfSubmerged(s16 x, s16 y, bool32 redrawMap) { - SetPacifidlogBridgeMetatiles(sHalfSubmergedBridgeMetatileOffsets, x, y, redrawMap); + TrySetPacifidlogBridgeMetatiles(sHalfSubmergedBridgeMetatileOffsets, x, y, redrawMap); } -static void UpdateFullySubmergedBridgeMetatiles(s16 x, s16 y, bool32 redrawMap) +static void TrySetLogBridgeFullySubmerged(s16 x, s16 y, bool32 redrawMap) { - SetPacifidlogBridgeMetatiles(sFullySubmergedBridgeMetatileOffsets, x, y, redrawMap); + TrySetPacifidlogBridgeMetatiles(sFullySubmergedBridgeMetatileOffsets, x, y, redrawMap); } -static void UpdateFloatingBridgeMetatiles(s16 x, s16 y, bool32 redrawMap) +static void TrySetLogBridgeFloating(s16 x, s16 y, bool32 redrawMap) { - SetPacifidlogBridgeMetatiles(sFloatingBridgeMetatileOffsets, x, y, redrawMap); + TrySetPacifidlogBridgeMetatiles(sFloatingBridgeMetatileOffsets, x, y, redrawMap); } -static bool32 StandingOnNewPacifidlogBridge(s16 x1, s16 y1, s16 x2, s16 y2) +// Returns FALSE if player has moved from one end of a log to the other (log should remain submerged). +// Otherwise it returns TRUE. +static bool32 ShouldRaisePacifidlogLogs(s16 newX, s16 newY, s16 oldX, s16 oldY) { - u16 metatileBehavior = MapGridGetMetatileBehaviorAt(x2, y2); + u16 oldBehavior = MapGridGetMetatileBehaviorAt(oldX, oldY); - if (MetatileBehavior_IsPacifidlogVerticalLog1(metatileBehavior)) + if (MetatileBehavior_IsPacifidlogVerticalLogTop(oldBehavior)) { - if (y1 > y2) + // Still on same one if moved from top to bottom + if (newY > oldY) return FALSE; } - else if (MetatileBehavior_IsPacifidlogVerticalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogVerticalLogBottom(oldBehavior)) { - if (y1 < y2) + // Still on same one if moved from bottom to top + if (newY < oldY) return FALSE; } - else if (MetatileBehavior_IsPacifidlogHorizontalLog1(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogLeft(oldBehavior)) { - if (x1 > x2) + // Still on same one if moved from left to right + if (newX > oldX) return FALSE; } - else if (MetatileBehavior_IsPacifidlogHorizontalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogRight(oldBehavior)) { - if (x1 < x2) + // Still on same one if moved from right to left + if (newX < oldX) return FALSE; } + + // Player is either on a different log or no log at all return TRUE; } -static bool32 StandingOnSamePacifidlogBridge(s16 x1, s16 y1, s16 x2, s16 y2) +// Returns FALSE if player has moved from one end of a log to the other (log should remain submerged). +// Otherwise it returns TRUE. +// This is the effectively the same as ShouldRaisePacifidlogLogs, as it swaps both the conditions and which position's behavior to check. +// In effect the previous function asks "was the player's previous position not the other end of a log they're standing on?" +// while this function asks "is the player's current position not the other end of a log they were previously standing on?" +// and with the same positions both questions always have the same answer. +static bool32 ShouldSinkPacifidlogLogs(s16 newX, s16 newY, s16 oldX, s16 oldY) { - u16 metatileBehavior = MapGridGetMetatileBehaviorAt(x1, y1); + u16 newBehavior = MapGridGetMetatileBehaviorAt(newX, newY); - if (MetatileBehavior_IsPacifidlogVerticalLog1(metatileBehavior)) + if (MetatileBehavior_IsPacifidlogVerticalLogTop(newBehavior)) { - if (y1 < y2) + // Still on same one if moved from bottom to top + if (newY < oldY) return FALSE; } - else if (MetatileBehavior_IsPacifidlogVerticalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogVerticalLogBottom(newBehavior)) { - if (y1 > y2) + // Still on same one if moved from top to bottom + if (newY > oldY) return FALSE; } - else if (MetatileBehavior_IsPacifidlogHorizontalLog1(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogLeft(newBehavior)) { - if (x1 < x2) + // Still on same one if moved from right to left + if (newX < oldX) return FALSE; } - else if (MetatileBehavior_IsPacifidlogHorizontalLog2(metatileBehavior)) + else if (MetatileBehavior_IsPacifidlogHorizontalLogRight(newBehavior)) { - if (x1 > x2) + // Still on same one if moved from left to right + if (newX > oldX) return FALSE; } return TRUE; } +#define tState data[1] +#define tPrevX data[2] +#define tPrevY data[3] +#define tToRaiseX data[4] +#define tToRaiseY data[5] +#define tDelay data[6] + static void PacifidlogBridgePerStepCallback(u8 taskId) { s16 *data; s16 x, y; data = gTasks[taskId].data; PlayerGetDestCoords(&x, &y); - switch (data[1]) + switch (tState) { - case 0: - data[2] = x; - data[3] = y; - UpdateFullySubmergedBridgeMetatiles(x, y, TRUE); - data[1] = 1; - break; - case 1: - if (x != data[2] || y != data[3]) - { - if (StandingOnNewPacifidlogBridge(x, y, data[2], data[3])) - { - UpdateHalfSubmergedBridgeMetatiles(data[2], data[3], TRUE); - UpdateFloatingBridgeMetatiles(data[2], data[3], FALSE); - data[4] = data[2]; - data[5] = data[3]; - data[1] = 2; - data[6] = 8; - } - else - { - data[4] = -1; - data[5] = -1; - } + case 0: + tPrevX = x; + tPrevY = y; + + // If player is already standing on a log when the callback + // is set then immediately set it to submerged + TrySetLogBridgeFullySubmerged(x, y, TRUE); + tState = 1; + break; + case 1: + // Skip if player hasn't moved + if (x == tPrevX && y == tPrevY) + return; + + if (ShouldRaisePacifidlogLogs(x, y, tPrevX, tPrevY)) + { + // Player's previous position is not the other end of a log + // they're standing on, try and set it half-submerged (rising to surface). + // The floating metatile is queued up by setting it but not drawing it, + // but this is pointless as state 2 will handle it in full anyway. + TrySetLogBridgeHalfSubmerged(tPrevX, tPrevY, TRUE); + TrySetLogBridgeFloating(tPrevX, tPrevY, FALSE); + tToRaiseX = tPrevX; + tToRaiseY = tPrevY; + tState = 2; + tDelay = 8; + } + else + { + // Player has moved but is still on the same log bridge section. + // Keep it submerged. + tToRaiseX = -1; + tToRaiseY = -1; + } - if (StandingOnSamePacifidlogBridge(x, y, data[2], data[3])) - { - UpdateHalfSubmergedBridgeMetatiles(x, y, TRUE); - data[1] = 2; - data[6] = 8; - } + if (ShouldSinkPacifidlogLogs(x, y, tPrevX, tPrevY)) + { + // Player's current position is not the other end of a log + // they were previously standing on, try and set it half-submerged (sinking) + TrySetLogBridgeHalfSubmerged(x, y, TRUE); + tState = 2; + tDelay = 8; + } - data[2] = x; - data[3] = y; - if (MetatileBehavior_IsPacifidlogLog(MapGridGetMetatileBehaviorAt(x, y))) - PlaySE(SE_PUDDLE); - } - break; - case 2: - if ((--data[6]) == 0) - { - UpdateFullySubmergedBridgeMetatiles(x, y, TRUE); - if (data[4] != -1 && data[5] != -1) - UpdateFloatingBridgeMetatiles(data[4], data[5], TRUE); + tPrevX = x; + tPrevY = y; - data[1] = 1; - } - break; + // If player's new position is a log play the puddle SE + if (MetatileBehavior_IsPacifidlogLog(MapGridGetMetatileBehaviorAt(x, y))) + PlaySE(SE_PUDDLE); + break; + case 2: + if (--tDelay == 0) + { + // If player's current position is a log submerge it fully. + TrySetLogBridgeFullySubmerged(x, y, TRUE); + + // Player's previous position is not the other end of a log + // they're standing on, try to raise their previous position. + if (tToRaiseX != -1 && tToRaiseY != -1) + TrySetLogBridgeFloating(tToRaiseX, tToRaiseY, TRUE); + + tState = 1; + } + break; } } -static void SetLoweredForetreeBridgeMetatile(s16 x, s16 y) +#undef tState +#undef tPrevX +#undef tPrevY +#undef tToRaiseX +#undef tToRaiseY +#undef tDelay + +static void TryLowerFortreeBridge(s16 x, s16 y) { u8 z = PlayerGetZCoord(); if (!(z & 1)) { switch (MapGridGetMetatileIdAt(x, y)) { - case METATILE_Fortree_BridgeOverGrass_Raised: - MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverGrass_Lowered); - break; - case METATILE_Fortree_BridgeOverTrees_Raised: - MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverTrees_Lowered); - break; + case METATILE_Fortree_BridgeOverGrass_Raised: + MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverGrass_Lowered); + break; + case METATILE_Fortree_BridgeOverTrees_Raised: + MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverTrees_Lowered); + break; } } } -static void SetNormalFortreeBridgeMetatile(s16 x, s16 y) +static void TryRaiseFortreeBridge(s16 x, s16 y) { u8 z = PlayerGetZCoord(); if (!(z & 1)) { switch (MapGridGetMetatileIdAt(x, y)) { - case METATILE_Fortree_BridgeOverGrass_Lowered: - MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverGrass_Raised); - break; - case METATILE_Fortree_BridgeOverTrees_Lowered: - MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverTrees_Raised); - break; + case METATILE_Fortree_BridgeOverGrass_Lowered: + MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverGrass_Raised); + break; + case METATILE_Fortree_BridgeOverTrees_Lowered: + MapGridSetMetatileIdAt(x, y, METATILE_Fortree_BridgeOverTrees_Raised); + break; } } } +#define tState data[1] +#define tPrevX data[2] +#define tPrevY data[3] +#define tOldBridgeX data[4] +#define tOldBridgeY data[5] +#define tBounceTime data[6] + static void FortreeBridgePerStepCallback(u8 taskId) { bool8 isFortreeBridgeCur; bool8 isFortreeBridgePrev; - u8 z, flag; - s16 x, y, x2, y2; + u8 z, onBridgeElevation; + s16 x, y, prevX, prevY; s16 *data = gTasks[taskId].data; PlayerGetDestCoords(&x, &y); - switch (data[1]) + switch (tState) { - default: - break; - case 0: - data[2] = x; - data[3] = y; - if (MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(x, y))) - { - SetLoweredForetreeBridgeMetatile(x, y); - CurrentMapDrawMetatileAt(x, y); - } - data[1] = 1; + default: + break; + case 0: + tPrevX = x; + tPrevY = y; + + // If player is already on bridge when callback is set then lower it immediately. + if (MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(x, y))) + { + TryLowerFortreeBridge(x, y); + CurrentMapDrawMetatileAt(x, y); + } + tState = 1; + break; + case 1: + prevX = tPrevX; + prevY = tPrevY; + + // Skip if player hasn't moved + if (x == prevX && y == prevY) break; - case 1: - x2 = data[2]; - y2 = data[3]; - if (x == x2 && y == y2) - break; - - isFortreeBridgeCur = MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(x, y)); - isFortreeBridgePrev = MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(x2, y2)); - z = PlayerGetZCoord(); - flag = 0; - if ((u8)(z & 1) == 0) - flag = 1; - - if (flag && (isFortreeBridgeCur == 1 || isFortreeBridgePrev == 1)) - PlaySE(SE_BRIDGE_WALK); - - if (isFortreeBridgePrev) - { - SetNormalFortreeBridgeMetatile(x2, y2); - CurrentMapDrawMetatileAt(x2, y2); - SetLoweredForetreeBridgeMetatile(x, y); - CurrentMapDrawMetatileAt(x, y); - } - data[4] = x2; - data[5] = y2; - data[2] = x; - data[3] = y; - if (!isFortreeBridgePrev) - break; + isFortreeBridgeCur = MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(x, y)); + isFortreeBridgePrev = MetatileBehavior_IsFortreeBridge(MapGridGetMetatileBehaviorAt(prevX, prevY)); + + // Make sure player isn't below bridge + z = PlayerGetZCoord(); + onBridgeElevation = FALSE; + if ((u8)(z & 1) == 0) + onBridgeElevation = TRUE; + + if (onBridgeElevation && (isFortreeBridgeCur == TRUE || isFortreeBridgePrev == TRUE)) + PlaySE(SE_BRIDGE_WALK); + + // Because this doesn't check for isFortreeBridgeCur, bridge sections aren't + // lowered when first stepping onto them from anything other than another bridge. + #ifdef BUGFIX + if (isFortreeBridgePrev || isFortreeBridgeCur) + #else + if (isFortreeBridgePrev) + #endif + { + // Raise old bridge + TryRaiseFortreeBridge(prevX, prevY); + CurrentMapDrawMetatileAt(prevX, prevY); + + // Lower new bridge + TryLowerFortreeBridge(x, y); + CurrentMapDrawMetatileAt(x, y); + } + + // These should really be set below the !isFortreeBridgePrev conditional, + // but it doesn't matter because it's not read until case 2 anyway. + tOldBridgeX = prevX; + tOldBridgeY = prevY; + + tPrevX = x; + tPrevY = y; + if (!isFortreeBridgePrev) + break; - data[6] = 16; - data[1] = 2; - // fallthrough + tBounceTime = 16; + tState = 2; + // fallthrough + case 2: + tBounceTime--; + prevX = tOldBridgeX; + prevY = tOldBridgeY; + switch (tBounceTime % 7) + { + case 0: + CurrentMapDrawMetatileAt(prevX, prevY); + case 1: case 2: - data[6]--; - x2 = data[4]; - y2 = data[5]; - switch (data[6] % 7) - { - case 0: - CurrentMapDrawMetatileAt(x2, y2); - case 1: - case 2: - case 3: - break; - case 4: - SetLoweredForetreeBridgeMetatile(x2, y2); - CurrentMapDrawMetatileAt(x2, y2); - SetNormalFortreeBridgeMetatile(x2, y2); - case 5: - case 6: - case 7: - break; - } - if (data[6] == 0) - { - data[1] = 1; - } + case 3: break; + case 4: + // Bounce bridge section that player has stepped off of + TryLowerFortreeBridge(prevX, prevY); + CurrentMapDrawMetatileAt(prevX, prevY); + TryRaiseFortreeBridge(prevX, prevY); + case 5: + case 6: + case 7: // Not possible with % 7 + break; + } + if (tBounceTime == 0) + tState = 1; + break; } } +#undef tState +#undef tPrevX +#undef tPrevY +#undef tOldBridgeX +#undef tOldBridgeY +#undef tBounceTime + +// Boundaries of the ice puzzle in Sootopolis Gym +#define ICE_PUZZLE_L 3 +#define ICE_PUZZLE_R 13 +#define ICE_PUZZLE_T 6 +#define ICE_PUZZLE_B 19 + +#define ICE_PUZZLE_WIDTH (ICE_PUZZLE_R - ICE_PUZZLE_L + 1) +#define ICE_PUZZLE_HEIGHT (ICE_PUZZLE_B - ICE_PUZZLE_T + 1) + static bool32 CoordInIcePuzzleRegion(s16 x, s16 y) { - if ((u16)(x - 3) < 11 && (u16)(y - 6) < 14 && sSootopolisGymIceRowVars[y]) + if ((u16)(x - ICE_PUZZLE_L) < ICE_PUZZLE_WIDTH + && (u16)(y - ICE_PUZZLE_T) < ICE_PUZZLE_HEIGHT + && sSootopolisGymIceRowVars[y]) return TRUE; else return FALSE; @@ -503,17 +615,17 @@ static bool32 CoordInIcePuzzleRegion(s16 x, s16 y) static void MarkIcePuzzleCoordVisited(s16 x, s16 y) { if (CoordInIcePuzzleRegion(x, y)) - *GetVarPointer(sSootopolisGymIceRowVars[y]) |= (1 << (x - 3)); + *GetVarPointer(sSootopolisGymIceRowVars[y]) |= (1 << (x - ICE_PUZZLE_L)); } static bool32 IsIcePuzzleCoordVisited(s16 x, s16 y) { - u32 var; + u16 var; if (!CoordInIcePuzzleRegion(x, y)) return FALSE; - var = VarGet(sSootopolisGymIceRowVars[y]) << 16; - if ((0x10000 << (x - 3)) & var) // TODO: fix that if + var = VarGet(sSootopolisGymIceRowVars[y]); + if (var &= (1 << (x - ICE_PUZZLE_L))) return TRUE; else return FALSE; @@ -534,116 +646,155 @@ void SetSootopolisGymCrackedIceMetatiles(void) } } +#define tState data[1] +#define tPrevX data[2] +#define tPrevY data[3] +#define tIceX data[4] +#define tIceY data[5] +#define tDelay data[6] + static void SootopolisGymIcePerStepCallback(u8 taskId) { s16 x, y; u16 tileBehavior; u16 *iceStepCount; s16 *data = gTasks[taskId].data; - switch (data[1]) + switch (tState) { - case 0: - PlayerGetDestCoords(&x, &y); - data[2] = x; - data[3] = y; - data[1] = 1; - break; - case 1: - PlayerGetDestCoords(&x, &y); - if (x != data[2] || y != data[3]) - { - data[2] = x; - data[3] = y; - tileBehavior = MapGridGetMetatileBehaviorAt(x, y); - iceStepCount = GetVarPointer(VAR_ICE_STEP_COUNT); - if (MetatileBehavior_IsThinIce(tileBehavior) == TRUE) - { - (*iceStepCount)++; - data[6] = 4; - data[1] = 2; - data[4] = x; - data[5] = y; - } - else if (MetatileBehavior_IsCrackedIce(tileBehavior) == TRUE) - { - *iceStepCount = 0; - data[6] = 4; - data[1] = 3; - data[4] = x; - data[5] = y; - } - } - break; - case 2: - if (data[6] != 0) - { - data[6]--; - } - else - { - x = data[4]; - y = data[5]; - PlaySE(SE_ICE_CRACK); - MapGridSetMetatileIdAt(x, y, METATILE_SootopolisGym_Ice_Cracked); - CurrentMapDrawMetatileAt(x, y); - MarkIcePuzzleCoordVisited(x - MAP_OFFSET, y - MAP_OFFSET); - data[1] = 1; - } - break; - case 3: - if (data[6] != 0) - { - data[6]--; - } - else - { - x = data[4]; - y = data[5]; - PlaySE(SE_ICE_BREAK); - MapGridSetMetatileIdAt(x, y, METATILE_SootopolisGym_Ice_Broken); - CurrentMapDrawMetatileAt(x, y); - data[1] = 1; - } - break; + case 0: + PlayerGetDestCoords(&x, &y); + tPrevX = x; + tPrevY = y; + tState = 1; + break; + case 1: + PlayerGetDestCoords(&x, &y); + // End if player hasn't moved + if (x == tPrevX && y == tPrevY) + return; + + tPrevX = x; + tPrevY = y; + tileBehavior = MapGridGetMetatileBehaviorAt(x, y); + iceStepCount = GetVarPointer(VAR_ICE_STEP_COUNT); + if (MetatileBehavior_IsThinIce(tileBehavior) == TRUE) + { + // Thin ice, set it to cracked ice + (*iceStepCount)++; + tDelay = 4; + tState = 2; + tIceX = x; + tIceY = y; + } + else if (MetatileBehavior_IsCrackedIce(tileBehavior) == TRUE) + { + // Cracked ice, set it to broken ice + *iceStepCount = 0; + tDelay = 4; + tState = 3; + tIceX = x; + tIceY = y; + } + break; + case 2: + if (tDelay != 0) + { + tDelay--; + } + else + { + // Crack ice + x = tIceX; + y = tIceY; + PlaySE(SE_ICE_CRACK); + MapGridSetMetatileIdAt(x, y, METATILE_SootopolisGym_Ice_Cracked); + CurrentMapDrawMetatileAt(x, y); + MarkIcePuzzleCoordVisited(x - MAP_OFFSET, y - MAP_OFFSET); + tState = 1; + } + break; + case 3: + if (tDelay != 0) + { + tDelay--; + } + else + { + // Break ice + x = tIceX; + y = tIceY; + PlaySE(SE_ICE_BREAK); + MapGridSetMetatileIdAt(x, y, METATILE_SootopolisGym_Ice_Broken); + CurrentMapDrawMetatileAt(x, y); + tState = 1; + } + break; } } +#undef tState +#undef tPrevX +#undef tPrevY +#undef tIceX +#undef tIceY +#undef tDelay + +#define tPrevX data[1] +#define tPrevY data[2] + static void AshGrassPerStepCallback(u8 taskId) { s16 x, y; u16 *ashGatherCount; s16 *data = gTasks[taskId].data; PlayerGetDestCoords(&x, &y); - if (x != data[1] || y != data[2]) + + // End if player hasn't moved + if (x == tPrevX && y == tPrevY) + return; + + tPrevX = x; + tPrevY = y; + if (MetatileBehavior_IsAshGrass(MapGridGetMetatileBehaviorAt(x, y))) { - data[1] = x; - data[2] = y; - if (MetatileBehavior_IsAshGrass(MapGridGetMetatileBehaviorAt(x, y))) - { - if (MapGridGetMetatileIdAt(x, y) == METATILE_Fallarbor_AshGrass) - StartAshFieldEffect(x, y, METATILE_Fallarbor_NormalGrass, 4); - else - StartAshFieldEffect(x, y, METATILE_Lavaridge_NormalGrass, 4); + // Remove ash from grass + if (MapGridGetMetatileIdAt(x, y) == METATILE_Fallarbor_AshGrass) + StartAshFieldEffect(x, y, METATILE_Fallarbor_NormalGrass, 4); + else + StartAshFieldEffect(x, y, METATILE_Lavaridge_NormalGrass, 4); - if (CheckBagHasItem(ITEM_SOOT_SACK, 1)) - { - ashGatherCount = GetVarPointer(VAR_ASH_GATHER_COUNT); - if (*ashGatherCount < 9999) - (*ashGatherCount)++; - } + // Try to gather ash + if (CheckBagHasItem(ITEM_SOOT_SACK, 1)) + { + ashGatherCount = GetVarPointer(VAR_ASH_GATHER_COUNT); + if (*ashGatherCount < 9999) + (*ashGatherCount)++; } } } +#undef tPrevX +#undef tPrevY + // This function uses the constants for gTileset_Cave's metatile labels, but other tilesets with // the CrackedFloorPerStepCallback callback use the same metatile numbers for the cracked floor // and hole metatiles, such as gTileset_MirageTower. static void SetCrackedFloorHoleMetatile(s16 x, s16 y) { - MapGridSetMetatileIdAt(x, y, MapGridGetMetatileIdAt(x, y) == METATILE_Cave_CrackedFloor ? METATILE_Cave_CrackedFloor_Hole : METATILE_Pacifidlog_SkyPillar_CrackedFloor_Hole); + u16 metatileId = MapGridGetMetatileIdAt(x, y) == METATILE_Cave_CrackedFloor ? METATILE_Cave_CrackedFloor_Hole : METATILE_Pacifidlog_SkyPillar_CrackedFloor_Hole; + MapGridSetMetatileIdAt(x, y, metatileId); CurrentMapDrawMetatileAt(x, y); } +#define tPrevX data[2] +#define tPrevY data[3] +#define tFloor1Delay data[4] +#define tFloor1X data[5] +#define tFloor1Y data[6] +#define tFloor2Delay data[7] +#define tFloor2X data[8] +#define tFloor2Y data[9] + static void CrackedFloorPerStepCallback(u8 taskId) { s16 x, y; @@ -651,113 +802,153 @@ static void CrackedFloorPerStepCallback(u8 taskId) s16 *data = gTasks[taskId].data; PlayerGetDestCoords(&x, &y); behavior = MapGridGetMetatileBehaviorAt(x, y); - if (data[4] != 0 && (--data[4]) == 0) - SetCrackedFloorHoleMetatile(data[5], data[6]); - if (data[7] != 0 && (--data[7]) == 0) - SetCrackedFloorHoleMetatile(data[8], data[9]); + // Update up to 2 previous cracked floor spaces + if (tFloor1Delay != 0 && (--tFloor1Delay) == 0) + SetCrackedFloorHoleMetatile(tFloor1X, tFloor1Y); + if (tFloor2Delay != 0 && (--tFloor2Delay) == 0) + SetCrackedFloorHoleMetatile(tFloor2X, tFloor2Y); if (MetatileBehavior_IsCrackedFloorHole(behavior)) VarSet(VAR_ICE_STEP_COUNT, 0); // this var does double duty - if ((x != data[2] || y != data[3])) + // End if player hasn't moved + if (x == tPrevX && y == tPrevY) + return; + + tPrevX = x; + tPrevY = y; + if (MetatileBehavior_IsCrackedFloor(behavior)) { - data[2] = x; - data[3] = y; - if (MetatileBehavior_IsCrackedFloor(behavior)) - { - if (GetPlayerSpeed() != 4) - VarSet(VAR_ICE_STEP_COUNT, 0); // this var does double duty + if (GetPlayerSpeed() != BIKE_SPEED_FASTEST) + VarSet(VAR_ICE_STEP_COUNT, 0); // this var does double duty - if (data[4] == 0) - { - data[4] = 3; - data[5] = x; - data[6] = y; - } - else if (data[7] == 0) - { - data[7] = 3; - data[8] = x; - data[9] = y; - } + if (tFloor1Delay == 0) + { + tFloor1Delay = 3; + tFloor1X = x; + tFloor1Y = y; + } + else if (tFloor2Delay == 0) + { + tFloor2Delay = 3; + tFloor2X = x; + tFloor2Y = y; } } } +#undef tPrevX +#undef tPrevY +#undef tFloor1Delay +#undef tFloor1X +#undef tFloor1Y +#undef tFloor2Delay +#undef tFloor2X +#undef tFloor2Y + +#define tMapId data[0] +#define tState data[1] +#define tPrevX data[2] +#define tPrevY data[3] +// data[4] - data[15] are data about up to 4 individual animating muddy slope metatiles +// They're divided into groups of 3, i.e data[4]-[6] track one metatile, data[7]-[9] another, and so on. +// For each data triplet, the 1sst is the animation time, and the 2nd/3rd are the x/y coordinates. +#define SLOPE_DATA_START 4 +#define SLOPE_DATA_END (3 * SLOPE_DATA_SIZE + SLOPE_DATA_START) // 13, which is the last slope data start point +enum { + SLOPE_TIME, + SLOPE_X, + SLOPE_Y, + SLOPE_DATA_SIZE +}; +#define tSlopeAnimTime(i) data[(i) * SLOPE_DATA_SIZE + SLOPE_DATA_START + SLOPE_TIME] + +static const u16 sMuddySlopeMetatiles[] = { + METATILE_General_MuddySlope_Frame0, + METATILE_General_MuddySlope_Frame3, + METATILE_General_MuddySlope_Frame2, + METATILE_General_MuddySlope_Frame1 +}; + +#define SLOPE_ANIM_TIME 32 +#define SLOPE_ANIM_STEP_TIME (SLOPE_ANIM_TIME / (int)ARRAY_COUNT(sMuddySlopeMetatiles)) + static void SetMuddySlopeMetatile(s16 *data, s16 x, s16 y) { - u16 tile; - if ((--data[0]) == 0) - tile = METATILE_General_MuddySlope_Frame0; + u16 metatileId; + if ((--data[SLOPE_TIME]) == 0) + metatileId = METATILE_General_MuddySlope_Frame0; else - tile = sMuddySlopeMetatiles[data[0] / 8]; + metatileId = sMuddySlopeMetatiles[data[SLOPE_TIME] / SLOPE_ANIM_STEP_TIME]; - MapGridSetMetatileIdAt(x, y, tile); + MapGridSetMetatileIdAt(x, y, metatileId); CurrentMapDrawMetatileAt(x, y); MapGridSetMetatileIdAt(x, y, METATILE_General_MuddySlope_Frame0); } static void Task_MuddySlope(u8 taskId) { - s16 x, y, x2, y2; + s16 x, y, cameraOffsetX, cameraOffsetY; int i; u16 mapId; s16 *data = gTasks[taskId].data; PlayerGetDestCoords(&x, &y); mapId = (gSaveBlock1Ptr->location.mapGroup << 8) | gSaveBlock1Ptr->location.mapNum; - switch (data[1]) + switch (tState) { - case 0: - data[0] = mapId; - data[2] = x; - data[3] = y; - data[1] = 1; - data[4] = 0; - data[7] = 0; - data[10] = 0; - data[13] = 0; + case 0: + tMapId = mapId; + tPrevX = x; + tPrevY = y; + tState = 1; + tSlopeAnimTime(0) = 0; + tSlopeAnimTime(1) = 0; + tSlopeAnimTime(2) = 0; + tSlopeAnimTime(3) = 0; + break; + case 1: + // Skip if player hasn't moved + if (tPrevX == x && tPrevY == y) break; - case 1: - if (data[2] != x || data[3] != y) + + tPrevX = x; + tPrevY = y; + if (MetatileBehavior_IsMuddySlope(MapGridGetMetatileBehaviorAt(x, y))) + { + for (i = SLOPE_DATA_START; i <= SLOPE_DATA_END; i += SLOPE_DATA_SIZE) { - data[2] = x; - data[3] = y; - if (MetatileBehavior_IsMuddySlope(MapGridGetMetatileBehaviorAt(x, y))) + if (data[i] == 0) { - for (i = 4; i < 14; i += 3) - { - if (data[i] == 0) - { - data[i] = 32; - data[i + 1] = x; - data[i + 2] = y; - break; - } - } + data[i + SLOPE_TIME] = SLOPE_ANIM_TIME; + data[i + SLOPE_X] = x; + data[i + SLOPE_Y] = y; + break; } } - break; + } + break; } - if (gCamera.active && mapId != data[0]) + + if (gCamera.active && mapId != tMapId) { - data[0] = mapId; - x2 = gCamera.x; - y2 = gCamera.y; + tMapId = mapId; + cameraOffsetX = gCamera.x; + cameraOffsetY = gCamera.y; } else { - x2 = 0; - y2 = 0; + cameraOffsetX = 0; + cameraOffsetY = 0; } - for (i = 4; i < 14; i += 3) + for (i = SLOPE_DATA_START; i <= SLOPE_DATA_END; i += SLOPE_DATA_SIZE) { - if (data[i]) + if (data[i + SLOPE_TIME]) { - data[i + 1] -= x2; - data[i + 2] -= y2; - SetMuddySlopeMetatile(&data[i], data[i + 1], data[i + 2]); + data[i + SLOPE_X] -= cameraOffsetX; + data[i + SLOPE_Y] -= cameraOffsetY; + SetMuddySlopeMetatile(&data[i + SLOPE_TIME], data[i + SLOPE_X], data[i + SLOPE_Y]); } } } diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index 5720363c2..2b87557c2 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -2487,19 +2487,19 @@ static void CreateAbnormalWeatherTask(void) static u8 TranslateWeatherNum(u8); static void UpdateRainCounter(u8, u8); -void SetSav1Weather(u32 weather) +void SetSavedWeather(u32 weather) { u8 oldWeather = gSaveBlock1Ptr->weather; gSaveBlock1Ptr->weather = TranslateWeatherNum(weather); UpdateRainCounter(gSaveBlock1Ptr->weather, oldWeather); } -u8 GetSav1Weather(void) +u8 GetSavedWeather(void) { return gSaveBlock1Ptr->weather; } -void SetSav1WeatherFromCurrMapHeader(void) +void SetSavedWeatherFromCurrMapHeader(void) { u8 oldWeather = gSaveBlock1Ptr->weather; gSaveBlock1Ptr->weather = TranslateWeatherNum(gMapHeader.weather); @@ -2508,19 +2508,19 @@ void SetSav1WeatherFromCurrMapHeader(void) void SetWeather(u32 weather) { - SetSav1Weather(weather); - SetNextWeather(GetSav1Weather()); + SetSavedWeather(weather); + SetNextWeather(GetSavedWeather()); } void SetWeather_Unused(u32 weather) { - SetSav1Weather(weather); - SetCurrentAndNextWeather(GetSav1Weather()); + SetSavedWeather(weather); + SetCurrentAndNextWeather(GetSavedWeather()); } void DoCurrentWeather(void) { - u8 weather = GetSav1Weather(); + u8 weather = GetSavedWeather(); if (weather == WEATHER_ABNORMAL) { @@ -2539,7 +2539,7 @@ void DoCurrentWeather(void) void ResumePausedWeather(void) { - u8 weather = GetSav1Weather(); + u8 weather = GetSavedWeather(); if (weather == WEATHER_ABNORMAL) { diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 8ce1e14dc..07dd8f228 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -26,7 +26,6 @@ #include "overworld.h" #include "math_util.h" #include "constants/battle_frontier.h" -#include "constants/maps.h" #include "constants/rgb.h" #include "constants/region_map_sections.h" #include "constants/songs.h" diff --git a/src/heal_location.c b/src/heal_location.c index 5eda24d67..ab8dc5265 100644 --- a/src/heal_location.c +++ b/src/heal_location.c @@ -1,6 +1,5 @@ #include "global.h" #include "heal_location.h" -#include "constants/maps.h" #include "constants/heal_locations.h" #include "data/heal_locations.h" diff --git a/src/link.c b/src/link.c index 01cc06e7c..1084d4a6d 100644 --- a/src/link.c +++ b/src/link.c @@ -292,10 +292,9 @@ static void LinkTestScreen(void) gLinkType = LINKTYPE_TRADE; OpenLink(); SeedRng(gMain.vblankCounter2); - for (i = 0; i < MAX_LINK_PLAYERS; i++) - { + for (i = 0; i < TRAINER_ID_LENGTH; i++) gSaveBlock2Ptr->playerTrainerId[i] = Random() % 256; - } + InitLinkTestBG(0, 2, 4, 0, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_ON); CreateTask(Task_DestroySelf, 0); diff --git a/src/mail_data.c b/src/mail_data.c index 683bd854e..ca50a687e 100644 --- a/src/mail_data.c +++ b/src/mail_data.c @@ -157,7 +157,7 @@ void ClearMailItemId(u8 mailId) gSaveBlock1Ptr->mail[mailId].itemId = ITEM_NONE; } -u8 TakeMailFromMon2(struct Pokemon *mon) +u8 TakeMailFromMonAndSave(struct Pokemon *mon) { u8 i; u8 newHeldItem[2]; @@ -179,6 +179,7 @@ u8 TakeMailFromMon2(struct Pokemon *mon) } } + // No space to save mail return MAIL_NONE; } diff --git a/src/match_call.c b/src/match_call.c index 85df5822d..de7f13416 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -29,7 +29,6 @@ #include "constants/abilities.h" #include "constants/battle_frontier.h" #include "constants/event_objects.h" -#include "constants/maps.h" #include "constants/region_map_sections.h" #include "constants/songs.h" #include "constants/trainers.h" diff --git a/src/menu_helpers.c b/src/menu_helpers.c index 5bc197010..d5cf83bd2 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -16,7 +16,6 @@ #include "decompress.h" #include "constants/songs.h" #include "constants/items.h" -#include "constants/maps.h" #define TAG_SWAP_LINE 109 diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index ad5eb42cc..6b58e3f05 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -126,10 +126,10 @@ static const u8 sTileBitAttributes[] = [MB_BRIDGE_OVER_POND_LOW] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_BRIDGE_OVER_POND_MED] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_BRIDGE_OVER_POND_HIGH] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_PACIFIDLOG_VERTICAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_PACIFIDLOG_VERTICAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_PACIFIDLOG_HORIZONTAL_LOG_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), - [MB_PACIFIDLOG_HORIZONTAL_LOG_2] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_PACIFIDLOG_VERTICAL_LOG_TOP] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_PACIFIDLOG_VERTICAL_LOG_BOTTOM] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_PACIFIDLOG_HORIZONTAL_LOG_LEFT] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), + [MB_PACIFIDLOG_HORIZONTAL_LOG_RIGHT] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_FORTREE_BRIDGE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), [MB_UNUSED_79] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_BRIDGE_OVER_POND_MED_EDGE_1] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE), @@ -1131,33 +1131,33 @@ bool8 MetatileBehavior_IsFortreeBridge(u8 metatileBehavior) return FALSE; } -bool8 MetatileBehavior_IsPacifidlogVerticalLog1(u8 metatileBehavior) +bool8 MetatileBehavior_IsPacifidlogVerticalLogTop(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1) + if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_TOP) return TRUE; else return FALSE; } -bool8 MetatileBehavior_IsPacifidlogVerticalLog2(u8 metatileBehavior) +bool8 MetatileBehavior_IsPacifidlogVerticalLogBottom(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2) + if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_BOTTOM) return TRUE; else return FALSE; } -bool8 MetatileBehavior_IsPacifidlogHorizontalLog1(u8 metatileBehavior) +bool8 MetatileBehavior_IsPacifidlogHorizontalLogLeft(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1) + if (metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_LEFT) return TRUE; else return FALSE; } -bool8 MetatileBehavior_IsPacifidlogHorizontalLog2(u8 metatileBehavior) +bool8 MetatileBehavior_IsPacifidlogHorizontalLogRight(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2) + if (metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_RIGHT) return TRUE; else return FALSE; @@ -1165,10 +1165,10 @@ bool8 MetatileBehavior_IsPacifidlogHorizontalLog2(u8 metatileBehavior) bool8 MetatileBehavior_IsPacifidlogLog(u8 metatileBehavior) { - if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_1 - || metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_2 - || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_1 - || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_2) + if (metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_TOP + || metatileBehavior == MB_PACIFIDLOG_VERTICAL_LOG_BOTTOM + || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_LEFT + || metatileBehavior == MB_PACIFIDLOG_HORIZONTAL_LOG_RIGHT) return TRUE; else return FALSE; diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 9473b0f82..730026298 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -15,7 +15,6 @@ #include "task.h" #include "window.h" #include "constants/event_objects.h" -#include "constants/maps.h" #include "constants/rgb.h" #include "constants/songs.h" #include "constants/metatile_labels.h" diff --git a/src/new_game.c b/src/new_game.c index 4bd3d3704..077b86775 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -29,7 +29,6 @@ #include "pokedex.h" #include "apprentice.h" #include "frontier_util.h" -#include "constants/maps.h" #include "pokedex.h" #include "save.h" #include "link_rfu.h" @@ -126,7 +125,7 @@ static void ClearFrontierRecord(void) static void WarpToTruck(void) { - SetWarpDestination(MAP_GROUP(INSIDE_OF_TRUCK), MAP_NUM(INSIDE_OF_TRUCK), -1, -1, -1); + SetWarpDestination(MAP_GROUP(INSIDE_OF_TRUCK), MAP_NUM(INSIDE_OF_TRUCK), WARP_ID_NONE, -1, -1); WarpIntoMap(); } diff --git a/src/overworld.c b/src/overworld.c index 518771875..f6c4c0f3d 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -62,7 +62,6 @@ #include "constants/abilities.h" #include "constants/layouts.h" #include "constants/map_types.h" -#include "constants/maps.h" #include "constants/region_map_sections.h" #include "constants/songs.h" #include "constants/trainer_hill.h" @@ -175,7 +174,6 @@ static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *, u static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *, u8, u16, u8); static u16 GetCenterScreenMetatileBehavior(void); -// IWRAM bss vars static void *sUnusedOverworldCallback; static u8 sPlayerLinkStates[MAX_LINK_PLAYERS]; // This callback is called with a player's key code. It then returns an @@ -185,7 +183,6 @@ static u16 (*sPlayerKeyInterceptCallback)(u32); static bool8 sReceivingFromLink; static u8 sRfuKeepAliveTimer; -// IWRAM common u16 *gBGTilemapBuffers1; u16 *gBGTilemapBuffers2; u16 *gBGTilemapBuffers3; @@ -195,7 +192,6 @@ bool8 (*gFieldCallback2)(void); u8 gLocalLinkPlayerId; // This is our player id in a multiplayer mode. u8 gFieldLinkPlayerCount; -// EWRAM vars EWRAM_DATA static u8 sObjectEventLoadFlag = 0; EWRAM_DATA struct WarpData gLastUsedWarp = {0}; EWRAM_DATA static struct WarpData sWarpDestination = {0}; // new warp position @@ -207,12 +203,11 @@ EWRAM_DATA static u16 sAmbientCrySpecies = 0; EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE; EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0}; -// const rom data static const struct WarpData sDummyWarpData = { - .mapGroup = -1, - .mapNum = -1, - .warpId = -1, + .mapGroup = MAP_GROUP(UNDEFINED), + .mapNum = MAP_NUM(UNDEFINED), + .warpId = WARP_ID_NONE, .x = -1, .y = -1, }; @@ -495,7 +490,7 @@ void LoadSaveblockObjEventScripts(void) savObjTemplates[i].script = mapHeaderObjTemplates[i].script; } -void Overworld_SetObjEventTemplateCoords(u8 localId, s16 x, s16 y) +void SetObjEventTemplateCoords(u8 localId, s16 x, s16 y) { s32 i; struct ObjectEventTemplate *savObjTemplates = gSaveBlock1Ptr->objectEventTemplates; @@ -512,7 +507,7 @@ void Overworld_SetObjEventTemplateCoords(u8 localId, s16 x, s16 y) } } -void Overworld_SetObjEventTemplateMovementType(u8 localId, u8 movementType) +void SetObjEventTemplateMovementType(u8 localId, u8 movementType) { s32 i; @@ -570,11 +565,11 @@ static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId static bool32 IsDummyWarp(struct WarpData *warp) { - if (warp->mapGroup != -1) + if (warp->mapGroup != (s8)MAP_GROUP(UNDEFINED)) return FALSE; - else if (warp->mapNum != -1) + else if (warp->mapNum != (s8)MAP_NUM(UNDEFINED)) return FALSE; - else if (warp->warpId != -1) + else if (warp->warpId != WARP_ID_NONE) return FALSE; else if (warp->x != -1) return FALSE; @@ -612,16 +607,20 @@ static void SetPlayerCoordsFromWarp(void) { if (gSaveBlock1Ptr->location.warpId >= 0 && gSaveBlock1Ptr->location.warpId < gMapHeader.events->warpCount) { + // warpId is a valid warp for this map, use the coords of that warp. gSaveBlock1Ptr->pos.x = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].x; gSaveBlock1Ptr->pos.y = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].y; } else if (gSaveBlock1Ptr->location.x >= 0 && gSaveBlock1Ptr->location.y >= 0) { + // Invalid warpId given. The given coords are valid, use those instead. + // WARP_ID_NONE is used to reach this intentionally. gSaveBlock1Ptr->pos.x = gSaveBlock1Ptr->location.x; gSaveBlock1Ptr->pos.y = gSaveBlock1Ptr->location.y; } else { + // Invalid warpId and coords given. Put player in center of map. gSaveBlock1Ptr->pos.x = gMapHeader.mapLayout->width / 2; gSaveBlock1Ptr->pos.y = gMapHeader.mapLayout->height / 2; } @@ -663,7 +662,7 @@ void SetWarpDestinationToHealLocation(u8 healLocationId) { const struct HealLocation *warp = GetHealLocation(healLocationId); if (warp) - SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y); + SetWarpDestination(warp->group, warp->map, WARP_ID_NONE, warp->x, warp->y); } void SetWarpDestinationToLastHealLocation(void) @@ -675,7 +674,7 @@ void SetLastHealLocationWarp(u8 healLocationId) { const struct HealLocation *healLocation = GetHealLocation(healLocationId); if (healLocation) - SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, -1, healLocation->x, healLocation->y); + SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, WARP_ID_NONE, healLocation->x, healLocation->y); } void UpdateEscapeWarp(s16 x, s16 y) @@ -683,7 +682,7 @@ void UpdateEscapeWarp(s16 x, s16 y) u8 currMapType = GetCurrentMapType(); u8 destMapType = GetMapTypeByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum); if (IsMapTypeOutdoors(currMapType) && IsMapTypeOutdoors(destMapType) != TRUE) - SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET + 1); + SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE, x - MAP_OFFSET, y - MAP_OFFSET + 1); } void SetEscapeWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) @@ -716,7 +715,7 @@ void SetWarpDestinationToFixedHoleWarp(s16 x, s16 y) if (IsDummyWarp(&sFixedHoleWarp) == TRUE) sWarpDestination = gLastUsedWarp; else - SetWarpDestination(sFixedHoleWarp.mapGroup, sFixedHoleWarp.mapNum, -1, x, y); + SetWarpDestination(sFixedHoleWarp.mapGroup, sFixedHoleWarp.mapNum, WARP_ID_NONE, x, y); } static void SetWarpDestinationToContinueGameWarp(void) @@ -733,7 +732,7 @@ void SetContinueGameWarpToHealLocation(u8 healLocationId) { const struct HealLocation *warp = GetHealLocation(healLocationId); if (warp) - SetWarpData(&gSaveBlock1Ptr->continueGameWarp, warp->group, warp->map, -1, warp->x, warp->y); + SetWarpData(&gSaveBlock1Ptr->continueGameWarp, warp->group, warp->map, WARP_ID_NONE, warp->x, warp->y); } void SetContinueGameWarpToDynamicWarp(int unused) @@ -763,7 +762,7 @@ static bool8 SetDiveWarp(u8 dir, u16 x, u16 y) if (connection != NULL) { - SetWarpDestination(connection->mapGroup, connection->mapNum, -1, x, y); + SetWarpDestination(connection->mapGroup, connection->mapNum, WARP_ID_NONE, x, y); } else { @@ -789,7 +788,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) { s32 paletteIndex; - SetWarpDestination(mapGroup, mapNum, -1, -1, -1); + SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, -1, -1); // Dont transition map music between BF Outside West/East if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER) @@ -804,7 +803,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) RestartWildEncounterImmunitySteps(); TryUpdateRandomTrainerRematches(mapGroup, mapNum); DoTimeBasedEvents(); - SetSav1WeatherFromCurrMapHeader(); + SetSavedWeatherFromCurrMapHeader(); ChooseAmbientCrySpecies(); SetDefaultFlashLevel(); Overworld_ClearSavedMusic(); @@ -855,7 +854,7 @@ static void LoadMapFromWarp(bool32 a1) TryUpdateRandomTrainerRematches(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); if (a1 != TRUE) DoTimeBasedEvents(); - SetSav1WeatherFromCurrMapHeader(); + SetSavedWeatherFromCurrMapHeader(); ChooseAmbientCrySpecies(); if (isOutdoors) FlagClear(FLAG_SYS_USE_FLASH); @@ -968,6 +967,10 @@ bool32 Overworld_IsBikingAllowed(void) return TRUE; } +// Flash level of 0 is fully bright +// Flash level of 1 is the largest flash radius +// Flash level of 7 is the smallest flash radius +// Flash level of 8 is fully black void SetDefaultFlashLevel(void) { if (!gMapHeader.cave) @@ -978,14 +981,14 @@ void SetDefaultFlashLevel(void) gSaveBlock1Ptr->flashLevel = gMaxFlashLevel - 1; } -void Overworld_SetFlashLevel(s32 flashLevel) +void SetFlashLevel(s32 flashLevel) { if (flashLevel < 0 || flashLevel > gMaxFlashLevel) flashLevel = 0; gSaveBlock1Ptr->flashLevel = flashLevel; } -u8 Overworld_GetFlashLevel(void) +u8 GetFlashLevel(void) { return gSaveBlock1Ptr->flashLevel; } @@ -1100,7 +1103,7 @@ u16 GetCurrLocationDefaultMusic(void) // Play the desert music only when the sandstorm is active on Route 111. if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111) - && GetSav1Weather() == WEATHER_SANDSTORM) + && GetSavedWeather() == WEATHER_SANDSTORM) return MUS_ROUTE111; music = GetLocationMusic(&gSaveBlock1Ptr->location); @@ -1790,7 +1793,7 @@ static void InitCurrentFlashLevelScanlineEffect(void) WriteBattlePyramidViewScanlineEffectBuffer(); ScanlineEffect_SetParams(sFlashEffectParams); } - else if ((flashLevel = Overworld_GetFlashLevel())) + else if ((flashLevel = GetFlashLevel())) { WriteFlashScanlineEffectBuffer(flashLevel); ScanlineEffect_SetParams(sFlashEffectParams); @@ -3147,17 +3150,17 @@ static u8 FlipVerticalAndClearForced(u8 newFacing, u8 oldFacing) return oldFacing; } -static u8 LinkPlayerDetectCollision(u8 selfObjEventId, u8 a2, s16 x, s16 y) +static bool8 LinkPlayerDetectCollision(u8 selfObjEventId, u8 direction, s16 x, s16 y) { u8 i; - for (i = 0; i < 16; i++) + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { if (i != selfObjEventId) { if ((gObjectEvents[i].currentCoords.x == x && gObjectEvents[i].currentCoords.y == y) || (gObjectEvents[i].previousCoords.x == x && gObjectEvents[i].previousCoords.y == y)) { - return 1; + return TRUE; } } } diff --git a/src/party_menu.c b/src/party_menu.c index 43f522034..d654afa33 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -69,7 +69,6 @@ #include "constants/field_effects.h" #include "constants/item_effects.h" #include "constants/items.h" -#include "constants/maps.h" #include "constants/moves.h" #include "constants/party_menu.h" #include "constants/rgb.h" @@ -3343,7 +3342,7 @@ static void Task_HandleSendMailToPCYesNoInput(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case 0: // Yes, send to PC - if (TakeMailFromMon2(&gPlayerParty[gPartyMenu.slotId]) != 0xFF) + if (TakeMailFromMonAndSave(&gPlayerParty[gPartyMenu.slotId]) != MAIL_NONE) { DisplayPartyMenuMessage(gText_MailSentToPC, FALSE); gTasks[taskId].func = Task_UpdateHeldItemSprite; @@ -6133,7 +6132,7 @@ static void BufferMonSelection(void) { gSpecialVar_0x8004 = GetCursorSelectionMonId(); if (gSpecialVar_0x8004 >= PARTY_SIZE) - gSpecialVar_0x8004 = 0xFF; + gSpecialVar_0x8004 = PARTY_NOTHING_CHOSEN; gFieldCallback2 = CB2_FadeFromPartyMenu; SetMainCallback2(CB2_ReturnToField); } @@ -6176,7 +6175,7 @@ static void CB2_ChooseContestMon(void) { gContestMonPartyIndex = GetCursorSelectionMonId(); if (gContestMonPartyIndex >= PARTY_SIZE) - gContestMonPartyIndex = 0xFF; + gContestMonPartyIndex = PARTY_NOTHING_CHOSEN; gSpecialVar_0x8004 = gContestMonPartyIndex; gFieldCallback2 = CB2_FadeFromPartyMenu; SetMainCallback2(CB2_ReturnToField); @@ -6221,7 +6220,7 @@ static void CB2_ChooseMonForMoveRelearner(void) { gSpecialVar_0x8004 = GetCursorSelectionMonId(); if (gSpecialVar_0x8004 >= PARTY_SIZE) - gSpecialVar_0x8004 = 0xFF; + gSpecialVar_0x8004 = PARTY_NOTHING_CHOSEN; else gSpecialVar_0x8005 = GetNumberOfRelearnableMoves(&gPlayerParty[gSpecialVar_0x8004]); gFieldCallback2 = CB2_FadeFromPartyMenu; diff --git a/src/pokeball.c b/src/pokeball.c index 501d86ca3..cb68d6883 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1138,7 +1138,7 @@ static void SpriteCB_TradePokeball(struct Sprite *sprite) sprite->callback = SpriteCB_TradePokeballSendOff; #ifdef BUGFIX // FIX: If this is used on a sprite that has previously had an affine animation, it will not - // play the shrink anim properly due to being paused. Works together with the fix to `sub_817F77C`. + // play the shrink anim properly due to being paused. Works together with the fix to ResetSpriteAfterAnim. gSprites[monSpriteId].affineAnimPaused = FALSE; #endif // BUGFIX StartSpriteAffineAnim(&gSprites[monSpriteId], BATTLER_AFFINE_RETURN); diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index e2973dcab..141041f4f 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -16,7 +16,6 @@ #include "trig.h" #include "pokedex_area_region_map.h" #include "wild_encounter.h" -#include "constants/maps.h" #include "constants/region_map_sections.h" #include "constants/rgb.h" #include "constants/songs.h" diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index f18dc68d1..727cc5538 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -37,7 +37,6 @@ #include "walda_phrase.h" #include "window.h" #include "constants/items.h" -#include "constants/maps.h" #include "constants/moves.h" #include "constants/rgb.h" #include "constants/songs.h" diff --git a/src/region_map.c b/src/region_map.c index 759a26e84..0dc902674 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -7,7 +7,6 @@ #include "palette.h" #include "party_menu.h" #include "trig.h" -#include "constants/maps.h" #include "overworld.h" #include "event_data.h" #include "secret_base.h" @@ -290,56 +289,56 @@ static const u32 sFlyTargetIcons_Gfx[] = INCBIN_U32("graphics/pokenav/region_map static const u8 sMapHealLocations[][3] = { - {MAP_GROUP(LITTLEROOT_TOWN), MAP_NUM(LITTLEROOT_TOWN), HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F}, - {MAP_GROUP(OLDALE_TOWN), MAP_NUM(OLDALE_TOWN), HEAL_LOCATION_OLDALE_TOWN}, - {MAP_GROUP(DEWFORD_TOWN), MAP_NUM(DEWFORD_TOWN), HEAL_LOCATION_DEWFORD_TOWN}, - {MAP_GROUP(LAVARIDGE_TOWN), MAP_NUM(LAVARIDGE_TOWN), HEAL_LOCATION_LAVARIDGE_TOWN}, - {MAP_GROUP(FALLARBOR_TOWN), MAP_NUM(FALLARBOR_TOWN), HEAL_LOCATION_FALLARBOR_TOWN}, - {MAP_GROUP(VERDANTURF_TOWN), MAP_NUM(VERDANTURF_TOWN), HEAL_LOCATION_VERDANTURF_TOWN}, - {MAP_GROUP(PACIFIDLOG_TOWN), MAP_NUM(PACIFIDLOG_TOWN), HEAL_LOCATION_PACIFIDLOG_TOWN}, - {MAP_GROUP(PETALBURG_CITY), MAP_NUM(PETALBURG_CITY), HEAL_LOCATION_PETALBURG_CITY}, - {MAP_GROUP(SLATEPORT_CITY), MAP_NUM(SLATEPORT_CITY), HEAL_LOCATION_SLATEPORT_CITY}, - {MAP_GROUP(MAUVILLE_CITY), MAP_NUM(MAUVILLE_CITY), HEAL_LOCATION_MAUVILLE_CITY}, - {MAP_GROUP(RUSTBORO_CITY), MAP_NUM(RUSTBORO_CITY), HEAL_LOCATION_RUSTBORO_CITY}, - {MAP_GROUP(FORTREE_CITY), MAP_NUM(FORTREE_CITY), HEAL_LOCATION_FORTREE_CITY}, - {MAP_GROUP(LILYCOVE_CITY), MAP_NUM(LILYCOVE_CITY), HEAL_LOCATION_LILYCOVE_CITY}, - {MAP_GROUP(MOSSDEEP_CITY), MAP_NUM(MOSSDEEP_CITY), HEAL_LOCATION_MOSSDEEP_CITY}, - {MAP_GROUP(SOOTOPOLIS_CITY), MAP_NUM(SOOTOPOLIS_CITY), HEAL_LOCATION_SOOTOPOLIS_CITY}, - {MAP_GROUP(EVER_GRANDE_CITY), MAP_NUM(EVER_GRANDE_CITY), HEAL_LOCATION_EVER_GRANDE_CITY}, - {MAP_GROUP(ROUTE101), MAP_NUM(ROUTE101), 0}, - {MAP_GROUP(ROUTE102), MAP_NUM(ROUTE102), 0}, - {MAP_GROUP(ROUTE103), MAP_NUM(ROUTE103), 0}, - {MAP_GROUP(ROUTE104), MAP_NUM(ROUTE104), 0}, - {MAP_GROUP(ROUTE105), MAP_NUM(ROUTE105), 0}, - {MAP_GROUP(ROUTE106), MAP_NUM(ROUTE106), 0}, - {MAP_GROUP(ROUTE107), MAP_NUM(ROUTE107), 0}, - {MAP_GROUP(ROUTE108), MAP_NUM(ROUTE108), 0}, - {MAP_GROUP(ROUTE109), MAP_NUM(ROUTE109), 0}, - {MAP_GROUP(ROUTE110), MAP_NUM(ROUTE110), 0}, - {MAP_GROUP(ROUTE111), MAP_NUM(ROUTE111), 0}, - {MAP_GROUP(ROUTE112), MAP_NUM(ROUTE112), 0}, - {MAP_GROUP(ROUTE113), MAP_NUM(ROUTE113), 0}, - {MAP_GROUP(ROUTE114), MAP_NUM(ROUTE114), 0}, - {MAP_GROUP(ROUTE115), MAP_NUM(ROUTE115), 0}, - {MAP_GROUP(ROUTE116), MAP_NUM(ROUTE116), 0}, - {MAP_GROUP(ROUTE117), MAP_NUM(ROUTE117), 0}, - {MAP_GROUP(ROUTE118), MAP_NUM(ROUTE118), 0}, - {MAP_GROUP(ROUTE119), MAP_NUM(ROUTE119), 0}, - {MAP_GROUP(ROUTE120), MAP_NUM(ROUTE120), 0}, - {MAP_GROUP(ROUTE121), MAP_NUM(ROUTE121), 0}, - {MAP_GROUP(ROUTE122), MAP_NUM(ROUTE122), 0}, - {MAP_GROUP(ROUTE123), MAP_NUM(ROUTE123), 0}, - {MAP_GROUP(ROUTE124), MAP_NUM(ROUTE124), 0}, - {MAP_GROUP(ROUTE125), MAP_NUM(ROUTE125), 0}, - {MAP_GROUP(ROUTE126), MAP_NUM(ROUTE126), 0}, - {MAP_GROUP(ROUTE127), MAP_NUM(ROUTE127), 0}, - {MAP_GROUP(ROUTE128), MAP_NUM(ROUTE128), 0}, - {MAP_GROUP(ROUTE129), MAP_NUM(ROUTE129), 0}, - {MAP_GROUP(ROUTE130), MAP_NUM(ROUTE130), 0}, - {MAP_GROUP(ROUTE131), MAP_NUM(ROUTE131), 0}, - {MAP_GROUP(ROUTE132), MAP_NUM(ROUTE132), 0}, - {MAP_GROUP(ROUTE133), MAP_NUM(ROUTE133), 0}, - {MAP_GROUP(ROUTE134), MAP_NUM(ROUTE134), 0} + [MAPSEC_LITTLEROOT_TOWN] = {MAP_GROUP(LITTLEROOT_TOWN), MAP_NUM(LITTLEROOT_TOWN), HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F}, + [MAPSEC_OLDALE_TOWN] = {MAP_GROUP(OLDALE_TOWN), MAP_NUM(OLDALE_TOWN), HEAL_LOCATION_OLDALE_TOWN}, + [MAPSEC_DEWFORD_TOWN] = {MAP_GROUP(DEWFORD_TOWN), MAP_NUM(DEWFORD_TOWN), HEAL_LOCATION_DEWFORD_TOWN}, + [MAPSEC_LAVARIDGE_TOWN] = {MAP_GROUP(LAVARIDGE_TOWN), MAP_NUM(LAVARIDGE_TOWN), HEAL_LOCATION_LAVARIDGE_TOWN}, + [MAPSEC_FALLARBOR_TOWN] = {MAP_GROUP(FALLARBOR_TOWN), MAP_NUM(FALLARBOR_TOWN), HEAL_LOCATION_FALLARBOR_TOWN}, + [MAPSEC_VERDANTURF_TOWN] = {MAP_GROUP(VERDANTURF_TOWN), MAP_NUM(VERDANTURF_TOWN), HEAL_LOCATION_VERDANTURF_TOWN}, + [MAPSEC_PACIFIDLOG_TOWN] = {MAP_GROUP(PACIFIDLOG_TOWN), MAP_NUM(PACIFIDLOG_TOWN), HEAL_LOCATION_PACIFIDLOG_TOWN}, + [MAPSEC_PETALBURG_CITY] = {MAP_GROUP(PETALBURG_CITY), MAP_NUM(PETALBURG_CITY), HEAL_LOCATION_PETALBURG_CITY}, + [MAPSEC_SLATEPORT_CITY] = {MAP_GROUP(SLATEPORT_CITY), MAP_NUM(SLATEPORT_CITY), HEAL_LOCATION_SLATEPORT_CITY}, + [MAPSEC_MAUVILLE_CITY] = {MAP_GROUP(MAUVILLE_CITY), MAP_NUM(MAUVILLE_CITY), HEAL_LOCATION_MAUVILLE_CITY}, + [MAPSEC_RUSTBORO_CITY] = {MAP_GROUP(RUSTBORO_CITY), MAP_NUM(RUSTBORO_CITY), HEAL_LOCATION_RUSTBORO_CITY}, + [MAPSEC_FORTREE_CITY] = {MAP_GROUP(FORTREE_CITY), MAP_NUM(FORTREE_CITY), HEAL_LOCATION_FORTREE_CITY}, + [MAPSEC_LILYCOVE_CITY] = {MAP_GROUP(LILYCOVE_CITY), MAP_NUM(LILYCOVE_CITY), HEAL_LOCATION_LILYCOVE_CITY}, + [MAPSEC_MOSSDEEP_CITY] = {MAP_GROUP(MOSSDEEP_CITY), MAP_NUM(MOSSDEEP_CITY), HEAL_LOCATION_MOSSDEEP_CITY}, + [MAPSEC_SOOTOPOLIS_CITY] = {MAP_GROUP(SOOTOPOLIS_CITY), MAP_NUM(SOOTOPOLIS_CITY), HEAL_LOCATION_SOOTOPOLIS_CITY}, + [MAPSEC_EVER_GRANDE_CITY] = {MAP_GROUP(EVER_GRANDE_CITY), MAP_NUM(EVER_GRANDE_CITY), HEAL_LOCATION_EVER_GRANDE_CITY}, + [MAPSEC_ROUTE_101] = {MAP_GROUP(ROUTE101), MAP_NUM(ROUTE101), 0}, + [MAPSEC_ROUTE_102] = {MAP_GROUP(ROUTE102), MAP_NUM(ROUTE102), 0}, + [MAPSEC_ROUTE_103] = {MAP_GROUP(ROUTE103), MAP_NUM(ROUTE103), 0}, + [MAPSEC_ROUTE_104] = {MAP_GROUP(ROUTE104), MAP_NUM(ROUTE104), 0}, + [MAPSEC_ROUTE_105] = {MAP_GROUP(ROUTE105), MAP_NUM(ROUTE105), 0}, + [MAPSEC_ROUTE_106] = {MAP_GROUP(ROUTE106), MAP_NUM(ROUTE106), 0}, + [MAPSEC_ROUTE_107] = {MAP_GROUP(ROUTE107), MAP_NUM(ROUTE107), 0}, + [MAPSEC_ROUTE_108] = {MAP_GROUP(ROUTE108), MAP_NUM(ROUTE108), 0}, + [MAPSEC_ROUTE_109] = {MAP_GROUP(ROUTE109), MAP_NUM(ROUTE109), 0}, + [MAPSEC_ROUTE_110] = {MAP_GROUP(ROUTE110), MAP_NUM(ROUTE110), 0}, + [MAPSEC_ROUTE_111] = {MAP_GROUP(ROUTE111), MAP_NUM(ROUTE111), 0}, + [MAPSEC_ROUTE_112] = {MAP_GROUP(ROUTE112), MAP_NUM(ROUTE112), 0}, + [MAPSEC_ROUTE_113] = {MAP_GROUP(ROUTE113), MAP_NUM(ROUTE113), 0}, + [MAPSEC_ROUTE_114] = {MAP_GROUP(ROUTE114), MAP_NUM(ROUTE114), 0}, + [MAPSEC_ROUTE_115] = {MAP_GROUP(ROUTE115), MAP_NUM(ROUTE115), 0}, + [MAPSEC_ROUTE_116] = {MAP_GROUP(ROUTE116), MAP_NUM(ROUTE116), 0}, + [MAPSEC_ROUTE_117] = {MAP_GROUP(ROUTE117), MAP_NUM(ROUTE117), 0}, + [MAPSEC_ROUTE_118] = {MAP_GROUP(ROUTE118), MAP_NUM(ROUTE118), 0}, + [MAPSEC_ROUTE_119] = {MAP_GROUP(ROUTE119), MAP_NUM(ROUTE119), 0}, + [MAPSEC_ROUTE_120] = {MAP_GROUP(ROUTE120), MAP_NUM(ROUTE120), 0}, + [MAPSEC_ROUTE_121] = {MAP_GROUP(ROUTE121), MAP_NUM(ROUTE121), 0}, + [MAPSEC_ROUTE_122] = {MAP_GROUP(ROUTE122), MAP_NUM(ROUTE122), 0}, + [MAPSEC_ROUTE_123] = {MAP_GROUP(ROUTE123), MAP_NUM(ROUTE123), 0}, + [MAPSEC_ROUTE_124] = {MAP_GROUP(ROUTE124), MAP_NUM(ROUTE124), 0}, + [MAPSEC_ROUTE_125] = {MAP_GROUP(ROUTE125), MAP_NUM(ROUTE125), 0}, + [MAPSEC_ROUTE_126] = {MAP_GROUP(ROUTE126), MAP_NUM(ROUTE126), 0}, + [MAPSEC_ROUTE_127] = {MAP_GROUP(ROUTE127), MAP_NUM(ROUTE127), 0}, + [MAPSEC_ROUTE_128] = {MAP_GROUP(ROUTE128), MAP_NUM(ROUTE128), 0}, + [MAPSEC_ROUTE_129] = {MAP_GROUP(ROUTE129), MAP_NUM(ROUTE129), 0}, + [MAPSEC_ROUTE_130] = {MAP_GROUP(ROUTE130), MAP_NUM(ROUTE130), 0}, + [MAPSEC_ROUTE_131] = {MAP_GROUP(ROUTE131), MAP_NUM(ROUTE131), 0}, + [MAPSEC_ROUTE_132] = {MAP_GROUP(ROUTE132), MAP_NUM(ROUTE132), 0}, + [MAPSEC_ROUTE_133] = {MAP_GROUP(ROUTE133), MAP_NUM(ROUTE133), 0}, + [MAPSEC_ROUTE_134] = {MAP_GROUP(ROUTE134), MAP_NUM(ROUTE134), 0} }; static const u8 *const sEverGrandeCityNames[] = @@ -2013,7 +2012,7 @@ static void CB_ExitFlyMap(void) if (sMapHealLocations[sFlyMap->regionMap.mapSecId][2] != 0) SetWarpDestinationToHealLocation(sMapHealLocations[sFlyMap->regionMap.mapSecId][2]); else - SetWarpDestinationToMapWarp(sMapHealLocations[sFlyMap->regionMap.mapSecId][0], sMapHealLocations[sFlyMap->regionMap.mapSecId][1], -1); + SetWarpDestinationToMapWarp(sMapHealLocations[sFlyMap->regionMap.mapSecId][0], sMapHealLocations[sFlyMap->regionMap.mapSecId][1], WARP_ID_NONE); break; } ReturnToFieldFromFlyMapSelect(); diff --git a/src/roamer.c b/src/roamer.c index b8d100967..4811ac3b2 100644 --- a/src/roamer.c +++ b/src/roamer.c @@ -3,7 +3,6 @@ #include "pokemon.h" #include "random.h" #include "roamer.h" -#include "constants/maps.h" // Despite having a variable to track it, the roamer is // hard-coded to only ever be in map group 0 diff --git a/src/rotating_gate.c b/src/rotating_gate.c index ea2eec126..23fbb3e1d 100644 --- a/src/rotating_gate.c +++ b/src/rotating_gate.c @@ -5,7 +5,6 @@ #include "fieldmap.h" #include "sound.h" #include "sprite.h" -#include "constants/maps.h" #include "constants/songs.h" #define ROTATING_GATE_TILE_TAG 0x1300 diff --git a/src/save_location.c b/src/save_location.c index b201ca1c0..74d2f2c44 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -1,6 +1,5 @@ #include "global.h" #include "save_location.h" -#include "constants/maps.h" #define LIST_END 0xFFFF diff --git a/src/scrcmd.c b/src/scrcmd.c index 6007fb493..5b7c95e8e 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -49,7 +49,6 @@ #include "tv.h" #include "window.h" #include "constants/event_objects.h" -#include "constants/maps.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); @@ -58,11 +57,11 @@ EWRAM_DATA const u8 *gRamScriptRetAddr = NULL; static EWRAM_DATA u32 sAddressOffset = 0; // For relative addressing in vgoto etc., used by saved scripts (e.g. Mystery Event) static EWRAM_DATA u16 sPauseCounter = 0; static EWRAM_DATA u16 sMovingNpcId = 0; -static EWRAM_DATA u16 sMovingNpcMapBank = 0; -static EWRAM_DATA u16 sMovingNpcMapId = 0; +static EWRAM_DATA u16 sMovingNpcMapGroup = 0; +static EWRAM_DATA u16 sMovingNpcMapNum = 0; static EWRAM_DATA u16 sFieldEffectScriptId = 0; -static u8 gBrailleWindowId; +static u8 sBrailleWindowId; extern const SpecialFunc gSpecials[]; extern const u8 *gStdScripts[]; @@ -610,11 +609,9 @@ bool8 ScrCmd_animateflash(struct ScriptContext *ctx) return TRUE; } -bool8 ScrCmd_setflashradius(struct ScriptContext *ctx) +bool8 ScrCmd_setflashlevel(struct ScriptContext *ctx) { - u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); - - Overworld_SetFlashLevel(flashLevel); + SetFlashLevel(VarGet(ScriptReadHalfword(ctx))); return FALSE; } @@ -668,9 +665,7 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) static bool8 RunPauseTimer(void) { - sPauseCounter--; - - if (sPauseCounter == 0) + if (--sPauseCounter == 0) return TRUE; else return FALSE; @@ -711,13 +706,13 @@ bool8 ScrCmd_setweather(struct ScriptContext *ctx) { u16 weather = VarGet(ScriptReadHalfword(ctx)); - SetSav1Weather(weather); + SetSavedWeather(weather); return FALSE; } bool8 ScrCmd_resetweather(struct ScriptContext *ctx) { - SetSav1WeatherFromCurrMapHeader(); + SetSavedWeatherFromCurrMapHeader(); return FALSE; } @@ -794,7 +789,7 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) if (mapGroup == MAP_GROUP(UNDEFINED) && mapNum == MAP_NUM(UNDEFINED)) SetWarpDestinationToFixedHoleWarp(x - MAP_OFFSET, y - MAP_OFFSET); else - SetWarpDestination(mapGroup, mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET); + SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, x - MAP_OFFSET, y - MAP_OFFSET); DoFallWarp(); ResetInitialPlayerAvatarState(); return TRUE; @@ -945,9 +940,9 @@ bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) bool8 ScrCmd_playbgm(struct ScriptContext *ctx) { u16 songId = ScriptReadHalfword(ctx); - bool8 val = ScriptReadByte(ctx); + bool8 save = ScriptReadByte(ctx); - if (val == TRUE) + if (save == TRUE) Overworld_SetSavedMusic(songId); PlayNewMapMusic(songId); return FALSE; @@ -1018,7 +1013,7 @@ bool8 ScrCmd_applymovement_at(struct ScriptContext *ctx) static bool8 WaitForMovementFinish(void) { - return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); + return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapNum, sMovingNpcMapGroup); } bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) @@ -1027,8 +1022,8 @@ bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) if (localId != 0) sMovingNpcId = localId; - sMovingNpcMapBank = gSaveBlock1Ptr->location.mapGroup; - sMovingNpcMapId = gSaveBlock1Ptr->location.mapNum; + sMovingNpcMapGroup = gSaveBlock1Ptr->location.mapGroup; + sMovingNpcMapNum = gSaveBlock1Ptr->location.mapNum; SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } @@ -1036,15 +1031,15 @@ bool8 ScrCmd_waitmovement(struct ScriptContext *ctx) bool8 ScrCmd_waitmovement_at(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); - u8 mapBank; - u8 mapId; + u8 mapGroup; + u8 mapNum; if (localId != 0) sMovingNpcId = localId; - mapBank = ScriptReadByte(ctx); - mapId = ScriptReadByte(ctx); - sMovingNpcMapBank = mapBank; - sMovingNpcMapId = mapId; + mapGroup = ScriptReadByte(ctx); + mapNum = ScriptReadByte(ctx); + sMovingNpcMapGroup = mapGroup; + sMovingNpcMapNum = mapNum; SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } @@ -1101,7 +1096,7 @@ bool8 ScrCmd_setobjectxyperm(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetObjEventTemplateCoords(localId, x, y); + SetObjEventTemplateCoords(localId, x, y); return FALSE; } @@ -1133,24 +1128,24 @@ bool8 ScrCmd_hideobject_at(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setobjectpriority(struct ScriptContext *ctx) +bool8 ScrCmd_setobjectsubpriority(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); u8 priority = ScriptReadByte(ctx); - SetObjectPriority(localId, mapNum, mapGroup, priority + 83); + SetObjectSubpriority(localId, mapNum, mapGroup, priority + 83); return FALSE; } -bool8 ScrCmd_resetobjectpriority(struct ScriptContext *ctx) +bool8 ScrCmd_resetobjectsubpriority(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - ResetObjectPriority(localId, mapNum, mapGroup); + ResetObjectSubpriority(localId, mapNum, mapGroup); return FALSE; } @@ -1178,7 +1173,7 @@ bool8 ScrCmd_setobjectmovementtype(struct ScriptContext *ctx) u16 localId = VarGet(ScriptReadHalfword(ctx)); u8 movementType = ScriptReadByte(ctx); - Overworld_SetObjEventTemplateMovementType(localId, movementType); + SetObjEventTemplateMovementType(localId, movementType); return FALSE; } @@ -1311,7 +1306,7 @@ bool8 ScrCmd_messageinstant(struct ScriptContext *ctx) msg = (const u8 *)ctx->data[0]; LoadMessageBoxAndBorderGfx(); DrawDialogueFrame(0, 1); - AddTextPrinterParameterized(0, FONT_NORMAL, msg, 0, 1, 0, 0); + AddTextPrinterParameterized(0, FONT_NORMAL, msg, 0, 1, 0, NULL); return FALSE; } @@ -1463,7 +1458,9 @@ bool8 ScrCmd_showmonpic(struct ScriptContext *ctx) bool8 ScrCmd_hidemonpic(struct ScriptContext *ctx) { - bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); + // The hide function returns a pointer to a function + // that returns true once the pic is hidden + bool8 (*func)(void) = ScriptMenu_HidePokemonPic(); if (func == NULL) return FALSE; @@ -1528,13 +1525,13 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) yText = (yText - yWindow - 1) * 8; winTemplate = CreateWindowTemplate(0, xWindow, yWindow + 1, width, height, 0xF, 0x1); - gBrailleWindowId = AddWindow(&winTemplate); - LoadUserWindowBorderGfx(gBrailleWindowId, 0x214, 0xE0); - DrawStdWindowFrame(gBrailleWindowId, 0); - PutWindowTilemap(gBrailleWindowId); - FillWindowPixelBuffer(gBrailleWindowId, PIXEL_FILL(1)); - AddTextPrinterParameterized(gBrailleWindowId, FONT_BRAILLE, gStringVar4, xText, yText, TEXT_SKIP_DRAW, NULL); - CopyWindowToVram(gBrailleWindowId, COPYWIN_FULL); + sBrailleWindowId = AddWindow(&winTemplate); + LoadUserWindowBorderGfx(sBrailleWindowId, 0x214, 0xE0); + DrawStdWindowFrame(sBrailleWindowId, 0); + PutWindowTilemap(sBrailleWindowId); + FillWindowPixelBuffer(sBrailleWindowId, PIXEL_FILL(1)); + AddTextPrinterParameterized(sBrailleWindowId, FONT_BRAILLE, gStringVar4, xText, yText, TEXT_SKIP_DRAW, NULL); + CopyWindowToVram(sBrailleWindowId, COPYWIN_FULL); return FALSE; } @@ -1638,12 +1635,12 @@ bool8 ScrCmd_bufferstdstring(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_buffercontesttype(struct ScriptContext *ctx) +bool8 ScrCmd_buffercontestname(struct ScriptContext *ctx) { u8 stringVarIndex = ScriptReadByte(ctx); - u16 index = VarGet(ScriptReadHalfword(ctx)); + u16 category = VarGet(ScriptReadHalfword(ctx)); - BufferContestName(sScriptStringVars[stringVarIndex], index); + BufferContestName(sScriptStringVars[stringVarIndex], category); return FALSE; } @@ -1933,17 +1930,17 @@ bool8 ScrCmd_setberrytree(struct ScriptContext *ctx) u8 growthStage = ScriptReadByte(ctx); if (berry == 0) - PlantBerryTree(treeId, 0, growthStage, FALSE); + PlantBerryTree(treeId, berry, growthStage, FALSE); else PlantBerryTree(treeId, berry, growthStage, FALSE); return FALSE; } -bool8 ScrCmd_getpricereduction(struct ScriptContext *ctx) +bool8 ScrCmd_getpokenewsactive(struct ScriptContext *ctx) { u16 newsKind = VarGet(ScriptReadHalfword(ctx)); - gSpecialVar_Result = GetPriceReduction(newsKind); + gSpecialVar_Result = IsPokeNewsActive(newsKind); return FALSE; } @@ -1985,7 +1982,7 @@ bool8 ScrCmd_dofieldeffect(struct ScriptContext *ctx) return FALSE; } -bool8 ScrCmd_setfieldeffectarg(struct ScriptContext *ctx) +bool8 ScrCmd_setfieldeffectargument(struct ScriptContext *ctx) { u8 argNum = ScriptReadByte(ctx); @@ -2230,9 +2227,7 @@ bool8 ScrCmd_checkmoneventlegal(struct ScriptContext *ctx) return FALSE; } -// TODO: Should be renamed. Name implies general usage, but its specifically for Wonder Card -// See GetSavedRamScriptIfValid, which is NULL if ValidateSavedWonderCard returns FALSE -bool8 ScrCmd_gotoram(struct ScriptContext *ctx) +bool8 ScrCmd_gotowondercardscript(struct ScriptContext *ctx) { const u8* script = GetSavedRamScriptIfValid(); @@ -2244,7 +2239,7 @@ bool8 ScrCmd_gotoram(struct ScriptContext *ctx) return FALSE; } -// Unused +// This warp is only used by the Union Room. // For the warp used by the Aqua Hideout, see DoTeleportTileWarp bool8 ScrCmd_warpspinenter(struct ScriptContext *ctx) { @@ -2273,8 +2268,8 @@ bool8 ScrCmd_setmonmetlocation(struct ScriptContext *ctx) static void CloseBrailleWindow(void) { - ClearStdWindowAndFrame(gBrailleWindowId, 1); - RemoveWindow(gBrailleWindowId); + ClearStdWindowAndFrame(sBrailleWindowId, 1); + RemoveWindow(sBrailleWindowId); } bool8 ScrCmd_buffertrainerclassname(struct ScriptContext *ctx) diff --git a/src/script.c b/src/script.c index b10e0db49..4728e739c 100644 --- a/src/script.c +++ b/src/script.c @@ -3,7 +3,7 @@ #include "event_data.h" #include "mystery_gift.h" #include "util.h" -#include "constants/maps.h" +#include "constants/event_objects.h" #include "constants/map_scripts.h" #define RAM_SCRIPT_MAGIC 51 @@ -399,6 +399,8 @@ const u8 *GetRamScript(u8 objectId, const u8 *script) } } +#define NO_OBJECT OBJ_EVENT_ID_PLAYER + bool32 ValidateSavedRamScript(void) { struct RamScriptData *scriptData = &gSaveBlock1Ptr->ramScript.data; @@ -408,7 +410,7 @@ bool32 ValidateSavedRamScript(void) return FALSE; if (scriptData->mapNum != MAP_NUM(UNDEFINED)) return FALSE; - if (scriptData->objectId != 0xFF) + if (scriptData->objectId != NO_OBJECT) return FALSE; if (CalculateRamScriptChecksum() != gSaveBlock1Ptr->ramScript.checksum) return FALSE; @@ -426,7 +428,7 @@ u8 *GetSavedRamScriptIfValid(void) return NULL; if (scriptData->mapNum != MAP_NUM(UNDEFINED)) return NULL; - if (scriptData->objectId != 0xFF) + if (scriptData->objectId != NO_OBJECT) return NULL; if (CalculateRamScriptChecksum() != gSaveBlock1Ptr->ramScript.checksum) { @@ -443,5 +445,5 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize) { if (scriptSize > sizeof(gSaveBlock1Ptr->ramScript.data.script)) scriptSize = sizeof(gSaveBlock1Ptr->ramScript.data.script); - InitRamScript(script, scriptSize, MAP_GROUP(UNDEFINED), MAP_NUM(UNDEFINED), 0xFF); + InitRamScript(script, scriptSize, MAP_GROUP(UNDEFINED), MAP_NUM(UNDEFINED), NO_OBJECT); } diff --git a/src/script_menu.c b/src/script_menu.c index ae0fe91e6..1680758f2 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -563,6 +563,7 @@ static void Task_PokemonPicWindow(u8 taskId) task->tState++; break; case 1: + // Wait until state is advanced by ScriptMenu_HidePokemonPic break; case 2: FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId], task->tMonSpriteId); @@ -600,7 +601,7 @@ bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y) } } -bool8 (*ScriptMenu_GetPicboxWaitFunc(void))(void) +bool8 (*ScriptMenu_HidePokemonPic(void))(void) { u8 taskId = FindTaskIdByFunc(Task_PokemonPicWindow); diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index 07e86656e..ae7aa92dc 100755 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -150,7 +150,12 @@ void CreateScriptedWildMon(u16 species, u8 level, u16 item) void ScriptSetMonMoveSlot(u8 monIndex, u16 move, u8 slot) { +// Allows monIndex to go out of bounds of gPlayerParty. Doesn't occur in vanilla +#ifdef BUGFIX + if (monIndex >= PARTY_SIZE) +#else if (monIndex > PARTY_SIZE) +#endif monIndex = gPlayerPartyCount - 1; SetMonMoveSlot(&gPlayerParty[monIndex], move, slot); diff --git a/src/secret_base.c b/src/secret_base.c index 72560ee23..8fc97141f 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -39,7 +39,6 @@ #include "constants/event_objects.h" #include "constants/field_specials.h" #include "constants/items.h" -#include "constants/maps.h" #include "constants/map_types.h" #include "constants/metatile_behaviors.h" #include "constants/metatile_labels.h" @@ -446,7 +445,7 @@ void EnterSecretBase(void) { CreateTask(Task_EnterSecretBase, 0); FadeScreen(FADE_TO_BLACK, 0); - SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); } bool8 SecretBaseMapPopupEnabled(void) @@ -490,7 +489,7 @@ static void Task_EnterNewlyCreatedSecretBase(u8 taskId) SetWarpDestination( gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, - -1, + WARP_ID_NONE, GET_BASE_COMPUTER_X(secretBaseGroup), GET_BASE_COMPUTER_Y(secretBaseGroup)); WarpIntoMap(); @@ -700,7 +699,7 @@ static void Task_WarpOutOfSecretBase(u8 taskId) gTasks[taskId].data[0] = 2; break; case 2: - SetWarpDestinationToDynamicWarp(0x7e); + SetWarpDestinationToDynamicWarp(WARP_ID_SECRET_BASE); WarpIntoMap(); gFieldCallback = FieldCB_DefaultWarpExit; SetMainCallback2(CB2_LoadMap); @@ -1215,108 +1214,107 @@ void SecretBasePerStepCallback(u8 taskId) tState = 1; break; case 1: + // End if player hasn't moved PlayerGetDestCoords(&x, &y); - if (x != tPlayerX || y != tPlayerY) + if (x == tPlayerX && y == tPlayerY) + return; + + tPlayerX = x; + tPlayerY = y; + VarSet(VAR_SECRET_BASE_STEP_COUNTER, VarGet(VAR_SECRET_BASE_STEP_COUNTER) + 1); + behavior = MapGridGetMetatileBehaviorAt(x, y); + tileId = MapGridGetMetatileIdAt(x, y); + if (tileId == METATILE_SecretBase_SolidBoard_Top || tileId == METATILE_SecretBase_SolidBoard_Bottom) { - tPlayerX = x; - tPlayerY = y; - VarSet(VAR_SECRET_BASE_STEP_COUNTER, VarGet(VAR_SECRET_BASE_STEP_COUNTER) + 1); - behavior = MapGridGetMetatileBehaviorAt(x, y); - tileId = MapGridGetMetatileIdAt(x, y); - if (tileId == METATILE_SecretBase_SolidBoard_Top || tileId == METATILE_SecretBase_SolidBoard_Bottom) - { - if (sInFriendSecretBase == TRUE) - { - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SOLID_BOARD); - } - } - else if (tileId == METATILE_SecretBase_SmallChair - || tileId == METATILE_SecretBase_PokemonChair - || tileId == METATILE_SecretBase_HeavyChair - || tileId == METATILE_SecretBase_PrettyChair - || tileId == METATILE_SecretBase_ComfortChair - || tileId == METATILE_SecretBase_RaggedChair - || tileId == METATILE_SecretBase_BrickChair - || tileId == METATILE_SecretBase_CampChair - || tileId == METATILE_SecretBase_HardChair) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_CHAIR); - } - else if (tileId == METATILE_SecretBase_RedTent_DoorTop - || tileId == METATILE_SecretBase_RedTent_Door - || tileId == METATILE_SecretBase_BlueTent_DoorTop - || tileId == METATILE_SecretBase_BlueTent_Door) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_TENT); - } - else if ((behavior == MB_IMPASSABLE_NORTHEAST && tileId == METATILE_SecretBase_Stand_CornerRight) - || (behavior == MB_IMPASSABLE_NORTHWEST && MapGridGetMetatileIdAt(x, y) == METATILE_SecretBase_Stand_CornerLeft)) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_STAND); - } - else if (behavior == MB_IMPASSABLE_WEST_AND_EAST && tileId == METATILE_SecretBase_Slide_StairLanding) - { - if (sInFriendSecretBase == TRUE) - { - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ SECRET_BASE_USED_SLIDE); - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_DECLINED_SLIDE); - } - } - else if (behavior == MB_SLIDE_SOUTH && tileId == METATILE_SecretBase_Slide_SlideTop) + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SOLID_BOARD); + } + else if (tileId == METATILE_SecretBase_SmallChair + || tileId == METATILE_SecretBase_PokemonChair + || tileId == METATILE_SecretBase_HeavyChair + || tileId == METATILE_SecretBase_PrettyChair + || tileId == METATILE_SecretBase_ComfortChair + || tileId == METATILE_SecretBase_RaggedChair + || tileId == METATILE_SecretBase_BrickChair + || tileId == METATILE_SecretBase_CampChair + || tileId == METATILE_SecretBase_HardChair) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_CHAIR); + } + else if (tileId == METATILE_SecretBase_RedTent_DoorTop + || tileId == METATILE_SecretBase_RedTent_Door + || tileId == METATILE_SecretBase_BlueTent_DoorTop + || tileId == METATILE_SecretBase_BlueTent_Door) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_TENT); + } + else if ((behavior == MB_IMPASSABLE_NORTHEAST && tileId == METATILE_SecretBase_Stand_CornerRight) + || (behavior == MB_IMPASSABLE_NORTHWEST && MapGridGetMetatileIdAt(x, y) == METATILE_SecretBase_Stand_CornerLeft)) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_STAND); + } + else if (behavior == MB_IMPASSABLE_WEST_AND_EAST && tileId == METATILE_SecretBase_Slide_StairLanding) + { + if (sInFriendSecretBase == TRUE) { - if (sInFriendSecretBase == TRUE) - { - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SLIDE); - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ SECRET_BASE_DECLINED_SLIDE); - } + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ SECRET_BASE_USED_SLIDE); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_DECLINED_SLIDE); } - else if (MetatileBehavior_IsSecretBaseGlitterMat(behavior) == TRUE) + } + else if (behavior == MB_SLIDE_SOUTH && tileId == METATILE_SecretBase_Slide_SlideTop) + { + if (sInFriendSecretBase == TRUE) { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_GLITTER_MAT); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SLIDE); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ SECRET_BASE_DECLINED_SLIDE); } - else if (MetatileBehavior_IsSecretBaseBalloon(behavior) == TRUE) + } + else if (MetatileBehavior_IsSecretBaseGlitterMat(behavior) == TRUE) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_GLITTER_MAT); + } + else if (MetatileBehavior_IsSecretBaseBalloon(behavior) == TRUE) + { + PopSecretBaseBalloon(MapGridGetMetatileIdAt(x, y), x, y); + if (sInFriendSecretBase == TRUE) { - PopSecretBaseBalloon(MapGridGetMetatileIdAt(x, y), x, y); - if (sInFriendSecretBase == TRUE) + switch ((int)MapGridGetMetatileIdAt(x, y)) { - switch ((int)MapGridGetMetatileIdAt(x, y)) - { - case METATILE_SecretBase_RedBalloon: - case METATILE_SecretBase_BlueBalloon: - case METATILE_SecretBase_YellowBalloon: - VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_BALLOON); - break; - case METATILE_SecretBase_MudBall: - VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_MUD_BALL); - break; - } + case METATILE_SecretBase_RedBalloon: + case METATILE_SecretBase_BlueBalloon: + case METATILE_SecretBase_YellowBalloon: + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_BALLOON); + break; + case METATILE_SecretBase_MudBall: + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_MUD_BALL); + break; } } - else if (MetatileBehavior_IsSecretBaseBreakableDoor(behavior) == TRUE) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_BREAKABLE_DOOR); + } + else if (MetatileBehavior_IsSecretBaseBreakableDoor(behavior) == TRUE) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_BREAKABLE_DOOR); - ShatterSecretBaseBreakableDoor(x, y); - } - else if (MetatileBehavior_IsSecretBaseSoundMat(behavior) == TRUE){ - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_NOTE_MAT); - } - else if (MetatileBehavior_IsSecretBaseJumpMat(behavior) == TRUE) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_JUMP_MAT); - } - else if (MetatileBehavior_IsSecretBaseSpinMat(behavior) == TRUE) - { - if (sInFriendSecretBase == TRUE) - VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SPIN_MAT); - } + ShatterSecretBaseBreakableDoor(x, y); + } + else if (MetatileBehavior_IsSecretBaseSoundMat(behavior) == TRUE){ + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | SECRET_BASE_USED_NOTE_MAT); + } + else if (MetatileBehavior_IsSecretBaseJumpMat(behavior) == TRUE) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_JUMP_MAT); + } + else if (MetatileBehavior_IsSecretBaseSpinMat(behavior) == TRUE) + { + if (sInFriendSecretBase == TRUE) + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | SECRET_BASE_USED_SPIN_MAT); } break; case 2: diff --git a/src/shop.c b/src/shop.c index fa4a73bbb..f6fb2b9a0 100755 --- a/src/shop.c +++ b/src/shop.c @@ -562,7 +562,7 @@ static void BuyMenuPrintPriceInList(u8 windowId, u32 itemId, u8 y) { ConvertIntToDecimalStringN( gStringVar1, - ItemId_GetPrice(itemId) >> GetPriceReduction(POKENEWS_SLATEPORT), + ItemId_GetPrice(itemId) >> IsPokeNewsActive(POKENEWS_SLATEPORT), STR_CONV_MODE_LEFT_ALIGN, 5); } @@ -934,7 +934,7 @@ static void Task_BuyMenu(u8 taskId) if (sMartInfo.martType == MART_TYPE_NORMAL) { - sShopData->totalCost = (ItemId_GetPrice(itemId) >> GetPriceReduction(POKENEWS_SLATEPORT)); + sShopData->totalCost = (ItemId_GetPrice(itemId) >> IsPokeNewsActive(POKENEWS_SLATEPORT)); } else { @@ -1014,7 +1014,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) if (AdjustQuantityAccordingToDPadInput(&tItemCount, sShopData->maxQuantity) == TRUE) { - sShopData->totalCost = (ItemId_GetPrice(tItemId) >> GetPriceReduction(POKENEWS_SLATEPORT)) * tItemCount; + sShopData->totalCost = (ItemId_GetPrice(tItemId) >> IsPokeNewsActive(POKENEWS_SLATEPORT)) * tItemCount; BuyMenuPrintItemQuantityAndPrice(taskId); } else diff --git a/src/slot_machine.c b/src/slot_machine.c index 1c21f230d..6cbcd76fd 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -557,10 +557,10 @@ static struct SpriteFrameImage *sImageTables_DigitalDisplay[NUM_DIG_DISPLAY_SPRI // Const rom data. static const struct DigitalDisplaySprite *const sDigitalDisplayScenes[]; static const u16 sUnkPalette[]; -static const u8 sLuckyRoundProbabilities[][3]; +static const u8 sLuckyRoundProbabilities[NUM_SLOT_MACHINE_IDS][MAX_BET]; static const u8 sBiasTags[]; -static const u16 sLuckyFlagSettings_Top3[]; -static const u16 sLuckyFlagSettings_NotTop3[]; +static const u16 sLuckyFlagSettings_Top3[3]; +static const u16 sLuckyFlagSettings_NotTop3[5]; static const s16 sDigitalDisplay_SpriteCoords[][2]; static const SpriteCallback sDigitalDisplay_SpriteCallbacks[]; static const struct SpriteTemplate *const sSpriteTemplates_DigitalDisplay[NUM_DIG_DISPLAY_SPRITES]; @@ -582,8 +582,8 @@ static const struct SpriteSheet sSlotMachineSpriteSheets[22]; static const struct SpritePalette sSlotMachineSpritePalettes[]; static const u16 *const sDigitalDisplay_Pal; static const s16 sInitialReelPositions[NUM_REELS][2]; -static const u8 sLuckyFlagProbabilities_Top3[][6]; -static const u8 sLuckyFlagProbabilities_NotTop3[][6]; +static const u8 sLuckyFlagProbabilities_Top3[][NUM_SLOT_MACHINE_IDS]; +static const u8 sLuckyFlagProbabilities_NotTop3[][NUM_SLOT_MACHINE_IDS]; static const u8 sReeltimeProbabilities_UnluckyGame[][17]; static const u8 sReelTimeProbabilities_LuckyGame[][17]; static const u8 sSymToMatch[]; @@ -1651,22 +1651,18 @@ static void DrawLuckyFlags(void) if (IsThisRoundLucky()) { attempts = AttemptsAtLuckyFlags_Top3(); - if (attempts != 3) // if you found a lucky number + if (attempts != ARRAY_COUNT(sLuckyFlagSettings_Top3)) // if you found a lucky number { // attempts == 1: reelTime flag set sSlotMachine->luckyFlags |= sLuckyFlagSettings_Top3[attempts]; if (attempts != 1) - { return; - } } } // if it's not a lucky round or you got reel time, roll for the lower lucky flags attempts = AttemptsAtLuckyFlags_NotTop3(); - if (attempts != 5) // if you found a lucky number - { + if (attempts != ARRAY_COUNT(sLuckyFlagSettings_NotTop3)) // if you found a lucky number sSlotMachine->luckyFlags |= sLuckyFlagSettings_NotTop3[attempts]; - } } } } @@ -1704,7 +1700,7 @@ static u8 AttemptsAtLuckyFlags_Top3(void) { s16 count; - for (count = 0; count < 3; count++) + for (count = 0; count < (int)ARRAY_COUNT(sLuckyFlagSettings_Top3); count++) { s16 rval = Random() & 0xff; s16 value = sLuckyFlagProbabilities_Top3[count][sSlotMachine->machineId]; @@ -1718,7 +1714,7 @@ static u8 AttemptsAtLuckyFlags_NotTop3(void) { s16 count; - for (count = 0; count < 5; count++) + for (count = 0; count < (int)ARRAY_COUNT(sLuckyFlagSettings_NotTop3); count++) { s16 rval = Random() & 0xff; // random byte s16 value = sLuckyFlagProbabilities_NotTop3[count][sSlotMachine->machineId]; @@ -4807,27 +4803,83 @@ static const s16 sInitialReelPositions[NUM_REELS][2] = { [RIGHT_REEL] = {0, 2} }; -static const u8 sLuckyRoundProbabilities[][3] = { - {1, 1, 12}, - {1, 1, 14}, - {2, 2, 14}, - {2, 2, 14}, - {2, 3, 16}, - {3, 3, 16} +static const u8 sLuckyRoundProbabilities[NUM_SLOT_MACHINE_IDS][MAX_BET] = { + [SLOT_MACHINE_UNLUCKIEST] = {1, 1, 12}, + [SLOT_MACHINE_UNLUCKIER] = {1, 1, 14}, + [SLOT_MACHINE_UNLUCKY] = {2, 2, 14}, + [SLOT_MACHINE_LUCKY] = {2, 2, 14}, + [SLOT_MACHINE_LUCKIER] = {2, 3, 16}, + [SLOT_MACHINE_LUCKIEST] = {3, 3, 16} }; -static const u8 sLuckyFlagProbabilities_Top3[][6] = { - {25, 25, 30, 40, 40, 50}, - {25, 25, 30, 30, 35, 35}, - {25, 25, 30, 25, 25, 30} -}; - -static const u8 sLuckyFlagProbabilities_NotTop3[][6] = { - {20, 25, 25, 20, 25, 25}, - {12, 15, 15, 18, 19, 22}, - {25, 25, 25, 30, 30, 40}, - {25, 25, 20, 20, 15, 15}, - {40, 40, 35, 35, 40, 40} +static const u8 sLuckyFlagProbabilities_Top3[][NUM_SLOT_MACHINE_IDS] = { + { // Probabilities for LUCKY_BIAS_777 + [SLOT_MACHINE_UNLUCKIEST] = 25, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 30, + [SLOT_MACHINE_LUCKY] = 40, + [SLOT_MACHINE_LUCKIER] = 40, + [SLOT_MACHINE_LUCKIEST] = 50 + }, + { // Probabilities for LUCKY_BIAS_REELTIME + [SLOT_MACHINE_UNLUCKIEST] = 25, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 30, + [SLOT_MACHINE_LUCKY] = 30, + [SLOT_MACHINE_LUCKIER] = 35, + [SLOT_MACHINE_LUCKIEST] = 35 + }, + { // Probabilities for LUCKY_BIAS_MIXED_777 + [SLOT_MACHINE_UNLUCKIEST] = 25, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 30, + [SLOT_MACHINE_LUCKY] = 25, + [SLOT_MACHINE_LUCKIER] = 25, + [SLOT_MACHINE_LUCKIEST] = 30 + } +}; + +static const u8 sLuckyFlagProbabilities_NotTop3[][NUM_SLOT_MACHINE_IDS] = { + { // Probabilities for LUCKY_BIAS_POWER + [SLOT_MACHINE_UNLUCKIEST] = 20, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 25, + [SLOT_MACHINE_LUCKY] = 20, + [SLOT_MACHINE_LUCKIER] = 25, + [SLOT_MACHINE_LUCKIEST] = 25 + }, + { // Probabilities for LUCKY_BIAS_AZURILL + [SLOT_MACHINE_UNLUCKIEST] = 12, + [SLOT_MACHINE_UNLUCKIER] = 15, + [SLOT_MACHINE_UNLUCKY] = 15, + [SLOT_MACHINE_LUCKY] = 18, + [SLOT_MACHINE_LUCKIER] = 19, + [SLOT_MACHINE_LUCKIEST] = 22 + }, + { // Probabilities for LUCKY_BIAS_LOTAD + [SLOT_MACHINE_UNLUCKIEST] = 25, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 25, + [SLOT_MACHINE_LUCKY] = 30, + [SLOT_MACHINE_LUCKIER] = 30, + [SLOT_MACHINE_LUCKIEST] = 40 + }, + { // Probabilities for LUCKY_BIAS_CHERRY + [SLOT_MACHINE_UNLUCKIEST] = 25, + [SLOT_MACHINE_UNLUCKIER] = 25, + [SLOT_MACHINE_UNLUCKY] = 20, + [SLOT_MACHINE_LUCKY] = 20, + [SLOT_MACHINE_LUCKIER] = 15, + [SLOT_MACHINE_LUCKIEST] = 15 + }, + { // Probabilities for LUCKY_BIAS_REPLAY + [SLOT_MACHINE_UNLUCKIEST] = 40, + [SLOT_MACHINE_UNLUCKIER] = 40, + [SLOT_MACHINE_UNLUCKY] = 35, + [SLOT_MACHINE_LUCKY] = 35, + [SLOT_MACHINE_LUCKIER] = 40, + [SLOT_MACHINE_LUCKIEST] = 40 + } }; static const u8 sReeltimeProbabilities_UnluckyGame[][17] = { @@ -5708,7 +5760,7 @@ static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Insert = static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Stop = { - .tileTag = 18, + .tileTag = GFXTAG_STOP, .paletteTag = PALTAG_DIG_DISPLAY, .oam = &sOam_8x8, .anims = sAnims_SingleFrame, @@ -5741,7 +5793,7 @@ static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Lose = static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Bonus = { - .tileTag = 19, + .tileTag = GFXTAG_BONUS, .paletteTag = PALTAG_DIG_DISPLAY, .oam = &sOam_8x8, .anims = sAnims_SingleFrame, @@ -5752,7 +5804,7 @@ static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Bonus = static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Big = { - .tileTag = 20, + .tileTag = GFXTAG_BIG, .paletteTag = PALTAG_DIG_DISPLAY, .oam = &sOam_8x8, .anims = sAnims_SingleFrame, @@ -5763,7 +5815,7 @@ static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Big = static const struct SpriteTemplate sSpriteTemplate_DigitalDisplay_Reg = { - .tileTag = 21, + .tileTag = GFXTAG_REG, .paletteTag = PALTAG_DIG_DISPLAY, .oam = &sOam_8x8, .anims = sAnims_SingleFrame, diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 2c34f196e..04312a2dd 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -28,7 +28,6 @@ #include "constants/items.h" #include "constants/layouts.h" #include "constants/moves.h" -#include "constants/maps.h" #include "constants/trainers.h" #include "constants/easy_chat.h" #include "constants/trainer_hill.h" @@ -36,11 +36,11 @@ #include "data.h" #include "constants/battle_frontier.h" #include "constants/contest.h" +#include "constants/decorations.h" #include "constants/event_objects.h" #include "constants/items.h" #include "constants/layouts.h" #include "constants/lilycove_lady.h" -#include "constants/maps.h" #include "constants/metatile_behaviors.h" #include "constants/metatile_labels.h" #include "constants/moves.h" @@ -140,13 +140,13 @@ static void TryPutRandomPokeNewsOnAir(void); static void SortPurchasesByQuantity(void); static void UpdateMassOutbreakTimeLeft(u16); static void TryEndMassOutbreak(u16); -static void UpdatePokeNewsTimeLeft(u16); +static void UpdatePokeNewsCountdown(u16); static void ResolveWorldOfMastersShow(u16); static void ResolveNumberOneShow(u16); static void TryPutFishingAdviceOnAir(void); static u8 MonDataIdxToRibbon(u8); static void TryPutNumberOneOnAir(u8); -static bool8 IsPriceDiscounted(u8); +static bool8 ShouldApplyPokeNewsEffect(u8); static void TryPutWorldOfMastersOnAir(void); static void InterviewBefore_FanClubLetter(void); static void InterviewBefore_RecentHappenings(void); @@ -228,24 +228,24 @@ static const struct { } }; -static const u16 sGoldSymbolFlags[] = { - FLAG_SYS_TOWER_GOLD, - FLAG_SYS_DOME_GOLD, - FLAG_SYS_PALACE_GOLD, - FLAG_SYS_ARENA_GOLD, - FLAG_SYS_FACTORY_GOLD, - FLAG_SYS_PIKE_GOLD, - FLAG_SYS_PYRAMID_GOLD +static const u16 sGoldSymbolFlags[NUM_FRONTIER_FACILITIES] = { + [FRONTIER_FACILITY_TOWER] = FLAG_SYS_TOWER_GOLD, + [FRONTIER_FACILITY_DOME] = FLAG_SYS_DOME_GOLD, + [FRONTIER_FACILITY_PALACE] = FLAG_SYS_PALACE_GOLD, + [FRONTIER_FACILITY_ARENA] = FLAG_SYS_ARENA_GOLD, + [FRONTIER_FACILITY_FACTORY] = FLAG_SYS_FACTORY_GOLD, + [FRONTIER_FACILITY_PIKE] = FLAG_SYS_PIKE_GOLD, + [FRONTIER_FACILITY_PYRAMID] = FLAG_SYS_PYRAMID_GOLD }; -static const u16 sSilverSymbolFlags[] = { - FLAG_SYS_TOWER_SILVER, - FLAG_SYS_DOME_SILVER, - FLAG_SYS_PALACE_SILVER, - FLAG_SYS_ARENA_SILVER, - FLAG_SYS_FACTORY_SILVER, - FLAG_SYS_PIKE_SILVER, - FLAG_SYS_PYRAMID_SILVER +static const u16 sSilverSymbolFlags[NUM_FRONTIER_FACILITIES] = { + [FRONTIER_FACILITY_TOWER] = FLAG_SYS_TOWER_SILVER, + [FRONTIER_FACILITY_DOME] = FLAG_SYS_DOME_SILVER, + [FRONTIER_FACILITY_PALACE] = FLAG_SYS_PALACE_SILVER, + [FRONTIER_FACILITY_ARENA] = FLAG_SYS_ARENA_SILVER, + [FRONTIER_FACILITY_FACTORY] = FLAG_SYS_FACTORY_SILVER, + [FRONTIER_FACILITY_PIKE] = FLAG_SYS_PIKE_SILVER, + [FRONTIER_FACILITY_PYRAMID] = FLAG_SYS_PYRAMID_SILVER }; static const u16 sNumberOneVarsAndThresholds[][2] = { @@ -258,28 +258,28 @@ static const u16 sNumberOneVarsAndThresholds[][2] = { {VAR_DAILY_BP, 30} }; -static const u8 *const sPokeNewsTextGroup_Upcoming[] = { - NULL, - gPokeNewsTextSlateport_Upcoming, - gPokeNewsTextGameCorner_Upcoming, - gPokeNewsTextLilycove_Upcoming, - gPokeNewsTextBlendMaster_Upcoming +static const u8 *const sPokeNewsTextGroup_Upcoming[NUM_POKENEWS_TYPES + 1] = { + [POKENEWS_NONE] = NULL, + [POKENEWS_SLATEPORT] = gPokeNewsTextSlateport_Upcoming, + [POKENEWS_GAME_CORNER] = gPokeNewsTextGameCorner_Upcoming, + [POKENEWS_LILYCOVE] = gPokeNewsTextLilycove_Upcoming, + [POKENEWS_BLENDMASTER] = gPokeNewsTextBlendMaster_Upcoming }; -static const u8 *const sPokeNewsTextGroup_Ongoing[] = { - NULL, - gPokeNewsTextSlateport_Ongoing, - gPokeNewsTextGameCorner_Ongoing, - gPokeNewsTextLilycove_Ongoing, - gPokeNewsTextBlendMaster_Ongoing +static const u8 *const sPokeNewsTextGroup_Ongoing[NUM_POKENEWS_TYPES + 1] = { + [POKENEWS_NONE] = NULL, + [POKENEWS_SLATEPORT] = gPokeNewsTextSlateport_Ongoing, + [POKENEWS_GAME_CORNER] = gPokeNewsTextGameCorner_Ongoing, + [POKENEWS_LILYCOVE] = gPokeNewsTextLilycove_Ongoing, + [POKENEWS_BLENDMASTER] = gPokeNewsTextBlendMaster_Ongoing }; -static const u8 *const sPokeNewsTextGroup_Ending[] = { - NULL, - gPokeNewsTextSlateport_Ending, - gPokeNewsTextGameCorner_Ending, - gPokeNewsTextLilycove_Ending, - gPokeNewsTextBlendMaster_Ending +static const u8 *const sPokeNewsTextGroup_Ending[NUM_POKENEWS_TYPES + 1] = { + [POKENEWS_NONE] = NULL, + [POKENEWS_SLATEPORT] = gPokeNewsTextSlateport_Ending, + [POKENEWS_GAME_CORNER] = gPokeNewsTextGameCorner_Ending, + [POKENEWS_LILYCOVE] = gPokeNewsTextLilycove_Ending, + [POKENEWS_BLENDMASTER] = gPokeNewsTextBlendMaster_Ending }; u8 *const gTVStringVarPtrs[] = { @@ -1526,7 +1526,7 @@ void TryPutSmartShopperOnAir(void) show->smartshopperShow.itemIds[i] = gMartPurchaseHistory[i].itemId; show->smartshopperShow.itemAmounts[i] = gMartPurchaseHistory[i].quantity; } - show->smartshopperShow.priceReduced = GetPriceReduction(POKENEWS_SLATEPORT); + show->smartshopperShow.priceReduced = IsPokeNewsActive(POKENEWS_SLATEPORT); StringCopy(show->smartshopperShow.playerName, gSaveBlock2Ptr->playerName); StorePlayerIdInRecordMixShow(show); show->smartshopperShow.language = gGameLanguage; @@ -1569,13 +1569,13 @@ void StartMassOutbreak(void) gSaveBlock1Ptr->outbreakLocationMapNum = show->massOutbreak.locationMapNum; gSaveBlock1Ptr->outbreakLocationMapGroup = show->massOutbreak.locationMapGroup; gSaveBlock1Ptr->outbreakPokemonLevel = show->massOutbreak.level; - gSaveBlock1Ptr->outbreakUnk1 = show->massOutbreak.var02; - gSaveBlock1Ptr->outbreakUnk2 = show->massOutbreak.var0E; + gSaveBlock1Ptr->outbreakUnused1 = show->massOutbreak.unused1; + gSaveBlock1Ptr->outbreakUnused2 = show->massOutbreak.unused2; gSaveBlock1Ptr->outbreakPokemonMoves[0] = show->massOutbreak.moves[0]; gSaveBlock1Ptr->outbreakPokemonMoves[1] = show->massOutbreak.moves[1]; gSaveBlock1Ptr->outbreakPokemonMoves[2] = show->massOutbreak.moves[2]; gSaveBlock1Ptr->outbreakPokemonMoves[3] = show->massOutbreak.moves[3]; - gSaveBlock1Ptr->outbreakUnk4 = show->massOutbreak.var03; + gSaveBlock1Ptr->outbreakUnused3 = show->massOutbreak.unused3; gSaveBlock1Ptr->outbreakPokemonProbability = show->massOutbreak.probability; gSaveBlock1Ptr->outbreakDaysLeft = 2; } @@ -1668,19 +1668,19 @@ static void TryStartRandomMassOutbreak(void) show->massOutbreak.kind = TVSHOW_MASS_OUTBREAK; show->massOutbreak.active = TRUE; show->massOutbreak.level = sPokeOutbreakSpeciesList[outbreakIdx].level; - show->massOutbreak.var02 = 0; - show->massOutbreak.var03 = 0; + show->massOutbreak.unused1 = 0; + show->massOutbreak.unused3 = 0; show->massOutbreak.species = sPokeOutbreakSpeciesList[outbreakIdx].species; - show->massOutbreak.var0E = 0; + show->massOutbreak.unused2 = 0; show->massOutbreak.moves[0] = sPokeOutbreakSpeciesList[outbreakIdx].moves[0]; show->massOutbreak.moves[1] = sPokeOutbreakSpeciesList[outbreakIdx].moves[1]; show->massOutbreak.moves[2] = sPokeOutbreakSpeciesList[outbreakIdx].moves[2]; show->massOutbreak.moves[3] = sPokeOutbreakSpeciesList[outbreakIdx].moves[3]; show->massOutbreak.locationMapNum = sPokeOutbreakSpeciesList[outbreakIdx].location; show->massOutbreak.locationMapGroup = 0; - show->massOutbreak.var12 = 0; + show->massOutbreak.unused4 = 0; show->massOutbreak.probability = 50; - show->massOutbreak.var15 = 0; + show->massOutbreak.unused5 = 0; show->massOutbreak.daysLeft = 1; StorePlayerIdInNormalShow(show); show->massOutbreak.language = gGameLanguage; @@ -1695,13 +1695,13 @@ void EndMassOutbreak(void) gSaveBlock1Ptr->outbreakLocationMapNum = 0; gSaveBlock1Ptr->outbreakLocationMapGroup = 0; gSaveBlock1Ptr->outbreakPokemonLevel = 0; - gSaveBlock1Ptr->outbreakUnk1 = 0; - gSaveBlock1Ptr->outbreakUnk2 = 0; + gSaveBlock1Ptr->outbreakUnused1 = 0; + gSaveBlock1Ptr->outbreakUnused2 = 0; gSaveBlock1Ptr->outbreakPokemonMoves[0] = MOVE_NONE; gSaveBlock1Ptr->outbreakPokemonMoves[1] = MOVE_NONE; gSaveBlock1Ptr->outbreakPokemonMoves[2] = MOVE_NONE; gSaveBlock1Ptr->outbreakPokemonMoves[3] = MOVE_NONE; - gSaveBlock1Ptr->outbreakUnk4 = 0; + gSaveBlock1Ptr->outbreakUnused3 = 0; gSaveBlock1Ptr->outbreakPokemonProbability = 0; gSaveBlock1Ptr->outbreakDaysLeft = 0; } @@ -1710,7 +1710,7 @@ void UpdateTVShowsPerDay(u16 days) { UpdateMassOutbreakTimeLeft(days); TryEndMassOutbreak(days); - UpdatePokeNewsTimeLeft(days); + UpdatePokeNewsCountdown(days); ResolveWorldOfMastersShow(days); ResolveNumberOneShow(days); } @@ -1798,9 +1798,7 @@ void SetPokemonAnglerSpecies(u16 species) // Either way the temporary version of the show in the last slot is deleted. static void ResolveWorldOfMastersShow(u16 days) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; + TVShow *show = &gSaveBlock1Ptr->tvShows[LAST_TVSHOW_IDX]; if (show->worldOfMasters.kind == TVSHOW_WORLD_OF_MASTERS) { if (show->worldOfMasters.numPokeCaught >= 20) @@ -1864,7 +1862,7 @@ void TryPutTodaysRivalTrainerOnAir(void) show->rivalTrainer.mapLayoutId = gMapHeader.mapLayoutId; show->rivalTrainer.nSilverSymbols = 0; show->rivalTrainer.nGoldSymbols = 0; - for (i = 0; i < 7; i++) + for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) { if (FlagGet(sSilverSymbolFlags[i]) == TRUE) show->rivalTrainer.nSilverSymbols++; @@ -1990,33 +1988,39 @@ static void SecretBaseVisit_CalculateDecorationData(TVShow *show) u8 decoration; for (i = 0; i < DECOR_MAX_SECRET_BASE; i++) - sTV_DecorationsBuffer[i] = 0; + sTV_DecorationsBuffer[i] = DECOR_NONE; + // Count (and save) the unique decorations in the base for (i = 0, n = 0; i < DECOR_MAX_SECRET_BASE; i++) { decoration = gSaveBlock1Ptr->secretBases[0].decorations[i]; - if (decoration) + if (decoration != DECOR_NONE) { + // Search for an empty spot to save decoration for (j = 0; j < DECOR_MAX_SECRET_BASE; j++) { - if (sTV_DecorationsBuffer[j] == 0) + if (sTV_DecorationsBuffer[j] == DECOR_NONE) { + // Save and count new unique decoration sTV_DecorationsBuffer[j] = decoration; n++; break; } + + // Decoration has already been saved, skip and move on to the next base decoration if (sTV_DecorationsBuffer[j] == decoration) break; } } } - if (n > 4) - show->secretBaseVisit.nDecorations = 4; + // Cap the number of unique decorations to the number the TV show will talk about + if (n > ARRAY_COUNT(show->secretBaseVisit.decorations)) + show->secretBaseVisit.numDecorations = ARRAY_COUNT(show->secretBaseVisit.decorations); else - show->secretBaseVisit.nDecorations = n; + show->secretBaseVisit.numDecorations = n; - switch (show->secretBaseVisit.nDecorations) + switch (show->secretBaseVisit.numDecorations) { case 0: break; @@ -2024,16 +2028,16 @@ static void SecretBaseVisit_CalculateDecorationData(TVShow *show) show->secretBaseVisit.decorations[0] = sTV_DecorationsBuffer[0]; break; default: + // More than 1 decoration, randomize the full list for (k = 0; k < n * n; k++) { decoration = Random() % n; j = Random() % n; - i = sTV_DecorationsBuffer[decoration]; - sTV_DecorationsBuffer[decoration] = sTV_DecorationsBuffer[j]; - sTV_DecorationsBuffer[j] = i; + SWAP(sTV_DecorationsBuffer[decoration], sTV_DecorationsBuffer[j], i); } - for (i = 0; i < show->secretBaseVisit.nDecorations; i++) + // Pick the first decorations in the randomized list to talk about on the show + for (i = 0; i < show->secretBaseVisit.numDecorations; i++) show->secretBaseVisit.decorations[i] = sTV_DecorationsBuffer[i]; break; } @@ -2044,50 +2048,55 @@ static void SecretBaseVisit_CalculatePartyData(TVShow *show) u8 i; u16 move; u16 j; - u8 nMoves; - u8 nPokemon; + u8 numMoves; + u8 numPokemon; u16 sum; - for (i = 0, nPokemon = 0; i < PARTY_SIZE; i++) + for (i = 0, numPokemon = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { - sTV_SecretBaseVisitMonsTemp[nPokemon].level = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); - sTV_SecretBaseVisitMonsTemp[nPokemon].species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); - nMoves = 0; + sTV_SecretBaseVisitMonsTemp[numPokemon].level = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); + sTV_SecretBaseVisitMonsTemp[numPokemon].species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); + + // Check all the Pokémon's moves, then randomly select one to save + numMoves = 0; move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE1); if (move != MOVE_NONE) { - sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves++; + sTV_SecretBaseVisitMovesTemp[numMoves] = move; + numMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE2); if (move != MOVE_NONE) { - sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves++; + sTV_SecretBaseVisitMovesTemp[numMoves] = move; + numMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE3); if (move != MOVE_NONE) { - sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves++; + sTV_SecretBaseVisitMovesTemp[numMoves] = move; + numMoves++; } move = GetMonData(&gPlayerParty[i], MON_DATA_MOVE4); if (move != MOVE_NONE) { - sTV_SecretBaseVisitMovesTemp[nMoves] = move; - nMoves++; + sTV_SecretBaseVisitMovesTemp[numMoves] = move; + numMoves++; } - sTV_SecretBaseVisitMonsTemp[nPokemon].move = sTV_SecretBaseVisitMovesTemp[Random() % nMoves]; - nPokemon++; + sTV_SecretBaseVisitMonsTemp[numPokemon].move = sTV_SecretBaseVisitMovesTemp[Random() % numMoves]; + numPokemon++; } } - for (i = 0, sum = 0; i < nPokemon; i++) + + for (i = 0, sum = 0; i < numPokemon; i++) sum += sTV_SecretBaseVisitMonsTemp[i].level; - show->secretBaseVisit.avgLevel = sum / nPokemon; - j = Random() % nPokemon; + // Using the data calculated above, save the data to talk about on the show + // (average level, and one randomly selected species / move) + show->secretBaseVisit.avgLevel = sum / numPokemon; + j = Random() % numPokemon; show->secretBaseVisit.species = sTV_SecretBaseVisitMonsTemp[j].species; show->secretBaseVisit.move = sTV_SecretBaseVisitMonsTemp[j].move; } @@ -2225,7 +2234,7 @@ void TryPutBattleSeminarOnAir(u16 foeSpecies, u16 species, u8 moveIdx, const u16 } } -void TryPutSafariFanClubOnAir(u8 nMonsCaught, u8 nPkblkUsed) +void TryPutSafariFanClubOnAir(u8 monsCaught, u8 pokeblocksUsed) { TVShow *show; @@ -2236,8 +2245,8 @@ void TryPutSafariFanClubOnAir(u8 nMonsCaught, u8 nPkblkUsed) show->safariFanClub.kind = TVSHOW_SAFARI_FAN_CLUB; show->safariFanClub.active = FALSE; // NOTE: Show is not active until passed via Record Mix. StringCopy(show->safariFanClub.playerName, gSaveBlock2Ptr->playerName); - show->safariFanClub.nMonsCaught = nMonsCaught; - show->safariFanClub.nPkblkUsed = nPkblkUsed; + show->safariFanClub.monsCaught = monsCaught; + show->safariFanClub.pokeblocksUsed = pokeblocksUsed; StorePlayerIdInRecordMixShow(show); show->safariFanClub.language = gGameLanguage; } @@ -2537,12 +2546,12 @@ static void TryPutRandomPokeNewsOnAir(void) sCurTVShowSlot = GetFirstEmptyPokeNewsSlot(gSaveBlock1Ptr->pokeNews); if (sCurTVShowSlot != -1 && rbernoulli(1, 100) != TRUE) { - u8 newsKind = (Random() % NUM_POKENEWS_TYPES) + POKENEWS_SLATEPORT; + u8 newsKind = (Random() % NUM_POKENEWS_TYPES) + 1; // +1 to skip over POKENEWS_NONE if (IsAddingPokeNewsDisallowed(newsKind) != TRUE) { gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].kind = newsKind; - gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].days = 4; - gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].state = 1; + gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].dayCountdown = POKENEWS_COUNTDOWN; + gSaveBlock1Ptr->pokeNews[sCurTVShowSlot].state = POKENEWS_STATE_UPCOMING; } } } @@ -2571,8 +2580,8 @@ static void ClearPokeNews(void) static void ClearPokeNewsBySlot(u8 i) { gSaveBlock1Ptr->pokeNews[i].kind = POKENEWS_NONE; - gSaveBlock1Ptr->pokeNews[i].state = FALSE; - gSaveBlock1Ptr->pokeNews[i].days = 0; + gSaveBlock1Ptr->pokeNews[i].state = POKENEWS_STATE_INACTIVE; + gSaveBlock1Ptr->pokeNews[i].dayCountdown = 0; } static void CompactPokeNews(void) @@ -2604,8 +2613,8 @@ static u8 FindAnyPokeNewsOnTheAir(void) for (i = 0; i < POKE_NEWS_COUNT; i++) { if (gSaveBlock1Ptr->pokeNews[i].kind != POKENEWS_NONE - && gSaveBlock1Ptr->pokeNews[i].state == 1 - && gSaveBlock1Ptr->pokeNews[i].days < 3) + && gSaveBlock1Ptr->pokeNews[i].state == POKENEWS_STATE_UPCOMING + && gSaveBlock1Ptr->pokeNews[i].dayCountdown < POKENEWS_COUNTDOWN - 1) return i; } return 0xFF; @@ -2613,19 +2622,17 @@ static u8 FindAnyPokeNewsOnTheAir(void) void DoPokeNews(void) { - u8 i; - u16 n; - - i = FindAnyPokeNewsOnTheAir(); + u8 i = FindAnyPokeNewsOnTheAir(); if (i == 0xFF) { gSpecialVar_Result = FALSE; } else { - if (gSaveBlock1Ptr->pokeNews[i].days == 0) + if (gSaveBlock1Ptr->pokeNews[i].dayCountdown == 0) { - gSaveBlock1Ptr->pokeNews[i].state = 2; + // News event is occurring, make comment depending on how much time is left + gSaveBlock1Ptr->pokeNews[i].state = POKENEWS_STATE_ACTIVE; if (gLocalTime.hours < 20) ShowFieldMessage(sPokeNewsTextGroup_Ongoing[gSaveBlock1Ptr->pokeNews[i].kind]); else @@ -2633,16 +2640,20 @@ void DoPokeNews(void) } else { - n = gSaveBlock1Ptr->pokeNews[i].days; - ConvertIntToDecimalStringN(gStringVar1, n, STR_CONV_MODE_LEFT_ALIGN, 1); - gSaveBlock1Ptr->pokeNews[i].state = 0; + // News event is upcoming, make comment about countdown to event + u16 dayCountdown = gSaveBlock1Ptr->pokeNews[i].dayCountdown; + ConvertIntToDecimalStringN(gStringVar1, dayCountdown, STR_CONV_MODE_LEFT_ALIGN, 1); + + // Mark as inactive so the countdown TV airing doesn't repeat + // Will be flagged as "upcoming" again by UpdatePokeNewsCountdown + gSaveBlock1Ptr->pokeNews[i].state = POKENEWS_STATE_INACTIVE; ShowFieldMessage(sPokeNewsTextGroup_Upcoming[gSaveBlock1Ptr->pokeNews[i].kind]); } gSpecialVar_Result = TRUE; } } -bool8 GetPriceReduction(u8 newsKind) +bool8 IsPokeNewsActive(u8 newsKind) { u8 i; @@ -2653,7 +2664,7 @@ bool8 GetPriceReduction(u8 newsKind) { if (gSaveBlock1Ptr->pokeNews[i].kind == newsKind) { - if (gSaveBlock1Ptr->pokeNews[i].state == 2 && IsPriceDiscounted(newsKind)) + if (gSaveBlock1Ptr->pokeNews[i].state == POKENEWS_STATE_ACTIVE && ShouldApplyPokeNewsEffect(newsKind)) return TRUE; return FALSE; @@ -2662,16 +2673,23 @@ bool8 GetPriceReduction(u8 newsKind) return FALSE; } -static bool8 IsPriceDiscounted(u8 newsKind) +// Returns TRUE if the effects of the given PokeNews should be applied. +// For POKENEWS_SLATEPORT / POKENEWS_LILYCOVE, only apply the effect if +// the player is talking to the Energy Guru / at the Dept Store Rooftop. +// For any other type of PokeNews this is always TRUE. +static bool8 ShouldApplyPokeNewsEffect(u8 newsKind) { switch (newsKind) { case POKENEWS_SLATEPORT: - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SLATEPORT_CITY) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SLATEPORT_CITY) && gSpecialVar_LastTalked == 25) + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SLATEPORT_CITY) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SLATEPORT_CITY) + && gSpecialVar_LastTalked == LOCALID_SLATEPORT_ENERGY_GURU) return TRUE; return FALSE; case POKENEWS_LILYCOVE: - if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP)) + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP) + && gSaveBlock1Ptr->location.mapNum == MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_ROOFTOP)) return TRUE; return FALSE; } @@ -2693,7 +2711,7 @@ static bool8 IsAddingPokeNewsDisallowed(u8 newsKind) return FALSE; } -static void UpdatePokeNewsTimeLeft(u16 days) +static void UpdatePokeNewsCountdown(u16 days) { u8 i; @@ -2701,16 +2719,18 @@ static void UpdatePokeNewsTimeLeft(u16 days) { if (gSaveBlock1Ptr->pokeNews[i].kind != POKENEWS_NONE) { - if (gSaveBlock1Ptr->pokeNews[i].days < days) + if (gSaveBlock1Ptr->pokeNews[i].dayCountdown < days) { + // News event has elapsed, clear it from list ClearPokeNewsBySlot(i); } else { - if (gSaveBlock1Ptr->pokeNews[i].state == 0 && FlagGet(FLAG_SYS_GAME_CLEAR) == TRUE) - gSaveBlock1Ptr->pokeNews[i].state = 1; + // Progress countdown to news event + if (gSaveBlock1Ptr->pokeNews[i].state == POKENEWS_STATE_INACTIVE && FlagGet(FLAG_SYS_GAME_CLEAR) == TRUE) + gSaveBlock1Ptr->pokeNews[i].state = POKENEWS_STATE_UPCOMING; - gSaveBlock1Ptr->pokeNews[i].days -= days; + gSaveBlock1Ptr->pokeNews[i].dayCountdown -= days; } } } @@ -2760,9 +2780,7 @@ void CopyContestCategoryToStringVar(u8 varIdx, u8 category) void SetContestCategoryStringVarForInterview(void) { - TVShow *show; - - show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; + TVShow *show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; CopyContestCategoryToStringVar(1, show->bravoTrainer.contestCategory); } @@ -2789,9 +2807,7 @@ size_t CountDigits(int value) static void SmartShopper_BufferPurchaseTotal(u8 varIdx, TVShow *show) { u8 i; - int price; - - price = 0; + int price = 0; for (i = 0; i < SMARTSHOPPER_NUM_ITEMS; i++) { if (show->smartshopperShow.itemIds[i] != ITEM_NONE) @@ -2832,21 +2848,19 @@ static bool8 IsRecordMixShowAlreadySpawned(u8 kind, bool8 delete) static void SortPurchasesByQuantity(void) { u8 i, j; - u16 tmpId; - u16 tmpQn; - + for (i = 0; i < SMARTSHOPPER_NUM_ITEMS - 1; i++) { for (j = i + 1; j < SMARTSHOPPER_NUM_ITEMS; j++) { if (gMartPurchaseHistory[i].quantity < gMartPurchaseHistory[j].quantity) { - tmpId = gMartPurchaseHistory[i].itemId; - tmpQn = gMartPurchaseHistory[i].quantity; + u16 tempItemId = gMartPurchaseHistory[i].itemId; + u16 tempQuantity = gMartPurchaseHistory[i].quantity; gMartPurchaseHistory[i].itemId = gMartPurchaseHistory[j].itemId; gMartPurchaseHistory[i].quantity = gMartPurchaseHistory[j].quantity; - gMartPurchaseHistory[j].itemId = tmpId; - gMartPurchaseHistory[j].quantity = tmpQn; + gMartPurchaseHistory[j].itemId = tempItemId; + gMartPurchaseHistory[j].quantity = tempQuantity; } } } @@ -2923,7 +2937,8 @@ static void InterviewBefore_FanClubLetter(void) if (!gSpecialVar_Result) { StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubLetter.words, 6); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubLetter.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubLetter.words)); } } @@ -2932,7 +2947,8 @@ static void InterviewBefore_RecentHappenings(void) TryReplaceOldTVShowOfKind(TVSHOW_RECENT_HAPPENINGS); if (!gSpecialVar_Result) { - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].recentHappenings.words, 6); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].recentHappenings.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].recentHappenings.words)); } } @@ -2944,7 +2960,8 @@ static void InterviewBefore_PkmnFanClubOpinions(void) StringCopy(gStringVar1, gSpeciesNames[GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_SPECIES, NULL)]); GetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_NICKNAME, gStringVar2); StringGetEnd10(gStringVar2); - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubOpinions.words, 2); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubOpinions.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanclubOpinions.words)); } } @@ -2962,7 +2979,8 @@ static void InterviewBefore_BravoTrainerPkmnProfile(void) { TryReplaceOldTVShowOfKind(TVSHOW_BRAVO_TRAINER_POKEMON_PROFILE); if (!gSpecialVar_Result) - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainer.words, 2); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainer.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainer.words)); } static void InterviewBefore_ContestLiveUpdates(void) @@ -2979,14 +2997,16 @@ static void InterviewBefore_BravoTrainerBTProfile(void) { TryReplaceOldTVShowOfKind(TVSHOW_BRAVO_TRAINER_BATTLE_TOWER_PROFILE); if (!gSpecialVar_Result) - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainerTower.words, 1); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainerTower.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].bravoTrainerTower.words)); } static void InterviewBefore_FanClubSpecial(void) { TryReplaceOldTVShowOfKind(TVSHOW_FAN_CLUB_SPECIAL); if (!gSpecialVar_Result) - InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanClubSpecial.words, 1); + InitializeEasyChatWordArray(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanClubSpecial.words, + ARRAY_COUNT(gSaveBlock1Ptr->tvShows[sCurTVShowSlot].fanClubSpecial.words)); } static bool8 IsPartyMonNicknamedOrNotEnglish(u8 monIdx) @@ -3058,23 +3078,19 @@ static void CompactTVShowArray(TVShow *shows) } } -static u16 GetRandomDifferentSpeciesAndNameSeenByPlayer(u8 varIdx, u16 passedSpecies) +static u16 GetRandomDifferentSpeciesAndNameSeenByPlayer(u8 varIdx, u16 excludedSpecies) { - u16 species; - - species = GetRandomDifferentSpeciesSeenByPlayer(passedSpecies); + u16 species = GetRandomDifferentSpeciesSeenByPlayer(excludedSpecies); StringCopy(gTVStringVarPtrs[varIdx], gSpeciesNames[species]); return species; } -static u16 GetRandomDifferentSpeciesSeenByPlayer(u16 passedSpecies) +static u16 GetRandomDifferentSpeciesSeenByPlayer(u16 excludedSpecies) { - u16 species; - u16 initSpecies; + u16 species = Random() % (NUM_SPECIES - 1) + 1; + u16 initSpecies = species; - species = (Random() % (NUM_SPECIES - 1)) + 1; - initSpecies = species; - while (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN) != TRUE || species == passedSpecies) + while (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_SEEN) != TRUE || species == excludedSpecies) { if (species == SPECIES_NONE + 1) species = NUM_SPECIES - 1; @@ -3083,7 +3099,8 @@ static u16 GetRandomDifferentSpeciesSeenByPlayer(u16 passedSpecies) if (species == initSpecies) { - species = passedSpecies; + // Looped back to initial species (only Pokémon seen), must choose excluded species + species = excludedSpecies; return species; } }; @@ -3798,7 +3815,7 @@ void DeactivateAllNormalTVShows(void) } } -// Ensures a minimum of 5 empty mixed show slots +// Ensures a minimum of 5 empty record mixed show slots static void DeleteExcessMixedShows(void) { s8 i; @@ -3897,8 +3914,8 @@ static bool8 TryMixPokeNewsShow(PokeNews *dest, PokeNews *src, s8 slot) return FALSE; } dest[slot].kind = src->kind; - dest[slot].state = 1; - dest[slot].days = src->days; + dest[slot].state = POKENEWS_STATE_UPCOMING; + dest[slot].dayCountdown = src->dayCountdown; return TRUE; } @@ -3929,7 +3946,7 @@ static void ClearPokeNewsIfGameNotComplete(void) if (FlagGet(FLAG_SYS_GAME_CLEAR) != TRUE) { for (i = 0; i < POKE_NEWS_COUNT; i++) - gSaveBlock1Ptr->pokeNews[i].state = 0; + gSaveBlock1Ptr->pokeNews[i].state = POKENEWS_STATE_INACTIVE; } } @@ -5907,21 +5924,21 @@ static void DoTVShowSecretBaseVisit(void) { case 0: TVShowConvertInternationalString(gStringVar1, show->secretBaseVisit.playerName, show->secretBaseVisit.language); - if (show->secretBaseVisit.nDecorations == 0) + if (show->secretBaseVisit.numDecorations == 0) sTVShowState = 2; else sTVShowState = 1; break; case 1: StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[0]].name); - if (show->secretBaseVisit.nDecorations == 1) + if (show->secretBaseVisit.numDecorations == 1) sTVShowState = 4; else sTVShowState = 3; break; case 3: StringCopy(gStringVar2, gDecorations[show->secretBaseVisit.decorations[1]].name); - switch (show->secretBaseVisit.nDecorations) + switch (show->secretBaseVisit.numDecorations) { case 2: sTVShowState = 7; @@ -5985,21 +6002,13 @@ static void DoTVShowPokemonLotteryWinnerFlashReport(void) state = sTVShowState; TVShowConvertInternationalString(gStringVar1, show->lottoWinner.playerName, show->lottoWinner.language); if (show->lottoWinner.whichPrize == 0) - { StringCopy(gStringVar2, gText_Jackpot); - } else if (show->lottoWinner.whichPrize == 1) - { StringCopy(gStringVar2, gText_First); - } else if (show->lottoWinner.whichPrize == 2) - { StringCopy(gStringVar2, gText_Second); - } else - { StringCopy(gStringVar2, gText_Third); - } StringCopy(gStringVar3, ItemId_GetName(show->lottoWinner.item)); TVShowDone(); ShowFieldMessage(sTVPokemonLotteryWinnerFlashReportTextGroup[state]); @@ -6712,23 +6721,23 @@ static void DoTVShowSafariFanClub(void) switch (state) { case 0: - if (show->safariFanClub.nMonsCaught == 0) + if (show->safariFanClub.monsCaught == 0) sTVShowState = 6; - else if (show->safariFanClub.nMonsCaught < 4) + else if (show->safariFanClub.monsCaught < 4) sTVShowState = 5; else sTVShowState = 1; break; case 1: TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - ConvertIntToDecimalString(1, show->safariFanClub.nMonsCaught); - if (show->safariFanClub.nPkblkUsed == 0) + ConvertIntToDecimalString(1, show->safariFanClub.monsCaught); + if (show->safariFanClub.pokeblocksUsed == 0) sTVShowState = 3; else sTVShowState = 2; break; case 2: - ConvertIntToDecimalString(1, show->safariFanClub.nPkblkUsed); + ConvertIntToDecimalString(1, show->safariFanClub.pokeblocksUsed); sTVShowState = 4; break; case 3: @@ -6740,21 +6749,21 @@ static void DoTVShowSafariFanClub(void) break; case 5: TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - ConvertIntToDecimalString(1, show->safariFanClub.nMonsCaught); - if (show->safariFanClub.nPkblkUsed == 0) + ConvertIntToDecimalString(1, show->safariFanClub.monsCaught); + if (show->safariFanClub.pokeblocksUsed == 0) sTVShowState = 8; else sTVShowState = 7; break; case 6: TVShowConvertInternationalString(gStringVar1, show->safariFanClub.playerName, show->safariFanClub.language); - if (show->safariFanClub.nPkblkUsed == 0) + if (show->safariFanClub.pokeblocksUsed == 0) sTVShowState = 8; else sTVShowState = 7; break; case 7: - ConvertIntToDecimalString(1, show->safariFanClub.nPkblkUsed); + ConvertIntToDecimalString(1, show->safariFanClub.pokeblocksUsed); sTVShowState = 9; break; case 8: diff --git a/src/union_room.c b/src/union_room.c index 1400a0b1d..c624a9784 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -49,7 +49,6 @@ #include "constants/battle_frontier.h" #include "constants/cable_club.h" #include "constants/game_stat.h" -#include "constants/maps.h" #include "constants/party_menu.h" #include "constants/rgb.h" #include "constants/songs.h" @@ -1593,8 +1592,8 @@ void StartUnionRoomBattle(u16 battleFlags) static void WarpForWirelessMinigame(u16 linkService, u16 x, u16 y) { VarSet(VAR_CABLE_CLUB_STATE, linkService); - SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); - SetDynamicWarpWithCoords(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); + SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE, x, y); + SetDynamicWarpWithCoords(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE, x, y); WarpIntoMap(); } @@ -1605,7 +1604,7 @@ static void WarpForCableClubActivity(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 l gFieldLinkPlayerCount = GetLinkPlayerCount(); gLocalLinkPlayerId = GetMultiplayerId(); SetCableClubWarp(); - SetWarpDestination(mapGroup, mapNum, -1, x, y); + SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, x, y); WarpIntoMap(); } diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 65d8c86d0..5960692a2 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -20,7 +20,6 @@ #include "constants/game_stat.h" #include "constants/items.h" #include "constants/layouts.h" -#include "constants/maps.h" #include "constants/weather.h" extern const u8 EventScript_RepelWoreOff[]; |