Alchemy
Loading...
Searching...
No Matches

link.c File Reference

Link battles: the parties and Djinn exchanged, and the turn handshake. More...

Go to the source code of this file.

Macros

#define NAME_LIMIT   4
#define APPEND_NAME_SPACE   0

Enumerations

enum  LinkPartyPacketSize { LINK_PARTY_UNIT_BYTES = 340 , LINK_PARTY_OFFER_BYTES = 320 }
 What a link battle sends of each party member, and of the Djinn recovery list. More...

Functions

s32 LinkBattle_ReceiveParty (void)
 Link battle: receives the opponent's party into the enemy units, one member at a time, and puts the "Enemy" label (MsgEnemyLabel) before each name; then receives the opponent's Djinn recovery list.
s32 LinkBattle_SendParty (void)
 Link battle: sends the party, one member at a time and three places in all (an empty place has side 0), then the Djinn recovery list with each owner given the unit id the opponent knows them by.
UNUSED u8 * Text_CopyFiveCharsPaddingUnderscore (u32 unused0, u32 unused1, u16 *source)
 Copies four characters of a name and a terminator, an underscore for each missing character, and returns a pointer to the terminator.
s32 BattlePres_WaitSync (void)
 In a link battle, shows the "EXEC" signature to the other console and waits up to 30 frames for it to show the same.
s32 BattlePres_SyncTurn (void)
 In a link battle, after each action and after the end of each round, steps both consoles through the same handshake: "ex" "TU", then "rn", "EXEC", "tu" and finally "RN".
s32 BattleParty_AssignMemberSlots (void)
 Records, for each party member, the unit id the link opponent knows them by (FIRST_ENEMY_UNIT plus their place in the party), in gBattleWork->ownerSlots.
s32 Battle_ClearSerialTransferPayload (void)
 Clears the link transfer's payload, the signatures included.

Detailed Description

Link battles: the parties and Djinn exchanged, and the turn handshake.

Part of battle.c, the battle object, compiled only through it.

Definition in file link.c.

Macro Definition Documentation

◆ NAME_LIMIT

#define NAME_LIMIT   4

Definition at line 14 of file link.c.

Referenced by LinkBattle_ReceiveParty().

◆ APPEND_NAME_SPACE

#define APPEND_NAME_SPACE   0

Definition at line 15 of file link.c.

Enumeration Type Documentation

◆ LinkPartyPacketSize

What a link battle sends of each party member, and of the Djinn recovery list.

Enumerator
LINK_PARTY_UNIT_BYTES 
LINK_PARTY_OFFER_BYTES 

Definition at line 20 of file link.c.

Function Documentation

◆ LinkBattle_ReceiveParty()

s32 LinkBattle_ReceiveParty ( void )

Link battle: receives the opponent's party into the enemy units, one member at a time, and puts the "Enemy" label (MsgEnemyLabel) before each name; then receives the opponent's Djinn recovery list.

Stops early if a transfer cannot start. Returns how many of the received units are members (a unit sent with side 0 is an empty place). Nothing in the source calls it. Overwrites enemy units 128 to 130 and the opponent's recovery table.

Definition at line 32 of file link.c.

Referenced by LinkBattle_ReceiveParty().

◆ LinkBattle_SendParty()

s32 LinkBattle_SendParty ( void )

Link battle: sends the party, one member at a time and three places in all (an empty place has side 0), then the Djinn recovery list with each owner given the unit id the opponent knows them by.

Records that id of each member in gBattleWork->ownerSlots (0xff for none). Nothing in the source calls it.

Definition at line 102 of file link.c.

Referenced by LinkBattle_SendParty().

◆ Text_CopyFiveCharsPaddingUnderscore()

UNUSED u8 * Text_CopyFiveCharsPaddingUnderscore ( u32 unused0,
u32 unused1,
u16 * source )

Copies four characters of a name and a terminator, an underscore for each missing character, and returns a pointer to the terminator.

UBFIX keeps the private scratch buffer valid until the next call; the original returns a pointer to expired stack storage. The first two arguments are ignored. Nothing calls it.

Definition at line 170 of file link.c.

Referenced by Text_CopyFiveCharsPaddingUnderscore().

◆ BattlePres_WaitSync()

s32 BattlePres_WaitSync ( void )

In a link battle, shows the "EXEC" signature to the other console and waits up to 30 frames for it to show the same.

Returns 0 once both do (or outside a link battle), and -1 if the battle is paused, the link is lost for more than LINK_MAX_MISSED_FRAMES frames or the signatures never meet. Called by BattlePresentation_BuildActions. Writes the first eight bytes of gSerialTransfer.payload.

Definition at line 207 of file link.c.

Referenced by BattlePres_WaitSync(), and BattlePresentation_BuildActions().

◆ BattlePres_SyncTurn()

s32 BattlePres_SyncTurn ( void )

In a link battle, after each action and after the end of each round, steps both consoles through the same handshake: "ex" "TU", then "rn", "EXEC", "tu" and finally "RN".

Each step shows its signature and waits for the other console to show it too, failing if the other console shows a different earlier step. Returns -1 if the battle is paused, the link is lost for more than LINK_MAX_MISSED_FRAMES frames, or the steps disagree; 0 once in step, or outside a link battle. Called by Battle_RunEncounter. Writes the first sixteen bytes of gSerialTransfer.payload.

Definition at line 255 of file link.c.

Referenced by Battle_RunEncounter(), and BattlePres_SyncTurn().

◆ BattleParty_AssignMemberSlots()

s32 BattleParty_AssignMemberSlots ( void )

Records, for each party member, the unit id the link opponent knows them by (FIRST_ENEMY_UNIT plus their place in the party), in gBattleWork->ownerSlots.

Called by Battle_RunEncounter as a link battle is set up.

Definition at line 371 of file link.c.

Referenced by Battle_RunEncounter(), and BattleParty_AssignMemberSlots().

◆ Battle_ClearSerialTransferPayload()

s32 Battle_ClearSerialTransferPayload ( void )

Clears the link transfer's payload, the signatures included.

Called by Battle_RunEncounter on each way out of the battle but fleeing.

Definition at line 388 of file link.c.

Referenced by Battle_ClearSerialTransferPayload(), and Battle_RunEncounter().