home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / vmstrek / part45 < prev    next >
Encoding:
Text File  |  1992-11-20  |  14.4 KB  |  508 lines

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