pokeemerald/src/secret_base.c

2088 lines
56 KiB
C
Raw Normal View History

2017-10-24 00:35:06 +02:00
#include "global.h"
#include "alloc.h"
2019-01-02 00:19:07 +01:00
#include "battle.h"
#include "battle_setup.h"
#include "decoration.h"
#include "event_data.h"
#include "event_object_movement.h"
#include "event_scripts.h"
2017-10-25 02:19:33 +02:00
#include "field_camera.h"
2019-01-02 00:19:07 +01:00
#include "field_effect.h"
2017-10-24 01:29:16 +02:00
#include "field_player_avatar.h"
2018-12-08 22:05:11 +01:00
#include "field_screen_effect.h"
2019-01-02 00:19:07 +01:00
#include "field_specials.h"
2017-10-25 03:27:46 +02:00
#include "field_weather.h"
2019-01-02 00:19:07 +01:00
#include "fieldmap.h"
2018-12-24 21:59:05 +01:00
#include "fldeff.h"
2018-12-20 04:19:54 +01:00
#include "fldeff_misc.h"
2019-01-02 00:19:07 +01:00
#include "international_string_util.h"
#include "link.h"
#include "list_menu.h"
#include "main.h"
2017-10-25 03:41:22 +02:00
#include "map_name_popup.h"
2019-01-02 00:19:07 +01:00
#include "menu.h"
#include "menu_helpers.h"
#include "metatile_behavior.h"
#include "overworld.h"
#include "palette.h"
2017-10-25 03:41:22 +02:00
#include "script.h"
2019-01-02 00:19:07 +01:00
#include "secret_base.h"
#include "sound.h"
#include "string_util.h"
2017-10-27 03:39:34 +02:00
#include "strings.h"
2019-01-02 00:19:07 +01:00
#include "task.h"
2017-10-28 04:12:11 +02:00
#include "tv.h"
2019-01-02 00:19:07 +01:00
#include "window.h"
#include "constants/bg_event_constants.h"
#include "constants/decorations.h"
#include "constants/maps.h"
2018-07-13 05:39:38 +02:00
#include "constants/map_types.h"
2019-01-02 00:19:07 +01:00
#include "constants/metatile_behaviors.h"
2019-01-05 21:12:50 +01:00
#include "constants/secret_bases.h"
2019-01-02 00:19:07 +01:00
#include "constants/songs.h"
#include "constants/species.h"
2018-10-21 20:13:12 +02:00
#include "constants/trainers.h"
2017-10-24 00:35:06 +02:00
2018-02-14 01:12:17 +01:00
extern void mapldr_default(void);
2017-10-24 00:35:06 +02:00
// Static type declarations
2017-10-24 00:56:18 +02:00
struct SecretBaseListMenuBuffer {
struct ListMenuItem items[11];
u8 names[11][32];
};
2017-10-28 03:17:17 +02:00
struct SecretBaseRecordMixer {
struct SecretBaseRecord *records;
u32 version;
u32 language;
};
2017-10-24 00:35:06 +02:00
// Static RAM declarations
2017-10-24 01:21:08 +02:00
EWRAM_DATA u8 sCurSecretBaseId = 0;
2017-10-24 00:56:18 +02:00
EWRAM_DATA u8 gUnknown_0203A01D = 0;
EWRAM_DATA struct SecretBaseListMenuBuffer *gUnknown_0203A020 = NULL;
2017-10-24 00:35:06 +02:00
// Static ROM declarations
2017-10-27 03:39:34 +02:00
void sub_80E9C9C(u8 taskId);
void game_continue(u8 taskId);
2018-03-03 14:58:41 +01:00
void sub_80E9DEC(s32 a0, bool8 flag, struct ListMenu *menu);
2017-10-27 03:39:34 +02:00
void sub_80E9E00(u8 taskId);
2017-10-27 03:53:00 +02:00
void sub_80E9E44(u8 taskId);
2017-10-27 03:39:34 +02:00
void sub_80E9E90(u8 taskId);
2017-10-27 03:59:54 +02:00
void sub_80E9F20(u8 taskId);
2017-10-27 04:10:38 +02:00
void sub_80E9FB0(u8 taskId);
2017-10-28 05:21:09 +02:00
void sub_80E9FFC(u8 taskId);
2017-10-27 04:21:20 +02:00
void sub_80EA06C(u8 taskId);
2017-10-28 05:21:09 +02:00
void sub_80EA120(u8 taskId);
void sub_80EA13C(u8 taskId);
2017-10-27 04:37:16 +02:00
void sub_80EA18C(u8 taskId);
2017-10-27 03:39:34 +02:00
void task_pc_turn_off(u8 taskId);
2017-11-02 04:49:01 +01:00
u8 sub_80EA20C(u8 secretBaseRecordId);
2017-10-25 14:22:36 +02:00
2017-10-24 01:29:16 +02:00
// .rodata
2017-10-28 05:21:09 +02:00
const struct {
2017-10-25 02:19:33 +02:00
u16 tile1;
u16 tile2;
2017-10-28 05:21:09 +02:00
} gUnknown_0858CFCC[] = {
{0x0026, 0x0036},
{0x0027, 0x0037},
{0x01a0, 0x01a1},
{0x01a8, 0x01a9},
{0x01b0, 0x01b1},
{0x0208, 0x0210},
{0x0271, 0x0278}
};
const u8 gUnknown_0858CFE8[] = {
2017-12-05 18:55:48 +01:00
MAP_NUM(SECRET_BASE_RED_CAVE1), 0x00, 0x01, 0x03,
MAP_NUM(SECRET_BASE_RED_CAVE2), 0x00, 0x05, 0x09,
MAP_NUM(SECRET_BASE_RED_CAVE3), 0x00, 0x01, 0x03,
MAP_NUM(SECRET_BASE_RED_CAVE4), 0x00, 0x07, 0x0d,
MAP_NUM(SECRET_BASE_BROWN_CAVE1), 0x00, 0x02, 0x03,
MAP_NUM(SECRET_BASE_BROWN_CAVE2), 0x00, 0x09, 0x02,
MAP_NUM(SECRET_BASE_BROWN_CAVE3), 0x00, 0x0d, 0x04,
MAP_NUM(SECRET_BASE_BROWN_CAVE4), 0x00, 0x01, 0x02,
MAP_NUM(SECRET_BASE_BLUE_CAVE1), 0x00, 0x01, 0x03,
MAP_NUM(SECRET_BASE_BLUE_CAVE2), 0x00, 0x01, 0x02,
MAP_NUM(SECRET_BASE_BLUE_CAVE3), 0x00, 0x03, 0x0f,
MAP_NUM(SECRET_BASE_BLUE_CAVE4), 0x00, 0x03, 0x0e,
MAP_NUM(SECRET_BASE_YELLOW_CAVE1), 0x00, 0x09, 0x03,
MAP_NUM(SECRET_BASE_YELLOW_CAVE2), 0x00, 0x08, 0x07,
MAP_NUM(SECRET_BASE_YELLOW_CAVE3), 0x00, 0x03, 0x06,
MAP_NUM(SECRET_BASE_YELLOW_CAVE4), 0x00, 0x05, 0x09,
MAP_NUM(SECRET_BASE_TREE1), 0x00, 0x02, 0x03,
MAP_NUM(SECRET_BASE_TREE2), 0x00, 0x05, 0x06,
MAP_NUM(SECRET_BASE_TREE3), 0x00, 0x0f, 0x03,
MAP_NUM(SECRET_BASE_TREE4), 0x00, 0x04, 0x0a,
MAP_NUM(SECRET_BASE_SHRUB1), 0x00, 0x03, 0x03,
MAP_NUM(SECRET_BASE_SHRUB2), 0x00, 0x01, 0x02,
MAP_NUM(SECRET_BASE_SHRUB3), 0x00, 0x07, 0x08,
MAP_NUM(SECRET_BASE_SHRUB4), 0x00, 0x09, 0x06
2017-10-28 05:21:09 +02:00
};
const struct MenuAction gUnknown_0858D048[] = {
{gUnknown_085EA79D, {.void_u8 = sub_80E9FFC}},
{gText_Cancel, {.void_u8 = sub_80EA18C}}
};
const struct YesNoFuncTable gUnknown_0858D058 = {
sub_80EA120, sub_80EA13C
};
const u8 gUnknown_0858D060[10] = {
0x23, 0x24, 0x0f, 0x1f, 0x21,
0x2f, 0x0e, 0x14, 0x20, 0x22
};
2017-10-25 02:19:33 +02:00
2017-10-28 05:21:09 +02:00
const struct WindowTemplate gUnknown_0858D06C[] = {
{ 0, 18, 1, 11, 18, 15, 0x01 },
{ 0, 2, 1, 28, 4, 15, 0xc7 }
};
const struct ListMenuTemplate gUnknown_0858D07C = {
NULL,
sub_80E9DEC,
NULL,
0, 0,
0, 0, 8, 0,
9, 2, 1, 3, FALSE, 0, FALSE, 1
};
2017-10-25 03:10:58 +02:00
2017-10-24 01:29:16 +02:00
// .text
void ClearSecretBase(struct SecretBaseRecord *sbr)
2017-10-24 00:35:06 +02:00
{
u16 i;
CpuFastFill16(0, sbr, sizeof(struct SecretBaseRecord));
for (i = 0; i < 7; i ++)
{
sbr->trainerName[i] = EOS;
}
}
2017-10-24 00:56:18 +02:00
void ResetSecretBases(void)
{
u16 i;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-24 00:56:18 +02:00
{
ClearSecretBase(&gSaveBlock1Ptr->secretBases[i]);
2017-10-24 00:56:18 +02:00
}
}
void sub_80E8B58(void)
{
2017-10-24 01:21:08 +02:00
sCurSecretBaseId = gSpecialVar_0x8004;
}
void sub_80E8B6C(void)
{
u16 i;
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = FALSE;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-24 01:21:08 +02:00
{
if (sCurSecretBaseId != gSaveBlock1Ptr->secretBases[i].secretBaseId)
{
continue;
}
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = TRUE;
2018-12-10 01:22:59 +01:00
VarSet(VAR_CURRENT_SECRET_BASE, i);
2017-10-24 01:21:08 +02:00
break;
}
}
void sub_80E8BC8(void)
{
if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0)
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = TRUE;
2017-10-24 01:21:08 +02:00
}
else
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = FALSE;
2017-10-24 01:21:08 +02:00
}
2017-10-24 00:56:18 +02:00
}
2017-10-24 01:29:16 +02:00
u8 sub_80E8BF8(void)
{
s16 x;
s16 y;
s16 behavior;
2017-10-24 00:35:06 +02:00
2017-10-24 01:29:16 +02:00
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
behavior = MapGridGetMetatileBehaviorAt(x, y) & 0xFFF;
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_RED_CAVE || behavior == MB_SECRET_BASE_SPOT_RED_CAVE_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_RED_CAVE;
2017-10-24 01:29:16 +02:00
}
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_BROWN_CAVE || behavior == MB_SECRET_BASE_SPOT_BROWN_CAVE_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_BROWN_CAVE;
2017-10-24 01:29:16 +02:00
}
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_BLUE_CAVE || behavior == MB_SECRET_BASE_SPOT_BLUE_CAVE_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_BLUE_CAVE;
2017-10-24 01:29:16 +02:00
}
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_YELLOW_CAVE || behavior == MB_SECRET_BASE_SPOT_YELLOW_CAVE_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_YELLOW_CAVE;
2017-10-24 01:29:16 +02:00
}
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_TREE_LEFT || behavior == MB_SECRET_BASE_SPOT_TREE_LEFT_OPEN || behavior == MB_SECRET_BASE_SPOT_TREE_RIGHT || behavior == MB_SECRET_BASE_SPOT_TREE_RIGHT_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_TREE;
2017-10-24 01:29:16 +02:00
}
2019-01-02 00:19:07 +01:00
if (behavior == MB_SECRET_BASE_SPOT_SHRUB || behavior == MB_SECRET_BASE_SPOT_SHRUB_OPEN)
2017-10-24 01:29:16 +02:00
{
2019-01-05 21:12:50 +01:00
return SECRET_BASE_SHRUB;
2017-10-24 01:29:16 +02:00
}
return 0;
}
2017-10-25 02:19:33 +02:00
void sub_80E8C98(void)
{
gSpecialVar_0x8007 = sub_80E8BF8();
}
void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile)
{
2018-06-21 00:41:51 +02:00
const struct MapLayout *mapLayout;
2017-10-25 02:19:33 +02:00
s16 x;
s16 y;
2018-06-21 00:41:51 +02:00
mapLayout = gMapHeader.mapLayout;
for (y = 0; y < mapLayout->height; y ++)
2017-10-25 02:19:33 +02:00
{
2018-06-21 00:41:51 +02:00
for (x = 0; x < mapLayout->width; x ++)
2017-10-25 02:19:33 +02:00
{
2019-02-22 09:08:48 +01:00
if ((mapLayout->map[y * mapLayout->width + x] & MAP_METATILE_ID_MASK) == tile)
2017-10-25 02:19:33 +02:00
{
*xPtr = x;
*yPtr = y;
return;
}
}
}
}
void sub_80E8D4C(void)
{
s16 x;
s16 y;
s16 tile;
u16 i;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
tile = MapGridGetMetatileIdAt(x, y);
for (i = 0; i < 7; i ++)
{
if (gUnknown_0858CFCC[i].tile1 == tile)
{
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | MAP_IMPASSABLE_MASK);
2017-10-25 02:19:33 +02:00
CurrentMapDrawMetatileAt(x, y);
return;
}
}
for (i = 0; i < 7; i ++)
{
if (gUnknown_0858CFCC[i].tile2 == tile)
{
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile1 | MAP_IMPASSABLE_MASK);
2017-10-25 02:19:33 +02:00
CurrentMapDrawMetatileAt(x, y);
return;
}
}
}
2017-10-25 02:27:07 +02:00
u8 sub_80E8DF4(const u8 *src)
{
u8 i;
for (i = 0; i < 7; i ++)
{
if (src[i] == EOS)
{
return i;
}
}
return 7;
}
void sub_80E8E18(void)
{
u16 i;
gSaveBlock1Ptr->secretBases[0].secretBaseId = sCurSecretBaseId;
for (i = 0; i < 4; i ++)
{
gSaveBlock1Ptr->secretBases[0].trainerId[i] = gSaveBlock2Ptr->playerTrainerId[i];
}
2018-12-10 01:22:59 +01:00
VarSet(VAR_CURRENT_SECRET_BASE, 0);
2017-10-25 02:27:07 +02:00
StringCopyN(gSaveBlock1Ptr->secretBases[0].trainerName, gSaveBlock2Ptr->playerName, sub_80E8DF4(gSaveBlock2Ptr->playerName));
gSaveBlock1Ptr->secretBases[0].gender = gSaveBlock2Ptr->playerGender;
gSaveBlock1Ptr->secretBases[0].language = GAME_LANGUAGE;
VarSet(VAR_SECRET_BASE_MAP, gMapHeader.regionMapSectionId);
}
2017-10-25 02:37:38 +02:00
2018-05-09 12:07:56 +02:00
void sub_80E8EE0(struct MapEvents const *events)
2017-10-25 02:37:38 +02:00
{
2017-11-02 04:49:01 +01:00
u16 bgEventIndex;
u16 i;
u16 j;
2017-10-25 02:37:38 +02:00
s16 tile_id;
s16 x;
s16 y;
2017-11-02 04:49:01 +01:00
for (bgEventIndex = 0; bgEventIndex < events->bgEventCount; bgEventIndex ++)
2017-10-25 02:37:38 +02:00
{
2018-07-11 18:12:26 +02:00
if (events->bgEvents[bgEventIndex].kind == BG_EVENT_SECRET_BASE)
2017-10-25 02:37:38 +02:00
{
2019-01-02 00:19:07 +01:00
for (j = 0; j < SECRET_BASES_COUNT; j ++)
2017-10-25 02:37:38 +02:00
{
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[j].secretBaseId == events->bgEvents[bgEventIndex].bgUnion.secretBaseId)
2017-10-25 02:37:38 +02:00
{
2017-11-02 04:49:01 +01:00
x = events->bgEvents[bgEventIndex].x + 7;
y = events->bgEvents[bgEventIndex].y + 7;
2017-10-25 02:37:38 +02:00
tile_id = MapGridGetMetatileIdAt(x, y);
2017-11-02 04:49:01 +01:00
for (i = 0; i < 7; i ++)
2017-10-25 02:37:38 +02:00
{
2017-11-02 04:49:01 +01:00
if (gUnknown_0858CFCC[i].tile1 == tile_id)
2017-10-25 02:37:38 +02:00
{
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | MAP_IMPASSABLE_MASK);
2017-10-25 02:37:38 +02:00
break;
}
}
break;
}
}
}
}
}
2017-10-25 03:10:58 +02:00
void sub_80E8F9C(void)
{
s8 idx;
idx = sCurSecretBaseId / 10 * 4;
2018-12-27 23:30:47 +01:00
SetWarpDestinationToMapWarp(MAP_GROUP(SECRET_BASE_RED_CAVE1), gUnknown_0858CFE8[idx], gUnknown_0858CFE8[idx + 1]);
2017-10-25 03:10:58 +02:00
}
2017-10-25 03:27:46 +02:00
void sub_80E8FD0(u8 taskId)
{
2017-11-02 04:49:01 +01:00
u16 secretBaseRecordId;
2017-10-25 03:27:46 +02:00
switch (gTasks[taskId].data[0])
{
case 0:
if (!gPaletteFade.active)
{
gTasks[taskId].data[0] = 1;
}
break;
case 1:
2018-12-10 01:22:59 +01:00
secretBaseRecordId = VarGet(VAR_CURRENT_SECRET_BASE);
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_10 < 255)
2017-10-25 03:27:46 +02:00
{
2017-11-02 04:49:01 +01:00
gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_10 ++;
2017-10-25 03:27:46 +02:00
}
sub_80E8F9C();
WarpIntoMap();
2017-10-25 03:27:46 +02:00
gFieldCallback = sub_80AF168;
2018-02-14 00:58:22 +01:00
SetMainCallback2(CB2_LoadMap);
2017-10-25 03:27:46 +02:00
DestroyTask(taskId);
break;
}
}
void sub_80E9068(void)
{
CreateTask(sub_80E8FD0, 0);
2018-01-29 16:25:09 +01:00
FadeScreen(1, 0);
2018-12-27 23:30:47 +01:00
SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
2017-10-25 03:27:46 +02:00
}
bool8 sub_80E909C(void)
{
if (gMapHeader.mapType == MAP_TYPE_SECRET_BASE && VarGet(VAR_0x4097) == 0)
{
return FALSE;
}
return TRUE;
}
2017-10-25 03:41:22 +02:00
void sub_80E90C8(u8 taskId)
{
EventObjectTurn(&gEventObjects[gPlayerAvatar.eventObjectId], DIR_NORTH);
if (IsWeatherNotFadingIn() == TRUE)
2017-10-25 03:41:22 +02:00
{
EnableBothScriptContexts();
DestroyTask(taskId);
}
}
void sub_80E9108(void)
{
s16 x;
s16 y;
ScriptContext2_Enable();
HideMapNamePopUpWindow();
sub_80E8CB0(&x, &y, 0x220);
x += 7;
y += 7;
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x, y, 0x220 | MAP_IMPASSABLE_MASK);
2017-10-25 03:41:22 +02:00
CurrentMapDrawMetatileAt(x, y);
pal_fill_black();
CreateTask(sub_80E90C8, 0);
}
2017-10-25 04:00:29 +02:00
void sub_80E916C(u8 taskId)
{
s8 idx;
if (!gPaletteFade.active)
{
idx = sCurSecretBaseId / 10 * 4;
2018-12-27 23:30:47 +01:00
SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gUnknown_0858CFE8[idx + 2], gUnknown_0858CFE8[idx + 3]);
WarpIntoMap();
2017-10-25 04:00:29 +02:00
gFieldCallback = sub_80E9108;
2018-02-14 00:58:22 +01:00
SetMainCallback2(CB2_LoadMap);
2017-10-25 04:00:29 +02:00
DestroyTask(taskId);
}
}
2017-10-25 04:10:35 +02:00
void sub_80E91F8(void)
{
CreateTask(sub_80E916C, 0);
2018-01-29 16:25:09 +01:00
FadeScreen(1, 0);
2017-10-25 04:10:35 +02:00
}
bool8 CurrentMapIsSecretBase(void)
{
2017-12-05 18:55:48 +01:00
if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SECRET_BASE_RED_CAVE1) && (u8)gSaveBlock1Ptr->location.mapNum <= MAP_NUM(SECRET_BASE_SHRUB4))
2017-10-25 04:10:35 +02:00
{
return TRUE;
}
return FALSE;
}
2017-10-25 04:17:26 +02:00
void sub_80E9238(u8 flagIn)
{
u16 curBaseId;
u16 x;
u16 y;
u8 *decorations;
u8 *decorPos;
if (CurrentMapIsSecretBase())
{
2018-12-10 01:22:59 +01:00
curBaseId = VarGet(VAR_CURRENT_SECRET_BASE);
2017-10-25 04:17:26 +02:00
decorations = gSaveBlock1Ptr->secretBases[curBaseId].decorations;
decorPos = gSaveBlock1Ptr->secretBases[curBaseId].decorationPos;
for (x = 0; x < 16; x ++)
{
if (decorations[x] > 0 && decorations[x] <= 0x78 && gDecorations[decorations[x]].permission != DECORPERM_SOLID_MAT) {
sub_8127D38((decorPos[x] >> 4) + 7, (decorPos[x] & 0xF) + 7, decorations[x]);
}
}
if (curBaseId != 0)
{
sub_80E8CB0(&x, &y, 0x220);
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x + 7, y + 7, 0x221 | MAP_IMPASSABLE_MASK);
2017-10-25 04:17:26 +02:00
}
else if (flagIn == 1 && VarGet(VAR_0x4089) == 1)
{
sub_80E8CB0(&x, &y, 0x220);
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(x + 7, y + 7, 0x20a | MAP_IMPASSABLE_MASK);
2017-10-25 04:17:26 +02:00
}
}
}
2017-10-25 04:34:52 +02:00
void sub_80E933C(void)
{
2017-11-02 04:54:11 +01:00
u8 *roomDecor;
u8 *roomDecorPos;
u8 decorIdx;
u8 objIdx;
2017-10-25 04:34:52 +02:00
u8 metatile;
u8 category;
u8 permission;
2017-11-02 04:49:01 +01:00
u8 nDecor;
2017-10-25 04:34:52 +02:00
u16 curBase;
2017-11-02 04:54:11 +01:00
objIdx = 0;
2017-10-25 04:34:52 +02:00
if (!CurrentMapIsSecretBase())
{
2017-11-02 04:54:11 +01:00
roomDecor = gSaveBlock1Ptr->playerRoomDecor;
roomDecorPos = gSaveBlock1Ptr->playerRoomDecorPos;
2017-11-02 04:49:01 +01:00
nDecor = 12;
2017-10-25 04:34:52 +02:00
}
else
{
2018-12-10 01:22:59 +01:00
curBase = VarGet(VAR_CURRENT_SECRET_BASE);
2017-11-02 04:54:11 +01:00
roomDecor = gSaveBlock1Ptr->secretBases[curBase].decorations;
roomDecorPos = gSaveBlock1Ptr->secretBases[curBase].decorationPos;
2017-11-02 04:49:01 +01:00
nDecor = 16;
2017-10-25 04:34:52 +02:00
}
2017-11-02 04:54:11 +01:00
for (decorIdx = 0; decorIdx < nDecor; decorIdx ++)
2017-10-25 04:34:52 +02:00
{
2017-11-02 04:54:11 +01:00
if (roomDecor[decorIdx] != DECOR_NONE)
2017-10-25 04:34:52 +02:00
{
2017-11-02 04:54:11 +01:00
permission = gDecorations[roomDecor[decorIdx]].permission;
category = gDecorations[roomDecor[decorIdx]].category;
2017-10-25 04:34:52 +02:00
if (permission == DECORPERM_SOLID_MAT)
{
for (objIdx = 0; objIdx < gMapHeader.events->eventObjectCount; objIdx ++)
2017-10-25 04:34:52 +02:00
{
if (gMapHeader.events->eventObjects[objIdx].flagId == gSpecialVar_0x8004 + 0xAE)
2017-10-25 04:34:52 +02:00
{
break;
}
}
if (objIdx == gMapHeader.events->eventObjectCount)
2017-10-25 04:34:52 +02:00
{
continue;
}
2017-11-02 04:54:11 +01:00
gSpecialVar_0x8006 = roomDecorPos[decorIdx] >> 4;
gSpecialVar_0x8007 = roomDecorPos[decorIdx] & 0xF;
2017-10-25 04:34:52 +02:00
metatile = MapGridGetMetatileBehaviorAt(gSpecialVar_0x8006 + 7, gSpecialVar_0x8007 + 7);
if (MetatileBehavior_IsSecretBaseLargeMatEdge(metatile) == TRUE || MetatileBehavior_IsLargeMatCenter(metatile) == TRUE)
2017-10-25 04:34:52 +02:00
{
gSpecialVar_Result = gMapHeader.events->eventObjects[objIdx].graphicsId + VAR_0x3F20;
2017-11-11 01:12:18 +01:00
VarSet(gSpecialVar_Result, gDecorations[roomDecor[decorIdx]].tiles[0]);
gSpecialVar_Result = gMapHeader.events->eventObjects[objIdx].localId;
2017-10-25 04:34:52 +02:00
FlagClear(gSpecialVar_0x8004 + 0xAE);
2017-11-11 01:12:18 +01:00
show_sprite(gSpecialVar_Result, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
sub_808EBA8(gSpecialVar_Result, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, gSpecialVar_0x8006, gSpecialVar_0x8007);
sub_808F254(gSpecialVar_Result, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
2018-12-10 01:22:59 +01:00
if (CurrentMapIsSecretBase() == TRUE && VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-25 04:34:52 +02:00
{
if (category == DECORCAT_DOLL)
{
2017-11-11 01:12:18 +01:00
sub_808F28C(gSpecialVar_Result, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, DECORCAT_DOLL);
2017-10-25 04:34:52 +02:00
}
else if (category == DECORCAT_CUSHION)
{
2017-11-11 01:12:18 +01:00
sub_808F28C(gSpecialVar_Result, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, DECORCAT_CUSHION);
2017-10-25 04:34:52 +02:00
}
}
gSpecialVar_0x8004 ++;
}
}
}
}
}
2017-10-25 04:47:12 +02:00
void sub_80E9578(void)
{
2017-11-02 04:49:01 +01:00
u8 objectEventIdx;
2017-10-25 04:47:12 +02:00
u16 flagId;
for (objectEventIdx = 0; objectEventIdx < gMapHeader.events->eventObjectCount; objectEventIdx ++)
2017-10-25 04:47:12 +02:00
{
flagId = gMapHeader.events->eventObjects[objectEventIdx].flagId;
2019-01-02 00:19:07 +01:00
if (flagId >= FLAG_DECORATION_1 && flagId <= FLAG_DECORATION_14)
2017-10-25 04:47:12 +02:00
{
RemoveEventObjectByLocalIdAndMap(gMapHeader.events->eventObjects[objectEventIdx].localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
2017-10-25 04:47:12 +02:00
FlagSet(flagId);
}
}
}
2017-10-25 14:22:36 +02:00
void sub_80E95D4(void)
{
2018-12-10 01:22:59 +01:00
VarSet(VAR_OBJ_GFX_ID_F, gUnknown_0858D060[sub_80EA20C(VarGet(VAR_CURRENT_SECRET_BASE))]);
2017-10-25 14:22:36 +02:00
}
2018-10-17 04:47:08 +02:00
void sub_80E9608(const struct MapPosition *position, const struct MapEvents *events)
2017-10-25 14:22:36 +02:00
{
2017-11-02 04:49:01 +01:00
s16 bgEventIdx;
2017-10-25 14:22:36 +02:00
2017-11-02 04:49:01 +01:00
for (bgEventIdx = 0; bgEventIdx < events->bgEventCount; bgEventIdx ++)
2017-10-25 14:22:36 +02:00
{
2018-10-17 04:47:08 +02:00
if (events->bgEvents[bgEventIdx].kind == BG_EVENT_SECRET_BASE && position->x == events->bgEvents[bgEventIdx].x + 7 && position->y == events->bgEvents[bgEventIdx].y + 7)
2017-10-25 14:22:36 +02:00
{
2017-11-02 04:49:01 +01:00
sCurSecretBaseId = events->bgEvents[bgEventIdx].bgUnion.secretBaseId;
2017-10-25 14:22:36 +02:00
break;
}
}
}
2018-12-28 22:11:15 +01:00
void WarpIntoSecretBase(const struct MapPosition *position, const struct MapEvents *events)
2017-10-25 14:22:36 +02:00
{
2018-10-17 04:47:08 +02:00
sub_80E9608(position, events);
2017-10-25 14:22:36 +02:00
sub_80E8B6C();
2017-11-11 01:12:18 +01:00
ScriptContext1_SetupScript(EventScript_275BB7);
2017-10-25 14:22:36 +02:00
}
2017-10-25 14:34:41 +02:00
bool8 sub_80E9680(void)
{
sub_80E8B58();
sub_80E8B6C();
2017-11-11 01:12:18 +01:00
if (gSpecialVar_Result == TRUE)
2017-10-25 14:34:41 +02:00
{
return FALSE;
}
return TRUE;
}
void sub_80E96A4(u8 taskId)
{
switch (gTasks[taskId].data[0])
{
case 0:
ScriptContext2_Enable();
gTasks[taskId].data[0] = 1;
break;
case 1:
if (!gPaletteFade.active)
{
gTasks[taskId].data[0] = 2;
}
break;
case 2:
2018-12-27 23:30:47 +01:00
SetWarpDestinationToDynamicWarp(0x7e);
WarpIntoMap();
2017-10-25 14:34:41 +02:00
gFieldCallback = mapldr_default;
2018-02-14 00:58:22 +01:00
SetMainCallback2(CB2_LoadMap);
2017-10-25 14:34:41 +02:00
ScriptContext2_Disable();
DestroyTask(taskId);
break;
}
}
void sub_80E9728(void)
{
CreateTask(sub_80E96A4, 0);
2018-01-29 16:25:09 +01:00
FadeScreen(1, 0);
2017-10-25 14:34:41 +02:00
}
void sub_80E9744(void)
{
if (gSaveBlock1Ptr->secretBases[0].secretBaseId != sCurSecretBaseId)
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = TRUE;
2017-10-25 14:34:41 +02:00
}
else
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = FALSE;
2017-10-25 14:34:41 +02:00
}
}
2017-10-25 14:41:25 +02:00
2017-11-02 04:49:01 +01:00
u8 *sub_80E9780(u8 *dest, u8 secretBaseRecordId)
2017-10-25 14:41:25 +02:00
{
2017-11-02 04:49:01 +01:00
*StringCopyN(dest, gSaveBlock1Ptr->secretBases[secretBaseRecordId].trainerName, sub_80E8DF4(gSaveBlock1Ptr->secretBases[secretBaseRecordId].trainerName)) = EOS;
ConvertInternationalString(dest, gSaveBlock1Ptr->secretBases[secretBaseRecordId].language);
2017-10-25 14:41:25 +02:00
return StringAppend(dest, gText_ApostropheSBase);
}
2017-10-25 14:46:08 +02:00
u8 *GetSecretBaseMapName(u8 *dest)
{
2018-12-10 01:22:59 +01:00
return sub_80E9780(dest, VarGet(VAR_CURRENT_SECRET_BASE));
2017-10-25 14:46:08 +02:00
}
void sub_80E980C(void)
{
2017-11-02 04:49:01 +01:00
u8 secretBaseRecordId;
2017-10-25 14:46:08 +02:00
const u8 *src;
2018-12-10 01:22:59 +01:00
secretBaseRecordId = VarGet(VAR_CURRENT_SECRET_BASE);
2017-11-02 04:49:01 +01:00
src = gSaveBlock1Ptr->secretBases[secretBaseRecordId].trainerName;
2017-10-25 14:46:08 +02:00
*StringCopyN(gStringVar1, src, sub_80E8DF4(src)) = EOS;
2017-11-02 04:49:01 +01:00
ConvertInternationalString(gStringVar1, gSaveBlock1Ptr->secretBases[secretBaseRecordId].language);
2017-10-25 14:46:08 +02:00
}
2017-10-26 00:40:44 +02:00
2017-11-02 04:49:01 +01:00
bool8 sub_80E9878(u8 secretBaseRecordId)
2017-10-26 00:40:44 +02:00
{
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_1_6 != 0)
2017-10-26 00:40:44 +02:00
{
return TRUE;
}
return FALSE;
}
u8 sub_80E98AC(struct Pokemon *pokemon)
{
u16 evTotal;
evTotal = GetMonData(pokemon, MON_DATA_HP_EV);
evTotal += GetMonData(pokemon, MON_DATA_ATK_EV);
evTotal += GetMonData(pokemon, MON_DATA_DEF_EV);
2017-11-02 04:37:57 +01:00
evTotal += GetMonData(pokemon, MON_DATA_SPEED_EV);
2017-10-26 00:40:44 +02:00
evTotal += GetMonData(pokemon, MON_DATA_SPATK_EV);
evTotal += GetMonData(pokemon, MON_DATA_SPDEF_EV);
return evTotal / 6;
}
2017-10-26 01:54:24 +02:00
void sub_80E9914(void)
{
2017-11-02 04:59:48 +01:00
u16 partyIdx;
u16 moveIdx;
u16 sbPartyIdx;
2018-02-07 13:49:33 +01:00
struct SecretBaseParty *party;
2017-10-26 01:54:24 +02:00
2017-11-02 04:59:48 +01:00
sbPartyIdx = 0;
2018-02-07 13:49:33 +01:00
party = &gSaveBlock1Ptr->secretBases[0].party;
2017-10-26 01:54:24 +02:00
if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0)
{
2018-02-07 13:49:33 +01:00
for (partyIdx = 0; partyIdx < PARTY_SIZE; partyIdx++)
2017-10-26 01:54:24 +02:00
{
2018-02-07 13:49:33 +01:00
for (moveIdx = 0; moveIdx < 4; moveIdx++)
2017-10-26 01:54:24 +02:00
{
2018-02-07 13:49:33 +01:00
party->moves[partyIdx * 4 + moveIdx] = 0;
2017-10-26 01:54:24 +02:00
}
2018-02-07 13:49:33 +01:00
party->species[partyIdx] = 0;
party->heldItems[partyIdx] = 0;
party->levels[partyIdx] = 0;
party->personality[partyIdx] = 0;
party->EVs[partyIdx] = 0;
if (GetMonData(&gPlayerParty[partyIdx], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&gPlayerParty[partyIdx], MON_DATA_IS_EGG))
2017-10-26 01:54:24 +02:00
{
2018-02-07 13:49:33 +01:00
for (moveIdx = 0; moveIdx < 4; moveIdx++)
2017-10-26 01:54:24 +02:00
{
2018-02-07 13:49:33 +01:00
party->moves[sbPartyIdx * 4 + moveIdx] = GetMonData(&gPlayerParty[partyIdx], MON_DATA_MOVE1 + moveIdx);
2017-10-26 01:54:24 +02:00
}
2018-02-07 13:49:33 +01:00
party->species[sbPartyIdx] = GetMonData(&gPlayerParty[partyIdx], MON_DATA_SPECIES);
party->heldItems[sbPartyIdx] = GetMonData(&gPlayerParty[partyIdx], MON_DATA_HELD_ITEM);
party->levels[sbPartyIdx] = GetMonData(&gPlayerParty[partyIdx], MON_DATA_LEVEL);
party->personality[sbPartyIdx] = GetMonData(&gPlayerParty[partyIdx], MON_DATA_PERSONALITY);
party->EVs[sbPartyIdx] = sub_80E98AC(&gPlayerParty[partyIdx]);
sbPartyIdx++;
2017-10-26 01:54:24 +02:00
}
}
}
}
2017-10-26 02:03:55 +02:00
void sub_80E9A90(void)
{
u16 sbr_e;
sbr_e = gSaveBlock1Ptr->secretBases[0].sbr_field_e;
ClearSecretBase(&gSaveBlock1Ptr->secretBases[0]);
2017-10-26 02:03:55 +02:00
gSaveBlock1Ptr->secretBases[0].sbr_field_e = sbr_e;
sub_80E9728();
}
2017-10-26 14:40:08 +02:00
void sub_80E9AC0(void)
{
IncrementGameStat(GAME_STAT_MOVED_SECRET_BASE);
sub_80E9A90();
}
void sub_80E9AD0(void)
{
u16 i;
u16 j;
s16 tile;
2018-02-14 01:12:17 +01:00
const struct MapEvents *events;
2017-10-26 14:40:08 +02:00
events = gMapHeader.events;
for (i = 0; i < events->bgEventCount; i ++)
{
2018-07-11 18:12:26 +02:00
if (events->bgEvents[i].kind == BG_EVENT_SECRET_BASE && gSaveBlock1Ptr->secretBases[0].secretBaseId == events->bgEvents[i].bgUnion.secretBaseId)
2017-10-26 14:40:08 +02:00
{
tile = MapGridGetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7);
for (j = 0; j < 7; j ++)
{
if (gUnknown_0858CFCC[j].tile2 == tile)
{
2019-02-22 09:08:48 +01:00
MapGridSetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7, gUnknown_0858CFCC[j].tile1 | MAP_IMPASSABLE_MASK);
2017-10-26 14:40:08 +02:00
break;
}
}
DrawWholeMapView();
break;
}
}
}
2017-10-26 14:45:41 +02:00
void sub_80E9B70(void)
{
u16 sbr_e;
sub_80E9AD0();
IncrementGameStat(GAME_STAT_MOVED_SECRET_BASE);
sbr_e = gSaveBlock1Ptr->secretBases[0].sbr_field_e;
ClearSecretBase(&gSaveBlock1Ptr->secretBases[0]);
2017-10-26 14:45:41 +02:00
gSaveBlock1Ptr->secretBases[0].sbr_field_e = sbr_e;
}
u8 sub_80E9BA8(void)
{
2017-11-02 04:49:01 +01:00
u8 sum;
2017-10-26 14:45:41 +02:00
s16 i;
2017-11-02 04:49:01 +01:00
sum = 0;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-26 14:45:41 +02:00
{
if (sub_80E9878(i) == TRUE)
{
2017-11-02 04:49:01 +01:00
sum ++;
2017-10-26 14:45:41 +02:00
}
}
2017-11-02 04:49:01 +01:00
return sum;
2017-10-26 14:45:41 +02:00
}
2017-10-27 03:39:34 +02:00
void sub_80E9BDC(void)
{
2018-12-10 01:22:59 +01:00
if (sub_80E9878(VarGet(VAR_CURRENT_SECRET_BASE)) == TRUE)
2017-10-27 03:39:34 +02:00
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = 1;
2017-10-27 03:39:34 +02:00
}
else if (sub_80E9BA8() > 9)
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = 2;
2017-10-27 03:39:34 +02:00
}
else
{
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = 0;
2017-10-27 03:39:34 +02:00
}
}
void sub_80E9C2C(void)
{
2018-12-10 01:22:59 +01:00
gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].sbr_field_1_6 ^= 1;
2019-01-05 21:12:50 +01:00
FlagSet(FLAG_DECORATION_16);
2017-10-27 03:39:34 +02:00
}
void sub_80E9C74(void)
{
CreateTask(sub_8126AD8, 0);
}
void sub_80E9C88(void)
{
CreateTask(sub_80E9C9C, 0);
}
void sub_80E9C9C(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
ScriptContext2_Enable();
data[0] = sub_80E9BA8();
if (data[0] != 0)
{
data[1] = 0;
data[2] = 0;
sub_8197434(0, 0);
gUnknown_0203A020 = calloc(1, sizeof(struct SecretBaseListMenuBuffer));
2017-10-27 04:10:38 +02:00
data[6] = AddWindow(&gUnknown_0858D06C[0]);
2017-10-27 03:39:34 +02:00
game_continue(taskId);
sub_80E9E00(taskId);
gTasks[taskId].func = sub_80E9E90;
}
else
{
DisplayItemMessageOnField(taskId, gText_NoRegistry, task_pc_turn_off);
}
}
void game_continue(u8 taskId)
{
s16 *data;
u8 i;
2017-11-02 04:49:01 +01:00
u8 count;
2017-10-27 03:39:34 +02:00
data = gTasks[taskId].data;
2017-11-02 04:49:01 +01:00
count = 0;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-27 03:39:34 +02:00
{
if (sub_80E9878(i))
{
2017-11-02 04:49:01 +01:00
sub_80E9780(gUnknown_0203A020->names[count], i);
2017-12-16 00:08:23 +01:00
gUnknown_0203A020->items[count].name = gUnknown_0203A020->names[count];
gUnknown_0203A020->items[count].id = i;
2017-11-02 04:49:01 +01:00
count ++;
2017-10-27 03:39:34 +02:00
}
}
2017-12-16 00:08:23 +01:00
gUnknown_0203A020->items[count].name = gText_Cancel;
gUnknown_0203A020->items[count].id = -2;
2017-11-02 04:49:01 +01:00
data[0] = count + 1;
2017-10-27 03:39:34 +02:00
if (data[0] < 8)
{
data[3] = data[0];
}
else
{
data[3] = 8;
}
2017-12-16 00:08:23 +01:00
gMultiuseListMenuTemplate = gUnknown_0858D07C;
2018-03-02 16:34:31 +01:00
gMultiuseListMenuTemplate.windowId = data[6];
2017-12-16 00:08:23 +01:00
gMultiuseListMenuTemplate.totalItems = data[0];
gMultiuseListMenuTemplate.items = gUnknown_0203A020->items;
gMultiuseListMenuTemplate.maxShowed = data[3];
2017-10-27 03:39:34 +02:00
}
2017-10-27 03:53:00 +02:00
2018-03-03 14:58:41 +01:00
void sub_80E9DEC(s32 a0, bool8 flag, struct ListMenu *menu)
2017-10-27 03:53:00 +02:00
{
if (flag != TRUE)
{
PlaySE(SE_SELECT);
}
}
void sub_80E9E00(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
SetStandardWindowBorderStyle(data[6], 0);
2017-12-16 00:08:23 +01:00
data[5] = ListMenuInit(&gMultiuseListMenuTemplate, data[2], data[1]);
2017-10-27 03:53:00 +02:00
sub_80E9E44(taskId);
schedule_bg_copy_tilemap_to_vram(0);
}
void sub_80E9E44(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
2018-07-15 13:23:38 +02:00
data[8] = AddScrollIndicatorArrowPairParameterized(SCROLL_ARROW_UP, 0xbc, 0x0c, 0x94, data[0] - data[3], 0x13f8, 0x13f8, &data[2]);
2017-10-27 03:53:00 +02:00
}
2017-10-27 03:59:54 +02:00
void sub_80E9E90(u8 taskId)
{
s16 *data;
s32 input;
data = gTasks[taskId].data;
2019-02-02 11:04:38 +01:00
input = ListMenu_ProcessInput(data[5]);
2018-03-02 16:34:31 +01:00
ListMenuGetScrollAndRow(data[5], &data[2], &data[1]);
2017-10-27 03:59:54 +02:00
switch (input)
{
2019-02-02 11:04:38 +01:00
case LIST_NOTHING_CHOSEN:
2017-10-27 03:59:54 +02:00
break;
2019-02-02 11:04:38 +01:00
case LIST_B_PRESSED:
2017-10-27 03:59:54 +02:00
PlaySE(SE_SELECT);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[5], NULL, NULL);
2017-10-27 03:59:54 +02:00
RemoveScrollIndicatorArrowPair(data[8]);
sub_819746C(data[6], 0);
ClearWindowTilemap(data[6]);
RemoveWindow(data[6]);
schedule_bg_copy_tilemap_to_vram(0);
free(gUnknown_0203A020);
task_pc_turn_off(taskId);
break;
default:
PlaySE(SE_SELECT);
data[4] = input;
sub_80E9F20(taskId);
break;
}
}
2017-10-27 04:10:38 +02:00
void sub_80E9F20(u8 taskId)
{
struct WindowTemplate template;
s16 *data;
data = gTasks[taskId].data;
RemoveScrollIndicatorArrowPair(data[8]);
template = gUnknown_0858D06C[1];
template.width = GetMaxWidthInMenuTable(gUnknown_0858D048, 2);
data[7] = AddWindow(&template);
SetStandardWindowBorderStyle(data[7], 0);
PrintMenuTable(data[7], 2, gUnknown_0858D048);
InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[7], 2, 0);
schedule_bg_copy_tilemap_to_vram(0);
gTasks[taskId].func = sub_80E9FB0;
}
void sub_80E9FB0(u8 taskId)
{
s8 input;
2018-11-05 21:45:54 +01:00
input = Menu_ProcessInputNoWrap();
2017-10-27 04:10:38 +02:00
switch (input)
{
2019-02-02 11:04:38 +01:00
case MENU_B_PRESSED:
2017-10-27 04:10:38 +02:00
PlaySE(SE_SELECT);
sub_80EA18C(taskId);
break;
2019-02-02 11:04:38 +01:00
case MENU_NOTHING_CHOSEN:
2017-10-27 04:10:38 +02:00
break;
default:
PlaySE(SE_SELECT);
gUnknown_0858D048[input].func.void_u8(taskId);
break;
}
}
2017-10-27 04:21:20 +02:00
void sub_80E9FFC(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
sub_819746C(data[6], FALSE);
sub_819746C(data[7], FALSE);
ClearWindowTilemap(data[6]);
ClearWindowTilemap(data[7]);
RemoveWindow(data[7]);
schedule_bg_copy_tilemap_to_vram(0);
sub_80E9780(gStringVar1, data[4]);
StringExpandPlaceholders(gStringVar4, gText_OkayToDeleteFromRegistry);
DisplayItemMessageOnField(taskId, gStringVar4, sub_80EA06C);
}
void sub_80EA06C(u8 taskId)
{
2018-11-05 21:45:54 +01:00
DisplayYesNoMenu();
2018-12-31 23:09:45 +01:00
DoYesNoFuncWithChoice(taskId, &gUnknown_0858D058);
2017-10-27 04:21:20 +02:00
}
void sub_80EA08C(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
sub_8197434(0, 0);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[5], &data[2], &data[1]);
2017-10-27 04:21:20 +02:00
gSaveBlock1Ptr->secretBases[data[4]].sbr_field_1_6 = 0;
game_continue(taskId);
sub_812225C(&data[2], &data[1], data[3], data[0]);
sub_80E9E00(taskId);
gTasks[taskId].func = sub_80E9E90;
}
2017-10-27 04:37:16 +02:00
void sub_80EA120(u8 taskId)
{
DisplayItemMessageOnField(taskId, gText_RegisteredDataDeleted, sub_80EA08C);
}
void sub_80EA13C(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
sub_8197434(0, 0);
2018-03-02 16:34:31 +01:00
DestroyListMenuTask(data[5], &data[2], &data[1]);
2017-10-27 04:37:16 +02:00
sub_80E9E00(taskId);
gTasks[taskId].func = sub_80E9E90;
}
void sub_80EA18C(u8 taskId)
{
s16 *data;
data = gTasks[taskId].data;
sub_80E9E44(taskId);
sub_819746C(data[7], 0);
ClearWindowTilemap(data[7]);
RemoveWindow(data[7]);
schedule_bg_copy_tilemap_to_vram(0);
gTasks[taskId].func = sub_80E9E90;
}
void task_pc_turn_off(u8 taskId)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) == 0)
2017-10-27 04:37:16 +02:00
{
ScriptContext1_SetupScript(gUnknown_0823B4E8);
}
else
{
ScriptContext1_SetupScript(gUnknown_0823B5E9);
}
DestroyTask(taskId);
}
2017-11-02 04:49:01 +01:00
u8 sub_80EA20C(u8 secretBaseRecordId)
2017-10-27 04:37:16 +02:00
{
2017-11-02 04:49:01 +01:00
return (gSaveBlock1Ptr->secretBases[secretBaseRecordId].trainerId[0] % 5) + (gSaveBlock1Ptr->secretBases[secretBaseRecordId].gender * 5);
2017-10-27 04:37:16 +02:00
}
2017-10-27 04:49:51 +02:00
2017-12-01 21:25:13 +01:00
const u8 *GetSecretBaseTrainerLoseText(void)
2017-10-27 04:49:51 +02:00
{
u8 param;
2018-12-10 01:22:59 +01:00
param = sub_80EA20C(VarGet(VAR_CURRENT_SECRET_BASE));
2017-10-27 04:49:51 +02:00
if (param == 0)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_274966;
2017-10-27 04:49:51 +02:00
}
if (param == 1)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_274D13;
2017-10-27 04:49:51 +02:00
}
if (param == 2)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_274FFE;
2017-10-27 04:49:51 +02:00
}
if (param == 3)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_275367;
2017-10-27 04:49:51 +02:00
}
if (param == 4)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_2756C7;
2017-10-27 04:49:51 +02:00
}
if (param == 5)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_274B24;
2017-10-27 04:49:51 +02:00
}
if (param == 6)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_274E75;
2017-10-27 04:49:51 +02:00
}
if (param == 7)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_2751E1;
2017-10-27 04:49:51 +02:00
}
if (param == 8)
{
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_2754F6;
2017-10-27 04:49:51 +02:00
}
2017-11-11 01:12:18 +01:00
return SecretBase_RedCave1_Text_2758CC;
2017-10-27 04:49:51 +02:00
}
void sub_80EA2E4(void)
{
sub_813BADC(TRUE);
2018-10-21 20:13:12 +02:00
gTrainerBattleOpponent_A = TRAINER_SECRET_BASE;
2017-10-27 04:49:51 +02:00
gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_SECRET_BASE;
}
void sub_80EA30C(void)
{
2018-12-10 01:22:59 +01:00
gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].sbr_field_1_5 = gSpecialVar_Result;
2017-10-27 04:49:51 +02:00
}
2017-10-27 04:54:11 +02:00
void sub_80EA354(void)
{
2017-11-02 04:49:01 +01:00
u16 secretBaseRecordId;
2017-10-27 04:54:11 +02:00
u8 i;
2018-12-10 01:22:59 +01:00
secretBaseRecordId = VarGet(VAR_CURRENT_SECRET_BASE);
2019-01-05 21:12:50 +01:00
if (!FlagGet(FLAG_DAILY_SECRET_BASE))
2017-10-27 04:54:11 +02:00
{
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-27 04:54:11 +02:00
{
gSaveBlock1Ptr->secretBases[i].sbr_field_1_5 = FALSE;
}
2019-01-05 21:12:50 +01:00
FlagSet(FLAG_DAILY_SECRET_BASE);
2017-10-27 04:54:11 +02:00
}
2017-11-02 04:49:01 +01:00
gSpecialVar_0x8004 = sub_80EA20C(secretBaseRecordId);
2017-11-11 01:12:18 +01:00
gSpecialVar_Result = gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_1_5;
2017-10-27 04:54:11 +02:00
}
2017-10-27 05:35:41 +02:00
2018-12-31 19:22:27 +01:00
void SecretBasePerStepCallback(u8 taskId)
2017-10-27 05:35:41 +02:00
{
s16 x;
s16 y;
u8 behavior;
u16 tileId;
s16 *data;
data = gTasks[taskId].data;
switch (data[1])
{
case 0:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-27 05:35:41 +02:00
{
gUnknown_0203A01D = TRUE;
}
else
{
gUnknown_0203A01D = FALSE;
}
PlayerGetDestCoords(&data[2], &data[3]);
data[1] = 1;
break;
case 1:
PlayerGetDestCoords(&x, &y);
if (x != data[2] || y != data[3])
{
data[2] = x;
data[3] = y;
VarSet(VAR_0x40EC, VarGet(VAR_0x40EC) + 1);
behavior = MapGridGetMetatileBehaviorAt(x, y);
tileId = MapGridGetMetatileIdAt(x, y);
if (tileId == 0x234 || tileId == 0x23C)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x20);
}
}
else if (tileId == 0x2b8 || tileId == 0x2b9 || tileId == 0x2ba || tileId == 0x2c0 || tileId == 0x2c1 || tileId == 0x2c2 || tileId == 0x2c8 || tileId == 0x2c9 || tileId == 0x2ca)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x01);
}
}
else if (tileId == 0x239 || tileId == 0x241 || tileId == 0x251 || tileId == 0x259)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x04);
}
}
else if ((behavior == 0x34 && tileId == 0x26d) || (behavior == 0x35 && MapGridGetMetatileIdAt(x, y) == 0x26a))
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x200);
}
}
else if (behavior == 0xc1 && tileId == 0x23d)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) ^ 0x1000);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x2000);
}
}
else if (behavior == 0x47 && tileId == 0x23e)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x1000);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) ^ 0x2000);
}
}
else if (MetatileBehavior_IsSecretBaseGlitterMat(behavior) == TRUE)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x80);
}
}
else if (MetatileBehavior_IsSecretBaseBalloon(behavior) == TRUE)
{
PopSecretBaseBalloon(MapGridGetMetatileIdAt(x, y), x, y);
2017-10-27 05:35:41 +02:00
if (gUnknown_0203A01D == TRUE)
{
switch ((int)MapGridGetMetatileIdAt(x, y))
{
case 0x338:
case 0x33c:
case 0x340:
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x02);
break;
case 0x228:
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x100);
break;
}
}
}
else if (MetatileBehavior_IsSecretBaseBreakableDoor(behavior) == TRUE)
2017-10-27 05:35:41 +02:00
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x400);
}
ShatterSecretBaseBreakableDoor(x, y);
2017-10-27 05:35:41 +02:00
}
else if (MetatileBehavior_IsSecretBaseSoundMat(behavior) == TRUE){
if (gUnknown_0203A01D == TRUE) {
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x8000);
}
}
else if (MetatileBehavior_IsSecretBaseJumpMat(behavior) == TRUE)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x4000);
}
}
else if (MetatileBehavior_IsSecretBaseSpinMat(behavior) == TRUE)
{
if (gUnknown_0203A01D == TRUE)
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x02);
}
}
}
break;
case 2:
if (!FieldEffectActiveListContains(data[4]))
{
data[1] = 1;
}
break;
}
}
2017-10-27 14:29:58 +02:00
2017-11-02 04:49:01 +01:00
void sub_80EA828(u8 secretBaseRecordId, struct SecretBaseRecord *base, u32 version, u32 language)
2017-10-27 14:29:58 +02:00
{
2017-11-02 04:49:01 +01:00
int stringLength;
2017-10-27 14:29:58 +02:00
u8 *name;
2017-11-02 04:49:01 +01:00
gSaveBlock1Ptr->secretBases[secretBaseRecordId] = *base;
gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_1_6 = 2;
2017-10-27 14:29:58 +02:00
if (version == VERSION_SAPPHIRE || version == VERSION_RUBY)
{
2017-11-02 04:49:01 +01:00
gSaveBlock1Ptr->secretBases[secretBaseRecordId].language = LANGUAGE_ENGLISH;
2017-10-27 14:29:58 +02:00
}
if (version == VERSION_EMERALD && language == LANGUAGE_JAPANESE)
{
2017-11-02 04:49:01 +01:00
name = gSaveBlock1Ptr->secretBases[secretBaseRecordId].trainerName;
for (stringLength = 0; stringLength < 7; stringLength ++)
2017-10-27 14:29:58 +02:00
{
2017-11-02 04:49:01 +01:00
if (name[stringLength] == EOS)
2017-10-27 14:29:58 +02:00
{
break;
}
}
2017-11-02 04:49:01 +01:00
if (stringLength > 5)
2017-10-27 14:29:58 +02:00
{
2017-11-02 04:49:01 +01:00
gSaveBlock1Ptr->secretBases[secretBaseRecordId].language = LANGUAGE_ENGLISH;
2017-10-27 14:29:58 +02:00
}
}
}
2017-10-27 14:38:54 +02:00
bool8 sub_80EA8D4(struct SecretBaseRecord *sbr1, struct SecretBaseRecord *sbr2)
{
u8 i;
for (i = 0; i < 4; i ++)
{
if (sbr1->trainerId[i] != sbr2->trainerId[i])
{
return FALSE;
}
}
return TRUE;
}
bool8 sub_80EA904(struct SecretBaseRecord *sbr1, struct SecretBaseRecord *sbr2)
{
u8 i;
2018-09-01 22:03:21 +02:00
for (i = 0; i < PLAYER_NAME_LENGTH && (sbr1->trainerName[i] != EOS || sbr2->trainerName[i] != EOS); i++)
2017-10-27 14:38:54 +02:00
{
if (sbr1->trainerName[i] != sbr2->trainerName[i])
{
return FALSE;
}
}
return TRUE;
}
bool8 sub_80EA950(struct SecretBaseRecord *sbr1, struct SecretBaseRecord *sbr2)
{
if (sbr1->gender == sbr2->gender && sub_80EA8D4(sbr1, sbr2) && sub_80EA904(sbr1, sbr2))
{
return TRUE;
}
return FALSE;
}
2017-11-02 04:49:01 +01:00
s16 sub_80EA990(u8 secretBaseRecordId)
2017-10-27 14:38:54 +02:00
{
s16 i;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-27 14:38:54 +02:00
{
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[i].secretBaseId == secretBaseRecordId)
2017-10-27 14:38:54 +02:00
{
return i;
}
}
return -1;
}
2017-10-27 14:43:10 +02:00
u8 sub_80EA9D8(void)
{
s16 i;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-27 14:43:10 +02:00
{
if (gSaveBlock1Ptr->secretBases[i].secretBaseId == 0)
{
return i;
}
}
return 0;
}
u8 sub_80EAA18(void)
{
s16 i;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-27 14:43:10 +02:00
{
if (gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 == 0 && gSaveBlock1Ptr->secretBases[i].sbr_field_1_0 == 0)
{
return i;
}
}
return 0;
}
2017-10-28 02:32:05 +02:00
u8 sub_80EAA64(struct SecretBaseRecord *base, u32 version, u32 language)
{
2017-11-02 04:49:01 +01:00
s16 secretBaseRecordId;
2017-10-28 02:32:05 +02:00
if (base->secretBaseId == 0)
{
return 0;
}
2017-11-02 04:49:01 +01:00
secretBaseRecordId = sub_80EA990(base->secretBaseId);
if (secretBaseRecordId != 0)
2017-10-28 02:32:05 +02:00
{
2017-11-02 04:49:01 +01:00
if (secretBaseRecordId != -1)
2017-10-28 02:32:05 +02:00
{
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_1_0 == 1)
2017-10-28 02:32:05 +02:00
{
return 0;
}
2017-11-02 04:49:01 +01:00
if (gSaveBlock1Ptr->secretBases[secretBaseRecordId].sbr_field_1_6 != 2 || base->sbr_field_1_0 == 1)
2017-10-28 02:32:05 +02:00
{
2017-11-02 04:49:01 +01:00
sub_80EA828(secretBaseRecordId, base, version, language);
return secretBaseRecordId;
2017-10-28 02:32:05 +02:00
}
}
else
{
2017-11-02 04:49:01 +01:00
secretBaseRecordId = sub_80EA9D8();
if (secretBaseRecordId != 0)
2017-10-28 02:32:05 +02:00
{
2017-11-02 04:49:01 +01:00
sub_80EA828(secretBaseRecordId, base, version, language);
return secretBaseRecordId;
2017-10-28 02:32:05 +02:00
}
2017-11-02 04:49:01 +01:00
secretBaseRecordId = sub_80EAA18();
if (secretBaseRecordId != 0)
2017-10-28 02:32:05 +02:00
{
2017-11-02 04:49:01 +01:00
sub_80EA828(secretBaseRecordId, base, version, language);
return secretBaseRecordId;
2017-10-28 02:32:05 +02:00
}
}
}
return 0;
}
2017-10-28 02:39:02 +02:00
void sub_80EAAF4(void)
{
u8 i;
u8 j;
struct SecretBaseRecord base;
struct SecretBaseRecord *secretBases;
secretBases = gSaveBlock1Ptr->secretBases;
for (i = 1; i < 19; i ++)
{
2019-01-02 00:19:07 +01:00
for (j = i + 1; j < SECRET_BASES_COUNT; j ++)
2017-10-28 02:39:02 +02:00
{
if ((secretBases[i].sbr_field_1_6 == 0 && secretBases[j].sbr_field_1_6 == 1) || (secretBases[i].sbr_field_1_6 == 2 && secretBases[j].sbr_field_1_6 != 2))
{
base = secretBases[i];
secretBases[i] = secretBases[j];
secretBases[j] = base;
}
}
}
}
2017-10-28 02:47:07 +02:00
2017-10-28 03:17:17 +02:00
void sub_80EABA4(struct SecretBaseRecordMixer *mixer, u8 b)
2017-10-28 02:47:07 +02:00
{
u16 i;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-28 02:47:07 +02:00
{
2017-10-28 03:17:17 +02:00
if (mixer->records[i].sbr_field_1_6 == b)
2017-10-28 02:47:07 +02:00
{
2017-10-28 03:17:17 +02:00
sub_80EAA64(&mixer->records[i], mixer->version, mixer->language);
2017-10-28 02:47:07 +02:00
}
}
}
2017-10-28 02:50:32 +02:00
bool8 DoesSecretBaseBelongToPlayer(struct SecretBaseRecord *secretBase)
2017-10-28 02:50:32 +02:00
{
u8 i;
if (secretBase->secretBaseId == 0)
return FALSE;
if (secretBase->secretBaseId && secretBase->gender != gSaveBlock2Ptr->playerGender)
return FALSE;
// Check if the player's trainer Id matches the secret base's id.
for (i = 0; i < 4; i ++)
{
if (secretBase->trainerId[i] != gSaveBlock2Ptr->playerTrainerId[i])
return FALSE;
}
2018-09-01 22:03:21 +02:00
for (i = 0; i < PLAYER_NAME_LENGTH && (secretBase->trainerName[i] != EOS || gSaveBlock2Ptr->playerName[i] != EOS); i ++)
2017-10-28 02:50:32 +02:00
{
if (secretBase->trainerName[i] != gSaveBlock2Ptr->playerName[i])
return FALSE;
}
return TRUE;
}
void DeleteFirstOldBaseFromPlayerInRecordMixingFriendsRecords(struct SecretBaseRecord *basesA, struct SecretBaseRecord *basesB, struct SecretBaseRecord *basesC)
{
u8 i;
u8 sbFlags = 0x0;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
{
if (!(sbFlags & 0x1)) // 001
{
if (DoesSecretBaseBelongToPlayer(&basesA[i]) == TRUE)
{
ClearSecretBase(&basesA[i]);
sbFlags |= 1;
}
}
if (!(sbFlags & 0x2)) // 010
{
if (DoesSecretBaseBelongToPlayer(&basesB[i]) == TRUE)
{
ClearSecretBase(&basesB[i]);
sbFlags |= 2;
}
}
if (!(sbFlags & 0x4)) // 100
{
if (DoesSecretBaseBelongToPlayer(&basesC[i]) == TRUE)
{
ClearSecretBase(&basesC[i]);
sbFlags |= 4;
}
}
if (sbFlags == 0x7) // 111
{
break;
}
}
}
2017-10-28 03:00:59 +02:00
bool8 sub_80EAD14(struct SecretBaseRecord *base, struct SecretBaseRecord *secretBases, u8 c)
{
u8 i;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:00:59 +02:00
{
if (secretBases[i].secretBaseId != 0)
{
if (sub_80EA950(base, &secretBases[i]) == TRUE)
{
if (c == 0)
{
ClearSecretBase(&secretBases[i]);
return FALSE;
}
if (base->sbr_field_e > secretBases[i].sbr_field_e)
{
ClearSecretBase(&secretBases[i]);
return FALSE;
}
secretBases[i].sbr_field_1_0 = base->sbr_field_1_0;
ClearSecretBase(base);
return TRUE;
}
}
}
return FALSE;
}
2017-10-28 03:03:27 +02:00
void sub_80EAD94(struct SecretBaseRecord *basesA, struct SecretBaseRecord *basesB, struct SecretBaseRecord *basesC, struct SecretBaseRecord *basesD)
{
u8 i;
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:03:27 +02:00
{
if (basesA[i].secretBaseId)
{
if (basesA[i].sbr_field_1_6 == 1)
{
basesA[i].sbr_field_1_0 = 1;
}
if (!sub_80EAD14(&basesA[i], basesB, i))
{
if (!sub_80EAD14(&basesA[i], basesC, i))
{
sub_80EAD14(&basesA[i], basesD, i);
}
}
}
}
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:03:27 +02:00
{
if (basesB[i].secretBaseId)
{
basesB[i].sbr_field_1_5 = 0;
if (!sub_80EAD14(&basesB[i], basesC, i))
{
sub_80EAD14(&basesB[i], basesD, i);
}
}
}
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:03:27 +02:00
{
if (basesC[i].secretBaseId)
{
basesC[i].sbr_field_1_5 = 0;
sub_80EAD14(&basesC[i], basesD, i);
}
if (basesD[i].secretBaseId)
{
basesD[i].sbr_field_1_5 = 0;
}
}
}
2017-10-28 03:17:17 +02:00
void sub_80EAE90(struct SecretBaseRecord *base, u32 version, u32 language)
{
if (base->sbr_field_1_0 == 1)
{
sub_80EAA64(base, version, language);
ClearSecretBase(base);
}
}
2017-10-28 03:55:07 +02:00
void sub_80EAEB4(struct SecretBaseRecordMixer *mixers)
2017-10-28 03:17:17 +02:00
{
u16 i;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:17:17 +02:00
{
2017-10-28 03:55:07 +02:00
sub_80EAE90(&mixers[0].records[i], mixers[0].version, mixers[0].language);
sub_80EAE90(&mixers[1].records[i], mixers[1].version, mixers[1].language);
sub_80EAE90(&mixers[2].records[i], mixers[2].version, mixers[2].language);
2017-10-28 03:17:17 +02:00
}
}
2017-10-28 03:55:07 +02:00
void sub_80EAEF4(struct SecretBaseRecordMixer *mixers)
2017-10-28 03:17:17 +02:00
{
2017-10-28 03:55:07 +02:00
DeleteFirstOldBaseFromPlayerInRecordMixingFriendsRecords(mixers[0].records, mixers[1].records, mixers[2].records);
sub_80EAD94(gSaveBlock1Ptr->secretBases, mixers[0].records, mixers[1].records, mixers[2].records);
sub_80EAEB4(mixers);
sub_80EAA64(mixers[0].records, mixers[0].version, mixers[0].language);
sub_80EAA64(mixers[1].records, mixers[1].version, mixers[1].language);
sub_80EAA64(mixers[2].records, mixers[2].version, mixers[2].language);
sub_80EABA4(&mixers[0], 1);
sub_80EABA4(&mixers[1], 1);
sub_80EABA4(&mixers[2], 1);
sub_80EABA4(&mixers[0], 0);
sub_80EABA4(&mixers[1], 0);
sub_80EABA4(&mixers[2], 0);
}
2018-05-26 00:25:36 +02:00
void ReceiveSecretBasesData(void *records, size_t recordSize, u8 linkIdx)
2017-10-28 03:55:07 +02:00
{
struct SecretBaseRecordMixer mixers[3];
u16 i;
2017-11-15 22:12:18 +01:00
2019-01-05 21:12:50 +01:00
if (FlagGet(FLAG_RECEIVED_SECRET_POWER))
2017-10-28 03:55:07 +02:00
{
switch (GetLinkPlayerCount())
{
case 2:
memset(records + 2 * recordSize, 0, recordSize);
memset(records + 3 * recordSize, 0, recordSize);
break;
case 3:
memset(records + 3 * recordSize, 0, recordSize);
break;
}
switch (linkIdx)
{
case 0:
mixers[0].records = records + 1 * recordSize;
mixers[0].version = gLinkPlayers[1].version & 0xFF;
mixers[0].language = gLinkPlayers[1].language;
mixers[1].records = records + 2 * recordSize;
mixers[1].version = gLinkPlayers[2].version & 0xFF;
mixers[1].language = gLinkPlayers[2].language;
mixers[2].records = records + 3 * recordSize;
mixers[2].version = gLinkPlayers[3].version & 0xFF;
mixers[2].language = gLinkPlayers[3].language;
break;
case 1:
mixers[0].records = records + 2 * recordSize;
mixers[0].version = gLinkPlayers[2].version & 0xFF;
mixers[0].language = gLinkPlayers[2].language;
mixers[1].records = records + 3 * recordSize;
mixers[1].version = gLinkPlayers[3].version & 0xFF;
mixers[1].language = gLinkPlayers[3].language;
mixers[2].records = records + 0 * recordSize;
mixers[2].version = gLinkPlayers[0].version & 0xFF;
mixers[2].language = gLinkPlayers[0].language;
break;
case 2:
mixers[0].records = records + 3 * recordSize;
mixers[0].version = gLinkPlayers[3].version & 0xFF;
mixers[0].language = gLinkPlayers[3].language;
mixers[1].records = records + 0 * recordSize;
mixers[1].version = gLinkPlayers[0].version & 0xFF;
mixers[1].language = gLinkPlayers[0].language;
mixers[2].records = records + 1 * recordSize;
mixers[2].version = gLinkPlayers[1].version & 0xFF;
mixers[2].language = gLinkPlayers[1].language;
break;
case 3:
mixers[0].records = records + 0 * recordSize;
mixers[0].version = gLinkPlayers[0].version & 0xFF;
mixers[0].language = gLinkPlayers[0].language;
mixers[1].records = records + 1 * recordSize;
mixers[1].version = gLinkPlayers[1].version & 0xFF;
mixers[1].language = gLinkPlayers[1].language;
mixers[2].records = records + 2 * recordSize;
mixers[2].version = gLinkPlayers[2].version & 0xFF;
mixers[2].language = gLinkPlayers[2].language;
break;
}
sub_80EAEF4(mixers);
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:55:07 +02:00
{
if (gSaveBlock1Ptr->secretBases[i].sbr_field_1_0 == 1)
{
gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 = 1;
gSaveBlock1Ptr->secretBases[i].sbr_field_1_0 = 0;
}
}
sub_80EAAF4();
2019-01-02 00:19:07 +01:00
for (i = 1; i < SECRET_BASES_COUNT; i ++)
2017-10-28 03:55:07 +02:00
{
if (gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 == 2)
{
gSaveBlock1Ptr->secretBases[i].sbr_field_1_6 = 0;
}
}
if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0 && gSaveBlock1Ptr->secretBases[0].sbr_field_e != 0xFFFF)
{
gSaveBlock1Ptr->secretBases[0].sbr_field_e ++;
}
}
2017-10-28 03:17:17 +02:00
}
2017-10-28 04:12:11 +02:00
void sub_80EB18C(struct SecretBaseRecord *bases)
{
u32 i;
2019-01-02 00:19:07 +01:00
for (i = 0; i < SECRET_BASES_COUNT; i ++)
2017-10-28 04:12:11 +02:00
{
if (bases[i].language == LANGUAGE_JAPANESE)
{
ClearSecretBase(&bases[i]);
}
}
}
void sub_80EB1AC(void)
{
VarSet(VAR_0x40EC, 0);
VarSet(VAR_0x40ED, 0);
VarSet(VAR_0x40EE, 0);
VarSet(VAR_0x40EF, 0);
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:12:11 +02:00
{
VarSet(VAR_0x40F0, TRUE);
}
else
{
VarSet(VAR_0x40F0, FALSE);
}
gUnknown_0203A01D = FALSE;
}
void sub_80EB218(void)
{
if (VarGet(VAR_0x40F0) && gUnknown_0203A01D == TRUE && !CurrentMapIsSecretBase())
{
VarSet(VAR_0x40F0, FALSE);
gUnknown_0203A01D = FALSE;
sub_80EEA70();
VarSet(VAR_0x40EC, 0);
VarSet(VAR_0x40ED, 0);
VarSet(VAR_0x40EE, 0);
VarSet(VAR_0x40EF, 0);
VarSet(VAR_0x40F0, FALSE);
}
}
2017-10-28 04:20:13 +02:00
void sub_80EB290(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x800);
}
}
void sub_80EB2C8(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x400);
}
}
void sub_80EB300(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001);
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x2000);
}
}
void sub_80EB368(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001);
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x800);
}
}
void sub_80EB3D0(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001);
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x1000);
}
}
void sub_80EB438(void)
{
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:20:13 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001);
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x001);
}
}
2017-10-28 04:24:54 +02:00
void sub_80EB498(void)
{
s16 x;
s16 y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
switch (MapGridGetMetatileIdAt(x, y))
{
case 0x31C:
case 0x31D:
case 0x31E:
case 0x31F:
case 0x324:
case 0x325:
case 0x326:
case 0x327:
case 0x32C:
case 0x32D:
case 0x330:
case 0x331:
case 0x332:
case 0x333:
case 0x334:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:24:54 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x4000);
}
break;
}
}
2017-10-28 04:34:38 +02:00
void sub_80EB56C(void)
{
s16 x;
s16 y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
switch (MapGridGetMetatileIdAt(x, y))
{
case 0x28a:
case 0x28b:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x40);
}
break;
case 0x2d8:
case 0x2d9:
case 0x2da:
case 0x2db:
case 0x2dc:
case 0x2dd:
case 0x2e8:
case 0x2e9:
case 0x2ea:
case 0x2eb:
case 0x2ec:
case 0x2ed:
case 0x2ee:
case 0x2ef:
case 0x2f8:
case 0x2f9:
case 0x2fa:
case 0x2fb:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x8);
}
break;
case 0x22c:
case 0x233:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x40);
}
break;
case 0x288:
case 0x289:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x100);
}
break;
case 0x22d:
case 0x22e:
case 0x22f:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x10);
}
break;
case 0x287:
case 0x28f:
case 0x298:
case 0x299:
case 0x29a:
case 0x29b:
case 0x29c:
case 0x29d:
case 0x29e:
case 0x29f:
case 0x2ab:
case 0x2b0:
case 0x2b1:
case 0x2b2:
case 0x2b4:
case 0x2b5:
case 0x2b6:
case 0x2b7:
case 0x2cb:
case 0x2cc:
case 0x2cd:
case 0x2ce:
case 0x2cf:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:34:38 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8);
}
break;
}
}
2017-10-28 04:38:33 +02:00
void sub_80EB9E0(void)
{
s16 x;
s16 y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
switch (MapGridGetMetatileIdAt(x, y))
{
case 0x291:
case 0x294:
case 0x297:
case 0x2a1:
case 0x2a5:
case 0x2a9:
case 0x2ad:
case 0x2bb:
case 0x2be:
case 0x2c3:
case 0x2c6:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:38:33 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8);
}
break;
}
}
2017-10-28 04:43:11 +02:00
void sub_80EBB28(void)
{
s16 x;
s16 y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
switch (MapGridGetMetatileIdAt(x, y))
{
case 0x290:
case 0x292:
case 0x293:
case 0x295:
case 0x296:
case 0x2a0:
case 0x2a2:
case 0x2a3:
case 0x2a4:
case 0x2a6:
case 0x2a7:
case 0x2a8:
case 0x2aa:
case 0x2ac:
case 0x2ae:
case 0x2af:
case 0x2bc:
case 0x2bd:
case 0x2bf:
case 0x2c4:
case 0x2c5:
case 0x2c7:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:43:11 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8);
}
break;
case 0x280:
case 0x281:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:43:11 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x100);
}
break;
case 0x225:
case 0x226:
case 0x227:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:43:11 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x10);
}
break;
}
}
2017-10-28 04:46:57 +02:00
void sub_80EBE7C(void)
{
s16 x;
s16 y;
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
switch ((int)MapGridGetMetatileIdAt(x, y))
{
case 0x28d:
case 0x28e:
2018-12-10 01:22:59 +01:00
if (VarGet(VAR_CURRENT_SECRET_BASE) != 0)
2017-10-28 04:46:57 +02:00
{
VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x4);
}
break;
}
}