mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-03 12:03:30 +03:00
find trips using a parked car later
This commit is contained in:
parent
03d31477af
commit
b28874d5bc
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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] {
|
||||
|
Loading…
Reference in New Issue
Block a user