Military Buildings

👍

Reminder - Keep Daily Backups

When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.

What are military buildings?

When playing city-building games or battle strategy games you'll always be able to build some sort of structure that doesn't have any economic role. In this case we've added a category in the store for you to place these buildings.

The demo includes a few of these general buildings like the Wizard Hat, School House, or Workshop although some of them like the Tatami can have a special attribute - increase total max army size.

757

Click to view larger.

Military building special attribute: increase max army size

Other than resource generators and storage buildings - you can also store units in your structure to give the player a bigger maximum army size. The XML sections further down on this page teach what to do for the StoreType and StoreResource variables.

304

Maximum army size in the HUD.

Shop Menu

Here's a screenshot of the shop menu for the military buildings.

636

Click to view larger.

The examples here are general buildings that do not affect the player's stats except awarding XP for completion, although the Tatami item is one example that expands the maximum army size. More details below on how to do this in the ScriptableObjects.

749

Click to view larger.

Where to find the military store menu in Unity?

Open the game scene hierarchy and locate the ScrollView in Canvas > ModalsWindows > ShopWindows > ShopGroup > StorePanel > BottomGroup > Content > Content. Look at the below screenshot.

403

UIAnchor. Click to view larger.

Store Item

All of the store details seen in the below screenshot are taken from the Assets/CityBuildingKit/Resources/Assets/MilitaryCategory.asset file and loaded by Scripts/Creators/BaseCreator.cs (details below on what part of the script does this)

483

Breakdown of the information shown to players in the store.

From Image AboveDescription
NameThis is the Name variable
Time to BuildThe TimeToBuild variable (in minutes). How long the structure will take to to be created.
PriceThe Price variable.
CurrencyThe Currency variable (Either Gold, Mana, or Gems) You could change this to whatever currency you will have in your game and also add additional currencies.
DescriptionShows the Description text variable.
Xp AwardExperience obtained per build
HPLife points of structure
Up Ratio?
Id of big iconMain Icon of store
Id of small iconsmall icon of info
Id of icon on buy buttonicon of buy button
Id of black big IconMain Icon of store ( no available item version )
Max Count of this itemMax. amount allowed per current
IdItem id
LevelLevel of building
AssetGame unit prefab
Store Cap?
Store TypeType of storage (Internal / Distributed / None).
Store ResourceType of Resource ( for Resources Vaults )
Prod TypeType of Production ( for Resources Generator )
Prod per hourProduction time rate
Structure typeBuilding genre

Army Troop Storage MilitaryCategory.asset Example

Here's an example of how to do a building that stores extra army units. The most important item in this list to observe is that the StoreType is Distributed and StoreResource is set to Soldiers.

662

A closer look at MilitaryCategory SO (ScriptableObject) file

If you look closely in the above SO, you could use whatever currency you want in your game, in the demo we have two placeholders called Gold and Mana. (Plus one rare currency called Crystal Gems)

Further above in the SO for the Tatami item you'll see the type of storage increases the player's army size - by 25 total. (Distributed means Player stats - meanwhile StoreType = Internal is used for resource generators - see the documentation page Shop Menu > Resource Generators for details)

SO parameters for a normal building without any army capacity would look like this:

Meanwhile a normal building would look like the Workshop building example in the MilitaryCategory.asset, excerpt below:

723

You'll notice the only major change is that StoreType is set to None, StoreResource is set to None, and StoreCap is set to 0. This means no resources (army or in-game currency) are stored.

BaseCreator.cs - Where the SO is loaded into

In Scripts/Creators/BaseCreator.cs the building data from your XML file (seen above) is loaded using a common system for all the buildings like resource buildings, defense buildings, walls, decorations, and other buildings. Here's an excerpt from BaseCreator.cs of the XML data load:

protected void GetBuildingsXML()//reads structures FROM SCRIPTABLE OBJECT FILES
{
  //LOAD FOR ECONOMY BUILDINGS 
  List<BuildingCategoryLevels> buildingCategoryLevels = ShopData.Instance.BuildingsCategoryData.category;
  List<BuildingsCategory> buildingsCategoryData = buildingCategoryLevels.SelectMany(level => level.levels).Where(c => c.level == _structuressWithLevel).ToList();

 //LOAD FOR MILITARY BUILDINGS
		List<MilitaryCategoryLevels> militaryCategoryLevels = ShopData.Instance.MilitaryCategoryData.category;
		List<MilitaryCategory> militaryCategoryData = militaryCategoryLevels.SelectMany(level => level.levels).Where(c => c.level == _structuressWithLevel).ToList();

		FillBuildingData(buildingsCategoryData);
		FillBuildingData(militaryCategoryData);
}

When the data is loaded, the store panels are updated with the appropriate information.

Construction limits with XP levels

Read the Gameplay > XP and Levels documentation page for more details. Game players could have a maximum of two gold mines at level one until the player reaches level two, in which the maximum increases to five (or whatever value you choose -- read XP and Levels documentation for more details)

158

1/2 gold mines built. Maximum not reached.

161

2/2 maximum reached, can't build more

This is relevant to mention now because the menu items are greyed out for buildings that the player can no longer build until they increase their base level through other ways of gaining XP. The function UpdateLabelStats() DEPRECATED FUNCTION / UNUSED

What happens when the buy button is clicked for a building?

When the player clicks one of the buttons to build a building in the store, first one of the building functions is triggered. ( Look at Shop Menu > Resource Generators: What happens when the buy button is clicked for a building? section ), since it is exactly the same process. )

VerifyConditions()

Can the player build this structure? In Scripts/Creators/BaseCreator.cs the VerifyConditions() script takes over once the store button has been pushed to determine if the following conditions are met and canBuild is set to true. ( Look at Shop Menu > Resource Generators: VerifyConditions() section, since it is exactly the same process. )