Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
slot.c
Go to the documentation of this file.
2 {
3  NONE = 0,
5  //This will be used to set bit values (DO NOT ADD MORE VALUES)
6 }
7 
8 enum eWateredState
9 {
10  DRY = 0,
11  WET = 1
12  //Used to improve readability of watered state changes
13 }
14 
15 class 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;
25  float m_FertilizerUsage;
26  float m_FertilizerQuantity;
27  int m_slotIndex;
28  int m_slotId;
29 
30  string m_FertilizerType;
31  int m_FertilityState = eFertlityState.NONE;
32  int m_WateredState = eWateredState.DRY;
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 
38  float m_HarvestingEfficiency;
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;
49  Init( base_fertility );
50  }
51 
52  void ~Slot()
53  {
54  if (m_Plant && GetGame()) // GetGame() returns NULL when the game is being quit!
55  {
56  GetGame().ObjectDelete( GetPlant() );
57  }
58  }
59 
60  int GetSlotIndex()
61  {
62  return m_slotIndex;
63  }
64 
65  void SetSlotIndex(int index)
66  {
67  m_slotIndex = index;
68  }
69 
70  int GetSlotId()
71  {
72  return m_slotId;
73  }
74 
75  void SetSlotId(int id)
76  {
77  m_slotId = id;
78  }
79 
80  void SetGarden(GardenBase garden)
81  {
82  m_Garden = garden;
83  }
84 
85  GardenBase GetGarden()
86  {
87  return m_Garden;
88  }
89 
90  void SetSeed(ItemBase seed)
91  {
92  m_Seed = seed;
93  }
94 
95  PlantBase GetPlant()
96  {
97  return m_Plant;
98  }
99 
100  void SetPlant(PlantBase plant)
101  {
102  m_Plant = plant;
103 
104  if (plant)
105  {
106  plant.SetSlot(this);
107  }
108  }
109 
110  //Used to force water level an go around sync issues
111  void SetWater( int val )
112  {
113  val = Math.Clamp( val, 0, m_WaterMax );
114  m_WaterQuantity = val;
115  }
116 
117  ItemBase GetSeed()
118  {
119  return m_Seed;
120  }
121 
122  bool HasSeed()
123  {
124  if (m_Seed)
125  return true;
126 
127  return false;
128  }
129 
130  void GiveWater( float consumed_quantity )
131  {
132  bool needed_water = NeedsWater();
133  m_WaterQuantity += consumed_quantity;
134 
135  if (m_WaterQuantity >= GetWaterMax())
136  m_WaterQuantity = GetWaterMax();
137 
138  if (m_WaterQuantity < 0)
139  m_WaterQuantity = 0;
140 
141  if ( !NeedsWater() )
142  {
143  if ( !GetPlant() )
144  {
145  if ( GetSeed() )
146  {
147  GetGarden().CreatePlant(this);
148  }
149 
150  // if there is no seed then do not create plant. Plant will be created when the seed is inserted into watered slot.
151  }
152  }
153 
154  if ( needed_water != NeedsWater() )
155  {
156  SetWateredState( eWateredState.WET );
157  GetGarden().UpdateSlotTexture( GetSlotIndex() );
158  if ( m_Garden.GetSlotWateredState() != m_Garden.GetMaxWaterStateVal() )
159  m_Garden.SlotWaterStateUpdate( this );
160  }
161  }
162 
163  bool NeedsWater()
164  {
165  if ( m_WaterQuantity < GetWaterUsage() )
166  {
167  return true;
168  }
169  else
170  {
171  return false;
172  }
173  }
174 
175  bool CanBeWatered()
176  {
177  if ( m_WaterQuantity < GetWaterMax() )
178  {
179  return true;
180  }
181  else
182  {
183  return false;
184  }
185  }
186 
187  float GetWater()
188  {
189  return m_WaterQuantity;
190  }
191 
192  float GetFertility()
193  {
194  return m_Fertility;
195  }
196 
197  float GetFertilityMax()
198  {
199  return m_FertilizerUsage;
200  }
201 
202  void SetFertility(float fertility)
203  {
204  m_Fertility = fertility;
205  }
206 
207  float GetFertilizerQuantity()
208  {
209  return m_FertilizerQuantity;
210  }
211 
212  float GetFertilizerQuantityMax()
213  {
214  return m_FertilizerUsage;
215  }
216 
217  void SetFertilizerQuantity(float fertility)
218  {
219  m_FertilizerQuantity = fertility;
220  }
221 
222  string GetFertilityType()
223  {
224  return m_FertilizerType;
225  }
226 
227  void SetFertilityType(string type)
228  {
229  m_FertilizerType = type;
230  }
231 
232  int GetFertilityState()
233  {
234  return m_FertilityState;
235  }
236 
237  void SetFertilityState( int newState )
238  {
239  m_FertilityState = newState;
240  }
241 
242  int GetWateredState()
243  {
244  return m_WateredState;
245  }
246 
247  void SetWateredState( int newState )
248  {
249  m_WateredState = newState;
250  if ( m_WateredState == eWateredState.WET )
251  SetWater( GetWaterMax() );
252  }
253 
254  float GetWaterUsage()
255  {
256  return m_WaterNeeded;
257  }
258 
259  float GetWaterMax()
260  {
261  return m_WaterMax;
262  }
263 
264  int GetState()
265  {
266  return m_State;
267  }
268 
269  void SetState(int new_state)
270  {
271  m_State = new_state;
272  }
273 
274  bool IsDigged()
275  {
276  if (m_State == STATE_DIGGED)
277  {
278  return true;
279  }
280 
281  return false;
282  }
283  bool IsPlanted()
284  {
285  if (m_State == STATE_PLANTED)
286  {
287  return true;
288  }
289 
290  return false;
291  }
292 
293  void Init( float base_fertility )
294  {
295  m_Fertility = base_fertility;
296  m_FertilizerUsage = 200;
297  m_FertilizerQuantity = 0.0;
298  m_FertilizerType = "";
299  m_FertilityState = eFertlityState.NONE;
300 
301  m_WaterQuantity = 0;
302  m_WateredState = eWateredState.DRY;
303 
304  m_HarvestingEfficiency = 1.0;
305  //m_DiggedSlotComponent = "";
306  m_State = STATE_DIGGED;
307  m_Plant = NULL;
308  }
309 
310  void SetSlotComponent(string component)
311  {
312  m_DiggedSlotComponent = component;
313  }
314 
315  string GetSlotComponent()
316  {
317  return m_DiggedSlotComponent;
318  }
319 
320  bool OnStoreLoadCustom( ParamsReadContext ctx, int version )
321  {
322  if ( version < 102 )
323  {
324  ctx.Read( m_Fertility );
325  ctx.Read( m_FertilizerUsage );
326  ctx.Read( m_FertilizerQuantity );
327 
328  if ( !ctx.Read( m_FertilizerType ) )
329  m_FertilizerType = "";
330 
331  ctx.Read( m_HarvestingEfficiency );
332  ctx.Read( m_State );
333  }
334 
335  if ( version >= 102 )
336  {
337  ctx.Read( m_Fertility );
338  ctx.Read( m_FertilizerUsage );
339  ctx.Read( m_FertilizerQuantity );
340  ctx.Read( m_HarvestingEfficiency );
341  ctx.Read( m_State );
342 
343  if ( !ctx.Read( m_FertilizerType ) )
344  {
345  m_FertilizerType = "";
346  }
347  }
348 
349  return true;
350  }
351 
352  void OnStoreSaveCustom( ParamsWriteContext ctx )
353  {
354  ctx.Write( m_Fertility );
355  ctx.Write( m_FertilizerUsage );
356  ctx.Write( m_FertilizerQuantity );
357  ctx.Write( m_HarvestingEfficiency );
358  ctx.Write( m_State );
359  ctx.Write( m_FertilizerType );
360  }
361 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
NONE
@ NONE
Definition: slot.c:3
GetState
proto native int GetState()
returns one of STATE_...
Definition: staminahandler.c:29
DRY
enum eFertlityState DRY
eFertlityState
eFertlityState
Definition: slot.c:1
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
WET
@ WET
Definition: entityai.c:5
FERTILIZED
@ FERTILIZED
Definition: slot.c:4
SetState
void SetState(bool state)
Definition: staminahandler.c:30
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
Math
Definition: enmath.c:6
GardenBase
Definition: gardenplot.c:1
m_State
protected float m_DrainThreshold protected bool m_State
Definition: staminahandler.c:20