home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sources / apple2 / 6 < prev    next >
Encoding:
Text File  |  1992-11-08  |  21.6 KB  |  817 lines

  1. Path: sparky!uunet!stanford.edu!rutgers!igor.rutgers.edu!yoko.rutgers.edu!jac
  2. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  3. Newsgroups: comp.sources.apple2
  4. Subject: v001SRC065:  Robots for HyperC
  5. Message-ID: <Nov.8.18.12.09.1992.16069@yoko.rutgers.edu>
  6. Date: 8 Nov 92 23:12:10 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 806
  9. Approved: jac@paul.rutgers.edu
  10.  
  11. Submitted-by: Andy Tefft (teffta@tsengr.dnet.ge.com)
  12. Posting-number: Volume 1, Source:65
  13. Archive-name: games/c/robots
  14. Architecture: ANY_2
  15. Version-number: 2.5
  16.  
  17. The object of this game is to stay alive while robots chase you.  If
  18. a robot catches you, you die.  You are given two weapons in your fight:
  19. a teleportation device and a blaster.  When two robots crash into each
  20. other they create a junk heap; junk heaps are deadly to other robots.
  21. You are allowed to move junk heaps around.  When all the robots are
  22. junk heaps, you advance to the next level.
  23.  
  24. Enjoy.
  25.  
  26. =Read.Me
  27. -Robots
  28. -The object of this game is to stay alive while robots chase you.  If
  29. -a robot catches you, you die.  You are given two weapons in your fight:
  30. -a teleportation device and a blaster.  When two robots crash into each
  31. -other they create a junk heap; junk heaps are deadly to other robots.
  32. -You are allowed to move junk heaps around.  When all the robots are
  33. -junk heaps, you advance to the next level.
  34. -This version of robots is based on the robots game that is usually
  35. -distributed with Unix. It is not a port, however, but written mostly
  36. -on my Apple //c under Hyperc.  This is version 2.5.  It should be 
  37. -slightly faster than previous versions in the higher levels (results
  38. -vary), and fixes the unlimited blast bug. Revision history is in robots.c.
  39. -Files:
  40. -    Read.Me        This file
  41. -    ccrobots    script to compile and link source files
  42. -    ladd.c        ladd() function (see robots.doc)
  43. -    lnkrobots    script to just link object files
  44. -    robots.c    HyperC source
  45. -    robots.doc    Documentation
  46. -    robots.files     list of files for linker to link
  47. -    uitostr.c    uitostr() function (see robots.doc)
  48. -Andrew Tefft
  49. -TEFFTA@tsengr.dnet.ge.com
  50. -July 1992
  51. -Version 2.5
  52. -
  53. =Manifest
  54. -Read.Me
  55. -ccrobots
  56. -ladd.c
  57. -lnkrobots
  58. -robots.c
  59. -robots.doc
  60. -robots.files
  61. -uitostr.c
  62. =ccrobots
  63. -/csys/bin/ppf -i |/ram/|/csys/hdrs/ -o $1.p $1.c
  64. -/csys/bin/hyperc -o $1.s $1.p
  65. -rm $1.p
  66. -/csys/bin/asmcp -o $1.o $1.s
  67. -rm $1.s
  68. -lnk -l |/ram/|/csys/libs/ -o robots -as &s.o robots.o ladd.o &mylib &libc
  69. -
  70. =ladd.c
  71. -/* for some reason ladd is unresolved so... */
  72. -
  73. -/* this version of ladd just adds the lsb of src to the array dest. */
  74. -
  75. -ladd(dest,src)
  76. -unsigned int dest[2],src[2];
  77. -{
  78. -int t;
  79. -t=dest[1]+src[1];
  80. -if (t < dest[1]) dest[0]++;
  81. -dest[1]=t;
  82. -}
  83. -
  84. =lnkrobots
  85. -lnk -l |/ram/|/csys/libs/ -o robots -asi robots.files
  86. =robots.c
  87. -/* robots by Andy Tefft, 6/28/92
  88. -
  89. -version 1.0: 6/28/92 (original)
  90. -version 2.0: 6/29/92 (pushable piles) (developed under unix)
  91. -version 2.1: 6/29/92 (2-move robots)  (developed under unix)
  92. -version 2.2: 6/29/92 (ported back to hyperc)
  93. -version 2.3: 6/29/92 - disable / until it works
  94. -                     - add blast command
  95. -                     - various scoring changes
  96. -version 2.4: 7/4/92  attempt to use long integer array for score
  97. -version 2.5: 7/8/92  added first & last for faster looping
  98. -*/
  99. -
  100. -#define VER "2.5"
  101. -
  102. -#include <std.h>
  103. -
  104. -#define XSIZE 79
  105. -#define YSIZE 22
  106. -#define ROBOT(x) robot_string[robot_moves[x]]
  107. -
  108. -char robot_moves[251];
  109. -char robot_x[251],robot_y[251],player_x,player_y; /* position;
  110. -                                                    x=255 means dead */
  111. -char field[XSIZE+1][YSIZE+1]; /* grid array. 0: empty
  112. -                            1 - 250: robot #
  113. -                                253: wall
  114. -                                254: pile
  115. -                                255: player  */
  116. -
  117. -char pile_x[250],pile_y[250];
  118. -
  119. -int RANDSeed=5343;
  120. -int first,last,blasts,piles,safe_teleports,score[2];
  121. -char get_cmd,rndl,robot_string[4];
  122. -
  123. -main() {
  124. -int result,number; /* number of robots */
  125. -
  126. -printf("Robots by Andy Tefft, version %s.\n",VER);
  127. -
  128. -robot_string=" #&";
  129. -
  130. -while (1) {
  131. -  putstr("Seeding random number generator now...\n");
  132. -  rs();  /* randomize rndl */
  133. -  srandom( (unsigned int) rndl); /* seed with randomized # */
  134. -
  135. -  score[0]=0,score[1]=0;
  136. -  safe_teleports=0;
  137. -  blasts=1;
  138. -
  139. - for (number=10 ;; ++safe_teleports, ++blasts, number += (number < 240) * 10){
  140. -
  141. -    init(number); /* initialize arrays to 0 */
  142. -    randomize(number); /* fill screen with n robots */
  143. -    screensetup(number);
  144. -    first=1; last=number;
  145. -    get_cmd=0;
  146. -
  147. -while (1) {
  148. -    cursor(player_y,player_x);
  149. -    result=get_player_move(number);
  150. -    if (result==2) quit();
  151. -    if (!result) if ((result=robot_move(number))) break;
  152. -}
  153. -    if (result==2) { quit(); break; } /* died */
  154. -    /* otherwise result==-1 which means end of level so continue */
  155. -}
  156. -}
  157. -}
  158. -
  159. -quit() {
  160. -char key;
  161. -    cursor(23,0);
  162. -    putstr("\nYour score was: ");
  163. -    prscore();
  164. -    putstr("\nPress q to quit, any other key to play again: ");
  165. -    key=getkey(1);
  166. -    cr();
  167. -    if (key=='q') exit(0);
  168. -}
  169. -
  170. -/*  A random number generator */
  171. -
  172. -srandom(NewSeed)
  173. -int NewSeed;
  174. -
  175. -{
  176. -RANDSeed = NewSeed;
  177. -}
  178. -
  179. -unsigned int random()
  180. -{
  181. -  RANDSeed = RANDSeed * 18627;
  182. -  if (RANDSeed < 0)
  183. -   RANDSeed += 32768;
  184. -  return RANDSeed;
  185. -}
  186. -
  187. -#define FIELD(n) field[robot_x[n]][robot_y[n]]
  188. -
  189. -/* robot_move moves the robots, creates piles, checks for dead player.
  190. -    returns: 
  191. -        0: robots & player are alive
  192. -        2: player died
  193. -       -1: all robots are dead
  194. -*/
  195. -
  196. -robot_move(number)
  197. -int number;
  198. -{
  199. -int flag,i,alive,x,n,nx,ny;
  200. -
  201. -for (n=last,flag=0,alive=1; n>=first; n--) {
  202. -  if (robot_x[n]==255) continue;
  203. -
  204. -  for(i=0; i<robot_moves[n]; i++) {
  205. -
  206. -    if (FIELD(n)==n) {
  207. -        FIELD(n) = 0;
  208. -        cursor(robot_y[n],robot_x[n]);
  209. -        putchr(' ');                 /* blank out old position */
  210. -    }
  211. -
  212. -    if (robot_x[n] > player_x) --robot_x[n];
  213. -    else if (robot_x[n] < player_x) ++robot_x[n];
  214. -    if (robot_y[n] > player_y) --robot_y[n];
  215. -    else if (robot_y[n] < player_y) ++robot_y[n];
  216. -
  217. -    nx=robot_x[n]; ny=robot_y[n];
  218. -
  219. -    cursor(ny,nx);
  220. -
  221. -    if ((x=FIELD(n)) > n) {
  222. -        if (x==255) {
  223. -            return 2; /* player just died */
  224. -        }
  225. -        addscore(number*robot_moves[n]);
  226. -        if (get_cmd=='w') addscore(number*robot_moves[n]);
  227. -
  228. -        FIELD(n) = 254; /* pile */
  229. -/*
  230. -        pile_x[++piles]=robot_x[n];
  231. -        pile_y[piles]=robot_y[n];
  232. -*/
  233. -        robot_x[n]=255; /* this robot is dead */
  234. -        if (x != 254) {
  235. -            robot_x[x] = 255; /* kill the other robot too */
  236. -            addscore(number*robot_moves[x]);
  237. -            if (get_cmd=='w') addscore(number*robot_moves[x]);
  238. -        }
  239. -        putchr('*'); /* draw pile */
  240. -        break;   /* don't try and move a dead robot */
  241. -    }
  242. -    else  {
  243. -        FIELD(n)=n;
  244. -        putchr(ROBOT(n));
  245. -        alive=0;
  246. -        if (!flag) last=n;
  247. -        flag=n;
  248. -    }
  249. -  }
  250. -  if (robot_x[n]==255) continue; /* 2-mover just died */
  251. -}
  252. -first=flag;
  253. -return (-alive);
  254. -}
  255. -
  256. -/* return values:
  257. -    0: normal move
  258. -    1: don't move robots
  259. -    2: quit
  260. -*/
  261. -
  262. -get_player_move(number)
  263. -int number;
  264. -{
  265. -char move;
  266. -int ox,oy,ox1,oy1;
  267. -
  268. -    if (!get_cmd) move = getkey();
  269. -    else move=get_cmd;
  270. -
  271. -    if (!index(" .?qtrhjklyubnw>HJKLYUBNz",move)) return 1; /* legal moves */
  272. -    if (move=='q') return 2;
  273. -
  274. -    if (move=='t' && !safe_teleports) return 1;
  275. -    if (move=='r' || move=='t') {
  276. -        field[player_x][player_y]=0;
  277. -        cursor(player_y,player_x);
  278. -        putchr(' ');
  279. -
  280. -        if (move=='r') do {
  281. -            player_x=random()%(XSIZE-1)+1;
  282. -            player_y=random()%(YSIZE-1)+1;
  283. -        } while (field[player_x][player_y]);
  284. -
  285. -        else do {
  286. -            player_x=random()%(XSIZE-1)+1;
  287. -            player_y=random()%(YSIZE-1)+1;
  288. -        } while (!safe_pos(player_x,player_y));
  289. -        if (move=='t') safe_teleports--;
  290. -
  291. -        field[player_x][player_y]=255;
  292. -        cursor(player_y,player_x);
  293. -        putchr('@');
  294. -        cursor(player_y,player_x);
  295. -    return 0;
  296. -    }
  297. -
  298. -    if (move=='.') return 0;
  299. -
  300. -    if (move=='?') {
  301. -        cursor(23,0);
  302. -        putstr("hjklyubn move, . stay, r/t rand/safe, z blast  sc: ");
  303. -        prscore();
  304. -        printf(" tele: %d bl: %d (%d)",safe_teleports,blasts,
  305. -                number/10);
  306. -        return 1; /* don't do robot move */
  307. -    }
  308. -
  309. -    if (move==' ') return print_safe();
  310. -
  311. -    if (move=='z') return blast();
  312. -
  313. -    if (move=='/') {
  314. -        screensetup(number);
  315. -        return 1;
  316. -    }
  317. -
  318. -    if (move=='w') {
  319. -        get_cmd='w'; return 0;
  320. -    }
  321. -
  322. -    else if (move=='>') {
  323. -        if (safe_pos(player_x,player_y)) {
  324. -            get_cmd='>'; return 0;
  325. -        } else {
  326. -            get_cmd=0; return 1;
  327. -        }
  328. -    }
  329. -
  330. -/* all commands previous to this point MUST contain a return! */
  331. -
  332. -    ox=player_x; oy=player_y;
  333. -    field[player_x][player_y]=0;
  334. -    cursor(player_y,player_x);
  335. -    putchr(' ');
  336. -
  337. -/* move-while-safe moves */
  338. -
  339. -    if (move=='H') {
  340. -        if (!move_if_safe(player_x-1,player_y)) return put_n_stop();
  341. -        else get_cmd='H';
  342. -    } 
  343. -    else if (move=='J') {
  344. -        if (!move_if_safe(player_x,player_y+1)) return put_n_stop();
  345. -        else get_cmd='J';
  346. -    }
  347. -    else if (move=='K') {
  348. -        if (!move_if_safe(player_x,player_y-1)) return put_n_stop();
  349. -        else get_cmd='K';
  350. -    }
  351. -    else if (move=='L') {
  352. -        if (!move_if_safe(player_x+1,player_y)) return put_n_stop();
  353. -        else get_cmd='L';
  354. -    }
  355. -    else if (move=='Y') {
  356. -        if (!move_if_safe(player_x-1,player_y-1)) return put_n_stop();
  357. -        else get_cmd='Y';
  358. -    }
  359. -    else if (move=='U') {
  360. -        if (!move_if_safe(player_x+1,player_y-1)) return put_n_stop();
  361. -        else get_cmd='U';
  362. -    }
  363. -    else if (move=='B') {
  364. -        if (!move_if_safe(player_x-1,player_y+1)) return put_n_stop();
  365. -            get_cmd='B';
  366. -    }
  367. -    else if (move=='N') {
  368. -        if (!move_if_safe(player_x+1,player_y+1)) return put_n_stop();
  369. -            get_cmd='N';
  370. -    }
  371. -
  372. -/* regular moves */
  373. -
  374. -    ox1=player_x; oy1=player_y;
  375. -
  376. -    if ((move=='h' || move=='y' || move=='b') && player_x > 1 )
  377. -         --ox1;
  378. -    if ((move=='l' || move=='n' || move=='u') && player_x < XSIZE-1)
  379. -         ++ox1;
  380. -    if ((move=='j' || move=='b' || move=='n') && player_y < YSIZE-1)
  381. -         ++oy1;
  382. -    if ((move=='k' || move=='y' || move=='u') && player_y > 1)
  383. -         --oy1;
  384. -
  385. -    if (field[ox1][oy1]==254) move_pile(ox1,oy1,ox1-player_x,oy1-player_y);
  386. -
  387. -    if (!field[ox1][oy1]) player_x=ox1,player_y=oy1;
  388. -
  389. -    field[player_x][player_y]=255;
  390. -    cursor(player_y,player_x);
  391. -
  392. -    putchr('@');
  393. -
  394. -    cursor(player_y,player_x);
  395. -
  396. -    return (ox==player_x && oy==player_y);
  397. -}
  398. -
  399. -blast() {
  400. -int i,j,x;
  401. -    if (!blasts) return 1;
  402. -    blasts--;
  403. -    for (i=-1; i<2; i++)
  404. -        for (j=-1; j<2; j++)
  405. -            if ((x=(int)field[player_x+i][player_y+j]) < 251
  406. -                && x>0) {
  407. -               cursor(player_y+j,player_x+i);
  408. -               putchr(' ');
  409. -               field[player_x+i][player_y+j]=0;
  410. -               robot_x[x]=255;
  411. -            }
  412. -    return 0;
  413. -}
  414. -
  415. -
  416. -/* move_if_safe(x,y) updates player_x and player_y to x,y if x,y is
  417. -    a safe position. It does not update field[][]. Returns 1 if moved. */
  418. -
  419. -move_if_safe(x,y) 
  420. -int x,y;
  421. -{
  422. -  if (safe_pos(x,y)) {
  423. -      player_x=x,player_y=y;
  424. -      return 1;
  425. -  } else return 0;
  426. -}
  427. -
  428. -
  429. -/* put_n_stop() can be used anytime it is needed to draw the player
  430. -    and update the field[][] array with his position. */
  431. -
  432. -put_n_stop() {
  433. -    get_cmd=0;
  434. -    cursor(player_y,player_x);
  435. -    putchr('@');
  436. -    field[player_x][player_y]=255;
  437. -    return 1;
  438. -}
  439. -
  440. -/* move_pile moves pile from (x,y) to (x+dx,y+dy) if possible. returns 1
  441. -    if successful */
  442. -
  443. -move_pile(x,y,dx,dy) 
  444. -int x,y,dx,dy;
  445. -{
  446. -if (field[x+dx][y+dy]) return 0;
  447. -field[x][y]=0;
  448. -field[x+dx][y+dy]=254;
  449. -cursor(y,x);
  450. -putchr(' ');
  451. -cursor(y+dy,x+dx);
  452. -putchr('*');
  453. -return 1;
  454. -}
  455. -
  456. -/* safe_pos checks to see if pos (x,y) would be safe to go to. returns 1
  457. -    unless:
  458. -
  459. -    - wall or pile is there
  460. -    - robot would move there if player moved there
  461. -*/
  462. -
  463. -safe_pos(x,y)
  464. -int x,y;
  465. -{
  466. -int i,j;
  467. -
  468. -    if (field[x][y]) if (field[x][y] != 255) return 0;
  469. -    for (i=-2; i<3; i++)
  470. -        for (j=-2; j<3; j++) {
  471. -           if (x+i<0 || x+i>XSIZE || y+j<0 || y+j>YSIZE) continue;
  472. -           if (field[x+i][y+j]) if (field[x+i][y+j] < 251) {
  473. -              if (abs(i)<2 && abs(j)<2) return 0;
  474. -              if (robot_moves[field[x+i][y+j]] == 2 &&
  475. -                 field[x+i/2][y+j/2] != 253) return 0;
  476. -            }
  477. -    }
  478. -    return 1;
  479. -}
  480. -
  481. -init(number) 
  482. -int number; 
  483. -{
  484. -int x,y;
  485. -
  486. -page();
  487. -printf("initializing...\n");
  488. -
  489. -piles=0;
  490. -for (x=0; x<XSIZE; x++)
  491. -    for (y=0; y<YSIZE; y++)
  492. -        field[x][y]=0;
  493. -
  494. -}
  495. -
  496. -randomize(number) 
  497. -int number;
  498. -{
  499. -int i,x,y;
  500. -putstr("Randomizing...\n");
  501. -for (i=1; i<=number; i++) {
  502. -    do {
  503. -        x=random()%(XSIZE-1)+1;
  504. -        y=random()%(YSIZE-1)+1;
  505. -        }
  506. -    while (field[x][y]!=0);
  507. -
  508. -    robot_x[i]=x; robot_y[i]=y;
  509. -    field[x][y]=i;
  510. -
  511. -    if (random()%10==2) robot_moves[i]=2;
  512. -    else robot_moves[i]=1;
  513. -}
  514. -
  515. -    do {
  516. -        x=random()%(XSIZE-1)+1;
  517. -        y=random()%(YSIZE-1)+1;
  518. -        }
  519. -    while (field[x][y]!=0);
  520. -
  521. -    player_x=x; player_y=y;
  522. -    field[x][y]=255;
  523. -}
  524. -
  525. -screensetup(n)
  526. -int n;
  527. -{
  528. -int i;
  529. -
  530. -page();
  531. -
  532. -for (i=0; i<= XSIZE; i++) { putchr('-'); field[i][0]=253; }
  533. -cursor(YSIZE,0);
  534. -for (i=0; i<= XSIZE; i++) { putchr('-'); field[i][YSIZE]=253; }
  535. -
  536. -for (i=1; i<YSIZE; i++) {
  537. -    cursor(i,0);
  538. -    putchr('|');
  539. -    cursor(i,XSIZE);
  540. -    putchr('|');
  541. -    field[0][i]=253;
  542. -    field[XSIZE][i]=253;
  543. -}
  544. -
  545. -for (i=1; i<=n; i++) {
  546. -    cursor(robot_y[i],robot_x[i]);
  547. -    putchr(ROBOT(i));
  548. -}
  549. -
  550. -for (i=0; i<piles; i++) {
  551. -    cursor(pile_y[i],pile_x[i]);
  552. -    putchr('*');
  553. -}
  554. -
  555. -cursor(player_y,player_x);
  556. -putchr('@');
  557. -
  558. -}
  559. -
  560. -/* rs waits for a keypress, scrambling rndl until pressed. This seeds
  561. -    the random number generator. */
  562. -
  563. -rs() {
  564. -printf("Press a key to begin...");
  565. -while (!keypress()) ++rndl;
  566. -return 0;
  567. -}
  568. -
  569. -/* print_safe() is a kludge to print out the safe moves. */
  570. -
  571. -print_safe() {
  572. -cursor(23,0);
  573. -
  574. -clreol();
  575. -
  576. -if (safe_pos(player_x-1,player_y)) putchr('h');
  577. -if (safe_pos(player_x,player_y-1)) putchr('k');
  578. -if (safe_pos(player_x,player_y+1)) putchr('j');
  579. -if (safe_pos(player_x+1,player_y)) putchr('l');
  580. -if (safe_pos(player_x-1,player_y-1)) putchr('y');
  581. -if (safe_pos(player_x+1,player_y-1)) putchr('u');
  582. -if (safe_pos(player_x-1,player_y+1)) putchr('b');
  583. -if (safe_pos(player_x+1,player_y+1)) putchr('n');
  584. -if (safe_pos(player_x,player_y)) putchr('.');
  585. -
  586. -return 1;
  587. -}
  588. -
  589. -/* addscore adds int i to score[2] */
  590. -
  591. -addscore(i)
  592. -int i;
  593. -{
  594. -int i2[2];
  595. -
  596. -i2[0]=0;
  597. -i2[1]=i;
  598. -
  599. -ladd(score,i2);
  600. -}
  601. -
  602. -/* prscore prints the score in ascii */
  603. -
  604. -prscore() {
  605. -char scorestr[9];
  606. -
  607. -uitostr2(scorestr,score);
  608. -putstr(scorestr);
  609. -}
  610. -
  611. =robots.doc
  612. -This version of robots is based on the robots game that is usually
  613. -distributed with Unix. It is not a port however, but written mostly on
  614. -my Apple //c under Hyperc. The SYS file version was created with the
  615. -use of Gary Desrochers and Andy Werner's 'makesys' programs.
  616. -
  617. -The object of the game is to stay alive while robots chase after you.
  618. -These robots are evil in that they will kill you if they catch you. However,
  619. -they are also stupid, and tend to crash into each other.
  620. -
  621. -You are given two weapons in your fight. One is a teleportation device.
  622. -You are allowed unlimited random teleports (which can drop you right into
  623. -danger), and a limited number of 'guaranteed safe' teleports. You also
  624. -have a blaster which has limited uses; it destroys all robots adjacent
  625. -to you but does not stop the rest from advancing.
  626. -
  627. -When two robots crash into each other, they create a junk heap and you
  628. -get points. Robots which run into junk heaps are also destroyed, giving you
  629. -more points. If a robot runs into you, you die and the game ends. You cannot
  630. -run into junk heaps or the screen borders. You can push a junk heap in any
  631. -direction as long as there is a blank space to move it into.
  632. -
  633. -When all the robots are junk heaps, you advance to the next level.
  634. -You gain one safe teleportation and one blast, and the next level contains 
  635. -more robots (up to a maximum of 250). (if all the robots are dead but you
  636. -have not advanced to the next level, press any movement key.)
  637. -
  638. -You are represented on the screen by an inverse '@'. Robots are '#' and
  639. -'&'; the latter move twice as fast as the former. Junk heaps are '*'. Borders
  640. -are obvious.
  641. -
  642. -Keys are as follows (and are the same as vi cursor-motion keys):
  643. -
  644. -             y   k   u    >: wait as long as it's safe
  645. -               \ | /      w: wait until level is cleared or you die
  646. -             h -   - l    .: wait one move
  647. -               / | \
  648. -             b   j   n
  649. -
  650. -YUHJKLBN: run in that direction as long as it's safe
  651. -?: show brief help, # of safe teleports (te:), # of blasts (bl:), score (sc:),
  652. -   and level
  653. -z: blast (or think of it as zap)
  654. -<space>: show safe moves
  655. -q: quit
  656. -
  657. -Scoring: each '#' robot is worth 10 points times the level number. '&' robots
  658. -are worth double. Each dead robot after you press 'w' is worth double its
  659. -usual value. Robots that you blast are worth 0.
  660. -
  661. ------------------------------------------------------------------------
  662. -planned future enhancements:
  663. -
  664. -- high score list
  665. -- ability to skip lower levels
  666. -
  667. ------------------------------------------------------------------------
  668. -The files:
  669. -
  670. -robots.doc: this file
  671. -robots:     hyperc executable
  672. -robots.c:   hyperc source
  673. -robots.system: prodos SYS file
  674. -ladd.c:     the ladd() function (see below)
  675. -uitostr.c:  the uitostr() function (see below)
  676. -ladd.o, uitostr.o
  677. -robots.files: list of files to link; use -i option with the linker
  678. -lnkrobots: the link command in a script
  679. -
  680. -Please send me any bug reports or enhancements (I'm particularly looking
  681. -for speed improvements and a better random-number generator).
  682. -
  683. -Andy Tefft
  684. -teffta@tsengr.dnet.ge.com
  685. -6/30/90
  686. -------------------------------------------------------------------------
  687. -Version 2.4 (7/4/92):
  688. -
  689. -You only need read this section if you plan on compiling the program.
  690. -You can play robots without compiling the program. You would only need
  691. -to recompile it if you make changes.
  692. -
  693. -So that the score doesn't "roll over" at 65536, I now use a two-integer
  694. -array to store the score. At this time I have decided to start splitting
  695. -up the source because it is taking a long time to compile. Therefore
  696. -this distribution contains two extra files: uitostr.[c,o] and ladd.[c,o].
  697. -
  698. -To compile robots, you now must follow these steps:
  699. -
  700. -1) cc ladd, if ladd.o does not exist (the 'lnk' command will fail,
  701. -    but we just need the ladd.o file anyway)
  702. -2) cc uitostr, if uitostr.o does not exist
  703. -
  704. -(note: I have included uitostr.o and ladd.o in the distribution so
  705. -you don't have to compile them again unless you change them)
  706. -
  707. -3) cc robots
  708. -4) do 'lnkrobots' or else type in the lnk command yourself.
  709. -
  710. -Note that you only have to cc the files you change; keep the .o files
  711. -around so that you can just redo 'lnkrobots' after you change & cc
  712. -one or more of the source files.
  713. -
  714. -note on ladd:
  715. -
  716. -ladd(ldest,lsrc) is listed in the hyperc manual. lib /csys/libs/libc shows
  717. -ladd.o. But I kept getting _ladd: unresolved when I linked the program,
  718. -so I wrote my own ladd() function. IMPORTANT: it does *not* add the
  719. -most significant int of the arrays, even though it takes two arrays
  720. -as arguments. I only needed to add an int to a 2-byte int array so that's
  721. -all I made it do, although I made the calling interface the same as
  722. -what the manual specifies.
  723. -
  724. -What this means to you is that if something is screwed up in my copy
  725. -of hyperc, and your copy of hyperc includes ladd like it should, you
  726. -will get a duplicate reference when you link it. If this should happen,
  727. -just remove ladd.o from the 'robots.files' file which is used by the link
  728. -command, and re-link. It should work. 
  729. -
  730. -note on uitostr:
  731. -
  732. -It is ugly. If you have a better way to do it, send it to me! If you don't,
  733. -and you want to use uitostr, feel free, and keep these things in mind:
  734. -
  735. -1) uitostr(str,i) converts the integer i[2] to the string str. i[0]
  736. -    is the *least* significant 16 bits of i.
  737. -2) uitostr2(str,i) expects i[0] to be the *most* significant bits of i.
  738. -3) i must be positive; it is actually treated as an unsigned int by
  739. -    the function. If you want to print a negative number, figure out
  740. -    how to take its absolute value, and print a - yourself.
  741. -4) str must be declared with size of at least 9 -- up to 8 digits
  742. -    plus a trailing null. No checks are made on this size and the function
  743. -    will be more than happy to tromp on other variables if you declare
  744. -    the string too small.
  745. -5) the string returned is right-justified. to print it without the leading
  746. -    spaces, you can do something like this:
  747. -
  748. -    putstr(rindex(str,' ')+1);
  749. -
  750. -    (rindex will return a pointer to the last ' ' character in the string).
  751. -
  752. -
  753. =robots.files
  754. -&s.o
  755. -robots.o
  756. -uitostr.o
  757. -ladd.o
  758. -&libc
  759. =uitostr.c
  760. -/* uitostr.c:
  761. -
  762. -    prints a two-byte unsigned int in ascii.
  763. -    uitostr(buf,i) assumes i[2] with i[0]=least significant;
  764. -    uitostr2(buf,i) assumes i[0] is most significant
  765. -
  766. -    note: uitostr destroys i; uitostr2 does not.
  767. -*/
  768. -
  769. -
  770. -#include <std.h>
  771. -
  772. -__twodiv(i) /* divides i by 10 and leaves the result in i */
  773. -unsigned int i[2]; /* i[0] is lsb */
  774. -{
  775. -i[0]=(i[0]/10)+6553*(i[1]%10)+(i[0]%10+6*(i[1]%10))/10;
  776. -i[1]=i[1]/10;
  777. -}
  778. -
  779. -__mod10(i) /* returns i%10 */
  780. -unsigned int i[2];
  781. -{
  782. -return (i[0]%10+(6*i[1])%10)%10;
  783. -}
  784. -
  785. -uitostr(buf,i)
  786. -char buf[9]; /* room for 8 chars */
  787. -unsigned int i[2];
  788. -{
  789. -int j;
  790. -for(j=7; j>=0; j--) {
  791. -    if (!(i[1]|i[0])) buf[j]=' ';
  792. -    else buf[j]=__mod10(i)+'0';
  793. -    __twodiv(i);
  794. -}
  795. -buf[8]=0;
  796. -if (buf[7]==' ') buf[7]='0';
  797. -return;
  798. -}
  799. -
  800. -uitostr2(buf,i)
  801. -char buf[9];
  802. -unsigned int i[2];
  803. -{
  804. -unsigned int j[2];
  805. -j[0]=i[1];
  806. -j[1]=i[0];
  807. -uitostr(buf,j);
  808. -}
  809. -
  810. + END OF ARCHIVE
  811.