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 01:49:49 +01:00
|
|
|
#include "menu.h"
|
2017-10-30 13:46:36 +01:00
|
|
|
#include "gpu_regs.h"
|
2017-10-30 01:49:49 +01:00
|
|
|
#include "palette.h"
|
2017-10-30 13:39:39 +01:00
|
|
|
#include "trig.h"
|
2017-10-31 02:08:28 +01:00
|
|
|
#include "map_constants.h"
|
|
|
|
#include "overworld.h"
|
2017-10-31 02:20:31 +01:00
|
|
|
#include "flags.h"
|
|
|
|
#include "event_data.h"
|
2017-10-31 02:14:52 +01:00
|
|
|
#include "rom6.h"
|
2017-11-01 02:51:11 +01:00
|
|
|
#include "secret_base.h"
|
|
|
|
#include "string_util.h"
|
|
|
|
#include "text.h"
|
2017-10-30 13:39:39 +01:00
|
|
|
#include "region_map.h"
|
2017-10-30 00:33:53 +01:00
|
|
|
|
2017-10-30 13:58:43 +01:00
|
|
|
#define MAP_WIDTH 28
|
|
|
|
#define MAP_HEIGHT 15
|
|
|
|
#define MAPCURSOR_X_MIN 1
|
|
|
|
#define MAPCURSOR_Y_MIN 2
|
|
|
|
#define MAPCURSOR_X_MAX (MAPCURSOR_X_MIN + MAP_WIDTH - 1)
|
|
|
|
#define MAPCURSOR_Y_MAX (MAPCURSOR_Y_MIN + MAP_HEIGHT - 1)
|
|
|
|
|
2017-10-30 00:33:53 +01:00
|
|
|
// Static type declarations
|
|
|
|
|
|
|
|
struct UnkStruct_0203A148 {
|
|
|
|
u8 filler_000[0xa74];
|
|
|
|
};
|
|
|
|
|
2017-10-31 02:08:28 +01:00
|
|
|
struct RegionMapLocation
|
|
|
|
{
|
|
|
|
u8 x, y;
|
|
|
|
u8 width, height;
|
2017-11-01 02:51:11 +01:00
|
|
|
const u8 *name;
|
2017-10-31 02:08:28 +01:00
|
|
|
};
|
|
|
|
|
2017-10-30 00:33:53 +01:00
|
|
|
// Static RAM declarations
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
EWRAM_DATA struct RegionMap *gRegionMap = NULL;
|
2017-10-30 00:33:53 +01:00
|
|
|
EWRAM_DATA struct UnkStruct_0203A148 *gUnknown_0203A148 = NULL;
|
|
|
|
|
|
|
|
// Static ROM declarations
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
static u8 ProcessRegionMapInput_Full(void);
|
|
|
|
static u8 MoveRegionMapCursor_Full(void);
|
|
|
|
static u8 ProcessRegionMapInput_Zoomed(void);
|
|
|
|
static u8 MoveRegionMapCursor_Zoomed(void);
|
2017-10-31 03:20:09 +01:00
|
|
|
static void CalcZoomScrollParams(s16 scrollX, s16 scrollY, s16 c, s16 d, u16 e, u16 f, u8 rotation);
|
2017-11-01 01:58:47 +01:00
|
|
|
static u16 GetRegionMapSectionIdAt_Internal(u16 x, u16 y);
|
|
|
|
static void RegionMap_SetBG2XAndBG2Y(s16 x, s16 y);
|
|
|
|
static void RegionMap_InitializeStateBasedOnPlayerLocation(void);
|
|
|
|
static void RegionMap_InitializeStateBasedOnSSTidalLocation(void);
|
2017-10-31 02:20:31 +01:00
|
|
|
static u8 get_flagnr_blue_points(u16 mapSecId);
|
2017-11-01 01:58:47 +01:00
|
|
|
static u16 CorrectSpecialMapSecId_Internal(u16 mapSecId);
|
|
|
|
static u16 RegionMap_GetTerraCaveMapSecId(void);
|
|
|
|
static void RegionMap_GetMarineCaveCoords(u16 *x, u16 *y);
|
|
|
|
static bool32 RegionMap_IsPlayerInCave(u8 mapSecId);
|
|
|
|
static void RegionMap_GetPositionOfCursorWithinMapSection(void);
|
|
|
|
static bool8 RegionMap_IsMapSecIdInNextRow(u16 y);
|
|
|
|
static void FreeRegionMapCursorSprite(void);
|
|
|
|
static void HideRegionMapPlayerIcon(void);
|
|
|
|
static void UnhideRegionMapPlayerIcon(void);
|
2017-11-01 02:32:25 +01:00
|
|
|
static void RegionMapPlayerIconSpriteCallback_Zoomed(struct Sprite *sprite);
|
|
|
|
static void RegionMapPlayerIconSpriteCallback_Full(struct Sprite *sprite);
|
|
|
|
static void RegionMapPlayerIconSpriteCallback(struct Sprite *sprite);
|
2017-10-30 00:33:53 +01:00
|
|
|
|
|
|
|
// .rodata
|
|
|
|
|
2017-10-30 01:49:49 +01:00
|
|
|
extern const u8 gUnknown_0859F60C[];
|
|
|
|
extern const u8 gUnknown_0859F650[];
|
2017-10-30 13:58:43 +01:00
|
|
|
extern const u16 gUnknown_0859F73C[];
|
|
|
|
extern const u8 gUnknown_0859F77C[];
|
|
|
|
extern const u8 gUnknown_085A04E0[];
|
|
|
|
extern const u8 gUnknown_085A096C[];
|
2017-10-31 02:08:28 +01:00
|
|
|
extern const struct RegionMapLocation gRegionMapEntries[];
|
2017-11-01 00:40:35 +01:00
|
|
|
extern const u8 gUnknown_085A084C[];
|
|
|
|
extern const u16 gUnknown_085A082C[];
|
|
|
|
extern const u16 gUnknown_085A08CC[];
|
|
|
|
extern const u8 gUnknown_085A08EC[];
|
2017-10-31 02:34:19 +01:00
|
|
|
extern const u16 gUnknown_085A1B24[][2];
|
2017-10-31 02:47:37 +01:00
|
|
|
extern const u16 gUnknown_085A1B84[];
|
|
|
|
extern const u16 gUnknown_085A1B8A[];
|
|
|
|
extern const struct UCoords16 gUnknown_085A1BAC[];
|
2017-10-31 03:20:09 +01:00
|
|
|
extern const u8 gUnknown_085A1BCC[];
|
2017-10-31 13:38:17 +01:00
|
|
|
extern const struct SpritePalette gUnknown_085A1C00;
|
|
|
|
extern const struct SpriteTemplate gUnknown_085A1C08;
|
2017-11-01 00:40:35 +01:00
|
|
|
extern const struct OamData gUnknown_085A1C20;
|
|
|
|
extern const union AnimCmd *const gUnknown_085A1C30[];
|
2017-10-30 01:49:49 +01:00
|
|
|
|
2017-10-30 00:33:53 +01:00
|
|
|
// .text
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
void InitRegionMap(struct RegionMap *regionMap, bool8 zoomed)
|
2017-10-30 00:33:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
sub_8122CF8(regionMap, NULL, zoomed);
|
2017-10-30 00:33:53 +01:00
|
|
|
while (sub_8122DB0());
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
void sub_8122CF8(struct RegionMap *regionMap, struct BgTemplate *template, bool8 zoomed)
|
2017-10-30 00:33:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap = regionMap;
|
|
|
|
gRegionMap->initStep = 0;
|
|
|
|
gRegionMap->zoomed = zoomed;
|
|
|
|
gRegionMap->inputCallback = zoomed == TRUE ? ProcessRegionMapInput_Zoomed : ProcessRegionMapInput_Full;
|
|
|
|
if (template != NULL)
|
2017-10-30 00:33:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->bgNum = template->bg;
|
|
|
|
gRegionMap->charBaseIdx = template->charBaseIndex;
|
|
|
|
gRegionMap->mapBaseIdx = template->mapBaseIndex;
|
|
|
|
gRegionMap->bgManaged = TRUE;
|
2017-10-30 00:33:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->bgNum = 2;
|
|
|
|
gRegionMap->charBaseIdx = 2;
|
|
|
|
gRegionMap->mapBaseIdx = 28;
|
|
|
|
gRegionMap->bgManaged = FALSE;
|
2017-10-30 00:33:53 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 01:49:49 +01:00
|
|
|
|
|
|
|
void sub_8122D88(struct RegionMap *regionMap)
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap = regionMap;
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_InitializeStateBasedOnPlayerLocation();
|
2017-11-01 00:40:35 +01:00
|
|
|
gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX;
|
|
|
|
gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY;
|
2017-10-30 01:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool8 sub_8122DB0(void)
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
switch (gRegionMap->initStep)
|
2017-10-30 01:49:49 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->bgManaged)
|
2017-10-30 01:49:49 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
decompress_and_copy_tile_data_to_vram(gRegionMap->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:
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->bgManaged)
|
2017-10-30 01:49:49 +01:00
|
|
|
{
|
|
|
|
if (!free_temp_tile_data_buffers_if_possible())
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
decompress_and_copy_tile_data_to_vram(gRegionMap->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 13:39:39 +01:00
|
|
|
LZ77UnCompWram(gUnknown_0859F60C, gRegionMap->cursorSmallImage);
|
2017-10-30 01:49:49 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2017-10-30 13:39:39 +01:00
|
|
|
LZ77UnCompWram(gUnknown_0859F650, gRegionMap->cursorLargeImage);
|
2017-10-30 01:49:49 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_InitializeStateBasedOnPlayerLocation();
|
2017-11-01 00:40:35 +01:00
|
|
|
gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX;
|
|
|
|
gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY;
|
2017-11-01 01:58:47 +01:00
|
|
|
gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId);
|
2017-10-31 02:34:19 +01:00
|
|
|
gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId);
|
2017-10-30 13:39:39 +01:00
|
|
|
GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16);
|
2017-10-30 01:49:49 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->zoomed == FALSE)
|
2017-10-30 01:49:49 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0);
|
2017-10-30 01:49:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34;
|
|
|
|
gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44;
|
2017-10-31 03:35:28 +01:00
|
|
|
gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX;
|
|
|
|
gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY;
|
2017-10-30 13:39:39 +01:00
|
|
|
CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0);
|
2017-10-30 01:49:49 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_GetPositionOfCursorWithinMapSection();
|
2017-10-30 13:58:43 +01:00
|
|
|
UpdateRegionMapVideoRegs();
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorSprite = NULL;
|
|
|
|
gRegionMap->playerIconSprite = NULL;
|
|
|
|
gRegionMap->cursorMovementFrameCounter = 0;
|
|
|
|
gRegionMap->blinkPlayerIcon = FALSE;
|
|
|
|
if (gRegionMap->bgManaged)
|
2017-10-30 01:49:49 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_MAPBASEINDEX, 2);
|
|
|
|
SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_VISIBLE, gRegionMap->charBaseIdx);
|
|
|
|
SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_CHARBASEINDEX, gRegionMap->mapBaseIdx);
|
|
|
|
SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_PRIORITY, 1);
|
|
|
|
SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_SCREENSIZE, 1);
|
2017-10-30 01:49:49 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->initStep ++;
|
2017-10-30 01:49:49 +01:00
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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);
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
void FreeRegionMapIconResources(void)
|
2017-10-30 01:58:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorSprite != NULL)
|
2017-10-30 01:58:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
DestroySprite(gRegionMap->cursorSprite);
|
|
|
|
FreeSpriteTilesByTag(gRegionMap->cursorTileTag);
|
|
|
|
FreeSpritePaletteByTag(gRegionMap->cursorPaletteTag);
|
2017-10-30 01:58:53 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->playerIconSprite != NULL)
|
2017-10-30 01:58:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
DestroySprite(gRegionMap->playerIconSprite);
|
|
|
|
FreeSpriteTilesByTag(gRegionMap->playerIconTileTag);
|
|
|
|
FreeSpritePaletteByTag(gRegionMap->playerIconPaletteTag);
|
2017-10-30 01:58:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 sub_81230AC(void)
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
return gRegionMap->inputCallback();
|
2017-10-30 01:58:53 +01:00
|
|
|
}
|
2017-10-30 02:14:53 +01:00
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
static u8 ProcessRegionMapInput_Full(void)
|
2017-10-30 02:14:53 +01:00
|
|
|
{
|
|
|
|
u8 input;
|
|
|
|
|
|
|
|
input = INPUT_EVENT_NONE;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorDeltaX = 0;
|
|
|
|
gRegionMap->cursorDeltaY = 0;
|
2017-10-30 13:58:43 +01:00
|
|
|
if (gMain.heldKeys & DPAD_UP && gRegionMap->cursorPosY > MAPCURSOR_Y_MIN)
|
2017-10-30 02:14:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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 13:58:43 +01:00
|
|
|
if (gMain.heldKeys & DPAD_DOWN && gRegionMap->cursorPosY < MAPCURSOR_Y_MAX)
|
2017-10-30 02:14:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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 13:58:43 +01:00
|
|
|
if (gMain.heldKeys & DPAD_LEFT && gRegionMap->cursorPosX > MAPCURSOR_X_MIN)
|
2017-10-30 02:14:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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 13:58:43 +01:00
|
|
|
if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->cursorPosX < MAPCURSOR_X_MAX)
|
2017-10-30 02:14:53 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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 13:39:39 +01:00
|
|
|
gRegionMap->cursorMovementFrameCounter = 4;
|
|
|
|
gRegionMap->inputCallback = MoveRegionMapCursor_Full;
|
2017-10-30 02:14:53 +01:00
|
|
|
}
|
|
|
|
return input;
|
|
|
|
}
|
2017-10-30 02:31:38 +01:00
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
static u8 MoveRegionMapCursor_Full(void)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
|
|
|
u16 mapSecId;
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorMovementFrameCounter != 0)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
|
|
|
return INPUT_EVENT_MOVE_CONT;
|
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorDeltaX > 0)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorPosX ++;
|
2017-10-30 02:31:38 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorDeltaX < 0)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorPosX --;
|
2017-10-30 02:31:38 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorDeltaY > 0)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorPosY ++;
|
2017-10-30 02:31:38 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->cursorDeltaY < 0)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->cursorPosY --;
|
2017-10-30 02:31:38 +01:00
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
mapSecId = GetRegionMapSectionIdAt_Internal(gRegionMap->cursorPosX, gRegionMap->cursorPosY);
|
2017-10-31 02:34:19 +01:00
|
|
|
gRegionMap->iconDrawType = get_flagnr_blue_points(mapSecId);
|
2017-10-30 13:39:39 +01:00
|
|
|
if (mapSecId != gRegionMap->mapSecId)
|
2017-10-30 02:31:38 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->mapSecId = mapSecId;
|
|
|
|
GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16);
|
2017-10-30 02:31:38 +01:00
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_GetPositionOfCursorWithinMapSection();
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->inputCallback = ProcessRegionMapInput_Full;
|
2017-10-30 02:31:38 +01:00
|
|
|
return INPUT_EVENT_MOVE_END;
|
|
|
|
}
|
2017-10-30 02:38:45 +01:00
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
static u8 ProcessRegionMapInput_Zoomed(void)
|
2017-10-30 02:38:45 +01:00
|
|
|
{
|
|
|
|
u8 input;
|
|
|
|
|
|
|
|
input = INPUT_EVENT_NONE;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorDeltaX = 0;
|
|
|
|
gRegionMap->zoomedCursorDeltaY = 0;
|
|
|
|
if (gMain.heldKeys & DPAD_UP && gRegionMap->scrollY > -0x34)
|
2017-10-30 02:38:45 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorDeltaY = -1;
|
2017-10-30 02:38:45 +01:00
|
|
|
input = INPUT_EVENT_MOVE_START;
|
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gMain.heldKeys & DPAD_DOWN && gRegionMap->scrollY < 0x3c)
|
2017-10-30 02:38:45 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorDeltaY = +1;
|
2017-10-30 02:38:45 +01:00
|
|
|
input = INPUT_EVENT_MOVE_START;
|
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gMain.heldKeys & DPAD_LEFT && gRegionMap->scrollX > -0x2c)
|
2017-10-30 02:38:45 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorDeltaX = -1;
|
2017-10-30 02:38:45 +01:00
|
|
|
input = INPUT_EVENT_MOVE_START;
|
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->scrollX < 0xac)
|
2017-10-30 02:38:45 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->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)
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->inputCallback = MoveRegionMapCursor_Zoomed;
|
|
|
|
gRegionMap->zoomedCursorMovementFrameCounter = 0;
|
2017-10-30 02:38:45 +01:00
|
|
|
}
|
|
|
|
return input;
|
|
|
|
}
|
2017-10-30 03:05:15 +01:00
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
static u8 MoveRegionMapCursor_Zoomed(void)
|
2017-10-30 03:05:15 +01:00
|
|
|
{
|
|
|
|
u16 x;
|
|
|
|
u16 y;
|
|
|
|
u16 mapSecId;
|
|
|
|
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->scrollY += gRegionMap->zoomedCursorDeltaY;
|
|
|
|
gRegionMap->scrollX += gRegionMap->zoomedCursorDeltaX;
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_SetBG2XAndBG2Y(gRegionMap->scrollX, gRegionMap->scrollY);
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorMovementFrameCounter ++;
|
|
|
|
if (gRegionMap->zoomedCursorMovementFrameCounter == 8)
|
2017-10-30 03:05:15 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
x = (gRegionMap->scrollX + 0x2c) / 8 + 1;
|
|
|
|
y = (gRegionMap->scrollY + 0x34) / 8 + 2;
|
2017-10-31 03:35:28 +01:00
|
|
|
if (x != gRegionMap->zoomedCursorPosX || y != gRegionMap->zoomedCursorPosY)
|
2017-10-30 03:05:15 +01:00
|
|
|
{
|
2017-10-31 03:35:28 +01:00
|
|
|
gRegionMap->zoomedCursorPosX = x;
|
|
|
|
gRegionMap->zoomedCursorPosY = y;
|
2017-11-01 01:58:47 +01:00
|
|
|
mapSecId = GetRegionMapSectionIdAt_Internal(x, y);
|
2017-10-31 02:34:19 +01:00
|
|
|
gRegionMap->iconDrawType = get_flagnr_blue_points(mapSecId);
|
2017-10-30 13:39:39 +01:00
|
|
|
if (mapSecId != gRegionMap->mapSecId)
|
2017-10-30 03:05:15 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->mapSecId = mapSecId;
|
|
|
|
GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16);
|
2017-10-30 03:05:15 +01:00
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_GetPositionOfCursorWithinMapSection();
|
2017-10-30 03:05:15 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->zoomedCursorMovementFrameCounter = 0;
|
|
|
|
gRegionMap->inputCallback = ProcessRegionMapInput_Zoomed;
|
2017-10-30 03:05:15 +01:00
|
|
|
return INPUT_EVENT_MOVE_END;
|
|
|
|
}
|
2017-10-30 04:08:06 +01:00
|
|
|
return INPUT_EVENT_MOVE_CONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8123418(void)
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
if (gRegionMap->zoomed == FALSE)
|
2017-10-30 04:08:06 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->scrollY = 0;
|
|
|
|
gRegionMap->scrollX = 0;
|
|
|
|
gRegionMap->unk_040 = 0;
|
|
|
|
gRegionMap->unk_03c = 0;
|
|
|
|
gRegionMap->unk_060 = gRegionMap->cursorPosX * 8 - 0x34;
|
|
|
|
gRegionMap->unk_062 = gRegionMap->cursorPosY * 8 - 0x44;
|
|
|
|
gRegionMap->unk_044 = (gRegionMap->unk_060 << 8) / 16;
|
|
|
|
gRegionMap->unk_048 = (gRegionMap->unk_062 << 8) / 16;
|
2017-10-31 03:35:28 +01:00
|
|
|
gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX;
|
|
|
|
gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->unk_04c = 0x10000;
|
|
|
|
gRegionMap->unk_050 = -0x800;
|
2017-10-30 04:08:06 +01:00
|
|
|
}
|
2017-10-30 03:05:15 +01:00
|
|
|
else
|
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->unk_03c = gRegionMap->scrollX * 256;
|
|
|
|
gRegionMap->unk_040 = gRegionMap->scrollY * 256;
|
|
|
|
gRegionMap->unk_060 = 0;
|
|
|
|
gRegionMap->unk_062 = 0;
|
|
|
|
gRegionMap->unk_044 = -(gRegionMap->unk_03c / 16);
|
|
|
|
gRegionMap->unk_048 = -(gRegionMap->unk_040 / 16);
|
2017-10-31 03:35:28 +01:00
|
|
|
gRegionMap->cursorPosX = gRegionMap->zoomedCursorPosX;
|
|
|
|
gRegionMap->cursorPosY = gRegionMap->zoomedCursorPosY;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->unk_04c = 0x8000;
|
|
|
|
gRegionMap->unk_050 = 0x800;
|
2017-10-30 03:05:15 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->unk_06e = 0;
|
2017-11-01 01:58:47 +01:00
|
|
|
FreeRegionMapCursorSprite();
|
|
|
|
HideRegionMapPlayerIcon();
|
2017-10-30 03:05:15 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
bool8 sub_8123514(void)
|
2017-10-30 13:39:39 +01:00
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
bool8 r4;
|
2017-10-30 13:39:39 +01:00
|
|
|
|
|
|
|
if (gRegionMap->unk_06e >= 16)
|
2017-10-31 02:08:28 +01:00
|
|
|
{
|
2017-10-30 13:39:39 +01:00
|
|
|
return 0;
|
2017-10-31 02:08:28 +01:00
|
|
|
}
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->unk_06e ++;
|
|
|
|
if (gRegionMap->unk_06e == 16)
|
|
|
|
{
|
|
|
|
gRegionMap->unk_044 = 0;
|
|
|
|
gRegionMap->unk_048 = 0;
|
|
|
|
gRegionMap->scrollX = gRegionMap->unk_060;
|
|
|
|
gRegionMap->scrollY = gRegionMap->unk_062;
|
|
|
|
gRegionMap->unk_04c = (gRegionMap->zoomed == FALSE) ? (128 << 8) : (256 << 8);
|
|
|
|
gRegionMap->zoomed = !gRegionMap->zoomed;
|
|
|
|
gRegionMap->inputCallback = (gRegionMap->zoomed == FALSE) ? ProcessRegionMapInput_Full : ProcessRegionMapInput_Zoomed;
|
|
|
|
CreateRegionMapCursor(gRegionMap->cursorTileTag, gRegionMap->cursorPaletteTag);
|
2017-11-01 01:58:47 +01:00
|
|
|
UnhideRegionMapPlayerIcon();
|
|
|
|
r4 = FALSE;
|
2017-10-30 13:39:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->unk_03c += gRegionMap->unk_044;
|
|
|
|
gRegionMap->unk_040 += gRegionMap->unk_048;
|
|
|
|
gRegionMap->scrollX = gRegionMap->unk_03c >> 8;
|
|
|
|
gRegionMap->scrollY = gRegionMap->unk_040 >> 8;
|
|
|
|
gRegionMap->unk_04c += gRegionMap->unk_050;
|
2017-10-31 02:08:28 +01:00
|
|
|
if ((gRegionMap->unk_044 < 0 && gRegionMap->scrollX < gRegionMap->unk_060) || (gRegionMap->unk_044 > 0 && gRegionMap->scrollX > gRegionMap->unk_060))
|
2017-10-30 13:39:39 +01:00
|
|
|
{
|
|
|
|
gRegionMap->scrollX = gRegionMap->unk_060;
|
|
|
|
gRegionMap->unk_044 = 0;
|
|
|
|
}
|
2017-10-31 02:08:28 +01:00
|
|
|
if ((gRegionMap->unk_048 < 0 && gRegionMap->scrollY < gRegionMap->unk_062) || (gRegionMap->unk_048 > 0 && gRegionMap->scrollY > gRegionMap->unk_062))
|
2017-10-30 13:39:39 +01:00
|
|
|
{
|
|
|
|
gRegionMap->scrollY = gRegionMap->unk_062;
|
|
|
|
gRegionMap->unk_048 = 0;
|
|
|
|
}
|
|
|
|
if (gRegionMap->zoomed == FALSE)
|
|
|
|
{
|
|
|
|
if (gRegionMap->unk_04c < (128 << 8))
|
|
|
|
{
|
|
|
|
gRegionMap->unk_04c = (128 << 8);
|
|
|
|
gRegionMap->unk_050 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gRegionMap->unk_04c > (256 << 8))
|
|
|
|
{
|
|
|
|
gRegionMap->unk_04c = (256 << 8);
|
|
|
|
gRegionMap->unk_050 = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
r4 = TRUE;
|
2017-10-30 13:39:39 +01:00
|
|
|
}
|
|
|
|
CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, gRegionMap->unk_04c >> 8, gRegionMap->unk_04c >> 8, 0);
|
|
|
|
return r4;
|
|
|
|
}
|
|
|
|
|
2017-10-31 03:20:09 +01:00
|
|
|
static void CalcZoomScrollParams(s16 scrollX, s16 scrollY, s16 c, s16 d, u16 e, u16 f, u8 rotation)
|
2017-10-30 13:39:39 +01:00
|
|
|
{
|
|
|
|
s32 var1;
|
|
|
|
s32 var2;
|
|
|
|
s32 var3;
|
|
|
|
s32 var4;
|
|
|
|
|
|
|
|
gRegionMap->bg2pa = e * gSineTable[rotation + 64] >> 8;
|
2017-10-30 13:46:36 +01:00
|
|
|
gRegionMap->bg2pc = e * -gSineTable[rotation] >> 8;
|
|
|
|
gRegionMap->bg2pb = f * gSineTable[rotation] >> 8;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->bg2pd = f * gSineTable[rotation + 64] >> 8;
|
|
|
|
|
|
|
|
var1 = (scrollX << 8) + (c << 8);
|
2017-10-30 13:46:36 +01:00
|
|
|
var2 = d * gRegionMap->bg2pb + gRegionMap->bg2pa * c;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->bg2x = var1 - var2;
|
|
|
|
|
|
|
|
var3 = (scrollY << 8) + (d << 8);
|
2017-10-30 13:46:36 +01:00
|
|
|
var4 = gRegionMap->bg2pd * d + gRegionMap->bg2pc * c;
|
2017-10-30 13:39:39 +01:00
|
|
|
gRegionMap->bg2y = var3 - var4;
|
|
|
|
|
|
|
|
gRegionMap->needUpdateVideoRegs = TRUE;
|
|
|
|
}
|
2017-10-30 13:46:36 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void RegionMap_SetBG2XAndBG2Y(s16 x, s16 y)
|
2017-10-30 13:46:36 +01:00
|
|
|
{
|
|
|
|
gRegionMap->bg2x = (x << 8) + 0x1c00;
|
|
|
|
gRegionMap->bg2y = (y << 8) + 0x2400;
|
|
|
|
gRegionMap->needUpdateVideoRegs = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:58:43 +01:00
|
|
|
void UpdateRegionMapVideoRegs(void)
|
2017-10-30 13:46:36 +01:00
|
|
|
{
|
|
|
|
if (gRegionMap->needUpdateVideoRegs)
|
|
|
|
{
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PA, gRegionMap->bg2pa);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PB, gRegionMap->bg2pb);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PC, gRegionMap->bg2pc);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2PD, gRegionMap->bg2pd);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2X_L, gRegionMap->bg2x);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2X_H, gRegionMap->bg2x >> 16);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2Y_L, gRegionMap->bg2y);
|
|
|
|
SetGpuReg(REG_OFFSET_BG2Y_H, gRegionMap->bg2y >> 16);
|
|
|
|
gRegionMap->needUpdateVideoRegs = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-10-30 13:58:43 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
void PokedexAreaScreen_UpdateRegionMapVariablesAndVideoRegs(s16 x, s16 y)
|
2017-10-30 13:58:43 +01:00
|
|
|
{
|
|
|
|
CalcZoomScrollParams(x, y, 0x38, 0x48, 0x100, 0x100, 0);
|
|
|
|
UpdateRegionMapVideoRegs();
|
|
|
|
if (gRegionMap->playerIconSprite != NULL)
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->pos2.x = -x;
|
|
|
|
gRegionMap->playerIconSprite->pos2.y = -y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static u16 GetRegionMapSectionIdAt_Internal(u16 x, u16 y)
|
2017-10-30 13:58:43 +01:00
|
|
|
{
|
|
|
|
if (y < MAPCURSOR_Y_MIN || y > MAPCURSOR_Y_MAX || x < MAPCURSOR_X_MIN || x > MAPCURSOR_X_MAX)
|
|
|
|
{
|
2017-10-31 03:35:28 +01:00
|
|
|
return MAPSEC_NONE;
|
2017-10-30 13:58:43 +01:00
|
|
|
}
|
|
|
|
y -= MAPCURSOR_Y_MIN;
|
|
|
|
x -= MAPCURSOR_X_MIN;
|
|
|
|
return gUnknown_085A096C[x + y * MAP_WIDTH];
|
|
|
|
}
|
2017-10-31 02:08:28 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void RegionMap_InitializeStateBasedOnPlayerLocation(void)
|
2017-10-31 02:08:28 +01:00
|
|
|
{
|
|
|
|
const struct MapHeader *mapHeader;
|
|
|
|
u16 mapWidth;
|
|
|
|
u16 mapHeight;
|
|
|
|
u16 x;
|
|
|
|
u16 y;
|
|
|
|
u16 r1;
|
|
|
|
u16 r9;
|
|
|
|
struct WarpData *r4;
|
|
|
|
|
|
|
|
if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP_SS_TIDAL_CORRIDOR
|
|
|
|
&& (gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_CORRIDOR
|
|
|
|
|| gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_LOWER_DECK
|
|
|
|
|| gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_ROOMS))
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_InitializeStateBasedOnSSTidalLocation();
|
2017-10-31 02:08:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (get_map_light_level_by_bank_and_number(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum))
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
gRegionMap->mapSecId = gMapHeader.regionMapSectionId;
|
|
|
|
gRegionMap->playerIsInCave = FALSE;
|
|
|
|
mapWidth = gMapHeader.mapData->width;
|
|
|
|
mapHeight = gMapHeader.mapData->height;
|
|
|
|
x = gSaveBlock1Ptr->pos.x;
|
|
|
|
y = gSaveBlock1Ptr->pos.y;
|
|
|
|
if (gRegionMap->mapSecId == MAPSEC_UNDERWATER || gRegionMap->mapSecId == MAPSEC_UNDERWATER_MARINE_CAVE)
|
|
|
|
{
|
|
|
|
gRegionMap->playerIsInCave = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 7:
|
|
|
|
if (gMapHeader.flags & 0x02)
|
|
|
|
{
|
|
|
|
mapHeader = get_mapheader_by_bank_and_number(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum);
|
|
|
|
gRegionMap->mapSecId = mapHeader->regionMapSectionId;
|
|
|
|
gRegionMap->playerIsInCave = TRUE;
|
|
|
|
mapWidth = mapHeader->mapData->width;
|
|
|
|
mapHeight = mapHeader->mapData->height;
|
|
|
|
x = gSaveBlock1Ptr->warp4.x;
|
|
|
|
y = gSaveBlock1Ptr->warp4.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->mapSecId = gMapHeader.regionMapSectionId;
|
|
|
|
gRegionMap->playerIsInCave = TRUE;
|
|
|
|
mapWidth = 1;
|
|
|
|
mapHeight = 1;
|
|
|
|
x = 1;
|
|
|
|
y = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
mapHeader = get_mapheader_by_bank_and_number((u16)gSaveBlock1Ptr->warp2.mapGroup, (u16)gSaveBlock1Ptr->warp2.mapNum);
|
|
|
|
gRegionMap->mapSecId = mapHeader->regionMapSectionId;
|
|
|
|
gRegionMap->playerIsInCave = TRUE;
|
|
|
|
mapWidth = mapHeader->mapData->width;
|
|
|
|
mapHeight = mapHeader->mapData->height;
|
|
|
|
x = gSaveBlock1Ptr->warp2.x;
|
|
|
|
y = gSaveBlock1Ptr->warp2.y;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
|
|
|
|
gRegionMap->mapSecId = gMapHeader.regionMapSectionId;
|
2017-10-31 03:35:28 +01:00
|
|
|
if (gRegionMap->mapSecId != MAPSEC_UNK_0x57)
|
2017-10-31 02:08:28 +01:00
|
|
|
{
|
|
|
|
r4 = &gSaveBlock1Ptr->warp4;
|
|
|
|
mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r4 = &gSaveBlock1Ptr->warp2;
|
|
|
|
mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum);
|
|
|
|
gRegionMap->mapSecId = mapHeader->regionMapSectionId;
|
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
if (RegionMap_IsPlayerInCave(gRegionMap->mapSecId))
|
2017-10-31 02:08:28 +01:00
|
|
|
{
|
|
|
|
gRegionMap->playerIsInCave = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->playerIsInCave = FALSE;
|
|
|
|
}
|
|
|
|
mapWidth = mapHeader->mapData->width;
|
|
|
|
mapHeight = mapHeader->mapData->height;
|
|
|
|
x = r4->x;
|
|
|
|
y = r4->y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
r9 = x;
|
|
|
|
|
|
|
|
r1 = mapWidth / gRegionMapEntries[gRegionMap->mapSecId].width;
|
|
|
|
if (r1 == 0)
|
|
|
|
{
|
|
|
|
r1 = 1;
|
|
|
|
}
|
|
|
|
x /= r1;
|
|
|
|
if (x >= gRegionMapEntries[gRegionMap->mapSecId].width)
|
|
|
|
{
|
|
|
|
x = gRegionMapEntries[gRegionMap->mapSecId].width - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r1 = mapHeight / gRegionMapEntries[gRegionMap->mapSecId].height;
|
|
|
|
if (r1 == 0)
|
|
|
|
{
|
|
|
|
r1 = 1;
|
|
|
|
}
|
|
|
|
y /= r1;
|
|
|
|
if (y >= gRegionMapEntries[gRegionMap->mapSecId].height)
|
|
|
|
{
|
|
|
|
y = gRegionMapEntries[gRegionMap->mapSecId].height - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (gRegionMap->mapSecId)
|
|
|
|
{
|
|
|
|
case MAPSEC_ROUTE_114:
|
|
|
|
if (y != 0)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MAPSEC_ROUTE_126:
|
|
|
|
case MAPSEC_UNDERWATER_125:
|
|
|
|
x = 0;
|
|
|
|
if (gSaveBlock1Ptr->pos.x > 32)
|
|
|
|
{
|
|
|
|
x = 1;
|
|
|
|
}
|
|
|
|
if (gSaveBlock1Ptr->pos.x > 0x33)
|
|
|
|
{
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
y = 0;
|
|
|
|
if (gSaveBlock1Ptr->pos.y > 0x25)
|
|
|
|
{
|
|
|
|
y = 1;
|
|
|
|
}
|
|
|
|
if (gSaveBlock1Ptr->pos.y > 0x38)
|
|
|
|
{
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MAPSEC_ROUTE_121:
|
|
|
|
x = 0;
|
|
|
|
if (r9 > 14)
|
|
|
|
{
|
|
|
|
x = 1;
|
|
|
|
}
|
|
|
|
if (r9 > 0x1C)
|
|
|
|
{
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
if (r9 > 0x36)
|
|
|
|
{
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MAPSEC_UNDERWATER_MARINE_CAVE:
|
2017-11-01 01:58:47 +01:00
|
|
|
RegionMap_GetMarineCaveCoords(&gRegionMap->cursorPosX, &gRegionMap->cursorPosY);
|
2017-10-31 02:08:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gRegionMap->cursorPosX = gRegionMapEntries[gRegionMap->mapSecId].x + x + MAPCURSOR_X_MIN;
|
|
|
|
gRegionMap->cursorPosY = gRegionMapEntries[gRegionMap->mapSecId].y + y + MAPCURSOR_Y_MIN;
|
|
|
|
}
|
2017-10-31 02:14:52 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void RegionMap_InitializeStateBasedOnSSTidalLocation(void)
|
2017-10-31 02:14:52 +01:00
|
|
|
{
|
|
|
|
u16 y;
|
|
|
|
u16 x;
|
|
|
|
u8 mapGroup;
|
|
|
|
u8 mapNum;
|
|
|
|
u16 r1;
|
|
|
|
s16 sp2;
|
|
|
|
s16 sp4;
|
|
|
|
const struct MapHeader *mapHeader;
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
x = 0;
|
|
|
|
switch (GetSSTidalLocation(&mapGroup, &mapNum, &sp2, &sp4))
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
gRegionMap->mapSecId = MAPSEC_SLATEPORT_CITY;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
gRegionMap->mapSecId = MAPSEC_LILYCOVE_CITY;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
gRegionMap->mapSecId = MAPSEC_ROUTE_124;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
gRegionMap->mapSecId = MAPSEC_ROUTE_131;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum);
|
|
|
|
|
|
|
|
gRegionMap->mapSecId = mapHeader->regionMapSectionId;
|
|
|
|
r1 = mapHeader->mapData->width / gRegionMapEntries[gRegionMap->mapSecId].width;
|
|
|
|
if (r1 == 0)
|
|
|
|
r1 = 1;
|
|
|
|
x = sp2 / r1;
|
|
|
|
if (x >= gRegionMapEntries[gRegionMap->mapSecId].width)
|
|
|
|
x = gRegionMapEntries[gRegionMap->mapSecId].width - 1;
|
|
|
|
|
|
|
|
r1 = mapHeader->mapData->height / gRegionMapEntries[gRegionMap->mapSecId].height;
|
|
|
|
if (r1 == 0)
|
|
|
|
r1 = 1;
|
|
|
|
y = sp4 / r1;
|
|
|
|
if (y >= gRegionMapEntries[gRegionMap->mapSecId].height)
|
|
|
|
y = gRegionMapEntries[gRegionMap->mapSecId].height - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gRegionMap->playerIsInCave = FALSE;
|
|
|
|
gRegionMap->cursorPosX = gRegionMapEntries[gRegionMap->mapSecId].x + x + MAPCURSOR_X_MIN;
|
|
|
|
gRegionMap->cursorPosY = gRegionMapEntries[gRegionMap->mapSecId].y + y + MAPCURSOR_Y_MIN;
|
|
|
|
}
|
2017-10-31 02:20:31 +01:00
|
|
|
|
|
|
|
static u8 get_flagnr_blue_points(u16 mapSecId)
|
|
|
|
{
|
|
|
|
switch (mapSecId)
|
|
|
|
{
|
2017-10-31 03:35:28 +01:00
|
|
|
case MAPSEC_NONE:
|
2017-10-31 02:34:19 +01:00
|
|
|
return MAPSECTYPE_NONE;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_LITTLEROOT_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_LITTLEROOT_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_OLDALE_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_OLDALE_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_DEWFORD_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_DEWFORD_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_LAVARIDGE_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_LAVARIDGE_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_FALLARBOR_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_FALLARBOR_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_VERDANTURF_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_VERDANTURF_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_PACIFIDLOG_TOWN:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_PACIFIDLOG_TOWN) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_PETALBURG_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_PETALBURG_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_SLATEPORT_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_SLATEPORT_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_MAUVILLE_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_MAUVILLE_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_RUSTBORO_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_RUSTBORO_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_FORTREE_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_FORTREE_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_LILYCOVE_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_LILYCOVE_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_MOSSDEEP_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_MOSSDEEP_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_SOOTOPOLIS_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_SOOTOPOLIS_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_EVER_GRANDE_CITY:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_VISITED_EVER_GRANDE_CITY) ? MAPSECTYPE_CITY_CANFLY : MAPSECTYPE_CITY_CANTFLY;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_BATTLE_FRONTIER:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_UNLOCK_BATTLE_FRONTIER) ? MAPSECTYPE_BATTLE_FRONTIER : MAPSECTYPE_NONE;
|
2017-10-31 02:20:31 +01:00
|
|
|
case MAPSEC_SOUTHERN_ISLAND:
|
2017-10-31 02:34:19 +01:00
|
|
|
return FlagGet(FLAG_UNLOCK_SOUTHERN_ISLAND) ? MAPSECTYPE_PLAIN : MAPSECTYPE_NONE;
|
2017-10-31 02:20:31 +01:00
|
|
|
default:
|
2017-10-31 02:34:19 +01:00
|
|
|
return MAPSECTYPE_PLAIN;
|
2017-10-31 02:20:31 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 02:34:19 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
u16 GetRegionMapSectionIdAt(u16 x, u16 y)
|
2017-10-31 02:34:19 +01:00
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
return GetRegionMapSectionIdAt_Internal(x, y);
|
2017-10-31 02:34:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static u16 CorrectSpecialMapSecId_Internal(u16 mapSecId)
|
2017-10-31 02:34:19 +01:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i ++)
|
|
|
|
{
|
|
|
|
if (gUnknown_085A1B84[i] == mapSecId)
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
return RegionMap_GetTerraCaveMapSecId();
|
2017-10-31 02:34:19 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 03:35:28 +01:00
|
|
|
for (i = 0; gUnknown_085A1B24[i][0] != MAPSEC_NONE; i ++)
|
2017-10-31 02:34:19 +01:00
|
|
|
{
|
|
|
|
if (gUnknown_085A1B24[i][0] == mapSecId)
|
|
|
|
{
|
|
|
|
return gUnknown_085A1B24[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mapSecId;
|
|
|
|
}
|
2017-10-31 02:47:37 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static u16 RegionMap_GetTerraCaveMapSecId(void)
|
2017-10-31 02:47:37 +01:00
|
|
|
{
|
|
|
|
s16 idx;
|
|
|
|
|
|
|
|
idx = VarGet(VAR_0x4037) - 1;
|
|
|
|
if (idx < 0 || idx > 15)
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
}
|
|
|
|
return gUnknown_085A1B8A[idx];
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void RegionMap_GetMarineCaveCoords(u16 *x, u16 *y)
|
2017-10-31 02:47:37 +01:00
|
|
|
{
|
|
|
|
u16 idx;
|
|
|
|
|
|
|
|
idx = VarGet(VAR_0x4037);
|
|
|
|
if (idx < 9 || idx > 16)
|
|
|
|
{
|
|
|
|
idx = 9;
|
|
|
|
}
|
|
|
|
idx -= 9;
|
|
|
|
*x = gUnknown_085A1BAC[idx].x + MAPCURSOR_X_MIN;
|
|
|
|
*y = gUnknown_085A1BAC[idx].y + MAPCURSOR_Y_MIN;
|
|
|
|
}
|
2017-10-31 03:20:09 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static bool32 RegionMap_IsPlayerInCave(u8 mapSecId)
|
2017-10-31 03:20:09 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i == 0; i ++)
|
|
|
|
{
|
|
|
|
if (gUnknown_085A1BCC[i] == mapSecId)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
u16 CorrectSpecialMapSecId(u16 mapSecId)
|
2017-10-31 03:20:09 +01:00
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
return CorrectSpecialMapSecId_Internal(mapSecId);
|
2017-10-31 03:20:09 +01:00
|
|
|
}
|
2017-10-31 03:35:28 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void RegionMap_GetPositionOfCursorWithinMapSection(void)
|
2017-10-31 03:35:28 +01:00
|
|
|
{
|
|
|
|
u16 x;
|
|
|
|
u16 y;
|
2017-11-01 01:58:47 +01:00
|
|
|
u16 posWithinMapSec;
|
2017-10-31 03:35:28 +01:00
|
|
|
|
|
|
|
if (gRegionMap->mapSecId == MAPSEC_NONE)
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
gRegionMap->posWithinMapSec = 0;
|
2017-10-31 03:35:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!gRegionMap->zoomed)
|
|
|
|
{
|
|
|
|
x = gRegionMap->cursorPosX;
|
|
|
|
y = gRegionMap->cursorPosY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = gRegionMap->zoomedCursorPosX;
|
|
|
|
y = gRegionMap->zoomedCursorPosY;
|
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
posWithinMapSec = 0;
|
2017-10-31 03:35:28 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (x <= MAPCURSOR_X_MIN)
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
if (RegionMap_IsMapSecIdInNextRow(y))
|
2017-10-31 03:35:28 +01:00
|
|
|
{
|
|
|
|
y --;
|
|
|
|
x = MAPCURSOR_X_MAX + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x --;
|
2017-11-01 01:58:47 +01:00
|
|
|
if (GetRegionMapSectionIdAt_Internal(x, y) == gRegionMap->mapSecId)
|
2017-10-31 03:35:28 +01:00
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
posWithinMapSec ++;
|
2017-10-31 03:35:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
gRegionMap->posWithinMapSec = posWithinMapSec;
|
2017-10-31 03:35:28 +01:00
|
|
|
}
|
2017-10-31 13:38:17 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static bool8 RegionMap_IsMapSecIdInNextRow(u16 y)
|
2017-10-31 13:38:17 +01:00
|
|
|
{
|
|
|
|
u16 x;
|
|
|
|
|
|
|
|
if (y -- == 0)
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
return FALSE;
|
2017-10-31 13:38:17 +01:00
|
|
|
}
|
|
|
|
for (x = MAPCURSOR_X_MIN; x <= MAPCURSOR_X_MAX; x ++)
|
|
|
|
{
|
2017-11-01 01:58:47 +01:00
|
|
|
if (GetRegionMapSectionIdAt_Internal(x, y) == gRegionMap->mapSecId)
|
2017-10-31 13:38:17 +01:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void SpriteCallback_CursorFull(struct Sprite *sprite)
|
2017-10-31 13:38:17 +01:00
|
|
|
{
|
|
|
|
if (gRegionMap->cursorMovementFrameCounter != 0)
|
|
|
|
{
|
|
|
|
sprite->pos1.x += 2 * gRegionMap->cursorDeltaX;
|
|
|
|
sprite->pos1.y += 2 * gRegionMap->cursorDeltaY;
|
|
|
|
gRegionMap->cursorMovementFrameCounter --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void SpriteCallback_CursorZoomed(struct Sprite *sprite)
|
2017-10-31 13:38:17 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateRegionMapCursor(u16 tileTag, u16 paletteTag)
|
|
|
|
{
|
|
|
|
u8 spriteId;
|
|
|
|
struct SpriteTemplate template;
|
|
|
|
struct SpritePalette palette;
|
|
|
|
struct SpriteSheet sheet;
|
|
|
|
|
|
|
|
palette = gUnknown_085A1C00;
|
|
|
|
template = gUnknown_085A1C08;
|
|
|
|
sheet.tag = tileTag;
|
|
|
|
template.tileTag = tileTag;
|
|
|
|
gRegionMap->cursorTileTag = tileTag;
|
|
|
|
palette.tag = paletteTag;
|
|
|
|
template.paletteTag = paletteTag;
|
|
|
|
gRegionMap->cursorPaletteTag = paletteTag;
|
|
|
|
if (!gRegionMap->zoomed)
|
|
|
|
{
|
|
|
|
sheet.data = gRegionMap->cursorSmallImage;
|
|
|
|
sheet.size = sizeof(gRegionMap->cursorSmallImage);
|
2017-11-01 01:58:47 +01:00
|
|
|
template.callback = SpriteCallback_CursorFull;
|
2017-10-31 13:38:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sheet.data = gRegionMap->cursorLargeImage;
|
|
|
|
sheet.size = sizeof(gRegionMap->cursorLargeImage);
|
2017-11-01 01:58:47 +01:00
|
|
|
template.callback = SpriteCallback_CursorZoomed;
|
2017-10-31 13:38:17 +01:00
|
|
|
}
|
|
|
|
LoadSpriteSheet(&sheet);
|
|
|
|
LoadSpritePalette(&palette);
|
|
|
|
spriteId = CreateSprite(&template, 0x38, 0x48, 0);
|
|
|
|
if (spriteId != MAX_SPRITES)
|
|
|
|
{
|
|
|
|
gRegionMap->cursorSprite = &gSprites[spriteId];
|
|
|
|
if (gRegionMap->zoomed == TRUE)
|
|
|
|
{
|
|
|
|
gRegionMap->cursorSprite->oam.size = 2;
|
|
|
|
gRegionMap->cursorSprite->pos1.x -= 8;
|
|
|
|
gRegionMap->cursorSprite->pos1.y -= 8;
|
|
|
|
StartSpriteAnim(gRegionMap->cursorSprite, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->cursorSprite->oam.size = 1;
|
|
|
|
gRegionMap->cursorSprite->pos1.x = 8 * gRegionMap->cursorPosX + 4;
|
|
|
|
gRegionMap->cursorSprite->pos1.y = 8 * gRegionMap->cursorPosY + 4;
|
|
|
|
}
|
|
|
|
gRegionMap->cursorSprite->data1 = 2;
|
|
|
|
gRegionMap->cursorSprite->data2 = (IndexOfSpritePaletteTag(paletteTag) << 4) + 0x101;
|
2017-10-31 13:44:03 +01:00
|
|
|
gRegionMap->cursorSprite->data3 = TRUE;
|
2017-10-31 13:38:17 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 13:44:03 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
static void FreeRegionMapCursorSprite(void)
|
2017-10-31 13:44:03 +01:00
|
|
|
{
|
|
|
|
if (gRegionMap->cursorSprite != NULL)
|
|
|
|
{
|
|
|
|
DestroySprite(gRegionMap->cursorSprite);
|
|
|
|
FreeSpriteTilesByTag(gRegionMap->cursorTileTag);
|
|
|
|
FreeSpritePaletteByTag(gRegionMap->cursorPaletteTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8124268(void)
|
|
|
|
{
|
|
|
|
gRegionMap->cursorSprite->data3 = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_8124278(void)
|
|
|
|
{
|
|
|
|
gRegionMap->cursorSprite->data3 = FALSE;
|
|
|
|
}
|
2017-11-01 00:40:35 +01:00
|
|
|
|
2017-11-01 01:58:47 +01:00
|
|
|
void CreateRegionMapPlayerIcon(u16 tileTag, u16 paletteTag)
|
2017-11-01 00:40:35 +01:00
|
|
|
{
|
|
|
|
u8 spriteId;
|
|
|
|
struct SpriteSheet sheet = {gUnknown_085A084C, 0x80, tileTag};
|
|
|
|
struct SpritePalette palette = {gUnknown_085A082C, paletteTag};
|
|
|
|
struct SpriteTemplate template = {tileTag, paletteTag, &gUnknown_085A1C20, gUnknown_085A1C30, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy};
|
|
|
|
|
|
|
|
if (sub_8124668(gMapHeader.regionMapSectionId))
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (gSaveBlock2Ptr->playerGender == FEMALE)
|
|
|
|
{
|
|
|
|
sheet.data = gUnknown_085A08EC;
|
|
|
|
palette.data = gUnknown_085A08CC;
|
|
|
|
}
|
|
|
|
LoadSpriteSheet(&sheet);
|
|
|
|
LoadSpritePalette(&palette);
|
|
|
|
spriteId = CreateSprite(&template, 0, 0, 1);
|
|
|
|
gRegionMap->playerIconSprite = &gSprites[spriteId];
|
|
|
|
if (!gRegionMap->zoomed)
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->pos1.x = gRegionMap->playerIconSpritePosX * 8 + 4;
|
|
|
|
gRegionMap->playerIconSprite->pos1.y = gRegionMap->playerIconSpritePosY * 8 + 4;
|
2017-11-01 02:32:25 +01:00
|
|
|
gRegionMap->playerIconSprite->callback = RegionMapPlayerIconSpriteCallback_Full;
|
2017-11-01 00:40:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->pos1.x = gRegionMap->playerIconSpritePosX * 16 - 0x30;
|
|
|
|
gRegionMap->playerIconSprite->pos1.y = gRegionMap->playerIconSpritePosY * 16 - 0x42;
|
2017-11-01 02:32:25 +01:00
|
|
|
gRegionMap->playerIconSprite->callback = RegionMapPlayerIconSpriteCallback_Zoomed;
|
2017-11-01 00:40:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-01 01:58:47 +01:00
|
|
|
|
|
|
|
static void HideRegionMapPlayerIcon(void)
|
|
|
|
{
|
|
|
|
if (gRegionMap->playerIconSprite != NULL)
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->invisible = TRUE;
|
|
|
|
gRegionMap->playerIconSprite->callback = SpriteCallbackDummy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnhideRegionMapPlayerIcon(void)
|
|
|
|
{
|
|
|
|
if (gRegionMap->playerIconSprite != NULL)
|
|
|
|
{
|
|
|
|
if (gRegionMap->zoomed == TRUE)
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->pos1.x = gRegionMap->playerIconSpritePosX * 16 - 0x30;
|
|
|
|
gRegionMap->playerIconSprite->pos1.y = gRegionMap->playerIconSpritePosY * 16 - 0x42;
|
2017-11-01 02:32:25 +01:00
|
|
|
gRegionMap->playerIconSprite->callback = RegionMapPlayerIconSpriteCallback_Zoomed;
|
2017-11-01 01:58:47 +01:00
|
|
|
gRegionMap->playerIconSprite->invisible = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gRegionMap->playerIconSprite->pos1.x = gRegionMap->playerIconSpritePosX * 8 + 4;
|
|
|
|
gRegionMap->playerIconSprite->pos1.y = gRegionMap->playerIconSpritePosY * 8 + 4;
|
|
|
|
gRegionMap->playerIconSprite->pos2.x = 0;
|
|
|
|
gRegionMap->playerIconSprite->pos2.y = 0;
|
2017-11-01 02:32:25 +01:00
|
|
|
gRegionMap->playerIconSprite->callback = RegionMapPlayerIconSpriteCallback_Full;
|
2017-11-01 01:58:47 +01:00
|
|
|
gRegionMap->playerIconSprite->invisible = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 02:32:25 +01:00
|
|
|
|
|
|
|
static void RegionMapPlayerIconSpriteCallback_Zoomed(struct Sprite *sprite)
|
|
|
|
{
|
|
|
|
sprite->pos2.x = -2 * gRegionMap->scrollX;
|
|
|
|
sprite->pos2.y = -2 * gRegionMap->scrollY;
|
|
|
|
sprite->data0 = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY;
|
|
|
|
sprite->data1 = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX;
|
|
|
|
if (sprite->data0 < -8 || sprite->data0 > 0xa8 || sprite->data1 < -8 || sprite->data1 > 0xf8)
|
|
|
|
{
|
|
|
|
sprite->data2 = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite->data2 = TRUE;
|
|
|
|
}
|
|
|
|
if (sprite->data2 == TRUE)
|
|
|
|
{
|
|
|
|
RegionMapPlayerIconSpriteCallback(sprite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite->invisible = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RegionMapPlayerIconSpriteCallback_Full(struct Sprite *sprite)
|
|
|
|
{
|
|
|
|
RegionMapPlayerIconSpriteCallback(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RegionMapPlayerIconSpriteCallback(struct Sprite *sprite)
|
|
|
|
{
|
|
|
|
if (gRegionMap->blinkPlayerIcon)
|
|
|
|
{
|
|
|
|
if (++ sprite->data7 > 16)
|
|
|
|
{
|
|
|
|
sprite->data7 = 0;
|
|
|
|
sprite->invisible = sprite->invisible ? FALSE : TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite->invisible = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 02:51:11 +01:00
|
|
|
|
|
|
|
void sub_812454C(void)
|
|
|
|
{
|
|
|
|
if (gRegionMap->playerIsInCave)
|
|
|
|
{
|
|
|
|
gRegionMap->blinkPlayerIcon = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *GetMapName(u8 *dest, u16 regionMapId, u16 padLength)
|
|
|
|
{
|
|
|
|
u8 *str;
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
if (regionMapId == MAPSEC_SECRET_BASE)
|
|
|
|
{
|
|
|
|
str = GetSecretBaseMapName(dest);
|
|
|
|
}
|
|
|
|
else if (regionMapId < MAPSEC_NONE)
|
|
|
|
{
|
|
|
|
str = StringCopy(dest, gRegionMapEntries[regionMapId].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (padLength == 0)
|
|
|
|
{
|
|
|
|
padLength = 18;
|
|
|
|
}
|
|
|
|
return StringFill(dest, CHAR_SPACE, padLength);
|
|
|
|
}
|
|
|
|
if (padLength != 0)
|
|
|
|
{
|
|
|
|
for (i = str - dest; i < padLength; i ++)
|
|
|
|
{
|
|
|
|
*str++ = CHAR_SPACE;
|
|
|
|
}
|
|
|
|
*str = EOS;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|