Fixes Hidden Power dynamic type bug (#5463)

This commit is contained in:
Alex 2024-10-03 10:36:35 +02:00 committed by GitHub
parent 2597d8a35a
commit f082fe7e42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 84 additions and 94 deletions

View file

@ -5829,8 +5829,9 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
type3 = TYPE_MYSTERY; type3 = TYPE_MYSTERY;
} }
if (moveEffect == EFFECT_WEATHER_BALL) switch (moveEffect)
{ {
case EFFECT_WEATHER_BALL:
if (gMain.inBattle && WEATHER_HAS_EFFECT) if (gMain.inBattle && WEATHER_HAS_EFFECT)
{ {
if (gBattleWeather & B_WEATHER_RAIN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA) if (gBattleWeather & B_WEATHER_RAIN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA)
@ -5864,79 +5865,86 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
} }
return moveType; return moveType;
} }
} break;
else if (moveEffect == EFFECT_HIDDEN_POWER) case EFFECT_HIDDEN_POWER:
{
u8 typeBits;
if (gMain.inBattle)
{ {
typeBits = ((gBattleMons[battler].hpIV & 1) << 0) u32 typeBits = 0;
| ((gBattleMons[battler].attackIV & 1) << 1) if (gMain.inBattle)
| ((gBattleMons[battler].defenseIV & 1) << 2) {
| ((gBattleMons[battler].speedIV & 1) << 3) typeBits = ((gBattleMons[battler].hpIV & 1) << 0)
| ((gBattleMons[battler].spAttackIV & 1) << 4) | ((gBattleMons[battler].attackIV & 1) << 1)
| ((gBattleMons[battler].spDefenseIV & 1) << 5); | ((gBattleMons[battler].defenseIV & 1) << 2)
} | ((gBattleMons[battler].speedIV & 1) << 3)
else | ((gBattleMons[battler].spAttackIV & 1) << 4)
{ | ((gBattleMons[battler].spDefenseIV & 1) << 5);
typeBits = ((GetMonData(mon, MON_DATA_HP_IV) & 1) << 0) }
| ((GetMonData(mon, MON_DATA_ATK_IV) & 1) << 1) else
| ((GetMonData(mon, MON_DATA_DEF_IV) & 1) << 2) {
| ((GetMonData(mon, MON_DATA_SPEED_IV) & 1) << 3) typeBits = ((GetMonData(mon, MON_DATA_HP_IV) & 1) << 0)
| ((GetMonData(mon, MON_DATA_SPATK_IV) & 1) << 4) | ((GetMonData(mon, MON_DATA_ATK_IV) & 1) << 1)
| ((GetMonData(mon, MON_DATA_SPDEF_IV) & 1) << 5); | ((GetMonData(mon, MON_DATA_DEF_IV) & 1) << 2)
} | ((GetMonData(mon, MON_DATA_SPEED_IV) & 1) << 3)
| ((GetMonData(mon, MON_DATA_SPATK_IV) & 1) << 4)
| ((GetMonData(mon, MON_DATA_SPDEF_IV) & 1) << 5);
}
// Subtract 6 instead of 1 below because 5 types are excluded (TYPE_NONE, TYPE_NORMAL, TYPE_MYSTERY, TYPE_FAIRY and TYPE_STELLAR) // Subtract 6 instead of 1 below because 5 types are excluded (TYPE_NONE, TYPE_NORMAL, TYPE_MYSTERY, TYPE_FAIRY and TYPE_STELLAR)
// The final + 2 skips past TYPE_NONE and Normal. // The final + 2 skips past TYPE_NONE and Normal.
moveType = ((NUMBER_OF_MON_TYPES - 6) * typeBits) / 63 + 2; moveType = ((NUMBER_OF_MON_TYPES - 6) * typeBits) / 63 + 2;
if (moveType >= TYPE_MYSTERY) if (moveType >= TYPE_MYSTERY)
moveType++; moveType++;
return (moveType | F_DYNAMIC_TYPE_IGNORE_PHYSICALITY); return ((moveType | F_DYNAMIC_TYPE_IGNORE_PHYSICALITY) & 0x3F);
} }
else if (moveEffect == EFFECT_CHANGE_TYPE_ON_ITEM && holdEffect == gMovesInfo[move].argument) break;
{ case EFFECT_CHANGE_TYPE_ON_ITEM:
return ItemId_GetSecondaryId(heldItem); if (holdEffect == gMovesInfo[move].argument)
} return ItemId_GetSecondaryId(heldItem);
else if (moveEffect == EFFECT_REVELATION_DANCE && GetActiveGimmick(battler) != GIMMICK_Z_MOVE) break;
{ case EFFECT_REVELATION_DANCE:
u8 teraType; if (GetActiveGimmick(battler) != GIMMICK_Z_MOVE)
if (GetActiveGimmick(battler) == GIMMICK_TERA && ((teraType = GetMonData(mon, MON_DATA_TERA_TYPE)) != TYPE_STELLAR)) {
return teraType; u32 teraType;
else if (type1 != TYPE_MYSTERY && !(gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST && type1 == TYPE_FLYING)) if (GetActiveGimmick(battler) == GIMMICK_TERA && ((teraType = GetMonData(mon, MON_DATA_TERA_TYPE)) != TYPE_STELLAR))
return type1; return teraType;
else if (type2 != TYPE_MYSTERY && !(gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST && type2 == TYPE_FLYING)) else if (type1 != TYPE_MYSTERY && !(gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST && type1 == TYPE_FLYING))
return type1;
else if (type2 != TYPE_MYSTERY && !(gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST && type2 == TYPE_FLYING))
return type2;
else if (gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST)
return (B_ROOST_PURE_FLYING >= GEN_5 ? TYPE_NORMAL : TYPE_MYSTERY);
else if (type3 != TYPE_MYSTERY)
return type3;
else
return TYPE_MYSTERY;
}
break;
case EFFECT_RAGING_BULL:
switch (species)
{
case SPECIES_TAUROS_PALDEA_COMBAT:
case SPECIES_TAUROS_PALDEA_BLAZE:
case SPECIES_TAUROS_PALDEA_AQUA:
return type2; return type2;
else if (gBattleResources->flags->flags[battler] & RESOURCE_FLAG_ROOST) }
return (B_ROOST_PURE_FLYING >= GEN_5 ? TYPE_NORMAL : TYPE_MYSTERY); break;
else if (type3 != TYPE_MYSTERY) case EFFECT_IVY_CUDGEL:
return type3; switch (species)
else {
return TYPE_MYSTERY; case SPECIES_OGERPON_WELLSPRING:
} case SPECIES_OGERPON_HEARTHFLAME:
else if (moveEffect == EFFECT_RAGING_BULL case SPECIES_OGERPON_CORNERSTONE:
&& (species == SPECIES_TAUROS_PALDEA_COMBAT case SPECIES_OGERPON_WELLSPRING_TERA:
|| species == SPECIES_TAUROS_PALDEA_BLAZE case SPECIES_OGERPON_HEARTHFLAME_TERA:
|| species == SPECIES_TAUROS_PALDEA_AQUA)) case SPECIES_OGERPON_CORNERSTONE_TERA:
{ return type2;
return type2; }
} break;
else if (moveEffect == EFFECT_IVY_CUDGEL case EFFECT_NATURAL_GIFT:
&& (species == SPECIES_OGERPON_WELLSPRING || species == SPECIES_OGERPON_WELLSPRING_TERA
|| species == SPECIES_OGERPON_HEARTHFLAME || species == SPECIES_OGERPON_HEARTHFLAME_TERA
|| species == SPECIES_OGERPON_CORNERSTONE || species == SPECIES_OGERPON_CORNERSTONE_TERA))
{
return type2;
}
else if (moveEffect == EFFECT_NATURAL_GIFT)
{
if (ItemId_GetPocket(heldItem) == POCKET_BERRIES) if (ItemId_GetPocket(heldItem) == POCKET_BERRIES)
return gNaturalGiftTable[ITEM_TO_BERRY(heldItem)].type; return gNaturalGiftTable[ITEM_TO_BERRY(heldItem)].type;
else else
return moveType; return moveType;
} case EFFECT_TERRAIN_PULSE:
else if (moveEffect == EFFECT_TERRAIN_PULSE)
{
if (gMain.inBattle) if (gMain.inBattle)
{ {
if (IsBattlerTerrainAffected(battler, STATUS_FIELD_TERRAIN_ANY)) if (IsBattlerTerrainAffected(battler, STATUS_FIELD_TERRAIN_ANY))
@ -5969,14 +5977,15 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
} }
return moveType; return moveType;
} }
} break;
else if (moveEffect == EFFECT_TERA_BLAST && GetActiveGimmick(battler) == GIMMICK_TERA) case EFFECT_TERA_BLAST:
{ if (GetActiveGimmick(battler) == GIMMICK_TERA)
return GetMonData(mon, MON_DATA_TERA_TYPE); return GetMonData(mon, MON_DATA_TERA_TYPE);
} break;
else if (moveEffect == EFFECT_TERA_STARSTORM && species == SPECIES_TERAPAGOS_STELLAR) case EFFECT_TERA_STARSTORM:
{ if (species == SPECIES_TERAPAGOS_STELLAR)
return TYPE_STELLAR; return TYPE_STELLAR;
break;
} }
if (moveType == TYPE_NORMAL if (moveType == TYPE_NORMAL

View file

@ -6931,25 +6931,6 @@ void UpdateDaysPassedSinceFormChange(u16 days)
} }
} }
static inline u32 CalculateHiddenPowerType(struct Pokemon *mon)
{
u32 typehp;
u32 type;
u8 typeBits = ((GetMonData(mon, MON_DATA_HP_IV) & 1) << 0)
| ((GetMonData(mon, MON_DATA_ATK_IV) & 1) << 1)
| ((GetMonData(mon, MON_DATA_DEF_IV) & 1) << 2)
| ((GetMonData(mon, MON_DATA_SPEED_IV) & 1) << 3)
| ((GetMonData(mon, MON_DATA_SPATK_IV) & 1) << 4)
| ((GetMonData(mon, MON_DATA_SPDEF_IV) & 1) << 5);
type = (15 * typeBits) / 63 + 2;
if (type >= TYPE_MYSTERY)
type++;
type |= 0xC0;
typehp = type & 0x3F;
return typehp;
}
u32 CheckDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler) u32 CheckDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler)
{ {
u32 moveType = GetDynamicMoveType(mon, move, battler, NULL); u32 moveType = GetDynamicMoveType(mon, move, battler, NULL);