DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
WeaponDebug.c
См. документацию.
8
9
10
12{
13 const int BUFFER_SIZE = 1000;
18
29
31
32 //ref array<Selection> m_Selections = new array<Selection>();
33
45 //Shape temp_shape;
48
51
53 {
54 Weapon weapon_in_hands;
55 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
56 if( player && player.GetItemInHands() ) Class.CastTo(weapon_in_hands, player.GetItemInHands());
57
58 return weapon_in_hands;
59 }
60
62 {
63 m_DebugModesNames.Insert(eDebugMode.NORMAL, "Mode "+eDebugMode.NORMAL.ToString()+": shoot along the weapon barrel");
64 m_DebugModesNames.Insert(eDebugMode.MUZZLE_FIRE,"Mode "+eDebugMode.MUZZLE_FIRE.ToString()+": shoot from muzzle end to camera trace hit point");
65 m_DebugModesNames.Insert(eDebugMode.CAMERA_MUZZLE_HYBRID, "Mode "+eDebugMode.CAMERA_MUZZLE_HYBRID.ToString()+": shoot either from camera lens or from muzzle \n depending on the situation");
66 }
67
69 {
70 RemoveAllShapes(true);
71
72 }
73
96
97
99 {
100
101 m_IsLMBPressed = false;
102 m_IsFireKeyPressed = false;
103
104 if (KeyState(KeyCode.KC_LWIN) == 1)
105 {
107 {
108 OnKeyDown(KeyCode.KC_LWIN);
109 }
110 m_IsDrawKeyHeldDown = true;
111 }
112 else
113 {
115 {
116 //OnKeyUp();
117 }
118 m_IsDrawKeyHeldDown = false;
119 }
120
121 if (KeyState(KeyCode.KC_Z) == 1)
122 {
123 ClearKey(KeyCode.KC_Z);
125 }
126
127 if (KeyState(KeyCode.KC_X) == 1)
128 {
129 m_IsFireKeyPressed = true;
130 ClearKey(KeyCode.KC_X);
131 }
132
133 if (GetMouseState(MouseState.LEFT) & MB_PRESSED_MASK)
134 {
135 m_IsLMBPressed = true;
136 }
137 }
138
140 {
141 if (key == KeyCode.KC_X)
142 {
143 }
144 }
145
147 {
149 if ( m_CurrentMode == eDebugMode.COUNT )
150 {
151 m_CurrentMode = 0;
152 }
153
154 }
155
157 {
158 if ( GetWeaponInHands() )
159 {
161 Weapon weapon = GetWeaponInHands();
162 vector cameraDirection = GetGame().GetCurrentCameraDirection();
163 vector cameraPosition = GetGame().GetCurrentCameraPosition();
164 vector usti_hlavne_position = weapon.GetSelectionPositionMS( "usti hlavne" );//usti hlavne
165 vector konec_hlavne_position = weapon.GetSelectionPositionMS( "konec hlavne" );//konec hlavne
166 usti_hlavne_position = weapon.ModelToWorld(usti_hlavne_position);
167 konec_hlavne_position = weapon.ModelToWorld(konec_hlavne_position);
168
169 if ( m_CurrentMode == eDebugMode.NORMAL )
170 {
171 DrawLineOfFire(konec_hlavne_position,usti_hlavne_position );
172 }
173
174 if ( m_CurrentMode == eDebugMode.MUZZLE_FIRE )
175 {
176 DrawLineOfFireMuzzleToHit(usti_hlavne_position, cameraDirection, cameraPosition);
177 }
178
179 if ( m_CurrentMode == eDebugMode.CAMERA_MUZZLE_HYBRID )
180 {
181 DrawLineOfFireCameraHybrid(usti_hlavne_position, cameraDirection, cameraPosition, konec_hlavne_position);
182 }
183
185 {
186 AddPosToCyclicBuffer(usti_hlavne_position);
188 }
189
191
192
193 DrawEyePoint(weapon);
194 DrawBarrelMemoryPoints(konec_hlavne_position,usti_hlavne_position );
197 /*
198 vector pos;
199 weapon.GetProjectedCursorPos3d(pos);
200 Debug.RemoveShape(temp_shape);
201 temp_shape = Debug.DrawSphere(pos, 0.1, Colors.GREEN);
202 */
203 }
204 }
205
206 void DrawBarrelMemoryPoints(vector begin_point, vector end_point)
207 {
209 {
210 m_Shape_usti = Debug.DrawSphere(end_point, 0.011, Colors.GREEN, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER);
211 m_Shape_konec = Debug.DrawSphere(begin_point, 0.011, Colors.GREEN, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER);
212 }
213 }
214
215
216 void DrawLineOfFire(vector begin_point, vector end_point)
217 {
218 vector contact_point;
219 vector contact_dir;
220 vector aim_point = end_point - begin_point;
221 int contact_component;
222
223 aim_point = aim_point.Normalized() * 100;
224 aim_point = aim_point + end_point;
225
226 m_ShapeFireDirection1 = Debug.DrawLine(end_point, aim_point);
227 m_ShapeFireDirection2 = Debug.DrawLine(begin_point, end_point, ShapeFlags.NOZBUFFER );
228
229 if ( DayZPhysics.RaycastRV(end_point, aim_point, contact_point, contact_dir, contact_component, null, null, null, false, false, ObjIntersectFire) )
230 {
231 m_HitShape = Debug.DrawSphere(contact_point, 0.04, COLOR_RED);
232 }
233
234 if ( m_IsFireKeyPressed )
235 {
237 m_PermanentLine1 = Debug.DrawLine(end_point, contact_point, Colors.RED, ShapeFlags.NOZBUFFER );
238 }
239 }
240
242 {
246 {
247 m_BufferIndex = 0;
248 }
249 }
250
252 {
253 int unordered_index;
254
255 for (int i = 0; i < BUFFER_SIZE; i++)
256 {
257 unordered_index = m_BufferIndex + i;
258 if ( unordered_index >= BUFFER_SIZE )
259 {
260 unordered_index = unordered_index - BUFFER_SIZE;
261 }
262 m_AimTrailOrdered[i] = m_AimTrailCyclic[unordered_index];
263 }
264 }
265
266 void DrawEyePoint(Weapon weapon)
267 {
268 vector position = GetEyePointPosition(weapon);
269 m_ShapeEye = Debug.DrawSphere(position, 0.009, COLOR_BLUE, ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER);
270 }
271
273 {
274 string memory_point_name = weapon.ConfigGetString("memoryPointCamera");
275 ItemBase optics = weapon.GetAttachedOptics();
276 if (optics)
277 {
278 memory_point_name = optics.ConfigGetString("memoryPointCamera");
279 return optics.ModelToWorld(optics.GetSelectionPositionLS( memory_point_name ));
280 }
281 return weapon.ModelToWorld(weapon.GetSelectionPositionLS( memory_point_name ));
282
283 }
284
286 {
287 DbgUI.Begin("sway weight", 50, 50);
289 float sway_weight = player.GetAimingModel().GetSwayWeight();
290 DbgUI.Text("value: " + sway_weight.ToString());
291 DbgUI.Text("Hold LWIN to draw debug line");
292 DbgUI.Text("Press X to simulate fire");
293 DbgUI.Text("Press Z to cycle debug modes");
294 DbgUI.Text("Debug " +m_DebugModesNames.Get(m_CurrentMode) );
295 DbgUI.Text("");
296 DbgUI.End();
297 }
298
300 {
301 DbgUI.Begin("target distance", 50,200);
302 DbgUI.Text("value: " + m_TargetDistance.ToString());
303 DbgUI.End();
304 }
305
306
307 void DrawLineOfFireMuzzleToHit(vector begin_point, vector camera_dir, vector camera_pos)
308 {
309 vector contact_point_cam_trace;
310 vector contact_point_muzzle_trace;
311
312 vector contact_dir_muzzle;
313 vector contact_dir_camera;
314
315 vector contact_point;
316 vector contact_dir;
317
318 int contact_component;
319 int contact_component_muzzle;
320
321 vector end_point = camera_pos + camera_dir * 1000;
322 Man player = GetGame().GetPlayer();
323 Object player_o;
324 Class.CastTo(player_o, player);
325
326 if ( DayZPhysics.RaycastRV(camera_pos, end_point, contact_point_cam_trace, contact_dir_camera, contact_component,null, null, player_o , false, false, ObjIntersectFire, 0.1) )
327 {
328 m_ShapeFireDirCamera = Debug.DrawLine(begin_point, contact_point_cam_trace, Colors.RED, ShapeFlags.NOZBUFFER );
329 m_HitShape2 = Debug.DrawSphere(contact_point_cam_trace, 0.03, Colors.GREEN);
330 m_TargetDistance = vector.Distance( player.GetPosition(), contact_point_cam_trace);
331
332 if ( m_IsFireKeyPressed )
333 {
336 m_PermanentLine1 = Debug.DrawLine(begin_point, contact_point_cam_trace, Colors.RED, ShapeFlags.NOZBUFFER );
337 m_PermanentLine2 = Debug.DrawLine(camera_pos, contact_point_cam_trace, Colors.GREEN, ShapeFlags.NOZBUFFER );
338 }
339
340 }
341
342 else
343 {
344 m_ShapeFireDirCamera = Debug.DrawLine(begin_point, end_point, Colors.GREEN, ShapeFlags.NOZBUFFER );
345 m_TargetDistance = -1;
346 }
347
348 if ( DayZPhysics.RaycastRV(begin_point, contact_point_cam_trace, contact_point_muzzle_trace, contact_dir_muzzle, contact_component_muzzle, null, null, null, false, false, ObjIntersectFire, 0.0) )
349 {
350 m_HitShape3 = Debug.DrawSphere(contact_point_muzzle_trace, 0.03, COLOR_RED);
351 }
352 }
353
354 void DrawLineOfFireCameraHybrid(vector usti_hlavne_position, vector camera_dir, vector camera_pos, vector konec_hlavne_position)
355 {
356 bool muzzle_shot;
357 vector contact_point_cam_trace;
358 vector contact_point_muzzle_trace;
359
360 vector aim_at_position;
361
362 vector contact_dir_muzzle;
363 vector contact_dir;
364
365 vector contact_point;
366
367 int contact_component;
368 int contact_component_muzzle;
369
370 float distance_to_aim_at;
371 vector end_point = camera_pos + camera_dir * 100;
372 vector start_point = camera_pos + (CAMERA_BULLET_ORIGIN_OFFSET * camera_dir);
373 vector weapon_aim_direction = usti_hlavne_position - konec_hlavne_position;
374 weapon_aim_direction.Normalize();
375
376 Man player = GetGame().GetPlayer();
377 Object player_o;
378 Class.CastTo(player_o, player);
379
380 if ( DayZPhysics.RaycastRV(start_point, end_point, contact_point_cam_trace, contact_dir, contact_component,null, null, player_o , false, false, ObjIntersectFire) )
381 {
382 m_TargetDistance = vector.Distance(start_point, contact_point_cam_trace);
383 aim_at_position = contact_point_cam_trace;
384
385 if ( DayZPhysics.RaycastRV(usti_hlavne_position, contact_point_cam_trace, contact_point_muzzle_trace, contact_dir, contact_component,null, null, player_o , false, false, ObjIntersectFire, 0.05) )
386 {
387 float collision_distance = vector.Distance(contact_point_cam_trace, contact_point_muzzle_trace);
388 float muzzle_collision_distance = vector.Distance(usti_hlavne_position, contact_point_muzzle_trace);
389
390 if ((collision_distance > 2 && muzzle_collision_distance < MAX_MUZZLE_DISTANCE_TOLERANCE) || m_TargetDistance < CAMERA_TRACE_MIN_DISTANCE_TOLERANCE)
391 {
392 muzzle_shot = true;
393 aim_at_position = contact_point_muzzle_trace;
394 }
395 }
396 }
397
398
399
400 distance_to_aim_at = vector.Distance(camera_pos, aim_at_position);
401
402 if ( m_IsFireKeyPressed )
403 {
407
408 vector contact_point_temp;
409
410 if (muzzle_shot)
411 {
412 m_PermanentLine1 = Debug.DrawLine(usti_hlavne_position, usti_hlavne_position + weapon_aim_direction * 5, Colors.RED, ShapeFlags.NOZBUFFER );
413 m_PermanentLine2 = Debug.DrawLine(camera_pos, contact_point_cam_trace, Colors.GREEN, ShapeFlags.NOZBUFFER );
414 PrintString("muzle shot");
415 }
416 else
417 {
418 vector dir = contact_point_cam_trace - camera_pos;
419 dir.Normalize();
420 dir = dir * 100;
421 float dst = vector.Distance(camera_pos, contact_point_cam_trace);
422 float dist2 = vector.Distance(camera_pos, contact_point_cam_trace);
423
424 //m_PermanentShape1 = Debug.DrawSphere(start_point, 0.015,Colors.GREEN);
425 m_PermanentLine1 = Debug.DrawLine(start_point, contact_point_cam_trace + dir, Colors.RED, ShapeFlags.NOZBUFFER );
426 PrintString("camera shot");
427 }
428 }
429
430 float clamped_distance = Math.Clamp(distance_to_aim_at, 0 , 100);
431 float distance_normalized = Math.InverseLerp(0, 100, clamped_distance);
432 float hit_sphere_size = Math.Lerp(0.025, 0.75, distance_normalized);
433
436 m_HitShape = Debug.DrawSphere(contact_point_cam_trace, 0.20,Colors.GREEN, ShapeFlags.TRANSP);
437 m_HitShape4 = Debug.DrawSphere(aim_at_position, hit_sphere_size);
438
439 }
440
441}
map
Определения ControlsXboxNew.c:4
@ NORMAL
Определения ECameraZoomType.c:4
@ COUNT
Определения EGameStateIcons.c:7
PlayerBase GetPlayer()
Определения ModifierBase.c:51
eDebugMode
Определения WeaponDebug.c:2
@ CAMERA_MUZZLE_HYBRID
Определения WeaponDebug.c:5
@ MUZZLE_FIRE
Определения WeaponDebug.c:4
proto native DayZPlayer GetPlayer()
proto native vector GetCurrentCameraPosition()
proto native vector GetCurrentCameraDirection()
Super root of all classes in Enforce script.
Определения EnScript.c:11
const int GREEN
Определения Colors.c:8
const int RED
Определения Colors.c:5
Определения Colors.c:4
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Определения DayZPhysics.c:124
Определения ManBase.c:2
Определения DbgUI.c:60
static Shape DrawLines(vector[] positions, int count, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:395
static Shape DrawSphere(vector pos, float size=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Определения Debug.c:319
static void RemoveShape(out Shape shape)
Определения Debug.c:96
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Определения Debug.c:382
Определения Debug.c:2
Определения InventoryItem.c:731
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
Shape m_ShapeTrailLines
Определения WeaponDebug.c:40
void DrawBarrelMemoryPoints(vector begin_point, vector end_point)
Определения WeaponDebug.c:206
vector m_AimTrailOrdered[BUFFER_SIZE]
Определения WeaponDebug.c:28
bool m_IsLMBPressed
Определения WeaponDebug.c:22
const float CAMERA_TRACE_MIN_DISTANCE_TOLERANCE
Определения WeaponDebug.c:17
bool m_IsFireKeyPressed
Определения WeaponDebug.c:24
bool m_IsToggleKeyPressed
Определения WeaponDebug.c:23
void DisplayGeneralInfo()
Определения WeaponDebug.c:285
Shape m_Shape_konec
Определения WeaponDebug.c:35
void DrawLineOfFire(vector begin_point, vector end_point)
Определения WeaponDebug.c:216
void DisplayTargetInfo()
Определения WeaponDebug.c:299
void OnCommandHandlerUpdate()
Определения WeaponDebug.c:98
void OnKeyDown(KeyCode key)
Определения WeaponDebug.c:139
const float COLLISIONS_DISTANCE_TOLERANCE
Определения WeaponDebug.c:14
Shape m_HitShape4
Определения WeaponDebug.c:44
void RemoveAllShapes(bool is_exit=false)
Определения WeaponDebug.c:74
const float MAX_MUZZLE_DISTANCE_TOLERANCE
Определения WeaponDebug.c:15
void DrawLineOfFireMuzzleToHit(vector begin_point, vector camera_dir, vector camera_pos)
Определения WeaponDebug.c:307
ref map< int, string > m_DebugModesNames
Определения WeaponDebug.c:30
Shape m_PermanentLine2
Определения WeaponDebug.c:47
Shape m_Shape_usti
Определения WeaponDebug.c:34
vector m_AimTrailCyclic[BUFFER_SIZE]
Определения WeaponDebug.c:27
const float CAMERA_BULLET_ORIGIN_OFFSET
Определения WeaponDebug.c:16
Shape m_HitShape2
Определения WeaponDebug.c:42
Shape m_PermanentShape2
Определения WeaponDebug.c:50
vector GetEyePointPosition(Weapon weapon)
Определения WeaponDebug.c:272
Shape m_PermanentLine1
Определения WeaponDebug.c:46
void CycleDebugMode()
Определения WeaponDebug.c:146
bool m_IsDrawKeyHeldDown
Определения WeaponDebug.c:21
void WeaponDebug()
Определения WeaponDebug.c:61
Shape m_ShapeFireDirection2
Определения WeaponDebug.c:37
Shape m_PermanentShape1
Определения WeaponDebug.c:49
Shape m_HitShape3
Определения WeaponDebug.c:43
float m_TargetDistance
Определения WeaponDebug.c:25
Weapon GetWeaponInHands()
Определения WeaponDebug.c:52
void ~WeaponDebug()
Определения WeaponDebug.c:68
void OnPostFrameUpdate()
Определения WeaponDebug.c:156
int m_BufferIndex
Определения WeaponDebug.c:20
void AddPosToCyclicBuffer(vector pos)
Определения WeaponDebug.c:241
Shape m_ShapeFireDirection1
Определения WeaponDebug.c:36
void OrderTrailArray()
Определения WeaponDebug.c:251
const int BUFFER_SIZE
Определения WeaponDebug.c:13
Weapon m_WeaponInHands
Определения WeaponDebug.c:19
void DrawLineOfFireCameraHybrid(vector usti_hlavne_position, vector camera_dir, vector camera_pos, vector konec_hlavne_position)
Определения WeaponDebug.c:354
void DrawEyePoint(Weapon weapon)
Определения WeaponDebug.c:266
eDebugMode m_CurrentMode
Определения WeaponDebug.c:26
Shape m_ShapeFireDirCamera
Определения WeaponDebug.c:41
Shape m_ShapeEye
Определения WeaponDebug.c:39
Shape m_HitShape
Определения WeaponDebug.c:38
script counterpart to engine's class Weapon
Определения InventoryItem.c:49
proto string ToString(bool simple=true)
proto vector Normalized()
return normalized vector (keeps orginal vector untouched)
proto float Normalize()
Normalizes vector. Returns length.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
Определения EnConvert.c:106
proto native CGame GetGame()
const int COLOR_BLUE
Определения constants.c:66
const int COLOR_RED
Определения constants.c:64
const int COLOR_YELLOW
Определения constants.c:67
ShapeFlags
Определения EnDebug.c:126
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Определения EnScript.c:345
proto native void ClearKey(KeyCode key)
KeyCode
Определения EnSystem.c:157
proto native int KeyState(KeyCode key)
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
MouseState
Определения EnSystem.c:311
proto native int GetMouseState(MouseState index)