cacontinuousdisinfectplant.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. class CAContinuousDisinfectPlant : CAContinuousQuantity
  2. {
  3. protected float m_PlantNeededSpraying;
  4. protected float m_TimeToComplete;
  5. protected float m_SpentQuantityTotal;
  6. protected float m_StartQuantity;
  7. protected PlantBase m_Plant;
  8. void CAContinuousDisinfectPlant( float quantity_used_per_second )
  9. {
  10. m_QuantityUsedPerSecond = quantity_used_per_second;
  11. }
  12. override void Setup( ActionData action_data )
  13. {
  14. GardenBase garden_base;
  15. ActionTarget target = action_data.m_Target;
  16. if ( Class.CastTo(garden_base, target.GetObject()))
  17. {
  18. Slot slot;
  19. array<string> selections = new array<string>;
  20. garden_base.GetActionComponentNameList(target.GetComponentIndex(), selections);
  21. string selection;
  22. for (int s = 0; s < selections.Count(); s++)
  23. {
  24. selection = selections[s];
  25. slot = garden_base.GetSlotBySelection( selection );
  26. if (slot)
  27. break;
  28. }
  29. if ( slot && slot.GetPlant() )
  30. {
  31. m_Plant = PlantBase.Cast(slot.GetPlant());
  32. if ( m_Plant )
  33. {
  34. m_SpentQuantity = 0;
  35. m_StartQuantity = action_data.m_MainItem.GetQuantity();
  36. if ( !m_SpentUnits )
  37. {
  38. m_SpentUnits = new Param1<float>(0);
  39. }
  40. else
  41. {
  42. m_SpentUnits.param1 = 0;
  43. }
  44. if ( action_data.m_MainItem )
  45. {
  46. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  47. }
  48. if ( m_Plant )
  49. {
  50. m_PlantNeededSpraying = m_Plant.GetSprayUsage() - m_Plant.GetSprayQuantity();
  51. }
  52. m_TimeToComplete = (Math.Min(m_PlantNeededSpraying,m_ItemQuantity))/m_QuantityUsedPerSecond;
  53. }
  54. }
  55. }
  56. /*PlantBase target_PB;
  57. if (Class.CastTo(target_PB, action_data.m_Target.GetObject()))
  58. {
  59. m_SpentQuantity = 0;
  60. m_StartQuantity = action_data.m_MainItem.GetQuantity();
  61. if ( !m_SpentUnits )
  62. {
  63. m_SpentUnits = new Param1<float>(0);
  64. }
  65. else
  66. {
  67. m_SpentUnits.param1 = 0;
  68. }
  69. if ( action_data.m_MainItem )
  70. {
  71. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  72. }
  73. if ( target_PB )
  74. {
  75. m_PlantNeededSpraying = target_PB.GetSprayUsage() - target_PB.GetSprayQuantity();
  76. }
  77. m_TimeToComplete = (Math.Min(m_PlantNeededSpraying,m_ItemQuantity))/m_QuantityUsedPerSecond;
  78. }*/
  79. }
  80. override int Execute( ActionData action_data )
  81. {
  82. Object targetObject = action_data.m_Target.GetObject();
  83. if ( !action_data.m_Player )
  84. {
  85. return UA_ERROR;
  86. }
  87. if ( m_ItemQuantity <= 0 )
  88. {
  89. return UA_FINISHED;
  90. }
  91. else
  92. {
  93. if ( m_SpentQuantity < m_ItemQuantity && m_SpentQuantity < m_PlantNeededSpraying )
  94. {
  95. m_SpentQuantity += m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
  96. m_SpentQuantityTotal += m_SpentQuantity;
  97. if ( m_Action )
  98. {
  99. /*PlantBase plant;
  100. Class.CastTo(plant, targetObject );*/
  101. m_Plant.SprayPlant(m_SpentQuantity);
  102. //m_Action.SendMessageToClient(action_data.m_Player, plant.StopInfestation( transfered_spray ));
  103. }
  104. CalcAndSetQuantity( action_data );
  105. return UA_PROCESSING;
  106. }
  107. else
  108. {
  109. CalcAndSetQuantity( action_data );
  110. OnCompletePogress(action_data);
  111. return UA_FINISHED;
  112. }
  113. }
  114. }
  115. override float GetProgress()
  116. {
  117. //return (m_SpentQuantity*m_QuantityUsedPerSecond)/m_TimeToComplete;
  118. return -(m_SpentQuantityTotal / m_StartQuantity);
  119. }
  120. };