-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEDisasterHelpers.cs
34 lines (32 loc) · 1.7 KB
/
EDisasterHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using ColossalFramework;
using ColossalFramework.Math;
using UnityEngine;
using static EManagersLib.EPropManager;
namespace EManagersLib {
public static class EDisasterHelpers {
public static void DestroyProps(Vector3 position, float totalRadius, float removeRadius) {
const ushort Created = (ushort)(PropInstance.Flags.Created);
const ushort CreatedOrDeleted = (ushort)(PropInstance.Flags.Created | PropInstance.Flags.Deleted);
float radius = EMath.Min(totalRadius, removeRadius);
int startX = EMath.Max((int)((position.x - radius) / PROPGRID_CELL_SIZE + 135f), 0);
int startZ = EMath.Max((int)((position.z - radius) / PROPGRID_CELL_SIZE + 135f), 0);
int endX = EMath.Min((int)((position.x + radius) / PROPGRID_CELL_SIZE + 135f), PROPGRID_RESOLUTION - 1);
int endZ = EMath.Min((int)((position.z + radius) / PROPGRID_CELL_SIZE + 135f), PROPGRID_RESOLUTION - 1);
EPropInstance[] props = m_props.m_buffer;
uint[] propGrid = m_propGrid;
for (int i = startZ; i <= endZ; i++) {
for (int j = startX; j <= endX; j++) {
uint propID = propGrid[i * PROPGRID_RESOLUTION + j];
while (propID != 0) {
if ((props[propID].m_flags & CreatedOrDeleted) == Created) {
if (VectorUtils.LengthXZ(props[propID].Position - position) < radius) {
Singleton<PropManager>.instance.ReleaseProp(propID);
}
}
propID = props[propID].m_nextGridProp;
}
}
}
}
}
}