home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / xtrek.zip / XTREK4.6 < prev    next >
Text File  |  1987-07-05  |  59KB  |  2,282 lines

  1.  
  2. Article 50 of comp.sources.games:
  3. Path: ncrcce!rd1632!ncrlnk!ncrcae!ece-csc!mcnc!seismo!rochester!cornell!uw-beaver!tektronix!tekgen!tekred!games-request
  4. From: games-request@tekred.TEK.COM
  5. Newsgroups: comp.sources.games
  6. Subject: v01i076:  xtrek - multiplayer space war for X-windows, Part04/06
  7. Message-ID: <1369@tekred.TEK.COM>
  8. Date: 2 Jul 87 20:54:13 GMT
  9. Sender: billr@tekred.TEK.COM
  10. Lines: 2267
  11. Approved: billr@tekred.TEK.COM
  12.  
  13. Submitted by: Chris Guthrie <chris%ic.Berkeley.EDU@ucbvax.berkeley.edu>
  14. Comp.sources.games: Volume 1, Issue 76
  15. Archive-name: xtrek/Part04
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 4 (of 6)."
  25. # Contents:  Makefile inform.c main.c pstats.c sintab.c smessage.c
  26. #   stats.c struct.h war.c
  27. # Wrapped by billr@tekred on Thu Jul  2 10:26:32 1987
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f Makefile -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"Makefile\"
  31. else
  32. echo shar: Extracting \"Makefile\" \(9193 characters\)
  33. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  34. XDESTDIR = /usr/games
  35. XXTREKDIR = /usr/games/lib/xtrek
  36. XXTREKOWNER = daemon
  37. X
  38. XR_OBJS = colors.o \
  39. X        coup.o \
  40. X        data.o \
  41. X        death.o \
  42. X        detonate.o \
  43. X        dmessage.o \
  44. X        enter.o \
  45. X        getship.o \
  46. X        inform.o \
  47. X        input.o \
  48. X        interface.o \
  49. X        main.o \
  50. X        newwin.o \
  51. X        orbit.o \
  52. X        phaser.o \
  53. X        planetlist.o \
  54. X        playerlist.o \
  55. X        pstats.o \
  56. X        redraw.o \
  57. X        sintab.o \
  58. X        smessage.o \
  59. X        startdaemon.o \
  60. X        stats.o \
  61. X        torp.o \
  62. X        util.o \
  63. X        war.o \
  64. X        warning.o
  65. X
  66. XR_FILES = colors.c \
  67. X        coup.c \
  68. X        data.c \
  69. X        death.c \
  70. X        detonate.c \
  71. X        dmessage.c \
  72. X        enter.c \
  73. X        getship.c \
  74. X        inform.c \
  75. X        input.c \
  76. X        interface.c \
  77. X        main.c \
  78. X        newwin.c \
  79. X        orbit.c \
  80. X        phaser.c \
  81. X        planetlist.c \
  82. X        playerlist.c \
  83. X        pstats.c \
  84. X        redraw.c \
  85. X        sintab.c \
  86. X        smessage.c \
  87. X        startdaemon.c \
  88. X        stats.c \
  89. X        torp.c \
  90. X        util.c \
  91. X        war.c \
  92. X        warning.c
  93. X
  94. XD_OBJS =    daemon.o \
  95. X        sintab.o \
  96. X        data.o
  97. X#        random.o   -- put this back if you have a better rand()
  98. X
  99. Xr_OBJS =    data.o \
  100. X        detonate.o \
  101. X        enter.o \
  102. X        getship.o \
  103. X        interface.o \
  104. X        phaser.o \
  105. X        robot.o \
  106. X        rmove.o \
  107. X        sintab.o \
  108. X        startdaemon.o \
  109. X        torp.o \
  110. X        util.o
  111. X
  112. XLIBS = -lX -lm
  113. X
  114. XCFLAGS = -O
  115. X
  116. Xall: xtrek daemon robot
  117. X
  118. Xxtrek: $(R_OBJS)
  119. X    cc $(CFLAGS) -o xtrek $(R_OBJS) $(LIBS)
  120. X    chmod 4711 xtrek
  121. X
  122. Xdaemon: $(D_OBJS)
  123. X    cc $(CFLAGS) -o daemon $(D_OBJS) -lm
  124. X    chmod 4711 daemon
  125. X
  126. Xrobot: $(r_OBJS)
  127. X    cc $(CFLAGS) -o robot $(r_OBJS) $(LIBS)
  128. X    chmod 4711 robot
  129. X
  130. Xinstall: xtrek daemon
  131. X    -mv $(DESTDIR)/xtrek $(DESTDIR)/xtrek.old
  132. X    cp xtrek $(DESTDIR)
  133. X    chmod 4711 $(DESTDIR)/xtrek
  134. X    chown $(XTREKOWNER) $(DESTDIR)/xtrek
  135. X    -mv $(XTREKDIR)/daemon $(XTREKDIR)/daemon.old
  136. X    cp daemon $(XTREKDIR)
  137. X    chmod 4711 $(XTREKDIR)/daemon
  138. X    chown $(XTREKOWNER) $(XTREKDIR)/daemon
  139. X    -mv $(XTREKDIR)/robot $(XTREKDIR)/robot.old
  140. X    cp robot $(XTREKDIR)
  141. X    chmod 4711 $(XTREKDIR)/robot
  142. X    chown $(XTREKOWNER) $(XTREKDIR)/robot
  143. X    touch $(XTREKDIR)/.planets $(XTREKDIR)/.motd $(XTREKDIR)/.scores
  144. X    chown $(XTREKOWNER) $(XTREKDIR)/.planets $(XTREKDIR)/.motd \
  145. X    $(XTREKDIR)/.scores
  146. X    chmod 644 $(XTREKDIR)/.scores $(XTREKDIR)/.motd
  147. X    chmod 600 $(XTREKDIR)/.planets
  148. X    
  149. Xlint:
  150. X    lint -abchp ${R_FILES}
  151. X
  152. Xclean:
  153. X    -rm -f *.o core a.out xtrek daemon robot
  154. X
  155. X###
  156. Xcolors.o: /usr/include/stdio.h /usr/include/X/Xlib.h \
  157. X    /usr/include/X/mit-copyright.h /usr/include/sys/types.h \
  158. X    /usr/include/X/X.h /usr/include/strings.h data.h
  159. Xcoup.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  160. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  161. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h defs.h struct.h data.h
  162. Xdaemon.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  163. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  164. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h /usr/include/sys/time.h \
  165. X    /usr/include/sys/file.h /usr/include/sys/wait.h \
  166. X    /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h \
  167. X    /usr/include/sys/ttydev.h /usr/include/sgtty.h /usr/include/signal.h \
  168. X    /usr/include/setjmp.h /usr/include/math.h defs.h struct.h data.h \
  169. X    planets.h /usr/include/sys/resource.h
  170. Xdata.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  171. X    /usr/include/sys/types.h /usr/include/X/X.h defs.h struct.h data.h
  172. Xdeath.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  173. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  174. X    /usr/include/signal.h /usr/include/setjmp.h /usr/include/sys/time.h \
  175. X    defs.h struct.h data.h
  176. Xdetonate.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  177. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  178. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h defs.h struct.h data.h
  179. Xdmessage.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  180. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  181. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  182. Xenter.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  183. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  184. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h /usr/include/errno.h \
  185. X    /usr/include/pwd.h /usr/include/strings.h /usr/include/ctype.h defs.h \
  186. X    struct.h data.h
  187. Xgetship.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  188. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  189. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h defs.h struct.h data.h
  190. Xhose.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  191. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  192. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h /usr/include/sys/time.h \
  193. X    /usr/include/sys/file.h /usr/include/sys/wait.h \
  194. X    /usr/include/sys/ioctl.h /usr/include/sys/ttychars.h \
  195. X    /usr/include/sys/ttydev.h /usr/include/sgtty.h /usr/include/signal.h \
  196. X    /usr/include/setjmp.h /usr/include/math.h defs.h struct.h data.h \
  197. X    planets.h
  198. Xinform.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  199. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  200. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  201. Xinput.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  202. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  203. X    /usr/include/math.h /usr/include/sys/time.h /usr/include/signal.h \
  204. X    /usr/include/errno.h defs.h struct.h data.h
  205. Xinterface.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  206. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  207. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  208. Xmain.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  209. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  210. X    /usr/include/sys/time.h /usr/include/signal.h /usr/include/setjmp.h \
  211. X    defs.h struct.h data.h
  212. Xnewwin.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  213. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  214. X    /usr/include/math.h /usr/include/signal.h /usr/include/sys/time.h \
  215. X    defs.h struct.h data.h bitmaps.h clock.bitmap
  216. Xorbit.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  217. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  218. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h defs.h struct.h data.h
  219. Xphaser.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  220. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  221. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  222. Xplanetlist.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  223. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  224. X    defs.h struct.h data.h
  225. Xplayerlist.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  226. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  227. X    defs.h struct.h data.h
  228. Xpstats.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  229. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  230. X    /usr/include/sys/time.h /usr/include/sys/resource.h \
  231. X    /usr/include/sys/file.h /usr/include/signal.h /usr/include/setjmp.h \
  232. X    defs.h struct.h data.h
  233. Xredraw.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  234. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  235. X    /usr/include/signal.h /usr/include/math.h defs.h struct.h data.h \
  236. X    bitmaps.h
  237. Xrmove.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  238. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  239. X    /usr/include/signal.h /usr/include/math.h defs.h struct.h data.h
  240. Xrobot.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  241. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  242. X    /usr/include/sys/time.h /usr/include/signal.h /usr/include/setjmp.h \
  243. X    defs.h struct.h data.h
  244. Xrotate.o: /usr/include/stdio.h /usr/include/math.h
  245. Xscores.o: /usr/include/stdio.h /usr/include/sys/types.h \
  246. X    /usr/include/sys/file.h /usr/include/pwd.h defs.h struct.h
  247. Xsmessage.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  248. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  249. X    /usr/include/math.h /usr/include/signal.h /usr/include/ctype.h defs.h \
  250. X    struct.h data.h
  251. Xstartdaemon.o: /usr/include/stdio.h /usr/include/X/Xlib.h \
  252. X    /usr/include/X/mit-copyright.h /usr/include/sys/types.h \
  253. X    /usr/include/X/X.h defs.h struct.h data.h
  254. Xstats.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  255. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  256. X    defs.h struct.h data.h
  257. Xtorp.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  258. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  259. X    /usr/include/sys/ipc.h /usr/include/sys/shm.h defs.h struct.h data.h
  260. Xutil.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  261. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  262. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  263. Xwar.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  264. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  265. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  266. Xwarning.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  267. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  268. X    /usr/include/math.h /usr/include/signal.h defs.h struct.h data.h
  269. Xxx.o: /usr/include/X/Xlib.h /usr/include/X/mit-copyright.h \
  270. X    /usr/include/sys/types.h /usr/include/X/X.h /usr/include/stdio.h \
  271. X    /usr/include/sys/time.h /usr/include/signal.h /usr/include/setjmp.h \
  272. X    /usr/include/errno.h defs.h struct.h data.h
  273. END_OF_Makefile
  274. if test 9193 -ne `wc -c <Makefile`; then
  275.     echo shar: \"Makefile\" unpacked with wrong size!
  276. fi
  277. # end of overwriting check
  278. fi
  279. if test -f inform.c -a "${1}" != "-c" ; then 
  280.   echo shar: Will not over-write existing file \"inform.c\"
  281. else
  282. echo shar: Extracting \"inform.c\" \(5626 characters\)
  283. sed "s/^X//" >inform.c <<'END_OF_inform.c'
  284. X
  285. X/*
  286. X
  287. X    Copyright (c) 1986     Chris Guthrie
  288. X
  289. XPermission to use, copy, modify, and distribute this
  290. Xsoftware and its documentation for any purpose and without
  291. Xfee is hereby granted, provided that the above copyright
  292. Xnotice appear in all copies and that both that copyright
  293. Xnotice and this permission notice appear in supporting
  294. Xdocumentation.  No representations are made about the
  295. Xsuitability of this software for any purpose.  It is
  296. Xprovided "as is" without express or implied warranty.
  297. X
  298. X*/
  299. X
  300. X#include <X/Xlib.h>
  301. X#include <stdio.h>
  302. X#include <math.h>
  303. X#include <signal.h>
  304. X#include "defs.h"
  305. X#include "struct.h"
  306. X#include "data.h"
  307. X
  308. X#define WINSIDE 500
  309. X
  310. X/* Display information about the nearest objext to mouse */
  311. X
  312. X/*
  313. X** When the player asks for info, this routine finds the object
  314. X** nearest the mouse, either player or planet, and pop up a window
  315. X** with the desired information in it.
  316. X** 
  317. X** We intentionally provide less information than is actually
  318. X** available.  Keeps the fog of war up.
  319. X**
  320. X** There is a different sized window for each type player/planet
  321. X** and we take care to keep it from extending beyond the main
  322. X** window boundaries.
  323. X*/
  324. X
  325. Xinform(ww, x, y)
  326. XWindow ww;
  327. Xint x, y;
  328. X{
  329. X    char buf[BUFSIZ];
  330. X    int line = 0;
  331. X    register struct player *j;
  332. X    register struct planet *k;
  333. X    int mx, my;
  334. X    double dist;
  335. X    Window subw;
  336. X    struct obtype *gettarget(), *target;
  337. X    static WindowInfo    wi;
  338. X
  339. X    infomapped = 1;
  340. X    target = gettarget(ww, x, y, TARG_PLAYER|TARG_PLANET);
  341. X
  342. X    if (wi.width == 0)
  343. X    XQueryWindow(ww, &wi);
  344. X
  345. X    XQueryMouse(ww, &mx, &my, &subw);
  346. X
  347. X    if (target->o_type == PLAYERTYPE) {
  348. X    /* Too close to the edge? */
  349. X    if (mx + 23 * dfontinfo->width + 2 > wi.width)
  350. X        mx = wi.width - 23 * dfontinfo->width - 2;
  351. X    if (my + 7 * dfontinfo->height + 2 > wi.height)
  352. X        my = wi.height - 7 * dfontinfo->height - 2;
  353. X
  354. X    infow = XCreateWindow(ww, mx, my, 23 * dfontinfo->width,
  355. X        7 * dfontinfo->height, 2, foreTile, backTile);
  356. X    XMapWindow(infow);
  357. X    j = &players[target->o_num];
  358. X    dist = hypot((double) (me->p_x - j->p_x),
  359. X        (double) (me->p_y - j->p_y));
  360. X    (void) sprintf(buf, "%s (%c%1x):", j->p_name, teamlet[j->p_team], j->p_no);
  361. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  362. X        strlen(buf), shipFont(j), playerColor(j), backColor);
  363. X    (void) sprintf(buf, "Login   %-s", j->p_login);
  364. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  365. X        strlen(buf), dfont, playerColor(j), backColor);
  366. X    (void) sprintf(buf, "Display %-s", j->p_monitor);
  367. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  368. X        strlen(buf), dfont, playerColor(j), backColor);
  369. X    (void) sprintf(buf, "Speed   %-d", j->p_speed);
  370. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  371. X        strlen(buf), dfont, playerColor(j), backColor);
  372. X
  373. X    /*  Too much information.  Let 'em wonder
  374. X    (void) sprintf(buf, "Damage  %-d", j->p_damage);
  375. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  376. X        strlen(buf), dfont, playerColor(j), backColor);
  377. X    (void) sprintf(buf, "Shields %-d", j->p_shield);
  378. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  379. X        strlen(buf), dfont, playerColor(j), backColor);
  380. X    */
  381. X
  382. X    (void) sprintf(buf, "kills   %-4.2f", j->p_kills);
  383. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  384. X        strlen(buf), dfont, playerColor(j), backColor);
  385. X    (void) sprintf(buf, "dist    %-d", (int) dist);
  386. X    XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  387. X        strlen(buf), dfont, playerColor(j), backColor);
  388. X    if (j->p_swar & me->p_team)
  389. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, "WAR",
  390. X        3, dfont, playerColor(j), backColor);
  391. X    else if (j->p_hostile & me->p_team)
  392. X        XText(infow, dfontinfo->width, dfontinfo->height * line++,
  393. X        "HOSTILE", 7, dfont, playerColor(j), backColor);
  394. X    else
  395. X        XText(infow, dfontinfo->width, dfontinfo->height * line++,
  396. X        "PEACEFUL", 8, dfont, playerColor(j), backColor);
  397. X    }
  398. X    else {  /* Planet */
  399. X    /* Too close to the edge? */
  400. X    if (mx + 20 * dfontinfo->width + 2 > wi.width)
  401. X        mx = wi.width - 20 * dfontinfo->width - 2;
  402. X    if (my + 3 * dfontinfo->height + 2 > wi.height)
  403. X        my = wi.height - 3 * dfontinfo->height - 2;
  404. X
  405. X    infow = XCreateWindow(ww, mx, my, 20 * dfontinfo->width,
  406. X        3 * dfontinfo->height, 2, foreTile, backTile);
  407. X    XMapWindow(infow);
  408. X    k = &planets[target->o_num];
  409. X    dist = hypot((double) (me->p_x - k->pl_x),
  410. X        (double) (me->p_y - k->pl_y));
  411. X    if (k->pl_info & me->p_team) {
  412. X        (void) sprintf(buf, "%s (%c)", k->pl_name, teamlet[k->pl_owner]);
  413. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  414. X        strlen(buf), planetFont(k), planetColor(k), backColor);
  415. X        (void) sprintf(buf, "Armies %d", k->pl_armies);
  416. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  417. X        strlen(buf), dfont, planetColor(k), backColor);
  418. X        (void) sprintf(buf, "%s %s  %c%c%c%c",
  419. X        (k->pl_flags & PLREPAIR ? "REPAIR" : "      "),
  420. X        (k->pl_flags & PLFUEL ? "FUEL" : "    "),
  421. X        (k->pl_info & FED ? 'F' : ' '),
  422. X        (k->pl_info & ROM ? 'R' : ' '),
  423. X        (k->pl_info & KLI ? 'K' : ' '),
  424. X        (k->pl_info & ORI ? 'O' : ' '));
  425. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  426. X        strlen(buf), dfont, planetColor(k), backColor);
  427. X    }
  428. X    else {
  429. X        (void) sprintf(buf, "%s", k->pl_name);
  430. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  431. X        strlen(buf), dfont, planetColor(k), backColor);
  432. X        (void) sprintf(buf, "No other info");
  433. X        XText(infow, dfontinfo->width, dfontinfo->height * line++, buf,
  434. X        strlen(buf), dfont, planetColor(k), backColor);
  435. X    }
  436. X    XFlush();
  437. X    }
  438. X}
  439. X
  440. X
  441. XdestroyInfo()
  442. X{
  443. X    XDestroyWindow(infow);
  444. X    infomapped = 0;
  445. X}
  446. END_OF_inform.c
  447. if test 5626 -ne `wc -c <inform.c`; then
  448.     echo shar: \"inform.c\" unpacked with wrong size!
  449. fi
  450. # end of overwriting check
  451. fi
  452. if test -f main.c -a "${1}" != "-c" ; then 
  453.   echo shar: Will not over-write existing file \"main.c\"
  454. else
  455. echo shar: Extracting \"main.c\" \(4437 characters\)
  456. sed "s/^X//" >main.c <<'END_OF_main.c'
  457. X
  458. X/*
  459. X
  460. X    Copyright (c) 1986     Chris Guthrie
  461. X
  462. XPermission to use, copy, modify, and distribute this
  463. Xsoftware and its documentation for any purpose and without
  464. Xfee is hereby granted, provided that the above copyright
  465. Xnotice appear in all copies and that both that copyright
  466. Xnotice and this permission notice appear in supporting
  467. Xdocumentation.  No representations are made about the
  468. Xsuitability of this software for any purpose.  It is
  469. Xprovided "as is" without express or implied warranty.
  470. X
  471. X*/
  472. X
  473. X#include <X/Xlib.h>
  474. X#include <stdio.h>
  475. X#include <string.h>
  476. X#include <sys/types.h>
  477. X#ifdef hpux
  478. X#include <time.h>
  479. X#else hpux
  480. X#include <sys/time.h>
  481. X#endif hpux
  482. X#include <signal.h>
  483. X#include <setjmp.h>
  484. X#include <pwd.h>
  485. X#ifndef hpux
  486. X#include <sys/wait.h>
  487. X#endif hpux
  488. X#include "defs.h"
  489. X#include "struct.h"
  490. X#include "data.h"
  491. X
  492. Xjmp_buf env;
  493. X
  494. Xmain(argc, argv)
  495. Xint argc;
  496. Xchar **argv;
  497. X{
  498. X    int intrupt();
  499. X    int team;
  500. X    int pno;
  501. X    char *host = NULL;
  502. X    int usage = 0;
  503. X    int err = 0;
  504. X    char *name, *ptr, *rindex();
  505. X    char buf[80];
  506. X    struct passwd *pwent, *getpwuid();
  507. X    int reaper();
  508. X
  509. X    name = *argv++;
  510. X    argc--;
  511. X    if ((ptr = rindex(name, '/')) != NULL)
  512. X    name = ptr + 1;
  513. X    while (*argv) {
  514. X    if (**argv == '-')
  515. X        *++*argv;
  516. X    else
  517. X        break;
  518. X
  519. X    argc--;
  520. X    ptr = *argv++;
  521. X    while (*ptr) {
  522. X        switch (*ptr) {
  523. X        case 'u': usage++; break;
  524. X        case 'c': 
  525. X        if (*argv == 0) {
  526. X            fprintf(stderr, "Missing required player number\n");
  527. X            err++;
  528. X            break;
  529. X        }
  530. X        pno = atoi(*argv);
  531. X        argc--;
  532. X        argv++;
  533. X        if (pno < 0 || pno >= MAXPLAYER) {
  534. X            fprintf(stderr, "Bad Player Number: %d\n", pno);
  535. X            err++;
  536. X        } else
  537. X            copilot++; 
  538. X        break;
  539. X        case 'w': 
  540. X        if (*argv == 0) {
  541. X            fprintf(stderr, "Missing required player number\n");
  542. X            err++;
  543. X            break;
  544. X        }
  545. X        pno = atoi(*argv);
  546. X        argc--;
  547. X        argv++;
  548. X        if (pno < 0 || pno >= MAXPLAYER) {
  549. X            fprintf(stderr, "Bad Player Number: %d\n", pno);
  550. X            err++;
  551. X        } else
  552. X            watch++; 
  553. X        break;
  554. X        case 'd':
  555. X        host = *argv;
  556. X        argc--;
  557. X        argv++;
  558. X        break;
  559. X        default: 
  560. X        fprintf(stderr, "%s: unknown option '%c'\n", name, *ptr);
  561. X        err++;
  562. X        break;
  563. X        }
  564. X        ptr++;
  565. X    }
  566. X    }
  567. X    if (usage || err) {
  568. X    printUsage(name);
  569. X    exit(err);
  570. X    }
  571. X    if (watch && copilot) {
  572. X    printf("%s: Cannot simultaneously use both watch and copilot.",
  573. X        name);
  574. X    exit(err);
  575. X    }
  576. X    /* compatability */
  577. X    if (argc > 0)
  578. X    host = argv[0];
  579. X    srandom(getpid() * time((long *) 0));
  580. X    /* this creates the necessary x windows for the game */
  581. X    newwin(host, name);
  582. X    /* this finds the shared memory information */
  583. X    openmem();
  584. X    /* map the windows */
  585. X    mapAll();
  586. X    if ((!copilot) && (!watch)) {
  587. X    pno = findslot();
  588. X    }
  589. X    if (pno < 0) {
  590. X    /* print some appropriate message */
  591. X    exit(1);
  592. X    }
  593. X    me = &players[pno];
  594. X    myship = &me->p_ship;
  595. X    mystats = &me->p_stats;
  596. X    lastm = mctl->mc_current;
  597. X    signal(SIGINT, SIG_IGN);
  598. X    signal(SIGQUIT, SIG_IGN);
  599. X    (void) signal(SIGCLD, reaper);
  600. X
  601. X    if ((!copilot) && (!watch)) {
  602. X    me->p_team = ALLTEAM;   /* Give full choice in startup window */
  603. X    setjmp(env);        /* Reentry point of game */
  604. X    /* give the player the motd and find out which team he wants */
  605. X    team = entrywindow();
  606. X    if (team == -1) {
  607. X        if (me != NULL)
  608. X        savestats();
  609. X        players[pno].p_status = PFREE;
  610. X        exit(0);
  611. X    }
  612. X    time(&start_time);        /* For stat gathering */
  613. X    redrawall = 1;
  614. X    enter(team, DisplayName(), pno);
  615. X    XClear(w);
  616. X    /*
  617. X    for (i = 0; i < NSIG; i++) {
  618. X        signal(i, SIG_IGN);
  619. X    }
  620. X    */
  621. X
  622. X    if (showStats)            /* Default showstats are on. */
  623. X        statwin = openStats(me);
  624. X
  625. X    me->p_status = PALIVE;            /* Put player in game */
  626. X    me->p_ghostbuster = 0;
  627. X    }
  628. X    else if (copilot) {
  629. X    if (me->p_status != PALIVE)
  630. X        exit(1);
  631. X    if (!(me->p_flags & PFCOPILOT)) {
  632. X        printf("%s is not allowing copilots\n", me->p_name);
  633. X        exit(1);
  634. X    }
  635. X    if (showStats)            /* Default showstats are on. */
  636. X        statwin = openStats(me);
  637. X
  638. X    if ((pwent = getpwuid(getuid())) == NULL)
  639. X        sprintf(buf, "Unknown person joining as a copilot");
  640. X    else
  641. X        sprintf(buf, "%-8s joining as a copilot", pwent->pw_name);
  642. X    
  643. X    pmessage(buf, pno, MINDIV, "GOD->YOU");
  644. X    }
  645. X    /* else (watch) */
  646. X    /* Get input until the player quits or dies */
  647. X    input();
  648. X}
  649. X
  650. XprintUsage(prog)
  651. X    char    *prog;
  652. X{
  653. X    printf("Usage: %s [-u] [-[cw] copilot-number] [-d display-name]\n",
  654. X        prog);
  655. X}
  656. X
  657. Xreaper(sig)
  658. X{
  659. X#ifdef hpux
  660. X    wait((int *) 0);
  661. X#else hpux
  662. X    while (wait3((union wait *) 0, WNOHANG, (struct rusage *) 0) > 0)
  663. X    ;
  664. X#endif hpux
  665. X}
  666. END_OF_main.c
  667. if test 4437 -ne `wc -c <main.c`; then
  668.     echo shar: \"main.c\" unpacked with wrong size!
  669. fi
  670. # end of overwriting check
  671. fi
  672. if test -f pstats.c -a "${1}" != "-c" ; then 
  673.   echo shar: Will not over-write existing file \"pstats.c\"
  674. else
  675. echo shar: Extracting \"pstats.c\" \(1924 characters\)
  676. sed "s/^X//" >pstats.c <<'END_OF_pstats.c'
  677. X
  678. X/*
  679. X
  680. X    Copyright (c) 1986     Chris Guthrie
  681. X
  682. XPermission to use, copy, modify, and distribute this
  683. Xsoftware and its documentation for any purpose and without
  684. Xfee is hereby granted, provided that the above copyright
  685. Xnotice appear in all copies and that both that copyright
  686. Xnotice and this permission notice appear in supporting
  687. Xdocumentation.  No representations are made about the
  688. Xsuitability of this software for any purpose.  It is
  689. Xprovided "as is" without express or implied warranty.
  690. X
  691. X*/
  692. X
  693. X
  694. X#include <X/Xlib.h>
  695. X#include <stdio.h>
  696. X#include <sys/types.h>
  697. X#ifdef hpux
  698. X#include <time.h>
  699. X#else hpux
  700. X#include <sys/time.h>
  701. X#endif hpux
  702. X#include <sys/resource.h>
  703. X#include <sys/file.h>
  704. X#include <signal.h>
  705. X#include <setjmp.h>
  706. X#include "defs.h"
  707. X#include "struct.h"
  708. X#include "data.h"
  709. X
  710. Xstatic int fd;
  711. Xstatic struct stats old;
  712. Xstatic struct rusage buf;
  713. Xstatic long now;
  714. X
  715. Xsavestats()
  716. X{
  717. X    fd = open(SCOREFILE, O_RDWR, 0777);
  718. X    if (fd < 0)
  719. X    return;
  720. X    lseek(fd, getuid() * sizeof(struct stats), 0);
  721. X    read(fd, &old, sizeof(struct stats));
  722. X
  723. X    me->p_stats.st_kills += old.st_kills;
  724. X    me->p_stats.st_losses += old.st_losses;
  725. X    me->p_stats.st_entries += old.st_entries;
  726. X    me->p_stats.st_conqs += old.st_conqs;
  727. X    me->p_stats.st_coups += old.st_coups;
  728. X    me->p_stats.st_torps += old.st_torps;
  729. X    me->p_stats.st_phasers += old.st_phasers;
  730. X    me->p_stats.st_armsbomb += old.st_armsbomb;
  731. X    me->p_stats.st_armsship += old.st_armsship;
  732. X    me->p_stats.st_planets += old.st_planets;
  733. X    me->p_stats.st_genocides += old.st_genocides;
  734. X
  735. X    time(&now);
  736. X    me->p_stats.st_time = old.st_time + (now - start_time);
  737. X
  738. X    getrusage(0, &buf);
  739. X    me->p_stats.st_cpu = old.st_cpu + buf.ru_utime.tv_sec + buf.ru_stime.tv_sec;
  740. X
  741. X    if (oldmax > old.st_maxkills)
  742. X    mystats->st_maxkills = oldmax;
  743. X    else
  744. X    mystats->st_maxkills = old.st_maxkills;
  745. X
  746. X    lseek(fd, getuid() * sizeof(struct stats), 0);
  747. X    write(fd, mystats, sizeof(struct stats));
  748. X}
  749. END_OF_pstats.c
  750. if test 1924 -ne `wc -c <pstats.c`; then
  751.     echo shar: \"pstats.c\" unpacked with wrong size!
  752. fi
  753. # end of overwriting check
  754. fi
  755. if test -f sintab.c -a "${1}" != "-c" ; then 
  756.   echo shar: Will not over-write existing file \"sintab.c\"
  757. else
  758. echo shar: Extracting \"sintab.c\" \(6925 characters\)
  759. sed "s/^X//" >sintab.c <<'END_OF_sintab.c'
  760. X
  761. X/*
  762. X
  763. X    Copyright (c) 1986     Chris Guthrie
  764. X
  765. XPermission to use, copy, modify, and distribute this
  766. Xsoftware and its documentation for any purpose and without
  767. Xfee is hereby granted, provided that the above copyright
  768. Xnotice appear in all copies and that both that copyright
  769. Xnotice and this permission notice appear in supporting
  770. Xdocumentation.  No representations are made about the
  771. Xsuitability of this software for any purpose.  It is
  772. Xprovided "as is" without express or implied warranty.
  773. X
  774. X*/
  775. X
  776. Xdouble Sin[] = {
  777. X    -1.0000,
  778. X    -0.9997,
  779. X    -0.9988,
  780. X    -0.9973,
  781. X    -0.9952,
  782. X    -0.9925,
  783. X    -0.9892,
  784. X    -0.9853,
  785. X    -0.9808,
  786. X    -0.9757,
  787. X    -0.9701,
  788. X    -0.9638,
  789. X    -0.9570,
  790. X    -0.9496,
  791. X    -0.9416,
  792. X    -0.9330,
  793. X    -0.9239,
  794. X    -0.9143,
  795. X    -0.9040,
  796. X    -0.8933,
  797. X    -0.8820,
  798. X    -0.8701,
  799. X    -0.8578,
  800. X    -0.8449,
  801. X    -0.8315,
  802. X    -0.8176,
  803. X    -0.8033,
  804. X    -0.7884,
  805. X    -0.7731,
  806. X    -0.7573,
  807. X    -0.7410,
  808. X    -0.7243,
  809. X    -0.7072,
  810. X    -0.6896,
  811. X    -0.6716,
  812. X    -0.6533,
  813. X    -0.6345,
  814. X    -0.6153,
  815. X    -0.5958,
  816. X    -0.5759,
  817. X    -0.5557,
  818. X    -0.5351,
  819. X    -0.5142,
  820. X    -0.4930,
  821. X    -0.4715,
  822. X    -0.4497,
  823. X    -0.4277,
  824. X    -0.4054,
  825. X    -0.3828,
  826. X    -0.3600,
  827. X    -0.3370,
  828. X    -0.3138,
  829. X    -0.2904,
  830. X    -0.2668,
  831. X    -0.2431,
  832. X    -0.2192,
  833. X    -0.1952,
  834. X    -0.1711,
  835. X    -0.1469,
  836. X    -0.1225,
  837. X    -0.0982,
  838. X    -0.0737,
  839. X    -0.0492,
  840. X    -0.0247,
  841. X    -0.0001,
  842. X    0.0244,
  843. X    0.0489,
  844. X    0.0734,
  845. X    0.0979,
  846. X    0.1223,
  847. X    0.1466,
  848. X    0.1708,
  849. X    0.1949,
  850. X    0.2190,
  851. X    0.2428,
  852. X    0.2666,
  853. X    0.2901,
  854. X    0.3135,
  855. X    0.3367,
  856. X    0.3598,
  857. X    0.3825,
  858. X    0.4051,
  859. X    0.4274,
  860. X    0.4495,
  861. X    0.4713,
  862. X    0.4928,
  863. X    0.5140,
  864. X    0.5349,
  865. X    0.5554,
  866. X    0.5757,
  867. X    0.5956,
  868. X    0.6151,
  869. X    0.6343,
  870. X    0.6531,
  871. X    0.6714,
  872. X    0.6894,
  873. X    0.7070,
  874. X    0.7241,
  875. X    0.7408,
  876. X    0.7571,
  877. X    0.7729,
  878. X    0.7882,
  879. X    0.8031,
  880. X    0.8175,
  881. X    0.8314,
  882. X    0.8448,
  883. X    0.8576,
  884. X    0.8700,
  885. X    0.8818,
  886. X    0.8931,
  887. X    0.9039,
  888. X    0.9141,
  889. X    0.9238,
  890. X    0.9329,
  891. X    0.9415,
  892. X    0.9495,
  893. X    0.9569,
  894. X    0.9637,
  895. X    0.9700,
  896. X    0.9757,
  897. X    0.9808,
  898. X    0.9852,
  899. X    0.9891,
  900. X    0.9925,
  901. X    0.9952,
  902. X    0.9973,
  903. X    0.9988,
  904. X    0.9997,
  905. X    1.0000,
  906. X    0.9997,
  907. X    0.9988,
  908. X    0.9973,
  909. X    0.9952,
  910. X    0.9925,
  911. X    0.9892,
  912. X    0.9853,
  913. X    0.9808,
  914. X    0.9757,
  915. X    0.9700,
  916. X    0.9638,
  917. X    0.9569,
  918. X    0.9495,
  919. X    0.9415,
  920. X    0.9330,
  921. X    0.9239,
  922. X    0.9142,
  923. X    0.9040,
  924. X    0.8932,
  925. X    0.8819,
  926. X    0.8701,
  927. X    0.8577,
  928. X    0.8449,
  929. X    0.8315,
  930. X    0.8176,
  931. X    0.8032,
  932. X    0.7884,
  933. X    0.7730,
  934. X    0.7572,
  935. X    0.7410,
  936. X    0.7243,
  937. X    0.7071,
  938. X    0.6896,
  939. X    0.6716,
  940. X    0.6532,
  941. X    0.6344,
  942. X    0.6153,
  943. X    0.5957,
  944. X    0.5758,
  945. X    0.5556,
  946. X    0.5350,
  947. X    0.5141,
  948. X    0.4929,
  949. X    0.4714,
  950. X    0.4496,
  951. X    0.4276,
  952. X    0.4053,
  953. X    0.3827,
  954. X    0.3599,
  955. X    0.3369,
  956. X    0.3137,
  957. X    0.2903,
  958. X    0.2667,
  959. X    0.2430,
  960. X    0.2191,
  961. X    0.1951,
  962. X    0.1710,
  963. X    0.1468,
  964. X    0.1225,
  965. X    0.0981,
  966. X    0.0736,
  967. X    0.0491,
  968. X    0.0246,
  969. X    0.0000,
  970. X    -0.0245,
  971. X    -0.0490,
  972. X    -0.0735,
  973. X    -0.0980,
  974. X    -0.1224,
  975. X    -0.1467,
  976. X    -0.1709,
  977. X    -0.1950,
  978. X    -0.2190,
  979. X    -0.2429,
  980. X    -0.2667,
  981. X    -0.2902,
  982. X    -0.3136,
  983. X    -0.3368,
  984. X    -0.3598,
  985. X    -0.3826,
  986. X    -0.4052,
  987. X    -0.4275,
  988. X    -0.4496,
  989. X    -0.4713,
  990. X    -0.4928,
  991. X    -0.5140,
  992. X    -0.5349,
  993. X    -0.5555,
  994. X    -0.5758,
  995. X    -0.5956,
  996. X    -0.6152,
  997. X    -0.6343,
  998. X    -0.6531,
  999. X    -0.6715,
  1000. X    -0.6895,
  1001. X    -0.7071,
  1002. X    -0.7242,
  1003. X    -0.7409,
  1004. X    -0.7572,
  1005. X    -0.7730,
  1006. X    -0.7883,
  1007. X    -0.8032,
  1008. X    -0.8175,
  1009. X    -0.8314,
  1010. X    -0.8448,
  1011. X    -0.8577,
  1012. X    -0.8700,
  1013. X    -0.8819,
  1014. X    -0.8932,
  1015. X    -0.9040,
  1016. X    -0.9142,
  1017. X    -0.9238,
  1018. X    -0.9330,
  1019. X    -0.9415,
  1020. X    -0.9495,
  1021. X    -0.9569,
  1022. X    -0.9638,
  1023. X    -0.9700,
  1024. X    -0.9757,
  1025. X    -0.9808,
  1026. X    -0.9853,
  1027. X    -0.9892,
  1028. X    -0.9925,
  1029. X    -0.9952,
  1030. X    -0.9973,
  1031. X    -0.9988,
  1032. X    -0.9997
  1033. X};
  1034. Xdouble Cos[] = {
  1035. X    0.0000,
  1036. X    0.0245,
  1037. X    0.0491,
  1038. X    0.0736,
  1039. X    0.0980,
  1040. X    0.1224,
  1041. X    0.1467,
  1042. X    0.1710,
  1043. X    0.1951,
  1044. X    0.2191,
  1045. X    0.2430,
  1046. X    0.2667,
  1047. X    0.2903,
  1048. X    0.3137,
  1049. X    0.3369,
  1050. X    0.3599,
  1051. X    0.3827,
  1052. X    0.4052,
  1053. X    0.4275,
  1054. X    0.4496,
  1055. X    0.4714,
  1056. X    0.4929,
  1057. X    0.5141,
  1058. X    0.5350,
  1059. X    0.5556,
  1060. X    0.5758,
  1061. X    0.5957,
  1062. X    0.6152,
  1063. X    0.6344,
  1064. X    0.6532,
  1065. X    0.6715,
  1066. X    0.6895,
  1067. X    0.7071,
  1068. X    0.7242,
  1069. X    0.7409,
  1070. X    0.7572,
  1071. X    0.7730,
  1072. X    0.7883,
  1073. X    0.8032,
  1074. X    0.8176,
  1075. X    0.8315,
  1076. X    0.8448,
  1077. X    0.8577,
  1078. X    0.8701,
  1079. X    0.8819,
  1080. X    0.8932,
  1081. X    0.9040,
  1082. X    0.9142,
  1083. X    0.9239,
  1084. X    0.9330,
  1085. X    0.9415,
  1086. X    0.9495,
  1087. X    0.9569,
  1088. X    0.9638,
  1089. X    0.9700,
  1090. X    0.9757,
  1091. X    0.9808,
  1092. X    0.9853,
  1093. X    0.9892,
  1094. X    0.9925,
  1095. X    0.9952,
  1096. X    0.9973,
  1097. X    0.9988,
  1098. X    0.9997,
  1099. X    1.0000,
  1100. X    0.9997,
  1101. X    0.9988,
  1102. X    0.9973,
  1103. X    0.9952,
  1104. X    0.9925,
  1105. X    0.9892,
  1106. X    0.9853,
  1107. X    0.9808,
  1108. X    0.9757,
  1109. X    0.9700,
  1110. X    0.9638,
  1111. X    0.9570,
  1112. X    0.9495,
  1113. X    0.9416,
  1114. X    0.9330,
  1115. X    0.9239,
  1116. X    0.9142,
  1117. X    0.9040,
  1118. X    0.8933,
  1119. X    0.8819,
  1120. X    0.8701,
  1121. X    0.8578,
  1122. X    0.8449,
  1123. X    0.8315,
  1124. X    0.8176,
  1125. X    0.8032,
  1126. X    0.7884,
  1127. X    0.7731,
  1128. X    0.7573,
  1129. X    0.7410,
  1130. X    0.7243,
  1131. X    0.7072,
  1132. X    0.6896,
  1133. X    0.6716,
  1134. X    0.6532,
  1135. X    0.6344,
  1136. X    0.6153,
  1137. X    0.5958,
  1138. X    0.5759,
  1139. X    0.5556,
  1140. X    0.5351,
  1141. X    0.5142,
  1142. X    0.4930,
  1143. X    0.4715,
  1144. X    0.4497,
  1145. X    0.4276,
  1146. X    0.4053,
  1147. X    0.3828,
  1148. X    0.3600,
  1149. X    0.3370,
  1150. X    0.3138,
  1151. X    0.2904,
  1152. X    0.2668,
  1153. X    0.2431,
  1154. X    0.2192,
  1155. X    0.1952,
  1156. X    0.1710,
  1157. X    0.1468,
  1158. X    0.1225,
  1159. X    0.0981,
  1160. X    0.0737,
  1161. X    0.0492,
  1162. X    0.0246,
  1163. X    0.0001,
  1164. X    -0.0244,
  1165. X    -0.0490,
  1166. X    -0.0735,
  1167. X    -0.0979,
  1168. X    -0.1223,
  1169. X    -0.1466,
  1170. X    -0.1709,
  1171. X    -0.1950,
  1172. X    -0.2190,
  1173. X    -0.2429,
  1174. X    -0.2666,
  1175. X    -0.2902,
  1176. X    -0.3136,
  1177. X    -0.3368,
  1178. X    -0.3598,
  1179. X    -0.3826,
  1180. X    -0.4051,
  1181. X    -0.4275,
  1182. X    -0.4495,
  1183. X    -0.4713,
  1184. X    -0.4928,
  1185. X    -0.5140,
  1186. X    -0.5349,
  1187. X    -0.5555,
  1188. X    -0.5757,
  1189. X    -0.5956,
  1190. X    -0.6151,
  1191. X    -0.6343,
  1192. X    -0.6531,
  1193. X    -0.6715,
  1194. X    -0.6895,
  1195. X    -0.7070,
  1196. X    -0.7242,
  1197. X    -0.7409,
  1198. X    -0.7571,
  1199. X    -0.7729,
  1200. X    -0.7883,
  1201. X    -0.8031,
  1202. X    -0.8175,
  1203. X    -0.8314,
  1204. X    -0.8448,
  1205. X    -0.8577,
  1206. X    -0.8700,
  1207. X    -0.8819,
  1208. X    -0.8932,
  1209. X    -0.9039,
  1210. X    -0.9142,
  1211. X    -0.9238,
  1212. X    -0.9329,
  1213. X    -0.9415,
  1214. X    -0.9495,
  1215. X    -0.9569,
  1216. X    -0.9637,
  1217. X    -0.9700,
  1218. X    -0.9757,
  1219. X    -0.9808,
  1220. X    -0.9853,
  1221. X    -0.9892,
  1222. X    -0.9925,
  1223. X    -0.9952,
  1224. X    -0.9973,
  1225. X    -0.9988,
  1226. X    -0.9997,
  1227. X    -1.0000,
  1228. X    -0.9997,
  1229. X    -0.9988,
  1230. X    -0.9973,
  1231. X    -0.9952,
  1232. X    -0.9925,
  1233. X    -0.9892,
  1234. X    -0.9853,
  1235. X    -0.9808,
  1236. X    -0.9757,
  1237. X    -0.9701,
  1238. X    -0.9638,
  1239. X    -0.9570,
  1240. X    -0.9496,
  1241. X    -0.9416,
  1242. X    -0.9330,
  1243. X    -0.9239,
  1244. X    -0.9143,
  1245. X    -0.9041,
  1246. X    -0.8933,
  1247. X    -0.8820,
  1248. X    -0.8702,
  1249. X    -0.8578,
  1250. X    -0.8449,
  1251. X    -0.8316,
  1252. X    -0.8177,
  1253. X    -0.8033,
  1254. X    -0.7884,
  1255. X    -0.7731,
  1256. X    -0.7573,
  1257. X    -0.7411,
  1258. X    -0.7244,
  1259. X    -0.7072,
  1260. X    -0.6897,
  1261. X    -0.6717,
  1262. X    -0.6533,
  1263. X    -0.6345,
  1264. X    -0.6154,
  1265. X    -0.5958,
  1266. X    -0.5759,
  1267. X    -0.5557,
  1268. X    -0.5351,
  1269. X    -0.5142,
  1270. X    -0.4930,
  1271. X    -0.4715,
  1272. X    -0.4498,
  1273. X    -0.4277,
  1274. X    -0.4054,
  1275. X    -0.3828,
  1276. X    -0.3601,
  1277. X    -0.3371,
  1278. X    -0.3138,
  1279. X    -0.2905,
  1280. X    -0.2669,
  1281. X    -0.2432,
  1282. X    -0.2193,
  1283. X    -0.1953,
  1284. X    -0.1711,
  1285. X    -0.1469,
  1286. X    -0.1226,
  1287. X    -0.0982,
  1288. X    -0.0737,
  1289. X    -0.0493,
  1290. X    -0.0247
  1291. X};
  1292. END_OF_sintab.c
  1293. if test 6925 -ne `wc -c <sintab.c`; then
  1294.     echo shar: \"sintab.c\" unpacked with wrong size!
  1295. fi
  1296. # end of overwriting check
  1297. fi
  1298. if test -f smessage.c -a "${1}" != "-c" ; then 
  1299.   echo shar: Will not over-write existing file \"smessage.c\"
  1300. else
  1301. echo shar: Extracting \"smessage.c\" \(5214 characters\)
  1302. sed "s/^X//" >smessage.c <<'END_OF_smessage.c'
  1303. X
  1304. X/*
  1305. X
  1306. X    Copyright (c) 1986     Chris Guthrie
  1307. X
  1308. XPermission to use, copy, modify, and distribute this
  1309. Xsoftware and its documentation for any purpose and without
  1310. Xfee is hereby granted, provided that the above copyright
  1311. Xnotice appear in all copies and that both that copyright
  1312. Xnotice and this permission notice appear in supporting
  1313. Xdocumentation.  No representations are made about the
  1314. Xsuitability of this software for any purpose.  It is
  1315. Xprovided "as is" without express or implied warranty.
  1316. X
  1317. X*/
  1318. X
  1319. X
  1320. X#include <X/Xlib.h>
  1321. X#include <stdio.h>
  1322. X#include <math.h>
  1323. X#include <signal.h>
  1324. X#include <ctype.h>
  1325. X#include "defs.h"
  1326. X#include "struct.h"
  1327. X#include "data.h"
  1328. X
  1329. X#define ADDRLEN 10
  1330. X
  1331. Xstatic int lcount;
  1332. Xstatic char buf[80];
  1333. Xstatic char addr;
  1334. Xstatic char addrmesg[ADDRLEN];
  1335. X
  1336. Xsmessage(ichar)
  1337. Xchar ichar;
  1338. X{
  1339. X    register int i;
  1340. X
  1341. X    if (watch) {
  1342. X    warning("cannot send messages from watch");
  1343. X    return;
  1344. X    }
  1345. X    if (messpend == 0) {
  1346. X    messpend = 1;
  1347. X    if (mdisplayed) {
  1348. X        XPixSet(messagew, 5, 5, dfontinfo->width * lastcount,
  1349. X        dfontinfo->height, backColor);
  1350. X        mdisplayed = 0;
  1351. X    }
  1352. X    /* Put the proper recipient in the window */
  1353. X    if (getaddr(ichar) < 0) {
  1354. X        /* print error message */
  1355. X        messpend = 0;
  1356. X        return;
  1357. X    }
  1358. X    XText(messagew, 5 + dfontinfo->width, 5,
  1359. X        addrmesg, ADDRLEN, dfont, textColor, backColor);
  1360. X    lcount = ADDRLEN;
  1361. X    return;
  1362. X    }
  1363. X    switch (ichar) {
  1364. X    case '\b':
  1365. X    case '\177':
  1366. X        if (--lcount < ADDRLEN) {
  1367. X        lcount = ADDRLEN;
  1368. X        break;
  1369. X        }
  1370. X        XPixSet(messagew, 5 + dfontinfo->width * lcount, 5,
  1371. X        dfontinfo->width, dfontinfo->height, backColor);
  1372. X        break;
  1373. X    case '\027':
  1374. X        i = 0;
  1375. X        /* back up over blanks */
  1376. X        while (--lcount >= ADDRLEN && isspace(buf[lcount - ADDRLEN]))
  1377. X        i++;
  1378. X        lcount++;
  1379. X        /* back up over non-blanks */
  1380. X        while (--lcount >= ADDRLEN && !isspace(buf[lcount - ADDRLEN]))
  1381. X        i++;
  1382. X        lcount++;
  1383. X
  1384. X        if (i > 0)
  1385. X        XPixSet(messagew, 5 + dfontinfo->width * lcount, 5,
  1386. X            dfontinfo->width * i, dfontinfo->height, backColor);
  1387. X        break;
  1388. X    case '\025':
  1389. X    case '\030':
  1390. X        if (lcount > ADDRLEN)
  1391. X        XPixSet(messagew, 5 + dfontinfo->width * ADDRLEN, 5,
  1392. X            dfontinfo->width * (lcount - ADDRLEN),
  1393. X            dfontinfo->height, backColor);
  1394. X        lcount = ADDRLEN;
  1395. X        break;
  1396. X    case '\033':
  1397. X        XPixSet(messagew, 5, 5, dfontinfo->width * lcount,
  1398. X        dfontinfo->height, backColor);
  1399. X        mdisplayed = 0;
  1400. X        messpend = 0;
  1401. X        break;
  1402. X    case '\r':
  1403. X        buf[lcount - ADDRLEN] = 0;
  1404. X        messpend = 0;
  1405. X        switch (addr) {
  1406. X        case 'A':
  1407. X            pmessage(buf, 0, MALL, addrmesg);
  1408. X            break;
  1409. X        case 'F':
  1410. X            pmessage(buf, FED, MTEAM, addrmesg);
  1411. X            break;
  1412. X        case 'R':
  1413. X        case 'r':
  1414. X            pmessage(buf, ROM, MTEAM, addrmesg);
  1415. X            break;
  1416. X        case 'K':
  1417. X        case 'k':
  1418. X            pmessage(buf, KLI, MTEAM, addrmesg);
  1419. X            break;
  1420. X        case 'O':
  1421. X        case 'o':
  1422. X            pmessage(buf, ORI, MTEAM, addrmesg);
  1423. X            break;
  1424. X        case '0':
  1425. X        case '1':
  1426. X        case '2':
  1427. X        case '3':
  1428. X        case '4':
  1429. X        case '5':
  1430. X        case '6':
  1431. X        case '7':
  1432. X        case '8':
  1433. X        case '9':
  1434. X            pmessage(buf, addr - '0', MINDIV, addrmesg);
  1435. X            break;
  1436. X        case 'a':
  1437. X        case 'b':
  1438. X        case 'c':
  1439. X        case 'd':
  1440. X        case 'e':
  1441. X        case 'f':
  1442. X            pmessage(buf, addr - 'a' - 10, MINDIV, addrmesg);
  1443. X            break;
  1444. X        default:
  1445. X            warning("Not legal recipient");
  1446. X        }
  1447. X        XPixSet(messagew, 5, 5, dfontinfo->width * lcount,
  1448. X        dfontinfo->height, backColor);
  1449. X        mdisplayed = 0;
  1450. X        lcount = 0;
  1451. X        break;
  1452. X    default:
  1453. X        if (lcount == 80) {
  1454. X        XFeep(0);
  1455. X        break;
  1456. X        }
  1457. X        if (iscntrl(ichar))
  1458. X        break;
  1459. X        XText(messagew, 5 + dfontinfo->width * lcount, 5,
  1460. X        &ichar, 1, dfont, textColor, backColor);
  1461. X        buf[(lcount++) - ADDRLEN] = ichar;
  1462. X        break;
  1463. X    }
  1464. X}
  1465. X
  1466. Xpmessage(str, recip, group, address)
  1467. Xchar *str;
  1468. Xint recip;
  1469. Xint group;
  1470. Xchar *address;
  1471. X{
  1472. X    struct message *cur;
  1473. X    if (++(mctl->mc_current) >= MAXMESSAGE)
  1474. X    mctl->mc_current = 0;
  1475. X    cur = &messages[mctl->mc_current];
  1476. X    cur->m_no = mctl->mc_current;
  1477. X    cur->m_flags = group;
  1478. X    cur->m_time = 0;
  1479. X    cur->m_recpt = recip;
  1480. X    (void) sprintf(cur->m_data, "%-9s %s", address, str);
  1481. X    cur->m_flags |= MVALID;
  1482. X}
  1483. X
  1484. Xgetaddr(who)
  1485. Xchar who;
  1486. X{
  1487. X    addr = who;
  1488. X    (void) sprintf(addrmesg, " %c%x->", teamlet[me->p_team], me->p_no);
  1489. X    switch (who) {
  1490. X    case 'A':
  1491. X        (void) sprintf(&addrmesg[5], "ALL");
  1492. X        break;
  1493. X    case 'F':
  1494. X        (void) sprintf(&addrmesg[5], "FED");
  1495. X        break;
  1496. X    case 'R':
  1497. X    case 'r':
  1498. X        (void) sprintf(&addrmesg[5], "ROM");
  1499. X        break;
  1500. X    case 'K':
  1501. X    case 'k':
  1502. X        (void) sprintf(&addrmesg[5], "KLI");
  1503. X        break;
  1504. X    case 'O':
  1505. X    case 'o':
  1506. X        (void) sprintf(&addrmesg[5], "ORI");
  1507. X        break;
  1508. X    case '0':
  1509. X    case '1':
  1510. X    case '2':
  1511. X    case '3':
  1512. X    case '4':
  1513. X    case '5':
  1514. X    case '6':
  1515. X    case '7':
  1516. X    case '8':
  1517. X    case '9':
  1518. X        if (isAlive(&players[who - '0'])) {
  1519. X        (void) sprintf(&addrmesg[5], "%c%x ",
  1520. X            teamlet[players[who - '0'].p_team], who - '0');
  1521. X        }
  1522. X        else {
  1523. X        warning("Player is not in game");
  1524. X        return(-1);
  1525. X        }
  1526. X        break;
  1527. X    case 'a':
  1528. X    case 'b':
  1529. X    case 'c':
  1530. X    case 'd':
  1531. X    case 'e':
  1532. X    case 'f':
  1533. X        if (isAlive(&players[who - 'a' + 10])) {
  1534. X        (void) sprintf(&addrmesg[5], "%c%x ",
  1535. X            teamlet[players[who - 'a' + 10].p_team], who - 'a' + 10);
  1536. X        }
  1537. X        else {
  1538. X        warning("Player is not in game");
  1539. X        return(-1);
  1540. X        }
  1541. X        break;
  1542. X    default:
  1543. X        warning("Not legal recipient");
  1544. X        return(-1);
  1545. X    }
  1546. X    return(0);
  1547. X}
  1548. END_OF_smessage.c
  1549. if test 5214 -ne `wc -c <smessage.c`; then
  1550.     echo shar: \"smessage.c\" unpacked with wrong size!
  1551. fi
  1552. # end of overwriting check
  1553. fi
  1554. if test -f stats.c -a "${1}" != "-c" ; then 
  1555.   echo shar: Will not over-write existing file \"stats.c\"
  1556. else
  1557. echo shar: Extracting \"stats.c\" \(5532 characters\)
  1558. sed "s/^X//" >stats.c <<'END_OF_stats.c'
  1559. X
  1560. X/*
  1561. X
  1562. X    Copyright (c) 1986     Chris Guthrie
  1563. X
  1564. XPermission to use, copy, modify, and distribute this
  1565. Xsoftware and its documentation for any purpose and without
  1566. Xfee is hereby granted, provided that the above copyright
  1567. Xnotice appear in all copies and that both that copyright
  1568. Xnotice and this permission notice appear in supporting
  1569. Xdocumentation.  No representations are made about the
  1570. Xsuitability of this software for any purpose.  It is
  1571. Xprovided "as is" without express or implied warranty.
  1572. X
  1573. X*/
  1574. X
  1575. X#include <X/Xlib.h>
  1576. X#include <stdio.h>
  1577. X#include "defs.h"
  1578. X#include "struct.h"
  1579. X#include "data.h"
  1580. X
  1581. X#define    MIN(a,b)    (((a) < (b)) ? (a) : (b))
  1582. X#define    MAX(a,b)    (((a) > (b)) ? (a) : (b))
  1583. X
  1584. X#define    BX_OFF()    ((textWidth + 1) * dfontinfo->width + S_IBORDER)
  1585. X#define    BY_OFF(line)    ((line) * (dfontinfo->height + S_IBORDER) + S_IBORDER)
  1586. X#define    TX_OFF(len)    ((textWidth - len) * dfontinfo->width + S_IBORDER)
  1587. X#define    TY_OFF(line)    BY_OFF(line)
  1588. X
  1589. X#define STAT_WIDTH        160
  1590. X#define STAT_HEIGHT        BY_OFF(NUM_SLIDERS)
  1591. X#define STAT_BORDER        2
  1592. X#define S_IBORDER        5
  1593. X#define STAT_X            422
  1594. X#define STAT_Y            13
  1595. X
  1596. X#define SL_WID            \
  1597. X    (STAT_WIDTH - 2 * S_IBORDER - (textWidth + 1) * dfontinfo->width)
  1598. X#define SL_HEI            (dfontinfo->height)
  1599. X
  1600. X#define NUM_ELS(a)        (sizeof (a) / sizeof (*(a)))
  1601. X#define NUM_SLIDERS        NUM_ELS(sliders)
  1602. X
  1603. Xtypedef struct slider {
  1604. X    char    *label;
  1605. X    int    min, max;
  1606. X    int    low_red, high_red;
  1607. X    int    label_length;
  1608. X    int    diff;
  1609. X} SLIDER;
  1610. X
  1611. Xtypedef struct record {
  1612. X    short    *data;
  1613. X    short    last_value;
  1614. X} RECORD;
  1615. X
  1616. Xstatic SLIDER    sliders[] = {
  1617. X    { "Shields",        0,    100,    20,    100    },
  1618. X    { "Damage",        0,    100,    0,    0    },
  1619. X    { "Fuel",        0,    10000,    1000,    10000    },
  1620. X    { "Warp",        0,    9,    0,    9    },
  1621. X    { "Weapon Temp",    0,    1200,    0,    1000    },
  1622. X    { "Engine Temp",    0,    1200,    0,    1000    },
  1623. X};
  1624. X
  1625. Xstatic XAssocTable    *table;
  1626. Xstatic int        textWidth = 0;
  1627. Xstatic int        statX = STAT_X, statY = STAT_Y;
  1628. X
  1629. XinitStats(prog)
  1630. X    char    *prog;
  1631. X{
  1632. X    int    i, dummy;
  1633. X    char    *str;
  1634. X
  1635. X    if ((str = XGetDefault(prog, "stats.geometry")) != NULL)
  1636. X        XParseGeometry(str, &statX, &statY, &dummy, &dummy);
  1637. X    table = (XAssocTable *) XCreateAssocTable(8);
  1638. X    for (i = 0; i < NUM_SLIDERS; i++) {
  1639. X        sliders[i].label_length = strlen(sliders[i].label);
  1640. X        textWidth = MAX(textWidth, sliders[i].label_length);
  1641. X        sliders[i].diff = sliders[i].max - sliders[i].min;
  1642. X    }
  1643. X}
  1644. X
  1645. XWindow
  1646. XopenStats(p)
  1647. X    struct player    *p;
  1648. X{
  1649. X    Window        w;
  1650. X    RECORD        *rp;
  1651. X    extern Cursor    crosshair;
  1652. X    char         *calloc();
  1653. X
  1654. X    w = XCreateWindow(RootWindow, statX, statY, STAT_WIDTH, STAT_HEIGHT,
  1655. X        STAT_BORDER, foreTile, backTile);
  1656. X    XDefineCursor(w, crosshair);
  1657. X    rp = (RECORD *) calloc(NUM_SLIDERS, sizeof (RECORD));
  1658. X    rp[0].data = &(p->p_shield);
  1659. X    rp[1].data = &(p->p_damage);
  1660. X    rp[2].data = &(p->p_fuel);
  1661. X    rp[3].data = &(p->p_speed);
  1662. X    rp[4].data = &(p->p_wtemp);
  1663. X    rp[5].data = &(p->p_etemp);
  1664. X    XMakeAssoc(table, w, rp);
  1665. X    XSelectInput(w, ExposeWindow|ExposeRegion);
  1666. X    XMapWindow(w);
  1667. X    return (w);
  1668. X}
  1669. X
  1670. XredrawStats(w)
  1671. X    Window    w;
  1672. X{
  1673. X    int    i;
  1674. X    RECORD    *rp;
  1675. X
  1676. X    rp = (RECORD *) XLookUpAssoc(table, w);
  1677. X    if (rp == NULL) {
  1678. X        fputs("You gave redrawStats a bum window\n", stderr);
  1679. X        return;
  1680. X    }
  1681. X    XClear(w);
  1682. X    for (i = 0; i < NUM_SLIDERS; i++) {
  1683. X        rp[i].last_value = 0;
  1684. X        XText(w, TX_OFF(sliders[i].label_length), TY_OFF(i),
  1685. X            sliders[i].label, sliders[i].label_length, dfont,
  1686. X            textColor, backColor);
  1687. X        box(w, 0, BX_OFF() - 1, BY_OFF(i) - 1, SL_WID+2, SL_HEI+2,
  1688. X            borderColor, GXcopy, AllPlanes);
  1689. X    }
  1690. X}
  1691. X
  1692. XcloseStats(w)
  1693. X    Window    w;
  1694. X{
  1695. X    WindowInfo    wi;
  1696. X
  1697. X    XDeleteAssoc(table, w);
  1698. X    if (XQueryWindow(w, &wi) != 0) {
  1699. X        statX = wi.x;
  1700. X        statY = wi.y;
  1701. X    }
  1702. X    XDestroyWindow(w);
  1703. X}
  1704. X
  1705. XupdateStats(w)
  1706. X    Window        w;
  1707. X{
  1708. X    int    i, value, diff, color, old_x, new_x, wid;
  1709. X    RECORD    *rp, *r;
  1710. X    SLIDER    *s;
  1711. X
  1712. X    rp = (RECORD *) XLookUpAssoc(table, w);
  1713. X    for (i = 0; i < NUM_SLIDERS; i++) {
  1714. X        r = &rp[i];
  1715. X        s = &sliders[i];
  1716. X        value = *(r->data);
  1717. X        if (value < s->min)
  1718. X            value = s->min;
  1719. X        else if (value > s->max)
  1720. X            value = s->max;
  1721. X        if (value == r->last_value)
  1722. X            continue;
  1723. X        diff = value - r->last_value;
  1724. X        if (diff < 0)
  1725. X            color = backColor;
  1726. X        else {
  1727. X            if (value < s->low_red)
  1728. X                color = warningColor;
  1729. X            else if (value > s->high_red) {
  1730. X                color = warningColor;
  1731. X                    if (r->last_value <= s->high_red)
  1732. X                    r->last_value = 0;
  1733. X            } else {
  1734. X                color = myColor;
  1735. X                if (r->last_value < s->low_red)
  1736. X                    r->last_value = 0;
  1737. X            }
  1738. X        }
  1739. X        old_x = r->last_value * SL_WID / s->diff;
  1740. X        new_x = value * SL_WID / s->diff;
  1741. X        wid = new_x - old_x;
  1742. X        /*
  1743. X        if (wid > 0)
  1744. X            wid++;
  1745. X        else if (wid < 0)
  1746. X            wid--;
  1747. X        */
  1748. X        box(w, 1, BX_OFF() + old_x, BY_OFF(i), wid,
  1749. X            SL_HEI, color, GXcopy, AllPlanes);
  1750. X        if (diff < 0) {
  1751. X            if (r->last_value >= s->low_red && value < s->low_red)
  1752. X                box(w, 1, BX_OFF(), BY_OFF(i), new_x, SL_HEI,
  1753. X                    warningColor, GXcopy, AllPlanes);
  1754. X            else if (r->last_value > s->high_red && 
  1755. X                 value <= s->high_red)
  1756. X                box(w, 1, BX_OFF(), BY_OFF(i), new_x, SL_HEI,
  1757. X                    myColor, GXcopy, AllPlanes);
  1758. X        }
  1759. X        r->last_value = value;
  1760. X    }
  1761. X}
  1762. X
  1763. X
  1764. X            
  1765. Xbox(w, filled, x, y, wid, hei, pixel, func, planes)
  1766. X    Window    w;
  1767. X{
  1768. X    Vertex    vertex[5];
  1769. X
  1770. X    if (wid == 0 || hei == 0)
  1771. X        return;
  1772. X
  1773. X    if (filled) {
  1774. X        int    minX, minY;
  1775. X
  1776. X        minX = MIN(x, x + wid);
  1777. X        wid = ABS(wid);
  1778. X        minY = MIN(y, y + hei);
  1779. X        hei = ABS(hei);
  1780. X        XPixFill(w, minX, minY, wid + 1, hei + 1, pixel, 0,
  1781. X            func, planes);
  1782. X        return;
  1783. X    }
  1784. X
  1785. X    vertex[0].x = x;
  1786. X    vertex[0].y = y;
  1787. X    vertex[0].flags = VertexStartClosed;
  1788. X
  1789. X    vertex[1].x = x + wid;
  1790. X    vertex[1].y = y;
  1791. X    vertex[1].flags = 0;
  1792. X
  1793. X    vertex[2].x = x + wid;
  1794. X    vertex[2].y = y + hei;
  1795. X    vertex[2].flags = 0;
  1796. X
  1797. X    vertex[3].x = x;
  1798. X    vertex[3].y = y + hei;
  1799. X    vertex[3].flags = 0;
  1800. X
  1801. X    vertex[4].x = x;
  1802. X    vertex[4].y = y;
  1803. X    vertex[4].flags = VertexEndClosed;
  1804. X
  1805. X    XDraw(w, vertex, 5, 1, 1, pixel, func, planes);
  1806. X}
  1807. END_OF_stats.c
  1808. if test 5532 -ne `wc -c <stats.c`; then
  1809.     echo shar: \"stats.c\" unpacked with wrong size!
  1810. fi
  1811. # end of overwriting check
  1812. fi
  1813. if test -f struct.h -a "${1}" != "-c" ; then 
  1814.   echo shar: Will not over-write existing file \"struct.h\"
  1815. else
  1816. echo shar: Extracting \"struct.h\" \(6570 characters\)
  1817. sed "s/^X//" >struct.h <<'END_OF_struct.h'
  1818. X
  1819. X/*
  1820. X
  1821. X    Copyright (c) 1986     Chris Guthrie
  1822. X
  1823. XPermission to use, copy, modify, and distribute this
  1824. Xsoftware and its documentation for any purpose and without
  1825. Xfee is hereby granted, provided that the above copyright
  1826. Xnotice appear in all copies and that both that copyright
  1827. Xnotice and this permission notice appear in supporting
  1828. Xdocumentation.  No representations are made about the
  1829. Xsuitability of this software for any purpose.  It is
  1830. Xprovided "as is" without express or implied warranty.
  1831. X
  1832. X*/
  1833. X
  1834. Xstruct status {
  1835. X    int active;
  1836. X};
  1837. X
  1838. X#define PFREE 0
  1839. X#define POUTFIT 1
  1840. X#define PALIVE 2
  1841. X#define PEXPLODE 3
  1842. X#define PDEAD 4
  1843. X
  1844. X#define PFSHIELD    0x0001
  1845. X#define PFREPAIR    0x0002
  1846. X#define PFBOMB        0x0004
  1847. X#define PFORBIT        0x0008
  1848. X#define PFCLOAK        0x0010
  1849. X#define PFWEP        0x0020
  1850. X#define PFENG        0x0040
  1851. X#define PFROBOT        0x0080
  1852. X#define PFBEAMUP    0x0100
  1853. X#define PFBEAMDOWN    0x0200
  1854. X#define PFSELFDEST    0x0400
  1855. X#define PFGREEN        0x0800
  1856. X#define PFYELLOW    0x1000
  1857. X#define PFRED        0x2000
  1858. X#define PFPLOCK        0x4000        /* Locked on a player */
  1859. X#define PFPLLOCK    0x8000        /* Locked on a planet */
  1860. X#define PFCOPILOT    0x10000        /* Allow copilots */
  1861. X#define PFWAR        0x20000        /* computer reprogramming for war */
  1862. X#define PFPRACTR    0x40000        /* practice type robot (no kills) */
  1863. X
  1864. X#define KQUIT        0x01        /* Player quit */
  1865. X#define KTORP        0x02        /* killed by torp */
  1866. X#define KPHASER        0x03        /* killed by phaser */
  1867. X#define KPLANET        0x04        /* killed by planet */
  1868. X#define KSHIP        0x05        /* killed by other ship */
  1869. X#define KDAEMON        0x06        /* killed by dying daemon */
  1870. X#define KWINNER        0x07        /* killed by a winner */
  1871. X#define KGHOST        0x08        /* killed because a ghost */
  1872. X
  1873. Xstruct ship {
  1874. X    int s_turns;
  1875. X    short s_accs;
  1876. X    short s_torpdamage;
  1877. X    short s_phaserdamage;
  1878. X    short s_torpspeed;
  1879. X    short s_maxspeed;
  1880. X    short s_repair;
  1881. X    short s_maxfuel;
  1882. X    short s_torpcost;
  1883. X    short s_phasercost;
  1884. X    short s_detcost;
  1885. X    short s_warpcost;
  1886. X    short s_cloakcost;
  1887. X    short s_recharge;
  1888. X    int s_accint;
  1889. X    int s_decint;
  1890. X    short s_maxarmies;
  1891. X};
  1892. X
  1893. Xstruct stats {
  1894. X    int st_time;        /* real time in game */
  1895. X    int st_cpu;            /* cpu time in game */
  1896. X    double st_kills;        /* how many kills */
  1897. X    int st_losses;        /* times killed */
  1898. X    double st_maxkills;        /* times killed */
  1899. X    int st_entries;        /* times in game */
  1900. X    int st_conqs;        /* times galaxy taken over */
  1901. X    int st_coups;        /* retaken home planet */
  1902. X    int st_torps;        /* torps launched */
  1903. X    int st_phasers;        /* phasers fired */
  1904. X    int st_armsbomb;        /* armies bombed */
  1905. X    int st_armsship;        /* ship board armies killed */
  1906. X    int st_planets;        /* planets conquered */
  1907. X    int st_genocides;        /* races genocided */
  1908. X};
  1909. X
  1910. Xstruct player {
  1911. X    int p_no;
  1912. X    int p_updates;        /* Number of updates ship has survived */
  1913. X    int p_status;        /* Player status */
  1914. X    unsigned int p_flags;    /* Player flags */
  1915. X    char p_name[16];
  1916. X    char p_login[16];
  1917. X    char p_monitor[16];        /* Monitor being played on */
  1918. X    char p_mapchars[2];        /* Cache for map window image */
  1919. X    struct ship p_ship;        /* Personal ship statistics */
  1920. X    int p_x;
  1921. X    int p_y;
  1922. X    unsigned char p_dir;    /* Real direction */
  1923. X    unsigned char p_desdir;    /* desired direction */
  1924. X    int p_subdir;        /* fraction direction change */
  1925. X    short p_speed;        /* Real speed */
  1926. X    short p_desspeed;        /* Desired speed */
  1927. X    int p_subspeed;        /* Fractional speed */
  1928. X    short p_team;            /* Team I'm on */
  1929. X    short p_damage;        /* Current damage */
  1930. X    int p_subdamage;        /* Fractional damage repair */
  1931. X    short p_shield;        /* Current shield power */
  1932. X    int p_subshield;        /* Fractional shield recharge */
  1933. X    short p_ntorp;        /* Number of torps flying */
  1934. X    char p_hostile;        /* Who my torps will hurt */
  1935. X    char p_swar;        /* Who am I at sticky war with */
  1936. X    float p_kills;        /* Enemies killed */
  1937. X    short p_planet;        /* Planet orbiting or locked onto */
  1938. X    short p_playerl;        /* Player locked onto */
  1939. X    short p_armies;
  1940. X    short p_fuel;
  1941. X    short p_explode;        /* Keeps track of final explosion */
  1942. X    short p_etemp;
  1943. X    short p_etime;
  1944. X    short p_wtemp;
  1945. X    short p_wtime;
  1946. X    short p_whydead;        /* Tells you why you died */
  1947. X    short p_whodead;        /* Tells you who killed you */
  1948. X    struct stats p_stats;    /* player statistics */
  1949. X    int p_ghostbuster;
  1950. X};
  1951. X
  1952. X/* Torpedo states */
  1953. X
  1954. X#define TFREE 0
  1955. X#define TMOVE 1
  1956. X#define TEXPLODE 2
  1957. X#define TDET 3
  1958. X#define TOFF 4
  1959. X#define TSTRAIGHT 5        /* Non-wobbling torp */
  1960. X
  1961. Xstruct torp {
  1962. X    int t_no;
  1963. X    int t_status;        /* State information */
  1964. X    int t_owner;
  1965. X    int t_x;
  1966. X    int t_y;
  1967. X    unsigned char t_dir;    /* direction */
  1968. X    int t_damage;        /* damage for direct hit */
  1969. X    int t_speed;        /* Moving speed */
  1970. X    int t_fuse;            /* Life left in current state */
  1971. X    char t_war;            /* enemies */
  1972. X    char t_team;        /* launching team */
  1973. X};
  1974. X
  1975. X#define PHFREE 0x00
  1976. X#define PHHIT  0x01
  1977. X#define PHMISS 0x02
  1978. X
  1979. Xstruct phaser {
  1980. X    int ph_status;        /* What it's up to */
  1981. X    unsigned char ph_dir;    /* direction */
  1982. X    int ph_target;        /* Who's being hit (for drawing) */
  1983. X    int ph_fuse;        /* Life left for drawing */
  1984. X    int ph_damage;        /* Damage inflicted on victim */
  1985. X};
  1986. X
  1987. X/* An important note concerning planets:  The game assumes that
  1988. X    the planets are in a 'known' order.  Ten planets per team,
  1989. X    the first being the home planet.
  1990. X*/
  1991. X
  1992. X/* the lower bits represent the original owning team */
  1993. X#define PLREPAIR 0x010
  1994. X#define PLFUEL 0x020
  1995. X#define PLREDRAW 0x040        /* Player close for redraw */
  1996. X#define PLHOME 0x080        /* home planet for a given team */
  1997. X#define PLCOUP 0x100        /* Coup has occured */
  1998. X
  1999. Xstruct planet {
  2000. X    int pl_no;
  2001. X    int pl_flags;        /* State information */
  2002. X    int pl_owner;
  2003. X    int pl_x;
  2004. X    int pl_y;
  2005. X    char pl_name[16];
  2006. X    int pl_namelen;        /* Cuts back on strlen's */
  2007. X    int pl_armies;
  2008. X    int pl_info;        /* Teams which have info on planets */
  2009. X    int pl_deadtime;        /* Time before planet will support life */
  2010. X    int pl_couptime;        /* Time before coup may take place */
  2011. X};
  2012. X
  2013. X#define MVALID 0x01
  2014. X#define MINDIV 0x02
  2015. X#define MTEAM  0x04
  2016. X#define MALL   0x08
  2017. X
  2018. Xstruct message {
  2019. X    int m_no;
  2020. X    int m_flags;
  2021. X    int m_time;
  2022. X    int m_recpt;
  2023. X    char m_from[3];
  2024. X    char m_to[3];
  2025. X    char m_data[80];
  2026. X};
  2027. X
  2028. X/* message control structure */
  2029. X
  2030. Xstruct mctl {
  2031. X    int mc_current;
  2032. X};
  2033. X
  2034. X/* This is a structure used for objects returned by mouse pointing */
  2035. X
  2036. X#define PLANETTYPE 0x1
  2037. X#define PLAYERTYPE 0x2
  2038. X
  2039. Xstruct obtype {
  2040. X    int o_type;
  2041. X    int o_num;
  2042. X};
  2043. X
  2044. Xstruct memory {
  2045. X    struct player    players[MAXPLAYER];
  2046. X    struct torp        torps[MAXPLAYER * MAXTORP];
  2047. X    struct status    status[1];
  2048. X    struct planet    planets[MAXPLANETS];
  2049. X    struct phaser    phasers[MAXPLAYER];
  2050. X    struct mctl        mctl[1];
  2051. X    struct message    messages[MAXMESSAGE];
  2052. X};
  2053. END_OF_struct.h
  2054. if test 6570 -ne `wc -c <struct.h`; then
  2055.     echo shar: \"struct.h\" unpacked with wrong size!
  2056. fi
  2057. # end of overwriting check
  2058. fi
  2059. if test -f war.c -a "${1}" != "-c" ; then 
  2060.   echo shar: Will not over-write existing file \"war.c\"
  2061. else
  2062. echo shar: Extracting \"war.c\" \(4407 characters\)
  2063. sed "s/^X//" >war.c <<'END_OF_war.c'
  2064. X
  2065. X/*
  2066. X
  2067. X    Copyright (c) 1986     Chris Guthrie
  2068. X
  2069. XPermission to use, copy, modify, and distribute this
  2070. Xsoftware and its documentation for any purpose and without
  2071. Xfee is hereby granted, provided that the above copyright
  2072. Xnotice appear in all copies and that both that copyright
  2073. Xnotice and this permission notice appear in supporting
  2074. Xdocumentation.  No representations are made about the
  2075. Xsuitability of this software for any purpose.  It is
  2076. Xprovided "as is" without express or implied warranty.
  2077. X
  2078. X*/
  2079. X
  2080. X#include <X/Xlib.h>
  2081. X#include <stdio.h>
  2082. X#include <math.h>
  2083. X#include <signal.h>
  2084. X#include "defs.h"
  2085. X#include "struct.h"
  2086. X#include "data.h"
  2087. X
  2088. X#define WINSIDE 500
  2089. X
  2090. Xstatic int newhostile;
  2091. Xstatic int reprogram;
  2092. X
  2093. X/* Set up the war window and map it */
  2094. Xstatic char *feds = "FED - ";
  2095. Xstatic char *roms = "ROM - ";
  2096. Xstatic char *klis = "KLI - ";
  2097. Xstatic char *oris = "ORI - ";
  2098. Xstatic char *gos = "  Re-program";
  2099. Xstatic char *exs = "  Exit - no change";
  2100. Xstatic char *peaces = "Peace";
  2101. Xstatic char *hostiles = "Hostile";
  2102. Xstatic char *wars = "War";
  2103. X
  2104. Xwarwindow()
  2105. X{
  2106. X    XMapWindow(war);
  2107. X    newhostile = me->p_hostile;
  2108. X    reprogram = 0;
  2109. X    warrefresh();
  2110. X}
  2111. X
  2112. Xwarrefresh()
  2113. X{
  2114. X    fillwin(warf, feds, newhostile, me->p_swar, FED);
  2115. X    fillwin(warr, roms, newhostile, me->p_swar, ROM);
  2116. X    fillwin(wark, klis, newhostile, me->p_swar, KLI);
  2117. X    fillwin(waro, oris, newhostile, me->p_swar, ORI);
  2118. X    XText(wargo, 0, dfontinfo->height / 2, gos, strlen(gos), dfont,
  2119. X    textColor, backColor);
  2120. X    XText(warno, 0, dfontinfo->height / 2, exs, strlen(exs), dfont,
  2121. X    textColor, backColor);
  2122. X}
  2123. X
  2124. Xfillwin(win, string, hostile, warbits, team)
  2125. XWindow win;
  2126. Xchar *string;
  2127. Xint hostile, warbits;
  2128. Xint team;
  2129. X{
  2130. X    char buf[80];
  2131. X    XPixSet(win, 0, dfontinfo->height / 2, dfontinfo->width * 20,
  2132. X    dfontinfo->height, backColor); 
  2133. X    if (team & warbits) {
  2134. X    (void) sprintf(buf, "  %s%s", string, wars);
  2135. X    XText(win, 0, dfontinfo->height / 2, buf, strlen(buf), dfont,
  2136. X        rColor, backColor);
  2137. X    }
  2138. X    else if (team & hostile) {
  2139. X    (void) sprintf(buf, "  %s%s", string, hostiles);
  2140. X    XText(win, 0, dfontinfo->height / 2, buf, strlen(buf), dfont,
  2141. X        yColor, backColor);
  2142. X    }
  2143. X    else {
  2144. X    (void) sprintf(buf, "  %s%s", string, peaces);
  2145. X    XText(win, 0, dfontinfo->height / 2, buf, strlen(buf), dfont,
  2146. X        gColor, backColor);
  2147. X    }
  2148. X}
  2149. X
  2150. Xwaraction(data)
  2151. XXKeyOrButtonEvent *data;
  2152. X{
  2153. X    int changes;
  2154. X
  2155. X    if ((data->window != warno) && (watch)) {
  2156. X    warning("can't modify war settings from watch");
  2157. X    return;
  2158. X    }
  2159. X    if (data->window == warf) {
  2160. X    if (me->p_swar & FED) {
  2161. X        warning("You are already at war with the Federation");
  2162. X        XFeep(0);
  2163. X    }
  2164. X    else {
  2165. X        newhostile ^= FED;
  2166. X    }
  2167. X    }
  2168. X    if (data->window == warr) {
  2169. X    if (me->p_swar & ROM) {
  2170. X        warning("You are already at war with the Romulans");
  2171. X        XFeep(0);
  2172. X    }
  2173. X    else {
  2174. X        newhostile ^= ROM;
  2175. X    }
  2176. X    }
  2177. X    if (data->window == wark) {
  2178. X    if (me->p_swar & KLI) {
  2179. X        warning("You are already at war with the Klingons");
  2180. X        XFeep(0);
  2181. X    }
  2182. X    else {
  2183. X        newhostile ^= KLI;
  2184. X    }
  2185. X    }
  2186. X    if (data->window == waro) {
  2187. X    if (me->p_swar & ORI) {
  2188. X        warning("You are already at war with the Orions");
  2189. X        XFeep(0);
  2190. X    }
  2191. X    else {
  2192. X        newhostile ^= ORI;
  2193. X    }
  2194. X    }
  2195. X    warrefresh();
  2196. X
  2197. X    if (data->window == wargo) {
  2198. X    changes = me->p_hostile ^ newhostile;
  2199. X    if (changes & FED) {
  2200. X        sendwarn("Federation", newhostile & FED, FED);
  2201. X    }
  2202. X    if (changes & ROM) {
  2203. X        sendwarn("Romulans", newhostile & ROM, ROM);
  2204. X    }
  2205. X    if (changes & KLI) {
  2206. X        sendwarn("Klingons", newhostile & KLI, KLI);
  2207. X    }
  2208. X    if (changes & ORI) {
  2209. X        sendwarn("Orions", newhostile & ORI, ORI);
  2210. X    }
  2211. X    me->p_hostile = newhostile;
  2212. X    if (reprogram) {
  2213. X        delay = me->p_updates + 100;
  2214. X        me->p_flags |= PFWAR;    /* stop copilots, mostly */
  2215. X        warning("Pausing ten seconds to re-program battle computers.");
  2216. X    }
  2217. X    XUnmapWindow(war);
  2218. X    return;
  2219. X    }
  2220. X
  2221. X    if (data->window == warno) {
  2222. X    XUnmapWindow(war);
  2223. X    return;
  2224. X    }
  2225. X}
  2226. X
  2227. Xsendwarn(string, atwar, team)
  2228. Xchar *string;
  2229. Xint atwar;
  2230. Xint team;
  2231. X{
  2232. X    char buf[BUFSIZ];
  2233. X    char addrbuf[10];
  2234. X
  2235. X    if (atwar) {
  2236. X    (void) sprintf(buf, "%s (%c%x) declaring war on the %s",
  2237. X        me->p_name,
  2238. X        teamlet[me->p_team],
  2239. X        me->p_no,
  2240. X        string);
  2241. X    reprogram = 1;
  2242. X    }
  2243. X    else {
  2244. X    (void) sprintf(buf, "%s (%c%x) declaring peace with the %s",
  2245. X        me->p_name,
  2246. X        teamlet[me->p_team],
  2247. X        me->p_no,
  2248. X        string);
  2249. X    }
  2250. X
  2251. X    (void) sprintf(addrbuf, " %c%x->%-3s",
  2252. X    teamlet[me->p_team],
  2253. X    me->p_no,
  2254. X    teamshort[team]);
  2255. X    pmessage(buf, team, MTEAM, addrbuf);
  2256. X}
  2257. END_OF_war.c
  2258. if test 4407 -ne `wc -c <war.c`; then
  2259.     echo shar: \"war.c\" unpacked with wrong size!
  2260. fi
  2261. # end of overwriting check
  2262. fi
  2263. echo shar: End of archive 4 \(of 6\).
  2264. cp /dev/null ark4isdone
  2265. MISSING=""
  2266. for I in 1 2 3 4 5 6 ; do
  2267.     if test ! -f ark${I}isdone ; then
  2268.     MISSING="${MISSING} ${I}"
  2269.     fi
  2270. done
  2271. if test "${MISSING}" = "" ; then
  2272.     echo You have unpacked all 6 archives.
  2273.     rm -f ark[1-9]isdone
  2274. else
  2275.     echo You still need to unpack the following archives:
  2276.     echo "        " ${MISSING}
  2277. fi
  2278. ##  End of shell archive.
  2279. exit 0
  2280.  
  2281.