diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 890724c50..b21f80a1f 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2128,7 +2128,9 @@ BattleScript_GrowthDoMoveAnim:: waitanimation setbyte sSTAT_ANIM_PLAYED, FALSE playstatchangeanimation BS_ATTACKER, BIT_ATK | BIT_SPATK, 0 +.if B_GROWTH_UNDER_SUN >= GEN_5 jumpifweatheraffected BS_ATTACKER, B_WEATHER_SUN, BattleScript_GrowthAtk2 +.endif setstatchanger STAT_ATK, 1, FALSE goto BattleScript_GrowthAtk BattleScript_GrowthAtk2: @@ -2139,7 +2141,9 @@ BattleScript_GrowthAtk: printfromtable gStatUpStringIds waitmessage B_WAIT_TIME_LONG BattleScript_GrowthTrySpAtk:: +.if B_GROWTH_UNDER_SUN >= GEN_5 jumpifweatheraffected BS_ATTACKER, B_WEATHER_SUN, BattleScript_GrowthSpAtk2 +.endif setstatchanger STAT_SPATK, 1, FALSE goto BattleScript_GrowthSpAtk BattleScript_GrowthSpAtk2: @@ -4485,7 +4489,11 @@ BattleScript_NightmareWorked:: BattleScript_EffectMinimize:: attackcanceler setminimize +.if B_MINIMIZE_EVASION >= GEN_5 + setstatchanger STAT_EVASION, 2, FALSE +.else setstatchanger STAT_EVASION, 1, FALSE +.endif goto BattleScript_EffectStatUpAfterAtkCanceler BattleScript_EffectCurse:: @@ -6396,9 +6404,11 @@ BattleScript_LearnMoveReturn:: BattleScript_RainContinuesOrEnds:: printfromtable gRainContinuesStringIds waitmessage B_WAIT_TIME_LONG - jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_RAIN_STOPPED, BattleScript_RainContinuesOrEndsEnd + jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_RAIN_STOPPED, BattleScript_RainEnds playanimation BS_ATTACKER, B_ANIM_RAIN_CONTINUES -BattleScript_RainContinuesOrEndsEnd:: + end2 +BattleScript_RainEnds:: + call BattleScript_WeatherFormChanges end2 BattleScript_DamagingWeatherContinues:: @@ -6437,6 +6447,7 @@ BattleScript_DamagingWeatherContinuesEnd:: BattleScript_SandStormHailEnds:: printfromtable gSandStormHailEndStringIds waitmessage B_WAIT_TIME_LONG + call BattleScript_WeatherFormChanges end2 BattleScript_SunlightContinues:: @@ -6448,6 +6459,7 @@ BattleScript_SunlightContinues:: BattleScript_SunlightFaded:: printstring STRINGID_SUNLIGHTFADED waitmessage B_WAIT_TIME_LONG + call BattleScript_WeatherFormChanges end2 BattleScript_OverworldWeatherStarts:: @@ -8148,8 +8160,10 @@ BattleScript_DesolateLandEvaporatesWaterTypeMoves:: attackstring pause B_WAIT_TIME_SHORT ppreduce + jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_STRING_PRINTED, BattleScript_MoveEnd printstring STRINGID_MOVEEVAPORATEDINTHEHARSHSUNLIGHT waitmessage B_WAIT_TIME_LONG + orword gHitMarker, HITMARKER_STRING_PRINTED goto BattleScript_MoveEnd BattleScript_PrimordialSeaActivates:: @@ -8166,8 +8180,10 @@ BattleScript_PrimordialSeaFizzlesOutFireTypeMoves:: attackstring pause B_WAIT_TIME_SHORT ppreduce + jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_STRING_PRINTED, BattleScript_MoveEnd printstring STRINGID_MOVEFIZZLEDOUTINTHEHEAVYRAIN waitmessage B_WAIT_TIME_LONG + orword gHitMarker, HITMARKER_STRING_PRINTED goto BattleScript_MoveEnd BattleScript_DeltaStreamActivates:: @@ -8378,6 +8394,13 @@ BattleScript_ObliviousPreventsAttraction:: waitmessage B_WAIT_TIME_LONG goto BattleScript_MoveEnd +BattleScript_FlinchPrevention:: + pause B_WAIT_TIME_SHORT + call BattleScript_AbilityPopUp + printstring STRINGID_PKMNSXPREVENTSFLINCHING + waitmessage B_WAIT_TIME_LONG + goto BattleScript_MoveEnd + BattleScript_OwnTempoPrevents:: pause B_WAIT_TIME_SHORT call BattleScript_AbilityPopUp diff --git a/include/battle.h b/include/battle.h index 185167e46..e91ab96a1 100644 --- a/include/battle.h +++ b/include/battle.h @@ -474,7 +474,6 @@ struct MegaEvolutionData bool8 playerSelect; u8 triggerSpriteId; bool8 isWishMegaEvo; - bool8 isPrimalReversion; }; struct Illusion @@ -937,5 +936,6 @@ extern bool8 gHasFetchedBall; extern u8 gLastUsedBall; extern u16 gLastThrownBall; extern bool8 gSwapDamageCategory; // Photon Geyser, Shell Side Arm, Light That Burns the Sky +extern u8 gPartyCriticalHits[PARTY_SIZE]; #endif // GUARD_BATTLE_H diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 5cbe42be4..2f64b15c5 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -169,6 +169,7 @@ extern const u8 BattleScript_BRNPrevention[]; extern const u8 BattleScript_PRLZPrevention[]; extern const u8 BattleScript_PSNPrevention[]; extern const u8 BattleScript_ObliviousPreventsAttraction[]; +extern const u8 BattleScript_FlinchPrevention[]; extern const u8 BattleScript_OwnTempoPrevents[]; extern const u8 BattleScript_SoundproofProtected[]; extern const u8 BattleScript_AbilityNoSpecificStatLoss[]; diff --git a/include/battle_util.h b/include/battle_util.h index b457d862d..b44830579 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -134,6 +134,7 @@ u16 CalcPartyMonTypeEffectivenessMultiplier(u16 move, u16 speciesDef, u16 abilit u16 GetTypeModifier(u8 atkType, u8 defType); s32 GetStealthHazardDamage(u8 hazardType, u8 battlerId); u16 GetMegaEvolutionSpecies(u16 preEvoSpecies, u16 heldItemId); +u16 GetPrimalReversionSpecies(u16 preEvoSpecies, u16 heldItemId); u16 GetWishMegaEvolutionSpecies(u16 preEvoSpecies, u16 moveId1, u16 moveId2, u16 moveId3, u16 moveId4); bool32 CanMegaEvolve(u8 battlerId); void UndoMegaEvolution(u32 monId); @@ -171,6 +172,7 @@ void TryToApplyMimicry(u8 battlerId, bool8 various); void TryToRevertMimicry(void); void RestoreBattlerOriginalTypes(u8 battlerId); u32 GetBattlerMoveTargetType(u8 battlerId, u16 move); +bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move); bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId); // Ability checks bool32 IsRolePlayBannedAbilityAtk(u16 ability); diff --git a/include/constants/battle.h b/include/constants/battle.h index 7753733be..ba7d6c7c1 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -203,6 +203,7 @@ #define HITMARKER_CHARGING (1 << 27) #define HITMARKER_FAINTED(battler) (gBitTable[battler] << 28) #define HITMARKER_FAINTED2(battler) ((1 << 28) << battler) +#define HITMARKER_STRING_PRINTED (1 << 29) // Per-side statuses that affect an entire party #define SIDE_STATUS_REFLECT (1 << 0) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 2cbe3d248..f43a5c8be 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -99,7 +99,7 @@ #endif // Calculation settings -#define B_CRIT_CHANCE GEN_7 // Chances of a critical hit landing. See CalcCritChanceStage. +#define B_CRIT_CHANCE GEN_7 // Chances of a critical hit landing. See CalcCritChanceStage. Gen6+ chances guarantee that Farfetch'd and Sirfetch'd always get critical hits while holding a Leek and using high-crit ratio moves. #define B_CRIT_MULTIPLIER GEN_7 // In Gen6+, critical hits multiply damage by 1.5 instead of 2. #define B_PARALYSIS_SPEED GEN_7 // In Gen7+, Speed is decreased by 50% instead of 75%. #define B_CONFUSION_SELF_DMG_CHANCE GEN_7 // In Gen7+, confusion has a 33.3% of self-damage, instead of 50%. @@ -116,6 +116,7 @@ // Damage settings #define B_BURN_DAMAGE GEN_7 // In Gen7+, burn damage is 1/16th of max HP instead of 1/8th. +#define B_BURN_FACADE_DMG GEN_7 // In Gen6+, burn's effect of lowering the Attack stat no longer applies to Facade. #define B_BINDING_DAMAGE GEN_7 // In Gen6+, binding damage is 1/8 of max HP instead of 1/16. (With Binding Band, 1/6 and 1/8 respectively.) #define B_PSYWAVE_DMG GEN_7 // Psywave's damage formula. See Cmd_psywavedamageeffect. #define B_PAYBACK_SWITCH_BOOST GEN_7 // In Gen5+, if the opponent switches out, Payback's damage will no longer be doubled. @@ -153,16 +154,18 @@ #define B_RECOIL_IF_MISS_DMG GEN_7 // In Gen5+, Jump Kick and High Jump Kick will always do half of the user's max HP when missing. #define B_KLUTZ_FLING_INTERACTION GEN_7 // In Gen5+, Pokémon with the Klutz ability can't use Fling. #define B_UPDATED_CONVERSION GEN_7 // In Gen6+, Conversion changes the user's type to match their first move's. Before, it would choose a move at random. +#define B_PP_REDUCED_BY_SPITE GEN_7 // In Gen4+, Spite reduces the foe's last move's PP by 4, instead of 2 to 5. +#define B_MINIMIZE_EVASION GEN_7 // In Gen5+, Minimize raises evasion by 2 stages instead of 1. // Move accuracy settings #define B_TOXIC_NEVER_MISS GEN_7 // In Gen6+, if Toxic is used by a Poison-type Pokémon, it will never miss. #define B_MINIMIZE_DMG_ACC GEN_7 // In Gen6+, moves that causes double damage to minimized Pokémon will also skip accuracy checks. #define B_BLIZZARD_HAIL GEN_7 // In Gen4+, Blizzard bypasses accuracy checks if it's hailing. +#define B_SHEER_COLD_ACC GEN_7 // In Gen7+, Sheer Cold's base chance of hitting is reduced to 20% if the user isn't Ice-typed. // Other move settings #define B_SOUND_SUBSTITUTE GEN_7 // In Gen6+, sound moves bypass Substitute. #define B_INCINERATE_GEMS GEN_7 // In Gen6+, Incinerate can destroy Gems. -#define B_PP_REDUCED_BY_SPITE GEN_7 // In Gen4+, Spite reduces the foe's last move's PP by 4, instead of 2 to 5. #define B_CAN_SPITE_FAIL GEN_7 // In Gen4+, Spite can no longer fail if the foe's last move only has 1 remaining PP. #define B_CRASH_IF_TARGET_IMMUNE GEN_7 // In Gen4+, The user of Jump Kick or High Jump Kick will "keep going and crash" if it attacks a target that is immune to the move. #define B_MEMENTO_FAIL GEN_7 // In Gen4+, Memento fails if there is no target or if the target is protected or behind substitute. But not if Atk/Sp. Atk are at -6. @@ -173,6 +176,8 @@ #define B_RAMPAGE_CANCELLING GEN_7 // In Gen5+, a failed Thrash, etc, will cancel except on its last turn. #define B_HEAL_BLOCKING GEN_7 // In Gen5+, Heal Block prevents healing by Black Sludge, Leftovers, Shell Bell. Affected Pokémon will not consume held HP-restoring Berries or Berry Juice. // Draining abilities will not heal but will prevent damage. In Gen6+, Heal Block prevents the use of most HP-draining moves. +#define B_ROOTED_GROUNDING GEN_7 // In Gen4+, Ingrain causes the affected Pokémon to become grounded. +#define B_GROWTH_UNDER_SUN GEN_7 // In Gen5+, Growth's effects are doubled when under the effects of the sun. // Ability settings #define B_EXPANDED_ABILITY_NAMES TRUE // If TRUE, ability names are increased from 12 characters to 16 characters. @@ -185,11 +190,14 @@ #define B_SYNCHRONIZE_NATURE GEN_8 // In Gen8, if a Pokémon with Synchronize is leading the party, it's 100% guaranteed that wild Pokémon will have the same ability, as opposed to 50% previously. #define B_SYNCHRONIZE_TOXIC GEN_8 // In Gen5+, if a Pokémon with Synchronize is badly poisoned, the opponent will also become badly poisoned. Previously, the opponent would become regular poisoned. #define B_UPDATED_INTIMIDATE GEN_8 // In Gen8, Intimidate doesn't work on opponents with the Inner Focus, Scrappy, Own Tempo or Oblivious abilities. It also activates Rattled. +#define B_OBLIVIOUS_TAUNT GEN_7 // In Gen6+, Pokémon with Oblivious can't be taunted. #define B_PARENTAL_BOND_DAMAGE GEN_8 // In Gen7+, Parental Bond's second hit does 25% of the initial hits damage. Before, it did 50%. // Item settings #define B_HP_BERRIES GEN_7 // In Gen4+, berries which restore hp activate immediately after HP drops to half. In Gen3, the effect occurs at the end of the turn. #define B_BERRIES_INSTANT GEN_7 // In Gen4+, most berries activate on battle start/switch-in if applicable. In Gen3, they only activate either at the move end or turn end. +#define B_CONFUSE_BERRIES_HEAL GEN_8 // Before Gen7, Figy and similar berries restore 1/8th of HP and trigger at half HP. In Gen7 they restore half HP, triggering at 25% HP. In Gen8 they heal 1/3rd of HP. + // Requires using Item Expansion or manually editing the holdEffectParam of Figy, Wiki, Mago, Aguav and Iapapa berries. #define B_X_ITEMS_BUFF GEN_7 // In Gen7+, the X Items raise a stat by 2 stages instead of 1. #define B_MENTAL_HERB GEN_5 // In Gen5+, the Mental Herb cures Infatuation, Taunt, Encore, Torment, Heal Block, and Disable #define B_TRAINERS_KNOCK_OFF_ITEMS TRUE // If TRUE, trainers can steal/swap your items (non-berries are restored after battle). In vanilla games trainers cannot steal items. @@ -205,7 +213,6 @@ #define B_HEAVY_BALL_MODIFIER GEN_7 // In Gen7+, Heavy Ball's ranges change. See Cmd_handleballthrow. #define B_DREAM_BALL_MODIFIER GEN_8 // In Gen8, Dream Ball's catch multiplier is x4 when the target is asleep or has the ability Comatose. #define B_SERENE_GRACE_BOOST GEN_7 // In Gen5+, Serene Grace boosts the added flinch chance of King's Rock and Razor Fang. -#define B_LEEK_ALWAYS_CRIT GEN_7 // In Gen6+, if a Farfetch'd or Sirfetch'd holding a Leek use a move with increased Critical Hit ratio, it will always result in a Critical Hit. // Flag settings // To use the following features in scripting, replace the 0s with the flag ID you're assigning it to. @@ -247,6 +254,7 @@ // Other settings #define B_DOUBLE_WILD_CHANCE 0 // % chance of encountering two Pokémon in a Wild Encounter. #define B_MULTI_BATTLE_WHITEOUT GEN_8 // In Gen4+, multi battles end when the Player and also their Partner don't have any more Pokémon to fight. +#define B_EVOLUTION_AFTER_WHITEOUT GEN_6 // In Gen6+, Pokemon that qualify for evolution after battle will evolve even if the player loses. #define B_WILD_NATURAL_ENEMIES TRUE // If set to TRUE, certain wild mon species will attack other species when partnered in double wild battles (eg. Zangoose vs Seviper) // Animation Settings diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index c375bbdd1..13db5644e 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -379,14 +379,20 @@ #define EVO_SPECIFIC_MAP 32 // Pokémon levels up on specified map #define EVO_LEVEL_NATURE_AMPED 33 // Pokémon reaches the specified level, it has a Hardy, Brave, Adamant, Naughty, Docile, Impish, Lax, Hasty, Jolly, Naive, Rash, Sassy, or Quirky nature. #define EVO_LEVEL_NATURE_LOW_KEY 34 // Pokémon reaches the specified level, it has a Lonely, Bold, Relaxed, Timid, Serious, Modest, Mild, Quiet, Bashful, Calm, Gentle, or Careful nature. +#define EVO_CRITICAL_HITS 35 // Pokémon performs specified number of critical hits in one battle +#define EVO_SCRIPT_TRIGGER_DMG 36 // Pokémon has specified HP below max, then player interacts trigger +#define EVO_DARK_SCROLL 37 // interacts with Scroll of Darkness +#define EVO_WATER_SCROLL 38 // interacts with Scroll of Waters #define EVOS_PER_MON 10 // Evolution 'modes,' for GetEvolutionTargetSpecies -#define EVO_MODE_NORMAL 0 -#define EVO_MODE_TRADE 1 -#define EVO_MODE_ITEM_USE 2 -#define EVO_MODE_ITEM_CHECK 3 // If an Everstone is being held, still want to show that the stone *could* be used on that Pokémon to evolve +#define EVO_MODE_NORMAL 0 +#define EVO_MODE_TRADE 1 +#define EVO_MODE_ITEM_USE 2 +#define EVO_MODE_ITEM_CHECK 3 // If an Everstone is being held, still want to show that the stone *could* be used on that Pokémon to evolve +#define EVO_MODE_BATTLE_SPECIAL 4 +#define EVO_MODE_OVERWORLD_SPECIAL 5 #define NUM_MALE_LINK_FACILITY_CLASSES 8 #define NUM_FEMALE_LINK_FACILITY_CLASSES 8 diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 23a6a754d..051a43b77 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -438,6 +438,9 @@ static u8 ChooseMoveOrAction_Doubles(void) { if (gBattleMons[sBattler_AI].moves[j] != 0) { + if (!CanTargetBattler(sBattler_AI, i, gBattleMons[sBattler_AI].moves[j])) + continue; + if (mostViableMovesScores[0] == AI_THINKING_STRUCT->score[j]) { mostViableMovesScores[mostViableMovesNo] = AI_THINKING_STRUCT->score[j]; @@ -2296,6 +2299,8 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) case EFFECT_HIT_ENEMY_HEAL_ALLY: // pollen puff if (IsTargetingPartner(battlerAtk, battlerDef)) { + if (gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) + return 0; if (AtMaxHp(battlerDef)) score -= 10; else if (gBattleMons[battlerDef].hp > gBattleMons[battlerDef].maxHP / 2) @@ -4901,6 +4906,9 @@ static s16 AI_HPAware(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) || (moveType == TYPE_ELECTRIC && AI_DATA->atkPartnerAbility == ABILITY_VOLT_ABSORB) || (moveType == TYPE_WATER && (AI_DATA->atkPartnerAbility == ABILITY_DRY_SKIN || AI_DATA->atkPartnerAbility == ABILITY_WATER_ABSORB))) { + if (gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) + return 0; + if (CanTargetFaintAi(FOE(battlerAtk), AI_DATA->battlerAtkPartner) || (CanTargetFaintAi(BATTLE_PARTNER(FOE(battlerAtk)), AI_DATA->battlerAtkPartner))) score--; diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index de4271bba..8ed6e0490 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1499,6 +1499,10 @@ bool32 ShouldTryOHKO(u8 battlerAtk, u8 battlerDef, u16 atkAbility, u16 defAbilit else // test the odds { u16 odds = accuracy + (gBattleMons[battlerAtk].level - gBattleMons[battlerDef].level); + #if B_SHEER_COLD_ACC >= GEN_7 + if (gCurrentMove == MOVE_SHEER_COLD && !IS_BATTLER_OF_TYPE(gBattlerAttacker, TYPE_ICE)) + odds -= 10; + #endif if (Random() % 100 + 1 < odds && gBattleMons[battlerAtk].level >= gBattleMons[battlerDef].level) return TRUE; } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 69e0de5af..35e774341 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1605,6 +1605,7 @@ static void OpponentHandleChooseMove(void) else // Wild pokemon - use random move { u16 move; + u8 target; do { chosenMoveId = Random() & 3; @@ -1615,6 +1616,10 @@ static void OpponentHandleChooseMove(void) BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8)); else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { + do { + target = GetBattlerAtPosition(Random() & 2); + } while (!CanTargetBattler(gActiveBattler, target, move)); + #if B_WILD_NATURAL_ENEMIES == TRUE // Don't bother to loop through table if the move can't attack ally if (!(gBattleMoves[move].target & MOVE_TARGET_BOTH)) @@ -1641,14 +1646,14 @@ static void OpponentHandleChooseMove(void) break; } } - if (isPartnerEnemy) + if (isPartnerEnemy && CanTargetBattler(gActiveBattler, target, move)) BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler)) << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else #endif - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index bd6b3a023..0e01eb549 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -436,7 +436,8 @@ static void HandleInputChooseTarget(void) break; } - if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) + if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor] + || !CanTargetBattler(gActiveBattler, gMultiUsePlayerCursor, move)) i = 0; } while (i == 0); } @@ -485,7 +486,8 @@ static void HandleInputChooseTarget(void) break; } - if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) + if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor] + || !CanTargetBattler(gActiveBattler, gMultiUsePlayerCursor, move)) i = 0; } while (i == 0); } diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 9dbfa7771..2d441c7eb 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -914,6 +914,8 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 castform, bo { StartSpriteAnim(&gSprites[gBattlerSpriteIds[battlerAtk]], gBattleSpritesDataPtr->animationData->animArg); paletteOffset = 0x100 + battlerAtk * 16; + lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(targetSpecies, otId, personalityValue); + LZDecompressWram(lzPaletteData, gBattleStruct->castformPalette); LoadPalette(gBattleStruct->castformPalette[gBattleSpritesDataPtr->animationData->animArg], paletteOffset, 32); gBattleMonForms[battlerAtk] = gBattleSpritesDataPtr->animationData->animArg; if (gBattleSpritesDataPtr->battlerData[battlerAtk].transformSpecies != SPECIES_NONE) diff --git a/src/battle_interface.c b/src/battle_interface.c index 6d98d794d..e0d3b7d61 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -3309,7 +3309,7 @@ bool32 CanThrowLastUsedBall(void) #else if (!CanThrowBall()) return FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) + if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FRONTIER)) return FALSE; if (!CheckBagHasItem(gLastThrownBall, 1)) return FALSE; diff --git a/src/battle_main.c b/src/battle_main.c index 93be4b2dc..e2fd7fa4e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -64,6 +64,8 @@ #include "constants/trainers.h" #include "cable_club.h" +extern struct Evolution gEvolutionTable[][EVOS_PER_MON]; + extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; @@ -115,6 +117,7 @@ static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); static void SpriteCB_UnusedBattleInit(struct Sprite* sprite); static void SpriteCB_UnusedBattleInit_Main(struct Sprite *sprite); +static void TrySpecialEvolution(void); EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0; @@ -237,6 +240,8 @@ EWRAM_DATA bool8 gHasFetchedBall = FALSE; EWRAM_DATA u8 gLastUsedBall = 0; EWRAM_DATA u16 gLastThrownBall = 0; EWRAM_DATA bool8 gSwapDamageCategory = FALSE; // Photon Geyser, Shell Side Arm, Light That Burns the Sky +EWRAM_DATA u8 gPartyCriticalHits[PARTY_SIZE] = {0}; +EWRAM_DATA static u8 sTriedEvolving = 0; void (*gPreBattleCallback1)(void); void (*gBattleMainFunc)(void); @@ -3000,6 +3005,7 @@ static void BattleStartClearSetData(void) gBattleStruct->usedHeldItems[i][0] = 0; gBattleStruct->usedHeldItems[i][1] = 0; gBattleStruct->itemStolen[i].originalItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + gPartyCriticalHits[i] = 0; } gSwapDamageCategory = FALSE; // Photon Geyser, Shell Side Arm, Light That Burns the Sky @@ -3636,12 +3642,18 @@ static void TryDoEventsBeforeFirstTurn(void) // Primal Reversion for (i = 0; i < gBattlersCount; i++) { - if (CanMegaEvolve(i) - && GetBattlerHoldEffect(i, TRUE) == HOLD_EFFECT_PRIMAL_ORB) + if (GetBattlerHoldEffect(i, TRUE) == HOLD_EFFECT_PRIMAL_ORB) { - gBattlerAttacker = i; - BattleScriptExecute(BattleScript_PrimalReversion); - return; + for (j = 0; j < EVOS_PER_MON; j++) + { + if (gEvolutionTable[gBattleMons[i].species][j].targetSpecies != SPECIES_NONE + && gEvolutionTable[gBattleMons[i].species][j].method == EVO_PRIMAL_REVERSION) + { + gBattlerAttacker = i; + BattleScriptExecute(BattleScript_PrimalReversion); + return; + } + } } } @@ -5158,9 +5170,16 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gIsFishingEncounter = FALSE; gIsSurfingEncounter = FALSE; ResetSpriteData(); - if (gLeveledUpInBattle && (gBattleOutcome == B_OUTCOME_WON || gBattleOutcome == B_OUTCOME_CAUGHT)) + if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK + | BATTLE_TYPE_RECORDED_LINK + | BATTLE_TYPE_FIRST_BATTLE + | BATTLE_TYPE_SAFARI + | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_WALLY_TUTORIAL)) + && (B_EVOLUTION_AFTER_WHITEOUT >= GEN_6 || gBattleOutcome == B_OUTCOME_WON || gBattleOutcome == B_OUTCOME_CAUGHT)) { - gBattleMainFunc = TryEvolvePokemon; + gBattleMainFunc = TrySpecialEvolution; } else { @@ -5178,6 +5197,30 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) } } +static void TrySpecialEvolution(void) // Attempts to perform non-level related battle evolutions (not the script command). +{ + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + #ifndef POKEMON_EXPANSION + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i); + #else + u16 species = GetEvolutionTargetSpecies(&gPlayerParty[i], EVO_MODE_BATTLE_SPECIAL, i, NULL); + #endif + if (species != SPECIES_NONE && !(sTriedEvolving & gBitTable[i])) + { + sTriedEvolving |= gBitTable[i]; + FreeAllWindowBuffers(); + gBattleMainFunc = WaitForEvoSceneToFinish; + EvolutionScene(&gPlayerParty[i], species, TRUE, i); + return; + } + } + sTriedEvolving = 0; + gBattleMainFunc = TryEvolvePokemon; +} + static void TryEvolvePokemon(void) { s32 i; @@ -5212,7 +5255,7 @@ static void TryEvolvePokemon(void) static void WaitForEvoSceneToFinish(void) { if (gMain.callback2 == BattleMainCB2) - gBattleMainFunc = TryEvolvePokemon; + gBattleMainFunc = TrySpecialEvolution; } static void ReturnFromBattleToOverworld(void) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 75a27c9de..8d78a8240 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1402,24 +1402,20 @@ static void Cmd_attackcanceler(void) GET_MOVE_TYPE(gCurrentMove, moveType); - if (moveType == TYPE_FIRE - && (gBattleWeather & B_WEATHER_RAIN_PRIMAL) - && WEATHER_HAS_EFFECT - && gBattleMoves[gCurrentMove].power) + if (WEATHER_HAS_EFFECT && gBattleMoves[gCurrentMove].power) { - BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_PrimordialSeaFizzlesOutFireTypeMoves; - return; - } - - if (moveType == TYPE_WATER - && (gBattleWeather & B_WEATHER_SUN_PRIMAL) - && WEATHER_HAS_EFFECT - && gBattleMoves[gCurrentMove].power) - { - BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_DesolateLandEvaporatesWaterTypeMoves; - return; + if (moveType == TYPE_FIRE && (gBattleWeather & B_WEATHER_RAIN_PRIMAL)) + { + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_PrimordialSeaFizzlesOutFireTypeMoves; + return; + } + else if (moveType == TYPE_WATER && (gBattleWeather & B_WEATHER_SUN_PRIMAL)) + { + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_DesolateLandEvaporatesWaterTypeMoves; + return; + } } if (gBattleOutcome != 0) @@ -1942,11 +1938,7 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi else if (gStatuses3[battlerAtk] & STATUS3_LASER_FOCUS || gBattleMoves[move].effect == EFFECT_ALWAYS_CRIT || (abilityAtk == ABILITY_MERCILESS && gBattleMons[battlerDef].status1 & STATUS1_PSN_ANY) - || move == MOVE_SURGING_STRIKES - #if B_LEEK_ALWAYS_CRIT >= GEN_6 - || ((gBattleMoves[gCurrentMove].flags & FLAG_HIGH_CRIT) && BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk)) - #endif - ) + || move == MOVE_SURGING_STRIKES) { critChance = -2; } @@ -1978,6 +1970,7 @@ s8 GetInverseCritChance(u8 battlerAtk, u8 battlerDef, u32 move) static void Cmd_critcalc(void) { + u16 partySlot; s32 critChance = CalcCritChanceStage(gBattlerAttacker, gBattlerTarget, gCurrentMove, TRUE); gPotentialItemEffectBattler = gBattlerAttacker; @@ -1992,6 +1985,12 @@ static void Cmd_critcalc(void) else gIsCriticalHit = FALSE; + // Counter for EVO_CRITICAL_HITS. + partySlot = gBattlerPartyIndexes[gBattlerAttacker]; + if (gIsCriticalHit && GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER + && !(gBattleTypeFlags & BATTLE_TYPE_MULTI && GetBattlerPosition(gBattlerAttacker) == B_POSITION_PLAYER_LEFT)) + gPartyCriticalHits[partySlot]++; + gBattlescriptCurrInstr++; } @@ -3030,7 +3029,17 @@ void SetMoveEffect(bool32 primary, u32 certain) case MOVE_EFFECT_FLINCH: if (battlerAbility == ABILITY_INNER_FOCUS) { - gBattlescriptCurrInstr++; + if (primary == TRUE || certain == MOVE_EFFECT_CERTAIN) + { + gLastUsedAbility = ABILITY_INNER_FOCUS; + gBattlerAbility = gEffectBattler; + RecordAbilityBattle(gEffectBattler, ABILITY_INNER_FOCUS); + gBattlescriptCurrInstr = BattleScript_FlinchPrevention; + } + else + { + gBattlescriptCurrInstr++; + } } else { @@ -8703,7 +8712,7 @@ static void Cmd_various(void) gBattleStruct->mega.playerPrimalRevertedSpecies = gBattleStruct->mega.primalRevertedSpecies[gActiveBattler]; } // Checks Primal Reversion - primalSpecies = GetMegaEvolutionSpecies(gBattleStruct->mega.primalRevertedSpecies[gActiveBattler], gBattleMons[gActiveBattler].item); + primalSpecies = GetPrimalReversionSpecies(gBattleStruct->mega.primalRevertedSpecies[gActiveBattler], gBattleMons[gActiveBattler].item); gBattleMons[gActiveBattler].species = primalSpecies; PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); @@ -11072,6 +11081,10 @@ static void Cmd_tryKO(void) else { u16 odds = gBattleMoves[gCurrentMove].accuracy + (gBattleMons[gBattlerAttacker].level - gBattleMons[gBattlerTarget].level); + #if B_SHEER_COLD_ACC >= GEN_7 + if (gCurrentMove == MOVE_SHEER_COLD && !IS_BATTLER_OF_TYPE(gBattlerAttacker, TYPE_ICE)) + odds -= 10; + #endif if (Random() % 100 + 1 < odds && gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level) lands = TRUE; } @@ -12655,13 +12668,16 @@ static void Cmd_jumpifnodamage(void) static void Cmd_settaunt(void) { +#if B_OBLIVIOUS_TAUNT >= GEN_6 if (GetBattlerAbility(gBattlerTarget) == ABILITY_OBLIVIOUS) { gBattlescriptCurrInstr = BattleScript_NotAffectedAbilityPopUp; gLastUsedAbility = ABILITY_OBLIVIOUS; RecordAbilityBattle(gBattlerTarget, ABILITY_OBLIVIOUS); } - else if (gDisableStructs[gBattlerTarget].tauntTimer == 0) + else +#endif + if (gDisableStructs[gBattlerTarget].tauntTimer == 0) { #if B_TAUNT_TURNS >= GEN_5 u8 turns = 4; diff --git a/src/battle_util.c b/src/battle_util.c index cf9dff5e6..4072278b9 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -6207,12 +6207,18 @@ bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId) return FALSE; } +#if B_CONFUSE_BERRIES_HEAL >= GEN_7 + #define CONFUSE_BERRY_HP_FRACTION 4 +#else + #define CONFUSE_BERRY_HP_FRACTION 2 +#endif + static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) { #if B_HEAL_BLOCKING >= GEN_5 - if (HasEnoughHpToEatBerry(battlerId, 2, itemId) && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK)) + if (HasEnoughHpToEatBerry(battlerId, CONFUSE_BERRY_HP_FRACTION, itemId) && !(gStatuses3[battlerId] & STATUS3_HEAL_BLOCK)) #else - if (HasEnoughHpToEatBerry(battlerId, 2, itemId)) + if (HasEnoughHpToEatBerry(battlerId, CONFUSE_BERRY_HP_FRACTION, itemId)) #endif { PREPARE_FLAVOR_BUFFER(gBattleTextBuff1, flavorId); @@ -6249,6 +6255,8 @@ static u8 HealConfuseBerry(u32 battlerId, u32 itemId, u8 flavorId, bool32 end2) return 0; } +#undef CONFUSE_BERRY_HP_FRACTION + static u8 StatRaiseBerry(u32 battlerId, u32 itemId, u32 statId, bool32 end2) { if (CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN) && HasEnoughHpToEatBerry(battlerId, GetBattlerHoldEffectParam(battlerId), itemId)) @@ -7877,8 +7885,10 @@ bool32 IsBattlerGrounded(u8 battlerId) return TRUE; else if (gFieldStatuses & STATUS_FIELD_GRAVITY) return TRUE; +#if B_ROOTED_GROUNDING >= GEN_4 else if (gStatuses3[battlerId] & STATUS3_ROOTED) return TRUE; +#endif else if (gStatuses3[battlerId] & STATUS3_SMACKED_DOWN) return TRUE; @@ -9024,7 +9034,8 @@ static u32 CalcFinalDmg(u32 dmg, u16 move, u8 battlerAtk, u8 battlerDef, u8 move // check burn if (gBattleMons[battlerAtk].status1 & STATUS1_BURN && IS_MOVE_PHYSICAL(move) - && gBattleMoves[move].effect != EFFECT_FACADE && abilityAtk != ABILITY_GUTS) + && (gBattleMoves[move].effect != EFFECT_FACADE || B_BURN_FACADE_DMG < GEN_6) + && abilityAtk != ABILITY_GUTS) dmg = ApplyModifier(UQ_4_12(0.5), dmg); // check sunny/rain weather @@ -9439,8 +9450,20 @@ u16 GetMegaEvolutionSpecies(u16 preEvoSpecies, u16 heldItemId) for (i = 0; i < EVOS_PER_MON; i++) { - if ((gEvolutionTable[preEvoSpecies][i].method == EVO_MEGA_EVOLUTION - || gEvolutionTable[preEvoSpecies][i].method == EVO_PRIMAL_REVERSION) + if (gEvolutionTable[preEvoSpecies][i].method == EVO_MEGA_EVOLUTION + && gEvolutionTable[preEvoSpecies][i].param == heldItemId) + return gEvolutionTable[preEvoSpecies][i].targetSpecies; + } + return SPECIES_NONE; +} + +u16 GetPrimalReversionSpecies(u16 preEvoSpecies, u16 heldItemId) +{ + u32 i; + + for (i = 0; i < EVOS_PER_MON; i++) + { + if (gEvolutionTable[preEvoSpecies][i].method == EVO_PRIMAL_REVERSION && gEvolutionTable[preEvoSpecies][i].param == heldItemId) return gEvolutionTable[preEvoSpecies][i].targetSpecies; } @@ -9481,12 +9504,10 @@ bool32 CanMegaEvolve(u8 battlerId) // Check if trainer already mega evolved a pokemon. if (mega->alreadyEvolved[battlerPosition]) return FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - { - if (IsPartnerMonFromSameTrainer(battlerId) - && (mega->alreadyEvolved[partnerPosition] || (mega->toEvolve & gBitTable[BATTLE_PARTNER(battlerId)]))) - return FALSE; - } + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE + && IsPartnerMonFromSameTrainer(battlerId) + && (mega->alreadyEvolved[partnerPosition] || (mega->toEvolve & gBitTable[BATTLE_PARTNER(battlerId)]))) + return FALSE; // Check if mon is currently held by Sky Drop if (gStatuses3[battlerId] & STATUS3_SKY_DROPPED) @@ -9522,14 +9543,6 @@ bool32 CanMegaEvolve(u8 battlerId) gBattleStruct->mega.isWishMegaEvo = FALSE; return TRUE; } - - // Can undergo Primal Reversion. - if (holdEffect == HOLD_EFFECT_PRIMAL_ORB) - { - gBattleStruct->mega.isWishMegaEvo = FALSE; - gBattleStruct->mega.isPrimalReversion = TRUE; - return TRUE; - } } // Check if there is an entry in the evolution table for Wish Mega Evolution. @@ -9634,9 +9647,8 @@ bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId) // Mail can be stolen now if (itemId == ITEM_ENIGMA_BERRY) return FALSE; - else if (GET_BASE_SPECIES_ID(species) == SPECIES_KYOGRE && itemId == ITEM_BLUE_ORB) // includes primal - return FALSE; - else if (GET_BASE_SPECIES_ID(species) == SPECIES_GROUDON && itemId == ITEM_RED_ORB) // includes primal + // Primal Reversion inducing items cannot be lost if pokemon's base species can undergo primal reversion with it. + else if (holdEffect == HOLD_EFFECT_PRIMAL_ORB && (GetPrimalReversionSpecies(GET_BASE_SPECIES_ID(species), itemId) != SPECIES_NONE)) return FALSE; // Mega stone cannot be lost if pokemon's base species can mega evolve with it. else if (holdEffect == HOLD_EFFECT_MEGA_STONE && (GetMegaEvolutionSpecies(GET_BASE_SPECIES_ID(species), itemId) != SPECIES_NONE)) @@ -10222,3 +10234,12 @@ u32 GetBattlerMoveTargetType(u8 battlerId, u16 move) else return gBattleMoves[move].target; } + +bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move) +{ + if (gBattleMoves[move].effect == EFFECT_HIT_ENEMY_HEAL_ALLY + && GetBattlerSide(battlerAtk) == GetBattlerSide(battlerDef) + && gStatuses3[battlerAtk] & STATUS3_HEAL_BLOCK) + return FALSE; // Pokémon affected by Heal Block cannot target allies with Pollen Puff + return TRUE; +} diff --git a/src/data/text/move_descriptions.h b/src/data/text/move_descriptions.h index 942ab0fbf..5f6bcfb0e 100644 --- a/src/data/text/move_descriptions.h +++ b/src/data/text/move_descriptions.h @@ -79,7 +79,11 @@ static const u8 sFlyDescription[] = _( static const u8 sBindDescription[] = _( "Binds and squeezes the foe\n" +#if B_BINDING_TURNS >= GEN_5 + "for 4 or 5 turns."); +#else "for 2 to 5 turns."); +#endif static const u8 sSlamDescription[] = _( "Slams the foe with a long\n" @@ -139,7 +143,11 @@ static const u8 sBodySlamDescription[] = _( static const u8 sWrapDescription[] = _( "Wraps and squeezes the foe\n" +#if B_BINDING_TURNS >= GEN_5 + "4 or 5 times with vines, etc."); +#else "2 to 5 times with vines, etc."); +#endif static const u8 sTakeDownDescription[] = _( "A reckless charge attack\n" @@ -331,7 +339,11 @@ static const u8 sDragonRageDescription[] = _( static const u8 sFireSpinDescription[] = _( "Traps the foe in a ring of\n" +#if B_BINDING_TURNS >= GEN_5 + "fire for 4 or 5 turns."); +#else "fire for 2 to 5 turns."); +#endif static const u8 sThunderShockDescription[] = _( "An electrical attack that\n" @@ -511,7 +523,11 @@ static const u8 sWaterfallDescription[] = _( static const u8 sClampDescription[] = _( "Traps and squeezes the\n" +#if B_BINDING_TURNS >= GEN_5 + "foe for 4 or 5 turns."); +#else "foe for 2 to 5 turns."); +#endif static const u8 sSwiftDescription[] = _( "Sprays star-shaped rays\n" @@ -999,7 +1015,11 @@ static const u8 sRockSmashDescription[] = _( static const u8 sWhirlpoolDescription[] = _( "Traps and hurts the foe in\n" +#if B_BINDING_TURNS >= GEN_5 + "a whirlpool for 4 or 5 turns."); +#else "a whirlpool for 2 to 5 turns."); +#endif static const u8 sBeatUpDescription[] = _( "Summons party Pokémon to\n" @@ -1311,7 +1331,11 @@ static const u8 sSkyUppercutDescription[] = _( static const u8 sSandTombDescription[] = _( "Traps and hurts the foe in\n" +#if B_BINDING_TURNS >= GEN_5 + "quicksand for 4 or 5 turns."); +#else "quicksand for 2 to 5 turns."); +#endif static const u8 sSheerColdDescription[] = _( "A chilling attack that\n" @@ -1815,7 +1839,11 @@ static const u8 sSpacialRendDescription[] = _( static const u8 sMagmaStormDescription[] = _( "Traps the foe in a vortex\n" +#if B_BINDING_TURNS >= GEN_5 + "of fire for 4 or 5 turns."); +#else "of fire for 2 to 5 turns."); +#endif static const u8 sDarkVoidDescription[] = _( "Drags the foe into total\n" @@ -2367,7 +2395,11 @@ static const u8 sNuzzleDescription[] = _( static const u8 sInfestationDescription[] = _( "The foe is infested and\n" +#if B_BINDING_TURNS >= GEN_5 + "attacked for 4 or 5 turns."); +#else "attacked for 2 to 5 turns."); +#endif static const u8 sPowerUpPunchDescription[] = _( "A hard punch that raises\n" @@ -2912,7 +2944,11 @@ static const u8 sSurgingStrikesDescription[] = _( static const u8 sThunderCageDescription[] = _( "Traps the foe in a cage of\n" +#if B_BINDING_TURNS >= GEN_5 + "electricity for 4 or 5 turns."); +#else "electricity for 2 to 5 turns."); +#endif static const u8 sDragonEnergyDescription[] = _( "The higher the user's HP\n" diff --git a/src/pokemon.c b/src/pokemon.c index 71176d2eb..26f12dca2 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -6459,6 +6459,9 @@ void SetWildMonHeldItem(void) for (i = 0; i < count; i++) { + if (GetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, NULL) != ITEM_NONE) + continue; // prevent ovewriting previously set item + rnd = Random() % 100; species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES, 0); if (gMapHeader.mapLayoutId == LAYOUT_ALTERING_CAVE)