public Dictionary <Direction, TileAtmosphere> GetAdjacentTiles(MapIndices indices) { var sides = new Dictionary <Direction, TileAtmosphere>(); foreach (var dir in Cardinal()) { var side = indices.Offset(dir); sides[dir] = GetTile(side); } return(sides); }
public Dictionary <Direction, TileAtmosphere> GetAdjacentTiles(MapIndices indices) { var sides = new Dictionary <Direction, TileAtmosphere>(); foreach (var dir in Cardinal) { var side = indices.Offset(dir); var tile = GetTile(side); if (tile?.Air != null) { sides[dir] = tile; } } return(sides); }
private Dictionary <Direction, Atmosphere> GetAdjacentAtmospheres(MapIndices pos) { var sides = new Dictionary <Direction, Atmosphere>(); foreach (var dir in Cardinal()) { var side = pos.Offset(dir); if (IsObstructed(side)) { continue; } sides[dir] = GetAtmosphere(side); } return(sides); }
private void SplitAtmospheres(MapIndices pos) { // Remove the now-covered atmosphere _atmospheres.Remove(pos); var adjacent = GetAdjacentAtmospheres(pos); var adjacentPositions = adjacent.Select(p => pos.Offset(p.Key)).ToList(); var adjacentAtmospheres = new HashSet <Atmosphere>(adjacent.Values); foreach (var atmos in adjacentAtmospheres) { var i = 0; int?spaceIdx = null; var sides = new Dictionary <MapIndices, int>(); foreach (var pair in adjacent.Where(p => p.Value == atmos)) { var edgePos = pos.Offset(pair.Key); if (sides.ContainsKey(edgePos)) { continue; } var connected = FindConnectedCells(edgePos); if (connected == null) { if (spaceIdx == null) { spaceIdx = i++; } sides[edgePos] = (int)spaceIdx; continue; } foreach (var connectedPos in connected.Intersect(adjacentPositions)) { sides[connectedPos] = i; } i++; } // If the sides were all connected, this atmosphere is intact // TODO in some way adjust the atmosphere volume if (i == 1) { continue; } // If any of the sides that used to have this atmosphere are now exposed to space, remove // all the old atmosphere's cells. if (spaceIdx != null) { foreach (var rpos in FindRoomContents(atmos)) { _atmospheres.Remove(rpos); } } // Split up each of the sides for (var j = 0; j < i; j++) { // Find a position to represent this var basePos = sides.First(p => p.Value == j).Key; var connected = FindConnectedCells(basePos); if (connected == null) { continue; } var newAtmos = new Atmosphere(GetVolumeForCells(connected.Count)); // Copy over contents of atmos, scaling it down to maintain the partial pressure if (atmos != null) { newAtmos.Temperature = atmos.Temperature; foreach (var gas in atmos.Gasses) { newAtmos.SetQuantity(gas.Gas, gas.Volume * newAtmos.Volume / atmos.Volume); } } foreach (var cpos in connected) { _atmospheres[cpos] = newAtmos; } } } }