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_shiftup_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)
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) : {
…}
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;
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) {
…}
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')
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) {
…}
286 float turbotorque = 0.0f;
287 float turboInertia = 0.000003f;
311 float turbotorque = 0.0f;
312 float turboBOVtorque = 0.0f;
359 turboInertia = turboInertia * 0.7;
361 turboInertia = turboInertia * 1.3;
370 turbotorque += (turbotorque * 2.5);
425 float totaltorque = 0.0f;
586 else if (m_cur_engine_rpm < m_engine_shiftup_rpm && m_engine_shiftup_rpm > declutchRPM)
602 float torqueDiff = std::min(engineTorque, std::abs(reTorque));
603 float clutch = torqueDiff / reTorque;
617 if (hdir != Vector3::ZERO)
649 float avgRPM50 = 0.0f;
650 float avgRPM200 = 0.0f;
651 float avgAcc50 = 0.0f;
652 float avgAcc200 = 0.0f;
653 float avgBrake50 = 0.0f;
654 float avgBrake200 = 0.0f;
656 for (
unsigned int i = 0; i <
m_accs.size(); i++)
670 avgRPM50 /= std::min(
m_rpms.size(), (std::deque<float>::size_type)50);
671 avgAcc50 /= std::min(
m_accs.size(), (std::deque<float>::size_type)50);
672 avgBrake50 /= std::min(
m_brakes.size(), (std::deque<float>::size_type)50);
674 avgRPM200 /=
m_rpms.size();
675 avgAcc200 /=
m_accs.size();
678 if (avgAcc50 > 0.8f || avgAcc200 > 0.8f || avgBrake50 > 0.8f || avgBrake200 > 0.8f)
682 else if (acc < 0.5f && avgAcc50 < 0.5f && avgAcc200 < 0.5f && m_actor->ar_brake < 0.5f && avgBrake50 < 0.5f && avgBrake200 < 0.5)
753 if (newGear < m_cur_gear && m_kickdown_delay_counter > 0)
885void Engine::pushNetworkState(
float rpm,
float acc,
float clutch,
int gear,
bool running,
bool contact,
char automode,
char autoselect)
897 if (autoselect != -1)
885void Engine::pushNetworkState(
float rpm,
float acc,
float clutch,
int gear,
bool running,
bool contact,
char automode,
char autoselect) {
…}
974 rpmRatio = std::max(0.0f, rpmRatio);
975 rpmRatio = std::min(rpmRatio, 1.0f);
977 float crankfactor = 5.0f * rpmRatio;
1190 val = std::max(0.0f, val);
1202 float atValue = 0.0f;
1222 float tqValue = 1.0f;
1245 if (crankfactor < 0.9f)
1250 else if (crankfactor < 1.0f)
1253 return 10.0f * (1.0f - crankfactor);
1268 float acclModifier = 0.0f;
1271 acclModifier += 0.25f;
1275 acclModifier += 0.50f;
1277 accl *= acclModifier;
1283 float brakeModifier = 0.0f;
1286 brakeModifier += 0.25f;
1290 brakeModifier += 0.50f;
1292 brake *= brakeModifier;
1331 if (velocity < 1.0f && brake > 0.5f && accl < 0.5f && this->
getGear() > 0)
1343 else if (velocity > -1.0f && brake < 0.5f && accl > 0.5f && this->
getGear() < 0)
1405 float clutchModifier = 0.0f;
1408 clutchModifier += 0.25f;
1412 clutchModifier += 0.50f;
1414 clutch *= clutchModifier;
1448 for (
int i = 1; i < 19; i++)
1460 bool gear_changed =
false;
1462 int curgear = this->
getGear();
1464 int gearoffset = std::max(0, curgear - curgearrange * 6);
1472 gear_changed =
true;
1477 gear_changed =
true;
1482 gear_changed =
true;
1487 gear_changed =
true;
1489 fmt::format(
_L(
"Range cycled (current: {}/available: {})"),
1516 else if (curgear > 0 && curgear < 19)
1521 if (gear_changed || curgear == 0)
1537 for (
int i = 1; i < 19 && !found; i++)
1548 for (
int i = 1; i < 7 && !found; i++)
1552 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_)
wheel_t ar_wheels[MAX_WHEELS]
Ogre::Vector3 getDirection()
average actor velocity, calculated using the actor positions of the last two frames
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()
@ 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)
float m_engine_shiftup_rpm
Shift down RPM ('engine' attr #1)
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)
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_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.
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.
InputEngine * GetInputEngine()
CVar * io_arcade_controls
@ SE_TRUCK_ENGINE_DIED
triggered when the vehicle's engine dies (from underrev, water, etc), the argument refers to the acto...