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

General talk about the map making process.
Zehra
Private First Class
Posts: 921
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.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Zehra
Private First Class
Posts: 921
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.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Zehra
Private First Class
Posts: 921
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 previous example doesn't seem as intuitive or easy enough to work with in general. With this in mind, the following provides easier/stable building generation in terms of handling.

Basic start:
* The exterior a building consist of columns and walls.
* The floors/levels of a building consist of the exterior, but with each floor/level on top of a previous floor/level.
* These principles can be replicated into the following logic:

Code: Select all

``````// Z is the layer from which any floor/level is created from.
for (z) {
for (x) {
// Do all columns/walls at Min/Max Y ratio for all "X" intervals.
// The values used:
//  X,+Y,Z
//  X,-Y,Z
// -X,+Y,Z
// -X,-Y,Z
// 'X' will increase from the "center" point/initial position and "blossom" outward.
// Y is the max or min level of the building in the Y axis and remains constant during the blossoming of 'x' loop.
}

for (y) {
// Do all columns/walls at Min/Max X ratio for all "Y" intervals.
// The 'y' loop here is roughly a mirror of the 'x' loop.
}

// Do building corners here.
// Do floor/level here.
}
``````
This generates very basic building structures and columns. Walls and columns are optional and not strictly needed.

Keep in mind, none of the math for this is provided, but the initial pseudo-code for this example can be almost readily used.

The abstract of this is likely confusing, so if there is any uncertainties, please feel free to ask for clarification.

-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.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread