## Procedural Generation of Buildings in BZFlag - It's easy!

General talk about the map making process.
Zehra
Private First Class
Posts: 909
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

### Procedural Generation of Buildings in BZFlag - It's easy!

I'll use OverDose and Urban Jungle for examples of buildings for this. (Quad/square buildings.)

Keep in mind that I may be wrong with some of the algorithms used for generating buildings. (I haven't checked my scripts, which implemented large subsets of them, but never were fully realized as an aggregation of them all, but I'm sure this works.)

There is several observations which may be noted from them.

* They tend to follow a pattern
* Those patterns repeat in a set of some sorts
* This pattern can be formulated on a set of logic conditions

In more concrete terms, there is lots of columns, walls and floor levels/stories.

5x5 will be used to better demonstrate how it is.

If we represent the columns, they may be represented as some sort of an array. (2D array.)

Code: Select all

`````` 0 1 2 3 4
0[][][][][]
1[]      []
2[]      []
3[]      []
4[][][][][]
``````
00 04 40 44 are the corners of the "building". (Keep in mind that walls can be between the columns.)

The corners of the buildings can or may use "special" handling for better structural or visual effects.

The way walls are added are that they are in between the columns.

Walls can start as the from the first column until just one before the last column.

Which results in the following:

Code: Select all

``````[]-[]-[]-[]-[]
``````
Generally speaking, the walls will be checked by conditionals similar to the following:

Code: Select all

``````if [0][]
if [4][]

if [][0]
if [][4
]``````
(4 and 0 to be substituted with needed requirements)

Special handling can be done with something similar to the following:

Code: Select all

``````if [0][0]
if [4][0]
if [0][4]
if [4][4]
``````
And last, but not least, the trick to generate stories/floor levels.

Which in short is doing a loop and changing the z axis on each loop.

So you get something like this:

Code: Select all

``````for (z = 0, z <= twenty; z++)
buildfloor(z);
``````
So to summarize it all:

Code: Select all

``````floors (for z)
(for x)
(for y)
if ([x] == 0 || [x] == 4)
buildcolumns()
if ([y] == 1 || [y] == 3)
buildcolumns()
if ([x] >= 0 && [x] <= 3)
buildwall()
if ([y] >= 0 && [y] <= 3)
buildwall()
``````
And you basically have the technique to generate buildings.

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Zehra
Private First Class
Posts: 909
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

### Re: Procedural Generation of Buildings in BZFlag - It's easy!

The following code demonstrates the principle of this:

Code: Select all

``````var zero = 0
var size = 5
var floors = 3
var x = size
var y = size
var z = floors

while z > zero:
echo "layer"
x = size
while x > zero:
echo ""
y = size
while y > zero:
echo "looping"
y = y - 1
if y == 0:
x = x - 1
if x == zero:
z = z - 1
``````
This is the inherent principle behind procedural generation. It contains none of the handling for the building walls and columns. Since this code is too simple for copyright, it is therefore in the public domain.

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.