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;
9 private float m_SprayUsage;
11 private float m_InfestationChance;
13 private int m_GrowthStagesCount;
14 private int m_CropsCount;
15 private bool m_HasCrops;
16 private string m_CropsType;
17 private float m_PlantMaterialMultiplier;
19 private int m_PlantState;
20 private int m_PlantStateIndex;
21 private float m_CurrentPlantMaterialQuantity;
23 private bool m_IsInfested;
24 private float m_SprayQuantity;
25 bool m_MarkForDeletion =
false;
27 int m_DeleteDryPlantTime;
28 int m_SpoiledRemoveTime;
29 int m_FullMaturityTime;
30 int m_SpoilAfterFullMaturityTime;
31 int m_StateChangeTime;
33 ref
Timer m_GrowthTimer = NULL;
34 ref
Timer m_InfestationTimer = NULL;
35 ref
Timer m_SpoilAfterFullMaturityTimer = NULL;
36 ref
Timer m_SpoiledRemoveTimer = NULL;
37 ref
Timer m_DeleteDryPlantTimer = NULL;
40 private ref Slot m_Slot = NULL;
42 private PluginHorticulture m_ModuleHorticulture;
44 private const float SPOIL_AFTER_MATURITY_TIME = 14400;
48 m_ModuleHorticulture = PluginHorticulture.Cast(
GetPlugin( PluginHorticulture ) );
51 m_DeleteDryPlantTime = (60 * 10) +
Math.RandomInt(0, 60 * 2);
52 m_SpoiledRemoveTime = (60 * 20) +
Math.RandomInt(0, 60 * 5);
55 m_InfestationChance = 0.2;
57 string plant_type = this.
GetType();
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)
84 void Init(
GardenBase garden_base,
float fertility,
float harvesting_efficiency,
float water )
86 m_GardenBase = garden_base;
88 m_FullMaturityTime +=
Math.RandomInt(-60,180);
89 float divided = m_FullMaturityTime;
92 m_SpoilAfterFullMaturityTime = SPOIL_AFTER_MATURITY_TIME;
94 divided = (
float)((
float)m_FullMaturityTime / ((
float)m_GrowthStagesCount - 2.0));
95 m_StateChangeTime = divided;
97 float count = m_CropsCount * fertility * harvesting_efficiency;
98 m_CropsCount = (
int)
Math.Ceil( count );
100 m_PlantMaterialMultiplier = 0.1 * harvesting_efficiency;
102 float rain_intensity =
GetGame().GetWeather().GetRain().GetActual();
103 if ( rain_intensity > 0.0 )
113 SetPlantState(STATE_DRY);
118 m_DeleteDryPlantTimer.Run( m_DeleteDryPlantTime,
this,
"DeleteDryPlantTick", NULL,
false );
127 if ( !super.OnStoreLoad( ctx, version ) )
136 ctx.Read( slot_index );
140 Slot slot = garden.GetSlotByIndex(slot_index);
145 if ( !OnStoreLoadCustom( ctx, version ) )
153 super.OnStoreSave( ctx );
155 Slot slot = GetSlot();
159 int slot_index = slot.GetSlotIndex();
162 ctx.Write( slot_index );
164 OnStoreSaveCustom( ctx );
169 Print(
"Warning! A plant existed without a garden. Therefore it was deleted from the world to prevent issues!");
173 string GetCropsType()
182 if ( !ctx.Read( loadInt ) )
185 m_SprayUsage = loadInt;
188 if ( !ctx.Read( loadInt ) )
191 m_DeleteDryPlantTime = loadInt;
194 if ( !ctx.Read( loadInt ) )
196 m_SpoiledRemoveTime = loadInt;
199 if ( !ctx.Read( loadInt ) )
201 m_FullMaturityTime = loadInt;
204 if ( !ctx.Read( loadInt ) )
206 m_SpoilAfterFullMaturityTime = loadInt;
209 if ( !ctx.Read( loadInt ) )
211 m_StateChangeTime = loadInt;
213 float loadFloat = 0.0;
214 if ( !ctx.Read( loadFloat ) )
216 m_InfestationChance = loadFloat;
219 if ( !ctx.Read( loadInt ) )
221 m_GrowthStagesCount = loadInt;
224 if ( !ctx.Read( loadInt ) )
226 m_CropsCount = loadInt;
228 string loadString =
"";
229 if ( !ctx.Read( loadString ) )
231 m_CropsType = loadString;
234 if ( !ctx.Read( loadFloat ) )
236 m_PlantMaterialMultiplier = loadFloat;
239 if ( !ctx.Read( loadInt ) )
241 m_PlantState = loadInt;
244 if ( !ctx.Read( loadInt ) )
246 m_PlantStateIndex = loadInt;
249 if ( !ctx.Read( loadFloat ) )
251 m_CurrentPlantMaterialQuantity = loadFloat;
253 bool loadBool =
false;
254 if ( !ctx.Read( loadBool ) )
256 m_IsInfested = loadBool;
259 if ( !ctx.Read( loadFloat ) )
261 m_SprayQuantity = loadFloat;
266 if ( ctx.Read( loadBool ) )
273 m_GrowthTimer.Run( m_StateChangeTime,
this,
"GrowthTimerTick", NULL,
true );
283 if ( ctx.Read( loadFloat ) )
285 if ( loadFloat > 0.0 )
290 m_InfestationTimer.Run( loadFloat,
this,
"InfestationTimerTick", NULL,
false );
300 if ( ctx.Read( loadFloat ) )
302 if ( loadFloat > 0.0 )
307 m_SpoilAfterFullMaturityTimer.Run( loadFloat,
this,
"SetSpoiled", NULL,
false );
317 if ( ctx.Read( loadFloat ) )
319 if ( loadFloat > 0.0 )
323 if (!m_SpoiledRemoveTimer)
326 m_SpoiledRemoveTimer.Run( loadFloat,
this,
"SpoiledRemoveTimerTick", NULL,
false );
336 if ( ctx.Read( loadFloat ) )
338 if ( loadFloat > 0.0 )
343 m_DeleteDryPlantTimer.Run( loadFloat,
this,
"DeleteDryPlantTick", NULL,
false );
359 ctx.Write( m_SprayUsage );
361 ctx.Write( m_DeleteDryPlantTime );
363 ctx.Write( m_SpoiledRemoveTime );
365 ctx.Write( m_FullMaturityTime );
367 ctx.Write( m_SpoilAfterFullMaturityTime );
369 ctx.Write( m_StateChangeTime );
371 ctx.Write( m_InfestationChance );
373 ctx.Write( m_GrowthStagesCount );
375 ctx.Write( m_CropsCount );
377 ctx.Write( m_CropsType );
379 ctx.Write( m_PlantMaterialMultiplier );
381 ctx.Write( m_PlantState );
383 ctx.Write( m_PlantStateIndex );
385 ctx.Write( m_CurrentPlantMaterialQuantity );
387 ctx.Write( m_IsInfested );
389 ctx.Write( m_SprayQuantity );
391 bool saveBool =
false;
392 if ( m_GrowthTimer != NULL )
396 ctx.Write( saveBool );
398 float saveFloat = 0.0;
399 if ( m_InfestationTimer != NULL )
401 saveFloat = m_InfestationTimer.GetRemaining();
403 ctx.Write( saveFloat );
406 if ( m_SpoilAfterFullMaturityTimer != NULL )
408 saveFloat = m_SpoilAfterFullMaturityTimer.GetRemaining();
410 ctx.Write( saveFloat );
413 if ( m_SpoiledRemoveTimer != NULL )
415 saveFloat = m_SpoiledRemoveTimer.GetRemaining();
417 ctx.Write( saveFloat );
420 if ( m_DeleteDryPlantTimer != NULL )
422 saveFloat = m_DeleteDryPlantTimer.GetRemaining();
424 ctx.Write( saveFloat );
429 Print(
"PRINT ALL VALUES OF PLANT...");
434 Print(m_PlantStateIndex);
435 Print(m_CurrentPlantMaterialQuantity);
437 Print(m_SprayQuantity);
440 Print(
"----------------------------------------------------------");
445 return super.CanPutInCargo(parent);
450 return super.CanPutIntoHands(parent);
458 void ChangeInfestation(
bool is_infested )
460 m_IsInfested = is_infested;
467 if ( material.m_InfestedTex !=
"" )
469 SetObjectTexture( 0, material.m_InfestedTex );
471 if ( material.m_InfestedMat !=
"" )
473 SetObjectMaterial( 0, material.m_InfestedMat );
478 if ( material.m_HealthyTex !=
"" )
480 SetObjectTexture( 0, material.m_HealthyTex );
482 if ( material.m_HealthyMat !=
"" )
484 SetObjectMaterial( 0, material.m_HealthyMat );
491 if ( m_PlantStateIndex > 0 )
493 string plant_state_index = m_PlantStateIndex.ToStringLen(2);
494 string prev_plant_state_index = ( m_PlantStateIndex - 1 ).
ToStringLen( 2 );
497 ShowSelection(
"plantStage_" + plant_state_index );
498 HideSelection(
"plantStage_" + prev_plant_state_index );
504 ShowSelection(
"plantStage_" + plant_state_index +
"_crops" );
505 HideSelection(
"plantStage_" + prev_plant_state_index +
"_crops" );
509 HideSelection(
"plantStage_" + plant_state_index +
"_crops" );
510 HideSelection(
"plantStage_" + prev_plant_state_index +
"_crops" );
514 ShowSelection(
"plantStage_" + plant_state_index +
"_shadow" );
515 HideSelection(
"plantStage_" + prev_plant_state_index +
"_shadow" );
518 float float_plant_state_index = (
float)m_PlantStateIndex;
519 m_CurrentPlantMaterialQuantity = m_PlantMaterialMultiplier * float_plant_state_index;
522 void GrowthTimerTick()
526 if ( m_PlantStateIndex < m_GrowthStagesCount - 2 )
532 if ( m_PlantStateIndex == 0 )
534 float infestation_time_min = (
float)m_FullMaturityTime * 0.2;
535 int int_infestation_time_min = (
int)infestation_time_min;
537 float infestation_time_max = (
float)m_FullMaturityTime * 0.6;
538 int int_infestation_time_max = (
int)infestation_time_max;
542 if (!m_InfestationTimer)
545 m_InfestationTimer.Run(
Math.RandomInt(int_infestation_time_min, int_infestation_time_max),
this,
"InfestationTimerTick", NULL,
false );
549 if ( m_PlantStateIndex == m_GrowthStagesCount - 2 )
557 SetPlantState(STATE_MATURE);
562 else if ( IsMature() )
566 if (!m_SpoilAfterFullMaturityTimer)
569 if ( !m_SpoilAfterFullMaturityTimer.IsRunning() )
570 m_SpoilAfterFullMaturityTimer.Run( m_SpoilAfterFullMaturityTime,
this,
"SetSpoiled", NULL,
false );
575 void InfestationTimerTick()
577 float infestation_rnd =
Math.RandomFloat01();
579 if ( m_InfestationChance > infestation_rnd )
581 ChangeInfestation(
true );
585 void SpoiledRemoveTimerTick()
587 if ( m_GrowthTimer != NULL )
589 m_GrowthTimer.Stop();
595 void DeleteDryPlantTick()
605 if ( IsSpoiled() ==
false )
608 SetPlantState(STATE_SPOILED);
614 if (!m_SpoiledRemoveTimer)
617 if (!m_SpoiledRemoveTimer.IsRunning())
618 m_SpoiledRemoveTimer.Run( m_SpoiledRemoveTime,
this,
"SpoiledRemoveTimerTick", NULL,
false );
625 if ( !IsMature() && !NeedsWater() )
627 if ( m_DeleteDryPlantTimer )
629 m_DeleteDryPlantTimer.Stop();
632 SetPlantState(STATE_GROWING);
637 m_GrowthTimer.Run( m_StateChangeTime,
this,
"GrowthTimerTick", NULL,
true );
643 void SprayPlant(
float consumed_quantity )
646 m_SprayQuantity += consumed_quantity;
648 if ( !NeedsSpraying() )
650 if ( m_InfestationTimer != NULL )
652 m_InfestationTimer.Stop();
655 m_IsInfested =
false;
656 m_InfestationChance = 0;
658 ChangeInfestation(
false );
664 string StopInfestation(
float consumed_quantity )
666 m_SprayQuantity += consumed_quantity;
668 if ( !NeedsSpraying() )
670 if ( m_InfestationTimer != NULL )
672 m_InfestationTimer.Stop();
675 m_IsInfested =
false;
676 m_InfestationChance = 0;
678 ChangeInfestation(
false );
681 return "I've sprayed the plant a bit. Now it is enough spayed.";
685 return "I've sprayed the plant a bit.";
696 if ( m_CurrentPlantMaterialQuantity > 0.0 )
700 item.SetQuantity( m_CurrentPlantMaterialQuantity * 1000.0 );
707 void RemovePlantEx(
vector pos )
713 if ( m_CurrentPlantMaterialQuantity > 0.0 )
716 item.SetQuantity( m_CurrentPlantMaterialQuantity * 1000.0 );
743 for (
int i = 0; i < m_CropsCount; i++ )
745 vector pos = player.GetPosition();
747 item.SetQuantity( item.GetQuantityMax() );
756 void SetPlantState(
int state)
758 m_PlantState = state;
767 int GetPlantStateIndex()
769 return m_PlantStateIndex;
775 return GetSlot().GetWater();
783 return GetSlot().GetWaterUsage();
790 Slot slotPlant = m_Slot;
792 if ( IsDry() && slotPlant && slotPlant.GetWater() < slotPlant.GetWaterUsage() )
804 if ( m_SprayQuantity < m_SprayUsage )
814 float GetSprayQuantity()
816 return m_SprayQuantity;
819 float GetSprayUsage()
830 if (m_SpoiledRemoveTimer)
832 m_SpoiledRemoveTimer.Stop();
833 m_SpoiledRemoveTimer = NULL;
836 garden.RemoveSlotPlant(
this );
840 void SetSlot(Slot slot)
860 if ( GetPlantState() == STATE_DRY )
872 if ( GetPlantState() == STATE_GROWING )
885 if ( GetPlantState() == STATE_MATURE )
897 if ( GetPlantState() == STATE_SPOILED )