Don't crash when following a bus that's finished. #372 [rebuild] [release]

The UX of bus info panels is terrible, but just unbreak this.
This commit is contained in:
Dustin Carlino 2022-04-17 17:31:59 +01:00
parent 7b77b070a8
commit 7f50baa4c8

View File

@ -39,6 +39,7 @@ enum BusState {
AtStop(StopIdx),
// Or to the end of the lane with the last stop
DrivingOffMap,
Finished,
}
/// Manages public transit vehicles (buses and trains) that follow a route. The transit model is
@ -206,10 +207,10 @@ impl TransitSimState {
}
trips.transit_rider_reached_border(now, person, id, ctx);
}
self.buses.remove(&id).unwrap();
bus.state = BusState::Finished;
false
}
BusState::AtStop(_) => unreachable!(),
BusState::AtStop(_) | BusState::Finished => unreachable!(),
}
}
@ -217,7 +218,6 @@ impl TransitSimState {
let mut bus = self.buses.get_mut(&id).unwrap();
let route = self.routes.get_mut(&bus.route).unwrap();
match bus.state {
BusState::DrivingToStop(_) | BusState::DrivingOffMap => unreachable!(),
BusState::AtStop(stop_idx) => {
self.events.push(Event::BusDepartedFromStop(
id,
@ -232,6 +232,9 @@ impl TransitSimState {
}
Router::follow_bus_route(id, route.paths[stop_idx + 1].clone())
}
BusState::DrivingToStop(_) | BusState::DrivingOffMap | BusState::Finished => {
unreachable!()
}
}
}
@ -310,6 +313,7 @@ impl TransitSimState {
}
BusState::AtStop(idx) => Some(idx),
BusState::DrivingOffMap => Some(r.stops.len() - 1),
BusState::Finished => unreachable!(),
};
(*bus, stop)
})