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 System;
|
2020-09-06 17:53:13 +00:00
|
|
|
using System.Collections.Generic;
|
2016-11-12 18:19:17 +00:00
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
using PKHeX.Drawing;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.Misc;
|
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public partial class KChart : Form
|
|
|
|
{
|
|
|
|
private readonly SaveFile SAV;
|
|
|
|
private readonly string[] species = GameInfo.Strings.specieslist;
|
|
|
|
private readonly string[] abilities = GameInfo.Strings.abilitylist;
|
|
|
|
private readonly int[] baseForm;
|
|
|
|
private readonly int[] formVal;
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public KChart(SaveFile sav)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
Icon = Properties.Resources.Icon;
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
SAV = sav;
|
2016-11-12 18:19:17 +00:00
|
|
|
|
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
|
|
|
IPersonalTable pt = SAV.Personal;
|
|
|
|
Array.Resize(ref species, pt.Count);
|
2016-11-12 18:19:17 +00:00
|
|
|
|
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
|
|
|
var forms = pt.GetFormList(species, SAV.MaxSpeciesID);
|
|
|
|
species = pt.GetPersonalEntryList(forms, species, SAV.MaxSpeciesID, out baseForm, out formVal);
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DGV.Rows.Clear();
|
|
|
|
for (int i = 1; i < species.Length; i++)
|
|
|
|
PopEntry(i);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DGV.DoubleBuffered(true);
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DGV.Sort(DGV.Columns[0], ListSortDirection.Ascending);
|
|
|
|
}
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void PopEntry(int index)
|
|
|
|
{
|
|
|
|
var p = SAV.Personal[index];
|
|
|
|
if (p.HP == 0)
|
|
|
|
return;
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int s = index > SAV.MaxSpeciesID ? baseForm[index] : index;
|
|
|
|
var f = index <= SAV.MaxSpeciesID ? 0 : formVal[index];
|
2016-11-12 18:19:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var row = new DataGridViewRow();
|
|
|
|
row.CreateCells(DGV);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
int r = 0;
|
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
|
|
|
var bst = p.GetBaseStatTotal();
|
2022-06-18 18:04:24 +00:00
|
|
|
row.Cells[r++].Value = s.ToString("000") + (f > 0 ? $"-{f:00}" : "");
|
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
|
|
|
row.Cells[r++].Value = SpriteUtil.GetSprite(s, f, 0, 0, 0, false, Shiny.Never, SAV.Generation);
|
2022-06-18 18:04:24 +00:00
|
|
|
row.Cells[r++].Value = species[index];
|
|
|
|
row.Cells[r++].Value = GetIsNative(p, s);
|
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
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStatTotal(bst);
|
|
|
|
row.Cells[r++].Value = bst.ToString("000");
|
2022-06-18 18:04:24 +00:00
|
|
|
row.Cells[r++].Value = p.CatchRate.ToString("000");
|
|
|
|
row.Cells[r++].Value = TypeSpriteUtil.GetTypeSprite(p.Type1, SAV.Generation);
|
|
|
|
row.Cells[r++].Value = p.Type1 == p.Type2 ? SpriteUtil.Spriter.Transparent : TypeSpriteUtil.GetTypeSprite(p.Type2, SAV.Generation);
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.HP);
|
|
|
|
row.Cells[r++].Value = p.HP.ToString("000");
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.ATK);
|
|
|
|
row.Cells[r++].Value = p.ATK.ToString("000");
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.DEF);
|
|
|
|
row.Cells[r++].Value = p.DEF.ToString("000");
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPA);
|
|
|
|
row.Cells[r++].Value = p.SPA.ToString("000");
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPD);
|
|
|
|
row.Cells[r++].Value = p.SPD.ToString("000");
|
|
|
|
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPE);
|
|
|
|
row.Cells[r++].Value = p.SPE.ToString("000");
|
|
|
|
var abils = p.Abilities;
|
|
|
|
row.Cells[r++].Value = GetAbility(abils, 0);
|
|
|
|
row.Cells[r++].Value = GetAbility(abils, 1);
|
|
|
|
row.Cells[r].Value = GetAbility(abils, 2);
|
|
|
|
row.Height = SpriteUtil.Spriter.Height + 1;
|
|
|
|
DGV.Rows.Add(row);
|
|
|
|
}
|
2020-09-06 17:53:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private string GetAbility(IReadOnlyList<int> abilityIDs, int index)
|
|
|
|
{
|
|
|
|
if ((uint)index >= abilityIDs.Count)
|
|
|
|
return abilities[0];
|
|
|
|
return abilities[abilityIDs[index]];
|
2016-11-12 18:19:17 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
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
|
|
|
private static bool GetIsNative(IPersonalInfo personalInfo, int s) => personalInfo switch
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
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
|
|
|
PersonalInfo7 => s > 721 || Legal.PastGenAlolanNatives.Contains(s),
|
|
|
|
PersonalInfo8SWSH ss => ss.IsInDex,
|
|
|
|
PersonalInfo8BDSP bs => bs.IsInDex,
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => true,
|
|
|
|
};
|
2016-11-12 18:19:17 +00:00
|
|
|
}
|