Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Los.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4public class Los : EClass
5{
6 public static Point p = new Point();
7
8 public static Point originalP = new Point();
9
10 public static Action<Point, bool> onVisit;
11
12 public static int MAX(int a, int b)
13 {
14 if (a <= b)
15 {
16 return b;
17 }
18 return a;
19 }
20
21 public static int ABS(int a)
22 {
23 if (a >= 0)
24 {
25 return a;
26 }
27 return -a;
28 }
29
30 public static int ZSGN(int a)
31 {
32 if (a >= 0)
33 {
34 if (a <= 0)
35 {
36 return 0;
37 }
38 return 1;
39 }
40 return -1;
41 }
42
43 private static bool IsBlocked(int x, int z, int sx, int sz)
44 {
45 bool flag = false;
46 if (x < 0 || z < 0 || x >= EClass._map.Size || z >= EClass._map.Size)
47 {
48 flag = true;
49 }
50 else
51 {
52 Cell cell = EClass._map.cells[x, z];
53 byte[] weights = EClass._map.cells[x, z].weights;
54 if ((sz == -1 && weights[0] == 0) || (sz == 1 && weights[2] == 0) || (sx == 1 && weights[1] == 0) || (sx == -1 && weights[3] == 0))
55 {
56 flag = true;
57 }
58 if (!flag && sx != 0 && sz != 0)
59 {
60 if (x + sx < 0 || z + sz < 0 || x + sx >= EClass._map.Size || z + sz >= EClass._map.Size)
61 {
62 flag = true;
63 }
64 else
65 {
66 byte[] weights2 = EClass._map.cells[x + sx, z + sz].weights;
67 if ((sz < 0 && weights2[2] == 0) || (sx > 0 && weights2[3] == 0))
68 {
69 flag = true;
70 }
71 if ((sz > 0 && weights2[0] == 0) || (sx < 0 && weights2[1] == 0))
72 {
73 flag = true;
74 }
75 }
76 }
77 if (cell.blockSight)
78 {
79 flag = true;
80 }
81 }
82 p.Set(x, z);
83 if (onVisit != null)
84 {
85 onVisit(p, flag);
86 }
87 return flag;
88 }
89
90 public static List<Point> ListVisible(Point p1, Point p2, int radius, Action<Point, bool> _onVisit = null)
91 {
92 List<Point> list = new List<Point>();
93 List<Point> vecs = new List<Point>();
94 Point lastPoint = p1.Copy();
95 IsVisible(p1.x, p2.x, p1.z, p2.z, delegate(Point p, bool blocked)
96 {
97 Point point3 = new Point(p.x - lastPoint.x, p.z - lastPoint.z);
98 if (point3.x != 0 || point3.z != 0)
99 {
100 vecs.Add(point3);
101 }
102 lastPoint.Set(p);
103 }, returnOnBlock: false);
104 if (vecs.Count == 0)
105 {
106 return list;
107 }
108 Point point = p1.Copy();
109 for (int i = 0; i < radius; i++)
110 {
111 Point point2 = vecs[i % vecs.Count];
112 point.x += point2.x;
113 point.z += point2.z;
114 }
115 IsVisible(p1.x, point.x, p1.z, point.z, delegate(Point p, bool blocked)
116 {
117 if (!blocked)
118 {
119 list.Add(p.Copy());
120 }
121 if (_onVisit != null)
122 {
123 _onVisit(p, blocked);
124 }
125 });
126 return list;
127 }
128
129 public static Point GetNearestNeighbor(Point p1, Point p2)
130 {
131 Point dest = null;
132 IsVisible(p1, p2, delegate(Point p, bool blocked)
133 {
134 if (!blocked && dest == null && p2.Distance(p) == 1 && !p.HasChara)
135 {
136 dest = new Point(p);
137 }
138 });
139 return dest;
140 }
141
142 public static Point GetRushPoint(Point p1, Point dest)
143 {
144 Point rushPos = null;
145 bool valid = true;
146 IsVisible(p1, dest, delegate(Point p, bool blocked)
147 {
148 if (!p.Equals(dest) && !p.Equals(p1))
149 {
150 if (blocked || p.HasChara || p.IsBlocked)
151 {
152 valid = false;
153 }
154 if (p.Distance(dest) == 1)
155 {
156 rushPos = p.Copy();
157 }
158 }
159 });
160 if (!valid)
161 {
162 return null;
163 }
164 return rushPos;
165 }
166
167 public static bool IsVisible(Point p1, Point p2, Action<Point, bool> _onVisit = null)
168 {
169 return IsVisible(p1.x, p2.x, p1.z, p2.z, _onVisit);
170 }
171
172 public static bool IsVisible(Card c1, Card c2)
173 {
174 return IsVisible(c1.pos.x, c2.pos.x, c1.pos.z, c2.pos.z);
175 }
176
177 public static bool IsVisible(int x1, int x2, int z1, int z2, Action<Point, bool> _onVisit = null, bool returnOnBlock = true)
178 {
179 onVisit = _onVisit;
180 p.Set(x1, z1);
181 originalP.Set(x1, z1);
182 int a = x2 - x1;
183 int a2 = z2 - z1;
184 int num = ABS(a) << 1;
185 int num2 = ABS(a2) << 1;
186 int num3 = ZSGN(a);
187 int num4 = ZSGN(a2);
188 int num5 = x1;
189 int num6 = z1;
190 if (num >= num2)
191 {
192 int num7 = num2 - (num >> 1);
193 while (true)
194 {
195 if (num5 == x2)
196 {
197 p.Set(num5, num6);
198 if (onVisit != null)
199 {
200 onVisit(p, arg2: false);
201 }
202 return true;
203 }
204 if (IsBlocked(num5, num6, num3, (num7 >= 0) ? num4 : 0) && returnOnBlock)
205 {
206 break;
207 }
208 if (num7 >= 0)
209 {
210 num6 += num4;
211 num7 -= num;
212 }
213 num5 += num3;
214 num7 += num2;
215 }
216 return false;
217 }
218 if (num2 >= num)
219 {
220 int num8 = num - (num2 >> 1);
221 while (true)
222 {
223 if (num6 == z2)
224 {
225 p.Set(num5, num6);
226 if (onVisit != null)
227 {
228 onVisit(p, arg2: false);
229 }
230 return true;
231 }
232 if (IsBlocked(num5, num6, (num8 >= 0) ? num3 : 0, num4) && returnOnBlock)
233 {
234 break;
235 }
236 if (num8 >= 0)
237 {
238 num5 += num3;
239 num8 -= num2;
240 }
241 num6 += num4;
242 num8 += num;
243 }
244 return false;
245 }
246 return false;
247 }
248}
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
Definition: Card.cs:11
Point pos
Definition: Card.cs:55
Definition: Cell.cs:7
bool blockSight
Definition: Cell.cs:318
Definition: EClass.cs:5
static Map _map
Definition: EClass.cs:18
Definition: Los.cs:5
static int MAX(int a, int b)
Definition: Los.cs:12
static bool IsVisible(int x1, int x2, int z1, int z2, Action< Point, bool > _onVisit=null, bool returnOnBlock=true)
Definition: Los.cs:177
static List< Point > ListVisible(Point p1, Point p2, int radius, Action< Point, bool > _onVisit=null)
Definition: Los.cs:90
static Point p
Definition: Los.cs:6
static bool IsVisible(Card c1, Card c2)
Definition: Los.cs:172
static Point GetNearestNeighbor(Point p1, Point p2)
Definition: Los.cs:129
static bool IsBlocked(int x, int z, int sx, int sz)
Definition: Los.cs:43
static bool IsVisible(Point p1, Point p2, Action< Point, bool > _onVisit=null)
Definition: Los.cs:167
static Point GetRushPoint(Point p1, Point dest)
Definition: Los.cs:142
static int ZSGN(int a)
Definition: Los.cs:30
static Point originalP
Definition: Los.cs:8
static Action< Point, bool > onVisit
Definition: Los.cs:10
static int ABS(int a)
Definition: Los.cs:21
int Size
Definition: MapBounds.cs:20
Cell[,] cells
Definition: Map.cs:85
Definition: Point.cs:9
Point Copy()
Definition: Point.cs:467
Point Set(int _x, int _z)
Definition: Point.cs:479
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:924
int Distance(Point p)
Definition: Point.cs:953
bool HasChara
Definition: Point.cs:226