protected override void InterpretRow(Dictionary<string, string> fields) { int itemId = ParseId(fields["solarSystemID"]); string itemName = fields["solarSystemName"]; float security = ParseNumber(fields["security"]); int regionId = ParseId(fields["regionID"]); //Console.WriteLine("Line: "+ itemId.ToString() + " " + itemName.ToString() +" " + regionId.ToString()); Region r = null; if (regions.ContainsKey(regionId)) { r = regions[regionId]; } if (r == null) { r = new Region(regionId); regions.Add(regionId, r); } SolarSystem s = new SolarSystem(itemId, itemName, r, security); r.Systems.Add(s); solarSystems[itemId] = s; solarSystemsByName[itemName] = s; }
public Station(int id, int typeId, string name, SolarSystem system) { this.id = id; this.typeId = typeId; this.name = name; this.system = system; if (system != null) { system.Stations.Add(this); } }
public SecurityStatus.Level RouteSecurity(SolarSystem source, SolarSystem destination) { SecurityStatus.Level securityFromStartingSystem = SecurityStatus.Level.Isolated; int jumpsFromStartSecure = DistanceBetween(source, destination, true); int jumpsFromStartShortest = DistanceBetween(source, destination, false); if (jumpsFromStartSecure == jumpsFromStartShortest) { securityFromStartingSystem = SecurityStatus.Level.HighSec; } else if ((jumpsFromStartSecure > jumpsFromStartShortest) && (jumpsFromStartSecure != int.MaxValue)) { securityFromStartingSystem = SecurityStatus.Level.LowSecShortcut; } else if ((jumpsFromStartSecure == int.MaxValue) && (jumpsFromStartShortest != int.MaxValue)) { securityFromStartingSystem = SecurityStatus.Level.LowSecOnly; } return(securityFromStartingSystem); }
public void SortByProfitPerWarpFromStartingSystem(bool secure) { SolarSystem system = map.GetSystem(parameters.StartingSystem); if (system == null) throw new CannotFindStartingSystem(); if ((startingSystem == null) || (startingSystem != system)) { foreach (SingleTrip s in singleTrips) { s.StartingSystem = system; } startingSystem = system; } if (secure) { singleTrips.Sort(SingleTrip.CompareByProfitPerWarpFromStartingSystemSecure); } else { singleTrips.Sort(SingleTrip.CompareByProfitPerWarpFromStartingSystemShortest); } }
public float ProfitPerWarpFrom(SolarSystem startingSystem, bool secure) { // distance from a system is #jumps * 2 to warp there, and +1 to get to the right station int warps = Warps(secure) + map.DistanceBetween(startingSystem, source.System, secure) * 2 + 1; return Profit / warps; }
private SolarSystem GetNeighbourWithShortestDistanceTo(SolarSystem destination, bool secure) { SolarSystem nearest = null; int shortestFound = int.MaxValue; foreach (SolarSystem s in gates) { if ((secure) && (s.SignpostSecure.ContainsKey(destination))) { if (s.SignpostSecure[destination].Distance < shortestFound) { nearest = s; shortestFound = s.SignpostSecure[destination].Distance; } } else if ((!secure) && (s.SignpostShortest.ContainsKey(destination))) { if (s.SignpostShortest[destination].Distance < shortestFound) { nearest = s; shortestFound = s.SignpostShortest[destination].Distance; } } } return nearest; }
public bool UpdateSignpostTo(SolarSystem destination) // returns true if the destination has already been found { bool updated = false; SolarSystem sSecure = GetNeighbourWithShortestDistanceTo(destination, true); SolarSystem sShort = GetNeighbourWithShortestDistanceTo(destination, false); if ((sSecure != null) && (SecurityStatus.IsSecure(this.Security))) { if (signpostSecure.ContainsKey(destination)) { if (signpostSecure[destination].Distance > (sSecure.SignpostSecure[destination].Distance + 1)) { signpostSecure[destination] = new SignpostEntry(sSecure, sSecure.SignpostSecure[destination].Distance + 1); updated = true; } } else { signpostSecure[destination] = new SignpostEntry(sSecure, sSecure.SignpostSecure[destination].Distance + 1); updated = true; } } if (sShort != null) { if (signpostShortest.ContainsKey(destination)) { if (signpostShortest[destination].Distance > (sShort.SignpostShortest[destination].Distance + 1)) { signpostShortest[destination] = new SignpostEntry(sShort, sShort.SignpostShortest[destination].Distance + 1); updated = true; } } else { signpostShortest[destination] = new SignpostEntry(sShort, sShort.SignpostShortest[destination].Distance + 1); updated = true; } } return updated; }
public void AddGateTo(SolarSystem destination) { gates.Add(destination); if (SecurityStatus.IsSecure(Math.Min(this.Security, destination.Security))) { signpostSecure[destination] = new SignpostEntry(destination, 1); } signpostShortest[destination] = new SignpostEntry(destination, 1); }
public string Info(Station station, SolarSystem from, string postfix) { string result = Info(station); if (finder != null && station != null && from != null) { int jumpsSecure = finder.map.DistanceBetween(from, station.System, true); int jumpsShortest = finder.map.DistanceBetween(from, station.System, false); SecurityStatus.Level security = finder.map.RouteSecurity(from, station.System); if (security == SecurityStatus.Level.LowSecShortcut) { result += " <FONT COLOR=\"#00ff33\">(" + jumpsSecure + " " + Pluralize("jump", "jumps", jumpsSecure) + ")</FONT>"; result += "/<FONT COLOR=\"#ff0033\">(" + jumpsShortest + " " + Pluralize("jump", "jumps", jumpsShortest) + ")</FONT>" + postfix; } else if (security == SecurityStatus.Level.HighSec) { result += " <FONT COLOR=\"#00ff33\">(" + jumpsSecure + " " + Pluralize("jump", "jumps", jumpsSecure) + ")</FONT>" + postfix; ; } else { result += " <FONT COLOR=\"#ff0033\">(" + jumpsShortest + " " + Pluralize("jump", "jumps", jumpsShortest) + ")</FONT>" + postfix; } } return result; }
public string Info(Station station, SolarSystem from) { return Info(station, from, string.Empty); }
public SecurityStatus.Level RouteSecurity(SolarSystem source, SolarSystem destination) { SecurityStatus.Level securityFromStartingSystem = SecurityStatus.Level.Isolated; int jumpsFromStartSecure = DistanceBetween(source, destination, true); int jumpsFromStartShortest = DistanceBetween(source, destination, false); if (jumpsFromStartSecure == jumpsFromStartShortest) { securityFromStartingSystem = SecurityStatus.Level.HighSec; } else if ((jumpsFromStartSecure > jumpsFromStartShortest) && (jumpsFromStartSecure != int.MaxValue)) { securityFromStartingSystem = SecurityStatus.Level.LowSecShortcut; } else if ((jumpsFromStartSecure == int.MaxValue) && (jumpsFromStartShortest != int.MaxValue)) { securityFromStartingSystem = SecurityStatus.Level.LowSecOnly; } return securityFromStartingSystem; }
public SignpostEntry(SolarSystem direction, int distance) { Direction = direction; Distance = distance; }
void UpdateSignpostsBetween(SolarSystem source, SolarSystem destination) { bool stillExpanding = true; // maybe the route's impossible (Jove) in which case we need to know when to give up! while (stillExpanding && !(source.SignpostShortest.ContainsKey(destination) && source.SignpostSecure.ContainsKey(destination))) { stillExpanding = false; // assume false until proven otherwise foreach (SolarSystem s in solarSystemsById.Values) { bool expanded = s.UpdateSignpostTo(destination); stillExpanding = stillExpanding || expanded; } } if (!source.SignpostSecure.ContainsKey(destination)) { // If we didn't find a secure route, drop a marker here to indicate that source.SignpostSecure[destination] = new SignpostEntry(null, int.MaxValue); } }
public int DistanceBetween(SolarSystem source, SolarSystem destination, bool secure) { UpdateSignpostsBetween(source, destination); if ((secure) && (source.SignpostSecure.ContainsKey(destination))) { return source.SignpostSecure[destination].Distance; } else if ((!secure) && (source.SignpostShortest.ContainsKey(destination))) { return source.SignpostShortest[destination].Distance; } else { return int.MaxValue; } }
public string Info(Station station, SolarSystem from) { return(Info(station, from, string.Empty)); }
protected override void InterpretRow(Dictionary <string, string> fields) { float price = float.Parse(fields["price"], System.Globalization.CultureInfo.InvariantCulture); int quantity = (int)float.Parse(fields["volRemaining"], System.Globalization.CultureInfo.InvariantCulture); int minQuantity = (int)float.Parse(fields["minVolume"], System.Globalization.CultureInfo.InvariantCulture); int typeId = int.Parse(fields["typeID"]); int range = int.Parse(fields["range"]); int regionId = int.Parse(fields["regionID"]); int stationId = int.Parse(fields["stationID"]); int systemId = int.Parse(fields["solarSystemID"]); string isWanted = fields["bid"]; SolarSystem s = map.GetSystem(systemId); Station station = map.GetStation(stationId); ItemType type = itemDatabase.GetItemType(typeId); if (s != null && type != null && station != null) { Trade trade = new Trade(type, price, quantity, minQuantity); if (isWanted == "True") { // Range is in station only if (range == -1) { station.AddItemWanted(trade); if (!stationsWithItemsWanted.Contains(station)) { stationsWithItemsWanted.Add(station); } } // Range it either system or greater else if ((range > -1) & (range < 32767)) { foreach (SolarSystem sAtRange in s.Region.Systems) { if (map.DistanceBetween(s, sAtRange, false) <= range) { sAtRange.AddItemWanted(trade); foreach (Station remoteStation in sAtRange.Stations) { if (!stationsWithItemsWanted.Contains(remoteStation)) { stationsWithItemsWanted.Add(remoteStation); } } } } } // Range is regional else if (range == 32767) { s.Region.AddItemWanted(trade); foreach (SolarSystem system in s.Region.Systems) { foreach (Station remoteStation in system.Stations) { if (!stationsWithItemsWanted.Contains(remoteStation)) { stationsWithItemsWanted.Add(remoteStation); } } } } } else { station.AddItemForSale(trade); if (!stationsWithItemsForSale.Contains(station)) { stationsWithItemsForSale.Add(station); } } } }