From 46d41d2fb9c5d8ff842139410ebf0ff1642f9b82 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Fri, 28 Dec 2018 12:29:21 -0600 Subject: [PATCH] Use EVENT_OBJ_ID_PLAYER in C code --- src/event_obj_lock.c | 11 ++++++----- src/event_object_movement.c | 4 ++-- src/field_control_avatar.c | 13 +++++++------ src/field_player_avatar.c | 4 ++-- src/item_use.c | 11 ++++++----- src/mossdeep_gym.c | 3 ++- src/scrcmd.c | 13 +++++++------ 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/event_obj_lock.c b/src/event_obj_lock.c index 8c324ea82c..566b4931df 100644 --- a/src/event_obj_lock.c +++ b/src/event_obj_lock.c @@ -6,6 +6,7 @@ #include "script_movement.h" #include "task.h" #include "trainer_see.h" +#include "constants/event_objects.h" bool8 walkrun_is_standing_still(void) { @@ -89,20 +90,20 @@ void LockSelectedEventObject(void) void ScriptUnfreezeEventObjects(void) { - u8 objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + u8 playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); } void sub_8098524(void) { - u8 objectId; + u8 playerObjectId; if (gEventObjects[gSelectedEventObject].active) EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ffa8f53c92..7cee717bf4 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -6420,7 +6420,7 @@ bool8 MovementAction_FacePlayer_Step0(struct EventObject *eventObject, struct Sp { u8 playerObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(0xFF, 0, 0, &playerObjectId)) + if (!TryGetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0, &playerObjectId)) { FaceDirection(eventObject, sprite, GetDirectionToFace(eventObject->currentCoords.x, eventObject->currentCoords.y, gEventObjects[playerObjectId].currentCoords.x, gEventObjects[playerObjectId].currentCoords.y)); } @@ -6432,7 +6432,7 @@ bool8 MovementAction_FaceAwayPlayer_Step0(struct EventObject *eventObject, struc { u8 playerObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(0xFF, 0, 0, &playerObjectId)) + if (!TryGetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0, &playerObjectId)) { FaceDirection(eventObject, sprite, GetOppositeDirection(GetDirectionToFace(eventObject->currentCoords.x, eventObject->currentCoords.y, gEventObjects[playerObjectId].currentCoords.x, gEventObjects[playerObjectId].currentCoords.y))); } diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index bac0417dca..0642120bb1 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -27,6 +27,7 @@ #include "trainer_see.h" #include "wild_encounter.h" #include "constants/bg_event_constants.h" +#include "constants/event_objects.h" #include "constants/map_types.h" #include "constants/maps.h" #include "constants/songs.h" @@ -51,7 +52,7 @@ static bool32 TrySetupDiveDownScript(void); static bool32 TrySetupDiveEmergeScript(void); static bool8 TryStartStepBasedScript(struct MapPosition *, u16, u16); static bool8 CheckStandardWildEncounter(u16); -static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct MapPosition *, u16, u8); +static bool8 TryArrowWarp(struct MapPosition *, u16, u8); static bool8 IsWarpMetatileBehavior(u16); static bool8 IsArrowWarpMetatileBehavior(u16, u8); static s8 GetWarpEventAtMapPosition(struct MapHeader *, struct MapPosition *); @@ -161,7 +162,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input) return TRUE; if (input->input_field_0_4 && input->dpadDirection == playerDirection) { - if (mapheader_run_first_tag2_script_list_match_conditionally(&position, metatileBehavior, playerDirection) == TRUE) + if (TryArrowWarp(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; } @@ -266,7 +267,7 @@ const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatil else eventObjectId = GetEventObjectIdByXYZ(position->x + gDirectionToVectors[direction].x, position->y + gDirectionToVectors[direction].y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) return NULL; for (i = 0; i < 4; i++) @@ -287,14 +288,14 @@ static const u8 *GetInteractedEventObjectScript(struct MapPosition *position, u8 const u8 *script; eventObjectId = GetEventObjectIdByXYZ(position->x, position->y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) { if (MetatileBehavior_IsCounter(metatileBehavior) != TRUE) return NULL; // Look for an event object on the other side of the counter. eventObjectId = GetEventObjectIdByXYZ(position->x + gDirectionToVectors[direction].x, position->y + gDirectionToVectors[direction].y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) return NULL; } @@ -686,7 +687,7 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior) return FALSE; } -static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct MapPosition *position, u16 metatileBehavior, u8 direction) +static bool8 TryArrowWarp(struct MapPosition *position, u16 metatileBehavior, u8 direction) { s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index f14ac83293..8cb3ce9124 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -791,7 +791,7 @@ bool8 IsPlayerCollidingWithFarawayIslandMew(u8 direction) playerY = object->currentCoords.y; MoveCoords(direction, &playerX, &playerY); - mewObjectId = GetEventObjectIdByLocalIdAndMap(1, 0x39, 0x1A); + mewObjectId = GetEventObjectIdByLocalIdAndMap(1, MAP_NUM(FARAWAY_ISLAND_INTERIOR), MAP_GROUP(FARAWAY_ISLAND_INTERIOR)); if (mewObjectId == 16) { @@ -1389,7 +1389,7 @@ void InitPlayerAvatar(s16 x, s16 y, u8 direction, u8 gender) u8 eventObjectId; struct EventObject *eventObject; - playerEventObjTemplate.localId = 0xFF; + playerEventObjTemplate.localId = EVENT_OBJ_ID_PLAYER; playerEventObjTemplate.graphicsId = GetPlayerAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, gender); playerEventObjTemplate.x = x - 7; playerEventObjTemplate.y = y - 7; diff --git a/src/item_use.c b/src/item_use.c index 7592673454..91fdc81c8a 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -32,6 +32,7 @@ #include "task.h" #include "text.h" #include "constants/bg_event_constants.h" +#include "constants/event_objects.h" #include "constants/flags.h" #include "constants/items.h" #include "constants/songs.h" @@ -570,15 +571,15 @@ u8 sub_80FD9B0(s16 itemX, s16 itemY) void sub_80FDA24(u8 direction) { - EventObjectClearHeldMovementIfFinished(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); - EventObjectClearHeldMovement(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); - UnfreezeEventObject(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); + EventObjectClearHeldMovementIfFinished(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); + EventObjectClearHeldMovement(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); + UnfreezeEventObject(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); PlayerTurnInPlace(direction); } void sub_80FDA94(u8 taskId) { - if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE) + if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]) == TRUE) DisplayItemMessageOnField(taskId, gText_ItemFinderNearby, sub_80FD5CC); } @@ -586,7 +587,7 @@ void sub_80FDADC(u8 taskId) { s16 *data = gTasks[taskId].data; - if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE + if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]) == TRUE || data[2] == FALSE) { sub_80FDA24(gUnknown_085920E4[data[5]]); diff --git a/src/mossdeep_gym.c b/src/mossdeep_gym.c index 07920fe4cb..d8adbe0c61 100644 --- a/src/mossdeep_gym.c +++ b/src/mossdeep_gym.c @@ -5,6 +5,7 @@ #include "mossdeep_gym.h" #include "script_movement.h" #include "constants/event_object_movement_constants.h" +#include "constants/event_objects.h" // Movement scripts. extern const u8 gUnknown_08612698[]; @@ -52,7 +53,7 @@ void FinishMossdeepGymTiles(void) if (gUnknown_0203CE50 != NULL) FREE_AND_SET_NULL(gUnknown_0203CE50); - id = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); + id = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); EventObjectClearHeldMovementIfFinished(&gEventObjects[id]); sub_80D338C(); } diff --git a/src/scrcmd.c b/src/scrcmd.c index 39df1117d8..77852ad315 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -49,6 +49,7 @@ #include "trainer_see.h" #include "tv.h" #include "window.h" +#include "constants/event_objects.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); @@ -1239,11 +1240,11 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) bool8 ScrCmd_releaseall(struct ScriptContext *ctx) { - u8 objectId; + u8 playerObjectId; HideFieldMessageBox(); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); return FALSE; @@ -1251,13 +1252,13 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx) bool8 ScrCmd_release(struct ScriptContext *ctx) { - u8 objectId; + u8 playerObjectId; HideFieldMessageBox(); if (gEventObjects[gSelectedEventObject].active) EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); return FALSE;