Changing the upkeep / cost for a core-game building

This guide shows you how to change the resources needed and / or upkeep for a default in-game building (not modded).

Posted by on


Originally asked by Tolakram on the discord server, how can you change the cost of a core-game building?

Tolakram and myself tried unsuccessfully to change it, using the API provided here. After a while, we determined it must be a bug. It was not. The answer is just slightly more complicated than you would think. We asked the devs for a solution, and our saviour Maxime came to our rescue. Apparently, the cost / upkeep for core-game buildings is determined by BUILDING_PART_COST_LIST_DEFAULT. We need to override this. This code snippet will change the warehouse's upkeep to just 1 gold, down from 5 gold.

warehouseMod:override({
    Id = "BUILDING_PART_COST_LIST_DEFAULT",
    BuildingPartCostList = {
        Action = "APPEND",
        { 
            BuildingPart = "BUILDING_PART_WAREHOUSE", 
            BuildingPartCost = { 
                UpkeepCost = { 
                    { Resource = "GOLD", Quantity = 1 } 
                } 
            } 
        }
    }
})

Change BUILDING_PART_WAREHOUSE to whatever building part you want to edit, which you can find over on the API wiki. If you want to change the upkeep from something other than gold, you can find a list here. Change the quantity to however much you like. If you'd like to set the cost of a building as well (when you first place it) you can change that like so:

BuildingPartCost = { 
    UpkeepCost = { 
        { Resource = "GOLD", Quantity = 1 } 
    },
    RessourcesNeeded = {
        { Resource = "WOOD", Quantity = 5 },
        { Resource = "STONE", Quantity = 2 }
    }
} 

Now the warehouse needs 5 wood and 2 stone to be built, including the 1 gold upkeep. If you'd also like to set the upfront cost (usually gold in the vanilla game) you should use BuildRightTaxes. Example like so:

BuildingPartCost = { 
	UpkeepCost = { 
		{ Resource = "GOLD", Quantity = 1 } 
	},
	RessourcesNeeded = {
		{ Resource = "WOOD", Quantity = 5 },
		{ Resource = "STONE", Quantity = 2 }
	},
	BuildRightTaxes = {
		{ Resource = "GOLD", Quantity = 30 }
	}
} 

Keep in mind, however, that you can change this from gold to anything. If you want, you can make it so that it requires a deposit of 30 stone!

If you'd like to take a look at the whole code and not just the snippets, you can download it here.

Big thanks to Maxime for helping me figure this out!

Comments