Resource Buildings
All about resource buildings mechanic: from how to manage it in editor to how to work with code base.
Configuration
- Resource Generated Amount. Base amount resource building will generate each Generation Time seconds. 25 by default.
- Income Lowest Bound. Income can be not less than this value. 4 by default.
- Command Points Gained. Self-explanatory. 50 by default.
- Generation Time. How fast resources will be generated in seconds. 6 by default.
- Circle Radius. Income calculating area circle radius. 2000 by default. (TODO: in what?? Doesn't connect with MI_Selection).
- Terrain Coefficient. How much any other buildings affect on income. 1 by default. Only buildings counts.
- Income Algorithm Depth. It will be described lately. Higher value - higher income calculating precision. 20 by default.
- Resource Multiplier. It's an array with two elements: first for level 2, second for level 3. 1,2 and 1,35 for default.
- Income Lowering Pattern. Describe how the amount of generated resources will decrease for each new constructed resource building. For first eleven buildings values are 1, 1, 1, 0.95, 0.9, 0.9, 0.9, 0.85, 0.79, 0.76, 0.73. That means, if there is just one resource building, penalty is 1 (full income). It's same for two and three buildings. For four buildings penalty is 0.95 (new income is Resource Generated Amount x 0.95). After eleven buildings penalty will be raise for each two new resource buildings. So, for thirteen new buildings it will be Resource Generated Amount x 0.95 - 1 etc. But no less than Income Lowest Bound.
Income calculating algorithm
- Algorithm creates a circle of dots. Income Algorithm Depth affects how many dots there will be.
- Algorithm searches for every resource building placed in circle with radius Circle Radius x 2.
- For every dot in circle, if it's in circle of another resource building, algorithm is removing this dot.
- Algorithm searches for every building in Circle Radius x 2 radius.
- For every remaining dot in circle, if it's inside some building's bounds, algorithm is removing this dot.
- Multiply number of dots removed in 5 by Terrain Coefficient.
- Return num of remaining dots divided by num of initial dotes.
Building
First you need to add ability to BP_PlayerController (like here). Then, create building at any suitable place.
Income calculation
There are two cases income is calculated:
- While current resource building is created.
- When near resource building was destroyed.
Resource building creating
So, you clicked on ability button, and now a yellow circle is appeared with percentage in the center. While you move this circle around, income is calculated every tick. When you will place new resource building, income will be calculated last time, and this value will be stored.
Resource building destroying
When somehow resource building was destroyed, it searches for all buildings around. Then, all buildings check time destroyed resource building was constructed, and if it was constructed earlier than them, they recalculate their income.