More documentation in battle_main

This commit is contained in:
PikalaxALT 2021-03-12 16:55:58 -05:00
parent e32a1571af
commit 8d4dcb228a
5 changed files with 61 additions and 53 deletions

View File

@ -346,8 +346,8 @@ struct BattleTvMovePoints
struct MultiPartnerEnigmaBerry struct MultiPartnerEnigmaBerry
{ {
u8 field_0; u8 versionSignatureLo;
u8 field_1; u8 versionSignatureHi;
u8 vsScreenHealthFlagsLo; u8 vsScreenHealthFlagsLo;
u8 vsScreenHealthFlagsHi; u8 vsScreenHealthFlagsHi;
struct BattleEnigmaBerry battleEnigmaBerry; struct BattleEnigmaBerry battleEnigmaBerry;

View File

@ -37,7 +37,7 @@ struct Main
/*0x439*/ u8 oamLoadDisabled:1; /*0x439*/ u8 oamLoadDisabled:1;
/*0x439*/ u8 inBattle:1; /*0x439*/ u8 inBattle:1;
/*0x439*/ u8 field_439_x4:1; /*0x439*/ u8 isFrontierBattle:1;
}; };
extern const u8 gGameVersion; extern const u8 gGameVersion;

View File

@ -22,9 +22,9 @@ u8 GetRecordedBattleFrontierFacility(void);
u8 GetRecordedBattleFronterBrainSymbol(void); u8 GetRecordedBattleFronterBrainSymbol(void);
void RecordedBattle_SaveParties(void); void RecordedBattle_SaveParties(void);
u8 GetActiveBattlerLinkPlayerGender(void); u8 GetActiveBattlerLinkPlayerGender(void);
void sub_8185F84(void); void RecordedBattle_ClearFrontierPassFlag(void);
void sub_8185F90(u16 arg0); void RecordedBattle_SetFrontierPassFlagFromHword(u16 arg0);
u8 sub_8185FAC(void); u8 RecordedBattle_GetFrontierPassFlag(void);
u8 GetBattleSceneInRecordedBattle(void); u8 GetBattleSceneInRecordedBattle(void);
u8 GetTextSpeedInRecordedBattle(void); u8 GetTextSpeedInRecordedBattle(void);
void RecordedBattle_CopyBattlerMoves(void); void RecordedBattle_CopyBattlerMoves(void);

View File

@ -576,7 +576,7 @@ void CB2_InitBattle(void)
AllocateBattleResources(); AllocateBattleResources();
AllocateBattleSpritesData(); AllocateBattleSpritesData();
AllocateMonSpritesGfx(); AllocateMonSpritesGfx();
sub_8185F84(); RecordedBattle_ClearFrontierPassFlag();
if (gBattleTypeFlags & BATTLE_TYPE_MULTI) if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
{ {
@ -882,52 +882,56 @@ static void SetAllPlayersBerryData(void)
} }
} }
static void sub_8036EB8(u8 arg0, u8 arg1) // This was inlined in Ruby/Sapphire
static void FindLinkBattleMaster(u8 numPlayers, u8 multiPlayerId)
{ {
u8 var = 0; u8 found = 0;
if (gBlockRecvBuffer[0][0] == 256) // If player 1 is playing the minimum version, player 1 is master.
if (gBlockRecvBuffer[0][0] == 0x100)
{ {
if (arg1 == 0) if (multiPlayerId == 0)
gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER;
else else
gBattleTypeFlags |= BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_TRAINER;
var++; found++;
} }
if (var == 0) if (found == 0)
{ {
// If multiple different versions are being used, player 1 is master.
s32 i; s32 i;
for (i = 0; i < arg0; i++) for (i = 0; i < numPlayers; i++)
{ {
if (gBlockRecvBuffer[0][0] != gBlockRecvBuffer[i][0]) if (gBlockRecvBuffer[0][0] != gBlockRecvBuffer[i][0])
break; break;
} }
if (i == arg0) if (i == numPlayers)
{ {
if (arg1 == 0) if (multiPlayerId == 0)
gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER;
else else
gBattleTypeFlags |= BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_TRAINER;
var++; found++;
} }
if (var == 0) if (found == 0)
{ {
for (i = 0; i < arg0; i++) // Lowest index player with the highest game version is master.
for (i = 0; i < numPlayers; i++)
{ {
if (gBlockRecvBuffer[i][0] == 0x300) if (gBlockRecvBuffer[i][0] == 0x300 && i != multiPlayerId)
{ {
if (i != arg1 && i < arg1) if (i < multiPlayerId)
break; break;
} }
if (gBlockRecvBuffer[i][0] > 0x300 && i != arg1) if (gBlockRecvBuffer[i][0] > 0x300 && i != multiPlayerId)
break; break;
} }
if (i == arg0) if (i == numPlayers)
gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_IS_MASTER | BATTLE_TYPE_TRAINER;
else else
gBattleTypeFlags |= BATTLE_TYPE_TRAINER; gBattleTypeFlags |= BATTLE_TYPE_TRAINER;
@ -970,8 +974,9 @@ static void CB2_HandleStartBattle(void)
{ {
if (IsLinkTaskFinished()) if (IsLinkTaskFinished())
{ {
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; // 0x300
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0;
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3;
BufferPartyVsScreenHealth_AtStart(); BufferPartyVsScreenHealth_AtStart();
SetPlayerBerryDataInBattleStruct(); SetPlayerBerryDataInBattleStruct();
@ -1002,7 +1007,7 @@ static void CB2_HandleStartBattle(void)
u8 taskId; u8 taskId;
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
sub_8036EB8(2, playerMultiplayerId); FindLinkBattleMaster(2, playerMultiplayerId);
SetAllPlayersBerryData(); SetAllPlayersBerryData();
taskId = CreateTask(InitLinkBattleVsScreen, 0); taskId = CreateTask(InitLinkBattleVsScreen, 0);
gTasks[taskId].data[1] = 0x10E; gTasks[taskId].data[1] = 0x10E;
@ -1010,8 +1015,8 @@ static void CB2_HandleStartBattle(void)
gTasks[taskId].data[5] = 0; gTasks[taskId].data[5] = 0;
gTasks[taskId].data[3] = gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi << 8); gTasks[taskId].data[3] = gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsLo | (gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.vsScreenHealthFlagsHi << 8);
gTasks[taskId].data[4] = gBlockRecvBuffer[enemyMultiplayerId][1]; gTasks[taskId].data[4] = gBlockRecvBuffer[enemyMultiplayerId][1];
sub_8185F90(gBlockRecvBuffer[playerMultiplayerId][1]); RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[playerMultiplayerId][1]);
sub_8185F90(gBlockRecvBuffer[enemyMultiplayerId][1]); RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[enemyMultiplayerId][1]);
SetDeoxysStats(); SetDeoxysStats();
gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[MULTIUSE_STATE]++;
} }
@ -1178,8 +1183,9 @@ static void CB2_HandleStartMultiPartnerBattle(void)
if (IsLinkTaskFinished()) if (IsLinkTaskFinished())
{ {
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; // 0x300
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0;
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3;
BufferPartyVsScreenHealth_AtStart(); BufferPartyVsScreenHealth_AtStart();
SetPlayerBerryDataInBattleStruct(); SetPlayerBerryDataInBattleStruct();
SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry)); SendBlock(bitmask_all_link_players_but_self(), &gBattleStruct->multiBuffer.multiPartnerEnigmaBerry, sizeof(gBattleStruct->multiBuffer.multiPartnerEnigmaBerry));
@ -1204,7 +1210,7 @@ static void CB2_HandleStartMultiPartnerBattle(void)
u8 taskId; u8 taskId;
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
sub_8036EB8(2, playerMultiplayerId); FindLinkBattleMaster(2, playerMultiplayerId);
SetAllPlayersBerryData(); SetAllPlayersBerryData();
taskId = CreateTask(InitLinkBattleVsScreen, 0); taskId = CreateTask(InitLinkBattleVsScreen, 0);
gTasks[taskId].data[1] = 0x10E; gTasks[taskId].data[1] = 0x10E;
@ -1565,8 +1571,9 @@ static void CB2_HandleStartMultiBattle(void)
{ {
if (IsLinkTaskFinished()) if (IsLinkTaskFinished())
{ {
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_0) = 0; // 0x300
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.field_1) = 3; *(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureLo) = 0;
*(&gBattleStruct->multiBuffer.multiPartnerEnigmaBerry.versionSignatureHi) = 3;
BufferPartyVsScreenHealth_AtStart(); BufferPartyVsScreenHealth_AtStart();
SetPlayerBerryDataInBattleStruct(); SetPlayerBerryDataInBattleStruct();
@ -1589,7 +1596,7 @@ static void CB2_HandleStartMultiBattle(void)
if ((GetBlockReceivedStatus() & 0xF) == 0xF) if ((GetBlockReceivedStatus() & 0xF) == 0xF)
{ {
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
sub_8036EB8(4, playerMultiplayerId); FindLinkBattleMaster(4, playerMultiplayerId);
SetAllPlayersBerryData(); SetAllPlayersBerryData();
SetDeoxysStats(); SetDeoxysStats();
var = CreateTask(InitLinkBattleVsScreen, 0); var = CreateTask(InitLinkBattleVsScreen, 0);
@ -1601,7 +1608,7 @@ static void CB2_HandleStartMultiBattle(void)
for (id = 0; id < MAX_LINK_PLAYERS; id++) for (id = 0; id < MAX_LINK_PLAYERS; id++)
{ {
sub_8185F90(gBlockRecvBuffer[id][1]); RecordedBattle_SetFrontierPassFlagFromHword(gBlockRecvBuffer[id][1]);
switch (gLinkPlayers[id].id) switch (gLinkPlayers[id].id)
{ {
case 0: case 0:
@ -2248,7 +2255,7 @@ static void EndLinkBattleInSteps(void)
{ {
u8 monsCount; u8 monsCount;
gMain.field_439_x4 = sub_8185FAC(); gMain.isFrontierBattle = RecordedBattle_GetFrontierPassFlag();
if (gBattleTypeFlags & BATTLE_TYPE_MULTI) if (gBattleTypeFlags & BATTLE_TYPE_MULTI)
monsCount = 4; monsCount = 4;
@ -2264,7 +2271,7 @@ static void EndLinkBattleInSteps(void)
FreeAllWindowBuffers(); FreeAllWindowBuffers();
SetMainCallback2(sub_80392A8); SetMainCallback2(sub_80392A8);
} }
else if (!gMain.field_439_x4) else if (!gMain.isFrontierBattle)
{ {
SetMainCallback2(gMain.savedCallback); SetMainCallback2(gMain.savedCallback);
FreeBattleResources(); FreeBattleResources();
@ -2328,9 +2335,9 @@ static void EndLinkBattleInSteps(void)
gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[MULTIUSE_STATE]++;
break; break;
case 9: case 9:
if (!gMain.field_439_x4 || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1)
{ {
gMain.field_439_x4 = 0; gMain.isFrontierBattle = 0;
SetMainCallback2(gMain.savedCallback); SetMainCallback2(gMain.savedCallback);
FreeBattleResources(); FreeBattleResources();
FreeBattleSpritesData(); FreeBattleSpritesData();
@ -2426,7 +2433,7 @@ static void sub_803939C(void)
gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[MULTIUSE_STATE]++;
break; break;
case 1: case 1:
if (gMain.field_439_x4 && gReceivedRemoteLinkPlayers == 0) if (gMain.isFrontierBattle && gReceivedRemoteLinkPlayers == 0)
CreateTask(Task_ReconnectWithLinkPlayers, 5); CreateTask(Task_ReconnectWithLinkPlayers, 5);
gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[MULTIUSE_STATE]++;
break; break;
@ -2496,7 +2503,7 @@ static void sub_803939C(void)
if (IsLinkTaskFinished() == TRUE) if (IsLinkTaskFinished() == TRUE)
{ {
HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR);
if (gMain.field_439_x4) if (gMain.isFrontierBattle)
{ {
SetLinkStandbyCallback(); SetLinkStandbyCallback();
BattlePutTextOnWindow(gText_LinkStandby3, 0); BattlePutTextOnWindow(gText_LinkStandby3, 0);
@ -2507,15 +2514,15 @@ static void sub_803939C(void)
case 8: case 8:
if (--gBattleCommunication[1] == 0) if (--gBattleCommunication[1] == 0)
{ {
if (gMain.field_439_x4 && !gWirelessCommType) if (gMain.isFrontierBattle && !gWirelessCommType)
SetCloseLinkCallback(); SetCloseLinkCallback();
gBattleCommunication[MULTIUSE_STATE]++; gBattleCommunication[MULTIUSE_STATE]++;
} }
break; break;
case 9: case 9:
if (!gMain.field_439_x4 || gWirelessCommType || gReceivedRemoteLinkPlayers != 1) if (!gMain.isFrontierBattle || gWirelessCommType || gReceivedRemoteLinkPlayers != 1)
{ {
gMain.field_439_x4 = 0; gMain.isFrontierBattle = 0;
if (!gPaletteFade.active) if (!gPaletteFade.active)
{ {
SetMainCallback2(gMain.savedCallback); SetMainCallback2(gMain.savedCallback);
@ -2545,7 +2552,7 @@ static void sub_803939C(void)
case 11: case 11:
if (IsLinkTaskFinished() == TRUE && !IsTextPrinterActive(0) && --gBattleCommunication[1] == 0) if (IsLinkTaskFinished() == TRUE && !IsTextPrinterActive(0) && --gBattleCommunication[1] == 0)
{ {
if (gMain.field_439_x4) if (gMain.isFrontierBattle)
{ {
SetLinkStandbyCallback(); SetLinkStandbyCallback();
BattlePutTextOnWindow(gText_LinkStandby3, 0); BattlePutTextOnWindow(gText_LinkStandby3, 0);
@ -2557,7 +2564,7 @@ static void sub_803939C(void)
case 7: case 7:
if (!IsTextPrinterActive(0)) if (!IsTextPrinterActive(0))
{ {
if (gMain.field_439_x4) if (gMain.isFrontierBattle)
{ {
if (IsLinkTaskFinished() == TRUE) if (IsLinkTaskFinished() == TRUE)
{ {

View File

@ -84,7 +84,7 @@ EWRAM_DATA static u8 sFrontierFacility = 0;
EWRAM_DATA static u8 sFrontierBrainSymbol = 0; EWRAM_DATA static u8 sFrontierBrainSymbol = 0;
EWRAM_DATA static MainCallback sCallback2_AfterRecordedBattle = NULL; EWRAM_DATA static MainCallback sCallback2_AfterRecordedBattle = NULL;
EWRAM_DATA u8 gRecordedBattleMultiplayerId = 0; EWRAM_DATA u8 gRecordedBattleMultiplayerId = 0;
EWRAM_DATA static u8 sUnknown_0203C7B5 = 0; EWRAM_DATA static u8 sFrontierPassFlag = 0;
EWRAM_DATA static u8 sBattleScene = 0; EWRAM_DATA static u8 sBattleScene = 0;
EWRAM_DATA static u8 sTextSpeed = 0; EWRAM_DATA static u8 sTextSpeed = 0;
EWRAM_DATA static u32 sBattleFlags = 0; EWRAM_DATA static u32 sBattleFlags = 0;
@ -687,19 +687,20 @@ u8 GetActiveBattlerLinkPlayerGender(void)
return 0; return 0;
} }
void sub_8185F84(void) void RecordedBattle_ClearFrontierPassFlag(void)
{ {
sUnknown_0203C7B5 = 0; sFrontierPassFlag = 0;
} }
void sub_8185F90(u16 arg0) // Set sFrontierPassFlag to received state of FLAG_SYS_FRONTIER_PASS
void RecordedBattle_SetFrontierPassFlagFromHword(u16 arg0)
{ {
sUnknown_0203C7B5 |= (arg0 & 0x8000) >> 0xF; sFrontierPassFlag |= (arg0 & 0x8000) >> 15;
} }
u8 sub_8185FAC(void) u8 RecordedBattle_GetFrontierPassFlag(void)
{ {
return sUnknown_0203C7B5; return sFrontierPassFlag;
} }
u8 GetBattleSceneInRecordedBattle(void) u8 GetBattleSceneInRecordedBattle(void)