public void Remove(ISpaceObject sobj) { foreach (var l in SpaceObjectLocations.ToArray()) { if (l.Item == sobj) { SpaceObjectLocations.Remove(l); } } }
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); } }
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(); } }
public IEnumerable <IAbilityObject> GetContainedAbilityObjects(Empire emp) { return(SpaceObjectLocations.Select(l => l.Item).Where(sobj => sobj?.Owner == emp).OfType <IAbilityObject>()); }
/// <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))); }
public bool Contains(ISpaceObject sobj) { return(SpaceObjectLocations.Any(l => l.Item == sobj)); }