Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for XY's Sky Battles #2950

Merged
merged 49 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
50754be
Original implementation from Phlayne
pkmnsnfrn Apr 24, 2023
4deaf37
Moved Sky Battle Flag / Var into a config
pkmnsnfrn Apr 24, 2023
8cbfca8
Optimized existing code and fixed existing bugs
pkmnsnfrn Apr 25, 2023
a10c1bd
Added compatibility for Gen7+
pkmnsnfrn Apr 25, 2023
1c3e61b
Commented out Volt Crash from banned moves
pkmnsnfrn Apr 25, 2023
3f82f7a
Merge branch 'upcoming' of https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Apr 25, 2023
35c9e94
Cleaned up debug scripts from testing
pkmnsnfrn Apr 25, 2023
146e8a0
Fixed bug where player did not white out even if they had no healthy …
pkmnsnfrn Apr 25, 2023
db39306
Removed extra include from src/field_specials.c
pkmnsnfrn Apr 25, 2023
7b44742
Merged in most recent changes from upcoming
pkmnsnfrn Apr 27, 2023
f7e8a52
Added FLAG_DISABLED_IN_SKY_BATTLE
pkmnsnfrn Apr 27, 2023
8e2888c
Changed DoesSkyBattleCancelCurrentMove to look at move flags
pkmnsnfrn Apr 27, 2023
1da1765
Fixed alignment and spacing in battle_moves.h
pkmnsnfrn Apr 27, 2023
60a6a57
Added FLAG_DISABLED_IN_SKY_BATTLE to Sticky Web
pkmnsnfrn Apr 27, 2023
4aa9156
Added FLAG_DISABLED_IN_SKY_BATTLE to Steel Roller
pkmnsnfrn Apr 27, 2023
d2ada77
Disabled the ability to change Battle Terrain when Sky Battle is happ…
pkmnsnfrn Apr 27, 2023
7a6abe2
Fixed bug with SKY_BATTLE_STRICT_MECHANICS where conditions were not …
pkmnsnfrn Apr 28, 2023
2afa9ca
Merge branch 'upcoming' of https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Apr 29, 2023
f3584a0
Add rulesVariants to the BattleStruct
pkmnsnfrn Apr 29, 2023
aec9817
Replaced B_FLAG_SKY_BATTLE checks with rulesVariants.skyBattle checks
pkmnsnfrn Apr 29, 2023
3b0626a
Fixed debug script
pkmnsnfrn Apr 29, 2023
95c4eaf
Reverted include/config/battle.h
pkmnsnfrn Apr 29, 2023
2755fb5
Fixed spacing and placement of functions
pkmnsnfrn Apr 29, 2023
2dd238f
Fixed debug script omission
pkmnsnfrn Apr 29, 2023
1cb676f
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Apr 30, 2023
cca1b41
Added FLAG_DISABLED_IN_SKY_BATTLE to Psychic Terrain
pkmnsnfrn May 3, 2023
be1d562
Merged in most recent expansion
pkmnsnfrn May 3, 2023
2c88a92
Merge branch 'SkyBattle' of https://github.com/PokemonSanFran/pokeeme…
pkmnsnfrn May 3, 2023
fe50f1e
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Jun 30, 2023
e3814e1
Addressed DizzyEgg PR feedback
pkmnsnfrn Jun 30, 2023
d01ead1
Forgot a file in last commit
pkmnsnfrn Jun 30, 2023
d002dab
Merged in upcoming
pkmnsnfrn Jul 5, 2023
260d171
Merge branch 'upcoming' of https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Jul 8, 2023
dc3a6bd
Addressed feedback from DizzyEggg
pkmnsnfrn Jul 8, 2023
be205f8
Address Lunos' PR feedback
pkmnsnfrn Jul 9, 2023
f17e2d6
Update specials.inc
pkmnsnfrn Jul 9, 2023
eb0a034
Fixed spacing
pkmnsnfrn Jul 11, 2023
1a2877b
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Jul 18, 2023
9ef212f
Apply suggestions from code review
pkmnsnfrn Jul 19, 2023
dd2eb71
Updated skyBattleBanned and HandleBattleVariantEndParty to use correc…
pkmnsnfrn Jul 19, 2023
c674eef
Merge branch 'upcoming' of https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Sep 24, 2023
2d0aa40
Removed STRICT_MOVES and STRICT_MECHANICS
pkmnsnfrn Sep 24, 2023
e5e3746
Fixed minor spacing issues with merge
pkmnsnfrn Sep 24, 2023
9444255
Merged with upcoming
pkmnsnfrn Nov 23, 2023
5f6a1b0
Merged in upcoming
pkmnsnfrn Nov 23, 2023
5da6117
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Nov 23, 2023
fca1d47
Implemented feedback from Jasper
pkmnsnfrn Nov 24, 2023
ea0fc3f
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Nov 24, 2023
67e4921
Merge branch 'upcoming' into SkyBattle
pkmnsnfrn Nov 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions data/scripts/debug.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ Debug_FlagsNotSetBattleConfigMessage_Text:
.string "Please define a usable flag in:\l"
.string "'include/config/battle.h'!$"

pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
Debug_FlagsAndVarNotSetBattleConfigMessage::
lockall
message Debug_FlagsAndVarNotSetBattleConfigMessage_Text
waitmessage
waitbuttonpress
releaseall
end

Debug_FlagsAndVarNotSetBattleConfigMessage_Text:
.string "Feature unavailable! Please define a\n"
.string "usable flag and a usable var in:\l"
.string "'include/config/battle.h'!$"

Debug_Script_1::
end

Expand Down
1 change: 1 addition & 0 deletions data/specials.inc
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,4 @@ gSpecials::
def_special TrySetBattleTowerLinkType
def_special SetTotemBoost
def_special TrySpecialOverworldEvo
def_special TrySkyBattle
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ struct LostItem
u16 stolen:1;
};

struct BattleRulesVariant
{
bool8 skyBattle:1;
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
};

struct BattleStruct
{
u8 turnEffectsTracker;
Expand Down Expand Up @@ -667,6 +672,7 @@ struct BattleStruct
bool8 trainerSlideMegaEvolutionMsgDone;
bool8 trainerSlideZMoveMsgDone;
bool8 trainerSlideBeforeFirstTurnMsgDone;
struct BattleRulesVariant rulesVariants;
};

#define F_DYNAMIC_TYPE_1 (1 << 6)
Expand Down
2 changes: 2 additions & 0 deletions include/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi
s8 GetInverseCritChance(u8 battlerAtk, u8 battlerDef, u32 move);
u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u32 defAbility, u32 atkHoldEffect, u32 defHoldEffect);
u8 GetBattlerTurnOrderNum(u8 battlerId);
bool32 NoAliveMonsForPlayer(void);
bool32 NoAliveMonsForEitherParty(void);
void SetMoveEffect(bool32 primary, u32 certain);
bool32 CanBattlerSwitch(u32 battlerId);
Expand All @@ -45,6 +46,7 @@ void StealTargetItem(u8 battlerStealer, u8 battlerItem);
u8 GetCatchingBattler(void);
u32 GetHighestStatId(u32 battlerId);
bool32 ProteanTryChangeType(u32 battler, u32 ability, u32 move, u32 moveType);
bool32 DoesSkyBattleCancelMove(u32 gCurrentMove);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
bool32 DoSwitchInAbilitiesItems(u32 battlerId);
u8 GetFirstFaintedPartyIndex(u8 battlerId);

Expand Down
2 changes: 2 additions & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,7 @@ void RemoveConfusionStatus(u8 battlerId);
u8 GetBattlerGender(u8 battlerId);
bool8 AreBattlersOfOppositeGender(u8 battler1, u8 battler2);
u32 CalcSecondaryEffectChance(u8 battlerId, u8 secondaryEffectChance);
bool8 CanMonParticipateInSkyBattle(struct Pokemon* pokemon);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
bool8 IsMonBannedFromSkyBattles(u16 species);

#endif // GUARD_BATTLE_UTIL_H
8 changes: 8 additions & 0 deletions include/config/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@
#define VAR_TERRAIN 0 // If this var has a value, assigning a STATUS_FIELD_xx_TERRAIN to it before battle causes the battle to start with that terrain active
#define B_VAR_WILD_AI_FLAGS 0 // If not 0, you can use this var to add to default wild AI flags. NOT usable with flags above (1 << 15)

// Sky Battles
#define B_FLAG_SKY_BATTLE 0 // If this flag has a value, the player will be able to engage in scripted Sky Battles.
#define B_VAR_SKY_BATTLE 0 // If this var has a value, the game will remember the positions of Pokémon used in Sky Battles.

#define B_SKY_BATTLE_STRICT_ELIGIBILITY FALSE //If TRUE, Sky Battles will use the eligibility from Pokémon XY. If FALSE, all Flying-types or Pokémon with Levitate are allowed.
Bassoonian marked this conversation as resolved.
Show resolved Hide resolved
#define B_SKY_BATTLE_STRICT_MOVES FALSE //If TRUE, Sky Battles will use the banned moves from Pokémon XY. If FALSE, more moves that debuted after Pokémon XY are added.
#define B_SKY_BATTLE_STRICT_MECHANICS FALSE //If TRUE, Sky Battles will use the exact mechanics from Pokémon XY. If FALSE, moves and Abilities that set Terrain, Toxic Spikes, or Spikes will not have those effects activate.

// Flag and Var settings
#define B_RESET_FLAGS_VARS_AFTER_WHITEOUT TRUE // If TRUE, Overworld_ResetBattleFlagsAndVars will reset battle-related Flags and Vars when the player whites out.

Expand Down
1 change: 1 addition & 0 deletions include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define GUARD_DEBUG_H

void Debug_ShowMainMenu(void);
extern const u8 Debug_FlagsAndVarNotSetBattleConfigMessage[];

#endif // GUARD_DEBUG_H
1 change: 1 addition & 0 deletions include/field_specials.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ bool8 UsedPokemonCenterWarp(void);
void ResetFanClub(void);
bool8 ShouldShowBoxWasFullMessage(void);
void SetPCBoxToSendMon(u8 boxId);
void PreparePartyForSkyBattle(void);

#endif // GUARD_FIELD_SPECIALS_H
1 change: 1 addition & 0 deletions include/load_save.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void SetContinueGameWarpStatusToDynamicWarp(void);
void ClearContinueGameWarpStatus2(void);
void SavePlayerParty(void);
void LoadPlayerParty(void);
void SaveChangesToPlayerParty(void);
void SaveObjectEvents(void);
void LoadObjectEvents(void);
void CopyPartyAndObjectsToSave(void);
Expand Down
1 change: 1 addition & 0 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ struct BattleMove
u32 copycatBanned:1;
u32 sleepTalkBanned:1;
u32 instructBanned:1;
u32 skybattleBanned:1;
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
};

#define SPINDA_SPOT_WIDTH 16
Expand Down
26 changes: 23 additions & 3 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,20 @@ bool32 ProteanTryChangeType(u32 battler, u32 ability, u32 move, u32 moveType)
return FALSE;
}

bool32 DoesSkyBattleCancelCurrentMove(u32 gCurrentMove)
{
bool8 moveBannedFromSkyBattles = FALSE;

//if (gBattleMoves[gCurrentMove].flags & FLAG_DISABLED_IN_SKY_BATTLE)
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
if (gBattleMoves[gCurrentMove].skybattleBanned)
moveBannedFromSkyBattles = TRUE;

if ((gBattleStruct->rulesVariants.skyBattle) && (moveBannedFromSkyBattles)){
return TRUE;
}
return FALSE;
}

pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
static void Cmd_attackcanceler(void)
{
CMD_ARGS();
Expand Down Expand Up @@ -1369,7 +1383,7 @@ static void Cmd_attackcanceler(void)
}

gHitMarker |= HITMARKER_OBEYS;
if (NoTargetPresent(gBattlerAttacker, gCurrentMove) && (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)))
if ((NoTargetPresent(gBattlerAttacker, gCurrentMove) && (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS))) || (DoesSkyBattleCancelCurrentMove(gCurrentMove)))
{
gBattlescriptCurrInstr = BattleScript_ButItFailedAtkStringPpReduce;
if (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS))
Expand Down Expand Up @@ -3629,7 +3643,13 @@ void SetMoveEffect(bool32 primary, u32 certain)
{
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SPIKESSCATTERED;
BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_SpikesActivates;

#if B_SKY_BATTLE_STRICT_MECHANICS == FALSE
if (gBattleStruct->rulesVariants.skyBattle){
gBattlescriptCurrInstr++;
}else
#endif
gBattlescriptCurrInstr = BattleScript_SpikesActivates;
}
break;
case MOVE_EFFECT_TRIPLE_ARROWS:
Expand Down Expand Up @@ -4340,7 +4360,7 @@ static bool32 NoAliveMonsForPlayerAndPartner(void)
}
#endif

static bool32 NoAliveMonsForPlayer(void)
bool32 NoAliveMonsForPlayer(void)
{
u32 i;
u32 HP_count = 0;
Expand Down
15 changes: 14 additions & 1 deletion src/battle_setup.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "global.h"
#include "battle.h"
#include "load_save.h"
#include "battle_setup.h"
#include "battle_transition.h"
#include "main.h"
Expand Down Expand Up @@ -1349,15 +1350,27 @@ void BattleSetup_StartTrainerBattle(void)
ScriptContext_Stop();
}

static void HandleBattleVariantParty(void)
{
if (FlagGet(B_FLAG_SKY_BATTLE))
{
SaveChangesToPlayerParty();
LoadPlayerParty();
FlagClear(B_FLAG_SKY_BATTLE);
}
}
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved

static void CB2_EndTrainerBattle(void)
{
HandleBattleVariantParty();

if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE)
{
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
else if (IsPlayerDefeated(gBattleOutcome) == TRUE)
{
if (InBattlePyramid() || InTrainerHillChallenge())
if (InBattlePyramid() || InTrainerHillChallenge() || (!NoAliveMonsForPlayer()))
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
else
SetMainCallback2(CB2_WhiteOut);
Expand Down
57 changes: 57 additions & 0 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4011,7 +4011,11 @@ bool32 TryChangeBattleWeather(u8 battler, u32 weatherEnumId, bool32 viaAbility)

static bool32 TryChangeBattleTerrain(u32 battler, u32 statusFlag, u8 *timer)
{
#if B_SKY_BATTLE_STRICT_MECHANICS == TRUE
if (!(gFieldStatuses & statusFlag))
#else
if ((!(gFieldStatuses & statusFlag) && (!gBattleStruct->rulesVariants.skyBattle)))
#endif
{
gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_GRASSY_TERRAIN | STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_PSYCHIC_TERRAIN);
gFieldStatuses |= statusFlag;
Expand Down Expand Up @@ -5643,6 +5647,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
break;
case ABILITY_TOXIC_DEBRIS:
if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)
#if B_SKY_BATTLE_STRICT_MECHANICS == FALSE
&& (!gBattleStruct->rulesVariants.skyBattle)
#endif
&& !gProtectStructs[gBattlerAttacker].confusionSelfDmg
&& IS_MOVE_PHYSICAL(gCurrentMove)
&& TARGET_TURN_DAMAGED
Expand Down Expand Up @@ -10891,3 +10898,53 @@ bool32 IsAlly(u32 battlerAtk, u32 battlerDef)
{
return (GetBattlerSide(battlerAtk) == GetBattlerSide(battlerDef));
}

bool8 CanMonParticipateInSkyBattle(struct Pokemon* pokemon)
{
u16 species = GetMonData(pokemon, MON_DATA_SPECIES);
u16 monAbilityNum = GetMonData(pokemon, MON_DATA_ABILITY_NUM, NULL);

bool8 hasLevitateAbility = gSpeciesInfo[species].abilities[monAbilityNum] == ABILITY_LEVITATE;
bool8 isFlyingType = gSpeciesInfo[species].types[0] == TYPE_FLYING || gSpeciesInfo[species].types[1] == TYPE_FLYING;
bool8 monIsValidAndNotEgg = GetMonData(pokemon, MON_DATA_SANITY_HAS_SPECIES) && !GetMonData(pokemon, MON_DATA_IS_EGG);

if (monIsValidAndNotEgg)
{
if ((hasLevitateAbility || isFlyingType) && !IsMonBannedFromSkyBattles(species))
return TRUE;
}
return FALSE;
}

bool8 IsMonBannedFromSkyBattles(u16 species){
switch (species){
case SPECIES_EGG:
#if B_SKY_BATTLE_STRICT_ELIGIBILITY == TRUE
case SPECIES_SPEAROW:
case SPECIES_FARFETCHD:
case SPECIES_DODUO:
case SPECIES_DODRIO:
case SPECIES_HOOTHOOT:
case SPECIES_NATU:
case SPECIES_MURKROW:
case SPECIES_DELIBIRD:
case SPECIES_TAILLOW:
case SPECIES_STARLY:
case SPECIES_CHATOT:
case SPECIES_SHAYMIN:
case SPECIES_PIDOVE:
case SPECIES_ARCHEN:
case SPECIES_DUCKLETT:
case SPECIES_RUFFLET:
case SPECIES_VULLABY:
case SPECIES_FLETCHLING:
case SPECIES_HAWLUCHA:
case SPECIES_ROWLET:
case SPECIES_PIKIPEK:
#endif
return TRUE;
break;
default:
return FALSE;
}
}
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions src/battle_util2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void AllocateBattleResources(void)

gBattleStruct = AllocZeroed(sizeof(*gBattleStruct));

#if B_FLAG_SKY_BATTLE
gBattleStruct->rulesVariants.skyBattle = FlagGet(B_FLAG_SKY_BATTLE);
#endif

gBattleResources = AllocZeroed(sizeof(*gBattleResources));
gBattleResources->secretBase = AllocZeroed(sizeof(*gBattleResources->secretBase));
gBattleResources->flags = AllocZeroed(sizeof(*gBattleResources->flags));
Expand Down
Loading