home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / sources / games / 457 < prev    next >
Encoding:
Text File  |  1992-11-20  |  14.4 KB  |  507 lines

  1. Newsgroups: vmsnet.sources.games
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!usenet.coe.montana.edu!news.u.washington.edu!raven.alaska.edu!acad2.alaska.edu!asdmf
  3. From: asdmf@acad2.alaska.edu
  4. Subject: Vmsnetrek 45/47
  5. Message-ID: <1992Nov20.210948.1@acad2.alaska.edu>
  6. Lines: 495
  7. Sender: news@raven.alaska.edu (USENET News System)
  8. Nntp-Posting-Host: acad2.alaska.edu
  9. Organization: University of Alaska
  10. Date: Sat, 21 Nov 1992 01:09:48 GMT
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 45 -+-+-+-+-+-+-+-+
  13. X`009W_WriteText(war, 0, menunum, gColor, buf, strlen(buf), 0);
  14. X    `125
  15. X`125
  16. X
  17. Xwaraction(data)
  18. XW_Event *data;
  19. X`123
  20. X    int enemyteam;
  21. X
  22. X    if (data->y == 4) `123
  23. X`009W_UnmapWindow(war);
  24. X`009sendWarReq(newhostile);
  25. X`009return;
  26. X    `125
  27. X
  28. X    if (data->y == 5) `123
  29. X`009W_UnmapWindow(war);
  30. X`009return;
  31. X    `125
  32. X    if (data->y == 0) enemyteam=FED;
  33. X    if (data->y == 1) enemyteam=ROM;
  34. X    if (data->y == 2) enemyteam=KLI;
  35. X    if (data->y == 3) enemyteam=ORI;
  36. X
  37. X    if (me->p_swar & enemyteam) `123
  38. X`009warning("You are already at war!");
  39. X`009W_Beep();
  40. X    `125 else `123
  41. X`009if (me->p_team == enemyteam) `123
  42. X`009    warning("It would never work ... your crew would have you in the bri
  43. Vg in no time.");
  44. X`009`125 else `123
  45. X`009    newhostile `094= enemyteam;
  46. X`009`125
  47. X    `125
  48. X    warrefresh();
  49. X`125
  50. X
  51. $ CALL UNPACK WAR.C;1 1529531742
  52. $ create/nolog 'f'
  53. X/*
  54. X * warning.c
  55. X */
  56. X#include "copyright.h"
  57. X
  58. X#include <stdio.h>
  59. X#include <math.h>
  60. X#include <signal.h>
  61. X#include "Wlib.h"
  62. X#include "defs.h"
  63. X#include "struct.h"
  64. X#include "data.h"
  65. X
  66. X/*
  67. X** The warning in text will be printed in the warning window.
  68. X** The message will last WARNTIME/10 seconds unless another message
  69. X** comes through and overwrites it.
  70. X*/
  71. Xwarning(text)
  72. Xchar *text;
  73. X`123
  74. X    warntimer = udcounter + WARNTIME;  /* set the line to be cleared */
  75. X
  76. X    if (warncount > 0) `123
  77. X`009W_ClearArea(warnw, 5,5, W_Textwidth*warncount, W_Textheight,backColor);
  78. X    `125
  79. X    warncount = strlen(text);
  80. X    W_WriteText(warnw, 5, 5, textColor, text, warncount, W_RegularFont);
  81. X`125
  82. $ CALL UNPACK WARNING.C;1 773588199
  83. $ create/nolog 'f'
  84. X/* Wlib.h
  85. X *
  86. X * Include file for the Windowing interface.
  87. X *
  88. X * Kevin P. Smith  6/11/89
  89. X *`032
  90. X * The deal is this:
  91. X *   Call W_Initialize(), and then you may call any of the listed fuinctions
  92. V.
  93. X *   Also, externals you are allowed to pass or use include W_BigFont,
  94. X *     W_RegularFont, W_UnderlineFont, W_HighlightFont, W_White, W_Black,
  95. X *     W_Red, W_Green, W_Yellow, W_Cyan, W_Grey, W_Textwidth, and W_Textheig
  96. Vht.
  97. X */
  98. X#include "copyright2.h"
  99. X
  100. Xtypedef char *W_Window;
  101. Xtypedef char *W_Icon;
  102. Xtypedef char *W_Font;
  103. Xtypedef int W_Color;
  104. X
  105. Xextern W_Font W_BigFont, W_RegularFont, W_UnderlineFont, W_HighlightFont;
  106. Xextern W_Color W_White, W_Black, W_Red, W_Green, W_Yellow, W_Cyan, W_Grey;
  107. Xextern int W_Textwidth, W_Textheight;
  108. Xextern int W_FastClear;
  109. X
  110. Xextern void W_Initialize(/* display */);
  111. Xextern W_Window W_MakeWindow(/* name, x, y, width, height, parent, border, c
  112. Volor */);
  113. Xextern W_Icon W_StoreBitmap(/* width, height, data, window */);
  114. Xextern W_Window W_MakeTextWindow(/* name, x, y, width, height, parent, borde
  115. Vr */);
  116. Xextern W_Window W_MakeScrollingWindow(/* name, x, y, width, height, parent,b
  117. Vorder */);
  118. Xextern W_Window W_MakeMenu(/* name, x, y, width, height, parent, border */);
  119. Xextern void W_WriteText(/* window, x, y, color, str, length, font */);
  120. Xextern void W_MaskText(/* window, x, y, color, str, length, font */);
  121. Xextern void W_WriteBitmap(/* x, y, icon, color */);
  122. Xextern void W_ClearArea(/* window, x, y, width, height, color */);
  123. Xextern void W_MakeLine(/* window, x0, y0, x1, y1, color */);
  124. Xextern void W_MapWindow(/* window */);
  125. Xextern void W_UnmapWindow(/* window */);
  126. Xextern int W_EventsPending(/* void */);
  127. Xextern void W_NextEvent(/* W_Event *event */);
  128. Xextern void W_TileWindow(/* window, bitmap */);
  129. Xextern void W_UnTileWindow(/* window */);
  130. Xextern void W_ChangeBorder(/* window, color */);
  131. Xextern void W_DefineCursor(/* window, width, height, data, mask, xhot, yhot
  132. V */);
  133. Xextern int W_IsMapped(/* window */);
  134. Xextern void W_Beep(/* void */);
  135. Xextern void W_DestroyWindow(/* window */);
  136. Xextern int W_WindowWidth(/* window */);
  137. Xextern int W_WindowHeight(/* window */);
  138. Xextern int W_Socket(/* void */);
  139. Xextern void W_ClearWindow(/* window */);
  140. Xextern void W_SetIconWindow(/* mainwindow, iconwindow */);
  141. X
  142. X#define W_EV_EXPOSE`0091
  143. X#define W_EV_KEY`0092
  144. X#define W_EV_BUTTON`0093
  145. X
  146. X#define W_LBUTTON`0091
  147. X#define W_MBUTTON`0092
  148. X#define W_RBUTTON`0093
  149. X
  150. Xtypedef struct event `123
  151. X`009int`009type;
  152. X`009W_Window Window;
  153. X`009int`009key;
  154. X`009int`009x,y;
  155. X`125 W_Event;
  156. X
  157. X#define W_BoldFont W_HighlightFont
  158. $ CALL UNPACK WLIB.H;1 1903131216
  159. $ create/nolog 'f'
  160. X/* x11window.c
  161. X *
  162. X * Kevin P. Smith  6/11/89
  163. X */
  164. X#include "copyright2.h"
  165. X#include <stdio.h>
  166. X#include <assert.h>
  167. X#include "Wlib.h"
  168. X#include <x11/xlib.h>
  169. X#include <x11/xutil.h>
  170. X
  171. X#define FONTS 4
  172. X#define BITGC 4
  173. X
  174. X#define WHITE   0
  175. X#define BLACK   1
  176. X#define RED     2
  177. X#define GREEN   3
  178. X#define YELLOW  4
  179. X#define CYAN    5
  180. X#define GREY`0096
  181. X
  182. Xstatic int zero=0;
  183. Xstatic int one=1;
  184. Xstatic int two=2;
  185. Xstatic int three=3;
  186. Xint W_FastClear=0;
  187. X
  188. XDisplay *W_Display;
  189. XWindow W_Root;
  190. XColormap W_Colormap;
  191. Xint W_Screen;
  192. XW_Font W_BigFont= (W_Font) &zero, W_RegularFont= (W_Font) &one;
  193. XW_Font W_HighlightFont= (W_Font) &two, W_UnderlineFont= (W_Font) &three;
  194. XW_Color W_White=WHITE, W_Black=BLACK, W_Red=RED, W_Green=GREEN;
  195. XW_Color W_Yellow=YELLOW, W_Cyan=CYAN, W_Grey=GREY;
  196. Xint W_Textwidth, W_Textheight;
  197. Xchar *getdefault();
  198. Xchar *strdup();
  199. X
  200. Xstatic XClassHint class_hint = `123
  201. X`009"netrek", "Netrek",
  202. X`125;
  203. X
  204. Xstatic XWMHints wm_hint = `123
  205. X    InputHint, 1,`032
  206. X`125;   `032
  207. X
  208. Xstatic W_Event W_myevent;
  209. Xstatic int W_isEvent=0;
  210. X
  211. Xstruct fontInfo `123
  212. X    int baseline;
  213. X`125;
  214. X
  215. Xstruct colors `123
  216. X    char *name;
  217. X    GC contexts`091FONTS+1`093;
  218. X    Pixmap pixmap;
  219. X    int pixelValue;
  220. X`125;
  221. X
  222. Xstruct icon `123
  223. X    Window window;
  224. X    Pixmap bitmap;
  225. X    int width, height;
  226. X    Pixmap pixmap;
  227. X`125;
  228. X
  229. X#define WIN_GRAPH`0091
  230. X#define WIN_TEXT`0092
  231. X#define WIN_MENU`0093
  232. X#define WIN_SCROLL`0094
  233. X
  234. Xstruct window `123
  235. X    Window window;
  236. X    int type;
  237. X    char *data;
  238. X    int mapped;
  239. X    int width,height;
  240. X    char *name;
  241. X`125;
  242. X
  243. Xstruct stringList `123
  244. X    char *string;
  245. X    W_Color color;
  246. X    struct stringList *next;
  247. X`125;
  248. X
  249. Xstruct menuItem `123
  250. X    char *string;
  251. X    W_Color color;
  252. X`125;
  253. X
  254. Xstruct colors colortable`091`093 = `123
  255. X    `123 "white" `009   `125,
  256. X    `123 "black"`009   `125,
  257. X    `123 "red" `009   `125,
  258. X    `123 "green" `009   `125,
  259. X    `123 "yellow" `009   `125,
  260. X    `123 "cyan" `009   `125,
  261. X    `123 "light grey" `125
  262. X`125;
  263. X
  264. Xstruct windowlist `123
  265. X    struct window *window;
  266. X    struct windowlist *next;
  267. X`125;
  268. X
  269. X#define HASHSIZE 29
  270. X#define hash(x) (((int) (x)) % HASHSIZE)
  271. X
  272. Xstruct windowlist *hashtable`091HASHSIZE`093;
  273. Xstruct fontInfo fonts`091FONTS`093;
  274. X
  275. Xstruct window *newWindow();
  276. Xstruct window *findWindow();
  277. Xchar *malloc();
  278. Xshort *x11tox10bits();
  279. X
  280. Xstruct window myroot;
  281. X
  282. X#define NCOLORS (sizeof(colortable)/sizeof(colortable`0910`093))
  283. X#define W_Void2Window(win) ((win) ? (struct window *) (win) : &myroot)
  284. X#define W_Window2Void(window) ((W_Window) (window))
  285. X#define W_Void2Icon(bit) ((struct icon *) (bit))
  286. X#define W_Icon2Void(bit) ((W_Icon) (bit))
  287. X#define fontNum(font) (*((int *) font))
  288. X#define TILESIDE 16
  289. X
  290. X#define WIN_EDGE 5`009/* border on l/r edges of text windows */
  291. X#define MENU_PAD 4`009/* border on t/b edges of text windows */
  292. X#define MENU_BAR 4`009/* width of menu bar */
  293. X
  294. Xstatic char gray`091`093 = `123
  295. X`0090xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
  296. X`0090xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
  297. X`0090xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
  298. X`0090xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55
  299. X`125;
  300. X
  301. Xstatic char striped`091`093 = `123
  302. X`0090x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
  303. X`0090xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f,
  304. X`0090xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
  305. X`0090x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0
  306. X`125;
  307. X
  308. Xstatic char solid`091`093 = `123
  309. X`0090xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  310. X`0090xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  311. X`0090xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  312. X`0090xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  313. X`125;
  314. X
  315. Xvoid W_Initialize(str)
  316. Xchar *str;
  317. X`123
  318. X    int i;
  319. X
  320. X#ifdef DEBUG
  321. X    printf("Initializing...\n");
  322. X#endif
  323. X#ifdef VMS
  324. X    /* for some reason we can't specify anything but NULL in XOpenDisplay un
  325. Vder VMS */
  326. X    str = NULL;
  327. X#endif
  328. X    for (i=0; i<HASHSIZE; i++) `123
  329. X`009hashtable`091i`093=NULL;
  330. X    `125
  331. X    if ((W_Display = XOpenDisplay(str)) == NULL) `123
  332. X`009fprintf(stderr, "I cannot open your display!\n");
  333. X`009exit(1);
  334. X    `125
  335. X
  336. X    /*XSynchronize(W_Display, True);*/
  337. X    W_Root=DefaultRootWindow(W_Display);
  338. X    W_Screen=DefaultScreen(W_Display);
  339. X    W_Colormap=DefaultColormap(W_Display, W_Screen);
  340. X    myroot.window=W_Root;
  341. X    myroot.type=WIN_GRAPH;
  342. X
  343. X    GetFonts();
  344. X    GetColors();
  345. X
  346. X`125
  347. X
  348. XGetFonts()
  349. X`123
  350. X    Font regular, italic, bold, big;
  351. X    int i,j;
  352. X    XGCValues values;
  353. X    XFontStruct *fontinfo;
  354. X    char *fontname;
  355. X
  356. X    fontname=getdefault("font");
  357. X    if (fontname==NULL)
  358. X    fontname="sys$common:`091sysfont.decw.common`093decw$font_directory_comm
  359. Von.dat;2";
  360. X    fontinfo=XLoadQueryFont(W_Display, fontname);
  361. X    if (fontinfo==NULL) `123
  362. X`009printf("Couldn't find 6x10 font!\n");
  363. X`009exit(1);
  364. X    `125
  365. X    regular=fontinfo->fid;
  366. X    W_Textwidth=fontinfo->max_bounds.width;
  367. X    W_Textheight=fontinfo->max_bounds.descent+fontinfo->max_bounds.ascent;
  368. X    fonts`0911`093.baseline=fontinfo->max_bounds.ascent;
  369. X
  370. X    fontname=getdefault("boldfont");
  371. X    if (fontname==NULL) fontname="6x10B";
  372. X    fontinfo=XLoadQueryFont(W_Display, fontname);
  373. X    if (fontinfo==NULL) `123
  374. X`009bold=regular;
  375. X`009fonts`0912`093.baseline=fonts`0911`093.baseline;
  376. X    `125 else `123
  377. X`009bold=fontinfo->fid;
  378. X`009fonts`0912`093.baseline=fontinfo->max_bounds.ascent;
  379. X`009if (fontinfo->max_bounds.width > W_Textwidth)`032
  380. X`009    W_Textwidth=fontinfo->max_bounds.width;
  381. X`009if (fontinfo->max_bounds.descent+fontinfo->max_bounds.ascent > W_Texthei
  382. Vght)
  383. X`009    W_Textheight=fontinfo->max_bounds.descent+fontinfo->max_bounds.ascen
  384. Vt;
  385. X    `125
  386. X
  387. X    fontname=getdefault("italicfont");
  388. X    if (fontname==NULL) fontname="6x10I";
  389. X    fontinfo=XLoadQueryFont(W_Display, "6x10I");
  390. X    if (fontinfo==NULL) `123
  391. X`009italic=regular;
  392. X`009fonts`0913`093.baseline=fonts`0911`093.baseline;
  393. X    `125 else `123
  394. X`009italic=fontinfo->fid;
  395. X`009fonts`0913`093.baseline=fontinfo->max_bounds.ascent;
  396. X`009if (fontinfo->max_bounds.width > W_Textwidth)`032
  397. X`009    W_Textwidth=fontinfo->max_bounds.width;
  398. X`009if (fontinfo->max_bounds.descent+fontinfo->max_bounds.ascent > W_Texthei
  399. Vght)
  400. X`009    W_Textheight=fontinfo->max_bounds.descent+fontinfo->max_bounds.ascen
  401. Vt;
  402. X    `125
  403. X
  404. X    fontname=getdefault("bigfont");
  405. X    if (fontname==NULL) fontname="charB24";
  406. X    fontinfo=XLoadQueryFont(W_Display, fontname);
  407. X    if (fontinfo==NULL) `123
  408. X`009big=regular;
  409. X`009fonts`0910`093.baseline=fonts`0911`093.baseline;
  410. X    `125 else `123
  411. X`009big=fontinfo->fid;
  412. X`009fonts`0910`093.baseline=fontinfo->max_bounds.ascent;
  413. X    `125
  414. X    for (i=0; i<NCOLORS; i++) `123
  415. X`009values.font=big;
  416. X`009colortable`091i`093.contexts`0910`093=XCreateGC(W_Display, W_Root, GCFon
  417. Vt, &values);
  418. X`009values.font=regular;
  419. X`009colortable`091i`093.contexts`0911`093=XCreateGC(W_Display, W_Root, GCFon
  420. Vt, &values);
  421. X`009values.font=bold;
  422. X`009colortable`091i`093.contexts`0912`093=XCreateGC(W_Display, W_Root, GCFon
  423. Vt, &values);
  424. X`009values.font=italic;
  425. X`009colortable`091i`093.contexts`0913`093=XCreateGC(W_Display, W_Root, GCFon
  426. Vt, &values);
  427. X`009values.function=GXor;
  428. X`009colortable`091i`093.contexts`091BITGC`093=XCreateGC(W_Display, W_Root, G
  429. VCFunction,
  430. X`009    &values);
  431. X    `125
  432. X`125
  433. X
  434. XGetColors()
  435. X`123
  436. X    int i,j;
  437. X    XColor foo;
  438. X    int white, black;
  439. X    unsigned long pixel;
  440. X    unsigned long planes`0913`093;
  441. X    char defaultstring`091100`093;
  442. X    char *defaults;
  443. X
  444. X    if (DisplayCells(W_Display, W_Screen) <= 2) `123
  445. X`009white=WhitePixel(W_Display, W_Screen);
  446. X`009black=BlackPixel(W_Display, W_Screen);
  447. X`009for (i=0; i<NCOLORS; i++) `123
  448. X`009    if (i != W_Black) `123
  449. X`009`009colortable`091i`093.pixelValue=white;
  450. X`009    `125 else `123
  451. X`009`009colortable`091i`093.pixelValue=black;
  452. X`009    `125
  453. X`009    if (i==W_Red) `123
  454. X`009`009colortable`091i`093.pixmap=XCreatePixmapFromBitmapData(W_Display,
  455. X`009`009    W_Root, striped, TILESIDE, TILESIDE,
  456. X`009`009    white, black,
  457. X`009`009    DefaultDepth(W_Display, W_Screen));
  458. X`009    `125 else if (i==W_Yellow) `123
  459. X`009`009colortable`091i`093.pixmap=XCreatePixmapFromBitmapData(W_Display,
  460. X`009`009    W_Root, gray, TILESIDE, TILESIDE,
  461. X`009`009    white, black,
  462. X`009`009    DefaultDepth(W_Display, W_Screen));
  463. X`009    `125 else `123
  464. X`009`009colortable`091i`093.pixmap=XCreatePixmapFromBitmapData(W_Display,
  465. X`009`009    W_Root, solid, TILESIDE, TILESIDE,`032
  466. X`009`009    colortable`091i`093.pixelValue,
  467. X`009`009    colortable`091i`093.pixelValue,`032
  468. X`009`009    DefaultDepth(W_Display, W_Screen));
  469. X`009    `125
  470. X`009    /* We assume white is 0 or 1, and black is 0 or 1.
  471. X`009     * We adjust graphics function based upon who is who.
  472. X`009     */
  473. X`009    if (white==0) `123`009/* Black is 1 */
  474. X`009`009XSetFunction(W_Display, colortable`091i`093.contexts`091BITGC`093,`0
  475. V32
  476. X`009`009    GXand);
  477. X`009    `125
  478. X`009`125
  479. X    `125 else `123
  480. X`009XAllocColorCells(W_Display, W_Colormap, False, planes, 3, &pixel, 1);
  481. X`009for (i=0; i<NCOLORS; i++) `123
  482. X`009    sprintf(defaultstring, "color.%s", colortable`091i`093.name);
  483. X`009    defaults=getdefault(defaultstring);
  484. X`009    if (defaults==NULL) defaults=colortable`091i`093.name;
  485. X`009    XParseColor(W_Display, W_Colormap, defaults, &foo);
  486. X`009    /* Black must be the color with all the planes off.
  487. X`009     * That is the only restriction I concerned myself with in
  488. X`009     *  the following case statement.
  489. X`009     */
  490. X`009    switch(i) `123
  491. X`009    case WHITE:
  492. X`009`009foo.pixel=pixel`124planes`0910`093`124planes`0911`093`124planes`0912
  493. V`093;
  494. X`009`009break;
  495. X`009    case BLACK:
  496. X`009`009foo.pixel=pixel;
  497. X`009`009break;
  498. X`009    case RED:
  499. X`009`009foo.pixel=pixel`124planes`0910`093;
  500. X`009`009break;
  501. X`009    case CYAN:
  502. X`009`009foo.pixel=pixel`124planes`0911`093;
  503. X`009`009break;
  504. X`009    case YELLOW:
  505. X`009`009foo.pixel=pixel`124planes`0912`093;
  506. +-+-+-+-+-+-+-+-  END  OF PART 45 +-+-+-+-+-+-+-+-
  507.