From ee57228de53faffe58c04b85ab812f1fb2ce16ac Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Mon, 17 Mar 2014 00:22:46 +0000
Subject: [PATCH] [Add] Mission destinations are now marked when selecting
 mission at the mission computer.

---
 src/land.c    | 10 +++++++++-
 src/map.c     | 29 ++++++++++++++++++-----------
 src/mission.c | 17 +++++++++++++++++
 src/mission.h |  3 ++-
 src/space.c   |  9 +++++++++
 src/space.h   |  2 ++
 6 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/src/land.c b/src/land.c
index 479d47e..00b4e29 100644
--- a/src/land.c
+++ b/src/land.c
@@ -104,6 +104,7 @@ static void spaceport_bar_open(void);
 static void news_open(unsigned int parent, char* str);
 /* Mission computer. */
 static void misn_open(void);
+static void misn_close(unsigned int wid, char* name);
 static void misn_accept(unsigned int wid, char* str);
 static void misn_genList(unsigned int wid, int first);
 static void misn_update(unsigned int wid, char* str);
@@ -1016,7 +1017,7 @@ static void misn_open(void) {
   /* Buttons. */
   window_addButton(wid, -20, 20,
                    BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseMission",
-                   "Close", window_close);
+                   "Close", misn_close);
 
   window_addButton(wid, -20, 40+BUTTON_HEIGHT,
                    BUTTON_WIDTH, BUTTON_HEIGHT, "btnAcceptMission",
@@ -1037,6 +1038,12 @@ static void misn_open(void) {
   misn_genList(wid, 1);
 }
 
+static void misn_close(unsigned int wid, char* name) {
+  /* Remove computer markers just in case. */
+  space_clearComputerMarkers();
+  window_close(wid, name);
+}
+
 static void misn_accept(unsigned int wid, char* str) {
   char* misn_name;
   Mission* misn;
@@ -1107,6 +1114,7 @@ static void misn_update(unsigned int wid, char* str) {
     return;
   }
   misn = &mission_computer[toolkit_getListPos(wid, "lstMission")];
+  mission_sysComputerMark(misn);
   window_modifyText(wid, "txtReward", misn->reward);
   window_modifyText(wid, "txtDesc", misn->desc);
   window_enableButton(wid, "btnAcceptMission");
diff --git a/src/map.c b/src/map.c
index 5237486..ab54157 100644
--- a/src/map.c
+++ b/src/map.c
@@ -21,14 +21,14 @@
 #define BUTTON_WIDTH    60
 #define BUTTON_HEIGHT   30
 
-static double map_zoom = 1.;          /* Zoom of the map. */
-static double map_xpos  = 0.;         /* Map position. */
-static double map_ypos  = 0.;
-static int map_selected = -1;
-static StarSystem** map_path = NULL;  /* The path to current selected system. */
-int map_npath = 0;
+static double map_zoom  = 1.;         /**< Zoom of the map. */
+static double map_xpos  = 0.;         /**< Map X position. */
+static double map_ypos  = 0.;         /**< Map Y position. */
+static int map_selected = -1;         /**< Currently selected system on map. */
+static StarSystem** map_path = NULL;  /**< The path to current selected system. */
+int map_npath = 0;                    /**< Number of systems in map_path. */
 
-static int map_drag = 0;              /* Is the user dragging the map? */
+static int map_drag = 0;              /**< Is the user dragging the map? */
 
 /* Extern. */
 /* space.c */
@@ -45,7 +45,9 @@ static void map_mouse(unsigned int wid, SDL_Event* event, double mx, double my);
 static void map_buttonZoom(unsigned int wid, char* str);
 static void map_selectCur(void);
 
-/* Open the map window. */
+/**
+ * @brief Open the map window.
+ */
 void map_open(void) {
   unsigned int wid;
 
@@ -328,7 +330,8 @@ static void map_render(double bx, double by, double w, double h) {
     sys = &systems_stack[i];
 
     /* Check to make sure system is known of adjacent to known (or marked). */
-    if(!sys_isMarked(sys) && !space_sysReachable(sys)) continue;
+    if(!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys))
+      continue;
 
     /* System colours. */
     if(sys == cur_system) col = &cRadar_tPlanet;
@@ -342,8 +345,12 @@ static void map_render(double bx, double by, double w, double h) {
     gl_drawCircleInRect(tx, ty, r, bx, by, w, h);
 
     /* Mark the system if needed. */
-    if(sys_isMarked(sys)) {
-      COLOUR(cRed);
+    if(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) {
+      if(sys_isFlag(sys, SYSTEM_CMARKED))
+        COLOUR(cGreen);
+      else if(sys_isFlag(sys, SYSTEM_MARKED))
+        COLOUR(cRed);
+         
       glBegin(GL_TRIANGLES);
         glVertex2d(tx+r+9, ty+r+3);
         glVertex2d(tx+r+3, ty+r+3);
diff --git a/src/mission.c b/src/mission.c
index b00d786..ac9a51b 100644
--- a/src/mission.c
+++ b/src/mission.c
@@ -303,6 +303,23 @@ void mission_sysMark(void) {
   }
 }
 
+/**
+ * @brief Marks the system of the computer mission to reflect where it will head to.
+ *
+ * Does not modify other markers.
+ *    @param misn Mission to mark.
+ */
+void mission_sysComputerMark(Mission* misn) {
+  StarSystem* sys;
+
+  space_clearComputerMarkers();
+
+  if(misn->sys_marker != NULL) {
+    sys = system_get(misn->sys_marker);
+    sys_setFlag(sys, SYSTEM_CMARKED);
+  }
+}
+
 /* Links cargo to the mission for posterior cleanup. */
 int mission_linkCargo(Mission* misn, unsigned int cargo_id) {
   misn->ncargo++;
diff --git a/src/mission.h b/src/mission.h
index 3598ab9..40bd45c 100644
--- a/src/mission.h
+++ b/src/mission.h
@@ -76,13 +76,14 @@ Mission* missions_computer(int* n, int faction, char* planet, char* sysname);
 /* Player accepted mission - mission computer. */
 int mission_accept(Mission* mission);
 void missions_run(int loc, int faction, char* planet, char* sysname);
-int missions_start(char* name);
+int mission_start(char* name);
 
 /* Misc. */
 void missions_update(const double dt);
 int mission_getID(char* name);
 MissionData* mission_get(int id);
 void mission_sysMark(void);
+void mission_sysComputerMark(Mission* misn);
 
 /* Cargo stuff. */
 int mission_linkCargo(Mission* misn, unsigned int cargo_id);
diff --git a/src/space.c b/src/space.c
index 186ae91..8417a7d 100644
--- a/src/space.c
+++ b/src/space.c
@@ -1350,6 +1350,15 @@ void space_clearMarkers(void) {
     sys_rmFlag(&systems_stack[i], SYSTEM_MARKED);
 }
 
+/**
+ * @brief Clear all the system computer markers.
+ */
+void space_clearComputerMarkers(void) {
+  int i;
+  for(i = 0; i < systems_nstack; i++)
+    sys_rmFlag(&systems_stack[i], SYSTEM_CMARKED);
+}
+
 /* Save what is needed to be saved for space. */
 int space_sysSave(xmlTextWriterPtr writer) {
   int i;
diff --git a/src/space.h b/src/space.h
index 3272996..b4d6fab 100644
--- a/src/space.h
+++ b/src/space.h
@@ -82,6 +82,7 @@ typedef struct Planet_ {
 /* Star system flags. */
 #define SYSTEM_KNOWN      (1<<0)    /**< System is known. */
 #define SYSTEM_MARKED     (1<<1)    /**< System is marked by a mission. */
+#define SYSTEM_CMARKED    (1<<2)    /**< System is marked by a coputer mission. */
 #define sys_isFlag(s,f)   ((s)->flags & (f))    /**< Check system flag. */
 #define sys_setFlag(s,f)  ((s)->flags |= (f))   /**< Set a system flag. */
 #define sys_rmFlag(s,f)   ((s)->flags &= ~(f))  /**< Remove a system flag. */
@@ -165,5 +166,6 @@ char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions);
 char* space_getRndPlanet(void);
 void  space_clearKnown(void);
 void  space_clearMarkers(void);
+void  space_clearComputerMarkers(void);
 extern char* stardate;