From 4cde037a60a72ff22a8f8a37f34d092a18afd894 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 27 Feb 2022 15:09:30 -0800 Subject: [PATCH] Compress wild slots pickle Order areas for negligibly faster search --- .../Arceus/Util/EncounterTable8aUtil.cs | 23 ++++++++++--------- .../Arceus/Util/SpawnerType.cs | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkNX.Structures.FlatBuffers/Arceus/Util/EncounterTable8aUtil.cs b/pkNX.Structures.FlatBuffers/Arceus/Util/EncounterTable8aUtil.cs index 9865a694..10724cc5 100644 --- a/pkNX.Structures.FlatBuffers/Arceus/Util/EncounterTable8aUtil.cs +++ b/pkNX.Structures.FlatBuffers/Arceus/Util/EncounterTable8aUtil.cs @@ -56,7 +56,7 @@ public static class EncounterTable8aUtil var s = area.Spawners; var spawners = s.Where(z => nhoLottery.IsAreaGroup(z, nhoGroup, table.TableID)); var sl = spawners.SelectMany(z => z.GetIntersectingLocations(area.Locations, SpawnerBias)); - foreach (var a in GetAll(sl, SpawnerType.Spawner)) + foreach (var a in GetAll(sl, SpawnerType.SpawnerNHO)) yield return a; } @@ -97,14 +97,11 @@ IEnumerable GetAll(IEnumerable places, SpawnerType yield break; if (areas.Remove(baseArea) && areas.Count == 0) areas.Add(baseArea); + else if (!areas.All(IsDungeonZone) && !areas.Contains(baseArea)) + areas.Add(baseArea); - foreach (var a in areas) - { - var parent = baseArea; - if (IsDungeonZone(a)) - parent = a; // disallow crossover-out for dungeons - yield return GetArea(a, parent, slots, table.MinLevel, table.MaxLevel, type, misc, bmin, bmax); - } + areas.Sort(); + yield return GetArea(areas, slots, table.MinLevel, table.MaxLevel, type, misc, bmin, bmax); } } @@ -115,7 +112,7 @@ IEnumerable GetAll(IEnumerable places, SpawnerType private static readonly int[] OybnSettings = { 15, 15, 15, 20, 20 }; - private static byte[] GetArea(int location, int parentArea, IReadOnlyCollection slots, + private static byte[] GetArea(IReadOnlyList locations, IReadOnlyCollection slots, int tableMinLevel, int tableMaxLevel, SpawnerType type, PokeMiscTable8a misc, int bonusMin = 0, @@ -123,8 +120,12 @@ IEnumerable GetAll(IEnumerable places, SpawnerType { using var ms = new MemoryStream(); using var bw = new BinaryWriter(ms); - bw.Write((byte)location); - bw.Write((byte)parentArea); + bw.Write((byte)locations.Count); + foreach (var loc in locations) + bw.Write((byte)loc); + if (bw.BaseStream.Position % 2 != 0) + bw.Write((byte)0); + bw.Write((byte)type); bw.Write((byte)slots.Count); foreach (var s in slots) diff --git a/pkNX.Structures.FlatBuffers/Arceus/Util/SpawnerType.cs b/pkNX.Structures.FlatBuffers/Arceus/Util/SpawnerType.cs index 5f3290d1..ae34daac 100644 --- a/pkNX.Structures.FlatBuffers/Arceus/Util/SpawnerType.cs +++ b/pkNX.Structures.FlatBuffers/Arceus/Util/SpawnerType.cs @@ -5,5 +5,6 @@ public enum SpawnerType Spawner, Wormhole, Landmark, + SpawnerNHO, Unown, }