Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnOccupantsContextAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  [Attribute(desc: "Compartments Types To fill with characters within vehicle.", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(ECompartmentType))]
6  protected ref array<ECompartmentType> m_aCompartmentsTypes;
7 
8  //~ Store vehicles to spawn occupants in
9  protected ref map<SCR_BaseCompartmentManagerComponent, SCR_EditableVehicleComponent> m_VehiclesToOccupyQueue = new map<SCR_BaseCompartmentManagerComponent, SCR_EditableVehicleComponent>();
10 
11  protected bool m_bHasSendNotEnoughBudgetNotification = false;
12  protected bool m_bIsSpawningOccupants = false;
13 
14  override bool CanBeShown(SCR_EditableEntityComponent selectedEntity, vector cursorWorldPosition, int flags)
15  {
16  //~ Disabled until the system is reworked. HasEnoughBudgetForDefaultOccupants should be called here or at least in the budget component and the player Id needs to be send over to get the contentbrowser!
17  return false;
18 
19  SCR_EditableVehicleUIInfo uiInfo = SCR_EditableVehicleUIInfo.Cast(selectedEntity.GetInfo());
20  if (!uiInfo || (uiInfo && !uiInfo.CanFillWithGivenTypes(m_aCompartmentsTypes)))
21  return false;
22 
23  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(selectedEntity.GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
24 
25  return compartmentManager && compartmentManager.HasDefaultOccupantsDataForTypes(m_aCompartmentsTypes);
26  }
27 
28  override bool CanBePerformed(SCR_EditableEntityComponent selectedEntity, vector cursorWorldPosition, int flags)
29  {
30  //~ Disabled until the system is reworked. HasEnoughBudgetForDefaultOccupants should be called here or at least in the budget component and the player Id needs to be send over to get the contentbrowser!
31  return false;
32 
33  SCR_EditableVehicleComponent vehicle = SCR_EditableVehicleComponent.Cast(selectedEntity);
34  return vehicle && vehicle.CanOccupyVehicleWithCharacters(m_aCompartmentsTypes, -1, false, true, true, true, true);
35  }
36 
37  //~ Makes sure CanBePerformed is not executed twice
38  override void Perform(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition,int flags, int param = -1)
39  {
40  if (!InitPerform()) return;
41 
42  foreach (SCR_EditableEntityComponent entity : selectedEntities)
43  Perform(entity, cursorWorldPosition);
44  }
45 
46  override void Perform(SCR_EditableEntityComponent selectedEntity, vector cursorWorldPosition)
47  {
48  //~ Disabled until the system is reworked. HasEnoughBudgetForDefaultOccupants should be called here or at least in the budget component and the player Id needs to be send over to get the contentbrowser!
49  return;
50 
51  SCR_EditableVehicleComponent vehicle = SCR_EditableVehicleComponent.Cast(selectedEntity);
52  if (!vehicle)
53  return;
54 
55  SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(vehicle.GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
56  if (!compartmentManager)
57  return;
58 
59  //~ Already being spawned
60  if (m_VehiclesToOccupyQueue.Contains(compartmentManager))
61  return;
62 
63  //~ Add to spawn que
64  m_VehiclesToOccupyQueue.Insert(compartmentManager, vehicle);
65 
66  //~ If not yet spawning start spawn logic
67  if (!m_bIsSpawningOccupants)
68  {
69  m_bIsSpawningOccupants = true;
70 
71  //~ Start spawning by calling spawn next
72  SpawnNextOccupantsInEntity();
73  }
74  }
75 
76  //~ When done spawning characters in entity
77  protected void SpawnNextOccupantsInEntity(SCR_BaseCompartmentManagerComponent compartmentManager = null, array<IEntity> spawnedCharacters = null, bool wasCanceled = false)
78  {
79  //~ Remove listener
80  if (compartmentManager)
81  {
82  compartmentManager.GetOnDoneSpawningDefaultOccupants().Remove(SpawnNextOccupantsInEntity);
83  m_VehiclesToOccupyQueue.Remove(compartmentManager);
84  }
85 
86  //~ Nothing more to spawn so set spawning done
87  if (m_VehiclesToOccupyQueue.IsEmpty())
88  {
89  SetSpawningDone();
90  return;
91  }
92 
93  SCR_EditableVehicleComponent vehicleToOccupy = m_VehiclesToOccupyQueue.GetElement(0);
94 
95  //~ Entry is empty meaning that it was deleted so call the next in entry
96  if (!vehicleToOccupy)
97  {
98  m_VehiclesToOccupyQueue.RemoveElement(0);
99  SpawnNextOccupantsInEntity(null, null, false);
100  return;
101  }
102 
103  //~ Grab the new compartment
104  compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(vehicleToOccupy.GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
105 
106  //~ Check if compartment exists (which should always be the cause). But try spawn next if it does not
107  if (!compartmentManager)
108  {
109  m_VehiclesToOccupyQueue.RemoveElement(0);
110  SpawnNextOccupantsInEntity(null, null, false);
111  return;
112  }
113 
114  //~ No longer valid to spawn
115  if (!vehicleToOccupy.CanOccupyVehicleWithCharacters(m_aCompartmentsTypes, -1, true, checkEditorBudget: false, checkForFreeDefaultCompartments: true))
116  {
117  m_VehiclesToOccupyQueue.RemoveElement(0);
118  SpawnNextOccupantsInEntity(null, null, false);
119  return;
120  }
121 
122  //~ No longer valid budget
123  if (!vehicleToOccupy.CanOccupyVehicleWithCharacters(m_aCompartmentsTypes, -1, false, true, false, false, true))
124  {
125  //~ Todo get player ID to send notification
126  /*if (!m_bHasSendNotEnoughBudgetNotification)
127  {
128  m_bHasSendNotEnoughBudgetNotification = true;
129  SCR_NotificationsComponent.SendToPlayer(playerID, ENotification.EDITOR_PLACING_BUDGET_MAX_FOR_VEHICLE_OCCUPANTS);
130  }*/
131 
132  m_VehiclesToOccupyQueue.RemoveElement(0);
133  SpawnNextOccupantsInEntity(null, null, false);
134  return;
135  }
136 
137  //~ Fill next vehicle in queue
138  compartmentManager.GetOnDoneSpawningDefaultOccupants().Insert(SpawnNextOccupantsInEntity);
139  vehicleToOccupy.OccupyVehicleWithDefaultCharacters(m_aCompartmentsTypes);
140  }
141 
142  protected void SetSpawningDone()
143  {
144  m_VehiclesToOccupyQueue.Clear();
145  m_bIsSpawningOccupants = false;
146  m_bHasSendNotEnoughBudgetNotification = false;
147  }
148 };
ECompartmentType
ECompartmentType
Definition: ECompartmentType.c:7
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_SelectedEntitiesContextAction
Definition: SCR_SelectedEntitiesContextAction.c:10
SCR_SpawnOccupantsContextAction
Definition: SCR_SpawnOccupantsContextAction.c:3
SCR_BaseContainerCustomTitleUIInfo
void SCR_BaseContainerCustomTitleUIInfo(string propertyName, string format="%1")
Definition: Attributes.c:788
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_EditableVehicleUIInfo
Definition: SCR_EditableVehicleUIInfo.c:2