Progress has been made on the King of Adem project. For those of you not familiar with this project please read the original King of Adem post at …
Since the update I have been primarily working on the building queue. The building queue is the queue which buildings get inserted into when a player wishes to construct a building in one of his / her regions.
To get to the construct building screen the user has to be in one of his / her regions so those areas to get to that screen had to be part built.
The areas part built are namely user, game, region and building. Once on the construct building screen the user can select from a list of buildings that can be constructed.
Each building is validated on a case by case basis and if it does not pass the validations the building cannot be constructed, here are some of the validations so far …
Check fund available
The player must have the correct amount of fund available to construct the building. The amount of funds available is the players start of turn funds subtracting any funds that have been used in the current turn.
For example player may have started with 1000 coins, if a player constructs a building for 300 coins then the program gets the players start of turn funds but substracts 300 coins because it knows a building worth 300 coins was requested to be constructed this current turn.
Check building queue full
The building queue may only allow so many buildings to be in the queue at any one time for each region. Currently this number is set at 5 and the number is stored in a config file.
Check building already built
Check if the building has already been constructed in the region. Each building has a “constructionLimitPerRegion” variable which stores the number of times that particular building may be constructed in each region.
Check dependent buildings constructed
Each building can have what are called dependent buildings. These are buildings which need to be constructed first before you can build the current building.
Also the validation knows whether a building is an upgrade of an existing building or a completely different building that just happens to depend on another building being constructed.
All kinds of checking had to be implemented for this validation, whether building is an upgrade / dependant or just dependant, whether advanced tier buildings already exist for lower dependant buildings, whether lower dependant buildings already exist etc.
Check advanced tier building exists
Check if an advanced tier building already exists for the current building wanting to be constructed. If the advanced tier building already exists then there is no reason to build the current building.
Again this needs to take into account that some buildings can be constructed more than once so in some instances it may need to allow the building to be constructed even though the lower building has already been constructed.
The above validations are run everytime a user issues the command to insert a building into the building queue for a particular region. These validations are run from the “Building” Model. Each building is also given its own Model, the hierachy is like as follows …
\yii\db\ActiveRecord -> \app\components\ActiveRecord -> \app\models\Building -> \app\models\BuildingTownBarracks
\yii\db\ActiveRecord -> \app\components\ActiveRecord -> \app\models\Building -> \app\models\BuildingPort
I can run special validations for specific buildings by placing those validations in the specific building class. Those validations will only run for the specific building and not all buildings.
That is as far as I have got so far. Still a long, long way to go, more updates to come soon.