Resource Storage

👍

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 resource storage structures?

Like the resource generators we've described in the earlier documentation page, there are also resource storage buildings. These allow players to store resources and increase the total distributed storage space.

The city building kit comes with two in-game resource examples (gold and mana) plus one rare currency example. In the store you'll see the two storage examples, gold vault (example currency #1) and the mana barrel (example currency #2)

750

Examples of the resource storage structures in the store.

Resource #1 Storage (Gold)

Like many free-to-play strategy games, the first resource storage structure keeps gold as you can see in the below example.

601

Gold storage building. Click to view larger.

Resource #2 Storage (Liquid Mana)

The second type of resource storage in the city building kit is the mana barrel, as seen in the below screenshot.

601

Liquid resource storage. Click to view larger.

Can I change these currencies to others, like wood or stone?

Yes, you can change everything inside the city building kit. All the source code is included. The easiest way to change one of the existing currency examples like gold to wood without adding more currencies is to update the gold sprite images. The source code can remain the same.

Can I add more currencies to my game?

Yes, you can add more to your game by copying the existing source code for the first two currencies examples - gold and liquid mana. Or to have more than one purchase currency, you'll want to work with the rare crystal gem example included in the kit.

Adding more currencies to your game will take some time to fully understand. We'd hope you'd become comfortable with the kit source code first and editing the existing two currency examples before attempting more difficult customizations like additional currencies.

Resource BuildingsCategory.asset Example

Here's an example of how to do a resource generator, in this case a gold mine, in the ScriptableObject (SO). For resource generators, the single difference most noticeable is that ProdType (production type) is set to either Gold or Mana, instead of None.

625

For a closer look at the SO for resource generators and storage units, you want to open the Shops Menu > Resource Generators section of the documentation.

How resource storage works

Resource storage structures work by increasing the distributed storage cap for the player. In the case of the gold vault example above, you can see it's 2500 gold of additional storage that gets added to the total player stats (Distributed):

559

This storage addition is added to the total player stats in Scripts/Creators/ConstructionSelector.cs when ProgressBarUpdate() is triggered for the construction completion.

The following excerpt shows the special qualities for various buildings that are updated in the player stats when construction finishes. For the Barrel and Vault items, total player storage is increased by the StoreCap SO (ScriptableObject) item.

// ProgressBarUpdate() excerpt
// from Scripts/Creators/ConstructionSelector.cs
//
// The following part of the function updates the player stats depending 
// on what sort of special features the building they create

					//the builder previously assigned becomes available
					((Stats)stats).occupiedDobbits--;			

					// What type of building is it?
					// Any special building attributes are added to the player stats
					if(structureType=="Toolhouse")													
					{
					//increases total builders since they built a builder house
						((Stats)stats).dobbits += 1;
            															
					}
					else if(structureType=="Tatami")									
					{
            // increases total unit storage in Stats	because they built
            // the Tatami example which has unit storage
						((Stats)stats).maxHousing += storageAdd;
					}
					else if(structureType=="Forge")
					{
            // if it's a production building
            // later in this fuction we'll register it for
            // notifictions above the building using
            // RegisterAsProductionBuilding
						isProductionBuilding = true;			
					}
					else if(structureType=="Generator")
					{
            // if it's a production building
            // later in this fuction we'll register it for
            // notifictions above the building using
            // RegisterAsProductionBuilding
						isProductionBuilding = true;		
					}

					else if(structureType=="Barrel")				
					{	
            //increases total mana (currenct #2) storage in Stats														
						((Stats)stats).maxMana += storageAdd;
					}
					else if(structureType=="Vault")
					{
            //increases total gold (currency #1 storage in Stats	
						((Stats)stats).maxGold += storageAdd;
					}

					// since we've probably changed values seen in the UI 
					// (e.g. extra storage with a vault) then update the stats UI
					((Stats)stats).UpdateUI();

		// .........

Example of resource storage cap increase

The following screenshot shows before and after storage addition in the Stats UI. The storage cap is shown just above the progress bars for the total resources. In the below example, we start with 500,000 gold cap and after building a Gold Vault the player cap increases by 2,500 for a new total of 502,500.

557

Total resource cap before add (500,000). Click to view larger.

563

Total resource cap after add, now 2500 larger. Click to view larger.

After a certain amount is reached, the value of the resource yet to be collected appears above the resource structure. This continues accumulating until you reach the resource cap. In the case of the above example

Can I do internal storage instead of distributed storage?

Yes. Although this applies to the resource generators and not resource storage buildings. To keep the player engaged with your game they collect resources from their resource generators by tapping or clicking on the generator to add the total resources generated since last harvest collection to the player's stats.

240

Waiting too long means they miss out on resources that are generated because each building has a maximum storage cap defined in the BuildingsCategory.asset as seen above. This StoreCap item is used in the RunEconomy() function to throw away resources gained per second if the storage cap has been reached.

// Excerpt from RunEconomy() function in
// Scripts/Creators/ResourceGenerator.cs
// this function runs once per second

// The following checks if the stored gold plus the resources
// generated in the last second exceed the storage cap
// If exceeded, resources are discared until the player collects
// the stored resources.

					if (ExistingEconomyBuildings [i].storedGold + produce < ExistingEconomyBuildings [i].StoreCap) 
					{
						ExistingEconomyBuildings [i].ModifyGoldAmount (produce);
						//if((float)existingEconomyBuildings [i].storedGold/existingEconomyBuildings [i].StoreCap>0.1f)//to display when 10% full
						if(ExistingEconomyBuildings [i].storedGold>1)
							displayNotification = true;
						
					}

For more details about resource generators, please view the Buildings > Resource Generators section of the documentation.

How are player stats updated?

Seen in the above ProgressBarUpdate() function excerpt, the last line calls a UI update which then reflects the gold cap changes from 500,000 to after 502,500 with the 2,500 gold storage added from the gold vault in the images above.

((Stats)stats).UpdateUI ();

Where are the prefabs?

All of the game object prefabs are set in the ScriptableObjects at the path Assets/CityBuildingKit/Resources/Assets/
For example take a look at the BuildingsCategory.asset file below :

625

Game scene Game Manager > SaveLoadMap

In addition, you will want to look at GameManager > Creators > BuildingCreator (prefabs are also there) This is discussed in the Buildings > Part 2: Customize Menus section of the documentation. Prefabs are used by the creator for construction and by SaveLoadBattle for loading during battle.

🚧

Adding or Subtracting of Game Units

If you add new Resource storage structures or subtract some via the BuildingCategory.file , please don't forget to update GameUnitsSettings.asset file. Read more info at Documentation > XML files VS ScriptableObjects

GameManager > Creators > BuildingCreator

In the GameManager > Creators > BuildingCreator we have the list of game object prefabs used by the creator in addition to certain build settings used by the Scripts/Creators/BaseCreator.cs script. Let's describe these below. But first, here's how to open the BuildingCreator Inspector

273

Game scene Game Manager

In the Inspector you'll notice a few arrays, here's a description of each one. It's the same for every type of game object you can build in the game except for the RemovableCreator (removables are not for players to construct but rather remove -- see Player Removable Objects doc for details)

Array TitleDescription
Structure PfThe structure prefab.
Grass Pf1x1 to 5x5 dark green grass collider grid prefabs list. These you don't have to edit, they are shared by all structures in the game based on their grid size.
Construction PfUnder construction prefab list. There's 3 different sizes of this for 1x1 to 3x3 grid size construction projects.
Grass TypesSize of this array matches the the Structure Pf array size. We tell which Grass Pf element to use with each structure. Depends on structure size whether they take 1x1 (Grass Pf element 0) like a wall segment or 3x3 (Grass Pf element 2) like the large gold vault. Tatami is the only object that takes grass collider 5x5 ( Grass Pf Element 4).
Construction TypesArray size matches Structure Pf. Like grass types, we match the construction prefab grid size too. Since there's 3 different sizes of construction prefabs, this ranges from values 0 to 2. By default, we set most structures to use the 3x size.
Pivot CorrectionsArray size matches Structure Pf. Odd size grid structures (1x1 and 3x3) need a pivot correction so they don't appear accidentally off-center, taking more grid space than necessary. Pivot Correction does this.
Is ArrayArray size matches Structure Pf. If set to 1, uses the row making field builder for construction instead of the usual construction. The only objects that use this are the wall segments that let you pick a start and end point and automatically constructs a repeating row of the structure between the points.
Is InstantArray size matches Structure Pf. For items you set TimeToBuild to 0 (instant build) in the SO, you also want to set the elements Is Instant boolean to 1 in this array. The only objects that use this in the demo are the wall segments.

What about resource generator structures?

Please see the Buildings > Resource Generators section above to learn how resource generators produce player resources, and how they are collected by players.