Skip to content

Commit

Permalink
Synthesize dotmaps for other milieu
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Sep 15, 2016
1 parent 87c1810 commit e3e5876
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/SecondSurvey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
42 changes: 41 additions & 1 deletion server/Sector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions server/SectorMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ private class MilieuMap
public Dictionary<string, Sector> nameMap = new Dictionary<string, Sector>(StringComparer.InvariantCultureIgnoreCase);
public Dictionary<Point, Sector> locationMap = new Dictionary<Point, Sector>();

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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
}

Expand Down

0 comments on commit e3e5876

Please sign in to comment.