DayZ 1.24
Loading...
Searching...
No Matches
Slot.c
Go to the documentation of this file.
2{
3 NONE = 0,
4 FERTILIZED = 1
5 //This will be used to set bit values (DO NOT ADD MORE VALUES)
7
9{
10 DRY = 0,
11 WET = 1
12 //Used to improve readability of watered state changes
13}
14
15class Slot
16{
17 static const int STATE_DIGGED = 1;
18 static const int STATE_PLANTED = 2;
19
20 private int m_WaterQuantity;
21 static private int m_WaterNeeded = 190; // How much water is needed to water a plant from a bottle. Value is in mililitres
22 static private int m_WaterMax = 200;
23
24 float m_Fertility;
27 int m_slotIndex;
28 int m_slotId;
29
30 string m_FertilizerType;
33 string m_DiggedSlotComponent; // example: "Component02" for the 1st slot in GardenBase
34 string m_PlantType;
35 private ItemBase m_Seed;
36 private GardenBase m_Garden;
37
39
40 int m_State;
41
42 private PlantBase m_Plant;
43
44 void Slot(float base_fertility)
45 {
46 m_Seed = NULL;
47 m_Plant = NULL;
48 m_WaterQuantity = 0.0;
50 }
51
52 void ~Slot()
53 {
54 if (m_Plant && GetGame()) // GetGame() returns NULL when the game is being quit!
55 GetGame().ObjectDelete(GetPlant());
56 }
57
58 int GetSlotIndex()
59 {
60 return m_slotIndex;
61 }
62
63 void SetSlotIndex(int index)
64 {
66 }
67
68 int GetSlotId()
69 {
70 return m_slotId;
71 }
72
73 void SetSlotId(int id)
74 {
75 m_slotId = id;
76 }
77
79 {
81 }
82
83 GardenBase GetGarden()
84 {
85 return m_Garden;
86 }
87
89 {
90 m_Seed = seed;
91 }
92
93 PlantBase GetPlant()
94 {
95 return m_Plant;
96 }
97
98 void SetPlant(PlantBase plant)
99 {
100 m_Plant = plant;
101
102 if (plant)
103 plant.SetSlot(this);
104 }
105
106 //Used to force water level an go around sync issues
107 void SetWater(int val)
108 {
109 val = Math.Clamp(val, 0, m_WaterMax);
111 }
112
114 {
115 return m_Seed;
116 }
117
118 bool HasSeed()
119 {
120 if (m_Seed)
121 return true;
122
123 return false;
124 }
125
126 void GiveWater(float consumed_quantity)
127 {
128 bool needed_water = NeedsWater();
130
131 if (m_WaterQuantity >= GetWaterMax())
132 m_WaterQuantity = GetWaterMax();
133
134 if (m_WaterQuantity < 0)
135 m_WaterQuantity = 0;
136
137 if (!NeedsWater())
138 {
139 if (!GetPlant())
140 {
141 if (GetSeed())
142 GetGarden().CreatePlant(this);
143
144 // if there is no seed then do not create plant. Plant will be created when the seed is inserted into watered slot.
145 }
146 }
147
148 if (needed_water != NeedsWater())
149 {
151 GetGarden().UpdateSlotTexture(GetSlotIndex());
152 if (m_Garden.GetSlotWateredState() != m_Garden.GetMaxWaterStateVal())
153 m_Garden.SlotWaterStateUpdate(this);
154 }
155 }
156
157 bool NeedsWater()
158 {
160 return true;
161 else
162 return false;
163 }
164
165 bool CanBeWatered()
166 {
167 if (m_WaterQuantity < GetWaterMax())
168 return true;
169 else
170 return false;
171 }
172
173 float GetWater()
174 {
175 return m_WaterQuantity;
176 }
177
178 float GetFertility()
179 {
180 return m_Fertility;
181 }
182
183 float GetFertilityMax()
184 {
185 return m_FertilizerUsage;
186 }
187
188 void SetFertility(float fertility)
189 {
191 }
192
194 {
196 }
197
199 {
200 return m_FertilizerUsage;
201 }
202
204 {
206 }
207
208 string GetFertilityType()
209 {
210 return m_FertilizerType;
211 }
212
213 void SetFertilityType(string type)
214 {
215 m_FertilizerType = type;
216 }
217
219 {
220 return m_FertilityState;
221 }
222
224 {
226 }
227
228 int GetWateredState()
229 {
230 return m_WateredState;
231 }
232
233 void SetWateredState(int newState)
234 {
236 if (m_WateredState == eWateredState.WET)
237 SetWater(GetWaterMax());
238 }
239
240 float GetWaterUsage()
241 {
242 return m_WaterNeeded;
243 }
244
245 float GetWaterMax()
246 {
247 return m_WaterMax;
248 }
249
250 int GetState()
251 {
252 return m_State;
253 }
254
255 void SetState(int new_state)
256 {
258 }
259
260 bool IsDigged()
261 {
262 if (m_State == STATE_DIGGED)
263 return true;
264
265 return false;
266 }
267 bool IsPlanted()
268 {
269 if (m_State == STATE_PLANTED)
270 return true;
271
272 return false;
273 }
274
275 void Init(float base_fertility)
276 {
278 m_FertilizerUsage = 200;
280 m_FertilizerType = "";
282
283 m_WaterQuantity = 0;
285
287 //m_DiggedSlotComponent = "";
289 m_Plant = NULL;
290 }
291
292 void SetSlotComponent(string component)
293 {
295 }
296
297 string GetSlotComponent()
298 {
300 }
301
302 bool OnStoreLoadCustom(ParamsReadContext ctx, int version)
303 {
304 if (version < 102)
305 {
306 ctx.Read(m_Fertility);
309
310 if (!ctx.Read(m_FertilizerType))
311 m_FertilizerType = "";
312
314 ctx.Read(m_State);
315 }
316
317 if (version >= 102)
318 {
319 ctx.Read(m_Fertility);
323 ctx.Read(m_State);
324
325 if (!ctx.Read(m_FertilizerType))
326 m_FertilizerType = "";
327 }
328
329 return true;
330 }
331
332 void OnStoreSaveCustom(ParamsWriteContext ctx)
333 {
334 ctx.Write(m_Fertility);
335 ctx.Write(m_FertilizerUsage);
338 ctx.Write(m_State);
339 ctx.Write(m_FertilizerType);
340 }
341}
@ WET
Definition EntityAI.c:5
override Widget Init()
Definition DayZGame.c:120
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
enum eFertlityState DRY
eFertlityState
Definition Slot.c:2
@ FERTILIZED
Definition Slot.c:4
@ NONE
Definition Slot.c:3
void SetState(bool state)
bool m_State
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
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'.
proto native int GetState()
returns one of STATE_...