Example #1
0
        public static double DistanceSqrt( IPoint2D from, IPoint2D to )
        {
            float xDelta = Math.Abs( from.X - to.X );
            float yDelta = Math.Abs( from.Y - to.Y );

            return Math.Sqrt( xDelta*xDelta + yDelta*yDelta );
        }
Example #2
0
        public static int Distance( IPoint2D from, IPoint2D to )
        {
            int xDelta = Math.Abs( from.X - to.X );
            int yDelta = Math.Abs( from.Y - to.Y );

            return ( xDelta > yDelta ? xDelta : yDelta );
        }
Example #3
0
 public bool Contains(IPoint2D p)
 {
     foreach (var rect in m_Rects)
     {
         if (rect.Contains(p))
             return true;
     }
     return false;
 }
Example #4
0
 public bool Contains(IPoint2D p)
 {
     foreach (Rectangle2D rect in this.m_Rects)
     {
         if (rect.Contains(p))
             return true;
     }
     return false;
 }
Example #5
0
 public static NestArea Find(IPoint2D p)
 {
     foreach (NestArea area in m_Areas)
     {
         if (area.Contains(p))
             return area;
     }
     return null;
 }
Example #6
0
        /// <summary>
        /// Calculates the distance between two points
        /// </summary>
        /// <param name="origin">the starting point</param>
        /// <param name="target">the ending point</param>
        /// <returns>an integer of the distance between the origin and target</returns>
        public static int DistanceBetween( IPoint2D origin, IPoint2D target )
        {
            if( origin.X == target.X )
                return Math.Abs((origin.Y - target.Y));

            if( origin.Y == target.Y )
                return Math.Abs((origin.Y - target.Y));

            //pythagorean theorem... dist = sqrt of (x2-x1)^2 + (y2-y1)^2
            return (int)Math.Sqrt(Math.Pow(Math.Abs(target.X - origin.X), 2) + Math.Pow(Math.Abs(target.Y - origin.Y), 2));
        }
Example #7
0
		public static BaseBoat FindBoatAt( IPoint2D loc, Map map )
		{
			Sector sector = map.GetSector( loc );

			for ( int i = 0; i < sector.Multis.Count; i++ )
			{
				BaseBoat boat = sector.Multis[i] as BaseBoat;

				if ( boat != null && boat.Contains( loc.X, loc.Y ) )
					return boat;
			}

			return null;
		}
Example #8
0
        private static bool ConsumeJumpStamina( Player pm, IPoint2D start, IPoint2D end )
        {
            double weightRatio = (pm.TotalWeight / pm.MaxWeight);
            int weightInducedLoss = (int)(5 * weightRatio);

            int dist = Util.DistanceBetween(start, end);
            int toConsume = (int)(dist * 5);
            toConsume += weightInducedLoss;

            if( (pm.Stam - toConsume) <= 0 )
                return false;

            pm.Stam -= toConsume;

            return true;
        }
Example #9
0
		public static BaseMulti FindMultiAt(IPoint2D loc, Map map)
		{
			Sector sector = map.GetSector(loc);

			for (int i = 0; i < sector.Multis.Count; i++)
			{
				BaseMulti multi = sector.Multis[i];

				if (multi != null && multi.Contains(loc.X, loc.Y))
				{
					return multi;
				}
			}

			return null;
		}
Example #10
0
		public static bool Contains(IPoint2D p, IPoint2D a, IPoint2D b, IPoint2D c)
		{
			var x = p.X - a.X;
			var y = p.Y - a.Y;

			var delta = (b.X - a.X) * y - (b.Y - a.Y) * x > 0;

			if ((c.X - a.X) * y - (c.Y - a.Y) * x > 0 == delta)
			{
				return false;
			}

			if ((c.X - b.X) * (p.Y - b.Y) - (c.Y - b.Y) * (p.X - b.X) > 0 != delta)
			{
				return false;
			}

			return true;
		}
Example #11
0
		/// <summary>
		///     Gets a Point2D collection representing all locations between 'start' and 'end', including 'start' and 'end'.
		/// </summary>
		public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end)
		{
			return GetLine2D(start, end, null);
		}
Example #12
0
		public Rectangle2D(IPoint2D start, IPoint2D end)
			: this(start.X, start.Y, end.X, end.Y) {
		}
Example #13
0
 public Line2D(IPoint2D start, IPoint2D end)
 {
     m_Start = new Point2D(start);
     m_End   = new Point2D(end);
     Fix();
 }
Example #14
0
 public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p, bool multis)
 {
     return(map.Tiles.GetStaticTiles(p.X, p.Y, multis));
 }
Example #15
0
 public static Point2D Clone2D(this IPoint2D p, IPoint2D t)
 {
     return(new Point2D(p.X + t.X, p.Y + t.Y));
 }
Example #16
0
		public static double GetAngle(this IPoint2D source, IPoint2D target, bool radians = false)
		{
			int x = source.X - target.X;
			int y = source.Y - target.Y;

			double angle = Math.Atan2(y, x) - Math.Atan2(y, x);

			if (!radians)
			{
				angle = Geometry.RadiansToDegrees(angle);
			}

			return angle;
		}
Example #17
0
 public static double GetDistance(this IPoint2D start, IPoint2D end)
 {
     return(Math.Abs(Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2))));
 }
Example #18
0
 public static Point2D Delta2D(this IPoint2D start, int endX, int endY)
 {
     return(new Point2D(start.X - endX, start.Y - endY));
 }
Example #19
0
 public static Point3D ToPoint3D(this IPoint2D p, int z = 0)
 {
     return(new Point3D(p.X, p.Y, z));
 }
Example #20
0
 public static Point2D Delta2D(this IPoint2D start, IPoint2D end)
 {
     return(new Point2D(start.X - end.X, start.Y - end.Y));
 }
Example #21
0
 public static Point2D Lerp2D(this IPoint2D start, int x, int y, double percent)
 {
     return(Clone2D(start, (int)((x - start.X) * percent), (int)((y - start.Y) * percent)));
 }
Example #22
0
 public static Point2D Lerp2D(this IPoint2D start, IPoint2D end, double percent)
 {
     return(Lerp2D(start, end.X, end.Y, percent));
 }
Example #23
0
 public static Point2D Clone2D(this IPoint2D p, int xOffset = 0, int yOffset = 0)
 {
     return(new Point2D(p.X + xOffset, p.Y + yOffset));
 }
Example #24
0
		public static Point2D Rotate2D(this IPoint2D from, IPoint2D to, int count)
		{
			int rx = from.X - to.X, ry = from.Y - to.Y;

			for (int i = 0; i < count; ++i)
			{
				int temp = rx;
				rx = -ry;
				ry = temp;
			}

			return new Point2D(to.X + rx, to.Y + ry);
		}
Example #25
0
		public static double GetDistance(this IPoint2D from, IPoint2D to)
		{
			int x = from.X - to.X;
			int y = from.Y - to.Y;

			return Math.Sqrt((x * x) + (y * y));
		}
Example #26
0
 public static Point3D GetWorldTop(this IPoint2D p, Map map)
 {
     return(GetSurfaceTop(p, map, false));
 }
Example #27
0
 public bool InSquareRange(IPoint2D p, int xyRange)
 {
     return ((((this.m_X >= (p.X - xyRange)) && (this.m_X <= (p.X + xyRange))) && (this.m_Y >= (p.Y - xyRange))) && (this.m_Y <= (p.Y + xyRange)));
 }
Example #28
0
 public static string ToCoordsString(this IPoint2D p, Map map)
 {
     return(ToCoords(p, map).ToString());
 }
Example #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="point2D"></param>
 /// <param name="z"></param>
 public Point3D(IPoint2D point2D, float z)
     : this(point2D.X, point2D.Y, z)
 {
 }
Example #30
0
 public static Coords ToCoords(this IPoint2D p, Map m)
 {
     return(new Coords(m, p));
 }
Example #31
0
 public bool Contains(IPoint2D p)
 {
     return(m_Start <= p && m_End > p);
 }
Example #32
0
 public static int GetAverageZ(this IPoint2D p, Map map, int range)
 {
     return(GetAverageZ(new Rectangle2D(p.X - range, p.Y - range, (range * 2) + 1, (range * 2) + 1), map));
 }
Example #33
0
 public Rectangle2D(IPoint2D start, IPoint2D end)
 {
     m_Start = new Point2D(start);
     m_End   = new Point2D(end);
 }
Example #34
0
        public static void GetAverageZ(this IPoint2D p, Map map, out int cur, out int avg, out int top)
        {
            var land = new
            {
                T = map.Tiles.GetLandTile(p.X, p.Y),
                L = map.Tiles.GetLandTile(p.X, p.Y + 1),
                R = map.Tiles.GetLandTile(p.X + 1, p.Y),
                B = map.Tiles.GetLandTile(p.X + 1, p.Y + 1)
            };

            var surf = new
            {
                T = GetSurfaceTop(p, map, false, false),
                L = GetSurfaceTop(Clone2D(p, 0, 1), map, false, false),
                R = GetSurfaceTop(Clone2D(p, 1), map, false, false),
                B = GetSurfaceTop(Clone2D(p, 1, 1), map, false, false)
            };

            var nT = TileData.LandTable[land.T.ID].Name;
            var nL = TileData.LandTable[land.L.ID].Name;
            var nR = TileData.LandTable[land.R.ID].Name;
            var nB = TileData.LandTable[land.B.ID].Name;

            var zT = (land.T.Ignored || nT == "NoName" || surf.T.Z > Region.MinZ) ? surf.T.Z : land.T.Z;
            var zL = (land.L.Ignored || nL == "NoName" || surf.L.Z > Region.MinZ) ? surf.L.Z : land.L.Z;
            var zR = (land.R.Ignored || nR == "NoName" || surf.R.Z > Region.MinZ) ? surf.R.Z : land.R.Z;
            var zB = (land.B.Ignored || nB == "NoName" || surf.B.Z > Region.MinZ) ? surf.B.Z : land.B.Z;

            cur = zT;

            if (zL > Region.MinZ && zL < cur)
            {
                cur = zL;
            }

            if (zR > Region.MinZ && zR < cur)
            {
                cur = zR;
            }

            if (zB > Region.MinZ && zB < cur)
            {
                cur = zB;
            }

            top = zT;

            if (zL > Region.MinZ && zL > top)
            {
                top = zL;
            }

            if (zR > Region.MinZ && zR > top)
            {
                top = zR;
            }

            if (zB > Region.MinZ && zB > top)
            {
                top = zB;
            }

            if (cur <= Region.MinZ)
            {
                cur = 0;
            }

            if (top <= Region.MinZ)
            {
                top = 0;
            }

            if (zT <= Region.MinZ)
            {
                zT = 0;
            }

            if (zL <= Region.MinZ)
            {
                zL = 0;
            }

            if (zR <= Region.MinZ)
            {
                zR = 0;
            }

            if (zB <= Region.MinZ)
            {
                zB = 0;
            }

            var vL = zL + zR;

            if (vL < 0)
            {
                --vL;
            }

            var vR = zT + zB;

            if (vR < 0)
            {
                --vR;
            }

            avg = Math.Abs(zT - zB) > Math.Abs(zL - zR) ? vL / 2 : vR / 2;
        }
Example #35
0
 public Point3D(IPoint2D p, int z) : this(p.X, p.Y, z)
 {
 }
Example #36
0
 public static MapPoint ToMapPoint(this IPoint2D p, Map m, int z = 0)
 {
     return(new MapPoint(m, p, z));
 }
Example #37
0
		public static Direction GetDirection(this IPoint2D from, IPoint2D to)
		{
			int dx = to.X - from.X, dy = to.Y - from.Y, adx = Math.Abs(dx), ady = Math.Abs(dy);

			if (adx >= ady * 3)
			{
				if (dx > 0)
				{
					return Direction.East;
				}

				return Direction.West;
			}

			if (ady >= adx * 3)
			{
				if (dy > 0)
				{
					return Direction.South;
				}

				return Direction.North;
			}

			if (dx > 0)
			{
				if (dy > 0)
				{
					return Direction.Down;
				}

				return Direction.Right;
			}

			if (dy > 0)
			{
				return Direction.Left;
			}

			return Direction.Up;
		}
Example #38
0
 public static bool IsInHavenIsland(IPoint2D loc)
 {
     return(loc.X >= 3314 && loc.X <= 3814 && loc.Y >= 2345 && loc.Y <= 3095);
 }
Example #39
0
		/// <summary>
		///     Gets a Point2D collection representing all locations between 'start' and 'end', including 'start' and 'end', on the given 'map'.
		/// </summary>
		public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end, Map map)
		{
			var path = new List<Point2D>();

			Geometry.Line2D(ToPoint3D(start), ToPoint3D(end), map, (p, m) => path.Add(ToPoint2D(p)));

			var arr = path.OrderBy(p => GetDistance(start, p)).ToArray();

			path.Clear();
			path.TrimExcess();

			return arr;
		}
Example #40
0
 public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end)
 {
     return(PlotLine2D(start, end).ToArray());
 }
Example #41
0
		public static Point2D Lerp2D(this IPoint2D start, IPoint2D end, double percent)
		{
			return Lerp2D(start, end.X, end.Y, percent);
		}
Example #42
0
		/// <summary>
		/// Returns the angle towards a target spot in degrees, clockwise
		/// </summary>
		/// <param name="tx">target x</param>
		/// <param name="ty">target y</param>
		/// <returns>the angle towards the spot</returns>
		public float GetAngle( IPoint2D point )
		{
			float headingDifference = ( GetHeading( point ) & 0xFFF ) - ( this.Heading & 0xFFF );

			if (headingDifference < 0)
				headingDifference += 4096.0f;

			return (headingDifference * 360.0f / 4096.0f);
		}
Example #43
0
		public static TimeSpan GetTravelTime(this IPoint2D from, IPoint2D to, double speed)
		{
			var d = GetDistance(from, to);
			var s = speed * 1.25;
			var tt = TimeSpan.FromSeconds(d / s);

			//Console.WriteLine("2D Travel Time: {0} / {1} = {2}", d, s, tt.TotalSeconds);

			return tt;
		}
Example #44
0
		public static bool HasLand(this Map map, IPoint2D p)
		{
			return !GetLandTile(map, p).Ignored;
		}
Example #45
0
 public double DistanceSqrt(IPoint2D p)
 {
     int num = this.m_X - p.X;
     int num2 = this.m_Y - p.Y;
     return Math.Sqrt((double) ((num * num) + (num2 * num2)));
 }
Example #46
0
		public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p)
		{
			return map.Tiles.GetStaticTiles(p.X, p.Y);
		}
Example #47
0
 public static NestArea Find(IPoint2D p)
 {
     return(m_Areas.FirstOrDefault(area => area.Contains(p)));
 }
Example #48
0
 public static IEnumerable <Point2D> PlotLine2D(this IPoint2D start, IPoint2D end)
 {
     return(Line2D.Plot(start, end));
 }
Example #49
0
 public static bool InRange(IPoint2D from, IPoint2D to, int range)
 {
     return (from.X >= (to.X - range)) && (from.X <= (to.X + range)) && (from.Y >= (to.Y - range)) && (from.Y <= (to.Y + range));
 }
Example #50
0
 public bool Contains(IPoint2D p)
 {
     return(m_Rects.Any(rect => rect.Contains(p)));
 }
Example #51
0
		public static bool IsInHavenIsland( IPoint2D loc )
		{
			return ( loc.X >= 3314 && loc.X <= 3814 && loc.Y >= 2345 && loc.Y <= 3095 );
		}
Example #52
0
 public bool InRange(IPoint2D p, int range) =>
 p.X >= Location.m_X - range &&
 p.X <= Location.m_X + range &&
 p.Y >= Location.m_Y - range &&
 p.Y <= Location.m_Y + range;
Example #53
0
		public static bool HasWater(this Map map, IPoint2D p)
		{
			return IsWater(GetLandTile(map, p)) || GetStaticTiles(map, p).Any(IsWater);
		}
Example #54
0
 public bool Contains(IPoint2D p)
 {
     return(!IsDisposed && _Points.ContainsKey(GetHashCode(p.X, p.Y)));
 }
Example #55
0
		public static LandTile GetLandTile(this Map map, IPoint2D p)
		{
			return map.Tiles.GetLandTile(p.X, p.Y);
		}
Example #56
0
 public Point2D(IPoint2D p)
     : this(p.X, p.Y)
 {
 }
Example #57
0
		public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p, bool multis)
		{
			return map.Tiles.GetStaticTiles(p.X, p.Y, multis);
		}
Example #58
0
 public static bool RangeCheck(IPoint2D p1, IPoint2D p2, int range)
 {
     return((p1.X >= (p2.X - range)) && (p1.X <= (p2.X + range)) && (p1.Y >= (p2.Y - range)) && (p2.Y <= (p2.Y + range)));
 }
Example #59
0
		public bool InRange( IPoint2D from, int range )
		{
			if ( Region == null )
				return false;

			foreach ( Rectangle3D rect in Region.Area )
			{
				if ( from.X >= rect.Start.X - range && from.Y >= rect.Start.Y - range && from.X < rect.End.X + range && from.Y < rect.End.Y + range )
					return true;
			}

			return false;
		}
Example #60
0
 public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p)
 {
     return(map.Tiles.GetStaticTiles(p.X, p.Y));
 }