mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 23:17:56 +01:00
feat: a memory cell of its own for the derailment of a vehicle
report_derailment() writes the memory cell at once and only queues the events, which run later in Events.update(). A collision derails both vehicles in one frame, so when <A>:derailed ran, __simulation.derailment already held B. The scenery can now declare the memory cell <vehicle>:derailed, written the same way and with the same three fields as __simulation.derailment, for the events of that one vehicle to read. Documented that __simulation.derailment keeps only the last derailment of a frame; eu07_td_off_track_end_scenery_told checks the cell of the locomotive now.
This commit is contained in:
+17
-14
@@ -132,20 +132,23 @@ void
|
||||
state_manager::report_derailment( TDynamicObject const &Vehicle, derailment::notice const &Notice ) {
|
||||
|
||||
WriteLog( "derailment: " + derailment::describe( Notice ) );
|
||||
auto const name { std::string( derailment_name ) };
|
||||
if( auto *cell { Memory.find( name ) } ) {
|
||||
cell->UpdateValues(
|
||||
derailment::cell_text( Notice ),
|
||||
Notice.velocity,
|
||||
static_cast<double>( static_cast<int>( Notice.why ) ),
|
||||
basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2 );
|
||||
}
|
||||
if( auto *event { Events.FindEvent( name ) } ) {
|
||||
Events.AddToQuery( event, &Vehicle );
|
||||
}
|
||||
if( auto *event { Events.FindEvent( Vehicle.name() + ":derailed" ) } ) {
|
||||
Events.AddToQuery( event, &Vehicle );
|
||||
}
|
||||
auto const text { derailment::cell_text( Notice ) };
|
||||
// the cell of the name gets the notice at once, its event runs later (Events.update()): each with a cell of its own
|
||||
// for the events of one vehicle, which the derailment of another one in the same frame doesn't overwrite
|
||||
auto const tell { [ & ]( std::string const &Name ) {
|
||||
if( auto *cell { Memory.find( Name ) } ) {
|
||||
cell->UpdateValues(
|
||||
text,
|
||||
Notice.velocity,
|
||||
static_cast<double>( static_cast<int>( Notice.why ) ),
|
||||
basic_event::flags::text | basic_event::flags::value1 | basic_event::flags::value2 );
|
||||
}
|
||||
if( auto *launched { Events.FindEvent( Name ) } ) {
|
||||
Events.AddToQuery( launched, &Vehicle );
|
||||
}
|
||||
} };
|
||||
tell( std::string( derailment_name ) );
|
||||
tell( derailment::derailed_name( Vehicle.name() ) );
|
||||
Blackbox.derailed( &Vehicle, Notice );
|
||||
test().vehicle_derailed( Vehicle, Notice );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user