/* * 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 void Save() { if (!changed) { return; } lock (this) { if (continent == null) { return; } string filename = "PPather\\NPCInfo\\" + continent + "_" + myFaction + ".txt"; try { System.IO.TextWriter s = System.IO.File.CreateText(filename); foreach (string name in NPCs.Keys) { NPC n = NPCs[name]; s.WriteLine(n.ToString()); } s.Close(); } catch (Exception e) { PPather.WriteLine("!Error:Exception writing NPC data: " + e); } changed = false; } }
public void Save() { lock (this) { if (!changed) { return; } if (toonName == null) { return; } string filename = "PPather\\ToonInfo\\" + toonName + ".txt"; try { System.IO.TextWriter s = System.IO.File.CreateText(filename); foreach (string key in dic.Keys) { string val = dic[key]; s.WriteLine(key + "|" + val); } s.Close(); } catch (Exception e) { PPather.WriteLine("!Error:Exception writing toon state data: " + e); } changed = false; } }
public MoveResult move(double howClose) { if (GiveUpIfUnsafe) { if (!pather.IsItSafeAt(Me.Target, Me.Location)) { return(MoveResult.Unsafe); } } if (PathTimeout.IsReady) { MoveAlong = null; } if (MoveAlong == null) { Location from = new Location(Me.Location); mover.Stop(); Path path = world.CreatePath(from, target, (float)howClose, PPather.radar); PathTimeout.Reset(); if (path == null || path.Count() == 0) { PPather.WriteLine("EasyMover: Can not create path . giving up"); mover.MoveRandom(); Thread.Sleep(200); mover.Stop(); return(MoveResult.CantFindPath); } else { //PPather.WriteLine("Save path to " + pathfile); //path.Save(pathfile); MoveAlong = new MoveAlonger(pather, path); } } if (MoveAlong != null) { Location from = new Location(Me.Location); if (MoveAlong.path.Count() == 0 || from.GetDistanceTo(target) < howClose) { //PPather.WriteLine("Move along used up"); MoveAlong = null; mover.Stop(); return(MoveResult.GotThere); } else if (!MoveAlong.MoveAlong()) { MoveAlong = null; // got stuck! if (GiveUpIfStuck) { return(MoveResult.Stuck); } } } return(MoveResult.Moving); }
public static void dumpGObjects(string what) { lock (dumpGObjects_seenObjects) { dumpGObjects_seenObjects.Clear(); form.devTree.Nodes.Clear(); string check = form.dumpUiFilter.Text.ToLower(); try { MethodInfo mi = typeof(GObjectList).GetMethod(what); GObject[] objs = (GObject[])mi.Invoke(null, null); Array.Sort <GObject>(objs, new Comparison <GObject>( delegate(GObject o1, GObject o2) { return(o1.Name.CompareTo(o2.Name)); }) ); foreach (GObject obj in objs) { if (!obj.Name.ToLower().Contains(check)) { continue; } // if (obj == GPlayerSelf.Me) continue; // crashing ... PPather.WriteLine("Dumping: " + obj.Name); TreeNode node = dumpObjectRecursive(obj.Name, obj); form.devTree.Nodes.Add(node); } } catch (Exception e) { string s = e.GetType().FullName + "\n" + e.Message + "\n\n"; if (e.InnerException != null) { s += e.InnerException.GetType().FullName + "\n" + e.InnerException.Message + "\n\n"; } s += e.StackTrace; MessageBox.Show(s); } } }
public void Load() { lock (this) { if (toonName == null) { return; } dic = new Dictionary <string, string>(); // Load from file PPather.WriteLine("Loading toon data..."); try { string filename = "PPather\\ToonInfo\\" + toonName + ".txt"; System.IO.TextReader s = System.IO.File.OpenText(filename); int nr = 0; string line; while ((line = s.ReadLine()) != null) { char[] splitter = { '|' }; string[] st = line.Split(splitter); if (st.Length == 2) { string key = st[0]; string val = st[1]; Set(key, val); nr++; } } PPather.WriteLine("Loaded " + nr + " toon state data"); s.Close(); } catch (Exception) { PPather.WriteLine("!Warning:Failed reading toon state data"); } changed = false; } }
public void Load() { lock (this) { if (continent == null) { return; } NPCs = new Dictionary <string, NPC>(StringComparer.InvariantCultureIgnoreCase); // Load from file try { string filename = "PPather\\NPCInfo\\" + continent + "_" + myFaction + ".txt"; System.IO.TextReader s = System.IO.File.OpenText(filename); int nr = 0; string line; while ((line = s.ReadLine()) != null) { NPC n = new NPC(); if (n.FromString(line)) { if (!NPCs.ContainsKey(n.name)) { NPCs.Add(n.name, n); nr++; } } } PPather.WriteLine("Loaded " + nr + " NPCs"); s.Close(); } catch (Exception) { //PPather.WriteLine("Exception reading NPC data: " + e); PPather.WriteLine("!Warning:Failed to load NPC data"); } changed = false; } }
public void Update() { lock (this) { if (continent == null) { return; } if (NPCs == null) { return; } GUnit[] units = GObjectList.GetUnits(); foreach (GUnit unit in units) { if ((unit.Reaction == GReaction.Friendly || unit.Reaction == GReaction.Neutral) && !unit.IsPlayer && unit.CreatureType != GCreatureType.Critter && unit.CreatureType != GCreatureType.Totem && !PPather.IsPlayerFaction(unit)) { string name = unit.Name; NPC n = null; if (!NPCs.TryGetValue(name, out n)) { n = new NPC(); n.name = name; n.faction = unit.FactionID; n.location = unit.Location; n.reaction = unit.Reaction; PPather.WriteLine("New NPC found: " + name); NPCs.Add(name, n); changed = true; } } } } }
public static void SaveSettings() { PPather.PatherSettings.FormTitle = form.txt_setting_formtitle.Text; PPather.PatherSettings.UseMount = form.cb_setting_usemount.SelectedItem.ToString(); PPather.PatherSettings.MountRange = float.Parse(form.txt_setting_mountrange.Text); PPather.PatherSettings.MaxResurrection = form.chk_setting_maxres.Checked; PPather.PatherSettings.MaxResurrectionAmount = int.Parse(form.txt_setting_maxres.Text); PPather.PatherSettings.StopAtLevel = int.Parse(form.txt_setting_stoplevel.Text); try { PPather.PatherSettings.Save(); PPather.WriteLine("Your settings have been saved"); } catch { PPather.WriteLine("!Error:Couldn't access PPather.xml. Is it open in another program?"); } }
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 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); }