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;
30 ref
Timer m_CheckRainTimer;
36 RegisterNetSyncVariableInt(
"m_SlotFertilityState");
37 RegisterNetSyncVariableInt(
"m_SlotWateredState");
44 for (
int i = 1; i <= GetGardenSlotsCount() ; ++i)
47 string input = SLOT_SEEDBASE_PREFIX + i.ToString();
48 string output = SLOT_MEMORY_POINT_PREFIX;
51 output = output +
"0";
53 output = output + i.ToString();
55 m_map_slots.Set(input, output);
65 SetMaxWaterStateVal();
70 super.OnVariablesSynchronized();
75 override bool HasProxyParts()
82 return EInventoryIconVisibility.HIDE_VICINITY;
85 void SetBaseFertility(
float value)
87 m_DefaultFertility = value;
90 float GetBaseFertility()
92 return m_DefaultFertility;
98 UpdateTexturesOnAllSlots();
101 void InitializeSlots()
104 int slots_count = GetGardenSlotsCount();
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 );
120 void SetMaxWaterStateVal()
124 for (
int i = 0; i < m_Slots.Count(); i++ )
126 state += 1 *
Math.Pow( 2, i );
129 m_MaxWateredStateVal = state;
132 int GetMaxWaterStateVal()
134 return m_MaxWateredStateVal;
137 void UpdateTexturesOnAllSlots()
139 int slots_count = GetGardenSlotsCount();
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 );
161 int slots_count = GetGardenSlotsCount();
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();
196 for (
int i = 0; i < GetGardenSlotsCount(); i++ )
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 );
229 int slots_count = GetGardenSlotsCount();
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...");
246 Debug.Log(
"" +
this);
247 int slots = GetInventory().GetAttachmentSlotsCount();
248 Debug.Log(
"Nb Slots : " + slots);
250 for (
int i = 0; i < slots ; i++ )
252 Slot slot = m_Slots.Get(i);
253 Debug.Log(
"i : " + i);
254 Debug.Log(
"Slot : " + slot);
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();
263 float slot_state= slot.GetState();
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);
273 Debug.Log(
"Water : " + slot_water);
274 Debug.Log(
"Water Usage : " + slot_water_usage);
275 Debug.Log(
"Watered State : " + slot_wateredState);
276 Debug.Log(
"Seed : " + slot_seed);
277 Debug.Log(
"Plant : " + slot_plant);
278 Debug.Log(
"State : " + slot_state);
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...");
285 Debug.Log(
"" +
this);
290 if ( !super.CanPutInCargo(parent) ) {
return false;}
296 if ( !super.CanPutIntoHands( parent ) )
308 int GetGardenSlotsCount()
313 bool CanPlantSeed(
string selection_component )
315 Slot slot = GetSlotBySelection( selection_component );
317 if ( slot != NULL && slot.m_State == Slot.STATE_DIGGED )
328 string ConvertAttSlotToPlantSlot(
string attach_slot)
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());
345 bool IsItemSeed =
GetGame().ConfigIsExisting(
path);
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());
385 bool IsItemSeed =
GetGame().ConfigIsExisting(
path);
387 string converted_slot_name = ConvertAttSlotToPlantSlot(slot_name);
388 Slot slot = GetSlotBySelection(converted_slot_name);
397 slot.SetState(Slot.STATE_DIGGED);
402 void PlantSeed(
ItemBase seed,
string selection_component )
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 );
429 void CreatePlant(Slot slot )
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();
448 void Fertilize(
PlayerBase player,
ItemBase item,
float consumed_quantity,
string selection_component )
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(
"");
496 bool IsCorrectFertilizer(
ItemBase item,
string selection_component )
498 Slot slot = GetSlotBySelection( selection_component );
502 string item_type = item.GetType();
504 if ( slot.GetFertilityType() ==
"" || slot.GetFertilityType() == item_type )
513 bool NeedsFertilization(
string selection_component )
515 Slot slot = GetSlotBySelection( selection_component );
528 void SlotWaterStateUpdate( Slot slot )
531 m_SlotWateredState |= slot.GetWateredState() << slot.GetSlotIndex();
535 void UpdateSlotTexture(
int slot_index )
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 );
561 void SetSlotTextureDigged(
int 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 );
585 void SetSlotTextureFertilized(
int slot_index,
string item_type )
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 );
627 void RemoveSlot(
int index )
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;
638 GetGame().ObjectDelete( plant );
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 );
657 void RemoveSlotPlant(
Object plant )
659 int index = GetSlotIndexByPlant( plant );
666 Slot GetSlotBySelection(
string selection_component )
668 int slot_index = GetSlotIndexBySelection( selection_component );
670 if ( slot_index > -1 )
672 return m_Slots.Get( slot_index );
681 int GetSlotIndexBySelection(
string selection_component )
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;
713 int GetSlotIndexByAttachmentSlot(
string att_slot )
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();
727 int GetSlotIndexByPlant(
Object plant )
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 )
745 int GetNearestSlotIDByState(
vector position,
int slot_state)
747 float nearest_distance = 1000.0;
748 int nearest_slot_index = -1;
749 int slots_count = GetGardenSlotsCount();
750 for (
int i = 0; i < slots_count; i++ )
752 Slot slot = m_Slots.Get(i);
754 vector slot_pos = GetSlotPosition( i );
755 float current_distance =
vector.Distance( position, slot_pos );
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;
770 vector GetSlotPosition(
int 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 );
778 void CheckRainStart()
780 if ( !m_CheckRainTimer )
783 m_CheckRainTimer.Run( CHECK_RAIN_INTERVAL,
this,
"CheckRainTick", NULL,
true );
788 float rain_intensity =
GetGame().GetWeather().GetRain().GetActual();
790 float wetness = rain_intensity * 20 * CHECK_RAIN_INTERVAL;
792 if (rain_intensity > 1 || rain_intensity < 0)
796 wetness = -0.1 * CHECK_RAIN_INTERVAL;
798 int slots_count = GetGardenSlotsCount();
800 if ( rain_intensity > 0 )
806 for (
int i = 0; i < slots_count; i++ )
810 Slot slot = m_Slots.Get( i );
814 slot.GiveWater( wetness *
Math.RandomFloat01() );
825 for (
int i = 0; i < m_Slots.Count(); i++ )
827 state += 1 *
Math.Pow( 2, i );
830 SetSlotWateredState( state );
838 Slot GetSlotByIndex(
int index )
840 return m_Slots.Get(index);
843 int GetSlotWateredState()
845 return m_SlotWateredState;
848 void SetSlotWateredState(
int newState )
850 m_SlotWateredState = newState;