4 static const string SLOT_TEXTURE_DIGGED_WET_LIME =
"dz\\gear\\cultivation\\data\\soil_digged_wet_lime_CO.paa";
5 static const string SLOT_TEXTURE_DIGGED_WET_PLANT =
"dz\\gear\\cultivation\\data\\soil_digged_wet_plant_CO.paa";
8 static const string SLOT_MATERIAL_WET =
"dz\\gear\\cultivation\\data\\soil_cultivated_wet.rvmat";
9 static const string SLOT_MATERIAL_DRY =
"dz\\gear\\cultivation\\data\\soil_cultivated.rvmat";
11 static const string SLOT_MATERIAL_LIMED_WET =
"dz\\gear\\cultivation\\data\\soil_cultivated_limed_wet.rvmat";
12 static const string SLOT_MATERIAL_LIMED_DRY =
"dz\\gear\\cultivation\\data\\soil_cultivated_limed.rvmat";
13 static const string SLOT_MATERIAL_COMPOST_WET =
"dz\\gear\\cultivation\\data\\soil_cultivated_compost_wet.rvmat";
14 static const string SLOT_MATERIAL_COMPOST_DRY =
"dz\\gear\\cultivation\\data\\soil_cultivated_compost.rvmat";
17 private static const string SLOT_SELECTION_DIGGED_PREFIX =
"seedbase_";
18 private static const string SLOT_SELECTION_COVERED_PREFIX =
"slotCovered_";
19 private static const string SLOT_MEMORY_POINT_PREFIX =
"slot_";
20 private static const string SLOT_SEEDBASE_PREFIX =
"seedbase_";
23 private static const int CHECK_RAIN_INTERVAL = 15;
26 protected int m_SlotFertilityState = 0;
27 protected int m_SlotWateredState = 0;
28 protected int m_MaxWateredStateVal = 0;
29 protected float m_DefaultFertility = 1;
36 RegisterNetSyncVariableInt(
"m_SlotFertilityState");
37 RegisterNetSyncVariableInt(
"m_SlotWateredState");
47 string input = SLOT_SEEDBASE_PREFIX + i.
ToString();
48 string output = SLOT_MEMORY_POINT_PREFIX;
51 output = output +
"0";
55 m_map_slots.
Set(input, output);
65 SetMaxWaterStateVal();
70 super.OnVariablesSynchronized();
82 return EInventoryIconVisibility.HIDE_VICINITY;
87 m_DefaultFertility = value;
92 return m_DefaultFertility;
98 UpdateTexturesOnAllSlots();
106 for (
int i = 0; i < slots_count; i++ )
108 Slot slot =
new Slot(GetBaseFertility());
109 slot.SetSlotIndex(i);
111 string name =
"SeedBase_" + i1;
113 slot.SetSlotId(slot_id);
114 slot.SetGarden(
this);
115 slot.m_State = Slot.STATE_DIGGED;
116 m_Slots.Insert( slot );
124 for (
int i = 0; i < m_Slots.Count(); i++ )
129 m_MaxWateredStateVal = state;
134 return m_MaxWateredStateVal;
141 for (
int i = 0; i < slots_count; i++ )
143 UpdateSlotTexture(i);
149 if ( version <= 118 )
152 if ( !super.OnStoreLoad( ctx, version ) )
158 ctx.
Read( some_value );
163 for (
int i = 0; i < slots_count; i++ )
165 Slot slot = m_Slots.Get( i );
167 if ( !slot.OnStoreLoadCustom( ctx, version ) )
174 if ( version >= 119 )
175 ctx.
Read( m_SlotFertilityState );
177 if ( version >= 120 )
178 ctx.
Read( m_SlotWateredState );
185 super.AfterStoreLoad();
191 super.EEOnAfterLoad();
199 int fertilityState = (m_SlotFertilityState >> i) & 1;
200 m_Slots[i].SetFertilityState(fertilityState);
202 int wateredState = (m_SlotWateredState >> i) & 1;
203 m_Slots[i].SetWateredState( wateredState );
207 m_Slots[i].SetFertilityType(
"" );
208 m_Slots[i].SetFertilizerQuantity( 0 );
211 if ( wateredState == eWateredState.DRY )
213 m_Slots[i].SetWater( 0 );
216 UpdateSlotTexture( i );
227 super.OnStoreSave( ctx );
231 for (
int i = 0; i < slots_count; i++ )
233 Slot slot = m_Slots.Get( i );
235 slot.OnStoreSaveCustom( ctx );
238 ctx.
Write(m_SlotFertilityState);
240 ctx.
Write( m_SlotWateredState );
245 Debug.
Log(
"PRINT ALL SLOTS FROM...");
247 int slots = GetInventory().GetAttachmentSlotsCount();
250 for (
int i = 0; i < slots ; i++ )
252 Slot slot = m_Slots.Get(i);
256 float slot_fertility = slot.GetFertility();
257 float slot_fertility_usage = slot.GetFertilityMax();
258 string slot_fertility_type = slot.GetFertilityType();
259 float slot_water = slot.GetWater();
260 float slot_water_usage = slot.GetWaterUsage();
261 ItemBase slot_seed = slot.GetSeed();
262 ItemBase slot_plant = slot.GetPlant();
264 float slot_slot_Index = slot.GetSlotIndex();
265 float slot_slot_ID = slot.GetSlotId();
266 int slot_wateredState = slot.GetWateredState();
267 int slot_FertilityState = slot.GetFertilityState();
269 Debug.
Log(
"Fertility : " + slot_fertility);
270 Debug.
Log(
"Fertility Usage : " + slot_fertility_usage);
271 Debug.
Log(
"Fertility Type : " + slot_fertility_type);
272 Debug.
Log(
"Fertility State : " + slot_FertilityState);
274 Debug.
Log(
"Water Usage : " + slot_water_usage);
275 Debug.
Log(
"Watered State : " + slot_wateredState);
279 Debug.
Log(
"Slot Index : " + slot_slot_Index);
280 Debug.
Log(
"Slot ID : " + slot_slot_ID);
281 Debug.
Log(
"///////////////////////////");
284 Debug.
Log(
"END OF ALL SLOTS FOR...");
290 if ( !super.CanPutInCargo(parent) ) {
return false;}
296 if ( !super.CanPutIntoHands( parent ) )
315 Slot slot = GetSlotBySelection( selection_component );
317 if ( slot != NULL && slot.m_State == Slot.STATE_DIGGED )
331 if ( m_map_slots.Contains(attach_slot) )
333 string return_value = m_map_slots.
Get(attach_slot);
342 super.EEItemAttached(item, slot_name);
344 string path =
string.
Format(
"CfgVehicles %1 Horticulture PlantType", item.GetType());
351 string converted_slot_name;
354 int index = GetSlotIndexByAttachmentSlot( slot_name );
358 converted_slot_name = SLOT_MEMORY_POINT_PREFIX +
"0" + index.
ToString();
362 converted_slot_name = SLOT_MEMORY_POINT_PREFIX + index.
ToString();
365 PlantSeed(
ItemBase.Cast( item ), converted_slot_name);
367 else if (
g_Game.IsClient())
369 Slot slot = GetSlotByIndex(GetSlotIndexByAttachmentSlot( slot_name) - 1);
372 slot.SetPlant(PlantBase.Cast( item ));
373 slot.m_State = Slot.STATE_PLANTED;
380 super.EEItemDetached(item, slot_name);
384 string path =
string.
Format(
"CfgVehicles %1 Horticulture PlantType", item.GetType());
387 string converted_slot_name = ConvertAttSlotToPlantSlot(slot_name);
388 Slot slot = GetSlotBySelection(converted_slot_name);
397 slot.SetState(Slot.STATE_DIGGED);
404 int slot_index = GetSlotIndexBySelection( selection_component );
406 if ( slot_index != -1 )
408 PluginHorticulture module_horticulture = PluginHorticulture.Cast(
GetPlugin( PluginHorticulture ) );
409 string plant_type = module_horticulture.GetPlantType( seed );
411 Slot slot = m_Slots.Get( slot_index );
412 slot.SetState(Slot.STATE_PLANTED);
413 slot.m_PlantType = plant_type;
416 if ( !slot.NeedsWater() )
420 Timer growthTimer = NULL;
422 Param createPlantParam =
new Param1<Slot>(slot);
423 growthTimer.Run( 0.1,
this,
"CreatePlant", createPlantParam,
false );
434 seed.UnlockFromParent();
437 PlantBase plant = PlantBase.Cast( GetInventory().CreateAttachmentEx( slot.m_PlantType, slot.GetSlotId()) );
439 int slot_index = slot.GetSlotIndex();
440 slot.SetPlant(plant);
441 plant.Init(
this, slot.GetFertility(), slot.m_HarvestingEfficiency, slot.GetWater() );
444 plant.LockToParent();
450 Slot slot = GetSlotBySelection( selection_component );
454 string item_type = item.GetType();
456 if ( slot.GetFertilityType() ==
"" || slot.GetFertilityType() == item_type )
458 slot.SetFertilityType(item_type);
460 float add_energy_to_slot =
GetGame().
ConfigGetFloat(
string.Format(
"cfgVehicles %1 Horticulture AddEnergyToSlot", item_type) );
461 slot.m_FertilizerUsage =
GetGame().
ConfigGetFloat(
string.Format(
"cfgVehicles %1 Horticulture ConsumedQuantity", item_type) );
463 float coef =
Math.
Clamp( consumed_quantity / slot.m_FertilizerUsage, 0.0, 1.0 );
464 add_energy_to_slot = coef * add_energy_to_slot;
466 slot.m_FertilizerQuantity += consumed_quantity;
467 slot.m_Fertility += add_energy_to_slot;
469 if ( slot.GetFertilizerQuantity() >= slot.GetFertilizerQuantityMax() )
471 int slot_index = slot.GetSlotIndex();
475 UpdateSlotTexture( slot_index );
478 m_SlotFertilityState |= slot.GetFertilityState() << slot.GetSlotIndex();
488 slot.SetFertilizerQuantity(0);
489 slot.SetFertilityType(
"");
498 Slot slot = GetSlotBySelection( selection_component );
502 string item_type = item.GetType();
504 if ( slot.GetFertilityType() ==
"" || slot.GetFertilityType() == item_type )
515 Slot slot = GetSlotBySelection( selection_component );
531 m_SlotWateredState |= slot.GetWateredState() << slot.GetSlotIndex();
538 Slot slot = m_Slots.Get( slot_index );
542 if ( slot.IsDigged() || slot.IsPlanted() )
544 string str_hide = SLOT_SELECTION_COVERED_PREFIX + (slot_index + 1).
ToStringLen(2);
545 string str_show = SLOT_SELECTION_DIGGED_PREFIX + (slot_index + 1).
ToStringLen(1);
547 HideSelection( str_hide );
548 ShowSelection( str_show );
551 if ( slot.GetFertilityType() !=
"" )
553 SetSlotTextureFertilized( slot_index, slot.GetFertilityType() );
557 SetSlotTextureDigged( slot_index );
565 string str_digged = SLOT_SELECTION_DIGGED_PREFIX + (slot_index + 1).
ToStringLen(1);
567 ShowSelection( str_digged );
568 string texture = textures.Get(0);
569 SetObjectTexture( slot_index, texture );
571 Slot slot = m_Slots.Get( slot_index );
573 if ( slot.GetWateredState() == 0 )
576 SetObjectMaterial( slot_index, SLOT_MATERIAL_DRY );
581 SetObjectMaterial( slot_index, SLOT_MATERIAL_WET );
589 int tex_id =
GetGame().
ConfigGetInt(
string.Format(
"cfgVehicles %1 Horticulture TexId", item_type) );
591 string str_show = SLOT_SELECTION_DIGGED_PREFIX + (slot_index + 1).
ToStringLen(2);
593 ShowSelection( str_show );
594 SetObjectTexture( slot_index, textures.Get(tex_id) );
596 Slot slot = m_Slots.Get( slot_index );
598 int slot_index_offset = 0;
601 if ( slot.GetWateredState() == 0 )
604 if ( slot.GetFertilityType() ==
"GardenLime" )
606 SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_LIMED_DRY );
608 else if ( slot.GetFertilityType() ==
"PlantMaterial" )
610 SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_COMPOST_DRY );
616 if ( slot.GetFertilityType() ==
"GardenLime" )
618 SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_LIMED_WET );
620 else if ( slot.GetFertilityType() ==
"PlantMaterial" )
622 SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_COMPOST_WET );
629 if ( m_Slots != NULL )
631 Slot slot = m_Slots.Get( index );
632 PlantBase plant = slot.GetPlant();
636 plant.UnlockFromParent();
637 plant.m_MarkForDeletion =
true;
641 slot.Init( GetBaseFertility() );
645 m_SlotFertilityState &= ~(1 << slot.GetSlotIndex());
647 slot.SetWateredState( eWateredState.DRY );
648 m_SlotWateredState &= ~(1 << slot.GetSlotIndex());
652 HideSelection( SLOT_SELECTION_COVERED_PREFIX + (index + 1).
ToStringLen(2) );
653 UpdateSlotTexture( index );
659 int index = GetSlotIndexByPlant( plant );
668 int slot_index = GetSlotIndexBySelection( selection_component );
670 if ( slot_index > -1 )
672 return m_Slots.Get( slot_index );
685 if ( m_Slots != NULL )
687 string selection_component_lower = selection_component;
688 selection_component_lower.
ToLower();
690 int start = selection_component_lower.
IndexOf( SLOT_MEMORY_POINT_PREFIX );
694 start += SLOT_MEMORY_POINT_PREFIX.
Length();
696 int length = selection_component.
Length();
700 int length_add = length - end;
701 int length_from_end = 2 + length_add;
702 string num_str = selection_component.
Substring( start, length_from_end );
703 slot_index = num_str.
ToInt();
705 slot_index = slot_index - 1;
717 int start =
"SeedBase_".Length();
718 int end = att_slot.
Length();
719 int len = end - start;
721 string num_str = att_slot.
Substring( start, len );
722 slot_index = num_str.
ToInt();
729 if ( m_Slots != NULL )
731 for (
int i = 0; i < m_Slots.Count(); i++ )
733 PlantBase found_plant = m_Slots.Get(i).GetPlant();
735 if ( found_plant == plant )
747 float nearest_distance = 1000.0;
748 int nearest_slot_index = -1;
750 for (
int i = 0; i < slots_count; i++ )
752 Slot slot = m_Slots.Get(i);
754 vector slot_pos = GetSlotPosition( i );
757 if ( current_distance < nearest_distance )
759 if ( slot != NULL && slot.m_State == slot_state )
761 nearest_distance = current_distance;
762 nearest_slot_index = i;
767 return nearest_slot_index;
772 string memory_point = SLOT_MEMORY_POINT_PREFIX + (index + 1).
ToStringLen(2);
773 vector pos = this.GetSelectionPositionMS( memory_point );
775 return this.ModelToWorld( pos );
780 if ( !m_CheckRainTimer )
783 m_CheckRainTimer.Run( CHECK_RAIN_INTERVAL,
this,
"CheckRainTick", NULL,
true );
790 float wetness = rain_intensity * 20 * CHECK_RAIN_INTERVAL;
792 if (rain_intensity > 1 || rain_intensity < 0)
796 wetness = -0.1 * CHECK_RAIN_INTERVAL;
800 if ( rain_intensity > 0 )
806 for (
int i = 0; i < slots_count; i++ )
810 Slot slot = m_Slots.Get( i );
825 for (
int i = 0; i < m_Slots.Count(); i++ )
830 SetSlotWateredState( state );
840 return m_Slots.Get(index);
845 return m_SlotWateredState;
850 m_SlotWateredState = newState;
void AddAction(typename actionName)
string ToStringLen(int len)
Integer to string with fixed length, padded with zeroes.
override void SyncSlots()
PluginBase GetPlugin(typename plugin_type)
class JsonUndergroundAreaTriggerData GetPosition
proto native void ObjectDelete(Object obj)
proto native float ConfigGetFloat(string path)
Get float value from config on path.
override ScriptCallQueue GetCallQueue(int call_category)
proto native int ConfigGetInt(string path)
Get int value from config on path.
proto native bool ConfigIsExisting(string path)
proto native bool IsServer()
proto native Weather GetWeather()
Returns weather controller object.
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
override int GetGardenSlotsCount()
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
override bool CanRemoveFromHands(EntityAI player)
void SetSlotTextureDigged(int slot_index)
bool IsCorrectFertilizer(ItemBase item, string selection_component)
string ConvertAttSlotToPlantSlot(string attach_slot)
override void OnStoreSave(ParamsWriteContext ctx)
int GetSlotIndexBySelection(string selection_component)
ref Timer m_CheckRainTimer
int GetSlotIndexByAttachmentSlot(string att_slot)
void SetMaxWaterStateVal()
vector GetSlotPosition(int index)
int GetGardenSlotsCount()
void SlotWaterStateUpdate(Slot slot)
override bool CanPutIntoHands(EntityAI player)
Slot GetSlotByIndex(int index)
override bool CanPutInCargo(EntityAI parent)
void RemoveSlotPlant(Object plant)
protected ref array< ref Slot > m_Slots
array< ref Slot > GetSlots()
int GetSlotIndexByPlant(Object plant)
int GetNearestSlotIDByState(vector position, int slot_state)
override void EEItemDetached(EntityAI item, string slot_name)
void Fertilize(PlayerBase player, ItemBase item, float consumed_quantity, string selection_component)
override void AfterStoreLoad()
void SetSlotTextureFertilized(int slot_index, string item_type)
override bool HasProxyParts()
override void EEOnAfterLoad()
override int GetHideIconMask()
void PlantSeed(ItemBase seed, string selection_component)
bool CanPlantSeed(string selection_component)
int GetMaxWaterStateVal()
static private ref map< string, string > m_map_slots
override bool OnStoreLoad(ParamsReadContext ctx, int version)
void CreatePlant(Slot slot)
override void EOnInit(IEntity other, int extra)
bool NeedsFertilization(string selection_component)
override void EEItemAttached(EntityAI item, string slot_name)
void UpdateSlotTexture(int slot_index)
override void OnVariablesSynchronized()
int GetSlotWateredState()
Slot GetSlotBySelection(string selection_component)
void SetBaseFertility(float value)
void UpdateTexturesOnAllSlots()
void RemoveSlot(int index)
void SetSlotWateredState(int newState)
override void SetActions()
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
proto void CallLater(func fn, int delay=0, bool repeat=false, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
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>.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto native CGame GetGame()
EntityEvent
Entity events for event-mask, or throwing event from code.
static proto float Pow(float v, float power)
Return power of v ^ power.
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'.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto native int ToInt()
Converts string to integer.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
string Get(int index)
Gets n-th character from string.
void Set(int n, string _value)
Sets n-th character in string.
proto native int IndexOf(string sample)
Finds 'sample' in 'str'. Returns -1 when not found.
proto int ToLower()
Changes string to lowercase. Returns length.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.
proto native int Length()
Returns length of string.