The town-building half of RampageWorld. Lays out a 4x4 grid of blocks separated by roads, decides what each lot is (houses, shops, offices, studio, church, farm, lab, petrol station, water tower, supermarket, arena, civic) and records building, toppler and prop plans plus street furniture and landmarks as plain numbers. Also builds the flat ground meshes for asphalt, pavement, lot surfaces, road markings, the manhole and a ring of background hills.
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// The town plan. A grid of five roads each way cuts the town into sixteen blocks; each block is
/// one kind of lot. The middle four are downtown (shops, offices, the TV studio, the church), the
/// corners hold the farm, the government lab, the petrol station and the water tower, and the
/// rest are houses, a supermarket, the arena and the civic buildings. The lizard comes up out of
/// a manhole in the central crossroads.
///
/// Everything here only writes plans (numbers): buildings and towers to build, and a spot for
/// every prop, sorted into cells. Nothing is made into objects until <c>RaiseTown</c>.
/// </summary>
public sealed partial class RampageWorld
{
const int Blocks = 4;
const float BlockSize = 2600f, BlockHalf = BlockSize * 0.5f;
/// <summary>A road with both its pavements.</summary>
const float RoadWidth = 640f;
const float PavementWidth = 120f;
/// <summary>Half the width of the grid of streets. Beyond it is grass, out to the edge of the world.</summary>
const float TownHalf = (Blocks * BlockSize + (Blocks + 1) * RoadWidth) * 0.5f;
/// <summary>How far the ground is drawn and solid, past the unseen walls.</summary>
const float Outer = 10400f;
/// <summary>Nothing is put down this close to the manhole.</summary>
const float SpawnClear = 380f;
static float RoadCentre( int i ) => -TownHalf + RoadWidth * 0.5f + i * (BlockSize + RoadWidth);
static float BlockCentre( int b ) => -TownHalf + RoadWidth + BlockHalf + b * (BlockSize + RoadWidth);
static bool OnRoadAxis( float v )
{
for ( int i = 0; i <= Blocks; i++ )
if ( MathF.Abs( v - RoadCentre( i ) ) <= RoadWidth * 0.5f ) return true;
return false;
}
enum Lot { Houses, Shops, Offices, Studio, Church, Farm, Lab, Petrol, Water, Market, Arena, Civic }
bool _familyHome;
/// <summary>What is on each block: the first index runs along X, the second along Y.</summary>
static readonly Lot[][] Lots =
{
new[] { Lot.Farm, Lot.Houses, Lot.Houses, Lot.Water },
new[] { Lot.Houses, Lot.Shops, Lot.Studio, Lot.Houses },
new[] { Lot.Civic, Lot.Church, Lot.Offices, Lot.Market },
new[] { Lot.Petrol, Lot.Houses, Lot.Arena, Lot.Lab },
};
static readonly string[] HouseLabels =
{
"NUMBER 14", "THE HENDERSONS'", "A STARTER HOME", "BUNGALOW (NEGATIVE EQUITY)", "SOMEBODY'S FOREVER HOME",
"HOUSE WITH THE NICE CURTAINS", "NUMBER 22 (NEVER LIKED THEM)", "A FIXER-UPPER (NOW MORE SO)", "THE NEIGHBOURHOOD WATCH HQ",
};
static readonly string[] ShopLabels =
{
"BAKERY", "SHOE SHOP", "VAPE EMPORIUM", "ESTATE AGENT", "ARTISANAL CANDLE SHOP", "PHONE REPAIR KIOSK", "BETTING SHOP",
"THE GOOD PUB", "CHARITY SHOP", "NAIL BAR", "PET SHOP (EVERYONE GOT OUT)", "THIRD COFFEE SHOP",
};
// ---- Small helpers ---------------------------------------------------------------------------
float R( float a, float b ) => a + (float)_rng.NextDouble() * (b - a);
bool Chance( float p ) => _rng.NextDouble() < p;
T Pick<T>( T[] from ) => from[_rng.Next( from.Length )];
void Landmark( string name, float x, float y )
{
_landmarks.Add( new Vector3( x, y, 0f ) );
_landmarkNames.Add( name );
}
/// <summary>Notes down one prop at a spot in the world.</summary>
PropSpot Prop( PropKind kind, float x, float y, float yaw = 0f, bool force = false )
{
if ( MathF.Abs( x ) > HalfSize - 120f || MathF.Abs( y ) > HalfSize - 120f ) return null;
if ( !force && x * x + y * y < SpawnClear * SpawnClear ) return null;
var spot = new PropSpot { Kind = kind, Position = new Vector3( x, y, 0f ), Yaw = yaw, Body = Pick( kind.BodyColours ), Label = Pick( kind.Labels ) };
CellAt( spot.Position ).Spots.Add( spot );
return spot;
}
/// <summary>
/// Every building's storeys are this many times as tough as its plan says. The plans were written
/// for a lizard-sized player; against a giant (whose whip is a car's worth and whose flail is a
/// house's) this keeps a building worth several blows, or one mega-swing.
/// </summary>
const float BuildingToughness = 2.5f;
/// <summary>Notes down one building.</summary>
BuildingPlan Plot( string label, float points, float x, float y, float sx, float sy, int storeys, float storeyHeight, float storeyHealth,
Color wall, RoofKind roof, Color roofColour )
{
var plan = new BuildingPlan
{
Label = label, Points = points, Centre = new Vector3( x, y, 0f ), SizeX = sx, SizeY = sy, Storeys = storeys,
StoreyHeight = storeyHeight, StoreyHealth = storeyHealth * BuildingToughness, Wall = wall, Roof = roof, RoofColour = roofColour,
};
_buildingPlans.Add( plan );
return plan;
}
/// <summary>Notes down one tall thing that topples. Its shape is filled in by the caller.</summary>
TopplerPlan Tall( string label, float points, float health, float x, float y, TopplerKind kind, float yaw = 0f )
{
var plan = new TopplerPlan { Label = label, Points = points, Health = health, Base = new Vector3( x, y, 0f ), Kind = kind, Yaw = yaw };
_topplerPlans.Add( plan );
return plan;
}
PropKind RandomVehicle()
{
double roll = _rng.NextDouble();
return roll < 0.66 ? Props.Car : roll < 0.78 ? Props.Van : roll < 0.87 ? Props.Taxi : Props.Pickup;
}
void Billboard( float x, float y, float yaw, string label )
{
var board = Tall( label, 150f, 120f, x, y, TopplerKind.Billboard, yaw );
board.Shape.Box( 0f, -120f, 0f, 10f, 10f, 260f, Tone.Slate ).Box( 0f, 120f, 0f, 10f, 10f, 260f, Tone.Slate )
.Box( 0f, 0f, 240f, 12f, 340f, 150f, Tone.White ).Box( 7f, 0f, 255f, 2f, 310f, 120f, Pick( new[] { Tone.Red, Tone.Blue, Tone.Yellow, Tone.Pink } ) );
}
// ---- The plan ----------------------------------------------------------------------------------
void PlanTown()
{
PlayerSpawn = new Vector3( 0f, 0f, 2f );
PlayerSpawnYaw = 0f;
Landmark( "TOWN SQUARE", 0f, 0f );
for ( int bx = 0; bx < Blocks; bx++ )
for ( int by = 0; by < Blocks; by++ )
{
float cx = BlockCentre( bx ), cy = BlockCentre( by );
switch ( Lots[bx][by] )
{
case Lot.Houses: LotHouses( cx, cy, -1f, 1f ); break;
case Lot.Shops: LotShops( cx, cy ); break;
case Lot.Offices: LotOffices( cx, cy ); break;
case Lot.Studio: LotStudio( cx, cy ); break;
case Lot.Church: LotChurch( cx, cy ); break;
case Lot.Farm: LotFarm( cx, cy ); break;
case Lot.Lab: LotLab( cx, cy ); break;
case Lot.Petrol: LotPetrol( cx, cy ); break;
case Lot.Water: LotWater( cx, cy ); break;
case Lot.Market: LotMarket( cx, cy ); break;
case Lot.Arena: LotArena( cx, cy ); break;
case Lot.Civic: LotCivic( cx, cy ); break;
}
}
PlanStreets();
PlanOutskirts();
// Somewhere to stand, every so often along both pavements of every road.
float pavement = RoadWidth * 0.5f - PavementWidth * 0.5f;
for ( int i = 0; i <= Blocks; i++ )
for ( float t = -TownHalf + 150f; t <= TownHalf - 150f; t += 500f )
foreach ( float side in new[] { -1f, 1f } )
{
_streetPoints.Add( new Vector3( t, RoadCentre( i ) + side * pavement, 0f ) );
_streetPoints.Add( new Vector3( RoadCentre( i ) + side * pavement, t, 0f ) );
}
}
// ---- Streets -----------------------------------------------------------------------------------
void PlanStreets()
{
for ( int i = 0; i <= Blocks; i++ )
for ( int b = 0; b < Blocks; b++ )
{
bool downtown = i >= 1 && i <= 3 && b >= 1 && b <= 2;
PlanSegment( true, RoadCentre( i ), BlockCentre( b ), downtown );
PlanSegment( false, RoadCentre( i ), BlockCentre( b ), downtown );
}
// The crossroads: a manhole cover each, and now and then some roadworks nobody is doing.
for ( int i = 0; i <= Blocks; i++ )
for ( int j = 0; j <= Blocks; j++ )
{
float x = RoadCentre( i ), y = RoadCentre( j );
Prop( Props.ManholeCover, x + R( -140f, 140f ), y + R( -140f, 140f ) );
if ( !Chance( 0.4f ) ) continue;
float wx = x + R( -120f, 120f ), wy = y + R( -120f, 120f );
for ( int k = 0; k < 4; k++ ) Prop( Props.Cone, wx + (k % 2) * 60f, wy + (k / 2) * 60f );
}
// The lid of the hole the lizard came out of, thrown aside.
Prop( Props.ManholeCover, 110f, 70f, 20f, force: true );
}
/// <summary>
/// One stretch of road between two crossroads, with what stands along it. Positions are given
/// along the road (t) and across it (off, positive to the left of the way t runs).
/// </summary>
void PlanSegment( bool alongX, float road, float mid, bool downtown )
{
void Put( PropKind kind, float t, float off, float yaw )
{
if ( alongX ) Prop( kind, mid + t, road + off, yaw );
else Prop( kind, road - off, mid + t, yaw + 90f );
}
// The yaw that points a thing's front across the pavement at the middle of the road.
float Face( float side ) => side > 0f ? -90f : 90f;
float kerb = RoadWidth * 0.5f - PavementWidth + 16f; // on the pavement, by the road
float back = RoadWidth * 0.5f - 22f; // on the pavement, by the lots
for ( int k = 0; k < 5; k++ )
{
float side = k % 2 == 0 ? 1f : -1f;
Put( Props.Lamppost, -1040f + k * 520f, side * kerb, Face( side ) );
}
foreach ( float side in new[] { -1f, 1f } )
{
for ( int k = 0; k < 5; k++ )
if ( Chance( 0.55f ) ) Put( Props.Tree, -1170f + k * 520f + R( -40f, 40f ), side * back, R( 0f, 360f ) );
Put( Props.Bin, R( -1200f, 1200f ), side * back, 0f );
if ( Chance( 0.5f ) ) Put( Props.Bin, R( -1200f, 1200f ), side * back, 0f );
if ( Chance( 0.5f ) ) Put( Props.Bench, R( -1100f, 1100f ), side * (back - 6f), side > 0f ? 180f : 0f );
if ( Chance( 0.4f ) ) Put( Props.Mailbox, R( -1100f, 1100f ), side * (kerb + 10f), Face( side ) );
if ( Chance( 0.3f ) ) Put( Props.NewsStand, R( -1100f, 1100f ), side * (back - 10f), Face( side ) );
if ( Chance( 0.2f ) ) Put( Props.PhoneBox, R( -1100f, 1100f ), side * (back - 14f), 0f );
if ( Chance( 0.15f ) ) Put( Props.BusShelter, R( -900f, 900f ), side * (back - 26f), side > 0f ? 180f : 0f );
if ( downtown && Chance( 0.4f ) ) Put( Props.HotDogStand, R( -1000f, 1000f ), side * (back - 30f), 0f );
Put( downtown ? Props.TrafficLight : Props.StopSign, side > 0f ? -1255f : 1255f, side * kerb, side > 0f ? 0f : 180f );
// Parked along the kerb.
for ( int k = 0; k < 9; k++ )
{
if ( !Chance( downtown ? 0.5f : 0.33f ) ) continue;
float t = -1000f + k * 250f + R( -20f, 20f );
Put( RandomVehicle(), t, side * 152f, (side > 0f ? 180f : 0f) + R( -4f, 4f ) );
if ( downtown && Chance( 0.6f ) ) Put( Props.ParkingMeter, t + 60f, side * kerb, 0f );
}
}
Put( Props.Hydrant, R( -1100f, 1100f ), (Chance( 0.5f ) ? 1f : -1f) * kerb, 0f );
// Stopped in the road, engines running, drivers gone.
for ( int k = 0; k < (downtown ? 2 : 1); k++ )
{
if ( !Chance( 0.7f ) ) continue;
float side = Chance( 0.5f ) ? 1f : -1f;
Put( Chance( 0.1f ) ? Props.Bus : RandomVehicle(), R( -1000f, 1000f ), side * 62f, (side > 0f ? 180f : 0f) + R( -8f, 8f ) );
}
}
/// <summary>The grass between the last road and the edge of the world: trees.</summary>
void PlanOutskirts()
{
for ( int i = 0; i < 420; i++ )
{
float x = R( -HalfSize + 200f, HalfSize - 200f ), y = R( -HalfSize + 200f, HalfSize - 200f );
if ( MathF.Max( MathF.Abs( x ), MathF.Abs( y ) ) < TownHalf + 90f ) continue;
Prop( Chance( 0.85f ) ? Props.Tree : Props.Hedge, x, y, R( 0f, 360f ) );
}
}
// ---- Lots --------------------------------------------------------------------------------------
/// <summary>A row of three houses along each given side of the block (-1 and 1 along Y), gardens and all.</summary>
void LotHouses( float cx, float cy, params float[] sides )
{
foreach ( float side in sides )
for ( int ix = -1; ix <= 1; ix++ )
House( cx + ix * 820f + R( -30f, 30f ), cy + side * 800f, side );
for ( int i = 0; i < 5; i++ ) Prop( Props.Tree, cx + R( -1150f, 1150f ), cy + R( -120f, 120f ), R( 0f, 360f ) );
}
/// <summary>One house, its front to the street on the given side, with the things people keep round a house.</summary>
void House( float x, float y, float side )
{
// One house is the family's who bought the pet: the humans module looks for a landmark
// with "home" or "family" in its name and puts the child and its parents on the pavement there.
if ( !_familyHome ) { _familyHome = true; Landmark( "THE FAMILY HOME", x, y + side * 600f ); }
float sx = R( 400f, 520f ), sy = R( 340f, 420f );
int storeys = Chance( 0.4f ) ? 2 : 1;
var plan = Plot( Pick( HouseLabels ), storeys == 2 ? 500f : 400f, x, y, sx, sy, storeys, 110f, 140f, Pick( Tone.Pastels ), RoofKind.Gable, Pick( Tone.Roofs ) );
plan.Add( 0, R( -80f, 80f ), side * (sy * 0.5f + 1f), 0f, 44f, 4f, 84f, Tone.Wood );
float fence = y + side * 470f; // the front fence, just inside the pavement
float yard = y + side * 340f; // the front garden
float garden = y - side * 330f; // the back garden
for ( int k = -4; k <= 3; k++ )
if ( k != -1 && k != 0 ) Prop( Props.Fence, x + (k + 0.5f) * 96f, fence, 0f );
Prop( Props.HouseMailbox, x + 70f, fence, 90f );
if ( Chance( 0.55f ) ) Prop( Props.Gnome, x + R( -180f, 180f ), yard + R( -40f, 40f ), R( 0f, 360f ) );
if ( Chance( 0.3f ) ) Prop( Props.Flamingo, x + R( -180f, 180f ), yard + R( -40f, 40f ), R( 0f, 360f ) );
if ( Chance( 0.5f ) ) Prop( Props.Hedge, x - 200f, y + side * (sy * 0.5f + 60f), 0f );
if ( Chance( 0.6f ) ) Prop( RandomVehicle(), x - sx * 0.5f - 80f, y + side * 120f, side > 0f ? 90f : -90f );
Prop( Props.Bin, x + sx * 0.5f + 40f, y, 0f );
var back = Pick( new[] { Props.Shed, Props.Barbecue, Props.PaddlingPool, Props.Tree, Props.Barbecue } );
Prop( back, x + R( -120f, 120f ), garden, R( 0f, 360f ) );
}
/// <summary>The shopping street: two terraces of shops back to back across a yard of tables and bins.</summary>
void LotShops( float cx, float cy )
{
Landmark( "SHOPPING STREET", cx, cy );
var walls = new[] { Tone.Brick, Tone.Stone, Tone.Pastels[0], Tone.Pastels[2], Tone.Pastels[4], Tone.Sand };
var awnings = new[] { Tone.Red, Tone.Green, Tone.Blue, Tone.Yellow, Tone.Pink, Tone.Orange };
foreach ( float side in new[] { -1f, 1f } )
for ( int i = 0; i < 4; i++ )
{
float x = cx - 960f + i * 640f, y = cy + side * 880f;
const float sx = 600f, sy = 620f;
int storeys = Chance( 0.5f ) ? 2 : 1;
var awning = Pick( awnings );
var plan = Plot( Pick( ShopLabels ), 500f, x, y, sx, sy, storeys, 130f, 170f, Pick( walls ), RoofKind.Flat, Tone.Slate );
plan.Add( 0, 0f, side * (sy * 0.5f + 26f), 88f, sx * 0.9f, 52f, 6f, awning );
plan.Add( 0, 0f, side * (sy * 0.5f + 1f), 0f, 60f, 4f, 88f, Tone.Dark );
plan.Add( -1, 0f, side * (sy * 0.5f - 12f), 12f, sx * 0.7f, 10f, 46f, awning );
Prop( Props.Dumpster, x + R( -150f, 150f ), cy + side * 500f, R( -10f, 10f ) );
}
for ( int i = 0; i < 9; i++ ) Prop( Props.CafeTable, cx + R( -1100f, 1100f ), cy + R( -330f, 330f ), R( 0f, 360f ) );
for ( int i = 0; i < 4; i++ ) Prop( Props.Tree, cx - 900f + i * 600f, cy, R( 0f, 360f ) );
for ( int i = 0; i < 4; i++ ) Prop( Props.Bench, cx - 600f + i * 400f, cy + R( -200f, 200f ), R( 0f, 360f ) );
Prop( Props.HotDogStand, cx - 300f, cy + 120f, 0f );
Prop( Props.HotDogStand, cx + 500f, cy - 160f, 90f );
for ( int i = 0; i < 4; i++ ) Prop( Props.Bin, cx + R( -1100f, 1100f ), cy + R( -300f, 300f ), 0f );
}
/// <summary>Two office towers and the tax office, round a plaza with a statue nobody liked.</summary>
void LotOffices( float cx, float cy )
{
Landmark( "OFFICE TOWERS", cx, cy );
var steel = new Color( 0.4f, 0.46f, 0.54f );
Plot( "MIDDLE MANAGEMENT TOWER", 2200f, cx - 650f, cy - 600f, 800f, 800f, 9, 140f, 260f, steel, RoofKind.Flat, Tone.Slate )
.Add( -1, 150f, 150f, 12f, 200f, 160f, 60f, Tone.Metal ).Add( -1, -200f, -200f, 12f, 12f, 12f, 240f, Tone.Metal )
.Add( 0, 0f, 401f, 0f, 160f, 4f, 110f, Tone.Dark );
Plot( "INSURANCE HEADQUARTERS", 1900f, cx + 650f, cy + 600f, 760f, 900f, 7, 140f, 260f, new Color( 0.5f, 0.5f, 0.46f ), RoofKind.Flat, Tone.Slate )
.Add( -1, 0f, 0f, 12f, 300f, 300f, 50f, Tone.Metal ).Add( 0, -381f, 0f, 0f, 4f, 160f, 110f, Tone.Dark );
Plot( "TAX OFFICE", 900f, cx + 650f, cy - 750f, 900f, 560f, 3, 130f, 240f, Tone.Concrete, RoofKind.Flat, Tone.Slate )
.Add( 0, 0f, 281f, 0f, 120f, 4f, 100f, Tone.Dark ).Add( -1, 0f, 250f, 12f, 400f, 10f, 50f, Tone.Blue );
Prop( Props.Statue, cx - 550f, cy + 600f, 0f );
for ( int i = 0; i < 6; i++ ) Prop( Props.Bench, cx - 550f + MathF.Cos( i * 1.05f ) * 220f, cy + 600f + MathF.Sin( i * 1.05f ) * 220f, i * 60f + 90f );
for ( int i = 0; i < 8; i++ ) Prop( Props.Tree, cx + R( -1150f, -100f ), cy + R( 150f, 1150f ), R( 0f, 360f ) );
for ( int i = 0; i < 5; i++ ) Prop( Props.CafeTable, cx + R( -100f, 200f ), cy + R( -300f, 100f ), R( 0f, 360f ) );
for ( int i = 0; i < 6; i++ ) Prop( RandomVehicle(), cx - 100f + i * 110f, cy - 60f + R( -10f, 10f ), 90f + R( -5f, 5f ) );
for ( int i = 0; i < 4; i++ ) Prop( Props.Bin, cx + R( -1100f, 1100f ), cy + R( -100f, 100f ), 0f );
}
/// <summary>The TV studio: a big shed with a bigger sign, a dish, a mast, and its vans outside.</summary>
void LotStudio( float cx, float cy )
{
Landmark( "TV STUDIO", cx, cy + 150f );
var plan = Plot( "TV STUDIO", 2000f, cx, cy + 150f, 1400f, 1000f, 2, 170f, 350f, new Color( 0.42f, 0.46f, 0.56f ), RoofKind.Flat, Tone.Slate );
plan.Landmark = "TV STUDIO";
plan.Add( -1, 0f, -470f, 12f, 900f, 20f, 180f, Tone.Red ).Add( -1, 0f, -482f, 60f, 760f, 6f, 80f, Tone.White )
.Add( -1, 400f, 200f, 12f, 14f, 14f, 120f, Tone.Metal )
.AddTilted( -1, new Vector3( 400f, 200f, 160f ), new Vector3( 260f, 260f, 14f ), Tone.White, Rotation.FromPitch( -45f ) )
.Add( -1, -450f, 250f, 12f, 22f, 22f, 420f, Tone.Red ).Add( 0, 0f, -501f, 0f, 200f, 4f, 130f, Tone.Dark );
Plot( "THE GREEN ROOM", 300f, cx - 850f, cy - 900f, 500f, 400f, 1, 120f, 150f, Tone.Green, RoofKind.Flat, Tone.Slate );
for ( int i = 0; i < 3; i++ ) Prop( Props.NewsVan, cx + 100f + i * 260f, cy - 650f, 90f + R( -8f, 8f ) );
for ( int i = 0; i < 5; i++ ) Prop( RandomVehicle(), cx - 400f + i * 120f, cy - 1000f, 90f + R( -5f, 5f ) );
Billboard( cx + 1050f, cy - 1050f, 45f, "BILLBOARD (YOUR FACE HERE)" );
for ( int i = 0; i < 4; i++ ) Prop( Props.Tree, cx - 1150f, cy - 300f + i * 380f, R( 0f, 360f ) );
Prop( Props.HotDogStand, cx + 950f, cy - 500f, 0f );
for ( int i = 0; i < 3; i++ ) Prop( Props.Bin, cx + R( -1000f, 1000f ), cy - 480f, 0f );
}
/// <summary>The church and its steeple, in a churchyard of trees and benches.</summary>
void LotChurch( float cx, float cy )
{
Landmark( "CHURCH", cx, cy + 100f );
float nx = cx - 150f, ny = cy + 100f;
var nave = Plot( "CHURCH", 1200f, nx, ny, 1100f, 500f, 1, 260f, 350f, Tone.Stone, RoofKind.Gable, Tone.Roofs[1] );
nave.Landmark = "CHURCH";
nave.Add( 0, -551f, 0f, 0f, 4f, 120f, 170f, Tone.Wood );
var steeple = Tall( "CHURCH STEEPLE", 800f, 400f, cx + 560f, ny, TopplerKind.Steeple );
steeple.Shape.Box( 0f, 0f, 0f, 240f, 240f, 520f, Tone.Stone ).Box( 0f, 0f, 520f, 264f, 264f, 20f, Tone.Slate )
.Box( 0f, 0f, 540f, 200f, 200f, 90f, Tone.Slate ).Box( 0f, 0f, 630f, 140f, 140f, 90f, Tone.Slate ).Box( 0f, 0f, 720f, 80f, 80f, 90f, Tone.Slate )
.Box( 0f, 0f, 810f, 30f, 30f, 80f, Tone.Slate ).Box( 0f, 0f, 890f, 6f, 6f, 60f, Tone.Yellow ).Box( 0f, 0f, 920f, 6f, 36f, 6f, Tone.Yellow )
.Box( 121f, 0f, 380f, 2f, 90f, 90f, Tone.White ).Box( 0f, -121f, 380f, 90f, 2f, 90f, Tone.White );
for ( int i = 0; i < 26; i++ )
{
float x = cx + R( -1200f, 1200f ), y = cy + R( -1200f, 1200f );
// Not inside the church.
if ( MathF.Abs( x - (cx + 100f) ) < 840f && MathF.Abs( y - ny ) < 340f ) continue;
Prop( i % 4 == 0 ? Props.Hedge : i % 5 == 0 ? Props.Bench : Props.Tree, x, y, R( 0f, 360f ) );
}
}
/// <summary>The farm on the corner of town: farmhouse, barn, silo, a field of corn and the truck.</summary>
void LotFarm( float cx, float cy )
{
Landmark( "THE FARM", cx, cy + 400f );
Plot( "FARMHOUSE", 400f, cx + 750f, cy + 800f, 500f, 420f, 2, 110f, 140f, Tone.White, RoofKind.Gable, Tone.Roofs[0] )
.Add( 0, 0f, -211f, 0f, 44f, 4f, 84f, Tone.Wood );
var barn = Plot( "BARN", 600f, cx - 250f, cy + 700f, 900f, 600f, 1, 300f, 300f, Tone.Red, RoofKind.Gable, Tone.Roofs[1] );
barn.Landmark = "THE FARM";
barn.Add( 0, 0f, -301f, 0f, 260f, 4f, 230f, Tone.White ).Add( 0, 0f, -303f, 0f, 220f, 4f, 200f, Tone.Shade( Tone.Red, 0.7f ) );
var silo = Tall( "GRAIN SILO", 500f, 300f, cx - 950f, cy + 700f, TopplerKind.Silo );
silo.Shape.Drum( 0f, 0f, 0f, 240f, 560f, Tone.Metal ).Drum( 0f, 0f, 560f, 200f, 50f, Tone.Slate ).Box( 0f, 0f, 610f, 120f, 120f, 40f, Tone.Slate )
.Box( 0f, 0f, 200f, 250f, 250f, 14f, Tone.Slate ).Box( 0f, 0f, 400f, 250f, 250f, 14f, Tone.Slate );
// The cornfield, with its scarecrow in the middle.
for ( float x = -1150f; x <= 1150f; x += 190f )
for ( float y = -1180f; y <= -160f; y += 170f )
{
if ( MathF.Abs( x ) < 100f && MathF.Abs( y + 670f ) < 90f ) continue;
Prop( Props.Corn, cx + x + R( -30f, 30f ), cy + y + R( -30f, 30f ), R( 0f, 360f ) );
}
Prop( Props.Scarecrow, cx, cy - 670f, 90f );
for ( float x = -1150f; x <= 1150f; x += 96f ) Prop( Props.Fence, cx + x, cy - 60f, 0f );
for ( int i = 0; i < 9; i++ ) Prop( Props.HayBale, cx - 250f + R( -420f, 420f ), cy + 250f + R( -90f, 90f ), R( 0f, 360f ) );
Prop( Props.Tractor, cx + 300f, cy + 200f, 30f );
Prop( Props.Pickup, cx + 750f, cy + 440f, 170f );
Prop( Props.Shed, cx + 1100f, cy + 300f, 0f );
for ( int i = 0; i < 4; i++ ) Prop( Props.Tree, cx + 1150f, cy + 500f + i * 200f, R( 0f, 360f ) );
}
/// <summary>The government lab: a white block behind a fence, with a guard hut on the gate.</summary>
void LotLab( float cx, float cy )
{
Landmark( "GOVERNMENT LAB", cx, cy );
var lab = Plot( "GOVERNMENT LAB", 2500f, cx, cy + 50f, 1300f, 1000f, 3, 160f, 500f, Tone.White, RoofKind.Flat, Tone.Metal );
lab.Landmark = "GOVERNMENT LAB";
lab.Add( -1, -300f, 200f, 12f, 200f, 160f, 60f, Tone.Metal ).Add( -1, 400f, -300f, 12f, 10f, 10f, 260f, Tone.Metal )
.Add( -1, 0f, -480f, 12f, 500f, 12f, 70f, Tone.Blue ).Add( 0, 0f, -501f, 0f, 130f, 4f, 110f, Tone.Slate )
.Add( 0, 0f, -502f, 110f, 1300f, 4f, 12f, Tone.Yellow );
Plot( "GUARD HUT", 150f, cx - 260f, cy - 1040f, 170f, 170f, 1, 100f, 80f, Tone.White, RoofKind.Flat, Tone.Blue );
// The fence, all the way round, but for the gate.
const float ring = 1180f;
for ( float t = -1140f; t <= 1140f; t += 120f )
{
if ( MathF.Abs( t ) > 130f ) Prop( Props.ChainFence, cx + t, cy - ring, 0f );
Prop( Props.ChainFence, cx + t, cy + ring, 0f );
Prop( Props.ChainFence, cx - ring, cy + t, 90f );
Prop( Props.ChainFence, cx + ring, cy + t, 90f );
}
Prop( Props.BarrierGate, cx + 20f, cy - ring, 0f );
for ( int i = 0; i < 12; i++ ) Prop( Props.Barrel, cx + 800f + R( -150f, 150f ), cy - 700f + R( -200f, 200f ), R( 0f, 360f ) );
for ( int i = 0; i < 5; i++ ) Prop( Props.Van, cx - 900f, cy - 400f + i * 150f, R( -5f, 5f ) );
for ( int i = 0; i < 4; i++ ) Prop( Props.Lamppost, cx - 1000f + i * 660f, cy - 900f, 90f );
Prop( Props.Transformer, cx + 950f, cy + 900f, 0f );
Prop( Props.Dumpster, cx - 800f, cy + 800f, 0f );
}
/// <summary>The petrol station: pumps under a canopy, a tanker making a delivery, a diner, a substation.</summary>
void LotPetrol( float cx, float cy )
{
Landmark( "PETROL STATION", cx - 350f, cy + 350f );
Plot( "PETROL STATION SHOP", 500f, cx + 550f, cy + 450f, 600f, 500f, 1, 130f, 170f, Tone.White, RoofKind.Flat, Tone.Red )
.Add( 0, -301f, 0f, 0f, 4f, 120f, 100f, Tone.Dark );
float px = cx - 350f, py = cy + 350f;
var canopy = Tall( "FORECOURT CANOPY", 300f, 220f, px, py, TopplerKind.Plain );
canopy.SolidFrom = 170f;
canopy.Shape.Box( 0f, 0f, 170f, 720f, 420f, 26f, Tone.White ).Box( 0f, 0f, 176f, 726f, 426f, 10f, Tone.Red );
foreach ( float x in new[] { -300f, 300f } )
foreach ( float y in new[] { -150f, 150f } )
canopy.Shape.Box( x, y, 0f, 16f, 16f, 170f, Tone.White );
foreach ( float x in new[] { -200f, 0f, 200f } )
foreach ( float y in new[] { -80f, 80f } )
Prop( Props.Pump, px + x, py + y, 90f );
Prop( Props.Car, px - 100f, py - 190f, R( -5f, 5f ) );
Prop( Props.Van, px + 110f, py + 190f, 180f + R( -5f, 5f ) );
Prop( Props.Tanker, px, py - 520f, 0f );
Prop( Props.PriceSign, cx - 1150f, cy + 1150f, 45f );
Plot( "DINER", 500f, cx - 650f, cy - 750f, 700f, 450f, 1, 130f, 170f, Tone.Metal, RoofKind.Flat, Tone.Red )
.Add( -1, 0f, 0f, 12f, 300f, 12f, 60f, Tone.Pink ).Add( 0, 0f, 226f, 0f, 60f, 4f, 90f, Tone.Dark );
for ( int i = 0; i < 5; i++ ) if ( Chance( 0.7f ) ) Prop( RandomVehicle(), cx - 900f + i * 130f, cy - 380f, 90f + R( -5f, 5f ) );
Prop( Props.Dumpster, cx - 200f, cy - 800f, 90f );
// The substation in the corner.
for ( int i = 0; i < 3; i++ ) Prop( Props.Transformer, cx + 780f + i * 120f, cy - 950f, 90f );
for ( float t = -180f; t <= 180f; t += 120f )
{
Prop( Props.ChainFence, cx + 900f + t, cy - 780f, 0f );
Prop( Props.ChainFence, cx + 900f + t, cy - 1120f, 0f );
}
for ( int i = 0; i < 6; i++ ) Prop( Props.Cone, cx + R( -200f, 400f ), cy + R( -300f, 0f ) );
}
/// <summary>The water tower, over a row of houses that are about to regret it.</summary>
void LotWater( float cx, float cy )
{
Landmark( "WATER TOWER", cx + 400f, cy + 500f );
LotHouses( cx, cy, -1f );
var tower = Tall( "WATER TOWER", 900f, 350f, cx + 400f, cy + 500f, TopplerKind.WaterTower );
tower.Landmark = "WATER TOWER";
tower.SolidFrom = 520f;
foreach ( float x in new[] { -130f, 130f } )
foreach ( float y in new[] { -130f, 130f } )
tower.Shape.Box( x, y, 0f, 18f, 18f, 520f, Tone.Metal );
tower.Shape.Box( 0f, 0f, 250f, 280f, 8f, 8f, Tone.Metal ).Box( 0f, 0f, 250f, 8f, 280f, 8f, Tone.Metal )
.Drum( 0f, 0f, 520f, 380f, 240f, Tone.White ).Drum( 0f, 0f, 760f, 300f, 40f, Tone.Slate ).Box( 0f, 0f, 610f, 392f, 392f, 30f, Tone.Blue );
for ( int i = 0; i < 8; i++ ) Prop( Props.Tree, cx + R( -1150f, 0f ), cy + R( 200f, 1150f ), R( 0f, 360f ) );
for ( int i = 0; i < 3; i++ ) Prop( Props.Bench, cx + R( 0f, 1000f ), cy + R( 900f, 1100f ), R( 0f, 360f ) );
}
/// <summary>The supermarket and its car park: a lot of cars, a lot of trolleys.</summary>
void LotMarket( float cx, float cy )
{
Landmark( "SUPERMARKET", cx, cy + 600f );
Plot( "SUPERMARKET", 1200f, cx, cy + 650f, 1800f, 900f, 1, 230f, 500f, new Color( 0.76f, 0.74f, 0.68f ), RoofKind.Flat, Tone.Slate )
.Add( -1, 0f, -440f, 12f, 700f, 14f, 110f, Tone.Green ).Add( 0, 0f, -451f, 0f, 300f, 4f, 140f, Tone.Dark )
.Add( 0, 0f, -452f, 150f, 1800f, 4f, 30f, Tone.Green );
foreach ( float row in new[] { -150f, -520f, -890f } )
for ( int i = 0; i < 11; i++ )
if ( Chance( 0.55f ) ) Prop( RandomVehicle(), cx - 1000f + i * 200f, cy + row, (Chance( 0.5f ) ? 90f : -90f) + R( -4f, 4f ) );
for ( int i = 0; i < 14; i++ ) Prop( Props.Trolley, cx + R( -1100f, 1100f ), cy + R( -1050f, 100f ), R( 0f, 360f ) );
for ( int i = 0; i < 4; i++ ) Prop( Props.Lamppost, cx - 900f + i * 600f, cy - 335f, 90f );
for ( int i = 0; i < 3; i++ ) Prop( Props.Bin, cx - 600f + i * 600f, cy + 150f, 0f );
Prop( Props.IceCreamVan, cx + 1050f, cy + 100f, 90f );
}
/// <summary>The front of the arena where it all started, and the fair that has grown up outside it.</summary>
void LotArena( float cx, float cy )
{
Landmark( "THE ARENA", cx + 150f, cy );
var arena = Plot( "THE COLOSSEUM (GIFT SHOP END)", 2000f, cx + 150f, cy, 1700f, 1500f, 2, 280f, 700f, Tone.Sand, RoofKind.Flat, Tone.Shade( Tone.Sand, 0.8f ) );
arena.Landmark = "THE ARENA";
for ( int i = 0; i < 6; i++ )
{
arena.Add( 0, -880f, -600f + i * 240f, 0f, 50f, 50f, 280f, Tone.Stone );
arena.Add( 1, -880f, -600f + i * 240f, 0f, 50f, 50f, 280f, Tone.Stone );
}
arena.Add( 1, -853f, 0f, 60f, 4f, 600f, 120f, Tone.Red ).Add( 0, -851f, 0f, 0f, 4f, 200f, 200f, Tone.Dark );
for ( int i = 0; i < 5; i++ ) Prop( Props.Portaloo, cx - 1150f, cy - 800f + i * 70f, 0f );
Prop( Props.HotDogStand, cx - 900f, cy - 300f, 0f );
Prop( Props.HotDogStand, cx - 950f, cy + 150f, 90f );
Prop( Props.IceCreamVan, cx - 1050f, cy - 1050f, 0f );
Prop( Props.Bus, cx - 1080f, cy + 600f, 90f );
Prop( Props.Bus, cx - 940f, cy + 640f, 90f );
Billboard( cx - 1050f, cy + 1130f, -45f, "BILLBOARD (INJURY LAWYERS)" );
for ( int i = 0; i < 8; i++ ) Prop( Props.Barricade, cx - 860f, cy - 420f + i * 120f, 90f );
for ( int i = 0; i < 6; i++ ) Prop( Props.Bin, cx - 1000f + R( -100f, 100f ), cy + R( -600f, 400f ), 0f );
}
/// <summary>The bank, the police station and the fire station.</summary>
void LotCivic( float cx, float cy )
{
var bank = Plot( "BANK", 1000f, cx - 750f, cy + 600f, 800f, 650f, 2, 150f, 300f, Tone.Stone, RoofKind.Flat, Tone.Slate );
for ( int i = 0; i < 4; i++ ) bank.Add( 0, -300f + i * 200f, 345f, 0f, 40f, 40f, 150f, Tone.White );
bank.Add( -1, 0f, 300f, 12f, 500f, 30f, 60f, Tone.White );
Plot( "POLICE STATION", 900f, cx + 600f, cy + 600f, 900f, 650f, 2, 140f, 280f, new Color( 0.4f, 0.46f, 0.6f ), RoofKind.Flat, Tone.Slate )
.Add( 0, 0f, -326f, 0f, 100f, 4f, 100f, Tone.Dark ).Add( -1, 0f, -300f, 12f, 300f, 10f, 44f, Tone.Blue );
var fire = Plot( "FIRE STATION", 900f, cx - 100f, cy - 650f, 1100f, 700f, 2, 160f, 280f, Tone.Brick, RoofKind.Flat, Tone.Slate );
for ( int i = 0; i < 3; i++ ) fire.Add( 0, -300f + i * 300f, 351f, 0f, 220f, 4f, 130f, Tone.Red );
for ( int i = 0; i < 4; i++ ) Prop( Props.PoliceCar, cx + 300f + i * 190f, cy + 100f, 90f + R( -5f, 5f ) );
for ( int i = 0; i < 6; i++ ) Prop( Props.Tree, cx + R( -1150f, 1150f ), cy + R( -100f, 120f ), R( 0f, 360f ) );
for ( int i = 0; i < 3; i++ ) Prop( Props.Bench, cx - 750f + (i - 1) * 200f, cy + 180f, 0f );
Prop( Props.Hydrant, cx - 100f, cy - 250f, 0f );
Prop( Props.Hydrant, cx + 300f, cy - 250f, 0f );
Prop( Props.Dumpster, cx + 900f, cy - 700f, 0f );
}
// ---- What is drawn on the ground ---------------------------------------------------------------
/// <summary>The roads, pavements, lots and grass, as one flat mesh per colour with no overlaps; the manhole; the hills.</summary>
void BuildGround()
{
var asphalt = new TownMesh { Tint = Tone.Asphalt };
var pavement = new TownMesh { Tint = Tone.Pavement };
var grass = new TownMesh { Tint = Tone.Grass };
var concrete = new TownMesh { Tint = Tone.Concrete };
var dirt = new TownMesh { Tint = Tone.Dirt };
var line = new TownMesh { Tint = Tone.Line };
// Along each axis the ground is strips: outside, then road, block, road, block... and outside again.
var spans = new List<(float From, float To, int Kind, int Index)> { (-Outer, -TownHalf, 0, 0) };
for ( int i = 0; i <= Blocks; i++ )
{
spans.Add( (RoadCentre( i ) - RoadWidth * 0.5f, RoadCentre( i ) + RoadWidth * 0.5f, 1, i) );
if ( i < Blocks ) spans.Add( (BlockCentre( i ) - BlockHalf, BlockCentre( i ) + BlockHalf, 2, i) );
}
spans.Add( (TownHalf, Outer, 0, 0) );
float lane = RoadWidth * 0.5f - PavementWidth;
foreach ( var sx in spans )
foreach ( var sy in spans )
{
if ( sx.Kind == 0 || sy.Kind == 0 )
{
grass.Flat( sx.From, sy.From, sx.To, sy.To, 0f );
}
else if ( sx.Kind == 1 && sy.Kind == 1 )
{
asphalt.Flat( sx.From, sy.From, sx.To, sy.To, 0f );
}
else if ( sx.Kind == 1 )
{
// A road running along Y.
float c = RoadCentre( sx.Index );
pavement.Flat( sx.From, sy.From, c - lane, sy.To, 0f );
asphalt.Flat( c - lane, sy.From, c + lane, sy.To, 0f );
pavement.Flat( c + lane, sy.From, sx.To, sy.To, 0f );
for ( float t = sy.From + 100f; t < sy.To - 150f; t += 260f ) line.Flat( c - 4f, t, c + 4f, t + 110f, 1.5f );
}
else if ( sy.Kind == 1 )
{
// A road running along X.
float c = RoadCentre( sy.Index );
pavement.Flat( sx.From, sy.From, sx.To, c - lane, 0f );
asphalt.Flat( sx.From, c - lane, sx.To, c + lane, 0f );
pavement.Flat( sx.From, c + lane, sx.To, sy.To, 0f );
for ( float t = sx.From + 100f; t < sx.To - 150f; t += 260f ) line.Flat( t, c - 4f, t + 110f, c + 4f, 1.5f );
}
else
{
var lot = Lots[sx.Index][sy.Index];
var surface = lot == Lot.Farm ? dirt : lot is Lot.Houses or Lot.Water or Lot.Church ? grass : concrete;
surface.Flat( sx.From, sy.From, sx.To, sy.To, 0f );
}
}
foreach ( var mesh in new[] { asphalt, pavement, grass, concrete, dirt, line } )
{
var model = Kit.Make( mesh );
if ( model is not null ) Kit.Draw( Kit.Empty( _groundArt, "Ground" ), model, mesh.Tint, false );
}
// The hole the lizard came out of, with the road heaved up round it. None of it is solid, so
// it is kept low: the camera rides a hand's width off the ground and must clear the lot,
// or it ends up looking at the inside of a slab.
Kit.Blob( _groundArt, "Manhole", new Vector3( 0f, 0f, 0.5f ), new Vector3( 120f, 120f, 3f ), Tone.Dark );
for ( int i = 0; i < 8; i++ )
{
float angle = i * 45f + 10f;
var out_ = Rotation.FromYaw( angle ).Forward;
var slab = Kit.Block( _groundArt, "Heaved Road", out_ * 88f + Vector3.Up * 1.2f, new Vector3( 56f, 40f, 4f ), Tone.Shade( Tone.Asphalt, 0.8f + (i % 3) * 0.15f ), false );
slab.LocalRotation = Rotation.From( -3.5f, angle, 0f );
}
// A ring of hills beyond the unseen walls, so the world ends in something.
var hills = new Random( Seed + 7 );
float Roll( float a, float b ) => a + (float)hills.NextDouble() * (b - a);
for ( int side = 0; side < 4; side++ )
for ( int k = 0; k < 7; k++ )
{
float width = Roll( 3200f, 4800f ), height = Roll( 1500f, 2700f );
float along = -HalfSize * 1.15f + k * (HalfSize * 2.3f / 6f) + Roll( -300f, 300f );
float away = HalfSize + width * 0.5f + Roll( 0f, 400f );
var at = side switch { 0 => new Vector3( along, away, 0f ), 1 => new Vector3( along, -away, 0f ), 2 => new Vector3( away, along, 0f ), _ => new Vector3( -away, along, 0f ) };
Kit.Blob( _groundArt, "Hill", at.WithZ( -height * 0.12f ), new Vector3( width, width, height ), Tone.Shade( Tone.Grass, Roll( 0.72f, 0.98f ) ) );
}
}
}