Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EvacuateTask.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "A support task.", color: "0 0 255 255")]
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  static const string SUPPORT_TASK_DESCRIPTION_TEXT = "#AR-CampaignTasks_TitleEvac";
10  static const SCR_ECampaignBaseType BASES_FILTER = SCR_ECampaignBaseType.BASE;
11 
12  protected vector m_vStartOrigin;
13 
14  //------------------------------------------------------------------------------------------------
15  static float GetMinDistanceFromStart()
16  {
17  if (!GetTaskManager())
18  return 1000;
19 
21  if (supportEntity)
22  return supportEntity.GetMinDistanceFromStart();
23 
24  return 1000;
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  static float GetMaxDistanceFromRequester()
29  {
30  if (!GetTaskManager())
31  return 50;
32 
34  if (supportEntity)
35  return supportEntity.GetMaxDistanceFromRequester();
36 
37  return 50;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override string GetMapDescriptorText()
42  {
43  return GetTaskListTaskText();
44  }
45 
46  //------------------------------------------------------------------------------------------------
47  void PeriodicalCheck()
48  {
49  if (!GetTaskManager())
50  return;
51 
53  if (!supportEntity)
54  return;
55 
56  bool assigneeCloseEnough = true;
57  bool requesterInBase = false;
58  GenericEntity requesterEntity = GenericEntity.Cast(m_Requester.GetControlledEntity());
59 
60  if (!requesterEntity)
61  {
62  supportEntity.FailTask(this);
63  return;
64  }
65 
66  FactionAffiliationComponent factionAffiliationComponent = FactionAffiliationComponent.Cast(requesterEntity.FindComponent(FactionAffiliationComponent));
67  if (!factionAffiliationComponent)
68  return;
69 
70  Faction requesterFaction = factionAffiliationComponent.GetAffiliatedFaction();
71 
72  vector requesterOrigin = requesterEntity.GetOrigin();
73 
74  array<SCR_MilitaryBaseComponent> bases = {};
75  SCR_MilitaryBaseSystem.GetInstance().GetBases(bases);
76 
77  for (int i = 0; i < bases.Count(); i++)
78  {
80 
81  if (!campaignBase)
82  continue;
83 
84  if (requesterFaction != campaignBase.GetCampaignFaction())
85  continue;
86 
87  vector baseOrigin = campaignBase.GetOwner().GetOrigin();
88  float baseToStartDistance = vector.Distance(baseOrigin, m_vStartOrigin);
89 
90  if (baseToStartDistance < SCR_EvacuateTask.GetMinDistanceFromStart())
91  continue;
92 
93  if (!campaignBase.GetIsEntityPresent(requesterEntity))
94  continue;
95 
96  requesterInBase = true;
97  break;
98  }
99 
100  SCR_BaseTaskExecutor assignee = GetAssignee();
101  if (!assignee)
102  assigneeCloseEnough = false;
103  else
104  {
105  IEntity assigneeEntity = assignee.GetControlledEntity();
106  vector assigneePosition = vector.Zero;
107  if (assigneeEntity)
108  assigneePosition = assigneeEntity.GetOrigin();
109  float distance = vector.Distance(requesterOrigin, assigneePosition);
110 
111  if (distance > SCR_EvacuateTask.GetMaxDistanceFromRequester())
112  assigneeCloseEnough = false;
113  }
114 
115  if (requesterInBase)
116  {
117  if (assigneeCloseEnough)
118  supportEntity.FinishTask(this);
119  else
120  supportEntity.FailTask(this);
121  }
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  void SetStartOrigin(vector startOrigin)
126  {
127  if (m_vStartOrigin != vector.Zero)
128  {
129  m_vStartOrigin = startOrigin;
130  return;
131  }
132 
133  if (!m_Requester)
134  return;
135 
136  GenericEntity requesterEntity = GenericEntity.Cast(m_Requester.GetControlledEntity());
137  if (!requesterEntity)
138  return;
139 
140  m_vStartOrigin = requesterEntity.GetOrigin();
141 
142  ShowAvailableTask();
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  vector GetStartOrigin()
147  {
148  return m_vStartOrigin;
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  override void Serialize(ScriptBitWriter writer)
153  {
154  super.Serialize(writer);
155 
156  vector startOrigin = GetStartOrigin();
157  writer.WriteVector(startOrigin);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override void Deserialize(ScriptBitReader reader)
162  {
163  super.Deserialize(reader);
164 
165  vector startOrigin;
166  reader.ReadVector(startOrigin);
167  SetStartOrigin(startOrigin);
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  void SCR_EvacuateTask(IEntitySource src, IEntity parent)
172  {
173  if (SCR_Global.IsEditMode(this))
174  return;
175 
176  SetEventMask(EntityEvent.FRAME);
177  SetIndividual(true);
178 
179  if (!GetTaskManager().IsProxy())
180  SCR_BaseTaskManager.s_OnPeriodicalCheck5Second.Insert(PeriodicalCheck);
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  void ~SCR_EvacuateTask()
185  {
186  if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
187  return;
188 
189  if (!GetTaskManager().IsProxy())
190  SCR_BaseTaskManager.s_OnPeriodicalCheck5Second.Remove(PeriodicalCheck);
191  }
192 
193 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_EvacuateTaskClass
Definition: SCR_EvacuateTask.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
SCR_EvacuateTask
Definition: SCR_EvacuateTask.c:7
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
SCR_RequestedTaskClass
Definition: SCR_RequestedTask.c:2
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_EvacuateTaskSupportEntity
Definition: SCR_EvacuateTaskSupportEntity.c:8
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
SCR_Global
Definition: Functions.c:6
SCR_RequestedTask
Definition: SCR_RequestedTask.c:8
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180