[Add] Some Hyperspace range stuff.

[Add] SectorMap indicates current ship location.
This commit is contained in:
Allanis 2017-11-13 20:59:38 +00:00
parent ec2479eb80
commit 56f5411516
12 changed files with 80 additions and 26 deletions

View File

@ -1,6 +1,7 @@
#include "l3d.h" #include "l3d.h"
#include "generic_system_view.h" #include "generic_system_view.h"
#include "sector_view.h" #include "sector_view.h"
#include "sector.h"
GenericSystemView::GenericSystemView(void) : View() { GenericSystemView::GenericSystemView(void) : View() {
px = py = pidx = 0xdeadbeef; px = py = pidx = 0xdeadbeef;
@ -29,9 +30,14 @@ void GenericSystemView::Draw3D(void) {
if(s && !s->IsSystem(px, py, pidx)) { if(s && !s->IsSystem(px, py, pidx)) {
s->GetPos(&px, &py, &pidx); s->GetPos(&px, &py, &pidx);
Sector sec(px, py);
Sector psec(L3D::playerLoc.secX, L3D::playerLoc.secY);
const float dist = Sector::DistanceBetween(&sec, pidx, &psec, L3D::playerLoc.sysIdx);
char buf[256];
snprintf(buf, sizeof(buf), "Dist. %.2f light years.", dist);
m_systemName->SetText(s->rootBody->name); m_systemName->SetText(s->rootBody->name);
m_distance->SetText("Dist. XX.XX light years."); m_distance->SetText(buf);
m_starType->SetText(s->rootBody->GetAstroDescription()); m_starType->SetText(s->rootBody->GetAstroDescription());
m_shortDesc->SetText("Short description of system"); m_shortDesc->SetText("Short description of system");

View File

@ -33,6 +33,10 @@ void InfoView::UpdateInfo(void) {
stats.free_capacity, stats.used_capacity, stats.free_capacity, stats.used_capacity,
stats.total_mass); stats.total_mass);
nfo += std::string(buf); nfo += std::string(buf);
snprintf(buf, sizeof(buf), "\n\nHyperspace range: %.2f light years.", stats.hyperspace_range);
nfo += std::string(buf);
info1->SetText(nfo); info1->SetText(nfo);
} }

View File

@ -5,6 +5,7 @@
#include "gui.h" #include "gui.h"
#include "view.h" #include "view.h"
#include "mtrand.h" #include "mtrand.h"
#include "star_system.h"
class Player; class Player;
class SectorView; class SectorView;
@ -69,6 +70,7 @@ public:
static View* GetView(void) { return current_view; } static View* GetView(void) { return current_view; }
static StarSystem* GetSelectedSystem(void); static StarSystem* GetSelectedSystem(void);
static systemloc_t playerLoc;
static Player* player; static Player* player;
static SectorView* sector_view; static SectorView* sector_view;
static SystemInfoView* system_info_view; static SystemInfoView* system_info_view;

View File

@ -46,6 +46,7 @@ MTRand L3D::rng;
double L3D::gameTime; double L3D::gameTime;
float L3D::frameTime; float L3D::frameTime;
GLUquadric* L3D::gluQuadric; GLUquadric* L3D::gluQuadric;
systemloc_t L3D::playerLoc;
void L3D::Init(IniConfig& config) { void L3D::Init(IniConfig& config) {
int width = config.Int("ScrWidth"); int width = config.Int("ScrWidth");
@ -186,7 +187,7 @@ void L3D::MainLoop(void) {
Space::AddBody(player); Space::AddBody(player);
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
Ship* body = new Ship(ShipType::LADYBIRD); Ship* body = new Ship(ShipType::SLEEK/*LADYBIRD*/);
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "X%c-0%02d", "A"+i, i); snprintf(buf, sizeof(buf), "X%c-0%02d", "A"+i, i);
body->SetLabel(buf); body->SetLabel(buf);
@ -325,6 +326,7 @@ void L3D::HyperspaceTo(StarSystem* dest) {
Space::BuildSystem(dest); Space::BuildSystem(dest);
float ang = rng(M_PI); float ang = rng(M_PI);
L3D::player->SetPosition(vector3d(sin(ang)*8*AU, cos(ang)*8*AU, 0)); L3D::player->SetPosition(vector3d(sin(ang)*8*AU, cos(ang)*8*AU, 0));
dest->GetPos(&L3D::playerLoc);
} }
IniConfig::IniConfig(const char* filename) { IniConfig::IniConfig(const char* filename) {

View File

@ -8,15 +8,16 @@ static const char* sys_names[SYS_NAME_FLAGS] =
Sector::Sector(int x, int y) { Sector::Sector(int x, int y) {
unsigned long _init[2] = { x, y }; unsigned long _init[2] = { x, y };
sx = x; sy = y;
MTRand rand(_init, 2); MTRand rand(_init, 2);
m_numSystems = rand(3,6); m_numSystems = rand(3,6);
for(int i = 0; i < m_numSystems; i++) { for(int i = 0; i < m_numSystems; i++) {
System s; System s;
s.p.x = rand(1.0); s.p.x = rand(SIZE);
s.p.y = rand(1.0); s.p.y = rand(SIZE);
s.p.z = 20.0*(rand(1.0)-0.5); s.p.z = rand(2*SIZE)-SIZE;
s.name = GenName(rand); s.name = GenName(rand);
float spec = rand(1.0); float spec = rand(1.0);
@ -41,10 +42,16 @@ Sector::Sector(int x, int y) {
} }
} }
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 Sector::GenName(MTRand& rand) {
std::string name; std::string name;
int len = rand(2, 4); int len = rand(2, 3);
for(int i = 0; i < len; i++) { for(int i = 0; i < len; i++) {
name += sys_names[rand(0, SYS_NAME_FLAGS-1)]; name += sys_names[rand(0, SYS_NAME_FLAGS-1)];
} }

View File

@ -6,7 +6,10 @@
class Sector { class Sector {
public: public:
/* Lightyears. */
enum { SIZE=8 };
Sector(int x, int y); Sector(int x, int y);
static float DistanceBetween(const Sector* a, int sysIdxA, const Sector* b, int sysIdxB);
int m_numSystems; int m_numSystems;
struct System { struct System {
@ -18,5 +21,6 @@ public:
private: private:
std::string GenName(MTRand& rand); std::string GenName(MTRand& rand);
int sx, sy;
}; };

View File

@ -4,6 +4,7 @@
#include "sector_view.h" #include "sector_view.h"
#include "sector.h" #include "sector.h"
#include "system_info_view.h" #include "system_info_view.h"
#include "player.h"
SectorView::SectorView(void) : GenericSystemView() { SectorView::SectorView(void) : GenericSystemView() {
SetTransparency(true); SetTransparency(true);
@ -50,7 +51,6 @@ bool SectorView::GetSelectedSystem(int* sector_x, int* sector_y, int* system_idx
return m_selected != -1; return m_selected != -1;
} }
#define SEC_SIZE 8
#define DRAW_RAD 2 #define DRAW_RAD 2
#define FFRAC(_x) ((_x)-floor(_x)) #define FFRAC(_x) ((_x)-floor(_x))
@ -73,13 +73,13 @@ void SectorView::Draw3D(void) {
glTranslatef(0, 0, -10-10*m_zoom); glTranslatef(0, 0, -10-10*m_zoom);
glRotatef(m_rot_x, 1, 0, 0); glRotatef(m_rot_x, 1, 0, 0);
glRotatef(m_rot_z, 0, 0, 1); glRotatef(m_rot_z, 0, 0, 1);
glTranslatef(-FFRAC(m_px)*SEC_SIZE, -FFRAC(m_py)*SEC_SIZE, 0); glTranslatef(-FFRAC(m_px)*Sector::SIZE, -FFRAC(m_py)*Sector::SIZE, 0);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
for(int sx = -DRAW_RAD; sx <= DRAW_RAD; sx++) { for(int sx = -DRAW_RAD; sx <= DRAW_RAD; sx++) {
for(int sy = -DRAW_RAD; sy <= DRAW_RAD; sy++) { for(int sy = -DRAW_RAD; sy <= DRAW_RAD; sy++) {
glPushMatrix(); glPushMatrix();
glTranslatef(sx*SEC_SIZE, sy*SEC_SIZE, 0); glTranslatef(sx*Sector::SIZE, sy*Sector::SIZE, 0);
DrawSector(m_secx+sx, m_secy+sy); DrawSector(m_secx+sx, m_secy+sy);
glPopMatrix(); glPopMatrix();
} }
@ -111,9 +111,9 @@ void SectorView::DrawSector(int sx, int sy) {
glColor3f(0, .8, 0); glColor3f(0, .8, 0);
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex3f(0, 0, 0); glVertex3f(0, 0, 0);
glVertex3f(0, SEC_SIZE, 0); glVertex3f(0, Sector::SIZE, 0);
glVertex3f(SEC_SIZE, SEC_SIZE, 0); glVertex3f(Sector::SIZE, Sector::SIZE, 0);
glVertex3f(SEC_SIZE, 0, 0); glVertex3f(Sector::SIZE, 0, 0);
glEnd(); glEnd();
if(!(sx || sy)) glColor3f(1, 1, 0); if(!(sx || sy)) glColor3f(1, 1, 0);
@ -121,7 +121,7 @@ void SectorView::DrawSector(int sx, int sy) {
for(std::vector<Sector::System>::iterator i = s.m_systems.begin(); i != s.m_systems.end(); ++i) { for(std::vector<Sector::System>::iterator i = s.m_systems.begin(); i != s.m_systems.end(); ++i) {
glColor3fv(StarSystem::starColors[(*i).primaryStarClass]); glColor3fv(StarSystem::starColors[(*i).primaryStarClass]);
glPushMatrix(); glPushMatrix();
glTranslatef((*i).p.x*SEC_SIZE, (*i).p.y*SEC_SIZE, 0); glTranslatef((*i).p.x, (*i).p.y, 0);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex3f(0, 0, 0); glVertex3f(0, 0, 0);
glVertex3f(0, 0, (*i).p.z); glVertex3f(0, 0, (*i).p.z);
@ -132,12 +132,32 @@ void SectorView::DrawSector(int sx, int sy) {
glRotatef(-m_rot_z, 0, 0, 1); glRotatef(-m_rot_z, 0, 0, 1);
glRotatef(-m_rot_x, 1, 0, 0); glRotatef(-m_rot_x, 1, 0, 0);
glCallList(m_gluDiskDlist); glCallList(m_gluDiskDlist);
/* Player location indicator. */
if((sx == L3D::playerLoc.secX) && (sy == L3D::playerLoc.secY) && (num == L3D::playerLoc.sysIdx)) {
shipstats_t stats;
L3D::player->CalcStats(&stats);
glColor3f(0, 0, 1);
glBegin(GL_LINE_LOOP);
/* Draw a lovely circle around our beloved player. */
for(float theta = 0; theta < 2*M_PI; theta += 0.05*M_PI) {
glVertex3f(stats.hyperspace_range*sin(theta), stats.hyperspace_range*cos(theta), 0);
}
glEnd();
glPushMatrix();
glDepthRange(0.2, 1.2);
glColor3f(3, 3, 3);
glCallList(m_gluDiskDlist);
glPopMatrix();
}
/* Selected indicator. */ /* Selected indicator. */
if((sx == m_secx) && (sy == m_secy) && (num == m_selected)) { if((sx == m_secx) && (sy == m_secy) && (num == m_selected)) {
glDepthRange(0.1, 1.1);
glColor3f(0, 0.8, 0); glColor3f(0, 0.8, 0);
glScalef(2, 2, 2); glScalef(2, 2, 2);
glCallList(m_gluDiskDlist); glCallList(m_gluDiskDlist);
} }
glDepthRange(0, 1);
glPopMatrix(); glPopMatrix();
glColor3f(.7, .7, .7); glColor3f(.7, .7, .7);
PutText((*i).name); PutText((*i).name);
@ -169,8 +189,8 @@ void SectorView::Update(void) {
m_secy = (int)floor(m_py); m_secy = (int)floor(m_py);
Sector s = Sector(m_secx, m_secy); Sector s = Sector(m_secx, m_secy);
float px = FFRAC(m_px); float px = FFRAC(m_px)*Sector::SIZE;
float py = FFRAC(m_py); float py = FFRAC(m_py)*Sector::SIZE;
m_selected = -1; m_selected = -1;
float min_dist = FLT_MAX; float min_dist = FLT_MAX;

View File

@ -50,6 +50,10 @@ void Ship::CalcStats(shipstats_t* stats) {
} }
stats->free_capacity = stats->max_capacity - stats->used_capacity; stats->free_capacity = stats->max_capacity - stats->used_capacity;
stats->total_mass = stats->used_capacity + stype.hullMass; stats->total_mass = stats->used_capacity + stype.hullMass;
Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE);
float hyperclass = EquipType::types[t].pval;
stats->hyperspace_range = 200 * hyperclass * hyperclass / stats->total_mass;
} }
void Ship::AITurn(void) { void Ship::AITurn(void) {

View File

@ -49,22 +49,22 @@ const EquipType EquipType::types[] = {
{ {
"None", "None",
Equip::SLOT_ENGINE, Equip::SLOT_ENGINE,
0, 0, 0
}, },
{ {
"Interplanetary Drive", "Interplanetary Drive",
Equip::SLOT_ENGINE, Equip::SLOT_ENGINE,
1 1, 0
}, },
{ {
"Class 1 Hyperdrive", "Class 1 Hyperdrive",
Equip::SLOT_ENGINE, Equip::SLOT_ENGINE,
4 4, 1
}, },
{ {
"1MW beam laser", "1MW beam laser",
Equip::SLOT_LASER, Equip::SLOT_LASER,
1 1, 1
} }
}; };

View File

@ -56,7 +56,7 @@ struct EquipType {
const char* name; const char* name;
Equip::Slot slot; Equip::Slot slot;
int mass; int mass;
int pval; /* Used for general 'power' attribute.. */
static const EquipType types[]; static const EquipType types[];
}; };

View File

@ -236,9 +236,9 @@ void StarSystem::SBody::EliminateBadChildren(void) {
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[3] = { system_idx, sector_x, sector_y };
m_sectorX = sector_x; loc.secX = sector_x;
m_sectorY = sector_y; loc.secY = sector_y;
m_systemIdx = 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, 3);
@ -442,7 +442,7 @@ StarSystem::~StarSystem(void) {
} }
bool StarSystem::IsSystem(int sector_x, int sector_y, int system_idx) { bool StarSystem::IsSystem(int sector_x, int sector_y, int system_idx) {
return (sector_x == m_sectorX) && (sector_y == m_sectorY) && (system_idx == m_systemIdx); return(sector_x == loc.secX) && (sector_y == loc.secY) && (system_idx == loc.sysIdx);
} }
StarSystem::SBody::~SBody(void) { StarSystem::SBody::~SBody(void) {

View File

@ -13,14 +13,19 @@
#define AU 149598000000.0 #define AU 149598000000.0
#define G 6.67428e-11 #define G 6.67428e-11
struct systemloc_t {
int secX, secY, sysIdx;
};
/* All masses are in Kg, all lengths in meters. */ /* All masses are in Kg, all lengths in meters. */
class StarSystem { class StarSystem {
public: public:
StarSystem(int sector_x, int sector_y, int system_idx); StarSystem(int sector_x, int sector_y, int system_idx);
~StarSystem(void); ~StarSystem(void);
bool IsSystem(int sector_x, int sector_y, int system_idx); bool IsSystem(int sector_x, int sector_y, int system_idx);
void GetPos(systemloc_t* l) { *l = loc; };
void GetPos(int* sec_x, int* sec_y, int* sys_idx) { void GetPos(int* sec_x, int* sec_y, int* sys_idx) {
*sec_x = m_sectorX; *sec_y = m_sectorY; *sys_idx = m_systemIdx; *sec_x = loc.secX; *sec_y = loc.secY, *sys_idx = loc.sysIdx;
} }
static float starColors[7][3]; static float starColors[7][3];
@ -84,7 +89,7 @@ public:
SBody* rootBody; SBody* rootBody;
private: private:
int m_sectorX, m_sectorY, m_systemIdx; systemloc_t loc;
MTRand rand; MTRand rand;
}; };