18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 00:35:59 +01:00
Files
maszyna/vehicle/smoke.cpp
jerrrrycho d8f3875929 fix(gfx): diesel smoke only once the engine fires, not while the starter turns (eu07/maszyna#523)
The smoke of a diesel came out at full strength the moment its ignition
set Mains and started the spin up, together with the ignition sound, whose
first part is the starter cranking the engine.

The ignition now starts a countdown of the new optional .fiz parameter
SmokeDelay (Engine section of DieselEngine and DieselElectric vehicles,
seconds, default 2.0, 0 restores the old behaviour); the smoke source of
the vehicle spawns nothing until it runs out. Engines already running, or
switched on another way, smoke as before. No SVN data change is needed;
vehicle authors may tune SmokeDelay to the cranking part of their
ignition: sample.
2026-11-07 18:22:42 +01:00

47 lines
1.6 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "vehicle/smoke.h"
#include "McZapkie/MOVER.h"
namespace smoke {
namespace {
// how hard the engine works, scaling the spawn rate of the source
double engine_load(TMoverParameters const &Mover) {
if (Mover.dizel_spinup) {
// starting up, it puffs harder the faster it turns
return ((Mover.enrot / 4) * 0.01);
}
auto const rpmrise{(Mover.DElist[Mover.MainCtrlPosNo].RPM - Mover.enrot) / 60};
if (Mover.DirAbsolute == 0 || Mover.Im == 0) {
// idling: speeding up to the revolutions of the master controller
return ((rpmrise * 0.02) * (Mover.EnginePower * 0.005));
}
// under load: the more current the traction motors draw, the more smoke
return ((rpmrise * (std::sqrt(Mover.Im) * 0.01) * 0.02) * (Mover.EnginePower * 0.005));
}
} // namespace
float vehicle_spawn_count(TMoverParameters const &Mover, bool const Ontracks, spawn_rate const &Rate, double const Timedelta) {
if (false == Ontracks || Mover.dizel_FiringCountdown > 0.0) {
return 0.f;
}
// the steady rate of the source, the way a source of the scenery spawns...
auto const steady{std::min<float>(static_cast<float>(Rate.pending + (Rate.rate * Timedelta * Rate.fidelity)), Rate.limit)};
// ...and on top of it the share of the engine
return std::min<float>(static_cast<float>(steady + (Rate.rate * Timedelta * Rate.fidelity * engine_load(Mover))), Rate.limit);
}
} // namespace smoke