sábado, 16 de marzo de 2013

Building Agent - Generic Buildings

The main function of the Building Agent is to attend requests for placing buildings. Some buildings require a very specific location to operate correctly, and some others not.

So we could divide the buildings in two types depending on its requirements, resource buildings and generic buildings.

Resources buildings like Lumberjack Hut, Stone mining camp and Gold mining camp, require a very specific location, whereas other buildings like Barn, Barracks, Monastery or University don't have those requirements.

In this post I am going to explain the Generic building placement. The only requirement of these buildings is to find a spot with enough space to place it around the Bastion (the main building). There are different approaches to solve this problem,  but this is the way I have solved the problem.

First of all, I have implemented some kind of grid system into the building agent. This system has 2 variables, BuildNodes_Iterations and BuildNodes_Space and allows the Building agent to create a grid of nodes around the selected building (in this case the Bastion), and use those nodes to find free spots for the generic buildings.

In this Image we can see the BuildNodes that it has generated around the Bastion with BuildNodes_Iterations = 4 (yellow numbers/lines ) and BuildNodes_Space = 25 (red numbers/lines ).



Basically, iterations is the amount of  node "squares" around the selected area, and Space is the space between nodes. 

Each BuildNode is a potential spot for a Generic Building.

Here other grid configurations:


BuildNodes_Iterations = 2, BuildNodes_Space = 50












Not enough BuildNodes


BuildNodes_Iterations = 6, BuildNodes_Space = 15















Too many BuildNodes




As you can see with this system I can easily modify the amount of BuildNodes around the selected area, and adapt it to my needs. Depending on the game, the number of different buildings, the size of the buildings etc. one configuration will be better than the other.


For my needs I think that BuildNodes_Iterations = 3 and BuildNodes_Space = 40 will do. I need enough nodes to have some diversity and randomness when placing the buildings, but not too many BuildNodes to avoid unnecessary and redundant calculations.

Once we have the BuildNodes grid, it "randomly" (some simple hints are given for each building) selects one and try to place the building there. If there are no obstacles within a certain radius (each building has its own radius), it places the building there, otherwise, it keeps looking for a valid BuildNode with enough free space around it. If no BuildNode satisfies the space requirements, the order is cancelled.

Here is a video where I order the Building Agent to place some buildings, and see how well this system works.



The solution is quite simplistic, and further development of this system would be probably required in order to have a well-organised city/empire. But for the moments it works pretty well, and it fits my needs for the project.

In the next post I will talk about Resource Buildings, which are more complex because they don't only need a free spot, but also the right or the best spot to operate correctly.

No hay comentarios:

Publicar un comentario