Part 2 - Placing Barriers
To place barriers:
[say "Barrier placement beginning.";]
let barrier size be 0;
let barrier start be north;
let barrier end be north;
let the temporary barrier be a random barrier in Z1;
repeat with temporary locale running through Blight rooms:
DM "[temporary locale]: ";
now the permitted directions list of the temporary locale is the compass set;
now the prevented directions list of the temporary locale is {};
now barrier size is 0;
now barrier start is north;
now barrier end is north;
now the temporary barrier is a random barrier in Z1;
DM "Picking a new barrier from Z1. ";
let the primary direction be a random compass direction;
while the primary direction is not entry 1 of the compass set:
rotate the compass set;
let the terminal direction be entry 8 of the compass set;
DM "Starting barrier placement at [primary direction] and ending at [terminal direction]. ";
repeat with thataway running through the compass set:
if barrier size is 0:
if the room thataway from the temporary locale is nothing:
DM "[line break] <<Starting a new barrier to block [thataway] in [temporary locale]. ";
now barrier start is thataway;
now the temporary barrier prevents thataway;
now barrier size is 1;
move the temporary barrier to the temporary locale;
otherwise:
if the room thataway from the temporary locale is nothing:
DM "Extending the new barrier across [thataway]; ";
now barrier size is barrier size plus 1;
now the temporary barrier prevents thataway;
now barrier end is thataway;
if thataway is the terminal direction:
move the temporary barrier to the temporary locale;
DM "Placing a barrier of size [barrier size] from [barrier start] to [barrier end] - ";
let N be 0;
while N is 0:
choose a random row in the Table of Defined Barrier Types;
if (barrier size >= barrier minimum size entry) and (barrier size <= barrier maximum size entry):
DM "type [barrier-type entry] -";
now the barrier-type of the temporary barrier is barrier-type entry;
if the barrier-type of the temporary barrier is ocean:
now the indefinite article of the temporary barrier is "the edge of a";
otherwise if the barrier-type of the temporary barrier is brambles:
now the indefinite article of the temporary barrier is "a wall of";
now N is 1;
DM " in [temporary locale]. [The temporary barrier] prevents [the list of directions that are prevented by the temporary barrier].>>";
now barrier size is 0;
now barrier start is thataway;
now barrier end is thataway;
otherwise:
move the temporary barrier to the temporary locale;
DM "Placing a barrier of size [barrier size] from [barrier start] to [barrier end] - ";
let N be 0;
while N is 0:
choose a random row in the Table of Defined Barrier Types;
if (barrier size >= barrier minimum size entry) and (barrier size <= barrier maximum size entry):
DM "type [barrier-type entry] -";
now the barrier-type of the temporary barrier is barrier-type entry;
now N is 1;
DM " in [temporary locale]. [The temporary barrier] prevents [the list of directions that are prevented by the temporary barrier].>>";
now the temporary barrier is a random barrier in Z1;
DM "[line break]Picking a new barrier from Z1. ";
now barrier size is 0;
now barrier start is thataway;
now barrier end is thataway;
repeat with thataway running through the compass set:
DM "[line break]Checking [thataway] in [temporary locale]";
repeat with temporary barrier2 running through (barriers in the temporary locale):
DM " against [temporary barrier2]. ";
if thataway is listed in the permitted directions list of the temporary locale and thataway is prevented by the temporary barrier2:
DM "Removing [thataway] from the permitted directions list due to [temporary barrier2]. ";
remove thataway from the permitted directions list of the temporary locale;
add thataway to the prevented directions list of the temporary locale;
DM "[line break]***[temporary locale]'s permitted directions list: [permitted directions list of the temporary locale].";
DM "***[temporary locale]'s prevented directions list: [prevented directions list of the temporary locale]."