Return agent properties for cars waiting to spawn at a border, rather than crash when asked.
@@ -1013,7 +1013,7 @@ impl DrivingSimState {
}
pub fn agent_properties(&self, id: CarID, now: Time) -> AgentProperties {
- let car = self.cars.get(&id).unwrap();
+ if let Some(car) = self.cars.get(&id) {
let path = car.router.get_path();
let time_spent_waiting = car.state.time_spent_waiting(now);
@@ -1034,6 +1034,26 @@ impl DrivingSimState {
dist_crossed: path.crossed_so_far() + current_state_dist,
total_dist: path.total_length(),
}
+ } else {
+ for (car, _) in &self.waiting_to_spawn {
+ if id == *car {
+ // If the vehicle is waiting to spawn, we don't have any stats on them yet. We
+ // could track when they originally tried to spawn and use for a few of these
+ // fields, but we should also make sure that delay gets recorded later.
+ return AgentProperties {
+ total_time: Duration::ZERO,
+ waiting_here: Duration::ZERO,
+ total_waiting: Duration::ZERO,
+ dist_crossed: Distance::ZERO,
+ total_dist: Distance::ZERO,
+ };
+ }
+ }
+ panic!(
+ "Can't get agent_properties of {} at {}; they don't exist",
+ id, now
+ );
+ }
}
pub fn get_path(&self, id: CarID) -> Option<&Path> {
