cacontinuousfertilizegardenslot.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. class CAContinuousFertilizeGardenSlot : CAContinuousQuantity
  2. {
  3. protected float m_SlotFertilizerNeed;
  4. protected float m_AlreadyFilledAmount; // amount of fertilizer present within slot during the setup of action
  5. protected float m_TimeToComplete;
  6. protected float m_SpentQuantityTotal;
  7. protected float m_StartQuantity;
  8. protected Slot m_Slot;
  9. protected string m_Selection;
  10. void CAContinuousFertilizeGardenSlot( float quantity_used_per_second )
  11. {
  12. m_QuantityUsedPerSecond = quantity_used_per_second;
  13. m_TimeToComplete = 0;
  14. }
  15. override void Setup( ActionData action_data )
  16. {
  17. GardenBase target_GB;
  18. if ( Class.CastTo(target_GB, action_data.m_Target.GetObject() ) )
  19. {
  20. m_SpentQuantity = 0;
  21. m_StartQuantity = action_data.m_MainItem.GetQuantity();
  22. if ( !m_SpentUnits )
  23. {
  24. m_SpentUnits = new Param1<float>(0);
  25. }
  26. else
  27. {
  28. m_SpentUnits.param1 = 0;
  29. }
  30. if ( action_data.m_MainItem )
  31. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  32. if ( target_GB )
  33. {
  34. /*string selection = target_GB.GetActionComponentName(action_data.m_Target.GetComponentIndex());
  35. Slot slot = target_GB.GetSlotBySelection( selection );*/
  36. array<string> selections = new array<string>;
  37. target_GB.GetActionComponentNameList(action_data.m_Target.GetComponentIndex(), selections);
  38. for (int s = 0; s < selections.Count(); s++)
  39. {
  40. //string selection = selections[s];
  41. m_Selection = selections[s];
  42. m_Slot = target_GB.GetSlotBySelection( m_Selection );
  43. if (m_Slot)
  44. break;
  45. }
  46. string item_type = action_data.m_MainItem.GetType();
  47. float consumed_quantity = GetGame().ConfigGetFloat( "cfgVehicles " + item_type + " Horticulture ConsumedQuantity" );
  48. float action_length = GetGame().ConfigGetFloat( "cfgVehicles " + item_type + " Horticulture FertilizeLength" );
  49. if (action_length == 0)
  50. action_length = 1;
  51. m_Slot.SetFertilizerQuantityMax(consumed_quantity);
  52. m_AlreadyFilledAmount = m_Slot.GetFertilizerQuantity();
  53. m_SlotFertilizerNeed = consumed_quantity - m_AlreadyFilledAmount;
  54. }
  55. float defaultTimeComplete = consumed_quantity/m_QuantityUsedPerSecond;
  56. float speedMultiplier = defaultTimeComplete / action_length;
  57. m_QuantityUsedPerSecond *= speedMultiplier;
  58. }
  59. }
  60. override int Execute( ActionData action_data )
  61. {
  62. if ( !action_data.m_Player )
  63. {
  64. return UA_ERROR;
  65. }
  66. if ( m_SpentQuantity >= m_ItemQuantity )
  67. {
  68. return UA_FINISHED;
  69. }
  70. else
  71. {
  72. if ( m_SpentQuantity <= m_ItemQuantity )
  73. {
  74. m_SpentQuantity = m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
  75. GardenBase garden_base;
  76. Class.CastTo(garden_base, action_data.m_Target.GetObject() );
  77. //string selection = garden_base.GetActionComponentName(action_data.m_Target.GetComponentIndex());
  78. m_SpentQuantityTotal += m_SpentQuantity;
  79. if (GetGame().IsServer())
  80. {
  81. action_data.m_MainItem.AddQuantity( -m_SpentQuantity );
  82. }
  83. garden_base.Fertilize( action_data.m_Player, action_data.m_MainItem, m_SpentQuantity, m_Selection );
  84. return UA_PROCESSING;
  85. }
  86. else
  87. {
  88. CalcAndSetQuantity( action_data );
  89. OnCompletePogress(action_data);
  90. return UA_FINISHED;
  91. }
  92. }
  93. }
  94. override float GetProgress()
  95. {
  96. return -((m_Slot.GetFertilizerQuantity() - m_AlreadyFilledAmount)/m_SlotFertilizerNeed);
  97. }
  98. };