Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
25  InitReddotData();
26  InitOpticsPPInfo();
27  InitCameraOverrideProperties();
28  InitOpticsDOFProperties(m_OpticsDOFProperties);
29  Init2DPreloadType();
30  InitOpticMode();
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 
176  override void OnWorkStart()
177  {
178  if (!GetGame().IsDedicatedServer())
179  {
180  ShowReddot(true);
181  }
182  }
183 
184  override void OnWorkStop()
185  {
186  if (!GetGame().IsDedicatedServer())
187  {
188  ShowReddot(false);
189  }
190  }
191 
192  bool IsWorking()
193  {
194  if (GetCompEM() && GetCompEM().CanWork())
195  return true;
196  return false;
197  }
198 
199  void UpdateOpticsReddotVisibility()
200  {
201  if (IsWorking() && !m_reddot_displayed)
202  {
203  ShowReddot(true);
204  }
205  else if (!IsWorking() && m_reddot_displayed)
206  {
207  ShowReddot(false);
208  }
209  }
210 
211  override void OnWasAttached( EntityAI parent, int slot_id )
212  {
213  super.OnWasAttached(parent, slot_id);
214 
215  SetTakeable(false);
216 
217  Weapon wep;
218  if (Class.CastTo(wep,parent))
219  {
220  SetZeroingClampDist(wep.GetZeroingClamp(wep.GetCurrentMuzzle()));
221  }
222  }
223 
224  override void OnWasDetached( EntityAI parent, int slot_id )
225  {
226  super.OnWasDetached(parent, slot_id);
227 
228  PlayerBase player;
229  if (PlayerBase.CastTo(player, GetHierarchyRootPlayer()))
230  {
231  player.SetReturnToOptics(false);
232  }
233 
234  SetTakeable(true);
235 
236  Weapon wep;
237  if (Class.CastTo(wep,parent))
238  {
239  SetZeroingClampDist(0.0);
240  }
241  }
242 
243  override void OnInventoryExit(Man player)
244  {
245  super.OnInventoryExit(player);
246 
247  PlayerBase playerPB;
248  if (PlayerBase.CastTo(playerPB, player))
249  {
250  playerPB.SetReturnToOptics(false);
251  }
252 
253  SetTakeable(true);
254  }
255 
256  override void OnStoreSave(ParamsWriteContext ctx)
257  {
258  super.OnStoreSave(ctx);
259 
260  ctx.Write(m_CurrentOpticMode);
261  }
262 
263  override bool OnStoreLoad(ParamsReadContext ctx, int version)
264  {
265  if ( !super.OnStoreLoad(ctx,version) )
266  {
267  return false;
268  }
269  m_IsStoreLoad = true;
270 
271  if ( version >= 126 )
272  {
273  if ( !ctx.Read(m_CurrentOpticMode) )
274  {
275  m_IsStoreLoad = false;
276  return false;
277  }
278  }
279 
280  OnOpticModeChange();
281  SetSynchDirty();
282 
283  m_IsStoreLoad = false;
284  return true;
285  }
286 
287  override void OnVariablesSynchronized()
288  {
289  super.OnVariablesSynchronized();
290 
291  if (m_CurrentOpticModeLocal != m_CurrentOpticMode)
292  {
293  OnOpticModeChange();
294  m_CurrentOpticModeLocal = m_CurrentOpticMode;
295  }
296  }
297 
298  void InitReddotData()
299  {
300  string path = "cfgVehicles " + GetType() + " OpticsInfo";
301  string temp;
302 
303  if (GetGame().ConfigIsExisting(path))
304  {
305  m_reddot_index = GetHiddenSelectionIndex("reddot");
306  if (GetGame().ConfigIsExisting(path + " opticSightTexture"))
307  {
308  GetGame().ConfigGetText(path + " opticSightTexture", temp);
309  m_optic_sight_texture = temp;
310  temp = "";
311  }
312  if (GetGame().ConfigIsExisting(path + " opticSightMaterial"))
313  {
314  GetGame().ConfigGetText(path + " opticSightMaterial", temp);
315  m_optic_sight_material = temp;
316  temp = "";
317  }
318  }
319  m_data_set = true;
320  }
321 
322  void ShowReddot(bool state)
323  {
324  if (GetGame().IsDedicatedServer())
325  {
326  ErrorEx("should not be called on the server!",ErrorExSeverity.INFO);
327  return;
328  }
329 
330  if (!m_data_set)
331  {
332  InitReddotData();
333  }
334 
335  // does not have reddot
336  if (m_reddot_index == -1)
337  {
338  return;
339  }
340 
341  if (state)
342  {
343  if (m_optic_sight_texture != "")
344  SetObjectTexture(m_reddot_index, m_optic_sight_texture);
345  if (m_optic_sight_material != "")
346  SetObjectMaterial(m_reddot_index, m_optic_sight_material);
347  }
348  else
349  {
350  SetObjectTexture(m_reddot_index, "");
351  SetObjectMaterial(m_reddot_index, "");
352  }
353  m_reddot_displayed = state;
354  }
355 
356  void InitOpticsPPInfo()
357  {
358  m_allowsDOF = InitDOFAvailability();
359  InitOpticsPP(m_mask_array, m_lens_array, m_blur_float);
360 
361  m_isNVOptic = ConfigGetBool("NVOptic");
362  }
363 
365  bool InitDOFAvailability()
366  {
367  float fov_max;
368  string path = "cfgVehicles " + GetType() + " OpticsInfo";
369 
370  /*
371  Weapon_Base weapon = Weapon_Base.Cast(GetHierarchyParent());
372  if (!weapon)
373  return false; // no DOF for handheld optics
374  */
375  fov_max = GetGame().ConfigGetFloat(path + " opticsZoomMax");
376  if (fov_max >= GameConstants.DZPLAYER_CAMERA_FOV_IRONSIGHTS)
377  {
378  return true;
379  }
380  return false;
381  }
382 
384  void InitOpticsPP(out array<float> mask_array, out array<float> lens_array, out float blur_float)
385  {
386  string path = "cfgVehicles " + GetType() + " OpticsInfo";
387  GetGame().ConfigGetFloatArray(path + " PPMaskProperties", mask_array);
388  GetGame().ConfigGetFloatArray(path + " PPLensProperties", lens_array);
389  blur_float = GetGame().ConfigGetFloat(path + " PPBlurProperties");
390  }
391 
392  void InitCameraOverrideProperties()
393  {
394  string path = "cfgVehicles " + GetType() + " OpticsInfo";
395  if ( GetGame().ConfigIsExisting(path + " nearPlaneDistanceOverride") )
396  {
397  m_nearplane_override = Math.Max(GetGame().ConfigGetFloat(path + " nearPlaneDistanceOverride"),DayZPlayerCameraBase.CONST_NEARPLANE_OPTICS_MIN);
398  }
399  else
400  {
401  m_nearplane_override = DayZPlayerCameraOptics.CONST_NEARPLANE_OPTICS;
402  }
403  }
404 
406  bool InitOpticsDOFProperties (out array<float> temp_array)
407  {
408  if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties"))
409  {
410  GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties", temp_array);
411  return true;
412  }
413  else if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties"))
414  {
415  GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties", temp_array);
416  return true;
417  }
418  return false;
419  }
420 
422  bool AllowsDOF()
423  {
424  return m_allowsDOF;
425  }
426 
427  bool IsNVOptic()
428  {
429  return m_isNVOptic;
430  }
431 
432  int GetCurrentNVType()
433  {
434  /*
435  //TODO - implement this into NV optics and modify (KazuarOptic example below)
436  if (IsWorking())
437  {
438  switch (m_CurrentOpticMode)
439  {
440  case GameConstants.OPTICS_STATE_DAY:
441  return NVTypes.NV_OPTICS_KAZUAR_DAY;
442 
443  case GameConstants.OPTICS_STATE_NIGHTVISION:
444  return NVTypes.NV_OPTICS_KAZUAR_NIGHT;
445  }
446  }
447  else
448  {
449  return NVTypes.NV_OPTICS_OFF;
450  }
451  */
452  return NVTypes.NONE;
453  }
454 
455  void SetCurrentOpticMode(int mode)
456  {
457  m_CurrentOpticMode = mode;
458  OnOpticModeChange();
459  }
460 
461  int GetCurrentOpticMode()
462  {
463  return m_CurrentOpticMode;
464  }
465 
467  void OnOpticModeChange(){}
468  void OnOpticEnter()
469  {
470  if ( GetGame() && !GetGame().IsDedicatedServer() )
471  {
472  HideSelection("hide");
473  }
474  }
475  void OnOpticExit()
476  {
477  if ( GetGame() && !GetGame().IsDedicatedServer() )
478  {
479  ShowSelection("hide");
480  }
481  }
482 
483  ref array<float> GetOpticsDOF()
484  {
485  return m_OpticsDOFProperties;
486  }
487  ref array<float> GetOpticsPPMask()
488  {
489  return m_mask_array;
490  }
491  ref array<float> GetOpticsPPLens()
492  {
493  return m_lens_array;
494  }
495  float GetOpticsPPBlur()
496  {
497  return m_blur_float;
498  }
499 
500  float GetNearPlaneValue()
501  {
502  return m_nearplane_override;
503  }
504 
505  void Init2DPreloadType()
506  {
507  string path = "cfgVehicles " + GetType() + " OpticsInfo preloadOpticType";
508  string type_2d;
509 
510  if ( GetGame().ConfigIsExisting(path) )
511  {
512  GetGame().ConfigGetText(path, type_2d);
513  m_2D_preload_type = type_2d;
514  }
515  }
516 
517  void InitOpticMode()
518  {
519  SetCurrentOpticMode(GameConstants.OPTICS_STATE_DAY);
520  }
521 
522  void UpdateSelectionVisibility() {}
523 
524  override void SetActions()
525  {
526  super.SetActions();
527 
529  }
530 
531  override void OnDebugSpawn()
532  {
533  GetInventory().CreateAttachment("Battery9V");
534  }
535 }
536 
537 typedef ItemOptics OpticBase;
538 
539 
GetGame
proto native CGame GetGame()
m_IsStoreLoad
bool m_IsStoreLoad
Definition: itembase.c:64
Weapon
script counterpart to engine's class Weapon
Definition: inventoryitem.c:48
DayZPlayerCameraOptics
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
Definition: dayzplayercameraironsights.c:365
ErrorEx
enum ShapeType ErrorEx
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
NVTypes
NVTypes
Definition: dayzplayercamera_base.c:54
ActionViewOptics
Definition: actionviewoptics.c:1
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
array< float >
InventoryItemSuper
Definition: inventoryitem.c:3
DayZPlayerCameraBase
this is main camera class
Definition: dayzplayercamera1stperson.c:4
GameConstants
Definition: constants.c:612
ItemOptics
Definition: itemoptics.c:1
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5
GetType
override int GetType()
Definition: huddebugwincharagents.c:49
path
string path
Definition: optionselectormultistate.c:135