From bf61de01a75c67e2003405c3a07f948ba4799751 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 31 Aug 2020 13:36:48 -0400 Subject: Start documenting battle factory screen --- src/battle_factory.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'src/battle_factory.c') diff --git a/src/battle_factory.c b/src/battle_factory.c index 940e71f7d..8a94dff0c 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -26,8 +26,8 @@ static void InitFactoryChallenge(void); static void GetBattleFactoryData(void); static void SetBattleFactoryData(void); static void SaveFactoryChallenge(void); -static void nullsub_75(void); -static void nullsub_123(void); +static void FactoryDummy1(void); +static void FactoryDummy2(void); static void SelectInitialRentalMons(void); static void SwapRentalMons(void); static void SetPerformedRentalSwap(void); @@ -42,8 +42,16 @@ static void RestorePlayerPartyHeldItems(void); static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 arg2); static u8 GetMoveBattleStyle(u16 move); -// Const rom data. -static const u8 sRequiredMoveCounts[] = {3, 3, 3, 2, 2, 2, 2}; +// Number of moves needed on the team to be considered using a certain battle style +static const u8 sRequiredMoveCounts[FACTORY_NUM_STYLES - 1] = { + [FACTORY_STYLE_PREPARATION - 1] = 3, + [FACTORY_STYLE_SLOW_STEADY - 1] = 3, + [FACTORY_STYLE_ENDURANCE - 1] = 3, + [FACTORY_STYLE_HIGH_RISK - 1] = 2, + [FACTORY_STYLE_WEAKENING - 1] = 2, + [FACTORY_STYLE_UNPREDICTABLE - 1] = 2, + [FACTORY_STYLE_WEATHER - 1] = 2 +}; static const u16 sMoves_TotalPreparation[] = { @@ -120,8 +128,8 @@ static void (* const sBattleFactoryFunctions[])(void) = [BATTLE_FACTORY_FUNC_GET_DATA] = GetBattleFactoryData, [BATTLE_FACTORY_FUNC_SET_DATA] = SetBattleFactoryData, [BATTLE_FACTORY_FUNC_SAVE] = SaveFactoryChallenge, - [BATTLE_FACTORY_FUNC_NULL] = nullsub_75, - [BATTLE_FACTORY_FUNC_NULL2] = nullsub_123, + [BATTLE_FACTORY_FUNC_NULL] = FactoryDummy1, + [BATTLE_FACTORY_FUNC_NULL2] = FactoryDummy2, [BATTLE_FACTORY_FUNC_SELECT_RENT_MONS] = SelectInitialRentalMons, [BATTLE_FACTORY_FUNC_SWAP_RENT_MONS] = SwapRentalMons, [BATTLE_FACTORY_FUNC_SET_SWAPPED] = SetPerformedRentalSwap, @@ -267,12 +275,12 @@ static void SaveFactoryChallenge(void) SaveGameFrontier(); } -static void nullsub_75(void) +static void FactoryDummy1(void) { } -static void nullsub_123(void) +static void FactoryDummy2(void) { } @@ -377,10 +385,10 @@ static void SetRentalsToOpponentParty(void) for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { - gSaveBlock2Ptr->frontier.rentalMons[i + 3].monId = gUnknown_03006298[i]; - gSaveBlock2Ptr->frontier.rentalMons[i + 3].ivs = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ATK_IV, NULL); - gSaveBlock2Ptr->frontier.rentalMons[i + 3].personality = GetMonData(&gEnemyParty[i], MON_DATA_PERSONALITY, NULL); - gSaveBlock2Ptr->frontier.rentalMons[i + 3].abilityNum = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ABILITY_NUM, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId = gUnknown_03006298[i]; + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ATK_IV, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].personality = GetMonData(&gEnemyParty[i], MON_DATA_PERSONALITY, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].abilityNum = GetBoxMonData(&gEnemyParty[i].box, MON_DATA_ABILITY_NUM, NULL); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[gUnknown_03006298[i]].itemTableId]); } } @@ -456,13 +464,13 @@ static void SetPlayerAndOpponentParties(void) case 2: for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { - monId = gSaveBlock2Ptr->frontier.rentalMons[i + 3].monId; - ivs = gSaveBlock2Ptr->frontier.rentalMons[i + 3].ivs; + monId = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].monId; + ivs = gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].ivs; CreateMon(&gEnemyParty[i], gFacilityTrainerMons[monId].species, monLevel, ivs, - TRUE, gSaveBlock2Ptr->frontier.rentalMons[i + 3].personality, + TRUE, gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].personality, OT_ID_PLAYER_ID, 0); count = 0; @@ -485,7 +493,7 @@ static void SetPlayerAndOpponentParties(void) for (k = 0; k < MAX_MON_MOVES; k++) SetMonMoveAvoidReturn(&gEnemyParty[i], gFacilityTrainerMons[monId].moves[k], k); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monId].itemTableId]); - SetMonData(&gEnemyParty[i], MON_DATA_ABILITY_NUM, &gSaveBlock2Ptr->frontier.rentalMons[i + 3].abilityNum); + SetMonData(&gEnemyParty[i], MON_DATA_ABILITY_NUM, &gSaveBlock2Ptr->frontier.rentalMons[i + FRONTIER_PARTY_SIZE].abilityNum); } break; } @@ -640,7 +648,7 @@ static void GetOpponentBattleStyle(void) } } - gSpecialVar_Result = 0; + gSpecialVar_Result = FACTORY_STYLE_NONE; for (i = 1; i < FACTORY_NUM_STYLES; i++) { if (stylePoints[i] >= sRequiredMoveCounts[i - 1]) -- cgit v1.2.3 From 200e8214cf6cb9b69e7e619bb7263d70896eb03b Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 28 Feb 2021 10:43:56 -0600 Subject: Document GetOpponentMostCommonMonType and fix its fake matching --- src/battle_factory.c | 53 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'src/battle_factory.c') diff --git a/src/battle_factory.c b/src/battle_factory.c index 9ba13b0d3..72772929a 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -592,39 +592,58 @@ static void GenerateInitialRentalMons(void) } } +// Determines if the upcoming opponent has a single most-common +// type in its party. If there are two different types that are +// tied, then the opponent is deemed to have no preferred type, +// and NUMBER_OF_MON_TYPES is the result. static void GetOpponentMostCommonMonType(void) { u8 i; - u8 typesCount[NUMBER_OF_MON_TYPES]; - u8 usedType[2]; + u8 typeCounts[NUMBER_OF_MON_TYPES]; + u8 mostCommonTypes[2]; gFacilityTrainerMons = gBattleFrontierMons; - for (i = 0; i < NUMBER_OF_MON_TYPES; i++) - typesCount[i] = 0; + + // Count the number of times each type occurs in the opponent's party. + for (i = TYPE_NORMAL; i < NUMBER_OF_MON_TYPES; i++) + typeCounts[i] = 0; for (i = 0; i < FRONTIER_PARTY_SIZE; i++) { u32 species = gFacilityTrainerMons[gFrontierTempParty[i]].species; - - typesCount[gBaseStats[species].type1]++; + typeCounts[gBaseStats[species].type1]++; if (gBaseStats[species].type1 != gBaseStats[species].type2) - typesCount[gBaseStats[species].type2]++; + typeCounts[gBaseStats[species].type2]++; } - usedType[0] = 0; - usedType[1] = 0; - for (i = 1; i < NUMBER_OF_MON_TYPES; i++) + // Determine which are the two most-common types. + // The second most-common type is only updated if + // its count is equal to the most-common type. + mostCommonTypes[0] = TYPE_NORMAL; + mostCommonTypes[1] = TYPE_NORMAL; + for (i = TYPE_FIGHTING; i < NUMBER_OF_MON_TYPES; i++) { - if (typesCount[usedType[0]] < typesCount[i]) - usedType[0] = i; - else if (typesCount[usedType[0]] == typesCount[i]) - usedType[1] = i; + if (typeCounts[mostCommonTypes[0]] < typeCounts[i]) + mostCommonTypes[0] = i; + else if (typeCounts[mostCommonTypes[0]] == typeCounts[i]) + mostCommonTypes[1] = i; } - gSpecialVar_Result = gSpecialVar_Result; // Needed to match. Don't ask me why. - if (typesCount[usedType[0]] != 0 && (typesCount[usedType[0]] > typesCount[usedType[1]] || usedType[0] == usedType[1])) - gSpecialVar_Result = usedType[0]; + if (typeCounts[mostCommonTypes[0]] != 0) + { + // The most-common type must be strictly greater than + // the second-most-common type, or the top two must be + // the same type. + if (typeCounts[mostCommonTypes[0]] > typeCounts[mostCommonTypes[1]]) + gSpecialVar_Result = mostCommonTypes[0]; + else if (mostCommonTypes[0] == mostCommonTypes[1]) + gSpecialVar_Result = mostCommonTypes[0]; + else + gSpecialVar_Result = NUMBER_OF_MON_TYPES; + } else + { gSpecialVar_Result = NUMBER_OF_MON_TYPES; + } } static void GetOpponentBattleStyle(void) -- cgit v1.2.3 From c9c558606899f898c7b14ad4a35f19ce2831d66a Mon Sep 17 00:00:00 2001 From: gAlfonso-bit <83477269+gAlfonso-bit@users.noreply.github.com> Date: Thu, 27 May 2021 08:32:09 -0400 Subject: =?UTF-8?q?Fixed=20ChangeBgY=5FScreenOff=E2=80=98s=20signature.=20?= =?UTF-8?q?(#1447)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Functions * Fix ChangeBgY_ScreenOff signature * Remove unneeded changes * Fix argument mismatch Just to get this out of the way * Not needed * Update palette.c --- src/battle_factory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/battle_factory.c') diff --git a/src/battle_factory.c b/src/battle_factory.c index 72772929a..e0bfdfdd0 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -38,7 +38,7 @@ static void GenerateInitialRentalMons(void); static void GetOpponentMostCommonMonType(void); static void GetOpponentBattleStyle(void); static void RestorePlayerPartyHeldItems(void); -static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 arg2); +static u16 GetFactoryMonId(u8 lvlMode, u8 challengeNum, bool8 useBetterRange); static u8 GetMoveBattleStyle(u16 move); // Number of moves needed on the team to be considered using a certain battle style -- cgit v1.2.3