Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EditableWaypointComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5
7
10{
11 [RplProp(onRplName: "OnPreWaypointIdRpl")]
12 protected RplId m_PrevWaypointId;
13
14 [RplProp()]
15 protected bool m_bIsCurrent;
16
17 [RplProp()]
18 protected int m_iIndex;
19
21 protected SCR_EditableEntityComponent m_PrevWaypoint;
22
23 protected SCR_AIWaypoint m_AIWaypoint;
25
26 [RplProp(onRplName: "OnAttachedToId")]
27 protected RplId m_AttachedToId;
28
29 //------------------------------------------------------------------------------------------------
31 {
32 return m_AttachedTo;
33 }
34
35 //------------------------------------------------------------------------------------------------
38 protected void AttachTo(SCR_EditableEntityComponent attachedTo)
39 {
40 m_AttachedTo = attachedTo;
41
42 //++ Remove from the existing parent first
43 if (GetOwner().GetParent())
44 m_AIWaypoint.GetParent().RemoveChild(m_AIWaypoint, true);
45
46 //++ Add to the new parent (when defined)
47 if (m_AttachedTo)
48 {
49 //++ Do not allow to attach if target exceeds attached entities number
50 if (m_AttachedTo.GetAttachedEntities().Count() >= EditorConstants.MAX_ATTACHED_ENTITIES)
51 {
52 SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_PLACING_BLOCKED, SCR_PlayerController.GetLocalPlayerId());
53 return;
54 }
55
56 m_AIWaypoint.SetOrigin(vector.Zero);
57 m_AttachedTo.GetOwner().AddChild(m_AIWaypoint, -1);
58
59 SCR_EntityWaypoint entityWaypoint = SCR_EntityWaypoint.Cast(m_AIWaypoint);
60 if (entityWaypoint)
61 entityWaypoint.SetEntity(m_AttachedTo.GetOwner());
62
63 m_AttachedTo.Attach(this);
64 }
65 else
66 {
67 SCR_EntityWaypoint entityWaypoint = SCR_EntityWaypoint.Cast(m_AIWaypoint);
68 if (entityWaypoint)
69 entityWaypoint.SetEntity(null);
70 if (m_AttachedTo)
71 m_AttachedTo.Detach(this);
72 }
73 }
74
75 //------------------------------------------------------------------------------------------------
77 protected void OnAttachedToId()
78 {
80 AttachTo(attachedTo);
81 }
82
83 //------------------------------------------------------------------------------------------------
88 void SetWaypointIndex(int index, bool isCurrent, SCR_EditableEntityComponent prevWaypoint)
89 {
90 m_iIndex = index;
91 m_bIsCurrent = isCurrent;
92 m_PrevWaypoint = prevWaypoint;
93 m_PrevWaypointId = Replication.FindItemId(prevWaypoint);
94 Replication.BumpMe();
95 }
96
97 //------------------------------------------------------------------------------------------------
101 {
102 return m_iIndex;
103 }
104
105 //------------------------------------------------------------------------------------------------
109 {
110 return m_bIsCurrent;
111 }
112
113 //------------------------------------------------------------------------------------------------
117 {
118 if (m_PrevWaypoint)
119 return m_PrevWaypoint;
120 else
121 return m_Group;
122 }
123
124 //------------------------------------------------------------------------------------------------
125 protected void OnPreWaypointIdRpl()
126 {
127 m_PrevWaypoint = SCR_EditableEntityComponent.Cast(Replication.FindItem(m_PrevWaypointId));
128 }
129
130 //------------------------------------------------------------------------------------------------
131 override bool CanDuplicate(out notnull set<SCR_EditableEntityComponent> outRecipients)
132 {
133 SCR_EditableEntityComponent groupComponent = GetAIGroup();
134 if (groupComponent)
135 outRecipients.Insert(groupComponent);
136
137 return true;
138 }
139
140 //------------------------------------------------------------------------------------------------
142 {
143 if (!m_Group)
144 return null;
145
146 Faction faction = m_Group.GetFaction();
147 return faction;
148 }
149
150 //------------------------------------------------------------------------------------------------
152 {
153 return m_Group;
154 }
155
156 //------------------------------------------------------------------------------------------------
157 override void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
158 {
159 if (!parentEntity)
160 return;
161
162
163 if (m_AIWaypoint && m_Group && m_Group != parentEntity)
164 {
165 AttachTo(parentEntity);
166
167 m_AttachedToId = Replication.FindItemId(parentEntity);
168 Replication.BumpMe();
169
170 super.OnParentEntityChanged(parentEntityPrev, parentEntityPrev, changedByUser); // Needed to register
171 return;
172 }
173
174 EEditableEntityType parentType = parentEntity.GetEntityType();
175 switch (parentType)
176 {
177 case EEditableEntityType.CHARACTER:
178 case EEditableEntityType.GROUP:
179 {
180 SCR_EditableEntityComponent group = parentEntity.GetAIGroup();
181 if (!group)
182 break;
183
184 m_Group = group;
185 super.OnParentEntityChanged(group, parentEntityPrev, changedByUser);
186 break;
187 }
188 }
189 }
190
191 //------------------------------------------------------------------------------------------------
192 override bool SetTransform(vector transform[4], bool changedByUser = false)
193 {
195 return super.SetTransform(transform, changedByUser);
196 }
197
198 //------------------------------------------------------------------------------------------------
199 override void SetTransformBroadcast(vector transform[4])
200 {
202 super.SetTransformBroadcast(transform);
203 }
204
205 //------------------------------------------------------------------------------------------------
207 protected void DetachFromTarget()
208 {
209 if (m_AIWaypoint)
210 AttachTo(null);
211 }
212
213 //------------------------------------------------------------------------------------------------
214 override bool GetPos(out vector pos)
215 {
216 if (m_Group)
217 return super.GetPos(pos);
218 else
219 return false;
220 }
221
222 //------------------------------------------------------------------------------------------------
223 override bool CanSetParent(SCR_EditableEntityComponent parentEntity)
224 {
225 //--- When the group was not assigned yet and the target is a GROUP or a CHARACTER, always allow them to be a parent
226 if (!m_Group)
227 {
228 switch (parentEntity.GetEntityType())
229 {
230 case EEditableEntityType.GROUP:
231 case EEditableEntityType.CHARACTER:
232 {
233 return true;
234 }
235 }
236 }
237
238 return super.CanSetParent(parentEntity);
239 }
240
241 //------------------------------------------------------------------------------------------------
243 {
244 if (recipient)
245 {
246 AIGroup group = AIGroup.Cast(recipient.GetOwner());
247 if (group)
248 {
249 if (!isQueue)
250 {
251 SCR_EditableGroupComponent editableGroup = SCR_EditableGroupComponent.Cast(recipient);
252 if (editableGroup && !editableGroup.AreCycledWaypointsEnabled())
253 editableGroup.ClearWaypoints();
254 }
255
256 group.AddWaypoint(AIWaypoint.Cast(GetOwner()));
257 }
258 }
259 return this;
260 }
261
262 //------------------------------------------------------------------------------------------------
263 override void OnDelete(IEntity owner)
264 {
265 super.OnDelete(owner);
266
267 //--- Manually remove the waypoint entity from group's list of waypoints - it doesn't happen automatically
268 if (m_Group && IsServer())
269 {
270 AIGroup aiGroup = AIGroup.Cast(m_Group.GetOwner());
271 if (aiGroup)
272 aiGroup.RemoveWaypoint(AIWaypoint.Cast(owner));
273 }
274 }
275
276 //------------------------------------------------------------------------------------------------
277 override bool IsAttachable()
278 {
279 return true;
280 }
281
282 //------------------------------------------------------------------------------------------------
283 override bool IsAttached()
284 {
285 if (GetAttachedTo())
286 return true;
287
288 return false;
289 }
290
291 //------------------------------------------------------------------------------------------------
293 {
294 return m_AIWaypoint;
295 }
296
297 //------------------------------------------------------------------------------------------------
299 {
300 m_AIWaypoint = SCR_AIWaypoint.Cast(ent);
301 }
302
303}
SCR_EAIThreatSectorFlags flags
EEditorPlacingFlags
ENotification
SCR_AIGroupSettingsComponentClass m_Group
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
RplId m_AttachedToId
void OnAttachedToId()
Runs when an ID is attached.
SCR_EditableEntityComponent m_AttachedTo
SCR_EditableEntityComponent GetPrevWaypoint()
SCR_AIWaypoint GetAIWaypoint()
void SCR_EditableWaypointComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnPreWaypointIdRpl()
void DetachFromTarget()
Detach the waypoint from the target, runs both in client and server.
void SetWaypointIndex(int index, bool isCurrent, SCR_EditableEntityComponent prevWaypoint)
Faction GetParent()
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
void SetTransformBroadcast(vector transform[4])
override void OnDelete(IEntity owner)
bool SetTransform(vector transform[4], bool changedByUser=false)
SCR_EditableEntityComponent EOnEditorPlace(out SCR_EditableEntityComponent parent, SCR_EditableEntityComponent recipient, EEditorPlacingFlags flags, bool isQueue, int playerID=0)
SCR_EditableEntityComponent GetAttachedTo()
void OnParentEntityChanged(SCR_EditableEntityComponent parentEntity, SCR_EditableEntityComponent parentEntityPrev, bool changedByUser)
EEditableEntityType GetEntityType(IEntity owner=null)
bool CanSetParent(SCR_EditableEntityComponent parentEntity)
bool CanDuplicate(out notnull set< SCR_EditableEntityComponent > outRecipients)
SCR_EditableEntityComponent GetAIGroup()
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
proto external GenericEntity GetOwner()
Get owner entity.
IEntity GetOwner()
Owner entity of the fuel tank.
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.