Cities
Algorithmically generated city layouts.
At the start of the simulation, the City is seeded with a major road node at a geographically central point. New nodes and edges are gradually added to represent roads and junctions. In the city, there are two types of road—major roads and minor roads. Cycles of major roads form “Quarters” with each Quarter having an assigned type of property (commercial, residential or industrial) and an associated StreetPattern that affects the geometric properties of the random road expansion (for example, road length and angle). Once a Quarter is established, it is filled with minor road expansion. If no Quarters are available for minor road expansion, the major road network is expanded until new Quarters are created.
The main simulation code consists of a road expansion loop that grows the city step by step, picking an existing node in the road network and creating and testing a proposed random road expansion.
- Unexpanded Quarters are searched for.
- If an empty Quarter is found, a node is selected from the major road boundary.
- A RoadProposal holds a proposed continuation from that node. If the node is already connected to two other nodes, a three-way junction is proposed. No more than four roads can lead from one node.
- The proposed road length and angle can be affected by the StreetPattern chosen for the Quarter.
- An adapt step may alter the endpoint to follow terrain, avoid obstacles, or create a junction where the proposal intersects an existing road.
- The proposal is checked for legality. Roads outside the Quarter, too close to an existing four-way junction, or creating a very tight angle are rejected.
- An accepted proposal is built and added to the city, connecting the source to a new or existing target node.
Traffic is periodically simulated between residential and commercial areas. Candidate roads become permanent once their traffic usage passes a threshold.