Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Tutorials
Advice to a stable uberEMU
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Roper" data-source="post: 11696" data-attributes="member: 235"><p>Use this pathfinder in uberEmulator, i'll give you the code but you may have to do some of your own tweaks to it.</p><p></p><p>[CODE]</p><p>using System;</p><p>namespace Chop.Game.Rooms</p><p>{</p><p> // CREDITS TO CECER1 FOR MAKING THIS!</p><p> public class IHIPathfinder</p><p> {</p><p> private byte[,] CollisionMap;</p><p> private float[,] Height;</p><p></p><p> public IHIPathfinder()</p><p> {</p><p></p><p> }</p><p></p><p> public void ApplyCollisionMap(byte[,] Map, float[,] Height)</p><p> {</p><p> if (CollisionMap != null)</p><p> lock (CollisionMap)</p><p> {</p><p> CollisionMap = Map;</p><p> this.Height = Height;</p><p> }</p><p> else</p><p> {</p><p> CollisionMap = Map;</p><p> this.Height = Height;</p><p> }</p><p> }</p><p></p><p> public byte[] Path(byte StartX, byte StartY, byte EndX, byte EndY)</p><p> {</p><p> IHIPathfinderValues Values;</p><p> lock (CollisionMap)</p><p> {</p><p> Values = new IHIPathfinderValues(CollisionMap, Height);</p><p></p><p> if (EndX >= CollisionMap.GetLength(0) || EndY >= CollisionMap.GetLength(1) || CollisionMap[EndX, EndY] == 0 || (StartX == EndX && StartY == EndY))</p><p> return new byte[0];</p><p></p><p> #region Init</p><p> if (StartX > CollisionMap.GetUpperBound(0) || StartY > CollisionMap.GetUpperBound(1))</p><p> return new byte[0];</p><p></p><p> Values.LastID++;</p><p> Values.Count++;</p><p> Values.BinaryHeap[Values.Count] = Values.LastID;</p><p> Values.X[Values.LastID] = StartX;</p><p> Values.Y[Values.LastID] = StartY;</p><p> Values.H[Values.LastID] = (ushort)GetH(StartX, StartY, EndX, EndY);</p><p> Values.Parent[Values.LastID] = 0;</p><p> Values.G[Values.LastID] = 0;</p><p> Values.F[Values.LastID] = (ushort)(Values.G[Values.LastID] + Values.H[Values.LastID]);</p><p> #endregion</p><p></p><p></p><p> while (Values.Count != 0)</p><p> {</p><p> Values.Location = Values.BinaryHeap[1];</p><p></p><p> if (Values.X[Values.Location] == EndX && Values.Y[Values.Location] == EndY)</p><p> break;</p><p></p><p> Move(Values);</p><p></p><p> Add(-1, -1, EndX, EndY, Values);</p><p> Add(-1, 1, EndX, EndY, Values);</p><p> Add(1, -1, EndX, EndY, Values);</p><p> Add(1, 1, EndX, EndY, Values);</p><p></p><p> Add(-1, 0, EndX, EndY, Values);</p><p> Add(0, -1, EndX, EndY, Values);</p><p> Add(1, 0, EndX, EndY, Values);</p><p> Add(0, 1, EndX, EndY, Values);</p><p> }</p><p> }</p><p></p><p> if (Values.Count == 0)</p><p> return new byte[0];</p><p></p><p> while (Values.X[Values.Parent[Values.Location]] != StartX || Values.Y[Values.Parent[Values.Location]] != StartY)</p><p> {</p><p> Values.Location = Values.Parent[Values.Location];</p><p> }</p><p></p><p> return new byte[] { Values.X[Values.Location], Values.Y[Values.Location] };</p><p> }</p><p></p><p></p><p></p><p> int GetH(int X, int Y, int EndX, int EndY)</p><p> {</p><p> return (Math.Abs(X + EndX) + Math.Abs(Y + EndY));</p><p> }</p><p></p><p></p><p> private void Add(sbyte iX, sbyte iY, byte EndX, byte EndY, IHIPathfinderValues Values)</p><p> {</p><p> byte X = (byte)(Values.X[Values.Location] + iX);</p><p> byte Y = (byte)(Values.Y[Values.Location] + iY);</p><p> ushort Parent = Values.Location;</p><p></p><p> if (X > CollisionMap.GetUpperBound(0) || Y > CollisionMap.GetUpperBound(1))</p><p> return;</p><p></p><p> if (Values.Tiles[X, Y] == 2)</p><p> return;</p><p> if ((CollisionMap[X, Y] == 0 || (CollisionMap[X, Y] == 2 && (X != EndX || Y != EndY))))</p><p> return;</p><p></p><p> float Z = Values.Z[X, Y];</p><p> float pZ = Values.Z[Values.X[Parent], Values.Y[Parent]];</p><p> if (Z > pZ + 1.2 || Z < pZ - 3.0) // TODO: Max/Min jump height from database</p><p> return;</p><p></p><p> if (Parent > 0)</p><p> {</p><p> if (Values.X[Parent] != X && Values.Y[Parent] != Y)</p><p> {</p><p> if (CollisionMap[X, Values.Y[Parent]] == 0 || CollisionMap[X, Values.Y[Parent]] == 2)</p><p> return;</p><p> if (CollisionMap[Values.X[Parent], Y] == 0 || CollisionMap[Values.X[Parent], Y] == 2)</p><p> return;</p><p> }</p><p> }</p><p></p><p></p><p></p><p> if (Values.Tiles[X, Y] == 1)</p><p> {</p><p> ushort i = 1;</p><p> for (; i <= Values.Count; i++)</p><p> {</p><p> if (Values.X[i] == X && Values.Y[i] == Y)</p><p> break;</p><p> }</p><p></p><p> if (Values.X[i] == EndX || Values.Y[i] == EndY)</p><p> {</p><p> if (10 + Values.G[Parent] < Values.G[i])</p><p> Values.Parent[i] = Parent;</p><p> }</p><p> else</p><p> if (14 + Values.G[Parent] < Values.G[i])</p><p> Values.Parent[i] = Parent;</p><p> return;</p><p> }</p><p></p><p> Values.LastID++;</p><p> Values.Count++;</p><p> Values.BinaryHeap[Values.Count] = Values.LastID;</p><p> Values.X[Values.LastID] = X;</p><p> Values.Y[Values.LastID] = Y;</p><p> Values.H[Values.LastID] = (ushort)GetH(X, Y, EndX, EndY);</p><p> Values.Parent[Values.LastID] = Parent;</p><p></p><p> if (X == Values.X[Parent] || Y == Values.Y[Parent])</p><p> Values.G[Values.LastID] = (ushort)(10 + Values.G[Parent]);</p><p> else</p><p> Values.G[Values.LastID] = (ushort)(14 + Values.G[Parent]);</p><p> Values.F[Values.LastID] = (ushort)(Values.G[Values.LastID] + Values.H[Values.LastID]);</p><p></p><p> ushort Temp;</p><p> for (ushort C = Values.Count; C != 1; C /= 2)</p><p> {</p><p> if (Values.F[Values.BinaryHeap[C]] <= Values.F[Values.BinaryHeap[C / 2]])</p><p> {</p><p> Temp = Values.BinaryHeap[C / 2];</p><p> Values.BinaryHeap[C / 2] = Values.BinaryHeap[C];</p><p> Values.BinaryHeap[C] = Temp;</p><p> }</p><p> else</p><p> break;</p><p> }</p><p> Values.Tiles[X, Y] = 1;</p><p> }</p><p> private static void Move(IHIPathfinderValues Values)</p><p> {</p><p> Values.Tiles[Values.X[Values.BinaryHeap[1]], Values.Y[Values.BinaryHeap[1]]] = 2;</p><p></p><p></p><p></p><p> Values.BinaryHeap[1] = Values.BinaryHeap[Values.Count];</p><p> Values.Count--;</p><p></p><p> ushort Location = 1;</p><p> ushort High;</p><p> while (true)</p><p> {</p><p> High = Location;</p><p> if (2 * High + 1 <= Values.Count)</p><p> {</p><p> if (Values.F[Values.BinaryHeap[High]] >= Values.F[Values.BinaryHeap[2 * High]]) Location = (ushort)(2 * High);</p><p> if (Values.F[Values.BinaryHeap[Location]] >= Values.F[Values.BinaryHeap[2 * High + 1]]) Location = (ushort)(2 * High + 1);</p><p> }</p><p> else if (2 * High <= Values.Count)</p><p> {</p><p> if (Values.F[Values.BinaryHeap[High]] >= Values.F[Values.BinaryHeap[2 * High]]) Location = (ushort)(2 * High);</p><p> }</p><p></p><p> if (High != Location)</p><p> {</p><p> ushort Temp = Values.BinaryHeap[High];</p><p> Values.BinaryHeap[High] = Values.BinaryHeap[Location];</p><p> Values.BinaryHeap[Location] = Temp;</p><p> }</p><p> else</p><p> break;</p><p> }</p><p> }</p><p> }</p><p></p><p> public class IHIPathfinderValues</p><p> {</p><p> public byte[,] Tiles;</p><p> public float[,] Z;</p><p></p><p></p><p> public byte[] X;</p><p> public byte[] Y;</p><p> public ushort[] H;</p><p> public ushort[] G;</p><p> public ushort[] F;</p><p></p><p> public ushort Count;</p><p> public ushort LastID;</p><p></p><p> public ushort[] BinaryHeap;</p><p> public ushort[] Parent;</p><p></p><p> public ushort Location;</p><p></p><p> public IHIPathfinderValues(byte[,] CollisionMap, float[,] Height)</p><p> {</p><p> Tiles = new byte[CollisionMap.GetLength(0), CollisionMap.GetLength(1)];</p><p></p><p> X = new byte[Tiles.Length];</p><p> Y = new byte[X.Length];</p><p> Z = Height;</p><p> H = new ushort[X.Length];</p><p> G = new ushort[X.Length];</p><p> F = new ushort[X.Length];</p><p></p><p> Count = 0;</p><p> LastID = 0;</p><p></p><p> BinaryHeap = new ushort[X.Length];</p><p> Parent = new ushort[X.Length];</p><p></p><p> Location = 0;</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="Roper, post: 11696, member: 235"] Use this pathfinder in uberEmulator, i'll give you the code but you may have to do some of your own tweaks to it. [CODE] using System; namespace Chop.Game.Rooms { // CREDITS TO CECER1 FOR MAKING THIS! public class IHIPathfinder { private byte[,] CollisionMap; private float[,] Height; public IHIPathfinder() { } public void ApplyCollisionMap(byte[,] Map, float[,] Height) { if (CollisionMap != null) lock (CollisionMap) { CollisionMap = Map; this.Height = Height; } else { CollisionMap = Map; this.Height = Height; } } public byte[] Path(byte StartX, byte StartY, byte EndX, byte EndY) { IHIPathfinderValues Values; lock (CollisionMap) { Values = new IHIPathfinderValues(CollisionMap, Height); if (EndX >= CollisionMap.GetLength(0) || EndY >= CollisionMap.GetLength(1) || CollisionMap[EndX, EndY] == 0 || (StartX == EndX && StartY == EndY)) return new byte[0]; #region Init if (StartX > CollisionMap.GetUpperBound(0) || StartY > CollisionMap.GetUpperBound(1)) return new byte[0]; Values.LastID++; Values.Count++; Values.BinaryHeap[Values.Count] = Values.LastID; Values.X[Values.LastID] = StartX; Values.Y[Values.LastID] = StartY; Values.H[Values.LastID] = (ushort)GetH(StartX, StartY, EndX, EndY); Values.Parent[Values.LastID] = 0; Values.G[Values.LastID] = 0; Values.F[Values.LastID] = (ushort)(Values.G[Values.LastID] + Values.H[Values.LastID]); #endregion while (Values.Count != 0) { Values.Location = Values.BinaryHeap[1]; if (Values.X[Values.Location] == EndX && Values.Y[Values.Location] == EndY) break; Move(Values); Add(-1, -1, EndX, EndY, Values); Add(-1, 1, EndX, EndY, Values); Add(1, -1, EndX, EndY, Values); Add(1, 1, EndX, EndY, Values); Add(-1, 0, EndX, EndY, Values); Add(0, -1, EndX, EndY, Values); Add(1, 0, EndX, EndY, Values); Add(0, 1, EndX, EndY, Values); } } if (Values.Count == 0) return new byte[0]; while (Values.X[Values.Parent[Values.Location]] != StartX || Values.Y[Values.Parent[Values.Location]] != StartY) { Values.Location = Values.Parent[Values.Location]; } return new byte[] { Values.X[Values.Location], Values.Y[Values.Location] }; } int GetH(int X, int Y, int EndX, int EndY) { return (Math.Abs(X + EndX) + Math.Abs(Y + EndY)); } private void Add(sbyte iX, sbyte iY, byte EndX, byte EndY, IHIPathfinderValues Values) { byte X = (byte)(Values.X[Values.Location] + iX); byte Y = (byte)(Values.Y[Values.Location] + iY); ushort Parent = Values.Location; if (X > CollisionMap.GetUpperBound(0) || Y > CollisionMap.GetUpperBound(1)) return; if (Values.Tiles[X, Y] == 2) return; if ((CollisionMap[X, Y] == 0 || (CollisionMap[X, Y] == 2 && (X != EndX || Y != EndY)))) return; float Z = Values.Z[X, Y]; float pZ = Values.Z[Values.X[Parent], Values.Y[Parent]]; if (Z > pZ + 1.2 || Z < pZ - 3.0) // TODO: Max/Min jump height from database return; if (Parent > 0) { if (Values.X[Parent] != X && Values.Y[Parent] != Y) { if (CollisionMap[X, Values.Y[Parent]] == 0 || CollisionMap[X, Values.Y[Parent]] == 2) return; if (CollisionMap[Values.X[Parent], Y] == 0 || CollisionMap[Values.X[Parent], Y] == 2) return; } } if (Values.Tiles[X, Y] == 1) { ushort i = 1; for (; i <= Values.Count; i++) { if (Values.X[i] == X && Values.Y[i] == Y) break; } if (Values.X[i] == EndX || Values.Y[i] == EndY) { if (10 + Values.G[Parent] < Values.G[i]) Values.Parent[i] = Parent; } else if (14 + Values.G[Parent] < Values.G[i]) Values.Parent[i] = Parent; return; } Values.LastID++; Values.Count++; Values.BinaryHeap[Values.Count] = Values.LastID; Values.X[Values.LastID] = X; Values.Y[Values.LastID] = Y; Values.H[Values.LastID] = (ushort)GetH(X, Y, EndX, EndY); Values.Parent[Values.LastID] = Parent; if (X == Values.X[Parent] || Y == Values.Y[Parent]) Values.G[Values.LastID] = (ushort)(10 + Values.G[Parent]); else Values.G[Values.LastID] = (ushort)(14 + Values.G[Parent]); Values.F[Values.LastID] = (ushort)(Values.G[Values.LastID] + Values.H[Values.LastID]); ushort Temp; for (ushort C = Values.Count; C != 1; C /= 2) { if (Values.F[Values.BinaryHeap[C]] <= Values.F[Values.BinaryHeap[C / 2]]) { Temp = Values.BinaryHeap[C / 2]; Values.BinaryHeap[C / 2] = Values.BinaryHeap[C]; Values.BinaryHeap[C] = Temp; } else break; } Values.Tiles[X, Y] = 1; } private static void Move(IHIPathfinderValues Values) { Values.Tiles[Values.X[Values.BinaryHeap[1]], Values.Y[Values.BinaryHeap[1]]] = 2; Values.BinaryHeap[1] = Values.BinaryHeap[Values.Count]; Values.Count--; ushort Location = 1; ushort High; while (true) { High = Location; if (2 * High + 1 <= Values.Count) { if (Values.F[Values.BinaryHeap[High]] >= Values.F[Values.BinaryHeap[2 * High]]) Location = (ushort)(2 * High); if (Values.F[Values.BinaryHeap[Location]] >= Values.F[Values.BinaryHeap[2 * High + 1]]) Location = (ushort)(2 * High + 1); } else if (2 * High <= Values.Count) { if (Values.F[Values.BinaryHeap[High]] >= Values.F[Values.BinaryHeap[2 * High]]) Location = (ushort)(2 * High); } if (High != Location) { ushort Temp = Values.BinaryHeap[High]; Values.BinaryHeap[High] = Values.BinaryHeap[Location]; Values.BinaryHeap[Location] = Temp; } else break; } } } public class IHIPathfinderValues { public byte[,] Tiles; public float[,] Z; public byte[] X; public byte[] Y; public ushort[] H; public ushort[] G; public ushort[] F; public ushort Count; public ushort LastID; public ushort[] BinaryHeap; public ushort[] Parent; public ushort Location; public IHIPathfinderValues(byte[,] CollisionMap, float[,] Height) { Tiles = new byte[CollisionMap.GetLength(0), CollisionMap.GetLength(1)]; X = new byte[Tiles.Length]; Y = new byte[X.Length]; Z = Height; H = new ushort[X.Length]; G = new ushort[X.Length]; F = new ushort[X.Length]; Count = 0; LastID = 0; BinaryHeap = new ushort[X.Length]; Parent = new ushort[X.Length]; Location = 0; } } } [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Tutorials
Advice to a stable uberEMU
Top