pokeemerald/src/save_location.c

140 lines
4.1 KiB
C
Raw Normal View History

2017-10-09 04:21:34 +02:00
#include "global.h"
#include "save_location.h"
2017-10-09 04:21:34 +02:00
2021-10-17 23:38:52 +02:00
#define LIST_END 0xFFFF
2017-10-09 04:21:34 +02:00
static bool32 IsCurMapInLocationList(const u16 *list)
{
2018-11-18 19:37:18 +01:00
s32 i;
2021-10-17 23:38:52 +02:00
u16 map = (gSaveBlock1Ptr->location.mapGroup << 8) + gSaveBlock1Ptr->location.mapNum;
2017-10-09 04:21:34 +02:00
2021-10-17 23:38:52 +02:00
for (i = 0; list[i] != LIST_END; i++)
2017-10-09 04:21:34 +02:00
{
2021-10-17 23:38:52 +02:00
if (list[i] == map)
2018-11-18 19:37:18 +01:00
return TRUE;
2017-10-09 04:21:34 +02:00
}
2018-11-18 19:37:18 +01:00
2017-10-09 04:21:34 +02:00
return FALSE;
}
static const u16 sSaveLocationPokeCenterList[] =
2017-10-09 04:21:34 +02:00
{
2017-12-05 18:55:48 +01:00
MAP_OLDALE_TOWN_POKEMON_CENTER_1F,
MAP_OLDALE_TOWN_POKEMON_CENTER_2F,
MAP_DEWFORD_TOWN_POKEMON_CENTER_1F,
MAP_DEWFORD_TOWN_POKEMON_CENTER_2F,
MAP_LAVARIDGE_TOWN_POKEMON_CENTER_1F,
MAP_LAVARIDGE_TOWN_POKEMON_CENTER_2F,
MAP_FALLARBOR_TOWN_POKEMON_CENTER_1F,
MAP_FALLARBOR_TOWN_POKEMON_CENTER_2F,
MAP_VERDANTURF_TOWN_POKEMON_CENTER_1F,
MAP_VERDANTURF_TOWN_POKEMON_CENTER_2F,
MAP_PACIFIDLOG_TOWN_POKEMON_CENTER_1F,
MAP_PACIFIDLOG_TOWN_POKEMON_CENTER_2F,
MAP_PETALBURG_CITY_POKEMON_CENTER_1F,
MAP_PETALBURG_CITY_POKEMON_CENTER_2F,
MAP_SLATEPORT_CITY_POKEMON_CENTER_1F,
MAP_SLATEPORT_CITY_POKEMON_CENTER_2F,
MAP_MAUVILLE_CITY_POKEMON_CENTER_1F,
MAP_MAUVILLE_CITY_POKEMON_CENTER_2F,
MAP_RUSTBORO_CITY_POKEMON_CENTER_1F,
MAP_RUSTBORO_CITY_POKEMON_CENTER_2F,
MAP_FORTREE_CITY_POKEMON_CENTER_1F,
MAP_FORTREE_CITY_POKEMON_CENTER_2F,
MAP_LILYCOVE_CITY_POKEMON_CENTER_1F,
MAP_LILYCOVE_CITY_POKEMON_CENTER_2F,
MAP_MOSSDEEP_CITY_POKEMON_CENTER_1F,
MAP_MOSSDEEP_CITY_POKEMON_CENTER_2F,
MAP_SOOTOPOLIS_CITY_POKEMON_CENTER_1F,
MAP_SOOTOPOLIS_CITY_POKEMON_CENTER_2F,
MAP_EVER_GRANDE_CITY_POKEMON_CENTER_1F,
MAP_EVER_GRANDE_CITY_POKEMON_CENTER_2F,
MAP_EVER_GRANDE_CITY_POKEMON_LEAGUE_1F,
MAP_EVER_GRANDE_CITY_POKEMON_LEAGUE_2F,
MAP_BATTLE_FRONTIER_POKEMON_CENTER_1F,
MAP_BATTLE_FRONTIER_POKEMON_CENTER_2F,
2019-11-07 18:37:11 +01:00
MAP_BATTLE_COLOSSEUM_2P,
2017-12-05 18:55:48 +01:00
MAP_TRADE_CENTER,
MAP_RECORD_CORNER,
2019-11-07 18:37:11 +01:00
MAP_BATTLE_COLOSSEUM_4P,
2021-10-17 23:38:52 +02:00
LIST_END,
2017-10-09 04:21:34 +02:00
};
static bool32 IsCurMapPokeCenter(void)
{
return IsCurMapInLocationList(sSaveLocationPokeCenterList);
2017-10-09 04:21:34 +02:00
}
2018-11-18 19:37:18 +01:00
static const u16 sSaveLocationReloadLocList[] = // There's only 1 location, and it's presumed its for the save reload feature for battle tower.
2017-10-09 04:21:34 +02:00
{
2017-12-05 18:55:48 +01:00
MAP_BATTLE_FRONTIER_BATTLE_TOWER_LOBBY,
2021-10-17 23:38:52 +02:00
LIST_END,
2017-10-09 04:21:34 +02:00
};
static bool32 IsCurMapReloadLocation(void)
{
return IsCurMapInLocationList(sSaveLocationReloadLocList);
2017-10-09 04:21:34 +02:00
}
2018-11-18 19:37:18 +01:00
// Nulled out list. Unknown what this would have been.
2021-10-17 23:38:52 +02:00
static const u16 sEmptyMapList[] =
2017-10-09 04:21:34 +02:00
{
2021-10-17 23:38:52 +02:00
LIST_END,
2017-10-09 04:21:34 +02:00
};
2021-10-17 23:38:52 +02:00
static bool32 IsCurMapInEmptyList(void)
2017-10-09 04:21:34 +02:00
{
2021-10-17 23:38:52 +02:00
return IsCurMapInLocationList(sEmptyMapList);
2017-10-09 04:21:34 +02:00
}
static void TrySetPokeCenterWarpStatus(void)
{
2021-10-17 23:38:52 +02:00
if (!IsCurMapPokeCenter())
gSaveBlock2Ptr->specialSaveWarpFlags &= ~POKECENTER_SAVEWARP;
2017-10-09 04:21:34 +02:00
else
2018-12-27 23:30:47 +01:00
gSaveBlock2Ptr->specialSaveWarpFlags |= POKECENTER_SAVEWARP;
2017-10-09 04:21:34 +02:00
}
static void TrySetReloadWarpStatus(void)
{
if (!IsCurMapReloadLocation())
2021-10-17 23:38:52 +02:00
gSaveBlock2Ptr->specialSaveWarpFlags &= ~LOBBY_SAVEWARP;
2017-10-09 04:21:34 +02:00
else
2018-12-27 23:30:47 +01:00
gSaveBlock2Ptr->specialSaveWarpFlags |= LOBBY_SAVEWARP;
2017-10-09 04:21:34 +02:00
}
2021-10-17 23:38:52 +02:00
// Unknown save warp flag. Never set because map list is empty.
static void TrySetUnknownWarpStatus(void)
2017-10-09 04:21:34 +02:00
{
2021-10-17 23:38:52 +02:00
if (!IsCurMapInEmptyList())
gSaveBlock2Ptr->specialSaveWarpFlags &= ~UNK_SPECIAL_SAVE_WARP_FLAG_3;
2017-10-09 04:21:34 +02:00
else
2018-12-27 23:30:47 +01:00
gSaveBlock2Ptr->specialSaveWarpFlags |= UNK_SPECIAL_SAVE_WARP_FLAG_3;
2017-10-09 04:21:34 +02:00
}
void TrySetMapSaveWarpStatus(void)
{
TrySetPokeCenterWarpStatus();
TrySetReloadWarpStatus();
2021-10-17 23:38:52 +02:00
TrySetUnknownWarpStatus();
2017-10-09 04:21:34 +02:00
}
2021-10-17 23:38:52 +02:00
// In FRLG, only bits 0, 4, and 5 are set when the pokedex is received.
// Bits 1, 2, 3, and 15 are instead set by SetPostgameFlags.
2020-04-13 14:42:31 +02:00
// These flags are read by Pokemon Colosseum/XD for linking. XD Additionally requires FLAG_SYS_GAME_CLEAR
void SetUnlockedPokedexFlags(void)
2017-10-09 04:21:34 +02:00
{
2021-10-17 23:38:52 +02:00
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 15);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 0);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 1);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 2);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 4);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 5);
gSaveBlock2Ptr->gcnLinkFlags |= (1 << 3);
2017-10-09 04:21:34 +02:00
}
2019-11-08 09:07:19 +01:00
void SetChampionSaveWarp(void)
2017-10-09 04:21:34 +02:00
{
2019-11-07 19:26:53 +01:00
gSaveBlock2Ptr->specialSaveWarpFlags |= CHAMPION_SAVEWARP;
2017-10-09 04:21:34 +02:00
}