|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 6803 (0x1a93) Types: TextFile Names: »inform.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xtrek/inform.c«
static char sccsid[] = "@(#)inform.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 /* Display information about the nearest objext to mouse */ /* ** When the player asks for info, this routine finds the object ** nearest the mouse, either player or planet, and pop up a window ** with the desired information in it. ** ** We intentionally provide less information than is actually ** available. Keeps the fog of war up. ** ** There is a different sized window for each type player/planet ** and we take care to keep it from extending beyond the main ** window boundaries. */ inform(p, ww, x, y) register struct player *p; Window ww; int x, y; { char buf[BUFSIZ*2]; int line = 0; register struct player *j; register struct planet *k; int mx, my; int rx, ry; int maskr; double dist; Window subw; struct obtype *gettarget(), *target; XWindowAttributes wa; p->infomapped = 1; target = gettarget(p, ww, x, y, TARG_PLAYER|TARG_PLANET|TARG_MYSELF); XGetWindowAttributes(p->display, ww, &wa); XQueryPointer(p->display, ww, &subw, &subw, &rx, &ry, &mx, &my, &maskr); /* XQueryMouse(ww, &mx, &my, &subw);*/ if (target->o_type == PLAYERTYPE) { /* Too close to the edge? */ if (mx + 23 * fontWidth(p->dfont) + 2 > wa.width) mx = wa.width - 23 * fontWidth(p->dfont) - 2; if (my + 7 * fontHeight(p->dfont) + 2 > wa.height) my = wa.height - 7 * fontHeight(p->dfont) - 2; p->infow = XCreateWindow(p->display, ww, mx, my, (unsigned) 23 * fontWidth(p->dfont), (unsigned) 7 * fontHeight(p->dfont), 2, DefaultDepth(p->display, p->screen), InputOutput, (Visual *)CopyFromParent, 0L, (XSetWindowAttributes *)0); XSetWindowBackground(p->display, p->infow, p->backColor); XClearWindow(p->display, p->infow); XMapWindow(p->display, p->infow); j = &players[target->o_num]; dist = hypot((double) (p->p_x - j->p_x), (double) (p->p_y - j->p_y)); (void) sprintf(buf, "%s (%c%1x):", j->p_name, teamlet[j->p_team], j->p_no); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "Login %-s", j->p_login); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "Display %-s", j->p_monitor); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "Speed %-d", j->p_speed); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); /* Too much information. Let 'em wonder NOTE: Give info to team members (void) sprintf(buf, "Damage %-d", j->p_damage); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "Shields %-d", j->p_shield); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); */ (void) sprintf(buf, "kills %-4.2f", j->p_kills); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "dist %-d", (int) dist); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); if (j->p_swar & p->p_team) XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, "WAR", 3); else if (j->p_hostile & p->p_team) XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, "HOSTILE", 7); else XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, "PEACEFUL", 8); } else { /* Planet */ /* Too close to the edge? */ if (mx + 20 * fontWidth(p->dfont) + 2 > wa.width) mx = wa.width - 20 * fontWidth(p->dfont) - 2; if (my + 3 * fontHeight(p->dfont) + 2 > wa.height) my = wa.height - 3 * fontHeight(p->dfont) - 2; p->infow = XCreateWindow(p->display, ww, mx, my, (unsigned) 20 * fontWidth(p->dfont), (unsigned) 3 * fontHeight(p->dfont), 2, DefaultDepth(p->display, p->screen), InputOutput, (Visual *)CopyFromParent, 0L, (XSetWindowAttributes *)0); XSetWindowBackground(p->display, p->infow, p->backColor); XClearWindow(p->display, p->infow); XMapWindow(p->display, p->infow); k = &planets[target->o_num]; dist = hypot((double) (p->p_x - k->pl_x), (double) (p->p_y - k->pl_y)); if (k->pl_info & p->p_team) { (void) sprintf(buf, "%s (%c)", k->pl_name, teamlet[k->pl_owner]); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "Armies %d", k->pl_armies); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "%s %s %c%c%c%c", (k->pl_flags & PLREPAIR ? "REPAIR" : " "), (k->pl_flags & PLFUEL ? "FUEL" : " "), (k->pl_info & FED ? 'F' : ' '), (k->pl_info & ROM ? 'R' : ' '), (k->pl_info & KLI ? 'K' : ' '), (k->pl_info & ORI ? 'O' : ' ')); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); } else { (void) sprintf(buf, "%s", k->pl_name); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); (void) sprintf(buf, "No other info"); XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont), p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf)); } XFlush(p->display); } } destroyInfo(p) register struct player *p; { XDestroyWindow(p->display, p->infow); p->infomapped = 0; p->redrawall = 1; }