Use EVENT_OBJ_ID_PLAYER in C code

This commit is contained in:
Marcus Huderle 2018-12-28 12:29:21 -06:00
parent 95dcff581b
commit 46d41d2fb9
7 changed files with 32 additions and 27 deletions

View File

@ -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();
}

View File

@ -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)));
}

View File

@ -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);

View File

@ -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;

View File

@ -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]]);

View File

@ -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();
}

View File

@ -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;