summaryrefslogtreecommitdiff
path: root/src/overworld.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/overworld.c')
-rw-r--r--src/overworld.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/overworld.c b/src/overworld.c
index 518771875..f6c4c0f3d 100644
--- a/src/overworld.c
+++ b/src/overworld.c
@@ -62,7 +62,6 @@
#include "constants/abilities.h"
#include "constants/layouts.h"
#include "constants/map_types.h"
-#include "constants/maps.h"
#include "constants/region_map_sections.h"
#include "constants/songs.h"
#include "constants/trainer_hill.h"
@@ -175,7 +174,6 @@ static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *, u
static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *, u8, u16, u8);
static u16 GetCenterScreenMetatileBehavior(void);
-// IWRAM bss vars
static void *sUnusedOverworldCallback;
static u8 sPlayerLinkStates[MAX_LINK_PLAYERS];
// This callback is called with a player's key code. It then returns an
@@ -185,7 +183,6 @@ static u16 (*sPlayerKeyInterceptCallback)(u32);
static bool8 sReceivingFromLink;
static u8 sRfuKeepAliveTimer;
-// IWRAM common
u16 *gBGTilemapBuffers1;
u16 *gBGTilemapBuffers2;
u16 *gBGTilemapBuffers3;
@@ -195,7 +192,6 @@ bool8 (*gFieldCallback2)(void);
u8 gLocalLinkPlayerId; // This is our player id in a multiplayer mode.
u8 gFieldLinkPlayerCount;
-// EWRAM vars
EWRAM_DATA static u8 sObjectEventLoadFlag = 0;
EWRAM_DATA struct WarpData gLastUsedWarp = {0};
EWRAM_DATA static struct WarpData sWarpDestination = {0}; // new warp position
@@ -207,12 +203,11 @@ EWRAM_DATA static u16 sAmbientCrySpecies = 0;
EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE;
EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0};
-// const rom data
static const struct WarpData sDummyWarpData =
{
- .mapGroup = -1,
- .mapNum = -1,
- .warpId = -1,
+ .mapGroup = MAP_GROUP(UNDEFINED),
+ .mapNum = MAP_NUM(UNDEFINED),
+ .warpId = WARP_ID_NONE,
.x = -1,
.y = -1,
};
@@ -495,7 +490,7 @@ void LoadSaveblockObjEventScripts(void)
savObjTemplates[i].script = mapHeaderObjTemplates[i].script;
}
-void Overworld_SetObjEventTemplateCoords(u8 localId, s16 x, s16 y)
+void SetObjEventTemplateCoords(u8 localId, s16 x, s16 y)
{
s32 i;
struct ObjectEventTemplate *savObjTemplates = gSaveBlock1Ptr->objectEventTemplates;
@@ -512,7 +507,7 @@ void Overworld_SetObjEventTemplateCoords(u8 localId, s16 x, s16 y)
}
}
-void Overworld_SetObjEventTemplateMovementType(u8 localId, u8 movementType)
+void SetObjEventTemplateMovementType(u8 localId, u8 movementType)
{
s32 i;
@@ -570,11 +565,11 @@ static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId
static bool32 IsDummyWarp(struct WarpData *warp)
{
- if (warp->mapGroup != -1)
+ if (warp->mapGroup != (s8)MAP_GROUP(UNDEFINED))
return FALSE;
- else if (warp->mapNum != -1)
+ else if (warp->mapNum != (s8)MAP_NUM(UNDEFINED))
return FALSE;
- else if (warp->warpId != -1)
+ else if (warp->warpId != WARP_ID_NONE)
return FALSE;
else if (warp->x != -1)
return FALSE;
@@ -612,16 +607,20 @@ static void SetPlayerCoordsFromWarp(void)
{
if (gSaveBlock1Ptr->location.warpId >= 0 && gSaveBlock1Ptr->location.warpId < gMapHeader.events->warpCount)
{
+ // warpId is a valid warp for this map, use the coords of that warp.
gSaveBlock1Ptr->pos.x = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].x;
gSaveBlock1Ptr->pos.y = gMapHeader.events->warps[gSaveBlock1Ptr->location.warpId].y;
}
else if (gSaveBlock1Ptr->location.x >= 0 && gSaveBlock1Ptr->location.y >= 0)
{
+ // Invalid warpId given. The given coords are valid, use those instead.
+ // WARP_ID_NONE is used to reach this intentionally.
gSaveBlock1Ptr->pos.x = gSaveBlock1Ptr->location.x;
gSaveBlock1Ptr->pos.y = gSaveBlock1Ptr->location.y;
}
else
{
+ // Invalid warpId and coords given. Put player in center of map.
gSaveBlock1Ptr->pos.x = gMapHeader.mapLayout->width / 2;
gSaveBlock1Ptr->pos.y = gMapHeader.mapLayout->height / 2;
}
@@ -663,7 +662,7 @@ void SetWarpDestinationToHealLocation(u8 healLocationId)
{
const struct HealLocation *warp = GetHealLocation(healLocationId);
if (warp)
- SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y);
+ SetWarpDestination(warp->group, warp->map, WARP_ID_NONE, warp->x, warp->y);
}
void SetWarpDestinationToLastHealLocation(void)
@@ -675,7 +674,7 @@ void SetLastHealLocationWarp(u8 healLocationId)
{
const struct HealLocation *healLocation = GetHealLocation(healLocationId);
if (healLocation)
- SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, -1, healLocation->x, healLocation->y);
+ SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, WARP_ID_NONE, healLocation->x, healLocation->y);
}
void UpdateEscapeWarp(s16 x, s16 y)
@@ -683,7 +682,7 @@ void UpdateEscapeWarp(s16 x, s16 y)
u8 currMapType = GetCurrentMapType();
u8 destMapType = GetMapTypeByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum);
if (IsMapTypeOutdoors(currMapType) && IsMapTypeOutdoors(destMapType) != TRUE)
- SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - MAP_OFFSET, y - MAP_OFFSET + 1);
+ SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE, x - MAP_OFFSET, y - MAP_OFFSET + 1);
}
void SetEscapeWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y)
@@ -716,7 +715,7 @@ void SetWarpDestinationToFixedHoleWarp(s16 x, s16 y)
if (IsDummyWarp(&sFixedHoleWarp) == TRUE)
sWarpDestination = gLastUsedWarp;
else
- SetWarpDestination(sFixedHoleWarp.mapGroup, sFixedHoleWarp.mapNum, -1, x, y);
+ SetWarpDestination(sFixedHoleWarp.mapGroup, sFixedHoleWarp.mapNum, WARP_ID_NONE, x, y);
}
static void SetWarpDestinationToContinueGameWarp(void)
@@ -733,7 +732,7 @@ void SetContinueGameWarpToHealLocation(u8 healLocationId)
{
const struct HealLocation *warp = GetHealLocation(healLocationId);
if (warp)
- SetWarpData(&gSaveBlock1Ptr->continueGameWarp, warp->group, warp->map, -1, warp->x, warp->y);
+ SetWarpData(&gSaveBlock1Ptr->continueGameWarp, warp->group, warp->map, WARP_ID_NONE, warp->x, warp->y);
}
void SetContinueGameWarpToDynamicWarp(int unused)
@@ -763,7 +762,7 @@ static bool8 SetDiveWarp(u8 dir, u16 x, u16 y)
if (connection != NULL)
{
- SetWarpDestination(connection->mapGroup, connection->mapNum, -1, x, y);
+ SetWarpDestination(connection->mapGroup, connection->mapNum, WARP_ID_NONE, x, y);
}
else
{
@@ -789,7 +788,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
{
s32 paletteIndex;
- SetWarpDestination(mapGroup, mapNum, -1, -1, -1);
+ SetWarpDestination(mapGroup, mapNum, WARP_ID_NONE, -1, -1);
// Dont transition map music between BF Outside West/East
if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER)
@@ -804,7 +803,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
RestartWildEncounterImmunitySteps();
TryUpdateRandomTrainerRematches(mapGroup, mapNum);
DoTimeBasedEvents();
- SetSav1WeatherFromCurrMapHeader();
+ SetSavedWeatherFromCurrMapHeader();
ChooseAmbientCrySpecies();
SetDefaultFlashLevel();
Overworld_ClearSavedMusic();
@@ -855,7 +854,7 @@ static void LoadMapFromWarp(bool32 a1)
TryUpdateRandomTrainerRematches(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum);
if (a1 != TRUE)
DoTimeBasedEvents();
- SetSav1WeatherFromCurrMapHeader();
+ SetSavedWeatherFromCurrMapHeader();
ChooseAmbientCrySpecies();
if (isOutdoors)
FlagClear(FLAG_SYS_USE_FLASH);
@@ -968,6 +967,10 @@ bool32 Overworld_IsBikingAllowed(void)
return TRUE;
}
+// Flash level of 0 is fully bright
+// Flash level of 1 is the largest flash radius
+// Flash level of 7 is the smallest flash radius
+// Flash level of 8 is fully black
void SetDefaultFlashLevel(void)
{
if (!gMapHeader.cave)
@@ -978,14 +981,14 @@ void SetDefaultFlashLevel(void)
gSaveBlock1Ptr->flashLevel = gMaxFlashLevel - 1;
}
-void Overworld_SetFlashLevel(s32 flashLevel)
+void SetFlashLevel(s32 flashLevel)
{
if (flashLevel < 0 || flashLevel > gMaxFlashLevel)
flashLevel = 0;
gSaveBlock1Ptr->flashLevel = flashLevel;
}
-u8 Overworld_GetFlashLevel(void)
+u8 GetFlashLevel(void)
{
return gSaveBlock1Ptr->flashLevel;
}
@@ -1100,7 +1103,7 @@ u16 GetCurrLocationDefaultMusic(void)
// Play the desert music only when the sandstorm is active on Route 111.
if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111)
&& gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111)
- && GetSav1Weather() == WEATHER_SANDSTORM)
+ && GetSavedWeather() == WEATHER_SANDSTORM)
return MUS_ROUTE111;
music = GetLocationMusic(&gSaveBlock1Ptr->location);
@@ -1790,7 +1793,7 @@ static void InitCurrentFlashLevelScanlineEffect(void)
WriteBattlePyramidViewScanlineEffectBuffer();
ScanlineEffect_SetParams(sFlashEffectParams);
}
- else if ((flashLevel = Overworld_GetFlashLevel()))
+ else if ((flashLevel = GetFlashLevel()))
{
WriteFlashScanlineEffectBuffer(flashLevel);
ScanlineEffect_SetParams(sFlashEffectParams);
@@ -3147,17 +3150,17 @@ static u8 FlipVerticalAndClearForced(u8 newFacing, u8 oldFacing)
return oldFacing;
}
-static u8 LinkPlayerDetectCollision(u8 selfObjEventId, u8 a2, s16 x, s16 y)
+static bool8 LinkPlayerDetectCollision(u8 selfObjEventId, u8 direction, s16 x, s16 y)
{
u8 i;
- for (i = 0; i < 16; i++)
+ for (i = 0; i < OBJECT_EVENTS_COUNT; i++)
{
if (i != selfObjEventId)
{
if ((gObjectEvents[i].currentCoords.x == x && gObjectEvents[i].currentCoords.y == y)
|| (gObjectEvents[i].previousCoords.x == x && gObjectEvents[i].previousCoords.y == y))
{
- return 1;
+ return TRUE;
}
}
}