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); }
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(); }
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(); } }
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); } }
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(); }
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; } }
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); } }