diff --git a/game/src/sandbox/gameplay/freeform.rs b/game/src/sandbox/gameplay/freeform.rs index 1c210170ad..2b8e0007e7 100644 --- a/game/src/sandbox/gameplay/freeform.rs +++ b/game/src/sandbox/gameplay/freeform.rs @@ -302,7 +302,9 @@ impl SimpleState for ChangeScenario { struct AgentSpawner { panel: Panel, source: Option, - goal: Option<(TripEndpoint, Option)>, + // (goal, feasible path, draw the path). Even if we can't draw the path, remember if the path + // exists at all. + goal: Option<(TripEndpoint, bool, Option)>, confirmed: bool, } @@ -409,6 +411,7 @@ impl State for AgentSpawner { { self.goal = Some(( to, + true, path.trace(&app.primary.map) .map(|pl| pl.make_polygons(NORMAL_LANE_THICKNESS)), )); @@ -468,7 +471,7 @@ impl State for AgentSpawner { if self .goal .as_ref() - .map(|(to, _)| to != &hovering) + .map(|(to, _, _)| to != &hovering) .unwrap_or(true) { if let Some(path) = TripEndpoint::path_req( @@ -481,15 +484,19 @@ impl State for AgentSpawner { { self.goal = Some(( hovering, + true, path.trace(&app.primary.map) .map(|pl| pl.make_polygons(NORMAL_LANE_THICKNESS)), )); } else { - self.goal = None; + // Don't constantly recalculate a failed path + self.goal = Some((hovering, false, None)); } } - if self.goal.is_some() && app.per_obj.left_click(ctx, "end here") { + if self.goal.as_ref().map(|(_, ok, _)| *ok).unwrap_or(false) + && app.per_obj.left_click(ctx, "end here") + { app.primary.current_selection = None; self.confirmed = true; self.panel.replace( @@ -529,7 +536,7 @@ impl State for AgentSpawner { }, ); } - if let Some((ref endpt, ref poly)) = self.goal { + if let Some((ref endpt, _, ref poly)) = self.goal { g.draw_polygon( Color::GREEN.alpha(0.8), match endpt {