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.

What is an example of the XML for resource storage?

Here's an example of how to do a resource generator, in this case a gold mine, in the XML. For resource generators, the single XML difference most noticeable is that ProdType (production type) line item is set to either Gold or Mana, instead of None. The order of items in the XML document must exactly match the scripts you customize in Buildings > Part 2: Customize Menus documentation as this XML item order becomes the structure index used in the scripts.

<Building> <!-- 03 -->		
		
		<Name>Gold Vault</Name>	
    <!--  name displayed in the store -->	
    
		<StructureType>Vault</StructureType>	
    <!--  IMPORTANT: use the same name same as prefab in your XML -->	

		<Description>Like a bank. But with gold. Always empty. Get back to work!</Description>
    <!--  description displayed in the store -->	
								
		<Currency>Mana</Currency>	
    <!-- save as Gold, Mana, or Crystals to buy; production/storage building, buy with gold, produces mana -->			
    
		<Price>200</Price>	
    <!-- amount of resource necessary to pay for the building -->					
		
		<ProdType>None</ProdType>	
    <!-- resource produced - gold/mana/none-->	
    
		<ProdPerHour>0</ProdPerHour>	
    <!-- the amount of the resource generated per hour -->	
		
		<StoreType>Distributed</StoreType>	
    <!-- None, Internal, Distributed (where the gold is stored, in this case 500 internally in the Unit until you click and disperse the gold into your player stats -->				
    
		<StoreResource>Gold</StoreResource>		
    <!-- resource stored - None/Gold/Mana/Dual (gold+mana)/Soldiers-->	
    
		<StoreCap>2500</StoreCap>		
    <!-- gold/mana/dual/soldiers storage -->	
    <!--although it's not centralized, there is an internal storage-->
								
		<TimeToBuild>15</TimeToBuild>	
    <!-- the time (in minutes) needed to create the building -->	
    
		<Life>400</Life>				
    <!-- hitpoints for the building in battle  -->			
    
		<XpAward>100</XpAward>		
    <!-- experience awarded for the completion of building this -->		
    
	</Building>

For a closer look at the XML for resource generators and storage buildings, 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 (specified in XML/buildings.xml). 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):

<StoreType>Distributed</StoreType>	
    <!-- None, Internal, Distributed (where the gold is stored, in this case 500 internally in the Unit until you click and disperse the gold into your player stats -->	

<StoreResource>Gold</StoreResource>		
    <!-- resource stored - None/Gold/Mana/Dual (gold+mana)/Soldiers-->	
    
<StoreCap>2500</StoreCap>		
    <!-- gold/mana/dual/soldiers storage -->	
    <!--although it's not centralized, there is an internal storage-->

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 XML line 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.

<StoreType>Internal</StoreType>					
    <!-- None, Internal, Distributed (where the gold is stored, in this case 500 internally in the Unit until you click and disperse the gold into your player stats -->
		<StoreResource>Gold</StoreResource>
    <!-- resource stored - None/Gold/Mana/Dual (gold+mana)/Soldiers-->	
		<StoreCap>500</StoreCap>		
    <!-- gold/mana/dual/soldiers storage -->	
    <!--although it's not centralized, there is an internal storage-->

Waiting too long means they miss out on resources that are generated because each building has a maximum storage cap defined in the XML/Buildings.xml 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) 
					{
  					// Adds resources
						existingEconomyBuildings [i].ModifyGoldAmount (produce);
						
  					// Displays harvest notification reminder
						if(existingEconomyBuildings [i].storedGold>1)
						DisplayHarvestNotification (i, existingEconomyBuildings [i].storedGold);					
					}

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 Game scene Game manager. Look at the below screenshots:

275

Game scene Game Manager > SaveLoadMap

360

Inspector Resource prefabs. Click to view closer.

In addition, you will want to look at GameManager > Creators > BuildingCreator (prefabs are also there) and Map01 scene GameManager > SaveLoadBattle. 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.

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

365

Resource storage buildings prefabs in the BuildingCreator

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. Order in this list matches the exact order of the XML items which the Creator matches the prefab with.
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 XML, 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.