Update of /cvsroot/netrek/client/netrekxp/src
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30771/src

Modified Files:
	input.c planetlist.c senddist.c 
Log Message:
Fix for macro crash bug with sending macros through the playerlist to
enemies who were not visible.
Added mapSort functionality.  Separates planet list to show ind planets
first, then your team's planets, then your largest enemy's planets, then
your second largest enemy's planets, then the last remaining team, and
finally the unknown planets.  Also added separator lines to both the
sorted and unsorted planet list.  Separator lines occur at regular 10
planet intervals in the unsorted list, so as to show each team's
original planets.  In the sorted list, they appear as divisors between
the current planet owners (rather than original owners).

Index: input.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/input.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- input.c	16 Mar 2007 01:44:24 -0000	1.28
+++ input.c	16 Mar 2007 17:24:16 -0000	1.29
@@ -1542,7 +1542,9 @@
         if (data->key == W_LBUTTON)
         {
             sortPlanets = !sortPlanets;
-            updatePlanetw();
+            /* Do a full refresh */
+            W_UnmapWindow (planetw);
+            W_MapWindow (planetw);
         }
         else if (data->key == W_RBUTTON)
             W_UnmapWindow (planetw);

Index: senddist.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/senddist.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- senddist.c	28 May 2006 23:05:12 -0000	1.5
+++ senddist.c	16 Mar 2007 17:24:16 -0000	1.6
@@ -89,11 +89,11 @@
     dist->preappend[0] = '\0';
     dist->macroflag = 0;
 
-	/* If any of gettarget calls returned -1 -> meaning we are in playerlist
-	   window trying to send distress to not available person */
-	if (dist->tclose_pl == 255 || dist->tclose_en == 255 ||
-		dist->tclose_fr == 255 || dist->tclose_j == 255)
-		dist->sender = 255;
+    /* If any of gettarget calls returned -1 -> meaning we are in playerlist
+       window trying to send distress to not available person */
+    if (dist->tclose_pl == 255 || dist->tclose_en == 255 ||
+        dist->tclose_fr == 255 || dist->tclose_j == 255)
+        dist->sender = 255;
 
     return (dist);
 }
@@ -116,8 +116,8 @@
     recip = me->p_team;
 
     dist = loaddistress (i, data);
-	if (dist->sender == 255)
-		return;
+    if (dist->sender == 255)
+        return;
 
     if (gen_distress)
     {
@@ -193,6 +193,8 @@
     pm = macro[mnum].string;
 
     dist = loaddistress (0, data);
+    if (dist->sender == 255)
+        return (0);
 
     len = makedistress (dist, cry, pm);
     if (len > 0)

Index: planetlist.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/planetlist.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- planetlist.c	16 Mar 2007 01:44:24 -0000	1.5
+++ planetlist.c	16 Mar 2007 17:24:16 -0000	1.6
@@ -19,6 +19,7 @@
 #include "proto.h"
 
 static char priorplanets[MAXPLANETS][BUFSIZ];
+int planet_row[MAXPLANETS];  /* planets location in current plist */
 
 static char *teamname[9] = {
     "IND",
@@ -32,8 +33,6 @@
     "ORI"
 };
 
-int planet_row[MAXPLANETS];  /* planets location in current plist */
-
 /* * Open a window which contains all the planets and their current *
  * statistics.  Players will not know about planets that their team * has not
  * orbited. */
@@ -58,14 +57,133 @@
 void
 updatePlanetw (void)
 {
-    register int i;
+    register int i, pos;
     char buf[BUFSIZ];
     register struct planet *j;
+    int planetCount[NUMTEAM + 2]; /* Ind Fed Rom Kli Ori Unknown */
+    int planetOffset[NUMTEAM + 2];
+    int counter[NUMTEAM + 2];
+    int playercount = 0;
+    int largestteam = -1, nextlargestteam= -1;
+    int largestteamcount = -1, nextlargestteamcount = -1;
+    
+    if (sortPlanets)
+    {
+        /* Must first know how many planets we have info on, that belong to
+           our team, then the ones belonging to the other 3 teams, plus
+           independent.  Order on planet list will be independent planets,
+           then our team, then the next largest team (player-wise), and
+           then the second-largest team (player-wise). */
+        
+        /* Init arrays.  Array position 0 will be always be independents,
+           array position 1 will always be my team, and final array position
+           will always be unknown planets */
+        for (i = NUMTEAM + 1; i >= 0; --i)
+        {
+            planetCount[i] = 0;
+            planetOffset[i] = 0;
+            counter[i] = 0;
+        }
+
+        /* Find the 2 largest teams enemy teams.  Team bits suck. */
+        for (i = 0; i < NUMTEAM; i++)
+        {
+            if (me->p_team == (1 << i))
+                continue;
+
+            playercount = realNumShips(1 << i);
+            if (playercount > largestteamcount)
+            {
+                nextlargestteam = largestteam;
+                nextlargestteamcount = largestteamcount;
+                largestteam = (1 << i);
+                largestteamcount = playercount;
+            }
+            else if (playercount > nextlargestteamcount)
+            {
+                nextlargestteam = (1 << i);
+                nextlargestteamcount = playercount;
+            }
+        }
 
+        /* Store # of visible planets from each team */
+        for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++)
+        {
+            if (j->pl_info & me->p_team)
+            {
+                if (j->pl_owner == 0) /* Independent */
+                    ++planetCount[0];
+                else if (j->pl_owner == me->p_team) /* My team */
+                    ++planetCount[1];
+                else if (j->pl_owner == largestteam) /* Largest enemy */
+                    ++planetCount[2];
+                else if (j->pl_owner == nextlargestteam) /* Next largest enemy */
+                    ++planetCount[3];
+                else /* Smallest enemy */
+                    ++planetCount[4];
+            }
+            else
+                ++planetCount[5];
+        }
+        /* Set the offsets */
+        planetOffset[0] = 0;
+        planetOffset[1] = planetOffset[0] + planetCount[0];
+        planetOffset[2] = planetOffset[1] + planetCount[1];
+        planetOffset[3] = planetOffset[2] + planetCount[2];
+        planetOffset[4] = planetOffset[3] + planetCount[3];
+        planetOffset[5] = planetOffset[4] + planetCount[4];
+    }
+#if 0 /* Debug */
+    LineToConsole("My team %d, Largest enemy %d, next %d\n",
+    remap[me->p_team], largestteam, nextlargestteam);
+    LineToConsole("Pl counts are %d %d %d %d %d\n",
+    planetCount[1],planetCount[2],planetCount[3],planetCount[4],planetCount[5]);
+    LineToConsole("Offsets are %d %d %d %d %d\n",
+    planetOffset[1],planetOffset[2],planetOffset[3],planetOffset[4],planetOffset[5]);
+#endif
     for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++)
     {
+        if (sortPlanets)
+        {
+            if (j->pl_info & me->p_team)
+            {
+                if (j->pl_owner == 0) /* Independent */
+                {
+                    pos = planetOffset[0] + counter[0];
+                    counter[0]++;
+                }
+                else if (j->pl_owner == me->p_team) /* My team */
+                {
+                    pos = planetOffset[1] + counter[1];
+                    counter[1]++;
+                }
+                else if (j->pl_owner == largestteam) /* Largest enemy */
+                {
+                    pos = planetOffset[2] + counter[2];
+                    counter[2]++;
+                }
+                else if (j->pl_owner == nextlargestteam) /* Next largest enemy */
+                {
+                    pos = planetOffset[3] + counter[3];
+                    counter[3]++;
+                }
+                else /* Smallest enemy */
+                {
+                    pos = planetOffset[4] + counter[4];
+                    counter[4]++;
+                }
+            }
+            else
+            {
+                pos = planetOffset[5] + counter[5];
+                counter[5]++;
+            }
+        }
+        else
+            pos = i;
+
         /* Fill planet_row to get right planet placement in the list */
-        planet_row[i] = j->pl_no;
+        planet_row[pos] = j->pl_no;
 
         if (j->pl_info & me->p_team)
         {
@@ -81,33 +199,64 @@
                             (j->pl_info & ROM ? 'R' : ' '),
                             (j->pl_info & KLI ? 'K' : ' '),
                             (j->pl_info & ORI ? 'O' : ' '));
-            if (strcmp(priorplanets[i], buf))
-            {
-                W_ClearArea (planetw, 2, i+2, 55, 1);
-                W_WriteText (planetw, 2, i+2, planetColor (j), buf, strlen (buf),
-                             planetFont (j));
-                strcpy(priorplanets[i], buf);
-            }
         }
         else
-        {
             (void) sprintf (buf, "%-16s", j->pl_name);
-            if (strcmp(priorplanets[i], buf))
-            {
-            	W_ClearArea (planetw, 2, i+2, 55, 1);
-                W_WriteText (planetw, 2, i+2, unColor, buf, strlen (buf),
-                             W_RegularFont);
-                strcpy(priorplanets[i], buf);
-            } 
-        }
-        if (i != 0 && (i % 10) == 0)
+
+        if (strcmp(priorplanets[pos], buf))
         {
-              W_MakeLine (planetw,
-                          2 + 18 * W_Textwidth,
-                          2 + W_Textheight * (i+2),
-                          2 + 39 * W_Textwidth,
-                          2 + W_Textheight * (i+2),
-                          W_White);
+            W_ClearArea (planetw, 2, pos+2, 55, 1);
+            if (j->pl_info & me->p_team)
+                W_WriteText (planetw, 2, pos+2, planetColor (j), buf, strlen (buf),
+                             planetFont (j));
+            else
+                W_WriteText (planetw, 2, pos+2, unColor, buf, strlen (buf),
+                             W_RegularFont);
+            strcpy(priorplanets[pos], buf);
+            /* Do we need to redraw a team separator line? */
+            if (!sortPlanets)
+            {
+                /* Static line positions - only redraw them if the relevant
+                   line changed */
+                if (pos == 9 || pos == 19 || pos == 29)
+                {
+                    W_MakeLine (planetw,
+                                2 + 18 * W_Textwidth,
+                                2 + W_Textheight * (pos+3),
+                                2 + 39 * W_Textwidth,
+                                2 + W_Textheight * (pos+3),
+                                W_White);
+                }
+            }
+            else
+            {
+                /* Dynamic team separators, sorted map */
+                if ((pos == planetOffset[1] - 1)
+                    || (pos == (planetOffset[2] - 1))
+                    || (pos == (planetOffset[3] - 1))
+                    || (pos == (planetOffset[4] - 1))
+                    || (pos == (planetOffset[5] - 1)))
+                {
+                    /* Erase any line above it first, if it was 
+                       part of the same team */
+                    if (pos != 0 && (planets[planet_row[pos]].pl_owner == 
+                        planets[planet_row[pos-1]].pl_owner))
+                    {
+                        W_MakeLine (planetw,
+                                    2 + 18 * W_Textwidth,
+                                    2 + W_Textheight * (pos+2),
+                                    2 + 39 * W_Textwidth,
+                                    2 + W_Textheight * (pos+2),
+                                    W_Black);
+                    }
+                    W_MakeLine (planetw,
+                                2 + 18 * W_Textwidth,
+                                2 + W_Textheight * (pos+3),
+                                2 + 39 * W_Textwidth,
+                                2 + W_Textheight * (pos+3),
+                                W_White);
+                }
+            }
         }
     }
 }
@@ -115,19 +264,8 @@
 int
 GetPlanetFromPlist (int x, int y)
 {
-    int i;
-    int planet_no;
-
-    /* Let's find what planet sits in poition y in the list */
-    for (i = 0; i < MAXPLANETS; i++)
-    {
-        if (planet_row[i] == y)
-        {
-            planet_no = i;
-            return planet_no;
-        }
-    }
-
-    // We didn't find planet
-    return (-1);
+    if (y < MAXPLANETS && y >= 0)
+        return planet_row[y];
+    else
+        return (-1);
 }
\ No newline at end of file