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

  1. Article 49 of comp.sources.games:
  2. Path: ncrcce!rd1632!ncrlnk!ncrcae!ece-csc!mcnc!seismo!rochester!cornell!uw-beaver!tektronix!tekgen!tekred!games-request
  3. From: games-request@tekred.TEK.COM
  4. Newsgroups: comp.sources.games
  5. Subject: v01i075:  xtrek - mulitplayer space war for X-windows, Part03/06
  6. Message-ID: <1368@tekred.TEK.COM>
  7. Date: 2 Jul 87 19:15:57 GMT
  8. Sender: billr@tekred.TEK.COM
  9. Lines: 1948
  10. Approved: billr@tekred.TEK.COM
  11.  
  12. Submitted by: Chris Guthrie <chris%ic.Berkeley.EDU@ucbvax.berkeley.edu>
  13. Comp.sources.games: Volume 1, Issue 75
  14. Archive-name: xtrek/Part03
  15.  
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 3 (of 6)."
  24. # Contents:  detonate.c input.c newwin.c redraw.c
  25. # Wrapped by billr@tekred on Thu Jul  2 10:26:30 1987
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f detonate.c -a "${1}" != "-c" ; then 
  28.   echo shar: Will not over-write existing file \"detonate.c\"
  29. else
  30. echo shar: Extracting \"detonate.c\" \(2757 characters\)
  31. sed "s/^X//" >detonate.c <<'END_OF_detonate.c'
  32. X
  33. X/*
  34. X
  35. X    Copyright (c) 1986     Chris Guthrie
  36. X
  37. XPermission to use, copy, modify, and distribute this
  38. Xsoftware and its documentation for any purpose and without
  39. Xfee is hereby granted, provided that the above copyright
  40. Xnotice appear in all copies and that both that copyright
  41. Xnotice and this permission notice appear in supporting
  42. Xdocumentation.  No representations are made about the
  43. Xsuitability of this software for any purpose.  It is
  44. Xprovided "as is" without express or implied warranty.
  45. X
  46. X*/
  47. X
  48. X#include <X/Xlib.h>
  49. X#include <stdio.h>
  50. X#include <sys/types.h>
  51. X#include <sys/ipc.h>
  52. X#include <sys/shm.h>
  53. X#include "defs.h"
  54. X#include "struct.h"
  55. X#include "data.h"
  56. X
  57. X/* Detonate torp */
  58. X
  59. X/*
  60. X** Detonating torps have become a difficult part of the game.  Players
  61. X** quickly learned that detonating their own torps when the cloud was
  62. X** around another player, caused that player to die very quickly.  I
  63. X** removed that feature because it lead to people not having to shoot
  64. X** well to collect kills.  Now when players detonate their own torps,
  65. X** the torps just vanish and become available for future firing.
  66. X*/
  67. X
  68. Xdetmine()
  69. X{
  70. X    register int i;
  71. X
  72. X    if (me->p_flags & PFWEP) {
  73. X    warning("Weapons overheated");
  74. X    return;
  75. X    }
  76. X    for (i = 0; i < MAXTORP; i++) {
  77. X    if (torps[i + (me->p_no * MAXTORP)].t_status == TMOVE) {
  78. X        torps[i + (me->p_no * MAXTORP)].t_status = TOFF;
  79. X    }
  80. X    else if (torps[i + (me->p_no * MAXTORP)].t_status == TSTRAIGHT) {
  81. X        torps[i + (me->p_no * MAXTORP)].t_status = TOFF;
  82. X    }
  83. X    }
  84. X}
  85. X
  86. X/*
  87. X** Here we have another flaw.  Detonating other players torps can be a
  88. X** very quick way to die.  Why?  Because you always take some damage.
  89. X** Experienced players never detonate other players' torps.  Balance is
  90. X** really hard to obtain with this type of function.  Technically, a
  91. X** player could nearly continuously detonate torps (at least faster than
  92. X** they could be fired) and never be hurt, if I allowed less damage as
  93. X** a possible result.  So here it sits.
  94. X*/
  95. X
  96. Xdetothers()
  97. X{
  98. X    register int h, i;
  99. X    int dx, dy;
  100. X    register struct torp *j;
  101. X
  102. X    if (me->p_fuel < myship->s_detcost) {
  103. X    warning("Not enough fuel to detonate");
  104. X    return;
  105. X    }
  106. X    if (me->p_flags & PFWEP) {
  107. X    warning("Weapons overheated");
  108. X    return;
  109. X    }
  110. X    me->p_fuel -= myship->s_detcost;
  111. X    me->p_wtemp += myship->s_detcost / 5;
  112. X
  113. X    for (h = 0; h < MAXPLAYER; h++) {
  114. X    if ((players[h].p_status == PFREE) || (h == me->p_no))
  115. X        continue;
  116. X    for (i = h * MAXTORP; i < MAXTORP * (h + 1); i++) {
  117. X        j = &torps[i];
  118. X        if ((j->t_status == TMOVE) || (j->t_status == TSTRAIGHT)) {
  119. X        dx = j->t_x - me->p_x;
  120. X        dy = j->t_y - me->p_y;
  121. X        if (ABS(dx) > DETDIST || ABS(dy) > DETDIST) /* XXX */
  122. X            continue;
  123. X        if (dx * dx + dy * dy < DETDIST * DETDIST)
  124. X            j->t_status = TDET;
  125. X        }
  126. X    }
  127. X    }
  128. X}
  129. END_OF_detonate.c
  130. if test 2757 -ne `wc -c <detonate.c`; then
  131.     echo shar: \"detonate.c\" unpacked with wrong size!
  132. fi
  133. # end of overwriting check
  134. fi
  135. if test -f input.c -a "${1}" != "-c" ; then 
  136.   echo shar: Will not over-write existing file \"input.c\"
  137. else
  138. echo shar: Extracting \"input.c\" \(10383 characters\)
  139. sed "s/^X//" >input.c <<'END_OF_input.c'
  140. X
  141. X/*
  142. X
  143. X    Copyright (c) 1986     Chris Guthrie
  144. X
  145. XPermission to use, copy, modify, and distribute this
  146. Xsoftware and its documentation for any purpose and without
  147. Xfee is hereby granted, provided that the above copyright
  148. Xnotice appear in all copies and that both that copyright
  149. Xnotice and this permission notice appear in supporting
  150. Xdocumentation.  No representations are made about the
  151. Xsuitability of this software for any purpose.  It is
  152. Xprovided "as is" without express or implied warranty.
  153. X
  154. X*/
  155. X
  156. X#include <X/Xlib.h>
  157. X#include <stdio.h>
  158. X#include <math.h>
  159. X#include <sys/types.h>
  160. X#ifdef hpux
  161. X#include <time.h>
  162. X#else hpux
  163. X#include <sys/time.h>
  164. X#endif hpux
  165. X#include <signal.h>
  166. X#include <errno.h>
  167. X#include "defs.h"
  168. X#include "struct.h"
  169. X#include "data.h"
  170. X
  171. X#define WINSIDE 500
  172. X
  173. Xstatic int    doTheRedrawDude, skipUpdates = 1;
  174. X
  175. Xinitinput()
  176. X{
  177. X    XSelectInput(iconWin, ExposeWindow|ExposeRegion);
  178. X    XSelectInput(w, 
  179. X    KeyPressed|ButtonPressed|ButtonReleased|ExposeRegion|ExposeWindow);
  180. X    XSelectInput(mapw, 
  181. X    KeyPressed|ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  182. X    XSelectInput(messagew, 
  183. X    KeyPressed|ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  184. X    XSelectInput(tstatw, ExposeWindow|ExposeRegion);
  185. X    /*  May want this for a later refresh 
  186. X    XSelectInput(war,
  187. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  188. X    */
  189. X    XSelectInput(warf,
  190. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  191. X    XSelectInput(warr,
  192. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  193. X    XSelectInput(wark,
  194. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  195. X    XSelectInput(waro,
  196. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  197. X    XSelectInput(wargo,
  198. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  199. X    XSelectInput(warno,
  200. X    ButtonPressed|ButtonReleased|ExposeWindow|ExposeRegion);
  201. X    XSelectInput(helpWin,ExposeRegion);
  202. X    XSelectInput(planetw,ExposeRegion);
  203. X    XSelectInput(playerw,ExposeRegion);
  204. X}
  205. X
  206. XsetRedrawFlag()
  207. X{
  208. X    /* let the daemon know I'm real */
  209. X    if (!watch)
  210. X        me->p_ghostbuster = 0;
  211. X
  212. X    if (skipUpdates)
  213. X        doTheRedrawDude = 1;
  214. X    else
  215. X        doTheRedrawDude++;
  216. X}
  217. X
  218. Xinput()
  219. X{
  220. X    XEvent data;
  221. X    XKeyOrButtonEvent *tmp;
  222. X    char *buf;
  223. X    int nchar;
  224. X    int fd;
  225. X    struct itimerval    udt;
  226. X
  227. X    signal(SIGALRM, setRedrawFlag);
  228. X    udt.it_interval.tv_sec = 0;
  229. X    udt.it_interval.tv_usec = 200000;
  230. X    udt.it_value.tv_sec = 0;
  231. X    udt.it_value.tv_usec = 200000;
  232. X    setitimer(ITIMER_REAL, &udt, 0);
  233. X
  234. X    tmp = (XKeyOrButtonEvent *) &data;
  235. X
  236. X    while (1) {
  237. X    while (doTheRedrawDude-- > 0) {
  238. X        intrupt();
  239. X    }
  240. X    while (!XPending()) {
  241. X        fd = (1 << dpyno());
  242. X        select(32, &fd, 0, 0, 0);
  243. X        while (doTheRedrawDude-- > 0)
  244. X        intrupt();
  245. X    }
  246. X    XNextEvent(&data);
  247. X    if ((!(copilot || watch)) && (me->p_updates > delay)) {
  248. X        me->p_flags &= ~(PFWAR);
  249. X    }
  250. X    switch ((int) data.type) {
  251. X        case KeyPressed:
  252. X        if (inputIgnored())
  253. X            continue;
  254. X        if ((me->p_flags & PFSELFDEST) && (!watch)) {
  255. X            me->p_flags &= ~PFSELFDEST;
  256. X            warning("Self Destruct has been canceled");
  257. X        }
  258. X        buf = XLookupMapping(&data, &nchar);
  259. X        if (nchar > 0) {
  260. X            if (data.window == messagew)
  261. X            smessage(*buf);
  262. X            else
  263. X            keyaction(*buf, tmp);
  264. X        }
  265. X        break;
  266. X        case ButtonPressed:
  267. X        if (inputIgnored())
  268. X            continue;
  269. X        if ((me->p_flags & PFSELFDEST) && (!watch)) {
  270. X            me->p_flags &= ~PFSELFDEST;
  271. X            warning("Self Destruct has been canceled");
  272. X        }
  273. X        if (data.window == warf) 
  274. X            waraction(tmp);
  275. X        else if (data.window == warr) 
  276. X            waraction(tmp);
  277. X        else if (data.window == wark) 
  278. X            waraction(tmp);
  279. X        else if (data.window == waro) 
  280. X            waraction(tmp);
  281. X        else if (data.window == wargo) 
  282. X            waraction(tmp);
  283. X        else if (data.window == warno) 
  284. X            waraction(tmp);
  285. X        else
  286. X            buttonaction(tmp);
  287. X        break;
  288. X        case ExposeRegion:
  289. X        case ExposeWindow:
  290. X        if (data.window == statwin && showStats)
  291. X            redrawStats(statwin);
  292. X        else if (data.window == tstatw)
  293. X            redrawTstats();
  294. X        else if (data.window == mapw)
  295. X            redrawall = 1;
  296. X        else if (data.window == iconWin)
  297. X            drawIcon();
  298. X        else if (data.window == helpWin)
  299. X            fillhelp();
  300. X        else if (data.window == playerw)
  301. X            playerlist();
  302. X        else if (data.window == planetw)
  303. X            planetlist();
  304. X        break;
  305. X        default:
  306. X        break;
  307. X    }
  308. X    }
  309. X}
  310. X
  311. Xkeyaction(key, data)
  312. Xchar key;
  313. XXKeyOrButtonEvent *data;
  314. X{
  315. X    char buf[80];
  316. X    unsigned char course;
  317. X    struct obtype *gettarget(), *target;
  318. X    struct player *p;
  319. X    struct planet *pl;
  320. X
  321. X    if (watch && !index("LPSMiQ?hw ", key)) {
  322. X    char    buf[BUFSIZ];
  323. X
  324. X    sprintf(buf, "'%c' command is not permitted in watch mode.", key);
  325. X    warning(buf);
  326. X    return;
  327. X    }
  328. X    switch(key) {
  329. X    case '0':
  330. X    case '1':
  331. X    case '2':
  332. X    case '3':
  333. X    case '4':
  334. X    case '5':
  335. X    case '6':
  336. X    case '7':
  337. X    case '8':
  338. X    case '9':
  339. X        set_speed(key - '0');
  340. X        break;
  341. X    case 'k': /* k = set course */
  342. X        course = getcourse(data->window, data->x, data->y);
  343. X        set_course(course);
  344. X        me->p_flags &= ~(PFPLOCK | PFPLLOCK);
  345. X        break;
  346. X    case 'p': /* p = fire phasers */
  347. X        course = getcourse(data->window, data->x, data->y);
  348. X        phaser(course);
  349. X        break;
  350. X    case 't': /* t = launch torps */
  351. X        course = getcourse(data->window, data->x, data->y);
  352. X        ntorp(course, TMOVE, data->time);
  353. X        break;
  354. X    case 'd': /* d = detonate other torps */
  355. X        detothers();
  356. X        break;
  357. X    case 'D': /* D = detonate my torps */
  358. X        detmine();
  359. X        break;
  360. X    case '+': /* + = Put shields up */
  361. X        shield_up();
  362. X        break;
  363. X    case '-': /* - = Put shields down */
  364. X        shield_down();
  365. X        break;
  366. X    case 'u': /* u = toggle shields */
  367. X    case 's': /* For Serge */
  368. X        shield_tog();
  369. X        break;
  370. X    case 'b': /* b = bomb planet */
  371. X        bomb_planet();
  372. X        break;
  373. X    case 'z': /* z = beam up */
  374. X        beam_up();
  375. X        break;
  376. X    case 'x': /* x = beam down */
  377. X        beam_down();
  378. X        break;
  379. X    case 'R': /* R = Go into repair mode */
  380. X        me->p_flags &= ~(PFPLOCK | PFPLLOCK);
  381. X        repair();
  382. X        break;
  383. X    case 'o': /* o = orbit nearest planet */
  384. X        me->p_flags &= ~(PFPLOCK | PFPLLOCK);
  385. X        orbit();
  386. X        break;
  387. X    case 'Q':
  388. X        if (copilot || watch)
  389. X        exit(1);
  390. X        me->p_flags |= PFSELFDEST;
  391. X        selfdest = me->p_updates + 100;
  392. X        warning("Self destruct initiated");
  393. X        break;
  394. X    case '?': /* ? = Redisplay all messages */
  395. X        repeat_message();
  396. X        break;
  397. X    case 'c': /* c = cloak */
  398. X        cloak();
  399. X        break;
  400. X    case 'C': /* C = coups */
  401. X        coup();
  402. X        break;
  403. X    case 'l': /* l = lock onto */
  404. X        /* since a robot would never use this function (it's user
  405. X           Interface dependent,) all the work is done here instead
  406. X           of in interface.c */
  407. X        target = gettarget(data->window, data->x, data->y,
  408. X        TARG_PLAYER|TARG_PLANET);
  409. X        if (target->o_type == PLAYERTYPE) {
  410. X        me->p_flags |= PFPLOCK;
  411. X        me->p_flags &= ~(PFPLLOCK|PFORBIT|PFBEAMUP|PFBEAMDOWN|PFBOMB);
  412. X        me->p_playerl = target->o_num;
  413. X        p = &players[target->o_num];
  414. X        sprintf(buf, "Locking onto %s (%c%d)",
  415. X            p->p_name,
  416. X            teamlet[p->p_team],
  417. X            p->p_no);
  418. X        warning(buf);
  419. X        }
  420. X        else {     /* It's a planet */
  421. X        me->p_flags |= PFPLLOCK;
  422. X        me->p_flags &= ~(PFPLOCK|PFORBIT|PFBEAMUP|PFBEAMDOWN|PFBOMB);
  423. X        me->p_planet = target->o_num;
  424. X        pl = &planets[target->o_num];
  425. X        sprintf(buf, "Locking onto %s",
  426. X            pl->pl_name);
  427. X        warning(buf);
  428. X        }
  429. X        break;
  430. X    case '@': /* @ = toggle copilot permissions */
  431. X        me->p_flags ^= PFCOPILOT;
  432. X        break;
  433. X    case '*': /* * = send in practice robot */
  434. X        practice_robo();
  435. X        break;
  436. X
  437. X    /* Start of display functions */
  438. X    case ' ': /* ' ' = clear special windows */
  439. X        if (ismapped(playerw))
  440. X        XUnmapWindow(playerw);
  441. X        if (ismapped(planetw))
  442. X        XUnmapWindow(planetw);
  443. X        if (infomapped)
  444. X        destroyInfo();
  445. X        if (ismapped(helpWin))
  446. X        XUnmapWindow(helpWin);
  447. X        if (ismapped(war))
  448. X        XUnmapWindow(war);
  449. X        break;
  450. X    case 'L': /* L = Player list */
  451. X        if (ismapped(playerw)) {
  452. X        XUnmapWindow(playerw);
  453. X        } else {
  454. X        XMapWindow(playerw);
  455. X        }
  456. X        break;
  457. X    case 'P': /* P = Planet list */
  458. X        if (ismapped(planetw)) {
  459. X        XUnmapWindow(planetw);
  460. X        } else {
  461. X        XMapWindow(planetw);
  462. X        }
  463. X        break;
  464. X    case 'S': /* S = toggle stat mode */
  465. X       if (showStats) {
  466. X        showStats = !showStats;
  467. X        closeStats(statwin);
  468. X       } else {
  469. X        statwin = openStats(me);
  470. X        showStats = !showStats;
  471. X       }
  472. X       break;
  473. X    case 'M': /* M = Toggle Map mode */
  474. X        mapmode = !mapmode;
  475. X        break;
  476. X    case 'N': /* N = Toggle Name mode */
  477. X        namemode = !namemode;
  478. X        break;
  479. X    case 'i': /* i = get information */
  480. X        if (!infomapped)
  481. X        inform(data->window, data->x, data->y);
  482. X        else
  483. X        destroyInfo();
  484. X        break;
  485. X    case 'h': /* h = Map help window */
  486. X        if (ismapped(helpWin)) {
  487. X        XUnmapWindow(helpWin);
  488. X        } else {
  489. X        XMapWindow(helpWin);
  490. X        }
  491. X        break;
  492. X    case 'w': /* w = map war stuff */
  493. X        if (copilot) {
  494. X        warning("Copilots cannot alter war settings");
  495. X        break;
  496. X        }
  497. X        if (ismapped(war))
  498. X        XUnmapWindow(war);
  499. X        else
  500. X        warwindow();
  501. X        break;
  502. X    default:
  503. X        XFeep(0);
  504. X        break;
  505. X    }
  506. X}
  507. X
  508. Xbuttonaction(data)
  509. XXKeyOrButtonEvent *data;
  510. X{
  511. X    unsigned char course;
  512. X    struct obtype *gettarget(), *target;
  513. X
  514. X    if (watch) {    /* Special case */
  515. X    target = gettarget(data->window, data->x, data->y,
  516. X        TARG_PLAYER|TARG_CLOAK);
  517. X    setwatch(target->o_num);
  518. X    return;
  519. X    }
  520. X
  521. X    if ((data->detail & 0xf) == RightButton) {
  522. X    course = getcourse(data->window, data->x, data->y);
  523. X    me->p_desdir = course;
  524. X    me->p_flags &= ~(PFPLOCK | PFPLLOCK);
  525. X    }
  526. X    else if ((data->detail & 0xf) == LeftButton) {
  527. X    course = getcourse(data->window, data->x, data->y);
  528. X    ntorp(course, TMOVE, data->time);
  529. X    }
  530. X    else if ((data->detail & 0xf) == MiddleButton) {
  531. X    course = getcourse(data->window, data->x, data->y);
  532. X    phaser(course);
  533. X    }
  534. X}
  535. X
  536. Xgetcourse(ww, x, y)
  537. XWindow ww;
  538. Xint x, y;
  539. X{
  540. X    if (ww == mapw) {
  541. X    int    me_x, me_y;
  542. X
  543. X    me_x = me->p_x * WINSIDE / GWIDTH;
  544. X    me_y = me->p_y * WINSIDE / GWIDTH;
  545. X    return((unsigned char) (atan2((double) (x - me_x),
  546. X        (double) (me_y - y)) / 3.14159 * 128.));
  547. X    }
  548. X    else
  549. X    return((unsigned char) (atan2((double) (x - WINSIDE/2),
  550. X        (double) (WINSIDE/2 - y))
  551. X        / 3.14159 * 128.));
  552. X}
  553. X
  554. XinputIgnored()
  555. X{
  556. X    if (watch)
  557. X        return(0);
  558. X    if (me->p_status != PALIVE)
  559. X        return (1);
  560. X    if (me->p_flags & PFWAR) {
  561. X        warning("Battle computers being re-programmed");
  562. X        return (1);
  563. X    }
  564. X    return (0);
  565. X}
  566. X
  567. Xsetwatch(pno)
  568. Xint pno;
  569. X{
  570. X    me = &players[pno];
  571. X    myship = &me->p_ship;
  572. X    mystats = &me->p_stats;
  573. X    lastm = mctl->mc_current;
  574. X    redrawall = 1;
  575. X    if (showStats) {
  576. X    closeStats(statwin);
  577. X    statwin = openStats(me);
  578. X    }
  579. X}
  580. END_OF_input.c
  581. if test 10383 -ne `wc -c <input.c`; then
  582.     echo shar: \"input.c\" unpacked with wrong size!
  583. fi
  584. # end of overwriting check
  585. fi
  586. if test -f newwin.c -a "${1}" != "-c" ; then 
  587.   echo shar: Will not over-write existing file \"newwin.c\"
  588. else
  589. echo shar: Extracting \"newwin.c\" \(16570 characters\)
  590. sed "s/^X//" >newwin.c <<'END_OF_newwin.c'
  591. X/*
  592. X
  593. X    Copyright (c) 1986     Chris Guthrie
  594. X
  595. XPermission to use, copy, modify, and distribute this
  596. Xsoftware and its documentation for any purpose and without
  597. Xfee is hereby granted, provided that the above copyright
  598. Xnotice appear in all copies and that both that copyright
  599. Xnotice and this permission notice appear in supporting
  600. Xdocumentation.  No representations are made about the
  601. Xsuitability of this software for any purpose.  It is
  602. Xprovided "as is" without express or implied warranty.
  603. X
  604. X*/
  605. X
  606. X#include <X/Xlib.h>
  607. X#include <stdio.h>
  608. X#include <math.h>
  609. X#include <signal.h>
  610. X#include <sys/types.h>
  611. X#ifdef hpux
  612. X#include <time.h>
  613. X#else hpux
  614. X#include <sys/time.h>
  615. X#endif hpux
  616. X#include "defs.h"
  617. X#include "struct.h"
  618. X#include "data.h"
  619. X#include "bitmaps.h"
  620. X
  621. X#define SIZEOF(a)    (sizeof (a) / sizeof (*(a)))
  622. X
  623. X#define WINSIDE        500
  624. X#define BOXSIDE        (WINSIDE / 5)
  625. X#define BORDER        4
  626. X#define TILESIDE    16
  627. X#define MESSAGESIZE    20
  628. X#define STATSIZE    (MESSAGESIZE * 2 + BORDER)
  629. X#define YOFF        100
  630. X
  631. Xstatic FontInfo    *bigFont;
  632. X    
  633. Xnewwin(hostmon, progname)
  634. Xchar *hostmon, *progname;
  635. X{
  636. X
  637. X    if ((display = XOpenDisplay(hostmon)) == NULL) {
  638. X    perror(hostmon);
  639. X    exit(1);
  640. X    }
  641. X    getResources(progname);
  642. X
  643. X    savebitmaps();
  644. X
  645. X    baseWin = XCreateWindow(RootWindow, 0, YOFF, WINSIDE * 2 + 1 * BORDER,
  646. X    WINSIDE + 2 * BORDER + 2 * MESSAGESIZE, BORDER, gTile, backTile);
  647. X    iconWin = XCreateWindow(RootWindow, 0, 0, icon_width, icon_height,
  648. X    BORDER, gTile, backTile);
  649. X    XSetIconWindow(baseWin, iconWin);
  650. X    w = XCreateWindow(baseWin, -BORDER, -BORDER, WINSIDE, WINSIDE, 
  651. X    BORDER, foreTile, backTile);
  652. X    mapw = XCreateWindow(baseWin, WINSIDE, -BORDER, WINSIDE,
  653. X    WINSIDE, BORDER, foreTile, backTile);
  654. X    tstatw = XCreateWindow(baseWin, -BORDER, WINSIDE, WINSIDE,
  655. X    STATSIZE, BORDER, foreTile, backTile);
  656. X    warnw = XCreateWindow(baseWin, WINSIDE, WINSIDE,
  657. X    WINSIDE, MESSAGESIZE, BORDER, foreTile, backTile);
  658. X    messagew = XCreateWindow(baseWin, WINSIDE,
  659. X    WINSIDE + BORDER + MESSAGESIZE,
  660. X    WINSIDE, MESSAGESIZE, BORDER, foreTile, backTile);
  661. X    planetw = XCreateWindow(w, 10, 10, 47 * dfontinfo->width,
  662. X    (MAXPLANETS + 3) * dfontinfo->height, 2, foreTile, backTile);
  663. X    playerw = XCreateWindow(w, 10, 10, 66 * dfontinfo->width,
  664. X    (MAXPLAYER + 3) * dfontinfo->height, 2, foreTile, backTile);
  665. X    helpWin = XCreateWindow(RootWindow,
  666. X    0, YOFF + WINSIDE + 2 * BORDER + 2 * MESSAGESIZE,
  667. X    WINSIDE * 2 + 1 * BORDER, 10 * dfontinfo->height,
  668. X    BORDER, foreTile, backTile);
  669. X    XDefineCursor(baseWin, crosshair);
  670. X    XDefineCursor(iconWin, crosshair);
  671. X
  672. X/* These windows will be used for setting one's warlike stats */
  673. X
  674. X#define WARHEIGHT (dfontinfo->height * 2)
  675. X#define WARWIDTH (dfontinfo->width * 20)
  676. X#define WARBORDER 2
  677. X    war = XCreateWindow(baseWin, WINSIDE+ 10, -BORDER + 10, WARWIDTH,
  678. X    WARHEIGHT * 6, WARBORDER, foreTile, backTile);
  679. X    warf = XCreateWindow(war, 0, 0 * WARHEIGHT, WARWIDTH,
  680. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  681. X    warr = XCreateWindow(war, 0, 1 * WARHEIGHT, WARWIDTH,
  682. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  683. X    wark = XCreateWindow(war, 0, 2 * WARHEIGHT, WARWIDTH,
  684. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  685. X    waro = XCreateWindow(war, 0, 3 * WARHEIGHT, WARWIDTH,
  686. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  687. X    wargo = XCreateWindow(war, 0, 4 * WARHEIGHT, WARWIDTH,
  688. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  689. X    warno = XCreateWindow(war, 0, 5 * WARHEIGHT, WARWIDTH,
  690. X     WARHEIGHT, WARBORDER, foreTile, backTile);
  691. X
  692. X    XMapWindow(warf);
  693. X    XMapWindow(warr);
  694. X    XMapWindow(wark);
  695. X    XMapWindow(waro);
  696. X    XMapWindow(wargo);
  697. X    XMapWindow(warno);
  698. X}
  699. X
  700. X/*
  701. X * this is separate from newwin.  It should; be called *after*
  702. X * openmem.  If not, expose events will be eaten by the forked
  703. X * process (daemon).
  704. X */
  705. XmapAll()
  706. X{
  707. X    initinput();
  708. X    XMapWindow(mapw);
  709. X    XMapWindow(tstatw);
  710. X    XMapWindow(warnw);
  711. X    XMapWindow(messagew);
  712. X    XMapWindow(w);
  713. X    XMapWindow(baseWin);
  714. X}
  715. X
  716. Xsavebitmaps()
  717. X{
  718. X    register int i;
  719. X    crosshair = XCreateCursor(crossw, crossh, crossbits, crossmask_bits, 8, 8,
  720. X    myColor, backColor, GXcopy);
  721. X    for (i = 0; i < VIEWS; i++) {
  722. X    fedview[i] = XStoreBitmap(ship_width, ship_height, fed_bits[i]);
  723. X    romview[i] = XStoreBitmap(ship_width, ship_height, rom_bits[i]);
  724. X    kliview[i] = XStoreBitmap(ship_width, ship_height, kli_bits[i]);
  725. X    oriview[i] = XStoreBitmap(ship_width, ship_height, ori_bits[i]);
  726. X    }
  727. X    cloud = XStoreBitmap(cloud_width, cloud_height, cloud_bits);
  728. X    etorp = XStoreBitmap(etorp_width, etorp_height, etorp_bits);
  729. X    mtorp = XStoreBitmap(mtorp_width, mtorp_height, mtorp_bits);
  730. X    bplanet = XStoreBitmap(planet_width, planet_height, planet_bits);
  731. X    /*
  732. X    e_bplanetPix = XMakePixmap(bplanet, enemyColor, backColor);
  733. X    a_bplanetPix = XMakePixmap(bplanet, allyColor, backColor);
  734. X    */
  735. X    mbplanet = XStoreBitmap(mplanet_width, mplanet_height, mplanet_bits);
  736. X    /*
  737. X    e_mbplanetPix = XMakePixmap(mbplanet, enemyColor, backColor);
  738. X    a_mbplanetPix = XMakePixmap(mbplanet, allyColor, backColor);
  739. X    */
  740. X    for (i = 0; i < EX_FRAMES; i++) {
  741. X    expview[i] = XStoreBitmap(ex_width, ex_height, ex_bits[i]);
  742. X    }
  743. X    shield = XStoreBitmap(shield_width, shield_height, shield_bits);
  744. X}
  745. X
  746. X/* This routine throws up an entry window for the player. */
  747. X
  748. Xentrywindow() 
  749. X{
  750. X    int team;
  751. X    long    startTime;
  752. X    Window fwin, rwin, kwin, owin, qwin;
  753. X    XEvent event;
  754. X
  755. X    /* The following allows quick choosing of teams */
  756. X    if ((me->p_team & FED) && !mustexit) {
  757. X    fwin = XCreateWindow(w, 0 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  758. X        XMakeTile(shipCol[1]), backTile);
  759. X    XSelectInput(fwin, KeyPressed|ButtonPressed|ButtonReleased|
  760. X        ExposeRegion);
  761. X    XMapWindow(fwin);
  762. X    }
  763. X    else {
  764. X    fwin = XCreateWindow(w, 0 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  765. X        XMakeTile(shipCol[1]), stippleTile);
  766. X    XSelectInput(fwin, ExposeRegion);
  767. X    XMapWindow(fwin);
  768. X    }
  769. X    if ((me->p_team & ROM) && !mustexit) {
  770. X    rwin = XCreateWindow(w, 1 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  771. X        XMakeTile(shipCol[2]), backTile);
  772. X    XSelectInput(rwin, KeyPressed|ButtonPressed|ButtonReleased|
  773. X        ExposeRegion);
  774. X    XMapWindow(rwin);
  775. X    }
  776. X    else {
  777. X    rwin = XCreateWindow(w, 1 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  778. X        XMakeTile(shipCol[2]), stippleTile);
  779. X    XSelectInput(rwin, ExposeRegion);
  780. X    XMapWindow(rwin);
  781. X    }
  782. X    if ((me->p_team & KLI) && !mustexit) {
  783. X    kwin = XCreateWindow(w, 2 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  784. X        XMakeTile(shipCol[3]), backTile);
  785. X    XSelectInput(kwin, KeyPressed|ButtonPressed|ButtonReleased|
  786. X        ExposeRegion);
  787. X    XMapWindow(kwin);
  788. X    }
  789. X    else {
  790. X    kwin = XCreateWindow(w, 2 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  791. X        XMakeTile(shipCol[3]), stippleTile);
  792. X    XSelectInput(kwin, ExposeRegion);
  793. X    XMapWindow(kwin);
  794. X    }
  795. X    if ((me->p_team & ORI) && !mustexit) {
  796. X    owin = XCreateWindow(w, 3 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1,
  797. X        XMakeTile(shipCol[4]), backTile);
  798. X    XSelectInput(owin, KeyPressed|ButtonPressed|ButtonReleased|
  799. X        ExposeRegion);
  800. X    XMapWindow(owin);
  801. X    }
  802. X    else {
  803. X    owin = XCreateWindow(w, 3 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1, 
  804. X        XMakeTile(shipCol[4]), stippleTile);
  805. X    XSelectInput(owin, ExposeRegion);
  806. X    XMapWindow(owin);
  807. X    }
  808. X    qwin = XCreateWindow(w, 4 * BOXSIDE, 400, BOXSIDE, BOXSIDE, 1,
  809. X    XMakeTile(textColor), backTile);
  810. X    XSelectInput(qwin, KeyPressed|ButtonPressed|ExposeRegion);
  811. X    XMapWindow(qwin);
  812. X
  813. X    team = -1;
  814. X    startTime = time(0);
  815. X    makeClock(qwin);
  816. X    do {
  817. X        me->p_ghostbuster = 0;
  818. X        while (!XPending()) {
  819. X        int        mask, elapsed;
  820. X        struct timeval    tv;
  821. X
  822. X        me->p_ghostbuster = 0;
  823. X        tv.tv_sec = 1;
  824. X        tv.tv_usec = 0;
  825. X        mask = 1 << dpyno();
  826. X        select(dpyno() + 1, &mask, 0, 0, &tv);
  827. X        elapsed = time(0) - startTime;
  828. X        if (elapsed > AUTOQUIT) {
  829. X            printf("Auto-Quit.\n");
  830. X            team = 4;
  831. X            break;
  832. X        }
  833. X        showTimeLeft(elapsed, AUTOQUIT);
  834. X        redrawFed(fwin);
  835. X        redrawRom(rwin);
  836. X        redrawKli(kwin);
  837. X        redrawOri(owin);
  838. X        }
  839. X        if (team == 4)
  840. X        break;
  841. X
  842. X        XNextEvent(&event);
  843. X        switch ((int) event.type) {
  844. X        case KeyPressed:
  845. X        case ButtonPressed:
  846. X            if (event.window == fwin)
  847. X            team = 0;
  848. X            else if (event.window == rwin)
  849. X            team = 1;
  850. X            else if (event.window == kwin)
  851. X            team = 2;
  852. X            else if (event.window == owin)
  853. X            team = 3;
  854. X            else if (event.window == qwin)
  855. X            team = 4;
  856. X            break;
  857. X        case ExposeRegion:
  858. X        case ExposeWindow:
  859. X            if (event.window == fwin)
  860. X            redrawFed(fwin);
  861. X            else if (event.window == rwin)
  862. X            redrawRom(rwin);
  863. X            else if (event.window == kwin)
  864. X            redrawKli(kwin);
  865. X            else if (event.window == owin)
  866. X            redrawOri(owin);
  867. X            else if (event.window == qwin)
  868. X            redrawQuit(qwin);
  869. X            else if (event.window == tstatw)
  870. X            redrawTstats();
  871. X            else if (event.window == iconWin)
  872. X              drawIcon();
  873. X            else if (event.window == w)
  874. X            showMotd();
  875. X            else if (event.window == helpWin)
  876. X            fillhelp();
  877. X            break;
  878. X        }
  879. X    } while (team < 0);
  880. X    destroyClock();
  881. X
  882. X    if (team == 4)
  883. X    team = -1;
  884. X                
  885. X    XDestroyWindow(fwin);
  886. X    XDestroyWindow(rwin);
  887. X    XDestroyWindow(kwin);
  888. X    XDestroyWindow(owin);
  889. X    XDestroyWindow(qwin);
  890. X    return(team);
  891. X}
  892. X
  893. XnumShips(owner)
  894. X{
  895. X    int        i, num = 0;
  896. X    struct player    *p;
  897. X
  898. X    for (i = 0, p = players; i < MAXPLAYER; i++, p++)
  899. X        if (p->p_status == PALIVE && p->p_team == owner)
  900. X            num++;
  901. X    return (num);
  902. X}
  903. X
  904. Xstatic char    *AUTHOR[] = {
  905. X    "",
  906. X    "---  XTREK Release Version 4.0 ---",
  907. X    "",
  908. X    "By Chris Guthrie (chris@ic.berkeley.edu)",
  909. X    "And Ed James (edjames@ic.berkeley.edu)"
  910. X};
  911. X
  912. XshowMotd()
  913. X{
  914. X    char buf[BUFSIZ];
  915. X    FILE *motd, *fopen();
  916. X    int    i, length, top, center;
  917. X
  918. X    /* Author Gratification */
  919. X    XClear(w);
  920. X    for (i = 0; i < SIZEOF(AUTHOR); i++) {
  921. X    length = strlen(AUTHOR[i]);
  922. X    center = WINSIDE / 2 - (length * dfontinfo->width) / 2;
  923. X    XText(w, center, i * dfontinfo->height, AUTHOR[i], 
  924. X        length, dfont, textColor, backColor);
  925. X    }
  926. X    top = SIZEOF(AUTHOR) + 2;
  927. X
  928. X    /* the following will print a motd */
  929. X    if ((motd = fopen(MOTD, "r")) != NULL) {
  930. X    for (i = top; fgets(buf, sizeof (buf), motd) != NULL; i++) {
  931. X        length = strlen(buf);
  932. X        buf[length-1] = NULL;
  933. X        if (length > 80)
  934. X        length = 80;
  935. X        XText(w, 20, i * dfontinfo->height, buf, length, dfont,
  936. X        textColor, backColor);
  937. X    }
  938. X    (void) fclose(motd);
  939. X    }
  940. X}
  941. X
  942. XgetResources(prog)
  943. X    char    *prog;
  944. X{
  945. X    getColorDefs(prog);
  946. X    getFonts(prog);
  947. X    getTiles(prog);
  948. X    initStats(prog);
  949. X
  950. X    showShields = booleanDefault(prog, "showshields");
  951. X    showStats = booleanDefault(prog, "showstats");
  952. X}
  953. X
  954. Xstatic short    solid[TILESIDE] = {
  955. X    0xffff, 0xffff, 0xffff, 0xffff,
  956. X    0xffff, 0xffff, 0xffff, 0xffff,
  957. X    0xffff, 0xffff, 0xffff, 0xffff,
  958. X    0xffff, 0xffff, 0xffff, 0xffff,
  959. X};
  960. Xstatic short    gray[TILESIDE] = {
  961. X    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  962. X    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  963. X    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  964. X    0xaaaa, 0x5555, 0xaaaa, 0x5555,
  965. X};
  966. Xstatic short    striped[TILESIDE] = {
  967. X    0xff00, 0xff00, 0xff00, 0xff00,
  968. X    0x0ff0, 0x0ff0, 0x0ff0, 0x0ff0,
  969. X    0x00ff, 0x00ff, 0x00ff, 0x00ff,
  970. X    0xf00f, 0xf00f, 0xf00f, 0xf00f,
  971. X};
  972. X
  973. XgetTiles(prog)
  974. X    char    *prog;
  975. X{
  976. X    short    rPatt[TILESIDE], yPatt[TILESIDE], gPatt[TILESIDE];
  977. X    int    rSize = sizeof (rPatt);
  978. X    int    ySize = sizeof (yPatt);
  979. X    int    gSize = sizeof (gPatt);
  980. X
  981. X    backTile = XMakeTile(backColor);
  982. X    foreTile = XMakeTile(borderColor);
  983. X
  984. X    if (DisplayCells() > 2) {
  985. X        rTile = XMakeTile(rColor);
  986. X        yTile = XMakeTile(yColor);
  987. X        gTile = XMakeTile(gColor);
  988. X    } else {
  989. X        if (arrayDefault(prog, "RalertPattern", &rSize, rPatt) < 0) {
  990. X            rSize = TILESIDE;
  991. X            bcopy(striped, rPatt, sizeof (rPatt));
  992. X        }
  993. X        if (arrayDefault(prog, "YalertPattern", &ySize, yPatt) < 0) {
  994. X            ySize = TILESIDE;
  995. X            bcopy(gray, yPatt, sizeof (yPatt));
  996. X        }
  997. X        if (arrayDefault(prog, "GalertPattern", &gSize, gPatt) < 0) {
  998. X            gSize = TILESIDE;
  999. X            bcopy(solid, gPatt, sizeof (gPatt));
  1000. X        }
  1001. X
  1002. X        rTile = XMakePixmap(XStoreBitmap(rSize, rSize, rPatt), 
  1003. X            rColor, backColor);
  1004. X        yTile = XMakePixmap(XStoreBitmap(ySize, ySize, yPatt), 
  1005. X            yColor, backColor);
  1006. X        gTile = XMakePixmap(XStoreBitmap(gSize, gSize, gPatt), 
  1007. X            gColor, backColor);
  1008. X    }
  1009. X    stippleTile = XMakePixmap(XStoreBitmap(stipple_width,
  1010. X        stipple_height, stipple_bits), 
  1011. X        textColor, backColor);
  1012. X}
  1013. X
  1014. XgetFonts(prog)
  1015. X    char    *prog;
  1016. X{
  1017. X    char    *font;
  1018. X
  1019. X    if ((font = XGetDefault(prog, "font")) == NULL)
  1020. X    font = "6x10";
  1021. X    if ((dfontinfo = XOpenFont(font)) == NULL) {
  1022. X    perror(font);
  1023. X    exit(1);
  1024. X    }
  1025. X
  1026. X    if ((font = XGetDefault(prog, "boldfont")) == NULL)
  1027. X    font = "6x10b";
  1028. X    if ((bfontinfo = XOpenFont(font)) == NULL)
  1029. X    bfontinfo = dfontinfo;
  1030. X
  1031. X    if ((font = XGetDefault(prog, "italicFont")) == NULL)
  1032. X    font = "6x10i";
  1033. X    if ((ifontinfo = XOpenFont(font)) == NULL)
  1034. X    ifontinfo = dfontinfo;
  1035. X
  1036. X    if ((font = XGetDefault(prog, "bigFont")) == NULL)
  1037. X    font = "sbdr40sx";
  1038. X    if ((bigFont = XOpenFont(font)) == NULL)
  1039. X    bigFont = dfontinfo;
  1040. X
  1041. X    dfont = dfontinfo->id;
  1042. X    bfont = bfontinfo->id;
  1043. X    ifont = ifontinfo->id;
  1044. X}
  1045. X
  1046. XredrawFed(fwin)
  1047. X    Window fwin;
  1048. X{
  1049. X    char buf[BUFSIZ];
  1050. X
  1051. X    XClear(fwin);
  1052. X    XText(fwin, 5, 5, "Federation", 10, dfont, shipCol[1], backColor);
  1053. X    (void) sprintf(buf, "%d", numShips(FED));
  1054. X    XTextMask(fwin, 5, 50, buf, strlen(buf), bigFont->id, shipCol[1]);
  1055. X}
  1056. X
  1057. XredrawRom(rwin)
  1058. X    Window rwin;
  1059. X{
  1060. X    char buf[BUFSIZ];
  1061. X
  1062. X    XClear(rwin);
  1063. X    XText(rwin, 5, 5, "Romulan", 7, dfont, shipCol[2], backColor);
  1064. X    (void) sprintf(buf, "%d", numShips(ROM));
  1065. X    XTextMask(rwin, 5, 50, buf, strlen(buf), bigFont->id, shipCol[1]);
  1066. X}
  1067. X
  1068. XredrawKli(kwin)
  1069. X    Window kwin;
  1070. X{
  1071. X    char buf[BUFSIZ];
  1072. X
  1073. X    XClear(kwin);
  1074. X    XText(kwin, 5, 5, "Klingon", 7, dfont, shipCol[3], backColor);
  1075. X    (void) sprintf(buf, "%d", numShips(KLI));
  1076. X    XTextMask(kwin, 5, 50, buf, strlen(buf), bigFont->id, shipCol[1]);
  1077. X}
  1078. X
  1079. XredrawOri(owin)
  1080. X    Window owin;
  1081. X{
  1082. X    char buf[BUFSIZ];
  1083. X
  1084. X    XClear(owin);
  1085. X    XText(owin, 5, 5, "Orion", 5, dfont, shipCol[4], backColor);
  1086. X    (void) sprintf(buf, "%d", numShips(ORI));
  1087. X    XTextMask(owin, 5, 50, buf, strlen(buf), bigFont->id, shipCol[1]);
  1088. X}
  1089. X
  1090. XredrawQuit(qwin)
  1091. X    Window qwin;
  1092. X{
  1093. X    XText(qwin, 5, 5, "Quit xtrek", 10, dfont, textColor, backColor);
  1094. X}
  1095. X
  1096. Xchar *help_message[] = {
  1097. X    "0-9  Set speed",
  1098. X    "k    Set course",
  1099. X    "p    Fire phaser",
  1100. X    "t    Launch torp",
  1101. X    "d    detonate other torps",
  1102. X    "D    detonate your torps",
  1103. X    "L    List players",
  1104. X    "P    List planets",
  1105. X    "S    (Un)Map status window",
  1106. X    "M    Turn on/off map window updating",
  1107. X    "+    Put up screens",
  1108. X    "-    Put down screens",
  1109. X    "u    Toggle screens",
  1110. X    "i    Get info on player/planet",
  1111. X    "b    Bomb planet",
  1112. X    "z    Beam up armies",
  1113. X    "x    Beam down armies",
  1114. X    "R    Enter repair mode",
  1115. X    "o    orbit planet",
  1116. X    "Q    Quit",
  1117. X    "?    Review messages",
  1118. X    "c    Toggle cloak mode",
  1119. X    "C    Coup a planet",
  1120. X    "l    Lock on to player/planet",
  1121. X    "@    (Dis)Allow copilots",
  1122. X    "h    (Un)Map this window",
  1123. X    "w    (Un)Map war window",
  1124. X    "*    Send in practice robot",
  1125. X    0,
  1126. X};
  1127. X
  1128. X#define MAXHELP 40
  1129. X
  1130. Xfillhelp()
  1131. X{
  1132. X    register int i = 0, row, column;
  1133. X
  1134. X    for (column = 0; column < 4; column++) {
  1135. X    for (row = 1; row < 9; row++) {
  1136. X        if (help_message[i] == 0)
  1137. X        break;
  1138. X        else {
  1139. X        XText(helpWin, dfontinfo->width * (MAXHELP * column + 1),
  1140. X            dfontinfo->height * row, help_message[i],
  1141. X            strlen(help_message[i]), dfont, textColor, backColor);
  1142. X        i++;
  1143. X        }
  1144. X    }
  1145. X    if (help_message[i] == 0)
  1146. X        break;
  1147. X    }
  1148. X}
  1149. X
  1150. XdrawIcon()
  1151. X{
  1152. X    XBitmapBitsPut(iconWin, 0, 0, icon_width, icon_height, icon_bits, 
  1153. X    WhitePixel, BlackPixel, 0, GXcopy, AllPlanes);
  1154. X}
  1155. X
  1156. Xstatic Window    clock;
  1157. X
  1158. X#define CLOCK_WID    (BOXSIDE * 9 / 10)
  1159. X#define CLOCK_HEI    (BOXSIDE * 2 / 3)
  1160. X#define CLOCK_BDR    0
  1161. X#define CLOCK_X        (BOXSIDE / 2 - CLOCK_WID / 2)
  1162. X#define CLOCK_Y        (BOXSIDE / 2 - CLOCK_HEI / 2)
  1163. X
  1164. XmakeClock(w)
  1165. X    Window    w;
  1166. X{
  1167. X    clock = XCreateWindow(w, CLOCK_X, CLOCK_Y, CLOCK_WID, CLOCK_HEI,
  1168. X        CLOCK_BDR, foreTile, backTile);
  1169. X    XMapWindow(clock);
  1170. X}
  1171. X
  1172. XdestroyClock()
  1173. X{
  1174. X    XDestroyWindow(clock);
  1175. X}
  1176. X
  1177. X#define PI        3.141592654
  1178. X#include "clock.bitmap"
  1179. X
  1180. XshowTimeLeft(time, max)
  1181. X{
  1182. X    char    buf[BUFSIZ], *cp;
  1183. X    int    cx, cy, ex, ey, tx, ty;
  1184. X
  1185. X    XClear(clock);
  1186. X
  1187. X    cx = CLOCK_WID / 2;
  1188. X    cy = (CLOCK_HEI - dfontinfo->height) / 2;
  1189. X    ex = cx - clock_width / 2;
  1190. X    ey = cy - clock_height / 2;
  1191. X    XBitmapBitsPut(clock, ex, ey, clock_width, clock_height, clock_bits, 
  1192. X        textColor, backColor, 0, GXcopy, AllPlanes);
  1193. X
  1194. X    ex = cx - clock_width * sin(2 * PI * time / max) / 2;
  1195. X    ey = cy - clock_height * cos(2 * PI * time / max) / 2;
  1196. X    XLine(clock, cx, cy, ex, ey, 1, 1, textColor, GXcopy, AllPlanes);
  1197. X
  1198. X    sprintf(buf, "%d", max - time);
  1199. X    tx = cx - dfontinfo->width * strlen(buf) / 2;
  1200. X    ty = cy - dfontinfo->height / 2;
  1201. X    XText(clock, tx, ty, buf, strlen(buf), dfont, textColor, backColor);
  1202. X
  1203. X    cp = "Auto Quit";
  1204. X    tx = cx - dfontinfo->width * strlen(cp) / 2;
  1205. X    ty = CLOCK_HEI - dfontinfo->height;
  1206. X    XText(clock, tx, ty, cp, strlen(cp), dfont, textColor, backColor);
  1207. X}
  1208. END_OF_newwin.c
  1209. if test 16570 -ne `wc -c <newwin.c`; then
  1210.     echo shar: \"newwin.c\" unpacked with wrong size!
  1211. fi
  1212. # end of overwriting check
  1213. fi
  1214. if test -f redraw.c -a "${1}" != "-c" ; then 
  1215.   echo shar: Will not over-write existing file \"redraw.c\"
  1216. else
  1217. echo shar: Extracting \"redraw.c\" \(21165 characters\)
  1218. sed "s/^X//" >redraw.c <<'END_OF_redraw.c'
  1219. X
  1220. X/*
  1221. X
  1222. X    Copyright (c) 1986     Chris Guthrie
  1223. X
  1224. XPermission to use, copy, modify, and distribute this
  1225. Xsoftware and its documentation for any purpose and without
  1226. Xfee is hereby granted, provided that the above copyright
  1227. Xnotice appear in all copies and that both that copyright
  1228. Xnotice and this permission notice appear in supporting
  1229. Xdocumentation.  No representations are made about the
  1230. Xsuitability of this software for any purpose.  It is
  1231. Xprovided "as is" without express or implied warranty.
  1232. X
  1233. X*/
  1234. X
  1235. X#include <X/Xlib.h>
  1236. X#include <stdio.h>
  1237. X#include <signal.h>
  1238. X#include <math.h>
  1239. X#include "defs.h"
  1240. X#include "struct.h"
  1241. X#include "data.h"
  1242. X#include "bitmaps.h"
  1243. X
  1244. X#define WINSIDE 500
  1245. X
  1246. Xstatic char *shipnos = "0123456789abcdef";
  1247. X
  1248. Xstatic int clearzone[4][(MAXTORP + 1) * MAXPLAYER + MAXPLANETS];
  1249. Xstatic int clearcount;
  1250. Xstatic int clearline[4][MAXPLAYER];
  1251. Xstatic int clearlcount;
  1252. Xstatic int mclearzone[4][MAXPLAYER + MAXPLANETS];    /* For map window */
  1253. Xstatic int mclearcount;
  1254. X
  1255. Xstatic short nplayers;
  1256. X
  1257. Xintrupt()
  1258. X{
  1259. X    if (((me->p_status == PDEAD) || (me->p_status == POUTFIT))
  1260. X    && (me->p_ntorp <= 0)) {
  1261. X    if (copilot)
  1262. X        exit(0);
  1263. X    else if (!watch)
  1264. X        death();
  1265. X    }
  1266. X
  1267. X    if (! (copilot || watch))
  1268. X    udcounter++;
  1269. X    auto_features();
  1270. X    redraw();
  1271. X}
  1272. X
  1273. Xredraw()
  1274. X{
  1275. X
  1276. X    /* erase warning line if necessary */
  1277. X    if ((warntimer <= udcounter) && (warncount > 0)) {
  1278. X    XPixSet(warnw, 5, 5, dfontinfo->width * warncount, dfontinfo->height,
  1279. X        backColor);
  1280. X    warncount = 0;
  1281. X    }
  1282. X
  1283. X    while (clearcount) {
  1284. X    clearcount--;
  1285. X    XPixSet(w, clearzone[0][clearcount], clearzone[1][clearcount],
  1286. X        clearzone[2][clearcount], clearzone[3][clearcount],
  1287. X        backColor);
  1288. X    }
  1289. X    while (clearlcount) {
  1290. X    clearlcount--;
  1291. X    XLine(w, clearline[0][clearlcount], clearline[1][clearlcount],
  1292. X        clearline[2][clearlcount], clearline[3][clearlcount],
  1293. X        1, 1, backColor, GXcopy, AllPlanes);
  1294. X    }
  1295. X
  1296. X    if ((mapmode) && (udcounter % ((nplayers == 0) ? 1 : nplayers) == 0))
  1297. X    map();
  1298. X
  1299. X    /* Display a new message every MESSTIME/10 seconds */
  1300. X    if (udcounter % MESSTIME == 0)
  1301. X    dmessage();
  1302. X
  1303. X    local();    /* redraw local window */
  1304. X
  1305. X    stline();
  1306. X
  1307. X    if (showStats)
  1308. X    updateStats(statwin);
  1309. X
  1310. X}
  1311. X
  1312. Xlocal()
  1313. X{
  1314. X    register int h, i;
  1315. X    register struct player *j;
  1316. X    register struct torp *k;
  1317. X    register struct planet *l;
  1318. X    register struct phaser *php;
  1319. X
  1320. X    int dx, dy;
  1321. X    int view;
  1322. X
  1323. X    /* Draw Planets */
  1324. X    view = SCALE * WINSIDE / 2;
  1325. X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
  1326. X    dx = l->pl_x - me->p_x;
  1327. X    dy = l->pl_y - me->p_y;
  1328. X    if (dx > view || dx < -view || dy > view || dy < -view)
  1329. X        continue;
  1330. X    dx = dx / SCALE + WINSIDE / 2;
  1331. X    dy = dy / SCALE + WINSIDE / 2;
  1332. X    XPixFill(w, dx - (planet_width/2), dy - (planet_height/2),
  1333. X        planet_width, planet_height,
  1334. X        planetColor(l), bplanet, GXcopy, AllPlanes);
  1335. X    if (namemode) {
  1336. X        XText(w, dx - (planet_width/2), dy + (planet_height/2),
  1337. X        l->pl_name, l->pl_namelen, planetFont(l),
  1338. X        planetColor(l), backColor);
  1339. X        clearzone[0][clearcount] = dx - (planet_width/2);
  1340. X        clearzone[1][clearcount] = dy + (planet_height/2);
  1341. X        clearzone[2][clearcount] = dfontinfo->width * l->pl_namelen;
  1342. X        clearzone[3][clearcount] = dfontinfo->height;
  1343. X        clearcount++;
  1344. X    }
  1345. X    clearzone[0][clearcount] = dx - (planet_width/2);
  1346. X    clearzone[1][clearcount] = dy - (planet_height/2);
  1347. X    clearzone[2][clearcount] = planet_width;
  1348. X    clearzone[3][clearcount] = planet_height;
  1349. X    clearcount++;
  1350. X    }
  1351. X
  1352. X    /* Draw ships */
  1353. X    nplayers = 0;
  1354. X    view = SCALE * WINSIDE / 2;
  1355. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  1356. X    int tx, ty;
  1357. X    if ((j->p_status != PALIVE) && (j->p_status != PEXPLODE))
  1358. X        continue;
  1359. X    if (j->p_flags & PFCLOAK)
  1360. X        continue;
  1361. X    nplayers++;
  1362. X    dx = j->p_x - me->p_x;
  1363. X    dy = j->p_y - me->p_y;
  1364. X    if (dx > view || dx < -view || dy > view || dy < -view)
  1365. X        continue;
  1366. X    dx = dx / SCALE + WINSIDE / 2;
  1367. X    dy = dy / SCALE + WINSIDE / 2;
  1368. X    if (j->p_status == PALIVE) {
  1369. X        switch (j->p_team) {
  1370. X        case FED:
  1371. X            XPixFill(w, dx - (ship_width/2), dy - (ship_height/2),
  1372. X            ship_width, ship_height, playerColor(j),
  1373. X            fedview[rosette(j->p_dir)], GXcopy, AllPlanes);
  1374. X            break;
  1375. X        case ROM:
  1376. X            XPixFill(w, dx - (ship_width/2), dy - (ship_height/2),
  1377. X            ship_width, ship_height, playerColor(j),
  1378. X            romview[rosette(j->p_dir)], GXcopy, AllPlanes);
  1379. X            break;
  1380. X        case KLI:
  1381. X            XPixFill(w, dx - (ship_width/2), dy - (ship_height/2),
  1382. X            ship_width, ship_height, playerColor(j),
  1383. X            kliview[rosette(j->p_dir)], GXcopy, AllPlanes);
  1384. X            break;
  1385. X        case ORI:
  1386. X            XPixFill(w, dx - (ship_width/2), dy - (ship_height/2),
  1387. X            ship_width, ship_height, playerColor(j),
  1388. X            oriview[rosette(j->p_dir)], GXcopy, AllPlanes);
  1389. X            break;
  1390. X        }
  1391. X        XText(w, dx + (ship_width/2), dy - (ship_height/2),
  1392. X        shipnos + j->p_no, 1, shipFont(j), playerColor(j), backColor);
  1393. X           
  1394. X        if (showShields && j->p_flags & PFSHIELD)
  1395. X        XPixFill(w, dx - (shield_width/2), dy - (shield_height/2),
  1396. X            shield_width, shield_height, playerColor(j),
  1397. X            shield, GXcopy, AllPlanes);
  1398. X
  1399. X        clearzone[0][clearcount] = dx + (ship_width/2);
  1400. X        clearzone[1][clearcount] = dy - (ship_height/2);
  1401. X        clearzone[2][clearcount] = dfontinfo->width;
  1402. X        clearzone[3][clearcount] = dfontinfo->height;
  1403. X        clearcount++;
  1404. X        clearzone[0][clearcount] = dx - (shield_width/2);
  1405. X        clearzone[1][clearcount] = dy - (shield_height/2);
  1406. X        clearzone[2][clearcount] = shield_width;
  1407. X        clearzone[3][clearcount] = shield_height;
  1408. X        clearcount++;
  1409. X    }
  1410. X    else if (j->p_status == PEXPLODE) {
  1411. X        XPixFill(w, dx - (ex_width/2), dy - (ex_height/2),
  1412. X        ex_width, ex_height, playerColor(j),
  1413. X        expview[(10 - j->p_explode)/2], GXcopy, AllPlanes);
  1414. X        clearzone[0][clearcount] = dx - (ex_width/2);
  1415. X        clearzone[1][clearcount] = dy - (ex_height/2);
  1416. X        clearzone[2][clearcount] = ex_width;
  1417. X        clearzone[3][clearcount] = ex_height;
  1418. X        clearcount++;
  1419. X    }
  1420. X    /* Now draw his phaser (if it exists) */
  1421. X    php = &phasers[j->p_no];
  1422. X    if (php->ph_status != PHFREE) {
  1423. X        if (php->ph_status == PHMISS) {
  1424. X        /* Here I will have to compute end coordinate */
  1425. X        tx = j->p_x + PHASEDIST * Cos[php->ph_dir];
  1426. X        ty = j->p_y + PHASEDIST * Sin[php->ph_dir];
  1427. X        tx = (tx - me->p_x) / SCALE + WINSIDE / 2;
  1428. X        ty = (ty - me->p_y) / SCALE + WINSIDE / 2;
  1429. X        XLine(w, dx, dy, tx, ty, 1, 1, phaserColor(php),
  1430. X            GXcopy, AllPlanes);
  1431. X        }
  1432. X        else { /* Start point is dx, dy */
  1433. X        tx = (players[php->ph_target].p_x - me->p_x) /
  1434. X            SCALE + WINSIDE / 2;
  1435. X        ty = (players[php->ph_target].p_y - me->p_y) /
  1436. X            SCALE + WINSIDE / 2;
  1437. X        XLine(w, dx, dy, tx, ty, 1, 1, phaserColor(php),
  1438. X            GXcopy, AllPlanes);
  1439. X        }
  1440. X        clearline[0][clearlcount] = dx;
  1441. X        clearline[1][clearlcount] = dy;
  1442. X        clearline[2][clearlcount] = tx;
  1443. X        clearline[3][clearlcount] = ty;
  1444. X        clearlcount++;
  1445. X    }
  1446. X    }
  1447. X    /* Draw torps */
  1448. X    view = SCALE * WINSIDE / 2;
  1449. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  1450. X    if (!j->p_ntorp)
  1451. X        continue;
  1452. X    for (h = 0, k = &torps[MAXTORP * i + h]; h < MAXTORP; h++, k++) {
  1453. X        if (!k->t_status)
  1454. X        continue;
  1455. X        dx = k->t_x - me->p_x;
  1456. X        dy = k->t_y - me->p_y;
  1457. X        if (dx > view || dx < -view || dy > view || dy < -view)
  1458. X        continue;
  1459. X        dx = dx / SCALE + WINSIDE / 2;
  1460. X        dy = dy / SCALE + WINSIDE / 2;
  1461. X        if (k->t_status == TEXPLODE) {
  1462. X        XPixFill(w, dx - (cloud_width/2), dy - (cloud_height/2),
  1463. X            cloud_width, cloud_height, torpColor(k),
  1464. X            cloud, GXcopy, AllPlanes);
  1465. X        clearzone[0][clearcount] = dx - (cloud_width/2);
  1466. X        clearzone[1][clearcount] = dy - (cloud_height/2);
  1467. X        clearzone[2][clearcount] = cloud_width;
  1468. X        clearzone[3][clearcount] = cloud_height;
  1469. X        clearcount++;
  1470. X        }
  1471. X        else if (k->t_owner != me->p_no && ((k->t_war & me->p_team) ||
  1472. X              (k->t_team & (me->p_hostile | me->p_swar))))
  1473. X        {
  1474. X        XPixFill(w, dx - (etorp_width/2), dy - (etorp_height/2),
  1475. X            etorp_width, etorp_height, torpColor(k),
  1476. X            etorp, GXcopy, AllPlanes);
  1477. X        clearzone[0][clearcount] = dx - (etorp_width/2);
  1478. X        clearzone[1][clearcount] = dy - (etorp_height/2);
  1479. X        clearzone[2][clearcount] = etorp_width;
  1480. X        clearzone[3][clearcount] = etorp_height;
  1481. X        clearcount++;
  1482. X        }
  1483. X        else {
  1484. X        XPixFill(w, dx - (mtorp_width/2), dy - (mtorp_height/2),
  1485. X            mtorp_width, mtorp_height, torpColor(k),
  1486. X            mtorp, GXcopy, AllPlanes);
  1487. X        clearzone[0][clearcount] = dx - (mtorp_width/2);
  1488. X        clearzone[1][clearcount] = dy - (mtorp_height/2);
  1489. X        clearzone[2][clearcount] = mtorp_width;
  1490. X        clearzone[3][clearcount] = mtorp_height;
  1491. X        clearcount++;
  1492. X        }
  1493. X    }
  1494. X    }
  1495. X    /* Draw Edges */
  1496. X    if (me->p_x < (WINSIDE / 2) * SCALE) {
  1497. X    int    sy, ey;
  1498. X
  1499. X    dx = (WINSIDE / 2) - (me->p_x) / SCALE;
  1500. X    sy = (WINSIDE / 2) + (0 - me->p_y) / SCALE;
  1501. X    ey = (WINSIDE / 2) + (GWIDTH - me->p_y) / SCALE;
  1502. X    if (sy < 0) sy = 0;
  1503. X    if (ey > WINSIDE - 1) ey = WINSIDE - 1;
  1504. X    XLine(w, dx, sy, dx, ey, 1, 1, warningColor, GXcopy, AllPlanes);
  1505. X    clearline[0][clearlcount] = dx;
  1506. X    clearline[1][clearlcount] = sy;
  1507. X    clearline[2][clearlcount] = dx;
  1508. X    clearline[3][clearlcount] = ey;
  1509. X    clearlcount++;
  1510. X    }
  1511. X    if ((GWIDTH - me->p_x) < (WINSIDE / 2) * SCALE) {
  1512. X    int    sy, ey;
  1513. X
  1514. X    dx = (WINSIDE / 2) + (GWIDTH - me->p_x) / SCALE;
  1515. X    sy = (WINSIDE / 2) + (0 - me->p_y) / SCALE;
  1516. X    ey = (WINSIDE / 2) + (GWIDTH - me->p_y) / SCALE;
  1517. X    if (sy < 0) sy = 0;
  1518. X    if (ey > WINSIDE - 1) ey = WINSIDE - 1;
  1519. X    XLine(w, dx, sy, dx, ey, 1, 1, warningColor, GXcopy, AllPlanes);
  1520. X    clearline[0][clearlcount] = dx;
  1521. X    clearline[1][clearlcount] = sy;
  1522. X    clearline[2][clearlcount] = dx;
  1523. X    clearline[3][clearlcount] = ey;
  1524. X    clearlcount++;
  1525. X    }
  1526. X    if (me->p_y < (WINSIDE / 2) * SCALE) {
  1527. X    int    sx, ex;
  1528. X
  1529. X    dy = (WINSIDE / 2) - (me->p_y) / SCALE;
  1530. X    sx = (WINSIDE / 2) + (0 - me->p_x) / SCALE;
  1531. X    ex = (WINSIDE / 2) + (GWIDTH - me->p_x) / SCALE;
  1532. X    if (sx < 0) sx = 0;
  1533. X    if (ex > WINSIDE - 1) ex = WINSIDE - 1;
  1534. X    XLine(w, sx, dy, ex, dy, 1, 1, warningColor, GXcopy, AllPlanes);
  1535. X    clearline[0][clearlcount] = sx;
  1536. X    clearline[1][clearlcount] = dy;
  1537. X    clearline[2][clearlcount] = ex;
  1538. X    clearline[3][clearlcount] = dy;
  1539. X    clearlcount++;
  1540. X    }
  1541. X    if ((GWIDTH - me->p_y) < (WINSIDE / 2) * SCALE) {
  1542. X    int    sx, ex;
  1543. X
  1544. X    dy = (WINSIDE / 2) + (GWIDTH - me->p_y) / SCALE;
  1545. X    sx = (WINSIDE / 2) + (0 - me->p_x) / SCALE;
  1546. X    ex = (WINSIDE / 2) + (GWIDTH - me->p_x) / SCALE;
  1547. X    if (sx < 0) sx = 0;
  1548. X    if (ex > WINSIDE - 1) ex = WINSIDE - 1;
  1549. X    XLine(w, sx, dy, ex, dy, 1, 1, warningColor, GXcopy, AllPlanes);
  1550. X    clearline[0][clearlcount] = sx;
  1551. X    clearline[1][clearlcount] = dy;
  1552. X    clearline[2][clearlcount] = ex;
  1553. X    clearline[3][clearlcount] = dy;
  1554. X    clearlcount++;
  1555. X    }
  1556. X
  1557. X    /* Change border color to signify alert status */
  1558. X
  1559. X    if (oldalert != (me->p_flags & (PFGREEN|PFYELLOW|PFRED))) {
  1560. X        oldalert = (me->p_flags & (PFGREEN|PFYELLOW|PFRED));
  1561. X    switch (oldalert) {
  1562. X        case PFGREEN:
  1563. X        XChangeBorder(baseWin, gTile);
  1564. X        XChangeBorder(iconWin, gTile);
  1565. X        break;
  1566. X        case PFYELLOW:
  1567. X        XChangeBorder(baseWin, yTile);
  1568. X        XChangeBorder(iconWin, yTile);
  1569. X        break;
  1570. X        case PFRED:
  1571. X        XChangeBorder(baseWin, rTile);
  1572. X        XChangeBorder(iconWin, rTile);
  1573. X        break;
  1574. X    }
  1575. X    }
  1576. X}
  1577. X
  1578. Xmap()
  1579. X{
  1580. X    char buf[80];
  1581. X    register int i;
  1582. X    register struct player *j;
  1583. X    register struct planet *l;
  1584. X    int dx, dy;
  1585. X
  1586. X    while (mclearcount) {
  1587. X    mclearcount--;
  1588. X    XPixSet(mapw, mclearzone[0][mclearcount], mclearzone[1][mclearcount],
  1589. X        mclearzone[2][mclearcount], mclearzone[3][mclearcount],
  1590. X        backColor);
  1591. X    }
  1592. X
  1593. X    /* Draw Planets */
  1594. X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
  1595. X    if (!(l->pl_flags & PLREDRAW) && (!redrawall))
  1596. X        continue;
  1597. X    dx = l->pl_x * WINSIDE / GWIDTH;
  1598. X    dy = l->pl_y * WINSIDE / GWIDTH;
  1599. X    XPixFill(mapw, dx - (mplanet_width/2), dy - (mplanet_height/2),
  1600. X        mplanet_width, mplanet_height,
  1601. X        planetColor(l), mbplanet, GXcopy, AllPlanes);
  1602. X    XText(mapw, dx - (mplanet_width/2), dy + (mplanet_height/2),
  1603. X        l->pl_name, 3, planetFont(l), planetColor(l), backColor);
  1604. X
  1605. X/*
  1606. X    clearzone[0][clearcount] = dx - (mplanet_width/2);
  1607. X    clearzone[1][clearcount] = dy + (mplanet_height/2);
  1608. X    clearzone[2][clearcount] = dfontinfo->width * 3;
  1609. X    clearzone[3][clearcount] = dfontinfo->height;
  1610. X    clearcount++;
  1611. X    clearzone[0][clearcount] = dx - (mplanet_width/2);
  1612. X    clearzone[1][clearcount] = dy - (mplanet_height/2);
  1613. X    clearzone[2][clearcount] = mplanet_width;
  1614. X    clearzone[3][clearcount] = mplanet_height;
  1615. X    clearcount++;
  1616. X*/
  1617. X    }
  1618. X    redrawall = 0;
  1619. X
  1620. X    /* Draw ships */
  1621. X    nplayers = 0;
  1622. X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
  1623. X    if (j->p_status != PALIVE)
  1624. X        continue;
  1625. X    nplayers++;
  1626. X    dx = j->p_x * WINSIDE / GWIDTH;
  1627. X    dy = j->p_y * WINSIDE / GWIDTH;
  1628. X    if (j->p_flags & PFCLOAK) {
  1629. X        XText(mapw, dx - dfontinfo->width, dy - dfontinfo->height/2,
  1630. X        "??", 2, dfont, unColor, backColor);
  1631. X    }
  1632. X    else {
  1633. X        XText(mapw, dx - dfontinfo->width, dy - dfontinfo->height/2,
  1634. X        j->p_mapchars, 2, shipFont(j), playerColor(j), backColor);
  1635. X    }
  1636. X
  1637. X    mclearzone[0][mclearcount] = dx - dfontinfo->width;
  1638. X    mclearzone[1][mclearcount] = dy - dfontinfo->height/2;
  1639. X    mclearzone[2][mclearcount] = dfontinfo->width * 2;
  1640. X    mclearzone[3][mclearcount] = dfontinfo->height;
  1641. X    mclearcount++;
  1642. X    }
  1643. X}
  1644. X
  1645. Xstline()
  1646. X{
  1647. X    char buf[80];
  1648. X
  1649. X    /* Instead of one sprintf, we do all this by hand for optimization */
  1650. X
  1651. X    buf[0] = (me->p_flags & PFSHIELD ? 'S': ' ');
  1652. X    if (me->p_flags & PFGREEN)
  1653. X    buf[1] = 'G';
  1654. X    else if (me->p_flags & PFYELLOW)
  1655. X    buf[1] = 'Y';
  1656. X    else if (me->p_flags & PFRED)
  1657. X    buf[1] = 'R';
  1658. X    buf[2] = (me->p_flags & (PFPLLOCK | PFPLOCK) ? 'L': ' ');
  1659. X    buf[3] = (me->p_flags & PFREPAIR ? 'R': ' ');
  1660. X    buf[4] = (me->p_flags & PFBOMB ? 'B': ' ');
  1661. X    buf[5] = (me->p_flags & PFORBIT ? 'O': ' ');
  1662. X    buf[6] = (me->p_flags & PFCLOAK ? 'C': ' ');
  1663. X    buf[7] = (me->p_flags & PFWEP ? 'W': ' ');
  1664. X    buf[8] = (me->p_flags & PFENG ? 'E': ' ');
  1665. X    buf[9] = (me->p_flags & PFBEAMUP ? 'u': ' ');
  1666. X    buf[10] = (me->p_flags & PFBEAMDOWN ? 'd': ' ');
  1667. X    buf[11] = (me->p_flags & PFCOPILOT ? 'P' : ' ');
  1668. X    buf[12] = ' ';
  1669. X    buf[13] = ' ';
  1670. X    buf[14] = ' ';
  1671. X    buf[15] = '0' + me->p_speed;    /* speed */
  1672. X    buf[16] = ' ';
  1673. X    buf[17] = ' ';
  1674. X    buf[18] = '0' + (me->p_damage / 100);
  1675. X    if (buf[18] == '0')
  1676. X    buf[18] = ' ';
  1677. X    buf[19] = '0' + ((me->p_damage % 100) / 10);
  1678. X    if ((buf[19] == '0') && (me->p_damage < 100))
  1679. X    buf[19] = ' ';
  1680. X    buf[20] = '0' + (me->p_damage % 10);
  1681. X    buf[21] = ' ';
  1682. X    buf[22] = '0' + (me->p_shield / 100);
  1683. X    if (buf[22] == '0')
  1684. X    buf[22] = ' ';
  1685. X    buf[23] = '0' + ((me->p_shield % 100) / 10);
  1686. X    if ((buf[23] == '0') && (me->p_shield < 100))
  1687. X    buf[23] = ' ';
  1688. X    buf[24] = '0' + (me->p_shield % 10);
  1689. X    buf[25] = ' ';
  1690. X    buf[26] = ' ';
  1691. X    buf[27] = '0' + ((me->p_ntorp % 100) / 10);
  1692. X    if (buf[27] == '0')
  1693. X    buf[27] = ' ';
  1694. X    buf[28] = '0' + (me->p_ntorp % 10);
  1695. X    buf[29] = ' ';
  1696. X    buf[30] = ' ';
  1697. X    buf[31] = ' ';
  1698. X    buf[32] = ' ';
  1699. X    buf[33] = '0' + ((int) (me->p_kills / 10));
  1700. X    if (buf[33] == '0')
  1701. X    buf[33] = ' ';
  1702. X    buf[34] = '0' + (((int) me->p_kills) % 10);
  1703. X    buf[35] = '.';
  1704. X    buf[36] = '0' + (((int) (me->p_kills * 10)) % 10);
  1705. X    buf[37] = '0' + (((int) (me->p_kills * 100)) % 10);
  1706. X    buf[38] = ' ';
  1707. X    buf[39] = ' ';
  1708. X    buf[40] = '0' + ((me->p_armies % 100) / 10);
  1709. X    if (buf[40] == '0')
  1710. X    buf[40] = ' ';
  1711. X    buf[41] = '0' + (me->p_armies % 10);
  1712. X    buf[42] = ' ';
  1713. X    buf[43] = ' ';
  1714. X    buf[44] = ' ';
  1715. X    buf[45] = ' ';
  1716. X
  1717. X    buf[46] = '0' + (me->p_fuel / 10000);
  1718. X    if (buf[46] == '0')
  1719. X    buf[46] = ' ';
  1720. X    buf[47] = '0' + ((me->p_fuel % 10000) / 1000);
  1721. X    if ((buf[47] == '0') && (me->p_fuel < 10000))
  1722. X    buf[47] = ' ';
  1723. X    buf[48] = '0' + ((me->p_fuel % 1000) / 100);
  1724. X    if ((buf[48] == '0') && (me->p_fuel < 1000))
  1725. X    buf[48] = ' ';
  1726. X    buf[49] = '0' + ((me->p_fuel % 100) / 10);
  1727. X    if ((buf[49] == '0') && (me->p_fuel < 100))
  1728. X    buf[49] = ' ';
  1729. X    buf[50] = '0' + (me->p_fuel % 10);
  1730. X    buf[51] = ' ';
  1731. X    buf[52] = ' ';
  1732. X    buf[53] = ' ';
  1733. X
  1734. X    buf[54] = '0' + ((me->p_wtemp / 10) / 100);
  1735. X    if (buf[54] == '0')
  1736. X    buf[54] = ' ';
  1737. X    buf[55] = '0' + (((me->p_wtemp / 10) % 100) / 10);
  1738. X    if ((buf[55] == '0') && (me->p_wtemp < 1000))
  1739. X    buf[55] = ' ';
  1740. X    buf[56] = '0' + ((me->p_wtemp / 10) % 10);
  1741. X
  1742. X    buf[57] = ' ';
  1743. X    buf[58] = ' ';
  1744. X    buf[59] = ' ';
  1745. X
  1746. X    buf[60] = '0' + ((me->p_etemp / 10) / 100);
  1747. X    if (buf[60] == '0')
  1748. X    buf[60] = ' ';
  1749. X    buf[61] = '0' + (((me->p_etemp / 10) % 100) / 10);
  1750. X    if ((buf[61] == '0') && (me->p_etemp < 1000))
  1751. X    buf[61] = ' ';
  1752. X    buf[62] = '0' + ((me->p_etemp / 10) % 10);
  1753. X
  1754. X    /* Draw status line */
  1755. X    XText(tstatw, 50, 20, buf, 63, dfont, textColor, backColor);
  1756. X
  1757. X#ifdef notdef
  1758. X
  1759. X    /* This code is being left around because it is much more elegant
  1760. X    ** than that above.  However, it lacks a tremendous amount in efficiency.
  1761. X    */
  1762. X    char alertchar = '?';
  1763. X
  1764. X    if (me->p_flags & PFGREEN)
  1765. X    alertchar = 'G';
  1766. X    else if (me->p_flags & PFYELLOW)
  1767. X    alertchar = 'Y';
  1768. X    else if (me->p_flags & PFRED)
  1769. X    alertchar = 'R';
  1770. X    /* Draw status line */
  1771. X    sprintf(buf,
  1772. X"%c%c%c%c%c%c%c%c%c%c%c%c   %1d  %3d %3d  %2d    %5.2f  %2d    %5d   %3d   %3d",
  1773. X    (me->p_flags & PFSHIELD ? 'S': ' '),
  1774. X    alertchar,
  1775. X    (me->p_flags & (PFPLLOCK | PFPLOCK) ? 'L': ' '),
  1776. X    (me->p_flags & PFREPAIR ? 'R': ' '),
  1777. X    (me->p_flags & PFBOMB ? 'B': ' '),
  1778. X    (me->p_flags & PFORBIT ? 'O': ' '),
  1779. X    (me->p_flags & PFCLOAK ? 'C': ' '),
  1780. X    (me->p_flags & PFWEP ? 'W': ' '),
  1781. X    (me->p_flags & PFENG ? 'E': ' '),
  1782. X    (me->p_flags & PFBEAMUP ? 'u': ' '),
  1783. X    (me->p_flags & PFBEAMDOWN ? 'd': ' '),
  1784. X    (me->p_flags & PFCOPILOT ? 'P' : ' '),
  1785. X    me->p_speed,
  1786. X    me->p_damage,
  1787. X    me->p_shield,
  1788. X    me->p_ntorp,
  1789. X    me->p_kills,
  1790. X    me->p_armies,
  1791. X    me->p_fuel,
  1792. X    me->p_wtemp/10,
  1793. X    me->p_etemp/10);
  1794. X    XText(tstatw, 50, 20, buf, strlen(buf), dfont, textColor, backColor);
  1795. X    XFlush();
  1796. X
  1797. X#endif notdef
  1798. X}
  1799. X
  1800. X/* These are routines that need to be done on interrupts but
  1801. X   don't belong in the redraw routine and particularly don't
  1802. X   belong in the daemon. */
  1803. X
  1804. Xauto_features()
  1805. X{
  1806. X    char buf[80];
  1807. X    struct player *pl;
  1808. X    struct planet *pln;
  1809. X    unsigned char course;
  1810. X
  1811. X    if (copilot && (!(me->p_flags & PFCOPILOT))) {
  1812. X    printf("Owning player has kicked you out\n");
  1813. X    exit(0);
  1814. X    }
  1815. X    if ((!copilot) && (!watch)  && (me->p_flags & PFSELFDEST)) {
  1816. X    if ((me->p_updates >= selfdest) ||
  1817. X        ((me->p_flags & PFGREEN) && (me->p_damage == 0)
  1818. X        && (me->p_shield == 100))) {
  1819. X        me->p_flags &= ~PFSELFDEST;
  1820. X        me->p_explode = 10;
  1821. X        me->p_whydead = KQUIT;
  1822. X        me->p_status = PEXPLODE;
  1823. X    }
  1824. X    else {
  1825. X        sprintf(buf, "Self Destruct in %d seconds",
  1826. X        (selfdest - me->p_updates) / 10);
  1827. X        warning(buf);
  1828. X    }
  1829. X    }
  1830. X    /* give certain information about bombing or beaming */
  1831. X    if (me->p_flags & PFBOMB) {
  1832. X    if (planets[me->p_planet].pl_armies < 5) {
  1833. X        sprintf(buf, "Cannot bomb %s while armies are less than 5",
  1834. X        planets[me->p_planet].pl_name);
  1835. X        warning(buf);
  1836. X        if (! (copilot || watch))
  1837. X        me->p_flags &= ~PFBOMB;
  1838. X    }
  1839. X    else {
  1840. X        sprintf(buf, "Bombing %s.  %d armies left",
  1841. X        planets[me->p_planet].pl_name,
  1842. X        planets[me->p_planet].pl_armies);
  1843. X        warning(buf);
  1844. X    }
  1845. X    }
  1846. X
  1847. X    if (me->p_flags & PFBEAMUP) {
  1848. X    if (planets[me->p_planet].pl_armies < 5) {
  1849. X        sprintf(buf, "%s: Too few armies to beam up",
  1850. X        planets[me->p_planet].pl_name);
  1851. X        warning(buf);
  1852. X        if (! (copilot || watch))
  1853. X        me->p_flags &= ~PFBEAMUP;
  1854. X    }
  1855. X    else if ((me->p_armies == (int) (me->p_kills * 2)) ||
  1856. X        (me->p_armies == myship->s_maxarmies)) {
  1857. X        sprintf(buf, "No more room on board for armies");
  1858. X        warning(buf);
  1859. X        if (! (copilot || watch))
  1860. X        me->p_flags &= ~PFBEAMUP;
  1861. X    }
  1862. X    else {
  1863. X        sprintf(buf, "Beaming up.  (%d/%d)", me->p_armies,
  1864. X        ((me->p_kills * 2) > myship->s_maxarmies) ?
  1865. X            myship->s_maxarmies : (int) (me->p_kills * 2));
  1866. X        warning(buf);
  1867. X    }
  1868. X    }
  1869. X    if (me->p_flags & PFBEAMDOWN) {
  1870. X    if (me->p_armies == 0) {
  1871. X        sprintf(buf, "No more armies to beam down to %s.",
  1872. X        planets[me->p_planet].pl_name);
  1873. X        warning(buf);
  1874. X        if (! (copilot || watch))
  1875. X        me->p_flags &= ~PFBEAMDOWN;
  1876. X    }
  1877. X    else {
  1878. X        sprintf(buf, "Beaming down.  (%d/%d) %s has %d armies left",
  1879. X        me->p_armies,
  1880. X        ((me->p_kills * 2) > myship->s_maxarmies) ?
  1881. X            myship->s_maxarmies : (int) (me->p_kills * 2),
  1882. X        planets[me->p_planet].pl_name,
  1883. X        planets[me->p_planet].pl_armies);
  1884. X        warning(buf);
  1885. X    }
  1886. X    }
  1887. X    if (me->p_flags & PFREPAIR) {
  1888. X    if ((me->p_damage == 0) && (me->p_shield == 100))
  1889. X        if (! (copilot || watch))
  1890. X        me->p_flags &= ~PFREPAIR;
  1891. X    }
  1892. X    if (me->p_flags & PFPLOCK) {     /* set course to player x */
  1893. X    pl = &players[me->p_playerl];
  1894. X    if (pl->p_status != PALIVE)
  1895. X        me->p_flags &= ~PFPLOCK;
  1896. X    course = newcourse(pl->p_x, pl->p_y);
  1897. X    set_course(course);
  1898. X    }
  1899. X    if (me->p_flags & PFPLLOCK) {     /* set course to planet x */
  1900. X    int dist;
  1901. X    pln = &planets[me->p_planet];
  1902. X    dist = hypot((double) (me->p_x - pln->pl_x),
  1903. X        (double) (me->p_y - pln->pl_y));
  1904. X
  1905. X    /* This is magic.  It should be based on defines, but it slows
  1906. X       the ship down to warp two an appropriate distance from the
  1907. X       planet for orbit */
  1908. X
  1909. X    if (dist < (50 * ((me->p_speed * (me->p_speed+1)) + 10)))
  1910. X        set_speed(2);
  1911. X    if ((dist < ENTORBDIST) && (me->p_speed <= 2))  {
  1912. X        me->p_flags &= ~PFPLLOCK;
  1913. X        orbit();
  1914. X    }
  1915. X    else {
  1916. X        course = newcourse(pln->pl_x, pln->pl_y);
  1917. X        set_course(course);
  1918. X    }
  1919. X    }
  1920. X}
  1921. X
  1922. Xnewcourse(x, y)
  1923. Xint x, y;
  1924. X{
  1925. X    return((unsigned char) (atan2((double) (x - me->p_x),
  1926. X        (double) (me->p_y - y)) / 3.14159 * 128.));
  1927. X}
  1928. X
  1929. XredrawTstats()
  1930. X{
  1931. X    char    buf[BUFSIZ];
  1932. X
  1933. X    sprintf(buf, 
  1934. X    "Flags        warp dam shd torps  kills armies  fuel  wtemp etemp");
  1935. X    XText(tstatw, 50, 10, buf, strlen(buf), dfont, textColor, backColor);
  1936. X}
  1937. END_OF_redraw.c
  1938. if test 21165 -ne `wc -c <redraw.c`; then
  1939.     echo shar: \"redraw.c\" unpacked with wrong size!
  1940. fi
  1941. # end of overwriting check
  1942. fi
  1943. echo shar: End of archive 3 \(of 6\).
  1944. cp /dev/null ark3isdone
  1945. MISSING=""
  1946. for I in 1 2 3 4 5 6 ; do
  1947.     if test ! -f ark${I}isdone ; then
  1948.     MISSING="${MISSING} ${I}"
  1949.     fi
  1950. done
  1951. if test "${MISSING}" = "" ; then
  1952.     echo You have unpacked all 6 archives.
  1953.     rm -f ark[1-9]isdone
  1954. else
  1955.     echo You still need to unpack the following archives:
  1956.     echo "        " ${MISSING}
  1957. fi
  1958. ##  End of shell archive.
  1959. exit 0
  1960.  
  1961.  
  1962.