boat.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //! Boat's sound controller list. (native, do not change or extend)
  2. enum BoatSoundCtrl
  3. {
  4. // simulation
  5. ENGINE, //!< indicates if engine is ON
  6. SPEED, //!< speed of the boat in km/h
  7. // miscellaneous
  8. PLAYER //!< indicates if driver is controlled by player
  9. };
  10. //! Type of vehicle's fluid. (native, do not change or extend)
  11. enum BoatFluid
  12. {
  13. FUEL
  14. };
  15. class BoatOwnerState : TransportOwnerState
  16. {
  17. };
  18. class BoatMove : TransportMove
  19. {
  20. };
  21. //! Native class for boats - handles physics simulation
  22. class Boat extends Transport
  23. {
  24. //!
  25. protected override event typename GetOwnerStateType()
  26. {
  27. return BoatOwnerState;
  28. }
  29. //!
  30. protected override event typename GetMoveType()
  31. {
  32. return BoatMove;
  33. }
  34. //! Returns the actual steering value in range <-1, 1>.
  35. proto native float GetSteering();
  36. //! Sets the future steering value.
  37. proto native void SetSteering(float value);
  38. //! Returns the actual throttle value in range <0, 1>.
  39. proto native float GetThrottle();
  40. //! Sets the future throttle value.
  41. proto native void SetThrottle(float value);
  42. //! Returns the value of how much the clutch is disengaged.
  43. proto native int GetClutch();
  44. //! Sets the future clutch value.
  45. proto native void SetClutch(float value);
  46. //! Returns if there is an engine.
  47. proto native bool HasEngine();
  48. //! Returns engine's min operating rpm.
  49. proto native float EngineGetRPMMin();
  50. //! Returns engine's idle rpm before engine stalls.
  51. proto native float EngineGetRPMIdle();
  52. //! Returns engine's max rpm before engine blows up.
  53. proto native float EngineGetRPMMax();
  54. //! Returns engine's maximal working rpm without damaging the engine.
  55. proto native float EngineGetRPMRedline();
  56. //! Returns engine's rpm value.
  57. proto native float EngineGetRPM();
  58. //! Returns true when engine is running, false otherwise.
  59. proto native bool EngineIsOn();
  60. //! Starts the engine.
  61. proto native void EngineStart();
  62. //! Stops the engine.
  63. proto native void EngineStop();
  64. //! Returns the index of the current gear, -1 if there is no engine.
  65. proto native int GetCurrentGear();
  66. //! Returns the index of the future gear, -1 if there is no engine.
  67. proto native int GetGear();
  68. //! Returns the index of the neutral gear.
  69. proto native int GetNeutralGear();
  70. //! Returns the number of gears.
  71. proto native int GetGearCount();
  72. //! Shifts the future gear up, triggering gearbox simulation.
  73. proto native void ShiftUp();
  74. //! Shifts the future gear to selected gear, triggering gearbox simulation.
  75. proto native void ShiftTo(int gear);
  76. //! Shifts the future gear down, triggering gearbox simulation.
  77. proto native void ShiftDown();
  78. //! Returns the propeller position in local space
  79. proto native vector PropellerGetPosition();
  80. //! Returns the angular velocity of the propeller
  81. proto native float PropellerGetAngularVelocity();
  82. /*!
  83. Returns tank capacity for the specified vehicle's fluid.
  84. \param fluid the specified fluid type
  85. */
  86. proto native float GetFluidCapacity(BoatFluid fluid);
  87. /*!
  88. Returns fraction value (in range <0, 1>)
  89. of the current state of the specified vehicle's fluid.
  90. \param[in] fluid the specified fluid type
  91. */
  92. proto native float GetFluidFraction(BoatFluid fluid);
  93. //! Removes from the specified fluid the specified amount.
  94. proto native void Leak(BoatFluid fluid, float amount);
  95. //! Removes all the specified fluid from vehicle.
  96. proto native void LeakAll(BoatFluid fluid);
  97. //! Adds to the specified fluid the specified amount.
  98. proto native void Fill(BoatFluid fluid, float amount);
  99. /*!
  100. Is called every time the game wants to start the engine.
  101. \return true if the engine can start, false otherwise.
  102. */
  103. bool OnBeforeEngineStart()
  104. {
  105. // engine can start by default
  106. return true;
  107. }
  108. /*!
  109. Is called every time the engine starts.
  110. */
  111. void OnEngineStart() {}
  112. /*!
  113. Is called every time the engine stops.
  114. */
  115. void OnEngineStop() {}
  116. /*!
  117. Is called every time when the simulation changed gear.
  118. \param[in] newGear new gear level
  119. \param[in] oldGear previous gear level before gear shift
  120. */
  121. void OnGearChanged(int newGear, int oldGear) {}
  122. /*!
  123. Is called every time when the specified vehicle's fluid level changes.
  124. This callback is called on owner only.
  125. \param[in] fluid fluid identifier, \see BoatFluid
  126. \param[in] newValue new fluid level
  127. \param[in] oldValue previous fluid level before change
  128. */
  129. void OnFluidChanged(BoatFluid fluid, float newValue, float oldValue) {}
  130. /*!
  131. Is called every sound simulation step.
  132. In this callback, user can modify behaviour of sound controllers.
  133. \param[in] ctrl sound controller identifier, \see BoatSoundCtrl
  134. \param[in] oldValue already computed value by the game code
  135. \return new value of the specified sound controller.
  136. */
  137. float OnSound(BoatSoundCtrl ctrl, float oldValue)
  138. {
  139. // just use the computed value by the game code
  140. return oldValue;
  141. }
  142. };