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