4 static const int STATE_DRY = 0;
5 static const int STATE_GROWING = 1;
6 static const int STATE_MATURE = 2;
7 static const int STATE_SPOILED = 3;
25 bool m_MarkForDeletion =
false;
44 private const float SPOIL_AFTER_MATURITY_TIME = 14400;
48 m_ModuleHorticulture = PluginHorticulture.Cast(
GetPlugin(PluginHorticulture));
55 m_InfestationChance = 0.2;
58 m_GrowthStagesCount =
GetGame().ConfigGetInt(
"cfgVehicles " +
plant_type +
" Horticulture GrowthStagesCount");
59 m_CropsCount =
GetGame().ConfigGetInt(
"cfgVehicles " +
plant_type +
" Horticulture CropsCount");
60 GetGame().ConfigGetText(
"cfgVehicles " +
plant_type +
" Horticulture CropsType", m_CropsType);
62 m_PlantStateIndex = -1;
63 m_CurrentPlantMaterialQuantity = 0;
65 m_SprayQuantity = 0.0;
71 RegisterNetSyncVariableBool(
"m_HasCrops");
72 RegisterNetSyncVariableInt(
"m_PlantState");
73 RegisterNetSyncVariableInt(
"m_PlantStateIndex");
78 if (!m_MarkForDeletion)
87 float divided = m_FullMaturityTime;
90 m_SpoilAfterFullMaturityTime = SPOIL_AFTER_MATURITY_TIME;
92 divided = (
float)((
float)m_FullMaturityTime / ((
float)m_GrowthStagesCount - 2.0));
109 SetPlantState(STATE_DRY);
114 m_DeleteDryPlantTimer.Run(m_DeleteDryPlantTime,
this,
"DeleteDryPlantTick",
NULL,
false);
123 if (!
super.OnStoreLoad(
ctx, version))
141 if (!OnStoreLoadCustom(
ctx, version))
151 Slot slot = GetSlot();
160 OnStoreSaveCustom(
ctx);
165 Print(
"Warning! A plant existed without a garden. Therefore it was deleted from the world to prevent issues!");
187 m_DeleteDryPlantTime =
loadInt;
202 m_SpoilAfterFullMaturityTime =
loadInt;
247 m_CurrentPlantMaterialQuantity =
loadFloat;
268 m_GrowthTimer.Run(m_StateChangeTime,
this,
"GrowthTimerTick",
NULL,
true);
283 m_InfestationTimer.Run(
loadFloat,
this,
"InfestationTimerTick",
NULL,
false);
298 m_SpoilAfterFullMaturityTimer.Run(
loadFloat,
this,
"SetSpoiled",
NULL,
false);
312 if (!m_SpoiledRemoveTimer)
315 m_SpoiledRemoveTimer.Run(
loadFloat,
this,
"SpoiledRemoveTimerTick",
NULL,
false);
330 m_DeleteDryPlantTimer.Run(
loadFloat,
this,
"DeleteDryPlantTick",
NULL,
false);
344 ctx.Write(m_SprayUsage);
346 ctx.Write(m_DeleteDryPlantTime);
348 ctx.Write(m_SpoiledRemoveTime);
350 ctx.Write(m_FullMaturityTime);
352 ctx.Write(m_SpoilAfterFullMaturityTime);
354 ctx.Write(m_StateChangeTime);
356 ctx.Write(m_InfestationChance);
358 ctx.Write(m_GrowthStagesCount);
360 ctx.Write(m_CropsCount);
362 ctx.Write(m_CropsType);
364 ctx.Write(m_PlantMaterialMultiplier);
366 ctx.Write(m_PlantState);
368 ctx.Write(m_PlantStateIndex);
370 ctx.Write(m_CurrentPlantMaterialQuantity);
372 ctx.Write(m_IsInfested);
374 ctx.Write(m_SprayQuantity);
377 if (m_GrowthTimer !=
NULL)
382 if (m_InfestationTimer !=
NULL)
383 saveFloat = m_InfestationTimer.GetRemaining();
387 if (m_SpoilAfterFullMaturityTimer !=
NULL)
388 saveFloat = m_SpoilAfterFullMaturityTimer.GetRemaining();
392 if (m_SpoiledRemoveTimer !=
NULL)
393 saveFloat = m_SpoiledRemoveTimer.GetRemaining();
397 if (m_DeleteDryPlantTimer !=
NULL)
398 saveFloat = m_DeleteDryPlantTimer.GetRemaining();
404 Print(
"PRINT ALL VALUES OF PLANT...");
409 Print(m_PlantStateIndex);
410 Print(m_CurrentPlantMaterialQuantity);
412 Print(m_SprayQuantity);
415 Print(
"----------------------------------------------------------");
420 return super.CanPutInCargo(parent);
425 return super.CanPutIntoHands(parent);
443 SetObjectTexture(0,
material.m_InfestedTex);
445 SetObjectMaterial(0,
material.m_InfestedMat);
450 SetObjectTexture(0,
material.m_HealthyTex);
452 SetObjectMaterial(0,
material.m_HealthyMat);
458 if (m_PlantStateIndex > 0)
493 if (m_PlantStateIndex < m_GrowthStagesCount - 2)
499 if (m_PlantStateIndex == 0)
509 if (!m_InfestationTimer)
516 if (m_PlantStateIndex == m_GrowthStagesCount - 2)
521 SetPlantState(STATE_MATURE);
529 if (!m_SpoilAfterFullMaturityTimer)
532 if (!m_SpoilAfterFullMaturityTimer.IsRunning())
533 m_SpoilAfterFullMaturityTimer.Run(m_SpoilAfterFullMaturityTime,
this,
"SetSpoiled",
NULL,
false);
543 ChangeInfestation(
true);
548 if (m_GrowthTimer !=
NULL)
549 m_GrowthTimer.Stop();
564 if (IsSpoiled() ==
false)
567 SetPlantState(STATE_SPOILED);
573 if (!m_SpoiledRemoveTimer)
576 if (!m_SpoiledRemoveTimer.IsRunning())
577 m_SpoiledRemoveTimer.Run(m_SpoiledRemoveTime,
this,
"SpoiledRemoveTimerTick",
NULL,
false);
584 if (!IsMature() && !NeedsWater())
586 if (m_DeleteDryPlantTimer)
587 m_DeleteDryPlantTimer.Stop();
589 SetPlantState(STATE_GROWING);
594 m_GrowthTimer.Run(m_StateChangeTime,
this,
"GrowthTimerTick",
NULL,
true);
605 if (!NeedsSpraying())
607 if (m_InfestationTimer !=
NULL)
608 m_InfestationTimer.Stop();
610 m_IsInfested =
false;
611 m_InfestationChance = 0;
613 ChangeInfestation(
false);
623 if (!NeedsSpraying())
625 if (m_InfestationTimer !=
NULL)
626 m_InfestationTimer.Stop();
628 m_IsInfested =
false;
629 m_InfestationChance = 0;
631 ChangeInfestation(
false);
634 return "I've sprayed the plant a bit. Now it is enough spayed.";
637 return "I've sprayed the plant a bit.";
647 if (m_CurrentPlantMaterialQuantity > 0.0)
651 item.SetQuantity(m_CurrentPlantMaterialQuantity * 1000.0);
664 if (m_CurrentPlantMaterialQuantity > 0.0)
667 item.SetQuantity(m_CurrentPlantMaterialQuantity * 1000.0);
694 for (
int i = 0;
i < m_CropsCount;
i++)
698 item.SetQuantity(
item.GetQuantityMax());
709 m_PlantState =
state;
720 return m_PlantStateIndex;
726 return GetSlot().GetWater();
734 return GetSlot().GetWaterUsage();
751 if (m_SprayQuantity < m_SprayUsage)
759 return m_SprayQuantity;
773 if (m_SpoiledRemoveTimer)
775 m_SpoiledRemoveTimer.Stop();
776 m_SpoiledRemoveTimer =
NULL;
779 garden.RemoveSlotPlant(
this);
801 if (GetPlantState() == STATE_DRY)
809 if (GetPlantState() == STATE_GROWING)
818 if (GetPlantState() == STATE_MATURE)
826 if (GetPlantState() == STATE_SPOILED)
eBleedingSourceType GetType()
void AddAction(typename actionName)
const int ECE_PLACE_ON_SURFACE
string ToStringLen(int len)
Integer to string with fixed length, padded with zeroes.
override void SetTakeable(bool pState)
void UnlockFromParent()
Unlocks this item from its attachment slot of its parent.
PluginBase GetPlugin(typename plugin_type)
class JsonUndergroundAreaTriggerData GetPosition
override bool CanPutIntoHands(EntityAI player)
void SprayPlant(float consumed_quantity)
float m_CurrentPlantMaterialQuantity
override bool OnStoreLoad(ParamsReadContext ctx, int version)
void ChangeInfestation(bool is_infested)
override bool CanRemoveFromHands(EntityAI player)
override void SetActions()
void Init(GardenBase garden_base, float fertility, float harvesting_efficiency, float water)
float m_InfestationChance
override void OnStoreSave(ParamsWriteContext ctx)
int m_SpoilAfterFullMaturityTime
void InfestationTimerTick()
void SpoiledRemoveTimerTick()
void Harvest(PlayerBase player)
void DeleteDryPlantTick()
string StopInfestation(float consumed_quantity)
override bool CanPutInCargo(EntityAI parent)
bool OnStoreLoadCustom(ParamsReadContext ctx, int version)
void RemovePlantEx(vector pos)
void OnStoreSaveCustom(ParamsWriteContext ctx)
PluginHorticulture m_ModuleHorticulture
float m_PlantMaterialMultiplier
void SetPlantState(int state)
Serialization general interface. Serializer API works with:
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static proto float Ceil(float f)
Returns ceil of value.