Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_2DSightsComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Weapon/Sights", description: "", color: "0 0 255 255")]
3{
4 [Attribute("0", UIWidgets.CheckBox, "Should hide parent of parent object when using 2D sights", category: "2DSights")]
6
7 //------------------------------------------------------------------------------------------------
12}
13
14//------------------------------------------------------------------------------------------------
15class SCR_2DSightsComponent : SCR_2DOpticsComponent
16{
18
19 protected static bool s_bIsUsingSights;
20
21 //------------------------------------------------------------------------------------------------
22 static bool IsUsingSights()
23 {
24 return s_bIsUsingSights;
25 }
26
27 //------------------------------------------------------------------------------------------------
28 protected void RegisterInputs()
29 {
30 // Clear previous inputs for safety sake
32
33 // Zoom
34 GetGame().GetInputManager().AddActionListener(ACTION_ZOOM_IN, EActionTrigger.DOWN, ActionZoomIn);
35 GetGame().GetInputManager().AddActionListener(ACTION_ZOOM_OUT, EActionTrigger.DOWN, ActionZoomOut);
36
37 // Illumination
38 GetGame().GetInputManager().AddActionListener(ACTION_ILLUMINATION, EActionTrigger.DOWN, ToggleIllumination);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 protected void UnregisterInputs()
43 {
44 // Zoom
45 GetGame().GetInputManager().RemoveActionListener(ACTION_ZOOM_IN, EActionTrigger.DOWN, ActionZoomIn);
46 GetGame().GetInputManager().RemoveActionListener(ACTION_ZOOM_OUT, EActionTrigger.DOWN, ActionZoomOut);
47
48 // Illumination
49 GetGame().GetInputManager().RemoveActionListener(ACTION_ILLUMINATION, EActionTrigger.DOWN, ToggleIllumination);
50 }
51
52 //------------------------------------------------------------------------------------------------
53 protected override void HandleSightActivation()
54 {
55 super.HandleSightActivation();
56
57 // Set fov
58 if (!m_SightsFovInfo)
59 {
60 m_SightsFovInfo = SCR_SightsZoomFOVInfo.Cast(GetFOVInfo());
62 }
63
64 SelectZoomLevel(m_iSelectedZoomLevel);
65
66 s_bIsUsingSights = true;
67
68 // Set parent
69 IEntity owner = GetOwner();
70 if (!owner)
71 return;
72
74
75 IEntity parent = owner.GetParent();
76 if (data && data.ShouldHideParentObject())
77 {
78 owner.ClearFlags(EntityFlags.VISIBLE, false);
79 if (parent && data.ShouldHideParentParentObject())
80 parent.ClearFlags(EntityFlags.VISIBLE, false);
81 }
82
84 if (turretController)
85 {
86 BaseCompartmentSlot slot = turretController.GetCompartmentSlot();
87 if (slot)
88 m_ParentCharacter = ChimeraCharacter.Cast(slot.GetOccupant());
89 }
90 else
91 {
92 while (parent)
93 {
94 m_ParentCharacter = ChimeraCharacter.Cast(parent);
95 if (m_ParentCharacter)
96 break;
97
98 parent = parent.GetParent();
99 }
100 }
101 }
102
103 //------------------------------------------------------------------------------------------------
104 protected override void HandleSightDeactivation()
105 {
106 IEntity owner = GetOwner();
108 if (!data)
109 return;
110
111 if (data.ShouldHideParentObject() && owner && !owner.IsDeleted())
112 {
113 owner.SetFlags(EntityFlags.VISIBLE, true);
114 IEntity parent = owner.GetParent();
115 if (parent && data.ShouldHideParentParentObject())
116 parent.SetFlags(EntityFlags.VISIBLE, true);
117 }
118
119 if (data.ShouldHideParentCharacter() && m_ParentCharacter)
120 {
121 if (!m_ParentCharacter.IsDeleted())
122 m_ParentCharacter.SetFlags(EntityFlags.VISIBLE, false);
123
124 m_ParentCharacter = null;
125 }
126
127 s_bIsUsingSights = false;
128
129 super.HandleSightDeactivation();
130 }
131
132 //------------------------------------------------------------------------------------------------
133 override void OnSightADSActivated()
134 {
135 super.OnSightADSActivated();
136
138 }
139
140 //------------------------------------------------------------------------------------------------
141 override void OnSightADSDeactivated()
142 {
143 super.OnSightADSDeactivated();
144
146 }
147
148 //------------------------------------------------------------------------------------------------
149 override bool CanFreelook()
150 {
151 return false;
152 }
153
154 //------------------------------------------------------------------------------------------------
155 protected override void ApplyRecoilToCamera(inout vector pOutCameraTransform[4], vector aimModAngles)
156 {
157 vector weaponAnglesMat[3];
158 Math3D.AnglesToMatrix(aimModAngles, weaponAnglesMat);
159 Math3D.MatrixMultiply3(pOutCameraTransform, weaponAnglesMat, pOutCameraTransform);
160 }
161
162 //------------------------------------------------------------------------------------------------
163 protected void SetupFovInfo()
164 {
165 if (!m_SightsFovInfo)
166 return;
167
168 // Set zooms
169 //m_SightsFovInfo.SetupZooms();
170 array<float> zooms = m_SightsFovInfo.ZoomsToArray();
171
172 // Get zooms
173 //int zoomCount = m_SightsFovInfo.GetStepsCount();
174 int zoomCount = zooms.Count();
175
176 for (int i; i < zoomCount; i++)
177 {
178 // Calculate fov for each zoom
179 float zoom = zooms[i];
180 float fov = CalculateZoomFOV(zoom);
181 m_SightsFovInfo.InsertFov(fov);
182
183 // Initial setup
184 if (i == 0)
185 m_SightsFovInfo.SetCurrentFov(fov);
186 }
187 }
188
189 //------------------------------------------------------------------------------------------------
191 protected void SelectZoomLevel(int id)
192 {
193 // Check sights and id
194 if (!m_SightsFovInfo)
195 return;
196
197 if (id < 0 || id > m_SightsFovInfo.GetStepsCount() - 1)
198 return;
199
200 // Set zoom
201 m_SightsFovInfo.SetIndex(id);
202 m_fMagnification = m_SightsFovInfo.GetCurrentZoom();
203 }
204
205 //------------------------------------------------------------------------------------------------
207 protected void ActionZoomIn(float value = 0.0, EActionTrigger reason = 0)
208 {
209 AdjustZoom(1);
210 }
211
212 //------------------------------------------------------------------------------------------------
214 protected void ActionZoomOut(float value = 0.0, EActionTrigger reason = 0)
215 {
216 AdjustZoom(-1);
217 }
218
219 //------------------------------------------------------------------------------------------------
221 protected void AdjustZoom(float value)
222 {
223 if (!m_SightsFovInfo || value == 0)
224 return;
225
226 // TEMPORARY SOLUTION
227 // There is a 'mistake' in inheritance, m_pParentCharacter is never set because ADS changes are not propagated (super is not called in SCR_2DPIPSightsComponent)
228 SCR_ChimeraCharacter pParentCharacter = null;
229 IEntity parent = null;
230 IEntity owner = GetOwner();
231 if (owner)
232 {
233 parent = owner.GetParent();
234
235 IEntity parentParent = parent;
236 while (parentParent)
237 {
238 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(parentParent);
239 if (character)
240 {
241 pParentCharacter = character;
242 break;
243 }
244
245 parentParent = parentParent.GetParent();
246 }
247 }
248
249 // Down
250 if (value > 0 && m_iSelectedZoomLevel < m_SightsFovInfo.GetStepsCount())
251 {
252 m_iSelectedZoomLevel++;
253 SelectZoomLevel(m_iSelectedZoomLevel);
254
255 if (parent && pParentCharacter)
256 pParentCharacter.SetNewZoomLevel(m_iSelectedZoomLevel, true, Replication.FindItemId(parent.FindComponent(WeaponComponent)));
257 }
258
259 // Up
260 if (value < 0 && m_iSelectedZoomLevel > 0)
261 {
262 m_iSelectedZoomLevel--;
263 SelectZoomLevel(m_iSelectedZoomLevel);
264
265 if (parent && pParentCharacter)
266 pParentCharacter.SetNewZoomLevel(m_iSelectedZoomLevel, false, Replication.FindItemId(parent.FindComponent(WeaponComponent)));
267 }
268 }
269
270 //------------------------------------------------------------------------------------------------
272 protected void ToggleIllumination(float value, EActionTrigger trigger)
273 {
274 m_bIsIlluminationOn = !m_bIsIlluminationOn;
275 EnableReticleIllumination(m_bIsIlluminationOn);
276
277 // TEMPORARY SOLUTION
278 // There is a 'mistake' in inheritance, m_pParentCharacter is never set because ADS changes are not propagated (super is not called in SCR_2DPIPSightsComponent)
279 SCR_ChimeraCharacter parentCharacter = GetCharacterOwner();
280 IEntity soundSource = GetOwner();
281 if (!Turret.Cast(soundSource))//turrets have sight component in them and not as an attachment
282 {
283 IEntity parent = soundSource.GetParent();
284 while (parent)
285 {
286 if (ChimeraCharacter.Cast(parent))
287 break;
288
289 soundSource = parent;
290 parent = parent.GetParent();
291 }
292 }
293
294 if (!parentCharacter || !soundSource)
295 return;
296
297 RplComponent wpnRplComp = SCR_EntityHelper.GetEntityRplComponent(soundSource);
298 if (!wpnRplComp)
299 return;
300
301 parentCharacter.SetIllumination(m_bIsIlluminationOn, wpnRplComp.Id());
302 }
303
304 //------------------------------------------------------------------------------------------------
305 protected SCR_ChimeraCharacter GetCharacterOwner()
306 {
307 IEntity owner = GetOwner();
308 if (!owner)
309 return null;
310
311 if (Turret.Cast(owner))
312 {
313 SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(owner.FindComponent(SCR_BaseCompartmentManagerComponent));
314 if (!compartmentManager || !compartmentManager.AnyCompartmentsOccupiedOrLocked())
315 return null;
316
317 array<BaseCompartmentSlot> outCompartments = {};
318 if (compartmentManager.GetCompartments(outCompartments) < 1)
319 return null;
320
321 foreach (BaseCompartmentSlot compartment: outCompartments)
322 {
323 if (TurretCompartmentSlot.Cast(compartment))
324 return SCR_ChimeraCharacter.Cast(compartment.GetOccupant());
325 }
326 }
327 else
328 {
329 IEntity parent = owner.GetParent();
330 SCR_ChimeraCharacter character;
331 while (parent)
332 {
333 character = SCR_ChimeraCharacter.Cast(parent);
334 if (character)
335 return character;
336
337 parent = parent.GetParent();
338 }
339 }
340
341 return null;
342 }
343
344 //------------------------------------------------------------------------------------------------
345 protected override float GetReticleOffsetYTarget()
346 {
348 if (!data)
349 return 0;
350
351 if (data.GetZeroType() == SCR_EPIPZeroingType.EPZ_RETICLE_OFFSET)
352 return m_fReticleOffsetY + GetCurrentSightsRange()[0];
353
354 return m_fReticleOffsetY;
355 }
356
357 //------------------------------------------------------------------------------------------------
358 // Get Set API
359 //------------------------------------------------------------------------------------------------
360
361 //------------------------------------------------------------------------------------------------
366}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SetupFovInfo()
void ToggleIllumination(float value, EActionTrigger trigger)
Action for toggling illumination.
override void ApplyRecoilToCamera(inout vector pOutCameraTransform[4], vector aimModAngles)
SCR_2DSightsComponentClass m_SightsFovInfo
SCR_SightsZoomFOVInfo GetSightsFovInfo()
void SelectZoomLevel(int id)
Switch betweem zoom levels from sights.
void UnregisterInputs()
void RegisterInputs()
void AdjustZoom(float value)
Move zoom level up and down based on mouse wheel value.
void ActionZoomOut(float value=0.0, EActionTrigger reason=0)
Move zoom level up and down based on mouse wheel value.
void ActionZoomIn(float value=0.0, EActionTrigger reason=0)
Move zoom level up and down based on mouse wheel value.
override bool CanFreelook()
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Get all prefabs that have the spawner data
SCR_ChimeraCharacter GetCharacterOwner()
Returns the top most owner of this object or the operator of this turret.
proto external Managed FindComponent(typename typeName)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external IEntity GetParent()
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
proto external bool IsDeleted()
Main replication API.
Definition Replication.c:14
override void OnSightADSActivated()
override void OnSightADSDeactivated()
static float CalculateZoomFOV(float magnification)
Return camera FOV for given magnification. Focus FOV is used as reference 1x magnification.
void EnableReticleIllumination(bool enable)
Toggle between illumination modes.
static RplComponent GetEntityRplComponent(notnull IEntity entity)
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EActionTrigger