[Change] Cleaned up codebase to not exceed 80 characters.
This commit is contained in:
parent
7fb9bbedce
commit
1d6b0268b5
28
src/ai.c
28
src/ai.c
@ -57,7 +57,8 @@
|
||||
// Registers a C function.
|
||||
#define lua_regfunc(l,s,f) (lua_pushcfunction(l,f), lua_setglobal(L,s))
|
||||
// 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.
|
||||
#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[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,
|
||||
strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)+1,
|
||||
@ -323,7 +325,8 @@ void ai_think(Pilot* pilot) {
|
||||
cur_pilot->solid->dir_vel = 0.;
|
||||
if(pilot_turn) // Set the turning velocity.
|
||||
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.
|
||||
if(ai_isFlag(AI_PRIMARY)) pilot_shoot(pilot, pilot_target, 0); // Primary.
|
||||
@ -519,7 +522,7 @@ static int ai_minbrakedist(lua_State* L) {
|
||||
double time = VMOD(cur_pilot->solid->vel) /
|
||||
(cur_pilot->ship->thrust / cur_pilot->solid->mass);
|
||||
|
||||
double dist = VMOD(cur_pilot->solid->vel) * (time + 180./cur_pilot->ship->turn) -
|
||||
double dist = VMOD(cur_pilot->solid->vel)*(time + 180./cur_pilot->ship->turn)-
|
||||
0.5 * (cur_pilot->ship->thrust / cur_pilot->solid->mass)*time*time;
|
||||
|
||||
lua_pushnumber(L, dist); // return
|
||||
@ -551,13 +554,15 @@ static int ai_isstopped(lua_State* L) {
|
||||
// Check if the pilot is an enemy.
|
||||
static int ai_isenemy(lua_State* L) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Check if the pilot is an ally.
|
||||
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;
|
||||
}
|
||||
|
||||
@ -574,7 +579,8 @@ static int ai_incombat(lua_State* L) {
|
||||
|
||||
// Accelerate the pilot based on a param.
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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(invert) mod *= -1;
|
||||
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;
|
||||
|
||||
@ -792,7 +799,8 @@ static int ai_settimer(lua_State* L) {
|
||||
int n; // Get the timer.
|
||||
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;
|
||||
}
|
||||
|
||||
@ -822,7 +830,7 @@ static int ai_broadcast(lua_State* L) {
|
||||
MIN_ARGS(1);
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
player_message("Broadcast: %s> \"%s\"", cur_pilot->name, lua_tostring(L, 1));
|
||||
player_message("Broadcast: %s> \"%s\"", cur_pilot->name, lua_tostring(L,1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
11
src/board.c
11
src/board.c
@ -73,10 +73,13 @@ void player_board(void) {
|
||||
"%s\n",
|
||||
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, "btnBoardingClose", "Leave", board_exit);
|
||||
window_addButton(board_wid, 20, 20, 50, 30, "btnStealScred", "SCred",
|
||||
board_stealCreds);
|
||||
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", "Leave",
|
||||
board_exit);
|
||||
}
|
||||
|
||||
static void board_exit(char* str) {
|
||||
@ -97,7 +100,7 @@ static void board_stealCreds(char* str) {
|
||||
}
|
||||
|
||||
// Calculate success.
|
||||
if(RNG(0, 100) < (int)(50. * (double)p->ship->crew/(double)player->ship->crew)) {
|
||||
if(RNG(0,100) < (int)(50.*(double)p->ship->crew/(double)player->ship->crew)) {
|
||||
board_fail();
|
||||
return;
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
#include "log.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.
|
||||
// asx - Position of x of sprite a.
|
||||
// asy - Position of y of sprite a.
|
||||
@ -11,8 +12,9 @@
|
||||
// bsx - Position of x of sprite b.
|
||||
// bsy - Position of y of sprite b.
|
||||
// bp - Position in space of sprite b.
|
||||
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
|
||||
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) {
|
||||
int CollideSprite(const glTexture* at, const int asx, const int asy,
|
||||
const Vec2* ap, const glTexture* bt,
|
||||
const int bsx, const int bsy, const Vec2* bp) {
|
||||
|
||||
int x,y;
|
||||
int ax1, ax2, ay1, ay2;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "opengl.h"
|
||||
#include "physics.h"
|
||||
|
||||
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
|
||||
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp);
|
||||
int CollideSprite(const glTexture* at, const int asx, const int asy,
|
||||
const Vec2* ap, const glTexture* bt,
|
||||
const int bsx, const int bsy, const Vec2* bp);
|
||||
|
||||
|
@ -208,7 +208,8 @@ void conf_parseCLI(int argc, char** argv) {
|
||||
int option_index = 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) {
|
||||
case 'f':
|
||||
gl_screen.flags |= OPENGL_FULLSCREEN;
|
||||
|
@ -98,7 +98,8 @@ int areAllies(Faction* a, Faction* b) {
|
||||
static Faction* faction_parse(xmlNodePtr parent) {
|
||||
Faction* tmp = CALLOC_L(Faction);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -111,7 +112,8 @@ static void alliance_parse(xmlNodePtr parent) {
|
||||
node = parent->xmlChildrenNode;
|
||||
|
||||
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.
|
||||
alliances = realloc(alliances, sizeof(Alliance)*(++nalliances));
|
||||
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.
|
||||
for(j = 0; j < (*i); j++) {
|
||||
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++) {
|
||||
// Add as ally for all factions exept self.
|
||||
if(n == j) m--;
|
||||
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;
|
||||
|
||||
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;
|
||||
f = NULL;
|
||||
j = NULL;
|
||||
@ -180,7 +186,8 @@ static void enemies_parse(xmlNodePtr parent) {
|
||||
// Enemy thing is an alliance.
|
||||
a = alliance_get((char*)cur->children->content);
|
||||
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;
|
||||
f[i-1] = a->factions;
|
||||
}
|
||||
@ -190,7 +197,8 @@ static void enemies_parse(xmlNodePtr parent) {
|
||||
f[i-1] = malloc(sizeof(Faction*));
|
||||
f[i-1][0] = faction_get((char*)cur->children->content);
|
||||
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);
|
||||
}
|
||||
@ -204,7 +212,8 @@ static void enemies_parse(xmlNodePtr parent) {
|
||||
if(x != n) e += j[x]; // Store the total enemies.
|
||||
// Now allocate the memory.
|
||||
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.
|
||||
for(x = 0, z = 0; x < i; x++)
|
||||
|
17
src/font.c
17
src/font.c
@ -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.
|
||||
// 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,
|
||||
const glColour* c, const char* fmt, ...) {
|
||||
int gl_printMax(const glFont* ft_font, const int max,
|
||||
const double x, const double y, const glColour* c, const char* fmt, ...) {
|
||||
//float h = ft_font->h / .63; // Slightly increases font size.
|
||||
char txt[256];
|
||||
va_list ap;
|
||||
@ -231,8 +231,8 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
|
||||
glPushMatrix(); // Translation matrix.
|
||||
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.
|
||||
|
||||
p = lastspace;
|
||||
@ -272,7 +272,8 @@ int gl_printWidth(const glFont* ft_font, const char* fmt, ...) {
|
||||
// ================
|
||||
// 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_Bitmap bitmap;
|
||||
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(i = 0; i < w; i++) {
|
||||
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.
|
||||
glBindTexture(GL_TEXTURE_2D, tex_base[(int)ch]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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.
|
||||
|
||||
|
@ -22,12 +22,12 @@ void gl_print(const glFont* ft_font, const double x, const double y,
|
||||
const glColour* c, const char* fmt, ...);
|
||||
|
||||
// Print text to a max length.
|
||||
int gl_printMax(const glFont* ft_font, const int max, const double x, const double y,
|
||||
const glColour* c, const char* fmt, ...);
|
||||
int gl_printMax(const glFont* ft_font, const int max,
|
||||
const double x, const double y, const glColour* c, const char* fmt, ...);
|
||||
|
||||
// Print text centered in width at x.
|
||||
int gl_printMid(const glFont* ft_font, const int width, double x, const double y,
|
||||
const glColour* c, const char* fmt, ...);
|
||||
int gl_printMid(const glFont* ft_font, const int width,
|
||||
double x, const double y, const glColour* c, const char* fmt, ...);
|
||||
|
||||
// Respects \n -> bx, by is top left position.
|
||||
int gl_printText(const glFont* ft_font, const int width, const int height,
|
||||
|
25
src/input.c
25
src/input.c
@ -23,14 +23,14 @@ static Keybind** input_keybinds; // Contains the players keybindings.
|
||||
|
||||
|
||||
// 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.
|
||||
"secondary", "secondary_next", // Secondary weapons.
|
||||
"target_planet", "land", "thyperspace","starmap",
|
||||
"jump", // Navigation.
|
||||
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu",
|
||||
"info", // Misc.
|
||||
"target_planet", "land", "thyperspace","starmap", "jump", // Navigation.
|
||||
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info", // Misc.
|
||||
"end" }; // Must terminate at the end.
|
||||
|
||||
// From player.c
|
||||
extern double player_turn;
|
||||
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) {
|
||||
int 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);
|
||||
return;
|
||||
}
|
||||
@ -264,7 +265,8 @@ static void input_joyaxis(const unsigned int axis, const int value) {
|
||||
static void input_joydown(const unsigned int button) {
|
||||
int 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);
|
||||
return;
|
||||
}
|
||||
@ -274,7 +276,8 @@ static void input_joydown(const unsigned int button) {
|
||||
static void input_joyup(const unsigned int button) {
|
||||
int 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);
|
||||
return;
|
||||
}
|
||||
@ -286,7 +289,8 @@ static void input_joyup(const unsigned int button) {
|
||||
static void input_keydown(SDLKey key) {
|
||||
int 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);
|
||||
return;
|
||||
}
|
||||
@ -296,7 +300,8 @@ static void input_keydown(SDLKey key) {
|
||||
static void input_keyup(SDLKey key) {
|
||||
int 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);
|
||||
return;
|
||||
}
|
||||
|
@ -2,7 +2,12 @@
|
||||
#include <SDL.h>
|
||||
|
||||
// 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.
|
||||
void input_setDefault(void);
|
||||
|
@ -19,7 +19,8 @@ int joystick_get(char* namjoystick) {
|
||||
|
||||
int joystick_use(int indjoystick) {
|
||||
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;
|
||||
}
|
||||
if(joystick)
|
||||
@ -29,7 +30,8 @@ int joystick_use(int indjoystick) {
|
||||
LOG("Using joystick %d", indjoystick);
|
||||
joystick = SDL_JoystickOpen(indjoystick);
|
||||
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;
|
||||
}
|
||||
DEBUG("\t\tWith %d axes, %d buttons, %d balls, and %d hats",
|
||||
|
@ -38,7 +38,8 @@
|
||||
int landed = 0;
|
||||
|
||||
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;
|
||||
|
||||
// Commodity excahnge.
|
||||
@ -76,13 +77,15 @@ static void commodity_exchange(void) {
|
||||
goods[2] = strdup("testing.");
|
||||
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,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose",
|
||||
"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);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,8 @@ static void update_space(void);
|
||||
static void render_space(void);
|
||||
|
||||
#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;
|
||||
char *argv[] = { NULL };
|
||||
#else
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
#define LOG(str, args...)(fprintf(stdout, 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
|
||||
# undef DEBUG
|
||||
|
10
src/music.c
10
src/music.c
@ -46,7 +46,8 @@ static int nmusic_selection = 0;
|
||||
static ALfloat mvolume = 1.;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -159,7 +160,8 @@ static int stream_loadBuffer(ALuint buffer) {
|
||||
if(size == BUFFER_SIZE) break; // Buffer is full.
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
@ -234,7 +236,7 @@ static int music_find(void) {
|
||||
MUSIC_SUFFIX, strlen(MUSIC_SUFFIX))==0)) {
|
||||
|
||||
// Grow the selection size.
|
||||
music_selection = realloc(music_selection, ++nmusic_selection*sizeof(char*));
|
||||
music_selection = realloc(music_selection,++nmusic_selection*sizeof(char*));
|
||||
|
||||
// Remove the prefix and suffix.
|
||||
len = strlen(files[i]) - strlen(MUSIC_SUFFIX MUSIC_PREFIX);
|
||||
@ -298,7 +300,7 @@ void music_load(const char* name) {
|
||||
music_loadOGG(tmp);
|
||||
return;
|
||||
}
|
||||
WARN("Requested load song '%s' but it can't be found in the music stack", name);
|
||||
WARN("Requested load song '%s' but it can't be found in the music stack",name);
|
||||
}
|
||||
|
||||
void music_play(void) {
|
||||
|
33
src/opengl.c
33
src/opengl.c
@ -16,7 +16,8 @@
|
||||
#define SCREEN_W gl_screen.w
|
||||
#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_yoff;
|
||||
|
||||
@ -35,7 +36,8 @@ static int pot(int n);
|
||||
static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
|
||||
|
||||
// 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!
|
||||
@ -178,7 +180,8 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
|
||||
WARN("Unable to create POT surface %s", SDL_GetError());
|
||||
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());
|
||||
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());
|
||||
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());
|
||||
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.
|
||||
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;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
@ -557,7 +562,8 @@ int gl_init(void) {
|
||||
DEBUG("Available fullscreen modes:");
|
||||
for(i = 0; modes[i]; i++) {
|
||||
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.
|
||||
}
|
||||
}
|
||||
@ -611,10 +617,13 @@ int gl_init(void) {
|
||||
gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a;
|
||||
|
||||
// Debug heaven.
|
||||
DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h, 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("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h,
|
||||
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,
|
||||
(gl_has(OPENGL_DOUBLEBUF)) ? "yes" : "no");
|
||||
|
||||
DEBUG("Renderer: %s", glGetString(GL_RENDERER));
|
||||
|
||||
// Some openGL options.
|
||||
@ -645,7 +654,8 @@ void gl_exit(void) {
|
||||
}
|
||||
|
||||
// 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_infop info_ptr;
|
||||
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;
|
||||
|
||||
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";
|
||||
if(!(info_ptr = png_create_info_struct(png_ptr))) goto fail;
|
||||
|
17
src/outfit.c
17
src/outfit.c
@ -73,7 +73,8 @@ int outfit_isAmmo(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.
|
||||
@ -132,7 +133,13 @@ const char* outfit_typename[] = {
|
||||
};
|
||||
|
||||
// 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) {
|
||||
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, "accuracy")) tmp->u.blt.accuracy = xml_getFloat(node);
|
||||
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);
|
||||
}
|
||||
else if(xml_isNode(node, "spfx"))
|
||||
@ -179,7 +187,8 @@ static void outfit_parseSWeapon(Outfit* tmp, const xmlNodePtr parent) {
|
||||
} while((cur = cur->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)
|
||||
WARN("Outfit '%s' missing 'gfx' element", tmp->name);
|
||||
MELEMENT(tmp->u.blt.sound, "sound");
|
||||
|
@ -143,7 +143,8 @@ int pack_files(const char* outfile, const char** infiles, const uint32_t nfiles)
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
namesize += strlen(infiles[i]);
|
||||
@ -221,7 +222,8 @@ int pack_files(const char* outfile, const char** infiles, const uint32_t nfiles)
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
#undef WRITE
|
||||
@ -395,7 +397,8 @@ void* pack_readfile(const char* packfile, const char* filename, uint32_t* filesi
|
||||
size = file->end - file->start;
|
||||
buf = malloc(size+1);
|
||||
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(file);
|
||||
return NULL;
|
||||
|
@ -195,7 +195,8 @@ static void rk4_update(Solid* obj, const double dt) {
|
||||
}
|
||||
|
||||
// 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->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.
|
||||
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);
|
||||
if(dyn == NULL) ERR("Out of memory");
|
||||
solid_init(dyn, mass, dir, pos, vel);
|
||||
|
27
src/pilot.c
27
src/pilot.c
@ -169,7 +169,8 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) {
|
||||
switch(w->outfit->type) {
|
||||
case OUTFIT_TYPE_TURRET_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.
|
||||
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.
|
||||
else if(outfit_isLauncher(w->outfit) && (w == p->secondary) && (p->id != t)) {
|
||||
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.
|
||||
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.
|
||||
pilot_setFlag(pilot, PILOT_DISABLED);
|
||||
// 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);
|
||||
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.
|
||||
(*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))
|
||||
// Should not go faster.
|
||||
@ -468,8 +472,9 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||
// pos : Initial position.
|
||||
// flags : Tweaking the pilot.
|
||||
// ========================================================
|
||||
void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction, AI_Profile* ai,
|
||||
const double dir, const Vec2* pos, const Vec2* vel, const int flags) {
|
||||
void pilot_init(Pilot* pilot, Ship* ship, char* name, Faction* faction,
|
||||
AI_Profile* ai, const double dir, const Vec2* pos,
|
||||
const Vec2* vel, const int flags) {
|
||||
|
||||
if(flags & PILOT_PLAYER) // Player is ID 0
|
||||
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.
|
||||
unsigned int pilot_create(Ship* ship, char* name, Faction* faction, 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, const double dir, const Vec2* pos,
|
||||
const Vec2* vel, const int flags) {
|
||||
Pilot* dyn = MALLOC_L(Pilot);
|
||||
if(dyn == NULL) {
|
||||
WARN("Unable to allocate memory.");
|
||||
@ -685,7 +691,8 @@ static Fleet* fleet_parse(const xmlNodePtr parent) {
|
||||
c = (char*)xmlGetProp(cur, (xmlChar*)"chance"); // Mallocs.
|
||||
pilot->chance = atoi(c);
|
||||
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.
|
||||
|
||||
tmp->pilots = realloc(tmp->pilots, sizeof(FleetPilot)*tmp->npilots);
|
||||
@ -726,7 +733,7 @@ int fleet_load(void) {
|
||||
}
|
||||
|
||||
do {
|
||||
if(node->type == XML_NODE_START && strcmp((char*)node->name, XML_FLEET)==0) {
|
||||
if(node->type == XML_NODE_START && strcmp((char*)node->name,XML_FLEET)==0) {
|
||||
tmp = fleet_parse(node);
|
||||
fleet_stack = realloc(fleet_stack, sizeof(Fleet)*(++nfleets));
|
||||
memcpy(fleet_stack+nfleets-1, tmp, sizeof(Fleet));
|
||||
|
10
src/pilot.h
10
src/pilot.h
@ -122,11 +122,13 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
|
||||
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity);
|
||||
|
||||
// Creation.
|
||||
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai,
|
||||
const double dir, const Vec2* pos, const Vec2* vel, const int flags);
|
||||
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction,
|
||||
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,
|
||||
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, const double dir, const Vec2* pos,
|
||||
const Vec2* vel, const int flags);
|
||||
|
||||
// Init/Cleanup.
|
||||
void pilot_destroy(Pilot* p);
|
||||
|
52
src/player.c
52
src/player.c
@ -100,10 +100,13 @@ static Msg* msg_stack;
|
||||
|
||||
// External.
|
||||
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 planets_minimap(const double res, const double w, const double h, const RadarShape shape); // space.c
|
||||
extern void weapon_minimap(const double res,
|
||||
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.
|
||||
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 void gui_renderPilot(const Pilot* p);
|
||||
static void gui_renderBar(const glColour* c, const Rect* r, const double w);
|
||||
@ -380,10 +383,12 @@ void player_render(void) {
|
||||
// Nav.
|
||||
if(planet_target >= 0) {
|
||||
// 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,
|
||||
NULL, "%s", cur_system->planets[planet_target].name);
|
||||
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
|
||||
gui.nav.y - 10 - gl_smallFont.h, NULL, "%s",
|
||||
cur_system->planets[planet_target].name);
|
||||
}
|
||||
else if(hyperspace_target >= 0) {
|
||||
// Hyperspace target.
|
||||
@ -391,8 +396,9 @@ void player_render(void) {
|
||||
gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5,
|
||||
c, "Hyperspace");
|
||||
|
||||
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x, gui.nav.y - 10 - gl_smallFont.h,
|
||||
NULL, "%s", systems_nstack[cur_system->jumps[hyperspace_target]].name);
|
||||
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
|
||||
gui.nav.y - 10 - gl_smallFont.h, NULL, "%s",
|
||||
systems_nstack[cur_system->jumps[hyperspace_target]].name);
|
||||
}
|
||||
else {
|
||||
// No NAV target.
|
||||
@ -637,7 +643,8 @@ int gui_load(const char* name) {
|
||||
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;
|
||||
int param;
|
||||
|
||||
@ -759,24 +766,28 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
||||
cur = node->children;
|
||||
do {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} while((cur = cur->next));
|
||||
}
|
||||
// Secondary 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);
|
||||
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")) {
|
||||
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);
|
||||
gui.target_faction.y -= gl_smallFont.h;
|
||||
}
|
||||
|
||||
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);
|
||||
gui.target_health.y -= gl_smallFont.h;
|
||||
}
|
||||
@ -850,7 +863,8 @@ void player_think(Pilot* player) {
|
||||
if(player_isFlag(PLAYER_SECONDARY)) // Needs a target.
|
||||
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.
|
||||
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);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -998,7 +1013,8 @@ void player_screenshot(void) {
|
||||
WARN("You have reached the maximum amount of screenshots [128]");
|
||||
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.
|
||||
if(fp == NULL) done = 1;
|
||||
else {
|
||||
|
@ -75,11 +75,13 @@ static Ship* ship_parse(xmlNodePtr parent) {
|
||||
do {
|
||||
// Load all the data.
|
||||
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));
|
||||
tmp->gfx_space = gl_newSprite(str, 6, 6);
|
||||
// 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));
|
||||
tmp->gfx_target = gl_newImage(str);
|
||||
|
||||
@ -145,7 +147,8 @@ static Ship* ship_parse(xmlNodePtr parent) {
|
||||
otmp->data = outfit_get(xml_get(cur));
|
||||
stmp = xml_nodeProp(cur, "quantity");
|
||||
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);
|
||||
free(stmp);
|
||||
otmp->next = NULL;
|
||||
|
11
src/space.c
11
src/space.c
@ -73,7 +73,8 @@ extern void player_message(const char* fmt, ...);
|
||||
// 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) {
|
||||
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;
|
||||
@ -372,7 +373,8 @@ static Planet* planet_get(const char* name) {
|
||||
|
||||
// Check elements.
|
||||
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_exterior, "GFX_exterior");
|
||||
MELEMENT(flags&FLAG_XSET, "x");
|
||||
@ -494,7 +496,8 @@ static void system_parseJumps(const xmlNodePtr parent) {
|
||||
system = &systems_stack[i];
|
||||
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.
|
||||
|
||||
node = parent->xmlChildrenNode;
|
||||
@ -597,7 +600,7 @@ void space_render(double dt) {
|
||||
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);
|
||||
glVertex2d(stars[i].x+x*stars[i].brightness,stars[i].y+y*stars[i].brightness);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
19
src/weapon.c
19
src/weapon.c
@ -65,7 +65,8 @@ static void think_seeker(Weapon* w);
|
||||
// Draw the minimap weapons (player.c).
|
||||
#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 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;
|
||||
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));
|
||||
w->solid->dir_vel = 10 * diff * w->outfit->u.amm.turn;
|
||||
// Face the target.
|
||||
if(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;
|
||||
if(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);
|
||||
@ -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_SWARM_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);
|
||||
continue;
|
||||
}
|
||||
@ -384,10 +388,11 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
|
||||
}
|
||||
|
||||
// Add a new weapon.
|
||||
void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos, const Vec2* vel,
|
||||
unsigned int parent, unsigned int target) {
|
||||
void weapon_add(const Outfit* outfit, const double dir, const Vec2* pos,
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user