Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
VehicleControllerComponent.c
Go to the documentation of this file.
4
8class VehicleControllerComponent : BaseVehicleControllerComponent
9{
11 protected int m_iOccupants;
12
15 protected SCR_PowerComponent m_PowerComponent;
16 protected bool m_bIsStarting;
17
18 //sound
22
23 //------------------------------------------------------------------------------------------------
32
33 //------------------------------------------------------------------------------------------------
42
43 //------------------------------------------------------------------------------------------------
48
49 //------------------------------------------------------------------------------------------------
52 {
53 if (m_DamageManager && !m_DamageManager.GetEngineFunctional())
54 return false;
55
56 // TODO: Option to start engine despite lack of power if vehicle is moving
57 if (m_PowerComponent && !m_PowerComponent.HasPower())
58 return false;
59
60 return true;
61 }
62
63 //------------------------------------------------------------------------------------------------
64 protected void OnDestroyed(IEntity ent)
65 {
66 auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(ent);
67 if (garbageSystem)
68 garbageSystem.Insert(ent);
69 }
70
71 //------------------------------------------------------------------------------------------------
72 protected void OnCompartmentEntered(IEntity vehicle, BaseCompartmentManagerComponent mgr, IEntity occupant, int managerId, int slotID)
73 {
74 if (m_iOccupants++ == 0)
75 {
76 auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(vehicle);
77 if (garbageSystem)
78 garbageSystem.Withdraw(vehicle);
79 }
80 }
81
82 //------------------------------------------------------------------------------------------------
83 protected void OnCompartmentLeft(IEntity vehicle, BaseCompartmentManagerComponent mgr, IEntity occupant, int managerId, int slotID)
84 {
85 if (--m_iOccupants == 0)
86 {
87 auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(vehicle);
88 if (garbageSystem)
89 garbageSystem.Insert(vehicle);
90 }
91 }
92
93 //------------------------------------------------------------------------------------------------
94 protected override void OnPostInit(IEntity owner)
95 {
96 m_PowerComponent = SCR_PowerComponent.Cast(owner.FindComponent(SCR_PowerComponent));
98
99 EventHandlerManagerComponent ev = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
100 if (ev)
101 {
102 ev.RegisterScriptHandler("OnDestroyed", this, OnDestroyed, false);
103 ev.RegisterScriptHandler("OnCompartmentEntered", this, OnCompartmentEntered, false);
104 ev.RegisterScriptHandler("OnCompartmentLeft", this, OnCompartmentLeft, false);
105 }
106 }
107
108 //------------------------------------------------------------------------------------------------
109 protected override void OnDelete(IEntity owner)
110 {
111 EventHandlerManagerComponent ev = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
112 if (ev)
113 {
114 ev.RemoveScriptHandler("OnDestroyed", this, OnDestroyed, false);
115 ev.RemoveScriptHandler("OnCompartmentEntered", this, OnCompartmentEntered);
116 ev.RemoveScriptHandler("OnCompartmentLeft", this, OnCompartmentLeft);
117 }
118 }
119
120 //------------------------------------------------------------------------------------------------
122 override void OnEngineStartBegin()
123 {
124 if (GetEngineDrowned())
125 return;
126
127 if (!IsStarterFunctional())
128 return;
129
130 m_bIsStarting = true;
131
132 SCR_MotorExhaustEffectGeneralComponent motorExhaust = SCR_MotorExhaustEffectGeneralComponent.Cast(GetOwner().FindComponent(SCR_MotorExhaustEffectGeneralComponent));
133 if (motorExhaust)
134 motorExhaust.OnEngineStart(true);
135
136 SoundComponent soundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
137 if (soundComponent)
138 {
139 soundComponent.Terminate(m_iEngineStopHandle);
141
142 m_iEngineStarterHandle = soundComponent.SoundEvent(SCR_SoundEvent.SOUND_ENGINE_STARTER_LP);
143 }
144 }
145
146 //------------------------------------------------------------------------------------------------
148 override void OnEngineStartProgress()
149 {
150 if (!m_bIsStarting)
151 return;
152
153 if (m_DamageManager && !m_DamageManager.GetEngineFunctional())
155 else if (!IsStarterFunctional())
157 }
158
159 //------------------------------------------------------------------------------------------------
162 {
163 m_bIsStarting = false;
164
165 SCR_MotorExhaustEffectGeneralComponent motorExhaust = SCR_MotorExhaustEffectGeneralComponent.Cast(GetOwner().FindComponent(SCR_MotorExhaustEffectGeneralComponent));
166 if (motorExhaust)
167 motorExhaust.OnEngineStop();
168
169 SoundComponent soundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
170 if (soundComponent)
171 {
172 soundComponent.Terminate(m_iEngineStarterHandle);
174 soundComponent.Terminate(m_iEngineStartHandle);
176 }
177 }
178
179 //------------------------------------------------------------------------------------------------
181 override void OnEngineStartSuccess()
182 {
183 m_bIsStarting = false;
184
185 SoundComponent soundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
186 if (soundComponent)
187 {
188 soundComponent.Terminate(m_iEngineStarterHandle);
190 soundComponent.Terminate(m_iEngineStartHandle);
191 m_iEngineStartHandle = soundComponent.SoundEvent(SCR_SoundEvent.SOUND_ENGINE_START);
192 }
193 }
194
195 //------------------------------------------------------------------------------------------------
198 {
199 if (!m_bIsStarting)
200 return;
201
202 m_bIsStarting = false;
203
204 SCR_MotorExhaustEffectGeneralComponent motorExhaust = SCR_MotorExhaustEffectGeneralComponent.Cast(GetOwner().FindComponent(SCR_MotorExhaustEffectGeneralComponent));
205 if (motorExhaust)
206 motorExhaust.OnEngineStop();
207
208 SoundComponent soundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
209 if (soundComponent)
210 {
211 soundComponent.Terminate(m_iEngineStarterHandle);
213 soundComponent.Terminate(m_iEngineStartHandle);
215
217 return;
218
219 soundComponent.SoundEvent(SCR_SoundEvent.SOUND_ENGINE_START_FAILED);
220 }
221 }
222
223 //------------------------------------------------------------------------------------------------
229 override bool OnBeforeEngineStart()
230 {
231 if (!IsStarterFunctional())
232 return false;
233
234 // engine can start by default
235 return true;
236 }
237
238 //------------------------------------------------------------------------------------------------
240 override void OnEngineStart()
241 {
242 SCR_FuelConsumptionComponent fuelConsumption = SCR_FuelConsumptionComponent.Cast(GetOwner().FindComponent(SCR_FuelConsumptionComponent));
243 if (fuelConsumption)
244 fuelConsumption.SetEnabled(true);
245
246 SCR_MotorExhaustEffectGeneralComponent motorExhaust = SCR_MotorExhaustEffectGeneralComponent.Cast(GetOwner().FindComponent(SCR_MotorExhaustEffectGeneralComponent));
247 if (motorExhaust)
248 motorExhaust.OnEngineStart(false);
249
250 if (m_OnEngineStart)
251 m_OnEngineStart.Invoke();
252 }
253
254 //------------------------------------------------------------------------------------------------
256 override void OnEngineStop()
257 {
258 SCR_FuelConsumptionComponent fuelConsumption = SCR_FuelConsumptionComponent.Cast(GetOwner().FindComponent(SCR_FuelConsumptionComponent));
259 if (fuelConsumption)
260 fuelConsumption.SetEnabled(false);
261
262 if (m_OnEngineStop)
263 m_OnEngineStop.Invoke();
264
265 SCR_MotorExhaustEffectGeneralComponent motorExhaust = SCR_MotorExhaustEffectGeneralComponent.Cast(GetOwner().FindComponent(SCR_MotorExhaustEffectGeneralComponent));
266 if (motorExhaust)
267 motorExhaust.OnEngineStop();
268
269 SoundComponent soundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
270 if (soundComponent)
271 {
272 soundComponent.Terminate(m_iEngineStarterHandle);
274
275 soundComponent.Terminate(m_iEngineStartHandle);
277
278 soundComponent.SoundEvent(SCR_SoundEvent.SOUND_ENGINE_STOP);
279 }
280 }
281 //------------------------------------------------------------------------------------------------
282 override bool ValidateCanMove()
283 {
284 return m_DamageManager.GetMovementDamage() < 1;
285 }
286}
DamageManagerComponent m_DamageManager
void OnCompartmentEntered(AIAgent agent, IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
void OnCompartmentLeft(AIAgent agent, IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
void OnDestroyed(IEntity owner)
void OnEngineStop()
Turn off the effect and pause the damaged exhaust effect.
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
override bool OnBeforeEngineStart()
bool IsStarterFunctional()
Return if engine starter is functional.
AudioHandle m_iEngineStarterHandle
override void OnEngineStartSuccess()
Gets called when the engine start routine has successfully completed.
ScriptInvokerVoid GetOnEngineStop()
Invoker for the Engine Stopped event.
VehicleControllerComponentClass m_OnEngineStop
override void OnEngineStartBegin()
Gets called when the engine start routine begins (animation event).
override void OnEngineStart()
Is called every time the engine starts.
AudioHandle m_iEngineStartHandle
override void OnEngineStartFail(EVehicleEngineStartFailedReason reason)
Gets called when the engine start routine has failed.
SCR_VehicleDamageManagerComponent GetDamageManager()
AudioHandle m_iEngineStopHandle
ScriptInvokerVoid GetOnEngineStart()
Invoker for the Engine Started event.
override void OnEngineStartProgress()
Get called while engine starter is active.
VehicleControllerComponentClass m_OnEngineStart
override void OnEngineStartInterrupt()
Gets called when the engine start routine was interrupted.
SCR_PowerComponent m_PowerComponent
proto external Managed FindComponent(typename typeName)
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
proto external void Terminate(AudioHandle handle)
IEntity GetOwner()
Owner entity of the fuel tank.
EVehicleEngineStartFailedReason
Describes failure types of engine startup routine.
event bool ValidateCanMove()