Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignReconfigureRelayUserAction.c
Go to the documentation of this file.
3 {
4  // Member variables
5  protected SCR_CampaignMilitaryBaseComponent m_Base;
6  protected IEntity m_TowerRadio;
7  protected bool m_bCanBeShownResult = false;
8 
9  //------------------------------------------------------------------------------------------------
12  static Faction GetPlayerFaction(IEntity player)
13  {
14  if (!player)
15  return null;
16 
17  if (!ChimeraCharacter.Cast(player))
18  return null;
19 
20  auto foundComponent = ChimeraCharacter.Cast(player).FindComponent(FactionAffiliationComponent);
21  Faction faction;
22 
23  if (foundComponent)
24  {
25  auto castedComponent = FactionAffiliationComponent.Cast(foundComponent);
26  faction = castedComponent.GetAffiliatedFaction();
27  };
28 
29  return faction;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
34  {
35  if (!pOwnerEntity || !GetGame().InPlayMode())
36  return;
37 
38  IEntity parent = pOwnerEntity.GetParent();
39 
40  // Register parent base
41  if (parent && parent.FindComponent(SCR_CampaignMilitaryBaseComponent))
43 
44  m_TowerRadio = pOwnerEntity;
45  m_Base.RegisterHQRadio(m_TowerRadio);
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  override void OnActionStart(IEntity pUserEntity)
50  {
51  if (m_Base)
52  SCR_CampaignReconfigureHQRadioUserAction.ToggleBaseCaptured(m_Base, true);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
57  {
58  if (m_Base)
59  SCR_CampaignReconfigureHQRadioUserAction.ToggleBaseCaptured(m_Base, false);
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
64  {
65  if (!m_Base)
66  return;
67 
68  bool isAI = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity) == 0;
69 
70  if (isAI)
71  {
72  FactionAffiliationComponent comp = FactionAffiliationComponent.Cast(pUserEntity.FindComponent(FactionAffiliationComponent));
73 
74  if (!comp)
75  return;
76 
77  m_Base.SetFaction(SCR_CampaignFaction.Cast(comp.GetAffiliatedFaction()));
78 
79  return;
80  }
81  else
82  {
83  PlayerController playerController = GetGame().GetPlayerController();
84 
85  if (!playerController)
86  return;
87 
88  SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
89 
90  if (campaignNetworkComponent)
91  campaignNetworkComponent.CaptureBase(m_Base);
92  }
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  override bool CanBePerformedScript(IEntity user)
97  {
98  SCR_CampaignFaction playerFaction;
99  bool isAI = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user) == 0;
100 
101  if (isAI)
102  {
103  FactionAffiliationComponent comp = FactionAffiliationComponent.Cast(user.FindComponent(FactionAffiliationComponent));
104 
105  if (!comp)
106  return false;
107 
108  playerFaction = SCR_CampaignFaction.Cast(comp.GetAffiliatedFaction());
109  }
110  else
111  playerFaction = SCR_CampaignFaction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
112 
113  if (!playerFaction)
114  return false;
115 
116  // Already ours
117  if (m_Base.GetFaction() == playerFaction)
118  {
119  SetCannotPerformReason("#AR-Campaign_Action_Done-UC");
120  return false;
121  }
122 
123  // No radio signal
124  if (m_Base != playerFaction.GetMainBase() && !m_Base.IsHQRadioTrafficPossible(playerFaction))
125  {
126  SetCannotPerformReason("#AR-Campaign_Action_NoSignal-UC");
127  return false;
128  }
129 
130  return true;
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  override bool CanBeShownScript(IEntity user)
135  {
136  return (m_Base != null);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  override bool HasLocalEffectOnlyScript()
141  {
142  return true;
143  }
144 };
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
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
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
SCR_CampaignReconfigureRelayUserAction
Action to reconfigure relays in Campaign.
Definition: SCR_CampaignReconfigureRelayUserAction.c:2