Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIIdleBehavior_Driver.c
Go to the documentation of this file.
1class SCR_AIIdleBehavior_Driver : SCR_AIIdleBehavior
2{
3 protected const int LIGHTS_CHECK_INTERVAL_MS = 2*1000;
4 protected const int UNSAFE_LIGHTS_LOCK_DURATION_MS = 5 * 60 * 1000; // For how long since feeling unsafe we don't want to enable lights
5
6 protected const float MIN_HIBEAM_LIGHTS_VEHICLE_SPEED_MPS_SQ = 4; // Min speed in sq m/s to enable hi beam lights
7
8 protected const int VEHICLE_DANGER_HIBEAM_LIGHTS_TIMEOUT_MS = 5*1000; // For how long since last vehicle danger event we don't use hi beam lights
9
11 protected IEntity m_Vehicle;
13
14 protected float m_fNextLightsCheck;
15
16 protected float m_fHiBeamIgnoreTime;
17
18 void SCR_AIIdleBehavior_Driver(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, notnull IEntity vehicleEntity)
19 {
20 if (!utility)
21 return;
22
23 m_sBehaviorTree = "AI/BehaviorTrees/Chimera/Soldier/VehicleInCombat_DriverListener.bt";
24 SetPriority(PRIORITY_BEHAVIOR_IDLE_DRIVER);
25 m_bUseCombatMove = true;
26
27 m_Vehicle = vehicleEntity;
29 m_Info = utility.m_AIInfo;
30 }
31
32 //------------------------------------------------------------------------------------------------
33 override void OnFail()
34 {
35 super.OnFail();
36
37 // Disable lights when exiting
38 if (m_Utility.GetOwner().IsAIActivated() && IsLightInteractionAllowed())
39 SetLightsState(false);
40 }
41
42 //------------------------------------------------------------------------------------------------
43 // Called by SCR_AIDangerReaction_Vehicle each time we have car approaching
45 {
47
48 // Turn off hi beams immediately
51 }
52
53 //------------------------------------------------------------------------------------------------
54 protected void EvaluateLightsUsage()
55 {
56 // Disable hazard lights on first evaluation
58 m_VehicleLightManager.SetLightsState(ELightType.Hazard, false);
59
60 float worldTime = GetGame().GetWorld().GetWorldTime();
61 if (worldTime < m_fNextLightsCheck)
62 return;
63
64 // Do nothing if we are forbidden to touch lights
66 return;
67
68 m_fNextLightsCheck = worldTime + LIGHTS_CHECK_INTERVAL_MS * Math.RandomFloat(0.8, 1.2);
69 bool useLights = ShouldUseLights(worldTime);
70 bool useHiBeams;
71
72 if (useLights)
73 useHiBeams = ShouldUseHiBeamLights(worldTime);
74
75 if (GetLightsState() != useLights || GetHiBeamLightsState() != useHiBeams)
76 SetLightsState(useLights, useHiBeams);
77 }
78
79 //------------------------------------------------------------------------------------------------
80 override float CustomEvaluate()
81 {
84
85 return GetPriority();
86 }
87
88
89 //------------------------------------------------------------------------------------------------------------------------------
90 // Auxiliary methods related to lights
91
92 //------------------------------------------------------------------------------------------------
93 protected bool ShouldUseHiBeamLights(float worldTime)
94 {
95 if (m_fHiBeamIgnoreTime > worldTime)
96 return false;
97
98 Physics ph = m_Vehicle.GetPhysics();
99 if (!ph)
100 return false;
101
102 return ph.GetVelocity().LengthSq() > MIN_HIBEAM_LIGHTS_VEHICLE_SPEED_MPS_SQ;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 protected bool ShouldUseLights(float worldTime)
107 {
108 if (!SCR_AIWorldHandling.IsLowLightEnvironment())
109 return false;
110
111 if (m_Info.GetThreatState() != EAIThreatState.SAFE)
112 {
113 // We're feeling unsafe, lock lights at disabled state for set duration
115 return false;
116 }
117
118 return true;
119 }
120
121 //------------------------------------------------------------------------------------------------
123 {
124 if (!m_Utility.m_SettingsComponent)
125 return true;
126
128 if (!setting)
129 return true;
130
131 return setting.IsLightInterractionAllowed();
132 }
133
134 //------------------------------------------------------------------------------------------------
135 protected bool GetHiBeamLightsState()
136 {
138 return false;
139
140 return m_VehicleLightManager.GetLightsState(ELightType.HiBeam);
141 }
142
143 //------------------------------------------------------------------------------------------------
144 protected bool GetLightsState()
145 {
147 return false;
148
149 return m_VehicleLightManager.GetLightsState(ELightType.Head);
150 }
151
152 //------------------------------------------------------------------------------------------------
153 protected void SetHiBeamLightState(bool enable)
154 {
156 return;
157
158 m_VehicleLightManager.SetLightsState(ELightType.HiBeam, enable);
159 }
160
161 //------------------------------------------------------------------------------------------------
162 protected void SetLightsState(bool enableLights, bool enableHiBeamLights = false)
163 {
165 return;
166
167 m_VehicleLightManager.SetLightsState(ELightType.Head, enableLights);
168 SetHiBeamLightState(enableLights && enableHiBeamLights);
169 }
170}
ELightType
Definition ELightType.c:8
ArmaReforgerScripted GetGame()
Definition game.c:1398
ResourceName m_sBehaviorTree
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
bool m_bUseCombatMove
Definition Math.c:13
void SCR_AIIdleBehavior_Driver(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, notnull IEntity vehicleEntity)
void SetLightsState(bool enableLights, bool enableHiBeamLights=false)
bool ShouldUseHiBeamLights(float worldTime)
BaseLightManagerComponent m_VehicleLightManager