private ComponentProperty[] ResolveLocations(ShipComponent component) { List <ComponentProperty> properties = new List <ComponentProperty>(); Facing facing = grid.GetZone(component); properties.AddRange(ResolveLocations(facing, component.Type.properties)); properties.AddRange(ResolveLocations(facing, component.Properties)); return(properties.ToArray()); }
public void ReportDamage(ShipComponent c) { if (c == null) { OnDamageAndShield(); } else { OnComponentDestroyed(c); } }
public Facing GetZone(ShipComponent component) { IntPair p = locations[component].location; int mid = (int)Math.Floor(width / 2f); bool upOrLeft = (p.x >= mid ? p.x - 1 : p.x) + p.y < height; if ((p.x > mid ? p.x - 1 : p.x) > p.y) { return(upOrLeft ? Facing.UP : Facing.RIGHT); } else { return(upOrLeft ? Facing.LEFT : Facing.DOWN); } }
private ComponentAdjacencyBonus[] ResolveLocationAdjacencies(ShipComponent component) { Facing facing = grid.GetZone(component); List <ComponentAdjacencyBonus> adjacencyBonuses = new List <ComponentAdjacencyBonus>(); foreach (ComponentAdjacencyBonus bonus in component.Type.adjacencyBonuses) { if (bonus.propertyIdentifier.EndsWith(zoneBasedStringMarker)) { adjacencyBonuses.Add(new ComponentAdjacencyBonus( bonus.componentIdentifier, bonus.propertyIdentifier.Replace(zoneBasedStringMarker, facing.GetPropertyString()), bonus.amount)); } else { adjacencyBonuses.Add(bonus); } } return(adjacencyBonuses.ToArray()); }
private void Grid_OnComponentDestroyed(ShipComponent component) { newConfigAvailable(BuildShipConfiguration(), false); }
private void Grid_OnComponentMove(ShipComponent component, ShipGrid.LocationInformation location) { newConfigAvailable(BuildShipConfiguration(), false); }
public List <ShipComponent> GetAdjacentComponents(ShipComponent component) { List <IntPair> adjacentTiles = GetAdjacentTiles(component); return(components.Where(i => GetOccupiedTiles(i).Intersect(adjacentTiles).Any()).ToList()); }
public void AddComponent(ShipComponent component, IntPair location) { locations.Add(component, new LocationInformation(location, Rotation.UP)); }
private List <IntPair> GetAdjacentTiles(ShipComponent component) { return(GetAdjacentTiles(GetOccupiedTiles(component))); }
private List <IntPair> GetOccupiedTiles(ShipComponent component) { Rotation rotation = locations[component].rotation; return(component.Type.shape.Select(i => i.Rotate(rotation) + locations[component].location).ToList <IntPair>()); }