DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T w

⟦6347f9658⟧ TextFile

    Length: 4996 (0x1384)
    Types: TextFile
    Names: »war.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/X/Xtrek/war.c« 

TextFile

static char sccsid[] = "@(#)war.c	1.1";
/*

	Copyright (c) 1986 	Chris Guthrie

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation.  No representations are made about the
suitability of this software for any purpose.  It is
provided "as is" without express or implied warranty.

*/

#include <X11/Xlib.h>
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include "defs.h"
#include "data.h"

#define WINSIDE 500

/* Set up the war window and map it */
static char *feds = "FED - ";
static char *roms = "ROM - ";
static char *klis = "KLI - ";
static char *oris = "ORI - ";
static char *gos = "  Re-program";
static char *exs = "  Exit - no change";
static char *peaces = "Peace";
static char *hostiles = "Hostile";
static char *wars = "War";

warwindow(p)
register struct player	*p;
{
    XMapWindow(p->display, p->war);
    p->newhostile = p->p_hostile;
    p->reprogram = 0;
    warrefresh(p);
}

warrefresh(p)
register struct player	*p;
{
    fillwin(p, p->warf, feds, p->newhostile, p->p_swar, FED);
    fillwin(p, p->warr, roms, p->newhostile, p->p_swar, ROM);
    fillwin(p, p->wark, klis, p->newhostile, p->p_swar, KLI);
    fillwin(p, p->waro, oris, p->newhostile, p->p_swar, ORI);
    XDrawImageString(p->display, p->wargo, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, gos, strlen(gos));
    XDrawImageString(p->display, p->warno, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, exs, strlen(exs));
}

fillwin(p, win, string, hostile, warbits, team)
register struct player	*p;
Window win;
char *string;
int hostile, warbits;
int team;
{
    char buf[80];

	XFillRectangle(p->display, win, p->cleargc, 0, fontHeight(p->dfont) / 2, fontWidth(p->dfont) * 20,
	fontHeight(p->dfont));
/*    XPixSet(win, 0, fontHeight(dfont) / 2, fontWidth(dfont) * 20,
	fontHeight(dfont), backColor); */
    if (team & warbits) {
	(void) sprintf(buf, "  %s%s", string, wars);
	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
    }
    else if (team & hostile) {
	(void) sprintf(buf, "  %s%s", string, hostiles);
	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
    }
    else {
	(void) sprintf(buf, "  %s%s", string, peaces);
	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
    }
}

waraction(p, data)
register struct player	*p;
XKeyEvent *data;
{
    int changes;

#ifdef notdef
    if ((data->window != warno) && (watch)) {
	warning(p, "can't modify war settings from watch");
	return;
    }
#endif
    if (data->window == p->warf) {
	if (p->p_swar & FED) {
	    warning(p, "You are already at war with the Federation");
	    XBell(p->display, 0);
	}
	else {
	    p->newhostile ^= FED;
	}
    }
    if (data->window == p->warr) {
	if (p->p_swar & ROM) {
	    warning(p, "You are already at war with the Romulans");
	    XBell(p->display, 0);
	}
	else {
	    p->newhostile ^= ROM;
	}
    }
    if (data->window == p->wark) {
	if (p->p_swar & KLI) {
	    warning(p, "You are already at war with the Klingons");
	    XBell(p->display, 0);
	}
	else {
	    p->newhostile ^= KLI;
	}
    }
    if (data->window == p->waro) {
	if (p->p_swar & ORI) {
	    warning(p, "You are already at war with the Orions");
	    XBell(p->display, 0);
	}
	else {
	    p->newhostile ^= ORI;
	}
    }
    warrefresh(p);

    if (data->window == p->wargo) {
	changes = p->p_hostile ^ p->newhostile;
	if (changes & FED) {
	    sendwarn(p, "Federation", p->newhostile & FED, FED);
	}
	if (changes & ROM) {
	    sendwarn(p, "Romulans", p->newhostile & ROM, ROM);
	}
	if (changes & KLI) {
	    sendwarn(p, "Klingons", p->newhostile & KLI, KLI);
	}
	if (changes & ORI) {
	    sendwarn(p, "Orions", p->newhostile & ORI, ORI);
	}
	p->p_hostile = p->newhostile;
	if (p->reprogram) {
	    p->delay = p->p_updates + 100;
	    p->p_flags |= PFWAR;	/* stop copilots, mostly */
	    warning(p, "Pausing ten seconds to re-program battle computers.");
	}
	XUnmapWindow(p->display, p->war);
	return;
    }

    if (data->window == p->warno) {
	XUnmapWindow(p->display, p->war);
	return;
    }
}

sendwarn(p, string, atwar, team)
register struct player	*p;
char *string;
int atwar;
int team;
{
    char buf[BUFSIZ];
    char addrbuf[10];

    if (atwar) {
	(void) sprintf(buf, "%s (%c%x) declaring war on the %s",
	    p->p_name,
	    teamlet[p->p_team],
	    p->p_no,
	    string);
	p->reprogram = 1;
    }
    else {
	(void) sprintf(buf, "%s (%c%x) declaring peace with the %s",
	    p->p_name,
	    teamlet[p->p_team],
	    p->p_no,
	    string);
    }

    (void) sprintf(addrbuf, " %c%x->%-3s",
	teamlet[p->p_team],
	p->p_no,
	teamshort[team]);
    pmessage(buf, team, MTEAM, addrbuf);
}