protected Vector2D ResolvePoint(string vsParam) { string p = vsParam.Trim(); if (p.StartsWith("{") && p.EndsWith("}")) { long id; if (!long.TryParse(p.Substring(1, p.Length - 2).Trim(), out id)) return null; Entity e = World.TheWorld.GetEntity(id); if (e == null) return null; return e.Position; } else if (p.StartsWith("(") && p.EndsWith(")") && p.IndexOf('|') > 0) { int pos = p.IndexOf('|'); string px = p.Substring(1, pos-1).Trim(); string py = p.Substring(pos +1, p.Length - pos - 2).Trim(); Vector2D ret = new Vector2D(); double dx; double dy; if (!double.TryParse(px, out dx)) return null; if (!double.TryParse(py, out dy)) return null; ret.X = dx; ret.Y = dy; return ret; } else return null; }
public Vector2D GetHitpoint(Entity voTarget, bool vbShoot) { double dist = this.Position.VirtualDistanceTo(voTarget.Position); double time = dist / (vbShoot?vShootspeed:this.Speed); Vector2D p = new Vector2D(voTarget.mlSpeed); p.Angle = voTarget.Direction; p.Mult(time); Vector2D target = voTarget.Position.Add(p); return target; }
public static void Main(string[] args) { string sName = "borg"; string sURL = "10.1.1.19"; //string sURL = "test.scubywars.de"; int lPort = 1337; MainClass mc = new MainClass(); mc.moWorld = new World(sName); mc.moWorld.PlayerEntered += mc.PlayerEntered; InpScript oScript = InpScript.TryParse("/home/uditaren/td/src/ScubyNet/testbot.inp"); mc.c = new Connection(sName, sURL, lPort); mc.moWorld.RegisterBot(oScript, mc.c); mc.mcConnections.Add(mc.c.ID, mc.c); for (int i=0;i< 2; i++) { Connection oC = new Connection(sName, sURL, lPort); mc.moWorld.RegisterBot(oScript, oC); mc.mcConnections.Add(oC.ID, oC); new Thread(new ThreadStart(new DummyReader(oC).Read)).Start(); } //new Thread(new ThreadStart(mc.ProcessPackages)).Start(); Vector2D a = new Vector2D(100.0, 100.0); Vector2D b = new Vector2D(800.0, 100.0); Console.WriteLine(a.DistanceTo(b)); Console.WriteLine(b.DistanceTo(a)); Console.WriteLine(a.VirtualDistanceTo(b)); Console.WriteLine(b.VirtualDistanceTo(a)); Console.WriteLine(a.AngleTo(b)); Console.WriteLine(b.AngleTo(a)); //Console.WriteLine (Math.Atan2( 0.0, 1.0 )); //Console.WriteLine (Math.Atan2( 1.0, 1.0 )); //Console.WriteLine (Math.Atan2( 1.0, 0.0 )); //Console.WriteLine (Math.Atan2( 1.0, -1.0 )); //Console.WriteLine (Math.Atan2( 0.0, -1.0 )); //Console.WriteLine (Math.Atan2( -1.0, -1.0 )); //Console.WriteLine (Math.Atan2( -1.0, 0.0 )); //Console.WriteLine (Math.Atan2( -1.0, 1.0 )); }
public double DistanceTo(Vector2D vV) { return this.Add(vV.Inv()).Length; }
public double AngleTo(Vector2D vV) { return this.Add(vV.Inv()).Angle; }
public Vector2D Add(Vector2D vV) { return Add(vV.x, vV.y); }
public double VirtualDistanceTo(Vector2D v1) { double dx = (v1.x < (MAX_X/2.0)) ? MAX_X : -MAX_X; double dy = (v1.y < (MAX_Y/2.0)) ? MAX_Y : -MAX_Y; Vector2D v2 = v1.Add( dx, 0.0); Vector2D v3 = v1.Add(0.0, dy); Vector2D v4 = v1.Add( dx, dy); double dist = DistanceTo(v1) ; dist = Math.Min(dist, DistanceTo(v2)); dist = Math.Min(dist, DistanceTo(v3)); dist = Math.Min(dist, DistanceTo(v4)); return dist; }
public double VirtualAngleTo(Vector2D v1) { double dx = (v1.x < (MAX_X/2.0)) ? MAX_X : -MAX_X; double dy = (v1.y < (MAX_Y/2.0)) ? MAX_Y : -MAX_Y; Vector2D v2 = v1.Add( dx, 0.0); Vector2D v3 = v1.Add(0.0, dy); Vector2D v4 = v1.Add( dx, dy); double angle = AngleTo(v1); double dist = DistanceTo(v1); double dist2 = DistanceTo(v2); if (dist2 < dist) { angle = AngleTo(v2); dist = dist2; } dist2 = DistanceTo(v3); if (dist2 < dist) { angle = AngleTo(v3); dist = dist2; } dist2 = DistanceTo(v4); if (dist2 < dist) { angle = AngleTo(v4); dist = dist2; } return angle; }