9 public void SetVisible(
int x,
int y)
11 Cell cell =
Fov.map.cells[x, y];
12 if (cell.light > 100 && !
this.isPC)
16 int key = x + y *
Fov.map.Size;
17 if (this.isPC && !cell.outOfBounds)
21 if (
Fov._power < 0.1f)
23 this.lastPoints[key] = 0;
26 float num = this.GetVisDistance(x, y,
Fov.origin.X,
Fov.origin.Y);
27 float num2 =
Fov._power;
28 if (this.limitGradient)
30 num2 *=
Fov.nonGradientMod;
31 if (num >= (
float)
Fov.range)
33 num2 *=
EClass.scene.profile.global.edgeLight;
42 num2 *= (float)(
Fov.range + 1) - num;
54 if (this.isPC && (num2 > 0f || this.GetVisDistance(
Fov.origin.X,
Fov.origin.Y, x, y) < 4f))
60 this.lastPoints[key] = (byte)num2;
64 public void ClearVisible()
66 foreach (KeyValuePair<int, byte> keyValuePair
in this.lastPoints)
68 Cell cell =
Fov.map.GetCell(keyValuePair.Key);
69 byte value = keyValuePair.Value;
73 cell3.lightR -= (ushort)(value * this.r / 2);
75 cell4.lightG -= (ushort)(value * this.g / 2);
77 cell5.lightB -= (ushort)(value * this.b / 2);
83 this.lastPoints.Clear();
87 public List<Point> ListPoints()
89 List<Point> list =
new List<Point>();
90 foreach (KeyValuePair<int, byte> keyValuePair
in this.lastPoints)
92 list.Add(
new Point(keyValuePair.Key));
98 private float GetVisDistance(
int x1,
int y1,
int x2,
int y2)
100 return Mathf.Sqrt((
float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
104 public static float DistanceFloat(
int x1,
int y1,
int x2,
int y2)
106 return Mathf.Sqrt((
float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
110 public static int Distance(
int x1,
int y1,
int x2,
int y2)
112 return (
int)Mathf.Sqrt((
float)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
116 public void Perform(
int _x,
int _z,
int _range,
float power = 1f)
127 this.SetVisible(
Fov.origin.X,
Fov.origin.Y);
128 int num = Fov.origin.X -
Fov.range;
133 int num2 = Fov.origin.Y -
Fov.range;
138 int num3 = Fov.origin.X + Fov.range + 1;
139 if (num3 >=
EClass._map.Size)
143 int num4 = Fov.origin.Y + Fov.range + 1;
144 if (num4 >=
EClass._map.Size)
148 for (
int i = num; i < num3; i++)
150 this.TraceLine(i, num2);
151 this.TraceLine(i, num4 - 1);
153 for (
int j = num2 + 1; j < num4 - 1; j++)
155 this.TraceLine(num, j);
156 this.TraceLine(num3 - 1, j);
160 int max = EClass._map.Size - 1;
161 int x = (Fov.origin.X + 4).ClampMax(max);
162 int y = (Fov.origin.Y + 1).ClampMax(max);
163 int x2 = (Fov.origin.X - 4).ClampMin(0);
164 int y2 = (Fov.origin.Y - 1).ClampMin(0);
165 int x3 = (Fov.origin.X + 1).ClampMax(max);
166 int y3 = (Fov.origin.Y + 4).ClampMax(max);
167 int x4 = (Fov.origin.X - 1).ClampMin(0);
168 int y4 = (Fov.origin.Y - 4).ClampMin(0);
169 this.TraceLine(x, y);
170 this.TraceLine(x, y2);
171 this.TraceLine(x2, y);
172 this.TraceLine(x2, y2);
173 this.TraceLine(x3, y3);
174 this.TraceLine(x3, y4);
175 this.TraceLine(x4, y3);
176 this.TraceLine(x4, y4);
178 foreach (KeyValuePair<int, byte> keyValuePair
in this.lastPoints)
180 Cell cell =
Fov.map.GetCell(keyValuePair.Key);
181 byte value = keyValuePair.Value;
183 cell2.light += value;
185 cell3.lightR += (ushort)(value * this.r / 2);
187 cell4.lightG += (ushort)(value * this.g / 2);
189 cell5.lightB += (ushort)(value * this.b / 2);
190 if (this.isPC && (value > 0 || this.GetVisDistance(
Fov.origin.X,
Fov.origin.Y, (
int)cell.x, (
int)cell.z) < 2f) && !cell.isSeen && (!cell.HasWall ||
EClass._zone.UseFog || cell.room ==
EClass.pc.Cell.room || cell.hasDoor))
192 EClass._map.SetSeen((
int)cell.x, (
int)cell.z,
true,
true);
193 Fov.newPoints.Add(cell);
196 if (this.isPC &&
Fov.newPoints.Count > 0)
203 private void TraceLine(
int x2,
int y2)
205 int value = x2 -
Fov.origin.X;
206 int value2 = y2 -
Fov.origin.Y;
207 int num = Math.Abs(value);
208 int num2 = Math.Abs(value2);
209 int num3 = Math.Sign(value);
210 int num4 = Math.Sign(value2) << 16;
211 int num5 = (Fov.origin.Y << 16) +
Fov.origin.X;
233 Fov.x = (num5 & 65535);
235 int num11 = (int)this.GetVisDistance(
Fov.origin.X,
Fov.origin.Y,
Fov.x,
Fov.y);
236 if (
Fov.range >= 0 && num11 >
Fov.range)
240 this.SetVisible(
Fov.x,
Fov.y);
241 if (
Fov.map.cells[
Fov.x,
Fov.y].blockSight)
249 public static float nonGradientMod;
252 public static List<Cell> newPoints =
new List<Cell>();
255 public static Map map;
261 public static int range;
264 public static float _power;
279 public bool limitGradient;
282 public Dictionary<int, byte> lastPoints =
new Dictionary<int, byte>();
285 private static int x;
288 private static int y;