Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignDeployMobileAssemblyUserAction.c
Go to the documentation of this file.
2 {
3  protected IEntity m_TruckBed;
4  protected SCR_CampaignMobileAssemblyComponent m_AssemblyComponent;
5  protected DamageManagerComponent m_DamageManagerComponent;
6 
7  static const float MAX_TERRAIN_HEIGHT = 0.5;
8  static const float TERRAIN_SLOPE_THRESHOLD = 0.9;
9 
10  //------------------------------------------------------------------------------------------------
11  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
12  {
13  m_TruckBed = pOwnerEntity;
14 
15  if (!m_TruckBed)
16  return;
17 
18  m_AssemblyComponent = SCR_CampaignMobileAssemblyComponent.Cast(m_TruckBed.FindComponent(SCR_CampaignMobileAssemblyComponent));
19  }
20 
21  //------------------------------------------------------------------------------------------------
22  DamageManagerComponent GetDamageManagerComponent()
23  {
26 
27  if (!m_TruckBed)
28  return null;
29 
30  IEntity truck = m_TruckBed.GetParent();
31 
32  if (!truck)
33  return null;
34 
36 
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override bool CanBeShownScript(IEntity user)
42  {
43  float depth;
44  if (SCR_WorldTools.IsObjectUnderwater(GetOwner(), vector.Zero, -1, depth) && depth > SCR_CampaignMobileAssemblyComponent.MAX_WATER_DEPTH)
45  return false;
46 
47  if (!m_AssemblyComponent)
48  return false;
49 
50  Faction f = SCR_FactionManager.SGetLocalPlayerFaction();
51 
52  if (!f)
53  return false;
54 
55  if (f != m_AssemblyComponent.GetParentFaction())
56  return false;
57 
58  if (GetDamageManagerComponent() && GetDamageManagerComponent().GetState() == EDamageState.DESTROYED)
59  return false;
60 
61  if (m_TruckBed)
62  {
63  IEntity truck = m_TruckBed.GetParent();
64 
65  if (truck)
66  {
67  Physics physicsComponent = truck.GetPhysics();
68  vector vel = physicsComponent.GetVelocity();
69  vel[1] = 0; // Ignore Y velocity
70 
71  if (physicsComponent && vel.LengthSq() > 0.01)
72  return false;
73  }
74  }
75 
76  return !m_AssemblyComponent.IsDeployed();
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override bool CanBePerformedScript(IEntity user)
81  {
82  if (!m_AssemblyComponent)
83  return false;
84 
85  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
86 
87  if (!campaign)
88  return false;
89 
90  SCR_CampaignFaction f = m_AssemblyComponent.GetParentFaction();
91 
92  if (!f)
93  return false;
94 
95  if (f.GetMobileAssembly())
96  {
97  SetCannotPerformReason("#AR-Campaign_Action_AnotherAssemblyActive-UC");
98  return false;
99  }
100 
101  SCR_CampaignFeedbackComponent feedbackComponent = SCR_CampaignFeedbackComponent.GetInstance();
102 
103  if (!feedbackComponent)
104  return false;
105 
106  if (feedbackComponent.GetBaseWithPlayer())
107  {
108  SetCannotPerformReason("#AR-Campaign_Action_AnotherHQNearby-UC");
109  return false;
110  }
111 
112  bool isInRange = m_AssemblyComponent.IsInRadioRange();
113 
114  if (!isInRange)
115  SetCannotPerformReason("#AR-Campaign_Action_NoSignal-UC");
116 
117  IEntity truck = m_TruckBed.GetParent();
118 
119  if (truck)
120  {
121  vector pos = truck.GetOrigin();
122 
123  if (SCR_TerrainHelper.GetHeightAboveTerrain(pos) > MAX_TERRAIN_HEIGHT)
124  {
125  SetCannotPerformReason("#AR-Campaign_Action_UnevenTerrain-UC");
126  return false;
127  }
128 
129  /*if (SCR_TerrainHelper.GetTerrainNormal(pos)[1] < TERRAIN_SLOPE_THRESHOLD)
130  {
131  SetCannotPerformReason("#AR-Campaign_Action_UnevenTerrain-UC");
132  return false;
133  }*/
134  }
135 
136  return isInRange;
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
141  {
142  PlayerController playerController = GetGame().GetPlayerController();
143 
144  if (!playerController)
145  return;
146 
147  SCR_CampaignNetworkComponent campaignNetworkComponent = SCR_CampaignNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignNetworkComponent));
148 
149  if (!campaignNetworkComponent)
150  return;
151 
152  campaignNetworkComponent.DeployMobileAsembly(m_AssemblyComponent, true);
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  override bool HasLocalEffectOnlyScript()
157  {
158  return true;
159  }
160 };
SCR_TerrainHelper
Definition: SCR_TerrainHelper.c:1
GetState
EEditableEntityState GetState()
Definition: SCR_BaseEntitiesEditorUIEffect.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_WorldTools
Definition: SCR_WorldTools.c:1
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
m_DamageManagerComponent
private DamageManagerComponent m_DamageManagerComponent
Definition: SpectateTargetComponent.c:11
SCR_CampaignDeployMobileAssemblyUserAction
Definition: SCR_CampaignDeployMobileAssemblyUserAction.c:1
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
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
DamageManagerComponent
Definition: DamageManagerComponent.c:12