field_player_avatar.c: Fix TryInterruptObjectEventSpecialAnim fakematch.

This commit is contained in:
Kaz 2020-09-17 18:24:11 -04:00
parent c724f2b809
commit 1404cf3330
5 changed files with 44 additions and 49 deletions

View File

@ -195,15 +195,10 @@ struct ObjectEvent
/*0x0C*/ struct Coords16 initialCoords;
/*0x10*/ struct Coords16 currentCoords;
/*0x14*/ struct Coords16 previousCoords;
/*0x18*/ u8 facingDirection:4; // current direction?
/*0x18*/ u8 movementDirection:4;
/*0x19*/ union __attribute__((packed)) {
u8 as_byte;
struct __attribute__((packed)) {
u8 x:4;
u8 y:4;
} ALIGNED(1) as_nybbles;
} ALIGNED(1) range;
/*0x18*/ u16 facingDirection:4; // current direction?
u16 movementDirection:4;
u16 rangeX:4;
u16 rangeY:4;
/*0x1A*/ u8 fieldEffectSpriteId;
/*0x1B*/ u8 warpArrowSpriteId;
/*0x1C*/ u8 movementActionId;

View File

@ -1232,8 +1232,8 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template,
objectEvent->previousCoords.y = y;
objectEvent->currentElevation = template->elevation;
objectEvent->previousElevation = template->elevation;
objectEvent->range.as_nybbles.x = template->movementRangeX;
objectEvent->range.as_nybbles.y = template->movementRangeY;
objectEvent->rangeX = template->movementRangeX;
objectEvent->rangeY = template->movementRangeY;
objectEvent->trainerType = template->trainerType;
objectEvent->mapNum = mapNum; //redundant, but needed to match
objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId;
@ -1242,13 +1242,13 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template,
SetObjectEventDynamicGraphicsId(objectEvent);
if (gRangedMovementTypes[objectEvent->movementType])
{
if (objectEvent->range.as_nybbles.x == 0)
if (objectEvent->rangeX == 0)
{
objectEvent->range.as_nybbles.x++;
objectEvent->rangeX++;
}
if (objectEvent->range.as_nybbles.y == 0)
if (objectEvent->rangeY == 0)
{
objectEvent->range.as_nybbles.y++;
objectEvent->rangeY++;
}
}
return objectEventId;
@ -4755,19 +4755,19 @@ static bool8 IsCoordOutsideObjectEventMovementRange(struct ObjectEvent *objectEv
s16 top;
s16 bottom;
if (objectEvent->range.as_nybbles.x != 0)
if (objectEvent->rangeX != 0)
{
left = objectEvent->initialCoords.x - objectEvent->range.as_nybbles.x;
right = objectEvent->initialCoords.x + objectEvent->range.as_nybbles.x;
left = objectEvent->initialCoords.x - objectEvent->rangeX;
right = objectEvent->initialCoords.x + objectEvent->rangeX;
if (left > x || right < x)
{
return TRUE;
}
}
if (objectEvent->range.as_nybbles.y != 0)
if (objectEvent->rangeY != 0)
{
top = objectEvent->initialCoords.y - objectEvent->range.as_nybbles.y;
bottom = objectEvent->initialCoords.y + objectEvent->range.as_nybbles.y;
top = objectEvent->initialCoords.y - objectEvent->rangeY;
bottom = objectEvent->initialCoords.y + objectEvent->rangeY;
if (top > y || bottom < y)
{
return TRUE;

View File

@ -343,10 +343,6 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEvent, u8 direction)
{
u8 r5 = direction;
u8 r6 = direction;
r6++; r6--;
if (ObjectEventIsMovementOverridden(playerObjEvent)
&& !ObjectEventClearHeldMovementIfFinished(playerObjEvent))
{
@ -358,13 +354,13 @@ static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEve
return TRUE;
}
if (playerObjEvent->movementDirection != r5)
if (playerObjEvent->movementDirection != direction)
{
ObjectEventClearHeldMovement(playerObjEvent);
return FALSE;
}
if (!sub_808B028(r6))
if (!sub_808B028(direction))
{
ObjectEventClearHeldMovement(playerObjEvent);
return FALSE;
@ -2086,7 +2082,7 @@ static void sub_808D094(u8 taskId)
sub_808D074(object->facingDirection);
data[1] = 0;
data[2] = 1;
data[3] = (u16)(sprite->pos1.y + sprite->pos2.y) * 16;
data[3] = (u16)(sprite->pos1.y + sprite->pos2.y) << 4;
sprite->pos2.y = 0;
CameraObjectReset2();
object->fixedPriority = TRUE;

View File

@ -2909,7 +2909,11 @@ static void ZeroObjectEvent(struct ObjectEvent *objEvent)
memset(objEvent, 0, sizeof(struct ObjectEvent));
}
static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4)
#define linkGender(obj) obj->singleMovementActive
// not even one can reference *byte* aligned bitfield members...
#define linkDirection(obj) ((u8*)obj)[offsetof(typeof(*obj), fieldEffectSpriteId) - 1] // -> rangeX
static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 gender)
{
u8 objEventId = GetFirstInactiveObjectEventId();
struct LinkPlayerObjectEvent *linkPlayerObjEvent = &gLinkPlayerObjectEvents[linkPlayerId];
@ -2924,8 +2928,8 @@ static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4)
linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FREE;
objEvent->active = 1;
objEvent->singleMovementActive = a4;
objEvent->range.as_byte = 2;
linkGender(objEvent) = gender;
linkDirection(objEvent) = 2;
objEvent->spriteId = 64;
InitLinkPlayerObjectEventPos(objEvent, x, y);
@ -2948,7 +2952,7 @@ static void sub_80877DC(u8 linkPlayerId, u8 a2)
{
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
struct ObjectEvent *objEvent = &gObjectEvents[objEventId];
objEvent->range.as_byte = a2;
linkDirection(objEvent) = a2;
}
}
@ -2983,7 +2987,7 @@ static u8 GetLinkPlayerFacingDirection(u8 linkPlayerId)
{
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
struct ObjectEvent *objEvent = &gObjectEvents[objEventId];
return objEvent->range.as_byte;
return linkDirection(objEvent);
}
static u8 GetLinkPlayerElevation(u8 linkPlayerId)
@ -3068,10 +3072,10 @@ static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayer
{
s16 x, y;
objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte);
ObjectEventMoveDestCoords(objEvent, objEvent->range.as_byte, &x, &y);
linkDirection(objEvent) = FlipVerticalAndClearForced(a3, linkDirection(objEvent));
ObjectEventMoveDestCoords(objEvent, linkDirection(objEvent), &x, &y);
if (LinkPlayerDetectCollision(linkPlayerObjEvent->objEventId, objEvent->range.as_byte, x, y))
if (LinkPlayerDetectCollision(linkPlayerObjEvent->objEventId, linkDirection(objEvent), x, y))
{
return FALSE;
}
@ -3086,7 +3090,7 @@ static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayer
static bool8 FacingHandler_ForcedFacingChange(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
{
objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte);
linkDirection(objEvent) = FlipVerticalAndClearForced(a3, linkDirection(objEvent));
return FALSE;
}
@ -3100,7 +3104,7 @@ static void MovementStatusHandler_TryAdvanceScript(struct LinkPlayerObjectEvent
{
objEvent->directionSequenceIndex--;
linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FROZEN;
MoveCoords(objEvent->range.as_byte, &objEvent->initialCoords.x, &objEvent->initialCoords.y);
MoveCoords(linkDirection(objEvent), &objEvent->initialCoords.x, &objEvent->initialCoords.y);
if (!objEvent->directionSequenceIndex)
{
ShiftStillObjectEventCoords(objEvent);
@ -3161,14 +3165,14 @@ static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion)
{
case VERSION_FIRE_RED:
case VERSION_LEAF_GREEN:
objEvent->spriteId = AddPseudoObjectEvent(GetFRLGAvatarGraphicsIdByGender(objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0);
objEvent->spriteId = AddPseudoObjectEvent(GetFRLGAvatarGraphicsIdByGender(linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0);
break;
case VERSION_RUBY:
case VERSION_SAPPHIRE:
objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0);
objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0);
break;
case VERSION_EMERALD:
objEvent->spriteId = AddPseudoObjectEvent(GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0);
objEvent->spriteId = AddPseudoObjectEvent(GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0);
break;
}
@ -3189,9 +3193,9 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite)
sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation);
if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE)
StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte));
StartSpriteAnim(sprite, GetFaceDirectionAnimNum(linkDirection(objEvent)));
else
StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte));
StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(linkDirection(objEvent)));
UpdateObjectEventSpriteVisibility(sprite, 0);
if (objEvent->triggerGroundEffectsOnMove)

View File

@ -377,15 +377,15 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap
}
// preserve mapobj_unk_19 before clearing.
unk19_temp = trainerObj->range.as_nybbles.x;
unk19b_temp = trainerObj->range.as_nybbles.y;
trainerObj->range.as_nybbles.x = 0;
trainerObj->range.as_nybbles.y = 0;
unk19_temp = trainerObj->rangeX;
unk19b_temp = trainerObj->rangeY;
trainerObj->rangeX = 0;
trainerObj->rangeY = 0;
collision = GetCollisionAtCoords(trainerObj, x, y, direction);
trainerObj->range.as_nybbles.x = unk19_temp;
trainerObj->range.as_nybbles.y = unk19b_temp;
trainerObj->rangeX = unk19_temp;
trainerObj->rangeY = unk19b_temp;
if (collision == 4)
return approachDistance;