Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DamageAreaComponent.c
Go to the documentation of this file.
4
5class SCR_DamageAreaComponent : DamageAreaComponent
6{
7 protected ref array<ref DamageArea> m_aDamageAreas = {};
8
9#ifdef ENABLE_DIAG
10 protected ref SCR_DebugShapeManager m_DebugShapeMgr = new SCR_DebugShapeManager();
11
12 //------------------------------------------------------------------------------------------------
14 SCR_DebugShapeManager GetDebugShapeMgr()
15 {
16 return m_DebugShapeMgr;
17 }
18
19 //------------------------------------------------------------------------------------------------
20 override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
21 {
22 m_DebugShapeMgr.Clear();
23 DrawMarker(owner);
24 InitializeShapes(owner);
25 DrawCustomShapes(owner);
26 }
27
28 //------------------------------------------------------------------------------------------------
29 override void _WB_SetTransform(IEntity owner, inout vector mat[4], IEntitySource src)
30 {
31 m_DebugShapeMgr.Clear();
32 DrawMarker(owner);
33 DrawCustomShapes(owner);
34 }
35
36 //------------------------------------------------------------------------------------------------
37 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
38 {
39 m_DebugShapeMgr.Clear();
40 DrawMarker(owner);
41 DrawCustomShapes(owner);
42
43 array<ref DamageArea> damageAreas = {};
44 GetDamageAreas(damageAreas);
45
46 SCR_BaseDamageAreaShape shape;
47 bool somethingChanged;
48 foreach (DamageArea area : damageAreas)
49 {
50 if (!area)
51 continue;
52
53 shape = SCR_BaseDamageAreaShape.Cast(area.GetShape());
54 if (!shape)
55 continue;
56
57 somethingChanged = shape._WB_OnKeyChanged(owner, src, key, ownerContainers, parent) || somethingChanged;
58 }
59
60 return somethingChanged;
61 }
62
63 //------------------------------------------------------------------------------------------------
66 protected void DrawCustomShapes(IEntity owner)
67 {
68 array<ref DamageArea> damageAreas = {};
69 GetDamageAreas(damageAreas);
70
71 SCR_BaseDamageAreaShape shape;
72 foreach (DamageArea area : damageAreas)
73 {
74 if (!area)
75 continue;
76
77 shape = SCR_BaseDamageAreaShape.Cast(area.GetShape());
78 if (!shape)
79 continue;
80
81 shape.DrawDebug(owner, m_DebugShapeMgr);
82 }
83 }
84
85 //------------------------------------------------------------------------------------------------
88 protected void DrawMarker(IEntity owner)
89 {
90 vector origin = owner.GetOrigin();
91 m_DebugShapeMgr.AddArrow(origin + vector.Up * 5, origin, 1);
92 string prefab = GetPrefabname(owner);
93 if (prefab.IsEmpty())
94 return;
95
96 m_DebugShapeMgr.AddText("Damage area\n" + prefab, origin + vector.Up * 5.5, 0.5);
97 }
98#endif
99
100 //------------------------------------------------------------------------------------------------
103 static string GetPrefabname(IEntity owner)
104 {
105 string prefab = SCR_ResourceNameUtils.GetPrefabName(owner);
106 const int lastSlash = prefab.LastIndexOf(SCR_StringHelper.SLASH);
107 if (lastSlash < 0)
108 return string.Empty;
109
110 return prefab.Substring(lastSlash + 1, prefab.Length() - lastSlash - 1);
111 }
112
113 //------------------------------------------------------------------------------------------------
117 protected void InitializeShapes(IEntity owner, inout array<ref DamageArea> damageAreas = null)
118 {
119 if (!damageAreas)
120 {
121 damageAreas = {};
122 GetDamageAreas(damageAreas);
123 }
124
126 foreach (DamageArea area : damageAreas)
127 {
128 if (!area)
129 {
130 Print("SCR_DamageAreaComponent->InitializeShapes: " + owner + " contains null areas!!!", LogLevel.ERROR);
131 continue;
132 }
133
134 shape = SCR_BaseDamageAreaShape.Cast(area.GetShape());
135 if (!shape)
136 {
137 Print("SCR_DamageAreaComponent->InitializeShapes: " + owner + " has a " + area.Type().ToString() + " which contains null shape!!!", LogLevel.ERROR);
138 continue;
139 }
140
141 shape.Init(owner);
142 }
143 }
144
145 //------------------------------------------------------------------------------------------------
146 override protected void OnPostInit(IEntity owner)
147 {
148 SetEventMask(owner, EntityEvent.INIT);
149 }
150
151 //------------------------------------------------------------------------------------------------
152 override protected void EOnInit(IEntity owner)
153 {
154 m_aDamageAreas = {};
157
158 if (!GetGame().InPlayMode())
159 return;
160
161 SCR_DamageArea scriptedArea;
162 foreach (int i, DamageArea area : m_aDamageAreas)
163 {
164 if (!area)
165 {
166 Print("SCR_DamageAreaComponent->EOnInit: " + GetPrefabname(owner) + " contains null areas at position " + i + "!!!", LogLevel.ERROR);
167 continue;
168 }
169
170 scriptedArea = SCR_DamageArea.Cast(area);
171 if (!area.GetShape())
172 {
173 Print("SCR_DamageAreaComponent->EOnInit: " + GetPrefabname(owner) + " is missing a shape for area with id = " + i, LogLevel.ERROR);
174 continue;
175 }
176
177 if (scriptedArea && !scriptedArea.IsRegisteredAutomatically())
178 continue;
179
180 RegisterDamageArea(area);
181 }
182 }
183
184 //------------------------------------------------------------------------------------------------
185 override protected void OnDelete(IEntity owner)
186 {
187 if (!GetGame().InPlayMode())
188 return;
189
190 foreach (DamageArea area : m_aDamageAreas)
191 {
193 }
194 }
195}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DamageAreaComponentClass m_aDamageAreas
void InitializeShapes(IEntity owner, inout array< ref DamageArea > damageAreas=null)
override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
Any property value has been changed. You can use editor API here and do some additional edit actions ...
enum EVehicleType IEntity
proto external vector GetOrigin()
bool IsRegisteredAutomatically()
override void EOnInit(IEntity owner)
DamageAreaComponentClass ScriptComponentClass RegisterDamageArea(notnull DamageArea area)
proto external void UnregisterDamageArea(notnull DamageArea area)
proto external void GetDamageAreas(out notnull array< ref DamageArea > damageAreas)
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
EntityEvent
Various entity events.
Definition EntityEvent.c:14