Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CaptureBasesContextAction.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  override bool CanBeShown(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
6  {
7  IEntity owner = null;
8  int selectedEntitiesCount = 0;
9 
10  if (selectedEntities)
11  selectedEntitiesCount = selectedEntities.Count();
12 
13  // No entity to perform the action on
14  if (!hoveredEntity && selectedEntitiesCount == 0)
15  return false;
16 
17  if (hoveredEntity)
18  {
19  owner = hoveredEntity.GetOwner();
20  if (!owner.IsInherited(SCR_CampaignMilitaryBaseComponent))
21  return false;
22  }
23 
24  for (int i = 0; i < selectedEntitiesCount; i++)
25  {
26  owner = selectedEntities[i].GetOwner();
27  if (!owner.IsInherited(SCR_CampaignMilitaryBaseComponent))
28  return false;
29  }
30 
31  return true;
32  }
33 
34  override bool CanBePerformed(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition, int flags)
35  {
36  return true;
37  }
38 
39  override void Perform(SCR_EditableEntityComponent hoveredEntity, notnull set<SCR_EditableEntityComponent> selectedEntities, vector cursorWorldPosition,int flags, int param = -1)
40  {
41  FactionManager factionManager = GetGame().GetFactionManager();
42  if (!factionManager)
43  return;
44 
45  array<Faction> factions = new array<Faction>();
46  array<int> factionIDs = new array<int>();
47  factionManager.GetFactionsList(factions);
48 
49  if (!factions)
50  return;
51 
52  int factionsCount = factions.Count();
53 
54  if (factionsCount == 0)
55  return;
56 
57  foreach (Faction f: factions)
58  if (SCR_Faction.Cast(f).IsPlayable())
59  factionIDs.Insert(factionManager.GetFactionIndex(f));
60 
61  int factionIDsCount = factionIDs.Count();
62 
63  if (factionIDsCount == 0)
64  return;
65 
66  if (hoveredEntity)
67  PerformOn(hoveredEntity, factionIDs, factionIDsCount);
68 
69  if (!selectedEntities)
70  return;
71 
72  int selectedEntitiesCount = selectedEntities.Count();
73  for (int i = 0; i < selectedEntitiesCount; i++)
74  {
75  if (selectedEntities[i] == hoveredEntity)
76  continue;
77 
78  PerformOn(selectedEntities[i], factionIDs, factionIDsCount);
79  }
80  }
81 
82  void PerformOn(SCR_EditableEntityComponent entity, array<int> factionIDs, int factionIDsCount)
83  {
85  FactionManager factionManager = GetGame().GetFactionManager();
86 
87  if (!base)
88  return;
89 
90  int index = factionIDs.Find(factionManager.GetFactionIndex(base.GetFaction())) + 1;
91 
92  if (index >= factionIDsCount)
93  index = 0;
94 
95  PlayerController pc = GetGame().GetPlayerController();
96 
97  if (!pc)
98  return;
99 
100  SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(pc.FindComponent(SCR_CampaignNetworkComponent));
101 
102  if (!campaignNetworkComponent)
103  return;
104 
105  campaignNetworkComponent.CaptureBaseGM(base, factionIDs[index]);
106  }
107 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CaptureBasesContextAction
Definition: SCR_CaptureBasesContextAction.c:3
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
Faction
Definition: Faction.c:12
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_SelectedEntitiesContextAction
Definition: SCR_SelectedEntitiesContextAction.c:10
SCR_BaseContainerCustomTitleUIInfo
void SCR_BaseContainerCustomTitleUIInfo(string propertyName, string format="%1")
Definition: Attributes.c:788
SCR_Faction
Definition: SCR_Faction.c:6
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_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38