pokeemerald/src/region_map.c

386 lines
12 KiB
C
Raw Normal View History

2017-10-30 00:33:53 +01:00
// Includes
#include "global.h"
2017-10-30 02:14:53 +01:00
#include "main.h"
2017-10-30 00:33:53 +01:00
#include "region_map.h"
2017-10-30 01:49:49 +01:00
#include "menu.h"
#include "palette.h"
#include "bg.h"
2017-10-30 00:33:53 +01:00
// Static type declarations
struct UnkStruct_0203A148 {
u8 filler_000[0xa74];
};
// Static RAM declarations
EWRAM_DATA struct RegionMap *gUnknown_0203A144 = NULL;
EWRAM_DATA struct UnkStruct_0203A148 *gUnknown_0203A148 = NULL;
// Static ROM declarations
u8 sub_81230C4(void);
2017-10-30 02:14:53 +01:00
u8 sub_8123254(void);
void sub_81236C4(s32 a0, s32 a1, s32 a2, s32 a3, u16 a4, u16 a5, u16 a6);
void sub_81237B4(void);
2017-10-30 01:49:49 +01:00
void sub_81238AC(void);
u8 get_flagnr_blue_points(u16 mapSecId);
2017-10-30 02:14:53 +01:00
u16 sub_8123EB4(u16 mapSecId);
2017-10-30 01:49:49 +01:00
void sub_8123FB0(void);
2017-10-30 02:14:53 +01:00
u8 _swiopen(void);
2017-10-30 02:38:45 +01:00
u8 sub_8123334(void);
2017-10-30 02:31:38 +01:00
u16 sub_812386C(u16 x, u16 y);
2017-10-30 03:05:15 +01:00
void sub_812378C(s16 x, s16 y);
2017-10-30 04:08:06 +01:00
void sub_8124238(void);
void sub_81243B0(void);
2017-10-30 00:33:53 +01:00
// .rodata
2017-10-30 01:49:49 +01:00
extern const u8 gUnknown_0859F77C[];
extern const u8 gUnknown_085A04E0[];
extern const u16 gUnknown_0859F73C[];
extern const u8 gUnknown_0859F60C[];
extern const u8 gUnknown_0859F650[];
2017-10-30 00:33:53 +01:00
// .text
2017-10-30 01:49:49 +01:00
void sub_8122CDC(struct RegionMap *regionMap, u8 argument)
2017-10-30 00:33:53 +01:00
{
sub_8122CF8(regionMap, NULL, argument);
while (sub_8122DB0());
}
2017-10-30 01:49:49 +01:00
void sub_8122CF8(struct RegionMap *regionMap, struct UnkStruct_8122CF8 *arg1, u8 arg2)
2017-10-30 00:33:53 +01:00
{
gUnknown_0203A144 = regionMap;
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->initStep = 0;
gUnknown_0203A144->zoomed = arg2;
2017-10-30 00:33:53 +01:00
gUnknown_0203A144->inputCallback = arg2 == TRUE ? sub_8123254 : sub_81230C4;
if (arg1 != NULL)
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->bgNum = arg1->unk_0_0;
2017-10-30 00:33:53 +01:00
gUnknown_0203A144->unk_081 = arg1->unk_0_2;
gUnknown_0203A144->unk_082 = arg1->unk_0_4;
gUnknown_0203A144->unk_083 = TRUE;
}
else
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->bgNum = 2;
2017-10-30 00:33:53 +01:00
gUnknown_0203A144->unk_081 = 2;
gUnknown_0203A144->unk_082 = 28;
gUnknown_0203A144->unk_083 = FALSE;
}
}
2017-10-30 01:49:49 +01:00
void sub_8122D88(struct RegionMap *regionMap)
{
gUnknown_0203A144 = regionMap;
sub_81238AC();
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->unk_074 = gUnknown_0203A144->cursorPosX;
gUnknown_0203A144->unk_076 = gUnknown_0203A144->cursorPosY;
2017-10-30 01:49:49 +01:00
}
bool8 sub_8122DB0(void)
{
2017-10-30 03:05:15 +01:00
switch (gUnknown_0203A144->initStep)
2017-10-30 01:49:49 +01:00
{
case 0:
if (gUnknown_0203A144->unk_083)
{
2017-10-30 03:05:15 +01:00
decompress_and_copy_tile_data_to_vram(gUnknown_0203A144->bgNum, gUnknown_0859F77C, 0, 0, 0);
2017-10-30 01:49:49 +01:00
}
else
{
LZ77UnCompVram(gUnknown_0859F77C, (u16 *)BG_SCREEN_ADDR(16));
}
break;
case 1:
if (gUnknown_0203A144->unk_083)
{
if (!free_temp_tile_data_buffers_if_possible())
{
2017-10-30 03:05:15 +01:00
decompress_and_copy_tile_data_to_vram(gUnknown_0203A144->bgNum, gUnknown_085A04E0, 0, 0, 1);
2017-10-30 01:49:49 +01:00
}
}
else
{
LZ77UnCompVram(gUnknown_085A04E0, (u16 *)BG_SCREEN_ADDR(28));
}
break;
case 2:
if (!free_temp_tile_data_buffers_if_possible())
{
LoadPalette(gUnknown_0859F73C, 0x70, 0x60);
}
break;
case 3:
2017-10-30 03:05:15 +01:00
LZ77UnCompWram(gUnknown_0859F60C, gUnknown_0203A144->cursorSmallImage);
2017-10-30 01:49:49 +01:00
break;
case 4:
2017-10-30 03:05:15 +01:00
LZ77UnCompWram(gUnknown_0859F650, gUnknown_0203A144->cursorLargeImage);
2017-10-30 01:49:49 +01:00
break;
case 5:
sub_81238AC();
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->unk_074 = gUnknown_0203A144->cursorPosX;
gUnknown_0203A144->unk_076 = gUnknown_0203A144->cursorPosY;
2017-10-30 01:49:49 +01:00
gUnknown_0203A144->mapSecId = sub_8123EB4(gUnknown_0203A144->mapSecId);
gUnknown_0203A144->unk_002 = get_flagnr_blue_points(gUnknown_0203A144->mapSecId);
GetMapName(gUnknown_0203A144->mapSecName, gUnknown_0203A144->mapSecId, 16);
break;
case 6:
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->zoomed == FALSE)
2017-10-30 01:49:49 +01:00
{
sub_81236C4(0, 0, 0, 0, 0x100, 0x100, 0);
}
else
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->scrollX = gUnknown_0203A144->cursorPosX * 8 - 0x34;
gUnknown_0203A144->scrollY = gUnknown_0203A144->cursorPosY * 8 - 0x44;
gUnknown_0203A144->unk_064 = gUnknown_0203A144->cursorPosX;
gUnknown_0203A144->unk_066 = gUnknown_0203A144->cursorPosY;
sub_81236C4(gUnknown_0203A144->scrollX, gUnknown_0203A144->scrollY, 0x38, 0x48, 0x80, 0x80, 0);
2017-10-30 01:49:49 +01:00
}
break;
case 7:
sub_8123FB0();
sub_81237B4();
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorSprite = NULL;
gUnknown_0203A144->playerIconSprite = NULL;
gUnknown_0203A144->cursorMovementFrameCounter = 0;
gUnknown_0203A144->blinkPlayerIcon = FALSE;
2017-10-30 01:49:49 +01:00
if (gUnknown_0203A144->unk_083)
{
2017-10-30 03:05:15 +01:00
SetBgAttribute(gUnknown_0203A144->bgNum, BG_CTRL_ATTR_MAPBASEINDEX, 2);
SetBgAttribute(gUnknown_0203A144->bgNum, BG_CTRL_ATTR_VISIBLE, gUnknown_0203A144->unk_081);
SetBgAttribute(gUnknown_0203A144->bgNum, BG_CTRL_ATTR_CHARBASEINDEX, gUnknown_0203A144->unk_082);
SetBgAttribute(gUnknown_0203A144->bgNum, BG_CTRL_ATTR_PRIORITY, 1);
SetBgAttribute(gUnknown_0203A144->bgNum, BG_CTRL_ATTR_SCREENSIZE, 1);
2017-10-30 01:49:49 +01:00
}
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->initStep ++;
2017-10-30 01:49:49 +01:00
return FALSE;
default:
return FALSE;
}
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->initStep ++;
2017-10-30 01:49:49 +01:00
return TRUE;
}
2017-10-30 01:58:53 +01:00
void sub_8123030(u16 a0, u32 a1)
{
BlendPalettes(0x380, a1, a0);
CpuCopy16(gPlttBufferFaded + 0x70, gPlttBufferUnfaded + 0x70, 0x60);
}
void sub_812305C(void)
{
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorSprite != NULL)
2017-10-30 01:58:53 +01:00
{
2017-10-30 03:05:15 +01:00
DestroySprite(gUnknown_0203A144->cursorSprite);
FreeSpriteTilesByTag(gUnknown_0203A144->cursorTileTag);
FreeSpritePaletteByTag(gUnknown_0203A144->cursorPaletteTag);
2017-10-30 01:58:53 +01:00
}
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->playerIconSprite != NULL)
2017-10-30 01:58:53 +01:00
{
2017-10-30 03:05:15 +01:00
DestroySprite(gUnknown_0203A144->playerIconSprite);
FreeSpriteTilesByTag(gUnknown_0203A144->playerIconTileTag);
FreeSpritePaletteByTag(gUnknown_0203A144->playerIconPaletteTag);
2017-10-30 01:58:53 +01:00
}
}
u8 sub_81230AC(void)
{
return gUnknown_0203A144->inputCallback();
}
2017-10-30 02:14:53 +01:00
u8 sub_81230C4(void)
{
u8 input;
input = INPUT_EVENT_NONE;
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorDeltaX = 0;
gUnknown_0203A144->cursorDeltaY = 0;
if (gMain.heldKeys & DPAD_UP && gUnknown_0203A144->cursorPosY > 2)
2017-10-30 02:14:53 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorDeltaY = -1;
2017-10-30 02:31:38 +01:00
input = INPUT_EVENT_MOVE_START;
2017-10-30 02:14:53 +01:00
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_DOWN && gUnknown_0203A144->cursorPosY < 16)
2017-10-30 02:14:53 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorDeltaY = +1;
2017-10-30 02:31:38 +01:00
input = INPUT_EVENT_MOVE_START;
2017-10-30 02:14:53 +01:00
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_LEFT && gUnknown_0203A144->cursorPosX > 1)
2017-10-30 02:14:53 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorDeltaX = -1;
2017-10-30 02:31:38 +01:00
input = INPUT_EVENT_MOVE_START;
2017-10-30 02:14:53 +01:00
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_RIGHT && gUnknown_0203A144->cursorPosX < 28)
2017-10-30 02:14:53 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorDeltaX = +1;
2017-10-30 02:31:38 +01:00
input = INPUT_EVENT_MOVE_START;
2017-10-30 02:14:53 +01:00
}
if (gMain.newKeys & A_BUTTON)
{
input = INPUT_EVENT_A_BUTTON;
}
else if (gMain.newKeys & B_BUTTON)
{
input = INPUT_EVENT_B_BUTTON;
}
2017-10-30 02:31:38 +01:00
if (input == INPUT_EVENT_MOVE_START)
2017-10-30 02:14:53 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorMovementFrameCounter = 4;
2017-10-30 02:14:53 +01:00
gUnknown_0203A144->inputCallback = _swiopen;
}
return input;
}
2017-10-30 02:31:38 +01:00
u8 _swiopen(void)
{
u16 mapSecId;
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorMovementFrameCounter != 0)
2017-10-30 02:31:38 +01:00
{
return INPUT_EVENT_MOVE_CONT;
}
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorDeltaX > 0)
2017-10-30 02:31:38 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorPosX ++;
2017-10-30 02:31:38 +01:00
}
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorDeltaX < 0)
2017-10-30 02:31:38 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorPosX --;
2017-10-30 02:31:38 +01:00
}
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorDeltaY > 0)
2017-10-30 02:31:38 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorPosY ++;
2017-10-30 02:31:38 +01:00
}
2017-10-30 03:05:15 +01:00
if (gUnknown_0203A144->cursorDeltaY < 0)
2017-10-30 02:31:38 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->cursorPosY --;
2017-10-30 02:31:38 +01:00
}
2017-10-30 03:05:15 +01:00
mapSecId = sub_812386C(gUnknown_0203A144->cursorPosX, gUnknown_0203A144->cursorPosY);
2017-10-30 02:31:38 +01:00
gUnknown_0203A144->unk_002 = get_flagnr_blue_points(mapSecId);
if (mapSecId != gUnknown_0203A144->mapSecId)
{
gUnknown_0203A144->mapSecId = mapSecId;
GetMapName(gUnknown_0203A144->mapSecName, gUnknown_0203A144->mapSecId, 16);
}
sub_8123FB0();
gUnknown_0203A144->inputCallback = sub_81230C4;
return INPUT_EVENT_MOVE_END;
}
2017-10-30 02:38:45 +01:00
u8 sub_8123254(void)
{
u8 input;
input = INPUT_EVENT_NONE;
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorDeltaX = 0;
gUnknown_0203A144->zoomedCursorDeltaY = 0;
if (gMain.heldKeys & DPAD_UP && gUnknown_0203A144->scrollY > -0x34)
2017-10-30 02:38:45 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorDeltaY = -1;
2017-10-30 02:38:45 +01:00
input = INPUT_EVENT_MOVE_START;
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_DOWN && gUnknown_0203A144->scrollY < 0x3c)
2017-10-30 02:38:45 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorDeltaY = +1;
2017-10-30 02:38:45 +01:00
input = INPUT_EVENT_MOVE_START;
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_LEFT && gUnknown_0203A144->scrollX > -0x2c)
2017-10-30 02:38:45 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorDeltaX = -1;
2017-10-30 02:38:45 +01:00
input = INPUT_EVENT_MOVE_START;
}
2017-10-30 03:05:15 +01:00
if (gMain.heldKeys & DPAD_RIGHT && gUnknown_0203A144->scrollX < 0xac)
2017-10-30 02:38:45 +01:00
{
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorDeltaX = +1;
2017-10-30 02:38:45 +01:00
input = INPUT_EVENT_MOVE_START;
}
if (gMain.newKeys & A_BUTTON)
{
input = INPUT_EVENT_A_BUTTON;
}
if (gMain.newKeys & B_BUTTON)
{
input = INPUT_EVENT_B_BUTTON;
}
if (input == INPUT_EVENT_MOVE_START)
{
gUnknown_0203A144->inputCallback = sub_8123334;
2017-10-30 03:05:15 +01:00
gUnknown_0203A144->zoomedCursorMovementFrameCounter = 0;
2017-10-30 02:38:45 +01:00
}
return input;
}
2017-10-30 03:05:15 +01:00
u8 sub_8123334(void)
{
u16 x;
u16 y;
u16 mapSecId;
gUnknown_0203A144->scrollY += gUnknown_0203A144->zoomedCursorDeltaY;
gUnknown_0203A144->scrollX += gUnknown_0203A144->zoomedCursorDeltaX;
sub_812378C(gUnknown_0203A144->scrollX, gUnknown_0203A144->scrollY);
gUnknown_0203A144->zoomedCursorMovementFrameCounter ++;
if (gUnknown_0203A144->zoomedCursorMovementFrameCounter == 8)
{
x = (gUnknown_0203A144->scrollX + 0x2c) / 8 + 1;
y = (gUnknown_0203A144->scrollY + 0x34) / 8 + 2;
if (x != gUnknown_0203A144->unk_064 || y != gUnknown_0203A144->unk_066)
{
gUnknown_0203A144->unk_064 = x;
gUnknown_0203A144->unk_066 = y;
mapSecId = sub_812386C(x, y);
gUnknown_0203A144->unk_002 = get_flagnr_blue_points(mapSecId);
if (mapSecId != gUnknown_0203A144->mapSecId)
{
gUnknown_0203A144->mapSecId = mapSecId;
GetMapName(gUnknown_0203A144->mapSecName, gUnknown_0203A144->mapSecId, 16);
}
sub_8123FB0();
}
gUnknown_0203A144->zoomedCursorMovementFrameCounter = 0;
gUnknown_0203A144->inputCallback = sub_8123254;
return INPUT_EVENT_MOVE_END;
}
2017-10-30 04:08:06 +01:00
return INPUT_EVENT_MOVE_CONT;
}
void sub_8123418(void)
{
if (gUnknown_0203A144->zoomed == FALSE)
{
gUnknown_0203A144->scrollY = 0;
gUnknown_0203A144->scrollX = 0;
gUnknown_0203A144->unk_040 = 0;
gUnknown_0203A144->unk_03c = 0;
gUnknown_0203A144->unk_060 = gUnknown_0203A144->cursorPosX * 8 - 0x34;
gUnknown_0203A144->unk_062 = gUnknown_0203A144->cursorPosY * 8 - 0x44;
gUnknown_0203A144->unk_044 = (gUnknown_0203A144->unk_060 << 8) / 16;
gUnknown_0203A144->unk_048 = (gUnknown_0203A144->unk_062 << 8) / 16;
gUnknown_0203A144->unk_064 = gUnknown_0203A144->cursorPosX;
gUnknown_0203A144->unk_066 = gUnknown_0203A144->cursorPosY;
gUnknown_0203A144->unk_04c = 0x10000;
gUnknown_0203A144->unk_050 = -0x800;
}
2017-10-30 03:05:15 +01:00
else
{
2017-10-30 04:08:06 +01:00
gUnknown_0203A144->unk_03c = gUnknown_0203A144->scrollX * 256;
gUnknown_0203A144->unk_040 = gUnknown_0203A144->scrollY * 256;
gUnknown_0203A144->unk_060 = 0;
gUnknown_0203A144->unk_062 = 0;
gUnknown_0203A144->unk_044 = -(gUnknown_0203A144->unk_03c / 16);
gUnknown_0203A144->unk_048 = -(gUnknown_0203A144->unk_040 / 16);
gUnknown_0203A144->cursorPosX = gUnknown_0203A144->unk_064;
gUnknown_0203A144->cursorPosY = gUnknown_0203A144->unk_066;
gUnknown_0203A144->unk_04c = 0x8000;
gUnknown_0203A144->unk_050 = 0x800;
2017-10-30 03:05:15 +01:00
}
2017-10-30 04:08:06 +01:00
gUnknown_0203A144->unk_06e = 0;
sub_8124238();
sub_81243B0();
2017-10-30 03:05:15 +01:00
}