Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
gardenbase.c
Go to the documentation of this file.
1 class GardenBase extends ItemBase //BuildingSuper
2 {
3  // Paths to slot textures. Slots can have multiple states, so multiple textures must be generated
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";
6 
7  // Wet/dry material
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";
10 
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";
15 
16  // slot names -> MUST BE LOWERCASE
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_";
21 
22 
23  private static const int CHECK_RAIN_INTERVAL = 15;
24 
25  protected ref array<ref Slot> m_Slots;
26  protected int m_SlotFertilityState = 0; //Used to store fertility state of all slots
27  protected int m_SlotWateredState = 0; //Used to store fertility state of all slots
28  protected int m_MaxWateredStateVal = 0; //Used to store fertility state of all slots
29  protected float m_DefaultFertility = 1;
30  ref Timer m_CheckRainTimer;
31 
32  private static ref map<string,string> m_map_slots; // For the 'attachment slot -> plant slot' conversion. It is possible that this will be removed later.
33 
34  void GardenBase()
35  {
36  RegisterNetSyncVariableInt("m_SlotFertilityState");
37  RegisterNetSyncVariableInt("m_SlotWateredState");
38 
39  m_map_slots = new map<string,string>;
40 
41  SetEventMask(EntityEvent.INIT); // Enable EOnInit event
42 
43  // Prepare m_map_slots
44  for (int i = 1; i <= GetGardenSlotsCount() ; ++i)
45  {
46  // m_map_slots is supposed to be: <input, output>
47  string input = SLOT_SEEDBASE_PREFIX + i.ToString();
48  string output = SLOT_MEMORY_POINT_PREFIX;
49 
50  if (i < 10)
51  output = output + "0"; // Example: '1' changes to '01'
52 
53  output = output + i.ToString();
54 
55  m_map_slots.Set(input, output);
56  }
57 
58  if ( GetGame().IsServer() )
59  {
60  CheckRainStart();
61  }
62 
63  InitializeSlots();
64 
65  SetMaxWaterStateVal();
66  }
67 
68  override void OnVariablesSynchronized()
69  {
70  super.OnVariablesSynchronized();
71 
72  SyncSlots();
73  }
74 
75  override bool HasProxyParts()
76  {
77  return true;
78  }
79 
80  override int GetHideIconMask()
81  {
82  return EInventoryIconVisibility.HIDE_VICINITY;
83  }
84 
85  void SetBaseFertility(float value)
86  {
87  m_DefaultFertility = value;
88  }
89 
90  float GetBaseFertility()
91  {
92  return m_DefaultFertility;
93  }
94 
95  override void EOnInit(IEntity other, int extra)
96  {
97  CheckRainTick();
98  UpdateTexturesOnAllSlots();
99  }
100 
101  void InitializeSlots()
102  {
103  m_Slots = new array<ref Slot>;
104  int slots_count = GetGardenSlotsCount();
105 
106  for ( int i = 0; i < slots_count; i++ )
107  {
108  Slot slot = new Slot(GetBaseFertility());
109  slot.SetSlotIndex(i);
110  int i1 = i + 1;
111  string name = "SeedBase_" + i1;
112  int slot_id = InventorySlots.GetSlotIdFromString(name);
113  slot.SetSlotId(slot_id);
114  slot.SetGarden(this);
115  slot.m_State = Slot.STATE_DIGGED;
116  m_Slots.Insert( slot );
117  }
118  }
119 
120  void SetMaxWaterStateVal()
121  {
122  int state = 0;
123 
124  for ( int i = 0; i < m_Slots.Count(); i++ )
125  {
126  state += 1 * Math.Pow( 2, i );
127  }
128 
129  m_MaxWateredStateVal = state;
130  }
131 
132  int GetMaxWaterStateVal()
133  {
134  return m_MaxWateredStateVal;
135  }
136 
137  void UpdateTexturesOnAllSlots()
138  {
139  int slots_count = GetGardenSlotsCount();
140 
141  for ( int i = 0; i < slots_count; i++ )
142  {
143  UpdateSlotTexture(i);
144  }
145  }
146 
147  override bool OnStoreLoad( ParamsReadContext ctx, int version )
148  {
149  if ( version <= 118 )
150  return true;
151 
152  if ( !super.OnStoreLoad( ctx, version ) )
153  return false;
154 
155  if ( version < 102 )
156  {
157  float some_value;
158  ctx.Read( some_value ); // compatibility check
159  }
160 
161  int slots_count = GetGardenSlotsCount();
162 
163  for ( int i = 0; i < slots_count; i++ )
164  {
165  Slot slot = m_Slots.Get( i );
166 
167  if ( !slot.OnStoreLoadCustom( ctx, version ) )
168  return false;
169 
170  //Slot textures will be updated after store load
171  //UpdateSlotTexture( i );
172  }
173 
174  if ( version >= 119 )
175  ctx.Read( m_SlotFertilityState );
176 
177  if ( version >= 120 )
178  ctx.Read( m_SlotWateredState );
179 
180  return true;
181  }
182 
183  override void AfterStoreLoad()
184  {
185  super.AfterStoreLoad();
186  }
187 
188  override void EEOnAfterLoad()
189  {
190  GetGame().GetCallQueue( CALL_CATEGORY_GAMEPLAY ).CallLater( SyncSlots, 500, false, this );
191  super.EEOnAfterLoad();
192  }
193 
194  void SyncSlots()
195  {
196  for ( int i = 0; i < GetGardenSlotsCount(); i++ )
197  {
198  // Read relevant bit
199  int fertilityState = (m_SlotFertilityState >> i) & 1;
200  m_Slots[i].SetFertilityState(fertilityState);
201 
202  int wateredState = (m_SlotWateredState >> i) & 1;
203  m_Slots[i].SetWateredState( wateredState );
204 
205  if ( fertilityState == eFertlityState.NONE )
206  {
207  m_Slots[i].SetFertilityType( "" );
208  m_Slots[i].SetFertilizerQuantity( 0 );
209  }
210 
211  if ( wateredState == eWateredState.DRY )
212  {
213  m_Slots[i].SetWater( 0 );
214  }
215 
216  UpdateSlotTexture( i );
217  }
218 
219  if ( GetGame().IsServer() )
220  {
221  SetSynchDirty();
222  }
223  }
224 
225  override void OnStoreSave( ParamsWriteContext ctx )
226  {
227  super.OnStoreSave( ctx );
228 
229  int slots_count = GetGardenSlotsCount();
230 
231  for ( int i = 0; i < slots_count; i++ )
232  {
233  Slot slot = m_Slots.Get( i );
234 
235  slot.OnStoreSaveCustom( ctx );
236  }
237 
238  ctx.Write(m_SlotFertilityState);
239 
240  ctx.Write( m_SlotWateredState );
241  }
242 
243  void PrintSlots()
244  {
245  Debug.Log("PRINT ALL SLOTS FROM...");
246  Debug.Log("" + this);
247  int slots = GetInventory().GetAttachmentSlotsCount();
248  Debug.Log("Nb Slots : " + slots);
249 
250  for ( int i = 0; i < slots ; i++ )
251  {
252  Slot slot = m_Slots.Get(i);
253  Debug.Log("i : " + i);
254  Debug.Log("Slot : " + slot);
255 
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();
268 
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("///////////////////////////");
282  }
283 
284  Debug.Log("END OF ALL SLOTS FOR...");
285  Debug.Log("" + this);
286  }
287 
288  override bool CanPutInCargo( EntityAI parent )
289  {
290  if ( !super.CanPutInCargo(parent) ) {return false;}
291  return false;
292  }
293 
294  override bool CanPutIntoHands( EntityAI player )
295  {
296  if ( !super.CanPutIntoHands( parent ) )
297  {
298  return false;
299  }
300  return false;
301  }
302 
303  override bool CanRemoveFromHands( EntityAI player )
304  {
305  return false;
306  }
307 
308  int GetGardenSlotsCount()
309  {
310  return 0;
311  }
312 
313  bool CanPlantSeed( string selection_component )
314  {
315  Slot slot = GetSlotBySelection( selection_component );
316 
317  if ( slot != NULL && slot.m_State == Slot.STATE_DIGGED )
318  {
319  return true;
320  }
321  else
322  {
323  return false;
324  }
325  }
326 
327  // Converts attachment slot name into plant slot name. Example: 'seedbase_1' -> 'component02'
328  string ConvertAttSlotToPlantSlot(string attach_slot)
329  {
330  // Give result
331  if ( m_map_slots.Contains(attach_slot) )
332  {
333  string return_value = m_map_slots.Get(attach_slot);
334  return return_value;
335  }
336 
337  return "";
338  }
339 
340  override void EEItemAttached(EntityAI item, string slot_name)
341  {
342  super.EEItemAttached(item, slot_name);
343 
344  string path = string.Format("CfgVehicles %1 Horticulture PlantType", item.GetType());
345  bool IsItemSeed = GetGame().ConfigIsExisting(path); // Is this item a seed?
346 
347  int slot_id = InventorySlots.GetSlotIdFromString(slot_name);
348 
349  if ( IsItemSeed )
350  {
351  string converted_slot_name;
352 
353  vector pos = GetPosition();
354  int index = GetSlotIndexByAttachmentSlot( slot_name );
355 
356  if (index < 10)
357  {
358  converted_slot_name = SLOT_MEMORY_POINT_PREFIX + "0" + index.ToString();
359  }
360  else
361  {
362  converted_slot_name = SLOT_MEMORY_POINT_PREFIX + index.ToString();
363  }
364 
365  PlantSeed( ItemBase.Cast( item ), converted_slot_name);
366  }
367  else if (g_Game.IsClient())
368  {
369  Slot slot = GetSlotByIndex(GetSlotIndexByAttachmentSlot( slot_name) - 1);
370  if (slot)
371  {
372  slot.SetPlant(PlantBase.Cast( item ));
373  slot.m_State = Slot.STATE_PLANTED;
374  }
375  }
376  }
377 
378  override void EEItemDetached(EntityAI item, string slot_name)
379  {
380  super.EEItemDetached(item, slot_name);
381 
382  slot_name.ToLower();
383 
384  string path = string.Format("CfgVehicles %1 Horticulture PlantType", item.GetType());
385  bool IsItemSeed = GetGame().ConfigIsExisting(path); // Is this item a seed?
386 
387  string converted_slot_name = ConvertAttSlotToPlantSlot(slot_name);
388  Slot slot = GetSlotBySelection(converted_slot_name);
389 
390  if (slot)
391  {
392  if (IsItemSeed)
393  {
394  slot.SetSeed(NULL);
395  }
396 
397  slot.SetState(Slot.STATE_DIGGED);
398  }
399  }
400 
401  // Plants the seed into slot (selection_component)
402  void PlantSeed( ItemBase seed, string selection_component )
403  {
404  int slot_index = GetSlotIndexBySelection( selection_component );
405 
406  if ( slot_index != -1 )
407  {
408  PluginHorticulture module_horticulture = PluginHorticulture.Cast( GetPlugin( PluginHorticulture ) );
409  string plant_type = module_horticulture.GetPlantType( seed );
410 
411  Slot slot = m_Slots.Get( slot_index );
412  slot.SetState(Slot.STATE_PLANTED);
413  slot.m_PlantType = plant_type;
414  slot.SetSeed(seed);
415 
416  if ( !slot.NeedsWater() )
417  {
418  seed.LockToParent();
419  //Take some small amount of time before making a plant out of seeds
420  Timer growthTimer = NULL;
421  growthTimer = new Timer( CALL_CATEGORY_SYSTEM );
422  Param createPlantParam = new Param1<Slot>(slot);
423  growthTimer.Run( 0.1, this, "CreatePlant", createPlantParam, false ); //Use a const for timer delay
424  }
425  }
426  }
427 
428  // Creates a plant
429  void CreatePlant(Slot slot )
430  {
431  if (g_Game.IsServer())
432  {
433  ItemBase seed = slot.GetSeed();
434  seed.UnlockFromParent();
435  GetGame().ObjectDelete(seed);
436 
437  PlantBase plant = PlantBase.Cast( GetInventory().CreateAttachmentEx( slot.m_PlantType, slot.GetSlotId()) );
438 
439  int slot_index = slot.GetSlotIndex();
440  slot.SetPlant(plant);
441  plant.Init( this, slot.GetFertility(), slot.m_HarvestingEfficiency, slot.GetWater() );
442  //ShowSelection(SLOT_SELECTION_COVERED_PREFIX + (slot_index + 1).ToStringLen(2));
443 
444  plant.LockToParent();
445  }
446  }
447 
448  void Fertilize( PlayerBase player, ItemBase item, float consumed_quantity, string selection_component )
449  {
450  Slot slot = GetSlotBySelection( selection_component );
451 
452  if ( slot != NULL )
453  {
454  string item_type = item.GetType();
455 
456  if ( slot.GetFertilityType() == "" || slot.GetFertilityType() == item_type )
457  {
458  slot.SetFertilityType(item_type);
459 
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) );
462 
463  float coef = Math.Clamp( consumed_quantity / slot.m_FertilizerUsage, 0.0, 1.0 );
464  add_energy_to_slot = coef * add_energy_to_slot;
465 
466  slot.m_FertilizerQuantity += consumed_quantity;
467  slot.m_Fertility += add_energy_to_slot;
468 
469  if ( slot.GetFertilizerQuantity() >= slot.GetFertilizerQuantityMax() )
470  {
471  int slot_index = slot.GetSlotIndex();
472 
473  if (slot_index > -1)
474  {
475  UpdateSlotTexture( slot_index );
476  slot.SetFertilityState(eFertlityState.FERTILIZED);
477  // Set relevant bit
478  m_SlotFertilityState |= slot.GetFertilityState() << slot.GetSlotIndex();
479 
480  //TODO Boris: Add soft skill 2.0
481  //PluginExperience module_exp = GetPlugin(PluginExperience);
482  //slot.m_HarvestingEfficiency = module_exp.GetExpParamNumber(player, PluginExperience.EXP_FARMER_FERTILIZATION, "efficiency");
483  }
484  }
485  }
486  else
487  {
488  slot.SetFertilizerQuantity(0);
489  slot.SetFertilityType("");
490  slot.SetFertilityState(eFertlityState.NONE);
491  }
492  SetSynchDirty();
493  }
494  }
495 
496  bool IsCorrectFertilizer( ItemBase item, string selection_component )
497  {
498  Slot slot = GetSlotBySelection( selection_component );
499 
500  if ( slot != NULL )
501  {
502  string item_type = item.GetType();
503 
504  if ( slot.GetFertilityType() == "" || slot.GetFertilityType() == item_type )
505  {
506  return true;
507  }
508  }
509 
510  return false;
511  }
512 
513  bool NeedsFertilization( string selection_component )
514  {
515  Slot slot = GetSlotBySelection( selection_component );
516 
517  if ( slot )
518  {
519  if ( slot.GetFertilityState() == eFertlityState.NONE )
520  {
521  return true;
522  }
523  }
524 
525  return false;
526  }
527 
528  void SlotWaterStateUpdate( Slot slot )
529  {
530  // Set relevant bit
531  m_SlotWateredState |= slot.GetWateredState() << slot.GetSlotIndex();
532  SetSynchDirty();
533  }
534 
535  void UpdateSlotTexture( int slot_index )
536  {
537  // TO DO: Fix DAYZ-30633 here!
538  Slot slot = m_Slots.Get( slot_index );
539 
540  // Show / Hide selections according to DIGGED or COVERED states.
541 
542  if ( slot.IsDigged() || slot.IsPlanted() )
543  {
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);
546 
547  HideSelection( str_hide );
548  ShowSelection( str_show );
549  }
550 
551  if ( slot.GetFertilityType() != "" )
552  {
553  SetSlotTextureFertilized( slot_index, slot.GetFertilityType() );
554  }
555  else
556  {
557  SetSlotTextureDigged( slot_index );
558  }
559  }
560 
561  void SetSlotTextureDigged( int slot_index )
562  {
563  TStringArray textures = GetHiddenSelectionsTextures();
564 
565  string str_digged = SLOT_SELECTION_DIGGED_PREFIX + (slot_index + 1).ToStringLen(1);
566 
567  ShowSelection( str_digged );
568  string texture = textures.Get(0);
569  SetObjectTexture( slot_index, texture );
570 
571  Slot slot = m_Slots.Get( slot_index );
572 
573  if ( slot.GetWateredState() == 0 )
574  {
575  // Set dry material
576  SetObjectMaterial( slot_index, SLOT_MATERIAL_DRY );
577  }
578  else
579  {
580  // Set wet material
581  SetObjectMaterial( slot_index, SLOT_MATERIAL_WET );
582  }
583  }
584 
585  void SetSlotTextureFertilized( int slot_index, string item_type )
586  {
587  TStringArray textures = GetHiddenSelectionsTextures();
588 
589  int tex_id = GetGame().ConfigGetInt( string.Format("cfgVehicles %1 Horticulture TexId", item_type) );
590 
591  string str_show = SLOT_SELECTION_DIGGED_PREFIX + (slot_index + 1).ToStringLen(2);
592 
593  ShowSelection( str_show );
594  SetObjectTexture( slot_index, textures.Get(tex_id) );
595 
596  Slot slot = m_Slots.Get( slot_index );
597 
598  int slot_index_offset = 0;
599 
600  // Set material according to dry / wet states
601  if ( slot.GetWateredState() == 0 )
602  {
603  // Set dry material for garden lime
604  if ( slot.GetFertilityType() == "GardenLime" )
605  {
606  SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_LIMED_DRY );
607  }
608  else if ( slot.GetFertilityType() == "PlantMaterial" )
609  {
610  SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_COMPOST_DRY );
611  }
612  }
613  else
614  {
615  // Set dry material for compost
616  if ( slot.GetFertilityType() == "GardenLime" )
617  {
618  SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_LIMED_WET );
619  }
620  else if ( slot.GetFertilityType() == "PlantMaterial" )
621  {
622  SetObjectMaterial( slot_index + slot_index_offset, SLOT_MATERIAL_COMPOST_WET );
623  }
624  }
625  }
626 
627  void RemoveSlot( int index )
628  {
629  if ( m_Slots != NULL )
630  {
631  Slot slot = m_Slots.Get( index );
632  PlantBase plant = slot.GetPlant();
633 
634  if ( plant )
635  {
636  plant.UnlockFromParent();
637  plant.m_MarkForDeletion = true;
638  GetGame().ObjectDelete( plant );
639  }
640 
641  slot.Init( GetBaseFertility() );
642 
643  // Clear relevant bit
644  slot.SetFertilityState(eFertlityState.NONE);
645  m_SlotFertilityState &= ~(1 << slot.GetSlotIndex());
646 
647  slot.SetWateredState( eWateredState.DRY );
648  m_SlotWateredState &= ~(1 << slot.GetSlotIndex());
649 
650  SetSynchDirty();
651 
652  HideSelection( SLOT_SELECTION_COVERED_PREFIX + (index + 1).ToStringLen(2) );
653  UpdateSlotTexture( index );
654  }
655  }
656 
657  void RemoveSlotPlant( Object plant )
658  {
659  int index = GetSlotIndexByPlant( plant );
660  if ( index >= 0 )
661  {
662  RemoveSlot( index );
663  }
664  }
665 
666  Slot GetSlotBySelection( string selection_component )
667  {
668  int slot_index = GetSlotIndexBySelection( selection_component );
669 
670  if ( slot_index > -1 )
671  {
672  return m_Slots.Get( slot_index );
673  }
674  else
675  {
676  return NULL;
677  }
678  }
679 
680  // Returns slot array index by selection, starting from 0 as the first one.
681  int GetSlotIndexBySelection( string selection_component )
682  {
683  int slot_index = -1;
684 
685  if ( m_Slots != NULL )
686  {
687  string selection_component_lower = selection_component;
688  selection_component_lower.ToLower();
689 
690  int start = selection_component_lower.IndexOf( SLOT_MEMORY_POINT_PREFIX );
691 
692  if ( start > -1 )
693  {
694  start += SLOT_MEMORY_POINT_PREFIX.Length();
695  int end = start + 2;
696  int length = selection_component.Length();
697 
698  if ( length >= end )
699  {
700  int length_add = length - end; // Hack-fix for inconsistent component names in p3d
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();
704 
705  slot_index = slot_index - 1;
706  }
707  }
708  }
709 
710  return slot_index;
711  }
712 
713  int GetSlotIndexByAttachmentSlot( string att_slot )
714  {
715  int slot_index = -1;
716 
717  int start = "SeedBase_".Length();
718  int end = att_slot.Length();//start + 2;
719  int len = end - start;
720 
721  string num_str = att_slot.Substring( start, len );
722  slot_index = num_str.ToInt();
723 
724  return slot_index;
725  }
726 
727  int GetSlotIndexByPlant( Object plant )
728  {
729  if ( m_Slots != NULL )
730  {
731  for ( int i = 0; i < m_Slots.Count(); i++ )
732  {
733  PlantBase found_plant = m_Slots.Get(i).GetPlant();
734 
735  if ( found_plant == plant )
736  {
737  return i;
738  }
739  }
740  }
741 
742  return -1;
743  }
744 
745  int GetNearestSlotIDByState( vector position, int slot_state)
746  {
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++ )
751  {
752  Slot slot = m_Slots.Get(i); // Move this line by a scope higher in this function after debugging
753 
754  vector slot_pos = GetSlotPosition( i );
755  float current_distance = vector.Distance( position, slot_pos );
756 
757  if ( current_distance < nearest_distance )
758  {
759  if ( slot != NULL && slot.m_State == slot_state )
760  {
761  nearest_distance = current_distance;
762  nearest_slot_index = i;
763  }
764  }
765  }
766 
767  return nearest_slot_index;
768  }
769 
770  vector GetSlotPosition( int index )
771  {
772  string memory_point = SLOT_MEMORY_POINT_PREFIX + (index + 1).ToStringLen(2);
773  vector pos = this.GetSelectionPositionMS( memory_point );
774 
775  return this.ModelToWorld( pos );
776  }
777 
778  void CheckRainStart()
779  {
780  if ( !m_CheckRainTimer )
781  m_CheckRainTimer = new Timer( CALL_CATEGORY_SYSTEM );
782 
783  m_CheckRainTimer.Run( CHECK_RAIN_INTERVAL, this, "CheckRainTick", NULL, true );
784  }
785 
786  void CheckRainTick()
787  {
788  float rain_intensity = GetGame().GetWeather().GetRain().GetActual();
789 
790  float wetness = rain_intensity * 20 * CHECK_RAIN_INTERVAL;
791 
792  if (rain_intensity > 1 || rain_intensity < 0)
793  wetness = 0; // hackfix for weird values returned by weather system
794 
795  if (wetness == 0)
796  wetness = -0.1 * CHECK_RAIN_INTERVAL;
797 
798  int slots_count = GetGardenSlotsCount();
799 
800  if ( rain_intensity > 0 )
801  {
802  WaterAllSlots();
803  SetSynchDirty();
804  }
805 
806  for ( int i = 0; i < slots_count; i++ )
807  {
808  if ( m_Slots )
809  {
810  Slot slot = m_Slots.Get( i );
811 
812  if ( slot )
813  {
814  slot.GiveWater( wetness * Math.RandomFloat01() );
815  }
816  }
817  }
818  }
819 
820  //Used to update
821  void WaterAllSlots()
822  {
823  int state = 0;
824 
825  for ( int i = 0; i < m_Slots.Count(); i++ )
826  {
827  state += 1 * Math.Pow( 2, i );
828  }
829 
830  SetSlotWateredState( state );
831  }
832 
833  array<ref Slot> GetSlots()
834  {
835  return m_Slots;
836  }
837 
838  Slot GetSlotByIndex( int index )
839  {
840  return m_Slots.Get(index);
841  }
842 
843  int GetSlotWateredState()
844  {
845  return m_SlotWateredState;
846  }
847 
848  void SetSlotWateredState( int newState )
849  {
850  m_SlotWateredState = newState;
851  }
852 
853  override void SetActions()
854  {
858  }
859 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
GetHideIconMask
override int GetHideIconMask()
Definition: basebuildingbase.c:87
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
SyncSlots
override void SyncSlots()
Definition: gardenplot.c:153
eFertlityState
eFertlityState
Definition: slot.c:1
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
ActionRemovePlant
Definition: actionremoveplant.c:1
EOnInit
protected override void EOnInit(IEntity other, int extra)
Definition: testframework.c:235
ActionRemoveSeed
Definition: actionremoveseed.c:1
IEntity
Definition: enentity.c:164
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ToStringLen
string ToStringLen(int len)
Integer to string with fixed length, padded with zeroes.
Definition: enconvert.c:59
PlayerBase
Definition: playerbaseclient.c:1
CanPutIntoHands
override bool CanPutIntoHands(EntityAI parent)
Definition: explosivesbase.c:257
map
map
Definition: controlsxboxnew.c:3
vector
Definition: enconvert.c:105
CanPutInCargo
override bool CanPutInCargo(EntityAI parent)
Definition: explosivesbase.c:247
AfterStoreLoad
void AfterStoreLoad()
Definition: emotemanager.c:577
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
CanRemoveFromHands
override bool CanRemoveFromHands(EntityAI parent)
Definition: explosivesbase.c:267
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
EEOnAfterLoad
override void EEOnAfterLoad()
Definition: basebuildingbase.c:497
SetActions
void SetActions()
Definition: advancedcommunication.c:79
array< ref Slot >
ActionHarvestCrops
Definition: actionharvestcrops.c:1
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: modifierbase.c:229
Debug
Definition: debug.c:13
Timer
Definition: dayzplayerimplement.c:62
Math
Definition: enmath.c:6
GardenBase
Definition: gardenplot.c:1
EntityEvent
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition: enentity.c:44
EEItemAttached
override void EEItemAttached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:520
EEItemDetached
override void EEItemDetached(EntityAI item, string slot_name)
Definition: basebuildingbase.c:529
EntityAI
Definition: building.c:5
path
string path
Definition: optionselectormultistate.c:135