// Includes #include "global.h" #include "list_menu.h" #include "decoration.h" #include "decoration_inventory.h" #include "fieldmap.h" #include "field_camera.h" #include "field_player_avatar.h" #include "text.h" #include "string_util.h" #include "event_data.h" #include "secret_base.h" // Static type declarations struct SecretBaseListMenuBuffer { struct ListMenuItem items[11]; u8 names[11][32]; }; // Static RAM declarations EWRAM_DATA u8 sCurSecretBaseId = 0; EWRAM_DATA u8 gUnknown_0203A01D = 0; EWRAM_DATA struct SecretBaseListMenuBuffer *gUnknown_0203A020 = NULL; // Static ROM declarations // .rodata extern const struct { u16 tile1; u16 tile2; } gUnknown_0858CFCC[7]; // .text void sub_80E8AF0(struct SecretBaseRecord *sbr) { u16 i; CpuFastFill16(0, sbr, sizeof(struct SecretBaseRecord)); for (i = 0; i < 7; i ++) { sbr->trainerName[i] = EOS; } } void ResetSecretBases(void) { u16 i; for (i = 0; i < 20; i ++) { sub_80E8AF0(&gSaveBlock1Ptr->secretBases[i]); } } void sub_80E8B58(void) { sCurSecretBaseId = gSpecialVar_0x8004; } void sub_80E8B6C(void) { u16 i; gScriptResult = FALSE; for (i = 0; i < 20; i ++) { if (sCurSecretBaseId != gSaveBlock1Ptr->secretBases[i].secretBaseId) { continue; } gScriptResult = TRUE; VarSet(VAR_0x4054, i); break; } } void sub_80E8BC8(void) { if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0) { gScriptResult = TRUE; } else { gScriptResult = FALSE; } } u8 sub_80E8BF8(void) { s16 x; s16 y; s16 behavior; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); behavior = MapGridGetMetatileBehaviorAt(x, y) & 0xFFF; if (behavior == 0x90 || behavior == 0x91) { return 1; } if (behavior == 0x92 || behavior == 0x93) { return 2; } if (behavior == 0x9a || behavior == 0x9b) { return 3; } if (behavior == 0x94 || behavior == 0x95) { return 4; } if (behavior == 0x96 || behavior == 0x97 || behavior == 0x9c || behavior == 0x9d) { return 5; } if (behavior == 0x98 || behavior == 0x99) { return 6; } return 0; } void sub_80E8C98(void) { gSpecialVar_0x8007 = sub_80E8BF8(); } void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile) { struct MapData *mapData; s16 x; s16 y; mapData = gMapHeader.mapData; for (y = 0; y < mapData->height; y ++) { for (x = 0; x < mapData->width; x ++) { if ((mapData->map[y * mapData->width + x] & 0x3ff) == tile) { *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) { MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | 0xC00); CurrentMapDrawMetatileAt(x, y); return; } } for (i = 0; i < 7; i ++) { if (gUnknown_0858CFCC[i].tile2 == tile) { MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile1 | 0xC00); CurrentMapDrawMetatileAt(x, y); return; } } } 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]; } VarSet(VAR_0x4054, 0); 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); } void sub_80E8EE0(struct MapEvents *events) { u16 bgevidx; u16 idx; u16 jdx; s16 tile_id; s16 x; s16 y; for (bgevidx = 0; bgevidx < events->bgEventCount; bgevidx ++) { if (events->bgEvents[bgevidx].kind == 8) { for (jdx = 0; jdx < 20; jdx ++) { if (gSaveBlock1Ptr->secretBases[jdx].secretBaseId == events->bgEvents[bgevidx].bgUnion.secretBaseId) { x = events->bgEvents[bgevidx].x + 7; y = events->bgEvents[bgevidx].y + 7; tile_id = MapGridGetMetatileIdAt(x, y); for (idx = 0; idx < 7; idx ++) { if (gUnknown_0858CFCC[idx].tile1 == tile_id) { MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[idx].tile2 | 0xc00); break; } } break; } } } } }