Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousfilloil.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 CAContinuousFillOil( 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  if ( !car )
29  return;
30 
31  m_TimeElpased = 0;
32  m_SpentQuantity = 0;
33 
34  if ( !m_SpentUnits )
35  {
36  m_SpentUnits = new Param1<float>( 0 );
37  }
38  else
39  {
40  m_SpentUnits.param1 = 0;
41  }
42 
43  float oilCapacity = car.GetFluidCapacity( CarFluid.OIL );
44  float currentOil = car.GetFluidFraction( CarFluid.OIL );
45  currentOil = currentOil * oilCapacity;
46 
47  m_EmptySpace = (oilCapacity - currentOil) * 1000;
48  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
49 
50  if ( m_EmptySpace <= m_ItemQuantity )
51  m_ItemQuantity = m_EmptySpace;
52 
53  }
54 
55  //---------------------------------------------------------------------------
56  override int Execute( ActionData action_data )
57  {
58  Car car = Car.Cast(action_data.m_Target.GetObject());
59 
60  if ( !car )
61  return UA_ERROR;
62 
63  if ( !action_data.m_Player )
64  {
65  return UA_ERROR;
66  }
67 
68  if ( m_ItemQuantity <= 0 )
69  {
70  return UA_FINISHED;
71  }
72  else
73  {
74  if ( m_SpentQuantity_total < m_ItemQuantity )
75  {
76  m_AdjustedQuantityUsedPerSecond = action_data.m_Player.GetSoftSkillsManager().SubtractSpecialtyBonus( m_QuantityUsedPerSecond, m_Action.GetSpecialtyWeight(), true);
77  m_SpentQuantity += m_AdjustedQuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
78  m_TimeElpased += action_data.m_Player.GetDeltaT();
79 
80  if ( m_TimeElpased >= m_DefaultTimeStep )
81  {
82  CalcAndSetQuantity( action_data );
83  m_TimeElpased = 0;
84  //Setup(action_data); //reset data after repeat
85  }
86 
87  return UA_PROCESSING;
88  }
89  else
90  {
91  CalcAndSetQuantity( action_data );
92  OnCompletePogress(action_data);
93  return UA_FINISHED;
94  }
95  }
96  }
97 
98  //---------------------------------------------------------------------------
99  override int Cancel( ActionData action_data )
100  {
101  if ( !action_data.m_Player )
102  {
103  return UA_ERROR;
104  }
105 
106  CalcAndSetQuantity( action_data );
107  return UA_INTERRUPT;
108  }
109 
110  //---------------------------------------------------------------------------
111  override float GetProgress()
112  {
113  if ( m_ItemQuantity <= 0 )
114  return 1;
115 
116  return -(m_SpentQuantity_total / m_ItemQuantity);
117  }
118 
119  //---------------------------------------------------------------------------
120  void CalcAndSetQuantity( ActionData action_data )
121  {
122 
123  m_SpentQuantity_total += m_SpentQuantity;
124 
125  if ( m_SpentUnits )
126  {
127  m_SpentUnits.param1 = m_SpentQuantity;
128  SetACData(m_SpentUnits);
129  }
130 
131 
132  if ( GetGame().IsServer() )
133  {
134  if ( action_data.m_MainItem ) // Item EngineOil gets deleted after full consumption
135  action_data.m_MainItem.AddQuantity( -m_SpentQuantity );
136 
137  Car car = Car.Cast(action_data.m_Target.GetObject());
138  car.Fill( CarFluid.OIL, (m_SpentQuantity * 0.001) );
139  }
140 
141  m_SpentQuantity = 0;
142  }
143 }
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
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
CAContinuousFillOil
Definition: cacontinuousfilloil.c:1
m_Action
enum ActionInputType m_Action