Game Stats Planets Calculation
Hi there, I've been looking at the Game Stats screen and through many hours of gameplay I've noticed that it's not always accurate. I started looking at Planets and made a small modification to how this is calculated in game_stats.c
82,93c82
<
< /* Calculate the number of habitable planets to use as the total number planets */
< int habitable_planets = 0;
< for (int i = 0; i < num; ++i) {
< const planet_t *p = &(g->planet[i]);
< if (p->type != 0) {
< ++habitable_planets;
< }
< }
<
< /* More accurate calculation using floating point re-cast to int */
< return (int)(((float)sum / habitable_planets) * 100);
---
> return (sum * 100) / (num + 1);
What I found is that the total number of planets in the galaxy is used, and as such the total percent possible will never be 100%. This gets especially skewed when playing a huge galaxy since there will be many planets that are uninhabitable asteroid fields. I also found that using an int will always seem to "round down" and a floating-point (re-cast back to an int) provides better accuracy.
I realize that this strays away from the "vanilla" behavior of the original DOS game, and completely understand if you're not interested to change this aspect of the gameplay. But, I think it's more accurate, and possibly would have been implemented back then if there wasn't a processing hit for the additional code.
I'd also be happy to submit this via a commit, but I am not an expert in that area and wasn't sure if I was permitted to submit code to this repository.