Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableVehicleComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor (Editables)", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 }
5 
7 
9 class SCR_EditableVehicleComponent : SCR_EditableEntityComponent
10 {
11  protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
13  protected ref ScriptInvoker m_OnUIRefresh;
14 
15  protected int m_iPlayersInVehicle;
16 
17  //------------------------------------------------------------------------------------------------
20  {
21  return m_iPlayersInVehicle;
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  protected void OnFactionUpdate(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
26  {
27  if (m_OnUIRefresh)
28  m_OnUIRefresh.Invoke();
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  protected void OnDestroyed(IEntity owner)
33  {
34  if (m_OnUIRefresh)
35  m_OnUIRefresh.Invoke();
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  override Faction GetFaction()
40  {
41  //--- Destroyed entities have no faction
42  if (IsDestroyed())
43  return null;
44 
46  return m_VehicleFactionAffiliation.GetAffiliatedFaction();
47 
48  return null;
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  override ScriptInvoker GetOnUIRefresh()
53  {
54  if (!m_OnUIRefresh)
55  m_OnUIRefresh = new ScriptInvoker();
56 
57  return m_OnUIRefresh;
58  }
59 
60  //------------------------------------------------------------------------------------------------
62  {
64  return null;
65 
67  array<BaseCompartmentSlot> compartments = {};
68  for (int i = 0, count = m_CompartmentManager.GetCompartments(compartments); i < count; i++)
69  {
70  occupant = SCR_EditableEntityComponent.GetEditableEntity(compartments[i].GetOccupant());
71  if (occupant)
72  return occupant.GetAIGroup();
73  }
74  return null;
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  {
81  return null;
82 
84  array<BaseCompartmentSlot> compartments = {};
85  for (int i = 0, count = m_CompartmentManager.GetCompartments(compartments); i < count; i++)
86  {
87  occupant = SCR_EditableEntityComponent.GetEditableEntity(compartments[i].GetOccupant());
88  if (occupant)
89  return occupant;
90  }
91  return null;
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override int GetPlayerID()
96  {
98  return 0;
99 
100  PlayerManager playerManager = GetGame().GetPlayerManager();
101 
103  array<BaseCompartmentSlot> compartments = {};
104  int playerIdToReturn = 0;
105  for (int i = 0, count = m_CompartmentManager.GetCompartments(compartments); i < count; i++)
106  {
107  BaseCompartmentSlot compartment = compartments[i];
108  occupant = SCR_EditableEntityComponent.GetEditableEntity(compartment.GetOccupant());
109  if (occupant)
110  {
111  int playerId = occupant.GetPlayerID();
112  if (playerId <= 0)
113  continue;
114 
115  if (playerIdToReturn == 0)
116  playerIdToReturn = playerId;
117  else if (compartment.GetType() == ECompartmentType.Pilot)
118  return playerId;
119  }
120  }
121 
122  return playerIdToReturn;
123  }
124 
125  //------------------------------------------------------------------------------------------------
128  {
130  return;
131 
133  array<BaseCompartmentSlot> compartments = {};
134  PlayerManager playerManager = GetGame().GetPlayerManager();
135 
136  int playerCount = 0;
137  for (int i = 0, count = m_CompartmentManager.GetCompartments(compartments); i < count; i++)
138  {
139  occupant = SCR_EditableEntityComponent.GetEditableEntity(compartments[i].GetOccupant());
140  if (occupant)
141  {
142  int playerId = playerManager.GetPlayerIdFromControlledEntity(occupant.GetOwner());
143  if (playerId != 0)
144  playerCount++;
145  }
146  }
147 
148  m_iPlayersInVehicle = playerCount;
149  if (m_OnUIRefresh)
150  m_OnUIRefresh.Invoke();
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  override int GetCrew(out notnull array<CompartmentAccessComponent> crewCompartmentAccess, bool ignorePlayers = true)
155  {
156  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
157  if (!compartmentManager)
158  return 0;
159 
160  PlayerManager playerManager;
161 
162  //If Ignore players
163  if (ignorePlayers)
164  playerManager = GetGame().GetPlayerManager();
165 
166  array<IEntity> occupants = {};
167  compartmentManager.GetOccupants(occupants);
168  CompartmentAccessComponent compartmentAccess;
169 
170  foreach (IEntity occupant : occupants)
171  {
172  if (ignorePlayers && playerManager.GetPlayerIdFromControlledEntity(occupant) > 0)
173  continue;
174 
175  compartmentAccess = CompartmentAccessComponent.Cast(occupant.FindComponent(CompartmentAccessComponent));
176 
177  if (compartmentAccess && compartmentAccess.IsInCompartment())
178  crewCompartmentAccess.Insert(compartmentAccess);
179  }
180 
181  return crewCompartmentAccess.Count();
182  }
183 
184  //------------------------------------------------------------------------------------------------
186  protected void PlayerTeleportedFeedback()
187  {
188  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
189  if (!compartmentManager)
190  return;
191 
192  array<IEntity> occupants = {};
193  SCR_EditableCharacterComponent editableCharacter;
194  compartmentManager.GetOccupants(occupants);
195 
196  foreach (IEntity occupant : occupants)
197  {
198  editableCharacter = SCR_EditableCharacterComponent.Cast(occupant.FindComponent(SCR_EditableCharacterComponent));
199  if (editableCharacter)
200  editableCharacter.PlayerTeleportedByParentFeedback(true);
201  }
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  override void SetTransform(vector transform[4], bool changedByUser = false)
206  {
207  super.SetTransform(transform, changedByUser);
208 
209  //~ Add feedback to players that they are teleported when inside of the vehicle
211  }
212 
213  //--------------------------------------------------- Spawn occupants ---------------------------------------------------\\
214 
215  //------------------------------------------------------------------------------------------------
225  bool CanOccupyVehicleWithCharacters(array<ECompartmentType> compartmentTypes, bool checkHasDefaultOccupantsData, int playerID, bool checkEditorBudget = true, bool checkOccupyingFaction = true, bool checkForFreeCompartments = true, bool checkForFreeDefaultCompartments = false)
226  {
227  FactionKey factionKey = string.Empty;
228 
230  return false;
231 
232  if (checkOccupyingFaction)
233  {
235  if (uiInfo)
236  factionKey = uiInfo.GetFactionKey();
237  }
238 
239  bool hasEnoughBudgetForDefaultCompartments;
240  bool hasFreeDefaultCompartments;
241 
242  if (checkEditorBudget || checkForFreeDefaultCompartments)
243  hasEnoughBudgetForDefaultCompartments = HasEnoughBudgetForDefaultOccupants(compartmentTypes, playerID, EEditorMode.EDIT, hasFreeDefaultCompartments);
244 
245  if (checkEditorBudget && !hasEnoughBudgetForDefaultCompartments)
246  return false;
247 
248  if (checkForFreeDefaultCompartments && !hasFreeDefaultCompartments)
249  return false;
250 
251  return m_CompartmentManager.CanOccupy(compartmentTypes, checkHasDefaultOccupantsData, factionKey, checkOccupyingFaction, checkForFreeCompartments);
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  //~ Check if there is enough budget to spawn default occupants
256  protected bool HasEnoughBudgetForDefaultOccupants(array<ECompartmentType> compartmentTypes, int playerID, EEditorMode editorMode, out bool noFreeDefaultCompartments)
257  {
258  noFreeDefaultCompartments = true;
259 
260  array<BaseCompartmentSlot> compartments = {};
261 
262  //~ Get all free compartments of given types
263  foreach (ECompartmentType compartmentType : compartmentTypes)
264  {
265  m_CompartmentManager.GetFreeCompartmentsOfType(compartments, compartmentType);
266  }
267 
268  array<ResourceName> occupantsToSpawn = {};
269  ResourceName occupant;
270 
271  foreach (BaseCompartmentSlot compartment : compartments)
272  {
273  occupant = compartment.GetDefaultOccupantPrefab();
274  if (!occupant.IsEmpty())
275  occupantsToSpawn.Insert(occupant);
276  }
277 
278  //~ Is empty so it has enough budget but will also return that there are no free seats
279  if (occupantsToSpawn.IsEmpty())
280  {
281  noFreeDefaultCompartments = false;
282  return true;
283  }
284 
285  SCR_EditorManagerEntity editorManager;
286 
287  //~ Get EditorManager from given player
288  if (playerID > 0)
289  {
291  if (!editorCore)
292  return false;
293 
294  editorManager = editorCore.GetEditorManager(playerID);
295  }
296  //~ Get Editor manager from local player
297  else
298  {
299  editorManager = SCR_EditorManagerEntity.GetInstance();
300  }
301 
302  if (!editorManager)
303  return false;
304 
305  SCR_EditorModeEntity modeEntity = editorManager.FindModeEntity(editorMode);
306  if (!modeEntity)
307  return false;
308 
310  return contentBrowser && contentBrowser.CanPlace(occupantsToSpawn, EEditableEntityType.CHARACTER);
311  }
312 
313  //------------------------------------------------------------------------------------------------
316  void OccupyVehicleWithDefaultCharacters(notnull array<ECompartmentType> compartmentTypes)
317  {
318  m_CompartmentManager.SpawnDefaultOccupants(compartmentTypes);
319  }
320 
321  //------------------------------------------------------------------------------------------------
324  SCR_BaseCompartmentManagerComponent GetCompartmentManager()
325  {
326  return m_CompartmentManager;
327  }
328 
329  //------------------------------------------------------------------------------------------------
331  {
332  //~ No vehicle placing flag
333  if (!SCR_Enum.HasPartialFlag(flags, EEditorPlacingFlags.VEHICLE_CREWED | EEditorPlacingFlags.VEHICLE_PASSENGER))
334  return this;
335 
336  //~ Todo: Check if EEditorPlacingFlags.CHARACTER_PLAYER and spawn the first character as player. If Only EEditorPlacingFlags.CHARACTER_PLAYER add itself as pilot (or any other availible slots)
337 
339  array<ECompartmentType> compartmentsToFill = {};
340 
341  bool hasFreeSeats;
342 
343  //~ Check crew budget
344  if (SCR_Enum.HasFlag(flags, EEditorPlacingFlags.VEHICLE_CREWED) && HasEnoughBudgetForDefaultOccupants(SCR_BaseCompartmentManagerComponent.CREW_COMPARTMENT_TYPES, playerID, EEditorMode.EDIT, hasFreeSeats))
345  {
346  //~ Occupy with Crew
347  if (!uiInfo || !uiInfo.GetEditorPlaceAsOneGroup())
348  OccupyVehicleWithDefaultCharacters(SCR_BaseCompartmentManagerComponent.CREW_COMPARTMENT_TYPES);
349  else
350  compartmentsToFill.InsertAll(SCR_BaseCompartmentManagerComponent.CREW_COMPARTMENT_TYPES);
351  }
352 
353  //~ Check passenger budget
354  if (SCR_Enum.HasFlag(flags, EEditorPlacingFlags.VEHICLE_PASSENGER) && HasEnoughBudgetForDefaultOccupants(SCR_BaseCompartmentManagerComponent.PASSENGER_COMPARTMENT_TYPES, playerID, EEditorMode.EDIT, hasFreeSeats))
355  {
356  //~ Occupy with Passengers
357  if (!uiInfo || !uiInfo.GetEditorPlaceAsOneGroup())
358  OccupyVehicleWithDefaultCharacters(SCR_BaseCompartmentManagerComponent.PASSENGER_COMPARTMENT_TYPES);
359  else
360  compartmentsToFill.InsertAll(SCR_BaseCompartmentManagerComponent.PASSENGER_COMPARTMENT_TYPES);
361  }
362 
363  //~ Occupy vehicle with both Crew and Passengers in one group (If both placing flags where selected)
364  if (!compartmentsToFill.IsEmpty())
365  OccupyVehicleWithDefaultCharacters(compartmentsToFill);
366 
367  return this;
368  }
369 
370  //------------------------------------------------------------------------------------------------
371  override void EOnPhysicsActive(IEntity owner, bool activeState)
372  {
373  //--- Move to root when the vehicle is activated
374  if (activeState)
375  SetParentEntity(null);
376  //ClearEventMask(m_Owner, EntityEvent.PHYSICSACTIVE);
377  }
378 
379  //------------------------------------------------------------------------------------------------
380  override void OnPostInit(IEntity owner)
381  {
382  if (DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE))
383  return;
384 
385  super.OnPostInit(owner);
386 
387  //SetEventMask(owner, EntityEvent.PHYSICSACTIVE);
388 
389  m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(owner.FindComponent(SCR_BaseCompartmentManagerComponent));
392  m_VehicleFactionAffiliation.GetOnFactionChanged().Insert(OnFactionUpdate);
393 
394  EventHandlerManagerComponent eventHandlerManager = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
395  if (eventHandlerManager)
396  eventHandlerManager.RegisterScriptHandler("OnDestroyed", owner, OnDestroyed);
397  }
398 
399  //------------------------------------------------------------------------------------------------
400  // destructor
402  {
404  m_VehicleFactionAffiliation.GetOnFactionChanged().Remove(OnFactionUpdate);
405  }
406 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
OnFactionUpdate
protected void OnFactionUpdate(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
Definition: SCR_EditableVehicleComponent.c:25
SCR_VehicleFactionAffiliationComponent
Definition: SCR_VehicleFactionAffiliationComponent.c:6
GetOccupant
IEntity GetOccupant(IEntity slot)
Definition: SCR_CompositionSlotManagerComponent.c:72
SCR_Enum
Definition: SCR_Enum.c:1
IsDestroyed
override bool IsDestroyed()
Definition: SCR_EditableGroupComponent.c:433
GetAIEntity
override SCR_EditableEntityComponent GetAIEntity()
Definition: SCR_EditableVehicleComponent.c:78
GetPlayerID
override int GetPlayerID()
Definition: SCR_EditableVehicleComponent.c:95
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iPlayersInVehicle
protected int m_iPlayersInVehicle
Definition: SCR_EditableVehicleComponent.c:15
GetInfo
override SCR_UIInfo GetInfo(IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:140
GetOnUIRefresh
override ScriptInvoker GetOnUIRefresh()
Definition: SCR_EditableVehicleComponent.c:52
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
GetCrew
override int GetCrew(out notnull array< CompartmentAccessComponent > crewCompartmentAccess, bool ignorePlayers=true)
Definition: SCR_EditableVehicleComponent.c:154
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
GetAIGroup
override SCR_EditableEntityComponent GetAIGroup()
Definition: SCR_EditableVehicleComponent.c:61
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
SCR_ContentBrowserEditorComponent
Definition: SCR_ContentBrowserEditorComponent.c:16
CanOccupyVehicleWithCharacters
bool CanOccupyVehicleWithCharacters(array< ECompartmentType > compartmentTypes, bool checkHasDefaultOccupantsData, int playerID, bool checkEditorBudget=true, bool checkOccupyingFaction=true, bool checkForFreeCompartments=true, bool checkForFreeDefaultCompartments=false)
Definition: SCR_EditableVehicleComponent.c:225
m_CompartmentManager
SCR_EditableVehicleComponentClass m_CompartmentManager
Special configuration for editable wehicle.
PlayerTeleportedFeedback
protected void PlayerTeleportedFeedback()
Add feedback to players that they are teleported when inside of the vehicle.
Definition: SCR_EditableVehicleComponent.c:186
~SCR_EditableVehicleComponent
void ~SCR_EditableVehicleComponent()
Definition: SCR_EditableVehicleComponent.c:401
GetPlayerCountInVehicle
int GetPlayerCountInVehicle()
Definition: SCR_EditableVehicleComponent.c:19
OnDestroyed
protected void OnDestroyed(IEntity owner)
Definition: SCR_EditableVehicleComponent.c:32
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_EditableVehicleComponent.c:380
SCR_EditableVehicleComponentClass
Definition: SCR_EditableVehicleComponent.c:2
EEditorPlacingFlags
EEditorPlacingFlags
Definition: EEditorPlacingFlags.c:1
UpdatePlayerCountInVehicle
void UpdatePlayerCountInVehicle()
Definition: SCR_EditableVehicleComponent.c:127
m_VehicleFactionAffiliation
protected SCR_VehicleFactionAffiliationComponent m_VehicleFactionAffiliation
Definition: SCR_EditableVehicleComponent.c:12
SetTransform
override void SetTransform(vector transform[4], bool changedByUser=false)
Definition: SCR_EditableVehicleComponent.c:205
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
HasEnoughBudgetForDefaultOccupants
protected bool HasEnoughBudgetForDefaultOccupants(array< ECompartmentType > compartmentTypes, int playerID, EEditorMode editorMode, out bool noFreeDefaultCompartments)
Definition: SCR_EditableVehicleComponent.c:256
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
Faction
Definition: Faction.c:12
EOnEditorPlace
override SCR_EditableEntityComponent EOnEditorPlace(out SCR_EditableEntityComponent parent, SCR_EditableEntityComponent recipient, EEditorPlacingFlags flags, bool isQueue, int playerID=0)
Definition: SCR_EditableVehicleComponent.c:330
OccupyVehicleWithDefaultCharacters
void OccupyVehicleWithDefaultCharacters(notnull array< ECompartmentType > compartmentTypes)
Definition: SCR_EditableVehicleComponent.c:316
EOnPhysicsActive
override void EOnPhysicsActive(IEntity owner, bool activeState)
Definition: SCR_EditableVehicleComponent.c:371
m_OnUIRefresh
protected ref ScriptInvoker m_OnUIRefresh
Definition: SCR_EditableVehicleComponent.c:13
SetParentEntity
override SCR_EditableEntityComponent SetParentEntity(SCR_EditableEntityComponent parentEntity, bool changedByUser=false)
Definition: SCR_EditableCharacterComponent.c:289
GetCompartmentManager
SCR_BaseCompartmentManagerComponent GetCompartmentManager()
Definition: SCR_EditableVehicleComponent.c:324
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
GetFaction
override Faction GetFaction()
Definition: SCR_EditableVehicleComponent.c:39
PlayerManager
Definition: PlayerManager.c:12
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditableVehicleUIInfo
Definition: SCR_EditableVehicleUIInfo.c:2
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26