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;
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;
44 private const float SPOIL_AFTER_MATURITY_TIME = 14400;
48 m_ModuleHorticulture = PluginHorticulture.Cast(
GetPlugin( PluginHorticulture ) );
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" );
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;
94 divided = (
float)((
float)m_FullMaturityTime / ((
float)m_GrowthStagesCount - 2.0));
95 m_StateChangeTime = divided;
97 float count = m_CropsCount * fertility * harvesting_efficiency;
100 m_PlantMaterialMultiplier = 0.1 * harvesting_efficiency;
103 if ( rain_intensity > 0.0 )
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);
153 super.OnStoreSave( ctx );
159 int slot_index = slot.GetSlotIndex();
162 ctx.
Write( slot_index );
169 Print(
"Warning! A plant existed without a garden. Therefore it was deleted from the world to prevent issues!");
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);
460 m_IsInfested = is_infested;
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;
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 )
566 if (!m_SpoilAfterFullMaturityTimer)
569 if ( !m_SpoilAfterFullMaturityTimer.IsRunning() )
570 m_SpoilAfterFullMaturityTimer.Run( m_SpoilAfterFullMaturityTime,
this,
"SetSpoiled", NULL,
false );
579 if ( m_InfestationChance > infestation_rnd )
587 if ( m_GrowthTimer != NULL )
589 m_GrowthTimer.Stop();
614 if (!m_SpoiledRemoveTimer)
617 if (!m_SpoiledRemoveTimer.IsRunning())
618 m_SpoiledRemoveTimer.Run( m_SpoiledRemoveTime,
this,
"SpoiledRemoveTimerTick", NULL,
false );
627 if ( m_DeleteDryPlantTimer )
629 m_DeleteDryPlantTimer.Stop();
637 m_GrowthTimer.Run( m_StateChangeTime,
this,
"GrowthTimerTick", NULL,
true );
646 m_SprayQuantity += consumed_quantity;
650 if ( m_InfestationTimer != NULL )
652 m_InfestationTimer.Stop();
655 m_IsInfested =
false;
656 m_InfestationChance = 0;
666 m_SprayQuantity += consumed_quantity;
670 if ( m_InfestationTimer != NULL )
672 m_InfestationTimer.Stop();
675 m_IsInfested =
false;
676 m_InfestationChance = 0;
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 );
713 if ( m_CurrentPlantMaterialQuantity > 0.0 )
716 item.SetQuantity( m_CurrentPlantMaterialQuantity * 1000.0 );
745 vector pos = player.GetPosition();
747 item.SetQuantity( item.GetQuantityMax() );
758 m_PlantState = state;
783 return GetSlot().GetWaterUsage();
792 if (
IsDry() && slotPlant && slotPlant.GetWater() < slotPlant.GetWaterUsage() )
804 if ( m_SprayQuantity < m_SprayUsage )
830 if (m_SpoiledRemoveTimer)
832 m_SpoiledRemoveTimer.Stop();
833 m_SpoiledRemoveTimer = NULL;
836 garden.RemoveSlotPlant(
this );
eBleedingSourceType GetType()
void AddAction(typename actionName)
class RecipeCacheData int
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
proto native void ObjectDelete(Object obj)
proto bool ConfigGetText(string path, out string value)
Get string value from config on path.
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto native bool IsServer()
proto native Weather GetWeather()
Returns weather controller object.
private float m_PlantMaterialMultiplier
void Init(GardenBase garden_base, float fertility, float harvesting_efficiency, float water)
override bool CanRemoveFromHands(EntityAI player)
private const float SPOIL_AFTER_MATURITY_TIME
void OnStoreSaveCustom(ParamsWriteContext ctx)
void InfestationTimerTick()
override void OnStoreSave(ParamsWriteContext ctx)
void SprayPlant(float consumed_quantity)
void ChangeInfestation(bool is_infested)
override bool CanPutIntoHands(EntityAI player)
override bool CanPutInCargo(EntityAI parent)
private int m_PlantStateIndex
private float m_InfestationChance
void SpoiledRemoveTimerTick()
private float m_CurrentPlantMaterialQuantity
void RemovePlantEx(vector pos)
private float m_SprayQuantity
private bool m_IsInfested
override bool OnStoreLoad(ParamsReadContext ctx, int version)
private int m_GrowthStagesCount
private GardenBase m_GardenBase
private string m_CropsType
void DeleteDryPlantTick()
bool OnStoreLoadCustom(ParamsReadContext ctx, int version)
int m_SpoilAfterFullMaturityTime
void SetPlantState(int state)
private float m_SprayUsage
void Harvest(PlayerBase player)
override void SetActions()
private PluginHorticulture m_ModuleHorticulture
string StopInfestation(float consumed_quantity)
Serialization general interface. Serializer API works with:
proto bool Write(void value_out)
proto bool Read(void value_in)
proto native Rain GetRain()
Returns a rain phenomenon object.
proto native float GetActual()
Returns actual value of phenomenon in range <0, 1>.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
static proto float Ceil(float f)
Returns ceil of value.