cacontinuousfillcoolant.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. class CAContinuousFillCoolant : CAContinuousBase
  2. {
  3. protected float m_ItemQuantity;
  4. protected float m_SpentQuantity;
  5. protected float m_SpentQuantity_total;
  6. protected float m_EmptySpace; //basically free capacity
  7. protected float m_TimeElpased;
  8. protected float m_QuantityUsedPerSecond;
  9. protected float m_AdjustedQuantityUsedPerSecond;
  10. protected float m_DefaultTimeStep;
  11. protected ref Param1<float> m_SpentUnits;
  12. protected PlayerBase m_Player;
  13. void CAContinuousFillCoolant( float quantity_used_per_second, float time_to_progress )
  14. {
  15. m_QuantityUsedPerSecond = quantity_used_per_second;
  16. m_DefaultTimeStep = time_to_progress;
  17. }
  18. //---------------------------------------------------------------------------
  19. override void Setup( ActionData action_data )
  20. {
  21. m_Player = action_data.m_Player;
  22. Car car = Car.Cast(action_data.m_Target.GetParent());
  23. if ( !car )
  24. return;
  25. m_TimeElpased = 0;
  26. m_SpentQuantity = 0;
  27. if ( !m_SpentUnits )
  28. {
  29. m_SpentUnits = new Param1<float>( 0 );
  30. }
  31. else
  32. {
  33. m_SpentUnits.param1 = 0;
  34. }
  35. m_QuantityUsedPerSecond *= Math.Min(action_data.m_MainItem.GetLiquidThroughputCoef(),car.GetLiquidThroughputCoef());
  36. float coolCapacity = car.GetFluidCapacity( CarFluid.COOLANT );
  37. float currentCool = car.GetFluidFraction( CarFluid.COOLANT );
  38. currentCool = currentCool * coolCapacity;
  39. m_EmptySpace = (coolCapacity - currentCool) * 1000;
  40. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  41. if ( m_EmptySpace <= m_ItemQuantity )
  42. m_ItemQuantity = m_EmptySpace;
  43. }
  44. //---------------------------------------------------------------------------
  45. override int Execute( ActionData action_data )
  46. {
  47. Car car = Car.Cast(action_data.m_Target.GetParent());
  48. if ( !car )
  49. return UA_ERROR;
  50. if ( !action_data.m_Player )
  51. {
  52. return UA_ERROR;
  53. }
  54. if ( m_ItemQuantity <= 0 )
  55. {
  56. return UA_FINISHED;
  57. }
  58. else
  59. {
  60. if ( m_SpentQuantity_total < m_ItemQuantity )
  61. {
  62. m_AdjustedQuantityUsedPerSecond = m_QuantityUsedPerSecond;//removed softskills
  63. m_SpentQuantity += m_AdjustedQuantityUsedPerSecond * action_data.m_Player.GetDeltaT();
  64. m_TimeElpased += action_data.m_Player.GetDeltaT();
  65. if ( m_TimeElpased >= m_DefaultTimeStep )
  66. {
  67. CalcAndSetQuantity( action_data );
  68. m_TimeElpased = 0;
  69. //Setup(action_data); //reset data after repeat
  70. }
  71. return UA_PROCESSING;
  72. }
  73. else
  74. {
  75. CalcAndSetQuantity( action_data );
  76. OnCompletePogress(action_data);
  77. return UA_FINISHED;
  78. }
  79. }
  80. }
  81. //---------------------------------------------------------------------------
  82. override int Cancel( ActionData action_data )
  83. {
  84. if ( !action_data.m_Player )
  85. {
  86. return UA_ERROR;
  87. }
  88. CalcAndSetQuantity( action_data );
  89. return UA_CANCEL;
  90. }
  91. //---------------------------------------------------------------------------
  92. override float GetProgress()
  93. {
  94. if ( m_ItemQuantity <= 0 )
  95. return 1;
  96. return -(m_SpentQuantity_total / m_ItemQuantity);
  97. }
  98. //---------------------------------------------------------------------------
  99. void CalcAndSetQuantity( ActionData action_data )
  100. {
  101. m_SpentQuantity_total += m_SpentQuantity;
  102. if ( m_SpentUnits )
  103. {
  104. m_SpentUnits.param1 = m_SpentQuantity;
  105. SetACData(m_SpentUnits);
  106. }
  107. if ( GetGame().IsServer() )
  108. {
  109. if( action_data.m_MainItem )
  110. action_data.m_MainItem.AddQuantity( -m_SpentQuantity );
  111. Car car = Car.Cast(action_data.m_Target.GetParent());
  112. if( car )
  113. car.Fill( CarFluid.COOLANT, (m_SpentQuantity * 0.001) );
  114. }
  115. m_SpentQuantity = 0;
  116. }
  117. }