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

Fixes Hidden Power dynamic type bug #5463

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
155 changes: 82 additions & 73 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5829,8 +5829,9 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
type3 = TYPE_MYSTERY;
}

if (moveEffect == EFFECT_WEATHER_BALL)
switch (moveEffect)
{
case EFFECT_WEATHER_BALL:
if (gMain.inBattle && WEATHER_HAS_EFFECT)
{
if (gBattleWeather & B_WEATHER_RAIN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA)
Expand Down Expand Up @@ -5864,79 +5865,86 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
}
return moveType;
}
}
else if (moveEffect == EFFECT_HIDDEN_POWER)
{
u8 typeBits;
if (gMain.inBattle)
break;
case EFFECT_HIDDEN_POWER:
{
typeBits = ((gBattleMons[battler].hpIV & 1) << 0)
| ((gBattleMons[battler].attackIV & 1) << 1)
| ((gBattleMons[battler].defenseIV & 1) << 2)
| ((gBattleMons[battler].speedIV & 1) << 3)
| ((gBattleMons[battler].spAttackIV & 1) << 4)
| ((gBattleMons[battler].spDefenseIV & 1) << 5);
u32 typeBits = 0;
if (gMain.inBattle)
{
typeBits = ((gBattleMons[battler].hpIV & 1) << 0)
| ((gBattleMons[battler].attackIV & 1) << 1)
| ((gBattleMons[battler].defenseIV & 1) << 2)
| ((gBattleMons[battler].speedIV & 1) << 3)
| ((gBattleMons[battler].spAttackIV & 1) << 4)
| ((gBattleMons[battler].spDefenseIV & 1) << 5);
}
else
{
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);
}

// 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.
moveType = ((NUMBER_OF_MON_TYPES - 6) * typeBits) / 63 + 2;
if (moveType >= TYPE_MYSTERY)
moveType++;
return ((moveType | F_DYNAMIC_TYPE_IGNORE_PHYSICALITY) & 0x3F);
}
else
break;
case EFFECT_CHANGE_TYPE_ON_ITEM:
if (holdEffect == gMovesInfo[move].argument)
return ItemId_GetSecondaryId(heldItem);
break;
case EFFECT_REVELATION_DANCE:
if (GetActiveGimmick(battler) != GIMMICK_Z_MOVE)
{
u32 teraType;
if (GetActiveGimmick(battler) == GIMMICK_TERA && ((teraType = GetMonData(mon, MON_DATA_TERA_TYPE)) != TYPE_STELLAR))
return teraType;
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)
{
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);
case SPECIES_TAUROS_PALDEA_COMBAT:
case SPECIES_TAUROS_PALDEA_BLAZE:
case SPECIES_TAUROS_PALDEA_AQUA:
return type2;
}

// 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.
moveType = ((NUMBER_OF_MON_TYPES - 6) * typeBits) / 63 + 2;
if (moveType >= TYPE_MYSTERY)
moveType++;
return (moveType | F_DYNAMIC_TYPE_IGNORE_PHYSICALITY);
}
else if (moveEffect == EFFECT_CHANGE_TYPE_ON_ITEM && holdEffect == gMovesInfo[move].argument)
{
return ItemId_GetSecondaryId(heldItem);
}
else if (moveEffect == EFFECT_REVELATION_DANCE && GetActiveGimmick(battler) != GIMMICK_Z_MOVE)
{
u8 teraType;
if (GetActiveGimmick(battler) == GIMMICK_TERA && ((teraType = GetMonData(mon, MON_DATA_TERA_TYPE)) != TYPE_STELLAR))
return teraType;
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))
break;
case EFFECT_IVY_CUDGEL:
switch (species)
{
case SPECIES_OGERPON_WELLSPRING:
case SPECIES_OGERPON_HEARTHFLAME:
case SPECIES_OGERPON_CORNERSTONE:
case SPECIES_OGERPON_WELLSPRING_TERA:
case SPECIES_OGERPON_HEARTHFLAME_TERA:
case SPECIES_OGERPON_CORNERSTONE_TERA:
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;
}
else if (moveEffect == EFFECT_RAGING_BULL
&& (species == SPECIES_TAUROS_PALDEA_COMBAT
|| species == SPECIES_TAUROS_PALDEA_BLAZE
|| species == SPECIES_TAUROS_PALDEA_AQUA))
{
return type2;
}
else if (moveEffect == EFFECT_IVY_CUDGEL
&& (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)
{
}
break;
case EFFECT_NATURAL_GIFT:
if (ItemId_GetPocket(heldItem) == POCKET_BERRIES)
return gNaturalGiftTable[ITEM_TO_BERRY(heldItem)].type;
else
return moveType;
}
else if (moveEffect == EFFECT_TERRAIN_PULSE)
{
case EFFECT_TERRAIN_PULSE:
if (gMain.inBattle)
{
if (IsBattlerTerrainAffected(battler, STATUS_FIELD_TERRAIN_ANY))
Expand Down Expand Up @@ -5969,14 +5977,15 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
}
return moveType;
}
}
else if (moveEffect == EFFECT_TERA_BLAST && GetActiveGimmick(battler) == GIMMICK_TERA)
{
return GetMonData(mon, MON_DATA_TERA_TYPE);
}
else if (moveEffect == EFFECT_TERA_STARSTORM && species == SPECIES_TERAPAGOS_STELLAR)
{
return TYPE_STELLAR;
break;
case EFFECT_TERA_BLAST:
if (GetActiveGimmick(battler) == GIMMICK_TERA)
return GetMonData(mon, MON_DATA_TERA_TYPE);
break;
case EFFECT_TERA_STARSTORM:
if (species == SPECIES_TERAPAGOS_STELLAR)
return TYPE_STELLAR;
break;
}

if (moveType == TYPE_NORMAL
Expand Down
19 changes: 0 additions & 19 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 moveType = GetDynamicMoveType(mon, move, battler, NULL);
Expand Down
Loading