Procedural Generation of Buildings in BZFlag - It's easy!
Posted: Sun Feb 04, 2024 6:18 pm
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.)
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:
Generally speaking, the walls will be checked by conditionals similar to the following:
(4 and 0 to be substituted with needed requirements)
Special handling can be done with something similar to the following:
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:
So to summarize it all:
And you basically have the technique to generate buildings.
-Zehra
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[][][][][]
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
[]-[]-[]-[]-[]
Code: Select all
if [0][]
if [4][]
if [][0]
if [][4
]
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]
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);
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()
-Zehra