cacontinuousfillpowergenerator.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. class CAContinuousFillPowerGenerator : CAContinuousFill
  2. {
  3. void CAContinuousFillPowerGenerator( float quantity_filled_per_second , int liquid_type )
  4. {
  5. m_QuantityFilledPerSecond = quantity_filled_per_second;
  6. m_liquid_type = liquid_type;
  7. }
  8. override void Setup( ActionData action_data )
  9. {
  10. m_TimeElpased = 0;
  11. if ( !m_SpentUnits )
  12. {
  13. m_SpentUnits = new Param1<float>(0);
  14. }
  15. else
  16. {
  17. m_SpentUnits.param1 = 0;
  18. }
  19. EntityAI pg = EntityAI.Cast(action_data.m_Target.GetObject()); // get power generator
  20. m_QuantityFilledPerSecond *= Math.Min(action_data.m_MainItem.GetLiquidThroughputCoef(),pg.GetLiquidThroughputCoef());
  21. m_ItemQuantity = action_data.m_MainItem.GetQuantity();
  22. m_TargetUnits = pg.GetCompEM().GetEnergyMax() - pg.GetCompEM().GetEnergy();
  23. m_AdjustedQuantityFilledPerSecond = m_QuantityFilledPerSecond;//removed softskills
  24. }
  25. override int Execute( ActionData action_data )
  26. {
  27. if ( !action_data.m_Player )
  28. {
  29. return UA_ERROR;
  30. }
  31. PowerGeneratorBase pg = PowerGeneratorBase.Cast(action_data.m_Target.GetObject()); // get power generator
  32. if ( pg.GetFuel() >= pg.GetMaxFuel() )
  33. {
  34. return UA_FINISHED;
  35. }
  36. else
  37. {
  38. if ( m_SpentQuantity_total < m_TargetUnits )
  39. {
  40. m_SpentQuantity += m_AdjustedQuantityFilledPerSecond * action_data.m_Player.GetDeltaT();
  41. m_TimeElpased += action_data.m_Player.GetDeltaT();
  42. if ( m_TimeElpased >= m_DefaultTimeStep )
  43. {
  44. CalcAndSetQuantity( action_data );
  45. m_TimeElpased = 0;
  46. //Setup(action_data); //reset data after repeat
  47. }
  48. return UA_PROCESSING;
  49. }
  50. else
  51. {
  52. CalcAndSetQuantity( action_data );
  53. OnCompletePogress(action_data);
  54. return UA_FINISHED;
  55. }
  56. }
  57. }
  58. override void CalcAndSetQuantity( ActionData action_data )
  59. {
  60. m_SpentQuantity_total += m_SpentQuantity;
  61. if ( m_SpentUnits )
  62. {
  63. m_SpentUnits.param1 = m_SpentQuantity;
  64. SetACData(m_SpentUnits);
  65. }
  66. if ( GetGame().IsServer() )
  67. {
  68. PowerGeneratorBase pg = PowerGeneratorBase.Cast(action_data.m_Target.GetObject()); // get power generator
  69. int consumed_fuel = pg.AddFuel( m_SpentQuantity );
  70. action_data.m_MainItem.AddQuantity( -consumed_fuel );
  71. }
  72. m_SpentQuantity = 0;
  73. }
  74. };