From 16baff189ec42c7bff7b2f92d7570b145c09d12e Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Tue, 11 Jun 2013 22:50:04 +0100
Subject: [PATCH] [Change] Added a few nazi flags, and fixed code up a little.

---
 bin/Makefile   |  5 +++--
 src/ai.c       |  3 +++
 src/base64.c   | 11 ++---------
 src/faction.c  |  4 ++++
 src/hook.c     |  3 +++
 src/misn_lua.c |  5 +++++
 src/mission.c  |  3 +++
 src/player.c   |  3 +++
 src/player.h   |  1 +
 src/sound.c    |  4 ++--
 src/space.c    |  8 ++++----
 src/weapon.c   |  8 ++++++--
 12 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/bin/Makefile b/bin/Makefile
index 429fea1..820d1a3 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -24,9 +24,10 @@ CTTF = $(shell freetype-config --cflags)
 CAL  = -lopenal $(shell freealut-config --cflags)
 CVORBIS =
 CGL  =
-CFLAGS = $(CLUA) $(CPLUTO) $(CSDL) $(CXML) $(CTTF) $(CGL) $(CAL) $(CVORBIS) $(VERSION) -D$(OS) -fgnu89-inline
+CFLAGS = $(CLUA) $(CPLUTO) $(CSDL) $(CXML) $(CTTF) $(CGL) $(CAL) $(CVORBIS) $(VERSION) -D$(OS)
 ifdef DEBUG
-CFLAGS += -W -Wall -Wextra -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99
+CFLAGS += -W -Wall -Wextra -Wmissing-prototypes -Winline -Wcast-align \
+					-Wmissing-declarations -fno-inline -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99
 else
 CFLAGS += -O2 -funroll-loops -pipe -std=c99
 endif
diff --git a/src/ai.c b/src/ai.c
index a24ed43..a928f92 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -85,6 +85,9 @@ static void ai_freetask(Task* t);
 // External C routines.
 void ai_attacked(Pilot* attacked, const unsigned int attacker); // weapon.c
 void ai_create(Pilot* pilot);
+// C routines made external.
+void ai_destroy(Pilot* p);
+void ai_think(Pilot* pilot);
 
 // Ai routines for Lua.
 // Tasks.
diff --git a/src/base64.c b/src/base64.c
index 6d0167a..a777a84 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -189,15 +189,8 @@ char* base64_encode(size_t* len, char* src, size_t sz) {
 }
 
 // Decode the buffer, same syntax as base64_encode.
-static inline int dec_valid(char inp) {
-  if(cd64[(int)inp] == -1)
-    return 0;
-  return 1;
-}
-
-static inline char dec_ch(char inp) {
-  return cd64[(int)inp];
-}
+#define dec_valid(inp)    (cd64[(int)inp] == -1) ? 0 : 1
+#define dec_ch(inp)       cd64[(int)inp]
 
 char* base64_decode(size_t* len, char* src, size_t sz) {
   char* r, *dat, pad;
diff --git a/src/faction.c b/src/faction.c
index 060f1ec..c554d98 100644
--- a/src/faction.c
+++ b/src/faction.c
@@ -45,10 +45,14 @@ typedef struct Alliance_ {
 static Alliance* alliances = NULL;
 static int nalliances = 0;
 
+// Static.
 static Faction* faction_parse(xmlNodePtr parent);
 static void alliance_parse(xmlNodePtr parent);
 static void enemies_parse(xmlNodePtr parent);
 static Alliance* alliance_get(char* name);
+// Extern.
+int pfaction_save(xmlTextWriterPtr writer);
+int pfaction_load(xmlNodePtr parent);
 
 // Return the faction of name "name".
 int faction_get(const char* name) {
diff --git a/src/hook.c b/src/hook.c
index 0040dc7..a944132 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -30,6 +30,9 @@ static int hook_run(Hook* hook);
 static void hook_free(Hook* h);
 static int hook_needSave(Hook* h);
 static int hook_parse(xmlNodePtr base);
+// Extern.
+int hook_save(xmlTextWriterPtr writer);
+int hook_load(xmlNodePtr parent);
 
 static int hook_run(Hook* hook) {
   int i;
diff --git a/src/misn_lua.c b/src/misn_lua.c
index feb71d5..6f3e48a 100644
--- a/src/misn_lua.c
+++ b/src/misn_lua.c
@@ -46,9 +46,14 @@ static int var_mstack = 0;
 static Mission* cur_mission = NULL;
 static int misn_delete = 0; // If 1 delete current mission.
 
+// Static.
 static int var_add(misn_var* var);
 static void var_free(misn_var* var);
 static unsigned int  hook_generic(lua_State* L, char* stack);
+// Extern.
+int misn_run(Mission* misn, char* func);
+int var_save(xmlTextWriterPtr writer);
+int var_load(xmlNodePtr parent);
 
 // -- Libraries. --
 
diff --git a/src/mission.c b/src/mission.c
index 458f560..682bd79 100644
--- a/src/mission.c
+++ b/src/mission.c
@@ -44,6 +44,9 @@ static MissionData* mission_parse(const xmlNodePtr parent);
 static int  missions_parseActive(xmlNodePtr parent);
 static int  mission_persistData(lua_State* L, xmlTextWriterPtr writer);
 static int  mission_unpersistData(lua_State* L, xmlNodePtr parent);
+// Extern.
+int missions_saveActive(xmlTextWriterPtr writer);
+int missions_loadActive(xmlNodePtr parent);
 
 // Generate a new id for the mission.
 static unsigned int mission_genID(void) {
diff --git a/src/player.c b/src/player.c
index e0656b5..73cd44b 100644
--- a/src/player.c
+++ b/src/player.c
@@ -163,6 +163,9 @@ void player_dead(void);
 void player_destroyed(void);
 int player_save(xmlTextWriterPtr writer);
 int player_load(xmlNodePtr parent);
+void player_think(Pilot* player);
+void player_brokeHyperspace(void);
+double player_faceHyperspace(void);
 
 // Prompt player name.
 void player_new(void) {
diff --git a/src/player.h b/src/player.h
index fb05af5..3d0b618 100644
--- a/src/player.h
+++ b/src/player.h
@@ -34,6 +34,7 @@ void player_new(void);
 void player_newShip(Ship* ship, double px, double py,
                     double vx, double vy, double dir);
 void player_cleanup(void);
+int gui_load(const char* name);
 
 // Render.
 int gui_init(void);
diff --git a/src/sound.c b/src/sound.c
index 49c1a32..51dbcbc 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -90,7 +90,7 @@ static int source_nstack = 0;
 struct alVoice {
   alVoice* next;      // Yes it's a linked list.
 
-  //ALuint id;          // Unique id for the voice.
+  //ALuint id;        // Unique id for the voice.
 
   ALuint source;      // Source itself, 0 if not set.
   ALuint buffer;      // Buffer.
@@ -98,7 +98,7 @@ struct alVoice {
   int priority;       // Base priority.
 
   double px, py;      // Position.
-  //double vx, vy;      // Velocity.
+  //double vx, vy;    // Velocity.
 
   unsigned int start; // time started in ms.
   unsigned int flags; // Flags to set properties.
diff --git a/src/space.c b/src/space.c
index a346858..c26b8bb 100644
--- a/src/space.c
+++ b/src/space.c
@@ -78,13 +78,15 @@ static void system_parseJumps(const xmlNodePtr parent);
 static PlanetClass planetclass_get(const char a);
 // Extern.
 extern void player_message(const char* fmt, ...);
+void planets_minimap(const double res, const double w,
+    const double h, const RadarShape shape);
 
 // Draw the planet. Used in planet.c
 // Matrix mode is already displaced to center of the minimap.
 #define PIXEL(x,y)  if((shape == RADAR_RECT && ABS(x)<w/2. && ABS(y)<h/2.) || \
   (shape == RADAR_CIRCLE && (((x)*(x)+(y)*(y)) < rc))) glVertex2i((x),(y))
-void planets_minimap(const double res,
-                     const double w, const double h, const RadarShape shape) {
+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;
@@ -333,8 +335,6 @@ StarSystem** system_getJumpPath(int* njumps, char* sysstart, char* sysend) {
   }
 
   // Free the linked list.
-  //A_freeList(open);
-  //A_freeList(closed);
   A_freeList(A_gc);
   return res;
 }
diff --git a/src/weapon.c b/src/weapon.c
index 555152d..41ae537 100644
--- a/src/weapon.c
+++ b/src/weapon.c
@@ -58,6 +58,7 @@ static Weapon** wfrontLayer = NULL;  // Behind pilots.
 static int nwfrontLayer    = 0;    // Number of elements.
 static int mwfrontLayer    = 0;    // Allocated memory size.
 
+// Static.
 static Weapon* weapon_create(const Outfit* outfit, const double dir,
                              const Vec2* pos, const Vec2* vel,
                              const unsigned int parent,
@@ -72,12 +73,15 @@ static void weapon_free(Weapon* w);
 // Think.
 static void think_seeker(Weapon* w, const double dt);
 static void think_smart(Weapon* w, const double dt);
+// Extern.
+void weapon_minimap(const double res, const double w,
+    const double h, const RadarShape shape);
 
 // 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;