Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LightHitZone.c
Go to the documentation of this file.
1//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
3{
4 private BaseLightManagerComponent m_LightManager;
5 private ref array<BaseLightSlot> m_aLightSlots = {};
6 protected string m_sSurfaceName;
7 protected int m_iParentSurfaceID;
8
9 //------------------------------------------------------------------------------------------------
10 void SetSurfaceName(string surfaceName)
11 {
12 m_aLightSlots.Clear();
14 if (surfaceName == string.Empty)
15 return;
16
17 m_sSurfaceName = surfaceName;
18 IEntity parent = GetOwner();
19 while (parent && !m_LightManager)
20 {
22 if (!m_LightManager)
23 parent = parent.GetParent();
24 }
25
26 if (!m_LightManager)
27 return;
28
29 SCR_LightSlot scrLightSlot;
30 array<BaseLightSlot> lights = {};
31 m_LightManager.GetLights(lights);
32 foreach (BaseLightSlot lightSlot : lights)
33 {
34 scrLightSlot = SCR_LightSlot.Cast(lightSlot);
35 if (scrLightSlot && m_sSurfaceName.Compare(scrLightSlot.GetParentSurfaceName(), false) == 0)
36 {
37 m_aLightSlots.Insert(lightSlot);
38 if (m_iParentSurfaceID == -1)
39 m_iParentSurfaceID = lightSlot.GetSurfaceID();
40
41#ifdef WORKBENCH
42 if (m_iParentSurfaceID != -1 && m_iParentSurfaceID != lightSlot.GetSurfaceID())
43 Print("WARNING! Multiple lights tied to the hit zone from this entity: "+GetOwner()+" while having different parent surface id ("+m_iParentSurfaceID+" != "+lightSlot.GetSurfaceID()+")", LogLevel.ERROR);
44#endif
45 }
46 }
47
48 UpdateLightState(GetDamageState());
49 }
50
51 //------------------------------------------------------------------------------------------------
52 override void OnDamageStateChanged(EDamageState newState, EDamageState previousDamageState, bool isJIP)
53 {
54 super.OnDamageStateChanged(newState, previousDamageState, isJIP);
55
56 UpdateLightState(newState);
57 }
58
59 //------------------------------------------------------------------------------------------------
61 {
62 if (!m_LightManager)
63 return;
64
65 RplComponent rplComp = SCR_EntityHelper.GetEntityRplComponent(GetOwner());
66 if (rplComp && rplComp.IsProxy())
67 return;
68
69 bool isAlive = newState != EDamageState.DESTROYED;
70
71 bool functionalityStateChanged;
72 if (m_iParentSurfaceID > -1)
73 functionalityStateChanged = m_LightManager.TrySetSurfaceFunctional(m_iParentSurfaceID, isAlive);
74
75 int lightSide;
76 bool lastState;
77 foreach (BaseLightSlot lightSlot : m_aLightSlots)
78 {
79 if (!lightSlot)
80 continue;
81
82 lightSlot.SetLightFunctional(isAlive);
83 if (isAlive && functionalityStateChanged && lightSlot.GetLightType() == ELightType.Hazard)
84 {//hazards need to be reset as its possible that they will get out of sync
85 lightSide = lightSlot.GetLightSide();
86 lastState = m_LightManager.GetLightsState(lightSlot.GetLightType(), lightSide);
87 if (lightSide != -1)
88 {//check if other side is also turned on and in such case we need to reset both sides
89 if (lightSide == 0)
90 lightSide = 1;//right
91 else
92 lightSide = 0;//left
93
94 if (lastState == m_LightManager.GetLightsState(lightSlot.GetLightType(), lightSide))
95 lightSide = -1;//all sides
96 else
97 lightSide = lightSlot.GetLightSide();
98 }
99
100 if (!lastState)
101 return;
102
103 m_LightManager.SetLightsState(lightSlot.GetLightType(), false, lightSide);//first we need to turn them off or else they will blink faster
104 m_LightManager.SetLightsState(lightSlot.GetLightType(), lastState, lightSide);
105
106 functionalityStateChanged = false;
107 }
108 }
109 }
110
111 //------------------------------------------------------------------------------------------------
113 {
114 m_aLightSlots.Clear();
115 m_aLightSlots = null;
116 }
117}
118//---- REFACTOR NOTE END ----
ELightType
Definition ELightType.c:8
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
static RplComponent GetEntityRplComponent(notnull IEntity entity)
IEntity GetOwner()
Definition SCR_HitZone.c:42
void SetSurfaceName(string surfaceName)
void UpdateLightState(EDamageState newState)
override void OnDamageStateChanged(EDamageState newState, EDamageState previousDamageState, bool isJIP)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EDamageState