Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EvacuateTaskSupportEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Tasks", description: "Evacuate task support entity.", color: "0 0 255 255")]
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
9 {
10  [Attribute("#AR-CampaignTasks_RequestImpossiblePosition-UC")]
11  protected string m_sNowhereToRun;
12 
13  [Attribute("#AR-CampaignTasks_RequestImpossibleSignal-UC")]
14  protected string m_sNoSignal;
15 
16  [Attribute("1000", desc: "Minimum distance of a base from the place this task is requested from. (in m)")]
17  protected float m_fMinDistanceFromStart;
18 
19  [Attribute("50", desc: "Maximum distance of the rescuer from the evacuated player, once a rescue base is reached. (in m)")]
20  protected float m_fMaxDistanceFromRequester;
21 
22  //------------------------------------------------------------------------------------------------
23  override bool CanRequest()
24  {
25  return (super.CanRequest() && HasValidBase());
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override void Request()
30  {
32  if (!playerController)
33  return;
34 
35  SCR_MapRadialUI ctxMenu = SCR_MapRadialUI.GetInstance();
36  if (!ctxMenu)
37  return;
38 
39  vector position = ctxMenu.GetMenuWorldPosition();
40 
41  IEntity requesterEntity = playerController.GetMainEntity();
42  if (!requesterEntity)
43  return;
44 
45  FactionAffiliationComponent factionAffiliationComponent = FactionAffiliationComponent.Cast(requesterEntity.FindComponent(FactionAffiliationComponent));
46  if (!factionAffiliationComponent)
47  return;
48 
49  Faction requesterFaction = factionAffiliationComponent.GetAffiliatedFaction();
50  if (!requesterFaction)
51  return;
52 
53  vector requesterOrigin = requesterEntity.GetOrigin();
54  array<SCR_MilitaryBaseComponent> bases = {};
55 
56  SCR_MilitaryBaseSystem.GetInstance().GetBases(bases);
57 
58  bool foundValidBase = false;
59  for (int i = bases.Count() - 1; i >= 0; i--)
60  {
61  if (requesterFaction != bases[i].GetFaction())
62  continue;
63 
64  float baseToStartDistance = vector.Distance(bases[i].GetOwner().GetOrigin(), requesterOrigin);
65 
66  if (baseToStartDistance > SCR_EvacuateTask.GetMinDistanceFromStart())
67  {
68  foundValidBase = true;
69  break;
70  }
71  }
72 
73  if (!foundValidBase)
74  {
75  SCR_PopUpNotification.GetInstance().PopupMsg(m_sNowhereToRun);
76  return;
77  }
78 
79  if (!SCR_UIRequestEvacTaskComponent.IsInRange(requesterFaction, requesterEntity))
80  {
81  SCR_PopUpNotification.GetInstance().PopupMsg(m_sNoSignal);
82  return;
83  }
84 
85  // Find task network component to send RPC to server
86  SCR_CampaignTaskNetworkComponent taskNetworkComponent = SCR_CampaignTaskNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignTaskNetworkComponent));
87  if (!taskNetworkComponent)
88  return;
89 
90  taskNetworkComponent.RequestEvacuation(position);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  //This should only be called on the server!
95  void RequestEvacuation(int requesterID, vector position)
96  {
97  SCR_EvacuateTask evacuateTask = SCR_EvacuateTask.Cast(CreateTask());
98  if (!evacuateTask)
99  return;
100 
101  evacuateTask.SetStartOrigin(position); // Should be enough to be set just on the server
102 
103  SCR_BaseTaskExecutor requester = SCR_BaseTaskExecutor.GetTaskExecutorByID(requesterID);
104 
105  SetRequester(evacuateTask, requester);
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  float GetMinDistanceFromStart()
110  {
111  return m_fMinDistanceFromStart;
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  float GetMaxDistanceFromRequester()
116  {
117  return m_fMaxDistanceFromRequester;
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  bool HasValidBase()
122  {
123  IEntity requesterEntity = SCR_PlayerController.GetLocalControlledEntity();
124  if (!requesterEntity)
125  return false;
126 
127  FactionAffiliationComponent factionAffiliationComponent = FactionAffiliationComponent.Cast(requesterEntity.FindComponent(FactionAffiliationComponent));
128  if (!factionAffiliationComponent)
129  return false;
130 
131  Faction requesterFaction = factionAffiliationComponent.GetAffiliatedFaction();
132  if (!requesterFaction)
133  return false;
134 
135  bool foundValidBase = false;
136 
137  vector requesterOrigin = requesterEntity.GetOrigin();
138  array<SCR_MilitaryBaseComponent> bases = {};
139 
140  SCR_MilitaryBaseSystem.GetInstance().GetBases(bases);
141 
142  for (int i = bases.Count() - 1; i >= 0; i--)
143  {
144  if (requesterFaction != bases[i].GetFaction())
145  continue;
146 
147  float baseToStartDistance = vector.Distance(bases[i].GetOwner().GetOrigin(), requesterOrigin);
148 
149  if (baseToStartDistance > SCR_EvacuateTask.GetMinDistanceFromStart())
150  {
151  foundValidBase = true;
152  break;
153  }
154  }
155 
156  return foundValidBase;
157  }
158 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_RequestedTaskSupportEntityClass
Definition: SCR_RequestedTaskSupportEntity.c:3
SCR_UIRequestEvacTaskComponent
Definition: SCR_UIRequestEvacTaskComponent.c:1
SCR_MapRadialUI
2D map radial menu UI
Definition: SCR_MapRadialUI.c:13
SCR_CampaignTaskNetworkComponent
void SCR_CampaignTaskNetworkComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CampaignTaskNetworkComponent.c:264
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_RequestedTaskSupportEntity
Definition: SCR_RequestedTaskSupportEntity.c:8
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EvacuateTaskSupportEntityClass
Definition: SCR_EvacuateTaskSupportEntity.c:3
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
SCR_EvacuateTask
Definition: SCR_EvacuateTask.c:7
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_EvacuateTaskSupportEntity
Definition: SCR_EvacuateTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
CreateTask
protected bool CreateTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:389
GetFaction
SCR_CampaignFaction GetFaction()
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:351
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180