Exemple #1
0
        /// <summary>
        /// Builds the A* map to be used for NPC pathfinding
        /// </summary>
        /// <param name="spriteTileReferences"></param>
        protected void InitializeAStarMap(TileReferences spriteTileReferences)
        {
            Debug.Assert(TheMap != null);
            Debug.Assert(TheMap.Length > 0);
            int nXTiles = TheMap[0].Length;
            int nYTiles = TheMap.Length;

            // load the A-Star compatible map into memory
            AStarNodes = Utils.Init2DList <Node>(nXTiles, nYTiles);

            for (int x = 0; x < nXTiles; x++)
            {
                for (int y = 0; y < nYTiles; y++)
                {
                    TileReference currentTile = spriteTileReferences.GetTileReference(TheMap[x][y]);

                    bool bIsWalkable =
                        currentTile.IsWalking_Passable || currentTile.Index ==
                        spriteTileReferences.GetTileReferenceByName("RegularDoor").Index ||
                        currentTile.Index == spriteTileReferences
                        .GetTileReferenceByName("RegularDoorView").Index ||
                        currentTile.Index == spriteTileReferences
                        .GetTileReferenceByName("LockedDoor").Index ||
                        currentTile.Index == spriteTileReferences
                        .GetTileReferenceByName("LockedDoorView").Index;

                    float fWeight = GetAStarWeight(spriteTileReferences, new Point2D(x, y));

                    Node node = new Node(new System.Numerics.Vector2(x, y), bIsWalkable, fWeight);
                    AStarNodes[x].Add(node);
                }
            }
            AStar = new AStar(AStarNodes);
        }
Exemple #2
0
        /// <summary>
        /// Calculates an appropriate A* weight based on the current tile as well as the surrounding tiles
        /// </summary>
        /// <param name="spriteTileReferences"></param>
        /// <param name="xy"></param>
        /// <returns></returns>
        protected override float GetAStarWeight(TileReferences spriteTileReferences, Point2D xy)
        {
            bool isPreferredIndex(int nSprite)
            {
                bool bIsPreferredIndex = nSprite == spriteTileReferences.GetTileReferenceByName("BrickFloor").Index || spriteTileReferences.IsPath(nSprite);

                return(bIsPreferredIndex);
            }

            const int     fDefaultDeduction = 2;
            TileReference currentTile       = spriteTileReferences.GetTileReference(TheMap[xy.X][xy.Y]);

            float fCost = 10;

            // we reduce the weight for the A* for each adjacent brick floor or path tile
            if (xy.X - 1 >= 0)
            {
                fCost -= isPreferredIndex(TheMap[xy.X - 1][xy.Y]) ? fDefaultDeduction : 0;
            }
            if (xy.X + 1 < XTILES)
            {
                fCost -= isPreferredIndex(TheMap[xy.X + 1][xy.Y]) ? fDefaultDeduction : 0;
            }
            if (xy.Y - 1 >= 0)
            {
                fCost -= isPreferredIndex(TheMap[xy.X][xy.Y - 1]) ? fDefaultDeduction : 0;
            }
            if (xy.Y + 1 < YTILES)
            {
                fCost -= isPreferredIndex(TheMap[xy.X][xy.Y + 1]) ? fDefaultDeduction : 0;
            }

            return(fCost);
        }
Exemple #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="u5StringRef"></param>
        public TileReferences(U5StringRef u5StringRef)
        {
            this._u5StringRef       = u5StringRef;
            TileReferenceDictionary = TileReferences.Load();

            for (int i = 0; i < TileReferenceDictionary.Count; i++)
            {
                TileReference tileRef = TileReferenceDictionary[i];
                // this is gross, but I can't seem to get the index number in any other way...
                tileRef.Index = i;
                TileReferenceByStringDictionary.Add(tileRef.Name, tileRef);
            }
        }
Exemple #4
0
        public SmallMaps(SmallMapReferences smallMapRef, string u5Directory, TileReferences spriteTileReferences, TileOverrides tileOverrides)
        {
            this._smallMapRef          = smallMapRef;
            this._spriteTileReferences = spriteTileReferences;
            foreach (SmallMapReferences.SingleMapReference mapRef in smallMapRef.MapReferenceList)
            {
                // now I can go through each and every reference
                SmallMap smallMap = new SmallMap(u5Directory, mapRef, spriteTileReferences, tileOverrides);
                _smallMaps.Add(smallMap);

                // we make a map that allows us to map the _location and Floor number to the small map with
                // details such as the grid
                if (!_mapLocationDictionary.ContainsKey(mapRef.MapLocation))
                {
                    _mapLocationDictionary.Add(mapRef.MapLocation, new Dictionary <int, SmallMap>());
                }
                _mapLocationDictionary[mapRef.MapLocation].Add(mapRef.Floor, smallMap);
            }
        }
Exemple #5
0
 protected override float GetAStarWeight(TileReferences spriteTileReferences, Point2D xy)
 {
     return(1);
 }
Exemple #6
0
 /// <summary>
 /// Calculates an appropriate A* weight based on the current tile as well as the surrounding tiles
 /// </summary>
 /// <param name="spriteTileReferences"></param>
 /// <param name="xy"></param>
 /// <returns></returns>
 protected abstract float GetAStarWeight(TileReferences spriteTileReferences, Point2D xy);
Exemple #7
0
        /// <summary>
        /// Creates a small map object using a pre-defined map reference
        /// </summary>
        /// <param name="u5Directory"></param>
        /// <param name="mapRef"></param>
        /// <param name="spriteTileReferences"></param>
        /// <param name="tileOverrides"></param>
        public SmallMap(string u5Directory, SmallMapReferences.SingleMapReference mapRef, TileReferences spriteTileReferences, TileOverrides tileOverrides) : base(u5Directory, tileOverrides, mapRef)
        {
            _mapRef = mapRef;

            // load the map into memory
            TheMap = LoadSmallMapFile(Path.Combine(u5Directory, mapRef.MapFilename), mapRef.FileOffset);


            InitializeAStarMap(spriteTileReferences);
        }