public Map(int width, int height) { Width = width; Height = height; _terrain = new Terrain[Width, Height]; _explored = new bool[Width, Height]; EnemyStatusToggle = false; _layers = new List <ISpatialMap <MObject> >(); ResistanceMap = new LambdaMapView <double>(Width, Height, pos => IsTransparent(pos) ? 0 : 1); WalkabilityMap = new LambdaMapView <bool>(Width, Height, IsWalkable); Pather = new AStar(WalkabilityMap, Distance.CHEBYSHEV); for (int i = 0; i < _layerSize; i++) { if (_layerCanHaveMultipleItems[i]) { _layers.Add(new MultiSpatialMap <MObject>()); } else { _layers.Add(new SpatialMap <MObject>()); } } }
public void LambaMapViewTest() { ArrayMap <bool> map = new ArrayMap <bool>(10, 10); RectangleMapGenerator.Generate(map); IMapView <double> lambdaMapView = new LambdaMapView <double>(map.Width, map.Height, c => map[c] ? 1.0 : 0.0); checkMaps(map, lambdaMapView); }
public ArrayMap <Cell> GenerateMap(int mapSizeTiles, int Openness = 10, bool overLapTiles = true) { mapSize = mapSizeTiles; overLap = overLapTiles; rand = Openness; size = overLap == true ? (mapSize * tileSize) - mapSize + 1 : mapSize * tileSize; overlayMap = BuildOverlayMap(); //We can use a LamdaMapView to extract the indexes indexMap = new LambdaMapView <int>(mapSizeTiles, mapSizeTiles, pos => overlayMap[(pos.X * 2) + 1, (pos.Y * 2) + 1]); ArrayMap <bool> walkMap = BuildWalkMap(); ArrayMap <Cell> tiles = new ArrayMap <Cell>(size, size); //Flood the cells with walls to be on the safe side. FloodWalls(tiles); for (int x = 0; x < walkMap.Width; x++) { for (int y = 0; y < walkMap.Height; y++) { if (walkMap[x, y]) { tiles[x, y] = new Cell(Color.Gray, Color.Black, ' '); } else { tiles[x, y] = new Cell(Color.Gray, Color.Black, '#'); } } } return(tiles); }
/// <summary> /// Constructor. Constructs map with the given terrain layer, determining width/height based on the width/height of that terrain layer. /// </summary> /// <remarks> /// Because of the way polymorphism works for custom classes in C#, the <paramref name="terrainLayer"/> parameter MUST be of type /// <see cref="ISettableMapView{IGameObject}"/>, rather than <see cref="ISettableMapView{T}"/> where T is a type that derives from or implements /// <see cref="IGameObject"/>. If you need to use a map view storing type T rather than IGameObject, use the /// <see cref="CreateMap{T}(ISettableMapView{T}, int, Distance, uint, uint, uint)"/> function to create the map. /// </remarks> /// <param name="terrainLayer">The <see cref="ISettableMapView{IGameObject}"/> that represents the terrain layer for this map. After the /// map has been created, you should use the <see cref="SetTerrain(IGameObject)"/> function to modify the values in this map view, rather /// than setting the values via the map view itself -- if you re-assign the value at a location via the map view, the /// <see cref="ObjectAdded"/>/<see cref="ObjectRemoved"/> events are NOT guaranteed to be called, and many invariants of map may not be properly /// enforced.</param> /// <param name="numberOfEntityLayers">Number of non-terrain layers for the map.</param> /// <param name="distanceMeasurement"><see cref="Distance"/> measurement to use for pathing/measuring distance on the map.</param> /// <param name="layersBlockingWalkability">Layer mask containing those layers that should be allowed to have items that block walkability. /// Defaults to all layers.</param> /// <param name="layersBlockingTransparency">Layer mask containing those layers that should be allowed to have items that block FOV. /// Defaults to all layers.</param> /// <param name="entityLayersSupportingMultipleItems">Layer mask containing those layers that should be allowed to have multiple objects at the same /// location on the same layer. Defaults to no layers.</param> public Map(ISettableMapView <IGameObject> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue, uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0) { _terrain = terrainLayer; Explored = new ArrayMap <bool>(_terrain.Width, _terrain.Height); _entities = new LayeredSpatialMap <IGameObject>(numberOfEntityLayers, 1, entityLayersSupportingMultipleItems); LayersBlockingWalkability = layersBlockingWalkability; LayersBlockingTransparency = layersBlockingTransparency; _entities.ItemAdded += (s, e) => ObjectAdded?.Invoke(this, e); _entities.ItemRemoved += (s, e) => ObjectRemoved?.Invoke(this, e); _entities.ItemMoved += (s, e) => ObjectMoved?.Invoke(this, e); if (layersBlockingTransparency == 1) // Only terrain so we optimize { TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsTransparent); } else { TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsTransparent); } if (layersBlockingWalkability == 1) // Similar, only terrain blocks, so optimize { WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsWalkable); } else { WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsWalkable); } _fov = new FOV(TransparencyView); AStar = new AStar(WalkabilityView, distanceMeasurement); }