DayZ 1.24
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)
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
41
47
53
59
65
71
76
82
89
95
101
106
112
119
126
133
139
145
151
157
163
169
175
176 override void OnWorkStart()
177 {
178 if (!GetGame().IsDedicatedServer())
179 ShowReddot(true);
180 }
181
182 override void OnWorkStop()
183 {
184 if (!GetGame().IsDedicatedServer())
185 ShowReddot(false);
186 }
187
189 {
190 if (GetCompEM() && GetCompEM().CanWork())
191 return true;
192 return false;
193 }
194
196 {
198 ShowReddot(true);
199 else if (!IsWorking() && m_reddot_displayed)
200 ShowReddot(false);
201 }
202
203 override void OnWasAttached(EntityAI parent, int slot_id)
204 {
205 super.OnWasAttached(parent, slot_id);
206
207 SetTakeable(false);
208
209 Weapon wep;
210 if (Class.CastTo(wep, parent))
211 SetZeroingClampDist(wep.GetZeroingClamp(wep.GetCurrentMuzzle()));
212 }
213
214 override void OnWasDetached(EntityAI parent, int slot_id)
215 {
216 super.OnWasDetached(parent, slot_id);
217
219 if (PlayerBase.CastTo(player, GetHierarchyRootPlayer()))
220 player.SetReturnToOptics(false);
221
222 SetTakeable(true);
223
224 Weapon wep;
225 if (Class.CastTo(wep, parent))
227 }
228
229 override void OnInventoryExit(Man player)
230 {
231 super.OnInventoryExit(player);
232
234 if (PlayerBase.CastTo(playerPB, player))
235 playerPB.SetReturnToOptics(false);
236
237 SetTakeable(true);
238 }
239
241 {
242 super.OnStoreSave(ctx);
243
244 ctx.Write(m_CurrentOpticMode);
245 }
246
247 override bool OnStoreLoad(ParamsReadContext ctx, int version)
248 {
249 if (!super.OnStoreLoad(ctx, version))
250 return false;
251 m_IsStoreLoad = true;
252
253 if (version >= 126)
254 {
255 if (!ctx.Read(m_CurrentOpticMode))
256 {
257 m_IsStoreLoad = false;
258 return false;
259 }
260 }
261
263 SetSynchDirty();
264
265 m_IsStoreLoad = false;
266 return true;
267 }
268
270 {
271 super.OnVariablesSynchronized();
272
274 {
277 }
278 }
279
281 {
282 string path = "cfgVehicles " + GetType() + " OpticsInfo";
283 string temp;
284
285 if (GetGame().ConfigIsExisting(path))
286 {
287 m_reddot_index = GetHiddenSelectionIndex("reddot");
288 if (GetGame().ConfigIsExisting(path + " opticSightTexture"))
289 {
290 GetGame().ConfigGetText(path + " opticSightTexture", temp);
292 temp = "";
293 }
294 if (GetGame().ConfigIsExisting(path + " opticSightMaterial"))
295 {
296 GetGame().ConfigGetText(path + " opticSightMaterial", temp);
298 temp = "";
299 }
300 }
301 m_data_set = true;
302 }
303
304 void ShowReddot(bool state)
305 {
306 if (GetGame().IsDedicatedServer())
307 {
308 ErrorEx("should not be called on the server!", ErrorExSeverity.INFO);
309 return;
310 }
311
312 if (!m_data_set)
314
315 // does not have reddot
316 if (m_reddot_index == -1)
317 return;
318
319 if (state)
320 {
321 if (m_optic_sight_texture != "")
322 SetObjectTexture(m_reddot_index, m_optic_sight_texture);
323 if (m_optic_sight_material != "")
324 SetObjectMaterial(m_reddot_index, m_optic_sight_material);
325 }
326 else
327 {
328 SetObjectTexture(m_reddot_index, "");
329 SetObjectMaterial(m_reddot_index, "");
330 }
332 }
333
335 {
338
339 m_isNVOptic = ConfigGetBool("NVOptic");
340 }
341
344 {
345 float fov_max;
346 string path = "cfgVehicles " + GetType() + " OpticsInfo";
347
348 /*
349 Weapon_Base weapon = Weapon_Base.Cast(GetHierarchyParent());
350 if (!weapon)
351 return false; // no DOF for handheld optics
352 */
353 fov_max = GetGame().ConfigGetFloat(path + " opticsZoomMax");
355 return true;
356 return false;
357 }
358
361 {
362 string path = "cfgVehicles " + GetType() + " OpticsInfo";
363 GetGame().ConfigGetFloatArray(path + " PPMaskProperties", mask_array);
364 GetGame().ConfigGetFloatArray(path + " PPLensProperties", lens_array);
365 blur_float = GetGame().ConfigGetFloat(path + " PPBlurProperties");
366 }
367
369 {
370 string path = "cfgVehicles " + GetType() + " OpticsInfo";
371 if (GetGame().ConfigIsExisting(path + " nearPlaneDistanceOverride"))
372 m_nearplane_override = Math.Max(GetGame().ConfigGetFloat(path + " nearPlaneDistanceOverride"), DayZPlayerCameraBase.CONST_NEARPLANE_OPTICS_MIN);
373 else
374 m_nearplane_override = DayZPlayerCameraOptics.CONST_NEARPLANE_OPTICS;
375 }
376
379 {
380 if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties"))
381 {
382 GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfo PPDOFProperties", temp_array);
383 return true;
384 }
385 else if (GetGame().ConfigIsExisting("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties"))
386 {
387 GetGame().ConfigGetFloatArray("cfgVehicles " + GetType() + " OpticsInfoWeaponOverride PPDOFProperties", temp_array);
388 return true;
389 }
390 return false;
391 }
392
395 {
396 return m_allowsDOF;
397 }
398
400 {
401 return m_isNVOptic;
402 }
403
405 {
406 /*
407 //TODO - implement this into NV optics and modify (KazuarOptic example below)
408 if (IsWorking())
409 {
410 switch (m_CurrentOpticMode)
411 {
412 case GameConstants.OPTICS_STATE_DAY:
413 return NVTypes.NV_OPTICS_KAZUAR_DAY;
414
415 case GameConstants.OPTICS_STATE_NIGHTVISION:
416 return NVTypes.NV_OPTICS_KAZUAR_NIGHT;
417 }
418 }
419 else
420 {
421 return NVTypes.NV_OPTICS_OFF;
422 }
423 */
424 return NVTypes.NONE;
425 }
426
432
434 {
435 return m_CurrentOpticMode;
436 }
437
441 {
442 if (GetGame() && !GetGame().IsDedicatedServer())
443 HideSelection("hide");
444 }
446 {
447 if (GetGame() && !GetGame().IsDedicatedServer())
448 ShowSelection("hide");
449 }
450
456 {
457 return m_mask_array;
458 }
460 {
461 return m_lens_array;
462 }
464 {
465 return m_blur_float;
466 }
467
469 {
471 }
472
474 {
475 string path = "cfgVehicles " + GetType() + " OpticsInfo preloadOpticType";
476 string type_2d;
477
478 if (GetGame().ConfigIsExisting(path))
479 {
480 GetGame().ConfigGetText(path, type_2d);
482 }
483 }
484
489
491
492 override void SetActions()
493 {
494 super.SetActions();
495
497 }
498
499 override void OnDebugSpawn()
500 {
501 GetInventory().CreateAttachment("Battery9V");
502 }
503}
504
505typedef ItemOptics OpticBase;
506
eBleedingSourceType GetType()
void AddAction(typename actionName)
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
bool m_IsStoreLoad
Definition ItemBase.c:4743
Super root of all classes in Enforce script.
Definition EnScript.c:11
this is main camera class
proto native bool SetStepZeroing(int step)
void OnOpticModeChange()
optic-specific behaviour to be defined here (override)
Definition ItemOptics.c:439
proto native bool IsUsingWeaponIronsightsOverride()
is optics using ironsights override settings or not
proto native float GetZeroingDistanceZoomMax()
Gets Zeroing distance at opticsZoomMax.
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:360
bool m_allowsDOF
Definition ItemOptics.c:4
proto native float GetZeroingDistanceZoomMin()
Gets Zeroing distance at opticsZoomMin.
proto native bool ExitOptics()
switches out of optics mode (if possible)
override void OnDebugSpawn()
Definition ItemOptics.c:499
proto native bool StepFOVDown()
sets zoom to previous (respective to current) defined value in zoom fov config array
int m_reddot_index
Definition ItemOptics.c:9
proto native float GetZoomInit()
gets FOV value, when entering optics
int m_CurrentOpticModeLocal
Definition ItemOptics.c:8
void InitOpticMode()
Definition ItemOptics.c:485
string m_2D_preload_type
Definition ItemOptics.c:14
void OnOpticExit()
Definition ItemOptics.c:445
override void OnWorkStart()
Definition ItemOptics.c:176
void InitReddotData()
Definition ItemOptics.c:280
int GetCurrentOpticMode()
Definition ItemOptics.c:433
ref array< float > GetOpticsPPLens()
Definition ItemOptics.c:459
bool IsWorking()
Definition ItemOptics.c:188
bool m_reddot_displayed bool m_isNVOptic
Definition ItemOptics.c:6
override void OnStoreSave(ParamsWriteContext ctx)
Definition ItemOptics.c:240
proto native bool EnterOptics()
switches to optics mode if possible
bool AllowsDOF()
returns 'true' for non-magnifying optics
Definition ItemOptics.c:394
int GetCurrentNVType()
Definition ItemOptics.c:404
proto native int GetStepZeroing()
returns position of currently used value in zeroing config array
ref array< float > GetOpticsPPMask()
Definition ItemOptics.c:455
proto native float GetZoomMin()
gets FOV minimum
proto native bool IsInOptics()
is weapon in optics mode or not
float GetNearPlaneValue()
Definition ItemOptics.c:468
proto native bool UseWeaponIronsightsOverride(bool state)
switches into ironsights override settings
void OnOpticEnter()
Definition ItemOptics.c:440
proto native bool SetStepFOVIndex(int step)
sets zoom to fov value defined at given in 'discretefov' config array
ref array< float > m_mask_array
Definition ItemOptics.c:15
override void ShowSelection(string selection_name)
void UpdateOpticsReddotVisibility()
Definition ItemOptics.c:195
proto native float GetZoomMax()
gets FOV maximum
proto native void SetZeroingClampDist(float dist)
Sets zeroing clamp for the optics and updates the clamp if dist > 0. Used when attached to weapon.
proto native float GetCurrentStepFOV()
returns fov value at current index, or 'OpticsInfo.opticsZoomInit' config value (non-zooming optics)
void UpdateSelectionVisibility()
Definition ItemOptics.c:490
bool m_data_set
Definition ItemOptics.c:3
override void HideSelection(string selection_name)
bool InitDOFAvailability()
optics with more than 1x zoom do not allow DOF changes
Definition ItemOptics.c:343
void InitOpticsPPInfo()
Definition ItemOptics.c:334
float GetOpticsPPBlur()
Definition ItemOptics.c:463
override void OnVariablesSynchronized()
Definition ItemOptics.c:269
int m_CurrentOpticMode
Definition ItemOptics.c:7
override void SetActions()
Definition ItemOptics.c:492
float m_blur_float
Definition ItemOptics.c:10
bool IsNVOptic()
Definition ItemOptics.c:399
ref array< float > m_OpticsDOFProperties
Definition ItemOptics.c:17
bool InitOpticsDOFProperties(out array< float > temp_array)
Initializes DOF properties for optic's alternate ironsights (ACOG etc.)
Definition ItemOptics.c:378
proto native void GetCameraPoint(out vector pos, out vector dir)
gets camera position & direction in model space of optics entity
ref array< float > GetOpticsDOF()
Definition ItemOptics.c:451
void Init2DPreloadType()
Definition ItemOptics.c:473
void SetCurrentOpticMode(int mode)
Definition ItemOptics.c:427
proto native bool StepZeroingDown()
sets zeroing to previous (respective to current) defined value in zeroing config array
proto native int GetStepFOVIndex()
returns index of currently used value in 'discretefov' config array
override void OnWasAttached(EntityAI parent, int slot_id)
Definition ItemOptics.c:203
string m_optic_sight_material
Definition ItemOptics.c:13
void ItemOptics()
Definition ItemOptics.c:19
override void OnInventoryExit(Man player)
Definition ItemOptics.c:229
float m_nearplane_override
Definition ItemOptics.c:11
void InitCameraOverrideProperties()
Definition ItemOptics.c:368
void ShowReddot(bool state)
Definition ItemOptics.c:304
proto native bool HasWeaponIronsightsOverride()
is weapon in optics mode or not
proto native bool StepZeroingUp()
sets zeroing to next defined (respective to current) value in zeroing config array
ref array< float > m_lens_array
Definition ItemOptics.c:16
proto native int GetStepFOVCount()
returns number of configured steps
proto native bool StepFOVUp()
sets zoom to next defined (respective to current) value in zoom fov config array
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition ItemOptics.c:247
override void OnWorkStop()
Definition ItemOptics.c:182
string m_optic_sight_texture
Definition ItemOptics.c:12
override void OnWasDetached(EntityAI parent, int slot_id)
Definition ItemOptics.c:214
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
script counterpart to engine's class Weapon
proto native CGame GetGame()
ErrorExSeverity
Definition EnDebug.c:62
enum ShapeType ErrorEx
const float DZPLAYER_CAMERA_FOV_IRONSIGHTS
Definition constants.c:836
const int OPTICS_STATE_DAY
Definition constants.c:800
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.