Esempio n. 1
0
		/*==========================================
		 * is ranged attack from (x0,y0) to (x1,y1) possible?
		 *------------------------------------------*/
		public static bool SearchLongPath(ShootpathData spd, Map m, int x0, int y0, int x1, int y1, ECollisionType cell) {
			int dx, dy;
			int wx = 0, wy = 0;
			int weight;

			if (spd == null)
				spd = new ShootpathData(); // use dummy output variable

			dx = (x1 - x0);
			if (dx < 0) {
				x0 = x0.Swap(ref x1);
				y0 = y0.Swap(ref y1);
				dx = -dx;
			}
			dy = (y1 - y0);

			spd.rx = spd.ry = 0;
			spd.len = 1;
			spd.x[0] = x0;
			spd.y[0] = y0;

			if (m.CheckCell(x1, y1, cell))
				return false;

			if (dx > Math.Abs(dy)) {
				weight = dx;
				spd.ry = 1;
			} else {
				weight = Math.Abs(y1 - y0);
				spd.rx = 1;
			}

			while (x0 != x1 || y0 != y1) {
				if (m.CheckCell(x0, y0, cell))
					return false;
				wx += dx;
				wy += dy;
				if (wx >= weight) {
					wx -= weight;
					x0++;
				}
				if (wy >= weight) {
					wy -= weight;
					y0++;
				} else if (wy < 0) {
					wy += weight;
					y0--;
				}
				if (spd.len < MAX_WALKPATH) {
					spd.x[spd.len] = x0;
					spd.y[spd.len] = y0;
					spd.len++;
				}
			}

			return true;
		}
Esempio n. 2
0
        /*==========================================
         * is ranged attack from (x0,y0) to (x1,y1) possible?
         *------------------------------------------*/
        public static bool SearchLongPath(ShootpathData spd, Map m, int x0, int y0, int x1, int y1, ECollisionType cell)
        {
            int dx, dy;
            int wx = 0, wy = 0;
            int weight;

            if (spd == null)
            {
                spd = new ShootpathData();                 // use dummy output variable
            }
            dx = (x1 - x0);
            if (dx < 0)
            {
                x0 = x0.Swap(ref x1);
                y0 = y0.Swap(ref y1);
                dx = -dx;
            }
            dy = (y1 - y0);

            spd.rx   = spd.ry = 0;
            spd.len  = 1;
            spd.x[0] = x0;
            spd.y[0] = y0;

            if (m.CheckCell(x1, y1, cell))
            {
                return(false);
            }

            if (dx > Math.Abs(dy))
            {
                weight = dx;
                spd.ry = 1;
            }
            else
            {
                weight = Math.Abs(y1 - y0);
                spd.rx = 1;
            }

            while (x0 != x1 || y0 != y1)
            {
                if (m.CheckCell(x0, y0, cell))
                {
                    return(false);
                }
                wx += dx;
                wy += dy;
                if (wx >= weight)
                {
                    wx -= weight;
                    x0++;
                }
                if (wy >= weight)
                {
                    wy -= weight;
                    y0++;
                }
                else if (wy < 0)
                {
                    wy += weight;
                    y0--;
                }
                if (spd.len < MAX_WALKPATH)
                {
                    spd.x[spd.len] = x0;
                    spd.y[spd.len] = y0;
                    spd.len++;
                }
            }

            return(true);
        }