Fix SM dex form fetch for spewpa

Closes #2826

It doesn't find it in the SM table, but didn't return -1
rework logic flow to return when found, rather than after loop finishes.

Also fix display off-by-1 since we're not using zero indexing for our entry numbers.

Thanks @Ammako !
This commit is contained in:
Kurt
2020-05-24 20:42:45 -07:00
parent 7c6ea78c63
commit 46b443903d
3 changed files with 10 additions and 11 deletions

View File

@@ -197,12 +197,13 @@ public int GetDexFormIndex(int spec, int fc, int f)
public IList<string> GetEntryNames(IReadOnlyList<string> Species)
{
var names = new List<string>();
for (int i = 1; i <= SAV.MaxSpeciesID; i++)
var max = SAV.MaxSpeciesID;
for (int i = 1; i <= max; i++)
names.Add($"{i:000} - {Species[i]}");
// Add Formes
int ctr = SAV.MaxSpeciesID;
for (int spec = 1; spec <= SAV.MaxSpeciesID; spec++)
int ctr = max + 1;
for (int spec = 1; spec <= max; spec++)
{
int c = SAV.Personal[spec].FormeCount;
for (int f = 1; f < c; f++)

View File

@@ -97,19 +97,16 @@ public static class DexFormUtil
private static int GetDexFormBitIndex(int species, int formct, int start, IReadOnlyList<ushort> formtable)
{
int formindex = start;
int f = 0;
for (int i = 0; i < formtable.Count; i += 2)
{
int s = formtable[i];
f = formtable[i + 1];
int f = formtable[i + 1];
if (s == species)
break;
return f > formct ? -1 : formindex;
formindex += f - 1;
}
if (f > formct)
return -1;
return formindex;
return -1;
}
private static int GetDexFormCount(int species, IReadOnlyList<ushort> formtable)

View File

@@ -152,8 +152,9 @@ private bool FillLBForms()
if (f < 0)
return true; // bit index valid
if (f > fspecies - LB_Forms.Items.Count - 1)
LB_Forms.SelectedIndex = fspecies - f - 1;
var findex = fspecies - f - 1;
if (findex < LB_Forms.Items.Count)
LB_Forms.SelectedIndex = findex;
else
LB_Forms.SelectedIndex = -1;
}