Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignMobileAssemblyComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Campaign", description: "Allow respawning at this vehicle in Campaign", color: "0 0 255 255")]
2 class SCR_CampaignMobileAssemblyComponentClass : ScriptComponentClass
3 {
4  [Attribute("{6D282026AB95FC81}Prefabs/MP/Campaign/CampaignMobileAssemblySpawnpoint.et", UIWidgets.ResourceNamePicker, "", "et")]
5  protected ResourceName m_sSpawnpointPrefab;
6 
7  //------------------------------------------------------------------------------------------------
9  ResourceName GetSpawnpointPrefab()
10  {
11  return m_sSpawnpointPrefab;
12  }
13 }
14 
15 class SCR_CampaignMobileAssemblyComponent : ScriptComponent
16 {
17  static const float MAX_WATER_DEPTH = 2.5;
18 
19  protected RplComponent m_RplComponent;
20 
22 
23  protected bool m_bIsInRadioRange;
24 
25  protected ref array<SCR_CampaignMilitaryBaseComponent> m_aBasesInRadioRange = {};
26  protected ref array<SCR_CampaignMilitaryBaseComponent> m_aBasesInRadioRangeOld = {};
27 
29 
30  protected SCR_CampaignMobileAssemblyStandaloneComponent m_StandaloneComponent;
31 
32  [RplProp(onRplName: "OnParentFactionIDSet")]
33  protected int m_iParentFaction = SCR_CampaignMilitaryBaseComponent.INVALID_FACTION_INDEX;
34 
35  [RplProp(onRplName: "OnSpawnpointCreated")]
36  protected int m_iSpawnpointId = RplId.Invalid();
37 
38  [RplProp(onRplName: "OnDeployChanged")]
39  protected bool m_bIsDeployed;
40 
41  //------------------------------------------------------------------------------------------------
42  override void OnPostInit(IEntity owner)
43  {
44  if (!GetGame().InPlayMode())
45  return;
46 
47  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
48 
49  if (!campaign)
50  return;
51 
52  super.OnPostInit(owner);
53 
54  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
55 
56  GetGame().GetCallqueue().CallLater(UpdateRadioCoverage, 1000, true);
57 
58  if (IsProxy())
59  {
60  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Insert(OnParentFactionIDSet);
61  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Insert(OnDeployChanged);
62  }
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  override void OnDelete(IEntity owner)
67  {
68  super.OnDelete(owner);
69 
70  GetGame().GetCallqueue().Remove(UpdateRadioCoverage);
71 
72  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
73 
74  if (!campaign)
75  return;
76 
77  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Remove(OnParentFactionIDSet);
78  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Remove(OnDeployChanged);
79  }
80 
81  //------------------------------------------------------------------------------------------------
84  {
85  array<SCR_MilitaryBaseComponent> bases = {};
86  SCR_MilitaryBaseSystem.GetInstance().GetBases(bases);
87 
88  float radioRange = GetRadioRange();
89  radioRange = radioRange * radioRange; // We're checking square distance
90  vector truckPosition = GetOwner().GetOrigin();
92 
94 
95  foreach (SCR_MilitaryBaseComponent base : bases)
96  {
97  campaignBase = SCR_CampaignMilitaryBaseComponent.Cast(base);
98 
99  if (!campaignBase || !campaignBase.IsInitialized())
100  continue;
101 
102  if (campaignBase.IsHQ() && campaignBase.GetFaction() != m_ParentFaction)
103  continue;
104 
105  if (vector.DistanceSqXZ(truckPosition, campaignBase.GetOwner().GetOrigin()) < radioRange)
106  m_aBasesInRadioRange.Insert(campaignBase);
107  }
108  }
109 
110  //------------------------------------------------------------------------------------------------
114  {
115  return m_aBasesInRadioRange.Contains(base);
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected bool IsProxy()
120  {
121  return (m_RplComponent && m_RplComponent.IsProxy());
122  }
123 
124  //------------------------------------------------------------------------------------------------
126  void SetParentFactionID(int factionID)
127  {
128  m_iParentFaction = factionID;
129  Replication.BumpMe();
131  }
132 
133  //------------------------------------------------------------------------------------------------
135  {
136  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
137 
138  if (!campaign)
139  return;
140 
141  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
142  SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
143  m_ParentFaction = SCR_CampaignFaction.Cast(fManager.GetFactionByIndex(m_iParentFaction));
144  }
145 
146  //------------------------------------------------------------------------------------------------
149  {
150  return m_iParentFaction;
151  }
152 
153  //------------------------------------------------------------------------------------------------
156  {
157  return m_ParentFaction;
158  }
159 
160  //------------------------------------------------------------------------------------------------
163  int GetBasesInRange(notnull out array<SCR_CampaignMilitaryBaseComponent> basesInRange)
164  {
165  return basesInRange.Copy(m_aBasesInRadioRange);
166  }
167 
168  //------------------------------------------------------------------------------------------------
171  {
172  IEntity truck = GetOwner().GetParent();
173 
174  if (!truck)
175  return 0;
176 
177  BaseRadioComponent comp = BaseRadioComponent.Cast(truck.FindComponent(BaseRadioComponent));
178 
179  if (!comp)
180  return 0;
181 
182  BaseTransceiver tsv = comp.GetTransceiver(0);
183 
184  if (!tsv)
185  return 0;
186 
187  return tsv.GetRange();
188  }
189 
190  //------------------------------------------------------------------------------------------------
195  bool Deploy(SCR_EMobileAssemblyStatus status, int playerId = 0)
196  {
197  if (!m_bIsInRadioRange && status == SCR_EMobileAssemblyStatus.DEPLOYED)
198  return false;
199 
200  if (!m_ParentFaction)
201  return false;
202 
203  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
204 
205  if (!campaign)
206  return false;
207 
208  if (m_ParentFaction.GetMobileAssembly() && status == SCR_EMobileAssemblyStatus.DEPLOYED)
209  return false;
210 
211  if (status == SCR_EMobileAssemblyStatus.DEPLOYED)
212  {
214  m_bIsDeployed = true;
215  }
216  else
217  {
218  m_bIsDeployed = false;
219 
220  if (m_SpawnPoint)
221  RplComponent.DeleteRplEntity(m_SpawnPoint, false);
222 
223  campaign.GetBaseManager().RecalculateRadioCoverage(m_ParentFaction);
224  }
225 
226  OnDeployChanged();
227  Replication.BumpMe();
228  campaign.BroadcastMHQFeedback(status, playerId, GetGame().GetFactionManager().GetFactionIndex(m_ParentFaction));
229 
230  return true;
231  }
232 
233  //------------------------------------------------------------------------------------------------
235  {
236  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
237  BaseRadioComponent radioComponent;
238 
239  IEntity vehicle = GetOwner().GetParent();
240 
241  if (vehicle)
242  radioComponent = BaseRadioComponent.Cast(vehicle.FindComponent(BaseRadioComponent));
243 
245 
246  if (m_bIsDeployed)
247  {
249 
250  if (!IsProxy())
251  {
252  if (radioComponent)
253  radioComponent.SetPower(true);
254 
255  if (GetTaskManager())
256  {
258 
259  if (supportClass)
260  supportClass.GenerateCaptureTasks(GetOwner());
261  }
262 
263  GetGame().GetCallqueue().CallLater(CheckStatus, 500, true);
264  }
265  }
266  else
267  {
269 
270  if (!IsProxy())
271  {
272  if (radioComponent)
273  radioComponent.SetPower(false);
274 
275  GetGame().GetCallqueue().Remove(CheckStatus);
276  }
277  }
278  }
279 
280  //------------------------------------------------------------------------------------------------
282  void CheckStatus()
283  {
284  IEntity truck = GetOwner().GetParent();
285 
286  if (!truck)
287  return;
288 
289  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
290 
291  if (!campaign)
292  return;
293 
294  DamageManagerComponent damageComponent = DamageManagerComponent.Cast(truck.FindComponent(DamageManagerComponent));
295 
296  // Destroyed?
297  if (damageComponent && damageComponent.GetState() == EDamageState.DESTROYED)
298  {
300 
301  return;
302  }
303 
304  // Moved?
305  Physics physicsComponent = truck.GetPhysics();
306 
307  if (!physicsComponent)
308  return;
309 
310  vector vel = physicsComponent.GetVelocity();
311  vel[1] = 0;
312 
313  if (vel.LengthSq() <= 0.01)
314  return;
315 
316  Deploy(SCR_EMobileAssemblyStatus.DISMANTLED);
317  }
318 
319  //------------------------------------------------------------------------------------------------
321  {
322  // Delay so spawnpoint has time to be streamed in for clients
323  GetGame().GetCallqueue().CallLater(RegisterSpawnpoint, 1000);
324  }
325 
326  //------------------------------------------------------------------------------------------------
329  {
330  // On server the assignment is done in CreateSpawnpoint()
331  if (!IsProxy())
332  return;
333 
334  m_SpawnPoint = SCR_SpawnPoint.Cast(Replication.FindItem(m_iSpawnpointId));
335 
336  if (!m_SpawnPoint)
337  return;
338 
339  m_StandaloneComponent = SCR_CampaignMobileAssemblyStandaloneComponent.Cast(m_SpawnPoint.FindComponent(SCR_CampaignMobileAssemblyStandaloneComponent));
340  }
341 
342  //------------------------------------------------------------------------------------------------
345  {
346  return m_SpawnPoint;
347  }
348 
349  //------------------------------------------------------------------------------------------------
351  SCR_CampaignMobileAssemblyStandaloneComponent GetStandaloneComponent()
352  {
353  return m_StandaloneComponent;
354  }
355 
356  //------------------------------------------------------------------------------------------------
358  bool IsDeployed()
359  {
360  return m_bIsDeployed;
361  }
362 
363  //------------------------------------------------------------------------------------------------
366  {
367  return m_bIsInRadioRange;
368  }
369 
370  //------------------------------------------------------------------------------------------------
373  {
374  if (!m_ParentFaction)
375  return;
376 
377  bool inRangeNow = SCR_GameModeCampaign.GetInstance().GetBaseManager().IsEntityInFactionRadioSignal(GetOwner(), m_ParentFaction);
378  bool refreshLinks = inRangeNow != m_bIsInRadioRange;
379  m_bIsInRadioRange = inRangeNow;
380  }
381 
382  //------------------------------------------------------------------------------------------------
385  {
387 
388  if (!componentData)
389  return;
390 
391  Resource spawnpointResource = Resource.Load(componentData.GetSpawnpointPrefab());
392 
393  if (!spawnpointResource || !spawnpointResource.IsValid())
394  return;
395 
396  EntitySpawnParams params = EntitySpawnParams();
397  params.TransformMode = ETransformMode.WORLD;
398  GetOwner().GetTransform(params.Transform);
399  m_SpawnPoint = SCR_SpawnPoint.Cast(GetGame().SpawnEntityPrefab(spawnpointResource, null, params));
400 
401  if (!m_SpawnPoint)
402  return;
403 
404  m_StandaloneComponent = SCR_CampaignMobileAssemblyStandaloneComponent.Cast(m_SpawnPoint.FindComponent(SCR_CampaignMobileAssemblyStandaloneComponent));
405 
407  {
408  m_StandaloneComponent.SetRadioRange(GetRadioRange());
409  m_StandaloneComponent.SetVehicle(SCR_EntityHelper.GetMainParent(GetOwner(), true));
410 
411  // Delay so map item can initialize
412  GetGame().GetCallqueue().CallLater(m_StandaloneComponent.SetParentFactionID, SCR_GameModeCampaign.MINIMUM_DELAY, false, m_iParentFaction);
413  }
414 
415  m_iSpawnpointId = Replication.FindId(m_SpawnPoint);
417  Replication.BumpMe();
418  }
419 
420  //------------------------------------------------------------------------------------------------
421  // destructor
423  {
424  if (Replication.IsClient())
425  return;
426 
427  if (m_SpawnPoint)
428  RplComponent.DeleteRplEntity(m_SpawnPoint, false);
429 
430  if (!m_ParentFaction || !IsDeployed())
431  return;
432 
433  Deploy(SCR_EMobileAssemblyStatus.DISMANTLED);
434  }
435 }
436 
438 {
442 }
GetStandaloneComponent
SCR_CampaignMobileAssemblyStandaloneComponent GetStandaloneComponent()
Definition: SCR_CampaignMobileAssemblyComponent.c:351
OnSpawnpointCreated
void OnSpawnpointCreated()
Definition: SCR_CampaignMobileAssemblyComponent.c:320
m_ParentFaction
protected SCR_CampaignFaction m_ParentFaction
Definition: SCR_CampaignMobileAssemblyComponent.c:21
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
GetBasesInRange
int GetBasesInRange(notnull out array< SCR_CampaignMilitaryBaseComponent > basesInRange)
Definition: SCR_CampaignMobileAssemblyComponent.c:163
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
m_bIsDeployed
protected bool m_bIsDeployed
Definition: SCR_CampaignMobileAssemblyComponent.c:39
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
OnParentFactionIDSet
void OnParentFactionIDSet()
Definition: SCR_CampaignMobileAssemblyComponent.c:134
SCR_CampaignTaskSupportEntity
Definition: SCR_CampaignTaskSupportEntity.c:8
GetSpawnPoint
SCR_SpawnPoint GetSpawnPoint()
Definition: SCR_CampaignMobileAssemblyComponent.c:344
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
DISMANTLED
@ DISMANTLED
Definition: SCR_CampaignMobileAssemblyComponent.c:440
GetFactionIndex
int GetFactionIndex()
Definition: SCR_EditableFactionComponent.c:57
SetParentFactionID
void SetParentFactionID(int factionID)
Definition: SCR_CampaignMobileAssemblyComponent.c:126
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_CampaignMobileAssemblyComponent.c:66
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
m_StandaloneComponent
protected SCR_CampaignMobileAssemblyStandaloneComponent m_StandaloneComponent
Definition: SCR_CampaignMobileAssemblyComponent.c:30
SCR_CampaignMobileAssemblyComponentClass
Definition: SCR_CampaignMobileAssemblyComponent.c:2
DESTROYED
@ DESTROYED
Definition: SCR_CampaignMobileAssemblyComponent.c:441
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
CreateSpawnpoint
void CreateSpawnpoint()
Definition: SCR_CampaignMobileAssemblyComponent.c:384
m_aBasesInRadioRangeOld
protected ref array< SCR_CampaignMilitaryBaseComponent > m_aBasesInRadioRangeOld
Definition: SCR_CampaignMobileAssemblyComponent.c:26
IsDeployed
bool IsDeployed()
Definition: SCR_CampaignMobileAssemblyComponent.c:358
CanReachByRadio
bool CanReachByRadio(notnull SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignMobileAssemblyComponent.c:113
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_aBasesInRadioRange
protected ref array< SCR_CampaignMilitaryBaseComponent > m_aBasesInRadioRange
Definition: SCR_CampaignMobileAssemblyComponent.c:25
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
OnDeployChanged
void OnDeployChanged()
Definition: SCR_CampaignMobileAssemblyComponent.c:234
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CampaignMobileAssemblyComponent.c:42
IsInRadioRange
bool IsInRadioRange()
Definition: SCR_CampaignMobileAssemblyComponent.c:365
MAX_WATER_DEPTH
SCR_CampaignMobileAssemblyComponentClass MAX_WATER_DEPTH
~SCR_CampaignMobileAssemblyComponent
void ~SCR_CampaignMobileAssemblyComponent()
Definition: SCR_CampaignMobileAssemblyComponent.c:422
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignMobileAssemblyComponent.c:119
UpdateBasesInRadioRange
void UpdateBasesInRadioRange()
Definition: SCR_CampaignMobileAssemblyComponent.c:83
m_SpawnPoint
protected SCR_SpawnPoint m_SpawnPoint
Definition: SCR_CampaignMobileAssemblyComponent.c:28
BaseTransceiver
Definition: BaseTransceiver.c:12
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Faction
Definition: Faction.c:12
m_bIsInRadioRange
protected bool m_bIsInRadioRange
Definition: SCR_CampaignMobileAssemblyComponent.c:23
GetRadioRange
int GetRadioRange()
Definition: SCR_CampaignMobileAssemblyComponent.c:170
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
Deploy
bool Deploy(SCR_EMobileAssemblyStatus status, int playerId=0)
Definition: SCR_CampaignMobileAssemblyComponent.c:195
UpdateRadioCoverage
void UpdateRadioCoverage()
Definition: SCR_CampaignMobileAssemblyComponent.c:372
SCR_EMobileAssemblyStatus
SCR_EMobileAssemblyStatus
Definition: SCR_CampaignMobileAssemblyComponent.c:437
GetParentFaction
SCR_CampaignFaction GetParentFaction()
Definition: SCR_CampaignMobileAssemblyComponent.c:155
m_iSpawnpointId
protected int m_iSpawnpointId
Definition: SCR_CampaignMobileAssemblyComponent.c:36
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
GetParentFactionID
int GetParentFactionID()
Definition: SCR_CampaignMobileAssemblyComponent.c:148
DEPLOYED
@ DEPLOYED
Definition: SCR_CampaignMobileAssemblyComponent.c:439
m_iParentFaction
protected int m_iParentFaction
Definition: SCR_CampaignMobileAssemblyComponent.c:33
DamageManagerComponent
Definition: DamageManagerComponent.c:12
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignMobileAssemblyComponent.c:19
RegisterSpawnpoint
void RegisterSpawnpoint()
Definition: SCR_CampaignMobileAssemblyComponent.c:328
CheckStatus
void CheckStatus()
Definition: SCR_CampaignMobileAssemblyComponent.c:282
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180