Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
itemoptics.c
Go to the documentation of this file.
1class ItemOptics : InventoryItemSuper
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
202 {
203 return ItemOpticsType.Cast(GetInventoryItemType());
204 }
205
208 {
210 return type.IsUsingOptics2DModel();
211 }
212
214 {
215 return false;
216 }
217
219 {
220 return false;
221 }
222
223 override void OnWorkStart()
224 {
225 if (!g_Game.IsDedicatedServer())
226 {
227 ShowReddot(true);
228 }
229 }
230
231 override void OnWorkStop()
232 {
233 if (!g_Game.IsDedicatedServer())
234 {
235 ShowReddot(false);
236 }
237 }
238
240 {
241 if (GetCompEM() && GetCompEM().CanWork())
242 return true;
243 return false;
244 }
245
247 {
248 if (IsWorking() && !m_reddot_displayed)
249 {
250 ShowReddot(true);
251 }
252 else if (!IsWorking() && m_reddot_displayed)
253 {
254 ShowReddot(false);
255 }
256 }
257
258 override void OnWasAttached( EntityAI parent, int slot_id )
259 {
260 super.OnWasAttached(parent, slot_id);
261
262 SetTakeable(false);
263
264 Weapon wep;
265 if (Class.CastTo(wep,parent))
266 {
267 SetZeroingClampDist(wep.GetZeroingClamp(wep.GetCurrentMuzzle()));
268 }
269 }
270
271 override void OnWasDetached( EntityAI parent, int slot_id )
272 {
273 super.OnWasDetached(parent, slot_id);
274
275 PlayerBase player;
276 if (PlayerBase.CastTo(player, GetHierarchyRootPlayer()))
277 {
278 player.SetReturnToOptics(false);
279 }
280
281 SetTakeable(true);
282
283 Weapon wep;
284 if (Class.CastTo(wep,parent))
285 {
286 SetZeroingClampDist(0.0);
287 }
288 }
289
290 override void OnInventoryExit(Man player)
291 {
292 super.OnInventoryExit(player);
293
294 PlayerBase playerPB;
295 if (PlayerBase.CastTo(playerPB, player))
296 {
297 playerPB.SetReturnToOptics(false);
298 }
299
300 SetTakeable(true);
301 }
302
304 {
305 super.OnStoreSave(ctx);
306
307 ctx.Write(m_CurrentOpticMode);
308 }
309
310 override bool OnStoreLoad(ParamsReadContext ctx, int version)
311 {
312 if ( !super.OnStoreLoad(ctx,version) )
313 {
314 return false;
315 }
316 m_IsStoreLoad = true;
317
318 if ( version >= 126 )
319 {
320 if ( !ctx.Read(m_CurrentOpticMode) )
321 {
322 m_IsStoreLoad = false;
323 return false;
324 }
325 }
326
328 SetSynchDirty();
329
330 m_IsStoreLoad = false;
331 return true;
332 }
333
335 {
336 super.OnVariablesSynchronized();
337
338 if (m_CurrentOpticModeLocal != m_CurrentOpticMode)
339 {
341 m_CurrentOpticModeLocal = m_CurrentOpticMode;
342 }
343 }
344
346 {
347 bool isUsing2D = IsUsingOptics2DModel();
348
349 string path;
350 if (isUsing2D)
351 {
352 path = "cfgVehicles " + GetType() + " OpticsModelInfo";
353 }
354 else
355 {
356 path = "cfgVehicles " + GetType() + " OpticsInfo";
357 }
358 string temp;
359
360 if (g_Game.ConfigIsExisting(path))
361 {
362 if (isUsing2D)
363 m_reddot_index = GetItemOpticsType().FindOptics2DSelection("reddot");
364 else
365 m_reddot_index = GetHiddenSelectionIndex("reddot");
366
367 if (g_Game.ConfigIsExisting(path + " opticSightTexture"))
368 {
369 g_Game.ConfigGetText(path + " opticSightTexture", temp);
370 m_optic_sight_texture = temp;
371 temp = "";
372 }
373 if (g_Game.ConfigIsExisting(path + " opticSightMaterial"))
374 {
375 g_Game.ConfigGetText(path + " opticSightMaterial", temp);
376 m_optic_sight_material = temp;
377 temp = "";
378 }
379 }
380 m_data_set = true;
381 }
382
383 void ShowReddot(bool state)
384 {
385 if (g_Game.IsDedicatedServer())
386 {
387 ErrorEx("should not be called on the server!",ErrorExSeverity.INFO);
388 return;
389 }
390
391 if (!m_data_set)
392 {
394 }
395
396 // does not have reddot
397 if (m_reddot_index == -1)
398 {
399 return;
400 }
401
402 // 2D model has special handling in `OnDrawOptics2D`
404 {
405 if (state)
406 {
407 if (m_optic_sight_texture != "")
408 SetObjectTexture(m_reddot_index, m_optic_sight_texture);
409 if (m_optic_sight_material != "")
410 SetObjectMaterial(m_reddot_index, m_optic_sight_material);
411 }
412 else
413 {
414 SetObjectTexture(m_reddot_index, "");
415 SetObjectMaterial(m_reddot_index, "");
416 }
417 }
418 m_reddot_displayed = state;
419 }
420
422 {
423 m_allowsDOF = InitDOFAvailability();
424 InitOpticsPP(m_mask_array, m_lens_array, m_blur_float);
425
426 m_isNVOptic = ConfigGetBool("NVOptic");
427 }
428
431 {
432 float fov_max;
433 string path = "cfgVehicles " + GetType() + " OpticsInfo";
434
435 /*
436 Weapon_Base weapon = Weapon_Base.Cast(GetHierarchyParent());
437 if (!weapon)
438 return false; // no DOF for handheld optics
439 */
440 fov_max = g_Game.ConfigGetFloat(path + " opticsZoomMax");
441 if (fov_max >= GameConstants.DZPLAYER_CAMERA_FOV_IRONSIGHTS)
442 {
443 return true;
444 }
445 return false;
446 }
447
449 void InitOpticsPP(out array<float> mask_array, out array<float> lens_array, out float blur_float)
450 {
451 string path = "cfgVehicles " + GetType() + " OpticsInfo";
452 g_Game.ConfigGetFloatArray(path + " PPMaskProperties", mask_array);
453 g_Game.ConfigGetFloatArray(path + " PPLensProperties", lens_array);
454 blur_float = g_Game.ConfigGetFloat(path + " PPBlurProperties");
455 }
456
458 {
459 string path = "cfgVehicles " + GetType() + " OpticsInfo";
460 if ( g_Game.ConfigIsExisting(path + " nearPlaneDistanceOverride") )
461 {
462 m_nearplane_override = Math.Max(g_Game.ConfigGetFloat(path + " nearPlaneDistanceOverride"),DayZPlayerCameraBase.CONST_NEARPLANE_OPTICS_MIN);
463 }
464 else
465 {
466 m_nearplane_override = DayZPlayerCameraOptics.CONST_NEARPLANE_OPTICS;
467 }
468 }
469
472 {
473 if (g_Game.ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties"))
474 {
475 g_Game.ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties", temp_array);
476 return true;
477 }
478 else if (g_Game.ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties"))
479 {
480 g_Game.ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties", temp_array);
481 return true;
482 }
483 return false;
484 }
485
488 {
489 return m_allowsDOF;
490 }
491
493 {
494 return m_isNVOptic;
495 }
496
498 {
499 /*
500 //TODO - implement this into NV optics and modify (KazuarOptic example below)
501 if (IsWorking())
502 {
503 switch (m_CurrentOpticMode)
504 {
505 case GameConstants.OPTICS_STATE_DAY:
506 return NVTypes.NV_OPTICS_KAZUAR_DAY;
507
508 case GameConstants.OPTICS_STATE_NIGHTVISION:
509 return NVTypes.NV_OPTICS_KAZUAR_NIGHT;
510 }
511 }
512 else
513 {
514 return NVTypes.NV_OPTICS_OFF;
515 }
516 */
517 return NVTypes.NONE;
518 }
519
520 void SetCurrentOpticMode(int mode)
521 {
522 m_CurrentOpticMode = mode;
524 }
525
527 {
528 return m_CurrentOpticMode;
529 }
530
534 {
535 if ( g_Game && !g_Game.IsDedicatedServer() )
536 {
537 HideSelection("hide");
538 }
539 }
541 {
542 if ( g_Game && !g_Game.IsDedicatedServer() )
543 {
544 ShowSelection("hide");
545 }
546 }
547
549 {
550 return m_OpticsDOFProperties;
551 }
553 {
554 return m_mask_array;
555 }
557 {
558 return m_lens_array;
559 }
561 {
562 return m_blur_float;
563 }
564
566 {
567 return m_nearplane_override;
568 }
569
571 {
572 string path = "cfgVehicles " + GetType() + " OpticsInfo preloadOpticType";
573 string type_2d;
574
575 if ( g_Game.ConfigIsExisting(path) )
576 {
577 g_Game.ConfigGetText(path, type_2d);
578 m_2D_preload_type = type_2d;
579 }
580 }
581
583 {
584 SetCurrentOpticMode(GameConstants.OPTICS_STATE_DAY);
585 }
586
588
589 override void SetActions()
590 {
591 super.SetActions();
592
594 }
595
596 override void OnDebugSpawn()
597 {
598 GetInventory().CreateAttachment("Battery9V");
599 }
600}
601
602typedef ItemOptics OpticBase;
603
604
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:532
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:449
override void OnDebugSpawn()
Definition itemoptics.c:596
void InitOpticMode()
Definition itemoptics.c:582
bool IsUsingOptics2DModel()
Returns whether this ItemOptics uses the 2D optics model.
Definition itemoptics.c:207
void OnOpticExit()
Definition itemoptics.c:540
override void OnWorkStart()
Definition itemoptics.c:223
void InitReddotData()
Definition itemoptics.c:345
int GetCurrentOpticMode()
Definition itemoptics.c:526
ref array< float > GetOpticsPPLens()
Definition itemoptics.c:556
bool IsWorking()
Definition itemoptics.c:239
bool IsUsableWithNV()
Definition itemoptics.c:218
override void OnStoreSave(ParamsWriteContext ctx)
Definition itemoptics.c:303
bool AllowsDOF()
returns 'true' for non-magnifying optics
Definition itemoptics.c:487
int GetCurrentNVType()
Definition itemoptics.c:497
ref array< float > GetOpticsPPMask()
Definition itemoptics.c:552
float GetNearPlaneValue()
Definition itemoptics.c:565
void OnOpticEnter()
Definition itemoptics.c:533
void UpdateOpticsReddotVisibility()
Definition itemoptics.c:246
void UpdateSelectionVisibility()
Definition itemoptics.c:587
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:430
void InitOpticsPPInfo()
Definition itemoptics.c:421
float GetOpticsPPBlur()
Definition itemoptics.c:560
override void OnVariablesSynchronized()
Definition itemoptics.c:334
override void SetActions()
Definition itemoptics.c:589
bool IsNVOptic()
Definition itemoptics.c:492
bool InitOpticsDOFProperties(out array< float > temp_array)
Initializes DOF properties for optic's alternate ironsights (ACOG etc.).
Definition itemoptics.c:471
ref array< float > GetOpticsDOF()
Definition itemoptics.c:548
void Init2DPreloadType()
Definition itemoptics.c:570
void SetCurrentOpticMode(int mode)
Definition itemoptics.c:520
override void OnWasAttached(EntityAI parent, int slot_id)
Definition itemoptics.c:258
override void OnInventoryExit(Man player)
Definition itemoptics.c:290
void InitCameraOverrideProperties()
Definition itemoptics.c:457
void ShowReddot(bool state)
Definition itemoptics.c:383
ItemOpticsType GetItemOpticsType()
Returns the ItemOpticsType of this ItemOptics instance.
Definition itemoptics.c:201
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition itemoptics.c:310
override void OnWorkStop()
Definition itemoptics.c:231
override void OnWasDetached(EntityAI parent, int slot_id)
Definition itemoptics.c:271
Definition enmath.c:7
script counterpart to engine's class Weapon
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
Serializer ParamsReadContext
Definition gameplay.c:15
Serializer ParamsWriteContext
Definition gameplay.c:16
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
override void SetTakeable(bool pState)
Definition itembase.c:9284
bool m_IsStoreLoad
Definition itembase.c:4966
StarlightOptic ItemOptics