Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignMilitaryBaseMapDescriptorComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_CampaignMilitaryBaseMapDescriptorComponent : SCR_MilitaryBaseMapDescriptorComponent
6 {
7  protected ref array<MapLink> m_aMapLinks = {};
8 
10 
11  protected bool m_bIsHovered;
12 
13  //------------------------------------------------------------------------------------------------
16  {
17  m_Base = base;
18  }
19 
20  //------------------------------------------------------------------------------------------------
23  void MapSetup(notnull Faction faction)
24  {
25  MapItem item = Item();
26  Faction baseFaction = m_Base.GetFaction();
27 
28  if (m_Base.IsHQ() && faction != baseFaction)
29  {
30  item.SetVisible(false);
31  return;
32  }
33  else
34  {
35  item.SetVisible(true);
36  item.SetDisplayName(m_Base.GetBaseName());
37 
38  MapDescriptorProps props = item.GetProps();
39  props.SetDetail(96);
40 
41  Color rangeColor;
42 
43  if (baseFaction)
44  rangeColor = Color.FromInt(baseFaction.GetFactionColor().PackToInt());
45  else
46  rangeColor = Color.FromInt(Color.WHITE);
47 
48  props.SetOutlineColor(rangeColor);
49  rangeColor.SetA(0.1);
50  props.SetBackgroundColor(rangeColor);
51 
52  item.SetProps(props);
53  item.SetRange(0);
54  }
55  }
56 
57  //------------------------------------------------------------------------------------------------
60  void OnIconHovered(SCR_CampaignMapUIBase icon, bool hovering)
61  {
62  m_bIsHovered = hovering;
63 
64  for (int i = m_aMapLinks.Count() - 1; i >= 0; i--)
65  {
66  if (!m_aMapLinks[i])
67  continue;
68 
70  }
71  }
72 
73  //------------------------------------------------------------------------------------------------
76  void UnregisterMapLink(notnull MapLink link)
77  {
78  m_aMapLinks.RemoveItem(link);
79  }
80 
81  //------------------------------------------------------------------------------------------------
86  bool FindMapLink(MapDescriptorComponent owner, MapDescriptorComponent target)
87  {
88  for (int i = m_aMapLinks.Count() - 1; i >= 0; i--)
89  {
90  if(!m_aMapLinks[i])
91  return false;
92  if ((m_aMapLinks[i].Owner().Descriptor() == owner && m_aMapLinks[i].Target().Descriptor() == target) || (m_aMapLinks[i].Owner().Descriptor() == target && m_aMapLinks[i].Target().Descriptor() == owner))
93  return true;
94  }
95 
96  return false;
97  }
98 
99  //------------------------------------------------------------------------------------------------
102  void RegisterMapLink(notnull MapLink link)
103  {
104  m_aMapLinks.Insert(link);
105  }
106 
107  //------------------------------------------------------------------------------------------------
110  void ColorMapLink(notnull MapLink link)
111  {
112  MapLinkProps props = link.GetMapLinkProps();
113 
114  if (!props)
115  return;
116 
117  props.SetLineWidth(m_Base.GetLineWidth());
118 
119  Color c = Color.FromInt(props.GetLineColor().PackToInt());
120 
121  if (!c)
122  return;
123 
124  SCR_GraphLinesData linesData = m_Base.GetGraphLinesData();
125 
126  if (!linesData)
127  return;
128 
129  if (m_bIsHovered)
130  {
131  // Highlight only bases in range
132  MapItem otherEnd = link.Target();
133 
134  if (otherEnd == Item())
135  otherEnd = link.Owner();
136 
137  IEntity otherEndOwner = otherEnd.Entity();
138 
139  if (!otherEndOwner)
140  return;
141 
143  SCR_CampaignMobileAssemblyStandaloneComponent mobileHQ;
144 
145  if (!otherBase)
146  {
147  SCR_SpawnPoint spawnpoint = SCR_SpawnPoint.Cast(otherEndOwner);
148 
149  if (spawnpoint)
150  {
152  SCR_CampaignMobileAssemblyStandaloneComponent factionMHQ = faction.GetMobileAssembly();
153 
154  if (factionMHQ && factionMHQ.GetOwner() == spawnpoint)
155  mobileHQ = factionMHQ;
156  }
157 
158  if (!mobileHQ)
159  return;
160  }
161 
162  if ((mobileHQ && m_Base.CanReachByRadio(mobileHQ)) || (otherBase && m_Base.CanReachByRadio(otherBase)))
163  c.SetA(linesData.GetHighlightedAlpha());
164  else
165  return;
166  }
167  else
168  {
169  c.SetA(linesData.GetDefaultAlpha());
170  }
171 
172  props.SetLineColor(c);
173  }
174 
175  //------------------------------------------------------------------------------------------------
178  void UnregisterMyMapLinks(bool unlinkHQ = false)
179  {
180  Faction playerFaction = SCR_FactionManager.SGetLocalPlayerFaction();
181 
182  for (int i = m_aMapLinks.Count() - 1; i >= 0; i--)
183  {
184  if (!m_aMapLinks.IsIndexValid(i))
185  continue;
186 
187  MapLink link = m_aMapLinks[i];
188 
189  if (!link)
190  continue;
191 
192  IEntity otherBaseOwner;
193 
194  if (link.Owner().Entity() == m_Base.GetOwner())
195  otherBaseOwner = link.Target().Entity();
196  else
197  otherBaseOwner = link.Owner().Entity();
198 
199  if (!otherBaseOwner || (unlinkHQ && SCR_SpawnPoint.Cast(otherBaseOwner) != null))
200  {
201  link.Target().UnLink(Item());
202  Item().UnLink(link.Target());
203  UnregisterMapLink(link);
204  continue;
205  }
206 
208 
209  if (otherBase && (!otherBase.CanReachByRadio(m_Base) || m_Base.GetHQRadioCoverage(playerFaction) == SCR_ECampaignHQRadioComms.NONE))
210  {
211  otherBase.GetMapDescriptor().UnregisterMapLink(link);
212  UnregisterMapLink(link);
213  Item().UnLink(otherBase.GetMapDescriptor().Item());
214  otherBase.GetMapDescriptor().Item().UnLink(Item());
215  }
216  }
217  }
218 
219  //------------------------------------------------------------------------------------------------
222  void HandleMapLinks(bool unlinkHQ = false)
223  {
224  if (m_Base.IsHQ() && m_Base.GetFaction() != SCR_FactionManager.SGetLocalPlayerFaction())
225  return;
226 
227  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
228 
229  if (!campaign)
230  return;
231 
232  UnregisterMyMapLinks(unlinkHQ);
233  SCR_CampaignFaction localPlayerFaction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
234 
235  if (!localPlayerFaction)
236  return;
237 
238  SCR_CampaignMobileAssemblyStandaloneComponent mobileHQ = localPlayerFaction.GetMobileAssembly();
239  MapItem mobilehqMapItem;
240 
241  if (mobileHQ)
242  {
243  SCR_SpawnPoint spawnpoint = SCR_SpawnPoint.Cast(mobileHQ.GetOwner());
244 
245  if (spawnpoint)
246  {
247  SCR_MapDescriptorComponent desc = SCR_MapDescriptorComponent.Cast(spawnpoint.FindComponent(SCR_MapDescriptorComponent));
248 
249  if (desc && mobileHQ.IsInRadioRange())
250  {
251  array<SCR_CampaignMilitaryBaseComponent> basesInRangeOfMobileHQ = {};
252  mobileHQ.GetBasesInRange(basesInRangeOfMobileHQ);
253 
254  if (basesInRangeOfMobileHQ.Contains(m_Base))
255  mobilehqMapItem = desc.Item();
256  }
257  }
258  }
259 
260  SCR_CampaignFaction faction = m_Base.GetCampaignFaction();
261 
262  if (!mobilehqMapItem)
263  {
264  if (!m_Base.IsHQRadioTrafficPossible(localPlayerFaction) || localPlayerFaction != faction)
265  return;
266  }
267 
268  CreateLinks(faction, localPlayerFaction, mobilehqMapItem);
269  }
270 
271  //------------------------------------------------------------------------------------------------
276  void CreateLinks(Faction myFaction, Faction localPlayerFaction, MapItem mobilehq = null)
277  {
278  if (mobilehq)
279  {
280  MapLink link = Item().LinkTo(mobilehq);
281  ColorMapLink(link);
282  RegisterMapLink(link);
283  SCR_CampaignMobileAssemblyStandaloneComponent comp = SCR_CampaignFaction.Cast(localPlayerFaction).GetMobileAssembly();
284 
285  if (comp)
286  comp.AddMapLink(link);
287  }
288 
289  array<SCR_CampaignMilitaryBaseComponent> bases = {};
290  m_Base.GetBasesInRange(SCR_ECampaignBaseType.BASE | SCR_ECampaignBaseType.RELAY, bases);
291 
292  for (int i = bases.Count() - 1; i >= 0; i--)
293  {
294  if (bases[i].IsHQ() && bases[i].GetFaction() != localPlayerFaction)
295  continue;
296 
297  if (FindMapLink(this, bases[i].GetMapDescriptor()))
298  continue;
299 
300  if (myFaction != localPlayerFaction)
301  continue;
302 
303  MapItem otherMapItem = bases[i].GetMapDescriptor().Item();
304 
305  if (!otherMapItem)
306  continue;
307 
308  MapLink link = Item().LinkTo(otherMapItem);
309  ColorMapLink(link);
310  RegisterMapLink(link);
311  bases[i].GetMapDescriptor().RegisterMapLink(link);
312  }
313  }
314 
315  //------------------------------------------------------------------------------------------------
318  void HandleMapInfo(SCR_CampaignFaction playerFactionCampaign = null)
319  {
320  SCR_GameModeCampaign campaignGameMode = SCR_GameModeCampaign.GetInstance();
321 
322  if (!campaignGameMode)
323  return;
324 
325  if (!playerFactionCampaign)
326  playerFactionCampaign = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
327 
328  if (!playerFactionCampaign)
329  playerFactionCampaign = campaignGameMode.GetBaseManager().GetLocalPlayerFaction();
330 
331  if (!playerFactionCampaign)
332  return;
333 
334  if (m_Base.IsHQ() && m_Base.GetFaction() != playerFactionCampaign)
335  return;
336 
337  // Set callsign based on player's faction
338  if (m_Base.GetType() != SCR_ECampaignBaseType.RELAY && m_Base.GetCallsignDisplayName().IsEmpty())
339  m_Base.SetCallsign(playerFactionCampaign);
340 
341  SCR_CampaignMapUIBase mapUI = m_Base.GetMapUI();
342 
343  if (mapUI)
344  mapUI.SetIconInfoText();
345 
346  // Update base icon color
347  EFactionMapID factionMapID = EFactionMapID.UNKNOWN;
348  bool isInRange = m_Base.IsHQRadioTrafficPossible(playerFactionCampaign);
349 
350  // Show proper faction color only for HQs or bases within radio signal
351  if (m_Base.GetFaction() && (m_Base.IsHQ() || isInRange))
352  {
353  switch (m_Base.GetFaction().GetFactionKey())
354  {
355  case campaignGameMode.GetFactionKeyByEnum(SCR_ECampaignFaction.OPFOR): {factionMapID = EFactionMapID.EAST; break;};
356  case campaignGameMode.GetFactionKeyByEnum(SCR_ECampaignFaction.BLUFOR): {factionMapID = EFactionMapID.WEST; break;};
357  case campaignGameMode.GetFactionKeyByEnum(SCR_ECampaignFaction.INDFOR): {factionMapID = EFactionMapID.FIA; break;};
358  }
359  }
360 
361  Item().SetFactionIndex(factionMapID);
362 
363  array<SCR_ServicePointDelegateComponent> delegates = {};
364  m_Base.GetServiceDelegates(delegates);
365 
366  foreach (SCR_ServicePointDelegateComponent delegate: delegates)
367  {
368  IEntity owner = delegate.GetOwner();
369 
370  if (!owner)
371  continue;
372 
374 
375  if (comp)
376  {
377  if (isInRange)
378  comp.SetServiceMarker(m_Base.GetCampaignFaction());
379  else
380  comp.SetServiceMarker(visible: false);
381  }
382  }
383 
384  if (mapUI)
385  mapUI.UpdateBaseIcon(factionMapID);
386 
387  HandleMapLinks();
388  }
389 }
SetParentBase
void SetParentBase(notnull SCR_CampaignMilitaryBaseComponent base)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:15
GetMapDescriptor
SCR_CampaignMilitaryBaseMapDescriptorComponent GetMapDescriptor()
Definition: SCR_CampaignMilitaryBaseComponent.c:1507
SCR_ECampaignFaction
SCR_ECampaignFaction
Definition: SCR_CampaignFactionManager.c:130
CreateLinks
void CreateLinks(Faction myFaction, Faction localPlayerFaction, MapItem mobilehq=null)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:276
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CampaignMapUIBase
Definition: SCR_CampaignMapUIBase.c:2
UnregisterMyMapLinks
void UnregisterMyMapLinks(bool unlinkHQ=false)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:178
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
IsHQ
bool IsHQ()
Definition: SCR_CampaignMilitaryBaseComponent.c:651
SCR_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
FindMapLink
bool FindMapLink(MapDescriptorComponent owner, MapDescriptorComponent target)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:86
OnIconHovered
void OnIconHovered(SCR_CampaignMapUIBase icon, bool hovering)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:60
SCR_ServicePointMapDescriptorComponent
void SCR_ServicePointMapDescriptorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ServicePointMapDescriptorComponent.c:198
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
MapSetup
void MapSetup(notnull Faction faction)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:23
MapDescriptorProps
Definition: MapDescriptorProps.c:12
Item
proto external MapItem Item()
raist todo: this is temporary - before we fix script
m_bIsHovered
protected bool m_bIsHovered
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:11
HandleMapLinks
void HandleMapLinks(bool unlinkHQ=false)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:222
SCR_MilitaryBaseMapDescriptorComponentClass
Definition: SCR_MilitaryBaseMapDescriptorComponent.c:1
MapItem
Definition: MapItem.c:12
SCR_CampaignMilitaryBaseMapDescriptorComponentClass
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:1
m_aMapLinks
SCR_CampaignMilitaryBaseMapDescriptorComponentClass m_aMapLinks
SCR_GraphLinesData
Definition: SCR_GraphLinesData.c:3
RegisterMapLink
void RegisterMapLink(notnull MapLink link)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:102
ColorMapLink
void ColorMapLink(notnull MapLink link)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:110
UnregisterMapLink
void UnregisterMapLink(notnull MapLink link)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:76
m_Base
SCR_CampaignMilitaryBaseComponent m_Base
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:9
Faction
Definition: Faction.c:12
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
GetFaction
SCR_CampaignFaction GetFaction()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:351
HandleMapInfo
void HandleMapInfo(SCR_CampaignFaction playerFactionCampaign=null)
Definition: SCR_CampaignMilitaryBaseMapDescriptorComponent.c:318
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38