Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
itemoptics.c
Go to the documentation of this file.
2{
3 bool m_data_set;
4 bool m_allowsDOF; //true if optics DOES NOT have magnification (FOV >= DZPLAYER_CAMERA_FOV_IRONSIGHTS)
5 bool m_reddot_displayed
6 bool m_isNVOptic = false;
7 int m_CurrentOpticMode; //generic optic mode, currently used for NV optics only (could be expanded)
8 int m_CurrentOpticModeLocal; //local mirror for sync purposes;
9 int m_reddot_index;
10 float m_blur_float;
11 float m_nearplane_override; //override value for DayZPlayerCameraOptics only!
12 string m_optic_sight_texture;
13 string m_optic_sight_material;
14 string m_2D_preload_type;
15 ref array<float> m_mask_array;
16 ref array<float> m_lens_array;
17 ref array<float> m_OpticsDOFProperties;
18
19 void ItemOptics()
20 {
21 m_mask_array = new array<float>;
22 m_lens_array = new array<float>;
23 m_OpticsDOFProperties = new array<float>;
24
28 InitOpticsDOFProperties(m_OpticsDOFProperties);
31
32 m_CurrentOpticModeLocal = -1;
33 RegisterNetSyncVariableInt( "m_CurrentOpticMode", 0, 63 );
34 }
35
40 proto native bool EnterOptics ();
41
46 proto native bool IsInOptics ();
47
52 proto native bool ExitOptics ();
53
58 proto native bool HasWeaponIronsightsOverride ();
59
64 proto native bool UseWeaponIronsightsOverride(bool state);
65
70 proto native bool IsUsingWeaponIronsightsOverride();
71
75 proto native int GetStepFOVCount ();
76
81 proto native int GetStepFOVIndex ();
82
88 proto native bool SetStepFOVIndex (int step);
89
94 proto native bool StepFOVUp ();
95
100 proto native bool StepFOVDown ();
101
105 proto native float GetCurrentStepFOV ();
106
111 proto native int GetStepZeroing ();
112
118 proto native bool SetStepZeroing (int step);
119
125 proto native bool StepZeroingUp ();
126
132 proto native bool StepZeroingDown ();
133
138 proto native void GetCameraPoint (out vector pos, out vector dir);
139
144 proto native float GetZoomInit();
145
150 proto native float GetZoomMin();
151
156 proto native float GetZoomMax();
157
162 proto native float GetZeroingDistanceZoomMin();
163
168 proto native float GetZeroingDistanceZoomMax();
169
174 proto native void SetZeroingClampDist(float dist);
175
180 protected void OnDrawOptics2D()
181 {
182 if (m_reddot_index == -1)
183 return;
184
185 ItemOpticsType opticsType = GetItemOpticsType();
186 if (m_reddot_displayed)
187 {
188 if (m_optic_sight_texture != "")
189 opticsType.SetOptics2DTexture(m_reddot_index, m_optic_sight_texture);
190 if (m_optic_sight_material != "")
191 opticsType.SetOptics2DMaterial(m_reddot_index, m_optic_sight_material);
192 }
193 else
194 {
195 opticsType.SetOptics2DTexture(m_reddot_index, "");
196 opticsType.SetOptics2DMaterial(m_reddot_index, "");
197 }
198 }
199
201 protected ItemOpticsType GetItemOpticsType()
202 {
203 return ItemOpticsType.Cast(GetInventoryItemType());
204 }
205
208 {
209 ItemOpticsType type = GetItemOpticsType();
210 return type.IsUsingOptics2DModel();
211 }
212
214 {
215 return false;
216 }
217
218 override void OnWorkStart()
219 {
220 if (!GetGame().IsDedicatedServer())
221 {
222 ShowReddot(true);
223 }
224 }
225
226 override void OnWorkStop()
227 {
228 if (!GetGame().IsDedicatedServer())
229 {
230 ShowReddot(false);
231 }
232 }
233
235 {
236 if (GetCompEM() && GetCompEM().CanWork())
237 return true;
238 return false;
239 }
240
242 {
243 if (IsWorking() && !m_reddot_displayed)
244 {
245 ShowReddot(true);
246 }
247 else if (!IsWorking() && m_reddot_displayed)
248 {
249 ShowReddot(false);
250 }
251 }
252
253 override void OnWasAttached( EntityAI parent, int slot_id )
254 {
255 super.OnWasAttached(parent, slot_id);
256
257 SetTakeable(false);
258
259 Weapon wep;
260 if (Class.CastTo(wep,parent))
261 {
262 SetZeroingClampDist(wep.GetZeroingClamp(wep.GetCurrentMuzzle()));
263 }
264 }
265
266 override void OnWasDetached( EntityAI parent, int slot_id )
267 {
268 super.OnWasDetached(parent, slot_id);
269
270 PlayerBase player;
271 if (PlayerBase.CastTo(player, GetHierarchyRootPlayer()))
272 {
273 player.SetReturnToOptics(false);
274 }
275
276 SetTakeable(true);
277
278 Weapon wep;
279 if (Class.CastTo(wep,parent))
280 {
281 SetZeroingClampDist(0.0);
282 }
283 }
284
285 override void OnInventoryExit(Man player)
286 {
287 super.OnInventoryExit(player);
288
289 PlayerBase playerPB;
290 if (PlayerBase.CastTo(playerPB, player))
291 {
292 playerPB.SetReturnToOptics(false);
293 }
294
295 SetTakeable(true);
296 }
297
299 {
300 super.OnStoreSave(ctx);
301
302 ctx.Write(m_CurrentOpticMode);
303 }
304
305 override bool OnStoreLoad(ParamsReadContext ctx, int version)
306 {
307 if ( !super.OnStoreLoad(ctx,version) )
308 {
309 return false;
310 }
311 m_IsStoreLoad = true;
312
313 if ( version >= 126 )
314 {
315 if ( !ctx.Read(m_CurrentOpticMode) )
316 {
317 m_IsStoreLoad = false;
318 return false;
319 }
320 }
321
323 SetSynchDirty();
324
325 m_IsStoreLoad = false;
326 return true;
327 }
328
330 {
331 super.OnVariablesSynchronized();
332
333 if (m_CurrentOpticModeLocal != m_CurrentOpticMode)
334 {
336 m_CurrentOpticModeLocal = m_CurrentOpticMode;
337 }
338 }
339
341 {
342 bool isUsing2D = IsUsingOptics2DModel();
343
344 string path;
345 if (isUsing2D)
346 {
347 path = "cfgVehicles " + GetType() + " OpticsModelInfo";
348 }
349 else
350 {
351 path = "cfgVehicles " + GetType() + " OpticsInfo";
352 }
353 string temp;
354
355 if (GetGame().ConfigIsExisting(path))
356 {
357 if (isUsing2D)
358 m_reddot_index = GetItemOpticsType().FindOptics2DSelection("reddot");
359 else
360 m_reddot_index = GetHiddenSelectionIndex("reddot");
361
362 if (GetGame().ConfigIsExisting(path + " opticSightTexture"))
363 {
364 GetGame().ConfigGetText(path + " opticSightTexture", temp);
365 m_optic_sight_texture = temp;
366 temp = "";
367 }
368 if (GetGame().ConfigIsExisting(path + " opticSightMaterial"))
369 {
370 GetGame().ConfigGetText(path + " opticSightMaterial", temp);
371 m_optic_sight_material = temp;
372 temp = "";
373 }
374 }
375 m_data_set = true;
376 }
377
378 void ShowReddot(bool state)
379 {
380 if (GetGame().IsDedicatedServer())
381 {
382 ErrorEx("should not be called on the server!",ErrorExSeverity.INFO);
383 return;
384 }
385
386 if (!m_data_set)
387 {
389 }
390
391 // does not have reddot
392 if (m_reddot_index == -1)
393 {
394 return;
395 }
396
397 // 2D model has special handling in `OnDrawOptics2D`
399 {
400 if (state)
401 {
402 if (m_optic_sight_texture != "")
403 SetObjectTexture(m_reddot_index, m_optic_sight_texture);
404 if (m_optic_sight_material != "")
405 SetObjectMaterial(m_reddot_index, m_optic_sight_material);
406 }
407 else
408 {
409 SetObjectTexture(m_reddot_index, "");
410 SetObjectMaterial(m_reddot_index, "");
411 }
412 }
413 m_reddot_displayed = state;
414 }
415
417 {
418 m_allowsDOF = InitDOFAvailability();
419 InitOpticsPP(m_mask_array, m_lens_array, m_blur_float);
420
421 m_isNVOptic = ConfigGetBool("NVOptic");
422 }
423
426 {
427 float fov_max;
428 string path = "cfgVehicles " + GetType() + " OpticsInfo";
429
430 /*
431 Weapon_Base weapon = Weapon_Base.Cast(GetHierarchyParent());
432 if (!weapon)
433 return false; // no DOF for handheld optics
434 */
435 fov_max = GetGame().ConfigGetFloat(path + " opticsZoomMax");
436 if (fov_max >= GameConstants.DZPLAYER_CAMERA_FOV_IRONSIGHTS)
437 {
438 return true;
439 }
440 return false;
441 }
442
444 void InitOpticsPP(out array<float> mask_array, out array<float> lens_array, out float blur_float)
445 {
446 string path = "cfgVehicles " + GetType() + " OpticsInfo";
447 GetGame().ConfigGetFloatArray(path + " PPMaskProperties", mask_array);
448 GetGame().ConfigGetFloatArray(path + " PPLensProperties", lens_array);
449 blur_float = GetGame().ConfigGetFloat(path + " PPBlurProperties");
450 }
451
453 {
454 string path = "cfgVehicles " + GetType() + " OpticsInfo";
455 if ( GetGame().ConfigIsExisting(path + " nearPlaneDistanceOverride") )
456 {
457 m_nearplane_override = Math.Max(GetGame().ConfigGetFloat(path + " nearPlaneDistanceOverride"),DayZPlayerCameraBase.CONST_NEARPLANE_OPTICS_MIN);
458 }
459 else
460 {
461 m_nearplane_override = DayZPlayerCameraOptics.CONST_NEARPLANE_OPTICS;
462 }
463 }
464
467 {
468 if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties"))
469 {
470 GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties", temp_array);
471 return true;
472 }
473 else if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties"))
474 {
475 GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties", temp_array);
476 return true;
477 }
478 return false;
479 }
480
483 {
484 return m_allowsDOF;
485 }
486
488 {
489 return m_isNVOptic;
490 }
491
493 {
494 /*
495 //TODO - implement this into NV optics and modify (KazuarOptic example below)
496 if (IsWorking())
497 {
498 switch (m_CurrentOpticMode)
499 {
500 case GameConstants.OPTICS_STATE_DAY:
501 return NVTypes.NV_OPTICS_KAZUAR_DAY;
502
503 case GameConstants.OPTICS_STATE_NIGHTVISION:
504 return NVTypes.NV_OPTICS_KAZUAR_NIGHT;
505 }
506 }
507 else
508 {
509 return NVTypes.NV_OPTICS_OFF;
510 }
511 */
512 return NVTypes.NONE;
513 }
514
515 void SetCurrentOpticMode(int mode)
516 {
517 m_CurrentOpticMode = mode;
519 }
520
522 {
523 return m_CurrentOpticMode;
524 }
525
529 {
530 if ( GetGame() && !GetGame().IsDedicatedServer() )
531 {
532 HideSelection("hide");
533 }
534 }
536 {
537 if ( GetGame() && !GetGame().IsDedicatedServer() )
538 {
539 ShowSelection("hide");
540 }
541 }
542
544 {
545 return m_OpticsDOFProperties;
546 }
548 {
549 return m_mask_array;
550 }
552 {
553 return m_lens_array;
554 }
556 {
557 return m_blur_float;
558 }
559
561 {
562 return m_nearplane_override;
563 }
564
566 {
567 string path = "cfgVehicles " + GetType() + " OpticsInfo preloadOpticType";
568 string type_2d;
569
570 if ( GetGame().ConfigIsExisting(path) )
571 {
572 GetGame().ConfigGetText(path, type_2d);
573 m_2D_preload_type = type_2d;
574 }
575 }
576
578 {
579 SetCurrentOpticMode(GameConstants.OPTICS_STATE_DAY);
580 }
581
583
584 override void SetActions()
585 {
586 super.SetActions();
587
589 }
590
591 override void OnDebugSpawn()
592 {
593 GetInventory().CreateAttachment("Battery9V");
594 }
595}
596
597typedef ItemOptics OpticBase;
598
599
eBleedingSourceType GetType()
void AddAction(typename actionName)
Super root of all classes in Enforce script.
Definition enscript.c:11
this is main camera class
void OnOpticModeChange()
optic-specific behaviour to be defined here (override)
Definition itemoptics.c:527
void InitOpticsPP(out array< float > mask_array, out array< float > lens_array, out float blur_float)
initializes values for optics' post-processes
Definition itemoptics.c:444
override void OnDebugSpawn()
Definition itemoptics.c:591
void InitOpticMode()
Definition itemoptics.c:577
bool IsUsingOptics2DModel()
Returns whether this ItemOptics uses the 2D optics model.
Definition itemoptics.c:207
void OnOpticExit()
Definition itemoptics.c:535
override void OnWorkStart()
Definition itemoptics.c:218
void InitReddotData()
Definition itemoptics.c:340
int GetCurrentOpticMode()
Definition itemoptics.c:521
ref array< float > GetOpticsPPLens()
Definition itemoptics.c:551
bool IsWorking()
Definition itemoptics.c:234
override void OnStoreSave(ParamsWriteContext ctx)
Definition itemoptics.c:298
bool AllowsDOF()
returns 'true' for non-magnifying optics
Definition itemoptics.c:482
int GetCurrentNVType()
Definition itemoptics.c:492
ref array< float > GetOpticsPPMask()
Definition itemoptics.c:547
float GetNearPlaneValue()
Definition itemoptics.c:560
void OnOpticEnter()
Definition itemoptics.c:528
void UpdateOpticsReddotVisibility()
Definition itemoptics.c:241
void UpdateSelectionVisibility()
Definition itemoptics.c:582
void OnDrawOptics2D()
Definition itemoptics.c:180
bool IsSightOnly()
Definition itemoptics.c:213
bool InitDOFAvailability()
optics with more than 1x zoom do not allow DOF changes
Definition itemoptics.c:425
void InitOpticsPPInfo()
Definition itemoptics.c:416
float GetOpticsPPBlur()
Definition itemoptics.c:555
override void OnVariablesSynchronized()
Definition itemoptics.c:329
override void SetActions()
Definition itemoptics.c:584
bool IsNVOptic()
Definition itemoptics.c:487
bool InitOpticsDOFProperties(out array< float > temp_array)
Initializes DOF properties for optic's alternate ironsights (ACOG etc.)
Definition itemoptics.c:466
ref array< float > GetOpticsDOF()
Definition itemoptics.c:543
void Init2DPreloadType()
Definition itemoptics.c:565
void SetCurrentOpticMode(int mode)
Definition itemoptics.c:515
override void OnWasAttached(EntityAI parent, int slot_id)
Definition itemoptics.c:253
override void OnInventoryExit(Man player)
Definition itemoptics.c:285
void InitCameraOverrideProperties()
Definition itemoptics.c:452
void ShowReddot(bool state)
Definition itemoptics.c:378
ItemOpticsType GetItemOpticsType()
Returns the ItemOpticsType of this ItemOptics instance.
Definition itemoptics.c:201
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition itemoptics.c:305
override void OnWorkStop()
Definition itemoptics.c:226
override void OnWasDetached(EntityAI parent, int slot_id)
Definition itemoptics.c:266
Definition enmath.c:7
Serialization general interface. Serializer API works with:
Definition serializer.c:56
script counterpart to engine's class Weapon
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
proto native CGame GetGame()
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
override void SetTakeable(bool pState)
Definition itembase.c:9184
bool m_IsStoreLoad
Definition itembase.c:4910