public Vector2d(IVector2 v) { ITuple2_Double _v = v.AsTupleDouble(); this.X = _v.X; this.Y = _v.Y; }
public static float Distance(IVector2 v1, IVector2 v2) { int dx = v2.x - v1.x; int dy = v2.y - v1.y; return(Mathf.Sqrt(dx * dx + dy * dy)); }
public static double DiagonalDistance(IVector2 _from, IVector2 _to, double _defaultVal) { var a = Math.Abs(_from.x - _to.x); var b = Math.Abs(_from.y - _to.y); return((double)Math.Ceiling(Math.Sqrt(a * a + b * b))); }
public override void Transform(IVector2 v, IOpVector2 vout) { ITuple2_Double _v = v.AsTupleDouble(); IOpTuple2_Double _vout = vout.AsOpTupleDouble(); _vout.Set(_v.X, _v.Y); }
public void setTile(IVector2 v, byte foreground, byte background) { if (!inBounds(v)) { return; } setByte(v, FOREGROUND_ID, foreground); setByte(v, BACKGROUND_ID, background); TileSpec t = TileSpecList.getTileSpec(foreground); byte d = 1; if (t != null) { d = t.durability; } setByte(v, DURABILITY, d); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { IVector2 vi = v + new IVector2(x, y); updateTileSpec(vi); if (inBounds(vi)) { makeDirty(vi.x / chunkSize, vi.y / chunkSize); } } } }
public AStarOpenNode(IVector2 _coord, IVector2?_parent, double _costSoFar, double _estTotalCost) { Coord = _coord; Parent = _parent; CostSoFar = _costSoFar; EstTotalCost = _estTotalCost; }
/// <summary> /// 決定可否瞬間移動,可以則transportPos為瞬間移動後的位置 /// </summary> /// <param name="creature">生物種類</param> /// <param name="pos">位置</param> /// <param name="transportPos">瞬間移動後位置</param> public bool CanTransport(Creature creature, IVector2 pos, out IVector2 transportPos) { transportPos = pos.Clone(); if (!CheckPosLegal(pos)) { return(false); } if (creature != Creature.Scarab || allMapBlock[pos.x][pos.y].MapBlockType != BlockType.Hole) { return(false); } if (holePos == null || !holePos.ContainsKey(pos.DataToUInt())) { return(false); } else { transportPos = holePos[pos.DataToUInt()].Clone(); if (!CheckPosLegal(transportPos)) { return(false); } if (allMapBlock[transportPos.x][transportPos.y].LivingObject != Creature.None) { return(false); } else { return(true); } } }
public void updateTileSpec(IVector2 v) { if (!inBounds(v)) { return; } map [v.y, v.x] &= 0x00FF0000FFFF; bool[] b = new bool[directions.Length]; for (int i = 0; i < directions.Length; i++) { b[i] = isForegroundSolid(v + Direction.getDirection(directions[i])); } setByte(v, FOREGROUND_CONTEXT, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) { b[i] = isBackgroundSolid(v + Direction.getDirection(directions[i])); } setByte(v, BACKGROUND_CONTEXT, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) { b[i] = unnavigable(v + Direction.getDirection(directions[i])); } setByte(v, NAVIGATION_MAP, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) { b[i] = ladderable(v + Direction.getDirection(directions[i])); } setByte(v, LADDER_MAP, Direction.packByte(directions, b)); }
public void Lineal(IVector2 v2, double alpha, double beta) { ITuple2_Double _v2 = v2.AsTupleDouble(); this.Set(alpha * this.x + beta * _v2.X, alpha * this.y + beta * _v2.Y); }
public void SimpleMul(IVector2 v1, IVector2 v2) { ITuple2_Double _v1 = v1.AsTupleDouble(); ITuple2_Double _v2 = v2.AsTupleDouble(); this.Set(_v1.X * _v2.X, _v1.Y * _v2.Y); }
public void Sub(IVector2 v1, IVector2 v2) { ITuple2_Double _v1 = v1.AsTupleDouble(); ITuple2_Double _v2 = v2.AsTupleDouble(); this.Set(_v1.X - _v2.X, _v1.Y - _v2.Y); }
public static int DistanceManhatten(IVector2 v1, IVector2 v2) { int dx = Mathf.Abs(v2.x - v1.x); int dy = Mathf.Abs(v2.y - v1.y); return(dx + dy); }
public Vector2i(IVector2 v) { ITuple2_Integer _v = v.AsTupleInteger(); this.X = _v.X; this.Y = _v.Y; }
public void ProjectTo(IVector2 where) { BuffVector2d aux = new BuffVector2d(where); aux.ProjV(new Vector2d(this.x, this.y)); this.Set(aux.X, aux.Y); }
public void Update(Vector2 start, Vector2 end, bool hit) { start = rect.InversePoint(start); end = rect.InversePoint(end); Vector2 p = start; IVector2 ij = new IVector2(p); IVector2 stop = new IVector2(end); Vector2 d = end - start; int dx = (int)Mathf.Sign(d.x); int dy = (int)Mathf.Sign(d.y); while (ij != stop) { SetOccupied(ij, false); float dh = Mathf.Abs(ij.x + dx - p.x); float dv = Mathf.Abs(ij.y + dy - p.y); if (dv * d.x < dh * d.y) { ij.y += dy; } else { ij.x += dx; } } // update the endpoint SetOccupied(stop, hit); }
public static Quadratic From3Coordinate2(IVector2 <double> A, IVector2 <double> B, IVector2 <double> C) { //Convert the 3 points to quadratic equations. var equation1 = new Quadratic(A.X, A.Y); var equation2 = new Quadratic(B.X, B.Y); var equation3 = new Quadratic(C.X, C.Y); //Cancel out "C" var equation4 = equation1.MakeSubject(equation1.C).Subtract(equation2.MakeSubject(equation1.C)); var equation5 = equation2.MakeSubject(equation2.C).Subtract(equation3.MakeSubject(equation3.C)); //Cancel out "B" var equation6 = equation4.MakeSubject(equation4.B).Subtract(equation5.MakeSubject(equation5.B)); //Solve for A then B then C var a = equation6.MakeSubject(equation6.A).Result; //Substitute into EQ 6 var b = (equation4.Result - equation4.A * a) / equation4.B; //Into EQ 4 var c = (A.Y) - (a * (A.X) * (A.X)) - (b * (A.X)); //Into EQ 1 //Create new Quadratic solver based on A, B and C. var output = new Quadratic { A = a, B = b, C = c }; return(output); }
public static IVector2?FindIntersection(IVector2 _start1, IVector2 _end1, IVector2 _start2, IVector2 _end2) { double denom = ((_end1.x - _start1.x) * (_end2.y - _start2.y)) - ((_end1.y - _start1.y) * (_end2.x - _start2.x)); // AB & CD are parallel if (denom == 0) { return(null); } double numer = ((_start1.y - _start2.y) * (_end2.x - _start2.x)) - ((_start1.x - _start2.x) * (_end2.y - _start2.y)); double r = numer / denom; double numer2 = ((_start1.y - _start2.y) * (_end1.x - _start1.x)) - ((_start1.x - _start2.x) * (_end1.y - _start1.y)); double s = numer2 / denom; if ((r < 0 || r > 1) || (s < 0 || s > 1)) { return(null); } // Find intersection IVector2 IVector2 result = new IVector2(0, 0); result.x = _start1.x + (int)(r * ((double)_end1.x - (double)_start1.x)); result.y = _start1.y + (int)(r * ((double)_end1.y - (double)_start1.y)); return(result); }
public Vector2 CursorPosition(IVector2 pos) { if (text == "") { return(transform.position); } Rect r = worldRect; Vector2 p = new Vector2(r.xMin, r.yMin + r.height / 2); int px = 0; int tx = 0; for (int i = 0; i < sizeChars.Length; i++) { if (i < sizeChars.Length && i < pos.x) { px += (sizeChars[i]); } tx += (sizeChars[i]); } if (tx > 0 && px > 0) { return(p + new Vector2((r.width / tx) * px, 0)); } else { return(transform.position); } }
public List <IVector2> GetNeighborCoordsOf(int _x, int _y, bool _useDiag = false) { var neighbors = new List <IVector2>(); for (var x = _x - 1; x <= _x + 1; ++x) { for (var y = _y - 1; y <= _y + 1; ++y) { var p = new IVector2(x, y); if (CoordInRange(new IVector2(p.x, p.y))) { if (!p.Equals(new IVector2(_x, _y))) { if (!_useDiag) { if (Math.Abs(_x - x) + Math.Abs(_y - y) == 1) { neighbors.Add(p); } } else { neighbors.Add(p); } } } } } return(neighbors); }
public bool Contains(IVector2 _point) { int maxX = (int)Math.Max(m_Start.x, m_End.x); int maxY = (int)Math.Max(m_Start.y, m_End.y); int minX = (int)Math.Min(m_Start.x, m_End.x); int minY = (int)Math.Min(m_Start.y, m_End.y); if (_point.x > maxX || _point.x < minX || _point.y > maxY || _point.y < minY) { return(false); } double slope = (double)(m_Start.y - m_End.y) / (double)(m_Start.x - m_End.x); int yInt; if (slope == double.PositiveInfinity || slope == double.NegativeInfinity) { return(_point.x == m_Start.x); } else { yInt = (int)(-slope * m_Start.x + m_Start.y); return((int)_point.y == (int)(slope * _point.x + yInt)); } }
private IVector2 FindBin(Vector2 pos, float[] binsX, float[] binsY) { IVector2 bin = new IVector2(-1, -1); for (int x = 0; x < binsX.Length; x++) { if (pos.x <= binsX[x]) { bin.x = x; break; } } if (bin.x == -1) { bin.x = binsX.Length; } for (int y = 0; y < binsY.Length; y++) { if (pos.y <= binsY[y]) { bin.y = y; break; } } if (bin.y == -1) { bin.y = binsY.Length; } return(bin); }
public Line2 Translate(IVector2 translation) { Line2 lineOut = new Line2(Point1.Plus(translation), Point2.Plus(translation)); lineOut.Col = Col; return(lineOut); }
public Vector2[] GetNeighbors(){ List<Vector2> neighbors = new List<Vector2>(); IVector2 pos = new IVector2(location.x,location.y); if(m == null){ m = GameObject.FindObjectOfType<Map>(); } int[] dirs = new int[]{Direction.TOP, Direction.BOTTOM, Direction.LEFT, Direction.RIGHT, Direction.TOPLEFT, Direction.TOPRIGHT, Direction.BOTTOMLEFT, Direction.BOTTOMRIGHT}; bool[] passability = Direction.extractByte(dirs, (byte)(~m.getByte(pos, Map.NAVIGATION_MAP))); bool[] ladder = Direction.extractByte(dirs, (byte)(m.getByte(pos, Map.LADDER_MAP))); bool[] solid = Direction.extractByte(dirs, (byte)(~m.getByte(pos, Map.FOREGROUND_CONTEXT))); IVector2[] directions = Direction.getDirections(dirs); for (int i = 4; i < 6; i++){ if(passability[i] && solid[0]) neighbors.Add (pos + directions[i]); } for (int i = 6; i < 8; i++){ if(passability[i] && solid[i - 4]) neighbors.Add (pos + directions[i]); } for (int i = 0; i < 4; i++){ if(passability[i] || ladder[i]) neighbors.Add (pos + directions[i]); } return neighbors.ToArray(); }
public void Translate(IVector2 trVec) { m_xMin += trVec.x; m_xMax += trVec.x; m_yMin += trVec.y; m_yMax += trVec.y; }
public static IFloat Distance(Vector2 v1, IVector2 v2) { int dx = Mathf.FloorToInt(((v2.x * FLOAT_HELPER) - (v1.x * FLOAT_HELPER)) * FLOAT_HELPER2); int dy = Mathf.FloorToInt(((v2.y * FLOAT_HELPER) - (v1.y * FLOAT_HELPER)) * FLOAT_HELPER2); return(Mathf.Sqrt(dx * dx + dy * dy)); }
public void Set(IVector2 v) { foreach (var f in floats) { f.Set(v); } }
internal void AddDoorway(IVector2 _doorway) { if (!m_Doorways.Contains(_doorway)) { m_Doorways.Add(_doorway); } }
public Vector2(IVector2 Vector2) { x = Vector2.X; y = Vector2.Y; Col = Vector2.Col; }
private CompData <T> GetData(IVector2 _coord, out int _index, out int _stripPos) { //Check that coords are valid if (CoordInRange(_coord)) { var curBlkLinear = 0; var trgBlkLinear = _coord.x + _coord.y * Dims.x; if (trgBlkLinear == 0) { _index = 0; _stripPos = 0; return(DataBlock[_index]); } //Find target block _index = 0; while (true) { curBlkLinear += DataBlock[_index].count; if (curBlkLinear > trgBlkLinear) { curBlkLinear -= DataBlock[_index].count; _stripPos = trgBlkLinear - curBlkLinear; break; } _index++; } return(DataBlock[_index]); } throw new ArgumentOutOfRangeException( "Coords (" + _coord.x + ", " + _coord.y + ") out of range. Dims (" + Dims.x + ", " + Dims.y + ")", "x, y"); }
public BuffVector2d(IVector2 other) { ITuple2_Double _other = other.AsTupleDouble(); this.x = _other.X; this.y = _other.Y; }
public IVector2 Mul(IVector2 v) { ITuple2_Double _v = v.AsTupleDouble(); return(new Vector2d(this.M00 * _v.X + this.M01 * _v.Y, this.M10 * _v.X + this.M11 * _v.Y)); }
public void activate(TileCluster tc){ IVector2 pos = new IVector2(this.transform.position.x,this.transform.position.y); Map map = GameObject.FindObjectOfType<Map>(); TileCluster t = tc.copy(); t.x += pos.x; t.y += pos.y; map.populateCluster(t); }
// create info objects and link them to the tile void LinkNewObjects(IVector2[] tiles) { for (int t=0; t<tiles.Length; t++) { IVector2 tile = tiles[t]; string description = "tile has frame index "+ts.tiles[tile.x][tile.y]; if (ts.tiles[tile.x][tile.y] == -1) description = "tile is transparent"; ts.objects[tile.x][tile.y] = new TileInfo(tile,description); } }
public void draw(){ Map m = GameObject.FindObjectOfType<Map>(); IVector2 pos = new IVector2(this.transform.position.x,this.transform.position.y); TileCluster t = towerCluster.copy(); for(int x = t.x; x < t.x + t.width; x++){ for(int y = t.y; y < t.y + t.height + 2; y++){ if(Random.value < t.likeliness){ m.setTile(new IVector2(pos.x + x, pos.y + y),(byte)0,(byte)TileSpecList.getTileSpecInt(towerCluster.tileType)); } } } }
protected override void mine(IVector2 v){ byte d = map.getByte (v, Map.DURABILITY); if (mineTime <= 0){ digging = false; TileSpec ts = TileSpecList.getTileSpec(map.getByte(v,Map.FOREGROUND_ID)); map.setTile(v,(byte)spawnedTile,map.getByte(v,Map.BACKGROUND_ID)); eliminate(); } else{ mineTime -= Time.fixedDeltaTime; } }
public Vector2[] GetDigNeighbors(){ List<Vector2> neighbors = new List<Vector2>(); List<Vector2> goodNeighbors = new List<Vector2>(); IVector2 pos = new IVector2(location.x,location.y); neighbors.Add (new IVector2(location.x - 1, location.y)); neighbors.Add (new IVector2(location.x + 1, location.y)); neighbors.Add (new IVector2(location.x, location.y -1)); neighbors.Add (new IVector2(location.x, location.y + 1)); foreach(IVector2 v in neighbors){ byte b = m.getByte(v,Map.FOREGROUND_ID); TileSpec t = TileSpecList.getTileSpec(b); if(t.diggable && t.solid){ goodNeighbors.Add(v); } } return goodNeighbors.ToArray(); }
public Vector2 CursorPosition(IVector2 pos) { if (text == "") return transform.position; Rect r = worldRect; Vector2 p = new Vector2(r.xMin, r.yMin + r.height/2); int px = 0; int tx = 0; for (int i=0; i<sizeChars.Length; i++) { if (i<sizeChars.Length && i<pos.x) px+=(sizeChars[i]); tx+=(sizeChars[i]); } if (tx>0 && px >0) return p + new Vector2((r.width/tx) * px,0); else return transform.position; }
void UpdateTiles() { // determine offset point on tilemap where to retreive the tiles IVector2 tilemapOffset = new IVector2(Mathf.FloorToInt(pHor),Mathf.FloorToInt(pVer)); // determine scolling position tilesprite to get a smooth scrolling effect Vector2 scrollPosition = new Vector2( -((pHor - tilemapOffset.x) * (float)tilesSprite.tileSize.x), (pVer - tilemapOffset.y) * (float)tilesSprite.tileSize.y); // check if offset has changed and we need to refill the sprite if (!tilemapOffset.Equals(lastOffset)) { tilesSprite.FillFromTileMap(tilemap, tilemapOffset, new Rect(1,0,11,11)); lastOffset = tilemapOffset; } // set position of sprite to achieve a smooth scrolling effect tilesSprite.position = scrollPosition; }
public bool ladderable(IVector2 v){ return !isForegroundSolid (v) && getBackground (v) != TileSpecList.getTileSpec (0); }
public byte getRenderContext(IVector2 v){ switch(renderMode){ case NAVMESH: return getByte(v, NAVIGATION_MAP); case BACKGROUND: return getByte(v, BACKGROUND_CONTEXT); default: return getByte(v, FOREGROUND_CONTEXT); } }
public static IVector2[] getDirections(int[] directions){ IVector2[] dirs = new IVector2[directions.Length]; for (int i = 0; i < directions.Length; i++) dirs[i] = directionList[directions[i]]; return dirs; }
void laddercase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ bool s = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); bool f = map.getForeground(currentpos) == TileSpecList.getTileSpec("Ladder"); if(currentpos.x == dest.x){ ladderTile(currentpos); ladderTile(dest); } currentMovement.y = Mathf.Sign(v.y) * moveSpeed; }
void digcase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ handleDigging(dest,v); }
//****************************************************************************// void walkcase(IVector2 currentpos,IVector2 dest,ParentedNode node,Vector2 v){ if((v.y > .25f && Mathf.Abs(v.x) < .1f) || (map.getForeground(currentpos) == TileSpecList.getTileSpec(LADDERINDEX) && canLadder)){ laddercase(currentpos,dest,node,v); return; } currentState = movementState.WALKING; if(v.y > .25f && (Mathf.Abs(v.x) > .1f && cc.velocity.x == 0)){// || (lastPosition - currentpos).magnitude == 0){ Debug.Log("Jumping"); jump (); currentState = movementState.JUMPING; } }
protected override void CheckSettings() { base.CheckSettings (); if (!gridXY.Equals(gridXY_) || !cellXY.Equals(cellXY_) || lineThickness_!=_lineThickness || innerHorizontal!=innerHorizontal_ || innerVertical!=innerVertical_ || outerHorizontal!=outerHorizontal_ || outerVertical!=outerVertical_ ) { if (_gridXY.x<1) _gridXY.x = 1; if (_gridXY.y<1) _gridXY.y = 1; gridXY_ = _gridXY.Clone(); if (_cellXY.x<=0) _cellXY.x = 1f; if (_cellXY.y<1) _cellXY.y = 1; cellXY_ = _cellXY; if (_lineThickness<=0) _lineThickness = 1; lineThickness_ = _lineThickness; innerHorizontal_ = innerHorizontal; innerVertical_ = innerVertical; outerHorizontal_ = outerHorizontal; outerVertical_ = outerVertical; meshDirty = true; } }
public void updateTileSpec(IVector2 v){ if (!inBounds(v)) return; map [v.y,v.x] &= 0x00FF0000FFFF; bool[] b = new bool[directions.Length]; for (int i = 0; i < directions.Length; i++) b[i] = isForegroundSolid(v + Direction.getDirection(directions[i])); setByte(v, FOREGROUND_CONTEXT, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) b[i] = isBackgroundSolid(v + Direction.getDirection(directions[i])); setByte(v, BACKGROUND_CONTEXT, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) b[i] = unnavigable(v + Direction.getDirection(directions[i])); setByte(v, NAVIGATION_MAP, Direction.packByte(directions, b)); for (int i = 0; i < directions.Length; i++) b[i] = ladderable(v + Direction.getDirection(directions[i])); setByte(v, LADDER_MAP, Direction.packByte(directions, b)); }
public TileSpec getRenderBackground(IVector2 v){ switch(renderMode){ case NAVMESH: return TileSpecList.getTileSpec(0); case BACKGROUND: return TileSpecList.getTileSpec(0); default: return getBackground(v); } }
void ladderTile(IVector2 t){ if(!canLadder) return; currentState = movementState.CLIMBING; TileSpec ts = map.getForeground(t); if(!ts.solid && ts != TileSpecList.getTileSpec(LADDERINDEX)){ map.setTile(t,(byte)LADDERINDEX,(byte)1); } }
public TileSpec getRenderForeground(IVector2 v){ switch(renderMode){ case NAVMESH: return (!isForegroundSolid(v) && isForegroundSolid(v + Direction.getDirection(Direction.BOTTOM)))? TileSpecList.getTileSpec(0) : TileSpecList.getTileSpec(1); case BACKGROUND: return TileSpecList.getTileSpec(0); default: return getForeground(v); } }
protected virtual void mine(IVector2 v){ if(!canMine) return; byte d = map.getByte (v, Map.DURABILITY); if (d == 0){ digging = false; TileSpec ts = TileSpecList.getTileSpec(map.getByte(v,Map.FOREGROUND_ID)); InventroyManager.instance.addToInventory(ts.resource); map.setTile(v,0,map.getByte(v,Map.BACKGROUND_ID)); } else{ map.setByte(v, Map.DURABILITY, (byte)(d - 1)); digTimer = digTime; } // This element type should be determined by the element being mined }
public byte getBackgroundRenderContext(IVector2 v){ switch(renderMode){ case NAVMESH: return 0; default: return getByte(v, BACKGROUND_CONTEXT); } }
public void setByte(IVector2 v, byte i, byte data){ if (!inBounds(v)) return; map [v.y, v.x] = (map [v.y, v.x] & ~((ulong)0xFF << (i * 8))) | ((ulong)data << (i * 8)); }
public TileSpec getBackground(IVector2 v){ TileSpec t = TileSpecList.getTileSpec(getByte(v, BACKGROUND_ID)); if (t == null) return TileSpecList.getTileSpec(0); return t; }
private bool inBounds(IVector2 v){ return !((v.x < 0 || v.x >= getWidth()) || (v.y < 0 || v.y >= getHeight())); }
public void setTile(IVector2 v, byte foreground, byte background){ if (!inBounds(v)) return; setByte (v, FOREGROUND_ID, foreground); setByte (v, BACKGROUND_ID, background); TileSpec t = TileSpecList.getTileSpec(foreground); byte d = 1; if (t != null) d = t.durability; setByte (v, DURABILITY, d); for (int x = -1; x <= 1; x++){ for (int y = -1; y <= 1; y++){ IVector2 vi = v + new IVector2(x, y); updateTileSpec(vi); if (inBounds(vi)) makeDirty(vi.x / chunkSize, vi.y / chunkSize); } } }
public bool unnavigable(IVector2 v){ return getForeground(v) != TileSpecList.getTileSpec("Ladder") && (isForegroundSolid(v) || !isForegroundSolid(v + Direction.getDirection(Direction.BOTTOM))); }
// Use this for initialization protected new void Awake() { gridXY_ = gridXY.Clone(); cellXY_ = _cellXY; innerHorizontal_ = innerHorizontal; innerVertical_ = innerVertical; outerHorizontal_ = outerHorizontal; outerVertical_ = outerVertical; lineThickness_ = _lineThickness; base.Awake(); }
public void findPath(Vector2 v){ position = new Vector2(Mathf.RoundToInt(this.transform.position.x),Mathf.RoundToInt(this.transform.position.y)); destination = new IVector2(v.x,v.y); rePath = true; }
public byte getByte(IVector2 v, byte i, byte def){ if (!inBounds(v)) return def; return (byte)(map [v.y, v.x] >> i * 8); }
//Coroutine which calculates the path to the destination. public IEnumerator getPath(){ Vector2 lastDest = position; float waitTime = .1f; reset: while(true){ //This routine happens every second. yield return new WaitForSeconds(waitTime); //If the destination hasn't changed... if(lastDest == destination && !rePath){ pathing = false; waitTime = Mathf.Clamp(waitTime + .01f,.01f,.5f); //...Go back to start of the loop. goto reset; } pathing = true; rePath = false; if(!TileSpecList.getTileSpec(map.getByte(destination,Map.FOREGROUND_ID)).diggable){ lastDest = destination; path = new Route(); goto reset; } waitTime = .1f; Vector2 start = position; Vector2 end = new IVector2(destination.x ,destination.y); //Create a list of leaves List<ParentedNode> leaves = new List<ParentedNode>(); //Create a list of branches (used leaves) List<ParentedNode> branches = new List<ParentedNode>(); //If the character has to dig Route digRoute = new Route(); //Add current position to the leaves leaves.Add (new ParentedNode(null,position,0)); int count = 0; //While there are still leaves, and the destination hasn't changed. while(leaves.Count > 0){ ParentedNode current = getSmallestLeaf(leaves); leaves.Remove(current); branches.Add(current); //If it found the path... if(current.location == end){ //...Create a new route based on that last node. //ParentedNode p = new ParentedNode(current.parent,end,0); Route r = new Route(current); setPath(r); if(r.locations.Count > 0){ lastDest = new IVector2(r.locations[r.locations.Count-1].x,r.locations[r.locations.Count-1].y); } //Break out goto reset; } //Add new leaves, both open neighbors and ones where you dig. addToLeaves(current,current.GetNeighbors(),branches,leaves,start,end,0,ParentedNode.Type.WALK); if(canMine) addToLeaves(current,current.GetDigNeighbors(),branches,leaves,start,end,1,ParentedNode.Type.DIG); if(canLadder) addToLeaves(current,current.GetLadderNeighbors(),branches,leaves,start,end,3,ParentedNode.Type.LADDER); count ++; if(rePath){ goto reset; } //Only do 20 cycles per frame if(count % pathsPerFrame == 0){ yield return new WaitForSeconds(1); if(count > 10000){ destination = lastDest; goto reset; } } } //If it goes through and cant find anything, Debug.Log ("Path not found"); waitTime += .01f; } }