Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
cacontinuousfertilizegardenslot.c
Go to the documentation of this file.
2{
3 protected float m_SlotFertilizerNeed;
4 protected float m_AlreadyFilledAmount; // amount of fertilizer present within slot during the setup of action
5 protected float m_TimeToComplete;
6 protected Slot m_Slot;
7 protected string m_Selection;
8
9 void CAContinuousFertilizeGardenSlot(float quantity_used_per_second)
10 {
11 m_QuantityUsedPerSecond = quantity_used_per_second;
13 }
14
15 override void Setup(ActionData action_data)
16 {
17 GardenBase targetGB;
18 if (Class.CastTo(targetGB, action_data.m_Target.GetObject()))
19 {
21
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 (targetGB)
35 {
36 array<string> selections = new array<string>;
37 targetGB.GetActionComponentNameList(action_data.m_Target.GetComponentIndex(), selections);
38
39 for (int s = 0; s < selections.Count(); s++)
40 {
41 m_Selection = selections[s];
42 m_Slot = targetGB.GetSlotBySelection(m_Selection);
43 if (m_Slot)
44 break;
45 }
46
47 string itemType = action_data.m_MainItem.GetType();
48 float consumedQuantity = g_Game.ConfigGetFloat("cfgVehicles " + itemType + " Horticulture ConsumedQuantity");
49 float actionLength = g_Game.ConfigGetFloat("cfgVehicles " + itemType + " Horticulture FertilizeLength");
50 if (actionLength == 0)
51 actionLength = 1;
52
53 m_Slot.SetFertilizerQuantityMax(consumedQuantity);
54 m_AlreadyFilledAmount = m_Slot.GetFertilizerQuantity();
56 }
57
58 float defaultTimeComplete = consumedQuantity / m_QuantityUsedPerSecond;
59 float speedMultiplier = defaultTimeComplete / actionLength;
60 m_QuantityUsedPerSecond *= speedMultiplier;
61 }
62 }
63
64
65 override int Execute(ActionData action_data)
66 {
67 if (!action_data.m_Player)
68 {
69 return UA_ERROR;
70 }
71
73 {
74 return UA_FINISHED;
75 }
76 else
77 {
79 {
81 string itemType = action_data.m_MainItem.GetType();
82 if (m_Slot.GetFertilityType() != "" && m_Slot.GetFertilityType() != itemType)
83 {
84 m_Slot.SetFertilityType(itemType);
85 }
86
87 m_SpentQuantity = m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
88
89 GardenBase gardenBase;
90 if (!Class.CastTo(gardenBase, action_data.m_Target.GetObject()))
91 {
92 return UA_ERROR;
93 }
94
95 FertilizeSlot(action_data.m_MainItem, gardenBase, m_SpentQuantity);
96
97 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
98 {
99 action_data.m_MainItem.AddQuantity(-m_SpentQuantity);
100 }
101
102 return UA_PROCESSING;
103 }
104 else
105 {
106 CalcAndSetQuantity(action_data);
107 OnCompletePogress(action_data);
108 return UA_FINISHED;
109 }
110 }
111 }
112
113 protected void FertilizeSlot(ItemBase item, GardenBase gardenBase, float consumedQuantity)
114 {
115 if (m_Slot)
116 {
117 string itemType = item.GetType();
118 if (m_Slot.GetFertilityType() == "" || m_Slot.GetFertilityType() == itemType)
119 {
120 m_Slot.SetFertilityType(itemType);
121
122 float addEnergyToSlot = g_Game.ConfigGetFloat(string.Format("cfgVehicles %1 Horticulture AddEnergyToSlot", itemType));
123 m_Slot.m_FertilizerUsage = g_Game.ConfigGetFloat(string.Format("cfgVehicles %1 Horticulture ConsumedQuantity", itemType));
124
125 float coef = Math.Clamp(consumedQuantity / m_Slot.m_FertilizerUsage, 0.0, 1.0);
126 addEnergyToSlot = coef * addEnergyToSlot;
127
128 float fertilizerMax = m_Slot.GetFertilizerQuantityMax();
129 float newFertilizerQuantity = (m_Slot.m_FertilizerQuantity + consumedQuantity);
130 newFertilizerQuantity = Math.Clamp(newFertilizerQuantity, 0.0, fertilizerMax);
131 m_Slot.SetFertilizerQuantity(newFertilizerQuantity);
132
133 float newfertility = (m_Slot.m_Fertility + addEnergyToSlot);
134 float fertilityMax = m_Slot.GetFertilityMax();
135 newfertility = Math.Clamp(newfertility, 0.0, fertilityMax);
136 m_Slot.SetFertility(newfertility);
137 }
138 }
139 }
140
141 override float GetProgress()
142 {
143 return -((m_Slot.GetFertilizerQuantity() - m_AlreadyFilledAmount) / m_SlotFertilizerNeed);
144 }
145
147 protected float m_SpentQuantityTotal;
148 protected float m_StartQuantity;
149};
ActionBase ActionData
Definition actionbase.c:30
void OnCompletePogress(ActionData action_data)
void FertilizeSlot(ItemBase item, GardenBase gardenBase, float consumedQuantity)
override int Execute(ActionData action_data)
void CAContinuousFertilizeGardenSlot(float quantity_used_per_second)
override void Setup(ActionData action_data)
ref Param1< float > m_SpentUnits
void CAContinuousQuantity(float quantity_used_per_second)
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
void CalcAndSetQuantity()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
const int UA_FINISHED
Definition constants.c:469
const int UA_ERROR
Definition constants.c:488
const int UA_PROCESSING
Definition constants.c:467