Switch item banlist to allowed list

Precompute bool[] to quickly access the allowed status instead of
looping for contains.
This commit is contained in:
Kurt
2017-02-26 11:43:26 -08:00
parent 062e571b3f
commit f68a3b4b7d
8 changed files with 52 additions and 12 deletions

View File

@@ -72,8 +72,7 @@ private void verifyGender()
private void verifyItem()
{
var unreleasedItems = Legal.getUnreleasedItems(pkm.Format);
if (unreleasedItems.Contains(pkm.HeldItem))
if (!Legal.getHeldItemAllowed(pkm.Format, pkm.HeldItem))
AddLine(Severity.Invalid, "Held item is unreleased.", CheckIdentifier.Form);
}

View File

@@ -656,6 +656,30 @@ internal static IEnumerable<int> getFutureGenEvolutions(int generation)
}
}
internal static bool[] getReleasedHeldItems(int generation)
{
switch (generation)
{
case 2: return ReleasedHeldItems_2;
case 3: return ReleasedHeldItems_3;
case 4: return ReleasedHeldItems_4;
case 5: return ReleasedHeldItems_5;
case 6: return ReleasedHeldItems_6;
case 7: return ReleasedHeldItems_7;
default: return new bool[0];
}
}
internal static bool getHeldItemAllowed(int generation, int item)
{
if (item < 0)
return false;
if (item == 0)
return true;
var items = getReleasedHeldItems(generation);
return items.Length > item && items[item];
}
internal static bool getDexNavValid(PKM pkm)
{
if (!pkm.AO || !pkm.InhabitedGeneration(6))
@@ -1493,14 +1517,5 @@ private static IEnumerable<int> getTutorMoves(PKM pkm, int species, int form, bo
// No tutors in G7
return moves.Distinct();
}
public static int[] getUnreleasedItems(int generation)
{
switch (generation)
{
case 7: return UnreleasedItems_7;
default: return new int[0];
}
}
}
}

View File

@@ -59,5 +59,10 @@ public static partial class Legal
{
// todo
};
internal static readonly int[] UnreleasedItems_2 =
{
// todo
};
internal static readonly bool[] ReleasedHeldItems_2 = Enumerable.Range(1, MaxItemID_2).Select(i => HeldItems_GSC.Contains((ushort)i) && !UnreleasedItems_2.Contains(i)).ToArray();
}
}

View File

@@ -94,5 +94,10 @@ public static partial class Legal
};
// Ambipom Weavile Magnezone Lickilicky Tangrowth
// Yanmega Leafeon Glaceon Mamoswine Gliscor Probopass
internal static readonly int[] UnreleasedItems_3 =
{
// todo
};
internal static readonly bool[] ReleasedHeldItems_3 = Enumerable.Range(1, MaxItemID_3).Select(i => HeldItems_RS.Contains((ushort)i) && !UnreleasedItems_3.Contains(i)).ToArray();
}
}

View File

@@ -135,5 +135,10 @@ public static partial class Legal
{
700
};
internal static readonly int[] UnreleasedItems_4 =
{
// todo
};
internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(1, MaxItemID_4_HGSS).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray();
}
}

View File

@@ -94,5 +94,10 @@ public static partial class Legal
{
700
};
internal static readonly int[] UnreleasedItems_5 =
{
// todo
};
internal static readonly bool[] ReleasedHeldItems_5 = Enumerable.Range(1, MaxItemID_5_B2W2).Select(i => HeldItems_BW.Contains((ushort)i) && !UnreleasedItems_5.Contains(i)).ToArray();
}
}

View File

@@ -762,5 +762,10 @@ public static partial class Legal
05, 10, 05, 05, 15, 10, 05, 05, 05, 10, 10, 10, 10, 20, 25, 10, 20, 30, 25, 20, 20, 15, 20, 15, 20, 20, 10, 10, 10, 10, 10, 20, 10, 30, 15, 10, 10, 10, 20, 20, 05, 05, 05, 20, 10, 10, 20, 15, 20, 20,
10, 20, 30, 10, 10, 40, 40, 30, 20, 40, 20, 20, 10, 10, 10, 10, 05, 10, 10, 05, 05,
};
internal static readonly int[] UnreleasedItems_6 =
{
// todo
};
internal static readonly bool[] ReleasedHeldItems_6 = Enumerable.Range(0, MaxItemID_6_AO).Select(i => HeldItem_AO.Contains((ushort)i) && !UnreleasedItems_6.Contains(i)).ToArray();
}
}

View File

@@ -1252,7 +1252,7 @@ public static partial class Legal
#endregion
#region Unreleased Items
internal static readonly int[] UnreleasedItems_7 =
internal static readonly int[] UnreleasedHeldItems_7 =
{
016, // Cherish Ball
064, // Fluffy Tail
@@ -1342,5 +1342,6 @@ public static partial class Legal
836, // Pikashunium Z
};
#endregion
internal static readonly bool[] ReleasedHeldItems_7 = Enumerable.Range(1, MaxItemID_7).Select(i => HeldItems_SM.Contains((ushort)i) && !UnreleasedHeldItems_7.Contains(i)).ToArray();
}
}