Fix gen4 hm indexing

This commit is contained in:
Kurt 2021-01-25 20:58:56 -08:00
parent 94d6ce42bd
commit 511797c1f9
3 changed files with 45 additions and 25 deletions

View File

@ -715,7 +715,7 @@ void IsHMSource(IList<bool> flags, ICollection<int> source)
}
}
private static bool IsDefogWhirl(int move) => move == 250 || move == 432;
private static bool IsDefogWhirl(int move) => move is (int)Move.Defog or (int)Move.Whirlpool;
private static bool IsCheckInvalid(CheckResult? chk) => !(chk?.Valid ?? false);
private static bool IsCheckValid(CheckResult? chk) => chk?.Valid ?? false;

View File

@ -124,29 +124,28 @@ private static GameVersion GetIsMachine4HMTransfer(int species, int move, int fo
private static GameVersion GetIsMachine4HM(int species, int move, int form)
{
var dp = Legal.HM_DPPt;
for (var i = 0; i < dp.Length; i++)
{
int i = 0;
foreach (var m in Legal.HM_DPPt)
{
if (m == move)
{
if (PersonalTable.Pt.GetFormEntry(species, form).TMHM[i + 92])
return GameVersion.DPPt;
break;
}
i++;
}
foreach (var m in Legal.HM_HGSS)
{
if (m == move)
{
if (PersonalTable.HGSS.GetFormEntry(species, form).TMHM[i + 92])
return GameVersion.HGSS;
break;
}
i++;
}
var m = dp[i];
if (m != move)
continue;
if (PersonalTable.Pt.GetFormEntry(species, form).TMHM[i + 92])
return GameVersion.DPPt;
break;
}
var hgss = Legal.HM_HGSS;
for (var i = 0; i < hgss.Length; i++)
{
var m = hgss[i];
if (m != move)
continue;
if (PersonalTable.HGSS.GetFormEntry(species, form).TMHM[i + 92])
return GameVersion.HGSS;
break;
}
return Legal.NONE;
}

View File

@ -148,8 +148,29 @@ public static partial class Legal
// Defog (DPPt) excluded since it's actually useful -- prefer to fake transfer from HGSS instead of DPPt.
};
internal static readonly HashSet<int> HM_DPPt = new(HM_4_RemovePokeTransfer) {(int)Move.Defog};
internal static readonly HashSet<int> HM_HGSS = new(HM_4_RemovePokeTransfer) {(int)Move.Whirlpool};
internal static readonly int[] HM_DPPt =
{
(int)Move.Cut,
(int)Move.Fly,
(int)Move.Surf,
(int)Move.Strength,
(int)Move.Defog,
(int)Move.RockSmash,
(int)Move.Waterfall,
(int)Move.RockClimb,
};
internal static readonly int[] HM_HGSS =
{
(int)Move.Cut,
(int)Move.Fly,
(int)Move.Surf,
(int)Move.Strength,
(int)Move.Whirlpool,
(int)Move.RockSmash,
(int)Move.Waterfall,
(int)Move.RockClimb,
};
internal static readonly byte[] MovePP_DP =
{
@ -272,7 +293,7 @@ internal static int[] RemoveMovesHM45(int[] moves)
/// </summary>
/// <param name="moves">Current moves</param>
/// <returns>Preferred move ban list</returns>
private static HashSet<int> GetFavorableHMBanlist(int[] moves)
private static ICollection<int> GetFavorableHMBanlist(int[] moves)
{
// if has defog, return ban list with whirlpool
return moves.Contains(432) ? HM_HGSS : HM_DPPt;