示例#1
0
        /// <summary>
        /// Effectively a helper-constructor.  Constructs a map using an <see cref="ISettableMapView{T}"/> for the terrain map, where type T can
        /// be any type that implements <see cref="IGameObject"/>.  Note that a Map that is constructed using this function will throw an
        /// <see cref="InvalidCastException"/> if any IGameObject is given to <see cref="SetTerrain(IGameObject)"/> that cannot be casted to type T.
        /// </summary>
        /// <remarks>
        /// Suppose you have a class MyTerrain that inherits from BaseClass and implements <see cref="IGameObject"/>.  This construction function allows
        /// you to construct your map using an <see cref="ISettableMapView{MyTerrain}"/> instance as the terrain map, which you cannot do with the regular
        /// constructor since <see cref="ISettableMapView{MyTerrain}"/> does not satisfy the constructor's type requirement of
        /// <see cref="ISettableMapView{IGameObject}"/>.
        ///
        /// Since this function under the hood creates a <see cref="SettableTranslationMap{T, IGameObject}"/> that translates to/from IGameObject as needed,
        /// any change made using the map's <see cref="SetTerrain(IGameObject)"/> function will be reflected both in the map and in the original
        /// ISettableMapView.
        /// </remarks>
        /// <typeparam name="T">The type of terrain that will be stored in the created Map.  Can be any type that implements <see cref="IGameObject"/>.</typeparam>
        /// <param name="terrainLayer">The <see cref="ISettableMapView{T}"/> 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>
        /// <returns>A new Map whose terrain is created using the given terrainLayer, and with the given parameters.</returns>
        public static Map CreateMap <T>(ISettableMapView <T> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue,
                                        uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0) where T : IGameObject
        {
            var terrainMap = new LambdaSettableTranslationMap <T, IGameObject>(terrainLayer, t => t, g => (T)g);

            return(new Map(terrainMap, numberOfEntityLayers, distanceMeasurement, layersBlockingWalkability, layersBlockingTransparency, entityLayersSupportingMultipleItems));
        }
示例#2
0
        public void LambdaSettableTranslationMapTest()
        {
            ArrayMap <double> map = new ArrayMap <double>(10, 10);

            ArrayMap <bool> controlMap = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(controlMap);

            var settable = new LambdaSettableTranslationMap <double, bool>(map, d => d > 0.0, b => b ? 1.0 : 0.0);

            RectangleMapGenerator.Generate(settable);

            checkMaps(controlMap, map);
        }
示例#3
0
        public void LambdaSettableTranslationMapTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            QuickGenerators.GenerateRectangleMap(map);

            var settable = new LambdaSettableTranslationMap <bool, double>(map, b => b ? 1.0 : 0.0, d => d > 0.0);

            checkMaps(map, settable);

            // Check other constructor.  Intentaionally "misusing" the position parameter, to make sure we ensure the position
            // parameter is correct without complicating our test case
            settable = new LambdaSettableTranslationMap <bool, double>(map, (pos, b) => map[pos] ? 1.0 : 0.0, (pos, d) => d > 0.0);
            checkMaps(map, settable);
        }