diff --git a/PKHeX.Core/Legality/Areas/TreeCoordinates.cs b/PKHeX.Core/Legality/Areas/TreeCoordinates.cs new file mode 100644 index 000000000..b79bacc95 --- /dev/null +++ b/PKHeX.Core/Legality/Areas/TreeCoordinates.cs @@ -0,0 +1,19 @@ +namespace PKHeX.Core +{ + /// + /// Coordinate / Index Relationship for a Generation 2 Headbutt Tree + /// + 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; + } + } +} \ No newline at end of file diff --git a/PKHeX.Core/Legality/Areas/TreeEncounterAvailable.cs b/PKHeX.Core/Legality/Areas/TreeEncounterAvailable.cs new file mode 100644 index 000000000..2c6056a31 --- /dev/null +++ b/PKHeX.Core/Legality/Areas/TreeEncounterAvailable.cs @@ -0,0 +1,23 @@ +namespace PKHeX.Core +{ + /// + /// Indicates the Availability of the Generation 2 Headbutt Tree + /// + public enum TreeEncounterAvailable + { + /// + /// Encounter is possible a reachable tree + /// + ValidTree, + + /// + /// Encounter is only possible a tree reachable only with walk-through walls cheats + /// + InvalidTree, + + /// + /// Encounter is not possible in any tree + /// + Impossible + } +} \ No newline at end of file diff --git a/PKHeX.Core/Legality/Areas/TreesArea.cs b/PKHeX.Core/Legality/Areas/TreesArea.cs index 7d172ca1c..defc6a331 100644 --- a/PKHeX.Core/Legality/Areas/TreesArea.cs +++ b/PKHeX.Core/Legality/Areas/TreesArea.cs @@ -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 - /// Indicates the Availability of the Headbutt Tree - public enum TreeEncounterAvailable - { - /// Encounter is possible a reachable tree - ValidTree, - - /// Encounter is only possible a tree reachable only with walk-through walls cheats - InvalidTree, - - /// Encounter is not possible in any tree - Impossible - } - - /// Coordinate / Index Relationship for a Headbutt Tree - 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; - } - } - - /// Trees on a given map + /// + /// Generation 2 Headbutt Trees on a given map + /// 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)