Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TransportTaskSupportEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Tasks", description: "Transport task support entity.", color: "0 0 255 255")]
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
9 {
10  [Attribute("#AR-Tasks_RequestFromTransport")]
11  protected LocalizedString m_sRequestFromText;
12 
13  [Attribute("#AR-Tasks_RequestToTransport")]
14  protected LocalizedString m_sRequestToText;
15 
16  [Attribute("50", "How far can the assignee be from the requester when the task is evaluated.")]
17  protected float m_fMaxDistanceAssignee;
18 
19  [Attribute("50", "How far from the destination is the task evaluated.")]
20  protected float m_fMaxDistanceDestination;
21 
22  protected bool m_bSetFromPosition;
23  protected vector m_vFromPosition;
24  protected vector m_vToPosition;
25 
26  //------------------------------------------------------------------------------------------------
27  float GetMaxDistanceAssigneeSq()
28  {
29  return m_fMaxDistanceAssignee * m_fMaxDistanceAssignee;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  float GetMaxDistanceDestinationSq()
34  {
35  return m_fMaxDistanceDestination * m_fMaxDistanceAssignee;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  SCR_TransportTask CreateNewTransportTask(int requesterID, vector fromPosition, vector toPosition)
40  {
42  if (!task)
43  return null;
44 
45  SCR_BaseTaskExecutor requester = SCR_BaseTaskExecutor.GetTaskExecutorByID(requesterID);
46 
47  SetRequester(task, requester); // Internally replicated
48  SetTargetPosition(task, toPosition); // Internally replicated
49 
50  return task;
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  void SetTargetPosition(notnull SCR_TransportTask task, vector position)
55  {
56  if (!GetTaskManager())
57  return;
58 
59  int taskID = task.GetTaskID();
60 
61  RPC_SetTargetPosition(taskID, position);
62  Rpc(RPC_SetTargetPosition, taskID, position);
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  void TransportTaskNextPhase(notnull SCR_TransportTask transportTask)
67  {
68  if (!GetTaskManager())
69  return;
70 
71  if (!transportTask.GetVolunteerMet())
72  {
73  transportTask.SetVolunteerMet(true);
74 
75  MoveTask(transportTask.GetTargetPosition(), transportTask.GetTaskID());
76  Rpc(RPC_TransportTaskNextPhase, transportTask.GetTaskID());
77  }
78  else
79  FinishTask(transportTask);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
84  protected void RPC_TransportTaskNextPhase(int taskID)
85  {
86  if (!GetTaskManager())
87  return;
88 
89  SCR_TransportTask transportTask = SCR_TransportTask.Cast(GetTaskManager().GetTask(taskID));
90 
91  if (transportTask)
92  transportTask.SetVolunteerMet(true);
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
97  void RPC_SetTargetPosition(int taskID, vector position)
98  {
99  if (!GetTaskManager())
100  return;
101 
103  if (!task)
104  return;
105 
106  task.SetTargetPosition(position);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  //This should only be called on the server!
111  void RequestTransport(int requesterID, vector fromPosition, vector toPosition)
112  {
113  CreateNewTransportTask(requesterID, fromPosition, toPosition);
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  protected override void RegisterContextualMenuCallbacks()
118  {
119  if (m_sRequestButtonText.IsEmpty())
120  return;
121 
122  SCR_MapRadialUI radialMenu = SCR_MapRadialUI.Cast(SCR_MapEntity.GetMapInstance().GetMapUIComponent(SCR_MapRadialUI));
123  if (!radialMenu)
124  return;
125 
127  if (!entry)
128  return;
129 
130  entry.SetName(m_sRequestButtonText);
131  entry.SetSupportClass(this);
132  entry.GetOnPerform().Insert(Request);
133  //entry.m_OnShow.Insert(OnContextualEntryShow);
134 
135  radialMenu.InsertCustomRadialEntry(entry);
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected void SetToPosition()
140  {
141  SCR_MapRadialUI radialMenu = SCR_MapRadialUI.Cast(SCR_MapEntity.GetMapInstance().GetMapUIComponent(SCR_MapRadialUI));
142  if (!radialMenu)
143  return;
144 
145  m_vToPosition = radialMenu.GetMenuWorldPosition();
146  m_bSetFromPosition = false;
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void SetFromPosition()
151  {
152  SCR_MapRadialUI radialMenu = SCR_MapRadialUI.Cast(SCR_MapEntity.GetMapInstance().GetMapUIComponent(SCR_MapRadialUI));
153  if (!radialMenu)
154  return;
155 
156  m_vFromPosition = radialMenu.GetMenuWorldPosition();
157  m_bSetFromPosition = true;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override bool CanRequest()
162  {
163  return super.CanRequest();
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  override void SetRequestButtonText(notnull TextWidget textWidget)
168  {
169  if (!m_bSetFromPosition)
170  textWidget.SetTextFormat(m_sRequestFromText);
171  else
172  textWidget.SetTextFormat(m_sRequestToText);
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  override void Request()
177  {
178  if (!m_bSetFromPosition)
179  {
180  SetFromPosition();
181  return;
182  }
183 
184  SetToPosition();
185 
186  PlayerController playerController = GetGame().GetPlayerController();
187  if (!playerController)
188  return;
189 
190  // Find task network component to send RPC to server
191  SCR_CampaignTaskNetworkComponent taskNetworkComponent = SCR_CampaignTaskNetworkComponent.Cast(playerController.FindComponent(SCR_CampaignTaskNetworkComponent));
192  if (!taskNetworkComponent)
193  return;
194 
195  if (!SCR_UIRequestEvacTaskComponent.HasSignal(playerController))
196  return;
197 
198  taskNetworkComponent.RequestTransport(m_vFromPosition, m_vToPosition);
199  }
200 };
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_TransportTaskSupportEntity
Definition: SCR_TransportTaskSupportEntity.c:8
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetTask
SCR_ScenarioFrameworkTask GetTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:65
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_MapMenuRequestedTaskEntry
Definition: SCR_MapMenuCommandingEntry.c:20
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_TransportTask
Definition: SCR_TransportTask.c:7
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
SCR_TransportTaskSupportEntityClass
Definition: SCR_TransportTaskSupportEntity.c:3
CreateTask
protected bool CreateTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:389
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
LocalizedString
Definition: LocalizedString.c:21
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180