Merge branch 'master' of github.com:pret/pokefirered into misc_doc

This commit is contained in:
PikalaxALT
2021-03-24 08:15:08 -04:00
23 changed files with 3255 additions and 4336 deletions
+34 -27
View File
@@ -194,7 +194,7 @@ static void CreateConfirmLeaveTradeRoomPrompt(void);
static void InitLinkRoomStartMenuScript(void);
static void InitMenuBasedScript(const u8 *script);
static void sub_80581DC(const u8 *script);
static void sub_8058230(void);
static void RunTerminateLinkScript(void);
static void SpawnLinkPlayerObjectEvent(u8 i, s16 x, s16 y, u8 gender);
static void InitLinkPlayerObjectEventPos(struct ObjectEvent *objEvent, s16 x, s16 y);
static u8 GetSpriteForLinkedPlayer(u8 linkPlayerId);
@@ -2673,7 +2673,7 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
sub_8058230();
RunTerminateLinkScript();
}
return;
}
@@ -3170,7 +3170,7 @@ static void InitMenuBasedScript(const u8 *script)
ScriptContext2_Enable();
}
static void sub_8058230(void)
static void RunTerminateLinkScript(void)
{
ScriptContext1_SetupScript(TradeCenter_TerminateLink);
ScriptContext2_Enable();
@@ -3260,7 +3260,14 @@ static void ZeroObjectEvent(struct ObjectEvent *objEvent)
memset(objEvent, 0, sizeof(struct ObjectEvent));
}
static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4)
// Note: Emerald reuses the direction and range variables during Link mode
// as special gender and direction values. The types and placement
// conflict with the usual Event Object struct, thus the definitions.
#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];
@@ -3275,8 +3282,8 @@ static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4)
linkPlayerObjEvent->movementMode = MOVEMENT_MODE_FREE;
objEvent->active = TRUE;
objEvent->singleMovementActive = a4;
objEvent->range.as_byte = 2;
linkGender(objEvent) = gender;
linkDirection(objEvent) = DIR_NORTH;
objEvent->spriteId = MAX_SPRITES;
InitLinkPlayerObjectEventPos(objEvent, x, y);
@@ -3293,17 +3300,17 @@ static void InitLinkPlayerObjectEventPos(struct ObjectEvent *objEvent, s16 x, s1
ObjectEventUpdateZCoord(objEvent);
}
static void SetLinkPlayerObjectRange(u8 linkPlayerId, u8 range)
static void SetLinkPlayerObjectRange(u8 linkPlayerId, u8 dir)
{
if (gLinkPlayerObjectEvents[linkPlayerId].active)
{
u8 objEventId = gLinkPlayerObjectEvents[linkPlayerId].objEventId;
struct ObjectEvent *objEvent = &gObjectEvents[objEventId];
objEvent->range.as_byte = range;
linkDirection(objEvent) = dir;
}
}
static void DestroyLinkPlayerOBject(u8 linkPlayerId)
static void DestroyLinkPlayerObject(u8 linkPlayerId)
{
struct LinkPlayerObjectEvent *linkPlayerObjEvent = &gLinkPlayerObjectEvents[linkPlayerId];
u8 objEventId = linkPlayerObjEvent->objEventId;
@@ -3334,7 +3341,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)
@@ -3393,35 +3400,35 @@ static void SetPlayerFacingDirection(u8 linkPlayerId, u8 facing)
}
}
static u8 MovementEventModeCB_Normal(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
static u8 MovementEventModeCB_Normal(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
return sLinkPlayerFacingHandlers[a3](linkPlayerObjEvent, objEvent, a3);
return sLinkPlayerFacingHandlers[dir](linkPlayerObjEvent, objEvent, dir);
}
static u8 MovementEventModeCB_Ignored(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
static u8 MovementEventModeCB_Ignored(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
return FACING_UP;
}
// Duplicate Function
static u8 MovementEventModeCB_Normal_2(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
static u8 MovementEventModeCB_Normal_2(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
return sLinkPlayerFacingHandlers[a3](linkPlayerObjEvent, objEvent, a3);
return sLinkPlayerFacingHandlers[dir](linkPlayerObjEvent, objEvent, dir);
}
static bool8 FacingHandler_DoNothing(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
static bool8 FacingHandler_DoNothing(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
return FALSE;
}
static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 a3)
static bool8 FacingHandler_DpadMovement(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
s16 x, y;
objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte);
ObjectEventMoveDestCoords(objEvent, objEvent->range.as_byte, &x, &y);
linkDirection(objEvent) = FlipVerticalAndClearForced(dir, 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;
}
@@ -3434,9 +3441,9 @@ 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 dir)
{
objEvent->range.as_byte = FlipVerticalAndClearForced(a3, objEvent->range.as_byte);
linkDirection(objEvent) = FlipVerticalAndClearForced(dir, linkDirection(objEvent));
return FALSE;
}
@@ -3450,7 +3457,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);
@@ -3510,12 +3517,12 @@ static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion)
if (gameVersion == VERSION_FIRE_RED || gameVersion == VERSION_LEAF_GREEN)
{
objEvent->spriteId = AddPseudoObjectEvent(
GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, objEvent->singleMovementActive),
GetRivalAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, linkGender(objEvent)),
SpriteCB_LinkPlayer, 0, 0, 0);
}
else
{
objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(objEvent->singleMovementActive), SpriteCB_LinkPlayer, 0, 0, 0);
objEvent->spriteId = AddPseudoObjectEvent(GetRSAvatarGraphicsIdByGender(linkGender(objEvent)), SpriteCB_LinkPlayer, 0, 0, 0);
}
sprite = &gSprites[objEvent->spriteId];
@@ -3535,9 +3542,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)