Balancing an Economy
The money I calculated to be necessary to pay for all the labour was $0.42 per player. But the AI's were going bankrupt. Something was wrong. I bumped up the starting cash to $9.00. I figured out that the AI's were spending excessive amounts on orders of military units at another AI's factory. And I was calculating transportation costs using route lengths using the length squared function Magnitude3() on 2 dimensions which I mistook to be the one that just gave the length on 2 dimensions.
Fun fact: Andre LaMothe wrote about this trick in Tricks of the Game Programming Gurus. Instead of calculating the distance using square root and seeing if it's ten, you just take what you get before the square root and check if it's greater than 10 squared. Just today from Code Complete I learned how much CPU time this saves.
Another improvement is the fast inverse square root made popular by John Carmack for normalizing vectors.
Anyway, players were still going bankrupt, resulting in them selling all their property for $0 until only one AI remained with all the property. It became important to balance the initial selling prices of resources.
I first tried using value-added calculations. I set the wages for all labour/jobs to $0.01 (later I would bump everything up by a factor of 10 to allow variability because $0.01 is the smallest increment of change that can be made)...
...and added up the costs of all inputs in producing each resource plus a profit of $0.01.
Quarry: 10 labour => 5 stone so $0.10 / 5 stone + $0.01 = $0.03 / stone
Resources required transport from supplier to demander, which costs. Trucks consume 1 labour per 4 seconds and thus consume $0.01 / 4 seconds. The time that a trip takes, to supplier and then to demander, is calculated from the path length, and the charge to the client is based on it. I set the transport price to $0.02, giving a profit of $0.01 / 4 seconds. I found from logs that the usual trip was 6 payments long. So for each input, 6 payments of $0.02 are required ($0.12).
Cement plant: 10 labour + 5 stone + 1 transport => 5 cement so ( 10*$0.01 + 5*$0.03 + 1*$0.12 ) / 5 stone + $0.01 = <$0.09 / stone
Mine: 10 labour => 5 ore + 5 uronium + 5 cohl so 10*$0.01 / 15 ore, uronium, cohl + $0.01 = <$0.02 / ore, uronium, cohl
Reactor: 10 labour + 1 uronium => 10 electricity so ( 10*$0.01 + 1*$0.02 ) / 10 electricity + $0.01 = <$0.03 / electricity
Combustor: 10 labour + 1 cohl => 10 electricity so ( 10*$0.01 + 1*$0.02 ) / 10 electricity + $0.01 = <$0.03 / electricity
Derrick: 10 labour => 3 crude so 10*$0.01 / 3 crude + $0.01 = <$0.05
Chemical plant: 10 labour + 10 electricity => 10 chemicals so ( 10*$0.01 + 10*$0.03 ) / 10 chemicals + $0.01 = $0.05 / chemical
I had to remove the chemical plant's dependance on metal, which would cause a two-way dependancy with the smelter that I was too lazy to figure out how to solve mathematically.
I increased the usage of electricity of buildings to 10 to funnel more money from the shopping complex, which initially got all the money from hungry labourers buying food (consumer goods), spending money earned doing work for all the other players, bankrupting them.
Smelter: 10 labour + 5 ore + 10 chemicals => 5 metal so ( 10*$0.01 + 5*$0.02 + 10*$0.05 ) / 5 metal + $0.01 = $0.15 / metal
Refinery: 1 labour + 1 electricity + 1 chemicals + 1 crude + 1 transport => 3 zetrol so ( 1*$0.01 + 1*$0.03 + 1*$0.05 + 1*$0.12 ) / 3 zetrol + $0.01 = $0.08 / zetrol
I increased the labour requirements of the buildings to 10 because I found that after the construction phase of the game, most labourers became idle and were unable to make money to pay for rent or food. Increasing the required labour to 10 (the max amount of labour they do without rest) gave them something to do all the time. Before I had a problem with labourers buying too much food and multiplying during the construction phase, later being unable to find work and starving. I thought the new, high price of food (consumer goods) would balance things out. Evictions were also common with "tenants" being unable to pay the arbitrarily set rent price each minute. The rent might be collected at a time when the labourer had little money, even though I programmed them to keep a reserve for rent instead of spending everything on food. Housing required no inputs so I set it's price to the lowest possible - $0.01 - so labourers should have been able to afford it.
Trucks also consume "zetrol" fuel at a certain rate. The game runs at 30 frames per second so the number of frames per trip is
6 payments/trip * 4 seconds/payment * 30 frames/second = 720 frames/trip
The trucks drive 0.35 units per frame so they cover
720 frames/trip * 0.35 units/frame = 252 units/trip
And a tile is 16 units (I know I should've used metric) so
252 units/trip / 16 tiles/unit = 15.75 tiles/trip
The truck consumes zetrol every 2 tiles so
252 units/trip / 32 units/consumption = 7.875 consumption/trip
Each time it consumes 0.5 zetrol fuel.
7.875 consumption/trip * 0.5 fuel/consumption = 3.9375 fuel/trip
This actually seemed kinda high because I didn't observe the fuel being consumed this fast, but I'll trust the equation. (Some of the trips were only 3 payments long and 6 was actually the high end.) The price of fuel was $0.08 per unit as mentioned above so the fuel cost per transport job would be:
3.9375 fuel/trip * 0.08 $/fuel = 0.315 $/trip
The profits per trip
0.01 profit/payment * 6 payments/trip = $0.06 profit/trip
So the profits wouldn't be high enough to cover fuel costs. (I actually lowered the labour and other requirements for derricks and refineries to 1 later in an attempt to reduce fuel costs.)
I ran the simulation anyways. I found that labourers ran out of money on food (consumer goods), causing them to starve and die.
In my next attempt to balance the economy I would build a pyramid over the only thing that was certain - the rate of food consumption. Each labourer uses up 0.001 food per frame and the game runs at 30 frames per second.
0.001 food/frame/lab * 30 frames/second * 60 seconds/minute = 1.8 food/minute/lab
I want about 5 labourers to be supported by 1 shopping complex operating at x1 production rate.
5 lab/shop * 1.8 food/minute/lab = 9.0 food/minute/shop
This was just 1 unit less than it produced in a cycle. So some cycle it wouldn't operate and it would average out to 0.9 production rate. The inputs required would therefore balance out to be
Shop cplx: 0.9 ( 10 labour + 1 electricity + 1 chemicals ) / minute = ( 9 labour + 0.9 electricity + 0.9 chemicals ) / minute
Farm: 4.5 produce needed/minute / 5 produce harvested/minute = 0.9 production ratio
Farm: 0.9 ( 10 labour + 1 electricity + 1 chemicals ) / minute = ( 9 labour + 0.9 electricity + 0.9 chemicals ) / minute
Chem plant: 0.9 chemicals needed/minute / 10 chemicals produced/minute = 0.09 production ratio
Chem plant 0.09 ( 10 labour + 10 electricity ) / minute = ( 0.9 labour + 0.9 electricity ) / minute
Factory: 5 production needed/minute / 20 production generated/minute = 0.25 production ratio
The electricity required will be split among the reactor and combustor. Then I'll log the average time labourers spend going between buildings/to truck and figuring out how much time workers can spend working per minute (1 labour work per second) minus the time spent shopping and resting. I'll calculate the amount of transportation that has to be done. I'll calculate the amount of time spent driving and thus the fuel production rate requirements.
Then I'll calculate the amount of work labourers can do in a minute and adjust the required labour of the buildings essential to the production of food (consumer goods) to not exceed this maximum. Or I'll increase the number of workers and adjust the amount of food produced. And the number of tenants per apartment.
I'll calculate the amount of labourer income per minute and then divide it by the amount of food needed per minute to get its price.
I'll budget the price of fuel and its requisites based on how much profit trucks earn and divide it by the amount of fuel consumed to get its price. I'll then probably bump everything up by 10 or 100 and budget the costs of the requisites for food according to its price. Fuel is one of the requisites because transportation is needed, so the price of consumer goods has to be enough to cover the profits of transportation per minute (i.e. the fuel cost per minute), so that there aren't too many profits for a degenerate strategy.
Research and military unit production are non-essential and will be covered by any remaing profits.