From f26cf7e4e17080403380b6d1d42532984edc999b Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sat, 14 Dec 2013 00:45:01 +0000
Subject: [PATCH] [Change] Useing memset for pilot initialization. Also making
 a start on auto navigation stuff.

---
 src/pilot.c  | 28 +++-------------------------
 src/player.c | 26 ++++++++++++++++++++++++++
 src/player.h |  1 +
 3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/src/pilot.c b/src/pilot.c
index c309801..995e135 100644
--- a/src/pilot.c
+++ b/src/pilot.c
@@ -1191,9 +1191,11 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
                 AI_Profile* ai, const double dir, const Vec2* pos,
                 const Vec2* vel, const int flags) {
 
-  int i;
   ShipOutfit* so;
 
+  /* Clear memory. */
+  memset(pilot, 0, sizeof(Pilot));
+
   if(flags & PILOT_PLAYER) /* Player is ID 0 */
     pilot->id = PLAYER_ID;
   else
@@ -1207,22 +1209,11 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
 
   /* AI. */
   pilot->ai       = ai;
-  pilot->tcontrol = 0;
-  pilot->flags    = 0;
-  pilot->lockons  = 0;
 
   /* Solid. */
   pilot->solid = solid_create(ship->mass, dir, pos, vel);
 
-  /* Initially idle. */
-  pilot->task = NULL;
-
   /* Outfits. */
-  pilot->outfits = NULL;
-  pilot->secondary = NULL;
-  pilot->ammo = NULL;
-  pilot->afterburner = NULL;
-  pilot->noutfits = 0;
   if(!(flags & PILOT_NO_OUTFITS)) {
     if(ship->outfit) {
       pilot->noutfits = 0;
@@ -1238,14 +1229,7 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
     }
   }
 
-  /* Jamming - must be set before calcStats. */
-  pilot->jam_range = 0.;
-  pilot->jam_chance = 0.;
-
   /* Cargo must be set before calcStats. */
-  pilot->credits = 0;
-  pilot->commodities = NULL;
-  pilot->ncommodities = 0;
   pilot->cargo_free = pilot->ship->cap_cargo; /* should get redone with calcCargo. */
 
   /* Set the pilot stats based on her ship and outfits. */
@@ -1256,12 +1240,6 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction,
   pilot->fuel   = pilot->fuel_max   = 1.;
   pilot_calcStats(pilot);
 
-  /* Hooks. */
-  for(i = 0; i < PILOT_HOOKS; i++) {
-    pilot->hook_type[i] = PILOT_HOOK_NONE;
-    pilot->hook[i] = 0;
-  }
-
   /* Set flags and functions. */
   if(flags & PILOT_PLAYER) {
     pilot->think = player_think; /* Players don't need to thing! :P */
diff --git a/src/player.c b/src/player.c
index 92c1590..9b6cfb2 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1466,6 +1466,23 @@ void gui_free(void) {
   free(msg_stack);
 }
 
+void player_startAutonav(void) {
+  player_message("Autonav continuing.");
+  player_setFlag(PLAYER_AUTONAV);
+}
+
+/**
+ * @fn void player_abortAutonav(void)
+ *
+ * @brief Aborts autonav
+ */
+void player_abortAutonav(void) {
+  if(player_isFlag(PLAYER_AUTONAV)) {
+    player_message("Autonav aborted!");
+    player_rmFlag(PLAYER_AUTONAV);
+  }
+}
+
 /**
  * @fn void player_think(Pilot* pplayer)
  *
@@ -1481,6 +1498,15 @@ void player_think(Pilot* pplayer) {
     return;
   }
 
+  /* Autonav takes over normal controls. */
+  if(player_isFlag(PLAYER_AUTONAV)) {
+    if(pplayer->lockons > 0)
+      player_abortAutonav();
+
+    if(space_canHyperspace(pplayer))
+      player_jump();
+  }
+
   /* PLAYER_FACE will take over navigation. */
   if(player_isFlag(PLAYER_FACE)) {
     if(player_target != PLAYER_ID)
diff --git a/src/player.h b/src/player.h
index 5dd8e3d..f0eb900 100644
--- a/src/player.h
+++ b/src/player.h
@@ -14,6 +14,7 @@
 #define PLAYER_SECONDARY_L  (1<<14)   /**< Player shot secondary last frame. */
 #define PLAYER_LANDACK      (1<<15)   /**< Player has permission to land. */
 #define PLAYER_CREATING     (1<<16)   /**< Player is being created. */
+#define PLAYER_AUTONAV      (1<<16)   /**< Player has autonaviagation on. */
 
 /* Flag functions. */
 #define player_isFlag(f)  (player_flags  & f)   /**< Check for a player flag. */