[Add] Custom star systems.

This commit is contained in:
Allanis 2017-12-23 17:33:39 +00:00
parent b4b52b7451
commit 7864e3c64f
11 changed files with 298 additions and 53 deletions

View File

@ -8,7 +8,7 @@ Lephisto3D_SOURCES = main.cpp gui_button.cpp gui.cpp gui_fixed.cpp gui_screen.cp
gui_image_radio_button.cpp gui_multi_state_image_button.cpp ship_cpanel.cpp gui_widget.cpp sector_view.cpp \ gui_image_radio_button.cpp gui_multi_state_image_button.cpp ship_cpanel.cpp gui_widget.cpp sector_view.cpp \
mtrand.cpp world_view.cpp system_view.cpp star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp \ mtrand.cpp world_view.cpp system_view.cpp star_system.cpp sector.cpp system_info_view.cpp generic_system_view.cpp \
gui_container.cpp date.cpp space_station.cpp space_station_view.cpp model_body.cpp ship_type.cpp \ gui_container.cpp date.cpp space_station.cpp space_station_view.cpp model_body.cpp ship_type.cpp \
info_view.cpp model_coll_mesh_data.cpp object_viewer_view.cpp info_view.cpp model_coll_mesh_data.cpp object_viewer_view.cpp custom_starsystems.cpp
Lephisto3D_LDADD = sbre/libsbre.a Lephisto3D_LDADD = sbre/libsbre.a
include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h gui_container.h gui_events.h gui_fixed.h \ include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h gui_container.h gui_events.h gui_fixed.h \
@ -16,5 +16,5 @@ include_HEADERS = body.h frame.h generic_system_view.h glfreetype.h gui_button.h
gui_radio_group.h gui_screen.h gui_toggle_button.h gui_widget.h libs.h matrix4x4.h mtrand.h objimport.h l3d.h \ gui_radio_group.h gui_screen.h gui_toggle_button.h gui_widget.h libs.h matrix4x4.h mtrand.h objimport.h l3d.h \
planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \ planet.h player.h dynamic_body.h sector.h sector_view.h ship_cpanel.h ship.h space.h star.h star_system.h system_info_view.h \
system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h model_body.h gui_iselectable.h \ system_view.h vector3.h view.h world_view.h date.h space_station.h space_station_view.h model_body.h gui_iselectable.h \
ship_type.h object.h info_view.h model_coll_mesh_data.h object_viewer_view.h fixed.h ship_type.h object.h info_view.h model_coll_mesh_data.h object_viewer_view.h fixed.h custom_starsystems.h

View File

@ -0,0 +1,82 @@
#include "custom_starsystems.h"
const CustomSBody sol_system[] = {
{
"Sol", StarSystem::TYPE_STAR_G,
-1, fixed(1,1), fixed(1,1), 5700
},
{
"Mercury", StarSystem::TYPE_PLANET_SMALL,
0, fixed(38, 100), fixed(55, 1000), 340,
fixed(387,1000), fixed(205,1000), DEG2RAD(7.0)
},
{
"Venus", StarSystem::TYPE_PLANET_CO2_THICK_ATMOS,
0, fixed(95,100), fixed(815,1000), 735,
fixed(723,1000), fixed(7,1000), DEG2RAD(3.39)
},
{
"Earth", StarSystem::TYPE_PLANET_INDIGENOUS_LIFE,
0, fixed(1,1), fixed(1,1), 288,
fixed(1,1), fixed(167,10000),
},
{
"Moon", StarSystem::TYPE_PLANET_DWARF,
3, fixed(273,1000), fixed(12,1000), 220,
fixed(257,100000), fixed(549,10000), DEG2RAD(5.145)
},
{
"Mars", StarSystem::TYPE_PLANET_SMALL,
0, fixed(533,1000), fixed(107,1000), 227,
fixed(152,100), fixed(933,10000), DEG2RAD(1.85)
},
{
"Jupiter", StarSystem::TYPE_PLANET_LARGE_GAS_GIANT,
0, fixed(11,1), fixed(3178,10), 165,
fixed(5204,1000), fixed(488,10000), DEG2RAD(1.305)
},
{
"Saturn", StarSystem::TYPE_PLANET_MEDIUM_GAS_GIANT,
0, fixed(9,1), fixed(95152,100), 134,
fixed(9582,1000), fixed(557,10000), DEG2RAD(2.485)
},
{
"Uranus", StarSystem::TYPE_PLANET_SMALL_GAS_GIANT,
0, fixed(4,1), fixed(145,10), 76,
fixed(19229,1000), fixed(444,10000), DEG2RAD(0.772)
},
{
"Neptune", StarSystem::TYPE_PLANET_SMALL_GAS_GIANT,
0, fixed(38,10), fixed(17147,100), 72,
fixed(30104,1000), fixed(112, 10000), DEG2RAD(1.768)
},
/* Moons of jupiter. */
{
"Io", StarSystem::TYPE_PLANET_HIGHLY_VOLCANIC,
6, fixed(286,1000), fixed(15,1000), 130,
fixed(282,100000), fixed(41,10000), DEG2RAD(2.21)
},
{
"Europa", StarSystem::TYPE_PLANET_WATER,
6, fixed(245,1000), fixed(8,1000), 102,
fixed(441,100000), fixed(9,1000), 0.0
},
{ 0 }
};
const CustomSystem custom_systems[] = {
{ "Sol", sol_system, StarSystem::TYPE_STAR_G, 0, 0, vector3f(.5, .5, .5) },
{ "Barnard's Star", 0, StarSystem::TYPE_STAR_M, 0, 0, vector3f(.2, .3, .2) },
{ "Ross 154", 0, StarSystem::TYPE_STAR_M, 0, 0, vector3f(.1, .6, -.2) },
{ 0 }
};

26
src/custom_starsystems.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include "star_system.h"
#include "fixed.h"
struct CustomSBody {
const char* name; /* Null to end system. */
StarSystem::BodyType type;
int primaryIdx; /* -1 for primary. */
fixed radius; /* In earth radii for planets, sol radii for stars. */
fixed mass; /* Earth masses or sol masses. */
int averageTemp; /* Kelvin. */
fixed semiMajorAxis; /* In AUs. */
fixed eccentricity;
float inclination; /* Radians. */
};
struct CustomSystem {
const char* name;
const CustomSBody* sbodies; /* 0 to let system be random. */
StarSystem::BodyType primaryType;
int sectorX, sectorY;
vector3f pos;
};
extern const CustomSystem custom_systems[];

View File

@ -29,6 +29,8 @@
#define DEBUG #define DEBUG
#define UNIVERSE_SEED 0xabcd1234
/* /*
* Normal use: * Normal use:
* foreach(container, iter) { do_something(*iter); } * foreach(container, iter) { do_something(*iter); }
@ -50,4 +52,5 @@
#define MAX(x,y) ((x)>(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y))
#define CLAMP(a, min, max) (((a) > (max)) ? (max) : (((a) < (min)) ? (min) : (a))) #define CLAMP(a, min, max) (((a) > (max)) ? (max) : (((a) < (min)) ? (min) : (a)))
#define DEG_2_RAD 0.0174532925 #define DEG_2_RAD 0.0174532925
#define DEG2RAD(x) ((x)*M_PI/180.0)

View File

@ -192,9 +192,8 @@ void L3D::MainLoop(void) {
StarSystem s(0, 0, 0); StarSystem s(0, 0, 0);
HyperspaceTo(&s); HyperspaceTo(&s);
/* Linked list eh... Put player at planet f. */
const float zpos = EARTH_RADIUS * 7; const float zpos = EARTH_RADIUS * 7;
Frame* pframe = *(++(++(++(Space::rootFrame->m_children.begin())))); Frame* pframe = *(Space::rootFrame->m_children.begin());
player->SetFrame(pframe); player->SetFrame(pframe);
player->SetPosition(vector3d(0, zpos*0.1, zpos)); player->SetPosition(vector3d(0, zpos*0.1, zpos));

View File

@ -1,4 +1,6 @@
#include "sector.h" #include "sector.h"
#include "star_system.h"
#include "custom_starsystems.h"
#define SYS_NAME_FLAGS 32 #define SYS_NAME_FLAGS 32
static const char* sys_names[SYS_NAME_FLAGS] = static const char* sys_names[SYS_NAME_FLAGS] =
@ -6,22 +8,47 @@ static const char* sys_names[SYS_NAME_FLAGS] =
"lia", "an", "ar", "ur", "mi", "in", "ti", "qu", "so", "ed", "ess", "lia", "an", "ar", "ur", "mi", "in", "ti", "qu", "so", "ed", "ess",
"ex", "io", "ce", "ze", "fa", "ay", "wa", "da", "ack", "gre" }; "ex", "io", "ce", "ze", "fa", "ay", "wa", "da", "ack", "gre" };
void Sector::GetCustomSystems(void) {
int n = 0;
for(int i = 0; ; i++) {
if(custom_systems[i].name == 0) break;
if((custom_systems[i].sectorX == sx) &&
(custom_systems[i].sectorY == sy)) {
n++;
const CustomSystem* sys = &custom_systems[i];
System s;
s.p = SIZE*sys->pos;
s.name = custom_systems[i].name;
s.primaryStarClass = custom_systems[i].primaryType;
s.customDef = sys->sbodies;
m_systems.push_back(s);
}
}
}
Sector::Sector(int x, int y) { Sector::Sector(int x, int y) {
unsigned long _init[2] = { x, y }; unsigned long _init[3] = { x, y, UNIVERSE_SEED };
sx = x; sy = y; sx = x; sy = y;
MTRand rng(_init, 2); MTRand rng(_init, 3);
m_numSystems = rng.Int32(3,6); GetCustomSystems();
for(int i = 0; i < m_numSystems; i++) { if(m_systems.size() != 0) {
/* Custom sector. */
} else {
int numSystems = rng.Int32(3,6);
for(int i = 0; i < numSystems; i++) {
System s; System s;
s.p.x = rng.Double(SIZE); s.p.x = rng.Double(SIZE);
s.p.y = rng.Double(SIZE); s.p.y = rng.Double(SIZE);
s.p.z = rng.Double(2*SIZE)-SIZE; s.p.z = rng.Double(2*SIZE)-SIZE;
s.name = GenName(rng); s.name = GenName(rng);
s.customDef = 0;
float spec = rng.Int32(1000000); float spec = rng.Int32(1000000);
/* Frequences are from our friends over at wikipedia. ^.^ */ /* Frequencies from wiki. :D */
if(spec < 1) { if(spec < 1) {
s.primaryStarClass = StarSystem::TYPE_STAR_O; s.primaryStarClass = StarSystem::TYPE_STAR_O;
} else if(spec < 1300) { } else if(spec < 1300) {
@ -40,6 +67,7 @@ Sector::Sector(int x, int y) {
m_systems.push_back(s); m_systems.push_back(s);
} }
}
} }
float Sector::DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB) { float Sector::DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB) {

View File

@ -4,6 +4,8 @@
#include "libs.h" #include "libs.h"
#include "star_system.h" #include "star_system.h"
class CustomSBody;
class Sector { class Sector {
public: public:
/* Lightyears. */ /* Lightyears. */
@ -11,15 +13,16 @@ public:
Sector(int x, int y); Sector(int x, int y);
static float DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB); static float DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB);
int m_numSystems;
struct System { struct System {
std::string name; std::string name;
vector3f p; vector3f p;
StarSystem::BodyType primaryStarClass; StarSystem::BodyType primaryStarClass;
const CustomSBody* customDef;
}; };
std::vector<System>m_systems; std::vector<System>m_systems;
private: private:
void GetCustomSystems(void);
std::string GenName(MTRand& rand); std::string GenName(MTRand& rand);
int sx, sy; int sx, sy;
}; };

View File

@ -43,7 +43,7 @@ void Space::Clear(void) {
void Space::GenBody(StarSystem* system, StarSystem::SBody* sbody, Frame* f) { void Space::GenBody(StarSystem* system, StarSystem::SBody* sbody, Frame* f) {
Body* b; Body* b;
if(sbody->supertype == StarSystem::SUPERTYPE_STAR) { if(sbody->GetSuperType() == StarSystem::SUPERTYPE_STAR) {
Star* star = new Star(sbody); Star* star = new Star(sbody);
b = star; b = star;
} else { } else {

View File

@ -1,5 +1,6 @@
#include "star_system.h" #include "star_system.h"
#include "sector.h" #include "sector.h"
#include "custom_starsystems.h"
#define CELSIUS 273.15 #define CELSIUS 273.15
#define DEBUG_DUMP #define DEBUG_DUMP
@ -16,6 +17,7 @@ float StarSystem::starColors[7][3] = {
}; };
static const struct SBodySubTypeInfo { static const struct SBodySubTypeInfo {
StarSystem::BodySuperType supertype;
int mass; /* % sol for stars, unused for planets. */ int mass; /* % sol for stars, unused for planets. */
int radius; /* % Sol radii for stars, % earth radii for planets. */ int radius; /* % Sol radii for stars, % earth radii for planets. */
const char *description; const char *description;
@ -23,102 +25,128 @@ static const struct SBodySubTypeInfo {
int tempMin, tempMax; int tempMin, tempMax;
} bodyTypeInfo[StarSystem::TYPE_MAX] = { } bodyTypeInfo[StarSystem::TYPE_MAX] = {
{ {
StarSystem::SUPERTYPE_STAR,
40, 50, "Type 'M' red star", 40, 50, "Type 'M' red star",
"icons/object_star_m.png", "icons/object_star_m.png",
2000, 3500 2000, 3500
}, },
{ {
StarSystem::SUPERTYPE_STAR,
80, 90, "Type 'K' orange star", 80, 90, "Type 'K' orange star",
"icons/object_star_k.png", "icons/object_star_k.png",
3500, 5000 3500, 5000
}, },
{ {
StarSystem::SUPERTYPE_STAR,
110, 110, "Type 'G' yellow star", 110, 110, "Type 'G' yellow star",
"icons/object_star_g.png", "icons/object_star_g.png",
5000, 6000 5000, 6000
}, },
{ {
StarSystem::SUPERTYPE_STAR,
170, 140, "Type 'F' white star", 170, 140, "Type 'F' white star",
"icons/object_star_f.png", "icons/object_star_f.png",
6000, 7500 6000, 7500
}, },
{ {
StarSystem::SUPERTYPE_STAR,
310, 210, "Type 'A' hot white star", 310, 210, "Type 'A' hot white star",
"icons/object_star_a.png", "icons/object_star_a.png",
7500, 10000 7500, 10000
}, },
{ {
StarSystem::SUPERTYPE_STAR,
1800, 700, "Bright type 'B' blue star", 1800, 700, "Bright type 'B' blue star",
"icons/object_star_b.png", "icons/object_star_b.png",
10000, 30000 10000, 30000
}, },
{ {
StarSystem::SUPERTYPE_STAR,
6400, 1600, "Hot, massive type 'O' blue star", 6400, 1600, "Hot, massive type 'O' blue star",
"icons/object_star_o.png", "icons/object_star_o.png",
30000, 60000 30000, 60000
}, },
{ {
StarSystem::SUPERTYPE_GAS_GIANT,
0, 30, "Brown dwarf sub-stellar object", 0, 30, "Brown dwarf sub-stellar object",
"icons/object_brown_dwarf.png" "icons/object_brown_dwarf.png"
}, },
{ {
StarSystem::SUPERTYPE_GAS_GIANT,
0, 390, "Small gas giant", 0, 390, "Small gas giant",
"icons/object_planet_small_gas_giant.png" "icons/object_planet_small_gas_giant.png"
}, },
{ {
StarSystem::SUPERTYPE_GAS_GIANT,
0, 950, "Medium gas giant", 0, 950, "Medium gas giant",
"icons/object_planet_medium_gas_giant.png" "icons/object_planet_medium_gas_giant.png"
}, },
{ {
StarSystem::SUPERTYPE_GAS_GIANT,
0, 1110, "Large gas giant", 0, 1110, "Large gas giant",
"icons/object_planet_large_gas_giant.png" "icons/object_planet_large_gas_giant.png"
}, },
{ {
StarSystem::SUPERTYPE_GAS_GIANT,
0, 1500, "Very large gas giant", 0, 1500, "Very large gas giant",
"icons/object_planet_large_gas_giant.png" "icons/object_planet_large_gas_giant.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 26, "Small, rocky dwarf planet", 0, 26, "Small, rocky dwarf planet",
"icons/object_planet_dwarf.png" "icons/object_planet_dwarf.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 52, "Small, rocky planet with a thin atmosphere", 0, 52, "Small, rocky planet with a thin atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with liquid water and a nitrogen atmosphere", 0, 100, "Rocky planet with liquid water and a nitrogen atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with a carbon dioxide atmosphere", 0, 100, "Rocky planet with a carbon dioxide atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with a methane atmosphere", 0, 100, "Rocky planet with a methane atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with running water and a thick nitrogen atmosphere", 0, 100, "Rocky planet with running water and a thick nitrogen atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with a thick carbon dioxide atmosphere", 0, 100, "Rocky planet with a thick carbon dioxide atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Rocky planet with a thick methane atmosphere", 0, 100, "Rocky planet with a thick methane atmosphere",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "Highly volcanic world", 0, 100, "Highly volcanic world",
"icons/object_planet_small.png" "icons/object_planet_small.png"
}, },
{ {
StarSystem::SUPERTYPE_ROCKY_PLANET,
0, 100, "World with indigenous life and an oxygen atmosphere", 0, 100, "World with indigenous life and an oxygen atmosphere",
"icons/object_planet_life.png" "icons/object_planet_life.png"
} }
}; };
StarSystem::BodySuperType StarSystem::SBody::GetSuperType(void) const {
return bodyTypeInfo[type].supertype;
}
const char* StarSystem::SBody::GetAstroDescription(void) { const char* StarSystem::SBody::GetAstroDescription(void) {
return bodyTypeInfo[type].description; return bodyTypeInfo[type].description;
} }
@ -241,7 +269,7 @@ double calc_orbital_period(double semiMajorAxis, double centralMass) {
void StarSystem::SBody::EliminateBadChildren(void) { void StarSystem::SBody::EliminateBadChildren(void) {
/* Check for overlapping & unacceptably close orbits. Merge planets. */ /* Check for overlapping & unacceptably close orbits. Merge planets. */
for (std::vector<SBody*>::iterator i = children.begin(); i != children.end(); ++i) { for (std::vector<SBody*>::iterator i = children.begin(); i != children.end(); ++i) {
if((*i)->temp) continue; if((*i)->tmp) continue;
for(std::vector<SBody*>::iterator j = children.begin(); j != children.end(); ++j) { for(std::vector<SBody*>::iterator j = children.begin(); j != children.end(); ++j) {
if((*j) == (*i)) continue; if((*j) == (*i)) continue;
/* Don't eat anything bigger than self. */ /* Don't eat anything bigger than self. */
@ -254,40 +282,108 @@ void StarSystem::SBody::EliminateBadChildren(void) {
fixed j_avg = (j_min+j_max)>>1; fixed j_avg = (j_min+j_max)>>1;
bool eat = false; bool eat = false;
if(i_avg > j_avg) { if(i_avg > j_avg) {
if(i_min < j_max*fixed(12, 10)) eat = true; if(i_min < j_max*fixed(13, 10)) eat = true;
} else { } else {
if(i_max > j_min*fixed(8, 10)) eat = true; if(i_max > j_min*fixed(7, 10)) eat = true;
} }
if(eat) { if(eat) {
(*i)->mass += (*j)->mass; (*i)->mass += (*j)->mass;
(*j)->temp = 1; (*j)->tmp = 1;
} }
} }
} }
/* Kill the eaten ones. */ /* Kill the eaten ones. */
for(std::vector<SBody*>::iterator i = children.begin(); i != children.end();) { for(std::vector<SBody*>::iterator i = children.begin(); i != children.end();) {
if((*i)->temp) { if((*i)->tmp) {
i = children.erase(i); i = children.erase(i);
} }
else i++; else i++;
} }
} }
#if 0
struct CustomSBody {
const char* name; /* Null to end system. */
StarSystem::BodyType type;
int primaryIdx; /* -1 for primary. */
fixed radius; /* In earth radii for planets, sol radii for stars. */
fixed mass; /* Earth masses or sol masses. */
int averageTemp; /* Kelvin. */
fixed semiMajorAxis; /* in AUs. */
fixed eccentricity;
}
#endif
void StarSystem::CustomGetChildOf(SBody* parent, const CustomSBody* customDef, const int primaryIdx) {
const CustomSBody* c = customDef;
for(int i = 0; c->name; c++, i++) {
if(c->primaryIdx != primaryIdx) continue;
SBody* child = new SBody;
StarSystem::BodyType type = c->type;
child->type = type;
child->parent = parent;
child->radius = c->radius;
child->mass = c->mass;
child->averageTemp = c->averageTemp;
child->name = c->name;
child->orbit.eccentricity = c->eccentricity.ToDouble();
child->orbit.semiMajorAxis = c->semiMajorAxis.ToDouble() * AU;
child->orbit.period = calc_orbital_period(child->orbit.semiMajorAxis, parent->GetMass());
child->orbit.rotMatrix = matrix4x4d::RotateYMatrix(c->inclination) *
matrix4x4d::RotateZMatrix(rand.Double(M_PI));
parent->children.push_back(child);
/* Perihelion and Aphelion (in AUS). */
child->radMin = c->semiMajorAxis - c->eccentricity*c->semiMajorAxis;
child->radMax = 2*c->semiMajorAxis - child->radMin;
CustomGetChildOf(child, customDef, i);
}
}
void StarSystem::GenerateFromCustom(const CustomSBody* customDef) {
/* Find primary. */
const CustomSBody* csbody = customDef;
int idx = 0;
while((csbody->name) && (csbody->primaryIdx != -1)) { csbody++; idx++; }
assert(csbody->primaryIdx == -1);
rootBody = new SBody;
StarSystem::BodyType type = csbody->type;
rootBody->type = type;
rootBody->parent = NULL;
rootBody->radius = csbody->radius;
rootBody->mass = csbody->mass;
rootBody->averageTemp = csbody->averageTemp;
rootBody->name = csbody->name;
CustomGetChildOf(rootBody, customDef, idx);
}
/* /*
* Choices that depend on floating point values will result in * Choices that depend on floating point values will result in
* different universes on different platforms it seems. * different universes on different platforms it seems.
* As a result we should avoid floating point values in these places. * As a result we should avoid floating point values in these places.
*/ */
StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) { StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
unsigned long _init[3] = { system_idx, sector_x, sector_y }; unsigned long _init[4] = { system_idx, sector_x, sector_y, UNIVERSE_SEED };
loc.secX = sector_x; loc.secX = sector_x;
loc.secY = sector_y; loc.secY = sector_y;
loc.sysIdx = system_idx; loc.sysIdx = system_idx;
rootBody = 0; rootBody = 0;
if(system_idx == -1) return; if(system_idx == -1) return;
rand.seed(_init, 3); rand.seed(_init, 4);
Sector s = Sector(sector_x, sector_y); Sector s = Sector(sector_x, sector_y);
if(s.m_systems[system_idx].customDef) {
GenerateFromCustom(s.m_systems[system_idx].customDef);
return;
}
/* Primary. */ /* Primary. */
SBody* primary = new SBody; SBody* primary = new SBody;
@ -296,7 +392,6 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
primary->parent = NULL; primary->parent = NULL;
primary->radius = fixed(bodyTypeInfo[type].radius, 100); primary->radius = fixed(bodyTypeInfo[type].radius, 100);
primary->mass = fixed(bodyTypeInfo[type].mass, 100); primary->mass = fixed(bodyTypeInfo[type].mass, 100);
primary->supertype = SUPERTYPE_STAR;
primary->averageTemp = rand.Int32(bodyTypeInfo[type].tempMin, primary->averageTemp = rand.Int32(bodyTypeInfo[type].tempMin,
bodyTypeInfo[type].tempMax); bodyTypeInfo[type].tempMax);
rootBody = primary; rootBody = primary;
@ -312,9 +407,8 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
SBody* planet = new SBody; SBody* planet = new SBody;
planet->type = TYPE_PLANET_DWARF; planet->type = TYPE_PLANET_DWARF;
planet->supertype = SUPERTYPE_NONE;
planet->seed = rand.Int32(); planet->seed = rand.Int32();
planet->temp = 0; planet->tmp = 0;
planet->parent = primary; planet->parent = primary;
//planet->radius = EARTH_RADIUS*bodyTypeInfo[type].radius; //planet->radius = EARTH_RADIUS*bodyTypeInfo[type].radius;
planet->mass = mass; planet->mass = mass;
@ -444,21 +538,20 @@ void StarSystem::SBody::PickPlanetType(SBody* star, const fixed distToPrimary, M
radius = fixed(bodyTypeInfo[type].radius, 100); radius = fixed(bodyTypeInfo[type].radius, 100);
/* Generate moons. */ /* Generate moons. */
if((genMoons) && (mass > fixed(1,2))) { if((genMoons) && (mass > fixed(1,2))) {
std::vector<int>* disc = AccreteDisc(isqrt(mass.v>>12), 10, rand.Int32(1, 10), rand); std::vector<int>* disc = AccreteDisc(isqrt(mass.v>>13), 10, rand.Int32(1, 10), rand);
for(unsigned int i = 0; i < disc->size(); i++) { for(unsigned int i = 0; i < disc->size(); i++) {
fixed mass = fixed((*disc)[i]); fixed mass = fixed((*disc)[i]);
if(mass == 0) continue; if(mass == 0) continue;
SBody* moon = new SBody; SBody* moon = new SBody;
moon->type = TYPE_PLANET_DWARF; moon->type = TYPE_PLANET_DWARF;
moon->supertype = SUPERTYPE_NONE;
moon->seed = rand.Int32(); moon->seed = rand.Int32();
moon->temp = 0; moon->tmp = 0;
moon->parent = this; moon->parent = this;
//moon->radius = EARTH_RADIUS*bodyTypeInfo[type].radius; //moon->radius = EARTH_RADIUS*bodyTypeInfo[type].radius;
moon->mass = mass; moon->mass = mass;
fixed ecc = rand.NFixed(3); fixed ecc = rand.NFixed(3);
fixed semiMajorAxis = fixed(i+1, 2000); fixed semiMajorAxis = fixed(i+2, 2000);
moon->orbit.eccentricity = ecc.ToDouble(); moon->orbit.eccentricity = ecc.ToDouble();
moon->orbit.semiMajorAxis = semiMajorAxis.ToDouble()*AU; moon->orbit.semiMajorAxis = semiMajorAxis.ToDouble()*AU;
moon->orbit.period = calc_orbital_period(moon->orbit.semiMajorAxis, this->mass.ToDouble() * EARTH_MASS); moon->orbit.period = calc_orbital_period(moon->orbit.semiMajorAxis, this->mass.ToDouble() * EARTH_MASS);

View File

@ -17,6 +17,8 @@ struct systemloc_t {
int secX, secY, sysIdx; int secX, secY, sysIdx;
}; };
class CustomSBody;
/* Doubles: All masses are in Kg, all lengths in meters. */ /* Doubles: All masses are in Kg, all lengths in meters. */
class StarSystem { class StarSystem {
public: public:
@ -83,14 +85,21 @@ public:
const char* GetAstroDescription(void); const char* GetAstroDescription(void);
const char* GetIcon(void); const char* GetIcon(void);
BodySuperType GetSuperType() const;
double GetRadius(void) const { double GetRadius(void) const {
if(supertype == SUPERTYPE_STAR) if(GetSuperType() == SUPERTYPE_STAR)
return radius.ToDouble() * SOL_RADIUS; return radius.ToDouble() * SOL_RADIUS;
else else
return radius.ToDouble() * EARTH_RADIUS; return radius.ToDouble() * EARTH_RADIUS;
} }
double GetMass(void) const {
if(GetSuperType() == SUPERTYPE_STAR)
return mass.ToDouble() * SOL_MASS;
else
return mass.ToDouble() * EARTH_MASS;
}
int temp; int tmp;
Orbit orbit; Orbit orbit;
int seed; /* planet.cpp can use to generate terrain. */ int seed; /* planet.cpp can use to generate terrain. */
std::string name; std::string name;
@ -106,6 +115,8 @@ public:
SBody* rootBody; SBody* rootBody;
private: private:
void CustomGetChildOf(SBody* parent, const CustomSBody* customDef, const int parentIdx);
void GenerateFromCustom(const CustomSBody*);
systemloc_t loc; systemloc_t loc;
MTRand rand; MTRand rand;

View File

@ -18,7 +18,7 @@ void SystemInfoView::OnBodySelected(StarSystem::SBody* b) {
snprintf(buf, sizeof(buf), "%s: %s\n" snprintf(buf, sizeof(buf), "%s: %s\n"
"Mass %.2f %s masses\n", "Mass %.2f %s masses\n",
b->name.c_str(), b->GetAstroDescription(), b->mass.ToDouble(), b->name.c_str(), b->GetAstroDescription(), b->mass.ToDouble(),
(b->supertype == StarSystem::SUPERTYPE_STAR ? "Solar" : "Earth")); (b->GetSuperType() == StarSystem::SUPERTYPE_STAR ? "Solar" : "Earth"));
desc += buf; desc += buf;
snprintf(buf, sizeof(buf), "Surface temperature %d C\n", b->averageTemp-273); snprintf(buf, sizeof(buf), "Surface temperature %d C\n", b->averageTemp-273);