mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 04:05:58 +01:00
Merge pull request #269 from MaSzyna-EU07/fix/diesel-smoke-after-ignition
Diesel exhaust smoke only once the engine fires (eu07/maszyna#523)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "doctest.h"
|
||||
|
||||
#include "vehicle.h"
|
||||
#include "drive.h"
|
||||
|
||||
#include "vehicle/smoke.h"
|
||||
|
||||
@@ -83,3 +84,78 @@ TEST_CASE("smoke: the pending particles never outgrow the room of the source") {
|
||||
|
||||
CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, rate, 10.0) == rate.limit);
|
||||
}
|
||||
|
||||
TEST_CASE("smoke: an engine the starter turns lets out no smoke until it fires (#523)") {
|
||||
auto vehicle{diesel()};
|
||||
vehicle->dizel_spinup = true;
|
||||
auto pending{source};
|
||||
pending.pending = 5.f;
|
||||
|
||||
vehicle->dizel_FiringCountdown = 0.5;
|
||||
CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, pending, update) == 0.f);
|
||||
|
||||
vehicle->dizel_FiringCountdown = 0.0;
|
||||
CHECK(smoke::vehicle_spawn_count(vehicle.mover(), true, pending, update) >= 1.f);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// the locomotive's engine started the way the AI starts it, a second at a time, until it runs (Mains)
|
||||
bool start_engine(test::driven const &Driven, test::track const &Track) {
|
||||
for (int second = 0; second < 120 && false == Driven.controlling.Mains; ++second) {
|
||||
test::start_up(Driven, Track, 1.0);
|
||||
}
|
||||
return Driven.controlling.Mains;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("smoke: a real diesel smokes only once its engine has fired, SmokeDelay after the starter began (#523)") {
|
||||
// a diesel with a mechanical transmission and a diesel-electric one
|
||||
for (auto const *path : {"sm42_v1/6d1", "st44_v2/m62-1151"}) {
|
||||
CAPTURE(path);
|
||||
test::track const track{};
|
||||
{
|
||||
// SmokeDelay set in the .fiz of the locomotive
|
||||
test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 2)};
|
||||
REQUIRE(locomotive->dizel_SmokeDelay == doctest::Approx(2.0));
|
||||
auto const driven{test::driving(locomotive)};
|
||||
REQUIRE(start_engine(driven, track));
|
||||
// the engine started less than a second ago: the starter still turns it
|
||||
CHECK(locomotive->dizel_FiringCountdown > 0.5);
|
||||
CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) == 0.f);
|
||||
// it has fired since
|
||||
test::drive(driven, track, 3.0);
|
||||
CHECK(locomotive->Mains);
|
||||
CHECK(locomotive->dizel_FiringCountdown == 0.0);
|
||||
CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f);
|
||||
}
|
||||
{
|
||||
// a longer delay from the .fiz
|
||||
test::vehicle locomotive{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 5)};
|
||||
auto const driven{test::driving(locomotive)};
|
||||
REQUIRE(start_engine(driven, track));
|
||||
test::drive(driven, track, 3.0);
|
||||
CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) == 0.f);
|
||||
test::drive(driven, track, 3.0);
|
||||
CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("smoke: without SmokeDelay in its .fiz a diesel smokes as soon as the starter turns, as before (#523)") {
|
||||
for (auto const *path : {"sm42_v1/6d1", "st44_v2/m62-1151"}) {
|
||||
CAPTURE(path);
|
||||
test::track const track{};
|
||||
// a locomotive which has the delay, loaded first, doesn't hand it on to the next one: the value is the vehicle's own
|
||||
test::vehicle delayed{test::definition{test::definition::fiz(path)}.set("Engine", "SmokeDelay", 3)};
|
||||
REQUIRE(delayed->dizel_SmokeDelay == doctest::Approx(3.0));
|
||||
test::vehicle locomotive{test::definition::fiz(path)};
|
||||
REQUIRE(locomotive->dizel_SmokeDelay == 0.0);
|
||||
CHECK(delayed->dizel_SmokeDelay == doctest::Approx(3.0));
|
||||
auto const driven{test::driving(locomotive)};
|
||||
REQUIRE(start_engine(driven, track));
|
||||
CHECK(locomotive->dizel_FiringCountdown == 0.0);
|
||||
CHECK(smoke::vehicle_spawn_count(locomotive.mover(), true, source, update) >= 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user