internal Fleet(World world, string name, Realm owner, Zone location, List<Ship> ships) : base(world) { Id = IdSequence; Name = name; Owner = owner; Location = location; _ships = ships; }
public ZoneAdjacency(Zone province, Zone neighbourg, List<Vector3D> commonPoints) { Zone = province; Neighbourg = neighbourg; CommonPoints = commonPoints; PassingPoints = new List<Vector3D> { commonPoints.Aggregate(new Vector3D(), (total, vector) => total + vector)/commonPoints.Count }; }
public static Zone ClosestZone(Vector3D position) { while (true) { Zone closestNeighbourgOrSelf = _currentSearchZone.Adjacencies.Select(a => a.Neighbourg) .Union(_currentSearchZone) .MinBy(p => Vector3D.Distance(p.Center, position)); if (closestNeighbourgOrSelf == _currentSearchZone) return _currentSearchZone; _currentSearchZone = closestNeighbourgOrSelf; } }
private static List<Step> CalculatePath(IMovable movable, Zone destination) { List<Step> steps = new List<Step>(); if (movable.Location == destination || !movable.CanCross(destination)) return steps; //Calculate path using A* algorithm SortedSet<PathfindingNode> openList = new SortedSet<PathfindingNode>( Comparer<PathfindingNode>.Create((a, b) => a.CompareTo(b))); HashSet<Zone> closedList = new HashSet<Zone>(); openList.Add(new PathfindingNode(movable.Location, destination.DistanceWith(movable.Location))); bool pathFound = destination == movable.Location; while (!pathFound) { if (openList.Count == 0) break; PathfindingNode currentNode = openList.First(); foreach (Zone neighbourg in currentNode.Zone.Adjacencies.Select(a => a.Neighbourg).Where(s => movable.CanCross(s))) { if (closedList.Contains(neighbourg) || openList.Any(n => n.Zone == neighbourg)) continue; openList.Add(new PathfindingNode(neighbourg, destination.DistanceWith(neighbourg), currentNode)); if (neighbourg == destination) // Path found ! { pathFound = true; steps.Add(new Step(currentNode.Zone, destination)); while (currentNode.Parent != null) { steps.Add(new Step(currentNode.Parent.Zone, currentNode.Zone)); currentNode = currentNode.Parent; } steps.Reverse(); break; } } openList.Remove(currentNode); closedList.Add(currentNode.Zone); } if (steps.Count == 0) return steps; return steps; }
public LandProvince(World world, Zone zone) : base(world, zone) { Name = NameGenerator.GetRandomProvinceName(); Color = CustomColor.Random; Capital = new Settlement(world, this); }
public double DistanceWith(Zone other) { return Vector3D.Distance(Center, other.Center); }
internal static void Initialize(Zone seed) { _currentSearchZone = seed; }
public static List<Step> CalculatePath(Fleet fleet, Zone destination) { return CalculatePath((IMovable)fleet, destination); }
public Step(Zone source, Zone destination) { Source = source; Destination = destination; Distance = Vector3D.Distance(source.Center, destination.Center); }
void IMovable.SetLocation(Zone location) { Location = location; World.Notify(new FleetMovedNotification(this)); }