Add sanity check for enc gender request

If you set criteria to Male, and request to generate a Nidoran-F wild encounter, ofc the program will loop forever.
Oftentimes, users won't be looking at the criteria tab, and can stumble upon this accidentally.
Prevent the freeze entirely by just sanity checking and discarding the user's input if it is impossible.
This commit is contained in:
Kurt 2026-03-01 12:57:47 -06:00
parent f382291de4
commit b6eb0745a3
2 changed files with 10 additions and 1 deletions

View File

@ -85,6 +85,15 @@ public static byte GetGenderRatio(ushort species)
return NG;
}
/// <summary>
/// Checks if the species (base form) is a single gender.
/// </summary>
public static bool IsSingleGender(ushort species)
{
var ratio = GetGenderRatio(species);
return ratio is OM or OF or NG;
}
private static ReadOnlySpan<byte> GenderRatios =>
[
NG, VM, VM, VM, VM, VM, VM, VM, VM, VM, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, HH, OF, OF, OF, OM, OM, OM, MF, MF, MF, MF, MF,

View File

@ -256,7 +256,7 @@ private EncounterCriteria GetCriteria(IEncounterTemplate enc, EncounterDatabaseS
}
var criteria = _criteriaValue;
if (!isInChain)
if (!isInChain || EntityGender.IsSingleGender(enc.Species))
criteria = criteria with { Gender = Gender.Random }; // Genderless tabs and a gendered enc -> let's play safe.
return criteria;
}