PKHeX/PKHeX.Core/Legality/Tables/Tables1.cs

37 lines
1.3 KiB
C#
Raw Normal View History

Refactoring: Move Source (Legality) (#3560) Rewrites a good amount of legality APIs pertaining to: * Legal moves that can be learned * Evolution chains & cross-generation paths * Memory validation with forgotten moves In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data. The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space. The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation. * `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game. * `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`). * Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
using static PKHeX.Core.Species;
namespace PKHeX.Core;
public static partial class Legal
{
internal const int MaxSpeciesID_1 = 151;
internal const int MaxMoveID_1 = 165;
internal const int MaxItemID_1 = 255;
internal const int MaxAbilityID_1 = 0;
internal static readonly ushort[] Pouch_Items_RBY =
{
000,001,002,003,004,005,006, 010,011,012,013,014,015,
016,017,018,019,020, 029,030,031,
032,033,034,035,036,037,038,039,040,041,042,043, 045,046,047,
048,049, 051,052,053,054,055,056,057,058, 060,061,062,063,
064,065,066,067,068,069,070,071,072,073,074,075,076,077,078,079,
080,081,082,083,
// ...
196,197,198,199,200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
240,241,242,243,244,245,246,247,248,249,250,
};
internal static bool TransferSpeciesDefaultAbilityGen1(ushort species)
{
System.Diagnostics.Debug.Assert((uint)species <= MaxSpeciesID_1);
return species is (int)Gastly or (int)Haunter or (int)Gengar
or (int)Koffing or (int)Weezing
or (int)Mew;
}
}