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

Modified Files:
	cowmain.c data.c defaults.c feature.c input.c local.c map.c 
	mswindow.c newwin.c playback.c 
Log Message:
This lengthy patch contains one groundbreaking item - allowing user to
configure directly the size of the local and map windows.  Most of this
patch fixes all the problems that needed to be solved to make this happen.
First off, it was necessary to have the netrekrc defaults read in BEFORE
windows are generated.  So in both cowmain. and playback.c, the order
of newwin() and resetdefaults() were exchanged.  This created a problem
though in the netrekrc Windows Allowed Message settings required the
window to actually exist first, so this was yanked out of the resetdefaults()
routine and placed into newwin().  It was also copied over to the reread
netrekrc function, so that rereading netrekrc will update the WAMs.
Half-finished code for rechecking windows geometry after reading defaults
is now obsolete, and a comment has been left to that effect.
This exchange also fixes one of the problems with richText.  The netrekrc
richText option now works, as it controls what sort of message windows
are created.  Still buggy, but at least it's mostly functional.
Getting back to the initial goal, WINSIDE and SCALE were moved from
defines to variables.  This required some changes to be made.  Any static
variable which relied on WINSIDE had to be moved into functions.  This
was not so difficult, as it just required some view/fullview variables to be
redefined in the star redraw functions, and tts_ypos had to be changed a 
bit so that the preferred value was not the value in data.c but rather a
value based on WINSIDE.
With WINSIDE now a variable, the checkGeometry function can now set
WINSIDE to match the geometry in the user's netrekrc file.  Some (ok
a LOT) of work still needs to be done, to separate WINSIDE into 2 
variables, TWINSIDE and GWINSIDE, so local and map can be different
size squares.
Testing WINSIDE=1000 revealed that the star sectors did not scale properly,
and indeed it was a design flaw which needed to be fixed.  Star sectors now
are defined to be the size of the local window, and the star density remains
constant no matter what size window.  As it is now possible to have GWIDTH
divided by star sectors != integer, it was necessary to put in some additonal
checks against drawing stars outside of galactic bounds, and to add an 
additional star sector in either direction to handle the case where we need
a fraction of a star sector to fill in space (i.e if WINSIDE = 1000, local stretches
40000 galactic units, that makes galaxy 2.5 star sectors wide, and since most
things get rounded down, we need to create 2.5 + 1 = 3 star sectors).  It turns
out the old code made 4x as many star sectors as there was galaxy, for some
odd reason, so this is a nice improvement actually!
Since the local window can now be expanded, I added in a dashed line to
show the old 20000x20000 local scale, because some data is not sent beyond
this (ie other people's weapons).  A new INFORANGE constant is defined, and
if WINSIDE > INFORANGE, we draw these dashed lines to indicate fog of war.
The SMALL_SCREEN option, which wasn't functional anyways, was removed
as it is now obsolete.
New draw line function W_MakeDashedLine for making a line using the
dashed pen.
Added in a debug statement to ignore feature packet settings to test the
new infoborg features.

Index: mswindow.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/mswindow.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- mswindow.c	26 Mar 2007 02:47:18 -0000	1.53
+++ mswindow.c	5 Apr 2007 12:57:22 -0000	1.54
@@ -3043,6 +3043,35 @@
         ReleaseDC (win->hwnd, hdc);
 }
 
+void
+W_MakeDashedLine (W_Window window,
+                  int x0,
+                  int y0,
+                  int x1,
+                  int y1,
+                  W_Color color)
+{
+    register int border;
+    DBHEADER_VOID;
+    
+    border = win->border;
+
+    if (NetrekPalette)
+    {
+        SelectPalette (hdc, NetrekPalette, FALSE);
+        RealizePalette (hdc);
+    }
+    SetBkColor (hdc, colortable[BLACK].rgb);
+    SelectObject (hdc, colortable[color].dashedpen);
+    MoveTo (hdc, x0 + border, y0 + border);
+    LineTo (hdc, x1 + border, y1 + border);
+    /* Get that last point in there ... -SAC */
+    SetPixel (hdc, x1 + border, y1 + border, colortable[color].rgb);
+
+    if (!sdb || !doubleBuffering || !ingame)
+        ReleaseDC (win->hwnd, hdc);
+}
+
 //We don't need to cache...
 void
 W_CacheLine (W_Window window,
@@ -4797,6 +4826,12 @@
         while (*s != 'x' && *s != 0)
             s++;
         *width = atoi (geom_default);
+        if (!strcmp("local", name))
+            WINSIDE = *width;
+/*      Need to separate WINSIDE into TWINSIDE and GWINSIDE  
+        else if (!strcmp("map", name))
+            WINSIDE = *width;
+*/
         result |= G_SET_WIDTH;
         if (*s == 0)
             return result;
@@ -4805,6 +4840,18 @@
         while (*s != '+' && *s != '-' && *s != 0)
             s++;
         *height = atoi (geom_default);
+        if (!strcmp("local", name))
+        {
+            if (*height > *width)
+                WINSIDE = *height;
+        }
+/*
+        else if (!strcmp("map", name))
+        {
+            if (*height > *width)
+                WINSIDE = *height;
+        }
+*/
         result |= G_SET_HEIGHT;
         if (*s == 0)
             return result;

Index: newwin.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/newwin.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- newwin.c	2 Apr 2007 21:12:42 -0000	1.58
+++ newwin.c	5 Apr 2007 12:57:22 -0000	1.59
@@ -942,6 +942,9 @@
         W_SetWindowKeyDownHandler (reviewWin, handleMessageWindowKeyDown);
     }
     /* End of Message windows */
+    /* Now let's set Window Allowed Messages for all message windows */
+    for (i = 0; i < 6; i++)
+        W_SetWAM (wam_windows[i]);
 
     pStats = W_MakeWindow ("pingStats", 500, 4, pStatsWidth (), pStatsHeight (),
                             baseWin, 1, foreColor);

Index: input.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/input.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- input.c	1 Apr 2007 10:11:37 -0000	1.30
+++ input.c	5 Apr 2007 12:57:22 -0000	1.31
@@ -3502,6 +3502,7 @@
 void
 reread_defaults (void)
 {
+    int i;
     char mbuf[80];
 
     if (strlen (defaultsFile) > 0)
@@ -3510,6 +3511,9 @@
         warning (mbuf);
         initDefaults (defaultsFile);
         resetdefaults ();
+        /* Set Window Allowed Messages ( since it got moved to newwin() )*/
+        for (i = 0; i < 6; i++)
+            W_SetWAM (wam_windows[i]);
         initkeymap ();
     }
     else

Index: local.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- local.c	4 Apr 2007 04:06:37 -0000	1.85
+++ local.c	5 Apr 2007 12:57:22 -0000	1.86
@@ -68,8 +68,8 @@
 
 #define scaleLocal(pt)           ((pt)/SCALE + (WINSIDE/2))
 
-int fullview = WINSIDE * SCALE;
-int view = WINSIDE * SCALE / 2;
+#define STARSIDE 500          /* Used to normalize star density */
+#define INFORANGE 500         /* Range at which server stops sending some data */
 
 static struct _star stars[10][10][16];
 
@@ -123,11 +123,12 @@
 {
     register int i, j, k;
 
-    for (i = 0; i < 10; i++) {
-       for (j = 0; j < 10; j++) {
-            for (k = 0; k < 16; k++) {
-                stars[i][j][k].s_x = RANDOM() % 20000;
-                stars[i][j][k].s_y = RANDOM() % 20000;
+    /* Star density: 16 stars per 20000 x 20000 galactic region */
+    for (i = 0; i < (5 * STARSIDE / WINSIDE + 1); i++) {
+       for (j = 0; j < (5 * STARSIDE / WINSIDE + 1); j++) {
+            for (k = 0; k < (16 * (WINSIDE / STARSIDE) * (WINSIDE / STARSIDE)); k++) {
+                stars[i][j][k].s_x = RANDOM() % 20000 * WINSIDE / STARSIDE;
+                stars[i][j][k].s_y = RANDOM() % 20000 * WINSIDE / STARSIDE;
                 stars[i][j][k].s_color = randcolor();
             }
         }
@@ -138,6 +139,8 @@
 void
 DrawStars()
 {
+    const int fullview = WINSIDE * SCALE;
+    const int view = WINSIDE * SCALE / 2;
     /*
        note: cpp symbols in expressions (WINSIDE*SCALE) will be precalculated
        by any C optimizer
@@ -168,7 +171,7 @@
         sector_offy += fullview; 
     }   
 
-#define MAXSECTOR   (GWIDTH/(fullview))
+#define MAXSECTOR   (5 * STARSIDE / WINSIDE) + 1
   
     /* at worst we have to redraw 4 star sectors */
 
@@ -228,6 +231,8 @@
 static void
 redrawStarSector (int sectorx, int sectory)
 {
+    const int fullview = WINSIDE * SCALE;
+    const int view = WINSIDE * SCALE / 2;
     register int i, dx, dy, dxx, dyy;
     register int xbase = sectorx * fullview;
     register int ybase = sectory * fullview;
@@ -287,8 +292,11 @@
             }
             dxx = (int) (Cos[mydir] * streaklength / 10);
             dyy = (int) (Sin[mydir] * streaklength / 10);
-            for (i = 0, s = star_sector; i < 16; i++, s++)
+            for (i = 0, s = star_sector; i < (16 * (WINSIDE / STARSIDE) * (WINSIDE / STARSIDE)); i++, s++)
             {
+                if (s->s_x + xbase > GWIDTH || s->s_y + ybase > GWIDTH)
+                    continue;
+
                 dx = (s->s_x + xbase) - (me->p_x - (me->p_x % SCALE));
                 dy = (s->s_y + ybase) - (me->p_y - (me->p_y % SCALE));
                 if (ABS(dx) > (view) || ABS(dy) > (view))
@@ -307,8 +315,11 @@
             return;
         }
     }
-    for (i = 0, s = star_sector; i < 16; i++, s++)
+    for (i = 0, s = star_sector; i < (16 * (WINSIDE / STARSIDE) * (WINSIDE / STARSIDE)); i++, s++)
     {
+        if (s->s_x  + xbase > GWIDTH || s->s_y + ybase > GWIDTH)
+            continue;
+
         dx = (s->s_x + xbase) - (me->p_x - (me->p_x % SCALE));
         dy = (s->s_y + ybase) - (me->p_y - (me->p_y % SCALE));
         if (ABS(dx) > (view) || ABS(dy) > (view))
@@ -2372,6 +2383,50 @@
                                  * Ends the if, too */
 #endif /* HOCKEY_LINES */
 
+    /* Draw inforange box (if necessary) */
+    if ( WINSIDE > INFORANGE )
+    {
+        dx = (WINSIDE / 2) + (INFORANGE / 2);
+        sy = (WINSIDE / 2) - (INFORANGE / 2);
+        ey = (WINSIDE / 2) + (INFORANGE / 2);
+        W_MakeDashedLine (w, dx, sy, dx, ey, W_White);
+        clearline[0][clearlcount] = dx;
+        clearline[1][clearlcount] = sy;
+        clearline[2][clearlcount] = dx;
+        clearline[3][clearlcount] = ey;
+        clearlcount++;
+        
+        dx = (WINSIDE / 2) - (INFORANGE / 2);
+        sy = (WINSIDE / 2) - (INFORANGE / 2);
+        ey = (WINSIDE / 2) + (INFORANGE / 2);
+        W_MakeDashedLine (w, dx, sy, dx, ey, W_White);
+        clearline[0][clearlcount] = dx;
+        clearline[1][clearlcount] = sy;
+        clearline[2][clearlcount] = dx;
+        clearline[3][clearlcount] = ey;
+        clearlcount++;
+        
+        dy = (WINSIDE / 2) + (INFORANGE / 2);
+        sx = (WINSIDE / 2) - (INFORANGE / 2);
+        ex = (WINSIDE / 2) + (INFORANGE / 2);
+        W_MakeDashedLine (w, sx, dy, ex, dy, W_White);
+        clearline[0][clearlcount] = sx;
+        clearline[1][clearlcount] = dy;
+        clearline[2][clearlcount] = ex;
+        clearline[3][clearlcount] = dy;
+        clearlcount++;
+        
+        dy = (WINSIDE / 2) - (INFORANGE / 2);
+        sx = (WINSIDE / 2) - (INFORANGE / 2);
+        ex = (WINSIDE / 2) + (INFORANGE / 2);
+        W_MakeDashedLine (w, sx, dy, ex, dy, W_White);
+        clearline[0][clearlcount] = sx;
+        clearline[1][clearlcount] = dy;
+        clearline[2][clearlcount] = ex;
+        clearline[3][clearlcount] = dy;
+        clearlcount++;
+    }
+
     /* Draw Edges */
     if (me->p_x < (WINSIDE / 2) * SCALE)
     {

Index: playback.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/playback.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- playback.c	11 Mar 2007 22:15:58 -0000	1.19
+++ playback.c	5 Apr 2007 12:57:22 -0000	1.20
@@ -199,9 +199,10 @@
     if ((stringDefault ("indshipHRbmpfile")) != NULL)
         ind_ship_bmp_HR = stringDefault ("indshipHRbmpfile");
 
-    newwin (display_host, name);
 
     resetdefaults ();
+    newwin (display_host, name);
+
     savebitmaps ();
     
     /* open memory...? */

Index: defaults.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/defaults.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- defaults.c	4 Apr 2007 04:06:37 -0000	1.67
+++ defaults.c	5 Apr 2007 12:57:22 -0000	1.68
@@ -1660,7 +1660,7 @@
 
     doubleBuffering = booleanDefault ("doubleBuffering", doubleBuffering);
     allowWheelActions = booleanDefault ("allowWheelActions", allowWheelActions);
-    //richText = booleanDefault ("richText", richText);
+    richText = booleanDefault ("richText", richText);
     newQuit = booleanDefault ("newQuit", newQuit);
     newTeams = booleanDefault ("newTeams", newTeams);
     soundVolume= intDefault ("soundVolume", soundVolume);
@@ -1774,10 +1774,6 @@
     phaserStats = booleanDefault ("phaserStats", phaserStats);
 #endif
 
-    /* Now let's set Window Allowed Messages for all message windows */
-    for (i = 0; i < 6; i++)
-        W_SetWAM (wam_windows[i]);
-
 #ifdef XTRA_MESSAGE_UI
     messageHUD = intDefault ("messageHUD", messageHUD);
     messageHoldThresh = intDefault ("messageHoldThresh", messageHoldThresh);
@@ -1879,7 +1875,7 @@
 	
     tts_time = intDefault("tts_time", tts_time);
     tts_max_len = intDefault("tts_max_len", tts_max_len);
-    tts_ypos = intDefault("tts_ypos", tts_ypos);
+    tts_ypos = intDefault("tts_ypos", WINSIDE / 2 - 16);
 #endif /* BEEPLITE */
 
     shipdefaults[DEFAULTSHIP].keymap = (unsigned char *) stringDefault ("keymap");
@@ -1919,7 +1915,9 @@
     myshipdef = &shipdefaults[myshiptype];
 
 	/* Let's check whether windows settings had changed */
-/* Not working yet
+        /* Read in defaults was moved before window generation, thus this
+           code is obsolete and not worth fixing - BB 04/07 */
+/*
 	updateWindowsGeometry (baseWin);
 	updateWindowsGeometry (w);
 	updateWindowsGeometry (mapw);
@@ -2382,6 +2380,9 @@
     	if (saveBig)
     	{
     	    fputs ("# Window placements section\n", fp);
+    	    fputs ("# Local and map windows MUST be square.  Size can be adjusted.\n", fp);
+    	    fputs ("# If sizing downwards, don't forget to remap any windows nested\n", fp);
+    	    fputs ("# inside these windows, such as team select and quit windows.\n", fp);
     	    fputs ("\n", fp);
     	}
 

Index: data.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- data.c	4 Apr 2007 10:34:22 -0000	1.77
+++ data.c	5 Apr 2007 12:57:22 -0000	1.78
@@ -32,7 +32,9 @@
 struct mctl *mctl;
 struct memory universe;
 
-int ingame = 0;              /* If player is in game - to distinguish between whether
+int WINSIDE = 500;              /* Size of strategic and tactical windows */
+int SCALE = 40;                 /* Window will be one pixel for these # spaces */
+int ingame = 0;                 /* If player is in game - to distinguish between whether
                                    to use double buffering on the local and map window */
 int ghoststart = 0;             /* is this a ghostbust
                                  * restart? */
@@ -555,10 +557,7 @@
 int     last_tts_width = 0;
 int     tts_timer = 0;
 int     tts_time = 25;
-int     tts_ypos = WINSIDE / 2 - 16;		 /* as found in redraw.c *
-
-						  * 
-						  * * originally */
+int     tts_ypos = 234;		 /* was WINSIDE / 2 - 16 */
 char    lastIn[100];
 
 #endif /* BEEPLITE */

Index: feature.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/feature.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- feature.c	4 Apr 2007 10:34:22 -0000	1.13
+++ feature.c	5 Apr 2007 12:57:22 -0000	1.14
@@ -273,6 +273,12 @@
 	    break;
 	}
     }
+    /* Ignore these feature packets for testing purposes */
+#if DEBUG
+    F_show_army_count = 1;
+    F_show_other_speed = 1;
+    F_show_cloakers = 1;
+#endif
 #endif /* BEEPLITE */
 }
 

Index: cowmain.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/cowmain.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cowmain.c	2 Apr 2007 21:12:41 -0000	1.31
+++ cowmain.c	5 Apr 2007 12:57:22 -0000	1.32
@@ -779,6 +779,7 @@
     if ((stringDefault ("indshipHRbmpfile")) != NULL)
         ind_ship_bmp_HR = stringDefault ("indshipHRbmpfile");
 
+    resetdefaults ();
     newwin (display_host, name);
 
 #ifdef META
@@ -800,7 +801,6 @@
     /* Set observer flag as soon as we know port number */
     setObserverMode (xtrekPort);
 
-    resetdefaults ();
     savebitmaps ();
     
 #if defined(SOUND)

Index: map.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/map.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- map.c	4 Apr 2007 10:34:22 -0000	1.41
+++ map.c	5 Apr 2007 12:57:22 -0000	1.42
@@ -505,7 +505,7 @@
     for (l = planets + MAXPLANETS - 1; l >= planets; --l)
     {
         /* Synchronize planet info (up to 10 times/second) for current orbitted planet
-           and once every 5 seconds for all other planets we have info on*/
+           and once every 5 seconds for all other planets we have info on */
         if (F_check_planets)
         {
             if ((me->p_flags & PFORBIT)