From 127e76c542e6a7b35b3ae95d1a53d0c341e1f9dd Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Fri, 22 Mar 2013 18:35:11 +0000
Subject: [PATCH] [Fix] minor mem leak.

---
 bin/conf     | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/land.c   | 43 +++++++++++++++++++++++++++++++++++++------
 src/player.c | 17 +++++++++++++++--
 src/ship.c   |  1 +
 src/space.c  |  3 +++
 5 files changed, 103 insertions(+), 8 deletions(-)
 create mode 100644 bin/conf

diff --git a/bin/conf b/bin/conf
new file mode 100644
index 0000000..08fef31
--- /dev/null
+++ b/bin/conf
@@ -0,0 +1,47 @@
+--WINDOW.
+width       = 800
+height      = 640
+fullscreen  = 0
+
+-- SCREEN.
+fps = 0
+
+-- SOUND.
+nosound = 0
+sound 	= 0.7
+music 	= 0.5
+
+-- JOYSTICK.
+-- Can be number or substring of joystick name.
+joystick = "Precision"
+
+-- KEYBINDINGS.
+-- Type can be keyboard, jaxis or jbutton.
+--
+-- If left is an axis, it will automatically set right to the same axis.
+-- setting both to the same axis (key).
+-- You can use reverse = 1 option to reverse them.
+-- Currently keybindings work with the number of the key only (when doing
+-- keyboard). Would be cool to have a gui to do this for you at some point.
+
+-- Movement.
+accel           = { type = "jbutton",   key = 0   }
+left            = { type = "jaxis",     key = 0   }
+right           = { type = "jaxis",     key = 0   }
+
+-- Combat.
+primary         = { type = "jbutton",   key = 1   }
+target          = { type = "jbutton",   key = 4   }
+target_nearest  = { type = "jbutton",   key = 3   }
+face            = { type = "keyboard",  key = 38  }
+board           = { type = "keyboard",  key = 57  }
+secondary       = { type = "jbutton",   key = 7   }
+secondary_next  = { type = "jbutton",   key = 5   }
+
+-- Space.
+
+-- Gui.
+mapzoomin       = { type = "jbutton",   key = 4   }
+mapzoomout      = { type = "jbutton",   key = 6   }
+screenshot      = { type = "keyboard",  key = 82  }
+
diff --git a/src/land.c b/src/land.c
index f03830c..523143a 100644
--- a/src/land.c
+++ b/src/land.c
@@ -39,8 +39,9 @@
 int landed = 0;
 
 static int land_wid = 0; // Primary land window.
-// For the second opened land window (We can only have 2 max).
+// For the second opened land window
 static int secondary_wid = 0;
+static int terciary_wid = 0; // For fancy things like news, your ship etc..
 Planet* land_planet = NULL;
 
 // Commodity excahnge.
@@ -63,6 +64,9 @@ static void shipyard_close(char* str);
 static void shipyard_update(char* str);
 static void shipyard_info(char* str);
 static void shipyard_buy(char* str);
+// Your ship.
+static void shipyard_yours(char* str);
+static void shipyard_yoursClose(char* str);
 // Spaceport bar.
 static void spaceport_bar(void);
 static void spaceport_bar_close(char* str);
@@ -380,6 +384,10 @@ static void shipyard(void) {
                    BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseShipyard",
                    "Close", shipyard_close);
 
+  window_addButton(secondary_wid, -20, 40+BUTTON_HEIGHT,
+                   BUTTON_WIDTH, BUTTON_HEIGHT, "btnYourShips",
+                   "Your Ships", shipyard_yours);
+
   window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
                    BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
                    "Buy", shipyard_buy);
@@ -477,6 +485,30 @@ static void shipyard_buy(char* str) {
                  0., 0., player->solid->dir);
 }
 
+static void shipyard_yours(char* str) {
+  (void)str;
+  char** ships;
+  int nships;
+
+  terciary_wid = window_create("Your Ships",
+      -1, -1, SHIPYARD_WIDTH, SHIPYARD_HEIGHT);
+
+  window_addButton(terciary_wid, -20, 20,
+                   BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseYourShips",
+                   "Shipyard", shipyard_yoursClose);
+
+  ships = NULL;
+  nships = 0;
+  window_addList(terciary_wid, 20, 40,
+                 200, SHIPYARD_HEIGHT-80, "lstYourShips",
+                 ships, nships, 0, NULL);
+}
+
+static void shipyard_yoursClose(char* str) {
+  (void)str;
+  window_destroy(terciary_wid);
+}
+
 // Spaceport bar.
 static void spaceport_bar(void) {
   secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
@@ -501,23 +533,22 @@ static void spaceport_bar_close(char* str) {
 
 // Planet news reports.
 static void news(void) {
-  unsigned int news_wid;
-  news_wid = window_create("News Reports",
+  terciary_wid = window_create("News Reports",
                            -1, -1, NEWS_WIDTH, NEWS_HEIGHT);
 
-  window_addText(news_wid, 20, 20 + BUTTON_HEIGHT + 20,
+  window_addText(terciary_wid, 20, 20 + BUTTON_HEIGHT + 20,
                  NEWS_WIDTH-40, NEWS_HEIGHT - 20 - BUTTON_HEIGHT - 20 - 20 -20,
                  0, "txtNews", &gl_smallFont, &cBlack,
                  "News reporters report that they are on strike right now! D:");
 
-  window_addButton(news_wid, -20, 20,
+  window_addButton(terciary_wid, -20, 20,
                    BUTTON_WIDTH, BUTTON_HEIGHT,
                    "btnCloseNews", "Close", news_close);
 }
 
 static void news_close(char* str) {
   if(strcmp(str, "btnCloseNews")==0)
-    window_destroy(window_get("News Reports"));
+    window_destroy(terciary_wid);
 }
 
 // Land the player.
diff --git a/src/player.c b/src/player.c
index 9117ec4..347fbf4 100644
--- a/src/player.c
+++ b/src/player.c
@@ -161,9 +161,17 @@ void player_new(void) {
 static void player_nameClose(char* str) {
   (void)str;
   unsigned int wid;
+  char* name;
 
   wid = window_get("Player Name");
-  player_name = strdup(window_getInput(wid, "inpName"));
+  name = window_getInput(wid, "inpName");
+
+  if(strlen(name) < 3) {
+    toolkit_alert("Your name must be at least three characters long.");
+    return;
+  }
+
+  player_name = strdup(name);
   window_destroy(wid);
 
   player_newMake();
@@ -268,7 +276,12 @@ static void player_nameShipClose(char* str) {
 
   wid = window_get("Ship Name");
   ship_name = window_getInput(wid, "inpName");
-
+ 
+  if(strlen(ship_name) < 3) {
+    toolkit_alert("Your ship's name must be at least three characters long.");
+    return;
+  }
+  
   player_newShipMake(ship_name);
 
   window_destroy(wid);
diff --git a/src/ship.c b/src/ship.c
index 62fa05c..4aa1419 100644
--- a/src/ship.c
+++ b/src/ship.c
@@ -257,6 +257,7 @@ void ships_free(void) {
     if((ship_stack+i)->name) free(ship_stack[i].name);
     if((ship_stack+i)->description) free(ship_stack[i].description);
     if((ship_stack+i)->gui) free(ship_stack[i].gui);
+    if((ship_stack+i)->fabricator) free(ship_stack[i].fabricator);
     so = (ship_stack+i)->outfit;
     while(so) { // free the ship outfit.
       sot = so;
diff --git a/src/space.c b/src/space.c
index 0914a0b..3ac1730 100644
--- a/src/space.c
+++ b/src/space.c
@@ -732,6 +732,9 @@ void space_exit(void) {
         gl_freeTexture(systems_stack[i].planets[j].gfx_space);
       if(systems_stack[i].planets[j].gfx_exterior)
         gl_freeTexture(systems_stack[i].planets[j].gfx_exterior);
+
+      // Commodities.
+      free(systems_stack[i].planets[j].commodities);
     }
     free(systems_stack[i].planets);
   }