/* * 1 - location is front * 2 - location is right * 3 - location is back * 4 - location is left */ int GetLocationDirection(GLocation loc) { int dir = 0; double b = loc.Bearing; if (b > -PI / 4 && b <= PI / 4) // Front { dir = 1; } if (b > -3 * PI / 4 && b <= -PI / 4) // Left { dir = 4; } if (b <= -3 * PI / 4 || b > 3 * PI / 4) // Back { dir = 3; } if (b > PI / 4 && b <= 3 * PI / 4) // Right { dir = 2; } if (dir == 0) { PPather.WriteLine("Odd, no known direction"); } return(dir); }
public Node(int id, GLocation loc) { this.id = id; Loc = loc; NodeProches = new List <Nodacoter>(); DejaPasser = 0; }
private Point getPoint(Node n, GLocation CurPos) { Point p = new Point(); p.X = (int)Math.Truncate((n.Loc.X - CurPos.X) * 10); p.Y = (int)Math.Truncate((n.Loc.Y - CurPos.Y) * 10); return(p); }
public static double GetDistance3D(GLocation l0, GLocation l1) { double dx = l0.X - l1.X; double dy = l0.Y - l1.Y; double dz = l0.Z - l1.Z; return(Math.Sqrt(dx * dx + dy * dy + dz * dz)); }
public void addNode(GLocation pos, NavMesh w) { Node n = new Node(count, pos); n.NodeProches = new List <Nodacoter>(); Nodes.Add(n); count++; }
public UnitData(GUnit u) { unit = u; guid = u.GUID; movementSpeed = 0.0; oldLocation = u.Location; lastSeen = new GSpellTimer(120 * 1000); lastSeen.Reset(); }
private void checkThreadDistance(int i, GLocation loc) { while (UserBots[i].Objectlist.LocalPlayer.Location.distanceFrom(loc) > 1) { sendconsole("Distance: " + UserBots[i].Objectlist.LocalPlayer.Location.distanceFrom(loc).ToString(), ConsoleLvl.Debug); Thread.Sleep(100); } Thread.CurrentThread.Abort(); }
private void moveBotToLocation(GLocation location) { sendconsole("Bot are moving to location", ConsoleLvl.Medium); follow = false; DelActionToAllBot(new SAction(BotAction.FollowMain)); SAction todo = new SAction(); todo.Action = BotAction.GoToLocation; todo.Priority = runToLocationPriority; todo.Location = location; ActionToAllBot(todo, 3, true); }
public void Update(int dt) // dt is milliseconds { if (dt == 0) { return; } double ds = (double)dt / 1000.0; double d = oldLocation.GetDistanceTo(unit.Location); movementSpeed = d / ds; oldLocation = unit.Location; lastSeen.Reset(); }
// Constructor public MainPage() { InitializeComponent(); /* Adder add = new Adder(); ContentPanel.DataContext = add; */ gPoints = new ObservableCollection<GPoint>(); gLocationSystem = new GLocation(System.Device.Location.GeoPositionAccuracy.High); gLocationSystem.OnNewGPoint += new GLocation.NewGPoint(gLocationSystem_OnNewGPoint); //PointsListBox.ItemsSource = gPoints; }
private int getClosetWp(GLocation loc) { int id = 0; double distance = 99999999; foreach (Node n in nav.Nodes) { if (NavMesh.distance(n, loc) < distance) { id = n.id; distance = NavMesh.distance(n, loc); } } return(id); }
public NavMesh CheckProche(float distancea, float distanceb, GLocation loc) { double disteucl; NavMesh list = new NavMesh(); foreach (Node n in Nodes) { disteucl = (loc.X - n.Loc.X) * (loc.X - n.Loc.X) + (loc.Y - n.Loc.Y) * (loc.Y - n.Loc.Y) + (loc.Z - n.Loc.Z) * (loc.Z - n.Loc.Z); if (Math.Sqrt(disteucl) < distanceb && Math.Sqrt(disteucl) >= distancea) { list.addNode(n); } } return(list); }
public bool FromString(string s) { char[] splitter = { '|' }; string[] sp = s.Split(splitter); if (sp.Length < 4) { return(false); } name = sp[0]; string locs = sp[1]; char[] splitter2 = { ',' }; string[] coords = locs.Split(splitter2); if (coords.Length == 3) { float x = float.Parse(coords[0], PPather.numberFormat); float y = float.Parse(coords[1], PPather.numberFormat); float z = float.Parse(coords[2], PPather.numberFormat); location = new GLocation(x, y, z); } else { return(false); } faction = Int32.Parse(sp[2], PPather.numberFormat); string rs = sp[3]; if (rs == "Friendly") { reaction = GReaction.Friendly; } if (rs == "Hostile") { reaction = GReaction.Hostile; } if (rs == "Neutral") { reaction = GReaction.Neutral; } if (rs == "Unknown") { reaction = GReaction.Unknown; } return(true); }
public float Score(float x, float y, float z) { GLocation l = new GLocation(x, y, z); GLocation me = GContext.Main.Me.Location; if (l.GetDistanceTo(me) > 200.0) { return(0); } float s = 0; foreach (UnitData ud in dic.Values) { GUnit unit = ud.unit; if (!unit.IsPlayer) { int ld = unit.Level - GContext.Main.Me.Level; float distance = 30 + ld; float d = unit.Location.GetDistanceTo(l); if (((GMonster)unit).IsElite) { distance += 10; } if (d < distance) { float n = distance - d; //if(ld < 0) // n /= -ld+2; s += n; } } } //if(s>0) // PPather.WriteLine(" " + l + " score " + s); return(s); }
public void EnjoyFlight() { bool isFlying = true; while (isFlying) { GLocation loc1 = GContext.Main.Me.Location, loc2 = GContext.Main.Me.Location; Thread.Sleep(5000); GContext.Main.Me.Refresh(); Thread.Sleep(1500); loc2 = GContext.Main.Me.Location; // if we aren't moving.. we aren't in flight if (((loc1.X - loc2.X) == 0) && ((loc1.Y - loc2.Y) == 0) && ((loc1.Z - loc2.Z) == 0)) { isFlying = false; } } PPather.WriteLine("Taxi: Taxi should have landed, EnjoyFlight() done!"); }
public Location(GLocation l) { this.x = l.X; this.y = l.Y; this.z = l.Z; }
public static double distance(Node a, GLocation b) { return(Math.Sqrt((a.Loc.X - b.X) * (a.Loc.X - b.X) + (a.Loc.Y - b.Y) * (a.Loc.Y - b.Y) + (a.Loc.Z - b.Z) * (a.Loc.Z - b.Z))); }
private void threadMoveToLoc(int id, GLocation loc) { UserBots[id].deplacement(loc); Thread.CurrentThread.Abort(); }
private void MainThreadLoop(object data) { int id = (int)data; Bot CurrentBot = UserBots[id]; // CurrentBot.BotStart(); while (Thread.CurrentThread.IsAlive) { Thread.Sleep(50); if ((CurrentBot.ID != MainCharacter || SomeSettings.BotMod != BotMode.Classic) && CurrentBot.Objectlist.LocalPlayer.IsAlive) { CurrentBot.refreshInfo(); CurrentBot.refreshList(); SAction AttackM = new SAction(); SAction AttackN = new SAction(); Thread CurrentActionThread; AttackN.Action = BotAction.Attack; AttackN.Priority = AgroPriority; AttackM.Priority = attackMainTargetPriority; AttackM.Action = BotAction.AttackMain; SAction healA = new SAction(); bool AttackNb = false; bool AttackMb = false; bool healAt = false; if (CurrentBot.TargetList.Count != 0) { CurrentBot.ActionList.Add(AttackN); AttackNb = true; } if (CurrentBot.MainTargetList.Count != 0) { CurrentBot.ActionList.Add(AttackM); AttackMb = true; } SAction MaxAction = new SAction(); if (CurrentBot.HealList.Count != 0) { healA.Action = BotAction.Heal; healA.Priority = HealPriority; CurrentBot.ActionList.Add(healA); healAt = true; } CurrentBot.ActionList.Sort(); // bool hasAttackAction; CurrentBot.BreakCurActionB = false; if (CurrentBot.ActionList.Count != 0) { MaxAction = CurrentBot.ActionList[0]; if (MaxAction.Action == BotAction.GoToLocation) { CurrentActionThread = new Thread(delegate() { threadMoveToLoc(id, CurrentBot.ActionList[0].Location); }); GLocation Curloc = CurrentBot.ActionList[0].Location; CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } CurrentBot.ActionList.Remove(MaxAction); } else if (MaxAction.Action == BotAction.FollowMain) { CurrentActionThread = new Thread(delegate() { threadMoveToMain(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } } else if (MaxAction.Action == BotAction.Patrol) { CurrentActionThread = new Thread(delegate() { threadPatrol(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } } else if (MaxAction.Action == BotAction.Attack) { sendconsole("Bot Attacking!", ConsoleLvl.High); CurrentActionThread = new Thread(delegate() { threadAttack(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } } else if (MaxAction.Action == BotAction.AttackMain) { sendconsole("Bot Attacking!", ConsoleLvl.High); CurrentActionThread = new Thread(delegate() { threadAttackMain(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } } else if (MaxAction.Action == BotAction.Heal) { sendconsole("Bot Healing!", ConsoleLvl.High); CurrentActionThread = new Thread(delegate() { threadHeal(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } } else if (MaxAction.Action == BotAction.GotAggro) { sendconsole("Bot Got Aggro!", ConsoleLvl.High); CurrentActionThread = new Thread(delegate() { threadAggro(id); }); CurrentActionThread.Start(); while (CurrentActionThread.IsAlive) { Thread.Sleep(40); } CurrentBot.ActionList.Remove(MaxAction); } if (AttackMb) { CurrentBot.ActionList.Remove(AttackM); } if (AttackNb) { CurrentBot.ActionList.Remove(AttackN); } if (healAt) { CurrentBot.ActionList.Remove(healA); } } } } }
public bool moveTowardsFacing(GPlayerSelf Me, GLocation to, double distance, GLocation facing) { bool moving = false; double d = Me.Location.GetDistanceTo(to); if (d > distance) { int dir = GetLocationDirection(to); if (dir != 0) { moving |= true; } if (dir == 1 || dir == 3 || dir == 0) { StrafeLeft(false); StrafeRight(false); } ; if (dir == 2 || dir == 4 || dir == 0) { Forwards(false); Backwards(false); } ; if (dir == 1) { Forwards(true); } if (dir == 2) { StrafeRight(true); } if (dir == 3) { Backwards(true); } if (dir == 4) { StrafeLeft(true); } //PPather.WriteLine("Move dir: " + dir); } else { //PPather.WriteLine("Move is close"); StrafeLeft(false); StrafeRight(false); Forwards(false); Backwards(false); } double bearing = Me.GetHeadingDelta(facing); if (bearing < -PI / 8) { moving |= true; RotateLeft(true); } else if (bearing > PI / 8) { moving |= true; RotateRight(true); } else { StopRotate(); } return(moving); }
public bool checkStuck() { if (firstStuckCheck) { oldLocation = GContext.Main.Me.Location; predictedDX = 0; predictedDY = 0; firstStuckCheck = false; lastStuckCheck.Reset(); } else { // update predicted location double h; double speed; h = mover.GetMoveHeading(out speed); float dt = (float)-lastStuckCheck.TicksLeft / 1000f; float dx = (float)Math.Cos(h) * (float)speed * dt; float dy = (float)Math.Sin(h) * (float)speed * dt; //PPather.WriteLine("speed: " + speed + " dt: " + dt + " dx: " + dx + " dy : " + dy); predictedDX += dx; predictedDY += dy; lastStuckCheck.Reset(); if (StuckTimeout.IsReady) { // Check stuck GLocation loc = Me.Location; float realDX = loc.X - oldLocation.X; float realDY = loc.Y - oldLocation.Y; //PPather.WriteLine(" dx: " + predictedDX + " dy : " + predictedDY + " Real dx: " + realDX + " dy : " + realDY ); float predictDist = (float)Math.Sqrt(predictedDX * predictedDX + predictedDY * predictedDY); float realDist = (float)Math.Sqrt(realDX * realDX + realDY * realDY); //PPather.WriteLine(" pd " + predictDist + " rd " + realDist); int multiplier = 3; if (GPlayerSelf.Me.IsStealth) { multiplier = 4; } if (predictDist > realDist * multiplier) { // moving a lot slower than predicted // check direction GLocation excpected = new GLocation(loc.X + predictedDX, loc.Y + predictedDY); PPather.WriteLine("I am stuck " + stuckMove); //. Jumping to get free"); if (stuckMove == 0) { mover.Forwards(false); mover.Forwards(true); mover.StrafeLeft(true); //mover.Jump(); //mover.StrafeRight(false); } else if (stuckMove == 1) { mover.Forwards(false); mover.Forwards(true); mover.StrafeLeft(true); //PPather.WriteLine(" strafe left"); //mover.Jump(); //mover.StrafeLeft(false); } else if (stuckMove == 2) { mover.Forwards(false); mover.Forwards(true); mover.StrafeRight(true); //PPather.WriteLine(" strafe left"); //mover.StrafeLeft(true); } else if (stuckMove == 2) { mover.Forwards(false); mover.Forwards(true); mover.StrafeRight(true); //PPather.WriteLine(" strafe left"); //mover.StrafeLeft(true); } stuckMove++; if (stuckMove >= abortSensitivity) { return(true); } } else { stuckMove = 0; } predictedDX = 0; predictedDY = 0; oldLocation = loc; StuckTimeout.Reset(); } } return(false); }
public bool MoveAlong() { double max = 3.0; GLocation loc = GContext.Main.Me.Location; Location isAt = new Location(loc.X, loc.Y, loc.Z); /* * while (isAt.GetDistanceTo(current) < max && next != null) * { * //PPather.WriteLine(current + " - " + next); * path.RemoveFirst(); * if (path.Count() == 0) * { * //PPather.WriteLine("ya"); * //return true; // good in some way * } * else * { * prev = current; * current = path.GetFirst(); * next = path.GetSecond(); * } * } */ bool consume = false; do { bool blocked = false; consume = false; if (next != null) { world.triangleWorld.IsStepBlocked(loc.X, loc.Y, loc.Z, next.X, next.Y, next.Z, PathGraph.toonHeight, PathGraph.toonSize, null); } double d = isAt.GetDistanceTo(current); if ((d < max && !blocked) || d < 1.5) { consume = true; } if (consume) { //PPather.WriteLine("Consume spot " + current + " d " + d + " block " + blocked); path.RemoveFirst(); if (path.Count() == 0) { break; } else { prev = current; current = path.GetFirst(); next = path.GetSecond(); } } } while (consume); { //PPather.WriteLine("Move towards " + current); GLocation gto = new GLocation((float)current.X, (float)current.Y, (float)current.Z); GLocation face; if (next != null) { face = new GLocation(next.X, next.Y, next.Z); } else { face = gto; } if (!mover.moveTowardsFacing(Me, gto, 0.5, face)) { PPather.WriteLine("Can't move " + current); world.BlacklistStep(prev, current); //world.MarkStuckAt(loc, Me.Heading); mover.MoveRandom(); Thread.Sleep(500); mover.Stop(); return(false); // hmm, mover does not want to move, must be up or down } { double h; double speed; h = mover.GetMoveHeading(out speed); float stand_z = 0.0f; int flags = 0; float x = isAt.X + (float)Math.Cos(h) * 1.0f; float y = isAt.Y + (float)Math.Sin(h) * 1.0f; float z = isAt.Z; bool aheadOk = world.triangleWorld.FindStandableAt(x, y, z - 4, z + 6, out stand_z, out flags, 0, 0); if (!aheadOk) { blockCount++; PPather.WriteLine("Heading into a wall or off a cliff " + blockCount); world.MarkStuckAt(isAt, (float)Me.Heading); if (prev != null) { GLocation gprev = new GLocation((float)prev.X, (float)prev.Y, (float)prev.Z); if (!mover.moveTowardsFacing(Me, gprev, 0.5, face)) { mover.Stop(); return(false); } } if (blockCount > 1) { world.BlacklistStep(prev, current); return(false); } return(true); } else { blockCount = 0; } } if (sd.checkStuck()) { PPather.WriteLine("Stuck at " + isAt); world.MarkStuckAt(isAt, (float)Me.Heading); world.BlacklistStep(prev, current); mover.Stop(); return(false); } } return(true); }
public bool moveTowardsFacing(GPlayerSelf Me, GLocation to, double distance, GLocation facing) { bool moving = false; double d = Me.Location.GetDistanceTo(to); if (d > distance) { int dir = GetLocationDirection(to); if (dir != 0) moving |= true; if (dir == 1 || dir == 3 || dir == 0) { StrafeLeft(false); StrafeRight(false); }; if (dir == 2 || dir == 4 || dir == 0) { Forwards(false); Backwards(false); }; if (dir == 1) Forwards(true); if (dir == 2) StrafeRight(true); if (dir == 3) Backwards(true); if (dir == 4) StrafeLeft(true); } else { StrafeLeft(false); StrafeRight(false); Forwards(false); Backwards(false); } double bearing = Me.GetHeadingDelta(facing); if (bearing < -PI / 8) { moving |= true; RotateLeft(true); } else if (bearing > PI / 8) { moving |= true; RotateRight(true); } else StopRotate(); return moving; }
/* 1 - location is front 2 - location is right 3 - location is back 4 - location is left */ int GetLocationDirection(GLocation loc) { int dir = 0; double b = loc.Bearing; if (b > -PI / 4 && b <= PI / 4) // Front { dir = 1; } if (b > -3 * PI / 4 && b <= -PI / 4) // Left { dir = 4; } if (b <= -3 * PI / 4 || b > 3 * PI / 4) // Back { dir = 3; } if (b > PI / 4 && b <= 3 * PI / 4) // Right { dir = 2; } if (dir == 0) Context.Log("Odd, no known direction"); return dir; }
public bool checkStuck() { if (StuckTimeout.IsReady) { if (oldLocation != null) { if (mover.IsMoving()) { float d = Me.GetDistanceTo(oldLocation); if (d < 0.5) { stuck++; } else stuck = 0; if (stuck > stuckSensitivity) { // Jump a bit to get loose... int dir = random.Next(3); if (dir == 0) mover.StrafeRight(true); if (dir == 1) mover.StrafeLeft(true); if (random.Next(3) == 0) mover.Backwards(true); else mover.Forwards(true); Context.Log("I am stuck. Jumping to get free"); mover.Jump(); mover.StrafeLeft(false); mover.StrafeRight(false); mover.Forwards(false); // just to sync the keys mover.Backwards(false); } if (stuck > abortSensitivity) { return true; } } if (mover.IsRotating()) { double diff = Math.Abs(oldHeading - Me.Heading); if (diff < PI / 16) { //mlog("Rotate futility. resync keys"); if (mover.IsRotatingLeft()) { mover.RotateLeft(false); mover.RotateLeft(true); } if (mover.IsRotatingRight()) { mover.RotateRight(false); mover.RotateRight(true); } } } } oldLocation = Me.Location; oldHeading = Me.Heading; StuckTimeout.Reset(); } return false; }
public bool deplacement(GLocation Location) { return(move.MoveToLocation(Location)); }
public SAction(BotAction ba, int p, GLocation g) { Action = ba; Priority = p; Location = g; }