Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
POIMap.cs
Go to the documentation of this file.
1using System;
2
3public class POIMap
4{
5 public class Cell
6 {
7 public int x;
8
9 public int z;
10
11 public bool occupied;
12
14 {
15 return new Point(x * cellSize + cellSize / 2, z * cellSize + cellSize / 2).Clamp();
16 }
17 }
18
19 public static int cellSize;
20
21 public static int mapSize;
22
23 public Cell[,] cells;
24
25 public int length => mapSize / cellSize + 1;
26
27 public void Init(int _mapSize, int _cellSize)
28 {
29 cellSize = _cellSize;
30 mapSize = _mapSize;
31 cells = new Cell[length, length];
32 Reset();
33 }
34
35 public void Reset()
36 {
37 for (int i = 0; i < length; i++)
38 {
39 for (int j = 0; j < length; j++)
40 {
41 cells[i, j] = new Cell
42 {
43 x = i,
44 z = j
45 };
46 }
47 }
48 }
49
50 public Point GetCenterOfEmptyCell(int tries = 100)
51 {
52 new Point();
53 for (int i = 0; i < tries; i++)
54 {
55 int num = EClass.rnd(length - 2) + 1;
56 int num2 = EClass.rnd(length - 2) + 1;
57 if (!cells[num, num2].occupied)
58 {
59 return cells[num, num2].GetCenter();
60 }
61 }
62 return Point.Invalid;
63 }
64
65 public Cell GetCenterCell(int radius = 1)
66 {
67 return cells[length / 2 - radius + EClass.rnd(radius * 2), length / 2 - radius + EClass.rnd(radius * 2)];
68 }
69
71 {
72 new Point();
73 for (int i = 0; i < 100; i++)
74 {
75 int num = EClass.rnd(length - 2) + 1;
76 int num2 = EClass.rnd(length - 2) + 1;
77 if (cells[num, num2] == null)
78 {
79 return cells[num, num2];
80 }
81 }
82 return null;
83 }
84
85 public void ForeachCenterOfEmptyCell(Action<Point> action)
86 {
87 for (int i = 1; i < length - 2; i++)
88 {
89 for (int j = 1; j < length - 2; j++)
90 {
91 if (!cells[i, j].occupied)
92 {
93 action(cells[i, j].GetCenter());
94 }
95 }
96 }
97 }
98
99 public void OccyupyPOI(Point p, int radius = 0)
100 {
101 OccyupyPOI(p.x, p.z, radius);
102 }
103
104 public void OccyupyPOI(int _x, int _z, int radius)
105 {
106 int num = _x / cellSize;
107 int num2 = _z / cellSize;
108 cells[num, num2].occupied = true;
109 if (radius <= 0)
110 {
111 return;
112 }
113 for (int i = num - radius; i < num + radius + 1; i++)
114 {
115 if (i < 0 || i >= length)
116 {
117 continue;
118 }
119 for (int j = num2 - radius; j < num2 + radius + 1; j++)
120 {
121 if (j >= 0 && j < length)
122 {
123 cells[i, j].occupied = true;
124 }
125 }
126 }
127 }
128}
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
Point GetCenter()
Definition: POIMap.cs:13
bool occupied
Definition: POIMap.cs:11
int z
Definition: POIMap.cs:9
int x
Definition: POIMap.cs:7
Definition: POIMap.cs:4
Point GetCenterOfEmptyCell(int tries=100)
Definition: POIMap.cs:50
void OccyupyPOI(int _x, int _z, int radius)
Definition: POIMap.cs:104
Cell GetEmptyCell()
Definition: POIMap.cs:70
void ForeachCenterOfEmptyCell(Action< Point > action)
Definition: POIMap.cs:85
Cell GetCenterCell(int radius=1)
Definition: POIMap.cs:65
void Reset()
Definition: POIMap.cs:35
void OccyupyPOI(Point p, int radius=0)
Definition: POIMap.cs:99
Cell[,] cells
Definition: POIMap.cs:23
static int cellSize
Definition: POIMap.cs:19
static int mapSize
Definition: POIMap.cs:21
void Init(int _mapSize, int _cellSize)
Definition: POIMap.cs:27
int length
Definition: POIMap.cs:25
Definition: Point.cs:9
static Point Invalid
Definition: Point.cs:28
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
Point Clamp(bool useBounds=false)
Definition: Point.cs:972