What’s the difference between these two:
int maxEmployees = 50;
int employees = 25;
float taxRevenue = 1500.0f;
ONE : float revenue = (employees / maxEmployees) * taxRevenue;
TWO: float revenue = (employees * taxRevenue) / maxEmployees;
Mathematically, they’re the same. a/b * c = c/b * a
However, I missed one thing while coding (a lot harder to see when it’s not just this). They’re both integers. now what C# does is it divides 25/50. we get 0.5. but they’re both integers, so it tries to store it as an integer, which floors it to a 0. Therefore, it’ll suddenly jump to max revenue when the company is full. obviously not what was intended.
Option 2 makes you multiply the integer with a float, and stores 25 * 1500 as a float, which can now be nicely divided by 50 to get the value that we inteded.
Sometimes… actually, no MOST of the time it’s the little things that catch you out.
Anyways, this has very much balanced the game. The companies get as many employees as they can, then grow by 1 employee each day. Their revenue scales with the employee count, so now residential houses are useful for once. If anything, essential.
Next up: Road tax, Land tax. This might be the one time you want tax… or maybe it’s too much?
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.