From e3e5876c75b4f8f6a4c30054798a0ecbb1aba542 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Wed, 14 Sep 2016 21:05:01 -0700 Subject: [PATCH] Synthesize dotmaps for other milieu --- server/SecondSurvey.cs | 1 + server/Sector.cs | 42 +++++++++++++++++++++++++++++++++++++++++- server/SectorMap.cs | 29 ++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/server/SecondSurvey.cs b/server/SecondSurvey.cs index dd231c741..515a74318 100644 --- a/server/SecondSurvey.cs +++ b/server/SecondSurvey.cs @@ -429,6 +429,7 @@ public static string T5AllegianceCodeToLegacyCode(string t5code) "ImSy", // Third Imperium, Sylean Worlds (Core) "ImVd", // Third Imperium, Vegan Autonomous District (Solo) "XXXX", // Unknown + "??", // Placeholder - show as blank "--", // Placeholder - show as blank }; diff --git a/server/Sector.cs b/server/Sector.cs index 67a53d9ac..22bc2b103 100644 --- a/server/Sector.cs +++ b/server/Sector.cs @@ -230,7 +230,7 @@ public static int QuadrantIndexFor(string label) return -1; } - internal WorldCollection GetWorlds(ResourceManager resourceManager, bool cacheResults = true) + internal virtual WorldCollection GetWorlds(ResourceManager resourceManager, bool cacheResults = true) { lock (this) { @@ -468,6 +468,46 @@ public string StylesheetText } } private string stylesheetText; + + } + + internal class Dotmap : Sector + { + private Sector basis; + private WorldCollection worlds = null; + + public Dotmap(Sector basis) { + this.X = basis.X; + this.Y = basis.Y; + this.basis = basis; + } + + internal override WorldCollection GetWorlds(ResourceManager resourceManager, bool cacheResults = true) + { + if (this.worlds != null) + return this.worlds; + + WorldCollection worlds = basis.GetWorlds(resourceManager, cacheResults); + if (worlds == null) + return null; + + WorldCollection dots = new WorldCollection(); + foreach (var world in worlds) + { + var dot = new World(); + dot.Hex = world.Hex; + dot.UWP = "???????-?"; + dot.PBG = "???"; + dot.Allegiance = "??"; + dot.Sector = this; + dots[dot.X, dot.Y] = dot; + } + + if (cacheResults) + this.worlds = dots; + + return dots; + } } public class Product : MetadataItem diff --git a/server/SectorMap.cs b/server/SectorMap.cs index f51f72c42..a36e448cf 100644 --- a/server/SectorMap.cs +++ b/server/SectorMap.cs @@ -52,6 +52,20 @@ private class MilieuMap public Dictionary nameMap = new Dictionary(StringComparer.InvariantCultureIgnoreCase); public Dictionary locationMap = new Dictionary(); + public Sector FromName(string name) + { + Sector sector; + nameMap.TryGetValue(name, out sector); + return sector; + } + + public Sector FromLocation(Point coords) + { + Sector sector; + locationMap.TryGetValue(coords, out sector); + return sector; + } + public void Add(Sector sector) { locationMap.Add(sector.Location, sector); @@ -231,7 +245,7 @@ private Sector FromName(string name, string milieu) if (sectors == null) throw new MapNotInitializedException(); return SelectMilieux(milieu) - .Select(m => m.nameMap.ContainsKey(name) ? m.nameMap[name] : null) + .Select(m => m.FromName(name)) .Where(s => s != null) .FirstOrDefault(); } @@ -248,10 +262,19 @@ private Sector FromLocation(Point pt, string milieu) { if (sectors == null) throw new MapNotInitializedException(); - return SelectMilieux(milieu) - .Select(m => m.locationMap.ContainsKey(pt) ? m.locationMap[pt] : null) + Sector sector = SelectMilieux(milieu) + .Select(m => m.FromLocation(pt)) .Where(s => s != null) .FirstOrDefault(); + if (sector != null) + return sector; + sector = milieux[DEFAULT_MILIEU].FromLocation(pt); + if (sector == null) + return null; + sector = new Dotmap(sector); + if (milieux.ContainsKey(milieu)) + milieux[milieu].Add(sector); + return sector; } }