Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PowerComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/ScriptWizard", description: "THIS IS THE SCRIPT DESCRIPTION.", color: "0 0 255 255")]
5
6class SCR_PowerComponent : ScriptGameComponent
7{
8 [Attribute( defvalue: "1", uiwidget: UIWidgets.CheckBox, desc: "Should the engine output be reduced when there's no power (batteries destroyed)")]
9 private bool m_bShouldApplyNoPowerPenalty;
10
11 [Attribute( defvalue: "0.4", uiwidget: UIWidgets.EditBox, desc: "The multiplier to apply to the engine output in case the vehicle has no power (batteries destroyed)")]
12 private float m_fNoPowerMultiplier;
13
14 private ref ScriptInvoker m_EventBatteryStateChanged;
15 private ref array<HitZone> m_aBatteryHitZones;
16 private bool m_bHasPower = true;
17
18 //------------------------------------------------------------------------------------------------
20 bool HasPower()
21 {
22 return m_bHasPower;
23 }
24
25 //------------------------------------------------------------------------------------------------
27 bool ShouldApplyNoPowerPenalty()
28 {
29 return m_bShouldApplyNoPowerPenalty;
30 }
31
32 //------------------------------------------------------------------------------------------------
34 float GetNoPowerMultiplier()
35 {
36 return m_fNoPowerMultiplier;
37 }
38
39 //------------------------------------------------------------------------------------------------
42 ScriptInvoker GetEventBatteryStateChanged(bool createNew = true)
43 {
44 if (createNew && !m_EventBatteryStateChanged)
45 m_EventBatteryStateChanged = new ScriptInvoker();
46
47 return m_EventBatteryStateChanged;
48 }
49
52 void UpdatePowerState()
53 {
54 // Power is available if there are no colliders
55 bool hasPower = !m_aBatteryHitZones || m_aBatteryHitZones.IsEmpty();
56
57 if (m_aBatteryHitZones)
58 {
59 foreach (HitZone hitZone : m_aBatteryHitZones)
60 {
61 if (hitZone.GetDamageState() != EDamageState.DESTROYED)
62 {
63 hasPower = true;
64 break;
65 }
66 }
67 }
68
69 if (m_bHasPower == hasPower)
70 return;
71
72 m_bHasPower = hasPower;
73
74 if (m_EventBatteryStateChanged)
75 m_EventBatteryStateChanged.Invoke(hasPower);
76 }
77
78 //------------------------------------------------------------------------------------------------
81 void RegisterBatteryHitZone(notnull HitZone hitZone)
82 {
83 if (!m_aBatteryHitZones)
84 m_aBatteryHitZones = {};
85
86 m_aBatteryHitZones.Insert(hitZone);
87
88 // Trigger power state update if new battery has different state
89 bool hasPower = hitZone.GetDamageState() != EDamageState.DESTROYED;
90 if (m_bHasPower != hasPower)
91 UpdatePowerState();
92 }
93}
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_FieldOfViewSettings Attribute
EDamageState
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134