This is a difficult question.
Firstly you should be familiar with elmos. Spring distances are measured in elmos, you see them in the range of units within the detailed info screen. They are quite small, for example LLTs are 32 elmos wide and have 460 range.
The heightmap has a resoultion of 8 elmos. So maps are a grid of points 8 elmos apart and each point has a height value. The grid that appears during structure placement has a spacing of 8 elmos. Talking about volumes of terrain smaller than this resolution does not map much sense. Terraform cost is calculated at this level.
Resources are spent on terraform by nanolathing nodes on the ground called "Terraform". These units exist only to provide constructors with a target. I call them terraunits. Each of these terraunits handles its cost independently. If you make a large area of terraform it will be split into many terraunits but the cost is calculated as if each unit was designated by itself.
There are also 4 types of terraform (Level, Raise, Smooth and Restore) which have two distinct ways of being implemented (area or wall) as well as a special one; Ramp. The method which you use you give the terraform order has no relation to the cost of the terraform. Each order is translated into a set of points which want to be moved to certain heights. I will call the set of points the terraform points. The terraform points are the points which are selected when you give the command, if you give a Level or Raise command they are the vertices, edges and interiors of the blue boxes (because the blue grid has a spacing of 16).
Terraform has 4 components to its cost:
-
Base Cost
-
Perimeter Cost
-
Volume Cost
-
Pyramid Cost
These costs are set here:
https://github.com/ZeroK-RTS/Zero-K/blob/master/LuaRules/Gadgets/unit_terraform.lua#L115The Base Cost and Perimeter Cost are set when the terraunit is created. This cost has to be paid before any terrain is deformed. Volume Cost and Pyramid Cost can change during construction and the terrain is deformed to indicate how complete these costs are.
Base cost is the simplest of these. The current Base Cost is 12 so every terraunit has to have 12 metal spent on it before it does anything else.
Volume Cost is the next simplest. Every terraform point contributes cost equal to its required height change multiplied by the volume cost multiplier. Terraform points with a structure on them set their required height change to 0. Terrain changes during construction (such as structure placement/death or other terraform) can cause Volume Cost to recalculate to take the new required height change into account.
So for example say you want to build a 100 elmo high spire for your LLT. The blueprint grid for an LLT has 25 vertices so there are 25 terraform points. Each has to be raised by 100 elmos so the Volume Cost would be:
25*100*0.0064 = 16
Pyramid Cost is like Volume Cost but occurs for the supports form around high terraform. A terraform point can have up to 4 edge points, these are heightmap points which are adjacent orthogonally to the terraform point but are not themselves terraform points. If the difference in height between a terraform point and an edge point is greater than 30 then the height of the edge point has to be changed such that the difference is 30. This is done on the fly so Pyramid Cost is hard to calculate in advance.
The cost of changing the height of an edge point is the same as a terraform point, it depends on the volume cost multiplier. Edge points can have their own edge points which have their height restricted based on their distance to the terraform point that sits at the top of their family tree. This is what causes large and rounded pyramids. I won't do an example of Pyramid Cost because it is too messy to work through.
Volume Cost and Pyramid Cost are almost the same thing. The cost here is simply the total heightmap change caused by the terraform multiplied by the volume cost multiplier.
The complicated cost is Perimeter Cost. It exists as a fudge to make vehicles have a chance against bots who terraform long lines of terraform 6 elmos high across the entire map. With the costs stated so far it this would be a very inexpensive tactic. The first 6 elmos of height for terraform points with edge points incurs an extra cost. So if you terraform is 3 elmos high the cost is halved but anything over 6 elmos is no more expensive. The extra cost for each terraform cost is as follows:
#EdgePointMultiplier * min[height, 6] * PerimeterCostMultiplier
The #EdgePointMultiplier is 0 if the terraform point has no edge points, 1 if it has 1,3 or 4 and 1.4 if it has 2 edge points. PerimeterCostMultiplier is currently 0.05. If you wanted to make up some fluff to explain this cost you could say that the edges need a bit of extra reinforcement to prevent fraying.
This description of Perimeter Cost was probably not that useful. The upshot is that the Perimeter Cost of any height over 6 for LLT shaped terraform is a mere 5.28. From experimenting with walls I think the Perimeter Cost contribution for a wall is about 0.09 metal/elmo by the length of the wall.
It may be more useful to test this and see what happens. Cheat yourself a game with an economy at equilibrium and make terraform to see how much it costs.