From 5694a0b598e945c3f7ea9c77c65bb9b9a3d4188c Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Wed, 27 Feb 2013 15:38:15 +0000
Subject: [PATCH] [Change] Seperated boarding from player.c to board.c. Fixed
 ship information panel.

---
 src/board.c    | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/board.h    |  4 ++++
 src/input.c    |  1 +
 src/lephisto.h |  2 ++
 src/player.c   | 44 --------------------------------------
 src/ship.c     |  3 ++-
 6 files changed, 66 insertions(+), 45 deletions(-)
 create mode 100644 src/board.c
 create mode 100644 src/board.h

diff --git a/src/board.c b/src/board.c
new file mode 100644
index 0000000..ad67109
--- /dev/null
+++ b/src/board.c
@@ -0,0 +1,57 @@
+#include "lephisto.h"
+#include "pilot.h"
+#include "player.h"
+#include "toolkit.h"
+#include "space.h"
+#include "board.h"
+
+#define BOARDING_WIDTH	300
+#define BOARDING_HEIGHT	200
+
+extern unsigned int player_target;
+
+static void player_unboard(char* str);
+
+// Attempt to board the players target.
+void player_board(void) {
+	Pilot* p;
+	unsigned int wid;
+
+	if(player_target == PLAYER_ID) {
+		player_message("You need a target to board first!");
+		return;
+	}
+
+	p = pilot_get(player_target);
+
+	if(!pilot_isDisabled(p)) {
+		player_message("You cannot board a ship that is not disabled!");
+		return;
+	}
+	if(vect_dist(&player->solid->pos, &p->solid->pos) >
+				p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
+		player_message("You are too far away to board your target");
+		return;
+	}
+	if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
+				pow2(VY(player->solid->vel)-VY(p->solid->vel))) >
+				(double)pow2(MAX_HYPERSPACE_VEL)) {
+		player_message("You are going too fast to board the ship");
+		return;
+	}
+
+	// TODO: Actual boarding.
+	player_message("Boarding ship %s", p->name);
+
+	// Create the boarding window.
+	wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
+
+	window_addButton(wid, 20, 20, 50, 30, "btnStealScred", "SCred", player_unboard);
+	window_addButton(wid, -20, 20, 60, 30, "tbnBoardingClose", "Close", player_unboard);
+}
+
+static void player_unboard(char* str) {
+	if(strcmp(str, "btnBoardingClose")==0)
+		window_destroy(window_get("Boarding"));
+}
+
diff --git a/src/board.h b/src/board.h
new file mode 100644
index 0000000..e98e5b3
--- /dev/null
+++ b/src/board.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void player_board(void);
+
diff --git a/src/input.c b/src/input.c
index 3bd5dff..4fe5ce6 100644
--- a/src/input.c
+++ b/src/input.c
@@ -4,6 +4,7 @@
 #include "pause.h"
 #include "toolkit.h"
 #include "menu.h"
+#include "board.h"
 #include "input.h"
 
 #define KEY_PRESS   ( 1.)
diff --git a/src/lephisto.h b/src/lephisto.h
index 6f3be3b..6b0b5d0 100644
--- a/src/lephisto.h
+++ b/src/lephisto.h
@@ -10,6 +10,8 @@
 #define MAX(x,y)  (((x)>(y))?(x):(y))
 #define MIN(x,y)  (((x)>(y))?(y):(x))
 
+#define pow2(x)		((x)*(x))
+
 #define DATA_DEF    "data" // Default data packfile.
 extern char* data; // Modifiable datafile.
 #define DATA        data // Data file.
diff --git a/src/player.c b/src/player.c
index ae72d1c..f55a110 100644
--- a/src/player.c
+++ b/src/player.c
@@ -10,7 +10,6 @@
 #include "space.h"
 #include "rng.h"
 #include "land.h"
-#include "toolkit.h"
 #include "sound.h"
 #include "player.h"
 
@@ -24,11 +23,6 @@
 
 #define START_DATA    "../dat/start.xml"
 
-#define pow2(x) ((x)*(x))
-
-#define BOARDING_WIDTH  300
-#define BOARDING_HEIGHT 200
-
 // Player stuff.
 Pilot* player = NULL; // extern in pilot.h
 // Player global properties.
@@ -112,7 +106,6 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w,
 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);
-static void player_unboard(char* str);
 
 // Create a new player.
 void player_new(void) {
@@ -844,43 +837,6 @@ void player_setRadarRel(int mod) {
     else if(gui.radar.res < RADAR_RES_MIN) gui.radar.res = RADAR_RES_MIN;
 }
 
-void player_board(void) {
-  Pilot* p;
-  unsigned int wid;
-
-  if(player_target == PLAYER_ID) {
-    player_message("You need a target to board first!");
-    return;
-  }
-  p = pilot_get(player_target);
-
-  if(!pilot_isDisabled(p)) {
-    player_message("You cannot board a ship that isn't disabled!");
-    return;
-  }
-  if(vect_dist(&player->solid->pos, &p->solid->pos) > p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
-    player_message("You are too far away to board your target");
-    return;
-  }
-  if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) + 
-        pow2(VY(player->solid->vel)-VY(p->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) {
-    
-    player_message("You are going too fast to board the ship");
-    return;
-  }
-  player_message("Boarding ship %s", p->name);
-
-  // Create boarding window.
-  wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
-
-  window_addButton(wid, -20, 20, 50, 30, "btnBoardingClose", "Close", player_unboard);
-}
-
-static void player_unboard(char* str) {
-  if(strcmp(str, "btnBoardingClose")==0)
-    window_destroy(window_get("Boarding"));
-}
-
 // Get the next secondary weapon.
 void player_secondaryNext(void) {
   int i = 0;
diff --git a/src/ship.c b/src/ship.c
index 81cd53c..346456e 100644
--- a/src/ship.c
+++ b/src/ship.c
@@ -234,10 +234,11 @@ void ships_free(void) {
 
 // Used to visualize the ships status.
 void ship_view(char* shipname) {
-	Ship* s = NULL;
+	Ship* s;
 	char buf[1024];
 	unsigned int wid;
 	wid = window_create(shipname, -1, -1, VIEW_WIDTH, VIEW_HEIGHT);
+	s = ship_get(shipname);
 
 	window_addText(wid, 20, 0, 100, VIEW_HEIGHT-30,
 				0, "txtLabel", &gl_smallFont, &cDConsole,