mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-09 04:24:36 -05:00
Split apart headbutt tree logic
precompute Index & make readonly when initializing as we use Index at least once when initializing the treesarea
This commit is contained in:
parent
b5089658f7
commit
f89d9ca323
19
PKHeX.Core/Legality/Areas/TreeCoordinates.cs
Normal file
19
PKHeX.Core/Legality/Areas/TreeCoordinates.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Coordinate / Index Relationship for a Generation 2 Headbutt Tree
|
||||
/// </summary>
|
||||
internal sealed class TreeCoordinates
|
||||
{
|
||||
public readonly int X;
|
||||
public readonly int Y;
|
||||
public readonly int Index;
|
||||
|
||||
public TreeCoordinates(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Index = ((X * Y) + X + Y) / 5 % 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
PKHeX.Core/Legality/Areas/TreeEncounterAvailable.cs
Normal file
23
PKHeX.Core/Legality/Areas/TreeEncounterAvailable.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates the Availability of the Generation 2 Headbutt Tree
|
||||
/// </summary>
|
||||
public enum TreeEncounterAvailable
|
||||
{
|
||||
/// <summary>
|
||||
/// Encounter is possible a reachable tree
|
||||
/// </summary>
|
||||
ValidTree,
|
||||
|
||||
/// <summary>
|
||||
/// Encounter is only possible a tree reachable only with walk-through walls cheats
|
||||
/// </summary>
|
||||
InvalidTree,
|
||||
|
||||
/// <summary>
|
||||
/// Encounter is not possible in any tree
|
||||
/// </summary>
|
||||
Impossible
|
||||
}
|
||||
}
|
||||
|
|
@ -5,34 +5,9 @@ namespace PKHeX.Core
|
|||
// Pokemon Crystal Headbutt tree encounters by trainer id, based on mechanics described in
|
||||
// https://bulbapedia.bulbagarden.net/wiki/Headbutt_tree#Mechanics
|
||||
|
||||
/// <summary> Indicates the Availability of the Headbutt Tree </summary>
|
||||
public enum TreeEncounterAvailable
|
||||
{
|
||||
/// <summary> Encounter is possible a reachable tree </summary>
|
||||
ValidTree,
|
||||
|
||||
/// <summary> Encounter is only possible a tree reachable only with walk-through walls cheats </summary>
|
||||
InvalidTree,
|
||||
|
||||
/// <summary> Encounter is not possible in any tree </summary>
|
||||
Impossible
|
||||
}
|
||||
|
||||
/// <summary> Coordinate / Index Relationship for a Headbutt Tree </summary>
|
||||
internal sealed class TreeCoordinates
|
||||
{
|
||||
internal int X { get; }
|
||||
internal int Y { get; }
|
||||
internal int Index => ((X*Y) + X+Y) / 5 % 10;
|
||||
|
||||
public TreeCoordinates(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Trees on a given map </summary>
|
||||
/// <summary>
|
||||
/// Generation 2 Headbutt Trees on a given map
|
||||
/// </summary>
|
||||
public sealed class TreesArea
|
||||
{
|
||||
private const int PivotCount = 10;
|
||||
|
|
@ -40,13 +15,13 @@ public sealed class TreesArea
|
|||
|
||||
private static int[][] GenerateTrainersTreeIndex()
|
||||
{
|
||||
// A tree have a low encounter or moderate encounter base on the TID Pivot Index (TID % 10)
|
||||
// Calculate for every Trainer Pivot Index the 5 tree index for low encounters
|
||||
// A tree has a low encounter or moderate encounter base on the TID Pivot Index (TID % 10)
|
||||
// For every Trainer Pivot Index, calculate the low encounter trees (total of 5)
|
||||
int[][] TrainersIndex = new int[PivotCount][];
|
||||
for (int i = 0; i < PivotCount; i++)
|
||||
{
|
||||
int[] ModerateEncounterTreeIndex = new int[5];
|
||||
for (int j = 0; j <= 4; j++)
|
||||
for (int j = 0; j < ModerateEncounterTreeIndex.Length; j++)
|
||||
ModerateEncounterTreeIndex[j] = (i + j) % PivotCount;
|
||||
TrainersIndex[i] = ModerateEncounterTreeIndex.OrderBy(x => x).ToArray();
|
||||
}
|
||||
|
|
@ -76,7 +51,7 @@ private TreesArea(byte[] entry)
|
|||
|
||||
private void ReadAreaRawData(byte[] entry)
|
||||
{
|
||||
// Coordinates of trees for every are obtained with the program G2Map
|
||||
// Coordinates of trees were obtained with the program G2Map
|
||||
// ValidTrees are those accessible by the player
|
||||
Location = entry[0];
|
||||
ValidTrees = new TreeCoordinates[entry[1]];
|
||||
|
|
@ -131,9 +106,9 @@ private TreeEncounterAvailable GetAvailableLow(int[] moderate)
|
|||
}
|
||||
|
||||
#if DEBUG
|
||||
private void DumpLocation()
|
||||
public void DumpLocation(string[] locationNames)
|
||||
{
|
||||
string loc = GameInfo.GetStrings("en").metGSC_00000[Location];
|
||||
string loc = locationNames[Location];
|
||||
System.Console.WriteLine($"Location: {loc}");
|
||||
System.Console.WriteLine("Valid:");
|
||||
foreach (var tree in ValidTrees)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user