Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuousfill.c
Go to the documentation of this file.
2 {
3  protected float m_TargetUnits;
4  protected float m_SpentQuantity;
5  protected float m_SpentQuantity_total;
6  protected float m_ItemQuantity;
7  protected float m_AdjustedQuantityFilledPerSecond;
8  protected float m_QuantityFilledPerSecond;
9  protected ref Param1<float> m_SpentUnits;
10  protected float m_TimeElpased;
11  protected float m_DefaultTimeStep = 0.25;
12  protected int m_liquid_type;
13 
14  void CAContinuousFill( float quantity_filled_per_second , int liquid_type )
15  {
16  m_QuantityFilledPerSecond = quantity_filled_per_second;
17  m_liquid_type = liquid_type;
18  }
19 
20  override void Setup( ActionData action_data )
21  {
22  m_TimeElpased = 0;
23 
24  if ( !m_SpentUnits )
25  {
26  m_SpentUnits = new Param1<float>(0);
27  }
28  else
29  {
30  m_SpentUnits.param1 = 0;
31  }
32 
33  float throughputCoef = action_data.m_MainItem.GetLiquidThroughputCoef();
34  EntityAI entity;
35  if (action_data.m_Target && action_data.m_Target.GetObject() && Class.CastTo(entity,action_data.m_Target.GetObject()))
36  {
37  throughputCoef = Math.Min(throughputCoef,entity.GetLiquidThroughputCoef());
38  }
39  m_QuantityFilledPerSecond *= throughputCoef;
40 
41  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
42  m_TargetUnits = action_data.m_MainItem.GetQuantityMax() - action_data.m_MainItem.GetQuantity();
43  m_AdjustedQuantityFilledPerSecond = action_data.m_Player.GetSoftSkillsManager().AddSpecialtyBonus( m_QuantityFilledPerSecond, m_Action.GetSpecialtyWeight(), true );
44  }
45 
46  override int Execute( ActionData action_data )
47  {
48  if ( !action_data.m_Player )
49  {
50  return UA_ERROR;
51  }
52 
53  if ( action_data.m_MainItem.GetQuantity() >= action_data.m_MainItem.GetQuantityMax() )
54  {
55  return UA_FINISHED;
56  }
57  else
58  {
59  if ( m_SpentQuantity_total < m_TargetUnits )
60  {
61  m_SpentQuantity += m_AdjustedQuantityFilledPerSecond * action_data.m_Player.GetDeltaT();
62  m_TimeElpased += action_data.m_Player.GetDeltaT();
63 
64  if ( m_TimeElpased >= m_DefaultTimeStep )
65  {
66  CalcAndSetQuantity( action_data );
67  m_TimeElpased = 0;
68  //Setup(action_data); //reset data after repeat
69  }
70  return UA_PROCESSING;
71  }
72  else
73  {
74  CalcAndSetQuantity( action_data );
75  OnCompletePogress(action_data);
76  return UA_FINISHED;
77  }
78  }
79  }
80 
81  override int Cancel( ActionData action_data )
82  {
83  if ( !action_data.m_Player || !action_data.m_MainItem )
84  {
85  return UA_ERROR;
86  }
87 
88  CalcAndSetQuantity( action_data );
89  return UA_CANCEL;
90  }
91 
92  override int Interrupt( ActionData action_data )
93  {
94  if ( GetGame().IsServer() )
95  {
96  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( UASoftSkillsWeight.PRECISE_LOW );
97  }
98 
99  return super.Interrupt( action_data );
100  }
101 
102  override float GetProgress()
103  {
104  return m_SpentQuantity_total/m_TargetUnits;
105  }
106  //---------------------------------------------------------------------------
107 
108  void CalcAndSetQuantity(ActionData action_data)
109  {
110  m_SpentQuantity_total += m_SpentQuantity;
111  if (GetGame().IsServer())
112  {
113  if (m_SpentUnits)
114  {
115  m_SpentUnits.param1 = m_SpentQuantity;
116  SetACData(m_SpentUnits);
117  }
118 
119  bool injectAgents = true;
120  if (action_data.m_Target.GetObject() && (action_data.m_Target.GetObject().GetWaterSourceObjectType() == EWaterSourceObjectType.WELL || action_data.m_Target.GetObject().IsWell()))
121  injectAgents = false;
122 
123  Liquid.FillContainerEnviro(action_data.m_MainItem, m_liquid_type, m_SpentQuantity, injectAgents);
124  }
125 
126  m_SpentQuantity = 0;
127  }
128 }
GetGame
proto native CGame GetGame()
CAContinuousBase
Definition: cacontinuousbase.c:1
CAContinuousFill
Definition: cacontinuousfill.c:1
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
EWaterSourceObjectType
EWaterSourceObjectType
Definition: ewatersourceobjecttype.c:1
UASoftSkillsWeight
Definition: actionconstants.c:118
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
Liquid
Definition: liquid.c:1
Math
Definition: enmath.c:6
m_Action
enum ActionInputType m_Action
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5