From 8ee9b104bab26b0238d976bfa4e72a287ba141ad Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 5 Nov 2025 11:10:32 +0100 Subject: [PATCH] more clean-up --- include/math.h | 24 ++-- include/move_orb_effects_1.h | 4 +- include/number_util.h | 5 +- src/dungeon_8041AD0.c | 2 +- src/dungeon_config.c | 74 +++++------ src/dungeon_cutscene_hooh.c | 4 +- src/dungeon_cutscene_mewtwo.c | 4 +- src/dungeon_cutscene_rayquaza.c | 4 +- src/dungeon_cutscene_suicune.c | 4 +- src/dungeon_mon_sprite_render.c | 2 +- src/dungeon_monster_house.c | 2 +- src/dungeon_move.c | 2 +- src/move_orb_actions_1.c | 18 +-- src/move_orb_actions_2.c | 6 +- src/move_orb_actions_3.c | 4 +- src/move_orb_effects_1.c | 213 ++++++++++++++++---------------- 16 files changed, 188 insertions(+), 184 deletions(-) diff --git a/include/math.h b/include/math.h index 6762b4a85..7eb5e1f96 100644 --- a/include/math.h +++ b/include/math.h @@ -51,17 +51,17 @@ bool8 FP48_16_SLessThan(const s48_16 *a, const s48_16 *b); void FP48_16_Add(s48_16 *dst, s48_16 *a, s48_16 *b); void FP48_16_Subtract(s48_16 *dst, s48_16 *a, s48_16 *b); -#define F248LessThanInt(x, y) (x < 0x100 * y) -#define F248LessThanFloat(x, y) (x < (int)(y * 0x100)) -#define FloatLessThanF248(x, y) ((int)(x * 0x100) < y) -#define F248LessThan(x, y) (x < y) -#define F248GreaterThan(x, y) (x > y) -#define F248Equal(x, y) (x == y) -#define F248EqualsInt(x, y) (x == 0x100 * y) -#define F248_AddInt(x, y) ((s24_8){x + 0x100 * y}) -#define F248_SubInt(x, y) ((s24_8){x - 0x100 * y}) -#define F248_Add(x, y)(x + y) -#define F248_Sub(x, y)(x - y) -#define F248_MulInt(x, y)(x * y) +#define F248LessThanInt(x, y) ((x) < 0x100 * (y)) +#define F248LessThanFloat(x, y) ((x) < (int)((y) * 0x100)) +#define FloatLessThanF248(x, y) ((int)((x) * 0x100) < (y)) +#define F248LessThan(x, y) ((x) < (y)) +#define F248GreaterThan(x, y) ((x) > (y)) +#define F248Equal(x, y) ((x) == (y)) +#define F248EqualsInt(x, y) ((x) == 0x100 * (y)) +#define F248_AddInt(x, y) ((s24_8)((x) + 0x100 * (y)) +#define F248_SubInt(x, y) ((s24_8)((x) - 0x100 * (y)) +#define F248_Add(x, y)((x) + (y)) +#define F248_Sub(x, y)((x) - (y)) +#define F248_MulInt(x, y)((x) * (y)) #endif // GUARD_MATH_H diff --git a/include/move_orb_effects_1.h b/include/move_orb_effects_1.h index 8777ad0ba..5435a6481 100644 --- a/include/move_orb_effects_1.h +++ b/include/move_orb_effects_1.h @@ -36,8 +36,8 @@ u8 GetFlashFireStatus(Entity *pokemon); void ActivateFlashFire(Entity * pokemon, Entity *target); void ApplyOffensiveStatMultiplier(Entity *user, Entity *target, struct StatIndex stat, s24_8 multiplier, bool8 displayMessage); void ApplyDefensiveStatMultiplier(Entity *user, Entity *target, struct StatIndex stat, s24_8 multiplier, bool8 displayMessage); -void RaiseAccuracyStageTarget(Entity * pokemon, Entity * target, struct StatIndex stat); -void LowerAccuracyStageTarget(Entity * pokemon, Entity * target, struct StatIndex stat, bool8 displayMessage); +void BoostHitChanceStat(Entity *user, Entity *target, struct StatIndex stat); +void LowerHitChanceStat(Entity *user, Entity *target, struct StatIndex stat, bool8 displayMessage); void CringeStatusTarget(Entity * pokemon,Entity * target, bool8 displayMessage); void ParalyzeStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage); void RaiseMovementSpeedTarget(Entity * pokemon, Entity * target, s32 turns, bool8 diplayMessage); diff --git a/include/number_util.h b/include/number_util.h index 7d585caa9..d17b6ef3f 100644 --- a/include/number_util.h +++ b/include/number_util.h @@ -56,8 +56,7 @@ void WriteBellyBits(DataSerializer *r0, FixedPoint *src); // Sometimes it's used directly as opposed to calling IntToFixedPoint #define IntToFixedPointMacro(x) ((FixedPoint){x, 0}) -#define IntToF248(x) (((x) << 8)) -#define FloatToF248(x) ((int)(x * 0x100)) -#define F248ToInt(x) ((s24_8)(x / 256)) +#define IntToF248(x) ((int)((x) * 0x100)) +#define F248ToInt(x) ((s24_8)((x) / 256)) #endif diff --git a/src/dungeon_8041AD0.c b/src/dungeon_8041AD0.c index b8895e32c..11faa80b3 100644 --- a/src/dungeon_8041AD0.c +++ b/src/dungeon_8041AD0.c @@ -1515,7 +1515,7 @@ static void sub_8042A84(s16 param_1, Entity *entity, u32 param_3) sub_804151C(entity,param_1_s16,0); sub_803E708(param_3,0x42); do { - if (entity->unk1C > FloatToF248(199.999)) break; + if (entity->unk1C > IntToF248(199.999)) break; DungeonRunFrameActions(0x42); entity->unk1C += + r6; r6 += IntToF248(1); diff --git a/src/dungeon_config.c b/src/dungeon_config.c index b399b6442..8ae2535f5 100644 --- a/src/dungeon_config.c +++ b/src/dungeon_config.c @@ -173,16 +173,16 @@ UNUSED static const s16 sUnusedConfig1 = 95; const s16 gGinsengPlus3BoostChance = 12; // Move modifiers -const s24_8 gSolarBeamModifier = FloatToF248(2.0); -const s24_8 gSkyAttackModifier = FloatToF248(2.0); -const s24_8 gRazorWindModifier = FloatToF248(2.0); -const s24_8 gFocusPunchModifier = FloatToF248(2.0); -const s24_8 gSkullBashModifier = FloatToF248(2.0); -const s24_8 gFlyModifier = FloatToF248(2.0); -const s24_8 gBounceModifier = FloatToF248(2.0); -const s24_8 gDiveModifier = FloatToF248(2.0); -const s24_8 gDigModifier = FloatToF248(2.0); -const s24_8 gFacadeModifier = FloatToF248(2.0); +const s24_8 gSolarBeamModifier = IntToF248(2.0); +const s24_8 gSkyAttackModifier = IntToF248(2.0); +const s24_8 gRazorWindModifier = IntToF248(2.0); +const s24_8 gFocusPunchModifier = IntToF248(2.0); +const s24_8 gSkullBashModifier = IntToF248(2.0); +const s24_8 gFlyModifier = IntToF248(2.0); +const s24_8 gBounceModifier = IntToF248(2.0); +const s24_8 gDiveModifier = IntToF248(2.0); +const s24_8 gDigModifier = IntToF248(2.0); +const s24_8 gFacadeModifier = IntToF248(2.0); // Fixed damage/heal values const s16 gBurnDmgValue = 5; @@ -275,42 +275,42 @@ UNUSED static const s16 sUnusedConfig3 = 0; // Stat stage multipliers const s24_8 gAtkStatStageMultipliers[21] = { - FloatToF248(0.2500), FloatToF248(0.2696), FloatToF248(0.2892), FloatToF248(0.3087), FloatToF248(0.3282), FloatToF248(0.3478), - FloatToF248(0.3985), FloatToF248(0.4493), FloatToF248(0.5000), FloatToF248(0.6993), FloatToF248(1.0000), FloatToF248(1.2969), - FloatToF248(1.5000), FloatToF248(1.5978), FloatToF248(1.6485), FloatToF248(1.6993), FloatToF248(1.7500), FloatToF248(1.7969), - FloatToF248(1.8478), FloatToF248(1.8985), FloatToF248(2.0000) + IntToF248(0.2500), IntToF248(0.2696), IntToF248(0.2892), IntToF248(0.3087), IntToF248(0.3282), IntToF248(0.3478), + IntToF248(0.3985), IntToF248(0.4493), IntToF248(0.5000), IntToF248(0.6993), IntToF248(1.0000), IntToF248(1.2969), + IntToF248(1.5000), IntToF248(1.5978), IntToF248(1.6485), IntToF248(1.6993), IntToF248(1.7500), IntToF248(1.7969), + IntToF248(1.8478), IntToF248(1.8985), IntToF248(2.0000) }; const s24_8 gDefStatStageMultipliers[21] = { - FloatToF248(0.2500), FloatToF248(0.2696), FloatToF248(0.2892), FloatToF248(0.3087), FloatToF248(0.3282), FloatToF248(0.3478), - FloatToF248(0.3985), FloatToF248(0.5469), FloatToF248(0.6993), FloatToF248(0.8672), FloatToF248(1.0000), FloatToF248(1.2969), - FloatToF248(1.5000), FloatToF248(1.5978), FloatToF248(1.6485), FloatToF248(1.6993), FloatToF248(1.7500), FloatToF248(1.7969), - FloatToF248(1.8478), FloatToF248(1.8985), FloatToF248(2.0000) + IntToF248(0.2500), IntToF248(0.2696), IntToF248(0.2892), IntToF248(0.3087), IntToF248(0.3282), IntToF248(0.3478), + IntToF248(0.3985), IntToF248(0.5469), IntToF248(0.6993), IntToF248(0.8672), IntToF248(1.0000), IntToF248(1.2969), + IntToF248(1.5000), IntToF248(1.5978), IntToF248(1.6485), IntToF248(1.6993), IntToF248(1.7500), IntToF248(1.7969), + IntToF248(1.8478), IntToF248(1.8985), IntToF248(2.0000) }; const s24_8 gAccEvsStatStageMultipliers[2][21] = { // Accuracy { - FloatToF248(0.3282), FloatToF248(0.3478), FloatToF248(0.3672), FloatToF248(0.3985), FloatToF248(0.4297), FloatToF248(0.4493), - FloatToF248(0.5469), FloatToF248(0.5977), FloatToF248(0.6993), FloatToF248(0.7969), FloatToF248(1.0000), FloatToF248(1.2500), - FloatToF248(1.5000), FloatToF248(1.5978), FloatToF248(1.6485), FloatToF248(1.6993), FloatToF248(1.7500), FloatToF248(1.7969), - FloatToF248(1.8478), FloatToF248(1.8985), FloatToF248(2.0000) + IntToF248(0.3282), IntToF248(0.3478), IntToF248(0.3672), IntToF248(0.3985), IntToF248(0.4297), IntToF248(0.4493), + IntToF248(0.5469), IntToF248(0.5977), IntToF248(0.6993), IntToF248(0.7969), IntToF248(1.0000), IntToF248(1.2500), + IntToF248(1.5000), IntToF248(1.5978), IntToF248(1.6485), IntToF248(1.6993), IntToF248(1.7500), IntToF248(1.7969), + IntToF248(1.8478), IntToF248(1.8985), IntToF248(2.0000) }, // Evasion { - FloatToF248(2.0000), FloatToF248(1.8985), FloatToF248(1.8478), FloatToF248(1.7969), FloatToF248(1.7500), FloatToF248(1.6993), - FloatToF248(1.6485), FloatToF248(1.5978), FloatToF248(1.5000), FloatToF248(1.3515), FloatToF248(1.0000), FloatToF248(0.7969), - FloatToF248(0.6993), FloatToF248(0.5977), FloatToF248(0.5000), FloatToF248(0.3985), FloatToF248(0.3477), FloatToF248(0.2969), - FloatToF248(0.2500), FloatToF248(0.1993), FloatToF248(0.1485) + IntToF248(2.0000), IntToF248(1.8985), IntToF248(1.8478), IntToF248(1.7969), IntToF248(1.7500), IntToF248(1.6993), + IntToF248(1.6485), IntToF248(1.5978), IntToF248(1.5000), IntToF248(1.3515), IntToF248(1.0000), IntToF248(0.7969), + IntToF248(0.6993), IntToF248(0.5977), IntToF248(0.5000), IntToF248(0.3985), IntToF248(0.3477), IntToF248(0.2969), + IntToF248(0.2500), IntToF248(0.1993), IntToF248(0.1485) }, }; const s32 gDetectBandAccuracyDebuffValue = 30; // For attacking mon, which effectively raises target's evasion const s32 gIqQuickDodgerAccuracyDebuffValue = 30; // For attacking mon, which effectively raises target's evasion // Move modifiers again -const s24_8 gReversalModifiers[4] = {FloatToF248(8), FloatToF248(4), FloatToF248(2), FloatToF248(1)}; // Based on hp/max HP ratio -const s24_8 gWaterSpoutModifiers[4] = {FloatToF248(0.1), FloatToF248(0.2), FloatToF248(0.5), FloatToF248(1)}; // Based on hp/max HP ratio -const s24_8 gEruptionModifiers[4] = {FloatToF248(0.1), FloatToF248(0.2), FloatToF248(0.5), FloatToF248(1)}; // Based on hp/max HP ratio +const s24_8 gReversalModifiers[4] = {IntToF248(8), IntToF248(4), IntToF248(2), IntToF248(1)}; // Based on hp/max HP ratio +const s24_8 gWaterSpoutModifiers[4] = {IntToF248(0.1), IntToF248(0.2), IntToF248(0.5), IntToF248(1)}; // Based on hp/max HP ratio +const s24_8 gEruptionModifiers[4] = {IntToF248(0.1), IntToF248(0.2), IntToF248(0.5), IntToF248(1)}; // Based on hp/max HP ratio const s32 gStockpileHealHpValues[4] = {0, 20, 40, 80}; // Castform related @@ -327,14 +327,14 @@ const u8 gWeatherBallTypes[WEATHER_COUNT] = }; const s24_8 gWeatherBallModifiers[WEATHER_COUNT] = { - [WEATHER_CLEAR] = FloatToF248(1.0), - [WEATHER_SUNNY] = FloatToF248(2.0), - [WEATHER_SANDSTORM] = FloatToF248(2.0), - [WEATHER_CLOUDY] = FloatToF248(1.0), - [WEATHER_RAIN] = FloatToF248(2.0), - [WEATHER_HAIL] = FloatToF248(2.0), - [WEATHER_FOG] = FloatToF248(2.0), - [WEATHER_SNOW] = FloatToF248(2.0), + [WEATHER_CLEAR] = IntToF248(1.0), + [WEATHER_SUNNY] = IntToF248(2.0), + [WEATHER_SANDSTORM] = IntToF248(2.0), + [WEATHER_CLOUDY] = IntToF248(1.0), + [WEATHER_RAIN] = IntToF248(2.0), + [WEATHER_HAIL] = IntToF248(2.0), + [WEATHER_FOG] = IntToF248(2.0), + [WEATHER_SNOW] = IntToF248(2.0), }; const struct CastformWeatherData gCastformByWeather[WEATHER_COUNT] = diff --git a/src/dungeon_cutscene_hooh.c b/src/dungeon_cutscene_hooh.c index 8632fb51e..93c526feb 100644 --- a/src/dungeon_cutscene_hooh.c +++ b/src/dungeon_cutscene_hooh.c @@ -175,9 +175,9 @@ static void HoOhDropInEffect(Entity * param_1) PlaySoundEffect(0x1f8); while( 1 ) { iVar2 -= iVar1; - iVar1 = F248_Sub(iVar1, FloatToF248(0.375)); + iVar1 = F248_Sub(iVar1, IntToF248(0.375)); if (F248LessThanFloat(iVar1, 0.08)) { - iVar1 = FloatToF248(0.08); + iVar1 = IntToF248(0.08); } if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(param_1)->unk174 = iVar2; diff --git a/src/dungeon_cutscene_mewtwo.c b/src/dungeon_cutscene_mewtwo.c index fff89cdd8..7595a0353 100644 --- a/src/dungeon_cutscene_mewtwo.c +++ b/src/dungeon_cutscene_mewtwo.c @@ -149,9 +149,9 @@ static void MewtwoDropInEffect(Entity *mewtwoEntity) PlaySoundEffect(0x1f8); while( 1 ) { iVar2 -= iVar1; - iVar1 = F248_Sub(iVar1, FloatToF248(0.045)); + iVar1 = F248_Sub(iVar1, IntToF248(0.045)); if (F248LessThanFloat(iVar1, 0.12)) { - iVar1 = FloatToF248(0.12); + iVar1 = IntToF248(0.12); } if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(mewtwoEntity)->unk174 = iVar2; diff --git a/src/dungeon_cutscene_rayquaza.c b/src/dungeon_cutscene_rayquaza.c index 71f47ef39..cb2960da0 100644 --- a/src/dungeon_cutscene_rayquaza.c +++ b/src/dungeon_cutscene_rayquaza.c @@ -186,9 +186,9 @@ static void RayquazaDropInEffect(Entity *rayquazaEntity) PlaySoundEffect(0x1f8); while( 1 ) { iVar2 = iVar2 - iVar1; // must be - iVar1 = F248_Sub(iVar1, FloatToF248(3./32.)); + iVar1 = F248_Sub(iVar1, IntToF248(3./32.)); if (F248LessThanFloat(iVar1, 0.08)) { - iVar1 = FloatToF248(0.08); + iVar1 = IntToF248(0.08); } if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(rayquazaEntity)->unk174 = iVar2; diff --git a/src/dungeon_cutscene_suicune.c b/src/dungeon_cutscene_suicune.c index 0363853e6..e9ed25d9d 100644 --- a/src/dungeon_cutscene_suicune.c +++ b/src/dungeon_cutscene_suicune.c @@ -172,9 +172,9 @@ static void sub_808A528(Entity * param_1) PlaySoundEffect(0x1f8); while( 1 ) { iVar2 -= iVar1; - iVar1 = F248_Sub(iVar1, FloatToF248(0.375)); + iVar1 = F248_Sub(iVar1, IntToF248(0.375)); if (F248LessThanFloat(iVar1, 0.08)) { - iVar1 = FloatToF248(0.08); + iVar1 = IntToF248(0.08); } if (F248LessThanInt(iVar2, 0)) break; GetEntInfo(param_1)->unk174 = iVar2; diff --git a/src/dungeon_mon_sprite_render.c b/src/dungeon_mon_sprite_render.c index d3433a745..342f8f086 100644 --- a/src/dungeon_mon_sprite_render.c +++ b/src/dungeon_mon_sprite_render.c @@ -219,7 +219,7 @@ void UpdateMonsterSprite(Entity *entity) sub_8042EC8(entity, y2); if (entInfo->unk15C == 0) { if (entInfo->unkFF == 1) { - if (entInfo->unk174 <= FloatToF248(199.999)) { + if (entInfo->unk174 <= IntToF248(199.999)) { entInfo->unk174 += IntToF248(8); if (entInfo->unk174 > IntToF248(200)) { entInfo->unk174 = IntToF248(200); diff --git a/src/dungeon_monster_house.c b/src/dungeon_monster_house.c index 17ed9be3d..4ea690223 100644 --- a/src/dungeon_monster_house.c +++ b/src/dungeon_monster_house.c @@ -166,7 +166,7 @@ void TriggerMonsterHouse(Entity *entity, bool8 forcedMonsterHouse) if (EntityIsValid(newMonster)) { newMonster->unk1C = IntToF248(200); for (j = 0; j < 100; j++) { - newMonster->unk1C = s24_8_mul(newMonster->unk1C, FloatToF248(0.665)); + newMonster->unk1C = s24_8_mul(newMonster->unk1C, IntToF248(0.665)); if (newMonster->unk1C < IntToF248(1)) { break; } diff --git a/src/dungeon_move.c b/src/dungeon_move.c index 2f259a95b..b4e03e5be 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -392,7 +392,7 @@ void UseMoveAgainstTargets(Entity **targetsArray, Entity *attacker, Move *move, moveHadEffect = (HandleDamagingMove(attacker, currTarget, move, IntToF248(1), itemId) != 0); break; case MOVE_REGULAR_ATTACK: - moveHadEffect = (HandleDamagingMove(attacker, currTarget, move, FloatToF248(0.5), itemId) != 0); + moveHadEffect = (HandleDamagingMove(attacker, currTarget, move, IntToF248(0.5), itemId) != 0); break; case MOVE_NOTHING: moveHadEffect = (HandleDamagingMove(attacker, currTarget, move, IntToF248(0), itemId) != 0); diff --git a/src/move_orb_actions_1.c b/src/move_orb_actions_1.c index 361276bec..1cf60d7bb 100644 --- a/src/move_orb_actions_1.c +++ b/src/move_orb_actions_1.c @@ -56,7 +56,7 @@ bool8 IronTailMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId } static const s24_8 sRolloutModifiers[] = { - FloatToF248(1.0), FloatToF248(1.0), FloatToF248(1.5), FloatToF248(2.0), FloatToF248(2.5), FloatToF248(3.0), FloatToF248(3.5), FloatToF248(4.0), FloatToF248(4.5), FloatToF248(5.0) + IntToF248(1.0), IntToF248(1.0), IntToF248(1.5), IntToF248(2.0), IntToF248(2.5), IntToF248(3.0), IntToF248(3.5), IntToF248(4.0), IntToF248(4.5), IntToF248(5.0) }; bool8 sub_805768C(Entity *pokemon, Entity *target, Move *move, s32 itemId) @@ -129,13 +129,13 @@ bool8 DigMoveAction(Entity * pokemon, Entity * target, Move *move, s32 itemId) bool8 SweetScentMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - LowerAccuracyStageTarget(pokemon,target,gStatIndexSpecial,TRUE); + LowerHitChanceStat(pokemon,target,gStatIndexSpecial,TRUE); return TRUE; } bool8 CharmMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexAtkDef,FloatToF248(0.5),TRUE); + ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexAtkDef,IntToF248(0.5),TRUE); return TRUE; } @@ -325,7 +325,7 @@ bool8 SnoreMoveAction(Entity *pokemon, Entity *target, Move * move, s32 itemId) bool8 ScreechMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - ApplyDefensiveStatMultiplier(pokemon, target, gStatIndexAtkDef, FloatToF248(0.25), 1); + ApplyDefensiveStatMultiplier(pokemon, target, gStatIndexAtkDef, IntToF248(0.25), 1); return TRUE; } @@ -446,7 +446,7 @@ bool8 AuroraBeamMoveAction(Entity *pokemon, Entity *target, Move *move, s32 item flag = TRUE; if(sub_805727C(pokemon, target, gAuroraBeamAtkLowerChance)) { - ApplyOffensiveStatMultiplier(pokemon, target, gStatIndexAtkDef, FloatToF248(0.5), FALSE); + ApplyOffensiveStatMultiplier(pokemon, target, gStatIndexAtkDef, IntToF248(0.5), FALSE); } } return flag; @@ -458,8 +458,8 @@ bool8 MementoMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) entityInfo = GetEntInfo(pokemon); entityInfo->HP = 1; - ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexAtkDef,FloatToF248(0.25),TRUE); - ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexSpecial,FloatToF248(0.25),TRUE); + ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexAtkDef,IntToF248(0.25),TRUE); + ApplyOffensiveStatMultiplier(pokemon,target,gStatIndexSpecial,IntToF248(0.25),TRUE); entityInfo->unk154 = 1; return TRUE; } @@ -473,7 +473,7 @@ bool8 OctazookaMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemI flag = TRUE; if(sub_805727C(pokemon, target, gOctazookaAccLowerChance)) { - LowerAccuracyStageTarget(pokemon, target, gStatIndexAtkDef, FALSE); + LowerHitChanceStat(pokemon, target, gStatIndexAtkDef, FALSE); } } return flag; @@ -596,7 +596,7 @@ bool8 ExposeMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) bool8 DoubleTeamMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - RaiseAccuracyStageTarget(pokemon, target, gStatIndexSpecial); + BoostHitChanceStat(pokemon, target, gStatIndexSpecial); return TRUE; } diff --git a/src/move_orb_actions_2.c b/src/move_orb_actions_2.c index c12671f94..6d2315941 100644 --- a/src/move_orb_actions_2.c +++ b/src/move_orb_actions_2.c @@ -537,7 +537,7 @@ bool8 SandstormMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemI bool8 sub_8059528(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - LowerAccuracyStageTarget(pokemon, target, gStatIndexAtkDef, TRUE); + LowerHitChanceStat(pokemon, target, gStatIndexAtkDef, TRUE); return TRUE; } @@ -677,7 +677,7 @@ bool8 MuddyWaterMoveAction(Entity *pokemon, Entity *target, Move *move, s32 item flag = TRUE; if(sub_805727C(pokemon, target, gMuddyWaterAccLowerChance)) { - LowerAccuracyStageTarget(pokemon, target, gStatIndexAtkDef, FALSE); + LowerHitChanceStat(pokemon, target, gStatIndexAtkDef, FALSE); } } return flag; @@ -737,7 +737,7 @@ bool8 sub_80599EC(Entity *pokemon, Entity *target, Move *move, s32 itemId) bool8 MinimizeMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) { - RaiseAccuracyStageTarget(pokemon, target, gStatIndexSpecial); + BoostHitChanceStat(pokemon, target, gStatIndexSpecial); return TRUE; } diff --git a/src/move_orb_actions_3.c b/src/move_orb_actions_3.c index 63039abcf..ad64ffc33 100644 --- a/src/move_orb_actions_3.c +++ b/src/move_orb_actions_3.c @@ -260,7 +260,7 @@ bool8 MudSlapMoveAction(Entity *pokemon, Entity *target, Move *move, s32 itemId) flag = TRUE; if(sub_805727C(pokemon, target, 0)) { - LowerAccuracyStageTarget(pokemon, target, gStatIndexAtkDef, FALSE); + LowerHitChanceStat(pokemon, target, gStatIndexAtkDef, FALSE); } } return flag; @@ -715,7 +715,7 @@ bool8 SecretPowerMoveAction(Entity * pokemon, Entity * target, Move *move, s32 i LowerDefensiveStat(pokemon,target,gStatIndexAtkDef,1,1,FALSE); break; case 5: - LowerAccuracyStageTarget(pokemon,target,gStatIndexAtkDef,FALSE); + LowerHitChanceStat(pokemon,target,gStatIndexAtkDef,FALSE); break; case 6: ConfuseStatusTarget(pokemon,target,FALSE); diff --git a/src/move_orb_effects_1.c b/src/move_orb_effects_1.c index 5f873f0fb..5fd6d9d6b 100644 --- a/src/move_orb_effects_1.c +++ b/src/move_orb_effects_1.c @@ -1121,10 +1121,10 @@ void ApplyOffensiveStatMultiplier(Entity *user, Entity *target, struct StatIndex entityInfo->offensiveMultipliers[stat.id] = s24_8_mul(entityInfo->offensiveMultipliers[stat.id],multiplier); if (F248LessThanFloat(entityInfo->offensiveMultipliers[stat.id], 0.01)) { - entityInfo->offensiveMultipliers[stat.id] = FloatToF248(0.01); + entityInfo->offensiveMultipliers[stat.id] = IntToF248(0.01); } if (FloatLessThanF248(99.99, entityInfo->offensiveMultipliers[stat.id])) { - entityInfo->offensiveMultipliers[stat.id] = FloatToF248(99.99); + entityInfo->offensiveMultipliers[stat.id] = IntToF248(99.99); } if (F248GreaterThan(oldMulti, entityInfo->offensiveMultipliers[stat.id])) { @@ -1172,10 +1172,10 @@ void ApplyDefensiveStatMultiplier(Entity *user, Entity *target, struct StatIndex entityInfo->defensiveMultipliers[stat.id] = s24_8_mul(entityInfo->defensiveMultipliers[stat.id],multiplier); if (F248LessThanFloat(entityInfo->defensiveMultipliers[stat.id], 0.01)) { - entityInfo->defensiveMultipliers[stat.id] = FloatToF248(0.01); + entityInfo->defensiveMultipliers[stat.id] = IntToF248(0.01); } if (FloatLessThanF248(99.99, entityInfo->defensiveMultipliers[stat.id])) { - entityInfo->defensiveMultipliers[stat.id] = FloatToF248(99.99); + entityInfo->defensiveMultipliers[stat.id] = IntToF248(99.99); } if (F248GreaterThan(oldMulti, entityInfo->defensiveMultipliers[stat.id])) { @@ -1190,11 +1190,13 @@ void ApplyDefensiveStatMultiplier(Entity *user, Entity *target, struct StatIndex EntityUpdateStatusSprites(target); } -void RaiseAccuracyStageTarget(Entity * pokemon, Entity * target, struct StatIndex stat) +void BoostHitChanceStat(Entity *user, Entity *target, struct StatIndex stat) { - EntityInfo *entityInfo; + EntityInfo *entityInfo; + + if (!EntityIsValid(target)) + return; - if (EntityIsValid(target)) { entityInfo = GetEntInfo(target); SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); sub_8042040(target,stat); @@ -1204,140 +1206,143 @@ void RaiseAccuracyStageTarget(Entity * pokemon, Entity * target, struct StatInde else { strcpy(gFormatBuffer_Items[0],gUnknown_80FC084); } + if (entityInfo->hitChanceStages[stat.id] < MAX_STAT_STAGE) { - entityInfo->hitChanceStages[stat.id]++; - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC1C4); + entityInfo->hitChanceStages[stat.id]++; + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FC1C4); } else { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC218); + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FC218); } EntityUpdateStatusSprites(target); - } } -void LowerAccuracyStageTarget(Entity * pokemon, Entity * target, struct StatIndex stat, bool8 displayMessage) +void LowerHitChanceStat(Entity *user, Entity *target, struct StatIndex stat, bool8 displayMessage) { - EntityInfo *entityInfo; + EntityInfo *entityInfo; + + if (!EntityIsValid(target)) + return; - if (EntityIsValid(target)) { if (stat.id != STAT_INDEX_ACCURACY) { strcpy(gFormatBuffer_Items[0],gUnknown_80FC090); } else { strcpy(gFormatBuffer_Items[0],gUnknown_80FC084); } - if (!IsProtectedFromStatDrops(pokemon,target,displayMessage)) { - if (AbilityIsActive(target, ABILITY_KEEN_EYE) && (stat.id == STAT_INDEX_ACCURACY)){ - if(displayMessage) - { + + if (IsProtectedFromStatDrops(user,target,displayMessage)) + return; + + if (AbilityIsActive(target, ABILITY_KEEN_EYE) && stat.id == STAT_INDEX_ACCURACY) { + if (displayMessage) { SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCA64); + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FCA64); } - } - else { - entityInfo = GetEntInfo(target); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - sub_8042060(target,stat.id); - if (entityInfo->hitChanceStages[stat.id] != 0) { - entityInfo->hitChanceStages[stat.id]--; - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC1A4); - } - else { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC1F0); - } - EntityUpdateStatusSprites(target); - } + return; } - } + + entityInfo = GetEntInfo(target); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + sub_8042060(target,stat.id); + if (entityInfo->hitChanceStages[stat.id] != 0) { + entityInfo->hitChanceStages[stat.id]--; + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FC1A4); + } + else { + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FC1F0); + } + EntityUpdateStatusSprites(target); } -void CringeStatusTarget(Entity * pokemon,Entity * target, bool8 displayMessage) +void CringeStatusTarget(Entity *user ,Entity *target, bool8 displayMessage) { - EntityInfo *entityInfo; + EntityInfo *entityInfo; - if (EntityIsValid(target)) { - if (!HasSafeguardStatus(pokemon, target, displayMessage)) { - if (AbilityIsActive(target, ABILITY_INNER_FOCUS)){ - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - if(displayMessage) - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCC18); - } - else { - entityInfo = GetEntInfo(target); + if (!EntityIsValid(target)) + return; + + if (HasSafeguardStatus(user, target, displayMessage)) + return; + + if (AbilityIsActive(target, ABILITY_INNER_FOCUS)){ SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - if(entityInfo->cringeClassStatus.status != STATUS_CRINGE) - { - entityInfo->cringeClassStatus.status = STATUS_CRINGE; - entityInfo->cringeClassStatus.turns = CalculateStatusTurns(target, gCringeTurnRange, TRUE) + 1; - sub_80420A0(target); - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FB2E0); - } - else - { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FB300); - } - EntityUpdateStatusSprites(target); - } + if (displayMessage) + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FCC18); + return; } - } + + entityInfo = GetEntInfo(target); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + if (entityInfo->cringeClassStatus.status != STATUS_CRINGE) { + entityInfo->cringeClassStatus.status = STATUS_CRINGE; + entityInfo->cringeClassStatus.turns = CalculateStatusTurns(target, gCringeTurnRange, TRUE) + 1; + sub_80420A0(target); + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FB2E0); + } + else { + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FB300); + } + EntityUpdateStatusSprites(target); } -void ParalyzeStatusTarget(Entity * pokemon, Entity * target, bool8 displayMessage) +void ParalyzeStatusTarget(Entity *user, Entity *target, bool8 displayMessage) { - const Tile *mapTile; - EntityInfo *entityInfo; - Entity *mapPokemonEntity; - int index; - bool8 bVar6; - bool8 bVar7; + EntityInfo *entityInfo; + bool8 alreadyParalyzed; + + if (!EntityIsValid(target)) + return; + + if (HasSafeguardStatus(user, target, displayMessage)) + return; - if ((EntityIsValid(target)) && (!HasSafeguardStatus(pokemon,target,displayMessage))) { if (AbilityIsActive(target, ABILITY_LIMBER)) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - if (displayMessage) { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FCBF8); - } + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + if (displayMessage) { + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FCBF8); + } + return; } - else - { - bVar6 = TRUE; - entityInfo = GetEntInfo(target); - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - if (entityInfo->burnClassStatus.status != STATUS_PARALYSIS) { + + alreadyParalyzed = TRUE; + entityInfo = GetEntInfo(target); + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + if (entityInfo->burnClassStatus.status != STATUS_PARALYSIS) { entityInfo->burnClassStatus.status = STATUS_PARALYSIS; entityInfo->burnClassStatus.turns = CalculateStatusTurns(target,gParalysisTurnRange,TRUE) + 1; entityInfo->burnClassStatus.damageCountdown = 0; entityInfo->burnClassStatus.badlyPoisonedDamageCount = 0; - bVar6 = FALSE; - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FB2AC); + alreadyParalyzed = FALSE; + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FB2AC); sub_8041C1C(target); CalcSpeedStage(target); - } - else { - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FB2CC); - } - if ((AbilityIsActive(target, ABILITY_SYNCHRONIZE)) && (!bVar6)) { - bVar7 = FALSE; - - for(index = 0; index < NUM_DIRECTIONS; index++) - { - mapTile = GetTile(target->pos.x + gAdjacentTileOffsets[index].x,target->pos.y + gAdjacentTileOffsets[index].y); - mapPokemonEntity = mapTile->monster; - if ((EntityIsValid(mapPokemonEntity)) && (GetEntityType(mapPokemonEntity) == ENTITY_MONSTER)) { - if (!bVar7) { - bVar7 = TRUE; - SetMessageArgument_2(gFormatBuffer_Monsters[0],entityInfo,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FF01C); - } - if (GetTreatmentBetweenMonstersIgnoreStatus(target,mapPokemonEntity) == TREATMENT_TREAT_AS_ENEMY) { - ParalyzeStatusTarget(pokemon, mapPokemonEntity, displayMessage); - } - } - } - } - EntityUpdateStatusSprites(target); } - } + else { + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FB2CC); + } + + if (AbilityIsActive(target, ABILITY_SYNCHRONIZE) && !alreadyParalyzed) { + s32 i; + bool8 synchronizePrinted = FALSE; + + for (i = 0; i < NUM_DIRECTIONS; i++) { + const Tile *mapTile = GetTile(target->pos.x + gAdjacentTileOffsets[i].x,target->pos.y + gAdjacentTileOffsets[i].y); + Entity *mapMonster = mapTile->monster; + if (EntityIsValid(mapMonster) && GetEntityType(mapMonster) == ENTITY_MONSTER) { + if (!synchronizePrinted) { + synchronizePrinted = TRUE; + SetMessageArgument_2(gFormatBuffer_Monsters[0],entityInfo,0); + TryDisplayDungeonLoggableMessage3(user,target,gUnknown_80FF01C); + } + if (GetTreatmentBetweenMonstersIgnoreStatus(target,mapMonster) == TREATMENT_TREAT_AS_ENEMY) { + ParalyzeStatusTarget(user, mapMonster, displayMessage); + } + } + } + } + + EntityUpdateStatusSprites(target); } void RaiseMovementSpeedTarget(Entity * pokemon, Entity * target, s32 turns, bool8 displayMessage)