interactively spawn a parked car in a garage

This commit is contained in:
Dustin Carlino 2019-10-19 17:17:33 -07:00
parent 5b9a8dd914
commit 28bb1ba194
3 changed files with 29 additions and 5 deletions

View File

@ -47,6 +47,20 @@ impl AgentSpawner {
let map = &ui.primary.map;
match ui.primary.current_selection {
Some(ID::Building(id)) => {
let spots = ui.primary.sim.get_free_offstreet_spots(id);
if !spots.is_empty()
&& ctx
.input
.contextual_action(Key::F6, "seed a parked car here")
{
let mut rng = ui.primary.current_flags.sim_flags.make_rng();
ui.primary.sim.seed_parked_car(
Scenario::rand_car(&mut rng),
spots[0],
Some(id),
);
return None;
}
if ctx
.input
.contextual_action(Key::F3, "spawn a pedestrian starting here just walking")

View File

@ -90,11 +90,17 @@ impl ParkingSimState {
}
}
for b in self.driving_to_offstreet.get(l) {
for idx in 0..self.num_spots_per_offstreet[&b] {
let spot = ParkingSpot::offstreet(*b, idx);
if self.is_free(spot) {
spots.push(spot);
}
spots.extend(self.get_free_offstreet_spots(*b));
}
spots
}
pub fn get_free_offstreet_spots(&self, b: BuildingID) -> Vec<ParkingSpot> {
let mut spots: Vec<ParkingSpot> = Vec::new();
for idx in 0..self.num_spots_per_offstreet.get(&b).cloned().unwrap_or(0) {
let spot = ParkingSpot::offstreet(b, idx);
if self.is_free(spot) {
spots.push(spot);
}
}
spots

View File

@ -175,6 +175,10 @@ impl Sim {
self.parking.get_free_spots(l)
}
pub fn get_free_offstreet_spots(&self, b: BuildingID) -> Vec<ParkingSpot> {
self.parking.get_free_offstreet_spots(b)
}
// (Filled, available)
pub fn get_all_parking_spots(&self) -> (Vec<ParkingSpot>, Vec<ParkingSpot>) {
self.parking.get_all_parking_spots()