cacontinuouswaterplant.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class CAContinuousWaterPlant : CAContinuousQuantity
  2. {
  3. protected float m_PlantThirstyness;
  4. protected float m_TimeToComplete;
  5. void CAContinuousWaterPlant( float quantity_used_per_second )
  6. {
  7. m_QuantityUsedPerSecond = quantity_used_per_second;
  8. }
  9. override void Setup( ActionData action_data )
  10. {
  11. PlantBase target_PB;
  12. if (Class.CastTo(target_PB, action_data.m_Target.GetObject()))
  13. {
  14. m_SpentQuantity = 0;
  15. if ( !m_SpentUnits )
  16. {
  17. m_SpentUnits = new Param1<float>(0);
  18. }
  19. else
  20. {
  21. m_SpentUnits.param1 = 0;
  22. }
  23. if ( action_data.m_MainItem )
  24. {
  25. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  26. }
  27. if ( target_PB )
  28. {
  29. m_PlantThirstyness = target_PB.GetWaterMax() - target_PB.GetWater();
  30. }
  31. m_TimeToComplete = (Math.Min(m_PlantThirstyness,m_ItemQuantity))/m_QuantityUsedPerSecond;
  32. }
  33. }
  34. override int Execute( ActionData action_data )
  35. {
  36. if ( !action_data.m_Player )
  37. {
  38. return UA_ERROR;
  39. }
  40. if ( m_ItemQuantity <= 0 )
  41. {
  42. return UA_FINISHED;
  43. }
  44. else
  45. {
  46. if ( m_SpentQuantity < m_ItemQuantity && m_SpentQuantity < m_PlantThirstyness )
  47. {
  48. m_AdjustedQuantityUsedPerSecond = m_QuantityUsedPerSecond; //removed softskills
  49. m_SpentQuantity += m_QuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
  50. if ( m_Action )
  51. {
  52. PlantBase plant;
  53. Class.CastTo(plant, action_data.m_Target.GetObject() );
  54. Slot slot = plant.GetSlot();
  55. slot.GiveWater( m_SpentQuantity );
  56. }
  57. return UA_PROCESSING;
  58. }
  59. else
  60. {
  61. CalcAndSetQuantity( action_data );
  62. OnCompletePogress(action_data);
  63. return UA_FINISHED;
  64. }
  65. }
  66. }
  67. override float GetProgress()
  68. {
  69. //float progress = (m_SpentQuantity*m_QuantityUsedPerSecond)/m_TimeToComplete;
  70. return (m_SpentQuantity*m_QuantityUsedPerSecond)/m_TimeToComplete;
  71. }
  72. };