DayZ 1.24
Loading...
Searching...
No Matches
PoweredOptic_Base Class Reference
Collaboration diagram for PoweredOptic_Base:
[legend]

Protected Member Functions

void Rangefinder ()
 
float GetMeasurementUpdateInterval ()
 
override void OnWorkStart ()
 
override void OnWorkStop ()
 
void StartPeriodicMeasurement ()
 
void StopPeriodicMeasurement ()
 
void DoMeasurement ()
 
override void SetActions ()
 
override void OnDebugSpawn ()
 

Protected Attributes

ref Timer m_Timer
 
TextWidget m_RangeText
 

Private Member Functions

void NVGoggles ()
 
override void SetActions ()
 
override void EEItemAttached (EntityAI item, string slot_name)
 
override void EEItemDetached (EntityAI item, string slot_name)
 
override void OnWasAttached (EntityAI parent, int slot_id)
 
override void OnWasDetached (EntityAI parent, int slot_id)
 
override void OnWorkStart ()
 
override void OnWorkStop ()
 
override void OnWork (float consumed_energy)
 
void LoweredCheck ()
 
void RotateGoggles (bool state)
 
void SwitchOnNVGCheck ()
 
override int GetCurrentNVType ()
 
override bool IsNVG ()
 

Private Attributes

bool m_IsLowered
 
Clothing m_Strap
 
ref Timer m_WorkCheckTimer
 

Static Private Attributes

static const float RANGEFINDER_MAX_DISTANCE = 913.4856
 

Detailed Description

Definition at line 1 of file NVGoggles.c.

Member Function Documentation

◆ DoMeasurement()

void PoweredOptic_Base::DoMeasurement ( )
inlineprotected

Definition at line 62 of file Rangefinder.c.

63 {
65
66 if (player)
67 {
68 vector from = GetGame().GetCurrentCameraPosition();
69 vector to = from + (GetGame().GetCurrentCameraDirection() * RANGEFINDER_MAX_DISTANCE);
73
75
76 // Generate result
79
81 {
82 if (dist < 10)
83 m_RangeText.SetText("00" + dist.ToString());
84 else if (dist < 100)
85 m_RangeText.SetText("0" + dist.ToString());
86 else
87 m_RangeText.SetText(dist.ToString());
88 }
89 else
90 m_RangeText.SetText("- - -");
91 }
92 }
PlayerBase GetPlayer()
static proto bool RaycastRV(vector begPos, vector endPos, out vector contactPos, out vector contactDir, out int contactComponent, set< Object > results=NULL, Object with=NULL, Object ignore=NULL, bool sorted=false, bool ground_only=false, int iType=ObjIntersectView, float radius=0.0, CollisionFlags flags=CollisionFlags.NEARESTCONTACT)
Raycasts world by given parameters.
Definition EnMath.c:7
static const float RANGEFINDER_MAX_DISTANCE
Definition Rangefinder.c:3
TextWidget m_RangeText
Definition Rangefinder.c:6
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.

References vector::Distance(), GetGame(), GetPlayer(), RANGEFINDER_MAX_DISTANCE, DayZPhysics::RaycastRV(), and Math::Round().

◆ EEItemAttached()

override void PoweredOptic_Base::EEItemAttached ( EntityAI item,
string slot_name )
inlineprivate

Definition at line 21 of file NVGoggles.c.

22 {
23 super.EEItemAttached(item, slot_name);
24
25 if (GetCompEM().CanWork() && m_IsLowered)
26 m_WorkCheckTimer.Run(0.1, this, "SwitchOnNVGCheck", null, true);
27 //GetCompEM().SwitchOn();
28 }
ref Timer m_WorkCheckTimer
Definition NVGoggles.c:5

◆ EEItemDetached()

override void PoweredOptic_Base::EEItemDetached ( EntityAI item,
string slot_name )
inlineprivate

Definition at line 30 of file NVGoggles.c.

31 {
32 super.EEItemDetached(item, slot_name);
33
34 GetCompEM().SwitchOff();
35 }

◆ GetCurrentNVType()

override int PoweredOptic_Base::GetCurrentNVType ( )
inlineprivate

Definition at line 160 of file NVGoggles.c.

161 {
162 if (IsWorking())
163 {
164 //m_CurrentOpticMode
165 switch (m_CurrentOpticMode)
166 {
167 /*case GameConstants.OPTICS_STATE_DAY:
168 return NVTypes.NV_GOGGLES_WHATEVER;
169
170 case GameConstants.OPTICS_STATE_NIGHTVISION:
171 return NVTypes.NV_GOGGLES;*/
172 default:
173 return NVTypes.NV_GOGGLES;
174 }
175 Error("Undefined optic mode of " + this);
176 return NVTypes.NONE;
177 }
178 else
179 return NVTypes.NV_GOGGLES_OFF;
180 }
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90

References Error().

◆ GetMeasurementUpdateInterval()

float PoweredOptic_Base::GetMeasurementUpdateInterval ( )
inlineprotected

Definition at line 13 of file Rangefinder.c.

14 {
15 return 0.5;
16 }

Referenced by StartPeriodicMeasurement().

◆ IsNVG()

override bool PoweredOptic_Base::IsNVG ( )
inlineprivate

Definition at line 182 of file NVGoggles.c.

183 {
184 return true;
185 }

◆ LoweredCheck()

void PoweredOptic_Base::LoweredCheck ( )
inlineprivate

Definition at line 125 of file NVGoggles.c.

126 {
127 if (GetAnimationPhase("rotate") != m_IsLowered)
128 m_IsLowered = GetAnimationPhase("rotate");
129 }

◆ NVGoggles()

void PoweredOptic_Base::NVGoggles ( )
inlineprivate

Definition at line 7 of file NVGoggles.c.

8 {
9 RotateGoggles(true);
11 }
void RotateGoggles(bool state)
Definition NVGoggles.c:131

References RotateGoggles().

◆ OnDebugSpawn()

override void PoweredOptic_Base::OnDebugSpawn ( )
inlineprotected

Definition at line 102 of file Rangefinder.c.

103 {
104 GetInventory().CreateInInventory("Battery9V");
105 }

◆ OnWasAttached()

override void PoweredOptic_Base::OnWasAttached ( EntityAI parent,
int slot_id )
inlineprivate

Definition at line 37 of file NVGoggles.c.

38 {
39 super.OnWasAttached(parent, slot_id);
40 RotateGoggles(true);
41
42 m_Strap = Clothing.Cast(parent);
43 /*if (m_Strap)
44 SetPlayer(PlayerBase.Cast(m_Strap.GetHierarchyParent()));*/
45 }
Clothing m_Strap
Definition NVGoggles.c:4

References RotateGoggles().

◆ OnWasDetached()

override void PoweredOptic_Base::OnWasDetached ( EntityAI parent,
int slot_id )
inlineprivate

Definition at line 47 of file NVGoggles.c.

48 {
49 super.OnWasDetached(parent, slot_id);
50 RotateGoggles(true);
51
53 if (m_Strap == parent && PlayerBase.CastTo(player, parent.GetHierarchyRootPlayer()))
54 {
55 if (parent && Clothing.Cast(parent))
56 Clothing.Cast(parent).UpdateNVGStatus(player, false, true);
57 }
58
59 m_Strap = null;
60 //SetPlayer(null);
61 }

References RotateGoggles().

◆ OnWork()

override void PoweredOptic_Base::OnWork ( float consumed_energy)
inlineprivate

Definition at line 103 of file NVGoggles.c.

104 {
105 //adjust on load - ComponentEnergyManager stores the 'working' state independently
106 if (!m_IsLowered)
107 RotateGoggles(false);
108
112 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
113 {
114 headgear = player.FindAttachmentBySlotName("Headgear");
115 glasses = player.FindAttachmentBySlotName("Eyewear");
116
117 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
118 {
119 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
120 player.AddActiveNV(NVTypes.NV_GOGGLES);
121 }
122 }
123 }

References GetGame(), and RotateGoggles().

◆ OnWorkStart() [1/2]

override void PoweredOptic_Base::OnWorkStart ( )
inlineprivate

Definition at line 63 of file NVGoggles.c.

64 {
68 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
69 {
70 headgear = player.FindAttachmentBySlotName("Headgear");
71 glasses = player.FindAttachmentBySlotName("Eyewear");
72
73 //adjust on load - ComponentEnergyManager stores the 'working' state independently
74 if (!m_IsLowered)
75 RotateGoggles(false);
76
77 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
78 {
79 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
80 player.AddActiveNV(NVTypes.NV_GOGGLES);
81 }
82 }
83 }

References GetGame(), and RotateGoggles().

◆ OnWorkStart() [2/2]

override void PoweredOptic_Base::OnWorkStart ( )
inlineprotected

Definition at line 18 of file Rangefinder.c.

19 {
20 if (!GetGame().IsDedicatedServer())
21 {
23 PlayerBase player_owner = PlayerBase.Cast(GetHierarchyRootPlayer());
24
27 }
28 }
void StartPeriodicMeasurement()
Definition Rangefinder.c:42

References GetGame(), GetPlayer(), and StartPeriodicMeasurement().

◆ OnWorkStop() [1/2]

override void PoweredOptic_Base::OnWorkStop ( )
inlineprivate

Definition at line 85 of file NVGoggles.c.

86 {
90 if (m_Strap && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent()))
91 {
92 headgear = player.FindAttachmentBySlotName("Headgear");
93 glasses = player.FindAttachmentBySlotName("Eyewear");
94
95 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
96 {
97 if ((headgear == m_Strap || glasses == m_Strap) && player.IsControlledPlayer())
98 player.RemoveActiveNV(NVTypes.NV_GOGGLES);
99 }
100 }
101 }

References GetGame().

◆ OnWorkStop() [2/2]

override void PoweredOptic_Base::OnWorkStop ( )
inlineprotected

Definition at line 30 of file Rangefinder.c.

31 {
32 if (!GetGame().IsDedicatedServer())
33 {
35 PlayerBase player_owner = PlayerBase.Cast(GetHierarchyRootPlayer());
36
39 }
40 }
void StopPeriodicMeasurement()
Definition Rangefinder.c:52

References GetGame(), GetPlayer(), and StopPeriodicMeasurement().

◆ Rangefinder()

void PoweredOptic_Base::Rangefinder ( )
inlineprotected

Definition at line 8 of file Rangefinder.c.

9 {
10 }

◆ RotateGoggles()

void PoweredOptic_Base::RotateGoggles ( bool state)
inlineprivate

Definition at line 131 of file NVGoggles.c.

132 {
133 //if ( GetAnimationPhase("rotate") != state ) //useless?
134 SetAnimationPhase("rotate", !state);
136
138 int slot_id;
139 string slot_name;
140 if (m_Strap && m_Strap.GetInventory().GetCurrentAttachmentSlotInfo(slot_id, slot_name) && PlayerBase.CastTo(player, m_Strap.GetHierarchyParent())/*&& slot_id == InventorySlots.EYEWEAR*/)
141 player.SetNVGLowered(m_IsLowered);
142
143 if (GetCompEM())
144 {
145 if (!state && GetCompEM().CanWork())
146 GetCompEM().SwitchOn();
147 else
148 GetCompEM().SwitchOff();
149 }
150 }

Referenced by NVGoggles(), OnWasAttached(), OnWasDetached(), OnWork(), and OnWorkStart().

◆ SetActions() [1/2]

override void PoweredOptic_Base::SetActions ( )
inlineprivate

Definition at line 13 of file NVGoggles.c.

14 {
15 super.SetActions();
16
19 }
void AddAction(typename actionName)
void RemoveAction(typename actionName)

References AddAction(), and RemoveAction().

◆ SetActions() [2/2]

override void PoweredOptic_Base::SetActions ( )
inlineprotected

Definition at line 94 of file Rangefinder.c.

95 {
96 super.SetActions();
97
100 }

References AddAction(), and RemoveAction().

◆ StartPeriodicMeasurement()

void PoweredOptic_Base::StartPeriodicMeasurement ( )
inlineprotected

Definition at line 42 of file Rangefinder.c.

43 {
44 if (!m_Timer)
46
47 m_RangeText = TextWidget.Cast(GetGame().GetWorkspace().CreateWidgets("gui/layouts/gameplay/rangefinder_hud.layout"));
48
49 m_Timer.Run(GetMeasurementUpdateInterval(), this, "DoMeasurement", null, true);
50 }
ref Timer m_Timer
Definition Rangefinder.c:5
float GetMeasurementUpdateInterval()
Definition Rangefinder.c:13
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10

References CALL_CATEGORY_GAMEPLAY, GetGame(), GetMeasurementUpdateInterval(), and m_Timer.

Referenced by OnWorkStart().

◆ StopPeriodicMeasurement()

void PoweredOptic_Base::StopPeriodicMeasurement ( )
inlineprotected

Definition at line 52 of file Rangefinder.c.

53 {
54 if (m_Timer)
55 m_Timer.Stop();
56
57 if (m_RangeText)
58 delete m_RangeText;
59 }

References m_RangeText, and m_Timer.

Referenced by OnWorkStop().

◆ SwitchOnNVGCheck()

void PoweredOptic_Base::SwitchOnNVGCheck ( )
inlineprivate

Definition at line 152 of file NVGoggles.c.

153 {
154 //Print("SwitchOnNVGCheck");
155 GetCompEM().SwitchOn();
156 if (GetCompEM().IsSwitchedOn())
157 m_WorkCheckTimer.Stop();
158 }

Member Data Documentation

◆ m_IsLowered

bool PoweredOptic_Base::m_IsLowered
private

Definition at line 3 of file NVGoggles.c.

◆ m_RangeText

TextWidget PoweredOptic_Base::m_RangeText
protected

Definition at line 6 of file Rangefinder.c.

Referenced by StopPeriodicMeasurement().

◆ m_Strap

Clothing PoweredOptic_Base::m_Strap
private

Definition at line 4 of file NVGoggles.c.

◆ m_Timer

ref Timer PoweredOptic_Base::m_Timer
protected

Definition at line 5 of file Rangefinder.c.

◆ m_WorkCheckTimer

ref Timer PoweredOptic_Base::m_WorkCheckTimer
private

Definition at line 5 of file NVGoggles.c.

◆ RANGEFINDER_MAX_DISTANCE

const float PoweredOptic_Base::RANGEFINDER_MAX_DISTANCE = 913.4856
staticprivate

Definition at line 3 of file Rangefinder.c.

Referenced by DoMeasurement().


The documentation for this class was generated from the following files: