Esempio n. 1
0
        public PointTileNode GetTile(int x, int y)
        {
            // Console.WriteLine("x" + x + ", y" + y);
            PointTileNode t = null;

            _tilesByLocalPositionHash.TryGetValue(BitCruncher.PackTwoShorts(x, y), out t);
            return(t);
        }
Esempio n. 2
0
 public void SetTiles(IList <IntPoint> pPoints)
 {
     _tilesByLocalPositionHash.Clear();
     foreach (IntPoint t in pPoints)
     {
         PointTileNode newNode = new PointTileNode(t, this);
         _tilesByLocalPositionHash.Add(newNode.localPoint.GetHashCode(), newNode);
     }
     ApplyTileData();
     UpdateBounds();
 }
Esempio n. 3
0
 public override float DistanceTo(Pathfinding.IPoint pPoint)
 {
     if (pPoint is TileNode)
     {
         PointTileNode otherNode = pPoint as PointTileNode;
         return(worldPoint.EuclidianDistanceTo(otherNode.worldPoint));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Esempio n. 4
0
        private void ConnectNodes(PointTileNode pA, PointTileNode pB)
        {
            PathLink l = pB.GetLinkTo(pA);

            if (l == null)
            {
                l          = new PathLink(pA, pB);
                l.distance = 1f;
                pA.AddLink(l);
                pB.AddLink(l);
            }
        }
Esempio n. 5
0
        public void AddTile(PointTileNode pTileNode)
        {
#if DEBUG
            //Console.WriteLine("Called Room.AddTile() Warning, this is slow"); //. Callstack: " + Environment.StackTrace);
#endif
            try {
                _tilesByLocalPositionHash.Add(pTileNode.localPoint.GetHashCode(), pTileNode);
            }
            catch (Exception e) {
                throw new Exception("Could not add tileNode at: " + pTileNode.localPoint.ToString() + " hashcode " + pTileNode.GetHashCode(), e);
            }
            AddTileLinks(pTileNode);
            RefreshTileData();
            UpdateBounds();
        }
Esempio n. 6
0
        protected void ConnectToCurrentTile()
        {
            D.isNull(room, "room is null");
            PointTileNode tile = room.GetTile(position.localPosition);

            if (tile == null)
            {
                //D.Log("Found no tile for Ting " + name);
            }
            else
            {
                tile.AddOccupant(this);
                _isOccupyingTile = true;
            }
        }
Esempio n. 7
0
        private void AddTileLinks(PointTileNode tileNode)
        {
            PointTileNode start = tileNode;
            int           x     = start.localPoint.x;
            int           y     = start.localPoint.y;
            PointTileNode outputNode;

            if (_tilesByLocalPositionHash.TryGetValue(new IntPoint(x + 1, y).GetHashCode(), out outputNode))
            {
                ConnectNodes(start, outputNode);
            }
            if (_tilesByLocalPositionHash.TryGetValue(new IntPoint(x - 1, y).GetHashCode(), out outputNode))
            {
                ConnectNodes(start, outputNode);
            }
            if (_tilesByLocalPositionHash.TryGetValue(new IntPoint(x, y + 1).GetHashCode(), out outputNode))
            {
                ConnectNodes(start, outputNode);
            }
            if (_tilesByLocalPositionHash.TryGetValue(new IntPoint(x, y - 1).GetHashCode(), out outputNode))
            {
                ConnectNodes(start, outputNode);
            }
        }