mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-14 15:43:43 +01:00
field_player_avatar.c: Fix TryInterruptObjectEventSpecialAnim fakematch.
This commit is contained in:
parent
c724f2b809
commit
1404cf3330
@ -195,15 +195,10 @@ struct ObjectEvent
|
|||||||
/*0x0C*/ struct Coords16 initialCoords;
|
/*0x0C*/ struct Coords16 initialCoords;
|
||||||
/*0x10*/ struct Coords16 currentCoords;
|
/*0x10*/ struct Coords16 currentCoords;
|
||||||
/*0x14*/ struct Coords16 previousCoords;
|
/*0x14*/ struct Coords16 previousCoords;
|
||||||
/*0x18*/ u8 facingDirection:4; // current direction?
|
/*0x18*/ u16 facingDirection:4; // current direction?
|
||||||
/*0x18*/ u8 movementDirection:4;
|
u16 movementDirection:4;
|
||||||
/*0x19*/ union __attribute__((packed)) {
|
u16 rangeX:4;
|
||||||
u8 as_byte;
|
u16 rangeY:4;
|
||||||
struct __attribute__((packed)) {
|
|
||||||
u8 x:4;
|
|
||||||
u8 y:4;
|
|
||||||
} ALIGNED(1) as_nybbles;
|
|
||||||
} ALIGNED(1) range;
|
|
||||||
/*0x1A*/ u8 fieldEffectSpriteId;
|
/*0x1A*/ u8 fieldEffectSpriteId;
|
||||||
/*0x1B*/ u8 warpArrowSpriteId;
|
/*0x1B*/ u8 warpArrowSpriteId;
|
||||||
/*0x1C*/ u8 movementActionId;
|
/*0x1C*/ u8 movementActionId;
|
||||||
|
@ -1232,8 +1232,8 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template,
|
|||||||
objectEvent->previousCoords.y = y;
|
objectEvent->previousCoords.y = y;
|
||||||
objectEvent->currentElevation = template->elevation;
|
objectEvent->currentElevation = template->elevation;
|
||||||
objectEvent->previousElevation = template->elevation;
|
objectEvent->previousElevation = template->elevation;
|
||||||
objectEvent->range.as_nybbles.x = template->movementRangeX;
|
objectEvent->rangeX = template->movementRangeX;
|
||||||
objectEvent->range.as_nybbles.y = template->movementRangeY;
|
objectEvent->rangeY = template->movementRangeY;
|
||||||
objectEvent->trainerType = template->trainerType;
|
objectEvent->trainerType = template->trainerType;
|
||||||
objectEvent->mapNum = mapNum; //redundant, but needed to match
|
objectEvent->mapNum = mapNum; //redundant, but needed to match
|
||||||
objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId;
|
objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId;
|
||||||
@ -1242,13 +1242,13 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template,
|
|||||||
SetObjectEventDynamicGraphicsId(objectEvent);
|
SetObjectEventDynamicGraphicsId(objectEvent);
|
||||||
if (gRangedMovementTypes[objectEvent->movementType])
|
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;
|
return objectEventId;
|
||||||
@ -4755,19 +4755,19 @@ static bool8 IsCoordOutsideObjectEventMovementRange(struct ObjectEvent *objectEv
|
|||||||
s16 top;
|
s16 top;
|
||||||
s16 bottom;
|
s16 bottom;
|
||||||
|
|
||||||
if (objectEvent->range.as_nybbles.x != 0)
|
if (objectEvent->rangeX != 0)
|
||||||
{
|
{
|
||||||
left = objectEvent->initialCoords.x - objectEvent->range.as_nybbles.x;
|
left = objectEvent->initialCoords.x - objectEvent->rangeX;
|
||||||
right = objectEvent->initialCoords.x + objectEvent->range.as_nybbles.x;
|
right = objectEvent->initialCoords.x + objectEvent->rangeX;
|
||||||
if (left > x || right < x)
|
if (left > x || right < x)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (objectEvent->range.as_nybbles.y != 0)
|
if (objectEvent->rangeY != 0)
|
||||||
{
|
{
|
||||||
top = objectEvent->initialCoords.y - objectEvent->range.as_nybbles.y;
|
top = objectEvent->initialCoords.y - objectEvent->rangeY;
|
||||||
bottom = objectEvent->initialCoords.y + objectEvent->range.as_nybbles.y;
|
bottom = objectEvent->initialCoords.y + objectEvent->rangeY;
|
||||||
if (top > y || bottom < y)
|
if (top > y || bottom < y)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -343,10 +343,6 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
|
|||||||
|
|
||||||
static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEvent, u8 direction)
|
static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEvent, u8 direction)
|
||||||
{
|
{
|
||||||
u8 r5 = direction;
|
|
||||||
u8 r6 = direction;
|
|
||||||
r6++; r6--;
|
|
||||||
|
|
||||||
if (ObjectEventIsMovementOverridden(playerObjEvent)
|
if (ObjectEventIsMovementOverridden(playerObjEvent)
|
||||||
&& !ObjectEventClearHeldMovementIfFinished(playerObjEvent))
|
&& !ObjectEventClearHeldMovementIfFinished(playerObjEvent))
|
||||||
{
|
{
|
||||||
@ -358,13 +354,13 @@ static bool8 TryInterruptObjectEventSpecialAnim(struct ObjectEvent *playerObjEve
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerObjEvent->movementDirection != r5)
|
if (playerObjEvent->movementDirection != direction)
|
||||||
{
|
{
|
||||||
ObjectEventClearHeldMovement(playerObjEvent);
|
ObjectEventClearHeldMovement(playerObjEvent);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sub_808B028(r6))
|
if (!sub_808B028(direction))
|
||||||
{
|
{
|
||||||
ObjectEventClearHeldMovement(playerObjEvent);
|
ObjectEventClearHeldMovement(playerObjEvent);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -2086,7 +2082,7 @@ static void sub_808D094(u8 taskId)
|
|||||||
sub_808D074(object->facingDirection);
|
sub_808D074(object->facingDirection);
|
||||||
data[1] = 0;
|
data[1] = 0;
|
||||||
data[2] = 1;
|
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;
|
sprite->pos2.y = 0;
|
||||||
CameraObjectReset2();
|
CameraObjectReset2();
|
||||||
object->fixedPriority = TRUE;
|
object->fixedPriority = TRUE;
|
||||||
|
@ -2909,7 +2909,11 @@ static void ZeroObjectEvent(struct ObjectEvent *objEvent)
|
|||||||
memset(objEvent, 0, sizeof(struct ObjectEvent));
|
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();
|
u8 objEventId = GetFirstInactiveObjectEventId();
|
||||||
struct LinkPlayerObjectEvent *linkPlayerObjEvent = &gLinkPlayerObjectEvents[linkPlayerId];
|
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;
|
linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FREE;
|
||||||
|
|
||||||
objEvent->active = 1;
|
objEvent->active = 1;
|
||||||
objEvent->singleMovementActive = a4;
|
linkGender(objEvent) = gender;
|
||||||
objEvent->range.as_byte = 2;
|
linkDirection(objEvent) = 2;
|
||||||
objEvent->spriteId = 64;
|
objEvent->spriteId = 64;
|
||||||
|
|
||||||
InitLinkPlayerObjectEventPos(objEvent, x, y);
|
InitLinkPlayerObjectEventPos(objEvent, x, y);
|
||||||
@ -2948,7 +2952,7 @@ static void sub_80877DC(u8 linkPlayerId, u8 a2)
|
|||||||
{
|
{
|
||||||
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
|
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
|
||||||
struct ObjectEvent *objEvent = &gObjectEvents[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;
|
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
|
||||||
struct ObjectEvent *objEvent = &gObjectEvents[objEventId];
|
struct ObjectEvent *objEvent = &gObjectEvents[objEventId];
|
||||||
return objEvent->range.as_byte;
|
return linkDirection(objEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 GetLinkPlayerElevation(u8 linkPlayerId)
|
static u8 GetLinkPlayerElevation(u8 linkPlayerId)
|
||||||
@ -3068,10 +3072,10 @@ static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayer
|
|||||||
{
|
{
|
||||||
s16 x, y;
|
s16 x, y;
|
||||||
|
|
||||||
objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte);
|
linkDirection(objEvent) = FlipVerticalAndClearForced(a3, linkDirection(objEvent));
|
||||||
ObjectEventMoveDestCoords(objEvent, objEvent->range.as_byte, &x, &y);
|
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;
|
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)
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3100,7 +3104,7 @@ static void MovementStatusHandler_TryAdvanceScript(struct LinkPlayerObjectEvent
|
|||||||
{
|
{
|
||||||
objEvent->directionSequenceIndex--;
|
objEvent->directionSequenceIndex--;
|
||||||
linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FROZEN;
|
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)
|
if (!objEvent->directionSequenceIndex)
|
||||||
{
|
{
|
||||||
ShiftStillObjectEventCoords(objEvent);
|
ShiftStillObjectEventCoords(objEvent);
|
||||||
@ -3161,14 +3165,14 @@ static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion)
|
|||||||
{
|
{
|
||||||
case VERSION_FIRE_RED:
|
case VERSION_FIRE_RED:
|
||||||
case VERSION_LEAF_GREEN:
|
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;
|
break;
|
||||||
case VERSION_RUBY:
|
case VERSION_RUBY:
|
||||||
case VERSION_SAPPHIRE:
|
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;
|
break;
|
||||||
case VERSION_EMERALD:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3189,9 +3193,9 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite)
|
|||||||
sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation);
|
sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation);
|
||||||
|
|
||||||
if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE)
|
if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE)
|
||||||
StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte));
|
StartSpriteAnim(sprite, GetFaceDirectionAnimNum(linkDirection(objEvent)));
|
||||||
else
|
else
|
||||||
StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte));
|
StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(linkDirection(objEvent)));
|
||||||
|
|
||||||
UpdateObjectEventSpriteVisibility(sprite, 0);
|
UpdateObjectEventSpriteVisibility(sprite, 0);
|
||||||
if (objEvent->triggerGroundEffectsOnMove)
|
if (objEvent->triggerGroundEffectsOnMove)
|
||||||
|
@ -377,15 +377,15 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preserve mapobj_unk_19 before clearing.
|
// preserve mapobj_unk_19 before clearing.
|
||||||
unk19_temp = trainerObj->range.as_nybbles.x;
|
unk19_temp = trainerObj->rangeX;
|
||||||
unk19b_temp = trainerObj->range.as_nybbles.y;
|
unk19b_temp = trainerObj->rangeY;
|
||||||
trainerObj->range.as_nybbles.x = 0;
|
trainerObj->rangeX = 0;
|
||||||
trainerObj->range.as_nybbles.y = 0;
|
trainerObj->rangeY = 0;
|
||||||
|
|
||||||
collision = GetCollisionAtCoords(trainerObj, x, y, direction);
|
collision = GetCollisionAtCoords(trainerObj, x, y, direction);
|
||||||
|
|
||||||
trainerObj->range.as_nybbles.x = unk19_temp;
|
trainerObj->rangeX = unk19_temp;
|
||||||
trainerObj->range.as_nybbles.y = unk19b_temp;
|
trainerObj->rangeY = unk19b_temp;
|
||||||
if (collision == 4)
|
if (collision == 4)
|
||||||
return approachDistance;
|
return approachDistance;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user