summaryrefslogtreecommitdiff
path: root/src/trade.c
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-10-15 22:44:49 -0400
committerGitHub <noreply@github.com>2021-10-15 22:44:49 -0400
commit1f39c34ca47e43b0afccaabe97d1df19e3f0b39b (patch)
treec3d4cac1627512d166440ead47d9f2285c8b4044 /src/trade.c
parentb01213b8bc0e4f82a0ab7505b4fe7db2e2d0ddf2 (diff)
parenta4a3c1c9e5a0026415330eab9bea2f8f3e83e0a3 (diff)
Merge branch 'master' into minor-constants
Diffstat (limited to 'src/trade.c')
-rw-r--r--src/trade.c88
1 files changed, 30 insertions, 58 deletions
diff --git a/src/trade.c b/src/trade.c
index 526a9ac39..d1fc14efe 100644
--- a/src/trade.c
+++ b/src/trade.c
@@ -274,7 +274,7 @@ static bool32 IsLinkTradeTaskFinished(void)
{
if (gPlayerCurrActivity == ACTIVITY_29)
{
- if (gRfuSlotStatusNI[sub_800E87C(lman.acceptSlot_flag)]->send.state == 0)
+ if (gRfuSlotStatusNI[Rfu_GetIndexOfNewestChild(lman.acceptSlot_flag)]->send.state == 0)
return TRUE;
else
return FALSE;
@@ -459,7 +459,7 @@ static void CB2_CreateTradeMenu(void)
sTradeMenuData->timer = 0;
if (gWirelessCommType)
{
- sub_801048C(TRUE);
+ Rfu_SetLinkRecovery(TRUE);
SetLinkStandbyCallback();
}
}
@@ -1008,9 +1008,7 @@ static bool8 BufferTradeParties(void)
break;
case 3:
if (id == 0)
- {
- RequestLinkData(1);
- }
+ RequestLinkData(BLOCK_REQ_SIZE_200);
sTradeMenuData->bufferPartyState++;
break;
case 4:
@@ -1027,9 +1025,7 @@ static bool8 BufferTradeParties(void)
break;
case 7:
if (id == 0)
- {
- RequestLinkData(1);
- }
+ RequestLinkData(BLOCK_REQ_SIZE_200);
sTradeMenuData->bufferPartyState++;
break;
case 8:
@@ -1046,9 +1042,7 @@ static bool8 BufferTradeParties(void)
break;
case 11:
if (id == 0)
- {
- RequestLinkData(1);
- }
+ RequestLinkData(BLOCK_REQ_SIZE_200);
sTradeMenuData->bufferPartyState++;
break;
case 12:
@@ -1065,9 +1059,7 @@ static bool8 BufferTradeParties(void)
break;
case 15:
if (id == 0)
- {
- RequestLinkData(3);
- }
+ RequestLinkData(BLOCK_REQ_SIZE_220);
sTradeMenuData->bufferPartyState++;
break;
case 16:
@@ -1084,9 +1076,7 @@ static bool8 BufferTradeParties(void)
break;
case 19:
if (id == 0)
- {
- RequestLinkData(4);
- }
+ RequestLinkData(BLOCK_REQ_SIZE_40);
sTradeMenuData->bufferPartyState++;
break;
case 20:
@@ -1719,7 +1709,7 @@ static void CancelTrade_2(void)
static void LinkTradeWaitForQueue(void)
{
- if (!sub_801048C(FALSE) && GetNumQueuedActions() == 0)
+ if (!Rfu_SetLinkRecovery(FALSE) && GetNumQueuedActions() == 0)
{
SetLinkStandbyCallback();
sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_START_LINK_TRADE;
@@ -2448,80 +2438,70 @@ static bool32 IsDeoxysOrMewUntradable(u16 species, bool8 isEventLegal)
return FALSE;
}
-int GetUnionRoomTradeMessageId(struct GFtgtGnameSub rfuPlayer, struct GFtgtGnameSub rfuPartner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isEventLegal)
+int GetUnionRoomTradeMessageId(struct RfuGameCompatibilityData player, struct RfuGameCompatibilityData partner, u16 playerSpecies2, u16 partnerSpecies, u8 requestedType, u16 playerSpecies, u8 isEventLegal)
{
- bool8 playerHasNationalDex = rfuPlayer.hasNationalDex;
- bool8 playerIsChampion = rfuPlayer.isChampion;
- bool8 partnerHasNationalDex = rfuPartner.hasNationalDex;
- bool8 partnerIsChampion = rfuPartner.isChampion;
- u8 r1 = rfuPartner.version;
+ bool8 playerHasNationalDex = player.hasNationalDex;
+ bool8 playerIsChampion = player.isChampion;
+ bool8 partnerHasNationalDex = partner.hasNationalDex;
+ bool8 partnerIsChampion = partner.isChampion;
+ u8 partnerVersion = partner.version;
- if (r1 != VERSION_EMERALD)
+ // If partner is not using Emerald, both players must be champion
+ if (partnerVersion != VERSION_EMERALD)
{
if (!playerIsChampion)
- {
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_1;
- }
else if (!partnerIsChampion)
- {
return UR_TRADE_MSG_CANT_TRADE_WITH_PARTNER_2;
- }
}
+ // Cannot trade illegitimate Deoxys/Mew
if (IsDeoxysOrMewUntradable(playerSpecies, isEventLegal))
- {
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
- }
if (partnerSpecies == SPECIES_EGG)
{
+ // If partner is trading an Egg then the player must also be trading an Egg
if (playerSpecies2 != partnerSpecies)
- {
return UR_TRADE_MSG_NOT_EGG;
- }
}
else
{
- if (gBaseStats[playerSpecies2].type1 != requestedType && gBaseStats[playerSpecies2].type2 != requestedType)
- {
+ // Player's Pokémon must be of the type the partner requested
+ if (gBaseStats[playerSpecies2].type1 != requestedType
+ && gBaseStats[playerSpecies2].type2 != requestedType)
return UR_TRADE_MSG_NOT_MON_PARTNER_WANTS;
- }
}
+ // If the player is trading an Egg then the partner must also be trading an Egg
+ // Odd that this wasn't checked earlier, as by this point we know either the partner doesn't have an Egg or that both do.
if (playerSpecies2 == SPECIES_EGG && playerSpecies2 != partnerSpecies)
- {
return UR_TRADE_MSG_MON_CANT_BE_TRADED_1;
- }
+ // If the player doesn't have the National Dex then Eggs and non-Hoenn Pokémon can't be traded
if (!playerHasNationalDex)
{
if (playerSpecies2 == SPECIES_EGG)
- {
return UR_TRADE_MSG_EGG_CANT_BE_TRADED;
- }
if (!IsSpeciesInHoennDex(playerSpecies2))
- {
return UR_TRADE_MSG_MON_CANT_BE_TRADED_2;
- }
if (!IsSpeciesInHoennDex(partnerSpecies))
- {
return UR_TRADE_MSG_PARTNERS_MON_CANT_BE_TRADED;
- }
}
+ // If the partner doesn't have the National Dex then the player's offer has to be a Hoenn Pokémon
if (!partnerHasNationalDex && !IsSpeciesInHoennDex(playerSpecies2))
- {
return UR_TRADE_MSG_PARTNER_CANT_ACCEPT_MON;
- }
+ // Trade is allowed
return UR_TRADE_MSG_NONE;
}
-int CanRegisterMonForTradingBoard(struct GFtgtGnameSub rfuPlayer, u16 species2, u16 species, u8 isEventLegal)
+int CanRegisterMonForTradingBoard(struct RfuGameCompatibilityData player, u16 species2, u16 species, u8 isEventLegal)
{
- bool8 hasNationalDex = rfuPlayer.hasNationalDex;
+ bool8 hasNationalDex = player.hasNationalDex;
if (IsDeoxysOrMewUntradable(species, isEventLegal))
return CANT_REGISTER_MON;
@@ -2551,9 +2531,7 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx)
{
speciesArray[i] = GetMonData(&mon[i], MON_DATA_SPECIES2);
if (speciesArray[i] == SPECIES_EGG)
- {
speciesArray[i] = SPECIES_NONE;
- }
}
versions = 0;
@@ -2563,13 +2541,9 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx)
version = gLinkPlayers[i].version & 0xFF;
if (version == VERSION_FIRE_RED ||
version == VERSION_LEAF_GREEN)
- {
versions = 0;
- }
else
- {
versions |= 1;
- }
}
for (i = 0; i < GetLinkPlayerCount(); i++)
@@ -2600,9 +2574,7 @@ int CanSpinTradeMon(struct Pokemon *mon, u16 monIdx)
for (i = 0; i < gPlayerPartyCount; i++)
{
if (monIdx != i)
- {
numMonsLeft += speciesArray[i];
- }
}
if (!numMonsLeft)
@@ -3096,7 +3068,7 @@ static void TrySendTradeFinishData(void)
case 1:
if (IsLinkTaskFinished())
{
- SendBlock(bitmask_all_link_players_but_self(), sTradeData->linkData, sizeof(sTradeData->linkData));
+ SendBlock(BitmaskAllOtherLinkPlayers(), sTradeData->linkData, sizeof(sTradeData->linkData));
sTradeData->sendTradeFinishState++;
}
// fallthrough
@@ -4632,7 +4604,7 @@ static void CB2_TryFinishTrade(void)
&& sTradeData->partnerLinkFlagFinishTrade == READY_FINISH_TRADE)
{
sTradeData->linkData[0] = LINKCMD_CONFIRM_FINISH_TRADE;
- SendBlock(bitmask_all_link_players_but_self(), sTradeData->linkData, sizeof(sTradeData->linkData));
+ SendBlock(BitmaskAllOtherLinkPlayers(), sTradeData->linkData, sizeof(sTradeData->linkData));
sTradeData->playerLinkFlagFinishTrade = FINISH_TRADE;
sTradeData->partnerLinkFlagFinishTrade = FINISH_TRADE;
}