gardenplot.c 4.1 KB

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