gardenplot.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. class GardenPlot extends GardenBase
  2. {
  3. Object m_ClutterCutter;
  4. private const int GARDEN_SLOT_COUNT = 9;
  5. private const float PLACEMENT_HEIGHT_LIMIT = 0.3; // Y coord placement limit - this is important when server has collision checks disabled
  6. void GardenPlot()
  7. {
  8. SetBaseFertility(0.5);
  9. }
  10. override bool OnStoreLoad( ParamsReadContext ctx, int version )
  11. {
  12. if ( !super.OnStoreLoad(ctx, version) )
  13. return false;
  14. if ( !m_ClutterCutter )
  15. {
  16. m_ClutterCutter = GetGame().CreateObjectEx( "ClutterCutter6x6", GetPosition(), ECE_PLACE_ON_SURFACE );
  17. m_ClutterCutter.SetOrientation( GetOrientation() );
  18. }
  19. return true;
  20. }
  21. override void EEDelete(EntityAI parent)
  22. {
  23. super.EEDelete(parent);
  24. if (m_ClutterCutter && GetGame())
  25. {
  26. GetGame().ObjectDelete(m_ClutterCutter);
  27. m_ClutterCutter = NULL;
  28. }
  29. }
  30. override bool IsInventoryVisible()
  31. {
  32. return true;
  33. }
  34. override int GetGardenSlotsCount()
  35. {
  36. return GARDEN_SLOT_COUNT;
  37. }
  38. void RefreshSlots()
  39. {
  40. HideSelection("SeedBase_1");
  41. HideSelection("SeedBase_2");
  42. HideSelection("SeedBase_3");
  43. HideSelection("SeedBase_4");
  44. HideSelection("SeedBase_5");
  45. HideSelection("SeedBase_6");
  46. HideSelection("SeedBase_7");
  47. HideSelection("SeedBase_8");
  48. HideSelection("SeedBase_9");
  49. HideSelection("slotCovered_01");
  50. HideSelection("slotCovered_02");
  51. HideSelection("slotCovered_03");
  52. HideSelection("slotCovered_04");
  53. HideSelection("slotCovered_05");
  54. HideSelection("slotCovered_06");
  55. HideSelection("slotCovered_07");
  56. HideSelection("slotCovered_08");
  57. HideSelection("slotCovered_09");
  58. }
  59. //================================================================
  60. // ADVANCED PLACEMENT
  61. //================================================================
  62. override void OnPlacementStarted( Man player )
  63. {
  64. RefreshSlots();
  65. }
  66. override void OnHologramBeingPlaced( Man player )
  67. {
  68. RefreshSlots();
  69. }
  70. override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
  71. {
  72. super.OnPlacementComplete( player, position, orientation );
  73. // To properly move the clutter cutter from spawn position, it must be deleted and created again.
  74. if (m_ClutterCutter)
  75. {
  76. GetGame().ObjectDelete(m_ClutterCutter);
  77. m_ClutterCutter = NULL;
  78. }
  79. if (!m_ClutterCutter)
  80. {
  81. m_ClutterCutter = GetGame().CreateObjectEx( "ClutterCutter6x6", GetPosition(), ECE_PLACE_ON_SURFACE );
  82. m_ClutterCutter.SetOrientation( orientation );
  83. }
  84. SyncSlots();
  85. }
  86. override bool CanBePlaced( Man player, vector position )
  87. {
  88. string surface_type;
  89. float surfaceHeight = GetGame().SurfaceGetType3D( position[0], position[1], position[2], surface_type );
  90. if ((position[1] - surfaceHeight) > PLACEMENT_HEIGHT_LIMIT)
  91. return false;
  92. return GetGame().IsSurfaceFertile(surface_type);
  93. }
  94. override bool IsTakeable()
  95. {
  96. return false;
  97. }
  98. override bool CanPutInCargo( EntityAI parent )
  99. {
  100. return false;
  101. }
  102. override bool CanRemoveFromCargo( EntityAI parent )
  103. {
  104. return false;
  105. }
  106. //hands
  107. override bool CanPutIntoHands( EntityAI parent )
  108. {
  109. return false;
  110. }
  111. }
  112. //class GardenPlotOutside : GardenPlot {}
  113. class GardenPlotPolytunnel : GardenPlot
  114. {
  115. private const int POLYTUNNEL_SLOT_COUNT = 13;
  116. override int GetGardenSlotsCount()
  117. {
  118. return POLYTUNNEL_SLOT_COUNT;
  119. }
  120. override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
  121. {
  122. if ( g_Game.IsServer() || !g_Game.IsMultiplayer() )
  123. {
  124. SyncSlots();
  125. }
  126. }
  127. override void RefreshSlots()
  128. {
  129. HideSelection("SeedBase_1");
  130. HideSelection("SeedBase_2");
  131. HideSelection("SeedBase_3");
  132. HideSelection("SeedBase_4");
  133. HideSelection("SeedBase_5");
  134. HideSelection("SeedBase_6");
  135. HideSelection("SeedBase_7");
  136. HideSelection("SeedBase_8");
  137. HideSelection("SeedBase_9");
  138. HideSelection("SeedBase_10");
  139. HideSelection("SeedBase_11");
  140. HideSelection("SeedBase_12");
  141. HideSelection("SeedBase_13");
  142. }
  143. }
  144. class GardenPlotGreenhouse : GardenPlot
  145. {
  146. override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
  147. {
  148. if ( g_Game.IsServer() || !g_Game.IsMultiplayer() )
  149. {
  150. SyncSlots();
  151. }
  152. }
  153. }
  154. class GardenPlotPlacing extends GardenPlot
  155. {
  156. override void EOnInit(IEntity other, int extra) {};
  157. override void RefreshSlots() {};
  158. override void SyncSlots() {};
  159. }