14 private float m_InfestationChance;
16 private int m_GrowthStagesCount;
17 private int m_CropsCount;
18 private bool m_HasCrops;
19 private string m_CropsType;
20 private float m_PlantMaterialMultiplier;
22 private int m_PlantStateIndex;
23 private float m_CurrentPlantMaterialQuantity;
26 private bool m_IsInfested;
27 private float m_SprayQuantity;
28 bool m_MarkForDeletion =
false;
30 int m_DeleteDryPlantTime;
31 int m_SpoiledRemoveTime;
32 int m_FullMaturityTime;
33 int m_SpoilAfterFullMaturityTime;
34 float m_StateChangeTime;
40 private ref Slot m_Slot = NULL;
42 private PluginHorticulture m_ModuleHorticulture;
44 private const float SPOIL_AFTER_MATURITY_TIME = 14400.0;
45 private const int TICK_FREQUENCY = 1;
48 static int m_DebugFullMaturityTime;
49 static int m_DebugSpoilTime;
50 static int m_DebugSpoilRemoveTime;
51 static int m_DebugDeleteDryTime;
52 static float m_DebugTickSpeedMultiplier = 1;
56 m_ModuleHorticulture = PluginHorticulture.Cast(
GetPlugin( PluginHorticulture ) );
59 m_DeleteDryPlantTime = (60 * 10) +
Math.RandomInt(0, 60 * 2);
60 m_SpoiledRemoveTime = (60 * 20) +
Math.RandomInt(0, 60 * 5);
62 string plant_type = this.
GetType();
63 m_GrowthStagesCount =
GetGame().ConfigGetInt(
"cfgVehicles " + plant_type +
" Horticulture GrowthStagesCount" );
64 m_CropsCount =
GetGame().ConfigGetInt(
"cfgVehicles " + plant_type +
" Horticulture CropsCount" );
65 GetGame().ConfigGetText(
"cfgVehicles " + plant_type +
" Horticulture CropsType", m_CropsType );
67 if (m_GrowthStagesCount == 0)
68 m_GrowthStagesCount = 1;
70 m_InfestationChance = 0.2 / m_GrowthStagesCount;
72 m_PlantStateIndex = -1;
73 m_CurrentPlantMaterialQuantity = 0;
75 m_SprayQuantity = 0.0;
80 RegisterNetSyncVariableBool(
"m_HasCrops");
81 RegisterNetSyncVariableInt(
"m_PlantState");
82 RegisterNetSyncVariableInt(
"m_PlantStateIndex");
87 m_TimeTicker.Run(TICK_FREQUENCY,
this,
"Tick", NULL,
true);
102 void Init(
GardenBase garden_base,
float fertility,
float harvesting_efficiency,
float water )
104 m_GardenBase = garden_base;
106 if (m_DebugFullMaturityTime != 0)
107 m_FullMaturityTime = m_DebugFullMaturityTime;
109 m_FullMaturityTime +=
Math.RandomInt(-60,180);
111 if (m_DebugSpoilTime != 0)
112 m_SpoilAfterFullMaturityTime = m_DebugSpoilTime;
114 m_SpoilAfterFullMaturityTime = SPOIL_AFTER_MATURITY_TIME;
116 if (m_DebugSpoilRemoveTime != 0)
117 m_SpoiledRemoveTime = m_DebugSpoilRemoveTime;
119 if (m_DebugDeleteDryTime != 0)
120 m_DeleteDryPlantTime = m_DebugDeleteDryTime;
122 m_StateChangeTime = m_FullMaturityTime / (m_GrowthStagesCount - 2);
124 float count = m_CropsCount * fertility * harvesting_efficiency;
125 m_CropsCount = (
int)
Math.Ceil( count );
127 m_PlantMaterialMultiplier = 0.1 * harvesting_efficiency;
137 if (rain_intensity <= 0.0)
179 if ( !super.OnStoreLoad( ctx, version ) )
185 if (!ctx.Read(slot_index))
188 Slot slot = garden.GetSlotByIndex(slot_index);
192 if ( !OnStoreLoadCustom( ctx, version ) )
200 super.OnStoreSave( ctx );
202 Slot slot = GetSlot();
206 int slot_index = slot.GetSlotIndex();
209 ctx.Write( slot_index );
211 OnStoreSaveCustom( ctx );
215 ErrorEx(
"[Warning] A plant existed without a garden. Therefore it was deleted from the world to prevent issues! Position: " +
GetPosition(),
ErrorExSeverity.INFO);
220 string GetCropsType()
230 if (!ctx.Read(m_DeleteDryPlantTime))
233 if (!ctx.Read(m_SpoiledRemoveTime))
236 if (!ctx.Read(m_FullMaturityTime))
239 if (!ctx.Read(m_SpoilAfterFullMaturityTime))
242 if (!ctx.Read(m_StateChangeTime))
245 if (!ctx.Read(m_InfestationChance))
248 if (!ctx.Read(m_GrowthStagesCount))
251 if (!ctx.Read(m_CropsCount))
254 if (!ctx.Read(m_CropsType))
257 if (!ctx.Read(m_PlantMaterialMultiplier))
263 if (!ctx.Read(m_PlantStateIndex))
266 if (!ctx.Read(m_CurrentPlantMaterialQuantity))
269 if (!ctx.Read(m_IsInfested))
272 if (!ctx.Read(m_SprayQuantity))
276 if (!ctx.Read(loadBool))
279 float loadFloat = 0.0;
280 if (!ctx.Read(loadFloat))
284 if (ctx.Read(loadFloat))
295 if (ctx.Read(loadFloat))
306 if (ctx.Read(loadFloat))
308 if ( loadFloat > 0.0 )
316 if (m_StateChangeTime != (m_FullMaturityTime / (m_GrowthStagesCount - 2)))
318 m_StateChangeTime = m_FullMaturityTime / (m_GrowthStagesCount - 2);
324 if (!ctx.Read(m_HasCrops))
335 ctx.Write(m_DeleteDryPlantTime);
336 ctx.Write(m_SpoiledRemoveTime);
337 ctx.Write(m_FullMaturityTime);
338 ctx.Write(m_SpoilAfterFullMaturityTime);
339 ctx.Write(m_StateChangeTime);
340 ctx.Write(m_InfestationChance);
341 ctx.Write(m_GrowthStagesCount);
342 ctx.Write(m_CropsCount);
343 ctx.Write(m_CropsType);
344 ctx.Write(m_PlantMaterialMultiplier);
346 ctx.Write(m_PlantStateIndex);
347 ctx.Write(m_CurrentPlantMaterialQuantity);
348 ctx.Write(m_IsInfested);
349 ctx.Write(m_SprayQuantity);
351 bool saveBool =
false;
352 ctx.Write( saveBool );
354 float saveFloat = 0.0;
355 ctx.Write( saveFloat );
362 ctx.Write( saveFloat );
369 ctx.Write( saveFloat );
376 ctx.Write( saveFloat );
378 ctx.Write(m_HasCrops);
383 Print(
"PRINT ALL VALUES OF PLANT...");
386 Print(m_GrowthStagesCount);
389 Print(m_PlantStateIndex);
390 Print(m_CurrentPlantMaterialQuantity);
392 Print(m_SprayQuantity);
395 Print(m_StateChangeTime);
396 Print(m_FullMaturityTime);
397 Print(m_SpoilAfterFullMaturityTime);
399 Print(
"----------------------------------------------------------");
404 return super.CanPutInCargo(parent);
409 return super.CanPutIntoHands(parent);
417 void ChangeInfestation(
bool is_infested )
419 m_IsInfested = is_infested;
426 if ( material.m_InfestedTex !=
"" )
428 SetObjectTexture( 0, material.m_InfestedTex );
430 if ( material.m_InfestedMat !=
"" )
432 SetObjectMaterial( 0, material.m_InfestedMat );
437 if ( material.m_HealthyTex !=
"" )
439 SetObjectTexture( 0, material.m_HealthyTex );
441 if ( material.m_HealthyMat !=
"" )
443 SetObjectMaterial( 0, material.m_HealthyMat );
450 if ( m_PlantStateIndex > 0 )
452 string plant_state_index = m_PlantStateIndex.ToStringLen(2);
453 string prev_plant_state_index = ( m_PlantStateIndex - 1 ).
ToStringLen( 2 );
456 ShowSelection(
"plantStage_" + plant_state_index );
457 HideSelection(
"plantStage_" + prev_plant_state_index );
463 ShowSelection(
"plantStage_" + plant_state_index +
"_crops" );
464 HideSelection(
"plantStage_" + prev_plant_state_index +
"_crops" );
468 HideSelection(
"plantStage_" + plant_state_index +
"_crops" );
469 HideSelection(
"plantStage_" + prev_plant_state_index +
"_crops" );
473 ShowSelection(
"plantStage_" + plant_state_index +
"_shadow" );
474 HideSelection(
"plantStage_" + prev_plant_state_index +
"_shadow" );
477 float float_plant_state_index = (
float)m_PlantStateIndex;
478 m_CurrentPlantMaterialQuantity = m_PlantMaterialMultiplier * float_plant_state_index;
481 void GrowthTimerTick()
485 if ( m_PlantStateIndex < m_GrowthStagesCount - 2 )
491 float infestation_rnd =
Math.RandomFloat01();
492 if ( m_InfestationChance > infestation_rnd )
493 ChangeInfestation(
true);
495 if ( m_PlantStateIndex == m_GrowthStagesCount - 2 )
526 void SprayPlant(
float consumed_quantity )
529 m_SprayQuantity += consumed_quantity;
533 m_IsInfested =
false;
534 m_InfestationChance = 0;
536 ChangeInfestation(
false );
541 void RemovePlantEx(
vector pos )
547 if ( m_CurrentPlantMaterialQuantity > 0.0 )
550 item.SetQuantity( m_CurrentPlantMaterialQuantity * 1000.0 );
571 for (
int i = 0; i < m_CropsCount; i++ )
573 vector pos = player.GetPosition();
575 item.SetQuantity( item.GetQuantityMax() );
584 m_GardenBase.SyncSlots();
587 void SetPlantState(
int state)
599 int GetPlantStateIndex()
601 return m_PlantStateIndex;
607 return GetSlot().GetWater();
615 return GetSlot().GetWaterUsage();
622 Slot slotPlant = m_Slot;
630 float GetSprayQuantity()
632 return m_SprayQuantity;
635 float GetSprayUsage()
645 garden.RemoveSlotPlant(
this );
648 void SetSlot(Slot slot)
663 m_GardenBase = gardenBase;
700 void DebugSetTimes(
int maturity,
int spoil,
int spoilRemove,
int dryDelete)
704 m_FullMaturityTime = maturity;
705 m_StateChangeTime = m_FullMaturityTime / (m_GrowthStagesCount - 2);
709 m_SpoilAfterFullMaturityTime = spoil;
711 if (spoilRemove != 0)
712 m_SpoiledRemoveTime = spoilRemove;
715 m_DeleteDryPlantTime = dryDelete;
718 static void DebugSetGlobalTimes(
int maturity,
int spoil,
int spoilRemove,
int dryDelete)
720 m_DebugFullMaturityTime = maturity;
721 m_DebugSpoilTime = spoil;
722 m_DebugSpoilRemoveTime = spoilRemove;
723 m_DebugDeleteDryTime = dryDelete;
726 static void DebugSetTickSpeedMultiplier(
float multiplier)
728 m_DebugTickSpeedMultiplier = multiplier;
732 static const int STATE_DRY = 0;
733 static const int STATE_GROWING = 1;
734 static const int STATE_MATURE = 2;
735 static const int STATE_SPOILED = 3;
737 ref
Timer m_SpoiledRemoveTimer;
738 ref
Timer m_DeleteDryPlantTimer;
739 ref
Timer m_SpoilAfterFullMaturityTimer;
740 ref
Timer m_GrowthTimer;
741 ref
Timer m_InfestationTimer;
743 void DeleteDryPlantTick();
744 void SpoiledRemoveTimerTick();
745 void InfestationTimerTick();
751 bool NeedsSpraying();
753 string StopInfestation(
float consumed_quantity )
eBleedingSourceType GetType()
void AddAction(typename actionName)
const int ECE_PLACE_ON_SURFACE
proto native Weather GetWeather()
Returns weather controller object.
Serialization general interface. Serializer API works with:
string ToStringLen(int len)
Integer to string with fixed length, padded with zeroes.
override bool CanPutInCargo(EntityAI parent)
override bool CanPutIntoHands(EntityAI parent)
override bool CanRemoveFromHands(EntityAI parent)
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
bool IsPendingDeletion()
Get whether the Effect is queued up for being cleaned up.
class JsonUndergroundAreaTriggerData GetPosition
override void SetTakeable(bool pState)
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
enum EPlantState m_SprayUsage
PluginBase GetPlugin(typename plugin_type)