Simplify PID gender checking

don't have multiple locations where comparisons are done, just generate
the gender and compare
only fetch gender once from getter
This commit is contained in:
Kurt 2017-05-18 19:16:11 -07:00
parent 46c0f4f30c
commit 84d901f647
2 changed files with 16 additions and 17 deletions

View file

@ -549,7 +549,7 @@ namespace PKHeX.Core
}
}
/// <summary>
/// <summary>do {
/// Checks if the PKM has its original met location.
/// </summary>
/// <returns>Returns false if the Met Location has been overwritten via generational transfer.</returns>
@ -561,23 +561,19 @@ namespace PKHeX.Core
/// <returns>True if valid, False if invalid.</returns>
public virtual bool getGenderIsValid()
{
int gender = Gender;
int gv = PersonalInfo.Gender;
if (gv == 255)
return Gender == 2;
return gender == 2;
if (gv == 254)
return Gender == 1;
return gender == 1;
if (gv == 0)
return Gender == 0;
return gender == 0;
if (GenNumber >= 6)
return true;
if ((PID & 0xFF) < gv)
return Gender == 1;
if (gv <= (PID & 0xFF))
return Gender == 0;
return false;
return gender == PKX.getGender(Species, PID, gv);
}
/// <summary>

View file

@ -470,14 +470,12 @@ namespace PKHeX.Core
else if (bits != (pid & 0x00010001)) // keep ability bits
continue;
// Gen 3/4/5: Gender derived from PID
uint gv = pid & 0xFF;
if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less)
return pid; // PID can be anything
if (cg == 1 && gv <= gt) // Female
return pid; // PID Passes
if (cg == 0 && gv > gt) // Male
return pid; // PID Passes
// Gen 3/4/5: Gender derived from PID
if (cg == getGender(species, pid, gt))
return pid;
}
}
@ -1408,6 +1406,11 @@ namespace PKHeX.Core
/// <returns>Gender ID (0/1/2)</returns>
/// <remarks>This method should only be used for Generations 3-5 origin.</remarks>
public static int getGender(int species, uint PID)
{
int genderratio = Personal[species].Gender;
return getGender(species, PID, genderratio);
}
public static int getGender(int species, uint PID, int gv)
{
int genderratio = Personal[species].Gender;
switch (genderratio)
@ -1415,7 +1418,7 @@ namespace PKHeX.Core
case 255: return 2;
case 254: return 1;
case 0: return 0;
default: return (PID & 0xFF) < genderratio ? 1 : 0;
default: return (PID & 0xFF) <= genderratio ? 1 : 0;
}
}
#region Gen 3 Species Table