public override Direction[] Find(Mobile m, Map map, Point3D start, Point3D goal) { int z = start.Z; int dBase = 0; Point3D pos = new Point3D(start); List <Direction> path = new List <Direction>(); //Console.WriteLine("StupidPathing from {0} to {1}", start, goal); for (int step = 0; step < 3; step++) { bool ok = false; int t, i, d = 0; if ((step % 2) == 0) { dBase = GetDirection(pos, goal); } t = Utility.Random(tries.Length); for (i = 0; i < tries[t].Length; i++) { d = (dBase + tries[t][i]) % 8; z = pos.Z; ok = CalcMoves.CheckMovement(m, map, pos, (Direction)d, out z); if (ok) { break; } } if (!ok) { break; } //Console.WriteLine("Direction {0} at Try[{1}][{2}] worked.", d, t, i); if (path.Count == 0) { path.Add((Direction)dBase); // always make the first rule to try and go in the proper direction } path.Add((Direction)d); Offset(d, ref pos); dBase = d; pos.Z = z; } //Console.WriteLine("Done pathing, got {0} steps.", path.Count); if (path.Count == 0) { return(null); } else { return(path.ToArray()); } }
public int GetSuccessors(int p, Mobile m, Map map) { int px = p % AreaSize; int py = (p / AreaSize) % AreaSize; int pz = m_Nodes[p].z; int x, y, z; Point3D p3D = new Point3D(px + m_xOffset, py + m_yOffset, pz); int[] vals = m_Successors; int count = 0; for (int i = 0; i < 8; ++i) { switch (i) { default: case 0: x = 0; y = -1; break; case 1: x = 1; y = -1; break; case 2: x = 1; y = 0; break; case 3: x = 1; y = 1; break; case 4: x = 0; y = 1; break; case 5: x = -1; y = 1; break; case 6: x = -1; y = 0; break; case 7: x = -1; y = -1; break; } x += px; y += py; if (x < 0 || x >= AreaSize || y < 0 || y >= AreaSize) { continue; } if (CalcMoves.CheckMovement(m, map, p3D, (Direction)i, out z)) { if (MoveImpl.CheckNoItemMob(map, m, x + m_xOffset, y + m_yOffset, z)) { int idx = GetIndex(x + m_xOffset, y + m_yOffset, z); if (idx >= 0 && idx < NodeCount) { m_Nodes[idx].z = z; vals[count++] = idx; } } } } return(count); }
public void RunAround(Mobile enemy) { ArrayList Directions = new ArrayList(); int z; try { //make list of all non blocked adjacent tiles from our position for (int i = 0; i < 8; ++i) { if (CalcMoves.CheckMovement(m_Mobile, m_Mobile.Map, m_Mobile.Location, (Direction)i, out z)) { Directions.Add(i); } } //filter list and make sure none of those tiles have enemys adjacent to them //if a enemy is adjacent remove it from list of tiles not blocked. if (Directions != null) { for (int j = 0; j < Directions.Count; j++) { int TileX = m_Mobile.X; int TileY = m_Mobile.Y; int Dir = (int)Directions[j]; Direction d = (Direction)Dir; //caculate are X/Y corridnate based on direction offset Offset(d, ref TileX, ref TileY); if (IsAdjacentToEnemy(TileX, TileY, enemy.X, enemy.Y)) { Directions.RemoveAt(j); } } Directions.TrimToSize(); if (Directions.Count > 0) { int Dir2 = (int)Directions[Utility.Random(Directions.Count)]; Run((Direction)Dir2 & Direction.Mask); } } } catch (Exception exc) { LogHelper.LogException(exc); System.Console.WriteLine("catch I: Send to Zen please: "); System.Console.WriteLine("Exception caught in HumanMageAI.RunAround: " + exc.Message); System.Console.WriteLine(exc.StackTrace); } }
public void Advance(ref Point3D p, int index) { if (m_Path?.Success == true) { var dirs = m_Path.Directions; if (index >= 0 && index < dirs.Length) { int x = p.X, y = p.Y; CalcMoves.Offset(dirs[index], ref x, ref y); p.X = x; p.Y = y; } } }
public void Advance(ref Point3D p, int index) { if (this.m_Path != null && this.m_Path.Success) { Direction[] dirs = this.m_Path.Directions; if (index >= 0 && index < dirs.Length) { int x = p.X, y = p.Y; CalcMoves.Offset(dirs[index], ref x, ref y); p.X = x; p.Y = y; } } }
public override Direction[] Find(Mobile m, Map map, Point3D start, Point3D goal) { m_Goal = goal; BaseCreature bc = m as BaseCreature; PathNode curNode; PathNode goalNode = new PathNode(); goalNode.x = goal.X; goalNode.y = goal.Y; goalNode.z = goal.Z; PathNode startNode = new PathNode(); startNode.x = start.X; startNode.y = start.Y; startNode.z = start.Z; startNode.h = Heuristic(startNode.x, startNode.y, startNode.z); PathNode[] closed = m_Closed, open = m_Open, successors = m_Successors; Direction[] path = m_Path; int closedCount = 0, openCount = 0, sucCount = 0, pathCount = 0; int popIndex, curF; int x, y, z; int depth = 0; int xBacktrack, yBacktrack, zBacktrack, iBacktrack = 0; open[openCount++] = startNode; while (openCount > 0) { curNode = open[0]; curF = curNode.g + curNode.h; popIndex = 0; for (int i = 1; i < openCount; ++i) { if ((open[i].g + open[i].h) < curF) { curNode = open[i]; curF = curNode.g + curNode.h; popIndex = i; } } if (curNode.x == goalNode.x && curNode.y == goalNode.y && Math.Abs(curNode.z - goalNode.z) < 16) { if (closedCount == MaxNodes) { break; } closed[closedCount++] = curNode; xBacktrack = curNode.px; yBacktrack = curNode.py; zBacktrack = curNode.pz; if (pathCount == MaxNodes) { break; } path[pathCount++] = (Direction)curNode.dir; while (xBacktrack != startNode.x || yBacktrack != startNode.y || zBacktrack != startNode.z) { bool found = false; for (int j = 0; !found && j < closedCount; ++j) { if (closed[j].x == xBacktrack && closed[j].y == yBacktrack && closed[j].z == zBacktrack) { if (pathCount == MaxNodes) { break; } curNode = closed[j]; path[pathCount++] = (Direction)curNode.dir; xBacktrack = curNode.px; yBacktrack = curNode.py; zBacktrack = curNode.pz; found = true; } } if (!found) { Console.WriteLine("bugaboo.."); return(null); } if (pathCount == MaxNodes) { break; } } if (pathCount == MaxNodes) { break; } Direction[] dirs = new Direction[pathCount]; while (pathCount > 0) { dirs[iBacktrack++] = path[--pathCount]; } return(dirs); } --openCount; for (int i = popIndex; i < openCount; ++i) { open[i] = open[i + 1]; } sucCount = 0; if (bc != null) { MoveImpl.AlwaysIgnoreDoors = bc.CanOpenDoors; MoveImpl.IgnoreMovableImpassables = bc.CanMoveOverObstacles; } for (int i = 0; i < 8; ++i) { switch (i) { default: case 0: x = 0; y = -1; break; case 1: x = 1; y = -1; break; case 2: x = 1; y = 0; break; case 3: x = 1; y = 1; break; case 4: x = 0; y = 1; break; case 5: x = -1; y = 1; break; case 6: x = -1; y = 0; break; case 7: x = -1; y = -1; break; } if (CalcMoves.CheckMovement(m, map, new Point3D(curNode.x, curNode.y, curNode.z), (Direction)i, out z)) { successors[sucCount].x = x + curNode.x; successors[sucCount].y = y + curNode.y; successors[sucCount++].z = z; } } MoveImpl.AlwaysIgnoreDoors = false; MoveImpl.IgnoreMovableImpassables = false; if (sucCount == 0 || ++depth > MaxDepth) { break; } for (int i = 0; i < sucCount; ++i) { x = successors[i].x; y = successors[i].y; z = successors[i].z; successors[i].g = curNode.g + 1; int openIndex = -1, closedIndex = -1; for (int j = 0; openIndex == -1 && j < openCount; ++j) { if (open[j].x == x && open[j].y == y && open[j].z == z) { openIndex = j; } } if (openIndex >= 0 && open[openIndex].g < successors[i].g) { continue; } for (int j = 0; closedIndex == -1 && j < closedCount; ++j) { if (closed[j].x == x && closed[j].y == y && closed[j].z == z) { closedIndex = j; } } if (closedIndex >= 0 && closed[closedIndex].g < successors[i].g) { continue; } if (openIndex >= 0) { --openCount; for (int j = openIndex; j < openCount; ++j) { open[j] = open[j + 1]; } } if (closedIndex >= 0) { --closedCount; for (int j = closedIndex; j < closedCount; ++j) { closed[j] = closed[j + 1]; } } successors[i].px = curNode.x; successors[i].py = curNode.y; successors[i].pz = curNode.z; successors[i].dir = (int)GetDirection(curNode.x, curNode.y, x, y); successors[i].h = Heuristic(x, y, z); if (openCount == MaxNodes) { break; } open[openCount++] = successors[i]; } if (openCount == MaxNodes || closedCount == MaxNodes) { break; } closed[closedCount++] = curNode; } return(null); }
public int GetSuccessors(int p, Mobile m, Map map) { var px = p % AreaSize; var py = p / AreaSize % AreaSize; var pz = m_Nodes[p].z; var p3D = new Point3D(px + m_xOffset, py + m_yOffset, pz); var vals = m_Successors; var count = 0; for (var i = 0; i < 8; ++i) { int x; int y; switch (i) { default: case 0: x = 0; y = -1; break; case 1: x = 1; y = -1; break; case 2: x = 1; y = 0; break; case 3: x = 1; y = 1; break; case 4: x = 0; y = 1; break; case 5: x = -1; y = 1; break; case 6: x = -1; y = 0; break; case 7: x = -1; y = -1; break; } x += px; y += py; if (x < 0 || x >= AreaSize || y < 0 || y >= AreaSize) { continue; } if (CalcMoves.CheckMovement(m, map, p3D, (Direction)i, out var z)) { var idx = GetIndex(x + m_xOffset, y + m_yOffset, z); if (idx >= 0 && idx < NodeCount) { m_Nodes[idx].z = z; vals[count++] = idx; } } } return(count); }