Esempio n. 1
0
 public void Remove(ISpaceObject sobj)
 {
     foreach (var l in SpaceObjectLocations.ToArray())
     {
         if (l.Item == sobj)
         {
             SpaceObjectLocations.Remove(l);
         }
     }
 }
Esempio n. 2
0
 public Point FindCoordinates(ISpaceObject sobj)
 {
     try
     {
         return(SpaceObjectLocations.Single(l => l.Item == sobj).Location);
     }
     catch (Exception ex)
     {
         throw new Exception("Can't find coordinates of " + sobj + " in " + this + ".", ex);
     }
 }
Esempio n. 3
0
        public void Place(ISpaceObject sobj, Point coords)
        {
            var sys = sobj.FindStarSystem();

            if (sys != null)
            {
                sys.Remove(sobj);
                sobj.Sector = null;
            }
            else
            {
                sobj.Sector = new Sector(this, coords);
            }

            SpaceObjectLocations.Add(new ObjectLocation <ISpaceObject>(sobj, coords));

            MarkAsExploredBy(sobj.Owner);

            // see if we got hit by a minefield
            if (!Serializer.IsDeserializing)
            {
                sobj.DealWithMines();
            }
        }
Esempio n. 4
0
 public IEnumerable <IAbilityObject> GetContainedAbilityObjects(Empire emp)
 {
     return(SpaceObjectLocations.Select(l => l.Item).Where(sobj => sobj?.Owner == emp).OfType <IAbilityObject>());
 }
Esempio n. 5
0
 /// <summary>
 /// Searches for space objects matching criteria.
 /// </summary>
 /// <typeparam name="T">The type of space object.</typeparam>
 /// <param name="criteria">The criteria.</param>
 /// <returns>The matching space objects.</returns>
 public IEnumerable <T> FindSpaceObjects <T>(Func <T, bool> criteria = null)
 {
     return(SpaceObjectLocations.Select(l => l.Item).OfType <T>().Where(l => criteria == null || criteria(l)));
 }
Esempio n. 6
0
 public bool Contains(ISpaceObject sobj)
 {
     return(SpaceObjectLocations.Any(l => l.Item == sobj));
 }