14 return (this.x + this.maxX) / 2;
24 return (this.z + this.maxZ) / 2;
34 return this.maxX - this.x + 1;
44 return this.maxZ - this.z + 1;
49 public void SetBounds(
int _x,
int _z,
int _maxX,
int _maxZ)
58 public bool Contains(
int dx,
int dz)
60 return dx >= this.x && dz >= this.z && dx <= this.maxX && dz <= this.maxZ;
64 public bool Contains(
Point p)
66 return this.Contains(p.x, p.z);
70 public Point GetCenterPos()
72 return new Point(this.CenterX, this.CenterZ);
76 public Point GetRandomTopPos()
78 return new Point(this.x +
EClass.rnd(
this.maxX -
this.x),
this.maxZ);
82 public Point GetRandomRightPos()
84 return new Point(this.maxX, this.z +
EClass.rnd(
this.maxZ -
this.z));
88 public Point GetRandomBottomPos()
90 return new Point(this.x +
EClass.rnd(
this.maxX -
this.x),
this.z);
94 public Point GetRandomLeftPos()
96 return new Point(this.x, this.z +
EClass.rnd(
this.maxZ -
this.z));
100 public Point GetTopPos(
float rate = -1f)
102 return this.GetSpawnPos(this.x, this.maxZ, this.maxX, this.maxZ);
106 public Point GetRightPos(
float rate = -1f)
108 return this.GetSpawnPos(this.maxX, this.z, this.maxX, this.maxZ);
112 public Point GetBottomPos(
float rate = -1f)
114 return this.GetSpawnPos(this.x, this.z, this.maxX, this.z);
118 public Point GetLeftPos(
float rate = -1f)
120 return this.GetSpawnPos(this.x, this.z, this.x, this.maxZ);
124 public Point GetRandomPoint()
126 return new Point(this.x +
EClass.rnd(
this.Width),
this.z +
EClass.rnd(
this.Height));
130 public Point GetSpawnPos(
int x,
int z,
int maxX,
int maxZ)
133 for (
int i = z; i < maxZ + 1; i++)
135 for (
int j = x; j < maxX + 1; j++)
138 foreach (
Thing thing
in point.Things)
146 else if (thing.dir == 1)
150 else if (thing.dir == 2)
163 return new Point(x + (maxX - x) / 2, z + (maxZ - z) / 2);
167 public bool CanExpand(
int a)
169 return this.x - a >= 1 || this.z - a >= 1 || this.maxX + a < EClass._map.Size - 1 || this.maxZ + a < EClass._map.Size - 1;
173 public void Expand(
int a)
187 if (this.maxX >=
EClass._map.Size - 1)
189 this.maxX = EClass._map.Size - 2;
191 if (this.maxZ >=
EClass._map.Size - 1)
193 this.maxZ = EClass._map.Size - 2;
198 public Point GetSurface(
int x,
int z,
bool walkable =
true)
202 if (!walkable || !point.cell.blocked)
206 return Point.Invalid;
210 public Point GetRandomSurface(
int x,
int z,
int radius,
bool walkable =
true,
bool allowWater =
false)
212 for (
int i = 0; i < radius * radius * 2; i++)
215 if (surface.IsValid && (allowWater || !surface.IsWater))
220 return EClass._map.GetCenterPos();
224 public Point GetRandomSurface(
bool centered =
false,
bool walkable =
true,
bool allowWater =
false)
226 for (
int i = 0; i < 10000; i++)
228 Point surface = this.GetSurface(centered ? (this.CenterX +
EClass.rnd(
this.Width / 4) -
EClass.rnd(
this.Width / 4)) : (
this.x +
EClass.rnd(
this.Width)), centered ? (
this.CenterZ +
EClass.rnd(
this.Height / 4) -
EClass.rnd(
this.Height / 4)) : (
this.z +
EClass.rnd(
this.Height)), walkable);
229 if (surface.IsValid && (allowWater || !surface.IsWater))
234 return this.GetSurface(this.CenterX, this.CenterZ,
false);
238 public Point GetRandomSpawnPos()
240 for (
int i = 0; i < 10000; i++)
243 if (!randomPoint.cell.blocked && randomPoint.cell.room ==
null && randomPoint.cell.light <= 0 && randomPoint.IsValid)
248 return this.GetCenterPos().GetNearestPoint(
false,
true,
true,
false);
252 public Point GetRandomEdge(
int r = 3)
254 for (
int i = 0; i < 10000; i++)
260 num = ((
EClass.rnd(2) == 0) ? (this.x +
EClass.rnd(r)) : (
this.maxX -
EClass.rnd(r)));
261 num2 = this.z +
EClass.rnd(this.Height);
265 num2 = ((
EClass.rnd(2) == 0) ? (this.z +
EClass.rnd(r)) : (
this.maxZ -
EClass.rnd(r)));
266 num = this.x +
EClass.rnd(this.Width);
268 Point surface = this.GetSurface(num, num2,
false);
274 return this.GetSurface(this.Size / 2, this.Size / 2,
false);
278 public Point GetRandomSpace(
int width,
int height,
int tries = 100)
282 for (
int i = 0; i < tries; i++)
285 point2.Set(this.x +
EClass.rnd(
this.maxX -
this.x),
this.z +
EClass.rnd(
this.maxZ -
this.z));
286 for (
int j = 0; j < height; j++)
288 for (
int k = 0; k < width; k++)
290 point.Set(point2.x + k, point2.z + j);
291 if (point.x >
this.maxX || point.z >
this.maxZ || point.IsBlocked || point.cell.HasZoneStairs(
true))
307 Debug.Log(
"valid space not found:" + width.ToString() +
"/" + height.ToString());
312 public void ForeachCell(Action<Cell> action)
315 for (
int i = this.x; i <= this.maxX; i++)
317 for (
int j = this.z; j <= this.maxZ; j++)
325 public void ForeachPoint(Action<Point> action)
328 for (
int i = this.x; i <= this.maxX; i++)
330 for (
int j = this.z; j <= this.maxZ; j++)
332 action(point.Set(i, j));
338 public void ForeachXYZ(Action<int, int> action)
340 for (
int i = this.x; i <= this.maxX; i++)
342 for (
int j = this.z; j <= this.maxZ; j++)