666 lines
20 KiB
C
666 lines
20 KiB
C
#include <malloc.h>
|
|
#include <math.h>
|
|
|
|
#include "log.h"
|
|
#include "physics.h"
|
|
#include "rng.h"
|
|
#include "pack.h"
|
|
#include "space.h"
|
|
#include "faction.h"
|
|
#include "xml.h"
|
|
#include "pause.h"
|
|
#include "weapon.h"
|
|
#include "toolkit.h"
|
|
#include "spfx.h"
|
|
#include "player.h"
|
|
|
|
#define XML_PLANET_ID "Planets"
|
|
#define XML_PLANET_TAG "planet"
|
|
|
|
#define XML_SYSTEM_ID "Systems"
|
|
#define XML_SYSTEM_TAG "ssys"
|
|
|
|
#define PLANET_DATA "../dat/planet.xml"
|
|
#define SYSTEM_DATA "../dat/ssys.xml"
|
|
|
|
#define PLANET_GFX_SPACE "../gfx/planet/space/"
|
|
#define PLANET_GFX_EXTERIOR "../gfx/planet/exterior/"
|
|
|
|
#define PLANET_GFX_EXTERIOR_W 400
|
|
#define PLANET_GFX_EXTERIOR_H 400
|
|
|
|
// Overcome warning due to zero value.
|
|
|
|
#define FLAG_XSET (1<<0)
|
|
#define FLAG_YSET (1<<1)
|
|
#define FLAG_ASTEROIDSSET (1<<2)
|
|
#define FLAG_INTEFERENCESET (1<<3)
|
|
|
|
// Star system stack and co.
|
|
StarSystem* systems = NULL; // Star system stack.
|
|
static int nsystems = 0; // Number of star systems.
|
|
static int nplanets = 0; // Total number of loaded planets - A little silly.
|
|
StarSystem* cur_system = NULL; // Current star system.
|
|
|
|
// Current stardate in nice format.
|
|
char* stardate = "Stardate";
|
|
unsigned int date = 0; // time since epoch.
|
|
|
|
// Fleet spawn rate.
|
|
unsigned int spawn_timer = 0; // Controls spawn rate.
|
|
|
|
// Star stack and co.
|
|
#define STAR_BUF 100 // Area to leave around screen, more = less repitition.
|
|
typedef struct Star_ {
|
|
double x, y; // Position. It is simpler ligher to use two doubles than the physics.
|
|
double brightness;
|
|
} Star;
|
|
|
|
static Star* stars = NULL; // Star array.
|
|
static int nstars = 0; // Total stars.
|
|
static int mstars = 0; // Memory stars are taking.
|
|
|
|
// Intern
|
|
static Planet* planet_get(const char* name);
|
|
static void space_addFleet(Fleet* fleet);
|
|
static StarSystem* system_parse(const xmlNodePtr parent);
|
|
static void system_parseJumps(const xmlNodePtr parent);
|
|
static PlanetClass planetclass_get(const char a);
|
|
// Extern.
|
|
extern void player_message(const char* fmt, ...);
|
|
|
|
// Draw the planet. Used in planet.c
|
|
// Matrix mode is already displaced to center of the minimap.
|
|
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x)<w/2. && ABS(y)<h/2.) || \
|
|
(shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y)) < rc))) glVertex2i((x),(y))
|
|
void planets_minimap(const double res, const double w, const double h, const RadarShape shape) {
|
|
int i;
|
|
int cx, cy, x, y, r, rc;
|
|
double p;
|
|
|
|
if(shape == RADAR_CIRCLE) rc = (int)(w*w);
|
|
|
|
glBegin(GL_POINTS);
|
|
glMatrixMode(GL_PROJECTION);
|
|
for(i = 0; i < cur_system->nplanets; i++) {
|
|
r = (int)(cur_system->planets[i].gfx_space->sw / res);
|
|
cx = (int)((cur_system->planets[i].pos.x - player->solid->pos.x) / res);
|
|
cy = (int)((cur_system->planets[i].pos.y - player->solid->pos.y) / res);
|
|
|
|
x = 0;
|
|
y = r;
|
|
p = (5. - (double)(r*3)) / 4.;
|
|
|
|
PIXEL(cx, cy+y);
|
|
PIXEL(cx, cy-y);
|
|
PIXEL(cx+y, cy);
|
|
PIXEL(cx-y, cy);
|
|
|
|
while(x < y) {
|
|
x++;
|
|
if(p < 0) p += 2*(double)(x)+1;
|
|
else p += 2*(double)(x-(--y))+1;
|
|
|
|
if(x == 0) {
|
|
PIXEL(cx, cy+y);
|
|
PIXEL(cx, cy-y);
|
|
PIXEL(cx+y, cy);
|
|
PIXEL(cx-y, cy);
|
|
} else
|
|
if(x == y) {
|
|
PIXEL(cx+x, cy+y);
|
|
PIXEL(cx-x, cy+y);
|
|
PIXEL(cx+x, cy-y);
|
|
PIXEL(cx-x, cy-y);
|
|
} else
|
|
if(x < y) {
|
|
PIXEL(cx+x, cy+y);
|
|
PIXEL(cx-x, cy+y);
|
|
PIXEL(cx+x, cy-y);
|
|
PIXEL(cx-x, cy-y);
|
|
PIXEL(cx+y, cy+x);
|
|
PIXEL(cx-y, cy+x);
|
|
PIXEL(cx+y, cy-x);
|
|
PIXEL(cx-y, cy-x);
|
|
}
|
|
}
|
|
}
|
|
if(ABS(x) < w/2. && ABS(y) < h/2.) {}
|
|
glEnd();
|
|
}
|
|
#undef PIXEL
|
|
|
|
static PlanetClass planetclass_get(const char a) {
|
|
switch(a) {
|
|
case 'A': return PLANET_CLASS_A;
|
|
case 'B': return PLANET_CLASS_B;
|
|
case 'C': return PLANET_CLASS_C;
|
|
case 'D': return PLANET_CLASS_D;
|
|
case 'E': return PLANET_CLASS_E;
|
|
case 'F': return PLANET_CLASS_F;
|
|
case 'G': return PLANET_CLASS_G;
|
|
case 'H': return PLANET_CLASS_H;
|
|
case 'I': return PLANET_CLASS_I;
|
|
case 'J': return PLANET_CLASS_J;
|
|
case 'K': return PLANET_CLASS_K;
|
|
case 'L': return PLANET_CLASS_L;
|
|
case 'M': return PLANET_CLASS_M;
|
|
case 'N': return PLANET_CLASS_N;
|
|
case 'O': return PLANET_CLASS_O;
|
|
case 'P': return PLANET_CLASS_P;
|
|
case 'Q': return PLANET_CLASS_Q;
|
|
case 'R': return PLANET_CLASS_R;
|
|
case 'S': return PLANET_CLASS_S;
|
|
case 'T': return PLANET_CLASS_T;
|
|
case 'X': return PLANET_CLASS_X;
|
|
case 'Y': return PLANET_CLASS_Y;
|
|
case 'Z': return PLANET_CLASS_Z;
|
|
|
|
default: return PLANET_CLASS_NULL;
|
|
};
|
|
}
|
|
|
|
// Check distance to ensure we can go into hyperspace.
|
|
int space_canHyperspace(Pilot* p) {
|
|
int i;
|
|
double d;
|
|
for(i = 0; i < cur_system->nplanets; i++) {
|
|
d = vect_dist(&p->solid->pos, &cur_system->planets[i].pos);
|
|
if(d < MIN_HYPERSPACE_DIST)
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
// Hyperspace, returns 0 if entering hyperspace, or the distance if not.
|
|
int space_hyperspace(Pilot* p) {
|
|
if(!space_canHyperspace(p)) return -1;
|
|
|
|
// Pilot is now going to get automatically ready for hyperspace.
|
|
pilot_setFlag(p, PILOT_HYP_PREP);
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Basically used for spawning fleets.
|
|
void space_update(const double dt) {
|
|
unsigned int t;
|
|
int i, j, f;
|
|
|
|
(void)dt; // Don't need it right now.
|
|
|
|
if(cur_system->nfleets == 0)
|
|
// Please stop checking that there are no fleets.
|
|
spawn_timer = t + 300000;
|
|
|
|
if(spawn_timer < t) {
|
|
// Time to possibly spawn.
|
|
|
|
// Spawn chance is based on overall percentage.
|
|
f = RNG(0, 100*cur_system->nfleets);
|
|
j = 0;
|
|
for(i = 0; i < cur_system->nfleets; i++) {
|
|
j += cur_system->fleets[i].chance;
|
|
if(f < j) {
|
|
// Add one fleet.
|
|
space_addFleet(cur_system->fleets[i].fleet);
|
|
break;
|
|
}
|
|
}
|
|
spawn_timer = t + 60000./(float)cur_system->nfleets;
|
|
}
|
|
}
|
|
|
|
// Crate a fleet.
|
|
static void space_addFleet(Fleet* fleet) {
|
|
int i;
|
|
Vec2 v, vn;
|
|
|
|
// Simulate them coming from hyperspace.
|
|
vect_pset(&v, 2*RNG(MIN_HYPERSPACE_DIST/2, MIN_HYPERSPACE_DIST),
|
|
RNG(0, 360)*M_PI/180.);
|
|
vectnull(&vn);
|
|
|
|
for(i = 0; i < fleet->npilots; i++)
|
|
if(RNG(0, 100) <= fleet->pilots[i].chance) {
|
|
vect_cadd(&v, RNG(75, 150) * (RNG(0,1) ? 1 : -1),
|
|
RNG(75, 150) * (RNG(0,1) ? 1 : -1));
|
|
|
|
pilot_create(fleet->pilots[i].ship,
|
|
fleet->pilots[i].name,
|
|
fleet->faction,
|
|
fleet->ai,
|
|
vect_angle(&v, &vn),
|
|
&v,
|
|
NULL,
|
|
0);
|
|
}
|
|
}
|
|
|
|
// Init the system.
|
|
void space_init(const char* sysname) {
|
|
int i;
|
|
|
|
// Cleanup some stuff.
|
|
player_clear(); // Clears targets.
|
|
pilots_clean(); // Destroy all the current pilots, exept player.
|
|
weapon_clear(); // Get rid of all the weapons.
|
|
spfx_clear(); // Remove of explosions.
|
|
|
|
if((sysname == NULL) && (cur_system == NULL))
|
|
ERR("Cannot reinit system if there is no system previously loaded");
|
|
else if(sysname != NULL) {
|
|
for(i = 0; i < nsystems; i++)
|
|
if(strcmp(sysname, systems[i].name)==0)
|
|
break;
|
|
if(i == nsystems) ERR("System %s not found in stack", sysname);
|
|
cur_system = systems+i;
|
|
|
|
player_message("Entering System %s on %s", sysname, stardate);
|
|
|
|
// Set up stars.
|
|
nstars = (cur_system->stars*gl_screen.w*gl_screen.h+STAR_BUF*STAR_BUF)/(800*640);
|
|
if(mstars < nstars)
|
|
stars = realloc(stars, sizeof(Star)*nstars); // should realloc not malloc.
|
|
for(i = 0; i < nstars; i++) {
|
|
stars[i].brightness = (double)RNG(50, 200)/256.;
|
|
stars[i].x = (double)RNG(-STAR_BUF, gl_screen.w + STAR_BUF);
|
|
stars[i].y = (double)RNG(-STAR_BUF, gl_screen.h + STAR_BUF);
|
|
}
|
|
}
|
|
// Set up fleets -> pilots.
|
|
for(i = 0; i < cur_system->nfleets; i++)
|
|
if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) // Fleet check (50% chance).
|
|
space_addFleet(cur_system->fleets[i].fleet);
|
|
|
|
// Start the spawn timer.
|
|
spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1);
|
|
}
|
|
|
|
// Load the planets of name 'name'.
|
|
static Planet* planet_get(const char* name) {
|
|
Planet* tmp = NULL;
|
|
|
|
char str[PATH_MAX] = "\0";
|
|
char* tstr;
|
|
|
|
uint32_t flags = 0;
|
|
|
|
uint32_t bufsize;
|
|
char* buf = pack_readfile(DATA, PLANET_DATA, &bufsize);
|
|
|
|
xmlNodePtr node, cur;
|
|
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
|
|
|
node = doc->xmlChildrenNode;
|
|
if(strcmp((char*)node->name, XML_PLANET_ID)) {
|
|
ERR("Malformed "PLANET_DATA" file: missing root element '"XML_PLANET_ID"'");
|
|
return NULL;
|
|
}
|
|
|
|
node = node->xmlChildrenNode; // First system node.
|
|
if(node == NULL) {
|
|
ERR("Malformed "PLANET_DATA" file: does not contain elements");
|
|
return NULL;
|
|
}
|
|
|
|
do {
|
|
if(xml_isNode(node, XML_PLANET_TAG)) {
|
|
tstr = xml_nodeProp(node, "name");
|
|
if(strcmp(tstr, name)==0) { // Found.
|
|
tmp = CALLOC_L(Planet);
|
|
tmp->name = tstr;
|
|
|
|
node = node->xmlChildrenNode;
|
|
|
|
do {
|
|
if(xml_isNode(node, "GFX")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "space")) {
|
|
// Load space gfx.
|
|
snprintf(str, strlen(xml_get(cur))+sizeof(PLANET_GFX_SPACE),
|
|
PLANET_GFX_SPACE"%s", xml_get(cur));
|
|
tmp->gfx_space = gl_newImage(str);
|
|
}
|
|
else if(xml_isNode(cur, "exterior")) {
|
|
// Load land gfx.
|
|
snprintf(str, strlen(xml_get(cur))+sizeof(PLANET_GFX_EXTERIOR),
|
|
PLANET_GFX_EXTERIOR"%s", xml_get(cur));
|
|
tmp->gfx_exterior = gl_newImage(str);
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
else if(xml_isNode(node, "pos")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "x")) {
|
|
flags |= FLAG_XSET;
|
|
tmp->pos.x = xml_getFloat(cur);
|
|
}
|
|
else if(xml_isNode(cur, "y")) {
|
|
flags |= FLAG_YSET;
|
|
tmp->pos.y = xml_getFloat(cur);
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
else if(xml_isNode(node, "general")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "class"))
|
|
tmp->class = planetclass_get(cur->children->content[0]);
|
|
else if(xml_isNode(cur, "faction"))
|
|
tmp->faction = faction_get(xml_get(cur));
|
|
else if(xml_isNode(cur, "description"))
|
|
tmp->description = strdup(xml_get(cur));
|
|
else if(xml_isNode(cur, "bar"))
|
|
tmp->bar_description = strdup(xml_get(cur));
|
|
else if(xml_isNode(cur, "services"))
|
|
tmp->services = xml_getInt(cur);
|
|
} while((cur = cur->next));
|
|
}
|
|
} while((node = node->next));
|
|
break;
|
|
} else
|
|
free(tstr); // xmlGetProp mallocs the string.
|
|
}
|
|
} while((node = node->next));
|
|
|
|
xmlFreeDoc(doc);
|
|
free(buf);
|
|
xmlCleanupParser();
|
|
|
|
// Check elements.
|
|
if(tmp) {
|
|
#define MELEMENT(o,s) if((o) == 0) WARN("Planet '%s' missing '"s"' element", tmp->name)
|
|
MELEMENT(tmp->gfx_space, "GFX_space");
|
|
MELEMENT(tmp->gfx_exterior, "GFX_exterior");
|
|
MELEMENT(flags&FLAG_XSET, "x");
|
|
MELEMENT(flags&FLAG_YSET, "y");
|
|
MELEMENT(tmp->class, "class");
|
|
MELEMENT(tmp->faction, "faction");
|
|
#undef MELEMENT
|
|
} else
|
|
WARN("No planet found matching name '%s'", name);
|
|
|
|
return tmp;
|
|
}
|
|
|
|
// Parse node 'parent' which should be the node of a system.
|
|
// Return the StarSystem fully loaded.
|
|
static StarSystem* system_parse(const xmlNodePtr parent) {
|
|
Planet* planet = NULL;
|
|
SystemFleet* fleet = NULL;
|
|
StarSystem* tmp = CALLOC_L(StarSystem);
|
|
char* ptrc;
|
|
xmlNodePtr cur, node;
|
|
|
|
uint32_t flags;
|
|
|
|
tmp->name = xml_nodeProp(parent, "name"); // Already mallocs.
|
|
|
|
node = parent->xmlChildrenNode;
|
|
|
|
do {
|
|
// Load all the things!
|
|
if(xml_isNode(node, "pos")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "x")) {
|
|
flags |= FLAG_XSET;
|
|
tmp->pos.x = xml_getFloat(cur);
|
|
}
|
|
if(xml_isNode(cur, "y")) {
|
|
flags |= FLAG_YSET;
|
|
tmp->pos.y = xml_getFloat(cur);
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
else if(xml_isNode(node, "general")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "stars")) // Non-zero.
|
|
tmp->stars = xml_getInt(cur);
|
|
else if(xml_isNode(cur, "asteroids")) {
|
|
flags |= FLAG_ASTEROIDSSET;
|
|
tmp->asteroids = xml_getInt(cur);
|
|
}
|
|
else if(xml_isNode(cur, "interference")) {
|
|
flags |= FLAG_INTEFERENCESET;
|
|
tmp->interference = xml_getFloat(cur)/100;
|
|
}
|
|
}while((cur = cur->next));
|
|
}
|
|
// Load all the planets.
|
|
else if(xml_isNode(node, "planets")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "planet")) {
|
|
nplanets++; // Increase planet counter.
|
|
planet = planet_get(xml_get(cur));
|
|
planet = planet_get((const char*)cur->children->content);
|
|
tmp->planets = realloc(tmp->planets, sizeof(Planet)*(++tmp->nplanets));
|
|
memcpy(tmp->planets+(tmp->nplanets-1), planet, sizeof(Planet));
|
|
free(planet);
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
// Load all the fleets.
|
|
else if(xml_isNode(node, "fleets")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "fleet")) {
|
|
fleet = CALLOC_L(SystemFleet);
|
|
fleet->fleet = fleet_get(xml_get(cur));
|
|
if(fleet->fleet == NULL)
|
|
WARN("Fleet %s for Star System %s not found", xml_get(cur), tmp->name);
|
|
|
|
ptrc = xml_nodeProp(cur, "chance"); // Malloc ptrc.
|
|
fleet->chance = atoi(ptrc);
|
|
if(fleet->chance == 0)
|
|
WARN("Fleet %s for Star System %s has 0%% chance to appear",
|
|
fleet->fleet->name, tmp->name);
|
|
if(ptrc) free(ptrc); // Free the ptrc.
|
|
|
|
tmp->fleets = realloc(tmp->fleets, sizeof(SystemFleet)*(++tmp->nfleets));
|
|
memcpy(tmp->fleets+(tmp->nfleets-1), fleet, sizeof(SystemFleet));
|
|
free(fleet);
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
} while((node = node->next));
|
|
// Check elements.
|
|
#define MELEMENT(o,s) if((o) == 0) WARN("Star System '%s' missing '"s"' element", tmp->name)
|
|
MELEMENT(flags&FLAG_XSET, "x");
|
|
MELEMENT(flags&FLAG_YSET, "y");
|
|
MELEMENT(tmp->stars, "stars");
|
|
MELEMENT(flags&FLAG_ASTEROIDSSET, "asteroids"); // Can be 0.
|
|
MELEMENT(flags&FLAG_INTEFERENCESET, "inteference");
|
|
#undef MELEMENT
|
|
|
|
return tmp;
|
|
}
|
|
|
|
// Load the jumps into a system.
|
|
static void system_parseJumps(const xmlNodePtr parent) {
|
|
int i;
|
|
StarSystem* system;
|
|
char* name;
|
|
xmlNodePtr cur, node;
|
|
|
|
name = xml_nodeProp(parent, "name"); // Already mallocs.
|
|
for(i = 0; i < nsystems; i++)
|
|
if(strcmp(systems[i].name, name)==0) {
|
|
system = &systems[i];
|
|
break;
|
|
}
|
|
if(i == nsystems) WARN("System '%s' was not found in the stack for some reason", name);
|
|
free(name); // No need for it now.
|
|
|
|
node = parent->xmlChildrenNode;
|
|
|
|
do {
|
|
// Load the data.
|
|
if(xml_isNode(node, "jumps")) {
|
|
cur = node->children;
|
|
do {
|
|
if(xml_isNode(cur, "jump")) {
|
|
for(i = 0; i < nsystems; i++)
|
|
if(strcmp(systems[i].name, xml_get(cur))==0) {
|
|
system->njumps++;
|
|
system->jumps = realloc(system->jumps, system->njumps*sizeof(int));
|
|
system->jumps[system->njumps-1] = i;
|
|
break;
|
|
}
|
|
if(i == nsystems)
|
|
WARN("System '%s' not found for jump linking", xml_get(cur));
|
|
}
|
|
} while((cur = cur->next));
|
|
}
|
|
} while((node = node->next));
|
|
}
|
|
|
|
// Load the ENTIRE universe into RAM. -- WOAH! -- Wasn't that bad. :P
|
|
// -- Used a two system pass to first load the star systems and then set jump routes.
|
|
int space_load(void) {
|
|
uint32_t bufsize;
|
|
char* buf = pack_readfile(DATA, SYSTEM_DATA, &bufsize);
|
|
|
|
StarSystem* tmp;
|
|
|
|
xmlNodePtr node;
|
|
xmlDocPtr doc = xmlParseMemory(buf, bufsize);
|
|
|
|
node = doc->xmlChildrenNode;
|
|
if(!xml_isNode(node, XML_SYSTEM_ID)) {
|
|
ERR("Malformed "SYSTEM_DATA" file: missing root element '"XML_SYSTEM_ID"'");
|
|
return -1;
|
|
}
|
|
node = node->xmlChildrenNode; // First system node.
|
|
if(node == NULL) {
|
|
ERR("Malformed "SYSTEM_DATA" file: does not contain elements");
|
|
return -1;
|
|
}
|
|
// Fist pass - Load all the star systems.
|
|
do {
|
|
if(xml_isNode(node, XML_SYSTEM_TAG)) {
|
|
tmp = system_parse(node);
|
|
systems = realloc(systems, sizeof(StarSystem)*(++nsystems));
|
|
memcpy(systems+nsystems-1, tmp, sizeof(StarSystem));
|
|
free(tmp);
|
|
}
|
|
} while((node = node->next));
|
|
|
|
// Second pass - Load all the jump routes.
|
|
node = doc->xmlChildrenNode->xmlChildrenNode;
|
|
do {
|
|
if(xml_isNode(node, XML_SYSTEM_TAG))
|
|
system_parseJumps(node); // Automatically load the jumps into the system.
|
|
} while((node = node->next));
|
|
|
|
// Cleanup.
|
|
xmlFreeDoc(doc);
|
|
free(buf);
|
|
xmlCleanupParser();
|
|
|
|
DEBUG("Loaded %d star system%s with %d planet%s",
|
|
nsystems, (nsystems==1) ? "" : "s",
|
|
nplanets, (nplanets==1) ? "" : "s");
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Render the system. -- Just playing god now.
|
|
void space_render(double dt) {
|
|
int i;
|
|
unsigned int t, timer;
|
|
double x, y, m;
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glPushMatrix(); // Translation matrix.
|
|
glTranslated(-(double)gl_screen.w/2., -(double)gl_screen.h/2., 0);
|
|
|
|
t = SDL_GetTicks();
|
|
timer = player->ptimer - HYPERSPACE_STARS_BLUR;
|
|
if(pilot_isFlag(player, PILOT_HYPERSPACE) && (timer < t)) {
|
|
// Fancy hyperspace effects.
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
// Lines will be based on velocity.
|
|
m = HYPERSPACE_STARS_LENGTH * (double)(t-timer) / (HYPERSPACE_STARS_BLUR);
|
|
x = m*cos(VANGLE(player->solid->vel)+M_PI);
|
|
y = m*sin(VANGLE(player->solid->vel)+M_PI);
|
|
|
|
for(i = 0; i < nstars; i++) {
|
|
glColor4d(1., 1., 1., stars[i].brightness);
|
|
glVertex2d(stars[i].x, stars[i].y);
|
|
glColor4d(1., 1., 1., 0.);
|
|
glVertex2d(stars[i].x + x*stars[i].brightness, stars[i].y + y*stars[i].brightness);
|
|
}
|
|
glEnd();
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
} else {
|
|
glBegin(GL_POINTS);
|
|
|
|
for(i = 0; i < nstars; i++) {
|
|
if(!paused && !toolkit) {
|
|
// Update position.
|
|
stars[i].x -= VX(player->solid->vel)/(13.-10.*stars[i].brightness)*dt;
|
|
stars[i].y -= VY(player->solid->vel)/(13.-10.*stars[i].brightness)*dt;
|
|
// Scroll those stars bitch!
|
|
if(stars[i].x > gl_screen.w + STAR_BUF) stars[i].x = -STAR_BUF;
|
|
else if(stars[i].x < -STAR_BUF) stars[i].x = gl_screen.w + STAR_BUF;
|
|
if(stars[i].y > gl_screen.h + STAR_BUF) stars[i].y = -STAR_BUF;
|
|
else if(stars[i].y < -STAR_BUF) stars[i].y = gl_screen.h + STAR_BUF;
|
|
}
|
|
// Render.
|
|
glColor4d(1., 1., 1., stars[i].brightness);
|
|
glVertex2d(stars[i].x, stars[i].y);
|
|
}
|
|
glEnd();
|
|
}
|
|
glPopMatrix(); // Translation matrix.
|
|
}
|
|
|
|
// Render the planets.
|
|
void planets_render(void) {
|
|
int i;
|
|
for(i = 0; i < cur_system->nplanets; i++)
|
|
gl_blitSprite(cur_system->planets[i].gfx_space,
|
|
cur_system->planets[i].pos.x, cur_system->planets[i].pos.y, 0, 0, NULL);
|
|
}
|
|
|
|
// Clean up the system.
|
|
void space_exit(void) {
|
|
int i,j;
|
|
for(i = 0; i < nsystems; i++) {
|
|
free(systems[i].name);
|
|
if(systems[i].fleets)
|
|
free(systems[i].fleets);
|
|
if(systems[i].jumps)
|
|
free(systems[i].jumps);
|
|
|
|
for(j = 0; j < systems[i].nplanets; j++) {
|
|
free(systems[i].planets[j].name);
|
|
if(systems[i].planets[j].description)
|
|
free(systems[i].planets[j].description);
|
|
if(systems[i].planets[j].bar_description)
|
|
free(systems[i].planets[j].bar_description);
|
|
|
|
// Graphics.
|
|
if(systems[i].planets[j].gfx_space)
|
|
gl_freeTexture(systems[i].planets[j].gfx_space);
|
|
if(systems[i].planets[j].gfx_exterior)
|
|
gl_freeTexture(systems[i].planets[j].gfx_exterior);
|
|
}
|
|
free(systems[i].planets);
|
|
}
|
|
free(systems);
|
|
if(stars) free(stars);
|
|
}
|
|
|