diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2018-11-18 20:19:10 +0100 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2018-11-18 20:19:10 +0100 |
commit | 27ee7d567e34b76c737c4920cfeccc36e6221543 (patch) | |
tree | 8df67f69c86109bb42e060100e2390ed20b33c61 /src | |
parent | 1b0cfb075723af7b457ec118eca2888df449bf9e (diff) | |
parent | 0bbe03f17030c8009508714fc2b41703f1a1310a (diff) |
fix merge conflict and use EVENT_OBJECT_TEMPLATES_COUNT
Diffstat (limited to 'src')
-rw-r--r-- | src/battle_main.c | 7 | ||||
-rw-r--r-- | src/battle_pyramid.c | 1297 | ||||
-rw-r--r-- | src/battle_script_commands.c | 111 | ||||
-rw-r--r-- | src/battle_setup.c | 14 | ||||
-rw-r--r-- | src/clear_save_data_screen.c | 148 | ||||
-rw-r--r-- | src/event_object_movement.c | 2 | ||||
-rw-r--r-- | src/graphics.c | 2 | ||||
-rw-r--r-- | src/hall_of_fame.c | 2 | ||||
-rw-r--r-- | src/item.c | 2 | ||||
-rw-r--r-- | src/load_save.c | 9 | ||||
-rw-r--r-- | src/overworld.c | 12 | ||||
-rw-r--r-- | src/pokemon.c | 3 | ||||
-rw-r--r-- | src/recorded_battle.c | 2 | ||||
-rw-r--r-- | src/save.c | 122 | ||||
-rw-r--r-- | src/save_failed_screen.c | 149 | ||||
-rw-r--r-- | src/save_location.c | 19 | ||||
-rw-r--r-- | src/start_menu.c | 6 | ||||
-rw-r--r-- | src/trainer_see.c | 3 | ||||
-rw-r--r-- | src/wild_encounter.c | 4 |
19 files changed, 1600 insertions, 314 deletions
diff --git a/src/battle_main.c b/src/battle_main.c index 4f5540616..97c0e26bb 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5,6 +5,7 @@ #include "battle_controllers.h" #include "battle_interface.h" #include "battle_message.h" +#include "battle_pyramid.h" #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" @@ -109,10 +110,8 @@ extern const u8 gText_Love[]; // functions extern void sub_81B9150(void); extern void sub_80B3AF8(u8 taskId); // cable club -extern u8 sub_81A9E28(void); // battle frontier 2 extern void sub_81B8FB0(u8, u8); // party menu extern u8 pokemon_order_func(u8); // party menu -extern bool8 InBattlePyramid(void); // this file's functions static void CB2_InitBattleInternal(void); @@ -5604,7 +5603,7 @@ bool8 TryRunFromBattle(u8 battler) if (InBattlePyramid()) { gBattleStruct->runTries++; - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) { @@ -5630,7 +5629,7 @@ bool8 TryRunFromBattle(u8 battler) { if (InBattlePyramid()) { - pyramidMultiplier = sub_81A9E28(); + pyramidMultiplier = GetPyramidRunMultiplier(); speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); if (speedVar > (Random() & 0xFF)) effect++; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c new file mode 100644 index 000000000..878ea4e70 --- /dev/null +++ b/src/battle_pyramid.c @@ -0,0 +1,1297 @@ +#include "global.h" +#include "battle_pyramid.h" +#include "battle_pyramid_bag.h" +#include "event_data.h" +#include "battle.h" +#include "battle_setup.h" +#include "battle_tower.h" +#include "save.h" +#include "fieldmap.h" +#include "palette.h" +#include "field_message_box.h" +#include "random.h" +#include "item.h" +#include "util.h" +#include "sound.h" +#include "task.h" +#include "start_menu.h" +#include "trainer_see.h" +#include "main.h" +#include "load_save.h" +#include "script.h" +#include "malloc.h" +#include "overworld.h" +#include "constants/battle_frontier.h" +#include "constants/event_objects.h" +#include "constants/event_object_movement_constants.h" +#include "constants/items.h" +#include "constants/maps.h" +#include "constants/moves.h" + +extern u8 gUnknown_0203CEF8[3]; +extern void door_upload_tiles(void); + +extern const struct MapLayout *const gMapLayouts[]; + +#define TOTAL_ROUNDS 20 +#define PICKUP_ITEMS_PER_ROUND 10 + +struct Struct_08613650 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 runMultiplier; + u8 unk5[8]; +}; + +struct PyramidWildMon +{ + u16 species; + u8 lvl; + u8 abilityBit; + u16 moves[4]; +}; + +struct ClassMusic +{ + u8 class; + u8 music; +}; + +extern const u16 gBattleFrontierHeldItems[]; +extern const struct FacilityMon gBattleFrontierMons[]; +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; + +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F[]; +extern const u8 BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A[]; + +// This file's functions. +static void sub_81A8E9C(void); +static void sub_81A8F38(void); +static void sub_81A9048(void); +static void sub_81A9134(void); +static void sub_81A917C(void); +static void sub_81A91FC(void); +static void sub_81A9254(void); +static void sub_81A9290(void); +static void sub_81A93C8(void); +static void sub_81A9414(void); +static void sub_81A9424(void); +static void sub_81A9618(void); +static void sub_81A966C(void); +static void sub_81A9684(void); +static void sub_81A975C(void); +static void sub_81A97C8(void); +static void sub_81A9828(void); +static void sub_81A9834(void); +static void InitBagItems(u8 lvlMode); +static u8 sub_81AA9E4(void); +static u8 sub_81A9998(s32 *, u8, u8); +static void sub_81A97DC(u8 taskId); +static void sub_81A9B44(u16 trainerId); +static void sub_81AA96C(u8 *mapNums); +static void sub_81AA33C(u8 *, u8 *); +static void sub_81AA398(u8); +static bool8 sub_81AA4D8(u8, u8); +static bool8 sub_81AA648(u8, u8); +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id); +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id); + +// Const rom data. +extern const struct Struct_08613650 gUnknown_08613650[]; +extern const u16 sPickupItemsLvl50[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; +extern const u16 sPickupItemsLvlOpen[TOTAL_ROUNDS][PICKUP_ITEMS_PER_ROUND]; +extern const u8 gUnknown_08613ABC[63][2]; +extern const u8 gUnknown_08613B3A[]; +extern const u16 gUnknown_08D856C8[][16]; +extern const u8 gUnknown_08613C1C[50][2]; +extern const u8 *const *const *const gUnknown_08613EC0[]; +extern const struct ClassMusic gUnknown_08613B44[54]; +extern const struct PyramidWildMon *const gBattlePyramidOpenLevelWildMonPointers[]; +extern const struct PyramidWildMon *const gBattlePyramidLevel50WildMonPointers[]; +extern const u8 gUnknown_08613794[]; +extern const u8 gUnknown_08613750[34][2]; + +static const u8 gUnknown_08613ED8[] = {3, 4, 5, 6, 7, 8, 3, 4}; + +static void (* const sBattlePyramidFunctions[])(void) = +{ + sub_81A8E9C, + sub_81A8F38, + sub_81A9048, + sub_81A9134, + sub_81A917C, + sub_81A91FC, + sub_81A9254, + sub_81A9290, + sub_81A93C8, + sub_81A9414, + sub_81A9424, + sub_81A9618, + sub_81A966C, + sub_81A9684, + sub_81A975C, + sub_81A97C8, + sub_81A9828, + sub_81A9834, +}; + +static const u16 gUnknown_08613F28[] = {ITEM_HP_UP, ITEM_PROTEIN, ITEM_IRON, ITEM_CALCIUM, ITEM_CARBOS, ITEM_ZINC}; +static const u16 gUnknown_08613F34[] = {ITEM_BRIGHT_POWDER, ITEM_WHITE_HERB, ITEM_QUICK_CLAW, ITEM_LEFTOVERS, ITEM_MENTAL_HERB, ITEM_KINGS_ROCK, ITEM_FOCUS_BAND, ITEM_SCOPE_LENS, ITEM_CHOICE_BAND}; + +static const u8 gUnknown_08613F46[][4] = +{ + {0x01, 0x04, 0xff, 0xff}, + {0x00, 0x02, 0x05, 0xff}, + {0x01, 0x03, 0x06, 0xff}, + {0x02, 0x07, 0xff, 0xff}, + {0x00, 0x05, 0x08, 0xff}, + {0x01, 0x04, 0x06, 0x09}, + {0x02, 0x05, 0x07, 0x0a}, + {0x03, 0x06, 0x0b, 0xff}, + {0x04, 0x09, 0x0c, 0xff}, + {0x05, 0x08, 0x0a, 0x0d}, + {0x06, 0x09, 0x0b, 0x0e}, + {0x07, 0x0a, 0x0f, 0xff}, + {0x08, 0x0d, 0xff, 0xff}, + {0x09, 0x0c, 0x0e, 0xff}, + {0x0a, 0x0d, 0x0f, 0xff}, + {0x0b, 0x0e, 0xff, 0xff}, +}; + +static const u8 sPickupPercentages[PICKUP_ITEMS_PER_ROUND] = {30, 40, 50, 60, 70, 80, 85, 90, 95, 100}; + +// code +void CallBattlePyramidFunction(void) +{ + sBattlePyramidFunctions[gSpecialVar_0x8004](); +} + +static void sub_81A8E9C(void) +{ + bool32 isCurrent; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + gSaveBlock2Ptr->frontier.field_CA8 = 0; + gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; + gSaveBlock2Ptr->frontier.field_CA9_a = 0; + if (lvlMode != FRONTIER_LVL_50) + isCurrent = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + else + isCurrent = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + + if (!isCurrent) + { + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = 0; + InitBagItems(lvlMode); + } + + sub_81C4EEC(); + gTrainerBattleOpponent_A = 0; + gBattleOutcome = 0; +} + +static void sub_81A8F38(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_E18; + break; + case 1: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; + break; + case 2: + if (lvlMode != FRONTIER_LVL_50) + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + else + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + break; + case 3: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_50]; + break; + case 4: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_OPEN]; + break; + case 5: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x1000; + break; + case 6: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CDC & 0x2000; + break; + } +} + +static void sub_81A9048(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + switch (gSpecialVar_0x8005) + { + case 0: + gSaveBlock2Ptr->frontier.field_E18 = gSpecialVar_0x8006; + break; + case 1: + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] = gSpecialVar_0x8006; + break; + case 2: + if (lvlMode != FRONTIER_LVL_50) + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x2000; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x2000); + } + else + { + if (gSpecialVar_0x8006) + gSaveBlock2Ptr->frontier.field_CDC |= 0x1000; + else + gSaveBlock2Ptr->frontier.field_CDC &= ~(0x1000); + } + break; + case 7: + gSaveBlock2Ptr->frontier.field_E2A = gSpecialVar_0x8006; + break; + } +} + +static void sub_81A9134(void) +{ + gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8005; + VarSet(VAR_TEMP_0, 0); + gSaveBlock2Ptr->frontier.field_CA9_a = 1; + save_serialize_map(); + TrySavingData(SAVE_LINK); +} + +static void sub_81A917C(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] > 41) + gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F34[Random() % ARRAY_COUNT(gUnknown_08613F34)]; + else + gSaveBlock2Ptr->frontier.field_E18 = gUnknown_08613F28[Random() % ARRAY_COUNT(gUnknown_08613F28)]; +} + +static void sub_81A91FC(void) +{ + if (AddBagItem(gSaveBlock2Ptr->frontier.field_E18, 1) == TRUE) + { + CopyItemName(gSaveBlock2Ptr->frontier.field_E18, gStringVar1); + gSaveBlock2Ptr->frontier.field_E18 = 0; + gSpecialVar_Result = TRUE; + } + else + { + gSpecialVar_Result = FALSE; + } +} + +static void sub_81A9254(void) +{ + s32 i; + + for (i = 0; i < 4; i++) + gSaveBlock2Ptr->frontier.field_E22[i] = Random(); + + gSaveBlock2Ptr->frontier.field_E2A = 0; +} + +static void sub_81A9290(void) +{ + s32 i; + s32 r7; + s32 rand; + u8 id; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u32 floor = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + u32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7) % TOTAL_ROUNDS; + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + id = sub_81AA9E4(); + r7 = (gSpecialVar_LastTalked - gUnknown_08613650[id].unk1) - 1; + rand = gSaveBlock2Ptr->frontier.field_E22[r7 / 2]; + SeedRng2(rand); + + for (i = 0; i < r7 + 1; i++) + rand = Random2() % 100; + + for (i = gUnknown_08613B3A[floor]; i < ARRAY_COUNT(gUnknown_08613ABC); i++) + { + if (rand < gUnknown_08613ABC[i][0]) + break; + } + + if (lvlMode != FRONTIER_LVL_50) + gSpecialVar_0x8000 = sPickupItemsLvlOpen[round][gUnknown_08613ABC[i][1]]; + else + gSpecialVar_0x8000 = sPickupItemsLvl50[round][gUnknown_08613ABC[i][1]]; + + gSpecialVar_0x8001 = 1; +} + +static void sub_81A93C8(void) +{ + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + s32 i = 0; + + for (;;) + { + if (events[i].localId == gSpecialVar_LastTalked) + { + events[i].x = 0x7FFF; + events[i].y = 0x7FFF; + break; + } + i++; + if (events[i].localId == 0) + break; + } +} + +static void sub_81A9414(void) +{ + gFacilityTrainers = gBattleFrontierTrainers; +} + +static void sub_81A9424(void) +{ + s32 i; + s32 var_24; + u8 id; + s32 class = 0; + s32 r7 = 0; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + u16 trainerId = LocalIdToPyramidTrainerId(gEventObjects[gSelectedEventObject].localId); + + for (i = 0; i < ARRAY_COUNT(gUnknown_08613C1C); i++) + { + if (gUnknown_08613C1C[i][0] == gFacilityTrainers[trainerId].facilityClass) + { + class = gUnknown_08613C1C[i][1]; + break; + } + } + + var_24 = gUnknown_08613ED8[gEventObjects[gSelectedEventObject].localId - 1]; + i = 0; + while (!i) + { + switch (var_24) + { + case 0: + r7 = sub_81A9998(&var_24, 8, 0); + i = 1; + break; + case 1: + for (i = 0; i < sub_81AAA40(); i++) + { + if (events[i].graphicsId == EVENT_OBJ_GFX_ITEM_BALL && events[i].x != 0x7FFF && events[i].y != 0x7FFF) + r7++; + } + i = 1; + break; + case 2: + id = sub_81AA9E4(); + r7 = gUnknown_08613650[id].unk1; + for (i = 0; i < 8; i++) + { + if (gBitTable[i] & gSaveBlock2Ptr->frontier.field_E2A) + r7--; + } + i = 1; + break; + case 3: + sub_81A9998(&var_24, 8, 2); + break; + case 4: + sub_81A9998(&var_24, 8, 1); + break; + case 5: + sub_81A9998(&var_24, 16, 2); + break; + case 6: + sub_81A9998(&var_24, 16, 1); + break; + case 7: + sub_81A9998(&var_24, 24, 2); + break; + case 8: + sub_81A9998(&var_24, 24, 1); + break; + } + } + ShowFieldMessage(gUnknown_08613EC0[class][var_24][r7]); +} + +static void sub_81A9618(void) +{ + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] < 999) + gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]++; + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] > gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode]) + gSaveBlock2Ptr->frontier.pyramidRecordStreaks[lvlMode] = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode]; +} + +static void sub_81A966C(void) +{ + gSpecialVar_Result = InBattlePyramid(); +} + +static void sub_81A9684(void) +{ + switch (gSpecialVar_0x8006) + { + case 0: + gSaveBlock2Ptr->frontier.field_E68 = gSpecialVar_0x8005; + break; + case 1: + switch (gSpecialVar_Result) + { + case 0: + if (!gPaletteFade.active) + { + if (gSaveBlock2Ptr->frontier.field_E68 >= 120) + gSaveBlock2Ptr->frontier.field_E68 = 120; + else + PlaySE(gSpecialVar_0x8007); + gSpecialVar_Result++; + } + break; + case 1: + if (gSpecialVar_0x8005 != 0) + { + gSpecialVar_0x8005--; + gSaveBlock2Ptr->frontier.field_E68++; + if (gSaveBlock2Ptr->frontier.field_E68 > 120) + { + gSaveBlock2Ptr->frontier.field_E68 = 120; + gSpecialVar_Result++; + } + door_upload_tiles(); + } + else + { + gSpecialVar_Result = 2; + } + break; + case 2: + default: + break; + } + break; + } +} + +static void sub_81A975C(void) +{ + s32 i, j; + u16 item = 0; + + for (i = 0; i < PARTY_SIZE; i++) + { + for (j = 0; j < 4; j++) + { + if (gSaveBlock2Ptr->frontier.selectedPartyMons[j] != 0 && gSaveBlock2Ptr->frontier.selectedPartyMons[j] - 1 == i) + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &item); + } + } +} + +static void sub_81A97C8(void) +{ + CreateTask(sub_81A97DC, 0); +} + +static void sub_81A97DC(u8 taskId) +{ + if (gPaletteFade.active) + { + CpuCopy16(gUnknown_08D856C8[gSaveBlock2Ptr->frontier.curChallengeBattleNum], &gPlttBufferUnfaded[96], 32); + DestroyTask(taskId); + } +} + +static void sub_81A9828(void) +{ + sub_809FDD4(); +} + +static void sub_81A9834(void) +{ + s32 i, j, k, l; + + for (i = 0; i < 3; i++) + { + s32 id = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; + for (j = 0; j < 3; j++) + { + if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL)) + { + for (k = 0; k < 4; k++) + { + for (l = 0; l < 4; l++) + { + if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL)) + break; + } + if (l == 4) + SetMonMoveSlot(&gPlayerParty[j], MOVE_SKETCH, k); + } + gSaveBlock1Ptr->playerParty[id] = gPlayerParty[j]; + gUnknown_0203CEF8[j] = id + 1; + break; + } + } + } + + for (i = 0; i < 3; i++) + gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i]; +} + +static u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) +{ + s32 i, j; + u8 ret = 0; + u16 *map = gUnknown_03005DC0.map; + map += gUnknown_03005DC0.width * 7 + 7; + + for (i = 0; i < 32; map += 47, i++) + { + for (j = 0; j < 32; j++) + { + if ((map[j] & 0x3FF) == 0x28E) + { + j += 7 - gEventObjects[gSelectedEventObject].initialCoords.x; + i += 7 - gEventObjects[gSelectedEventObject].initialCoords.y; + if (j >= arg1 || j <= -arg1 || i >= arg1 || i <= -arg1 || arg2 == 0) + { + if (j > 0 && i > 0) + { + if (j >= i) + ret = 2; + else + ret = 3; + } + else if (j < 0 && i < 0) + { + if (j > i) + ret = 0; + else + ret = 1; + } + else if (j == 0) + { + if (i > 0) + ret = 3; + else + ret = 0; + } + else if (i == 0) + { + if (j > 0) + ret = 2; + else + ret = 1; + } + else if (j < 0) + { + if (j + i > 0) + ret = 3; + else + ret = 1; + } + else + { + ret = (~(j + i) >= 0) ? 0 : 2; + } + *arg0 = 0; + } + else + { + *arg0 = arg2; + } + return ret; + } + } + } + + return ret; +} + +u16 LocalIdToPyramidTrainerId(u8 localId) +{ + return gSaveBlock2Ptr->frontier.field_CB4[localId - 1]; +} + +bool8 GetBattlePyramidTrainerFlag(u8 eventId) +{ + return gSaveBlock2Ptr->frontier.field_E2A & gBitTable[gEventObjects[eventId].localId - 1]; +} + +void sub_81A9B04(void) +{ + sub_81A9B44(gTrainerBattleOpponent_A); + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) + { + gSelectedEventObject = GetChosenApproachingTrainerEventObjectId(1); + sub_81A9B44(gTrainerBattleOpponent_B); + } +} + +static void sub_81A9B44(u16 trainerId) +{ + s32 i; + + for (i = 0; i < 8; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + gSaveBlock2Ptr->frontier.field_E2A |= gBitTable[i]; + } + + gEventObjects[gSelectedEventObject].movementType = MOVEMENT_TYPE_WANDER_AROUND; + gSaveBlock1Ptr->eventObjectTemplates[gSpecialVar_LastTalked - 1].movementType = MOVEMENT_TYPE_WANDER_AROUND; + gEventObjects[gSelectedEventObject].initialCoords.x = gEventObjects[gSelectedEventObject].currentCoords.x; + gEventObjects[gSelectedEventObject].initialCoords.y = gEventObjects[gSelectedEventObject].currentCoords.y; +} + +void GenerateBattlePyramidWildMon(void) +{ + u8 name[POKEMON_NAME_LENGTH + 1]; + s32 i; + const struct PyramidWildMon *wildMons; + u32 id; + u32 lvl = gSaveBlock2Ptr->frontier.lvlMode; + u16 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] / 7) % TOTAL_ROUNDS; + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + if (lvl != FRONTIER_LVL_50) + wildMons = gBattlePyramidOpenLevelWildMonPointers[round]; + else + wildMons = gBattlePyramidLevel50WildMonPointers[round]; + + id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1; + SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &wildMons[id].species); + GetSpeciesName(name, wildMons[id].species); + SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name); + if (lvl != FRONTIER_LVL_50) + { + lvl = SetFacilityPtrsGetLevel(); + lvl -= wildMons[id].lvl; + lvl = lvl - 5 + (Random() % 11); + } + else + { + lvl = wildMons[id].lvl - 5 + ((Random() % 11)); + } + SetMonData(&gEnemyParty[0], + MON_DATA_EXP, + &gExperienceTables[gBaseStats[wildMons[id].species].growthRate][lvl]); + + switch (wildMons[id].abilityBit) + { + case 0: + case 1: + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &wildMons[id].abilityBit); + break; + case 2: + default: + if (gBaseStats[wildMons[id].species].ability2) + { + i = GetMonData(&gEnemyParty[0], MON_DATA_PERSONALITY, NULL) % 2; + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i); + } + else + { + i = 0; + SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &i); + } + break; + } + + for (i = 0; i < 4; i++) + SetMonMoveSlot(&gEnemyParty[0], wildMons[id].moves[i], i); + + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] >= 140) // BUG: Reading outside the array as lvl was used for mon level instead of frontier lvl mode. + { + id = (Random() % 17) + 15; + for (i = 0; i < NUM_STATS; i++) + SetMonData(&gEnemyParty[0], MON_DATA_HP_IV + i, &id); + } + CalculateMonStats(&gEnemyParty[0]); +} + +u8 GetPyramidRunMultiplier(void) +{ + u8 id = sub_81AA9E4(); + return gUnknown_08613650[id].runMultiplier; +} + +u8 InBattlePyramid(void) +{ + if (gMapHeader.mapLayoutId == 361) + return 1; + else if (gMapHeader.mapLayoutId == 378) + return 2; + else + return FALSE; +} + +bool8 InBattlePyramid_(void) +{ + return (gMapHeader.mapLayoutId == 361 || gMapHeader.mapLayoutId == 378); +} + +void sub_81A9E90(void) +{ + if (InBattlePyramid()) + { + sub_81A9834(); + gSaveBlock2Ptr->frontier.field_CA8 = 2; + VarSet(VAR_TEMP_E, 0); + LoadPlayerParty(); + } +} + +void sub_81A9EC8(void) +{ + if (InBattlePyramid()) + DoSoftReset(); +} + +void CopyPyramidTrainerSpeechBefore(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechBefore); +} + +void CopyPyramidTrainerWinSpeech(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechWin); +} + +void CopyPyramidTrainerLoseSpeech(u16 trainerId) +{ + FrontierSpeechToString(gFacilityTrainers[trainerId].speechLose); +} + +u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerId) +{ + s32 i; + + for (i = 0; i < ARRAY_COUNT(gUnknown_08613B44); i++) + { + if (gUnknown_08613B44[i].class == gFacilityClassToTrainerClass[gFacilityTrainers[trainerId].facilityClass]) + return gUnknown_08613B44[i].music; + } + return 0; +} + +static void sub_81A9F80(void) +{ + ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88); +} + +static u16 sub_81A9F90(u8 count) +{ + s32 i; + u16 trainerId; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + u32 challengeNum = gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7; + u32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + if (battleNum == 7) + { + do + { + trainerId = sub_8162548(challengeNum + 1, battleNum); + for (i = 0 ; i < count; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != count); + } + else + { + do + { + trainerId = sub_8162548(challengeNum, battleNum); + for (i = 0 ; i < count; i++) + { + if (gSaveBlock2Ptr->frontier.field_CB4[i] == trainerId) + break; + } + } while (i != count); + } + + return trainerId; +} + +void sub_81AA078(u16 *mapArg, u8 arg1) +{ + s32 j, k; + s32 i; + u8 var0, var1; + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + sub_81AA33C(&var0, &var1); + for (i = 0; i < 16; i++) + { + u16 *map; + s32 heightAdd, widthAdd; + const struct MapLayout *mapLayout = gMapLayouts[allocated[i] + 0x169]; + const u16 *layoutMap = mapLayout->map; + + gUnknown_03005DC0.map = mapArg; + gUnknown_03005DC0.width = mapLayout->width * 4 + 15; + gUnknown_03005DC0.height = mapLayout->height * 4 + 14; + map = mapArg; + heightAdd = (((i / 4 * mapLayout->height) + 7) * (gUnknown_03005DC0.width)); + widthAdd = ((i % 4 * mapLayout->width) + 7); + map += heightAdd + widthAdd; + for (j = 0; j < mapLayout->height; j++) + { + for (k = 0; k < mapLayout->width; k++) + { + if ((layoutMap[k] & 0x3FF) != 0x28E) + { + map[k] = layoutMap[k]; + } + else if (i != var1) + { + if (i == var0 && arg1 == 0) + { + gSaveBlock1Ptr->pos.x = (mapLayout->width * (i % 4)) + k; + gSaveBlock1Ptr->pos.y = (mapLayout->height * (i / 4)) + j; + } + map[k] = (layoutMap[k] & 0xFC00) | 0x28D; + } + else + { + map[k] = layoutMap[k]; + } + } + map += 15 + (mapLayout->width * 4); + layoutMap += mapLayout->width; + } + } + mapheader_run_script_with_tag_x1(); + free(allocated); +} + +void sub_81AA1D8(void) +{ + s32 i; + u8 id; + u8 var0, var1; + + for (i = 0; i < 8; i++) + gSaveBlock2Ptr->frontier.field_CB4[i] |= 0xFFFF; + + id = sub_81AA9E4(); + sub_81AA33C(&var0, &var1); + CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates)); + for (i = 0; i < 2; i++) + { + u8 value; + + if (i == 0) + value = gUnknown_08613650[id].unk3; + else + value = gUnknown_08613650[id].unk2; + + switch (value) + { + case 0: + sub_81AA398(i); + break; + case 1: + if (sub_81AA4D8(i, var0)) + sub_81AA398(i); + break; + case 2: + if (sub_81AA4D8(i, var1)) + sub_81AA398(i); + break; + case 3: + if (sub_81AA648(i, var0)) + sub_81AA398(i); + break; + case 4: + if (sub_81AA648(i, var1)) + sub_81AA398(i); + break; + } + } +} + +void sub_81AA2F8(void) +{ + s32 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) + { + if (events[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C4F; + else + events[i].script = BattleFrontier_BattlePyramidEmptySquare_EventScript_252C6A; + } +} + +static void sub_81AA33C(u8 *var0, u8 *var1) +{ + *var0 = gSaveBlock2Ptr->frontier.field_E22[3] % 16; + *var1 = gSaveBlock2Ptr->frontier.field_E22[0] % 16; + + if (*var0 == *var1) + { + *var0 = (gSaveBlock2Ptr->frontier.field_E22[3] + 1 ) % 16; + *var1 = (gSaveBlock2Ptr->frontier.field_E22[0] + 15) % 16; + } +} + +static void sub_81AA398(u8 arg0) +{ + s32 i; + s32 count; + s32 var_28; + s32 r4; + u32 bits = 0; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + r4 = gSaveBlock2Ptr->frontier.field_E22[2] % 16; + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + do + { + do + { + if (bits & 1) + { + if (!(gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3])) + bits |= 2; + } + else + { + if (gBitTable[r4] & gSaveBlock2Ptr->frontier.field_E22[3]) + bits |= 2; + } + if (++r4 >= 16) + r4 = 0; + + if (r4 == gSaveBlock2Ptr->frontier.field_E22[2] % 16) + { + if (bits & 1) + bits |= 6; + else + bits |= 1; + } + } while (!(bits & 2)); + + } while (!(bits & 4) && sub_81AA760(arg0, allocated, r4, var_28 + i)); + bits &= 1; + } + free(allocated); +} + +static bool8 sub_81AA4D8(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r6 = 0; + s32 r7 = 0; + s32 var_34 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (r7 == 0) + { + if (sub_81AA760(arg0, allocated, arg1, var_28 + i)) + r7 = 1; + else + var_34++; + } + if (r7 & 1) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)) + { + do + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + r7 += 2; + } while (r7 >> 1 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r6], var_28 + i)); + var_34++; + } + else + { + r6++; + if (gUnknown_08613F46[arg1][r6] == 0xFF || r6 >= 4) + r6 = 0; + var_34++; + } + } + + if (r7 >> 1 == 4) + break; + + r7 &= 1; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > var_34); +} + +static bool8 sub_81AA648(u8 arg0, u8 arg1) +{ + s32 i; + s32 var_28; + s32 r4 = 0; + s32 r7 = 0; + s32 r8 = 0; + s32 count; + u8 id = sub_81AA9E4(); + u8 *allocated = AllocZeroed(0x10); + + sub_81AA96C(allocated); + if (arg0 == 0) + { + count = gUnknown_08613650[id].unk1; + var_28 = 0; + } + else + { + count = gUnknown_08613650[id].unk0; + var_28 = gUnknown_08613650[id].unk1; + } + + for (i = 0; i < count; i++) + { + if (sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)) + { + do + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r8++; + } while (r8 != 4 && sub_81AA760(arg0, allocated, gUnknown_08613F46[arg1][r4], var_28 + i)); + r7++; + } + else + { + r4++; + if (gUnknown_08613F46[arg1][r4] == 0xFF || r4 >= 4) + r4 = 0; + r7++; + } + + if (r8 == 4) + break; + } + // free(allocated); BUG: allocated memory not freed + + return (count / 2 > r7); +} + +static bool8 sub_81AA760(u8 arg0, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + + if (gSaveBlock2Ptr->frontier.field_E22[0] & 1) + { + s32 minus1 = -1; + for (i = 7; i > minus1; i--) + { + for (j = 7; j >= 0; j--) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + else + { + for (i = 0; i < 8; i++) + { + for (j = 0; j < 8; j++) + { + if (!sub_81AA810(arg0, j, i, mapNums, whichMap, id)) + return FALSE; + } + } + } + + return TRUE; +} + +static bool8 sub_81AA810(u8 arg0, u8 x, u8 y, u8 *mapNums, u8 whichMap, u8 id) +{ + s32 i, j; + const struct MapHeader *mapHeader; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + mapHeader = Overworld_GetMapHeaderByGroupAndId(MAP_GROUP(BATTLE_PYRAMID_SQUARE01), mapNums[whichMap] + MAP_NUM(BATTLE_PYRAMID_SQUARE01)); + for (i = 0; i < mapHeader->events->eventObjectCount; i++) + { + if (mapHeader->events->eventObjects[i].x != x || mapHeader->events->eventObjects[i].y != y) + continue; + + if (arg0 != 0 || mapHeader->events->eventObjects[i].graphicsId == EVENT_OBJ_GFX_ITEM_BALL) + { + if (arg0 != 1 || mapHeader->events->eventObjects[i].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + continue; + } + + for (j = 0; j < id; j++) + { + if (events[j].x == x + ((whichMap % 4) * 8) && events[j].y == y + ((whichMap / 4) * 8)) + break; + } + if (j != id) + continue; + + events[id] = mapHeader->events->eventObjects[i]; + events[id].x += ((whichMap % 4) * 8); + events[id].y += ((whichMap / 4) * 8); + events[id].localId = id + 1; + if (events[id].graphicsId != EVENT_OBJ_GFX_ITEM_BALL) + { + i = sub_81A9F90(id); + events[id].graphicsId = GetBattleFacilityTrainerGfxId(i); + gSaveBlock2Ptr->frontier.field_CB4[id] = i; + } + return FALSE; + } + + return TRUE; +} + +static void sub_81AA96C(u8 *mapNums) +{ + s32 i; + s32 bits = (gSaveBlock2Ptr->frontier.field_E22[0]) | (gSaveBlock2Ptr->frontier.field_E22[1] << 16); + u8 id = sub_81AA9E4(); + + for (i = 0; i < 16; i++) + { + mapNums[i] = gUnknown_08613650[id].unk5[bits & 7]; + bits >>= 3; + if (i == 7) + { + bits = (gSaveBlock2Ptr->frontier.field_E22[2]) | (gSaveBlock2Ptr->frontier.field_E22[3] << 16); + bits >>= 8; + } + } +} + +static u8 sub_81AA9E4(void) +{ + s32 i; + s32 var = gSaveBlock2Ptr->frontier.field_E22[3] % 100; + s32 battleNum = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + + for (i = gUnknown_08613794[battleNum]; i < ARRAY_COUNT(gUnknown_08613750); i++) + { + if (var < gUnknown_08613750[i][0]) + return gUnknown_08613750[i][1]; + } + return 0; +} + +u8 sub_81AAA40(void) +{ + u8 i; + struct EventObjectTemplate *events = gSaveBlock1Ptr->eventObjectTemplates; + + for (i = 0; i < 16; i++) + { + if (events[i].localId == 0) + break; + } + + return i; +} + +static void InitBagItems(u8 lvlMode) +{ + s32 i; + + for (i = 0; i < PYRAMID_BAG_ITEMS_COUNT; i++) + { + gSaveBlock2Ptr->frontier.pyramidBag.itemId[lvlMode][i] = 0; + gSaveBlock2Ptr->frontier.pyramidBag.quantity[lvlMode][i] = 0; + } + + AddPyramidBagItem(ITEM_HYPER_POTION, 1); + AddPyramidBagItem(ITEM_ETHER, 1); +} + +u16 GetBattlePyramidPickupItemId(void) +{ + s32 rand; + u32 i; + u32 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; + s32 round = (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvlMode] / 7); + + if (round >= TOTAL_ROUNDS) + round = TOTAL_ROUNDS - 1; + + rand = Random() % 100; + + for (i = 0; i < ARRAY_COUNT(sPickupPercentages); i++) + { + if (sPickupPercentages[i] > rand) + break; + } + + if (i >= PICKUP_ITEMS_PER_ROUND) + i = PICKUP_ITEMS_PER_ROUND - 1; + + if (lvlMode != FRONTIER_LVL_50) + return sPickupItemsLvlOpen[round][i]; + else + return sPickupItemsLvl50[round][i]; +} diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 8e084a46c..07ab81a02 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -45,6 +45,7 @@ #include "party_menu.h" #include "battle_arena.h" #include "battle_pike.h" +#include "battle_pyramid.h" extern u16 gBattle_BG1_X; extern u16 gBattle_BG1_Y; @@ -62,11 +63,8 @@ extern void sub_81D388C(struct Pokemon* mon, void* statStoreLocation); // pokena extern void sub_81D3640(u8 arg0, void* statStoreLocation1, void* statStoreLocation2, u8 arg3, u8 arg4, u8 arg5); // pokenav.s extern void sub_81D3784(u8 arg0, void* statStoreLocation1, u8 arg2, u8 arg3, u8 arg4); // pokenav.s extern u8* GetMonNickname(struct Pokemon* mon, u8* dst); // party_menu -extern u8 BattleArena_ShowJudgmentWindow(u8* arg0); // battle frontier 2 extern void sub_81B8E80(u8 battlerId, u8, u8); // party menu extern bool8 sub_81B1250(void); // ? -extern bool8 InBattlePyramid(void); -extern u16 GetBattlePyramidPickupItemId(void); extern u8 sub_813B21C(void); extern u16 get_unknown_box_id(void); @@ -9860,71 +9858,72 @@ static void atkE4_getsecretpowereffect(void) static void atkE5_pickup(void) { - if (!InBattlePike()) + s32 i; + u16 species, heldItem; + u8 ability; + + if (InBattlePike()) { - s32 i; - u16 species, heldItem; - u8 ability; - if (InBattlePyramid()) + } + else if (InBattlePyramid()) + { + for (i = 0; i < PARTY_SIZE; i++) { - for (i = 0; i < PARTY_SIZE; i++) - { - species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); - heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); - if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) - ability = gBaseStats[species].ability2; - else - ability = gBaseStats[species].ability1; + if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) + ability = gBaseStats[species].ability2; + else + ability = gBaseStats[species].ability1; - if (ability == ABILITY_PICKUP - && species != 0 - && species != SPECIES_EGG - && heldItem == ITEM_NONE - && (Random() % 10) == 0) - { - heldItem = GetBattlePyramidPickupItemId(); - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem); - } + if (ability == ABILITY_PICKUP + && species != 0 + && species != SPECIES_EGG + && heldItem == ITEM_NONE + && (Random() % 10) == 0) + { + heldItem = GetBattlePyramidPickupItemId(); + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &heldItem); } } - else + } + else + { + for (i = 0; i < PARTY_SIZE; i++) { - for (i = 0; i < PARTY_SIZE; i++) - { - species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); - heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); - if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) - ability = gBaseStats[species].ability2; - else - ability = gBaseStats[species].ability1; + if (GetMonData(&gPlayerParty[i], MON_DATA_ALT_ABILITY)) + ability = gBaseStats[species].ability2; + else + ability = gBaseStats[species].ability1; - if (ability == ABILITY_PICKUP - && species != 0 - && species != SPECIES_EGG - && heldItem == ITEM_NONE - && (Random() % 10) == 0) - { - s32 j; - s32 rand = Random() % 100; - u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10; - if (lvlDivBy10 > 9) - lvlDivBy10 = 9; + if (ability == ABILITY_PICKUP + && species != 0 + && species != SPECIES_EGG + && heldItem == ITEM_NONE + && (Random() % 10) == 0) + { + s32 j; + s32 rand = Random() % 100; + u8 lvlDivBy10 = (GetMonData(&gPlayerParty[i], MON_DATA_LEVEL) - 1) / 10; + if (lvlDivBy10 > 9) + lvlDivBy10 = 9; - for (j = 0; j < 9; j++) + for (j = 0; j < 9; j++) + { + if (sPickupProbabilities[j] > rand) { - if (sPickupProbabilities[j] > rand) - { - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]); - break; - } - else if (rand == 99 || rand == 98) - { - SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]); - break; - } + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sPickupItems[lvlDivBy10 + j]); + break; + } + else if (rand == 99 || rand == 98) + { + SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &sRarePickupItems[lvlDivBy10 + (99 - rand)]); + break; } } } diff --git a/src/battle_setup.c b/src/battle_setup.c index 18998e564..ab2a12fb7 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -34,6 +34,7 @@ #include "battle_tower.h" #include "gym_leader_rematch.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" @@ -54,7 +55,6 @@ struct TrainerBattleParameter u8 ptrType; }; -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); extern bool32 FieldPoisonEffectIsRunning(void); extern void RestartWildEncounterImmunitySteps(void); @@ -63,17 +63,13 @@ extern void sub_81BE72C(void); extern void sub_808BCF4(void); extern void sub_80EECC8(void); extern void sub_80AF6F0(void); -extern u16 sub_81A9AA8(u8 localId); extern u16 sub_81D6180(u8 localId); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjId); extern bool8 sub_81D5C18(void); -extern void sub_81A9B04(void); extern void sub_81D639C(void); extern void sub_81D6384(void); extern void sub_81D61E8(void); extern void sub_80982B8(void); -extern void sub_81A9EDC(u16 a0); extern void CopyTrainerHillTrainerText(u8 a0, u16 arg1); // this file's functions @@ -1131,12 +1127,12 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) { TrainerBattleLoadArgs(sOrdinaryBattleParams, data); SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_A = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } else { TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - gTrainerBattleOpponent_B = sub_81A9AA8(gSpecialVar_LastTalked); + gTrainerBattleOpponent_B = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } return EventScript_271362; case TRAINER_BATTLE_SET_TRAINER_A: @@ -1360,9 +1356,9 @@ void ShowTrainerIntroSpeech(void) if (InBattlePyramid()) { if (gNoOfApproachingTrainers == 0 || gNoOfApproachingTrainers == 1) - sub_81A9EDC(sub_81A9AA8(gSpecialVar_LastTalked)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gSpecialVar_LastTalked)); else - sub_81A9EDC(sub_81A9AA8(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); + CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gEventObjects[gApproachingTrainers[gApproachingTrainerId].eventObjectId].localId)); sub_80982B8(); } diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index 8da8502b3..72d0daf55 100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -10,6 +10,7 @@ #include "bg.h" #include "text_window.h" #include "constants/songs.h" +#include "constants/rgb.h" extern const u8 gText_ClearAllSaveData[]; extern const u8 gText_ClearingData[]; @@ -72,7 +73,7 @@ static const struct WindowTemplate sClearSaveYesNo[] = void CB2_InitClearSaveDataScreen(void) { - if(SetupClearSaveDataScreen()) + if (SetupClearSaveDataScreen()) CreateTask(Task_DoClearSaveDataScreenYesNo, 0); } @@ -86,18 +87,18 @@ static void Task_DoClearSaveDataScreenYesNo(u8 taskId) static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId) { - switch(Menu_ProcessInputNoWrapClearOnChoose()) + switch (Menu_ProcessInputNoWrapClearOnChoose()) { - case 0: - FillWindowPixelBuffer(0, 17); - AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); - gTasks[taskId].func = Task_ClearSaveData; - break; - case 1: - case -1: - PlaySE(SE_SELECT); - DestroyTask(taskId); - SetMainCallback2(CB2_FadeAndDoReset); + case 0: + FillWindowPixelBuffer(0, 17); + AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); + gTasks[taskId].func = Task_ClearSaveData; + break; + case 1: + case -1: + PlaySE(SE_SELECT); + DestroyTask(taskId); + SetMainCallback2(CB2_FadeAndDoReset); } } @@ -125,55 +126,55 @@ static bool8 SetupClearSaveDataScreen(void) switch(gMain.state) { - case 0: - default: - SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); - SetGpuReg(REG_OFFSET_BG0HOFS, 0); - SetGpuReg(REG_OFFSET_BG0VOFS, 0); - SetGpuReg(REG_OFFSET_BG3HOFS, 0); - SetGpuReg(REG_OFFSET_BG3VOFS, 0); - SetGpuReg(REG_OFFSET_WIN0H, 0); - SetGpuReg(REG_OFFSET_WIN0V, 0); - SetGpuReg(REG_OFFSET_WININ, 0); - SetGpuReg(REG_OFFSET_WINOUT, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0); - SetGpuReg(REG_OFFSET_BLDALPHA, 0); - SetGpuReg(REG_OFFSET_BLDY, 0); - DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); - DmaFill32(3, 0, (void *)OAM, OAM_SIZE); - DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); - ResetPaletteFade(); - gPlttBufferUnfaded[0] = 0x7fff; - gPlttBufferFaded[0] = 0x7fff; - gPlttBufferUnfaded[1] = 0x3945; - gPlttBufferFaded[1] = 0x3945; - for (i = 0; i < 0x10; i++) - ((u16 *)(VRAM + 0x20))[i] = 0x1111; - - for (i = 0; i < 0x400; i++) - ((u16 *)(VRAM + 0xF000))[i] = 0x0001; - ResetTasks(); - ResetSpriteData(); - ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); - SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); - ShowBg(0); - ShowBg(3); - SetGpuReg(REG_OFFSET_BLDCNT, 0); - InitClearSaveDataScreenWindows(); - BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); - EnableInterrupts(1); - SetVBlankCallback(VBlankCB); - gMain.state = 1; - break; - case 1: - UpdatePaletteFade(); - if(!gPaletteFade.active) - { - SetMainCallback2(MainCB); - return TRUE; - } + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); + DmaFill32(3, 0, (void *)OAM, OAM_SIZE); + DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); + ResetPaletteFade(); + gPlttBufferUnfaded[0] = RGB_WHITE; + gPlttBufferFaded[0] = RGB_WHITE; + gPlttBufferUnfaded[1] = RGB(5, 10, 14); + gPlttBufferFaded[1] = RGB(5, 10, 14); + for (i = 0; i < 0x10; i++) + ((u16 *)(VRAM + 0x20))[i] = 0x1111; + + for (i = 0; i < 0x400; i++) + ((u16 *)(VRAM + 0xF000))[i] = 0x0001; + ResetTasks(); + ResetSpriteData(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, sClearSaveBgTemplates, ARRAY_COUNT(sClearSaveBgTemplates)); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(3); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + InitClearSaveDataScreenWindows(); + BeginNormalPaletteFade(0x0000FFFF, 0, 0x10, 0, 0xFFFF); + EnableInterrupts(INTR_FLAG_VBLANK); + SetVBlankCallback(VBlankCB); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + SetMainCallback2(MainCB); + return TRUE; + } } return FALSE; } @@ -182,18 +183,19 @@ static void CB2_FadeAndDoReset(void) { switch(gMain.state) { - case 0: - default: - BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, 0xFFFF); - gMain.state = 1; - break; - case 1: - UpdatePaletteFade(); - if(!gPaletteFade.active) - { - FreeAllWindowBuffers(); - DoSoftReset(); - } + case 0: + default: + BeginNormalPaletteFade(0x0000FFFF, 0, 0, 0x10, RGB_WHITEALPHA); + gMain.state = 1; + break; + case 1: + UpdatePaletteFade(); + if(!gPaletteFade.active) + { + FreeAllWindowBuffers(); + DoSoftReset(); + } + break; } } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 93be006ea..cd5a547a9 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2559,7 +2559,7 @@ struct EventObjectTemplate *GetBaseTemplateForEventObject(const struct EventObje { return NULL; } - for (i = 0; i < 64; i++) // Using ARRAY_COUNT here results in the wrong conditional branch instruction (bls instead of ble) + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) { if (eventObject->localId == gSaveBlock1Ptr->eventObjectTemplates[i].localId) { diff --git a/src/graphics.c b/src/graphics.c index b055e5249..005737035 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1485,7 +1485,7 @@ const u32 gUnknown_08DD4C4C[] = INCBIN_U32("graphics/link/link_winedge.bin.lz"); const u32 gUnknown_08DD4CF8[] = INCBIN_U32("graphics/interface/unk_change_case.4bpp.lz"); -const u16 gTilesetPalettes_General[][16] = +const u16 gTilesetPalettes_General[][16] = { INCBIN_U16("data/tilesets/primary/general/palettes/00.gbapal"), INCBIN_U16("data/tilesets/primary/general/palettes/01.gbapal"), diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 12f04092b..514eb365d 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -521,7 +521,7 @@ static void Task_Hof_InitTeamSaveData(u8 taskId) static void Task_Hof_TrySaveData(u8 taskId) { gGameContinueCallback = CB2_DoHallOfFameScreenDontSaveData; - if (TrySavingData(3) == 0xFF && gDamagedSaveSectors != 0) + if (TrySavingData(SAVE_HALL_OF_FAME) == 0xFF && gDamagedSaveSectors != 0) { UnsetBgTilemapBuffer(1); UnsetBgTilemapBuffer(3); diff --git a/src/item.c b/src/item.c index b4a2fd6f0..b2c009be6 100644 --- a/src/item.c +++ b/src/item.c @@ -10,9 +10,9 @@ #include "item_menu.h" #include "strings.h" #include "load_save.h" +#include "battle_pyramid.h" #include "battle_pyramid_bag.h" -extern bool8 InBattlePyramid(void); extern u16 gUnknown_0203CF30[]; extern const struct Item gItems[]; diff --git a/src/load_save.c b/src/load_save.c index 45b4d200b..960a98981 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -6,14 +6,15 @@ #include "random.h" #include "malloc.h" #include "item.h" +#include "overworld.h" +#include "decoration_inventory.h" + +static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); extern void* gUnknown_0203CF5C; extern bool16 IdentifyFlash(void); -extern void SetDecorationInventoriesPointers(void); -extern void ApplyNewEncryptionKeyToGameStats(u32 key); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); -extern void sub_8084FAC(int unused); #define SAVEBLOCK_MOVE_RANGE 128 @@ -286,7 +287,7 @@ void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey) *word ^= newKey; } -void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) +static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey) { ApplyNewEncryptionKeyToGameStats(encryptionKey); ApplyNewEncryptionKeyToBagItems_(encryptionKey); diff --git a/src/overworld.c b/src/overworld.c index 69ac9c822..28d2d02ca 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1,5 +1,6 @@ #include "global.h" #include "overworld.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "berry.h" #include "bg.h" @@ -113,7 +114,6 @@ extern void ShowMapNamePopup(void); extern bool32 InTrainerHill(void); extern bool32 sub_808651C(void); extern bool8 sub_80AF6A4(void); -extern bool8 sub_81A9E6C(void); extern bool8 sub_80E909C(void); extern void sub_81AA1D8(void); extern void c2_change_map(void); @@ -517,7 +517,7 @@ void LoadSaveblockEventObjScripts(void) struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates; s32 i; - for (i = 0; i < 64; i++) + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) savObjTemplates[i].script = mapHeaderObjTemplates[i].script; } @@ -526,7 +526,7 @@ void Overworld_SetEventObjTemplateCoords(u8 localId, s16 x, s16 y) s32 i; struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates; - for (i = 0; i < 64; i++) + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) { struct EventObjectTemplate *eventObjectTemplate = &savObjTemplates[i]; if (eventObjectTemplate->localId == localId) @@ -543,7 +543,7 @@ void Overworld_SetEventObjTemplateMovementType(u8 localId, u8 movementType) s32 i; struct EventObjectTemplate *savObjTemplates = gSaveBlock1Ptr->eventObjectTemplates; - for (i = 0; i < 64; i++) + for (i = 0; i < EVENT_OBJECT_TEMPLATES_COUNT; i++) { struct EventObjectTemplate *eventObjectTemplate = &savObjTemplates[i]; if (eventObjectTemplate->localId == localId) @@ -764,7 +764,7 @@ void sub_8084F6C(u8 a1) SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y); } -void sub_8084FAC(void) +void sub_8084FAC(int unused) { gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2; } @@ -1808,7 +1808,7 @@ static void InitCurrentFlashLevelScanlineEffect(void) { u8 flashLevel; - if (sub_81A9E6C()) + if (InBattlePyramid_()) { door_upload_tiles(); ScanlineEffect_SetParams(sFlashEffectParams); diff --git a/src/pokemon.c b/src/pokemon.c index 47c4f9217..0f7c80b77 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -4,6 +4,7 @@ #include "battle_controllers.h" #include "battle_message.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "battle_setup.h" #include "battle_tower.h" #include "event_data.h" @@ -81,9 +82,7 @@ extern u8 StorageGetCurrentBox(void); extern void set_unknown_box_id(u8); extern void sub_803FA70(u8 battlerId); extern u8 sav1_map_get_name(void); -extern bool8 InBattlePyramid(void); extern bool8 sub_806F104(void); -extern u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerOpponentId); extern u8 sub_81D63C8(u16 trainerOpponentId); extern void SummaryScreen_SetUnknownTaskId(u8); diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 50dd2efa8..5d79cb789 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -490,7 +490,7 @@ bool32 MoveRecordedBattleToSaveData(void) static bool32 TryCopyRecordedBattleSaveData(struct RecordedBattleSave *dst, struct SaveSection *saveBuffer) { - if (TryCopySpecialSaveSection(SECTION_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) + if (TryCopySpecialSaveSection(SECTOR_ID_RECORDED_BATTLE, (void*)(saveBuffer)) != 1) return FALSE; memcpy(dst, saveBuffer, sizeof(struct RecordedBattleSave)); diff --git a/src/save.c b/src/save.c index 0bd48cca9..3ee98f4f7 100644 --- a/src/save.c +++ b/src/save.c @@ -1,15 +1,23 @@ #include "global.h" #include "gba/flash_internal.h" #include "save.h" -#include "constants/game_stat.h" #include "task.h" #include "decompress.h" #include "load_save.h" #include "overworld.h" +#include "main.h" +#include "constants/game_stat.h" + +static u16 CalculateChecksum(void *data, u16 size); +static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); +static u8 GetSaveValidStatus(const struct SaveSectionLocation *location); +static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); +static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location); +static u8 TryWriteSector(u8 sector, u8 *data); +static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); // for the chunk declarations -extern bool8 gSoftResetDisabled; extern u32 gUnknown_0203CF5C; // Divide save blocks into individual chunks to be written to flash sectors @@ -24,7 +32,7 @@ extern u32 gUnknown_0203CF5C; * Sectors 0 - 13: Save Slot 1 * Sectors 14 - 27: Save Slot 2 * Sectors 28 - 29: Hall of Fame - * Sector 30: e-Reader/Mystery Gift Stuff (note: e-Reader is deprecated in Emerald US) + * Sector 30: Trainer Hill * Sector 31: Recorded Battle * * There are two save slots for saving the player's game data. We alternate between @@ -105,7 +113,7 @@ void Save_ResetSaveCounters(void) gDamagedSaveSectors = 0; } -bool32 SetDamagedSectorBits(u8 op, u8 bit) +static bool32 SetDamagedSectorBits(u8 op, u8 bit) { bool32 retVal = FALSE; @@ -126,7 +134,7 @@ bool32 SetDamagedSectorBits(u8 op, u8 bit) return retVal; } -u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) +static u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) { u32 retVal; u16 i; @@ -142,11 +150,11 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) gLastKnownGoodSector = gLastWrittenSector; // backup the current written sector before attempting to write. gLastSaveCounter = gSaveCounter; gLastWrittenSector++; - gLastWrittenSector = gLastWrittenSector % 0xE; // array count save sector locations + gLastWrittenSector = gLastWrittenSector % SECTOR_SAVE_SLOT_LENGTH; // array count save sector locations gSaveCounter++; retVal = 1; - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) HandleWriteSector(i, location); if (gDamagedSaveSectors != 0) // skip the damaged sector. @@ -160,7 +168,7 @@ u8 save_write_to_flash(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) +static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 sector; @@ -168,8 +176,8 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) u16 size; sector = a1 + gLastWrittenSector; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); data = location[a1].data; size = location[a1].size; @@ -189,7 +197,7 @@ u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location) return TryWriteSector(sector, gFastSaveSection->data); } -u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) +static u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) { u16 i; struct SaveSection *section = &gSaveDataBuffer; @@ -206,7 +214,7 @@ u8 HandleWriteSectorNBytes(u8 sector, u8 *data, u16 size) return TryWriteSector(sector, section->data); } -u8 TryWriteSector(u8 sector, u8 *data) +static u8 TryWriteSector(u8 sector, u8 *data) { if (ProgramFlashSectorAndVerify(sector, data) != 0) // is damaged? { @@ -220,20 +228,20 @@ u8 TryWriteSector(u8 sector, u8 *data) } } -u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused +static u32 RestoreSaveBackupVarsAndIncrement(const struct SaveSectionLocation *location) // location is unused { gFastSaveSection = &gSaveDataBuffer; gLastKnownGoodSector = gLastWrittenSector; gLastSaveCounter = gSaveCounter; gLastWrittenSector++; - gLastWrittenSector = gLastWrittenSector % 0xE; + gLastWrittenSector %= SECTOR_SAVE_SLOT_LENGTH; gSaveCounter++; gUnknown_03006208 = 0; gDamagedSaveSectors = 0; return 0; } -u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused +static u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ever called once, and gSaveBlock2 is passed to this function. location is unused { gFastSaveSection = &gSaveDataBuffer; gLastKnownGoodSector = gLastWrittenSector; @@ -243,7 +251,7 @@ u32 RestoreSaveBackupVars(const struct SaveSectionLocation *location) // only ev return 0; } -u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) { u8 retVal; @@ -267,7 +275,7 @@ u8 sub_81529D4(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) { u8 retVal = 1; @@ -282,7 +290,7 @@ u8 sub_8152A34(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) +static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 sector; @@ -291,8 +299,8 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) u8 status; sector = a1 + gLastWrittenSector; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); data = location[a1].data; size = location[a1].size; @@ -356,13 +364,13 @@ u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location) } } -u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) +static u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector; // no sub 1? - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) { @@ -379,13 +387,13 @@ u8 sav12_xor_get(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector - 1; - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), ((u8 *)gFastSaveSection)[sizeof(struct UnkSaveSection)])) { @@ -402,13 +410,13 @@ u8 sub_8152CAC(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) { u16 sector; sector = a1 + gLastWrittenSector - 1; // no sub 1? - sector %= 0xE; - sector += 0xE * (gSaveCounter % 2); + sector %= SECTOR_SAVE_SLOT_LENGTH; + sector += SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); if (ProgramFlashByte(sector, sizeof(struct UnkSaveSection), 0x25)) { @@ -425,7 +433,7 @@ u8 sub_8152D44(u16 a1, const struct SaveSectionLocation *location) } } -u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) { u8 retVal; gFastSaveSection = &gSaveDataBuffer; @@ -442,14 +450,14 @@ u8 sub_8152DD0(u16 a1, const struct SaveSectionLocation *location) return retVal; } -u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) +static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) { u16 i; u16 checksum; - u16 v3 = 0xE * (gSaveCounter % 2); + u16 v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); u16 id; - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i + v3, gFastSaveSection); id = gFastSaveSection->id; @@ -468,7 +476,7 @@ u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location) return 1; } -u8 GetSaveValidStatus(const struct SaveSectionLocation *location) +static u8 GetSaveValidStatus(const struct SaveSectionLocation *location) { u16 i; u16 checksum; @@ -480,7 +488,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) u8 saveSlot2Status; // check save slot 1. - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i, gFastSaveSection); if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) @@ -511,9 +519,9 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) securityPassed = FALSE; // check save slot 2. - for (i = 0; i < 0xE; i++) + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { - DoReadFlashWholeSection(i + 0xE, gFastSaveSection); + DoReadFlashWholeSection(i + SECTOR_SAVE_SLOT_LENGTH, gFastSaveSection); if (gFastSaveSection->security == UNKNOWN_CHECK_VALUE) { securityPassed = TRUE; @@ -543,24 +551,16 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) if ((saveSlot1Counter == -1 && saveSlot2Counter == 0) || (saveSlot1Counter == 0 && saveSlot2Counter == -1)) { if ((unsigned)(saveSlot1Counter + 1) < (unsigned)(saveSlot2Counter + 1)) - { gSaveCounter = saveSlot2Counter; - } else - { gSaveCounter = saveSlot1Counter; - } } else { if (saveSlot1Counter < saveSlot2Counter) - { gSaveCounter = saveSlot2Counter; - } else - { gSaveCounter = saveSlot1Counter; - } } return 1; } @@ -593,7 +593,7 @@ u8 GetSaveValidStatus(const struct SaveSectionLocation *location) return 2; } -u8 sub_81530DC(u8 a1, u8 *data, u16 size) +static u8 sub_81530DC(u8 a1, u8 *data, u16 size) { u16 i; struct SaveSection *section = &gSaveDataBuffer; @@ -618,13 +618,13 @@ u8 sub_81530DC(u8 a1, u8 *data, u16 size) } } -u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) +static u8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) { ReadFlash(sector, 0, section->data, sizeof(struct SaveSection)); return 1; } -u16 CalculateChecksum(void *data, u16 size) +static u16 CalculateChecksum(void *data, u16 size) { u16 i; u32 checksum = 0; @@ -635,7 +635,7 @@ u16 CalculateChecksum(void *data, u16 size) return ((checksum >> 16) + checksum); } -void UpdateSaveAddresses(void) +static void UpdateSaveAddresses(void) { int i = 0; @@ -668,7 +668,7 @@ u8 HandleSavingData(u8 saveType) switch (saveType) { case SAVE_HALL_OF_FAME_ERASE_BEFORE: // deletes HOF before overwriting HOF completely. unused - for (i = 0xE * 2 + 0; i < 32; i++) + for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++) EraseFlashSector(i); case SAVE_HALL_OF_FAME: // hall of fame. if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999) @@ -676,8 +676,8 @@ u8 HandleSavingData(u8 saveType) SaveSerializedGame(); save_write_to_flash(0xFFFF, gRamSaveSectionLocations); tempAddr = gDecompressionBuffer; - HandleWriteSectorNBytes(0x1C, tempAddr, 0xF80); - HandleWriteSectorNBytes(0x1D, tempAddr + 0xF80, 0xF80); + HandleWriteSectorNBytes(SECTOR_ID_HOF_1, tempAddr, 0xF80); + HandleWriteSectorNBytes(SECTOR_ID_HOF_2, tempAddr + 0xF80, 0xF80); break; case SAVE_NORMAL: // normal save. also called by overwriting your own save. default: @@ -692,7 +692,7 @@ u8 HandleSavingData(u8 saveType) for(i = 0; i < 5; i++) sav12_xor_get(i, gRamSaveSectionLocations); break; - // support for Ereader was removed in Emerald. + // Support for Ereader was removed in Emerald. /* case EREADER_SAVE: // used in mossdeep "game corner" before/after battling old man e-reader trainer SaveSerializedGame(); @@ -700,7 +700,7 @@ u8 HandleSavingData(u8 saveType) break; */ case SAVE_OVERWRITE_DIFFERENT_FILE: - for (i = (0xE * 2 + 0); i < 32; i++) + for (i = SECTOR_ID_HOF_1; i < SECTORS_COUNT; i++) EraseFlashSector(i); // erase HOF. SaveSerializedGame(); save_write_to_flash(0xFFFF, gRamSaveSectionLocations); @@ -710,7 +710,7 @@ u8 HandleSavingData(u8 saveType) return 0; } -u8 TrySavingData(u8 saveType) // TrySave +u8 TrySavingData(u8 saveType) { if (gFlashMemoryPresent != TRUE) { @@ -744,7 +744,7 @@ bool8 sub_8153380(void) // trade.s save bool8 sub_81533AC(void) // trade.s save { - u8 retVal = sub_81529D4(0xE, gRamSaveSectionLocations); + u8 retVal = sub_81529D4(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); if (retVal == 0xFF) @@ -755,7 +755,7 @@ bool8 sub_81533AC(void) // trade.s save u8 sub_81533E0(void) // trade.s save { - sub_8152A34(0xE, gRamSaveSectionLocations); + sub_8152A34(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); return 0; @@ -763,7 +763,7 @@ u8 sub_81533E0(void) // trade.s save u8 sub_8153408(void) // trade.s save { - sub_8152CAC(0xE, gRamSaveSectionLocations); + sub_8152CAC(SECTOR_SAVE_SLOT_LENGTH, gRamSaveSectionLocations); if (gDamagedSaveSectors) DoSaveFailedScreen(0); return 0; @@ -840,8 +840,8 @@ u16 sub_815355C(void) return 0; UpdateSaveAddresses(); GetSaveValidStatus(gRamSaveSectionLocations); - v3 = 0xE * (gSaveCounter % 2); - for (i = 0; i < 14; i++) + v3 = SECTOR_SAVE_SLOT_LENGTH * (gSaveCounter % 2); + for (i = 0; i < SECTOR_SAVE_SLOT_LENGTH; i++) { DoReadFlashWholeSection(i + v3, gFastSaveSection); if (gFastSaveSection->id == 0) @@ -859,7 +859,7 @@ u32 TryCopySpecialSaveSection(u8 sector, u8* dst) s32 size; u8* savData; - if (sector != 30 && sector != 31) + if (sector != SECTOR_ID_TRAINER_HILL && sector != SECTOR_ID_RECORDED_BATTLE) return 0xFF; ReadFlash(sector, 0, (u8 *)&gSaveDataBuffer, sizeof(struct SaveSection)); if (*(u32*)(&gSaveDataBuffer.data[0]) != 0xB39D) diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 010279a87..c668c1db0 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -13,16 +13,17 @@ #include "starter_choose.h" #include "gba/flash_internal.h" #include "text_window.h" +#include "constants/rgb.h" #define MSG_WIN_TOP 12 #define CLOCK_WIN_TOP (MSG_WIN_TOP - 4) -extern u8 gText_SaveFailedCheckingBackup[]; -extern u8 gText_BackupMemoryDamaged[]; -extern u8 gText_CheckCompleted[]; -extern u8 gText_SaveCompleteGameCannotContinue[]; -extern u8 gText_SaveCompletePressA[]; -extern u8 gText_GamePlayCannotBeContinued[]; +extern const u8 gText_SaveFailedCheckingBackup[]; +extern const u8 gText_BackupMemoryDamaged[]; +extern const u8 gText_CheckCompleted[]; +extern const u8 gText_SaveCompleteGameCannotContinue[]; +extern const u8 gText_SaveCompletePressA[]; +extern const u8 gText_GamePlayCannotBeContinued[]; // gSaveFailedClockInfo enum enum @@ -155,8 +156,8 @@ static void VBlankCB_UpdateClockGraphics(void); static bool8 VerifySectorWipe(u16 sector); static bool8 WipeSectors(u32); -// although this is a general text printer, it's only used in this file. -static void SaveFailedScreenTextPrint(u8 *text, u8 var1, u8 var2) +// Although this is a general text printer, it's only used in this file. +static void SaveFailedScreenTextPrint(const u8 *text, u8 var1, u8 var2) { u8 color[3]; @@ -187,72 +188,70 @@ static void CB2_SaveFailedScreen(void) { switch (gMain.state) { - case 0: - default: - SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, 0); - SetGpuReg(REG_OFFSET_BG3CNT, 0); - SetGpuReg(REG_OFFSET_BG2CNT, 0); - SetGpuReg(REG_OFFSET_BG1CNT, 0); - SetGpuReg(REG_OFFSET_BG0CNT, 0); - SetGpuReg(REG_OFFSET_BG3HOFS, 0); - SetGpuReg(REG_OFFSET_BG3VOFS, 0); - SetGpuReg(REG_OFFSET_BG2HOFS, 0); - SetGpuReg(REG_OFFSET_BG2VOFS, 0); - SetGpuReg(REG_OFFSET_BG1HOFS, 0); - SetGpuReg(REG_OFFSET_BG1VOFS, 0); - SetGpuReg(REG_OFFSET_BG0HOFS, 0); - SetGpuReg(REG_OFFSET_BG0VOFS, 0); - // how come this doesnt use the Dma manager? - DmaFill16(3, 0, VRAM, VRAM_SIZE); - DmaFill32(3, 0, OAM, OAM_SIZE); - DmaFill16(3, 0, PLTT, PLTT_SIZE); - LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); - LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); - LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); - LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020)); - ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_085EFD88, 3); - SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); - CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); - LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214); - InitWindows(gUnknown_085EFD94); - // AddWindowWithoutTileMap returns a u16/integer, but the info is clobbered into a u8 here resulting in lost info. Bug? - gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); - SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); - gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); - SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); - DeactivateAllTextPrinters(); - ResetSpriteData(); - ResetTasks(); - ResetPaletteFade(); - LoadPalette(gBirchBagGrassPal, 0, 0x40); - LoadPalette(sSaveFailedClockPal, 0x100, 0x20); - LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); - LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); - SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); - FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); - CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? - CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); - SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); - BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); - EnableInterrupts(1); - SetVBlankCallback(VBlankCB); - SetGpuReg(0, 0x1040); - ShowBg(0); - ShowBg(2); - ShowBg(3); - gMain.state++; - break; - case 1: - if (!UpdatePaletteFade()) - { - SetMainCallback2(CB2_WipeSave); - SetVBlankCallback(VBlankCB_UpdateClockGraphics); - } - break; + case 0: + default: + SetVBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + DmaFill16(3, 0, VRAM, VRAM_SIZE); + DmaFill32(3, 0, OAM, OAM_SIZE); + DmaFill16(3, 0, PLTT, PLTT_SIZE); + LZ77UnCompVram(gBirchHelpGfx, (void *)VRAM); + LZ77UnCompVram(gBirchBagTilemap, (void *)(VRAM + 0x7000)); + LZ77UnCompVram(gBirchGrassTilemap, (void *)(VRAM + 0x7800)); + LZ77UnCompVram(sSaveFailedClockGfx, (void *)(VRAM + 0x10020)); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_085EFD88, 3); + SetBgTilemapBuffer(0, (void *)&gDecompressionBuffer[0x2000]); + CpuFill32(0, &gDecompressionBuffer[0x2000], 0x800); + LoadBgTiles(0, gTextWindowFrame1_Gfx, 0x120, 0x214); + InitWindows(gUnknown_085EFD94); + gSaveFailedWindowIds[TEXT_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFD9C); + SetWindowAttribute(gSaveFailedWindowIds[TEXT_WIN_ID], 7, (u32)&gDecompressionBuffer[0x2800]); + gSaveFailedWindowIds[CLOCK_WIN_ID] = AddWindowWithoutTileMap(gUnknown_085EFDA4); + SetWindowAttribute(gSaveFailedWindowIds[CLOCK_WIN_ID], 7, (u32)&gDecompressionBuffer[0x3D00]); + DeactivateAllTextPrinters(); + ResetSpriteData(); + ResetTasks(); + ResetPaletteFade(); + LoadPalette(gBirchBagGrassPal, 0, 0x40); + LoadPalette(sSaveFailedClockPal, 0x100, 0x20); + LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); + LoadPalette(gUnknown_0860F074, 0xF0, 0x20); + SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); + SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? + CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); + SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); + EnableInterrupts(1); + SetVBlankCallback(VBlankCB); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(2); + ShowBg(3); + gMain.state++; + break; + case 1: + if (!UpdatePaletteFade()) + { + SetMainCallback2(CB2_WipeSave); + SetVBlankCallback(VBlankCB_UpdateClockGraphics); + } + break; } } @@ -346,7 +345,7 @@ static void CB2_ReturnToTitleScreen(void) static void VBlankCB_UpdateClockGraphics(void) { - unsigned int n = (gMain.vblankCounter2 >> 3) & 7; + u32 n = (gMain.vblankCounter2 >> 3) & 7; gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; diff --git a/src/save_location.c b/src/save_location.c index 262aaf40c..d49afa736 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -9,21 +9,18 @@ static bool32 IsCurMapInLocationList(const u16 *list) { + s32 i; u16 locSum = (gSaveBlock1Ptr->location.mapGroup << 8) + (gSaveBlock1Ptr->location.mapNum); - // im sure it was written a different way, but for the love of christ I cant figure out how to write it different where it still matches. - if (*list != 0xFFFF) + for (i = 0; list[i] != 0xFFFF; i++) { - u16 termValue = 0xFFFF; - const u16 *localList; - for (localList = list; *localList != termValue; localList++) - if (*localList == locSum) - return TRUE; + if (list[i] == locSum) + return TRUE; } + return FALSE; } -// TODO: Not require a packed u16 array for these lists static const u16 sSaveLocationPokeCenterList[] = { MAP_OLDALE_TOWN_POKEMON_CENTER_1F, @@ -72,7 +69,7 @@ static bool32 IsCurMapPokeCenter(void) return IsCurMapInLocationList(sSaveLocationPokeCenterList); } -static const u16 sSaveLocationReloadLocList[] = // there's only 1 location, and it's presumed its for the save reload feature for battle tower +static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower. { MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY, 0xFFFF, @@ -83,13 +80,13 @@ static bool32 IsCurMapReloadLocation(void) return IsCurMapInLocationList(sSaveLocationReloadLocList); } -// nulled out list. unknown what this would have been +// Nulled out list. Unknown what this would have been. static const u16 sUnknown_0861440E[] = { 0xFFFF, }; -bool32 sub_81AFCEC(void) +static bool32 sub_81AFCEC(void) { return IsCurMapInLocationList(sUnknown_0861440E); } diff --git a/src/start_menu.c b/src/start_menu.c index 173d0a79f..976cbe2a6 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -460,18 +460,18 @@ static bool32 InitStartMenuStep(void) sUnknown_02037619[0]++; break; case 3: - if (GetSafariZoneFlag() != FALSE) + if (GetSafariZoneFlag()) { ShowSafariBallsWindow(); } - if (InBattlePyramid() != FALSE) + if (InBattlePyramid()) { ShowPyramidFloorWindow(); } sUnknown_02037619[0]++; break; case 4: - if (PrintStartMenuActions(&sUnknown_02037619[1], 2) == FALSE) + if (!PrintStartMenuActions(&sUnknown_02037619[1], 2)) { break; } diff --git a/src/trainer_see.c b/src/trainer_see.c index 726d89847..b74608d0b 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -12,11 +12,10 @@ #include "task.h" #include "trainer_see.h" #include "util.h" +#include "battle_pyramid.h" #include "constants/field_effects.h" -extern bool8 InBattlePyramid(void); extern bool32 InTrainerHill(void); -extern bool8 GetBattlePyramidTrainerFlag(u8 eventObjectId); extern bool8 GetTrainerHillTrainerFlag(u8 eventObjectId); extern void sub_809BE48(u16 npcId); diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 52dbdf65e..9b3c70ad7 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -19,6 +19,7 @@ #include "link.h" #include "script.h" #include "battle_pike.h" +#include "battle_pyramid.h" #include "constants/items.h" #include "constants/maps.h" @@ -26,9 +27,6 @@ extern const u8 EventScript_RepelWoreOff[]; #define NUM_FEEBAS_SPOTS 6 -extern void GenerateBattlePyramidWildMon(void); -extern bool8 InBattlePyramid(void); - // this file's functions static u16 FeebasRandom(void); static void FeebasSeedRng(u16 seed); |