Example #1
0
File: Fleet.cs Project: ndech/Alpha
 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;
 }
Example #2
0
 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
     };
 }
Example #3
0
 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;
     }
 }
Example #4
0
 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;
 }
Example #5
0
 public LandProvince(World world, Zone zone) : base(world, zone)
 {
     Name = NameGenerator.GetRandomProvinceName();
     Color = CustomColor.Random;
     Capital = new Settlement(world, this);
 }
Example #6
0
File: Zone.cs Project: ndech/Alpha
 public double DistanceWith(Zone other)
 {
     return Vector3D.Distance(Center, other.Center);
 }
Example #7
0
 internal static void Initialize(Zone seed)
 {
     _currentSearchZone = seed;
 }
Example #8
0
 public static List<Step> CalculatePath(Fleet fleet, Zone destination)
 {
     return CalculatePath((IMovable)fleet, destination);
 }
Example #9
0
File: Step.cs Project: ndech/Alpha
 public Step(Zone source, Zone destination)
 {
     Source = source;
     Destination = destination;
     Distance = Vector3D.Distance(source.Center, destination.Center);
 }
Example #10
0
File: Fleet.cs Project: ndech/Alpha
 void IMovable.SetLocation(Zone location)
 {
     Location = location;
     World.Notify(new FleetMovedNotification(this));
 }