Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
itemoptics.c
Go to the documentation of this file.
2{
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;
11 float m_nearplane_override; //override value for DayZPlayerCameraOptics only!
18
20 {
24
31
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
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 != "")
190 if (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 {
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
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
339 {
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)
364 else
365 m_reddot_index = GetHiddenSelectionIndex("reddot");
366
367 if (g_Game.ConfigIsExisting(path + " opticSightTexture"))
368 {
369 g_Game.ConfigGetText(path + " opticSightTexture", temp);
371 temp = "";
372 }
373 if (g_Game.ConfigIsExisting(path + " opticSightMaterial"))
374 {
375 g_Game.ConfigGetText(path + " opticSightMaterial", 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 {
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");
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 {
551 }
553 {
554 return m_mask_array;
555 }
557 {
558 return m_lens_array;
559 }
561 {
562 return m_blur_float;
563 }
564
566 {
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
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
proto native bool StepFOVDown()
sets zoom to previous (respective to current) defined value in zoom fov config array
void UpdateSelectionVisibility()
Definition itemoptics.c:587
proto native bool HasWeaponIronsightsOverride()
is weapon in optics mode or not
override void OnDebugSpawn()
Definition itemoptics.c:596
proto native void SetZeroingClampDist(float dist)
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
void OnDrawOptics2D()
Definition itemoptics.c:180
void InitReddotData()
Definition itemoptics.c:345
int GetCurrentNVType()
Definition itemoptics.c:497
void ItemOptics()
Definition itemoptics.c:19
override void OnInventoryExit(Man player)
Definition itemoptics.c:290
proto native bool SetStepFOVIndex(int step)
bool m_allowsDOF
Definition itemoptics.c:4
string m_2D_preload_type
Definition itemoptics.c:14
ref array< float > m_mask_array
Definition itemoptics.c:15
proto native float GetCurrentStepFOV()
returns fov value at current index, or 'OpticsInfo.opticsZoomInit' config value (non-zooming optics)
override void OnStoreSave(ParamsWriteContext ctx)
Definition itemoptics.c:303
bool InitOpticsDOFProperties(out array< float > temp_array)
Initializes DOF properties for optic's alternate ironsights (ACOG etc.).
Definition itemoptics.c:471
proto native float GetZeroingDistanceZoomMin()
Gets Zeroing distance at opticsZoomMin.
void ShowReddot(bool state)
Definition itemoptics.c:383
void InitOpticMode()
Definition itemoptics.c:582
void UpdateOpticsReddotVisibility()
Definition itemoptics.c:246
void OnOpticEnter()
Definition itemoptics.c:533
proto native bool StepFOVUp()
sets zoom to next defined (respective to current) value in zoom fov config array
bool m_data_set
Definition itemoptics.c:3
ref array< float > GetOpticsPPLens()
Definition itemoptics.c:556
proto native bool IsUsingWeaponIronsightsOverride()
is optics using ironsights override settings or not
override void HideSelection(string selection_name)
override void OnWorkStop()
Definition itemoptics.c:231
proto native bool EnterOptics()
switches to optics mode if possible
proto native float GetZoomInit()
gets FOV value, when entering optics
void OnOpticExit()
Definition itemoptics.c:540
proto native int GetStepFOVIndex()
returns index of currently used value in 'discretefov' config array
float GetOpticsPPBlur()
Definition itemoptics.c:560
bool IsWorking()
Definition itemoptics.c:239
ref array< float > m_OpticsDOFProperties
Definition itemoptics.c:17
string m_optic_sight_material
Definition itemoptics.c:13
string m_optic_sight_texture
Definition itemoptics.c:12
float m_blur_float
Definition itemoptics.c:10
proto native bool StepZeroingDown()
sets zeroing to previous (respective to current) defined value in zeroing config array
bool IsUsableWithNV()
Definition itemoptics.c:218
int m_CurrentOpticMode
Definition itemoptics.c:7
proto native bool UseWeaponIronsightsOverride(bool state)
proto native bool SetStepZeroing(int step)
override void OnWasDetached(EntityAI parent, int slot_id)
Definition itemoptics.c:271
override void ShowSelection(string selection_name)
proto native void GetCameraPoint(out vector pos, out vector dir)
bool IsUsingOptics2DModel()
Returns whether this ItemOptics uses the 2D optics model.
Definition itemoptics.c:207
bool InitDOFAvailability()
optics with more than 1x zoom do not allow DOF changes
Definition itemoptics.c:430
bool AllowsDOF()
returns 'true' for non-magnifying optics
Definition itemoptics.c:487
proto native float GetZoomMin()
gets FOV minimum
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition itemoptics.c:310
ref array< float > GetOpticsPPMask()
Definition itemoptics.c:552
bool IsNVOptic()
Definition itemoptics.c:492
proto native bool IsInOptics()
is weapon in optics mode or not
override void OnWorkStart()
Definition itemoptics.c:223
override void OnWasAttached(EntityAI parent, int slot_id)
Definition itemoptics.c:258
float GetNearPlaneValue()
Definition itemoptics.c:565
proto native float GetZoomMax()
gets FOV maximum
proto native int GetStepZeroing()
returns position of currently used value in zeroing config array
proto native int GetStepFOVCount()
returns number of configured steps
proto native bool StepZeroingUp()
sets zeroing to next defined (respective to current) value in zeroing config array
void SetCurrentOpticMode(int mode)
Definition itemoptics.c:520
override void OnVariablesSynchronized()
Definition itemoptics.c:334
int m_reddot_index
Definition itemoptics.c:9
proto native float GetZeroingDistanceZoomMax()
Gets Zeroing distance at opticsZoomMax.
bool IsSightOnly()
Definition itemoptics.c:213
int GetCurrentOpticMode()
Definition itemoptics.c:526
proto native bool ExitOptics()
switches out of optics mode (if possible)
void OnOpticModeChange()
optic-specific behaviour to be defined here (override)
Definition itemoptics.c:532
void Init2DPreloadType()
Definition itemoptics.c:570
ref array< float > GetOpticsDOF()
Definition itemoptics.c:548
float m_nearplane_override
Definition itemoptics.c:11
bool m_reddot_displayed bool m_isNVOptic
Definition itemoptics.c:6
int m_CurrentOpticModeLocal
Definition itemoptics.c:8
ref array< float > m_lens_array
Definition itemoptics.c:16
override void SetActions()
Definition itemoptics.c:589
void InitCameraOverrideProperties()
Definition itemoptics.c:457
void InitOpticsPPInfo()
Definition itemoptics.c:421
ItemOpticsType GetItemOpticsType()
Returns the ItemOpticsType of this ItemOptics instance.
Definition itemoptics.c:201
proto native int FindOptics2DSelection(string selectionName, bool ignoreCase=true)
Finds selection index by name.
proto native void SetOptics2DMaterial(int index, string materialName)
Set optics 2D material at provided selection index.
proto native bool IsUsingOptics2DModel()
Whether 2D model (modelOptics) is set and used for this type.
proto native void SetOptics2DTexture(int index, string textureName)
Set optics 2D model texture at provided selection index.
Definition enmath.c:7
proto bool Write(void value_out)
proto bool Read(void value_in)
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
const float DZPLAYER_CAMERA_FOV_IRONSIGHTS
Definition constants.c:983
const int OPTICS_STATE_DAY
Definition constants.c:910
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Max(float x, float y)
Returns bigger of two given values.
override void SetTakeable(bool pState)
Definition itembase.c:9284
bool m_IsStoreLoad
Definition itembase.c:4966