mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* fix(ai): the driver tells of standing with its pantographs up and no voltage An AI driver of an electric vehicle standing past the end of the overhead wire, or under a wire switched off, never gets out of Prepare_engine: the voltage PrepareEngine() waits for doesn't come. It waited without a word (eu07/maszyna#421, L053 poranek with an ET21 on TME222158). Now it says so in the log, once per episode, with the vehicle's name and position, telling a missing wire (no raised pantograph found one) from a wire without voltage. It keeps trying, so towed back under the wire or with the power switched on the vehicle still gets prepared. The decision is ai_power (vehicle/aipower), in the core library with unit tests; scenario case et21_td_no_wire_reports puts an ET21 on a track of its own with no wire next to td.scn. * refactor(ai): the power stall report without Sonar issues stall::none becomes stall::not_stalled (none shadowed a global enumerator), using enum in check(), and an explicit cast of the pantograph count. No change in behaviour. * fix(ai): the power stall report is a traction log line It went out as a generic error, so a scenery that keeps its wire off on purpose couldn't mute it with logs.filter like the other traction lines.
57 lines
1.4 KiB
C++
57 lines
1.4 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/aipower.h"
|
|
|
|
#include <format>
|
|
|
|
namespace ai_power {
|
|
|
|
stall check(state const &State) {
|
|
using enum stall;
|
|
if (false == State.collector || true == State.power) {
|
|
return not_stalled;
|
|
}
|
|
if (false == State.standing || false == State.pantographs_up) {
|
|
return waiting;
|
|
}
|
|
return State.wire ? no_voltage : no_wire;
|
|
}
|
|
|
|
std::optional<stall> reporter::update(stall const Stall, double const Now) {
|
|
if (Stall == stall::not_stalled) {
|
|
m_since.reset();
|
|
m_reported = false;
|
|
return std::nullopt;
|
|
}
|
|
if (Stall == stall::waiting) {
|
|
m_since.reset();
|
|
return std::nullopt;
|
|
}
|
|
if (false == m_since.has_value()) {
|
|
m_since = Now;
|
|
}
|
|
if (true == m_reported || Now - *m_since < report_delay) {
|
|
return std::nullopt;
|
|
}
|
|
m_reported = true;
|
|
return Stall;
|
|
}
|
|
|
|
std::string message(stall const Stall, std::string const &Name, glm::dvec3 const &Position) {
|
|
auto const reason{
|
|
Stall == stall::no_wire ?
|
|
"no overhead wire above its raised pantographs" :
|
|
"no voltage in the overhead wire at its raised pantographs"};
|
|
return std::format("AI [{}]: can't start, {} (at {:.2f}, {:.2f}, {:.2f}); it waits for the voltage", Name, reason, Position.x, Position.y, Position.z);
|
|
}
|
|
|
|
} // namespace ai_power
|