Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cacontinuouswaterslot.c
Go to the documentation of this file.
2 {
3  protected float m_PlantThirstyness;
4  protected float m_TimeToComplete;
5  protected float m_SpentQuantityTotal;
6  protected float m_StartQuantity;
7  protected Slot m_Slot;
8 
9  void CAContinuousWaterSlot( float quantity_used_per_second )
10  {
11  m_QuantityUsedPerSecond = quantity_used_per_second;
12  }
13 
14  override void Setup( ActionData action_data )
15  {
16  GardenBase target_GB;
17 
18  if ( Class.CastTo(target_GB, action_data.m_Target.GetObject()) )
19  {
20  m_SpentQuantity = 0;
21  m_StartQuantity = action_data.m_MainItem.GetQuantity();
22  if ( !m_SpentUnits )
23  {
24  m_SpentUnits = new Param1<float>(0);
25  }
26  else
27  {
28  m_SpentUnits.param1 = 0;
29  }
30 
31  if ( action_data.m_MainItem )
32  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
33 
34  if ( target_GB )
35  {
36  array<string> selections = new array<string>;
37  target_GB.GetActionComponentNameList(action_data.m_Target.GetComponentIndex(), selections);
38 
39  for (int s = 0; s < selections.Count(); s++)
40  {
41  string selection = selections[s];
42  m_Slot = target_GB.GetSlotBySelection( selection );
43  if (m_Slot)
44  break;
45  }
46 
47  m_PlantThirstyness = m_Slot.GetWaterUsage() - m_Slot.GetWater();
48  }
49 
50  m_TimeToComplete = (Math.Min(m_PlantThirstyness,m_ItemQuantity))/m_QuantityUsedPerSecond;
51 
52  if (m_TimeToComplete <= 0.1) // Division by zero prevention
53  {
54  m_TimeToComplete = 0.1;
55  }
56  }
57  }
58 
59  override int Execute( ActionData action_data )
60  {
61  GardenBase target_GB;
62  Class.CastTo(target_GB, action_data.m_Target.GetObject() );
63  m_ItemQuantity = action_data.m_MainItem.GetQuantity();
64  m_ItemMaxQuantity = action_data.m_MainItem.GetQuantityMax();
65 
66  if ( !action_data.m_Player )
67  {
68  return UA_ERROR;
69  }
70 
71  if ( m_ItemQuantity <= 0 )
72  {
73  return UA_FINISHED;
74  }
75  else
76  {
77  if ( m_Slot && m_SpentQuantity < m_ItemQuantity )
78  {
79  m_SpentQuantity += m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
80  float water = action_data.m_Player.GetSoftSkillsManager().AddSpecialtyBonus( m_SpentQuantity, m_Action.GetSpecialtyWeight(), true );
81  m_Slot.GiveWater( water );
82 
83  m_SpentQuantityTotal += m_SpentQuantity;
84  CalcAndSetQuantity( action_data );
85 
86  m_SpentQuantity = 0;
87 
88  return UA_PROCESSING;
89  }
90  else
91  {
92  CalcAndSetQuantity( action_data );
93  OnCompletePogress( action_data );
94 
95  return UA_FINISHED;
96  }
97  }
98  }
99 
100  override float GetProgress()
101  {
102  if ( m_ItemQuantity <= 0 )
103  return 1;
104  float progress = -(m_SpentQuantityTotal / m_StartQuantity);
105  return progress;
106  }
107 };
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
CAContinuousWaterSlot
Definition: cacontinuouswaterslot.c:1
CAContinuousQuantity
Definition: cacontinuousquantity.c:1
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
ActionData
Definition: actionbase.c:20
CalcAndSetQuantity
protected void CalcAndSetQuantity()
Definition: fireplacebase.c:2622
array< string >
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
Math
Definition: enmath.c:6
GardenBase
Definition: gardenplot.c:1
m_Action
enum ActionInputType m_Action
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10