DayZ
1.24
Loading...
Searching...
No Matches
Slot.c
Go to the documentation of this file.
1
enum
eFertlityState
2
{
3
NONE
= 0,
4
FERTILIZED
= 1
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
GetGame
().ObjectDelete(
GetPlant
());
56
}
57
58
int
GetSlotIndex
()
59
{
60
return
m_slotIndex
;
61
}
62
63
void
SetSlotIndex
(
int
index
)
64
{
65
m_slotIndex
=
index
;
66
}
67
68
int
GetSlotId()
69
{
70
return
m_slotId
;
71
}
72
73
void
SetSlotId(
int
id
)
74
{
75
m_slotId
=
id
;
76
}
77
78
void
SetGarden
(
GardenBase
garden
)
79
{
80
m_Garden
=
garden
;
81
}
82
83
GardenBase
GetGarden()
84
{
85
return
m_Garden
;
86
}
87
88
void
SetSeed
(
ItemBase
seed
)
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
);
110
m_WaterQuantity
=
val
;
111
}
112
113
ItemBase
GetSeed
()
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();
129
m_WaterQuantity
+=
consumed_quantity
;
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
{
150
SetWateredState
(
eWateredState
.WET);
151
GetGarden().UpdateSlotTexture(
GetSlotIndex
());
152
if
(
m_Garden
.GetSlotWateredState() !=
m_Garden
.GetMaxWaterStateVal())
153
m_Garden
.SlotWaterStateUpdate(
this
);
154
}
155
}
156
157
bool
NeedsWater()
158
{
159
if
(
m_WaterQuantity
<
GetWaterUsage
())
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
{
190
m_Fertility
=
fertility
;
191
}
192
193
float
GetFertilizerQuantity
()
194
{
195
return
m_FertilizerQuantity
;
196
}
197
198
float
GetFertilizerQuantityMax
()
199
{
200
return
m_FertilizerUsage
;
201
}
202
203
void
SetFertilizerQuantity
(
float
fertility
)
204
{
205
m_FertilizerQuantity
=
fertility
;
206
}
207
208
string
GetFertilityType
()
209
{
210
return
m_FertilizerType
;
211
}
212
213
void
SetFertilityType
(
string
type)
214
{
215
m_FertilizerType
= type;
216
}
217
218
int
GetFertilityState
()
219
{
220
return
m_FertilityState
;
221
}
222
223
void
SetFertilityState
(
int
newState
)
224
{
225
m_FertilityState
=
newState
;
226
}
227
228
int
GetWateredState
()
229
{
230
return
m_WateredState
;
231
}
232
233
void
SetWateredState
(
int
newState
)
234
{
235
m_WateredState
=
newState
;
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
{
257
m_State
=
new_state
;
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
{
277
m_Fertility
=
base_fertility
;
278
m_FertilizerUsage
= 200;
279
m_FertilizerQuantity
= 0.0;
280
m_FertilizerType
=
""
;
281
m_FertilityState
=
eFertlityState
.NONE;
282
283
m_WaterQuantity
= 0;
284
m_WateredState
=
eWateredState
.DRY;
285
286
m_HarvestingEfficiency
= 1.0;
287
//m_DiggedSlotComponent = "";
288
m_State
=
STATE_DIGGED
;
289
m_Plant =
NULL
;
290
}
291
292
void
SetSlotComponent
(
string
component
)
293
{
294
m_DiggedSlotComponent
=
component
;
295
}
296
297
string
GetSlotComponent
()
298
{
299
return
m_DiggedSlotComponent
;
300
}
301
302
bool
OnStoreLoadCustom(
ParamsReadContext
ctx
,
int
version)
303
{
304
if
(version < 102)
305
{
306
ctx
.Read(
m_Fertility
);
307
ctx
.Read(
m_FertilizerUsage
);
308
ctx
.Read(
m_FertilizerQuantity
);
309
310
if
(!
ctx
.Read(
m_FertilizerType
))
311
m_FertilizerType
=
""
;
312
313
ctx
.Read(
m_HarvestingEfficiency
);
314
ctx
.Read(
m_State
);
315
}
316
317
if
(version >= 102)
318
{
319
ctx
.Read(
m_Fertility
);
320
ctx
.Read(
m_FertilizerUsage
);
321
ctx
.Read(
m_FertilizerQuantity
);
322
ctx
.Read(
m_HarvestingEfficiency
);
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
);
336
ctx
.Write(
m_FertilizerQuantity
);
337
ctx
.Write(
m_HarvestingEfficiency
);
338
ctx
.Write(
m_State
);
339
ctx
.Write(
m_FertilizerType
);
340
}
341
}
WET
@ WET
Definition
EntityAI.c:5
Init
override Widget Init()
Definition
DayZGame.c:120
component
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
DRY
enum eFertlityState DRY
eFertlityState
eFertlityState
Definition
Slot.c:2
FERTILIZED
@ FERTILIZED
Definition
Slot.c:4
NONE
@ NONE
Definition
Slot.c:3
SetState
void SetState(bool state)
Definition
StaminaHandler.c:30
m_State
bool m_State
Definition
StaminaHandler.c:20
GardenBase
Definition
GardenPlot.c:2
ItemBase
Definition
InventoryItem.c:697
Math
Definition
EnMath.c:7
Param3
Definition
EntityAI.c:95
Serializer
Serialization general interface. Serializer API works with:
Definition
Serializer.c:56
GetGame
proto native CGame GetGame()
Math::Clamp
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'.
GetState
proto native int GetState()
returns one of STATE_...
Definition
StaminaHandler.c:29
scripts
4_World
Entities
GardenBase
Slot.c
Generated by
1.10.0