summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcus Huderle <huderlem@gmail.com>2019-03-31 14:09:40 -0500
committerMarcus Huderle <huderlem@gmail.com>2019-03-31 14:09:40 -0500
commitd13563b174119121964c2da62380bce44743b93f (patch)
tree32d364f6c44d709939824bc1fbd2b3e0084c5820 /src
parent462b196abc126cd8c2a06434f9b3b9c25a0d4327 (diff)
Document some faraway_island code
Diffstat (limited to 'src')
-rw-r--r--src/event_object_movement.c4
-rwxr-xr-xsrc/faraway_island.c131
2 files changed, 68 insertions, 67 deletions
diff --git a/src/event_object_movement.c b/src/event_object_movement.c
index 30dffd8d7..6a3527bc1 100644
--- a/src/event_object_movement.c
+++ b/src/event_object_movement.c
@@ -4414,8 +4414,8 @@ bool8 CopyablePlayerMovement_GoSpeed0(struct EventObject *eventObject, struct Sp
direction = playerDirection;
if (EventObjectIsFarawayIslandMew(eventObject))
{
- direction = sub_81D427C();
- if (direction == 0)
+ direction = GetMewMoveDirection();
+ if (direction == DIR_NONE)
{
direction = playerDirection;
direction = state_to_direction(gInitialMovementTypeFacingDirections[eventObject->movementType], eventObject->directionSequenceIndex, direction);
diff --git a/src/faraway_island.c b/src/faraway_island.c
index 1c8dff14e..6a835a02b 100755
--- a/src/faraway_island.c
+++ b/src/faraway_island.c
@@ -17,12 +17,13 @@ static u8 sub_81D4C9C(struct EventObject*, u8);
static u8 sub_81D4C58(struct EventObject*, u8);
static u8 sub_81D4CE0(struct EventObject*, u8);
static u8 sub_81D4D24(u8);
-static bool8 sub_81D4834(s16, s16);
+static bool8 CanMewWalkToCoords(s16, s16);
-extern u8 gUnknown_0203CF50;
-extern s16 gUnknown_030012F8;
-extern s16 gUnknown_030012FA;
-extern u8 gUnknown_030012FC[4];
+static EWRAM_DATA u8 sUnknown_0203CF50 = 0;
+
+static s16 sPlayerToMewDeltaX;
+static s16 sPlayerToMewDeltaY;
+static u8 sMewDirectionCandidates[4];
extern const struct SpritePalette gFieldEffectObjectPaletteInfo1;
extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[];
@@ -35,23 +36,23 @@ static const s16 sFarawayIslandRockCoords[4][2] =
{20, 20},
};
-static u8 sub_81D4258(void)
+static u8 GetMewEventObjectId(void)
{
u8 eventObjectId;
TryGetEventObjectIdByLocalIdAndMap(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &eventObjectId);
return eventObjectId;
}
-u32 sub_81D427C(void)
+u32 GetMewMoveDirection(void)
{
u8 i;
int skip;
- struct EventObject *mew = &gEventObjects[sub_81D4258()];
+ struct EventObject *mew = &gEventObjects[GetMewEventObjectId()];
- gUnknown_030012F8 = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x - mew->currentCoords.x;
- gUnknown_030012FA = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y - mew->currentCoords.y;
- for (i = 0; i < ARRAY_COUNT(gUnknown_030012FC); i++)
- gUnknown_030012FC[i] = DIR_NONE;
+ sPlayerToMewDeltaX = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x - mew->currentCoords.x;
+ sPlayerToMewDeltaY = gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y - mew->currentCoords.y;
+ for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++)
+ sMewDirectionCandidates[i] = DIR_NONE;
if (gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x == gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x
&& gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y == gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y)
@@ -85,33 +86,33 @@ u32 sub_81D427C(void)
if (!skip)
{
- if (gUnknown_030012F8 > 0)
+ if (sPlayerToMewDeltaX > 0)
{
if (mew->currentCoords.x + 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
- if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
}
- else if (gUnknown_030012F8 < 0)
+ else if (sPlayerToMewDeltaX < 0)
{
if (mew->currentCoords.x - 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
- if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
}
if (mew->currentCoords.x == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.x)
{
- if (gUnknown_030012FA > 0)
+ if (sPlayerToMewDeltaY > 0)
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
else
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
}
@@ -134,33 +135,33 @@ u32 sub_81D427C(void)
if (!skip)
{
- if (gUnknown_030012FA > 0)
+ if (sPlayerToMewDeltaY > 0)
{
if (mew->currentCoords.y + 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
}
- else if (gUnknown_030012FA < 0)
+ else if (sPlayerToMewDeltaY < 0)
{
if (mew->currentCoords.y - 1 == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
}
if (mew->currentCoords.y == gEventObjects[gPlayerAvatar.eventObjectId].previousCoords.y)
{
- if (gUnknown_030012F8 > 0)
+ if (sPlayerToMewDeltaX > 0)
{
- if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
else
{
- if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
}
@@ -208,52 +209,52 @@ u32 sub_81D427C(void)
return DIR_WEST;
}
- if (gUnknown_030012FA == 0)
+ if (sPlayerToMewDeltaY == 0)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y > mew->currentCoords.y)
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
}
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y < mew->currentCoords.y)
{
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1))
return DIR_NORTH;
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1))
return DIR_SOUTH;
}
- if (gUnknown_030012F8 == 0)
+ if (sPlayerToMewDeltaX == 0)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x > mew->currentCoords.x)
{
- if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x < mew->currentCoords.x)
{
- if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
}
- if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y))
return DIR_EAST;
- if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
+ if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y))
return DIR_WEST;
}
return sub_81D4890(DIR_NONE);
}
-static bool8 sub_81D4834(s16 x, s16 y)
+static bool8 CanMewWalkToCoords(s16 x, s16 y)
{
if (gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.x == x
&& gEventObjects[gPlayerAvatar.eventObjectId].currentCoords.y == y)
@@ -268,39 +269,39 @@ static u8 sub_81D4890(u8 ignoredDir)
{
u8 i;
u8 count = 0;
- struct EventObject *mew = &gEventObjects[sub_81D4258()];
+ struct EventObject *mew = &gEventObjects[GetMewEventObjectId()];
- for (i = 0; i < ARRAY_COUNT(gUnknown_030012FC); i++)
- gUnknown_030012FC[i] = DIR_NONE;
+ for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++)
+ sMewDirectionCandidates[i] = DIR_NONE;
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH)
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH)
{
- gUnknown_030012FC[count] = DIR_NORTH;
+ sMewDirectionCandidates[count] = DIR_NORTH;
count++;
}
- if (sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST)
+ if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST)
{
- gUnknown_030012FC[count] = DIR_EAST;
+ sMewDirectionCandidates[count] = DIR_EAST;
count++;
}
- if (sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH)
+ if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH)
{
- gUnknown_030012FC[count] = DIR_SOUTH;
+ sMewDirectionCandidates[count] = DIR_SOUTH;
count++;
}
- if (sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST)
+ if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST)
{
- gUnknown_030012FC[count] = DIR_WEST;
+ sMewDirectionCandidates[count] = DIR_WEST;
count++;
}
if (count > 1)
- return gUnknown_030012FC[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count];
+ return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count];
else
- return gUnknown_030012FC[0];
+ return sMewDirectionCandidates[0];
}
void UpdateFarawayIslandStepCounter(void)
@@ -355,7 +356,7 @@ void sub_81D4A90(void)
s16 x;
s16 y;
u8 spriteId;
- struct EventObject *mew = &gEventObjects[sub_81D4258()];
+ struct EventObject *mew = &gEventObjects[GetMewEventObjectId()];
mew->invisible = 0;
if (gSpecialVar_0x8004 == 1)
@@ -378,10 +379,10 @@ void sub_81D4A90(void)
x = mew->currentCoords.x;
y = mew->currentCoords.y;
sub_80930E0(&x, &y, 8, 8);
- gUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1);
- if (gUnknown_0203CF50 != MAX_SPRITES)
+ sUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1);
+ if (sUnknown_0203CF50 != MAX_SPRITES)
{
- struct Sprite *sprite = &gSprites[gUnknown_0203CF50];
+ struct Sprite *sprite = &gSprites[sUnknown_0203CF50];
sprite->coordOffsetEnabled = 1;
sprite->oam.priority = 2;
sprite->callback = SpriteCallbackDummy;
@@ -391,15 +392,15 @@ void sub_81D4A90(void)
void sub_81D4BEC(void)
{
- if (gUnknown_0203CF50 != MAX_SPRITES)
- DestroySprite(&gSprites[gUnknown_0203CF50]);
+ if (sUnknown_0203CF50 != MAX_SPRITES)
+ DestroySprite(&gSprites[sUnknown_0203CF50]);
}
static bool8 sub_81D4C14(struct EventObject *mew, u8 index)
{
- if (gUnknown_030012FA > 0 && sub_81D4834(mew->currentCoords.x, mew->currentCoords.y - 1))
+ if (sPlayerToMewDeltaY > 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1))
{
- gUnknown_030012FC[index] = DIR_NORTH;
+ sMewDirectionCandidates[index] = DIR_NORTH;
return TRUE;
}
@@ -408,9 +409,9 @@ static bool8 sub_81D4C14(struct EventObject *mew, u8 index)
static u8 sub_81D4C58(struct EventObject *mew, u8 index)
{
- if (gUnknown_030012F8 < 0 && sub_81D4834(mew->currentCoords.x + 1, mew->currentCoords.y))
+ if (sPlayerToMewDeltaX < 0 && CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y))
{
- gUnknown_030012FC[index] = DIR_EAST;
+ sMewDirectionCandidates[index] = DIR_EAST;
return TRUE;
}
@@ -419,9 +420,9 @@ static u8 sub_81D4C58(struct EventObject *mew, u8 index)
static u8 sub_81D4C9C(struct EventObject *mew, u8 index)
{
- if (gUnknown_030012FA < 0 && sub_81D4834(mew->currentCoords.x, mew->currentCoords.y + 1))
+ if (sPlayerToMewDeltaY < 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1))
{
- gUnknown_030012FC[index] = DIR_SOUTH;
+ sMewDirectionCandidates[index] = DIR_SOUTH;
return TRUE;
}
@@ -430,9 +431,9 @@ static u8 sub_81D4C9C(struct EventObject *mew, u8 index)
static u8 sub_81D4CE0(struct EventObject *mew, u8 index)
{
- if (gUnknown_030012F8 > 0 && sub_81D4834(mew->currentCoords.x - 1, mew->currentCoords.y))
+ if (sPlayerToMewDeltaX > 0 && CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y))
{
- gUnknown_030012FC[index] = DIR_WEST;
+ sMewDirectionCandidates[index] = DIR_WEST;
return TRUE;
}
@@ -441,5 +442,5 @@ static u8 sub_81D4CE0(struct EventObject *mew, u8 index)
static u8 sub_81D4D24(u8 mod)
{
- return gUnknown_030012FC[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % mod];
+ return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % mod];
}