[Change] Cleaned up codebase to not exceed 80 characters.

This commit is contained in:
Allanis 2013-03-10 14:18:07 +00:00
parent 7fb9bbedce
commit 1d6b0268b5
25 changed files with 240 additions and 133 deletions

View File

@ -57,7 +57,8 @@
// Registers a C function. // Registers a C function.
#define lua_regfunc(l,s,f) (lua_pushcfunction(l,f), lua_setglobal(L,s)) #define lua_regfunc(l,s,f) (lua_pushcfunction(l,f), lua_setglobal(L,s))
// L state, void* buf, int n size, char* s identifier. // L state, void* buf, int n size, char* s identifier.
#define luaL_dobuffer(L,b,n,s) (luaL_loadbuffer(L,b,n,s) || lua_pcall(L, 0, LUA_MULTRET, 0)) #define luaL_dobuffer(L,b,n,s) \
(luaL_loadbuffer(L,b,n,s) || lua_pcall(L, 0, LUA_MULTRET, 0))
// Don't run the function if (n) params aren't passed. // Don't run the function if (n) params aren't passed.
#define MIN_ARGS(n) if(lua_gettop(L) < n) return 0 #define MIN_ARGS(n) if(lua_gettop(L) < n) return 0
@ -234,7 +235,8 @@ static int ai_loadProfile(char* filename) {
profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles)); profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles));
profiles[nprofiles-1].name = profiles[nprofiles-1].name =
malloc(sizeof(char)*(strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX))+1); malloc(sizeof(char)*
(strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX))+1);
snprintf(profiles[nprofiles-1].name, snprintf(profiles[nprofiles-1].name,
strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)+1, strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)+1,
@ -323,7 +325,8 @@ void ai_think(Pilot* pilot) {
cur_pilot->solid->dir_vel = 0.; cur_pilot->solid->dir_vel = 0.;
if(pilot_turn) // Set the turning velocity. if(pilot_turn) // Set the turning velocity.
cur_pilot->solid->dir_vel -= cur_pilot->ship->turn * pilot_turn; cur_pilot->solid->dir_vel -= cur_pilot->ship->turn * pilot_turn;
vect_pset(&cur_pilot->solid->force, cur_pilot->ship->thrust * pilot_acc, cur_pilot->solid->dir); vect_pset(&cur_pilot->solid->force, cur_pilot->ship->thrust * pilot_acc,
cur_pilot->solid->dir);
// Fire weapons if needs be. // Fire weapons if needs be.
if(ai_isFlag(AI_PRIMARY)) pilot_shoot(pilot, pilot_target, 0); // Primary. if(ai_isFlag(AI_PRIMARY)) pilot_shoot(pilot, pilot_target, 0); // Primary.
@ -551,13 +554,15 @@ static int ai_isstopped(lua_State* L) {
// Check if the pilot is an enemy. // Check if the pilot is an enemy.
static int ai_isenemy(lua_State* L) { static int ai_isenemy(lua_State* L) {
if(lua_isnumber(L,1)) if(lua_isnumber(L,1))
lua_pushboolean(L, areEnemies(cur_pilot->faction, pilot_get(lua_tonumber(L,1))->faction)); lua_pushboolean(L, areEnemies(cur_pilot->faction,
pilot_get(lua_tonumber(L,1))->faction));
return 1; return 1;
} }
// Check if the pilot is an ally. // Check if the pilot is an ally.
static int ai_isally(lua_State* L) { static int ai_isally(lua_State* L) {
lua_pushboolean(L, areAllies(cur_pilot->faction, pilot_get(lua_tonumber(L,1))->faction)); lua_pushboolean(L, areAllies(cur_pilot->faction,
pilot_get(lua_tonumber(L,1))->faction));
return 1; return 1;
} }
@ -574,7 +579,8 @@ static int ai_incombat(lua_State* L) {
// Accelerate the pilot based on a param. // Accelerate the pilot based on a param.
static int ai_accel(lua_State* L) { static int ai_accel(lua_State* L) {
pilot_acc = (lua_gettop(L) > 1 && lua_isnumber(L, 1)) ? ABS((double)lua_tonumber(L, 1)) : 1.; pilot_acc = (lua_gettop(L) > 1 && lua_isnumber(L, 1)) ?
ABS((double)lua_tonumber(L, 1)) : 1.;
return 0; return 0;
} }
@ -608,7 +614,8 @@ static int ai_face(lua_State* L) {
if(lua_gettop(L) > 1 && lua_isnumber(L,2)) invert = (int)lua_tonumber(L,2); if(lua_gettop(L) > 1 && lua_isnumber(L,2)) invert = (int)lua_tonumber(L,2);
if(invert) mod *= -1; if(invert) mod *= -1;
diff = angle_diff(cur_pilot->solid->dir, diff = angle_diff(cur_pilot->solid->dir,
(n==-1) ? VANGLE(cur_pilot->solid->pos) : vect_angle(&cur_pilot->solid->pos, v)); (n==-1) ? VANGLE(cur_pilot->solid->pos) :
vect_angle(&cur_pilot->solid->pos, v));
pilot_turn = mod*diff; pilot_turn = mod*diff;
@ -792,7 +799,8 @@ static int ai_settimer(lua_State* L) {
int n; // Get the timer. int n; // Get the timer.
if(lua_isnumber(L, 1)) n = lua_tonumber(L,1); if(lua_isnumber(L, 1)) n = lua_tonumber(L,1);
cur_pilot->timer[n] = (lua_isnumber(L,2)) ? lua_tonumber(L,2) + SDL_GetTicks() : 0; cur_pilot->timer[n] = (lua_isnumber(L,2)) ?
lua_tonumber(L,2) + SDL_GetTicks() : 0;
return 0; return 0;
} }

View File

@ -73,10 +73,13 @@ void player_board(void) {
"%s\n", "%s\n",
cred, "none"); cred, "none");
window_addText(board_wid, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, str); window_addText(board_wid, 80, -30, 120, 60, 0, "txtData",
&gl_smallFont, &cBlack, str);
window_addButton(board_wid, 20, 20, 50, 30, "btnStealScred", "SCred", board_stealCreds); window_addButton(board_wid, 20, 20, 50, 30, "btnStealScred", "SCred",
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", "Leave", board_exit); board_stealCreds);
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", "Leave",
board_exit);
} }
static void board_exit(char* str) { static void board_exit(char* str) {

View File

@ -2,7 +2,8 @@
#include "log.h" #include "log.h"
#include "collision.h" #include "collision.h"
// Collide sprite at (asx, asy) int 'at' at pos 'ap' with sprite at (bsx,bsy) in 'bt' at 'bp' // Collide sprite at (asx, asy) int 'at' at pos 'ap' with sprite at (bsx,bsy)
//in 'bt' at 'bp'
// at - Texture a. // at - Texture a.
// asx - Position of x of sprite a. // asx - Position of x of sprite a.
// asy - Position of y of sprite a. // asy - Position of y of sprite a.
@ -11,8 +12,9 @@
// bsx - Position of x of sprite b. // bsx - Position of x of sprite b.
// bsy - Position of y of sprite b. // bsy - Position of y of sprite b.
// bp - Position in space of sprite b. // bp - Position in space of sprite b.
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap, int CollideSprite(const glTexture* at, const int asx, const int asy,
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) { const Vec2* ap, const glTexture* bt,
const int bsx, const int bsy, const Vec2* bp) {
int x,y; int x,y;
int ax1, ax2, ay1, ay2; int ax1, ax2, ay1, ay2;

View File

@ -2,6 +2,7 @@
#include "opengl.h" #include "opengl.h"
#include "physics.h" #include "physics.h"
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap, int CollideSprite(const glTexture* at, const int asx, const int asy,
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp); const Vec2* ap, const glTexture* bt,
const int bsx, const int bsy, const Vec2* bp);

View File

@ -208,7 +208,8 @@ void conf_parseCLI(int argc, char** argv) {
int option_index = 0; int option_index = 0;
int c = 0; int c = 0;
while((c = getopt_long(argc, argv, "fF:d:J:j:s:m:V:hv", long_options, &option_index)) != -1) { while((c = getopt_long(argc, argv, "fF:d:J:j:s:m:V:hv",
long_options, &option_index)) != -1) {
switch(c) { switch(c) {
case 'f': case 'f':
gl_screen.flags |= OPENGL_FULLSCREEN; gl_screen.flags |= OPENGL_FULLSCREEN;

View File

@ -98,7 +98,8 @@ int areAllies(Faction* a, Faction* b) {
static Faction* faction_parse(xmlNodePtr parent) { static Faction* faction_parse(xmlNodePtr parent) {
Faction* tmp = CALLOC_L(Faction); Faction* tmp = CALLOC_L(Faction);
tmp->name = (char*)xmlGetProp(parent, (xmlChar*)"name"); tmp->name = (char*)xmlGetProp(parent, (xmlChar*)"name");
if(tmp->name == NULL) WARN("Faction from "FACTION_DATA" has invalid or no name"); if(tmp->name == NULL) WARN("Faction from "FACTION_DATA"
has invalid or no name");
return tmp; return tmp;
} }
@ -111,7 +112,8 @@ static void alliance_parse(xmlNodePtr parent) {
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;
do { do {
if((node->type == XML_NODE_START) && (strcmp((char*)node->name, XML_ALLIANCE_TAG)==0)) { if((node->type == XML_NODE_START) && (strcmp((char*)node->name,
XML_ALLIANCE_TAG)==0)) {
// Allocate a new alliance. // Allocate a new alliance.
alliances = realloc(alliances, sizeof(Alliance)*(++nalliances)); alliances = realloc(alliances, sizeof(Alliance)*(++nalliances));
alliances[nalliances-1].name = (char*)xmlGetProp(node,(xmlChar*)"name"); alliances[nalliances-1].name = (char*)xmlGetProp(node,(xmlChar*)"name");
@ -140,12 +142,15 @@ static void alliance_parse(xmlNodePtr parent) {
// Set the crap needed by faction_stack. // Set the crap needed by faction_stack.
for(j = 0; j < (*i); j++) { for(j = 0; j < (*i); j++) {
a->factions[j]->nallies += (*i)-1; a->factions[j]->nallies += (*i)-1;
a->factions[j]->allies = realloc(a->factions[j]->allies, a->factions[j]->nallies*sizeof(Faction*)); static void map_render(double bx, double by, double w, double h);
a->factions[j]->allies = realloc(a->factions[j]->allies,
a->factions[j]->nallies*sizeof(Faction*));
for(n = 0, m = 0; n < (*i); n++, m++) { for(n = 0, m = 0; n < (*i); n++, m++) {
// Add as ally for all factions exept self. // Add as ally for all factions exept self.
if(n == j) m--; if(n == j) m--;
else if(n != j) else if(n != j)
a->factions[j]->allies[a->factions[j]->nallies-(*i)+1+m] = a->factions[n]; a->factions[j]->allies[a->factions[j]->nallies-(*i)+1+m] =
a->factions[n];
} }
} }
} }
@ -162,7 +167,8 @@ static void enemies_parse(xmlNodePtr parent) {
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;
do { do {
if((node->type == XML_NODE_START) && (strcmp((char*)node->name, XML_ENEMIES_TAG)==0)) { if((node->type == XML_NODE_START)
&& (strcmp((char*)node->name, XML_ENEMIES_TAG)==0)) {
i = 0; i = 0;
f = NULL; f = NULL;
j = NULL; j = NULL;
@ -180,7 +186,8 @@ static void enemies_parse(xmlNodePtr parent) {
// Enemy thing is an alliance. // Enemy thing is an alliance.
a = alliance_get((char*)cur->children->content); a = alliance_get((char*)cur->children->content);
if(a == NULL) if(a == NULL)
WARN("Alliance %s not found in stack", (char*)cur->children->content); WARN("Alliance %s not found in stack",
(char*)cur->children->content);
j[i-1] = a->nfactions; j[i-1] = a->nfactions;
f[i-1] = a->factions; f[i-1] = a->factions;
} }
@ -190,7 +197,8 @@ static void enemies_parse(xmlNodePtr parent) {
f[i-1] = malloc(sizeof(Faction*)); f[i-1] = malloc(sizeof(Faction*));
f[i-1][0] = faction_get((char*)cur->children->content); f[i-1][0] = faction_get((char*)cur->children->content);
if(f[i-1][0] == NULL) if(f[i-1][0] == NULL)
WARN("Faction %s not found in stack", (char*)cur->children->content); WARN("Faction %s not found in stack",
(char*)cur->children->content);
} }
free(type); free(type);
} }
@ -204,7 +212,8 @@ static void enemies_parse(xmlNodePtr parent) {
if(x != n) e += j[x]; // Store the total enemies. if(x != n) e += j[x]; // Store the total enemies.
// Now allocate the memory. // Now allocate the memory.
f[n][m]->nenemies += e; f[n][m]->nenemies += e;
f[n][m]->enemies = realloc(f[n][m]->enemies, sizeof(Faction*)*f[n][m]->nenemies); f[n][m]->enemies = realloc(f[n][m]->enemies,
sizeof(Faction*)*f[n][m]->nenemies);
// Add the actualy enemies. // Add the actualy enemies.
for(x = 0, z = 0; x < i; x++) for(x = 0, z = 0; x < i; x++)

View File

@ -75,8 +75,8 @@ void gl_print(const glFont* ft_font, const double x, const double y,
// Acts just like gl_print, but prints to a max length of max. // Acts just like gl_print, but prints to a max length of max.
// Return the amount of characters we had to suppress. // Return the amount of characters we had to suppress.
int gl_printMax(const glFont* ft_font, const int max, const double x, const double y, int gl_printMax(const glFont* ft_font, const int max,
const glColour* c, const char* fmt, ...) { const double x, const double y, const glColour* c, const char* fmt, ...) {
//float h = ft_font->h / .63; // Slightly increases font size. //float h = ft_font->h / .63; // Slightly increases font size.
char txt[256]; char txt[256];
va_list ap; va_list ap;
@ -231,8 +231,8 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
glPushMatrix(); // Translation matrix. glPushMatrix(); // Translation matrix.
glTranslated(x, y, 0); glTranslated(x, y, 0);
glCallLists(lastspace-p-1, GL_UNSIGNED_BYTE, &buf); // This is what we are displaying. // This is what we are displaying.
glCallLists(lastspace-p-1, GL_UNSIGNED_BYTE, &buf);
glPopMatrix(); // Translation matrix. glPopMatrix(); // Translation matrix.
p = lastspace; p = lastspace;
@ -272,7 +272,8 @@ int gl_printWidth(const glFont* ft_font, const char* fmt, ...) {
// ================ // ================
// FONT! // FONT!
// ================ // ================
static void glFontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base) { static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
GLuint* tex_base, int* width_base) {
FT_Glyph glyph; FT_Glyph glyph;
FT_Bitmap bitmap; FT_Bitmap bitmap;
GLubyte* expanded_data; GLubyte* expanded_data;
@ -301,14 +302,16 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex
for(j = 0; j < h; j++) { for(j = 0; j < h; j++) {
for(i = 0; i < w; i++) { for(i = 0; i < w; i++) {
expanded_data[2*(i+j*w)] = expanded_data[2*(i+j*w)+1] = expanded_data[2*(i+j*w)] = expanded_data[2*(i+j*w)+1] =
(i >= bitmap.width || j >= bitmap.rows) ? 0 : bitmap.buffer[i + bitmap.width*j]; (i >= bitmap.width || j >= bitmap.rows) ?
0 : bitmap.buffer[i + bitmap.width*j];
} }
} }
// Create the GL texture. // Create the GL texture.
glBindTexture(GL_TEXTURE_2D, tex_base[(int)ch]); glBindTexture(GL_TEXTURE_2D, tex_base[(int)ch]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_LUMINANCE_ALPHA,
GL_UNSIGNED_BYTE, expanded_data);
free(expanded_data); // No need for this now. free(expanded_data); // No need for this now.

View File

@ -22,12 +22,12 @@ void gl_print(const glFont* ft_font, const double x, const double y,
const glColour* c, const char* fmt, ...); const glColour* c, const char* fmt, ...);
// Print text to a max length. // Print text to a max length.
int gl_printMax(const glFont* ft_font, const int max, const double x, const double y, int gl_printMax(const glFont* ft_font, const int max,
const glColour* c, const char* fmt, ...); const double x, const double y, const glColour* c, const char* fmt, ...);
// Print text centered in width at x. // Print text centered in width at x.
int gl_printMid(const glFont* ft_font, const int width, double x, const double y, int gl_printMid(const glFont* ft_font, const int width,
const glColour* c, const char* fmt, ...); double x, const double y, const glColour* c, const char* fmt, ...);
// Respects \n -> bx, by is top left position. // Respects \n -> bx, by is top left position.
int gl_printText(const glFont* ft_font, const int width, const int height, int gl_printText(const glFont* ft_font, const int width, const int height,

View File

@ -23,14 +23,14 @@ static Keybind** input_keybinds; // Contains the players keybindings.
// Name of each keybinding. // Name of each keybinding.
const char* keybindNames[] = { "accel", "left", "right", "reverse", // Movement. const char* keybindNames[] =
{ "accel", "left", "right", "reverse", // Movement.
"primary", "target", "target_nearest", "face", "board", // Combat. "primary", "target", "target_nearest", "face", "board", // Combat.
"secondary", "secondary_next", // Secondary weapons. "secondary", "secondary_next", // Secondary weapons.
"target_planet", "land", "thyperspace","starmap", "target_planet", "land", "thyperspace","starmap", "jump", // Navigation.
"jump", // Navigation. "mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info", // Misc.
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu",
"info", // Misc.
"end" }; // Must terminate at the end. "end" }; // Must terminate at the end.
// From player.c // From player.c
extern double player_turn; extern double player_turn;
extern double player_acc; extern double player_acc;
@ -254,7 +254,8 @@ static void input_keyup(SDLKey key);
static void input_joyaxis(const unsigned int axis, const int value) { static void input_joyaxis(const unsigned int axis, const int value) {
int i; int i;
for(i = 0; strcmp(keybindNames[i], "end"); i++) for(i = 0; strcmp(keybindNames[i], "end"); i++)
if(input_keybinds[i]->type == KEYBIND_JAXIS && input_keybinds[i]->key == axis) { if(input_keybinds[i]->type == KEYBIND_JAXIS &&
input_keybinds[i]->key == axis) {
input_key(i, -(input_keybinds[i]->reverse) * (double)value / 32767., 1); input_key(i, -(input_keybinds[i]->reverse) * (double)value / 32767., 1);
return; return;
} }
@ -264,7 +265,8 @@ static void input_joyaxis(const unsigned int axis, const int value) {
static void input_joydown(const unsigned int button) { static void input_joydown(const unsigned int button) {
int i; int i;
for(i = 0; strcmp(keybindNames[i], "end");i++) for(i = 0; strcmp(keybindNames[i], "end");i++)
if(input_keybinds[i]->type == KEYBIND_JBUTTON && input_keybinds[i]->key == button) { if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
input_keybinds[i]->key == button) {
input_key(i, KEY_RELEASE, 0); input_key(i, KEY_RELEASE, 0);
return; return;
} }
@ -274,7 +276,8 @@ static void input_joydown(const unsigned int button) {
static void input_joyup(const unsigned int button) { static void input_joyup(const unsigned int button) {
int i; int i;
for(i = 0; strcmp(keybindNames[i], "end"); i++) for(i = 0; strcmp(keybindNames[i], "end"); i++)
if(input_keybinds[i]->type == KEYBIND_JBUTTON && input_keybinds[i]->key == button) { if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
input_keybinds[i]->key == button) {
input_key(i, KEY_RELEASE, 0); input_key(i, KEY_RELEASE, 0);
return; return;
} }
@ -286,7 +289,8 @@ static void input_joyup(const unsigned int button) {
static void input_keydown(SDLKey key) { static void input_keydown(SDLKey key) {
int i; int i;
for(i = 0; strcmp(keybindNames[i], "end"); i++) for(i = 0; strcmp(keybindNames[i], "end"); i++)
if(input_keybinds[i]->type == KEYBIND_KEYBOARD && input_keybinds[i]->key == key) { if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
input_keybinds[i]->key == key) {
input_key(i, KEY_PRESS, 0); input_key(i, KEY_PRESS, 0);
return; return;
} }
@ -296,7 +300,8 @@ static void input_keydown(SDLKey key) {
static void input_keyup(SDLKey key) { static void input_keyup(SDLKey key) {
int i; int i;
for(i = 0; strcmp(keybindNames[i], "end"); i++) for(i = 0; strcmp(keybindNames[i], "end"); i++)
if(input_keybinds[i]->type == KEYBIND_KEYBOARD && input_keybinds[i]->key == key) { if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
input_keybinds[i]->key == key) {
input_key(i, KEY_RELEASE, 0); input_key(i, KEY_RELEASE, 0);
return; return;
} }

View File

@ -2,7 +2,12 @@
#include <SDL.h> #include <SDL.h>
// Input types. // Input types.
typedef enum { KEYBIND_NULL, KEYBIND_KEYBOARD, KEYBIND_JAXIS, KEYBIND_JBUTTON } KeybindType; typedef enum {
KEYBIND_NULL,
KEYBIND_KEYBOARD,
KEYBIND_JAXIS,
KEYBIND_JBUTTON
} KeybindType;
// Set input. // Set input.
void input_setDefault(void); void input_setDefault(void);

View File

@ -19,7 +19,8 @@ int joystick_get(char* namjoystick) {
int joystick_use(int indjoystick) { int joystick_use(int indjoystick) {
if(indjoystick < 0 || indjoystick >= SDL_NumJoysticks()) { if(indjoystick < 0 || indjoystick >= SDL_NumJoysticks()) {
WARN("Joystick of index number %d does not exist. Switching to default (0)", indjoystick); WARN("Joystick of index number %d does not exist. Switching to default (0)",
indjoystick);
indjoystick = 0; indjoystick = 0;
} }
if(joystick) if(joystick)
@ -29,7 +30,8 @@ int joystick_use(int indjoystick) {
LOG("Using joystick %d", indjoystick); LOG("Using joystick %d", indjoystick);
joystick = SDL_JoystickOpen(indjoystick); joystick = SDL_JoystickOpen(indjoystick);
if(joystick == NULL) { if(joystick == NULL) {
WARN("Error opening joystick %d [%s]", indjoystick, SDL_JoystickName(indjoystick)); WARN("Error opening joystick %d [%s]",
indjoystick, SDL_JoystickName(indjoystick));
return -1; return -1;
} }
DEBUG("\t\tWith %d axes, %d buttons, %d balls, and %d hats", DEBUG("\t\tWith %d axes, %d buttons, %d balls, and %d hats",

View File

@ -38,7 +38,8 @@
int landed = 0; int landed = 0;
static int land_wid = 0; // Primary land window. static int land_wid = 0; // Primary land window.
static int secondary_wid = 0; // For the second opened land window (We can only have 2 max). // For the second opened land window (We can only have 2 max).
static int secondary_wid = 0;
static Planet* planet = NULL; static Planet* planet = NULL;
// Commodity excahnge. // Commodity excahnge.
@ -76,13 +77,15 @@ static void commodity_exchange(void) {
goods[2] = strdup("testing."); goods[2] = strdup("testing.");
ngoods = 3; ngoods = 3;
secondary_wid = window_create("Commodity Exchange", -1, -1, COMMODITY_WIDTH, COMMODITY_HEIGHT); secondary_wid = window_create("Commodity Exchange", -1, -1,
COMMODITY_WIDTH, COMMODITY_HEIGHT);
window_addButton(secondary_wid, -20, 20, window_addButton(secondary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose", BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
"Close", commodity_exchange_close); "Close", commodity_exchange_close);
window_addList(secondary_wid, 20, -40, COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT, window_addList(secondary_wid, 20, -40,
COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
"lstGoods", goods, ngoods, 0, NULL); "lstGoods", goods, ngoods, 0, NULL);
} }

View File

@ -62,7 +62,8 @@ static void update_space(void);
static void render_space(void); static void render_space(void);
#ifdef WIN32 #ifdef WIN32
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine,
int nCmdShow) {
int argc = 0; int argc = 0;
char *argv[] = { NULL }; char *argv[] = { NULL };
#else #else

View File

@ -3,7 +3,8 @@
#define LOG(str, args...)(fprintf(stdout, str"\n", ## args)) #define LOG(str, args...)(fprintf(stdout, str"\n", ## args))
#define WARN(str, args...)(fprintf(stderr, "Warning: "str"\n", ## args)) #define WARN(str, args...)(fprintf(stderr, "Warning: "str"\n", ## args))
#define ERR(str, args...) (fprintf(stderr, "ERROR %s:%d: "str"\n", __FILE__, __LINE__, ## args)) #define ERR(str, args...) (fprintf(stderr, "ERROR %s:%d: "str"\n", \
__FILE__, __LINE__, ## args))
#ifdef DEBUG #ifdef DEBUG
# undef DEBUG # undef DEBUG

View File

@ -46,7 +46,8 @@ static int nmusic_selection = 0;
static ALfloat mvolume = 1.; static ALfloat mvolume = 1.;
// Vorbis suff. // Vorbis suff.
static size_t ovpack_read(void* ptr, size_t size, size_t nmemb, void* datasource) { static size_t ovpack_read(void* ptr, size_t size,
size_t nmemb, void* datasource) {
return (ssize_t) pack_read(datasource, ptr, size*nmemb); return (ssize_t) pack_read(datasource, ptr, size*nmemb);
} }
@ -159,7 +160,8 @@ static int stream_loadBuffer(ALuint buffer) {
if(size == BUFFER_SIZE) break; // Buffer is full. if(size == BUFFER_SIZE) break; // Buffer is full.
} }
// Load the buffer. // Load the buffer.
alBufferData(buffer, music_vorbis.format, data, BUFFER_SIZE, music_vorbis.info->rate); alBufferData(buffer, music_vorbis.format, data, BUFFER_SIZE,
music_vorbis.info->rate);
return 0; return 0;
} }

View File

@ -16,7 +16,8 @@
#define SCREEN_W gl_screen.w #define SCREEN_W gl_screen.w
#define SCREEN_H gl_screen.h #define SCREEN_H gl_screen.h
// offsets to Adjust the pilot's place onscreen to be in the middle, even with the GUI. // offsets to Adjust the pilot's place onscreen
//to be in the middle, even with the GUI.
extern double gui_xoff; extern double gui_xoff;
extern double gui_yoff; extern double gui_yoff;
@ -35,7 +36,8 @@ static int pot(int n);
static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh); static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
// PNG. // PNG.
int write_png(const char* file_name, png_bytep* rows, int w, int h, int colourtype, int bitdepth); int write_png(const char* file_name, png_bytep* rows, int w, int h,
int colourtype, int bitdepth);
// ================ // ================
// MISC! // MISC!
@ -178,7 +180,8 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
WARN("Unable to create POT surface %s", SDL_GetError()); WARN("Unable to create POT surface %s", SDL_GetError());
return 0; return 0;
} }
if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT))) { if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0,
SDL_ALPHA_TRANSPARENT))) {
WARN("Unable to fill rect: %s", SDL_GetError()); WARN("Unable to fill rect: %s", SDL_GetError());
return 0; return 0;
} }
@ -199,7 +202,8 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
WARN("Unable to create POT surface %s", SDL_GetError()); WARN("Unable to create POT surface %s", SDL_GetError());
return 0; return 0;
} }
if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT))) { if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0,
SDL_ALPHA_TRANSPARENT))) {
WARN("Unable to fill rect: %s", SDL_GetError()); WARN("Unable to fill rect: %s", SDL_GetError());
return 0; return 0;
} }
@ -384,7 +388,8 @@ void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
} }
// Just straight out blit the thing at position. // Just straight out blit the thing at position.
void gl_blitStatic(const glTexture* texture, const double bx, const double by, const glColour* c) { void gl_blitStatic(const glTexture* texture, const double bx, const double by,
const glColour* c) {
double x, y; double x, y;
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -557,7 +562,8 @@ int gl_init(void) {
DEBUG("Available fullscreen modes:"); DEBUG("Available fullscreen modes:");
for(i = 0; modes[i]; i++) { for(i = 0; modes[i]; i++) {
DEBUG("\t%dx%d", modes[i]->w, modes[i]->h); DEBUG("\t%dx%d", modes[i]->w, modes[i]->h);
if((flags & SDL_FULLSCREEN) && (modes[i]->w == gl_screen.w) && (modes[i]->h == gl_screen.h)) if((flags & SDL_FULLSCREEN) && (modes[i]->w == gl_screen.w) &&
(modes[i]->h == gl_screen.h))
supported = 1; // Mode we asked for is supported. supported = 1; // Mode we asked for is supported.
} }
} }
@ -611,10 +617,13 @@ int gl_init(void) {
gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a; gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a;
// Debug heaven. // Debug heaven.
DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h, gl_screen.depth, DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h,
(gl_has(OPENGL_FULLSCREEN)) ? "fullscreen" : "window"); gl_screen.depth, (gl_has(OPENGL_FULLSCREEN)) ? "fullscreen" : "window");
DEBUG("r: %d, g: %d, b: %d, a: %d, doublebuffer: %s", gl_screen.r, gl_screen.g, gl_screen.b, gl_screen.a,
DEBUG("r: %d, g: %d, b: %d, a: %d, doublebuffer: %s",
gl_screen.r, gl_screen.g, gl_screen.b, gl_screen.a,
(gl_has(OPENGL_DOUBLEBUF)) ? "yes" : "no"); (gl_has(OPENGL_DOUBLEBUF)) ? "yes" : "no");
DEBUG("Renderer: %s", glGetString(GL_RENDERER)); DEBUG("Renderer: %s", glGetString(GL_RENDERER));
// Some openGL options. // Some openGL options.
@ -645,7 +654,8 @@ void gl_exit(void) {
} }
// Saves a png. // Saves a png.
int write_png(const char* file_name, png_bytep* rows, int w, int h, int colourtype, int bitdepth) { int write_png(const char* file_name, png_bytep* rows, int w, int h,
int colourtype, int bitdepth) {
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr; png_infop info_ptr;
FILE* fp = NULL; FILE* fp = NULL;
@ -654,7 +664,8 @@ int write_png(const char* file_name, png_bytep* rows, int w, int h, int colourty
if(!(fp = fopen(file_name, "wb"))) goto fail; if(!(fp = fopen(file_name, "wb"))) goto fail;
doing = "Create png write struct"; doing = "Create png write struct";
if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL))) goto fail; if(!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL))) goto fail;
doing = "Create png info struct"; doing = "Create png info struct";
if(!(info_ptr = png_create_info_struct(png_ptr))) goto fail; if(!(info_ptr = png_create_info_struct(png_ptr))) goto fail;

View File

@ -73,7 +73,8 @@ int outfit_isAmmo(const Outfit* o) {
} }
int outfit_isTurret(const Outfit* o) { int outfit_isTurret(const Outfit* o) {
return ((o->type == OUTFIT_TYPE_TURRET_BOLT) || (o->type == OUTFIT_TYPE_TURRET_BEAM)); return ((o->type == OUTFIT_TYPE_TURRET_BOLT) ||
(o->type == OUTFIT_TYPE_TURRET_BEAM));
} }
// Get the outfit graphics. // Get the outfit graphics.
@ -132,7 +133,13 @@ const char* outfit_typename[] = {
}; };
// Return the broad outfit type. // Return the broad outfit type.
const char* outfit_typenamebroad[] = { "NULL", "Weapon", "Launcher", "Ammo", "Turret" }; const char* outfit_typenamebroad[] = {
"NULL",
"Weapon",
"Launcher",
"Ammo",
"Turret"
};
const char* outfit_getTypeBroad(const Outfit* o) { const char* outfit_getTypeBroad(const Outfit* o) {
int i = 0; int i = 0;
@ -162,7 +169,8 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) {
else if(xml_isNode(node, "range")) tmp->u.blt.range = xml_getFloat(node); else if(xml_isNode(node, "range")) tmp->u.blt.range = xml_getFloat(node);
else if(xml_isNode(node, "accuracy")) tmp->u.blt.accuracy = xml_getFloat(node); else if(xml_isNode(node, "accuracy")) tmp->u.blt.accuracy = xml_getFloat(node);
else if(xml_isNode(node, "gfx")) { else if(xml_isNode(node, "gfx")) {
snprintf(str, strlen(xml_get(node))+sizeof(OUTFIT_GFX)+4, OUTFIT_GFX"%s.png", xml_get(node)); snprintf(str, strlen(xml_get(node))+sizeof(OUTFIT_GFX)+4,
OUTFIT_GFX"%s.png", xml_get(node));
tmp->u.blt.gfx_space = gl_newSprite(str, 6, 6); tmp->u.blt.gfx_space = gl_newSprite(str, 6, 6);
} }
else if(xml_isNode(node, "spfx")) else if(xml_isNode(node, "spfx"))
@ -179,7 +187,8 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) {
} while((cur = cur->next)); } while((cur = cur->next));
} }
} while((node = node->next)); } while((node = node->next));
#define MELEMENT(o,s) if((o) == 0) WARN("Outfit '%s' missing '"s"' element", tmp->name) #define MELEMENT(o,s) if((o) == 0) \
WARN("Outfit '%s' missing '"s"' element", tmp->name)
if(tmp->u.blt.gfx_space == NULL) if(tmp->u.blt.gfx_space == NULL)
WARN("Outfit '%s' missing 'gfx' element", tmp->name); WARN("Outfit '%s' missing 'gfx' element", tmp->name);
MELEMENT(tmp->u.blt.sound, "sound"); MELEMENT(tmp->u.blt.sound, "sound");

View File

@ -143,7 +143,8 @@ int pack_files(const char* outfile, const char** infiles, const uint32_t nfiles)
return -1; return -1;
} }
if(strlen(infiles[i]) > MAX_FILENAME) { if(strlen(infiles[i]) > MAX_FILENAME) {
ERR("filename '%s' is too long, should be only %d characters", infiles[i], MAX_FILENAME); ERR("filename '%s' is too long, should be only %d characters", infiles[i],
MAX_FILENAME);
return -1; return -1;
} }
namesize += strlen(infiles[i]); namesize += strlen(infiles[i]);
@ -221,7 +222,8 @@ int pack_files(const char* outfile, const char** infiles, const uint32_t nfiles)
#endif #endif
free(buf); free(buf);
DEBUG("Packfile success\n\t%d files\n\t%d bytes", nfiles, (int)getfilesize(outfile)); DEBUG("Packfile success\n\t%d files\n\t%d bytes",
nfiles, (int)getfilesize(outfile));
return 0; return 0;
} }
#undef WRITE #undef WRITE
@ -395,7 +397,8 @@ void* pack_readfile(const char* packfile, const char* filename, uint32_t* filesi
size = file->end - file->start; size = file->end - file->start;
buf = malloc(size+1); buf = malloc(size+1);
if((bytes = pack_read(file, buf, size)) != size) { if((bytes = pack_read(file, buf, size)) != size) {
ERR("Reading '%s' from packfile '%s'. Expected %d bytes got %d bytes", filename, packfile, size, bytes); ERR("Reading '%s' from packfile '%s'. Expected %d bytes got %d bytes",
filename, packfile, size, bytes);
free(buf); free(buf);
free(file); free(file);
return NULL; return NULL;

View File

@ -195,7 +195,8 @@ static void rk4_update(Solid* obj, const double dt) {
} }
// Initialize a new solid. // Initialize a new solid.
void solid_init(Solid* dest, const double mass, const double dir, const Vec2* pos, const Vec2* vel) { void solid_init(Solid* dest, const double mass, const double dir,
const Vec2* pos, const Vec2* vel) {
dest->mass = mass; dest->mass = mass;
dest->dir_vel = 0.; dest->dir_vel = 0.;
@ -215,7 +216,8 @@ void solid_init(Solid* dest, const double mass, const double dir, const Vec2* po
} }
// Create a new solid. // Create a new solid.
Solid* solid_create(const double mass, const double dir, const Vec2* pos, const Vec2* vel) { Solid* solid_create(const double mass, const double dir,
const Vec2* pos, const Vec2* vel) {
Solid* dyn = MALLOC_L(Solid); Solid* dyn = MALLOC_L(Solid);
if(dyn == NULL) ERR("Out of memory"); if(dyn == NULL) ERR("Out of memory");
solid_init(dyn, mass, dir, pos, vel); solid_init(dyn, mass, dir, pos, vel);

View File

@ -169,7 +169,8 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) {
switch(w->outfit->type) { switch(w->outfit->type) {
case OUTFIT_TYPE_TURRET_BOLT: case OUTFIT_TYPE_TURRET_BOLT:
case OUTFIT_TYPE_BOLT: case OUTFIT_TYPE_BOLT:
weapon_add(w->outfit, p->solid->dir, &p->solid->pos, &p->solid->vel, p->id, t); weapon_add(w->outfit, p->solid->dir, &p->solid->pos,
&p->solid->vel, p->id, t);
// Can't shoot for a while. // Can't shoot for a while.
w->timer = SDL_GetTicks(); w->timer = SDL_GetTicks();
@ -182,7 +183,8 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) {
// Must be secondary weapon, Shooter can't be the target. // Must be secondary weapon, Shooter can't be the target.
else if(outfit_isLauncher(w->outfit) && (w == p->secondary) && (p->id != t)) { else if(outfit_isLauncher(w->outfit) && (w == p->secondary) && (p->id != t)) {
if(p->ammo && (p->ammo->quantity > 0)) { if(p->ammo && (p->ammo->quantity > 0)) {
weapon_add(p->ammo->outfit, p->solid->dir, &p->solid->pos, &p->solid->vel, p->id, t); weapon_add(p->ammo->outfit, p->solid->dir, &p->solid->pos,
&p->solid->vel, p->id, t);
w->timer = SDL_GetTicks(); // Can't shoot for a while. w->timer = SDL_GetTicks(); // Can't shoot for a while.
p->ammo->quantity -= 1; // There's no getting this one back. p->ammo->quantity -= 1; // There's no getting this one back.
@ -333,7 +335,8 @@ static void pilot_update(Pilot* pilot, const double dt) {
// We are disabled. // We are disabled.
pilot_setFlag(pilot, PILOT_DISABLED); pilot_setFlag(pilot, PILOT_DISABLED);
// Come to a halt slowly. // Come to a halt slowly.
vect_pset(&pilot->solid->vel, VMOD(pilot->solid->vel) * (1. - dt*0.10), VANGLE(pilot->solid->vel)); vect_pset(&pilot->solid->vel,
VMOD(pilot->solid->vel) * (1. - dt*0.10), VANGLE(pilot->solid->vel));
vectnull(&pilot->solid->force); vectnull(&pilot->solid->force);
pilot->solid->dir_vel = 0.; // Stop it from turning. pilot->solid->dir_vel = 0.; // Stop it from turning.
@ -354,7 +357,8 @@ static void pilot_update(Pilot* pilot, const double dt) {
// Update the solid. // Update the solid.
(*pilot->solid->update)(pilot->solid, dt); (*pilot->solid->update)(pilot->solid, dt);
gl_getSpriteFromDir(&pilot->tsx, &pilot->tsy, pilot->ship->gfx_space, pilot->solid->dir); gl_getSpriteFromDir(&pilot->tsx, &pilot->tsy,
pilot->ship->gfx_space, pilot->solid->dir);
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE)) if(!pilot_isFlag(pilot, PILOT_HYPERSPACE))
// Should not go faster. // Should not go faster.
@ -468,8 +472,9 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
// pos : Initial position. // pos : Initial position.
// flags : Tweaking the pilot. // flags : Tweaking the pilot.
// ======================================================== // ========================================================
void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction, AI_Profile* ai, void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction,
const double dir, const Vec2* pos, const Vec2* vel, const int flags) { AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags) {
if(flags & PILOT_PLAYER) // Player is ID 0 if(flags & PILOT_PLAYER) // Player is ID 0
pilot->id = PLAYER_ID; pilot->id = PLAYER_ID;
@ -538,8 +543,9 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction, AI_Profi
} }
// Create a new pilot - Params are same as pilot_init. Return pilot's id. // Create a new pilot - Params are same as pilot_init. Return pilot's id.
unsigned int pilot_create(Ship* ship, char* name, Faction* faction, AI_Profile* ai, const double dir, unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
const Vec2* pos, const Vec2* vel, const int flags) { AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags) {
Pilot* dyn = MALLOC_L(Pilot); Pilot* dyn = MALLOC_L(Pilot);
if(dyn == NULL) { if(dyn == NULL) {
WARN("Unable to allocate memory."); WARN("Unable to allocate memory.");
@ -685,7 +691,8 @@ static Fleet* fleet_parse(const xmlNodePtr parent) {
c = (char*)xmlGetProp(cur, (xmlChar*)"chance"); // Mallocs. c = (char*)xmlGetProp(cur, (xmlChar*)"chance"); // Mallocs.
pilot->chance = atoi(c); pilot->chance = atoi(c);
if(pilot->chance == 0) if(pilot->chance == 0)
WARN("Pilot %s in Fleet %s has 0%% chance of appearing", pilot->name, tmp->name); WARN("Pilot %s in Fleet %s has 0%% chance of appearing",
pilot->name, tmp->name);
if(c) free(c); // Free the external malloc. if(c) free(c); // Free the external malloc.
tmp->pilots = realloc(tmp->pilots, sizeof(FleetPilot)*tmp->npilots); tmp->pilots = realloc(tmp->pilots, sizeof(FleetPilot)*tmp->npilots);

View File

@ -122,11 +122,13 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity); int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity);
// Creation. // Creation.
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai, void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction,
const double dir, const Vec2* pos, const Vec2* vel, const int flags); AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags);
unsigned int pilot_create(Ship* ship, char* name, Faction* faction, AI_Profile* ai, unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
const double dir, const Vec2* pos, const Vec2* vel, const int flags); AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags);
// Init/Cleanup. // Init/Cleanup.
void pilot_destroy(Pilot* p); void pilot_destroy(Pilot* p);

View File

@ -100,10 +100,13 @@ static Msg* msg_stack;
// External. // External.
extern void pilot_render(const Pilot* pilot); // Extern is in Pilot.* extern void pilot_render(const Pilot* pilot); // Extern is in Pilot.*
extern void weapon_minimap(const double res, const double w, const double h, const RadarShape shape); // weapon.c extern void weapon_minimap(const double res,
extern void planets_minimap(const double res, const double w, const double h, const RadarShape shape); // space.c const double w, const double h, const RadarShape shape); // weapon.c
extern void planets_minimap(const double res,
const double w, const double h, const RadarShape shape); // space.c
// Internal. // Internal.
static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h); static void rect_parse(const xmlNodePtr parent,
double* x, double* y, double* w, double* h);
static int gui_parse(const xmlNodePtr parent, const char* name); static int gui_parse(const xmlNodePtr parent, const char* name);
static void gui_renderPilot(const Pilot* p); static void gui_renderPilot(const Pilot* p);
static void gui_renderBar(const glColour* c, const Rect* r, const double w); static void gui_renderBar(const glColour* c, const Rect* r, const double w);
@ -380,10 +383,12 @@ void player_render(void) {
// Nav. // Nav.
if(planet_target >= 0) { if(planet_target >= 0) {
// Planet landing target. // Planet landing target.
gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5, &cConsole, "Land"); gl_printMid(NULL, (int)gui.nav.w,
gui.nav.x, gui.nav.y - 5, &cConsole, "Land");
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x, gui.nav.y - 10 - gl_smallFont.h, gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
NULL, "%s", cur_system->planets[planet_target].name); gui.nav.y - 10 - gl_smallFont.h, NULL, "%s",
cur_system->planets[planet_target].name);
} }
else if(hyperspace_target >= 0) { else if(hyperspace_target >= 0) {
// Hyperspace target. // Hyperspace target.
@ -391,8 +396,9 @@ void player_render(void) {
gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5, gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5,
c, "Hyperspace"); c, "Hyperspace");
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x, gui.nav.y - 10 - gl_smallFont.h, gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
NULL, "%s", systems_nstack[cur_system->jumps[hyperspace_target]].name); gui.nav.y - 10 - gl_smallFont.h, NULL, "%s",
systems_nstack[cur_system->jumps[hyperspace_target]].name);
} }
else { else {
// No NAV target. // No NAV target.
@ -637,7 +643,8 @@ int gui_load(const char* name) {
return 0; return 0;
} }
static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h) { static void rect_parse(const xmlNodePtr parent, double* x, double* y,
double* w, double* h) {
xmlNodePtr cur; xmlNodePtr cur;
int param; int param;
@ -759,24 +766,28 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
cur = node->children; cur = node->children;
do { do {
if(xml_isNode(cur, "shield")) { if(xml_isNode(cur, "shield")) {
rect_parse(cur, &gui.shield.x, &gui.shield.y, &gui.shield.w, &gui.shield.h); rect_parse(cur, &gui.shield.x, &gui.shield.y,
&gui.shield.w, &gui.shield.h);
RELATIVIZE(gui.shield); RELATIVIZE(gui.shield);
} }
if(xml_isNode(cur, "armour")) { if(xml_isNode(cur, "armour")) {
rect_parse(cur, &gui.armour.x, &gui.armour.y, &gui.armour.w, &gui.armour.h); rect_parse(cur, &gui.armour.x, &gui.armour.y,
&gui.armour.w, &gui.armour.h);
RELATIVIZE(gui.armour); RELATIVIZE(gui.armour);
} }
if(xml_isNode(cur, "energy")) { if(xml_isNode(cur, "energy")) {
rect_parse(cur, &gui.energy.x, &gui.energy.y, &gui.energy.w, &gui.energy.h); rect_parse(cur, &gui.energy.x, &gui.energy.y,
&gui.energy.w, &gui.energy.h);
RELATIVIZE(gui.energy); RELATIVIZE(gui.energy);
} }
} while((cur = cur->next)); } while((cur = cur->next));
} }
// Secondary weapon. // Secondary weapon.
else if(xml_isNode(node, "weapon")) { else if(xml_isNode(node, "weapon")) {
rect_parse(node, &gui.weapon.x, &gui.weapon.y, &gui.weapon.w, &gui.weapon.h); rect_parse(node, &gui.weapon.x, &gui.weapon.y,
&gui.weapon.w, &gui.weapon.h);
RELATIVIZE(gui.weapon); RELATIVIZE(gui.weapon);
gui.weapon.y -= gl_defFont.h; gui.weapon.y -= gl_defFont.h;
} }
@ -797,13 +808,15 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
} }
if(xml_isNode(cur, "faction")) { if(xml_isNode(cur, "faction")) {
rect_parse(cur, &gui.target_faction.x, &gui.target_faction.y, NULL, NULL); rect_parse(cur, &gui.target_faction.x, &gui.target_faction.y,
NULL, NULL);
RELATIVIZE(gui.target_faction); RELATIVIZE(gui.target_faction);
gui.target_faction.y -= gl_smallFont.h; gui.target_faction.y -= gl_smallFont.h;
} }
if(xml_isNode(cur, "health")) { if(xml_isNode(cur, "health")) {
rect_parse(cur, &gui.target_health.x, &gui.target_health.y, NULL, NULL); rect_parse(cur, &gui.target_health.x, &gui.target_health.y,
NULL, NULL);
RELATIVIZE(gui.target_health); RELATIVIZE(gui.target_health);
gui.target_health.y -= gl_smallFont.h; gui.target_health.y -= gl_smallFont.h;
} }
@ -850,7 +863,8 @@ void player_think(Pilot* player) {
if(player_isFlag(PLAYER_SECONDARY)) // Needs a target. if(player_isFlag(PLAYER_SECONDARY)) // Needs a target.
pilot_shoot(player, player_target, 1); pilot_shoot(player, player_target, 1);
vect_pset(&player->solid->force, player->ship->thrust * player_acc, player->solid->dir); vect_pset(&player->solid->force, player->ship->thrust * player_acc,
player->solid->dir);
// Set the listener stuff. // Set the listener stuff.
sound_listener(player->solid->dir, sound_listener(player->solid->dir,
@ -922,7 +936,8 @@ void player_land(void) {
player_message("You are too far away to land on %s", planet->name); player_message("You are too far away to land on %s", planet->name);
return; return;
} }
else if((pow2(VX(player->solid->vel)) + pow2(VY(player->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) { else if((pow2(VX(player->solid->vel)) + pow2(VY(player->solid->vel))) >
(double)pow2(MAX_HYPERSPACE_VEL)) {
player_message("You are going too fast to land on %s", planet->name); player_message("You are going too fast to land on %s", planet->name);
return; return;
} }
@ -998,7 +1013,8 @@ void player_screenshot(void) {
WARN("You have reached the maximum amount of screenshots [128]"); WARN("You have reached the maximum amount of screenshots [128]");
return; return;
} }
snprintf(filename, PATH_MAX, "../screenshots/screenshot%03d.png", screenshot_cur); snprintf(filename, PATH_MAX, "../screenshots/screenshot%03d.png",
screenshot_cur);
fp = fopen(filename, "r"); // Myeah, I know it's a horrible way to check. fp = fopen(filename, "r"); // Myeah, I know it's a horrible way to check.
if(fp == NULL) done = 1; if(fp == NULL) done = 1;
else { else {

View File

@ -75,11 +75,13 @@ static Ship* ship_parse(xmlNodePtr parent) {
do { do {
// Load all the data. // Load all the data.
if(xml_isNode(node,"GFX")) { if(xml_isNode(node,"GFX")) {
snprintf(str, strlen(xml_get(node)) + sizeof(SHIP_GFX) + sizeof(SHIP_EXT), snprintf(str, strlen(xml_get(node)) +
sizeof(SHIP_GFX) + sizeof(SHIP_EXT),
SHIP_GFX"%s"SHIP_EXT, xml_get(node)); SHIP_GFX"%s"SHIP_EXT, xml_get(node));
tmp->gfx_space = gl_newSprite(str, 6, 6); tmp->gfx_space = gl_newSprite(str, 6, 6);
// Target. // Target.
snprintf(str, strlen(xml_get(node)) + sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT), snprintf(str, strlen(xml_get(node)) +
sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT),
SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, xml_get(node)); SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, xml_get(node));
tmp->gfx_target = gl_newImage(str); tmp->gfx_target = gl_newImage(str);
@ -145,7 +147,8 @@ static Ship* ship_parse(xmlNodePtr parent) {
otmp->data = outfit_get(xml_get(cur)); otmp->data = outfit_get(xml_get(cur));
stmp = xml_nodeProp(cur, "quantity"); stmp = xml_nodeProp(cur, "quantity");
if(!stmp) if(!stmp)
WARN("Ship '%s' is missing tag 'quantity for outfit '%s'", tmp->name, otmp->data->name); WARN("Ship '%s' is missing tag 'quantity for outfit '%s'",
tmp->name, otmp->data->name);
otmp->quantity = atoi(stmp); otmp->quantity = atoi(stmp);
free(stmp); free(stmp);
otmp->next = NULL; otmp->next = NULL;

View File

@ -73,7 +73,8 @@ extern void player_message(const char* fmt, ...);
// Matrix mode is already displaced to center of the minimap. // 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.) || \ #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)) (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) { void planets_minimap(const double res,
const double w, const double h, const RadarShape shape) {
int i; int i;
int cx, cy, x, y, r, rc; int cx, cy, x, y, r, rc;
double p; double p;
@ -372,7 +373,8 @@ static Planet* planet_get(const char* name) {
// Check elements. // Check elements.
if(tmp) { if(tmp) {
#define MELEMENT(o,s) if((o) == 0) WARN("Planet '%s' missing '"s"' element", tmp->name) #define MELEMENT(o,s) if((o) == 0) WARN("Planet '%s' missing '"s"' element", \
tmp->name)
MELEMENT(tmp->gfx_space, "GFX_space"); MELEMENT(tmp->gfx_space, "GFX_space");
MELEMENT(tmp->gfx_exterior, "GFX_exterior"); MELEMENT(tmp->gfx_exterior, "GFX_exterior");
MELEMENT(flags&FLAG_XSET, "x"); MELEMENT(flags&FLAG_XSET, "x");
@ -494,7 +496,8 @@ static void system_parseJumps(const xmlNodePtr parent) {
system = &systems_stack[i]; system = &systems_stack[i];
break; break;
} }
if(i == systems_nstack) WARN("System '%s' was not found in the stack for some reason", name); if(i == systems_nstack)
WARN("System '%s' was not found in the stack for some reason", name);
free(name); // No need for it now. free(name); // No need for it now.
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;

View File

@ -65,7 +65,8 @@ static void think_seeker(Weapon* w);
// Draw the minimap weapons (player.c). // Draw the minimap weapons (player.c).
#define PIXEL(x,y) if((shape == RADAR_RECT && ABS(x) < w/2. && ABS(y)<h/2.) || \ #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)) (shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y))<rc))) glVertex2i((x),(y))
void weapon_minimap(const double res, const double w, const double h, const RadarShape shape) { void weapon_minimap(const double res,
const double w, const double h, const RadarShape shape) {
int i, rc; int i, rc;
double x, y; double x, y;
@ -129,8 +130,10 @@ static void think_seeker(Weapon* w) {
diff = angle_diff(w->solid->dir, vect_angle(&w->solid->pos, &p->solid->pos)); diff = angle_diff(w->solid->dir, vect_angle(&w->solid->pos, &p->solid->pos));
w->solid->dir_vel = 10 * diff * w->outfit->u.amm.turn; w->solid->dir_vel = 10 * diff * w->outfit->u.amm.turn;
// Face the target. // Face the target.
if(w->solid->dir_vel > w->outfit->u.amm.turn) w->solid->dir_vel = w->outfit->u.amm.turn; if(w->solid->dir_vel > w->outfit->u.amm.turn)
else if(w->solid->dir_vel < -w->outfit->u.amm.turn) w->solid->dir_vel = -w->outfit->u.amm.turn; w->solid->dir_vel = w->outfit->u.amm.turn;
else if(w->solid->dir_vel < -w->outfit->u.amm.turn)
w->solid->dir_vel = -w->outfit->u.amm.turn;
} }
vect_pset(&w->solid->force, w->outfit->u.amm.thrust, w->solid->dir); vect_pset(&w->solid->force, w->outfit->u.amm.thrust, w->solid->dir);
@ -202,7 +205,8 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO: case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO:
case OUTFIT_TYPE_MISSILE_SWARM_AMMO: case OUTFIT_TYPE_MISSILE_SWARM_AMMO:
case OUTFIT_TYPE_MISSILE_SWARM_SMART_AMMO: case OUTFIT_TYPE_MISSILE_SWARM_SMART_AMMO:
if(SDL_GetTicks() > (wlayer[i]->timer + wlayer[i]->outfit->u.amm.duration)) { if(SDL_GetTicks() >
(wlayer[i]->timer + wlayer[i]->outfit->u.amm.duration)) {
weapon_destroy(wlayer[i], layer); weapon_destroy(wlayer[i], layer);
continue; continue;
} }
@ -384,10 +388,11 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
} }
// Add a new weapon. // Add a new weapon.
void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const Vec2* vel, void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
unsigned int parent, unsigned int target) { const Vec2* vel, unsigned int parent, unsigned int target) {
if(!outfit_isWeapon(outfit) && !outfit_isAmmo(outfit) && !outfit_isTurret(outfit)) { if(!outfit_isWeapon(outfit) &&
!outfit_isAmmo(outfit) && !outfit_isTurret(outfit)) {
ERR("Trying to create a weapon from a non-Weapon type Outfit"); ERR("Trying to create a weapon from a non-Weapon type Outfit");
return; return;
} }