Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignMobileAssemblyStandaloneComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_CampaignMobileAssemblyStandaloneComponent : ScriptComponent
6 {
8  static ref ScriptInvokerVoid s_OnUpdateRespawnCooldown = new ScriptInvokerVoid();
9 
10  static const int RESPAWN_COOLDOWN = 60000;
11 
12  protected RplComponent m_RplComponent;
13 
14  protected MapItem m_MapItem;
15 
16  protected IEntity m_Vehicle;
17 
20 
21  protected bool m_bIsInRadioRange;
22  protected bool m_bCooldownDone = true;
23  protected bool m_bIsHovered;
24 
25  protected ref array<MapLink> m_aMapLinks = {};
26  protected ref array<SCR_CampaignMilitaryBaseComponent> m_aBasesInRadioRange = {};
27  protected ref array<SCR_CampaignMilitaryBaseComponent> m_aBasesInRadioRangeOld = {};
28 
29  [RplProp(onRplName: "OnFactionChanged")]
30  protected int m_iFaction = SCR_CampaignMilitaryBaseComponent.INVALID_FACTION_INDEX;
31 
32  [RplProp(onRplName: "OnParentFactionIDSet")]
33  protected int m_iParentFaction = SCR_CampaignMilitaryBaseComponent.INVALID_FACTION_INDEX;
34 
35  [RplProp()]
36  protected WorldTimestamp m_fRespawnAvailableSince;
37  [RplProp()]
38  protected int m_iBasesCoveredByMHQOnly;
39 
40  [RplProp()]
41  protected int m_iRadioRange;
42 
43  //------------------------------------------------------------------------------------------------
44  override void OnPostInit(IEntity owner)
45  {
46  if (!GetGame().InPlayMode())
47  return;
48 
49  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
50 
51  if (!campaign)
52  return;
53 
54  super.OnPostInit(owner);
55 
56  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
57 
58  GetGame().GetCallqueue().CallLater(UpdateRadioCoverage, 1000, true);
59  GetGame().GetCallqueue().CallLater(UpdateRespawnCooldown, 250, true, null);
60 
61  if (IsProxy())
62  {
63  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Insert(OnParentFactionIDSet);
64  }
65  else
66  {
67  // Only update respawn cooldown if a load state has not been applied
68  ChimeraWorld world = GetGame().GetWorld();
69  if (world.GetWorldTime() > 10000)
70  {
71  m_fRespawnAvailableSince = world.GetServerTimestamp().PlusMilliseconds(RESPAWN_COOLDOWN);
72  m_bCooldownDone = false;
73  }
74  else
75  {
76  m_fRespawnAvailableSince = world.GetServerTimestamp();
77  m_bCooldownDone = true;
78  }
79  Replication.BumpMe();
80  }
81 
82  if (RplSession.Mode() == RplMode.Dedicated)
83  return;
84 
85  // Delay so map links can operate with properly loaded (or deleted) spawnpoint
86  GetGame().GetCallqueue().CallLater(HandleMapLinks, 1000, false, false);
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override void OnDelete(IEntity owner)
91  {
92  super.OnDelete(owner);
93 
94  GetGame().GetCallqueue().Remove(UpdateRadioCoverage);
95  GetGame().GetCallqueue().Remove(UpdateRespawnCooldown);
96 
97  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
98 
99  if (!campaign)
100  return;
101 
102  if (RplSession.Mode() != RplMode.Dedicated)
103  {
105  m_aBasesInRadioRange.Clear();
106  HandleMapLinks(true);
107  }
108 
109  campaign.GetInstance().GetOnFactionAssignedLocalPlayer().Remove(OnParentFactionIDSet);
110  }
111 
112  //------------------------------------------------------------------------------------------------
115  {
116  array<SCR_MilitaryBaseComponent> bases = {};
117  SCR_MilitaryBaseSystem.GetInstance().GetBases(bases);
118 
119  int radioRange = m_iRadioRange * m_iRadioRange; // We're checking square distance
120  vector truckPosition = GetOwner().GetOrigin();
122 
124 
125  foreach (SCR_MilitaryBaseComponent base : bases)
126  {
127  campaignBase = SCR_CampaignMilitaryBaseComponent.Cast(base);
128 
129  if (!campaignBase || !campaignBase.IsInitialized())
130  continue;
131 
132  if (campaignBase.IsHQ() && campaignBase.GetFaction() != m_ParentFaction)
133  continue;
134 
135  if (vector.DistanceSqXZ(truckPosition, campaignBase.GetOwner().GetOrigin()) < radioRange)
136  m_aBasesInRadioRange.Insert(campaignBase);
137  }
138  }
139 
140  //------------------------------------------------------------------------------------------------
145  {
146  return m_aBasesInRadioRange.Contains(base);
147  }
148 
149  //------------------------------------------------------------------------------------------------
152  void OnIconHovered(SCR_CampaignMapUIBase icon, bool hovering)
153  {
154  m_bIsHovered = hovering;
155 
156  foreach (MapLink link : m_aMapLinks)
157  {
158  if (!link)
159  continue;
160 
161  ColorMapLink(link);
162  }
163  }
164 
165  //------------------------------------------------------------------------------------------------
168  void ColorMapLink(notnull MapLink link)
169  {
170  if (!m_ParentFaction)
171  return;
172 
173  MapLinkProps props = link.GetMapLinkProps();
174 
175  if (!props)
176  return;
177 
179 
180  if (!hq)
181  return;
182 
183  props.SetLineWidth(hq.GetLineWidth());
184 
185  Color c = Color.FromInt(props.GetLineColor().PackToInt());
186 
187  if (!c)
188  return;
189 
190  SCR_GraphLinesData linesData = hq.GetGraphLinesData();
191 
192  if (m_bIsHovered)
193  {
194  // Highlight only bases in range
195  MapItem otherEnd = link.Target();
196 
197  if (otherEnd == m_MapItem)
198  otherEnd = link.Owner();
199 
200  IEntity otherEndOwner = otherEnd.Entity();
201 
202  if (!otherEndOwner)
203  return;
204 
206 
207  if (!base)
208  return;
209 
210  if (!m_aBasesInRadioRange.Contains(base))
211  return;
212 
213  c.SetA(linesData.GetHighlightedAlpha());
214  }
215  else
216  {
217  c.SetA(linesData.GetDefaultAlpha());
218  }
219 
220  props.SetLineColor(c);
221  }
222 
223  //------------------------------------------------------------------------------------------------
224  protected void HandleMapLinks(bool onDelete = false)
225  {
227  {
228  if (!m_aBasesInRadioRange.Contains(base))
229  base.GetMapDescriptor().HandleMapLinks(onDelete);
230  }
231 
233  {
234  base.GetMapDescriptor().HandleMapLinks();
235  }
236  }
237 
238  //------------------------------------------------------------------------------------------------
241  void AddMapLink(notnull MapLink link)
242  {
243  m_aMapLinks.Insert(link);
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  protected bool IsProxy()
248  {
249  return (m_RplComponent && m_RplComponent.IsProxy());
250  }
251 
252  //------------------------------------------------------------------------------------------------
254  void SetVehicle(IEntity vehicle)
255  {
256  m_Vehicle = vehicle;
257  }
258 
259  //------------------------------------------------------------------------------------------------
261  IEntity GetVehicle()
262  {
263  return m_Vehicle;
264  }
265 
266  //------------------------------------------------------------------------------------------------
268  void SetParentFactionID(int factionID)
269  {
270  m_iParentFaction = factionID;
271  Replication.BumpMe();
273  }
274 
275  //------------------------------------------------------------------------------------------------
277  {
278  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
279 
280  if (!campaign)
281  return;
282 
283  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
284  SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
285  m_ParentFaction = SCR_CampaignFaction.Cast(fManager.GetFactionByIndex(m_iParentFaction));
286 
287  if (!m_ParentFaction)
288  return;
289 
290  m_ParentFaction.SetMobileAssembly(this);
291 
292  if (RplSession.Mode() != RplMode.Dedicated)
293  {
294  SCR_MapDescriptorComponent mapDescriptor = SCR_MapDescriptorComponent.Cast(GetOwner().FindComponent(SCR_MapDescriptorComponent));
295 
296  if (mapDescriptor)
297  m_MapItem = mapDescriptor.Item();
298 
299  if (!m_MapItem || m_ParentFaction != playerFaction)
300  return;
301 
302  m_MapItem.SetVisible(true);
303 
304  switch (m_ParentFaction.GetFactionKey())
305  {
306  case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.BLUFOR):
307  {
308  m_MapItem.SetFactionIndex(EFactionMapID.WEST);
309  break;
310  }
311 
312  case campaign.GetFactionKeyByEnum(SCR_ECampaignFaction.OPFOR):
313  {
314  m_MapItem.SetFactionIndex(EFactionMapID.EAST);
315  break;
316  }
317 
318  default:
319  {
320  m_MapItem.SetFactionIndex(EFactionMapID.UNKNOWN);
321  }
322  }
323  }
324 
327 
328  if (m_MapItem)
329  HandleMapLinks();
330 
331  if (!IsProxy())
332  campaign.GetBaseManager().RecalculateRadioCoverage(m_ParentFaction);
333  }
334 
335  //------------------------------------------------------------------------------------------------
338  {
339  return m_iParentFaction;
340  }
341 
342  //------------------------------------------------------------------------------------------------
345  {
346  return m_ParentFaction;
347  }
348 
349  //------------------------------------------------------------------------------------------------
352  {
353  return m_Faction;
354  }
355 
356  //------------------------------------------------------------------------------------------------
359  int GetBasesInRange(notnull out array<SCR_CampaignMilitaryBaseComponent> basesInRange)
360  {
361  return basesInRange.Copy(m_aBasesInRadioRange);
362  }
363 
364  //------------------------------------------------------------------------------------------------
366  void SetRadioRange(int range)
367  {
368  m_iRadioRange = range;
369  }
370 
371  //------------------------------------------------------------------------------------------------
374  {
375  return m_iRadioRange;
376  }
377 
378  //------------------------------------------------------------------------------------------------
380  {
381  SCR_CampaignFactionManager fManager = SCR_CampaignFactionManager.Cast(GetGame().GetFactionManager());
382 
383  if (!fManager)
384  return;
385 
386  FactionKey fKey;
387  Faction f = fManager.GetFactionByIndex(m_iFaction);
388 
389  if (f)
390  {
391  fKey = f.GetFactionKey();
392  m_Faction = SCR_CampaignFaction.Cast(f);
393  }
394 
395  SCR_SpawnPoint.Cast(GetOwner()).SetFaction(f);
397  }
398 
399  //------------------------------------------------------------------------------------------------
402  {
403  return m_bIsInRadioRange;
404  }
405 
406  //------------------------------------------------------------------------------------------------
409  {
410  return m_MapItem;
411  }
412 
413  //------------------------------------------------------------------------------------------------
416  {
417  m_iBasesCoveredByMHQOnly = count;
418  Replication.BumpMe();
419  }
420 
421  //------------------------------------------------------------------------------------------------
424  {
426  }
427 
428  //------------------------------------------------------------------------------------------------
431  {
432  if (!m_ParentFaction)
433  return;
434 
435  bool inRangeNow = SCR_GameModeCampaign.GetInstance().GetBaseManager().IsEntityInFactionRadioSignal(GetOwner(), m_ParentFaction);
436  bool refreshLinks = inRangeNow != m_bIsInRadioRange;
437  m_bIsInRadioRange = inRangeNow;
438 
439  if (refreshLinks && RplSession.Mode() != RplMode.Dedicated)
440  {
442  {
443  base.GetMapDescriptor().HandleMapLinks();
444  }
445  }
446 
447  DamageManagerComponent damageComponent = DamageManagerComponent.Cast(GetOwner().FindComponent(DamageManagerComponent));
448 
449  if (damageComponent && damageComponent.GetState() == EDamageState.DESTROYED)
450  {
451  if (m_MapItem)
452  m_MapItem.SetVisible(false);
453 
454  if (!IsProxy())
455  {
456  IEntity vehicle = GetOwner().GetParent();
457 
458  if (vehicle)
459  {
460  BaseRadioComponent radioComponent = BaseRadioComponent.Cast(vehicle.FindComponent(BaseRadioComponent));
461 
462  if (radioComponent)
463  radioComponent.SetPower(false);
464  }
465  }
466  }
467 
468  if (IsProxy())
469  return;
470 
471  if (!m_bIsInRadioRange && m_iFaction != SCR_CampaignMilitaryBaseComponent.INVALID_FACTION_INDEX)
472  {
473  m_iFaction = SCR_CampaignMilitaryBaseComponent.INVALID_FACTION_INDEX;
474  Replication.BumpMe();
476  }
477 
479  {
481  Replication.BumpMe();
483  }
484  }
485 
486  //------------------------------------------------------------------------------------------------
489  void UpdateRespawnCooldown(Widget w = null)
490  {
491  if (!m_ParentFaction)
492  return;
493 
495 
496  TextWidget respawn;
497  ImageWidget respawnImg;
498 
499  ResourceName imageset = hq.GetBuildingIconImageset();
500 
501  if (w && imageset)
502  {
503  respawn = TextWidget.Cast(w.FindAnyWidget("Respawn"));
504  respawnImg = ImageWidget.Cast(w.FindAnyWidget("RespawnIMG"));
505  respawnImg.LoadImageFromSet(0, imageset, "RespawnBig");
506  }
507 
508  ChimeraWorld world = GetOwner().GetWorld();
509  if (m_fRespawnAvailableSince.Greater(world.GetServerTimestamp()))
510  {
511  if (m_bCooldownDone)
512  m_bCooldownDone = false;
513 
514  if (RplSession.Mode() != RplMode.Dedicated)
515  {
516  if (!w)
517  s_OnUpdateRespawnCooldown.Invoke();
518  else
519  {
520  respawn.SetVisible(true);
521  respawnImg.SetVisible(true);
522 
523  float respawnCooldown = Math.Ceil(m_fRespawnAvailableSince.DiffMilliseconds(world.GetServerTimestamp()) * 0.001);
524  int d, h, m, s;
525  string sStr;
526  SCR_DateTimeHelper.GetDayHourMinuteSecondFromSeconds(respawnCooldown, d, h, m, s);
527  sStr = s.ToString();
528 
529  if (s < 10)
530  sStr = "0" + sStr;
531 
532  respawn.SetTextFormat("#AR-Campaign_MobileAssemblyCooldown", m, sStr);
533  }
534  }
535  }
536  else
537  {
538  GetGame().GetCallqueue().Remove(UpdateRespawnCooldown);
539 
540  if (w)
541  {
542  if (RplSession.Mode() != RplMode.Dedicated)
543  {
544  respawn.SetVisible(false);
545  respawnImg.SetVisible(false);
546  }
547  }
548  else
549  {
550  if (!m_bCooldownDone)
551  {
552  m_bCooldownDone = true;
553  s_OnUpdateRespawnCooldown.Invoke();
554 
555  if (!IsProxy() && IsInRadioRange())
556  {
558  Replication.BumpMe();
560  }
561  }
562  }
563  }
564  }
565 }
UpdateRadioCoverage
void UpdateRadioCoverage()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:430
SetVehicle
void SetVehicle(IEntity vehicle)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:254
ChimeraWorld
Definition: ChimeraWorld.c:12
OnIconHovered
void OnIconHovered(SCR_CampaignMapUIBase icon, bool hovering)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:152
UpdateBasesInRadioRange
void UpdateBasesInRadioRange()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:114
SCR_ECampaignFaction
SCR_ECampaignFaction
Definition: SCR_CampaignFactionManager.c:130
m_iFaction
protected int m_iFaction
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:30
m_iBasesCoveredByMHQOnly
protected int m_iBasesCoveredByMHQOnly
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:38
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:247
m_fRespawnAvailableSince
protected WorldTimestamp m_fRespawnAvailableSince
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:36
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_MapItem
protected MapItem m_MapItem
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:14
GetParentFactionID
int GetParentFactionID()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:337
SetParentFactionID
void SetParentFactionID(int factionID)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:268
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
OnFactionChanged
void OnFactionChanged()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:379
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UpdateRespawnCooldown
void UpdateRespawnCooldown(Widget w=null)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:489
m_aMapLinks
protected ref array< MapLink > m_aMapLinks
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:25
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:90
m_bCooldownDone
protected bool m_bCooldownDone
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:22
SCR_CampaignMapUIBase
Definition: SCR_CampaignMapUIBase.c:2
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
SetRadioRange
void SetRadioRange(int range)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:366
EDamageState
EDamageState
Definition: EDamageState.c:12
m_aBasesInRadioRangeOld
protected ref array< SCR_CampaignMilitaryBaseComponent > m_aBasesInRadioRangeOld
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:27
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
m_bIsInRadioRange
protected bool m_bIsInRadioRange
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:21
GetVehicle
IEntity GetVehicle()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:261
OnParentFactionIDSet
void OnParentFactionIDSet()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:276
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:12
m_iParentFaction
protected int m_iParentFaction
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:33
m_Vehicle
protected IEntity m_Vehicle
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:16
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
m_Faction
protected SCR_CampaignFaction m_Faction
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:19
SCR_DateTimeHelper
Definition: SCR_DateTimeHelper.c:1
m_ParentFaction
protected SCR_CampaignFaction m_ParentFaction
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:18
m_aBasesInRadioRange
protected ref array< SCR_CampaignMilitaryBaseComponent > m_aBasesInRadioRange
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:26
IsInRadioRange
bool IsInRadioRange()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:401
s_OnSpawnPointOwnerChanged
SCR_CampaignMobileAssemblyStandaloneComponentClass s_OnSpawnPointOwnerChanged
GetParentFaction
SCR_CampaignFaction GetParentFaction()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:344
SCR_CampaignMobileAssemblyStandaloneComponentClass
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:1
MapItem
Definition: MapItem.c:12
SetCountOfExclusivelyLinkedBases
void SetCountOfExclusivelyLinkedBases(int count)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:415
HandleMapLinks
protected void HandleMapLinks(bool onDelete=false)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:224
SCR_GraphLinesData
Definition: SCR_GraphLinesData.c:3
GetCountOfExclusivelyLinkedBases
int GetCountOfExclusivelyLinkedBases()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:423
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:44
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_bIsHovered
protected bool m_bIsHovered
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:23
CanReachByRadio
bool CanReachByRadio(notnull SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:144
Faction
Definition: Faction.c:12
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
GetRadioRange
int GetRadioRange()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:373
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
GetMapItem
MapItem GetMapItem()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:408
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
AddMapLink
void AddMapLink(notnull MapLink link)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:241
DamageManagerComponent
Definition: DamageManagerComponent.c:12
GetFaction
SCR_CampaignFaction GetFaction()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:351
GetBasesInRange
int GetBasesInRange(notnull out array< SCR_CampaignMilitaryBaseComponent > basesInRange)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:359
m_iRadioRange
protected int m_iRadioRange
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:41
ColorMapLink
void ColorMapLink(notnull MapLink link)
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:168
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38