Skip to content

Commit

Permalink
Spawn neighboring towns again and add uturns on road ends #285
Browse files Browse the repository at this point in the history
  • Loading branch information
aeplay committed Sep 19, 2018
1 parent ddcbbc7 commit 5a755ac
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 44 deletions.
11 changes: 6 additions & 5 deletions game_browser/src/simulation_browser/Simulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export function render(state, setState) {
(state.simulation.time[1] + "").padStart(2, "0"),
EL(Slider, {
className: "sim-speed",
value: state.simulation.speed,
min: 0, max: 10,
marks: { 1: "1x", 10: "10x" },
onChange: newSpeed => {
value: state.simulation.speed == 0 ? 0 : Math.log2(state.simulation.speed) + 1,
min: 0, max: 6,
marks: { 0: "||", 1: "1x", 3: "4x", 6: "32x" },
onChange: newSpeedLog => {
const newSpeed = newSpeedLog == 0 ? 0 : Math.pow(2, newSpeedLog - 1);
cityboundBrowser.set_sim_speed(newSpeed);
setState(oldState => update(oldState, { simulation: { speed: { $set: newSpeed } } }));
},
tipFormatter: speed => speed ? `Speed: ${speed}x` : "Pause"
tipFormatter: speed => speed ? `Speed: ${Math.pow(2, speed - 1)}x` : "Pause"
})]
);

Expand Down
1 change: 1 addition & 0 deletions game_common/src/economy/households/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ impl HouseholdLog {
pub fn log(&mut self, string: &str) {
if DO_HOUSEHOLD_LOGGING {
self.0.push_str(string);
println!("{}", string);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions game_common/src/economy/immigration_and_development/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ impl Sleeper for ImmigrationManager {
self.state = match self.state {
ImmigrationManagerState::Idle => {
let family_share = 1.0;
let grocery_share = 0.02;
let cow_farm_share = 0.09;
let veg_farm_share = 0.026;
let grain_farm_share = 0.02; //0.0016;
let mill_share = 0.02; //0.001;
let bakery_share = 0.02; //0.01;
let grocery_share = 0.2;
let cow_farm_share = 0.9;
let veg_farm_share = 0.26;
let grain_farm_share = 0.2; //0.0016;
let mill_share = 0.2; //0.001;
let bakery_share = 0.2; //0.01;

let total_share = family_share
+ grocery_share
Expand Down
8 changes: 4 additions & 4 deletions game_common/src/economy/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ impl LocationRequester for TripCostEstimator {
.node
.get_distance_to(destination.location, self.id_as(), world);
} else if self.n_resolved == 2 {
// println!(
// "Either source or dest not resolvable for {}",
// r_info(self.base_result.resource).0
// );
println!(
"Either source or dest not resolvable for {}",
self.base_result.resource
);
self.requester.on_result(
EvaluatedSearchResult {
resource: self.base_result.resource,
Expand Down
10 changes: 5 additions & 5 deletions game_common/src/land_use/buildings/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ pub fn build_building<R: Rng>(
}
}
BuildingStyle::NeighboringTownConnection => {
let length = 100.0;
let length = 20.0;
let building_orientation_orth = building_orientation.orthogonal();

let vertices = vec![
building_position - length / 4.0 * building_orientation_orth,
building_position + length / 2.0 * building_orientation,
building_position + length / 4.0 * building_orientation_orth,
building_position - length / 2.0 * building_orientation,
building_position - length / 4.0 * building_orientation,
building_position + length / 2.0 * building_orientation_orth,
building_position + length / 4.0 * building_orientation,
building_position - length / 2.0 * building_orientation_orth,
].into_iter()
.map(|v| Vertex {
position: [v.x, v.y, 3.0],
Expand Down
9 changes: 3 additions & 6 deletions game_common/src/land_use/buildings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ impl Sleeper for Building {
self.started_reconnect = false;
}
} else {
println!("Trying to connect building {:?}", self.id);
Lane::global_broadcast(world).try_reconnect_building(
self.id,
self.lot.center_point(),
self.lot.best_road_connection().0,
world,
);
Simulation::local_first(world).wake_up_in(
Expand All @@ -235,6 +236,7 @@ impl Building {
world: &mut World,
) {
if self.location.is_none() {
println!("{:?} reconnected to {:?}", self.id, new_location);
self.location = Some(new_location);
new_location.node.add_attachee(self.id_as(), world);
}
Expand Down Expand Up @@ -270,11 +272,6 @@ pub fn units_for_style(style: BuildingStyle) -> CVec<Unit> {
}.into()
}

pub const MIN_ROAD_LENGTH_TO_TOWN: f32 = 4000.0;
const MIN_NEIGHBORING_TOWN_DISTANCE: f32 = 2000.0;

pub const MIN_LANE_BUILDING_DISTANCE: f32 = 15.0;

#[derive(Compact, Clone, Default)]
pub struct BuildingPlanResultDelta {
buildings_to_destroy: CVec<BuildingID>,
Expand Down
91 changes: 89 additions & 2 deletions game_common/src/land_use/zone_planning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AreaError, WithUniqueOrthogonal};
use land_use::buildings::BuildingStyle;
use ordered_float::OrderedFloat;

use transport::transport_planning::RoadPrototype;
use transport::transport_planning::{RoadPrototype, LanePrototype};

use planning::{PlanHistory, VersionedGesture, PlanResult, Prototype, PrototypeID,
PrototypeKind, GestureIntent};
Expand Down Expand Up @@ -180,6 +180,89 @@ pub fn calculate_prototypes(
.filter_map(|maybe_proto| maybe_proto)
.collect::<Vec<_>>();

let mut neighboring_town_distance_per_octant = vec![
(0.0, None),
(0.0, None),
(0.0, None),
(0.0, None),
(0.0, None),
(0.0, None),
(0.0, None),
(0.0, None),
];

for prototype in current_result.prototypes.values() {
if let PrototypeKind::Road(RoadPrototype::Lane(LanePrototype(ref path, _))) = prototype.kind
{
let distance = (path.start() - P2::new(0.0, 0.0)).norm();
if distance > 300.0 {
let (x, y) = (path.start().x, path.start().y);
let octant = if x > 0.0 {
if y > 0.0 {
if x > y {
0
} else {
1
}
} else if x > y {
2
} else {
3
}
} else if y > 0.0 {
if x > y {
4
} else {
5
}
} else if x > y {
6
} else {
7
};

if distance > neighboring_town_distance_per_octant[octant].0 {
let direction = path.start_direction();
let direction_orth = path.start_direction().orthogonal();

let corners: CVec<P2> = vec![
path.start() + 3.0 * direction_orth,
path.start() + 3.0 * direction_orth + 10.0 * direction,
path.start() + 13.0 * direction_orth + 10.0 * direction,
path.start() + 13.0 * direction_orth,
path.start() + 3.0 * direction_orth,
].into();

if let Some(road_boundary) = LinePath::new(vec![corners[0], corners[1]].into())
{
if let Some(path) = LinePath::new(corners) {
if let Some(area_boundary) = ClosedLinePath::new(path) {
neighboring_town_distance_per_octant[octant] = (
distance,
Some(Prototype {
kind: PrototypeKind::Lot(LotPrototype {
occupancy: LotOccupancy::Occupied(
BuildingStyle::NeighboringTownConnection,
),
lot: Lot {
road_boundaries: vec![road_boundary].into(),
area: Area::new_simple(area_boundary),
land_uses: CVec::new(),
max_height: 0,
set_back: 0,
},
}),
id: PrototypeID::from_influences(prototype.id),
}),
);
}
}
}
}
}
}
}

let vacant_lot_prototypes = {
let building_areas = building_prototypes
.iter()
Expand Down Expand Up @@ -302,5 +385,9 @@ pub fn calculate_prototypes(
Ok(vacant_lot_prototypes
.into_iter()
.chain(building_prototypes)
.collect())
.chain(
neighboring_town_distance_per_octant
.into_iter()
.filter_map(|pair| pair.1),
).collect())
}
21 changes: 12 additions & 9 deletions game_common/src/transport/construction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ impl Lane {
}
}

use land_use::buildings::{BuildingID, MIN_LANE_BUILDING_DISTANCE};
use land_use::buildings::{BuildingID};
use style::dimensions::LANE_DISTANCE;
use transport::pathfinding::PreciseLocation;

impl Lane {
Expand All @@ -462,14 +463,16 @@ impl Lane {
let path = &self.construction.path;
let distance = path.distance_to(lot_position);

if distance >= MIN_LANE_BUILDING_DISTANCE
&& distance <= 1.7 * MIN_LANE_BUILDING_DISTANCE
{
if let Some((offset, projected_point)) = path.project_with_max_distance(
lot_position,
1.7 * MIN_LANE_BUILDING_DISTANCE,
0.5,
) {
println!(
"Building {:?} lane {:?} distance: {}",
building, self.id, distance
);

if distance <= 3.0 * LANE_DISTANCE {
if let Some((offset, projected_point)) =
path.project_with_max_distance(lot_position, 0.5, 3.0 * LANE_DISTANCE)
{
println!("Projected: {}", offset);
building.reconnect(
PreciseLocation { location, offset },
projected_point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pub fn create_connecting_lanes(intersection: &mut IntersectionPrototype) {
let n_lanes = incoming_group.len();

let has_inner_turn = intersection.outgoing.values().any(|outgoing_group| {
role_between_groups(incoming_group, outgoing_group).inner_turn
let role = role_between_groups(incoming_group, outgoing_group);
role.inner_turn || role.u_turn
});
let has_straight = intersection
.outgoing
Expand Down Expand Up @@ -125,7 +126,8 @@ pub fn create_connecting_lanes(intersection: &mut IntersectionPrototype) {
let n_lanes = outgoing_group.len();

let has_inner_turn = intersection.incoming.values().any(|incoming_group| {
role_between_groups(incoming_group, outgoing_group).inner_turn
let role = role_between_groups(incoming_group, outgoing_group);
role.inner_turn || role.u_turn
});
let has_straight = intersection
.incoming
Expand All @@ -146,18 +148,18 @@ pub fn create_connecting_lanes(intersection: &mut IntersectionPrototype) {
(true, false, true) => ((n_lanes / 2).max(1), (n_lanes / 2).max(1)),
};

for (l, incoming_lane) in outgoing_group.iter_mut().enumerate() {
for (l, outgoing_lane) in outgoing_group.iter_mut().enumerate() {
if l == 0 && has_inner_turn {
incoming_lane.role.u_turn = true;
outgoing_lane.role.u_turn = true;
}
if l < n_inner_turn_lanes {
incoming_lane.role.inner_turn = true;
outgoing_lane.role.inner_turn = true;
}
if n_lanes < 3 || l >= n_inner_turn_lanes && l < n_lanes - n_outer_turn_lanes {
incoming_lane.role.straight = true;
outgoing_lane.role.straight = true;
}
if l >= n_lanes - n_outer_turn_lanes {
incoming_lane.role.outer_turn = true;
outgoing_lane.role.outer_turn = true;
}
}
}
Expand Down

0 comments on commit 5a755ac

Please sign in to comment.