Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousfillfuel.c
Go to the documentation of this file.
2 {
3  protected float m_ItemQuantity;
4  protected float m_SpentQuantity;
5  protected float m_SpentQuantity_total;
6  protected float m_EmptySpace; //basically free capacity
7  protected float m_TimeElpased;
8  protected float m_QuantityUsedPerSecond;
9  protected float m_AdjustedQuantityUsedPerSecond;
10  protected float m_DefaultTimeStep;
11  protected ref Param1<float> m_SpentUnits;
12 
13  protected PlayerBase m_Player;
14 
15  void CAContinuousFillFuel( float quantity_used_per_second, float time_to_progress )
16  {
17  m_QuantityUsedPerSecond = quantity_used_per_second;
18  m_DefaultTimeStep = time_to_progress;
19  }
20 
21  //---------------------------------------------------------------------------
22  override void Setup( ActionData action_data )
23  {
24  m_Player = action_data.m_Player;
25 
26  Car car = Car.Cast(action_data.m_Target.GetObject());
27 
28  m_TimeElpased = 0;
29  m_SpentQuantity = 0;
30 
31  if ( !m_SpentUnits )
32  {
33  m_SpentUnits = new Param1<float>( 0 );
34  }
35  else
36  {
37  m_SpentUnits.param1 = 0;
38  }
39 
40  m_QuantityUsedPerSecond *= Math.Min(action_data.m_MainItem.GetLiquidThroughputCoef(),car.GetLiquidThroughputCoef());
41 
42  float fuelCapacity = car.GetFluidCapacity( CarFluid.FUEL );
43  float currentFuel = car.GetFluidFraction( CarFluid.FUEL );
44  currentFuel = currentFuel * fuelCapacity;
45 
46  m_EmptySpace = (fuelCapacity - currentFuel) * 1000;
47  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
48 
49  if ( m_EmptySpace <= m_ItemQuantity )
50  m_ItemQuantity = m_EmptySpace;
51 
52  }
53 
54  //---------------------------------------------------------------------------
55  override int Execute( ActionData action_data )
56  {
57  Car car = Car.Cast(action_data.m_Target.GetObject());
58 
59  if ( !action_data.m_Player )
60  {
61  return UA_ERROR;
62  }
63 
64  if ( m_ItemQuantity <= 0 )
65  {
66  return UA_FINISHED;
67  }
68  else
69  {
70  if ( m_SpentQuantity_total < m_ItemQuantity )
71  {
72  m_AdjustedQuantityUsedPerSecond = action_data.m_Player.GetSoftSkillsManager().SubtractSpecialtyBonus( m_QuantityUsedPerSecond, m_Action.GetSpecialtyWeight(), true);
73  m_SpentQuantity += m_AdjustedQuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
74  m_TimeElpased += action_data.m_Player.GetDeltaT();
75 
76  if ( m_TimeElpased >= m_DefaultTimeStep )
77  {
78  CalcAndSetQuantity( action_data );
79  m_TimeElpased = 0;
80  //Setup(action_data); //reset data after repeat
81  }
82 
83  return UA_PROCESSING;
84  }
85  else
86  {
87  CalcAndSetQuantity( action_data );
88  OnCompletePogress(action_data);
89  return UA_FINISHED;
90  }
91  }
92  }
93 
94  //---------------------------------------------------------------------------
95  override int Cancel( ActionData action_data )
96  {
97  if ( !action_data.m_Player )
98  {
99  return UA_ERROR;
100  }
101 
102  CalcAndSetQuantity( action_data );
103  return UA_INTERRUPT;
104  }
105 
106  //---------------------------------------------------------------------------
107  override float GetProgress()
108  {
109  if ( m_ItemQuantity <= 0 )
110  return 1;
111 
112  return -(m_SpentQuantity_total / m_ItemQuantity);
113  }
114 
115  //---------------------------------------------------------------------------
116  void CalcAndSetQuantity( ActionData action_data )
117  {
118 
119  m_SpentQuantity_total += m_SpentQuantity;
120 
121  if ( m_SpentUnits )
122  {
123  m_SpentUnits.param1 = m_SpentQuantity;
124  SetACData(m_SpentUnits);
125  }
126 
127 
128  if ( GetGame().IsServer() )
129  {
130  Car car = Car.Cast(action_data.m_Target.GetObject());
131  action_data.m_MainItem.AddQuantity( -m_SpentQuantity );
132  car.Fill( CarFluid.FUEL, (m_SpentQuantity * 0.001) );
133  }
134 
135  m_SpentQuantity = 0;
136  }
137 }
UA_INTERRUPT
const int UA_INTERRUPT
Definition: constants.c:438
GetGame
proto native CGame GetGame()
CAContinuousBase
Definition: cacontinuousbase.c:1
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
CAContinuousFillFuel
Definition: cacontinuousfillfuel.c:1
CarFluid
CarFluid
Type of vehicle's fluid. (native, do not change or extend)
Definition: car.c:18
PlayerBase
Definition: playerbaseclient.c:1
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
Math
Definition: enmath.c:6
m_Action
enum ActionInputType m_Action