Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignReconfigureHQRadioUserAction.c
Go to the documentation of this file.
3 {
4  protected SCR_CampaignMilitaryBaseComponent m_Base;
5  protected IEntity m_HQRadio;
6 
7  static const float MAX_BASE_DISTANCE = 50;
8 
9  //------------------------------------------------------------------------------------------------
10  protected bool IsParentBase(IEntity ent)
11  {
13 
14  // Base was found, stop query
15  if (m_Base)
16  {
17  m_Base.RegisterHQRadio(m_HQRadio);
18  return false;
19  }
20 
21  // Keep looking
22  return true;
23  }
24 
25  //------------------------------------------------------------------------------------------------
26  protected void CheckParentBase(vector origin)
27  {
28  if (!m_Base)
29  Print("HQ radio at " + string.ToString(origin) + " is not close enough (" + MAX_BASE_DISTANCE + "m) to any Conflict base!", LogLevel.ERROR);
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  static void ToggleBaseCaptured(SCR_CampaignMilitaryBaseComponent base, bool isBeingCaptured)
34  {
35  // Find local player controller
36  PlayerController playerController = GetGame().GetPlayerController();
37 
38  if (!playerController)
39  return;
40 
41  // Find conflict network component to send RPC to server
42  SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
43 
44  if (campaignNetworkComponent)
45  campaignNetworkComponent.ToggleBaseCapture(base, isBeingCaptured);
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
50  {
51  if (!pOwnerEntity)
52  return;
53 
54  m_HQRadio = pOwnerEntity;
55 
56  if (!GetGame().InPlayMode())
57  return;
58 
59  BaseWorld world = GetGame().GetWorld();
60 
61  if (!world)
62  return;
63 
64  vector origin = pOwnerEntity.GetOrigin();
65 
66  // Register parent base - find one in the nearest vicinity
67  world.QueryEntitiesBySphere(origin, MAX_BASE_DISTANCE, IsParentBase, null, EQueryEntitiesFlags.ALL);
68 
69  // Throw an error if no base has been found in the vicinity
70  GetGame().GetCallqueue().CallLater(CheckParentBase, 1000, false, origin);
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  override void OnActionStart(IEntity pUserEntity)
75  {
76  bool isAI = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity) == 0;
77 
78  if (!isAI && m_Base)
79  ToggleBaseCaptured(m_Base, true);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
84  {
85  ToggleBaseCaptured(m_Base, false);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
90  {
91  if (!m_Base)
92  return;
93 
94  bool isAI = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity) == 0;
95 
96  if (isAI)
97  {
98  FactionAffiliationComponent comp = FactionAffiliationComponent.Cast(pUserEntity.FindComponent(FactionAffiliationComponent));
99 
100  if (!comp)
101  return;
102 
103  m_Base.SetFaction(SCR_CampaignFaction.Cast(comp.GetAffiliatedFaction()));
104 
105  return;
106  }
107  else
108  {
109  PlayerController playerController = GetGame().GetPlayerController();
110 
111  if (!playerController)
112  return;
113 
114  SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
115 
116  if (campaignNetworkComponent)
117  campaignNetworkComponent.CaptureBase(m_Base);
118  }
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  override bool CanBePerformedScript(IEntity user)
123  {
124  bool isAI = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user) == 0;
125 
126  if (isAI)
127  {
128  FactionAffiliationComponent comp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
129 
130  if (!comp)
131  return false;
132 
133  return (comp.GetAffiliatedFaction() != m_Base.GetFaction());
134  }
135  else
136  {
137  SCR_CampaignFaction playerFaction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
138 
139  if (!playerFaction)
140  return false;
141 
142  // Already ours
143  if (m_Base.GetFaction() == playerFaction)
144  {
145  SetCannotPerformReason("#AR-Campaign_Action_Done-UC");
146  return false;
147  }
148 
149  // No radio signal
150  if (m_Base != playerFaction.GetMainBase() && !m_Base.IsHQRadioTrafficPossible(playerFaction))
151  {
152  SetCannotPerformReason("#AR-Campaign_Action_NoSignal-UC");
153  return false;
154  }
155 
156  return true;
157  }
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override bool CanBeShownScript(IEntity user)
162  {
163  CharacterControllerComponent comp = CharacterControllerComponent.Cast(user.FindComponent(CharacterControllerComponent));
164 
165  if (!comp)
166  return false;
167 
168  if (comp.IsDead())
169  return false;
170 
171  return (m_Base != null);
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  override bool HasLocalEffectOnlyScript()
176  {
177  return true;
178  }
179 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
m_Base
protected SCR_CampaignMilitaryBaseComponent m_Base
Definition: SCR_CampaignServiceCompositionComponent.c:19
SCR_CampaignReconfigureHQRadioUserAction
Action to reconfigure relays in Campaign.
Definition: SCR_CampaignReconfigureHQRadioUserAction.c:2
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
m_HQRadio
protected IEntity m_HQRadio
Definition: SCR_CampaignMilitaryBaseComponent.c:109
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38