view newwin.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
line wrap: on
line source

/* $Id: newwin.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */

/*
 * newwin.c
 */
#include "copyright.h"

#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <math.h>
#include <signal.h>
#include <sys/types.h>
#include <string.h>
#ifdef hpux
#include <time.h>
#else				/* hpux */
#include <sys/time.h>
#endif				/* hpux */
#ifdef RS6K
#include <sys/select.h>
#endif
#include "Wlib.h"
#include "defs.h"
#include "struct.h"
#include "data.h"
#include "gameconf.h"



#include "oldbitmaps.h"
#include "bitmaps_pr.h"
#include "bitmaps3.h"
#include "hullbitmaps.h"
#include "planetbitmaps.h"
#include "rabbitbitmaps.h"
#include "starbitmaps.h"

#ifdef BEEPLITE
#include "emph_planet_seq.h"
#include "emph_player_seq.h"
#include "emph_player_seql.h"
#endif

#include "packets.h"
#include "proto.h"

#define NRHEADERS	4
W_Icon  headerA, headerB, headerchanges[NRHEADERS];
W_Icon  safepic;
/* elapsed time in outfit window [BDyess] */
int     elapsed;

int     newMotdStuff = 0;	/* set to 1 when new motd packets arrive */
static struct piclist *motdPics = NULL;
/*static struct page *currpage = NULL;
static struct page *motddata = NULL;*/

#define LINESPERPAGE	38

#define BOXSIDE		(WINSIDE / 5)
#define TILESIDE	16
#define MESSAGESIZE	20
#define STATSIZE	(MESSAGESIZE * 2 + BORDER)
#define YOFF		0

#define stipple_width 16
#define stipple_height 16
static unsigned char stipple_bits[] = {
    0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08,
    0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80,
    0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08,
0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80};

/* ATM: extra stuff for those who don't like my visible tractors */
#define tract_width 5
#define tract_height 5
static char tract_bits[] = {
0x1f, 0x04, 0x04, 0x04, 0x04};
#define press_width 5
#define press_height 5
static char press_bits[] = {
0x0f, 0x11, 0x0f, 0x01, 0x01};

/* Prototypes */
static void savebitmaps P((void));
static int teamRequest P((int team, int ship));
static int numShips P((int owner));
static int checkBold P((char *line));
void showMotd P((W_Window win));
static void showPics P((W_Window win));
void showValues P((W_Window win));
static void getResources P((char *prog));
static void getTiles P((void));
static void redrawTeam P((W_Window win, int teamNo, int *lastnum));
static void redrawQuit P((void));
static void showTimeLeft P((int time, int max));

/* from dashboard.c: */
void light_erase P((void));

extern int helpmessages;

void
newwin(hostmon, progname)
    char   *hostmon, *progname;
{
    int     i;

    /* W_Initialize(hostmon); */

    baseWin = W_MakeWindow("netrek", 0, YOFF, WINSIDE * 2 + 1 * BORDER,
			   WINSIDE + 2 * BORDER + 2 * MESSAGESIZE, NULL, "bomb here", BORDER, gColor);
    iconWin = W_MakeWindow("netrek_icon", 0, 0, icon_width, icon_height, NULL,
			   (char *) 0, BORDER, gColor);
    W_SetIconWindow(baseWin, iconWin);
    w = W_MakeWindow("local", -BORDER, -BORDER, WINSIDE, WINSIDE, baseWin,
		     (char *) 0, BORDER, foreColor);
    mapw = W_MakeWindow("map", WINSIDE, -BORDER, WINSIDE, WINSIDE, baseWin,
			(char *) 0, BORDER, foreColor);
    tstatw = W_MakeWindow("tstat", -BORDER, WINSIDE, WINSIDE, STATSIZE, baseWin,
			  "xterm", BORDER, foreColor);
    warnw = W_MakeWindow("warn", WINSIDE, WINSIDE, WINSIDE, MESSAGESIZE,
			 baseWin, "xterm", BORDER, foreColor);
    messagew = W_MakeWindow("message", WINSIDE, WINSIDE + BORDER + MESSAGESIZE,
		 WINSIDE, MESSAGESIZE, baseWin, "xterm", BORDER, foreColor);
    planetw = W_MakeTextWindow("planet", 10, 10, 75, (nplanets + 13) / 2, w, (char *) 0, 2);
    planetw2 = W_MakeTextWindow("planet2", 10, 10, 75, (nplanets + 13) / 2, mapw, (char *) 0, 2);
    rankw = W_MakeTextWindow("rank", 50, 100, 65, nranks2 + 8, w, (char *) 0, 2);
    playerw = W_MakeTextWindow("player", 0, YOFF + WINSIDE + 2 * BORDER + 2 * MESSAGESIZE,
			       83, (nplayers + 14) / 2, NULL, (char *) 0, 2);
    helpWin = W_MakeTextWindow("help", 0, YOFF + WINSIDE + 2 * BORDER + 2 * MESSAGESIZE,
		       160, helpmessages / 4 + 1, NULL, (char *) 0, BORDER);
#ifdef METASERVER
    /*
       metaWin = W_MakeMenu ("MetaServer List", WINSIDE+10, -BORDER+10, 69,
       num_servers + 2, NULL, 2);
    */
#endif				/* METASERVER */
#if 0
    W_SetWindowKeyDownHandler(metaWin, metaaction);
    W_SetWindowButtonHandler(metaWin, metaaction);
#endif				/* 0 */

    initMessageWindows();

    pStats = W_MakeWindow("Network Statistics", 500, 4, pStatsWidth(), pStatsHeight(),
			  NULL, (char *) 0, 1, foreColor);
    udpWin = W_MakeMenu("UDP", WINSIDE + 10, -BORDER + 10, 40, UDP_NUMOPTS,
			NULL, 2);

#ifdef SHORT_PACKETS
    spWin = W_MakeMenu("network", WINSIDE + 10, -BORDER + 10, 40, SPK_NUMFIELDS,
		       NULL, 2);
#endif

#ifdef TOOLS
  toolsWin = W_MakeScrollingWindow("tools", WINSIDE + BORDER, BORDER,
				   80, TOOLSWINLEN, NULL, "xterm", BORDER);
#endif

    motdWin = W_MakeWindow("Motd"
			   ,-BORDER, -BORDER, WINSIDE, WINSIDE, NULL,
			   (char *) 0, BORDER, foreColor);

    for (i = 0; i < 4; i++) {
	teamWin[i] = W_MakeWindow(teaminfo[i].shortname, i * BOXSIDE, 0,
			  BOXSIDE, BOXSIDE, mapw, (char *) 0, 1, foreColor);
    }
    qwin = W_MakeWindow("quit", 4 * BOXSIDE, 0, BOXSIDE, BOXSIDE, mapw,
			"pirate", 1, foreColor);

/*    statwin = W_MakeWindow("stats", 422, 13, 160, 95, NULL, (char*)0,
      5, foreColor);*/
    statwin = W_MakeWindow("stats", 422, 13, 160, 80, NULL,
			   (char *) 0, 5, foreColor);

#define WARHEIGHT 2
#define WARWIDTH 20
#define WARBORDER 2

    war = W_MakeMenu("war", WINSIDE + 10, -BORDER + 10, WARWIDTH, 6, baseWin,
		     WARBORDER);


    getResources(progname);
    savebitmaps();
}

void
mapAll()
{
    initinput();
    W_MapWindow(mapw);
    W_MapWindow(tstatw);
    W_MapWindow(warnw);
    W_MapWindow(messagew);
    W_MapWindow(w);
    W_MapWindow(baseWin);

    /*
       since we aren't mapping windows that have root as parent in
       x11window.c (since that messes up the TransientFor feature) we have to
       map them here. (If already mapped, W_MapWindow returns)
    */

    if (checkMapped("planet"))
	W_MapWindow(planetw);
    if (checkMapped("planet2"))
	W_MapWindow(planetw2);
    if (checkMapped("rank"))
	W_MapWindow(rankw);
    if (checkMapped("help"))
	W_MapWindow(helpWin);
    if (checkMapped("Motd"))
	W_MapWindow(motdWin);
    if (checkMapped("review_all"))
	W_MapWindow(messWin[WALL].window);
    if (checkMapped("review_team"))
	W_MapWindow(messWin[WTEAM].window);
    if (checkMapped("review_your"))
	W_MapWindow(messWin[WINDIV].window);
    if (checkMapped("review_kill"))
	W_MapWindow(messWin[WKILL].window);
    if (checkMapped("review_phaser"))
	W_MapWindow(messWin[WPHASER].window);
    if (booleanDefault("player.mapped", 1))
	W_MapWindow(playerw);
    if (booleanDefault("review.mapped", 1))
	W_MapWindow(messWin[WREVIEW].window);
    if (checkMapped("UDP"))
	udpwindow();

}

static void
savebitmaps()
{
    register int i;
    int     tw, th, mw, mh;

    /* slurp_ship_bitmaps(); */

    clockpic = W_StoreBitmap(clock_width, clock_height, clock_bits,
			     qwin);
    safepic = W_StoreBitmap(safe_width, safe_height, safe_bits,
			    qwin);

#ifdef BEEPLITE
    for (i = 0; i < emph_player_seq_frames; i++) {
	emph_player_seq[emph_player_seq_frames - (i + 1)] =
	    W_StoreBitmap(emph_player_seq_width, emph_player_seq_height,
			  emph_player_seq_bits[i], mapw);
    }

    for (i = 0; i < emph_player_seql_frames; i++) {
	emph_player_seql[emph_player_seql_frames - (i + 1)] =
	    W_StoreBitmap(emph_player_seql_width, emph_player_seql_height,
			  emph_player_seql_bits[i], w);
    }

    for (i = 0; i < emph_planet_seq_frames; i++) {
	emph_planet_seq[emph_planet_seq_frames - (i + 1)] =
	    W_StoreBitmap(emph_planet_seq_width, emph_planet_seq_height,
			  emph_planet_seq_bits[i], mapw);
    }
#endif

    load_default_teamlogos();

    headerA = W_StoreBitmap(headerA_width, headerA_height,
			    headerA_bits, motdWin);
    headerB = W_StoreBitmap(headerB_width, headerB_height,
			    headerB_bits, motdWin);
    headerchanges[0] = W_StoreBitmap(header1_width, header1_height,
				     header1_bits, motdWin);
    headerchanges[1] = W_StoreBitmap(header2_width, header2_height,
				     header2_bits, motdWin);
    headerchanges[2] = W_StoreBitmap(header3_width, header3_height,
				     header3_bits, motdWin);
    headerchanges[3] = W_StoreBitmap(header4_width, header4_height,
				     header4_bits, motdWin);
    for (i = 0; i < HULL_FRAMES; i++)
	hull[i] = W_StoreBitmap(hull_width, hull_height, hull_bits[i], w);

    for (i = 0; i < 5; i++) {
	cloud[i] = W_StoreBitmap(cloud_width, cloud_height, cloud_bits[4 - i], w);
	plasmacloud[i] = W_StoreBitmap(plasmacloud_width,
			    plasmacloud_height, plasmacloud_bits[4 - i], w);
    }
    etorp = W_StoreBitmap(etorp_width, etorp_height, etorp_bits, w);
    mtorp = W_StoreBitmap(mtorp_width, mtorp_height, mtorp_bits, w);
    for (i = 0; i < NDRONEVIEWS; i++) {
	drone_bm[i] = W_StoreBitmap(drone_width, drone_height, drone_bits[i], w);
    }
    eplasmatorp =
	W_StoreBitmap(eplasmatorp_width, eplasmatorp_height, eplasmatorp_bits, w);
    mplasmatorp =
	W_StoreBitmap(mplasmatorp_width, mplasmatorp_height, mplasmatorp_bits, w);
    for (i = 0; i < VIEWS; i++) {
	fighter[i] =
	    W_StoreBitmap(fighter_width, fighter_height, fighter_bits[i], w);
    };
    warpbeacon = W_StoreBitmap(warpbeacon_width, warpbeacon_height, warpbeacon_bits, w);
    wbflash = W_StoreBitmap(warpbeacon_width, warpbeacon_height, warpflash_bits, w);

    tw = planet_width;
    th = planet_height;
    mw = mplanet_width;
    mh = mplanet_height;

    /* tactical screen planet bitmaps for team */

    bplanets[0] = W_StoreBitmap(tw, th, indplanet_bits, w);
    bplanets[1] = W_StoreBitmap(tw, th, fedplanet_bits, w);
    bplanets[2] = W_StoreBitmap(tw, th, romplanet_bits, w);
    bplanets[3] = W_StoreBitmap(tw, th, kliplanet_bits, w);
    bplanets[4] = W_StoreBitmap(tw, th, oriplanet_bits, w);
    bplanets[5] = W_StoreBitmap(tw, th, planet_bits, w);

    /* galactic screen planet bitmaps for team */

    mbplanets[0] = W_StoreBitmap(mw, mh, indmplanet_bits, mapw);
    mbplanets[1] = W_StoreBitmap(mw, mh, fedmplanet_bits, mapw);
    mbplanets[2] = W_StoreBitmap(mw, mh, rommplanet_bits, mapw);
    mbplanets[3] = W_StoreBitmap(mw, mh, klimplanet_bits, mapw);
    mbplanets[4] = W_StoreBitmap(mw, mh, orimplanet_bits, mapw);
    mbplanets[5] = W_StoreBitmap(mw, mh, mplanet_bits, mapw);



    /* tactical screen planet bitmaps for facilities */

    bplanets2[0] = bplanets[0];
    bplanets2[1] = W_StoreBitmap(tw, th, planet001_bits, w);
    bplanets2[2] = W_StoreBitmap(tw, th, planet010_bits, w);
    bplanets2[3] = W_StoreBitmap(tw, th, planet011_bits, w);
    bplanets2[4] = W_StoreBitmap(tw, th, planet100_bits, w);
    bplanets2[5] = W_StoreBitmap(tw, th, planet101_bits, w);
    bplanets2[6] = W_StoreBitmap(tw, th, planet110_bits, w);
    bplanets2[7] = W_StoreBitmap(tw, th, planet111_bits, w);
    bplanets2[8] = W_StoreBitmap(tw, th, planet1010_bits, w);
    bplanets2[9] = W_StoreBitmap(tw, th, planet1011_bits, w);
    bplanets2[10] = bplanets2[8];
    bplanets2[11] = bplanets2[9];
    bplanets2[12] = W_StoreBitmap(tw, th, planet1110_bits, w);
    bplanets2[13] = W_StoreBitmap(tw, th, planet1111_bits, w);
    bplanets2[14] = bplanets2[12];
    bplanets2[15] = bplanets2[13];

    /* galactic screen planet bitmaps for facilities */

    mbplanets2[0] = mbplanets[0];
    mbplanets2[1] = W_StoreBitmap(mw, mh, mplanet001_bits, mapw);
    mbplanets2[2] = W_StoreBitmap(mw, mh, mplanet010_bits, mapw);
    mbplanets2[3] = W_StoreBitmap(mw, mh, mplanet011_bits, mapw);
    mbplanets2[4] = W_StoreBitmap(mw, mh, mplanet100_bits, mapw);
    mbplanets2[5] = W_StoreBitmap(mw, mh, mplanet101_bits, mapw);
    mbplanets2[6] = W_StoreBitmap(mw, mh, mplanet110_bits, mapw);
    mbplanets2[7] = W_StoreBitmap(mw, mh, mplanet111_bits, mapw);
    mbplanets2[8] = W_StoreBitmap(mw, mh, mplanet1010_bits, mapw);
    mbplanets2[9] = W_StoreBitmap(mw, mh, mplanet1011_bits, mapw);
    mbplanets2[10] = mbplanets2[8];
    mbplanets2[11] = mbplanets2[9];
    mbplanets2[12] = W_StoreBitmap(mw, mh, mplanet1110_bits, mapw);
    mbplanets2[13] = W_StoreBitmap(mw, mh, mplanet1111_bits, mapw);
    mbplanets2[14] = mbplanets2[12];
    mbplanets2[15] = mbplanets2[13];

    /* tactical screen planet bitmaps for surface properties */

    bplanetsr[0] = bplanets[0];
    bplanetsr[1] = W_StoreBitmap(tw, th, planetr001_bits, w);
    bplanetsr[2] = W_StoreBitmap(tw, th, planetr010_bits, w);
    bplanetsr[3] = W_StoreBitmap(tw, th, planetr011_bits, w);
    bplanetsr[4] = W_StoreBitmap(tw, th, planetr100_bits, w);
    bplanetsr[5] = W_StoreBitmap(tw, th, planetr101_bits, w);
    bplanetsr[6] = W_StoreBitmap(tw, th, planetr110_bits, w);
    bplanetsr[7] = W_StoreBitmap(tw, th, planetr111_bits, w);

    /* galactic screen planet bitmaps for surface properties */

    mbplanetsr[0] = mbplanets[0];
    mbplanetsr[1] = W_StoreBitmap(mw, mh, mplanetr001_bits, mapw);
    mbplanetsr[2] = W_StoreBitmap(mw, mh, mplanetr010_bits, mapw);
    mbplanetsr[3] = W_StoreBitmap(mw, mh, mplanetr011_bits, mapw);
    mbplanetsr[4] = W_StoreBitmap(mw, mh, mplanetr100_bits, mapw);
    mbplanetsr[5] = W_StoreBitmap(mw, mh, mplanetr101_bits, mapw);
    mbplanetsr[6] = W_StoreBitmap(mw, mh, mplanetr110_bits, mapw);
    mbplanetsr[7] = W_StoreBitmap(mw, mh, mplanetr111_bits, mapw);

    /* tactical screen bitmaps for facilities, MOO-style */

    bplanetsMOO[0] = W_StoreBitmap(tw, th, rmyplanet000_bits, w);
    bplanetsMOO[1] = W_StoreBitmap(tw, th, rmyplanet001_bits, w);
    bplanetsMOO[2] = W_StoreBitmap(tw, th, rmyplanet010_bits, w);
    bplanetsMOO[3] = W_StoreBitmap(tw, th, rmyplanet011_bits, w);
    bplanetsMOO[4] = W_StoreBitmap(tw, th, rmyplanet100_bits, w);
    bplanetsMOO[5] = W_StoreBitmap(tw, th, rmyplanet101_bits, w);
    bplanetsMOO[6] = W_StoreBitmap(tw, th, rmyplanet110_bits, w);
    bplanetsMOO[7] = W_StoreBitmap(tw, th, rmyplanet111_bits, w);
    bplanetsMOO[8] = W_StoreBitmap(tw, th, rmyplanet1010_bits, w);
    bplanetsMOO[9] = W_StoreBitmap(tw, th, rmyplanet1011_bits, w);
    bplanetsMOO[10] = bplanetsMOO[8];
    bplanetsMOO[11] = bplanetsMOO[9];
    bplanetsMOO[12] = W_StoreBitmap(tw, th, rmyplanet1110_bits, w);
    bplanetsMOO[13] = W_StoreBitmap(tw, th, rmyplanet1111_bits, w);
    bplanetsMOO[14] = bplanetsMOO[12];
    bplanetsMOO[15] = bplanetsMOO[13];

    /* galactic screen bitmaps for facilities, MOO-style */

    mbplanetsMOO[0] = W_StoreBitmap(mw, mh, rmymplanet000_bits, mapw);
    mbplanetsMOO[1] = W_StoreBitmap(mw, mh, rmymplanet001_bits, mapw);
    mbplanetsMOO[2] = W_StoreBitmap(mw, mh, rmymplanet010_bits, mapw);
    mbplanetsMOO[3] = W_StoreBitmap(mw, mh, rmymplanet011_bits, mapw);
    mbplanetsMOO[4] = W_StoreBitmap(mw, mh, mplanet100_bits, mapw);
    mbplanetsMOO[5] = W_StoreBitmap(mw, mh, mplanet101_bits, mapw);
    mbplanetsMOO[6] = W_StoreBitmap(mw, mh, mplanet110_bits, mapw);
    mbplanetsMOO[7] = W_StoreBitmap(mw, mh, mplanet111_bits, mapw);
    mbplanetsMOO[8] = W_StoreBitmap(mw, mh, rmymplanet1010_bits, mapw);
    mbplanetsMOO[9] = W_StoreBitmap(mw, mh, rmymplanet1011_bits, mapw);
    mbplanetsMOO[10] = mbplanetsMOO[8];
    mbplanetsMOO[11] = mbplanetsMOO[9];
    mbplanetsMOO[12] = W_StoreBitmap(mw, mh, mplanet1110_bits, mapw);
    mbplanetsMOO[13] = W_StoreBitmap(mw, mh, mplanet1111_bits, mapw);
    mbplanetsMOO[14] = mbplanetsMOO[12];
    mbplanetsMOO[15] = mbplanetsMOO[13];

    for (i = 0; i < NSCOUTAGES; i++)
	mbplanetsA[i] = W_StoreBitmap(mw, mh, age_bits[i], mapw);

    /* star bitmaps */

    for (i = 0; i < STARFRAMES; i++) {
	starBM[i] = W_StoreBitmap(star_width, star_height, star_bitarray[i], w);
    }
    mstarBM = W_StoreBitmap(starm_width, starm_height, starm_bits, mapw);
#ifdef VISIBLE_WORMHOLES
    mholeBM = W_StoreBitmap(holem_width, holem_height, holem_bits, mapw);
#endif /*VISIBLE_WORMHOLES*/
    for (i = 0; i < WORMFRAMES; i++) {
        wormBM[i] = W_StoreBitmap(wormhole_width, wormhole_height,
				  wormhole_bitarray[i], w);
     }

/* set of 16 asteroid pics, and 3 asteroid fluff filler pics */
    asteroidBM[0] = W_StoreBitmap(terrain_width, terrain_height,
				  a0000_bits, w);
    asteroidBM[1] = W_StoreBitmap(terrain_width, terrain_height,
				  a0001_bits, w);
    asteroidBM[2] = W_StoreBitmap(terrain_width, terrain_height,
				  a0010_bits, w);
    asteroidBM[3] = W_StoreBitmap(terrain_width, terrain_height,
				  a0011_bits, w);
    asteroidBM[4] = W_StoreBitmap(terrain_width, terrain_height,
				  a0100_bits, w);
    asteroidBM[5] = W_StoreBitmap(terrain_width, terrain_height,
				  a0101_bits, w);
    asteroidBM[6] = W_StoreBitmap(terrain_width, terrain_height,
				  a0110_bits, w);
    asteroidBM[7] = W_StoreBitmap(terrain_width, terrain_height,
				  a0111_bits, w);
    asteroidBM[8] = W_StoreBitmap(terrain_width, terrain_height,
				  a1000_bits, w);
    asteroidBM[9] = W_StoreBitmap(terrain_width, terrain_height,
				  a1001_bits, w);
    asteroidBM[10] = W_StoreBitmap(terrain_width, terrain_height,
				  a1010_bits, w);
    asteroidBM[11] = W_StoreBitmap(terrain_width, terrain_height,
				  a1011_bits, w);
    asteroidBM[12] = W_StoreBitmap(terrain_width, terrain_height,
				  a1100_bits, w);
    asteroidBM[13] = W_StoreBitmap(terrain_width, terrain_height,
				  a1101_bits, w);
    asteroidBM[14] = W_StoreBitmap(terrain_width, terrain_height,
				  a1110_bits, w);
    asteroidBM[15] = W_StoreBitmap(terrain_width, terrain_height,
				  a1111_bits, w);
    asteroidfluff[0] = W_StoreBitmap(terrain_width, terrain_height,
				     a0_bits, w);
    asteroidfluff[1] = W_StoreBitmap(terrain_width, terrain_height,
				     a1_bits, w);
    asteroidfluff[2] = W_StoreBitmap(terrain_width, terrain_height,
				     a2_bits, w);
    for (i = 0; i < 2; i++) {
	basteroid2[i] = W_StoreBitmap(asteroid_width, asteroid_height, asteroid_bits, w);
	mbasteroid2[i] = W_StoreBitmap(masteroid_width, masteroid_height, masteroid_bits, mapw);
    }
    for (i = 0; i < 6; i++) {
	basteroid[i] = W_StoreBitmap(asteroid_width, asteroid_height, asteroid_bits, w);
	mbasteroid[i] = W_StoreBitmap(masteroid_width, masteroid_height, masteroid_bits, mapw);
    }

    kitchenSink = W_StoreBitmap(sink_width, sink_height, sink_bits, w);

    for (i = 0; i < EX_FRAMES; i++) {
	expview[i] = W_StoreBitmap(ex_width, ex_height, ex_bits[i], w);
    }
    for (i = 0; i < SBEXPVIEWS; i++) {
	sbexpview[i] = W_StoreBitmap(sbexp_width, sbexp_height, sbexp_bits[i], w);
    }

    cloakicon = W_StoreBitmap(cloak_width, cloak_height, cloak_bits, w);
    icon = W_StoreBitmap(icon_width, icon_height, icon_bits, iconWin);
    tractbits = W_StoreBitmap(tract_width, tract_height, tract_bits, w);
    pressbits = W_StoreBitmap(press_width, press_height, press_bits, w);
}

void
get_N_dispatch_outfit_event(team, s_type, lastplayercount)
    int    *team;
    int    *s_type;
    int    *lastplayercount;
{
    W_Event event;
    int     validshipletter = 0;
    static int resetting = 0;
    int     oldresetting;
    int     i;

    oldresetting = resetting;

    W_NextEvent(&event);
    switch ((int) event.type) {
    case W_EV_KEY:
	{
	    struct shiplist *shipscan;
	    validshipletter = 0;
	    shipscan = shiptypes;
	    while (shipscan) {
		if (shipscan->ship->s_letter == event.key) {
		    *s_type = shipscan->ship->s_type;
		    validshipletter = 1;
		    break;
		}
		shipscan = shipscan->next;
	    }
	}

	if (me->p_status == PTQUEUE) {
	    int     i;
	    for (i = 0; i < WNUM; i++) {
		if (event.Window == messWin[i].window) {
		    messageWinEvent(&event);
		    break;
		}
	    }
	    if (i != WNUM)
		break;
	    if (event.Window == messagew ||
		event.Window == tstatw ||
		event.Window == warnw)
		smessage(event.key);
	}
	if (event.Window == motdWin) {
	    motdWinEvent(event.key);
	    break;
	} else if (event.Window == playerw || event.Window == infow) {
	    /* allow 'i' 'I' and '^i' in playerw [BDyess] */
	    playerwEvent(&event);
	    break;
	} else if (event.Window == w || event.Window == mapw) {
	    switch (event.key) {
#ifdef Q_OUTFITTING
	    case 'q':
		*team = number_of_teams;
		me->p_status = PFREE;
		break;
#endif				/* Q_OUTFITTING */
	    case 'R':
		warning("Are you sure you want to reset your stats?");
		resetting = 1;
		break;
	    case 'y':
		if (resetting) {
		    sendResetStatsReq('Y');
		    warning("OK, your stats have been reset.");
		    resetting = 0;
		}
		break;
	    case 'n':
		if (resetting) {
		    warning("I didn't think so.");
		    resetting = 0;
		}
		break;

	    case 'f':		/* Scroll motd forward */
		if (currpage == NULL)
		    currpage = motddata;
		if (currpage == NULL || currpage->next == NULL)
		    break;
		currpage->next->prev = currpage;
		currpage = currpage->next;
		showMotd(w);
		resetting = 0;
		break;
	    case 'b':		/* Scroll motd backward */
		if (currpage == NULL || currpage->prev == NULL)
		    break;
		currpage = currpage->prev;
		showMotd(w);
		resetting = 0;
		break;
		/* ok, let's have some info windows available on the TQ */

	    default:		/* hmm, something that doesn't have to do
				   with the MOTD, maybe it's an info window
				   request */
		switch (doKeymap(&event)) {
		case 'U':	/* U = Rank list */
		    if (W_IsMapped(rankw)) {
			W_UnmapWindow(rankw);
		    } else {
			W_MapWindow(rankw);
		    }
		    break;
		case 'P':	/* P = Planet list */
		    if (W_IsMapped(planetw)) {
			W_UnmapWindow(planetw);
			W_UnmapWindow(planetw2);
		    } else {
			W_MapWindow(planetw);
			W_MapWindow(planetw2);
		    }
		    break;
		case 'h':	/* h = Map help window */
		    if (W_IsMapped(helpWin)) {
			W_UnmapWindow(helpWin);
		    } else {
			W_MapWindow(helpWin);
		    }
		    if (optionWin)
			optionredrawtarget(helpWin);
		    break;
		case 'O':	/* O = options Window */
		    if (optionWin != NULL && W_IsMapped(optionWin))
			optiondone();
		    else
			optionwindow();
		    break;
		case 'w':	/* w = map war stuff */
		    if (W_IsMapped(war))
			W_UnmapWindow(war);
		    else
			warwindow();
		    break;
		case '&':
		    if (defaultsFile) {
			char    buf[150];
			sprintf(buf, "Reading defaults from %s", defaultsFile);
			warning(buf);
			freeDefaults();
			defaultsFile = initDefaults(defaultsFile);
			resetDefaults();
		    } else {
			warning("No defaults file to read from!");
		    }
		}
		break;
	    }

	    break;		/* switch event type */
	}
	if (event.Window == qwin)
	    return;		/* normal keypresses can't make you quit */

	if (event.Window == optionWin) {
	    optionaction(&event);
	    return;
	}
	if (!validshipletter)
	    break;
	/*
	   it wasn't the main window, see if they hit the key in a team
	   window to choose their ship... falling through
	*/
    case W_EV_BUTTON:

	for (i = 0; i < number_of_teams; i++)
	    if (event.Window == teamWin[i]) {
		*team = i;
		break;
	    }
	if (event.Window == qwin) {
	    *team = number_of_teams;
	    me->p_status = PFREE;
	    break;
	}
	/* allow message scrollback [BDyess] */
	for (i = 0; i < WNUM; i++) {
	    if (event.Window == messWin[i].window) {
		messageWinEvent(&event);
		break;
	    }
	}
	/* allow bozo selection in playerw [BDyess] */
	if (event.Window == playerw) {
	    playerwEvent(&event);
	    break;
	} else if (event.Window == war)
	    waraction(&event);
	else if (event.Window == optionWin)
	    optionaction(&event);
	if (*team != -1 && !teamRequest(*team, *s_type)) {
	    *team = -1;
	}
	break;
    case W_EV_EXPOSE:
	for (i = 0; i < number_of_teams; i++)
	    if (event.Window == teamWin[i]) {
		lastplayercount[i] = -1;	/* force update */
		redrawTeam(teamWin[i], i, &lastplayercount[i]);
		break;
	    }
	if (event.Window == qwin)
	    redrawQuit();
	else if (event.Window == w)
	    showMotd(w);
	else if (event.Window == mapw) {
#ifdef COW_HAS_IT_WHY_SHOULDNT_WE
	    if(showMapAtMotd) {
		map();
		redraw_death_messages();
	    } else
#endif
		showValues(mapw);
	} else
	    /* let the normal expose handler figure out who to redraw */
	    dispatch_W_expose_event(&event);
	break;
    }

    if (oldresetting && resetting) {
	resetting = 0;
	warning("Resetting of stats cancelled");
    }
}

void
new_entrywindow(team, s_type)
    int    *team, *s_type;
{
    int     i;
    int     lastplayercount[4];	/* number of players on each team */
    int     okayMask, lastOkayMask;	/* teams you're allowed to choose */
    char    buf[100];

    /* OUTFIT timeout stuff */
    long    startTime = -1;
    long    lasttime = -1;
    int     spareTime = 0;

    if (fastQuit) {
	*team = -1;
	return;
    }
    lastOkayMask = okayMask = tournMask;

#ifdef PACKET_LIGHTS
    /* erase packet lights to make Bob happy [BDyess] */
    light_erase();
#endif				/* PACKET_LIGHTS */

    /*
       map all team selection windows, and stripe out those that are
       unchoosable
    */
    for (i = 0; i < number_of_teams; i++) {
	if (okayMask & (1 << i))
	    W_UnTileWindow(teamWin[i]);
	else
	    W_TileWindow(teamWin[i], stipple);

	W_MapWindow(teamWin[i]);
	lastplayercount[i] = -1;
    }
    W_MapWindow(qwin);

    /* no team selected yet */
    *team = -1;
    /*
       set to team index (0..n-1) to choose a team. set to n if you want to
       quit
    */

    /* I don't know why this restriction is in place - RF */
    if (me->p_whydead != KWINNER && me->p_whydead != KGENOCIDE) {
	showMotd(w);
#ifdef COW_HAS_IT_WHY_SHOULDNT_WE
	if(showMapAtMotd) {
	    map();
	    redraw_death_messages();
	} else
#endif
	    showValues(mapw);
    }
    do {

	/* set team to n if you want to quit */
	while (!W_EventsPending() && (me->p_status == POUTFIT ||
				      me->p_status == PTQUEUE)) {
	    /* no window events, just process socket stuff */
	    fd_set  mask;

#ifdef PACKET_LIGHTS
	    light_erase();
#endif				/* PACKET_LIGHTS */

	    readFromServer();

	    if (me->p_status == POUTFIT || me->p_status == PTQUEUE) {
		/* wait up to a half-second for input from the window system */
		struct timeval tv;

#ifndef AMIGA
		tv.tv_sec = 0;
		tv.tv_usec = 500000;

		FD_ZERO(&mask);
		FD_SET(W_Socket(), &mask);
		select(W_Socket() + 1, &mask, 0, 0, &tv);
#else
		StartTimer(0, 500000);
		while (1) {
#ifdef DNET
		    sigsPending = Wait(W_Socket() | portmask | sockMask | udpSockMask | SIGBREAKF_CTRL_C);
#else
/* something else.... */
#endif
		    if (sigsPending & SIGBREAKF_CTRL_C) {
			printf("Ctrl-c break from entrywindow!\n");
			StopTimer();
			exit(0);
		    }
		    if ((sigsPending & (W_Socket() | sockMask | udpSockMask)) ||
			(CheckIO(&(ior->tr_node))))
			break;
		}		/* timer returns false signals, wish I knew
				   why. :-( */
		StopTimer();
#endif				/* AMIGA */
	    }

#ifdef COW_HAS_IT_WHY_SHOULDNT_WE
	    if(showMapAtMotd) {
		map();
		redraw_death_messages();
	    }
#endif

	    if (me->p_status == PTQUEUE)
		startTime = -1;

	    if (me->p_status == POUTFIT) {
		/* time only elapses in OUTFIT mode */

		if (startTime == -1) {	/* we were on the tqueue */
		    /* I hate this [BDyess] */
#if 1
		    W_Deiconify(baseWin);	/* we changed status.  alert
						   the user */
#endif
		    startTime = time(0);
		    spareTime = 480;	/* Allow them extra time, as long */
		    /* as they are active */
		}
		elapsed = time(0) - startTime;

		if (elapsed > autoQuit) {
		    printf("Auto-Quit.\n");
		    *team = number_of_teams;
		    break;
		}
	    }
	    if (lasttime != time(0)) {
		if (W_IsMapped(playerw))
		    playerlist2();

		if (newMotdStuff) {
		    showMotd(w);
#ifdef COW_HAS_IT_WHY_SHOULDNT_WE
		    if(showMapAtMotd) {
			map();
			redraw_death_messages();
		    } else
#endif
			showValues(mapw);
		}
		if (me->p_status == POUTFIT) {
		    showTimeLeft(elapsed, autoQuit);
		}
		lasttime = time(0);
	    }
	    okayMask = tournMask;

	    /* redraw those windows whose choosable status has changed */
	    for (i = 0; i < number_of_teams; i++) {
		if ((okayMask ^ lastOkayMask) & (1 << i)) {
		    if (okayMask & (1 << i)) {
			W_UnTileWindow(teamWin[i]);
		    } else {
			W_TileWindow(teamWin[i], stipple);
		    }
		    lastplayercount[i] = -1;	/* force update */
		}
		redrawTeam(teamWin[i], i, &lastplayercount[i]);
	    }
	    lastOkayMask = okayMask;
	}

#ifdef RECORDER
	if (playback)  /* silly.  Shouldn't even be mapping team windows. */
	    break;
#endif
	/* they quit or ran out of time */
	if (*team == number_of_teams) {
	    me->p_status = PFREE;	/* exit outer while loop */
	    break;
	}
	/*
	   this makes them eventually run out of time no matter how awake
	   they are.  Only affects the OUTFIT screen.
	*/
	if (me->p_status == POUTFIT && startTime != -1) {
	    if (time(0) - startTime <= spareTime) {
		spareTime -= time(0) - startTime;
		startTime = time(0);
	    } else {
		startTime += spareTime;
		spareTime = 0;
	    }
	}
	if (!W_EventsPending())
	    continue;

	/* ok, there's a window event pending */

	/* thiswill set p_status to PFREE if they decide to quit */
	get_N_dispatch_outfit_event(team, s_type, lastplayercount);

    } while ((me->p_status == POUTFIT ||
	      me->p_status == PTQUEUE)
#ifdef RECORDER
	     && (!pb_update)
#endif
	);

    if (*team >= 0) {
	strcpy(buf, "Welcome aboard ");
	if (paradise)
	    strcat(buf, ranks2[me->p_stats2.st_rank].name);
	else
	    strcat(buf, ranks[me->p_stats.st_rank].name);
	sprintf(buf, "Welcome aboard %s!", get_players_rank_name(me));
	warning(buf);
    }
#ifdef RECORDER
    if (playback) {
	extern int lastTeamReq;
	*team = me->p_teami = lastTeamReq;
    } else
#endif
	/* if they quit or ran out of time */
    if (me->p_status == PFREE)
	*team = -1;
    else if (me->p_status == PALIVE ||
	     me->p_status == POBSERVE)
	if (*team == -1)
	    *team = me->p_teami;
	else
	    me->p_teami = *team;


    for (i = 0; i < number_of_teams; i++)
	W_UnmapWindow(teamWin[i]);
    W_UnmapWindow(qwin);
}

/* Attempt to pick specified team & ship */
static int
teamRequest(team, ship)
    int     team, ship;
{
    int     lastTime;

#ifdef RECORDER
    extern int lastTeamReq;

    if (!playback)
	lastTeamReq = team;
#endif
#ifdef TIMELORD
    if (!allowed_to_keep_playing()) {
	warning("You've played enough for today.  Get back to work!");
	return 0;
    }
#endif
    pickOk = -1;
    sendTeamReq(team, ship);
    lastTime = time(NULL);
    while (pickOk == -1) {
	if (lastTime + 3 < time(NULL)) {
	    sendTeamReq(team, ship);
	    lastTime = time(NULL);
	}
	socketPause(0, 20000);
	readFromServer();
	if (isServerDead()) {
	    printf("Whoops!  We've been ghostbusted!\n");
	    printf("Pray for a miracle!\n");

	    /* UDP fail-safe */
	    commMode = commModeReq = COMM_TCP;
	    commSwitchTimeout = 0;
	    if (udpSock >= 0)
		closeUdpConn();
	    if (udpWin) {
		udprefresh(UDP_CURRENT);
		udprefresh(UDP_STATUS);
	    }
	    connectToServer(nextSocket);
	    printf("Yea!  We've been resurrected!\n");
	    pickOk = 0;
	    break;
	}
#if 0				/* >this< is redundant ;-) */
	if (me->p_status == PALIVE) {	/* well, something happened and we've
					   got a ship! */
	    pickOk = 1;
	    break;
	}
#endif
    }

#if 1				/* this is not redundant? */
    if (pickOk) {
	me->p_status = PALIVE;	/* we got a ship.  We must be alive */
#ifdef TIMER
	timeBank[T_SHIP] = time(NULL);
#endif				/* TIMER */
    }
#endif
    return (pickOk);
}

static int
numShips(owner)
    int     owner;
{
    int     i, num = 0;
    struct player *p;

    for (i = 0, p = players; i < nplayers; i++, p++)
	if ((p->p_status == PALIVE || p->p_status == PTQUEUE)
	    && p->p_teami == owner)
	    num++;
    return (num);
}

#if 0
int
realNumShips(owner)
    int     owner;
{
    int     i, num = 0;
    struct player *p;

    for (i = 0, p = players; i < MAXPLAYER; i++, p++)
	if (p->p_status != PFREE &&
	    p->p_team == owner)
	    num++;
    return (num);
}
#endif

#if 0
int
deadTeam(owner)
    int     owner;
/* The team is dead if it has no planets and cannot coup it's home planet */
{
    int     i, num = 0;
    struct planet *p;

    if (planets[remap[owner] * 10 - 10].pl_couptime == 0)
	return (0);
    for (i = 0, p = planets; i < MAXPLANETS; i++, p++) {
	if (p->pl_owner & owner) {
	    num++;
	}
    }
    if (num != 0)
	return (0);
    return (1);
}
#endif

static int
checkBold(line)
/* Determine if that line should be highlighted on sign-on screen */
/* Which is done when it is the players own score being displayed */
    char   *line;
{
    char   *s, *t;
    int     i;
    int     end = 0;

    if ((int) strlen(line) < 60)
	return (0);
    s = line + 4;
    if (!me)
	return (0);
    t = me->p_name;

    for (i = 0; i < 16; i++) {
	if (!end) {
	    if (*t == '\0')
		end = 1;
	    else if (*t != *s)
		return (0);
	}
	if (end) {
	    if (*s != ' ')
		return (0);
	}
	s++;
	t++;
    }
    return (1);
}

struct list {
    char    bold;
    struct list *next;
    char   *data;
};
static struct list *sysdefptr = NULL;

void
showMotd(win)
    W_Window win;
{
    FILE   *fopen();
    int     i;
    struct list *data;
    int     count;
    int     headernum;

    newMotdStuff = 0;		/* clear the flag */

    if (currpage == NULL)
	currpage = motddata;
    if (currpage == NULL)
	return;
    if (!W_IsMapped(win))
	return;

    headernum = currpage->page % NRHEADERS;
    W_ClearWindow(win);
    W_WriteWinBitmap(win, 0, 0, headerA, foreColor);
    W_WriteWinBitmap(win, headerA_width, 0, headerB, foreColor);
    W_WriteWinBitmap(win, headerA_width, headerB_height, headerchanges[headernum], foreColor);
    if (headernum == 2) {	/* fill in client: */
	/* note: font dependant */
	W_WriteText(win, headerA_width + header3_x_hot, headerB_height + header3_y_hot
		- 7, textColor, CLIENTVERS, strlen(CLIENTVERS), W_BoldFont);
    } else if (headernum == 3) {/* fill in server: */
	;
    }
    if (currpage->first) {
	currpage->first = 0;
	data = currpage->text;
	while (data != NULL) {
	    data->bold = checkBold(data->data);
	    data = data->next;
	}
    }
    data = currpage->text;
    count = LINESPERPAGE;	/* Magical # of lines to display */
    i = headerA_height / (paradise ? 10 : W_Textheight) + 1;
    while (count > 0) {
	if (data == NULL)
	    break;

	if (data->bold) {
	    W_WriteText(win, 20, i * (paradise ? 10 : W_Textheight), textColor, data->data,
			strlen(data->data), W_BoldFont);
	} else {
	    W_WriteText(win, 20, i * (paradise ? 10 : W_Textheight), textColor, data->data,
			strlen(data->data), W_RegularFont);
	}
	data = data->next;
	count--;
	i++;
    }
    if (win == w) {
	count = W_StringWidth(blk_refitstring, W_RegularFont) / 2;
	W_WriteText(mapw, 250 - count, 480, textColor, blk_refitstring,
		    strlen(blk_refitstring), W_RegularFont);
    }
    showPics(win);
/*    showValues(mapw); Should be handled in event loop now RF */
}

static void
showPics(win)
    W_Window win;
{
    struct piclist *temp;
    int     page;

    page = currpage->page;
    temp = motdPics;

    while (temp != NULL) {
	if (page == temp->page) {
	    if (temp->thepic)
		W_WriteWinBitmap(win, temp->x, temp->y, temp->thepic, foreColor);
	    else {
		W_MakeLine(win, temp->x, temp->y,
			   temp->x + temp->width - 1, temp->y + temp->height - 1, W_Grey);
		W_MakeLine(win, temp->x, temp->y + temp->height - 1,
			   temp->x + temp->width - 1, temp->y, W_Grey);
		W_MakeLine(win, temp->x, temp->y,
			   temp->x + temp->width - 1, temp->y, W_Grey);
		W_MakeLine(win, temp->x, temp->y,
			   temp->x, temp->y + temp->height - 1, W_Grey);
		W_MakeLine(win, temp->x, temp->y + temp->height - 1,
			   temp->x + temp->width - 1, temp->y + temp->height - 1, W_Grey);
		W_MakeLine(win, temp->x + temp->width - 1, temp->y + temp->height - 1,
			   temp->x + temp->width - 1, temp->y, W_Grey);
	    }
	}
	temp = temp->next;
    }
}

/*
 * ATM: show the current values of the .sysdef parameters.
 */
void
showValues(win)
    W_Window win;
{
    int     i;
    struct list *data;

    /* try to find the start of the info */
    data = sysdefptr;

    for (i = 12; i < 50; i++) {
	if (data == NULL)
	    break;
	if (data->data[0] == '+')	/* quick boldface hack */
	    W_WriteText(win, 20, i * W_Textheight, textColor, data->data + 1,
			strlen(data->data) - 1, W_BoldFont);
	else
	    W_WriteText(win, 20, i * W_Textheight, textColor, data->data,
			strlen(data->data), W_RegularFont);
	data = data->next;
    }
}

#define	BETWEEN_PAGES	0
#define	IN_PAGE		1
#define	IN_SYSDEF	3

static int motdlinestate = BETWEEN_PAGES;
static int pagecount = 0;
static struct list **temp = NULL;
static struct page **ptemp = NULL;
static int linecount = 0;
static struct piclist **motd_buftail = &motdPics;

void
erase_motd()
{
    struct piclist *temppic;
    struct page *temppage;
    struct list *templist;

    while (motdPics) {
	temppic = motdPics;
	motdPics = temppic->next;
	if (temppic->thepic)
	    W_FreeBitmap(temppic->thepic);
	free(temppic);
    }
    motd_buftail = &motdPics;

    while (motddata) {
	temppage = motddata;
	motddata = temppage->next;
	while (temppage->text) {
	    templist = temppage->text;
	    temppage->text = templist->next;
	    free(templist->data);
	    free(templist);
	}
	free(temppage);
    }
    motdlinestate = BETWEEN_PAGES;
    currpage = 0;
    pagecount = 0;
    temp = 0;
    ptemp = 0;
    linecount = 0;

    while (sysdefptr) {
	templist = sysdefptr;
	sysdefptr = templist->next;
	free(templist->data);
	free(templist);
    }
}

void
newMotdPic(x, y, width, height, bits, page)
    int     x, y, page, width, height;
    char   *bits;
{
    struct piclist *temp;

    {
	struct motd_pic_spacket dummy;
	if ((width + 7) / 8 * height > sizeof(dummy.bits) && bits) {
	    fprintf(stderr, "MOTD picture from server is too big!  %dx%d couldn't possibly fit in the %d data bytes of the packet\n",
		    width, height, (int) sizeof(dummy.bits));
	    return;
	}
    }
    if ((currpage && page == currpage->page) || page == 0)
	newMotdStuff = 1;	/* set flag for event loop */

    temp = (*motd_buftail) = (struct piclist *) malloc(sizeof(struct piclist));
    temp->next = NULL;
    temp->x = x;
    temp->y = y;
    temp->width = width;
    temp->height = height;
    temp->thepic = bits ? W_StoreBitmap(width, height, bits, motdWin) : 0;
    temp->page = page;
    motd_buftail = &(temp->next);
}

void
newMotdLine(line)
    char   *line;
{

    /*
       Do this first.  That way we don't even have to worry about it at all.
    */

    if (strncmp("BLK: ", line, 5) == 0) {
	blk_parsemotd(line);
	return;
    }
    if (strncmp("\t@@@", line, 4) == 0 && motdlinestate != IN_SYSDEF) {
	motdlinestate = IN_SYSDEF;
	temp = &sysdefptr;
    }
    if (strncmp("\t@@b", line, 4) == 0 && motdlinestate == IN_PAGE)
	motdlinestate = BETWEEN_PAGES;

    if (motdlinestate == BETWEEN_PAGES ||
	(motdlinestate == IN_PAGE && linecount >= LINESPERPAGE)) {
	if (motddata == NULL)
	    ptemp = &motddata;
	(*ptemp) = (struct page *) malloc(sizeof(struct page));
	(*ptemp)->next = NULL;
	(*ptemp)->first = 1;
	(*ptemp)->prev = NULL;
	(*ptemp)->page = pagecount++;
	temp = &((*ptemp)->text);
	(*ptemp)->text = NULL;
	ptemp = &((*ptemp)->next);
	motdlinestate = IN_PAGE;
	linecount = 0;
    }
    if (strncmp("\t@@", line, 3) == 0)
	return;

    if (!currpage ||
	(pagecount - 1) == currpage->page ||
	motdlinestate == IN_SYSDEF)
	newMotdStuff = 1;	/* set flag for event loop */

    (*temp) = (struct list *) malloc(sizeof(struct list));
    (*temp)->next = NULL;
    (*temp)->data = (char *) malloc(strlen(line) + 1);
    strcpy((*temp)->data, line);
    temp = &((*temp)->next);

    if (motdlinestate == IN_PAGE)
	linecount++;
}

/*ARGSUSED*/
static void
getResources(prog)
    char   *prog;
{
    getColorDefs();
    getTiles();
}

static void
getTiles()
{
    stipple = W_StoreBitmap(stipple_width, stipple_height, stipple_bits, w);
}

static void
redrawTeam(win, teamNo, lastnum)
    W_Window win;
    int     teamNo;
    int    *lastnum;
{
    char    buf[BUFSIZ];
    int     num = numShips(teamNo);

    /* Only redraw if number of players has changed */
    if (*lastnum == num)
	return;

    drawIcon();

    W_ClearWindow(win);
    W_WriteBitmap(0, 0, teaminfo[teamNo].shield_logo, shipCol[teamNo + 1]);

    (void) sprintf(buf, "%d", num);
    W_MaskText(win, 5, 46, shipCol[teamNo + 1], buf, strlen(buf),
	       W_BigFont);
    *lastnum = num;
}

static void
redrawQuit()
{
    /* W_WriteText(qwin, 5, 5, textColor, "Quit xtrek", 10, W_RegularFont); */
    if (me->p_status == PTQUEUE) {
	W_ClearArea(qwin, 0, 0, BOXSIDE, BOXSIDE);
	W_WriteBitmap(0, 0, safepic, foreColor);
    }
}

void
drawIcon()
{
    if (!iconified) {
	me_messages = 0;
	team_messages = 0;
	all_messages = 0;
    }
#ifdef AMIGA
    /*
       not sure this isn't appropriate for X as well.  This is called from
       redrawTeam(),  so iconified is set, and then all my personal messages
       beep...iconified or not.
    */
    if (W_IsMapped(iconWin))
#endif
	iconified = 1;
    if (!infoIcon) {
	W_WriteBitmap(0, 0, icon, W_White);
    } else {			/* code for information icon 1/15 [BDyess] */
	int     side, bottom, top, digits, x, i;
	char    buf[50];

	W_ClearWindow(iconWin);
	side = icon_width / number_of_teams;
	bottom = 0 + side;
	top = 0;
	W_MakeLine(iconWin, 0, bottom, icon_width, bottom, W_White);
	for (i = 0; i <= number_of_teams; i++) {	/* draw the vertical
							   lines */
	    x = i * side;
	    x = (x > icon_width) ? icon_width : x;
	    W_MakeLine(iconWin, x, bottom, x, top, W_White);
	}
	for (i = 0; i < number_of_teams; i++) {
	    sprintf(buf, "%d", numShips(i));
	    digits = strlen(buf);
	    W_WriteText(iconWin, i * side + side / 2 - digits * W_Textwidth / 2,
			bottom - side / 2 - W_Textheight / 2,
			shipCol[i + 1], buf, digits, W_RegularFont);
	}
	if (me->p_status == PALIVE) {
#define TOP icon_height-10
	    if (me->p_flags & PFGREEN)
		W_FillArea(iconWin, 0, TOP, icon_width,
			   icon_height, W_Green);
	    else if (me->p_flags & PFYELLOW)
		W_FillArea(iconWin, 0, TOP,
			   icon_width, icon_height, W_Yellow);
	    else if (me->p_flags & PFRED)
		W_FillArea(iconWin, 0, TOP,
			   icon_width, icon_height, W_Red);
	}
	if (me_messages) {
	    sprintf(buf, "Personal: %d", me_messages);
	    W_WriteText(iconWin, 1, bottom + 2, W_White, buf, strlen(buf),
			W_RegularFont);
	}
	if (team_messages) {
	    sprintf(buf, "Team:     %d", team_messages);
	    W_WriteText(iconWin, 1, bottom + 2 + W_Textheight, W_White, buf,
			strlen(buf), W_RegularFont);
	}
	if (all_messages) {
	    sprintf(buf, "All:      %d", all_messages);
	    W_WriteText(iconWin, 1, bottom + 2 + 2 * W_Textheight, W_White, buf,
			strlen(buf), W_RegularFont);
	}
	if (me->p_status == POUTFIT) {
	    sprintf(buf, "Time left: %d", autoQuit - elapsed);
	    W_WriteText(iconWin, 1, bottom + 2 + W_Textheight, W_White, buf,
			strlen(buf), W_RegularFont);
	}
    }
}

#define CLOCK_WID	BOXSIDE
#define CLOCK_HEI	BOXSIDE
#define CLOCK_BDR	0

#ifndef PI
#define PI		3.141592654
#endif				/* PI */

static void
showTimeLeft(time, max)
    int     time, max;
{
    char    buf[BUFSIZ];
    int     cx, cy, ex, ey, tx, ty;

    if ((max - time) < 10 && time & 1) {
	W_Beep();
	W_Deiconify(baseWin);
    }
    if (iconified)
	drawIcon();
    /* XFIX */
    W_ClearArea(qwin, 0, 0, BOXSIDE, BOXSIDE);

    W_WriteBitmap(0, 0, clockpic, foreColor);

    cx = BOXSIDE / 2;
    cy = BOXSIDE / 2 - 6;
    ex = cx - 35 * Sin[((255 * time) / max + 64) % 256];
    ey = cy - 35 * Cos[((255 * time) / max + 64) % 256];
    W_MakeLine(qwin, cx, cy, ex, ey, foreColor);

    sprintf(buf, "%d", max - time);
    cy = BOXSIDE / 2 - 1;
    tx = cx - W_StringWidth(buf, W_RegularFont) / 2.0;
    ty = cy - W_Textheight;
    W_WriteText(qwin, tx, ty, textColor, buf, strlen(buf), W_RegularFont);
}


void
do_refit(type)
    int     type;
{
    sendRefitReq(type);
    localflags &= ~PFREFIT;
}