pluginhorticulture.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. class PluginHorticulture extends PluginBase
  2. {
  3. ref map<string, ref PlantMaterialHealth> m_PlantMaterials;
  4. void PluginHorticulture()
  5. {
  6. m_PlantMaterials = new map<string, ref PlantMaterialHealth>;
  7. LoadFromCfg();
  8. }
  9. void LoadFromCfg()
  10. {
  11. string cfg_access = "CfgHorticulture"; // it is stored in dz\gear\cultivation\cfgHorticulture.hpp
  12. int cfg_horticulture_count = GetGame().ConfigGetChildrenCount( cfg_access );
  13. for ( int i = 0; i < cfg_horticulture_count; i++ )
  14. {
  15. string cfg_class_name = "";
  16. GetGame().ConfigGetChildName( cfg_access, i, cfg_class_name );
  17. string cfg_class_access = cfg_access + " " + cfg_class_name;
  18. int cfg_class_count = GetGame().ConfigGetChildrenCount( cfg_class_access );
  19. for ( int j = 0; j < cfg_class_count; j++ )
  20. {
  21. string cfg_subclass_name = "";
  22. GetGame().ConfigGetChildName( cfg_class_access, j, cfg_subclass_name );
  23. string cfg_subclass_access = cfg_class_access + " " + cfg_subclass_name;
  24. int cfg_subclass_count = GetGame().ConfigGetChildrenCount( cfg_subclass_access );
  25. PlantMaterialHealth plantMaterialHealth = NULL;
  26. if ( cfg_class_name == "Plants" )
  27. {
  28. plantMaterialHealth = new PlantMaterialHealth;
  29. m_PlantMaterials.Set( cfg_subclass_name, plantMaterialHealth );
  30. }
  31. for ( int k = 0; k < cfg_subclass_count; k++ )
  32. {
  33. string cfg_variable_name = "";
  34. GetGame().ConfigGetChildName( cfg_subclass_access, k, cfg_variable_name );
  35. string cfg_variable_access = cfg_subclass_access + " " + cfg_variable_name;
  36. if ( cfg_class_name == "Plants" )
  37. {
  38. string string_param = "";
  39. GetGame().ConfigGetText( cfg_variable_access, string_param );
  40. if ( cfg_variable_name == "infestedTex" )
  41. {
  42. plantMaterialHealth.m_InfestedTex = string_param;
  43. }
  44. else if ( cfg_variable_name == "infestedMat" )
  45. {
  46. plantMaterialHealth.m_InfestedMat = string_param;
  47. }
  48. else if ( cfg_variable_name == "healthyTex" )
  49. {
  50. plantMaterialHealth.m_HealthyTex = string_param;
  51. }
  52. else if ( cfg_variable_name == "healthyMat" )
  53. {
  54. plantMaterialHealth.m_HealthyMat = string_param;
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. string GetPlantType( Object obj )
  62. {
  63. string seed_type = obj.GetType();
  64. string plant_type = "";
  65. GetGame().ConfigGetText( "cfgVehicles " + seed_type + " Horticulture PlantType", plant_type );
  66. return plant_type;
  67. }
  68. float GetSurfaceFertility( string surface_type )
  69. {
  70. float fertility = 0.8;
  71. if ( surface_type == "hlina" || surface_type == "CRGrass1" || surface_type == "CRGrass2" || surface_type == "CRForest1" || surface_type == "CRForest2" || surface_type == "CRGrit1" )
  72. {
  73. fertility = 0.8;
  74. }
  75. return fertility;
  76. }
  77. bool GiveWormsToPlayer( PlayerBase player, float chance )
  78. {
  79. if ( Math.RandomFloat01() <= chance )
  80. {
  81. ItemBase item = ItemBase.Cast( player.GetHumanInventory().CreateInInventory("Food_Worm") );
  82. item.SetQuantity( 1 );
  83. return true;
  84. }
  85. return false;
  86. }
  87. PlantMaterialHealth GetPlantMaterial( string plant_type )
  88. {
  89. if ( m_PlantMaterials.Contains(plant_type) )
  90. {
  91. return m_PlantMaterials.Get(plant_type);
  92. }
  93. return NULL;
  94. }
  95. }