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

  1.  
  2. Article 51 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: v01i077:  xtrek - mulitplayer space war for X-windows, Part05/06
  7. Message-ID: <1370@tekred.TEK.COM>
  8. Date: 2 Jul 87 20:55:27 GMT
  9. Sender: billr@tekred.TEK.COM
  10. Lines: 2126
  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 77
  15. Archive-name: xtrek/Part05
  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 5 (of 6)."
  25. # Contents:  clock.bitmap colors.c coup.c data.c data.h death.c defs.h
  26. #   dmessage.c enter.c interface.c orbit.c phaser.c planetlist.c
  27. #   planets.h robot.c scores.c startdaemon.c torp.c util.c
  28. # Wrapped by billr@tekred on Thu Jul  2 10:26:34 1987
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f clock.bitmap -a "${1}" != "-c" ; then 
  31.   echo shar: Will not over-write existing file \"clock.bitmap\"
  32. else
  33. echo shar: Extracting \"clock.bitmap\" \(1338 characters\)
  34. sed "s/^X//" >clock.bitmap <<'END_OF_clock.bitmap'
  35. X#define clock_width 48
  36. X#define clock_height 48
  37. Xstatic short clock_bits[] = {
  38. X   0x0000, 0x0ff8, 0x0000, 0x8000,
  39. X   0xf087, 0x0000, 0x6000, 0x0080,
  40. X   0x0003, 0x1800, 0x0080, 0x000c,
  41. X   0x1400, 0x0000, 0x0010, 0x2300,
  42. X   0x0000, 0x0068, 0x0080, 0x0000,
  43. X   0x0084, 0x0040, 0x0000, 0x0100,
  44. X   0x0020, 0x0000, 0x0200, 0x0020,
  45. X   0x0000, 0x0200, 0x0010, 0x0000,
  46. X   0x0400, 0x0018, 0x0000, 0x0800,
  47. X   0x0028, 0x0000, 0x0c00, 0x0004,
  48. X   0x0000, 0x1200, 0x0004, 0x0000,
  49. X   0x1000, 0x0002, 0x0000, 0x2000,
  50. X   0x0002, 0x0000, 0x2000, 0x0002,
  51. X   0x0000, 0x2000, 0x0002, 0x0000,
  52. X   0x2000, 0x0001, 0x0000, 0x4000,
  53. X   0x0001, 0x0000, 0x4000, 0x0001,
  54. X   0x0000, 0x4000, 0x0001, 0x0000,
  55. X   0x4000, 0x000f, 0x0080, 0x7800,
  56. X   0x0001, 0x0000, 0x4000, 0x0001,
  57. X   0x0000, 0x4000, 0x0001, 0x0000,
  58. X   0x4000, 0x0001, 0x0000, 0x4000,
  59. X   0x0002, 0x0000, 0x2000, 0x0002,
  60. X   0x0000, 0x2000, 0x4002, 0x5ddd,
  61. X   0x2001, 0x8002, 0xccc8, 0x2000,
  62. X   0x4004, 0x5d49, 0x1001, 0x0004,
  63. X   0x0000, 0x1000, 0x0028, 0x0000,
  64. X   0x0a00, 0x0018, 0x0000, 0x0c00,
  65. X   0x0010, 0x0000, 0x0400, 0x0020,
  66. X   0x0000, 0x0200, 0x0020, 0x0000,
  67. X   0x0200, 0x0040, 0x0000, 0x0100,
  68. X   0x0080, 0x0000, 0x0080, 0x2300,
  69. X   0x0000, 0x0062, 0x1400, 0x0000,
  70. X   0x0014, 0x1800, 0x0080, 0x000c,
  71. X   0x6000, 0x0080, 0x0003, 0x8000,
  72. X   0xf087, 0x0000, 0x0000, 0x0ff8,
  73. X   0x0000, 0x0000, 0x0000, 0x0000};
  74. END_OF_clock.bitmap
  75. if test 1338 -ne `wc -c <clock.bitmap`; then
  76.     echo shar: \"clock.bitmap\" unpacked with wrong size!
  77. fi
  78. # end of overwriting check
  79. fi
  80. if test -f colors.c -a "${1}" != "-c" ; then 
  81.   echo shar: Will not over-write existing file \"colors.c\"
  82. else
  83. echo shar: Extracting \"colors.c\" \(2570 characters\)
  84. sed "s/^X//" >colors.c <<'END_OF_colors.c'
  85. X
  86. X/*
  87. X
  88. X    Copyright (c) 1986     Chris Guthrie
  89. X
  90. XPermission to use, copy, modify, and distribute this
  91. Xsoftware and its documentation for any purpose and without
  92. Xfee is hereby granted, provided that the above copyright
  93. Xnotice appear in all copies and that both that copyright
  94. Xnotice and this permission notice appear in supporting
  95. Xdocumentation.  No representations are made about the
  96. Xsuitability of this software for any purpose.  It is
  97. Xprovided "as is" without express or implied warranty.
  98. X
  99. X*/
  100. X
  101. X#include <stdio.h>
  102. X#include <X/Xlib.h>
  103. X#include <string.h>
  104. X#include "data.h"
  105. X
  106. Xtypedef struct assoc {
  107. X    char    *str;
  108. X    int    *colorp;
  109. X    int    bWDef;
  110. X    char    *colorDef;
  111. X} ASSOC;
  112. X
  113. XASSOC    assoc[] = {
  114. X    { "border",    &borderColor,    WhitePixel,    "blue"        },
  115. X    { "background",    &backColor,    BlackPixel,    "black"        },
  116. X    { "text",    &textColor,    WhitePixel,    "white"        },
  117. X    { "nobody",    &shipCol[0],    WhitePixel,    "blue"    },
  118. X    { "fed",    &shipCol[1],    WhitePixel,    "yellow",    },
  119. X    { "rom",    &shipCol[2],    WhitePixel,    "red",        },
  120. X    { "kli",    &shipCol[3],    WhitePixel,    "green",    },
  121. X    { "ori",    &shipCol[4],    WhitePixel,    "#0ff",    },
  122. X    { "warning",    &warningColor,    WhitePixel,    "red"        },
  123. X    { "unknown",    &unColor,    WhitePixel,    "light grey"    },
  124. X    { "ralert",    &rColor,    WhitePixel,    "red"        },
  125. X    { "yalert",    &yColor,    WhitePixel,    "yellow"    },
  126. X    { "galert",    &gColor,    WhitePixel,    "green"        },
  127. X    { "me",        &myColor,    WhitePixel,    "white"        }
  128. X};
  129. X
  130. XgetColorDefs(prog)
  131. X    char    *prog;
  132. X{
  133. X    int    i, invert = 0;
  134. X    char    *color;
  135. X    Color    def;
  136. X
  137. X    if (DisplayCells() <= 2) {    /* b & w */
  138. X        invert = booleanDefault(prog, "reverseVideo");
  139. X        for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++)
  140. X            *assoc[i].colorp = 
  141. X                invert ? !assoc[i].bWDef : assoc[i].bWDef;
  142. X    } else {
  143. X        for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++) {
  144. X            if ((color = XGetDefault(prog, assoc[i].str)) == NULL)
  145. X                color = assoc[i].colorDef;
  146. X            XParseColor(color, &def);
  147. X            XGetHardwareColor(&def);
  148. X            *assoc[i].colorp = def.pixel;
  149. X        }
  150. X    }
  151. X}
  152. X
  153. XbooleanDefault(prog, def)
  154. X    char    *prog, *def;
  155. X{
  156. X    char    *str;
  157. X
  158. X    if ((str = XGetDefault(prog, def)) != NULL && strcmp(str, "on") == 0)
  159. X        return (1);
  160. X    else
  161. X        return (0);
  162. X}
  163. X
  164. X#define iswhite(c)    ((c) == ' ' || c == '\t' || (c) == ',')
  165. X
  166. XarrayDefault(prog, def, sizeP, sp)
  167. X    char    *prog, *def;
  168. X    int    *sizeP;
  169. X    short    *sp;
  170. X{
  171. X    int    max;
  172. X    char    *str;
  173. X
  174. X    str = XGetDefault(prog, def);
  175. X    if (str == NULL)
  176. X        return (-1);
  177. X    max = *sizeP;
  178. X    *sizeP = 0;
  179. X
  180. X    for (;;) {
  181. X        while (iswhite(*str))
  182. X            str++;
  183. X        if (*str == '\0')
  184. X            break;
  185. X        if (++(*sizeP) > max)
  186. X            return (-1);
  187. X        if (sscanf(str, "0x%hx", &sp[*sizeP]) != 1)
  188. X            return (-1);
  189. X        while (!iswhite(*str) && *str != '\0')
  190. X            str++;
  191. X    }
  192. X    return (0);
  193. X}
  194. END_OF_colors.c
  195. if test 2570 -ne `wc -c <colors.c`; then
  196.     echo shar: \"colors.c\" unpacked with wrong size!
  197. fi
  198. # end of overwriting check
  199. fi
  200. if test -f coup.c -a "${1}" != "-c" ; then 
  201.   echo shar: Will not over-write existing file \"coup.c\"
  202. else
  203. echo shar: Extracting \"coup.c\" \(1691 characters\)
  204. sed "s/^X//" >coup.c <<'END_OF_coup.c'
  205. X
  206. X/*
  207. X
  208. X    Copyright (c) 1986     Chris Guthrie
  209. X
  210. XPermission to use, copy, modify, and distribute this
  211. Xsoftware and its documentation for any purpose and without
  212. Xfee is hereby granted, provided that the above copyright
  213. Xnotice appear in all copies and that both that copyright
  214. Xnotice and this permission notice appear in supporting
  215. Xdocumentation.  No representations are made about the
  216. Xsuitability of this software for any purpose.  It is
  217. Xprovided "as is" without express or implied warranty.
  218. X
  219. X*/
  220. X
  221. X
  222. X#include <X/Xlib.h>
  223. X
  224. X#include <stdio.h>
  225. X#include <sys/types.h>
  226. X#include <sys/ipc.h>
  227. X#include <sys/shm.h>
  228. X#include "defs.h"
  229. X#include "struct.h"
  230. X#include "data.h"
  231. X
  232. X/* throw a coup */
  233. X
  234. Xcoup()
  235. X{
  236. X    register int i;
  237. X    register struct planet *l;
  238. X
  239. X    if (me->p_kills < 1.0) {
  240. X    warning("You must have one kill to throw a coup");
  241. X    return;
  242. X    }
  243. X    if (!(me->p_flags & PFORBIT)) {
  244. X    warning("You must orbit your home planet to throw a coup");
  245. X    return;
  246. X    }
  247. X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
  248. X    if ((l->pl_owner == me->p_team) && (l->pl_armies > 0)) {
  249. X        warning("You already own a planet!!!");
  250. X        return;
  251. X    }
  252. X    }
  253. X    l = &planets[me->p_planet];
  254. X
  255. X    if ((!(l->pl_flags & PLHOME)) || ((l->pl_flags & ALLTEAM) != me->p_team)) {
  256. X    warning("You must orbit your home planet to throw a coup");
  257. X    return;
  258. X    }
  259. X
  260. X    if (l->pl_armies > 4) {
  261. X    warning("Too many armies on planet to throw a coup");
  262. X    return;
  263. X    }
  264. X
  265. X    if (l->pl_couptime > 0) {
  266. X    warning("Planet not yet ready for a coup");
  267. X    return;
  268. X    }
  269. X
  270. X    if (l->pl_flags & PLCOUP) { /* Avoid race conditions */
  271. X    return;
  272. X    }
  273. X
  274. X    /* the cases are now met.  We can have a coup. */
  275. X
  276. X    l->pl_flags |= PLCOUP;
  277. X    mystats->st_coups++;
  278. X}
  279. END_OF_coup.c
  280. if test 1691 -ne `wc -c <coup.c`; then
  281.     echo shar: \"coup.c\" unpacked with wrong size!
  282. fi
  283. # end of overwriting check
  284. fi
  285. if test -f data.c -a "${1}" != "-c" ; then 
  286.   echo shar: Will not over-write existing file \"data.c\"
  287. else
  288. echo shar: Extracting \"data.c\" \(1881 characters\)
  289. sed "s/^X//" >data.c <<'END_OF_data.c'
  290. X
  291. X/*
  292. X
  293. X    Copyright (c) 1986     Chris Guthrie
  294. X
  295. XPermission to use, copy, modify, and distribute this
  296. Xsoftware and its documentation for any purpose and without
  297. Xfee is hereby granted, provided that the above copyright
  298. Xnotice appear in all copies and that both that copyright
  299. Xnotice and this permission notice appear in supporting
  300. Xdocumentation.  No representations are made about the
  301. Xsuitability of this software for any purpose.  It is
  302. Xprovided "as is" without express or implied warranty.
  303. X
  304. X*/
  305. X
  306. X#include <X/Xlib.h>
  307. X#include "defs.h"
  308. X#include "struct.h"
  309. X#include "data.h"
  310. X
  311. Xstruct player *players;
  312. Xstruct player *me;
  313. Xstruct torp *torps;
  314. Xstruct status *status;
  315. Xstruct ship *myship;
  316. Xstruct stats *mystats;
  317. Xstruct planet *planets;
  318. Xstruct phaser *phasers;
  319. Xstruct message *messages;
  320. Xstruct mctl *mctl;
  321. X
  322. Xint    oldalert = PFGREEN;    /* Avoid changing more than we have to */
  323. Xint     remap[9] = { 0, 1, 2, -1, 3, -1, -1, -1, 4 };
  324. Xint    messpend;
  325. Xint    lastcount;
  326. Xint    mdisplayed;
  327. Xint    redrawall;
  328. Xint    copilot = 0;
  329. Xint    nopilot = 1;
  330. Xint    watch = 0;
  331. Xint    selfdest;
  332. Xint    udcounter;
  333. Xint    lastm;
  334. Xint    delay;
  335. Xint    mapmode = 1; 
  336. Xint    namemode = 1; 
  337. Xint    statmode = 1;
  338. Xint    showStats;
  339. Xint    showShields;
  340. Xint    warncount = 0;
  341. Xint    warntimer = -1;
  342. Xint    infomapped = 0;
  343. Xint    mustexit = 0;
  344. X
  345. Xlong    start_time;
  346. X
  347. Xdouble    oldmax = 0.0;
  348. X
  349. Xdouble    Sin[], Cos[];         /* Initialized in sintab.c */
  350. X
  351. XPixmap    foreTile, backTile, rTile, yTile, gTile, stippleTile;
  352. X
  353. Xint    borderColor, backColor, textColor, myColor, warningColor, shipCol[5],
  354. X    rColor, yColor, gColor, unColor;
  355. X
  356. Xchar teamlet[] = {'I', 'F', 'R', 'X', 'K', 'X', 'X', 'X', 'O'};
  357. Xchar *teamshort[9] = {"IND", "FED", "ROM", "X", "KLI", "X", "X", "X", "ORI"};
  358. X
  359. XDisplay        *display;
  360. X
  361. XFont         dfont, bfont, ifont;
  362. XFontInfo     *dfontinfo, *bfontinfo, *ifontinfo;
  363. X
  364. XWindow    w, mapw, statwin, baseWin, messagew, infow, iconWin, tstatw,
  365. X    war, warf, warr, wark, waro, wargo, warno, warnw, helpWin,
  366. X    planetw, playerw;
  367. END_OF_data.c
  368. if test 1881 -ne `wc -c <data.c`; then
  369.     echo shar: \"data.c\" unpacked with wrong size!
  370. fi
  371. # end of overwriting check
  372. fi
  373. if test -f data.h -a "${1}" != "-c" ; then 
  374.   echo shar: Will not over-write existing file \"data.h\"
  375. else
  376. echo shar: Extracting \"data.h\" \(1830 characters\)
  377. sed "s/^X//" >data.h <<'END_OF_data.h'
  378. X
  379. X/*
  380. X
  381. X    Copyright (c) 1986     Chris Guthrie
  382. X
  383. XPermission to use, copy, modify, and distribute this
  384. Xsoftware and its documentation for any purpose and without
  385. Xfee is hereby granted, provided that the above copyright
  386. Xnotice appear in all copies and that both that copyright
  387. Xnotice and this permission notice appear in supporting
  388. Xdocumentation.  No representations are made about the
  389. Xsuitability of this software for any purpose.  It is
  390. Xprovided "as is" without express or implied warranty.
  391. X
  392. X*/
  393. X
  394. Xextern struct player *players;
  395. Xextern struct player *me;
  396. Xextern struct torp *torps;
  397. Xextern struct status *status;
  398. Xextern struct ship *myship;
  399. Xextern struct stats *mystats;
  400. Xextern struct planet *planets;
  401. Xextern struct phaser *phasers;
  402. Xextern struct message *messages;
  403. Xextern struct mctl *mctl;
  404. X
  405. Xextern int oldalert;
  406. Xextern int remap[];
  407. Xextern int udcounter;
  408. Xextern int messpend;
  409. Xextern int lastcount;
  410. Xextern int mdisplayed;
  411. Xextern int redrawall;
  412. Xextern int copilot;
  413. Xextern int nopilot;
  414. Xextern int watch;
  415. Xextern int selfdest;
  416. Xextern int lastm;
  417. Xextern int delay;
  418. Xextern int mapmode; 
  419. Xextern int namemode; 
  420. Xextern int statmode;
  421. Xextern int showShields;
  422. Xextern int showStats;
  423. Xextern int warncount;
  424. Xextern int warntimer;
  425. Xextern int infomapped;
  426. Xextern int mustexit;
  427. X
  428. Xextern long    start_time;
  429. X
  430. Xextern double    oldmax;
  431. Xextern double    Sin[], Cos[];
  432. X
  433. Xextern Pixmap    foreTile, backTile, rTile, yTile, gTile, stippleTile;
  434. X
  435. Xextern int    borderColor, backColor, textColor, myColor, 
  436. X        warningColor, shipCol[5], rColor, yColor,
  437. X        gColor, unColor;
  438. X
  439. Xextern char teamlet[];
  440. Xextern char *teamshort[];
  441. X
  442. Xextern Display    *display;
  443. X
  444. Xextern Font dfont, bfont, ifont;
  445. Xextern FontInfo *dfontinfo, *bfontinfo, *ifontinfo;
  446. X
  447. Xextern Window    w, mapw, statwin, baseWin, messagew, infow, iconWin, tstatw,
  448. X        war, warf, warr, wark, waro, wargo, warno, warnw, helpWin,
  449. X        planetw, playerw;
  450. END_OF_data.h
  451. if test 1830 -ne `wc -c <data.h`; then
  452.     echo shar: \"data.h\" unpacked with wrong size!
  453. fi
  454. # end of overwriting check
  455. fi
  456. if test -f death.c -a "${1}" != "-c" ; then 
  457.   echo shar: Will not over-write existing file \"death.c\"
  458. else
  459. echo shar: Extracting \"death.c\" \(4146 characters\)
  460. sed "s/^X//" >death.c <<'END_OF_death.c'
  461. X
  462. X/*
  463. X
  464. X#ifdef HPUX
  465. X#include <time.h>
  466. X#else HPUX
  467. X#include <sys/time.h>
  468. X#endif HPUX
  469. X    Copyright (c) 1986     Chris Guthrie
  470. X
  471. XPermission to use, copy, modify, and distribute this
  472. Xsoftware and its documentation for any purpose and without
  473. Xfee is hereby granted, provided that the above copyright
  474. Xnotice appear in all copies and that both that copyright
  475. Xnotice and this permission notice appear in supporting
  476. Xdocumentation.  No representations are made about the
  477. Xsuitability of this software for any purpose.  It is
  478. Xprovided "as is" without express or implied warranty.
  479. X
  480. X*/
  481. X
  482. X#include <X/Xlib.h>
  483. X#include <stdio.h>
  484. X#include <signal.h>
  485. X#include <setjmp.h>
  486. X#include <sys/types.h>
  487. X#ifdef hpux
  488. X#include <time.h>
  489. X#else hpux
  490. X#include <sys/time.h>
  491. X#endif hpux
  492. X#include "defs.h"
  493. X#include "struct.h"
  494. X#include "data.h"
  495. X
  496. Xextern jmp_buf env;
  497. X
  498. Xstatic struct itimerval udt;
  499. X
  500. Xdeath()
  501. X{
  502. X    char buf[80];
  503. X
  504. X    signal(SIGALRM, SIG_IGN);
  505. X    udt.it_interval.tv_sec = 0;
  506. X    udt.it_interval.tv_usec = 0;
  507. X    udt.it_value.tv_sec = 0;
  508. X    udt.it_value.tv_usec = 0;
  509. X    setitimer(ITIMER_REAL, &udt, 0);
  510. X    signal(SIGALRM, SIG_DFL);
  511. X
  512. X    me->p_status = POUTFIT;        /* Stop the ghost buster */
  513. X
  514. X    XClear(w);
  515. X    XChangeBorder(baseWin, gTile);
  516. X    if (showStats)
  517. X    closeStats(statwin);
  518. X    if (infomapped)
  519. X    destroyInfo();
  520. X    if (ismapped(playerw))
  521. X    XUnmapWindow(playerw);
  522. X    if (ismapped(planetw))
  523. X    XUnmapWindow(planetw);
  524. X    if (ismapped(war))
  525. X    XUnmapWindow(war);
  526. X
  527. X    switch (me->p_whydead) {
  528. X    case KQUIT:
  529. X        sprintf(buf, "You have self-destructed");
  530. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  531. X        mustexit = 1;  /* Hey!  If you quit, you quit */
  532. X        break;
  533. X    case KTORP:
  534. X        sprintf(buf, "You were killed by a torp from %s (%c%x)",
  535. X        players[me->p_whodead].p_name,
  536. X        teamlet[players[me->p_whodead].p_team],
  537. X        me->p_whodead);
  538. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  539. X        sprintf(buf, "who was %d%% damaged",
  540. X        players[me->p_whodead].p_damage);
  541. X        XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
  542. X        break;
  543. X    case KPHASER:
  544. X        sprintf(buf, "You were killed by a phaser shot from %s (%c%x)",
  545. X        players[me->p_whodead].p_name,
  546. X        teamlet[players[me->p_whodead].p_team],
  547. X        me->p_whodead);
  548. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  549. X        sprintf(buf, "who was %d%% damaged",
  550. X        players[me->p_whodead].p_damage);
  551. X        XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
  552. X        break;
  553. X    case KPLANET:
  554. X        sprintf(buf, "You were killed by planetary fire from %s (%c)",
  555. X        planets[me->p_whodead].pl_name,
  556. X        teamlet[planets[me->p_whodead].pl_owner]);
  557. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  558. X        break;
  559. X    case KSHIP:
  560. X        sprintf(buf, "You were killed by an exploding ship formerly owned by %s (%c%x)",
  561. X        players[me->p_whodead].p_name,
  562. X        teamlet[players[me->p_whodead].p_team],
  563. X        me->p_whodead);
  564. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  565. X        sprintf(buf, "who was %d%% damaged",
  566. X        players[me->p_whodead].p_damage);
  567. X        XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
  568. X        break;
  569. X    case KDAEMON:
  570. X        sprintf(buf, "You were killed by a dying daemon");
  571. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  572. X        mustexit = 1;
  573. X        break;
  574. X    case KWINNER:
  575. X        sprintf(buf, "Galaxy has been conquered by %s (%c%x)",
  576. X        players[me->p_whodead].p_name,
  577. X        teamlet[players[me->p_whodead].p_team],
  578. X        players[me->p_whodead].p_no);
  579. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  580. X        mustexit = 1;
  581. X        break;
  582. X    case KGHOST:
  583. X        sprintf(buf, "You were killed by a confused daemon");
  584. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  585. X        mustexit = 1;
  586. X        break;
  587. X    default:
  588. X        sprintf(buf, "You were killed by something unknown to this game?");
  589. X        XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
  590. X        mustexit = 1;
  591. X        break;
  592. X    }
  593. X    if (oldmax < me->p_kills)
  594. X    oldmax = me->p_kills;
  595. X    mystats->st_kills += me->p_kills;
  596. X    /* the exit routine in 'entryWindow' handles reentry now */
  597. X    XSync(1);
  598. X    longjmp(env, 0);
  599. X}
  600. END_OF_death.c
  601. if test 4146 -ne `wc -c <death.c`; then
  602.     echo shar: \"death.c\" unpacked with wrong size!
  603. fi
  604. # end of overwriting check
  605. fi
  606. if test -f defs.h -a "${1}" != "-c" ; then 
  607.   echo shar: Will not over-write existing file \"defs.h\"
  608. else
  609. echo shar: Extracting \"defs.h\" \(3997 characters\)
  610. sed "s/^X//" >defs.h <<'END_OF_defs.h'
  611. X
  612. X/*
  613. X
  614. X    Copyright (c) 1986     Chris Guthrie
  615. X
  616. XPermission to use, copy, modify, and distribute this
  617. Xsoftware and its documentation for any purpose and without
  618. Xfee is hereby granted, provided that the above copyright
  619. Xnotice appear in all copies and that both that copyright
  620. Xnotice and this permission notice appear in supporting
  621. Xdocumentation.  No representations are made about the
  622. Xsuitability of this software for any purpose.  It is
  623. Xprovided "as is" without express or implied warranty.
  624. X
  625. X*/
  626. X
  627. X#define MAXPLAYER 16
  628. X#define MAXPLANETS 40
  629. X#define MAXTORP 12
  630. X#define PKEY 257
  631. X
  632. X/* These are configuration definitions */
  633. X
  634. X#define GWIDTH 100000   /* galaxy is 100000 spaces on a side */
  635. X#define WARP1 20    /* warp one will move 20 spaces per update */
  636. X#define SCALE 40    /* Window will be one pixel for 20 spaces */
  637. X#define EXPDIST 400    /* At this range a torp will explode */
  638. X#define DETDIST 2500    /* At this range a player can detonate a torp */
  639. X#define PHASEDIST 6000    /* At this range a player can do damage with phasers */
  640. X#define ENTORBDIST 900    /* At this range a player can orbit a planet */
  641. X#define ORBDIST 800    /* A player will orbit at this radius */
  642. X#define ORBSPEED 2    /* This is the fastest a person can go into orbit */
  643. X#define PFIREDIST 1500    /* At this range a planet will shoot at a player */
  644. X#define UPDATE 100000    /* Update time is 100000 micro-seconds */
  645. X#define AUTOQUIT 60    /* auto logout in 60 secs */
  646. X
  647. X
  648. X/* These are memory sections */
  649. X#define PLAYER 1
  650. X#define MAXMESSAGE 50
  651. X
  652. X#define rosette(x)    ((((x) + 256/VIEWS/2) / (256/VIEWS)) % VIEWS)
  653. X
  654. X/* These are the teams */
  655. X/* Note that I used bit types for these mostly for messages and
  656. X   war status.  This was probably a mistake.  It meant that Ed
  657. X   had to add the 'remap' area to map these (which are used throughout
  658. X   the code as the proper team variable) into a nice four team deep
  659. X   array for his color stuff.  Oh well.
  660. X*/
  661. X#define NOBODY 0x0
  662. X#define FED 0x1
  663. X#define ROM 0x2
  664. X#define KLI 0x4
  665. X#define ORI 0x8
  666. X#define ALLTEAM (FED|ROM|KLI|ORI)
  667. X#define MAXTEAM (ORI)
  668. X#define NUMTEAM 4
  669. X/*
  670. X** These are random configuration variables
  671. X*/
  672. X#define VICTORY 30    /* Number of planets needed to conquer the galaxy */
  673. X#define WARNTIME 30    /* Number of updates to have a warning on the screen */
  674. X#define MESSTIME 30    /* Number of updates to have a message on the screen */
  675. X
  676. X#define TARG_PLAYER    0x1    /* Flags for gettarget */
  677. X#define TARG_PLANET    0x2
  678. X#define TARG_CLOAK    0x4    /* Include cloaked ships in search */
  679. X
  680. X/* Data files to make the game play across daemon restarts. */
  681. X
  682. X/* #define DIR        "/eros/staff/chris/nt */
  683. X#define DIR        "/usr/games/lib/xtrek
  684. X
  685. X#define PLFILE        DIR/.planets"
  686. X#define SCOREFILE    DIR/.scores"
  687. X#define MOTD        DIR/.motd"
  688. X#define DAEMON        DIR/daemon"
  689. X#define ROBOT        DIR/robot"
  690. X
  691. X/* Other stuff that Ed added */
  692. X
  693. X#define ABS(a)            /* abs(a) */ (((a) < 0) ? -(a) : (a))
  694. X
  695. X#define myTorp(t)        (me->p_no == (t)->t_owner)
  696. X#define friendlyTorp(t)        ((!(me->p_team & (t)->t_war)) || (myTorp(t)))
  697. X#define myPhaser(p)        (&phasers[me->p_no] == (p))
  698. X#define friendlyPhaser(p)    (me->p_team == players[(p) - phasers].p_team)
  699. X#define myPlayer(p)        (me == (p))
  700. X#define myPlanet(p)        (me->p_team == (p)->pl_owner)
  701. X#define friendlyPlayer(p)    ((!(me->p_team & \
  702. X                    ((p)->p_swar | (p)->p_hostile))) && \
  703. X                    (!((p)->p_team & \
  704. X                    (me->p_swar | me->p_hostile))))
  705. X#define isAlive(p)        ((p)->p_status == PALIVE)
  706. X#define friendlyPlanet(p)    ((p)->pl_info & me->p_team && \
  707. X                 !((p)->pl_owner & (me->p_swar | me->p_hostile)))
  708. X
  709. X#define torpColor(t)        \
  710. X    (myTorp(t) ? myColor : shipCol[remap[players[(t)->t_owner].p_team]])
  711. X#define phaserColor(p)        \
  712. X    (myPhaser(p) ? myColor : shipCol[remap[players[(p) - phasers].p_team]])
  713. X#define playerColor(p)        \
  714. X    (myPlayer(p) ? myColor : shipCol[remap[(p)->p_team]])
  715. X#define planetColor(p)        \
  716. X    (((p)->pl_info & me->p_team) ? shipCol[remap[(p)->pl_owner]] : unColor)
  717. X
  718. X#define planetFont(p)        \
  719. X    (myPlanet(p) ? bfont : friendlyPlanet(p) ? ifont : dfont)
  720. X#define shipFont(p)        \
  721. X    (myPlayer(p) ? bfont : friendlyPlayer(p) ? ifont : dfont)
  722. END_OF_defs.h
  723. if test 3997 -ne `wc -c <defs.h`; then
  724.     echo shar: \"defs.h\" unpacked with wrong size!
  725. fi
  726. # end of overwriting check
  727. fi
  728. if test -f dmessage.c -a "${1}" != "-c" ; then 
  729.   echo shar: Will not over-write existing file \"dmessage.c\"
  730. else
  731. echo shar: Extracting \"dmessage.c\" \(1623 characters\)
  732. sed "s/^X//" >dmessage.c <<'END_OF_dmessage.c'
  733. X
  734. X/*
  735. X
  736. X    Copyright (c) 1986     Chris Guthrie
  737. X
  738. XPermission to use, copy, modify, and distribute this
  739. Xsoftware and its documentation for any purpose and without
  740. Xfee is hereby granted, provided that the above copyright
  741. Xnotice appear in all copies and that both that copyright
  742. Xnotice and this permission notice appear in supporting
  743. Xdocumentation.  No representations are made about the
  744. Xsuitability of this software for any purpose.  It is
  745. Xprovided "as is" without express or implied warranty.
  746. X
  747. X*/
  748. X
  749. X#include <X/Xlib.h>
  750. X#include <stdio.h>
  751. X#include <math.h>
  752. X#include <signal.h>
  753. X#include "defs.h"
  754. X#include "struct.h"
  755. X#include "data.h"
  756. X
  757. Xdmessage()
  758. X{
  759. X    struct message *cur;
  760. X    char buf[80];
  761. X
  762. X    if (messpend)
  763. X    return;
  764. X    if (mctl->mc_current == lastm) {
  765. X    if (mdisplayed) {
  766. X        XPixSet(messagew, 5, 5, dfontinfo->width * lastcount,
  767. X        dfontinfo->height, backColor);
  768. X        mdisplayed = 0;
  769. X    }
  770. X    return;
  771. X    }
  772. X    do {
  773. X    if (++lastm >= MAXMESSAGE)
  774. X        lastm = 0;
  775. X    cur = &messages[lastm];
  776. X    if (cur->m_flags & MVALID) {
  777. X        if ((cur->m_flags & MALL) ||
  778. X        ((cur->m_flags & MTEAM) && (cur->m_recpt & me->p_team)) ||
  779. X        ((cur->m_flags & MINDIV) && (cur->m_recpt == me->p_no))) {
  780. X            if (mdisplayed) {
  781. X            XPixSet(messagew, 5, 5, dfontinfo->width * lastcount,
  782. X                dfontinfo->height, backColor);
  783. X            mdisplayed = 0;
  784. X            }
  785. X            (void) sprintf(buf, "%s", cur->m_data);
  786. X            lastcount = strlen(buf);
  787. X            if (lastcount > 80)
  788. X            lastcount = 80;
  789. X            XText(messagew, 5, 5, buf, lastcount, dfont,
  790. X            textColor, backColor);
  791. X            XFeep(0);
  792. X            mdisplayed = 1;
  793. X            XFlush();
  794. X            return;
  795. X        }
  796. X    }
  797. X    } while (lastm != mctl->mc_current);
  798. X}
  799. END_OF_dmessage.c
  800. if test 1623 -ne `wc -c <dmessage.c`; then
  801.     echo shar: \"dmessage.c\" unpacked with wrong size!
  802. fi
  803. # end of overwriting check
  804. fi
  805. if test -f enter.c -a "${1}" != "-c" ; then 
  806.   echo shar: Will not over-write existing file \"enter.c\"
  807. else
  808. echo shar: Extracting \"enter.c\" \(3429 characters\)
  809. sed "s/^X//" >enter.c <<'END_OF_enter.c'
  810. X
  811. X/*
  812. X
  813. X    Copyright (c) 1986     Chris Guthrie
  814. X
  815. XPermission to use, copy, modify, and distribute this
  816. Xsoftware and its documentation for any purpose and without
  817. Xfee is hereby granted, provided that the above copyright
  818. Xnotice appear in all copies and that both that copyright
  819. Xnotice and this permission notice appear in supporting
  820. Xdocumentation.  No representations are made about the
  821. Xsuitability of this software for any purpose.  It is
  822. Xprovided "as is" without express or implied warranty.
  823. X
  824. X*/
  825. X
  826. X#include <X/Xlib.h>
  827. X#include <stdio.h>
  828. X#include <sys/types.h>
  829. X#include <sys/ipc.h>
  830. X#include <sys/shm.h>
  831. X#include <errno.h>
  832. X#include <pwd.h>
  833. X#include <string.h>
  834. X#include <ctype.h>
  835. X#include "defs.h"
  836. X#include "struct.h"
  837. X#include "data.h"
  838. X
  839. X/* Enter the game */
  840. X
  841. Xlong random();
  842. X
  843. Xenter(tno, disp, pno)
  844. Xint tno;
  845. Xchar    *disp;
  846. Xint pno;
  847. X{
  848. X    struct passwd    *pwent, *getpwuid();
  849. X    char         *pseudo;
  850. X    char        buf[80];
  851. X
  852. X    if ((pwent = getpwuid(getuid())) == NULL)
  853. X    (void) strncpy(me->p_login, "Bozo", sizeof (me->p_login));
  854. X    else
  855. X    (void) strncpy(me->p_login, pwent->pw_name, sizeof (me->p_login));
  856. X    pseudo = XGetDefault("xtrek", "name");
  857. X    if (pseudo == NULL)
  858. X    (void) strncpy(me->p_name, me->p_login, sizeof (me->p_name));
  859. X    else
  860. X    (void) strncpy(me->p_name, pseudo, sizeof (me->p_name));
  861. X    me->p_no = pno;
  862. X    me->p_updates = 0;
  863. X    me->p_flags = PFSHIELD;
  864. X    (void) strncpy(me->p_monitor, disp, sizeof (me->p_monitor));
  865. X    me->p_dir = 0;
  866. X    me->p_desdir = 0;
  867. X    me->p_speed = 0;
  868. X    me->p_desspeed = 0;
  869. X    me->p_subspeed = 0;
  870. X    me->p_team = (1 << tno);
  871. X    me->p_x = planets[tno * 10].pl_x + (random() % 10000) - 5000;
  872. X    me->p_y = planets[tno * 10].pl_y + (random() % 10000) - 5000;
  873. X    me->p_ntorp = 0;
  874. X    me->p_damage = 0;
  875. X    me->p_subdamage = 0;
  876. X    me->p_etemp = 0;
  877. X    me->p_etime = 0;
  878. X    me->p_wtemp = 0;
  879. X    me->p_wtime = 0;
  880. X    me->p_shield = 100;
  881. X    me->p_subshield = 0;
  882. X    me->p_swar = 0;
  883. X    me->p_hostile = (FED|ROM|KLI|ORI);
  884. X    me->p_hostile &= ~me->p_team;
  885. X    me->p_kills = 0.0;
  886. X    me->p_armies = 0;
  887. X
  888. X    sprintf(buf, "%c%x", teamlet[me->p_team], me->p_no);
  889. X    strncpy(me->p_mapchars, buf, 2);
  890. X
  891. X    getship(myship);
  892. X    mystats->st_entries++;
  893. X    me->p_fuel = myship->s_maxfuel;
  894. X    delay = 0;
  895. X}
  896. X
  897. Xopenmem()
  898. X{
  899. X    extern int errno;
  900. X    int    shmemKey = PKEY;
  901. X    int    shmid;
  902. X    struct memory    *sharedMemory;
  903. X
  904. X    errno = 0;
  905. X    shmid = shmget(shmemKey, 0, 0);
  906. X    if (shmid < 0) {
  907. X    if (errno != ENOENT) {
  908. X        perror("shmget");
  909. X        exit(1);
  910. X    }
  911. X    startdaemon();
  912. X    sleep(2);
  913. X    shmid = shmget(shmemKey, 0, 0);
  914. X    if (shmid < 0) {
  915. X        fprintf(stderr, "Daemon not running\n");
  916. X        exit (1);
  917. X    }
  918. X    }
  919. X    sharedMemory = (struct memory *) shmat(shmid, 0, 0);
  920. X    if (sharedMemory == (struct memory *) -1) {
  921. X    perror("shared memory");
  922. X    exit (1);
  923. X    }
  924. X    players = sharedMemory->players;
  925. X    torps = sharedMemory->torps;
  926. X    status = sharedMemory->status;
  927. X    planets = sharedMemory->planets;
  928. X    phasers = sharedMemory->phasers;
  929. X    mctl = sharedMemory->mctl;
  930. X    messages = sharedMemory->messages;
  931. X}
  932. X
  933. Xfindslot()
  934. X{
  935. X    register int i;
  936. X
  937. X    for (i = 0; i < MAXPLAYER; i++) {
  938. X    if (players[i].p_status == PFREE) {    /* We have a free slot */
  939. X        players[i].p_status = POUTFIT;    /* possible race code */
  940. X        break;
  941. X    }
  942. X    }
  943. X    if (i == MAXPLAYER) {
  944. X    fprintf(stderr, "No more room in game\n");
  945. X    exit (0);
  946. X    }
  947. X    bzero(&players[i].p_stats, sizeof(struct stats));  /* Slight problem for
  948. X                              copilot */
  949. X    return(i);
  950. X}
  951. END_OF_enter.c
  952. if test 3429 -ne `wc -c <enter.c`; then
  953.     echo shar: \"enter.c\" unpacked with wrong size!
  954. fi
  955. # end of overwriting check
  956. fi
  957. if test -f interface.c -a "${1}" != "-c" ; then 
  958.   echo shar: Will not over-write existing file \"interface.c\"
  959. else
  960. echo shar: Extracting \"interface.c\" \(2542 characters\)
  961. sed "s/^X//" >interface.c <<'END_OF_interface.c'
  962. X
  963. X/*
  964. X
  965. X    Copyright (c) 1986     Chris Guthrie
  966. X
  967. XPermission to use, copy, modify, and distribute this
  968. Xsoftware and its documentation for any purpose and without
  969. Xfee is hereby granted, provided that the above copyright
  970. Xnotice appear in all copies and that both that copyright
  971. Xnotice and this permission notice appear in supporting
  972. Xdocumentation.  No representations are made about the
  973. Xsuitability of this software for any purpose.  It is
  974. Xprovided "as is" without express or implied warranty.
  975. X
  976. X*/
  977. X
  978. X/* This file will include all the interfaces between the input routines
  979. X    and the daemon.  They should be useful for writing robots and the
  980. X    like */
  981. X
  982. X#include <X/Xlib.h>
  983. X#include <stdio.h>
  984. X#include <math.h>
  985. X#include <signal.h>
  986. X#include "defs.h"
  987. X#include "struct.h"
  988. X#include "data.h"
  989. X
  990. Xset_speed(speed)
  991. Xint speed;
  992. X{
  993. X    me->p_desspeed = speed;
  994. X    me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
  995. X}
  996. X
  997. Xset_course(dir)
  998. Xunsigned char dir;
  999. X{
  1000. X    me->p_desdir = dir;
  1001. X    me->p_flags &= ~(PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
  1002. X}
  1003. X
  1004. Xshield_up()
  1005. X{
  1006. X    me->p_flags |= PFSHIELD;
  1007. X    me->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
  1008. X}
  1009. X
  1010. Xshield_down()
  1011. X{
  1012. X    me->p_flags &= ~PFSHIELD;
  1013. X}
  1014. X
  1015. Xshield_tog()
  1016. X{
  1017. X    me->p_flags ^= PFSHIELD;
  1018. X    me->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
  1019. X}
  1020. X
  1021. Xbomb_planet()
  1022. X{
  1023. X    if (!(me->p_flags & PFORBIT)) {
  1024. X    warning("Must be orbiting to bomb");
  1025. X    return;
  1026. X    }
  1027. X    me->p_flags |= PFBOMB;
  1028. X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
  1029. X}
  1030. X
  1031. Xbeam_up()
  1032. X{
  1033. X    if (!(me->p_flags & PFORBIT)) {
  1034. X    warning("Must be orbiting to beam up.");
  1035. X    return;
  1036. X    }
  1037. X    if (me->p_team != planets[me->p_planet].pl_owner) {
  1038. X    warning("Those aren't our men.");
  1039. X    return;
  1040. X    }
  1041. X    me->p_flags |= PFBEAMUP;
  1042. X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMDOWN);
  1043. X}
  1044. X
  1045. Xbeam_down()
  1046. X{
  1047. X    if (!(me->p_flags & PFORBIT)) {
  1048. X    warning("Must be orbiting to beam down.");
  1049. X    return;
  1050. X    }
  1051. X    me->p_flags |= PFBEAMDOWN;
  1052. X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMUP);
  1053. X}
  1054. X
  1055. Xrepair()
  1056. X{
  1057. X    me->p_desspeed = 0;
  1058. X    me->p_flags |= PFREPAIR;
  1059. X    me->p_flags &= ~(PFSHIELD | PFBOMB | PFBEAMUP | PFBEAMDOWN);
  1060. X}
  1061. X
  1062. Xrepair_off()
  1063. X{
  1064. X    me->p_flags &= ~PFREPAIR;
  1065. X}
  1066. X
  1067. X/*
  1068. Xcase 'Q':
  1069. X    me->p_flags |= PFSELFDEST;
  1070. X    selfdest = me->p_updates + 100;
  1071. X    warning("Self destruct initiated");
  1072. X    return;
  1073. X*/
  1074. X
  1075. Xrepeat_message()
  1076. X{
  1077. X    if (++lastm == MAXMESSAGE) ;
  1078. X    lastm = 0;
  1079. X}
  1080. X
  1081. Xcloak()
  1082. X{
  1083. X    me->p_flags ^= PFCLOAK;
  1084. X}
  1085. X
  1086. Xcloak_on()
  1087. X{
  1088. X    me->p_flags |= PFCLOAK;
  1089. X}
  1090. X
  1091. Xcloak_off()
  1092. X{
  1093. X    me->p_flags &= ~PFCLOAK;
  1094. X}
  1095. END_OF_interface.c
  1096. if test 2542 -ne `wc -c <interface.c`; then
  1097.     echo shar: \"interface.c\" unpacked with wrong size!
  1098. fi
  1099. # end of overwriting check
  1100. fi
  1101. if test -f orbit.c -a "${1}" != "-c" ; then 
  1102.   echo shar: Will not over-write existing file \"orbit.c\"
  1103. else
  1104. echo shar: Extracting \"orbit.c\" \(1552 characters\)
  1105. sed "s/^X//" >orbit.c <<'END_OF_orbit.c'
  1106. X
  1107. X/*
  1108. X
  1109. X    Copyright (c) 1986     Chris Guthrie
  1110. X
  1111. XPermission to use, copy, modify, and distribute this
  1112. Xsoftware and its documentation for any purpose and without
  1113. Xfee is hereby granted, provided that the above copyright
  1114. Xnotice appear in all copies and that both that copyright
  1115. Xnotice and this permission notice appear in supporting
  1116. Xdocumentation.  No representations are made about the
  1117. Xsuitability of this software for any purpose.  It is
  1118. Xprovided "as is" without express or implied warranty.
  1119. X
  1120. X*/
  1121. X
  1122. X#include <X/Xlib.h>
  1123. X
  1124. X#include <stdio.h>
  1125. X#include <math.h>
  1126. X#include <sys/types.h>
  1127. X#include <sys/ipc.h>
  1128. X#include <sys/shm.h>
  1129. X#include "defs.h"
  1130. X#include "struct.h"
  1131. X#include "data.h"
  1132. X
  1133. X/* orbit a planet */
  1134. X
  1135. Xorbit()
  1136. X{
  1137. X    register int i;
  1138. X    register struct planet *l;
  1139. X    unsigned char dir;
  1140. X    int dx, dy;
  1141. X
  1142. X    if (me->p_speed > ORBSPEED) {
  1143. X    warning("Speed must be less than two to orbit");
  1144. X    return;
  1145. X    }
  1146. X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
  1147. X    dx = ABS(l->pl_x - me->p_x);
  1148. X    dy = ABS(l->pl_y - me->p_y);
  1149. X    if (dx > ENTORBDIST || dy > ENTORBDIST)        /*XXX*/
  1150. X        continue;
  1151. X    if (dx * dx + dy * dy > ENTORBDIST * ENTORBDIST)
  1152. X        continue;
  1153. X
  1154. X    dir = (unsigned char) (atan2((double) (me->p_x - l->pl_x),
  1155. X        (double) (l->pl_y - me->p_y))
  1156. X        / 3.14159 * 128.);
  1157. X    l->pl_info |= me->p_team;
  1158. X    me->p_dir = dir + 64;
  1159. X    me->p_flags |= PFORBIT;
  1160. X    me->p_x = l->pl_x + ORBDIST * Cos[dir];
  1161. X    me->p_y = l->pl_y + ORBDIST * Sin[dir];
  1162. X    me->p_speed = me->p_desspeed = 0;
  1163. X    me->p_planet = l->pl_no;
  1164. X    return;
  1165. X    }
  1166. X    warning("Not close enough to any planet to orbit");
  1167. X}
  1168. END_OF_orbit.c
  1169. if test 1552 -ne `wc -c <orbit.c`; then
  1170.     echo shar: \"orbit.c\" unpacked with wrong size!
  1171. fi
  1172. # end of overwriting check
  1173. fi
  1174. if test -f phaser.c -a "${1}" != "-c" ; then 
  1175.   echo shar: Will not over-write existing file \"phaser.c\"
  1176. else
  1177. echo shar: Extracting \"phaser.c\" \(2487 characters\)
  1178. sed "s/^X//" >phaser.c <<'END_OF_phaser.c'
  1179. X
  1180. X/*
  1181. X
  1182. X    Copyright (c) 1986     Chris Guthrie
  1183. X
  1184. XPermission to use, copy, modify, and distribute this
  1185. Xsoftware and its documentation for any purpose and without
  1186. Xfee is hereby granted, provided that the above copyright
  1187. Xnotice appear in all copies and that both that copyright
  1188. Xnotice and this permission notice appear in supporting
  1189. Xdocumentation.  No representations are made about the
  1190. Xsuitability of this software for any purpose.  It is
  1191. Xprovided "as is" without express or implied warranty.
  1192. X
  1193. X*/
  1194. X
  1195. X#include <X/Xlib.h>
  1196. X#include <stdio.h>
  1197. X#include <math.h>
  1198. X#include <signal.h>
  1199. X#include "defs.h"
  1200. X#include "struct.h"
  1201. X#include "data.h"
  1202. X
  1203. Xphaser(course)
  1204. Xunsigned char course;
  1205. X{
  1206. X    register int i;
  1207. X    register struct player *j, *target;
  1208. X    register struct phaser *mine;
  1209. X    unsigned char dir;
  1210. X    int range, trange;
  1211. X    char buf[80];
  1212. X
  1213. X    mine = &phasers[me->p_no];
  1214. X
  1215. X    if (mine->ph_status != PHFREE) {
  1216. X    warning("Phasers have not recharged");
  1217. X    return;
  1218. X    }
  1219. X    if (me->p_fuel < myship->s_phasercost) {
  1220. X    warning("Not enough fuel for phaser");
  1221. X    return;
  1222. X    }
  1223. X    if (me->p_flags & PFREPAIR) {
  1224. X    warning("Can't fire while repairing");
  1225. X    return;
  1226. X    }
  1227. X    if (me->p_flags & PFWEP) {
  1228. X    warning("Weapons overheated");
  1229. X    return;
  1230. X    }
  1231. X    if (me->p_flags & PFCLOAK) {
  1232. X    warning("Cannot fire while cloaked");
  1233. X    return;
  1234. X    }
  1235. X
  1236. X    me->p_fuel -= myship->s_phasercost;
  1237. X    me->p_wtemp += myship->s_phasercost / 10;
  1238. X    target = (struct player *) 0;
  1239. X    mine->ph_dir = course;
  1240. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  1241. X    if ((j->p_status != PALIVE) || (j == me))
  1242. X        continue;
  1243. X    if ((!((j->p_swar | j->p_hostile) & me->p_team)) &&
  1244. X        (!((me->p_swar | me->p_hostile) & j->p_team)))
  1245. X        continue;
  1246. X    dir = (unsigned char) (atan2((double) (j->p_x - me->p_x),
  1247. X        (double) (me->p_y - j->p_y))
  1248. X        / 3.14159 * 128.);
  1249. X    if (angdist(dir, course) < 5) {
  1250. X        trange = (int) hypot((double) (j->p_x - me->p_x),
  1251. X        (double) (j->p_y - me->p_y));
  1252. X        if (target == 0) {
  1253. X        target = j;
  1254. X        range = trange;
  1255. X        }
  1256. X        else if (range > trange) {
  1257. X        target = j;
  1258. X        range = trange;
  1259. X        }
  1260. X    }
  1261. X    }
  1262. X    if ((target == 0) || (range > PHASEDIST)) {
  1263. X    mine->ph_fuse = 10;
  1264. X    mine->ph_status = PHMISS;
  1265. X    warning("Phaser missed!!!");
  1266. X    }
  1267. X    else {
  1268. X    mine->ph_fuse = 10;
  1269. X    mine->ph_target = target->p_no;
  1270. X    mine->ph_damage = (PHASEDIST- range) * 100 / PHASEDIST;
  1271. X    mine->ph_status = PHHIT;
  1272. X    (void) sprintf(buf, "Phaser hit %s for %d points",
  1273. X        target->p_name,
  1274. X        mine->ph_damage);
  1275. X    warning(buf);
  1276. X    }
  1277. X    mystats->st_phasers++;
  1278. X}
  1279. END_OF_phaser.c
  1280. if test 2487 -ne `wc -c <phaser.c`; then
  1281.     echo shar: \"phaser.c\" unpacked with wrong size!
  1282. fi
  1283. # end of overwriting check
  1284. fi
  1285. if test -f planetlist.c -a "${1}" != "-c" ; then 
  1286.   echo shar: Will not over-write existing file \"planetlist.c\"
  1287. else
  1288. echo shar: Extracting \"planetlist.c\" \(1791 characters\)
  1289. sed "s/^X//" >planetlist.c <<'END_OF_planetlist.c'
  1290. X
  1291. X/*
  1292. X
  1293. X    Copyright (c) 1986     Chris Guthrie
  1294. X
  1295. XPermission to use, copy, modify, and distribute this
  1296. Xsoftware and its documentation for any purpose and without
  1297. Xfee is hereby granted, provided that the above copyright
  1298. Xnotice appear in all copies and that both that copyright
  1299. Xnotice and this permission notice appear in supporting
  1300. Xdocumentation.  No representations are made about the
  1301. Xsuitability of this software for any purpose.  It is
  1302. Xprovided "as is" without express or implied warranty.
  1303. X
  1304. X*/
  1305. X
  1306. X
  1307. X#include <X/Xlib.h>
  1308. X#include <stdio.h>
  1309. X#include "defs.h"
  1310. X#include "struct.h"
  1311. X#include "data.h"
  1312. X
  1313. Xstatic char *teamname[9] = {
  1314. X    "IND",
  1315. X    "FED",
  1316. X    "ROM",
  1317. X    "",
  1318. X    "KLI",
  1319. X    "",
  1320. X    "",
  1321. X    "",
  1322. X    "ORI"
  1323. X};
  1324. X
  1325. X/*
  1326. X** Open a window which contains all the planets and their current
  1327. X** statistics.  Players will not know about planets that their team
  1328. X** has not orbited.
  1329. X*/
  1330. X
  1331. Xplanetlist()
  1332. X{
  1333. X    register int i;
  1334. X    register int k = 0;
  1335. X    char buf[BUFSIZ];
  1336. X    register struct planet *j;
  1337. X
  1338. X    (void) sprintf(buf, "  # Planet Name      own armies REPAIR FUEL");
  1339. X    XText(planetw, 0, dfontinfo->height, buf,
  1340. X       strlen(buf), dfont, textColor, backColor);
  1341. X    k = 2;
  1342. X    for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++) {
  1343. X    if (j->pl_info & me->p_team) {
  1344. X        (void) sprintf(buf, " %2d %-16s %3s %3d    %6s %4s",
  1345. X        j->pl_no,
  1346. X        j->pl_name,
  1347. X        teamname[j->pl_owner],
  1348. X        j->pl_armies,
  1349. X        (j->pl_flags & PLREPAIR ? "REPAIR" : "      "),
  1350. X        (j->pl_flags & PLFUEL ? "FUEL" : "    "));
  1351. X        XText(planetw, 0, dfontinfo->height * k++, buf, strlen(buf),
  1352. X           planetFont(j), planetColor(j), backColor);
  1353. X    }
  1354. X    else {
  1355. X        (void) sprintf(buf, " %2d %-16s",
  1356. X        j->pl_no,
  1357. X        j->pl_name);
  1358. X        XText(planetw, 0, dfontinfo->height * k++, buf, strlen(buf),
  1359. X           dfont, unColor, backColor);
  1360. X    }
  1361. X    }
  1362. X    XFlush();
  1363. X}
  1364. END_OF_planetlist.c
  1365. if test 1791 -ne `wc -c <planetlist.c`; then
  1366.     echo shar: \"planetlist.c\" unpacked with wrong size!
  1367. fi
  1368. # end of overwriting check
  1369. fi
  1370. if test -f planets.h -a "${1}" != "-c" ; then 
  1371.   echo shar: Will not over-write existing file \"planets.h\"
  1372. else
  1373. echo shar: Extracting \"planets.h\" \(3119 characters\)
  1374. sed "s/^X//" >planets.h <<'END_OF_planets.h'
  1375. X
  1376. X/*
  1377. X
  1378. X    Copyright (c) 1986     Chris Guthrie
  1379. X
  1380. XPermission to use, copy, modify, and distribute this
  1381. Xsoftware and its documentation for any purpose and without
  1382. Xfee is hereby granted, provided that the above copyright
  1383. Xnotice appear in all copies and that both that copyright
  1384. Xnotice and this permission notice appear in supporting
  1385. Xdocumentation.  No representations are made about the
  1386. Xsuitability of this software for any purpose.  It is
  1387. Xprovided "as is" without express or implied warranty.
  1388. X
  1389. X*/
  1390. X
  1391. X/*
  1392. X
  1393. Xstruct planet {
  1394. X    int pl_no;
  1395. X    int pl_status;
  1396. X    int pl_owner;
  1397. X    int pl_x;
  1398. X    int pl_y;
  1399. X    char pl_name[16];
  1400. X    pl_namelen
  1401. X    int pl_armies;
  1402. X}
  1403. X*/
  1404. X
  1405. Xstruct planet pdata[MAXPLANETS] = {
  1406. X    {  0, (FED|PLHOME|PLFUEL|PLREPAIR), FED, 20000, 80000, "Earth", 5, 30, FED },
  1407. X    {  1, FED, FED, 10000, 60000, "Sasus", 5, 30, FED },
  1408. X    {  2, FED, FED, 25000, 60000, "Candeleron", 10, 30, FED },
  1409. X    {  3, FED, FED, 44000, 81000, "Beta III", 8, 30, FED },
  1410. X    {  4, FED, FED, 33000, 55000, "Janus", 5, 30, FED },
  1411. X    {  5, FED, FED, 30000, 90000, "Deneb VI", 8, 30, FED },
  1412. X    {  6, FED, FED, 45000, 66000, "Ceti IV", 7, 30, FED },
  1413. X    {  7, FED, FED, 11000, 75000, "Altar", 5, 30, FED },
  1414. X    {  8, FED, FED,  8000, 93000, "Dekar", 5, 30, FED },
  1415. X    {  9, FED, FED, 32000, 74000, "Daltus", 6, 30, FED },
  1416. X    { 10, (ROM|PLHOME|PLFUEL|PLREPAIR), ROM, 20000, 20000, "Romulus", 7, 30, ROM },
  1417. X    { 11, ROM, ROM, 45000,  7000, "Ethen", 5, 30, ROM },
  1418. X    { 12, ROM, ROM,  4000, 12000, "Amur", 4, 30, ROM },
  1419. X    { 13, ROM, ROM, 42000, 44000, "Remus", 5, 30, ROM },
  1420. X    { 14, ROM, ROM, 13000, 45000, "Bal", 3, 30, ROM },
  1421. X    { 15, ROM, ROM, 28000,  8000, "Tahndar", 7, 30, ROM },
  1422. X    { 16, ROM, ROM, 28000, 23000, "Dact", 4, 30, ROM },
  1423. X    { 17, ROM, ROM, 40000, 25000, "Sirius II", 9, 30, ROM },
  1424. X    { 18, ROM, ROM, 25000, 44000, "Rakhir", 6, 30, ROM },
  1425. X    { 19, ROM, ROM,  8000, 29000, "Rus", 3, 30, ROM },
  1426. X    { 20, (KLI|PLHOME|PLFUEL|PLREPAIR), KLI, 80000, 20000, "Klingus", 7, 30, KLI },
  1427. X    { 21, KLI, KLI, 70000, 40000, "Malatrakir", 10, 30, KLI },
  1428. X    { 22, KLI, KLI, 60000, 10000, "Amakron", 7, 30, KLI },
  1429. X    { 23, KLI, KLI, 54000, 40000, "Laltir", 6, 30, KLI },
  1430. X    { 24, KLI, KLI, 93000,  8000, "Khartair", 8, 30, KLI },
  1431. X    { 25, KLI, KLI, 90000, 37000, "Monpur III", 10, 30, KLI },
  1432. X    { 26, KLI, KLI, 69000, 31000, "Sectus", 6, 30, KLI },
  1433. X    { 27, KLI, KLI, 83000, 48000, "Makus", 5, 30, KLI },
  1434. X    { 28, KLI, KLI, 54000, 21000, "Jakar", 5, 30, KLI },
  1435. X    { 29, KLI, KLI, 73000,  5000, "Gendus", 6, 30, KLI },
  1436. X    { 30, (ORI|PLHOME|PLFUEL|PLREPAIR), ORI, 80000, 80000, "Orion", 5, 30, ORI },
  1437. X    { 31, ORI, ORI, 92000, 59000, "Amterion", 8, 30, ORI },
  1438. X    { 32, ORI, ORI, 65000, 55000, "Lumecis", 7, 30, ORI },
  1439. X    { 33, ORI, ORI, 52000, 60000, "Bitar V", 7, 30, ORI },
  1440. X    { 34, ORI, ORI, 72000, 69000, "Prastan", 7, 30, ORI },
  1441. X    { 35, ORI, ORI, 64000, 80000, "Sorlen", 6, 30, ORI },
  1442. X    { 36, ORI, ORI, 56000, 89000, "Zetus", 5, 30, ORI },
  1443. X    { 37, ORI, ORI, 91000, 94000, "Jih", 3, 30, ORI },
  1444. X    { 38, ORI, ORI, 70000, 93000, "Markus II", 9, 30, ORI },
  1445. X    { 39, ORI, ORI, 85000, 70000, "Oren", 4, 30, ORI }
  1446. X};
  1447. END_OF_planets.h
  1448. if test 3119 -ne `wc -c <planets.h`; then
  1449.     echo shar: \"planets.h\" unpacked with wrong size!
  1450. fi
  1451. # end of overwriting check
  1452. fi
  1453. if test -f robot.c -a "${1}" != "-c" ; then 
  1454.   echo shar: Will not over-write existing file \"robot.c\"
  1455. else
  1456. echo shar: Extracting \"robot.c\" \(4260 characters\)
  1457. sed "s/^X//" >robot.c <<'END_OF_robot.c'
  1458. X
  1459. X/*
  1460. X
  1461. X    Copyright (c) 1986     Chris Guthrie
  1462. X
  1463. XPermission to use, copy, modify, and distribute this
  1464. Xsoftware and its documentation for any purpose and without
  1465. Xfee is hereby granted, provided that the above copyright
  1466. Xnotice appear in all copies and that both that copyright
  1467. Xnotice and this permission notice appear in supporting
  1468. Xdocumentation.  No representations are made about the
  1469. Xsuitability of this software for any purpose.  It is
  1470. Xprovided "as is" without express or implied warranty.
  1471. X
  1472. X*/
  1473. X
  1474. X#include <X/Xlib.h>
  1475. X#include <stdio.h>
  1476. X#include <sys/types.h>
  1477. X#ifdef hpux
  1478. X#include <time.h>
  1479. X#else hpux
  1480. X#include <sys/time.h>
  1481. X#endif hpux
  1482. X#include <signal.h>
  1483. X#include <setjmp.h>
  1484. X#include "defs.h"
  1485. X#include "struct.h"
  1486. X#include "data.h"
  1487. X
  1488. XWindow mapw;                /* XXX */
  1489. X
  1490. Xstruct itimerval udt;
  1491. Xint redrawall;
  1492. Xint lastm;
  1493. X
  1494. X/* lots of neat flags */
  1495. Xint hostile;
  1496. Xint debug;
  1497. Xint level;
  1498. Xint fleet;
  1499. Xint sticky;
  1500. Xint berserk;
  1501. Xint practice;
  1502. X
  1503. Xchar *rnames[4] = { "M5", "Colossus", "Guardian", "HAL"};
  1504. X
  1505. Xmain(argc, argv)
  1506. Xint argc;
  1507. Xchar **argv;
  1508. X{
  1509. X    register int i;
  1510. X    int rmove();
  1511. X    int team = -1;
  1512. X    int bteam;
  1513. X    int pno;
  1514. X    char str[80];
  1515. X
  1516. X    for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) {
  1517. X    switch(argv[1][1]) {
  1518. X        case 'f':
  1519. X        fleet++;
  1520. X        break;
  1521. X        case 's':
  1522. X        sticky++;
  1523. X        break;
  1524. X        case 'd':
  1525. X        debug++;
  1526. X        break;
  1527. X        case 'h':
  1528. X        hostile++;
  1529. X        break;
  1530. X        case 'p':
  1531. X        practice++;
  1532. X        break;
  1533. X        case 'b':
  1534. X        berserk++;
  1535. X        break;
  1536. X        case 'l':
  1537. X        if (argv[1][2] != NULL)
  1538. X            level = atoi(&argv[1][2]);
  1539. X        else
  1540. X            level = 0;
  1541. X        break;
  1542. X        case 'T':
  1543. X        switch (argv[1][2]) {
  1544. X            case 'f':
  1545. X            team = 0;
  1546. X            bteam = FED;
  1547. X            break;
  1548. X            case 'r':
  1549. X            team = 1;
  1550. X            bteam = ROM;
  1551. X            break;
  1552. X            case 'k':
  1553. X            team = 2;
  1554. X            bteam = KLI;
  1555. X            break;
  1556. X            case 'o':
  1557. X            team = 3;
  1558. X            bteam = ORI;
  1559. X            break;
  1560. X            default:
  1561. X            fprintf(stderr, "Unknown team type.  Usage -Tx where x is [frko]\n");
  1562. X            exit(1);
  1563. X        }
  1564. X        break;
  1565. X        default:
  1566. X        fprintf(stderr, "Unknown option '%c'\n", argv[1][1]);
  1567. X        exit(1);
  1568. X    }
  1569. X
  1570. X
  1571. X    }
  1572. X    srandom(getpid() * time((long *) 0));
  1573. X    if (team < 0 || team >= 4) {
  1574. X    if (debug)
  1575. X        fprintf(stderr, "Choosing random team.\n");
  1576. X    team = random() % 4;
  1577. X    }
  1578. X    openmem();
  1579. X    pno = findslot();
  1580. X    me = &players[pno];
  1581. X    myship = &me->p_ship;
  1582. X    mystats = &me->p_stats;
  1583. X    lastm = mctl->mc_current;
  1584. X    /* At this point we have memory set up.  If we aren't a fleet, we don't
  1585. X       want to replace any other robots on this team, so we'll check the
  1586. X       other players and get out if there are any on our team.
  1587. X    */
  1588. X
  1589. X    if (!fleet) {
  1590. X    for (i = 0; i < MAXPLAYER; i++) {
  1591. X        if ((players[i].p_status == PALIVE) && (players[i].p_team == bteam)) {
  1592. X        if (debug)
  1593. X            fprintf(stderr, "Galaxy already defended\n");
  1594. X        players[pno].p_status = PFREE;
  1595. X        exit(1);
  1596. X        }
  1597. X    }
  1598. X    }
  1599. X    enter(team, "Nowhere", pno);
  1600. X    if (berserk)
  1601. X    me->p_hostile = (FED|ROM|KLI|ORI);    /* unless they are berserk */
  1602. X    else if (practice)
  1603. X    me->p_hostile = bteam;            /* or practice */
  1604. X    else
  1605. X    me->p_hostile = 0;            /* robots are peaceful */
  1606. X
  1607. X    signal(SIGALRM, rmove);
  1608. X    me->p_flags |= PFROBOT;            /* Mark as a robot */
  1609. X    if (practice)
  1610. X    me->p_flags |= PFPRACTR;        /* Mark as a practice robot */
  1611. X    if (practice) {
  1612. X    strncpy(me->p_name, "Hoser", strlen("Hoser"));
  1613. X    me->p_name[strlen("Hoser")] = NULL;
  1614. X    }
  1615. X    else {
  1616. X    strncpy(me->p_name, rnames[team], strlen(rnames[team]));
  1617. X    me->p_name[strlen(rnames[team])] = NULL;
  1618. X    }
  1619. X    strncpy(me->p_login, "Robot", strlen("Robot"));
  1620. X    me->p_login[strlen("Robot")] = NULL;
  1621. X    myship->s_phasercost = 0;
  1622. X    myship->s_torpcost = 0;
  1623. X    myship->s_cloakcost = 0;
  1624. X    if (practice) {
  1625. X    udt.it_interval.tv_sec = 1;        /* Robots get to move 1/sec */
  1626. X    udt.it_interval.tv_usec = 000000;
  1627. X    }
  1628. X    else {
  1629. X    udt.it_interval.tv_sec = 0;        /* Robots get to move 2/sec */
  1630. X    udt.it_interval.tv_usec = 500000;
  1631. X    }
  1632. X    udt.it_value.tv_sec = 1;
  1633. X    udt.it_value.tv_usec = 0;
  1634. X    if (setitimer(ITIMER_REAL, &udt, 0) < 0) {
  1635. X    perror("setitimer");
  1636. X    me->p_status = PFREE;        /* Put robot in game */
  1637. X    exit(1);
  1638. X    }
  1639. X    /* allows robots to be forked by the daemon -- Evil ultrix bullshit */
  1640. X    sigsetmask(0);
  1641. X
  1642. X    me->p_status = PALIVE;        /* Put robot in game */
  1643. X    while (1) {
  1644. X    pause();
  1645. X    }
  1646. X}
  1647. X
  1648. Xwarning(mess)
  1649. Xint mess;
  1650. X{
  1651. X    if (debug)
  1652. X    fprintf(stderr, "warning: %s\n", mess);
  1653. X}
  1654. END_OF_robot.c
  1655. if test 4260 -ne `wc -c <robot.c`; then
  1656.     echo shar: \"robot.c\" unpacked with wrong size!
  1657. fi
  1658. # end of overwriting check
  1659. fi
  1660. if test -f scores.c -a "${1}" != "-c" ; then 
  1661.   echo shar: Will not over-write existing file \"scores.c\"
  1662. else
  1663. echo shar: Extracting \"scores.c\" \(1606 characters\)
  1664. sed "s/^X//" >scores.c <<'END_OF_scores.c'
  1665. X
  1666. X/*
  1667. X
  1668. X    Copyright (c) 1986     Chris Guthrie
  1669. X
  1670. XPermission to use, copy, modify, and distribute this
  1671. Xsoftware and its documentation for any purpose and without
  1672. Xfee is hereby granted, provided that the above copyright
  1673. Xnotice appear in all copies and that both that copyright
  1674. Xnotice and this permission notice appear in supporting
  1675. Xdocumentation.  No representations are made about the
  1676. Xsuitability of this software for any purpose.  It is
  1677. Xprovided "as is" without express or implied warranty.
  1678. X
  1679. X*/
  1680. X
  1681. X#include <stdio.h>
  1682. X#include <sys/types.h>
  1683. X#include <sys/file.h>
  1684. X#include <pwd.h>
  1685. X#include "defs.h"
  1686. X#include "struct.h"
  1687. X
  1688. X#define MAXENT 2000
  1689. X
  1690. Xstruct stats old;
  1691. X
  1692. Xmain()
  1693. X{
  1694. X    int fd;
  1695. X    register int i;
  1696. X    struct passwd *buf;
  1697. X
  1698. X    fd = open(SCOREFILE, O_RDONLY, 0777);
  1699. X    if (fd < 0) {
  1700. X    perror(SCOREFILE);
  1701. X    exit(1);
  1702. X    }
  1703. X    fprintf(stdout, "Name      rtime             cpu       kills  maxkills    losses  entries conqs coups     torps  phasers    abomb aship planets gens ratio Name\n");
  1704. X
  1705. X    for (i = 0; i < MAXENT; i++) {
  1706. X    if (read(fd, &old, sizeof(struct stats)) == 0)
  1707. X        break;
  1708. X    if (old.st_entries > 0) {
  1709. X        buf = getpwuid(i);
  1710. X        if (buf <= 0)
  1711. X        continue;
  1712. X        fprintf(stdout, "%-8s %15d %6d %11.2f    %6.2f %9d %8d %5d %5d %9d %8d %8d %5d %7d %4d %5.3f %-8s\n",
  1713. X        buf->pw_name,
  1714. X        old.st_time,
  1715. X        old.st_cpu,
  1716. X        old.st_kills,
  1717. X        old.st_maxkills,
  1718. X        old.st_losses,
  1719. X        old.st_entries,
  1720. X        old.st_conqs,
  1721. X        old.st_coups,
  1722. X        old.st_torps,
  1723. X        old.st_phasers,
  1724. X        old.st_armsbomb,
  1725. X        old.st_armsship,
  1726. X        old.st_planets,
  1727. X        old.st_genocides,
  1728. X        (old.st_losses ? old.st_kills / old.st_losses : 0.0),
  1729. X        buf->pw_name);
  1730. X
  1731. X    }
  1732. X    }
  1733. X}
  1734. END_OF_scores.c
  1735. if test 1606 -ne `wc -c <scores.c`; then
  1736.     echo shar: \"scores.c\" unpacked with wrong size!
  1737. fi
  1738. # end of overwriting check
  1739. fi
  1740. if test -f startdaemon.c -a "${1}" != "-c" ; then 
  1741.   echo shar: Will not over-write existing file \"startdaemon.c\"
  1742. else
  1743. echo shar: Extracting \"startdaemon.c\" \(1571 characters\)
  1744. sed "s/^X//" >startdaemon.c <<'END_OF_startdaemon.c'
  1745. X
  1746. X/*
  1747. X
  1748. X    Copyright (c) 1986     Chris Guthrie
  1749. X
  1750. XPermission to use, copy, modify, and distribute this
  1751. Xsoftware and its documentation for any purpose and without
  1752. Xfee is hereby granted, provided that the above copyright
  1753. Xnotice appear in all copies and that both that copyright
  1754. Xnotice and this permission notice appear in supporting
  1755. Xdocumentation.  No representations are made about the
  1756. Xsuitability of this software for any purpose.  It is
  1757. Xprovided "as is" without express or implied warranty.
  1758. X
  1759. X*/
  1760. X
  1761. X
  1762. X#include <stdio.h>
  1763. X#include <X/Xlib.h>
  1764. X#include <sys/types.h>
  1765. X#include <signal.h>
  1766. X#include "defs.h"
  1767. X#include "struct.h"
  1768. X#include "data.h"
  1769. X
  1770. Xstartdaemon()
  1771. X{
  1772. X    int i;
  1773. X
  1774. X    i = fork();
  1775. X    if (i == 0) {
  1776. X    XCloseDisplay(display);
  1777. X    execl(DAEMON, "daemon", 0);
  1778. X    perror(DAEMON);
  1779. X    fprintf(stderr, "Couldn't start daemon!!!\n");
  1780. X    _exit(1);
  1781. X    }
  1782. X}
  1783. X
  1784. Xpractice_robo()
  1785. X{
  1786. X    char *arg1;
  1787. X    register int i;
  1788. X    register struct player *j;
  1789. X
  1790. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  1791. X    if (j->p_status != PALIVE)
  1792. X        continue;
  1793. X    if (j == me)
  1794. X        continue;
  1795. X    warning("Can't send in practice robot with other players in the game.");
  1796. X    return;
  1797. X    }
  1798. X
  1799. X    if (fork() == 0) {
  1800. X    (void) signal(SIGALRM, SIG_DFL);
  1801. X    (void) close(0);
  1802. X    (void) close(1);
  1803. X    (void) close(2);
  1804. X    (void) close(dpyno());
  1805. X    switch (me->p_team) {
  1806. X        case FED:
  1807. X        arg1 = "-Tf";
  1808. X        break;
  1809. X        case ROM:
  1810. X        arg1 = "-Tr";
  1811. X        break;
  1812. X        case KLI:
  1813. X        arg1 = "-Tk";
  1814. X        break;
  1815. X        case ORI:
  1816. X        arg1 = "-To";
  1817. X        break;
  1818. X    }
  1819. X    execl(ROBOT, "robot", arg1, "-p", "-f", "-h", 0);
  1820. X    /* If we get here, we are hosed anyway */
  1821. X    _exit(1);
  1822. X    }
  1823. X}
  1824. END_OF_startdaemon.c
  1825. if test 1571 -ne `wc -c <startdaemon.c`; then
  1826.     echo shar: \"startdaemon.c\" unpacked with wrong size!
  1827. fi
  1828. # end of overwriting check
  1829. fi
  1830. if test -f torp.c -a "${1}" != "-c" ; then 
  1831.   echo shar: Will not over-write existing file \"torp.c\"
  1832. else
  1833. echo shar: Extracting \"torp.c\" \(2629 characters\)
  1834. sed "s/^X//" >torp.c <<'END_OF_torp.c'
  1835. X
  1836. X/*
  1837. X
  1838. X    Copyright (c) 1986     Chris Guthrie
  1839. X
  1840. XPermission to use, copy, modify, and distribute this
  1841. Xsoftware and its documentation for any purpose and without
  1842. Xfee is hereby granted, provided that the above copyright
  1843. Xnotice appear in all copies and that both that copyright
  1844. Xnotice and this permission notice appear in supporting
  1845. Xdocumentation.  No representations are made about the
  1846. Xsuitability of this software for any purpose.  It is
  1847. Xprovided "as is" without express or implied warranty.
  1848. X
  1849. X*/
  1850. X
  1851. X#include <X/Xlib.h>
  1852. X#include <stdio.h>
  1853. X#include <sys/types.h>
  1854. X#include <sys/ipc.h>
  1855. X#include <sys/shm.h>
  1856. X#include "defs.h"
  1857. X#include "struct.h"
  1858. X#include "data.h"
  1859. X
  1860. X/* Launch torp */
  1861. X
  1862. X/*
  1863. X** If a set of given conditions are met, fire a single torp in direction
  1864. X** course.  Type is used because robots are allowed to shoot straight.
  1865. X** Torps sent with status TMOVE wobble a bit.  TSTRAIGHT torps (fired
  1866. X** by robots) move in a straight line.
  1867. X**
  1868. X** torp->t_fuse is the life of the torpedo.  It is set here based on
  1869. X** a random function.  Torps currently live two to five seconds.
  1870. X*/
  1871. X
  1872. Xstatic unsigned short lasttime;
  1873. X#define GAP 10
  1874. Xlong random();
  1875. X
  1876. Xntorp(course, type, curtime)
  1877. Xunsigned char course;
  1878. Xint type;
  1879. Xunsigned short curtime;
  1880. X{
  1881. X    register int i;
  1882. X    register struct torp *k;
  1883. X
  1884. X/* Hose people who use the 't' key bursts.  */
  1885. X/* Boy will they be surprised!!! */
  1886. X
  1887. X    if (me->p_flags & PFWEP) {
  1888. X    warning("Weapons overheated");
  1889. X    return;
  1890. X    }
  1891. X    if ((curtime - lasttime) < GAP) {
  1892. X    me->p_wtemp += 20;        /* Heat weapons */
  1893. X    return;
  1894. X    }
  1895. X    else {
  1896. X    lasttime = curtime;
  1897. X    }
  1898. X
  1899. X    if (me->p_ntorp == MAXTORP) {
  1900. X    me->p_wtemp += 10;        /* Heat weapons */
  1901. X    warning("Torps limited to 12");
  1902. X    return;
  1903. X    }
  1904. X    if (me->p_fuel < myship->s_torpcost) {
  1905. X    warning("Not enough fuel for torp");
  1906. X    return;
  1907. X    }
  1908. X    if (me->p_flags & PFREPAIR) {
  1909. X    warning("Can't fire while repairing");
  1910. X    return;
  1911. X    }
  1912. X    if (me->p_flags & PFCLOAK) {
  1913. X    warning("Cannot fire while cloaked");
  1914. X    return;
  1915. X    }
  1916. X    me->p_ntorp++;
  1917. X    me->p_fuel -= myship->s_torpcost;
  1918. X    me->p_wtemp += (myship->s_torpcost / 10) - 10;    /* Heat weapons */
  1919. X    for (i = me->p_no * MAXTORP, k = &torps[i];        /* Find a free torp */
  1920. X    i < me->p_no * MAXTORP + MAXTORP; i++, k++) {
  1921. X        if (k->t_status == TFREE)
  1922. X        break;
  1923. X    }
  1924. X
  1925. X    /* Setup data in new torp */
  1926. X
  1927. X    k->t_no = i;
  1928. X    k->t_status = type;
  1929. X    k->t_owner = me->p_no;
  1930. X    k->t_team = me->p_team;
  1931. X    k->t_x = me->p_x;
  1932. X    k->t_y = me->p_y;
  1933. X    k->t_dir = course;
  1934. X    k->t_damage = myship->s_torpdamage;
  1935. X    k->t_speed = myship->s_torpspeed;
  1936. X    k->t_war = me->p_hostile | me->p_swar;
  1937. X    k->t_fuse = (random() % 30) + 20;
  1938. X    mystats->st_torps++;
  1939. X}
  1940. END_OF_torp.c
  1941. if test 2629 -ne `wc -c <torp.c`; then
  1942.     echo shar: \"torp.c\" unpacked with wrong size!
  1943. fi
  1944. # end of overwriting check
  1945. fi
  1946. if test -f util.c -a "${1}" != "-c" ; then 
  1947.   echo shar: Will not over-write existing file \"util.c\"
  1948. else
  1949. echo shar: Extracting \"util.c\" \(3209 characters\)
  1950. sed "s/^X//" >util.c <<'END_OF_util.c'
  1951. X
  1952. X/*
  1953. X
  1954. X    Copyright (c) 1986     Chris Guthrie
  1955. X
  1956. XPermission to use, copy, modify, and distribute this
  1957. Xsoftware and its documentation for any purpose and without
  1958. Xfee is hereby granted, provided that the above copyright
  1959. Xnotice appear in all copies and that both that copyright
  1960. Xnotice and this permission notice appear in supporting
  1961. Xdocumentation.  No representations are made about the
  1962. Xsuitability of this software for any purpose.  It is
  1963. Xprovided "as is" without express or implied warranty.
  1964. X
  1965. X*/
  1966. X
  1967. X#include <X/Xlib.h>
  1968. X#include <stdio.h>
  1969. X#include <math.h>
  1970. X#include <signal.h>
  1971. X#include "defs.h"
  1972. X#include "struct.h"
  1973. X#include "data.h"
  1974. X
  1975. X/*
  1976. X** Provide the angular distance between two angles.
  1977. X*/
  1978. Xangdist(x, y)
  1979. Xunsigned char x, y;
  1980. X{
  1981. X    register unsigned char res;
  1982. X
  1983. X    res = ABS(x - y);
  1984. X    if (res > 128)
  1985. X    return(256 - (int) res);
  1986. X    return((int) res);
  1987. X}
  1988. X
  1989. X#define WINSIDE 500
  1990. X
  1991. X/*
  1992. X** Find the object nearest mouse.  Returns a pointer to an
  1993. X** obtype structure.  This is used for info and locking on.
  1994. X**
  1995. X** Because we are never interested in it, this function will
  1996. X** never return your own ship as the target.
  1997. X**
  1998. X** Finally, this only works on the two main windows
  1999. X*/
  2000. X
  2001. Xstatic struct obtype _target;
  2002. X
  2003. Xstruct obtype *
  2004. Xgettarget(ww, x, y, targtype)
  2005. XWindow ww;
  2006. Xint x, y;
  2007. Xint targtype;
  2008. X{
  2009. X    register int i;
  2010. X    register struct player *j;
  2011. X    register struct planet *k;
  2012. X    int    g_x, g_y;
  2013. X    double dist, closedist;
  2014. X
  2015. X    if (ww == mapw) {
  2016. X    g_x = x * GWIDTH / WINSIDE;
  2017. X    g_y = y * GWIDTH / WINSIDE;
  2018. X    }
  2019. X    else {
  2020. X    g_x = me->p_x + ((x - WINSIDE/2) * SCALE);
  2021. X    g_y = me->p_y + ((y - WINSIDE/2) * SCALE);
  2022. X    }
  2023. X    closedist = GWIDTH;
  2024. X
  2025. X    if (targtype & TARG_PLANET) {
  2026. X    for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++) {
  2027. X        dist = hypot((double) (g_x - k->pl_x), (double) (g_y - k->pl_y));
  2028. X        if (dist < closedist) {
  2029. X        _target.o_type = PLANETTYPE;
  2030. X        _target.o_num = i;
  2031. X        closedist = dist;
  2032. X        }
  2033. X
  2034. X    }
  2035. X    }
  2036. X
  2037. X    if (targtype & TARG_PLAYER) {
  2038. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  2039. X        if (j->p_status != PALIVE)
  2040. X        continue;
  2041. X        if ((j->p_flags & PFCLOAK) && (!(targtype & TARG_CLOAK)))
  2042. X        continue;
  2043. X        if (j == me)
  2044. X        continue;
  2045. X        dist = hypot((double) (g_x - j->p_x), (double) (g_y - j->p_y));
  2046. X        if (dist < closedist) {
  2047. X        _target.o_type = PLAYERTYPE;
  2048. X        _target.o_num = i;
  2049. X        closedist = dist;
  2050. X        }
  2051. X    }
  2052. X    }
  2053. X
  2054. X    if (closedist == GWIDTH) {        /* Didn't get one.  bad news */
  2055. X    _target.o_type = PLAYERTYPE;
  2056. X    _target.o_num = me->p_no;    /* Return myself.  Oh well... */
  2057. X    return(&_target);
  2058. X    }
  2059. X    else {
  2060. X    return(&_target);
  2061. X    }
  2062. X}
  2063. X
  2064. X/*
  2065. X** Tell us if a window is currently visible on the screen
  2066. X*/
  2067. X
  2068. Xismapped(win)
  2069. XWindow win;
  2070. X{
  2071. X    WindowInfo info;
  2072. X    
  2073. X    XQueryWindow(win, &info);
  2074. X
  2075. X    return (info.mapped == IsMapped);
  2076. X}
  2077. X
  2078. X#ifdef hpux
  2079. X
  2080. Xsrandom(foo)
  2081. Xint foo;
  2082. X{
  2083. X    rand(foo);
  2084. X}
  2085. X
  2086. Xrandom()
  2087. X{
  2088. X    return(rand());
  2089. X}
  2090. X
  2091. X#include <time.h>
  2092. X#include <sys/resource.h>
  2093. X
  2094. Xgetrusage(foo, buf)
  2095. Xint foo;
  2096. Xstruct rusage *buf;
  2097. X{
  2098. X    buf->ru_utime.tv_sec = 0;
  2099. X    buf->ru_stime.tv_sec = 0;
  2100. X}
  2101. X
  2102. X#include <sys/signal.h>
  2103. X
  2104. Xint (*
  2105. Xsignal(sig, funct))()
  2106. Xint sig;
  2107. Xint (*funct)();
  2108. X{
  2109. X    struct sigvec vec, oldvec;
  2110. X
  2111. X    sigvector(sig, 0, &vec);
  2112. X    vec.sv_handler = funct;
  2113. X    sigvector(sig, &vec, (struct sigvec *) 0);
  2114. X}
  2115. X#endif hpux
  2116. END_OF_util.c
  2117. if test 3209 -ne `wc -c <util.c`; then
  2118.     echo shar: \"util.c\" unpacked with wrong size!
  2119. fi
  2120. # end of overwriting check
  2121. fi
  2122. echo shar: End of archive 5 \(of 6\).
  2123. cp /dev/null ark5isdone
  2124. MISSING=""
  2125. for I in 1 2 3 4 5 6 ; do
  2126.     if test ! -f ark${I}isdone ; then
  2127.     MISSING="${MISSING} ${I}"
  2128.     fi
  2129. done
  2130. if test "${MISSING}" = "" ; then
  2131.     echo You have unpacked all 6 archives.
  2132.     rm -f ark[1-9]isdone
  2133. else
  2134.     echo You still need to unpack the following archives:
  2135.     echo "        " ${MISSING}
  2136. fi
  2137. ##  End of shell archive.
  2138. exit 0
  2139.  
  2140.