Chapter 7 - The Planet's Surface
Table of Planetary Surface
x-coordinate | y-coordinate | elevation | feature |
a number | a number | a number | a thing |
with 364 [grid size squared] blank rows |
To decide what number is the z-coordinate of (item - a thing):
let x be the x-coordinate of the item;
let y be the y-coordinate of the item;
if the x by the y is off the grid:
decide on 0;
otherwise:
if the item is a crater, now x is x + 1; [calculate the height of the east wall rather than the bowl]
choose row x graphed by y in the Table of Planetary Surface;
decide on the elevation entry.
To decide what number is the z-coordinate of (item - a crater): [for craters, we pick a graph point that's off by one so we get the height of the crater wall rather than the height of the crater center; when you have a crater overlapping with the side of a peak this will be off but I hope to get away with it]
if the x-coordinate of the item + 1 by the y-coordinate of the item is off the grid:
decide on 0;
otherwise:
choose row x-coordinate of item + 1 graphed by y-coordinate of item in the Table of Planetary Surface;
decide on the elevation entry.
A terrain feature is a kind of thing. A terrain feature is usually improper-named.
A crater is a kind of terrain feature.
A ridge is a kind of terrain feature. A ridge can be north-south or east-west.
A peak is a kind of terrain feature.
Texture is a kind of value. The textures are jagged, crumbling, flat-topped, rounded, and pointed. A texture can be used or unused. A texture is usually unused. [This helps us make sure we don't generate more than one of each feature with the same texture.]
A terrain feature has a texture. Before printing the name of a terrain feature: say "[texture of the item described] ".
The seen name of a terrain feature is usually "[item described]". [Because the seen name is usually set to the printed name, which won't capture the texture.]
The indefinite article of a terrain feature is usually "a".
There are four craters. There are five ridges. There are three peaks.
To say a seen name of (item - a thing):
say "[if item is improper-named][indefinite article of item] [end if][seen name of item]".
When play begins:
initialize the grid map.
To dump the planet map:
say fixed letter spacing;
repeat with inverse y running from 0 to grid size - 1:
if grid size - inverse y < 10, say " ";
say grid size - inverse y;
say " ";
repeat with x running from 1 to grid size:
choose row x graphed by (grid size - inverse y) in the Table of Planetary Surface;
unless there is a feature entry:
say ",";
otherwise:
if the feature entry is a crater, say "C";
if the feature entry is a ridge, say "R";
if the feature entry is a peak, say "P";
say line break;
repeat with inverse y running from 0 to grid size - 1:
if grid size - inverse y < 10, say " ";
say grid size - inverse y;
say " ";
repeat with x running from 1 to grid size:
choose row x graphed by (grid size - inverse y) in the Table of Planetary Surface;
if the elevation entry < 0:
say "x";
otherwise:
say the elevation entry;
say line break.
To initialize the grid map:
repeat with index running from 1 to (grid size * grid size):
choose row index in the Table of Planetary Surface;
now the x-coordinate entry is (index / grid size) + 1;
now the y-coordinate entry is the remainder after dividing index by grid size;
if the y-coordinate entry is 0: [change an entry like "2, 0" to "1, 18," if the grid size is 18]
now the y-coordinate entry is grid size;
now the x-coordinate entry is the x-coordinate entry minus 1;
now the elevation entry is 0.
To decide what number is (x - a number) graphed by (y - a number):
decide on ((x - 1) * grid size) + y. [This is going to get used in looking up rows in the Table of Planetary Surface.]
The texture to be used is a texture that varies.
To randomly place the terrain features:
now every texture is unused;
repeat with feature running through craters:
now the texture to be used is a random unused texture;
deploy feature;
now every texture is unused;
repeat with feature running through ridges:
now the texture to be used is a random unused texture;
deploy feature;
now every texture is unused;
repeat with feature running through peaks:
now the texture to be used is a random unused texture;
deploy feature.
To deploy (caldera - a crater):
let placing succeeded be a truth state;
repeat with placing attempt running from 1 to 10: [we try ten times and if we can't deploy it, we give up]
now placing succeeded is true; [until we run into a problem]
now x-coordinate of caldera is a random number between 2 and grid size - 1;
now y-coordinate of caldera is a random number between 2 and grid size - 1;
repeat with obstructor running through things in the Planet:
if the squared distance from obstructor to caldera is less than 15: [I think this should prevent things from getting placed a knight's move apart or closer]
now placing succeeded is false;
break; [no need to continue with obstructor running through everything else]
if placing succeeded is true: [it's placed; give it its properties and adjust the Table of Planetary Surface accordingly]
now the texture of the caldera is the texture to be used;
now the texture to be used is used;
now the caldera is in Planet;
let crater height be a random number between 1 and 3; [craters whose centers are higher than the surrounding surface are volcanic rather than meteoric, and you can't prove they aren't]
now the sight radius of caldera is the greater of crater height + 1 and 3; [since we actually measure from crater center, we add one to make it easier to see the crater wall]
repeat with x running from x-coordinate of caldera - 1 to x-coordinate of caldera + 1:
repeat with y running from y-coordinate of caldera - 1 to y-coordinate of caldera + 1: [this is going to create a square crater]
choose row x graphed by y in the Table of Planetary Surface;
now the elevation entry is crater height;
now the feature entry is caldera;
if x is the x-coordinate of caldera and y is the y-coordinate of caldera:
let depth be a random number between 1 and 2;
now the elevation entry is crater height minus depth;
break; [this breaks out of the placing attempt loop]
if placing succeeded is false: [we couldn't place it, so we reset its coordinates]
now x-coordinate of caldera is -99;
now y-coordinate of caldera is -99.
To deploy (spine - a ridge):
let placing succeeded be a truth state;
repeat with placing attempt running from 1 to 10: [we try ten times and if we can't deploy it, we give up]
now placing succeeded is true; [until we run into a problem]
now x-coordinate of spine is a random number between 2 and grid size - 1;
now y-coordinate of spine is a random number between 2 and grid size - 1;
repeat with obstructor running through things in the Planet:
if the squared distance from obstructor to spine is less than 13: [ridges can be a bit closer than craters]
now placing succeeded is false;
break; [no need to continue with obstructor running through everything else]
if placing succeeded is true: [it's placed; give it its properties and adjust the Table of Planetary Surface accordingly]
now the texture of the spine is the texture to be used;
now the texture to be used is used;
now the spine is in Planet;
let ridge height be a random number between 1 and 2;
now the sight radius of spine is 2;
if a random chance of 1 in 2 succeeds: [determines whether the ridge runs north-south or east-west]
now spine is east-west;
repeat with x running from x-coordinate of spine - 1 to x-coordinate of spine + 1:
choose row x graphed by y-coordinate of spine in the Table of Planetary Surface;
now the elevation entry is ridge height;
now the feature entry is spine;
otherwise:
now spine is north-south;
repeat with y running from y-coordinate of spine - 1 to y-coordinate of spine + 1:
choose row x-coordinate of spine graphed by y in the Table of Planetary Surface;
now the elevation entry is ridge height;
now the feature entry is spine;
break; [this breaks out of the placing attempt loop]
if placing succeeded is false: [we couldn't place it, so we reset its coordinates]
now x-coordinate of spine is -99;
now y-coordinate of spine is -99.
To deploy (mountain - a peak):
let placing succeeded be a truth state;
repeat with placing attempt running from 1 to 10: [we try ten times and if we can't deploy it, we give up]
now placing succeeded is true; [until we run into a problem]
now x-coordinate of mountain is a random number between 2 and grid size - 1;
now y-coordinate of mountain is a random number between 2 and grid size - 1;
repeat with obstructor running through things in the Planet:
if the squared distance from obstructor to mountain is less than 15: [I think this should prevent things from getting placed a knight's move apart or closer]
now placing succeeded is false;
break; [no need to continue with obstructor running through everything else]
if placing succeeded is true: [it's placed; give it its properties and adjust the Table of Planetary Surface accordingly]
now the texture of the mountain is the texture to be used;
now the texture to be used is used;
now the mountain is in Planet;
let mountain height be a random number between 2 and 4;
now the sight radius of mountain is mountain height;
repeat with x-increment running from 0 - mountain height to mountain height: [lower things gradually in a square from the peak]
repeat with y-increment running from 0 - mountain height to mountain height:
let new x be x-coordinate of mountain plus x-increment;
let new y be y-coordinate of mountain plus y-increment;
if new x by new y is on the grid: [peaks can go off the map so we sanity check]
choose row new x graphed by new y in the Table of Planetary Surface;
let z be mountain height minus (the greater of the integer absolute value of x-increment and the integer absolute value of y-increment);
increase the elevation entry by z;
if z >= mountain height - 1: [only the very top shows up as a peak on the feature map]
now the feature entry is the mountain;
break; [out of the placing attempt loop, since placing succeeded is true]
if placing succeeded is false: [we couldn't place it, so we reset its coordinates]
now x-coordinate of mountain is -99;
now y-coordinate of mountain is -99.