private void TrySpreadEnvironment(Point position, Direction direction, IAreaMapCellInternal cell, CellPairsStorage mergedCells) { var nextPosition = Point.GetPointInDirection(position, direction); if (!ContainsCell(nextPosition)) { return; } var nextCell = GetOriginalCell(nextPosition.X, nextPosition.Y); if (mergedCells.ContainsPair(position, direction)) { return; } mergedCells.RegisterPair(position, direction); if (nextCell.BlocksEnvironment) { return; } cell.CheckSpreading(nextCell); cell.Environment.Balance(cell, nextCell); }
public AreaMap( int level, Func <IAreaMapCellInternal> cellFactory, int width, int height, IMapLightLevelProcessor mapLightLevelProcessor = null) { this.mapLightLevelProcessor = mapLightLevelProcessor ?? new MapLightLevelProcessor(); objectPositionCache = new Dictionary <Type, Point>(); destroyableObjects = new Dictionary <string, IDestroyableObject>(); Level = level; Width = width; Height = height; cells = new IAreaMapCellInternal[height][]; for (var y = 0; y < height; y++) { cells[y] = new IAreaMapCellInternal[width]; for (var x = 0; x < width; x++) { cells[y][x] = cellFactory(); } } }
private void SpreadEnvironment(Point position, IAreaMapCellInternal cell, CellPairsStorage mergedCells) { TrySpreadEnvironment(position, Direction.North, cell, mergedCells); TrySpreadEnvironment(position, Direction.South, cell, mergedCells); TrySpreadEnvironment(position, Direction.West, cell, mergedCells); TrySpreadEnvironment(position, Direction.East, cell, mergedCells); }
private void SpreadObject(ISpreadingObject liquid, IAreaMapCellInternal target) { var spreadAmount = Math.Min(liquid.MaxSpreadVolume, liquid.Volume - liquid.MaxVolumeBeforeSpread); var separated = liquid.Separate(spreadAmount); target.ObjectsCollection.AddVolumeObject(separated); }
private void MergeCellEnvironment(Point position, IAreaMapCellInternal cell, CellPairsStorage mergedCells) { if (cell.BlocksEnvironment) { return; } SpreadEnvironment(position, cell, mergedCells); }
private void CheckSpreadingObjects(IAreaMapCellInternal other) { var localSpreadingObjects = ObjectsCollection.OfType <ISpreadingObject>().ToArray(); var otherSpreadingObjects = other.ObjectsCollection.OfType <ISpreadingObject>().ToArray(); foreach (var spreadingObject in localSpreadingObjects) { if (spreadingObject.Volume >= spreadingObject.MaxVolumeBeforeSpread) { SpreadObject(spreadingObject, other); } } foreach (var otherSpreadingObject in otherSpreadingObjects) { if (otherSpreadingObject.Volume >= otherSpreadingObject.MaxVolumeBeforeSpread) { SpreadObject(otherSpreadingObject, this); } } }
public void CheckSpreading(IAreaMapCellInternal other) { CheckSpreadingObjects(other); }