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

Modified Files:
	dashboard.c data.c input.c local.c map.c newwin.c planetlist.c 
	rotate.c short.c socket.c util.c 
Log Message:
This patch changes the number of planets from a static to dynamic define.  Paradise servers can have more than 40 planets, so we first redefine the maximum # of planets that we will ever receive, which is MAXPLANETS = 60.  This is a change from the previous value of MAXPLANETS = 40.  We then use a 2nd variable, nplanets, to keep track of how many planets the server actually has.  The default value of nplanets is 40, which is what is used for bronco.  Most places in the code dealing with loop checks have been changed from MAXPLANETS to nplanets.  In a few cases where arrays are defined, the MAXPLANETS value is still used.  The planet window is initially created at bronco size, but as more planets are received via handlePlanet2, the window is recreated to fit the added planets.
Added another possible bug to the paradise todo list.
Fixed bug where print_packets was erroneously changing the value of nplanets.

Index: dashboard.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/dashboard.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- dashboard.c	25 May 2007 03:36:46 -0000	1.24
+++ dashboard.c	13 Apr 2008 02:25:50 -0000	1.25
@@ -1155,7 +1155,7 @@
     int target;
 
     closedist = GWIDTH;
-    for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++)
+    for (i = 0, k = &planets[i]; i < nplanets; i++, k++)
     {
         dist = hypot ((double) (x - k->pl_x), (double) (y - k->pl_y));
         if (dist < closedist)

Index: rotate.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/rotate.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rotate.c	21 Feb 2007 15:17:08 -0000	1.3
+++ rotate.c	13 Apr 2008 02:25:51 -0000	1.4
@@ -96,7 +96,7 @@
     redrawall = 1;
     reinitPlanets = 1;
 
-    for (i = 0, l = planets; i < MAXPLANETS; i++, l++)
+    for (i = 0, l = planets; i < nplanets; i++, l++)
     {
         if (rotate)
         {

Index: newwin.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/newwin.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- newwin.c	12 Apr 2008 23:28:29 -0000	1.70
+++ newwin.c	13 Apr 2008 02:25:51 -0000	1.71
@@ -1006,11 +1006,9 @@
 
     W_SetWindowKeyDownHandler (warnw, handleMessageWindowKeyDown);
 
-#ifdef PARADISE
-    planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 75, MAXPLANETS + 8, baseWin, 2);
-#else
-    planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 57, MAXPLANETS + 3, baseWin, 2);
-#endif
+    // Planet window sized assuming only 40 (nplanets) planets, can be resized if more planets received
+    // see void handlePlanet2 in socket.c
+    planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 57, nplanets + 3, baseWin, 2);
     W_SetWindowExposeHandler (planetw, planetlist);
 
 #ifdef PARADISE
@@ -2106,7 +2104,7 @@
 
     if (planets[remap[owner] * 10 - 10].pl_couptime == 0)
         return (0);
-    for (i = 0, p = planets; i < MAXPLANETS; i++, p++)
+    for (i = 0, p = planets; i < nplanets; i++, p++)
     {
         if (p->pl_owner & owner)
         {

Index: input.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/input.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- input.c	25 May 2007 03:36:46 -0000	1.42
+++ input.c	13 Apr 2008 02:25:51 -0000	1.43
@@ -355,7 +355,7 @@
     }
     closedist = GWIDTH;
 
-    for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++)
+    for (i = 0, k = &planets[i]; i < nplanets; i++, k++)
     {
         dist = hypot ((double) (g_x - k->pl_x), (double) (g_y - k->pl_y));
         if (dist < closedist)

Index: local.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -d -r1.109 -r1.110
--- local.c	12 Apr 2008 23:28:29 -0000	1.109
+++ local.c	13 Apr 2008 02:25:51 -0000	1.110
@@ -580,7 +580,7 @@
     register struct planet *l;
     int view = scaleFactor * TWINSIDE / 2 + BMP_PLANET_WIDTH * SCALE / 2;
 
-    for (l = planets + MAXPLANETS - 1; l >= planets; --l)
+    for (l = planets + nplanets - 1; l >= planets; --l)
     {
         dx = l->pl_x - me->p_x;
         dy = l->pl_y - me->p_y;

Index: planetlist.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/planetlist.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- planetlist.c	6 Apr 2008 22:41:45 -0000	1.10
+++ planetlist.c	13 Apr 2008 02:25:51 -0000	1.11
@@ -328,7 +328,7 @@
 
         /* Store # of visible planets from each team.  And let's sort them
            by army count (low to high) while we are at it. */
-        for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++)
+        for (i = 0, j = &planets[i]; i < nplanets; i++, j++)
         {
             if (j->pl_info & me->p_team)
             {
@@ -429,7 +429,7 @@
     planetOffset[1],planetOffset[2],planetOffset[3],planetOffset[4],planetOffset[5]);
 #endif
 
-    for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++)
+    for (i = 0, j = &planets[i]; i < nplanets; i++, j++)
     {
         if (sortPlanets)
         {
@@ -572,7 +572,7 @@
 int
 GetPlanetFromPlist (int x, int y)
 {
-    if (y < MAXPLANETS && y >= 0)
+    if (y < nplanets && y >= 0)
         return planet_row[y];
     else
         return (-1);

Index: short.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/short.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- short.c	7 Jun 2007 04:43:39 -0000	1.24
+++ short.c	13 Apr 2008 02:25:52 -0000	1.25
@@ -1131,12 +1131,12 @@
 
     numofplanets = (unsigned char) sbuf[1];
 
-    if (numofplanets > MAXPLANETS + 1)
+    if (numofplanets > nplanets + 1)
         return;
 
     for (i = 0; i < numofplanets; i++, packet++)
     {
-        if (packet->pnum >= MAXPLANETS)
+        if (packet->pnum < 0 || packet->pnum >= nplanets)
             continue;
 
         plan = &planets[packet->pnum];

Index: util.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/util.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- util.c	7 Apr 2007 05:17:39 -0000	1.6
+++ util.c	13 Apr 2008 02:25:52 -0000	1.7
@@ -111,7 +111,7 @@
     closedist = GWIDTH;
     if (targtype & TARG_PLANET)
     {
-        for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++)
+        for (i = 0, k = &planets[i]; i < nplanets; i++, k++)
         {
             dist = hypot ((double) (x - k->pl_x), (double) (y - k->pl_y));
             if (dist < closedist)

Index: map.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/map.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- map.c	12 Apr 2008 23:28:29 -0000	1.62
+++ map.c	13 Apr 2008 02:25:51 -0000	1.63
@@ -124,7 +124,7 @@
 #else
     pRadius = BMP_MPLANET_WIDTH * GWIDTH / GWINSIDE / 2;
 #endif
-    for (k = 0, pl = planets; k < MAXPLANETS; k++, pl++)
+    for (k = 0, pl = planets; k < nplanets; k++, pl++)
     {
         /*
            Size of planet is pRadius but a ship will touch the planet if
@@ -164,7 +164,7 @@
     }
     /* Now loop for the new planet bitmaps, which are roughly 50% wider */
     pRadius = 3 * BMP_MPLANET_WIDTH * GWIDTH / GWINSIDE / 4;
-    for (k = 0, pl = planets; k < MAXPLANETS; k++, pl++)
+    for (k = 0, pl = planets; k < nplanets; k++, pl++)
     {
         /*
            Size of planet is pRadius but a ship will touch the planet if
@@ -225,7 +225,7 @@
     const int tHeight = W_Textheight * GWIDTH / GWINSIDE;
     const int tWidth = W_Textwidth * GWIDTH / GWINSIDE;
 
-    for (k = 0, pl = planets; k < MAXPLANETS; k++, pl++)
+    for (k = 0, pl = planets; k < nplanets; k++, pl++)
     {
         startX = (pl->pl_x - pRadius - tWidth) / SIZE;
         endX = (pl->pl_x + pRadius + tWidth + (tWidth / 2)) / SIZE;
@@ -543,11 +543,11 @@
     register int dx, dy;
     char ch, agri_name[3];
 
-    for (l = planets + MAXPLANETS - 1; l >= planets; --l)
+    for (l = planets + nplanets - 1; l >= planets; --l)
     {
         /* Synchronize planet info (up to 10 times/second) for current orbitted
-           planet.  For all other planets, send info on planet 0 through planet
-           MAXPLANETS every MAXPLANETS/10 seconds, one planet at a time,
+           planet.  For all other planets, send info on planet 0 through last
+           planet (nplanets) every nplanets/10 seconds, one planet at a time,
            10 times/second. */
         if (F_check_planets)
         {
@@ -1010,7 +1010,7 @@
             redrawPlayer[i] = 1;
         }
 
-        for (l = planets + MAXPLANETS - 1; l >= planets; --l)
+        for (l = planets + nplanets - 1; l >= planets; --l)
             l->pl_flags |= PLREDRAW;
     }
     else
@@ -1195,7 +1195,7 @@
     /* Increment counter for requesting planet sync (F_check_planets) */
     if (F_check_planets)
     {
-        if ((planet_refresh * 10 / server_ups) >= MAXPLANETS)
+        if ((planet_refresh * 10 / server_ups) >= nplanets)
             planet_refresh = 0;
         else
             planet_refresh++;
@@ -1364,7 +1364,7 @@
             mcleary = dy;
             mclearr = rad;
             mclearccount++;
-            for (pl = planets + MAXPLANETS - 1; pl >= planets; --pl)
+            for (pl = planets + nplanets - 1; pl >= planets; --pl)
             {
                 /* Redraw check - redraw all planets in range.  Have to
                    adjust distance to account for planet radius and text

Index: data.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- data.c	12 Apr 2008 23:28:29 -0000	1.103
+++ data.c	13 Apr 2008 02:25:50 -0000	1.104
@@ -39,6 +39,9 @@
 
 int TWINSIDE = 500;             /* Size of tactical window */
 int GWINSIDE = 500;             /* Size of galactic window */
+
+int nplanets = 40;              /* can be larger for paradise servers, dynamically
+                                   sent via SP_PLANET2 */
 int globalerr = 0;              /* For sending error # between threads */
 int ingame = 0;                 /* If player is in game - to distinguish between whether
                                    to use double buffering on the local and map window */
@@ -292,7 +295,6 @@
 int ngthingies = 0;
 int nplasmas = 1;
 int nphasers = 1;
-int nplanets = MAXPLANETS;	/* get this info dyn. from Pserver */
 struct teaminfo_s *teaminfo = NULL;
 int number_of_teams = 4;
 /* MOTD data */

Index: socket.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/socket.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- socket.c	12 Apr 2008 23:28:30 -0000	1.39
+++ socket.c	13 Apr 2008 02:25:52 -0000	1.40
@@ -1759,6 +1759,8 @@
         return;
     }
 #endif
+    if (packet->pnum > nplanets) // This shouldn't happen...
+        LineToConsole( "handlePlanet: received planet num larger than nplanets\n");
 
     plan = &planets[packet->pnum];
 
@@ -2830,11 +2832,27 @@
     {
       first_planet_packet = 0;
       nplanets = packet->pnum+1;
+      //Resize planet window if more than the default # of planets (40)
+      if (nplanets > 40)
+      {
+        W_DestroyWindow (planetw);
+        planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 75, nplanets + 8, baseWin, 2);
+        W_SetWindowExposeHandler (planetw, planetlist);
+      }
     }
     else
     {
       if((packet->pnum+1) > nplanets)
+      {
         nplanets = packet->pnum+1;
+        //Resize planet window if more than the default # of planets (40)
+        if (nplanets > 40)
+        {
+          W_DestroyWindow (planetw);
+          planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 75, nplanets + 8, baseWin, 2);
+          W_SetWindowExposeHandler (planetw, planetlist);
+        }
+      }
     }
 
     planets[packet->pnum].pl_owner = packet->owner;
@@ -4503,7 +4521,7 @@
    int i;                        /* lcv */
    unsigned int j;
    unsigned char *data;
-   int kills, pnum, nplanets;
+   int kills, pnum, packet_planets;
    struct planet_s_spacket *plpacket;
    if(log_packets == 0) return;
    switch ( packet[0] )
@@ -4920,9 +4938,9 @@
 	 if (log_packets > 1)
 	   {
 	     plpacket = (struct planet_s_spacket *) &packet[2];
-	     nplanets = packet[1];
-             LineToConsole("nplanets = %d, ", nplanets);
-             for(i = 0; i < nplanets; i++, plpacket++ )
+	     packet_planets = packet[1];
+	     LineToConsole("packet_planets = %d, ", packet_planets);
+	     for(i = 0; i < packet_planets; i++, plpacket++ )
 	       LineToConsole(
 		       "pnum = %d, pl_owner = %d, info = %d, flags = %d, armies = %d ", 
 		       plpacket->pnum,