Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RefuelTask.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Campaign", description: "Refuel task.", color: "0 0 255 255")]
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  IEntity m_targetVehicle;
10 
11  //------------------------------------------------------------------------------------------------
12  static Vehicle GetVehicleExecutorIsIn(SCR_BaseTaskExecutor taskExecutor)
13  {
14  if (!taskExecutor)
15  return null;
16 
17  ChimeraCharacter character = ChimeraCharacter.Cast(taskExecutor.GetControlledEntity());
18  if (!character)
19  return null;
20 
21  if (!character.IsInVehicle())
22  return null;
23 
24  CompartmentAccessComponent compartmentAccessComponent = CompartmentAccessComponent.Cast(character.FindComponent(CompartmentAccessComponent));
25  if (!compartmentAccessComponent)
26  return null;
27 
28  BaseCompartmentSlot compartmentSlot = compartmentAccessComponent.GetCompartment();
29  if (!compartmentSlot)
30  return null;
31 
32  Vehicle vehicle = Vehicle.Cast(compartmentSlot.GetOwner());
33 
34  return vehicle;
35  }
36 
37  //------------------------------------------------------------------------------------------------
38  static bool CheckRefuelRequestConditions(notnull SCR_BaseTaskExecutor taskExecutor)
39  {
40  Vehicle vehicle = GetVehicleExecutorIsIn(taskExecutor);
41  if (!vehicle)
42  return false;
43 
44  SCR_FuelNode fuelNode = SCR_FuelNode.Cast(vehicle.FindComponent(SCR_FuelNode));
45  if (!fuelNode)
46  return false;
47 
48  float maxFuel = fuelNode.GetMaxFuel();
49  float currentFuel = fuelNode.GetFuel();
50  float fuelPercent = currentFuel / maxFuel;
51 
52  return fuelPercent <= GetFuelLimit();
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  static float GetFuelLimit()
57  {
58  if (!GetTaskManager())
59  return 0.5;
60 
62  if (supportEntity)
63  return supportEntity.GetFuelLimit();
64 
65  return 0.5;
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override string GetMapDescriptorText()
70  {
71  return GetTaskListTaskText();
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  void SetTargetVehicle(IEntity targetVehicle)
76  {
77  // Only set on server!
78  m_targetVehicle = targetVehicle;
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  IEntity GetTargetVehicle()
83  {
84  return m_targetVehicle;
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  void SetRequester(SCR_BaseTaskExecutor requester, vector startOrigin)
89  {
90  super.SetRequester(requester);
91 
92  ShowAvailableTask();
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  //Called whenever any fuel component finished refueling (even half way through)
97  void OnRefuelingFinished(SCR_FuelNode fuelNode, IEntity refueler)
98  {
99  if (!fuelNode || !refueler)
100  return;
101 
102  IEntity vehicle = fuelNode.GetOwner();
103  if (!vehicle)
104  return;
105 
106  if (GetTargetVehicle() != vehicle)
107  return;
108 
109  if (!GetTaskManager())
110  return;
111 
113  if (!supportEntity)
114  return;
115 
116  SCR_BaseTaskExecutor assignee = GetAssignee();
117  if (!assignee)
118  {
119  supportEntity.FailTask(this);
120  return;
121  }
122 
123  IEntity assigneeControlledEntity = assignee.GetControlledEntity();
124  if (!assigneeControlledEntity || assigneeControlledEntity != refueler)
125  {
126  supportEntity.FailTask(this);
127  return;
128  }
129 
130  float currentFuel, maxFuel;
131  currentFuel = fuelNode.GetFuel();
132  maxFuel = fuelNode.GetMaxFuel();
133  float percent = currentFuel / maxFuel;
134 
135  if (percent >= SCR_RefuelTask.GetFuelLimit())
136  supportEntity.FinishTask(this);
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  void SCR_RefuelTask(IEntitySource src, IEntity parent)
141  {
142  if (SCR_Global.IsEditMode(this))
143  return;
144 
145  SetEventMask(EntityEvent.INIT | EntityEvent.FRAME);
146  SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
147 
148  SetIndividual(true);
149 
150  if (!GetTaskManager().IsProxy())
151  SCR_FuelNode.s_OnRefuelingFinished.Insert(OnRefuelingFinished);
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  void ~SCR_RefuelTask()
156  {
157  if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
158  return;
159 
160  if (!GetTaskManager().IsProxy())
161  SCR_FuelNode.s_OnRefuelingFinished.Remove(OnRefuelingFinished);
162  }
163 
164 };
SCR_RefuelTask
Definition: SCR_RefuelTask.c:7
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_RefuelTaskClass
Definition: SCR_RefuelTask.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
SCR_RequestedTaskClass
Definition: SCR_RequestedTask.c:2
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
SCR_Global
Definition: Functions.c:6
SCR_RequestedTask
Definition: SCR_RequestedTask.c:8
SCR_RefuelTaskSupportEntity
Definition: SCR_RefuelTaskSupportEntity.c:8
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180