62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#include "sector.h"
|
|
|
|
#define SYS_NAME_FLAGS 32
|
|
static const char* sys_names[SYS_NAME_FLAGS] =
|
|
{ "en", "la", "can", "be", "and", "phi", "eth", "ol", "ve", "ho", "a",
|
|
"lia", "an", "ar", "ur", "mi", "in", "ti", "qu", "so", "ed", "ess",
|
|
"ex", "io", "ce", "ze", "fa", "ay", "wa", "da", "ack", "gre" };
|
|
|
|
Sector::Sector(int x, int y) {
|
|
unsigned long _init[2] = { x, y };
|
|
sx = x; sy = y;
|
|
MTRand rand(_init, 2);
|
|
|
|
m_numSystems = rand(3,6);
|
|
|
|
for(int i = 0; i < m_numSystems; i++) {
|
|
System s;
|
|
s.p.x = rand(SIZE);
|
|
s.p.y = rand(SIZE);
|
|
s.p.z = rand(2*SIZE)-SIZE;
|
|
s.name = GenName(rand);
|
|
|
|
float spec = rand(1.0);
|
|
/* Frequences are from our friends over at wikipedia. ^.^ */
|
|
if(spec < 0.0000003) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_O;
|
|
} else if(spec < 0.0013) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_B;
|
|
} else if(spec < 0.0073) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_A;
|
|
} else if(spec < 0.0373) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_F;
|
|
} else if(spec < 0.1133) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_G;
|
|
} else if(spec < 0.2343) {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_K;
|
|
} else {
|
|
s.primaryStarClass = StarSystem::SBody::SUBTYPE_STAR_M;
|
|
}
|
|
|
|
m_systems.push_back(s);
|
|
}
|
|
}
|
|
|
|
float Sector::DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB) {
|
|
vector3f dv = a->m_systems[sysIdxA].p - b->m_systems[sysIdxB].p;
|
|
dv += Sector::SIZE*vector3f(a->sx - b->sx, a->sy - b->sy, 0);
|
|
return dv.Length();
|
|
}
|
|
|
|
std::string Sector::GenName(MTRand& rand) {
|
|
std::string name;
|
|
|
|
int len = rand(2, 3);
|
|
for(int i = 0; i < len; i++) {
|
|
name += sys_names[rand(0, SYS_NAME_FLAGS-1)];
|
|
}
|
|
name[0] = toupper(name[0]);
|
|
return name;
|
|
}
|
|
|