From 6ec4fade91b861206172abd492361b0ca78e73f2 Mon Sep 17 00:00:00 2001
From: Allanis <allanis.saracraft.studios@gmail.com>
Date: Mon, 4 Dec 2017 21:49:30 +0000
Subject: [PATCH] [Change] A few more system gen float => int stuff. I didn't
 take into account that different platforms will likely handle them
 differently, resulting in diferent starsystems being generated between
 platforms.

---
 src/sector.cpp      | 14 +++++++-------
 src/star_system.cpp | 14 +++++++++-----
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/sector.cpp b/src/sector.cpp
index bb890d2..70ab8cf 100644
--- a/src/sector.cpp
+++ b/src/sector.cpp
@@ -20,19 +20,19 @@ Sector::Sector(int x, int y) {
     s.p.z = rng.Double(2*SIZE)-SIZE;
     s.name = GenName(rng);
 
-    float spec = rng.Double(1.0);
+    float spec = rng.Int32(1000000);
     /* Frequences are from our friends over at wikipedia. ^.^ */
-    if(spec < 0.0000003) {
+    if(spec < 1) {
       s.primaryStarClass = StarSystem::TYPE_STAR_O;
-    } else if(spec < 0.0013) {
+    } else if(spec < 1300) {
       s.primaryStarClass = StarSystem::TYPE_STAR_B;
-    } else if(spec < 0.0073) {
+    } else if(spec < 7300) {
       s.primaryStarClass = StarSystem::TYPE_STAR_A;
-    } else if(spec < 0.0373) {
+    } else if(spec < 37300) {
       s.primaryStarClass = StarSystem::TYPE_STAR_F;
-    } else if(spec < 0.1133) {
+    } else if(spec < 113300) {
       s.primaryStarClass = StarSystem::TYPE_STAR_G;
-    } else if(spec < 0.2343) {
+    } else if(spec < 234300) {
       s.primaryStarClass = StarSystem::TYPE_STAR_K;
     } else {
       s.primaryStarClass = StarSystem::TYPE_STAR_M;
diff --git a/src/star_system.cpp b/src/star_system.cpp
index 38fd2c0..0b391d5 100644
--- a/src/star_system.cpp
+++ b/src/star_system.cpp
@@ -239,6 +239,11 @@ void StarSystem::SBody::EliminateBadChildren(void) {
   }
 }
 
+/*
+ * Choices that depend on floating point values will result in
+ * different universes on different platforms it seems.
+ * As a result we should avoid floating point values in these places.
+ */
 StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
   unsigned long _init[3] = { system_idx, sector_x, sector_y };
   loc.secX    = sector_x;
@@ -262,6 +267,7 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
                                     (int)bodyTypeInfo[type].tempMax);
   rootBody = primary;
 
+  /* FIXME: Not good if the enum is tampered with... */
   int disc_size = rand.Int32(6, 100) + rand.Int32(60,140)*primary->type*primary->type;
   //printf("disc_size %.1fAU\n", disc_size/10.0);
 
@@ -285,11 +291,9 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
                            matrix4x4d::RotateZMatrix(rand.Double(M_PI));
     primary->children.push_back(planet);
 
-    double ang;
-    planet->orbit.KeplerPosAtTime(0, &planet->radMin, &ang);
-    planet->orbit.KeplerPosAtTime(planet->orbit.period*0.5, &planet->radMax, &ang);
-    //printf(%f,%f\n", min/AU, max/AU);
-    //printf(%f year orbital period\n", planet->orbit.period / (60*60*24*365));
+    /* Perihelion and Aphelion. */
+    planet->radMin = planet->orbit.semiMajorAxis - planet->orbit.eccentricity*planet->orbit.semiMajorAxis;
+    planet->radMax = 2*planet->orbit.semiMajorAxis - planet->radMin;
   }
   delete disc;