DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CfgPlayerRestrictedAreaHandler.c
См. документацию.
2{
3 private static bool m_Initialized;
4
7
8 //----------------------------------------------------------
9 //load, inits, validation
10
11 static bool LoadData()
12 {
13 if (m_Initialized)
14 return true;
15
16 m_Initialized = false;
17
18 if (GetGame().ServerConfigGetInt( "enableCfgGameplayFile" )) //only reach into the CfgGameplayHandler if properly loaded!
20 else
21 m_PRAFiles = g_Game.GetMission().GetWorldData().GetDefaultPRAPaths();
22
23 if (!m_PRAFiles)
24 return true;
25
26 string worldName;
27 GetGame().GetWorldName(worldName);
28
29 foreach (string filename : m_PRAFiles)
30 {
32
33 string errorMessage, path;
34
35 path = string.Format("$mission:%1", filename);
36 if (!JsonFileLoader<PlayerRestrictedAreaInstance>.LoadFile(path, area, errorMessage))
37 {
38 if (!FileExist(filename))
39 path = string.Format("dz/worlds/%1/ce/%2", worldName, filename);
40
41 if (!JsonFileLoader<PlayerRestrictedAreaInstance>.LoadFile(path, area, errorMessage))
42 {
43 ErrorEx(errorMessage);
44 continue;
45 }
46 }
47
48 if (area != null)
49 m_Data.m_Areas.Insert(area);
50 }
51
52 m_Initialized = m_Data.InitializeAreas();
53
54 return true;
55 }
56
57 static bool IsInitialized()
58 {
59 return m_Initialized;
60 }
61
62 //----------------------------------------------------------
63 //synchronization
64
65 static void SyncDataSend(notnull PlayerIdentity identity)
66 {
67 GetGame().RPCSingleParam(null, ERPCs.RPC_PLAYERRESTRICTEDAREAS_SYNC, new Param1<CfgPlayerRestrictedAreaJsonData>(m_Data), true, identity);
68 }
69
70 static void OnRPC(ParamsReadContext ctx)
71 {
72 Param1<CfgPlayerRestrictedAreaJsonData> data = new Param1<CfgPlayerRestrictedAreaJsonData>(null);
73
74 if (ctx.Read(data))
75 {
76 m_Data = data.param1;
77 m_Initialized = m_Data.m_ValidatedAreas.Count() > 0;
78 }
79 else
80 {
81 ErrorEx("CfgPlayerRestrictedAreaHandler - client failed to read incoming data");
82 }
83 }
84
85 //----------------------------------------------------------
86 //main area checking methods
87
89 {
90 if (!IsInitialized())
91 return false;
92
94 if (area && IsCylinderInAreaBox(area,point) || IsPointInAreaPolygon(area,point))
95 {
96 hitArea = area;
97 return true;
98 }
99 return false;
100 }
101
103 {
104 if (!IsInitialized())
105 return false;
106
107 foreach (PlayerRestrictedAreaInstance area : m_Data.m_ValidatedAreas)
108 {
109 if (IsCylinderInAreaBox(area,point) || IsPointInAreaPolygon(area,point))
110 {
111 hitArea = area;
112 return true;
113 }
114 }
115
116 return false;
117 }
118
119 //----------------------------------------------------------
120 //support methods
121
123 {
125 float closestDist = float.MAX;
126 float currentDist;
127
128 foreach (PlayerRestrictedAreaInstance area : m_Data.m_ValidatedAreas)
129 {
130 currentDist = vector.DistanceSq(point,area.GetCenterPos2D());
131 if (currentDist < closestDist)
132 {
133 ret = area;
134 closestDist = currentDist;
135 }
136 }
137
138 return ret;
139 }
140
142 private static bool IsCylinderInAreaBox(notnull PlayerRestrictedAreaInstance area, vector point, float cylinderRadius = 0.25, float cylinderHeight = 1)
143 {
144 foreach (PRAShapeBoxData boxData : area.m_PRABoxDataTranslated)
145 {
146 vector matPlayer4[4];
147 Math3D.MatrixIdentity4(matPlayer4);
148 matPlayer4[3] = point;
149 if (Math3D.IntersectCylinderOBB(boxData.m_Mins,boxData.m_Maxs,boxData.m_Mat4,matPlayer4,cylinderRadius,cylinderHeight))
150 return true;
151 }
152
153 return false;
154 }
155
156 private static bool IsPointInAreaPolygon(notnull PlayerRestrictedAreaInstance area, vector point)
157 {
158 array<float> translatedDta = new array<float>;
159 foreach (array<ref array<float>> polygonData : area.PRAPolygons)
160 {
161 translatedDta.Clear();
162
163 foreach (array<float> vertexPos : polygonData)
164 {
165 translatedDta.Insert(vertexPos[0]);
166 translatedDta.Insert(vertexPos[1]);
167 }
168
169 if (Math2D.IsPointInPolygon(translatedDta,point[0],point[2]))
170 return true;
171 }
172
173 return false;
174 }
175
176 //----------------------------------------------------------
177 //debugs
178
179 static private ref array<Shape> m_DbgShapesBoxes;
181
182 static void DrawBoxesDebug(bool draw)
183 {
184 if (!IsInitialized())
185 return;
186
187 if (!m_DbgShapesBoxes)
188 m_DbgShapesBoxes = {};
189
190 if (draw && m_DbgShapesBoxes.Count() == 0)
191 {
192 foreach (PlayerRestrictedAreaInstance area : m_Data.m_ValidatedAreas)
193 {
194 foreach (PRAShapeBoxData boxData : area.m_PRABoxDataTranslated)
195 {
196 Shape shp = Debug.DrawBox(boxData.m_Mins,boxData.m_Maxs);
197 shp.SetMatrix(boxData.m_Mat4);
198 m_DbgShapesBoxes.Insert(shp);
199 }
200 }
201 }
202 else if (!draw && m_DbgShapesBoxes.Count() > 0)
203 {
204 foreach (Shape box : m_DbgShapesBoxes)
205 {
206 box.Destroy();
207 }
208
209 m_DbgShapesBoxes.Clear();
210 }
211 }
212
213 static void DrawPolygonLinesDebug(bool draw)
214 {
215 if (!IsInitialized())
216 return;
217
220
221 if (draw && m_DbgShapesPolygonLines.Count() == 0)
222 {
223 array<vector> polygonVectors = {};
224 foreach (PlayerRestrictedAreaInstance area : m_Data.m_ValidatedAreas)
225 {
226 foreach (array<ref array<float>> polygonData : area.PRAPolygons)
227 {
228 vector first;
229 vector current;
230 vector last;
231
232 foreach (array<float> vertexPos : polygonData)
233 {
234 polygonVectors.Insert(Vector(vertexPos[0],GetGame().SurfaceY(vertexPos[0],vertexPos[1]) + 2,vertexPos[1]));
235 }
236
237 int count = polygonVectors.Count();
238 for (int i = 0; i < count; ++i)
239 {
240 current = polygonVectors[i];
241
242 if (i == 0)
243 first = polygonVectors[i];
244 else
245 Debug.DrawLine(last,current,COLOR_WHITE,ShapeFlags.TRANSP|ShapeFlags.NOZWRITE);
246
247 last = current;
248 }
249
250 m_DbgShapesPolygonLines.Insert(Debug.DrawLine(current,first,COLOR_RED,ShapeFlags.TRANSP|ShapeFlags.NOZWRITE));
251
252 polygonVectors.Clear();
253 }
254 }
255 }
256 else if (!draw && m_DbgShapesPolygonLines.Count() > 0)
257 {
258 foreach (Shape item : m_DbgShapesPolygonLines)
259 {
260 item.Destroy();
261 }
262
264 }
265 }
266}
DayZGame g_Game
Определения DayZGame.c:3868
ERPCs
Определения ERPCs.c:2
string path
Определения OptionSelectorMultistate.c:142
proto void GetWorldName(out string world_name)
proto native void RPCSingleParam(Object target, int rpc_type, Param param, bool guaranteed, PlayerIdentity recipient=null)
see CGame.RPC
static TStringArray GetPlayerRestrictedAreaFiles()
Определения CfgGameplayHandler.c:448
static void DrawBoxesDebug(bool draw)
static void DrawPolygonLinesDebug(bool draw)
static bool IsPointInPlayerRestrictedArea(vector point, out PlayerRestrictedAreaInstance hitArea)
static ref CfgPlayerRestrictedAreaJsonData m_Data
Определения CfgPlayerRestrictedAreaHandler.c:6
static void SyncDataSend(notnull PlayerIdentity identity)
static void OnRPC(ParamsReadContext ctx)
static ref TStringArray m_PRAFiles
Определения CfgPlayerRestrictedAreaHandler.c:5
static bool IsPointInPlayerRestrictedAreaClosest(vector point, out PlayerRestrictedAreaInstance hitArea)
ref array< Shape > m_DbgShapesBoxes
static PlayerRestrictedAreaInstance GetClosestArea(vector point)
static bool IsCylinderInAreaBox(notnull PlayerRestrictedAreaInstance area, vector point, float cylinderRadius=0.25, float cylinderHeight=1)
default cylinder values sufficient for player detection
ref array< Shape > m_DbgShapesPolygonLines
static bool IsPointInAreaPolygon(notnull PlayerRestrictedAreaInstance area, vector point)
static Shape DrawBox(vector pos1, vector pos2, int color=0x1fff7f7f)
Определения Debug.c:286
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:382
Определения Debug.c:2
Определения EnMath3D.c:28
The class that will be instanced (moddable)
Определения gameplay.c:389
ref array< ref PRAShapeBoxData > m_PRABoxDataTranslated
ref array< ref array< ref array< float > > > PRAPolygons
3D, not used directly!
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
Определения EnConvert.c:106
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
const int COLOR_RED
Определения constants.c:64
const int COLOR_WHITE
Определения constants.c:63
enum ShapeType ErrorEx
ShapeFlags
Определения EnDebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
array< string > TStringArray
Определения EnScript.c:685
proto bool FileExist(string name)
Check existence of file.
enum WindingOrder Math2D()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto bool IntersectCylinderOBB(vector mins, vector maxs, vector obbMat[4], vector cylMat[4], float cylinderRadius, float cylinderHeight)
Tests whether cylinder is intersecting oriented box.
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Определения EnMath3D.c:256