mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
Prevent warping near bridges, and ban travel along light rail entirely
This commit is contained in:
parent
97c5c45ca4
commit
766fea1441
@ -63,7 +63,7 @@ impl TitleScreen {
|
|||||||
.align_left(),
|
.align_left(),
|
||||||
{
|
{
|
||||||
let mut txt = Text::from(Line("15 minute Santa").display_title());
|
let mut txt = Text::from(Line("15 minute Santa").display_title());
|
||||||
txt.add(Line("An experiment"));
|
txt.add(Line("Created by Dustin Carlino, Yuwen Li, & Michael Kirk"));
|
||||||
txt.draw(ctx).centered_horiz()
|
txt.draw(ctx).centered_horiz()
|
||||||
},
|
},
|
||||||
Btn::text_bg1("Santa character created by @parallaxcreativedesign").build(
|
Btn::text_bg1("Santa character created by @parallaxcreativedesign").build(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use abstutil::MultiMap;
|
use abstutil::MultiMap;
|
||||||
use geom::{Angle, Circle, Distance, Pt2D, Speed};
|
use geom::{Angle, Circle, Distance, Pt2D, Speed};
|
||||||
@ -59,6 +59,10 @@ impl Player {
|
|||||||
) -> Vec<BuildingID> {
|
) -> Vec<BuildingID> {
|
||||||
let new_pos = self.pos.offset(dx, dy);
|
let new_pos = self.pos.offset(dx, dy);
|
||||||
|
|
||||||
|
// Make sure we only move between roads/intersections that're actually connected. Don't
|
||||||
|
// warp to bridges/tunnels.
|
||||||
|
let (valid_roads, valid_intersections) = self.on.get_connections(app);
|
||||||
|
|
||||||
// Make sure we're still on the road
|
// Make sure we're still on the road
|
||||||
let mut on = None;
|
let mut on = None;
|
||||||
for id in app
|
for id in app
|
||||||
@ -66,13 +70,17 @@ impl Player {
|
|||||||
.get_matching_objects(Circle::new(self.pos, Distance::meters(3.0)).get_bounds())
|
.get_matching_objects(Circle::new(self.pos, Distance::meters(3.0)).get_bounds())
|
||||||
{
|
{
|
||||||
if let ID::Intersection(i) = id {
|
if let ID::Intersection(i) = id {
|
||||||
if app.map.get_i(i).polygon.contains_pt(new_pos) {
|
if valid_intersections.contains(&i) && app.map.get_i(i).polygon.contains_pt(new_pos)
|
||||||
|
{
|
||||||
on = Some(On::Intersection(i));
|
on = Some(On::Intersection(i));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if let ID::Road(r) = id {
|
} else if let ID::Road(r) = id {
|
||||||
let road = app.map.get_r(r);
|
let road = app.map.get_r(r);
|
||||||
if road.get_thick_polygon(&app.map).contains_pt(new_pos) {
|
if valid_roads.contains(&r)
|
||||||
|
&& !road.is_light_rail()
|
||||||
|
&& road.get_thick_polygon(&app.map).contains_pt(new_pos)
|
||||||
|
{
|
||||||
// Where along the road are we?
|
// Where along the road are we?
|
||||||
let pt_on_center_line = road.center_pts.project_pt(new_pos);
|
let pt_on_center_line = road.center_pts.project_pt(new_pos);
|
||||||
if let Some((dist, _)) = road.center_pts.dist_along_of_point(pt_on_center_line)
|
if let Some((dist, _)) = road.center_pts.dist_along_of_point(pt_on_center_line)
|
||||||
@ -148,13 +156,41 @@ impl Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq)]
|
||||||
enum On {
|
enum On {
|
||||||
Intersection(IntersectionID),
|
Intersection(IntersectionID),
|
||||||
// Distance along the center line
|
// Distance along the center line
|
||||||
Road(RoadID, Distance),
|
Road(RoadID, Distance),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl On {
|
||||||
|
fn get_connections(&self, app: &SimpleApp) -> (HashSet<RoadID>, HashSet<IntersectionID>) {
|
||||||
|
let mut valid_roads = HashSet::new();
|
||||||
|
let mut valid_intersections = HashSet::new();
|
||||||
|
match self {
|
||||||
|
On::Road(r, _) => {
|
||||||
|
let r = app.map.get_r(*r);
|
||||||
|
valid_intersections.insert(r.src_i);
|
||||||
|
valid_intersections.insert(r.dst_i);
|
||||||
|
// Intersections might be pretty small
|
||||||
|
valid_roads.extend(app.map.get_i(r.src_i).roads.clone());
|
||||||
|
valid_roads.extend(app.map.get_i(r.dst_i).roads.clone());
|
||||||
|
}
|
||||||
|
On::Intersection(i) => {
|
||||||
|
let i = app.map.get_i(*i);
|
||||||
|
for r in &i.roads {
|
||||||
|
valid_roads.insert(*r);
|
||||||
|
// Roads can be small
|
||||||
|
let r = app.map.get_r(*r);
|
||||||
|
valid_intersections.insert(r.src_i);
|
||||||
|
valid_intersections.insert(r.dst_i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(valid_roads, valid_intersections)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct BuildingsAlongRoad {
|
struct BuildingsAlongRoad {
|
||||||
// For each road, all of the buildings along it. Ascending distance, with the distance matching
|
// For each road, all of the buildings along it. Ascending distance, with the distance matching
|
||||||
// the road's center points.
|
// the road's center points.
|
||||||
|
@ -401,7 +401,7 @@ impl ColorScheme {
|
|||||||
cs.unzoomed_highway = cs.parking_lane;
|
cs.unzoomed_highway = cs.parking_lane;
|
||||||
cs.unzoomed_residential = cs.driving_lane;
|
cs.unzoomed_residential = cs.driving_lane;
|
||||||
|
|
||||||
cs.panel_bg = Color::rgba(0, 48, 70, 0.6);
|
cs.panel_bg = Color::hex("#003046").alpha(0.8);
|
||||||
cs.gui_style.panel_bg = cs.panel_bg;
|
cs.gui_style.panel_bg = cs.panel_bg;
|
||||||
cs.inner_panel = cs.panel_bg;
|
cs.inner_panel = cs.panel_bg;
|
||||||
cs.minimap_cursor = Color::WHITE;
|
cs.minimap_cursor = Color::WHITE;
|
||||||
|
Loading…
Reference in New Issue
Block a user