Expose criteria optimization for trade/headbutt

If the criteria template is optimized, we will be able to source moves from sibling game pairs that require indications of it being traded (yay strict logic...)

ex: encgenerator now yields X/Y eggs when ORAS tutors requested in moveset and game is X/Y
This commit is contained in:
Kurt 2023-01-31 23:23:12 -08:00
parent c5ec20ef5d
commit 9ecb8981a9
2 changed files with 18 additions and 4 deletions

View file

@ -38,7 +38,7 @@ public static class EncounterMovesetGenerator
if (!IsSane(pk, moves))
yield break;
pk.TID16 = info.TID16; // Necessary for Gen2 Headbutt encounters.
OptimizeCriteria(pk, info);
var vers = versions.Length >= 1 ? versions : GameUtil.GetVersionsWithinRange(pk, pk.Format);
foreach (var ver in vers)
{
@ -70,7 +70,7 @@ public static class EncounterMovesetGenerator
if (!IsSane(pk, moves))
yield break;
pk.TID16 = info.TID16; // Necessary for Gen2 Headbutt encounters.
OptimizeCriteria(pk, info);
var vers = versions.Length >= 1 ? versions : GameUtil.GetVersionsWithinRange(pk, pk.Format);
foreach (var ver in vers)
{
@ -80,6 +80,19 @@ public static class EncounterMovesetGenerator
}
}
/// <summary>
/// Adapts the input <see cref="pk"/> so that it may match as many encounters as possible (indications of trades to other game pairs, etc).
/// </summary>
/// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
/// <param name="info">Trainer information of the receiver.</param>
public static void OptimizeCriteria(PKM pk, ITrainerID16 info)
{
pk.TID16 = info.TID16; // Necessary for Gen2 Headbutt encounters.
var htTrash = pk.HT_Trash;
if (htTrash.Length != 0)
htTrash[0] = 1; // Fake Trash to indicate trading.
}
/// <summary>
/// Gets possible <see cref="PKM"/> objects that allow all moves requested to be learned within a specific generation.
/// </summary>

View file

@ -283,7 +283,7 @@ public partial class SAV_Encounters : Form
yield return i;
}
private static IEnumerable<IEncounterInfo> GetAllSpeciesFormEncounters(IEnumerable<ushort> species, IPersonalTable pt, IReadOnlyList<GameVersion> versions, ushort[] moves, PKM pk, CancellationToken token)
private IEnumerable<IEncounterInfo> GetAllSpeciesFormEncounters(IEnumerable<ushort> species, IPersonalTable pt, IReadOnlyList<GameVersion> versions, ushort[] moves, PKM pk, CancellationToken token)
{
foreach (var s in species)
{
@ -327,11 +327,12 @@ public partial class SAV_Encounters : Form
}
}
private static IEnumerable<IEncounterInfo> GetEncounters(ushort species, byte form, ushort[] moves, PKM pk, IReadOnlyList<GameVersion> vers)
private IEnumerable<IEncounterInfo> GetEncounters(ushort species, byte form, ushort[] moves, PKM pk, IReadOnlyList<GameVersion> vers)
{
pk.Species = species;
pk.Form = form;
pk.SetGender(pk.GetSaneGender());
EncounterMovesetGenerator.OptimizeCriteria(pk, SAV);
return EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers);
}