diff --git a/sim/src/lib.rs b/sim/src/lib.rs index 028182db98..f731720939 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -226,11 +226,15 @@ pub struct SidewalkSpot { impl SidewalkSpot { // Pretty hacky case - pub fn deferred_parking_spot(b: BuildingID, goal: DrivingGoal, map: &Map) -> SidewalkSpot { + pub fn deferred_parking_spot( + start_bldg: BuildingID, + goal: DrivingGoal, + map: &Map, + ) -> SidewalkSpot { SidewalkSpot { - connection: SidewalkPOI::DeferredParkingSpot(b, goal), + connection: SidewalkPOI::DeferredParkingSpot(start_bldg, goal), // Dummy value - sidewalk_pos: map.get_b(b).front_path.sidewalk, + sidewalk_pos: map.get_b(start_bldg).front_path.sidewalk, } } diff --git a/sim/src/sim.rs b/sim/src/sim.rs index f6b925c229..1dbe56e7f8 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -760,7 +760,18 @@ impl Sim { } lines } else { - self.parking.tooltip_lines(car).unwrap() + let mut lines = self.parking.tooltip_lines(car).unwrap(); + if let Some(b) = self.parking.get_owner_of_car(car) { + if let Some((trip, start)) = self.trips.find_trip_using_car(car, b) { + lines.push(format!( + "{} will use this car, sometime after {}", + trip, start + )); + } else { + lines.push("Though this car has owner, no trips using it".to_string()); + } + } + lines } } diff --git a/sim/src/trips.rs b/sim/src/trips.rs index 478237999a..3f74112068 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -493,6 +493,12 @@ impl TripManager { end: trip.end.clone(), } } + + // Return trip start time too + pub fn find_trip_using_car(&self, id: CarID, home: BuildingID) -> Option<(TripID, Duration)> { + let t = self.trips.iter().find(|t| t.uses_car(id, home))?; + Some((t.id, t.spawned_at)) + } } #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -508,6 +514,19 @@ struct Trip { } impl Trip { + fn uses_car(&self, id: CarID, home: BuildingID) -> bool { + self.legs.iter().any(|l| match l { + TripLeg::Walk(_, _, ref walk_to) => match walk_to.connection { + SidewalkPOI::DeferredParkingSpot(b, _) => b == home, + _ => false, + }, + // No need to look up the contents of a SidewalkPOI::ParkingSpot. If a trip uses a + // specific parked car, then there'll be a TripLeg::Drive with it already. + TripLeg::Drive(ref vehicle, _) => vehicle.id == id, + _ => false, + }) + } + fn is_bus_trip(&self) -> bool { self.legs.len() == 1 && match self.legs[0] {