37Engine::Engine(
float _min_rpm,
float _max_rpm,
float torque,
float reverse_gear,
float neutral_gear, std::vector<float> forward_gears,
float diff_ratio,
ActorPtr actor) :
39 , m_auto_cur_acc(0.0f)
42 , m_braking_torque(-torque / 5.0f)
43 , m_clutch_force(10000.0f)
48 , m_cur_clutch_torque(0.0f)
49 , m_cur_engine_rpm(0.0f)
50 , m_cur_engine_torque(0.0f)
53 , m_cur_wheel_revolutions(0.0f)
54 , m_ref_wheel_revolutions(0.0f)
55 , m_diff_ratio(diff_ratio)
57 , m_engine_torque(torque)
58 , m_engine_has_air(true)
59 , m_engine_has_turbo(true)
60 , m_hydropump_state(0.0f)
61 , m_engine_idle_rpm(std::min(std::abs(_min_rpm), 800.0f))
62 , m_engine_inertia(10.0f)
63 , m_kickdown_delay_counter(0)
64 , m_max_idle_mixture(0.1f)
65 , m_engine_max_rpm(std::abs(_max_rpm))
66 , m_min_idle_mixture(0.0f)
67 , m_engine_min_rpm(std::abs(_min_rpm))
68 , m_num_gears((int)forward_gears.size())
69 , m_post_shift_time(0.2f)
70 , m_post_shift_clock(0.0f)
72 , m_engine_is_priming(false)
73 , m_engine_is_running(false)
74 , m_shift_behaviour(0.0f)
79 , m_engine_stall_rpm(300.0f)
83 , m_engine_turbo_mode(OLD)
85 , m_upshift_delay_counter(0)
86 , m_engine_is_electric(false)
87 , m_turbo_inertia_factor(1)
89 , m_max_turbo_rpm(200000.0f)
90 , m_turbo_engine_rpm_operation(0.0f)
93 , m_min_wastegate_psi(20)
94 , m_turbo_has_wastegate(false)
95 , m_turbo_has_bov(false)
96 , m_turbo_flutters(false)
97 , m_turbo_wg_threshold_p(0)
98 , m_turbo_wg_threshold_n(0)
99 , m_turbo_has_antilag(false)
100 , m_antilag_rand_chance(0.9975)
101 , m_antilag_min_rpm(3000)
102 , m_antilag_power_factor(170)
117 for (
float gear : forward_gears)
128void Engine::SetTurboOptions(
int type,
float tinertiaFactor,
int nturbos,
float param1,
float param2,
float param3,
float param4,
float param5,
float param6,
float param7,
float param8,
float param9,
float param10,
float param11)
136 LOG(
"Turbo: No more than 4 turbos allowed");
154 float turbo_max_psi = param1;
196void Engine::SetEngineOptions(
float einertia,
char etype,
float eclutch,
float ctime,
float stime,
float pstime,
float irpm,
float srpm,
float maximix,
float minimix,
float ebraking)
237 else if (etype ==
'e')
296 float turbotorque = 0.0f;
297 float turboInertia = 0.000003f;
321 float turbotorque = 0.0f;
322 float turboBOVtorque = 0.0f;
369 turboInertia = turboInertia * 0.7;
371 turboInertia = turboInertia * 1.3;
380 turbotorque += (turbotorque * 2.5);
435 float totaltorque = 0.0f;
596 else if (m_cur_engine_rpm < m_engine_min_rpm && m_engine_min_rpm > declutchRPM)
612 float torqueDiff = std::min(engineTorque, std::abs(reTorque));
613 float clutch = torqueDiff / reTorque;
627 if (hdir != Vector3::ZERO)
659 float avgRPM50 = 0.0f;
660 float avgRPM200 = 0.0f;
661 float avgAcc50 = 0.0f;
662 float avgAcc200 = 0.0f;
663 float avgBrake50 = 0.0f;
664 float avgBrake200 = 0.0f;
666 for (
unsigned int i = 0; i <
m_accs.size(); i++)
680 avgRPM50 /= std::min(
m_rpms.size(), (std::deque<float>::size_type)50);
681 avgAcc50 /= std::min(
m_accs.size(), (std::deque<float>::size_type)50);
682 avgBrake50 /= std::min(
m_brakes.size(), (std::deque<float>::size_type)50);
684 avgRPM200 /=
m_rpms.size();
685 avgAcc200 /=
m_accs.size();
688 if (avgAcc50 > 0.8f || avgAcc200 > 0.8f || avgBrake50 > 0.8f || avgBrake200 > 0.8f)
692 else if (acc < 0.5f && avgAcc50 < 0.5f && avgAcc200 < 0.5f && m_actor->ar_brake < 0.5f && avgBrake50 < 0.5f && avgBrake200 < 0.5)
763 if (newGear < m_cur_gear && m_kickdown_delay_counter > 0)
895void Engine::pushNetworkState(
float rpm,
float acc,
float clutch,
int gear,
bool running,
bool contact,
char automode,
char autoselect)
907 if (autoselect != -1)
984 rpmRatio = std::max(0.0f, rpmRatio);
985 rpmRatio = std::min(rpmRatio, 1.0f);
987 float crankfactor = 5.0f * rpmRatio;
1200 val = std::max(0.0f, val);
1212 float atValue = 0.0f;
1232 float tqValue = 1.0f;
1255 if (crankfactor < 0.9f)
1260 else if (crankfactor < 1.0f)
1263 return 10.0f * (1.0f - crankfactor);
1278 float acclModifier = 0.0f;
1281 acclModifier += 0.25f;
1285 acclModifier += 0.50f;
1287 accl *= acclModifier;
1293 float brakeModifier = 0.0f;
1296 brakeModifier += 0.25f;
1300 brakeModifier += 0.50f;
1302 brake *= brakeModifier;
1342 if (velocity < 1.0f && brake > 0.5f && accl < 0.5f && this->
getGear() > 0)
1354 else if (velocity > -1.0f && brake < 0.5f && accl > 0.5f && this->
getGear() < 0)
1416 float clutchModifier = 0.0f;
1419 clutchModifier += 0.25f;
1423 clutchModifier += 0.50f;
1425 clutch *= clutchModifier;
1459 for (
int i = 1; i < 19; i++)
1471 bool gear_changed =
false;
1473 int curgear = this->
getGear();
1475 int gearoffset = std::max(0, curgear - curgearrange * 6);
1483 gear_changed =
true;
1488 gear_changed =
true;
1493 gear_changed =
true;
1498 gear_changed =
true;
1500 fmt::format(
_L(
"Range cycled (current: {}/available: {})"),
1527 else if (curgear > 0 && curgear < 19)
1532 if (gear_changed || curgear == 0)
1548 for (
int i = 1; i < 19 && !found; i++)
1559 for (
int i = 1; i < 7 && !found; i++)
1563 this->
shiftTo(i + curgearrange * 6);
System integration layer; inspired by OgreBites::ApplicationContext.
void LOG(const char *msg)
Legacy alias - formerly a macro.
float approx_exp(const float x)
static const float RAD_PER_SEC_TO_RPM
Convert radian/second to RPM (60/2*PI)
#define SOUND_START(_ACTOR_, _TRIG_)
#define SOUND_STOP(_ACTOR_, _TRIG_)
#define SOUND_PLAY_ONCE(_ACTOR_, _TRIG_)
#define SOUND_MODULATE(_ACTOR_, _MOD_, _VALUE_)
bool getEventBoolValueBounce(int eventID, float time=0.2f)
wheel_t ar_wheels[MAX_WHEELS]
bool getEventBoolValue(int eventID)
Ogre::Vector3 getDirection()
average actor velocity, calculated using the actor positions of the last two frames
float getEventValue(int eventID, bool pure=false, InputSourceType valueSource=InputSourceType::IST_ANY)
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
float ar_avg_wheel_speed
Physics state; avg wheel speed in m/s.
Ogre::Real ar_brake
Physics state; braking intensity.
void RequestUpdateHudFeatures()
Ogre::Vector3 GetCameraDir()
Ogre::Vector3 getGForces()
bool ar_arcade_controls
Should we use arcade controls? This gets updated for the player actor according to 'io_arcade_control...
@ CONSOLE_MSGTYPE_INFO
Generic message.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
float m_tcase_ratio
Engine.
float m_engine_addi_torque[MAXTURBO]
void setWheelSpin(float rpm)
void autoShiftSet(int mode)
void pushNetworkState(float engine_rpm, float acc, float clutch, int gear, bool running, bool contact, char auto_mode, char auto_select=-1)
float m_antilag_power_factor
std::deque< float > m_rpms
char m_engine_type
't' = truck (default), 'c' = car ('engoption' attr #2)
void UpdateInputEvents(float dt)
float m_cur_engine_torque
Engine.
float m_one_third_rpm_range
float m_hydropump_state
Engine.
SimGearboxMode getAutoMode()
float getAccToHoldRPM()
estimate required throttle input to hold the current rpm
void setGearRange(int v)
low level gear changing (bypasses shifting logic)
void startEngine()
Quick engine start. Plays sounds.
float m_cur_wheel_revolutions
Gears; measured wheel revolutions.
int m_engine_turbo_mode
Engine attribute.
float m_diff_ratio
Global gear ratio ('engine' attr #4)
NodeNum_t m_air_intake_node
Node number of the air intake node (if any) - defaults to cinecam ref node (classic behavior) but can...
float m_engine_inertia
('engoption' attr #1)
float m_antilag_rand_chance
float m_min_wastegate_psi
float m_cur_engine_rpm
Engine.
float m_engine_idle_rpm
('engoption' attr #8)
bool m_turbo_has_wastegate
bool m_engine_has_air
Engine attribute.
float m_max_idle_mixture
Maximum throttle to maintain the idle RPM ('engoption' attr #9)
void setHydroPump(float work)
void SetEngineOptions(float einertia, char etype, float eclutch, float ctime, float stime, float pstime, float irpm, float srpm, float maximix, float minimix, float ebraking)
void setTCaseRatio(float ratio)
Set current transfer case gear (reduction) ratio.
void UpdateEngine(float dt, int doUpdate)
bool m_contact
Ignition switch is in ON/RUN position.
std::deque< float > m_accs
float m_cur_turbo_rpm[MAXTURBO]
std::deque< float > m_brakes
TorqueCurve * m_torque_curve
void offStart()
Quick start of vehicle engine.
float m_turbo_wg_threshold_n
float m_braking_torque
Engine attribute.
int m_cur_gear
Gears; Current gear {-1 = reverse, 0 = neutral, 1...21 = forward}.
int m_cur_gear_range
Gears.
float m_turbo_bov_rpm[MAXTURBO]
int m_kickdown_delay_counter
float m_turbo_wg_threshold_p
float m_turbo_engine_rpm_operation
Engine(float min_rpm, float max_rpm, float torque, float reverse_gear, float neutral_gear, std::vector< float > gears, float dratio, ActorPtr actor)
float m_shift_time
Time (in seconds) that it takes to shift ('engoption' attr #4)
float m_clutch_time
Time (in seconds) the clutch takes to apply ('engoption' attr #5)
void setGear(int v)
low level gear changing (bypasses shifting logic)
bool m_engine_has_turbo
Engine attribute.
std::vector< float > m_gear_ratios
[R|N|1|...] ('engine' attrs #4[global],#5[R],#6[N],#7[1]...)
void autoSetAcc(float val)
float m_cur_clutch_torque
float m_ref_wheel_revolutions
Gears; estimated wheel revolutions based on current vehicle speed along the longi....
float m_min_idle_mixture
Minimum throttle to maintain the idle RPM ('engoption' attr #10)
void stopEngine()
stall engine
int m_num_gears
Num. forward gears.
bool m_starter
Ignition switch is in START position.
SimGearboxMode m_auto_mode
int m_upshift_delay_counter
void SetTurboOptions(int type, float tinertiaFactor, int nturbos, float param1, float param2, float param3, float param4, float param5, float param6, float param7, float param8, float param9, float param10, float param11)
float m_clutch_force
('engoption' attr #3)
void setAutoMode(SimGearboxMode mode)
void setManualClutch(float val)
bool m_engine_is_priming
Engine.
void shift(int val)
Changes gear by a relative offset. Plays sounds.
bool m_engine_is_electric
Engine attribute.
float m_engine_min_rpm
Shift down RPM ('engine' attr #1)
float m_post_shift_time
Time (in seconds) until full torque is transferred ('engoption' attr #6)
bool m_engine_is_running
Engine state.
void toggleContact()
Ignition.
void updateShifts()
Changes gears. Plays sounds.
float m_engine_max_rpm
Shift up RPM ('engine' attr #2)
float m_engine_stall_rpm
('engoption' attr #7)
int getNumGearsRanges() const
float m_turbo_inertia_factor
float m_engine_torque
Torque in N/m ('engine' attr #3)
void shiftTo(int val)
Changes gear to given value. Plays sounds.
float getGearRatio(int pos)
-1=R, 0=N, 1... ('engine' attrs #5[R],#6[N],#7[1]...)
bool hasContact()
Ignition.
const TerrainPtr & GetTerrain()
This class loads and processes a torque curve for a vehicle.
Ogre::Real getEngineTorque(Ogre::Real rpm)
Returns the calculated engine torque based on the given RPM, interpolating the torque curve spline.
void TRIGGER_EVENT_ASYNC(scriptEvents type, int arg1, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
Asynchronously (via MSG_SIM_SCRIPT_EVENT_TRIGGERED) invoke script function eventCallbackEx(),...
std::string ToLocalizedString(SimGearboxMode e)
@ MANUAL_STICK
Fully manual: stick shift.
@ MANUAL_RANGES
Fully manual: stick shift with ranges.
@ SEMI_AUTO
Manual shift with auto clutch.
@ MANUAL
Fully manual: sequential shift.
GameContext * GetGameContext()
static const NodeNum_t NODENUM_INVALID
@ SE_TRUCK_ENGINE_DIED
triggered when the vehicle's engine dies (from underrev, water, etc), the argument refers to the acto...
Ogre::Vector3 AbsPosition
absolute position in the world (shaky)