From 1a5d3191e239d1d97ce38005a73ed2c85dafba84 Mon Sep 17 00:00:00 2001 From: kleeenexfeu Date: Tue, 23 Nov 2021 13:38:36 +0100 Subject: [PATCH 1/6] battle_engine merge --- include/constants/battle_config.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 29b7b57503..3180212f88 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -92,9 +92,6 @@ #define GEN_8 5 #endif -// Mega Evolution settings -#define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. - // Calculation settings #define B_CRIT_CHANCE GEN_7 // Chances of a critical hit landing. See CalcCritChanceStage. #define B_CRIT_MULTIPLIER GEN_7 // In Gen6+, critical hits multiply damage by 1.5 instead of 2. @@ -127,13 +124,16 @@ #define B_STEEL_RESISTANCES GEN_7 // In Gen6+, Steel-type Pokémon are no longer resistant to Dark-type and Ghost-type moves. #define B_PRANKSTER_DARK_TYPES GEN_7 // In Gen7+, Prankster-elevated status moves do not affect Dark type Pokémon. -// Turn count settings +// Turn settings #define B_BINDING_TURNS GEN_7 // In Gen5+, binding moves last for 4-5 turns instead of 2-5 turns. (With Grip Claw, 7 and 5 turns respectively.) #define B_UPROAR_TURNS GEN_7 // In Gen5+, Uproar lasts for 3 turns instead of 2-5 turns. #define B_DISABLE_TURNS GEN_7 // Disable's turns. See Cmd_disablelastusedattack. #define B_TAILWIND_TURNS GEN_7 // In Gen5+, Tailwind lasts 4 turns instead of 3. #define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns. #define B_TAUNT_TURNS GEN_7 // In Gen5+, Taunt lasts 3 turns if the user acts before the target, or 4 turns if the target acted before the user. In Gen3, taunt lasts 2 turns and in Gen 4, 3-5 turns. +#define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. +#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In gen 8, switching/using a move have consequences for the turn order of the current turn. + // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc. From 6ceffaaf3e5c0e981c7e81b03de0bdc7c91cf0da Mon Sep 17 00:00:00 2001 From: kleeenexfeu Date: Tue, 23 Nov 2021 13:46:36 +0100 Subject: [PATCH 2/6] recalculate turn order after relevant actions --- include/constants/battle_config.h | 1 - src/battle_util.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 3180212f88..ac3da4dd4e 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -134,7 +134,6 @@ #define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. #define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In gen 8, switching/using a move have consequences for the turn order of the current turn. - // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc. #define B_PHYSICAL_SPECIAL_SPLIT GEN_7 // In Gen3, the move's type determines if it will do physical or special damage. The split icon in the summary will reflect this. diff --git a/src/battle_util.c b/src/battle_util.c index 7e2320500c..7953565a03 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -871,6 +871,11 @@ void HandleAction_NothingIsFainted(void) void HandleAction_ActionFinished(void) { + #if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8 + u8 i, j; + u8 battler1 = 0; + u8 battler2 = 0; + #endif *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; gCurrentTurnActionNumber++; gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; @@ -894,6 +899,31 @@ void HandleAction_ActionFinished(void) gBattleCommunication[4] = 0; gBattleScripting.multihitMoveEffect = 0; gBattleResources->battleScriptsStack->size = 0; + + #if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8 + // i starts at `gCurrentTurnActionNumber` because we don't want to recalculate turn order for mon that have already + // taken action. It's been previously increased, which we want in order to not recalculate the turn of the mon that just finished its action + for (i = gCurrentTurnActionNumber; i < gBattlersCount - 1; i++) + { + for (j = i + 1; j < gBattlersCount; j++) + { + u8 battler1 = gBattlerByTurnOrder[i]; + u8 battler2 = gBattlerByTurnOrder[j]; + // We recalculate order only for action of the same priority. If any action other than switch/move has been taken, they should + // have been executed before. The only recalculation needed is for moves/switch. Mega evolution is handled in src/battle_main.c/TryChangeOrder + if((gActionsByTurnOrder[i] == B_ACTION_USE_MOVE && gActionsByTurnOrder[j] == B_ACTION_USE_MOVE)) + { + if (GetWhoStrikesFirst(battler1, battler2, FALSE)) + SwapTurnOrder(i, j); + } + else if ((gActionsByTurnOrder[i] == B_ACTION_SWITCH && gActionsByTurnOrder[j] == B_ACTION_SWITCH)) + { + if (GetWhoStrikesFirst(battler1, battler2, TRUE)) // If the actions chosen are switching, we recalc order but ignoring the moves + SwapTurnOrder(i, j); + } + } + } + #endif } // rom const data From 1a3561bb0bf4bcb3aa57a8029a3684b2adcfe2c8 Mon Sep 17 00:00:00 2001 From: kleeenexfeu Date: Tue, 23 Nov 2021 13:48:03 +0100 Subject: [PATCH 3/6] space --- src/battle_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_util.c b/src/battle_util.c index 7953565a03..ffe7c0b96f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -875,7 +875,7 @@ void HandleAction_ActionFinished(void) u8 i, j; u8 battler1 = 0; u8 battler2 = 0; - #endif + #endif *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; gCurrentTurnActionNumber++; gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; From 84e6e083f7d9d5830f000f07baf1bf7562c30ec1 Mon Sep 17 00:00:00 2001 From: kleeenexfeu <94004034+kleeenexfeu@users.noreply.github.com> Date: Tue, 23 Nov 2021 14:24:30 +0100 Subject: [PATCH 4/6] hate the explanations about turn order ._. Co-authored-by: Eduardo Quezada D'Ottone --- include/constants/battle_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index ac3da4dd4e..b792a6f723 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -132,7 +132,7 @@ #define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns. #define B_TAUNT_TURNS GEN_7 // In Gen5+, Taunt lasts 3 turns if the user acts before the target, or 4 turns if the target acted before the user. In Gen3, taunt lasts 2 turns and in Gen 4, 3-5 turns. #define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. -#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In gen 8, switching/using a move have consequences for the turn order of the current turn. +#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In Gen8, switching/using a move has consequences over the turn order of the rest of the current turn. // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc. From f2755ad97011672f482c7a0701c7a1853ea00eeb Mon Sep 17 00:00:00 2001 From: kleeenexfeu <94004034+kleeenexfeu@users.noreply.github.com> Date: Tue, 23 Nov 2021 14:28:52 +0100 Subject: [PATCH 5/6] reword B_RECALC_TURN_AFTER_ACTIONS explanation --- include/constants/battle_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index b792a6f723..4c02605b1d 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -132,7 +132,7 @@ #define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns. #define B_TAUNT_TURNS GEN_7 // In Gen5+, Taunt lasts 3 turns if the user acts before the target, or 4 turns if the target acted before the user. In Gen3, taunt lasts 2 turns and in Gen 4, 3-5 turns. #define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. -#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In Gen8, switching/using a move has consequences over the turn order of the rest of the current turn. +#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In Gen8, switching/using a move affects the current turn's order of switches/moves used. // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc. From 9b25e0147cc9f287a7b3505787cc40be1bc9042f Mon Sep 17 00:00:00 2001 From: kleeenexfeu <94004034+kleeenexfeu@users.noreply.github.com> Date: Tue, 23 Nov 2021 14:35:37 +0100 Subject: [PATCH 6/6] Update include/constants/battle_config.h Co-authored-by: LOuroboros --- include/constants/battle_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 4c02605b1d..795fe30755 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -132,7 +132,7 @@ #define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns. #define B_TAUNT_TURNS GEN_7 // In Gen5+, Taunt lasts 3 turns if the user acts before the target, or 4 turns if the target acted before the user. In Gen3, taunt lasts 2 turns and in Gen 4, 3-5 turns. #define B_MEGA_EVO_TURN_ORDER GEN_7 // In Gen7, a Pokémon's Speed after Mega Evolution is used to determine turn order, not its Speed before. -#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In Gen8, switching/using a move affects the current turn's order of switches/moves used. +#define B_RECALC_TURN_AFTER_ACTIONS GEN_8 // In Gen8, switching/using a move affects the current turn's order of actions. // Move data settings #define B_UPDATED_MOVE_DATA GEN_8 // Updates move data in gBattleMoves, including Power, Accuracy, PP, stat changes, targets, chances of secondary effects, etc.