Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AmbientVehicleSpawnPointComponent.c
Go to the documentation of this file.
1 class SCR_AmbientVehicleSpawnPointComponentClass : ScriptComponentClass
2 {
3 }
4 
5 class SCR_AmbientVehicleSpawnPointComponent : ScriptComponent
6 {
7  [Attribute("0", UIWidgets.EditBox, "How often will the vehicle respawn when destroyed. (seconds, 0 = no respawn)", "0 inf 1")]
8  protected int m_iRespawnPeriod;
9 
10  [Attribute("0", UIWidgets.ComboBox, "Select Entity Labels which you want to optionally include to random spawn. If you want to spawn everything, you can leave it out empty.", "", ParamEnumArray.FromEnum(EEditableEntityLabel))]
11  protected ref array<EEditableEntityLabel> m_aIncludedEditableEntityLabels;
12 
13  [Attribute("0", UIWidgets.ComboBox, "Select Entity Labels which you want to exclude from random spawn.", "", ParamEnumArray.FromEnum(EEditableEntityLabel))]
14  protected ref array<EEditableEntityLabel> m_aExcludedEditableEntityLabels;
15 
16  [Attribute("0", desc: "If true, only assets with ALL of provided included labels will be used.")]
18 
19  protected static const int SPAWNING_RADIUS = 5; //m, check empty space on a spawnpoint with this radius
20 
21  protected bool m_bDepleted;
22  protected bool m_bFirstSpawnDone;
23  protected bool m_bSpawnProcessed;
24 
25  protected int m_iID;
26 
27  protected WorldTimestamp m_fRespawnTimestamp;
28  protected WorldTimestamp m_fDespawnTimer;
29 
30  protected ResourceName m_sPrefab;
31 
32  protected Vehicle m_Vehicle;
33 
35 
36  //------------------------------------------------------------------------------------------------
39  {
40  return m_iRespawnPeriod;
41  }
42 
43  //------------------------------------------------------------------------------------------------
45  void SetID(int ID)
46  {
47  m_iID = ID;
48  }
49 
50  //------------------------------------------------------------------------------------------------
52  int GetID()
53  {
54  return m_iID;
55  }
56 
57  //------------------------------------------------------------------------------------------------
59  void SetIsDepleted(bool depleted)
60  {
61  m_bDepleted = depleted;
62  }
63 
64  //------------------------------------------------------------------------------------------------
67  {
68  return m_bDepleted;
69  }
70 
71  //------------------------------------------------------------------------------------------------
74  {
75  return m_bFirstSpawnDone;
76  }
77 
78  //------------------------------------------------------------------------------------------------
81  {
82  return m_bSpawnProcessed;
83  }
84 
85  //------------------------------------------------------------------------------------------------
87  void SetDespawnTimer(WorldTimestamp time)
88  {
89  m_fDespawnTimer = time;
90  }
91 
92  //------------------------------------------------------------------------------------------------
94  WorldTimestamp GetDespawnTimer()
95  {
96  return m_fDespawnTimer;
97  }
98 
99  //------------------------------------------------------------------------------------------------
101  void SetRespawnTimestamp(WorldTimestamp timestamp)
102  {
103  m_fRespawnTimestamp = timestamp;
104  }
105 
106  //------------------------------------------------------------------------------------------------
108  WorldTimestamp GetRespawnTimestamp()
109  {
110  return m_fRespawnTimestamp;
111  }
112 
113  //------------------------------------------------------------------------------------------------
116  {
117  return m_Vehicle;
118  }
119 
120  //------------------------------------------------------------------------------------------------
123  Vehicle SpawnVehicle()
124  {
126 
127  if (!comp)
128  return null;
129 
130  SCR_Faction faction = SCR_Faction.Cast(comp.GetAffiliatedFaction());
131 
132  if (!faction)
133  faction = SCR_Faction.Cast(comp.GetDefaultAffiliatedFaction());
134 
135  if (faction != m_SavedFaction || (!faction && m_sPrefab.IsEmpty()))
136  Update(faction);
137 
138  if (m_sPrefab.IsEmpty())
139  return null;
140 
141  Resource prefab = Resource.Load(m_sPrefab);
142 
143  if (!prefab || !prefab.IsValid())
144  return null;
145 
146  vector pos;
147  bool spawnEmpty = SCR_WorldTools.FindEmptyTerrainPosition(pos, GetOwner().GetOrigin(), SPAWNING_RADIUS, SPAWNING_RADIUS);
148 
149  if (!spawnEmpty)
150  {
151 #ifdef WORKBENCH
152  Print("SCR_AmbientVehicleSpawnPointComponent: FindEmptyTerrainPosition failed at " + GetOwner().GetOrigin().ToString(), LogLevel.WARNING);
153 #endif
154 
155  // In case this spawnpoint is blocked from the start, don't process it anymore
156  // Prevents unexpected behavior such as vehicles spawning on a spot where a service composition has been built and after a session load dismantled
157  if (!m_bFirstSpawnDone)
158  m_bDepleted = true;
159 
160  return null;
161  }
162 
163  EntitySpawnParams params = EntitySpawnParams();
164  params.TransformMode = ETransformMode.WORLD;
165  GetOwner().GetTransform(params.Transform);
166 
167  m_Vehicle = Vehicle.Cast(GetGame().SpawnEntityPrefab(prefab, null, params));
168  m_fRespawnTimestamp = null;
169  m_bFirstSpawnDone = true;
170  m_bSpawnProcessed = true;
171 
172  if (!m_Vehicle)
173  return null;
174 
175  CarControllerComponent_SA carController = CarControllerComponent_SA.Cast(m_Vehicle.FindComponent(CarControllerComponent_SA));
176 
177  // Activate handbrake so the vehicles don't go downhill on their own when spawned
178  if (carController)
179  carController.SetPersistentHandBrake(true);
180 
181  Physics physicsComponent = m_Vehicle.GetPhysics();
182 
183  // Snap to terrain
184  if (physicsComponent)
185  physicsComponent.SetVelocity("0 -1 0");
186 
187  EventHandlerManagerComponent handler = EventHandlerManagerComponent.Cast(m_Vehicle.FindComponent(EventHandlerManagerComponent));
188 
189  if (handler)
190  handler.RegisterScriptHandler("OnDestroyed", this, OnVehicleDestroyed);
191 
192  return m_Vehicle;
193  }
194 
195  //------------------------------------------------------------------------------------------------
197  void OnVehicleDestroyed(IEntity vehicle)
198  {
199  m_Vehicle = null;
200 
201  if (m_iRespawnPeriod > 0)
202  {
203  ChimeraWorld world = GetOwner().GetWorld();
204  m_fRespawnTimestamp = world.GetServerTimestamp().PlusSeconds(m_iRespawnPeriod);
205  }
206  else
207  m_bDepleted = true;
208  }
209 
210  //------------------------------------------------------------------------------------------------
213  {
214  m_fDespawnTimer = null;
215  m_bSpawnProcessed = false;
216 
217  if (!m_Vehicle)
218  return;
219 
220  RplComponent.DeleteRplEntity(m_Vehicle, false);
221  }
222 
223  //------------------------------------------------------------------------------------------------
224  protected void Update(SCR_Faction faction)
225  {
226  m_SavedFaction = faction;
227  SCR_EntityCatalog entityCatalog;
228 
229  if (faction)
230  {
231  entityCatalog = faction.GetFactionEntityCatalogOfType(EEntityCatalogType.VEHICLE);
232  }
233  else
234  {
235  SCR_EntityCatalogManagerComponent comp = SCR_EntityCatalogManagerComponent.GetInstance();
236 
237  if (!comp)
238  return;
239 
240  entityCatalog = comp.GetEntityCatalogOfType(EEntityCatalogType.VEHICLE);
241  }
242 
243  if (!entityCatalog)
244  return;
245 
246  array<SCR_EntityCatalogEntry> data = {};
247  entityCatalog.GetFullFilteredEntityListWithLabels(data, m_aIncludedEditableEntityLabels, m_aExcludedEditableEntityLabels, m_bRequireAllIncludedLabels);
248 
249  if (data.IsEmpty())
250  return;
251 
252  Math.Randomize(-1);
253  m_sPrefab = (data.GetRandomElement().GetPrefab());
254  }
255 
256  //------------------------------------------------------------------------------------------------
257  override void OnPostInit(IEntity owner)
258  {
260 
261  if (!factionComponent)
262  {
263  Print("SCR_AmbientVehicleSpawnPointComponent: SCR_FactionAffiliationComponent not found on owner entity. Vehicle spawning will not be available.", LogLevel.WARNING);
264  return;
265  }
266 
267  SetEventMask(owner, EntityEvent.INIT);
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  override void EOnInit(IEntity owner)
272  {
273  SCR_AmbientVehicleSystem manager = SCR_AmbientVehicleSystem.GetInstance();
274 
275  if (!manager)
276  return;
277 
278  manager.RegisterSpawnpoint(this);
279  }
280 
281  //------------------------------------------------------------------------------------------------
282  // destructor
284  {
285  SCR_AmbientVehicleSystem manager = SCR_AmbientVehicleSystem.GetInstance();
286 
287  if (!manager)
288  return;
289 
290  manager.UnregisterSpawnpoint(this);
291  }
292 }
ChimeraWorld
Definition: ChimeraWorld.c:12
EEditableEntityLabel
EEditableEntityLabel
Definition: EEditableEntityLabel.c:1
GetID
int GetID()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:52
m_iID
protected int m_iID
Definition: SCR_AmbientVehicleSpawnPointComponent.c:25
m_bRequireAllIncludedLabels
protected bool m_bRequireAllIncludedLabels
Definition: SCR_AmbientVehicleSpawnPointComponent.c:17
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
SetDespawnTimer
void SetDespawnTimer(WorldTimestamp time)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:87
Attribute
SCR_AmbientVehicleSpawnPointComponentClass ScriptComponentClass Attribute("0", UIWidgets.EditBox, "How often will the vehicle respawn when destroyed. (seconds, 0 = no respawn)", "0 inf 1")] protected int m_iRespawnPeriod
SCR_AmbientVehicleSpawnPointComponentClass
Definition: SCR_AmbientVehicleSpawnPointComponent.c:1
GetIsFirstSpawnDone
bool GetIsFirstSpawnDone()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:73
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
m_fRespawnTimestamp
protected WorldTimestamp m_fRespawnTimestamp
Definition: SCR_AmbientVehicleSpawnPointComponent.c:27
DespawnVehicle
void DespawnVehicle()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:212
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
~SCR_AmbientVehicleSpawnPointComponent
void ~SCR_AmbientVehicleSpawnPointComponent()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:283
SCR_WorldTools
Definition: SCR_WorldTools.c:1
m_bFirstSpawnDone
protected bool m_bFirstSpawnDone
Definition: SCR_AmbientVehicleSpawnPointComponent.c:22
m_bDepleted
protected bool m_bDepleted
Definition: SCR_AmbientVehicleSpawnPointComponent.c:21
Update
protected void Update(SCR_Faction faction)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:224
m_aIncludedEditableEntityLabels
protected ref array< EEditableEntityLabel > m_aIncludedEditableEntityLabels
Definition: SCR_AmbientVehicleSpawnPointComponent.c:11
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
m_bSpawnProcessed
protected bool m_bSpawnProcessed
Definition: SCR_AmbientVehicleSpawnPointComponent.c:23
GetDespawnTimer
WorldTimestamp GetDespawnTimer()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:94
m_fDespawnTimer
protected WorldTimestamp m_fDespawnTimer
Definition: SCR_AmbientVehicleSpawnPointComponent.c:28
SpawnVehicle
Vehicle SpawnVehicle()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:123
m_iRespawnPeriod
protected int m_iRespawnPeriod
Definition: SCR_AmbientPatrolSpawnPointComponent.c:33
m_Vehicle
protected Vehicle m_Vehicle
Definition: SCR_AmbientVehicleSpawnPointComponent.c:32
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AmbientVehicleSpawnPointComponent.c:257
m_SavedFaction
protected Faction m_SavedFaction
Definition: SCR_AmbientVehicleSpawnPointComponent.c:34
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SetID
void SetID(int ID)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:45
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:271
Faction
Definition: Faction.c:12
m_aExcludedEditableEntityLabels
protected ref array< EEditableEntityLabel > m_aExcludedEditableEntityLabels
Definition: SCR_AmbientVehicleSpawnPointComponent.c:14
SCR_EntityCatalog
Definition: SCR_EntityCatalog.c:181
GetIsSpawnProcessed
bool GetIsSpawnProcessed()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:80
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
OnVehicleDestroyed
void OnVehicleDestroyed(IEntity vehicle)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:197
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_FactionAffiliationComponent
Definition: SCR_FactionAffiliationComponent.c:10
GetIsDepleted
bool GetIsDepleted()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:66
SetRespawnTimestamp
void SetRespawnTimestamp(WorldTimestamp timestamp)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:101
GetRespawnTimestamp
WorldTimestamp GetRespawnTimestamp()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:108
GetRespawnPeriod
int GetRespawnPeriod()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:38
SCR_Faction
Definition: SCR_Faction.c:6
SetIsDepleted
void SetIsDepleted(bool depleted)
Definition: SCR_AmbientVehicleSpawnPointComponent.c:59
SCR_AmbientVehicleSystem
Definition: SCR_AmbientVehicleSystem.c:8
m_sPrefab
protected ResourceName m_sPrefab
Definition: SCR_AmbientVehicleSpawnPointComponent.c:30
GetSpawnedVehicle
Vehicle GetSpawnedVehicle()
Definition: SCR_AmbientVehicleSpawnPointComponent.c:115