home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume1 / warp7 / part03 < prev    next >
Internet Message Format  |  1987-06-10  |  50KB

  1. Path: seismo!rutgers!ames!ucbcad!ucbvax!decvax!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v01i047:  warp7 - space war game, Part03/07
  5. Message-ID: <1296@tekred.TEK.COM>
  6. Date: 10 Jun 87 20:40:33 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 1964
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: Larry Wall <lwall%sdcrdcf.UUCP@jove.cam.unisys.com>
  12. Comp.sources.games: Volume 1, Issue 47
  13. Archive-name: warp7/Part03
  14.  
  15.  
  16.  
  17. #! /bin/sh
  18.  
  19. # Make a new directory for the warp sources, cd to it, and run kits 1
  20. # thru 7 through sh.  When all 7 kits have been run, read README.
  21.  
  22. echo "This is warp 7.0 kit 3 (of 7).  If kit 3 is complete, the line"
  23. echo '"'"End of kit 3 (of 7)"'" will echo at the end.'
  24. echo ""
  25. export PATH || (echo "You didn't use sh, you clunch." ; kill $$)
  26. echo Extracting move.c
  27. sed >move.c <<'!STUFFY!FUNK!' -e 's/X//'
  28. X/* $Header: move.c,v 7.0.1.2 86/10/20 14:37:06 lwall Exp $ */
  29. X
  30. X/* $Log:    move.c,v $
  31. X * Revision 7.0.1.2  86/10/20  14:37:06  lwall
  32. X * Picked some lint.
  33. X * 
  34. X * Revision 7.0.1.1  86/10/16  10:52:09  lwall
  35. X * Added Damage.  Fixed random bugs.
  36. X * 
  37. X * Revision 7.0  86/10/08  15:12:40  lwall
  38. X * Split into separate files.  Added amoebas and pirates.
  39. X * 
  40. X */
  41. X
  42. X#include "EXTERN.h"
  43. X#include "warp.h"
  44. X#include "bang.h"
  45. X#include "object.h"
  46. X#include "move.h"
  47. X#include "play.h"
  48. X#include "score.h"
  49. X#include "term.h"
  50. X#include "them.h"
  51. X#include "us.h"
  52. X#include "util.h"
  53. X#include "weapon.h"
  54. X#include "INTERN.h"
  55. X#include "move.h"
  56. X
  57. Xvoid
  58. Xmove_init()
  59. X{
  60. X    ;
  61. X}
  62. X
  63. Xvoid
  64. Xbounce(obj)
  65. XReg4 OBJECT *obj;
  66. X{
  67. X    Reg1 int x;
  68. X    Reg2 int y;
  69. X    Reg3 int count=0;
  70. X
  71. X    y = (obj->posy - sgn(obj->vely) + YSIZE00) % YSIZE;
  72. X    x = (obj->posx - sgn(obj->velx) + XSIZE00) % XSIZE;
  73. X    while (occupant[y][x]) {
  74. X    y = (y + rand_mod(3) - 1 + YSIZE00) % YSIZE;
  75. X    x = (x + rand_mod(3) - 1 + XSIZE00) % XSIZE;
  76. X    if (++count > 10000) {     /* if universe full, get out of it fast */
  77. X        unmake_object(obj);
  78. X        if (ent) unmake_object(ent);
  79. X        if (base) unmake_object(base);
  80. X        finish = 1;
  81. X        return;
  82. X    }
  83. X    }
  84. X    obj->posy = y;
  85. X    obj->posx = x;
  86. X    obj->vely = 0;
  87. X    obj->velx = 0;
  88. X    occupant[y][x] = obj;
  89. X    if (numamoebas && obj->image == ' ')
  90. X    mvaddc(y+1, x*2, amb[y][x]);
  91. X    else
  92. X    mvaddc(y+1, x*2, obj->image);
  93. X}
  94. X
  95. Xvoid
  96. Xmove_universe()
  97. X{
  98. X    Reg1 OBJECT *curobj;
  99. X    Reg2 int x;
  100. X    Reg3 int y;
  101. X    Reg4 OBJECT *temp;
  102. X    OBJECT *thenext;
  103. X
  104. X    for (curobj = movers; curobj != &root; curobj = curobj->next) {
  105. X    x = curobj->posx;
  106. X    y = curobj->posy;
  107. X    if (curobj == occupant[y][x]) {
  108. X        occupant[y][x] = 0;
  109. X    }
  110. X    else if (curobj->type != Torp && curobj->type != Web) {
  111. X        resetty();
  112. X        abort();
  113. X    }
  114. X    }
  115. X    for (curobj = movers; curobj != &root; curobj = thenext) {
  116. X    thenext = curobj->next;
  117. X    if (curobj->vely || curobj->velx) {
  118. X        y = curobj->posy;
  119. X        x = curobj->posx;
  120. X        if (curobj->image != ' ' &&
  121. X          (!(temp=occupant[y][x]) || temp->image==' ') ) {
  122. X        move(y+1, x*2, numamoebas ? amb[y][x] : ' ');
  123. X        }
  124. X        y = (y + curobj->vely + YSIZE00) % YSIZE;
  125. X        x = (x + curobj->velx + XSIZE00) % XSIZE;
  126. X        if (!(temp=occupant[y][x]) || temp->type != Star ||
  127. X          curobj->type != Torp || curobj->image == '+' ||
  128. X          curobj->image == 'x') {
  129. X        curobj->posy = y;
  130. X        curobj->posx = x;
  131. X        }
  132. X        else {
  133. X        if (curobj->image == '0') {
  134. X            curobj->vely = rand_mod(3)-1;
  135. X            curobj->velx = rand_mod(3)-1;
  136. X        }
  137. X        else
  138. X            curobj->vely = curobj->velx = 0;
  139. X        y = curobj->posy;
  140. X        x = curobj->posx;
  141. X        }
  142. X    }
  143. X    else {            /* not moving */
  144. X        y = curobj->posy;
  145. X        x = curobj->posx;
  146. X        if (curobj->type == Torp ||
  147. X        curobj->type == Star ||
  148. X        curobj->type == Web) {
  149. X        curobj->flags |= STATIC;
  150. X        curobj->next->prev = curobj->prev;
  151. X        curobj->prev->next = curobj->next;
  152. X        curobj->prev = movers->prev;
  153. X        curobj->next = movers;
  154. X        movers->prev->next = curobj;
  155. X        movers->prev = curobj;
  156. X        }
  157. X    }
  158. X    if (temp = occupant[y][x]) {        /* already occupied? */
  159. X        if (!temp->contend) {
  160. X        if (temp->type == Torp) {
  161. X            if (temp->image == '+')
  162. X            blast[y][x] += 1250;
  163. X            else if (temp->image == 'o' && (base||ent))
  164. X            blast[y][x] += 500+super*20;
  165. X            else if (temp->image == 'O' && (base||ent))
  166. X            blast[y][x] += 5000+super*100;
  167. X        }
  168. X        }
  169. X        yblasted[y] |= 1;
  170. X        xblasted[x] |= 1;
  171. X        blasted = TRUE;
  172. X        curobj->contend = temp;
  173. X        occupant[y][x] = curobj;
  174. X        switch (curobj->type) {
  175. X        case Enemy:
  176. X        if (numamoebas && curobj == nuke && temp->image == '+')
  177. X            blast[y][x] += 80000;
  178. X        else if (temp->type == Enemy)
  179. X            blast[y][x] += 10;
  180. X        else
  181. X            goto defblast;
  182. X        break;
  183. X        case Crusher:
  184. X        if (curobj->velx)
  185. X            blast[y][x] += 100000;
  186. X        else
  187. X            goto defblast;
  188. X        break;
  189. X        case Torp:
  190. X        if (curobj->image == '+')
  191. X            blast[y][x] += (temp==nuke ? 80000 : 1250);
  192. X        else if (curobj->image == 'o')
  193. X            blast[y][x] += 500+super*20;
  194. X        else if (curobj->image == 'O')
  195. X            blast[y][x] += 5000+super*100;
  196. X        goto defblast;
  197. X        case Star:
  198. X        if (temp == ent)
  199. X            goto damshield;
  200. X        goto defblast;
  201. X        case Enterprise:
  202. X        if (temp->type == Star) {
  203. X          damshield:
  204. X            if (!rand_mod(10)) {
  205. X            if (!damflag[NOSHIELDS])
  206. X                damage++;
  207. X            if (damflag[NOSHIELDS] < 100)
  208. X                damflag[NOSHIELDS] += rand_mod(smarts)/5+2;
  209. X            }
  210. X        }
  211. X        goto defblast;
  212. X        default:
  213. X          defblast:
  214. X        blast[y][x] += rand_mod(751)+1;
  215. X        break;
  216. X        }
  217. X    }
  218. X    else {
  219. X        occupant[y][x] = curobj;
  220. X        if (curobj->image != ' ' &&
  221. X            (curobj->velx || curobj->vely ||
  222. X         curobj->type == Torp || curobj->type == Web) ) {
  223. X        mvaddc(y+1, x*2, curobj->image);
  224. X        }
  225. X        if (curobj->type == Crusher && curobj->velx) {
  226. X        blast[y][x] += 100000;
  227. X        yblasted[y] |= 1;
  228. X        xblasted[x] |= 1;
  229. X        blasted = TRUE;
  230. X        }
  231. X    }
  232. X    }
  233. X    if (blasted) {
  234. X    Reg7 int minxblast = -1;
  235. X    Reg8 int maxxblast = -2;
  236. X    Reg5 long tmpblast;
  237. X
  238. X    blasted = numamoebas;
  239. X    for (x=0; x<XSIZE; x++) {
  240. X        if (xblasted[x]) {
  241. X        xblasted[x] = 0;
  242. X        maxxblast = x;
  243. X        if (minxblast < 0)
  244. X            minxblast = x;
  245. X        }
  246. X    }
  247. X    for (y=0; y<YSIZE; y++) {
  248. X        if (yblasted[y]) {
  249. X        yblasted[y] = 0;
  250. X        for (x=minxblast; x<=maxxblast; x++) {
  251. X            tmpblast = blast[y][x];
  252. X            if (numamoebas && amb[y][x] == '~') {
  253. X            if (temp = occupant[y][x]) {
  254. X                if (temp->image == '&')
  255. X                tmpblast >>= 1;
  256. X                else if (temp->type == Web)
  257. X                tmpblast = 100000;
  258. X                else
  259. X                tmpblast += 50 + temp->energy/100;
  260. X                if (tmpblast > 250 && !rand_mod(5+(inumstars>>4)))
  261. X                modify_amoeba(y,x,1,'~',5);
  262. X            }
  263. X            xblasted[x] = 2;
  264. X            yblasted[y] = 2;
  265. X            }
  266. X            if (tmpblast) {
  267. X            Reg6 OBJECT *biggie = 0;
  268. X
  269. X            blast[y][x] = 0;
  270. X            temp = occupant[y][x];
  271. X            if (tmpblast < 0) {
  272. X                if (numamoebas && tmpblast < -1000000 &&
  273. X                amb[y][x] == '~' && temp != nuke) {
  274. X                amb[y][x] = ' ';
  275. X                if (!temp)
  276. X                    make_plink(y,x);
  277. X                ambsize--;
  278. X                }
  279. X                tmpblast = 0;
  280. X            }
  281. X            if (temp) {
  282. X                if ((!numamoebas || amb[y][x]==' ') &&
  283. X                  tmpblast < 100000)
  284. X                make_plink(y,x);
  285. X                for ( ;temp;
  286. X                  temp = curobj->contend,curobj->contend = 0){
  287. X                curobj = temp;
  288. X                switch (curobj->type) {
  289. X                case Enterprise: {
  290. X                    long tmp = curobj->energy;
  291. X
  292. X                    if (ent->energy>500 || apolloflag & 1)
  293. X                    curobj->energy -= tmpblast /
  294. X                       ((apolloflag & 1)
  295. X                        ? 20
  296. X                        : (5+abs(ent->velx)+abs(ent->vely))
  297. X                           / ((damflag[NOSHIELDS]>>3)+1)+1);
  298. X                    else
  299. X                    curobj->energy -= tmpblast;
  300. X                    if (rand_mod(1 + tmp - curobj->energy) > 100
  301. X                    || ent->energy < (entmax>>1)) {
  302. X                    if (debug & 128 ||
  303. X                      (damage <= smarts/10 &&
  304. X                       !rand_mod(6-smarts/20-massacre) )) {
  305. X                        tmp = rand_mod(MAXDAMAGE);
  306. X                        if (damflag[tmp]) {
  307. X                        if (damflag[tmp] < 60)
  308. X                          damflag[tmp] += rand_mod(60);
  309. X                        }
  310. X                        else {
  311. X                        damflag[tmp] =
  312. X                          rand_mod(smarts+10)+2;
  313. X                        damage++;
  314. X                        }
  315. X                    }
  316. X                    }
  317. X                    break;
  318. X                }
  319. X                case Base:
  320. X                    if (base->energy > 1000 || apolloflag & 2)
  321. X                    curobj->energy -= tmpblast /
  322. X                       ((apolloflag & 2)?20:5);
  323. X                    else
  324. X                    curobj->energy -= tmpblast;
  325. X                    break;
  326. X                case Crusher:
  327. X                    if (tmpblast > 132767)
  328. X                    curobj->energy -= (tmpblast - 100000);
  329. X                    else if (tmpblast >= 100000) {
  330. X                    curobj->energy += (tmpblast - 100000);
  331. X                    if (curobj->energy > 32767)
  332. X                        curobj->energy = 32767;
  333. X                    }
  334. X                    else    /* vulnerable while feeding */
  335. X                    curobj->energy -= tmpblast;
  336. X                    break;
  337. X                case Enemy:
  338. X                    curobj->energy -= tmpblast*10/enemshields;
  339. X                    break;
  340. X                default:
  341. X                    curobj->energy -= tmpblast;
  342. X                    break;
  343. X                }
  344. X                if (curobj->energy < 0) {    /* killed it? */
  345. X                    switch (curobj->image) {
  346. X                    case 'A':
  347. X                    tmpblast = 100000;
  348. X                    make_blast(y,x,8192L,1);
  349. X                    numapollos = apolloflag = 0;
  350. X                    numstars--;
  351. X                    numenemies--;
  352. X                    curscore += 5000;
  353. X                    deados = 0;
  354. X                    break;
  355. X                    case 'E': case 'e': case 'C': case 'c':
  356. X                    ent = 0;
  357. X                    numents--;
  358. X                    if (base)
  359. X                        status = 2;
  360. X                    else
  361. X                        status = 3;
  362. X                    deados = 0;
  363. X                    break;
  364. X                    case 'B': case 'b':
  365. X                    base = 0;
  366. X                    numbases--;
  367. X                    if (ent)
  368. X                        status = entmode;
  369. X                    else
  370. X                        status = 3;
  371. X                    deados = 0;
  372. X                    break;
  373. X                    case '&': {
  374. X                    int i, xxx, yyy;
  375. X
  376. X                    for (i = 0; i < YSIZE; i++)
  377. X                        yblasted[i] &= 1;
  378. X                    for (i = 0; i < XSIZE; i++)
  379. X                        xblasted[i] &= 1;
  380. X                    numamoebas = 0;    /* ignore amb[][] now */
  381. X                    for (yyy = 0; yyy < YSIZE; yyy++) {
  382. X                        for (xxx = 0; xxx < XSIZE; xxx++) {
  383. X                        if (amb[yyy][xxx] == '~' &&
  384. X                            !occupant[yyy][xxx]) {
  385. X                            mvaddch(yyy+1,xxx*2,' ');
  386. X                        }
  387. X                        }
  388. X                    }
  389. X                    numenemies--;
  390. X                    curscore += 10000;
  391. X                    if (curobj == enemies)
  392. X                        enemies = curobj->next;
  393. X                    deados = 0;
  394. X                    break;
  395. X                    }
  396. X                    case '<': case '>': {
  397. X                    int i;
  398. X
  399. X                    numenemies--;
  400. X                    numcrushes = 0;
  401. X                    curscore += 10000;
  402. X                    if (curobj == movers)
  403. X                        movers = curobj->next;
  404. X                    if (curobj == enemies)
  405. X                        enemies = curobj->next;
  406. X                    deados = 0;
  407. X
  408. X                    tmpblast = 100000;
  409. X                    make_blast(y,(x+XSIZE00)%XSIZE,10000L,0);
  410. X                    if (curobj->image == '<') {
  411. X                        for (i=XSIZE00; i<=XSIZE01; i++)
  412. X                        make_blast(y,(x+i)%XSIZE,
  413. X                            10000L,0);
  414. X                        for (i=XSIZE00; i<=XSIZE02; i++)
  415. X                        make_blast(y,(x+i)%XSIZE,
  416. X                            10000L,0);
  417. X                        make_blast(y,(x+XSIZE03)%XSIZE,
  418. X                        10000L,1);
  419. X                        for (i=XSIZE00; i<=XSIZE08; i++)
  420. X                        make_blast(y,(x+i)%XSIZE,
  421. X                            10000L,0);
  422. X                    }
  423. X                    else {
  424. X                        for (i=XSIZE00; i>=XSIZE99; i--)
  425. X                        make_blast(y,(x+i)%XSIZE,
  426. X                            10000L,0);
  427. X                        for (i=XSIZE00; i>=XSIZE98; i--)
  428. X                        make_blast(y,(x+i)%XSIZE,
  429. X                            10000L,0);
  430. X                        make_blast(y,(x+XSIZE97)%XSIZE,
  431. X                        10000L,1);
  432. X                        for (i=XSIZE00; i>=XSIZE92; i--)
  433. X                        make_blast(y,(x+i)%XSIZE,
  434. X                            10000L,0);
  435. X                    }
  436. X                    }
  437. X                    break;
  438. X                    case 'K':
  439. X                    numenemies--;
  440. X                    curscore += curobj->mass;
  441. X                    if (curobj == enemies)
  442. X                        enemies = curobj->next;
  443. X                    deados = 0;
  444. X                    break;
  445. X                    case 'T':
  446. X                    numenemies--;
  447. X                    curscore += curobj->mass*3/2;
  448. X                    if (curobj == enemies)
  449. X                        enemies = curobj->next;
  450. X                    deados = 0;
  451. X                    break;
  452. X                    case 'R': case ' ': case 'P':
  453. X                    numenemies--;
  454. X                    if (curobj->flags & PIRATE)
  455. X                        curscore += curobj->mass;
  456. X                    else
  457. X                        curscore += curobj->mass*3;
  458. X                    if (curobj == enemies)
  459. X                        enemies = curobj->next;
  460. X                    deados = 0;
  461. X                    break;
  462. X                    case 'G':
  463. X                    numenemies--;
  464. X                    numgorns--;
  465. X                    tmpblast = 100000;
  466. X                    if (madgorns)
  467. X                        curscore += curobj->mass/2;
  468. X                    else
  469. X                        curscore += curobj->mass*2;
  470. X                    if (curobj == enemies)
  471. X                        enemies = curobj->next;
  472. X                    {
  473. X                        int xxx,yyy;
  474. X
  475. X                        for (xxx = -1; xxx<=1; xxx++)
  476. X                        for (yyy = -1; yyy<=1; yyy++)
  477. X                            if (rand_mod(2+massacre))
  478. X                            fire_torp(curobj,
  479. X                                yyy,xxx);
  480. X                    }
  481. X                    deados = 0;
  482. X                    break;
  483. X                    case '@':
  484. X                    numinhab--;
  485. X                    /* FALL THROUGH */
  486. X                    case '*':
  487. X                    banging = TRUE;
  488. X                    numstars--;
  489. X                    break;
  490. X                    case '|': case '-': case '/': case '\\':
  491. X                    tmpblast = 100000;
  492. X                    make_blast(y,x,curobj->mass,1);
  493. X                    banging = TRUE;
  494. X                    deados = 0;
  495. X                    break;
  496. X                    case 'x':
  497. X                    curscore += 10;
  498. X                    deados = 0;
  499. X                    break;
  500. X                    case 'X':
  501. X                    curscore += 100;
  502. X                    numxes--;
  503. X                    deados = 0;
  504. X                    break;
  505. X                    case '0':
  506. X                    curscore += 35;
  507. X                    numos--;
  508. X                    deados += 3;
  509. X                    break;
  510. X                    case 'o':
  511. X                    curscore += 100;
  512. X                    numos--;
  513. X                    deados++;
  514. X                    break;
  515. X                    case 'O':
  516. X                    curscore += 200;
  517. X                    numos--;
  518. X                    deados += 2;
  519. X                    break;
  520. X                    case 'M':
  521. X                    deadmudds++;
  522. X                    inumfriends--;
  523. X                    numfriends--;
  524. X                    if (curobj == enemies)
  525. X                        enemies = curobj->next;
  526. X                    break;
  527. X                    case 'Q': case 'W': case 'Y': case 'U':
  528. X                    case 'I': case 'S': case 'D': case 'H':
  529. X                    case 'J': case 'L': case 'Z': case 'V':
  530. X                    case 'F':
  531. X                    numfriends--;
  532. X                    if (curobj == enemies)
  533. X                        enemies = curobj->next;
  534. X                    if (inumfriends < 10)
  535. X                        madfriends += 500;
  536. X                    else
  537. X                        madfriends += 10000/inumfriends;
  538. X                    break;
  539. X                    }
  540. X                    if (tmpblast < 100000)
  541. X                    make_blast(y,x,curobj->mass,1);
  542. X                    unmake_object(curobj);
  543. X                }
  544. X                else {        /* didn't kill anything */
  545. X                    if (!biggie)
  546. X                    biggie = curobj;
  547. X                    else {
  548. X                    if (biggie->mass > curobj->mass)
  549. X                        bounce(curobj);
  550. X                    else {
  551. X                        bounce(biggie);
  552. X                        biggie = curobj;
  553. X                    }
  554. X                    }
  555. X                }
  556. X                }
  557. X                if (biggie) {
  558. X                occupant[y][x] = biggie;
  559. X                if (numamoebas && biggie->image == ' ')
  560. X                    mvaddch(y+1,x*2, amb[y][x]);
  561. X                else
  562. X                    mvaddch(y+1,x*2, biggie->image);
  563. X                }
  564. X                else {
  565. X                occupant[y][x] = 0;
  566. X                mvaddch(y+1, x*2, numamoebas ? amb[y][x] : ' ');
  567. X                }
  568. X            }
  569. X            }
  570. X        }
  571. X        }
  572. X    }
  573. X    }
  574. X    do_bangs();
  575. X    if (numcrushes && movers->type == Crusher)
  576. X    movers->vely = 0;
  577. X    if (curobj = base) {
  578. X    char ch;
  579. X
  580. X    curobj->velx = 0;
  581. X    curobj->vely = 0;
  582. X    curobj->energy += 25*lookaround(curobj->posy,curobj->posx,Star);
  583. X    if (curobj->energy > basemax)
  584. X        curobj->energy = basemax;
  585. X    if (curobj->energy >= 1000)
  586. X        ch = 'B';
  587. X    else
  588. X        ch = 'b';
  589. X    if (ch != curobj->image) {
  590. X        setimage(curobj, ch);
  591. X    }
  592. X    }
  593. X    if (curobj = ent) {
  594. X    char ch;
  595. X
  596. X    if (entmode == 0) {
  597. X        curobj->velx = 0;
  598. X        curobj->vely = 0;
  599. X    }
  600. X    if (base && !cloaking && !curobj->velx && !curobj->vely &&
  601. X      lookfor(curobj->posy,curobj->posx,Base)) {
  602. X        int tmp;
  603. X
  604. X#ifdef lint
  605. X        tmp = 0;
  606. X#else
  607. X        tmp = (int) (base->energy - 1000 < entmax - curobj->energy ?
  608. X                 base->energy - 1000 : entmax - curobj->energy);
  609. X#endif
  610. X        if (tmp < 0)
  611. X        tmp = 0;
  612. X        curobj->energy += tmp;
  613. X        base->energy -= tmp;
  614. X        tmp = (btorp < 50 - etorp ?
  615. X           btorp : 50 - etorp);
  616. X        etorp += tmp;
  617. X        btorp -= tmp;
  618. X        if (damage) {
  619. X        tmp = rand_mod(MAXDAMAGE);
  620. X        if (damflag[tmp] > 5) {
  621. X            damflag[tmp] = rand_mod(5)+1;
  622. X        }
  623. X        }
  624. X    }
  625. X    if (curobj->energy >= 500 && (!damage || !damflag[NOSHIELDS]))
  626. X        ch = cloaked?'C':'E';
  627. X    else
  628. X        ch = cloaked?'c':'e';
  629. X    if (ch != curobj->image) {
  630. X        setimage(curobj, ch);
  631. X    }
  632. X    }
  633. X}
  634. X
  635. Xint
  636. Xlookaround(y, x, what)
  637. XReg1 int y;
  638. XReg2 int x;
  639. XReg4 char what;
  640. X{
  641. X    Reg3 OBJECT *obj;
  642. X    Reg5 int count=0;
  643. X    Reg6 int xp;
  644. X    Reg7 int xm;
  645. X
  646. X    if ((obj=occupant[y][xp=(x+XSIZE01)%XSIZE])&&obj->type == what) /* 0, 1 */
  647. X    count++;
  648. X    if ((obj=occupant[y][xm=(x+XSIZE99)%XSIZE])&&obj->type == what) /* 0, -1 */
  649. X    count++;
  650. X    if ((obj=occupant[y=(y+YSIZE99)%YSIZE][xp])&&obj->type == what) /* -1, 1 */
  651. X    count++;
  652. X    if ((obj=occupant[y][x])&&obj->type == what)                    /* -1, 0 */
  653. X    count++;
  654. X    if ((obj=occupant[y][xm])&&obj->type == what)                   /* -1, -1 */
  655. X    count++;
  656. X    if ((obj=occupant[y=(y+2)%YSIZE][xp])&&obj->type == what)       /* 1, 1 */
  657. X    count++;
  658. X    if ((obj=occupant[y][x])&&obj->type == what)                    /* 1, 0 */
  659. X    count++;
  660. X    if ((obj=occupant[y][xm])&&obj->type == what)                   /* 1, -1 */
  661. X    count++;
  662. X    return (count);
  663. X}
  664. X
  665. Xint
  666. Xlookfor(y, x, what)
  667. XReg1 int y;
  668. XReg2 int x;
  669. XReg4 char what;
  670. X{
  671. X    Reg3 OBJECT *obj;
  672. X    Reg5 int xp;
  673. X    Reg6 int xm;
  674. X
  675. X    if ((obj=occupant[y][xp=(x+XSIZE01)%XSIZE])&&obj->type == what ||/* 0, 1 */
  676. X        (obj=occupant[y][xm=(x+XSIZE99)%XSIZE])&&obj->type == what ||/* 0, -1 */
  677. X        (obj=occupant[y=(y+YSIZE99)%YSIZE][xp])&&obj->type == what ||/* -1, 1 */
  678. X        (obj=occupant[y][x])&&obj->type == what                    ||/* -1, 0 */
  679. X        (obj=occupant[y][xm])&&obj->type == what                   ||/* -1,-1 */
  680. X        (obj=occupant[y=(y+2)%YSIZE][xp])&&obj->type == what       ||/* 1, 1 */
  681. X        (obj=occupant[y][x])&&obj->type == what                    ||/* 1, 0 */
  682. X        (obj=occupant[y][xm])&&obj->type == what)                    /* 1, -1 */
  683. X    return(1);
  684. X    return (0);
  685. X}
  686. X
  687. XOBJECT*
  688. Xlookimg(y, x, what)
  689. XReg1 int y;
  690. XReg2 int x;
  691. XReg4 char what;
  692. X{
  693. X    Reg3 OBJECT *obj;
  694. X    Reg5 int xp;
  695. X    Reg6 int xm;
  696. X
  697. X    if ((obj=occupant[y][xp=(x+XSIZE01)%XSIZE])&&obj->image==what ||/* 0, 1 */
  698. X        (obj=occupant[y][xm=(x+XSIZE99)%XSIZE])&&obj->image==what ||/* 0, -1 */
  699. X        (obj=occupant[y=(y+YSIZE99)%YSIZE][xp])&&obj->image==what ||/* -1, 1 */
  700. X        (obj=occupant[y][x])&&obj->image==what                    ||/* -1, 0 */
  701. X        (obj=occupant[y][xm])&&obj->image==what                   ||/* -1,-1 */
  702. X        (obj=occupant[y=(y+2)%YSIZE][xp])&&obj->image==what       ||/* 1, 1 */
  703. X        (obj=occupant[y][x])&&obj->image==what                    ||/* 1, 0 */
  704. X        (obj=occupant[y][xm])&&obj->image==what)                    /* 1, -1 */
  705. X    return obj;
  706. X    return Null(OBJECT*);
  707. X}
  708. !STUFFY!FUNK!
  709. echo Extracting weapon.c
  710. sed >weapon.c <<'!STUFFY!FUNK!' -e 's/X//'
  711. X/* $Header: weapon.c,v 7.0.1.2 86/10/20 14:36:33 lwall Exp $ */
  712. X
  713. X/* $Log:    weapon.c,v $
  714. X * Revision 7.0.1.2  86/10/20  14:36:33  lwall
  715. X * Picked some lint.
  716. X * 
  717. X * Revision 7.0.1.1  86/10/16  10:54:42  lwall
  718. X * Added Damage.  Fixed random bugs.
  719. X * 
  720. X * Revision 7.0  86/10/08  15:18:08  lwall
  721. X * Split into separate files.  Added amoebas and pirates.
  722. X * 
  723. X */
  724. X
  725. X#include "EXTERN.h"
  726. X#include "warp.h"
  727. X#include "bang.h"
  728. X#include "object.h"
  729. X#include "move.h"
  730. X#include "score.h"
  731. X#include "sig.h"
  732. X#include "term.h"
  733. X#include "them.h"
  734. X#include "us.h"
  735. X#include "util.h"
  736. X#include "INTERN.h"
  737. X#include "weapon.h"
  738. X
  739. Xvoid
  740. Xweapon_init()
  741. X{
  742. X    ;
  743. X}
  744. X
  745. Xvoid
  746. Xfire_torp(from, ydir, xdir)
  747. XReg1 OBJECT *from;
  748. XReg3 int ydir;
  749. XReg4 int xdir;
  750. X{
  751. X    Reg2 OBJECT *to;
  752. X
  753. X    if (from->type == Enemy ||
  754. X       (from == ent && etorp > 0) ||
  755. X       (from == base && btorp > 0)) {
  756. X    to = occupant[(from->posy+from->vely+ydir+YSIZE00)%YSIZE]
  757. X             [(from->posx+from->velx+xdir+XSIZE00)%XSIZE];
  758. X    if (from->type != Enemy || !to || to->vely || to->velx) {
  759. X        if (from->type != Enemy &&
  760. X         (to = isatorp[from==base][ydir+1][xdir+1])) {
  761. X        to->vely += ydir;
  762. X        to->velx += xdir;
  763. X        }
  764. X        else {
  765. X        if (from == ent) {
  766. X            to = make_object(Torp, '+', from->posy,from->posx,
  767. X            from->vely+ydir,from->velx+xdir, 0L, 1L,&root);
  768. X            aretorps++;
  769. X            isatorp[0][ydir+1][xdir+1] = to;
  770. X            etorp--;
  771. X        }
  772. X        else if (from == base) {
  773. X            to = make_object(Torp, '+', from->posy,from->posx,
  774. X            from->vely+ydir,from->velx+xdir, 0L, 1L,&root);
  775. X            aretorps++;
  776. X            isatorp[1][ydir+1][xdir+1] = to;
  777. X            btorp--;
  778. X        }
  779. X        else if (from->image == 'G') {
  780. X            numos++;
  781. X            to = make_object(Torp, 'o', from->posy,from->posx,
  782. X            from->vely+ydir,from->velx+xdir, 100L, 1L,&root);
  783. X            if (madgorns) {
  784. X            possiblescore += 35;
  785. X            to->image = '0';
  786. X            to->mass = 2000;
  787. X            to->energy = 2000;
  788. X            }
  789. X            else if (rand_mod(120)+10 > smarts)
  790. X            possiblescore += 100;
  791. X            else {
  792. X            possiblescore += 200;
  793. X            to->image = 'O';
  794. X            }
  795. X        }
  796. X        else {
  797. X            to = make_object(Torp, 'x', from->posy,from->posx,
  798. X            from->vely+ydir,from->velx+xdir, 0L, 1L,&root);
  799. X            if (rand_mod(160)+10 > smarts)
  800. X            possiblescore += 10;
  801. X            else {
  802. X            possiblescore += 100;
  803. X            to->image = 'X';
  804. X            to->mass = 1000+super*20;
  805. X            numxes++;
  806. X            }
  807. X        }
  808. X        }
  809. X    }
  810. X    }
  811. X}
  812. X
  813. Xvoid
  814. Xattack(attackee)
  815. XReg7 OBJECT *attackee;
  816. X{
  817. X    Reg1 int dx;
  818. X    Reg2 int dy;
  819. X    Reg3 int curx;
  820. X    Reg4 int cury;
  821. X    Reg5 int prob;
  822. X    Reg6 OBJECT *obj;
  823. X    Reg8 bool torps;
  824. X    Reg9 bool webnear = FALSE;
  825. X    Reg10 bool thru_stars;
  826. X    int nukey;
  827. X    int nukex;
  828. X    int nukedist;
  829. X
  830. X    if (attackee) {
  831. X    if (attackee == nuke) {
  832. X        if (amb[attackee->posy][attackee->posx] != '~')
  833. X        return;
  834. X        nukey = nukex = 0;
  835. X        nukedist = 100;
  836. X    }
  837. X    for (dx= -1; dx<=1 ; dx++) {
  838. X        for (dy= -1; dy<=1; dy++) {
  839. X        if (dx||dy) {
  840. X            cury = attackee->posy;
  841. X            curx = attackee->posx;
  842. X            torps = thru_stars = FALSE;
  843. X            if (massacre || madgorns || !rand_mod(53-super) )
  844. X            webnear += rand_mod(2);
  845. X            else
  846. X            webnear = FALSE;
  847. X            for (prob = scandist;prob;prob--) {
  848. X            cury = (cury + dy + YSIZE00) % YSIZE;
  849. X            curx = (curx + dx + XSIZE00) % XSIZE;
  850. X            if (obj = occupant[cury][curx]) {
  851. X                switch (obj->image) {
  852. X                case 'P': case 'K': case 'R': case ' ':
  853. X        pot_shot:
  854. X                if (attackee == nuke) {
  855. X                    if (rand_mod(2+scandist-prob) <
  856. X                      rand_mod(smarts/40+1))
  857. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  858. X                }
  859. X                if (rand_mod(51 - sm50) <= prob) {
  860. X                    switch (obj->strategy||thru_stars?0:
  861. X                      rand_mod(ent?4:2)) {
  862. X                    case 1: case 2:
  863. X                    if (-dy + attackee->vely == obj->vely
  864. X                     && -dx + attackee->velx == obj->velx)
  865. X                        fire_torp(obj,
  866. X                         -dy + attackee->vely,
  867. X                         -dx + attackee->velx);
  868. X                    else
  869. X                        fire_torp(obj,
  870. X                         -dy + attackee->vely - obj->vely,
  871. X                         -dx + attackee->velx - obj->velx);
  872. X                    if (obj->image == ' ')
  873. X                        setimage(obj,
  874. X                          obj->flags & PIRATE ? 'P' : 'R');
  875. X                    break;
  876. X                    case 3: {
  877. X                    int newspeed =
  878. X                        rand_mod(prob<5&&smarts>70?4:3)-1;
  879. X                    
  880. X                    obj->vely = -dy * newspeed;
  881. X                    obj->velx = -dx * newspeed;
  882. X                    if (newspeed >= 0 &&
  883. X                        !rand_mod(82-sm80)) {
  884. X                        obj->vely += attackee->vely;
  885. X                        obj->velx += attackee->velx;
  886. X                    }
  887. X                    break;
  888. X                    }
  889. X                    case 0:
  890. X                    if (!torps && obj->energy > 1000) {
  891. X                        fire_phaser(obj, -dy, -dx);
  892. X                        if (smarts > 40 &&
  893. X                           (scandist-prob > 5
  894. X                        || attackee==base) &&
  895. X                           (massacre || obj->strategy ||
  896. X                            rand_mod(2)))
  897. X                        while (rand_mod(2))
  898. X                            fire_phaser(obj, -dy, -dx);
  899. X                        if (obj->image == ' ')
  900. X                        setimage(obj,
  901. X                          obj->flags&PIRATE ? 'P':'R');
  902. X                    }
  903. X                    if (obj->strategy) {
  904. X                        obj->velx = obj->vely = 0;
  905. X                        if (obj->energy < 1000 ||
  906. X                          bvely || bvelx)
  907. X                        obj->strategy = 0;
  908. X                    }
  909. X                    else if ((attackee==base ||
  910. X                          (cloaking && attackee==ent)
  911. X                         ) &&
  912. X                         scandist-prob > 5 &&
  913. X                             !(rand_mod(
  914. X                           ent?antibase*2:antibase)) )
  915. X                        obj->strategy = 1;
  916. X                    break;
  917. X                    }
  918. X                }
  919. X                goto bombout;
  920. X                case 'G':
  921. X                if (thru_stars && obj->strategy < 7)
  922. X                    goto bombout;
  923. X                if (attackee == nuke) {
  924. X                    if (rand_mod(2+scandist-prob) <
  925. X                      rand_mod(smarts/40+1))
  926. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  927. X                    goto bombout;
  928. X                }
  929. X                if (obj->strategy) {
  930. X                    if (madgorns || !rand_mod(4)) {
  931. X                    obj->vely = attackee->vely;
  932. X                    obj->velx = attackee->velx;
  933. X                    }
  934. X                    obj->strategy += (!torps && deados > 10);
  935. X                    if (obj->strategy > 4)
  936. X                    madgorns = TRUE;
  937. X                    if (!torps && obj->strategy > 5) {
  938. X                    do {
  939. X                        fire_phaser(obj, -dy, -dx);
  940. X                    } while (rand_mod(2));
  941. X                    }
  942. X                }
  943. X                else if (numgorns >= numenemies-1 &&
  944. X                    deados > 15+numgorns*5)
  945. X                    obj->strategy = 1;
  946. X                if (madgorns || rand_mod(51 - sm50) <= prob) {
  947. X                    if (-dy + attackee->vely == obj->vely
  948. X                     && -dx + attackee->velx == obj->velx)
  949. X                    fire_torp(obj,
  950. X                     -dy + attackee->vely,
  951. X                     -dx + attackee->velx);
  952. X                    else
  953. X                    fire_torp(obj,
  954. X                     -dy + attackee->vely - obj->vely,
  955. X                     -dx + attackee->velx - obj->velx);
  956. X                }
  957. X                goto bombout;
  958. X                case 'T':
  959. X                if (attackee == nuke) {
  960. X                    if (rand_mod(2+scandist-prob) <
  961. X                      rand_mod(smarts/40+1))
  962. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  963. X                }
  964. X                if (thru_stars)
  965. X                    goto bombout;
  966. X                if (webnear && scandist-prob > 5) {
  967. X                    if (massacre || rand_mod(50) < super) {
  968. X                    if (!torps && obj->energy > 1000) {
  969. X                        fire_phaser(obj, -dy, -dx);
  970. X                        while (!rand_mod(57-sm55))
  971. X                        fire_phaser(obj, -dy, -dx);
  972. X                    }
  973. X                    }
  974. X                }
  975. X                goto bombout;
  976. X                case 'C': case 'c':
  977. X                if (thru_stars)
  978. X                    goto bombout;
  979. X                break;
  980. X                case 'Q': case 'W': case 'Y': case 'U':
  981. X                case 'I': case 'S': case 'D': case 'H': case 'J':
  982. X                case 'L': case 'Z': case 'V': case 'M': case 'F':
  983. X                if (attackee == nuke) {
  984. X                    if (rand_mod(2+scandist-prob) <
  985. X                      rand_mod(smarts/40+1))
  986. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  987. X                    if (rand_mod(2))
  988. X                    goto pot_shot;
  989. X                }
  990. X                if (madfriends > 1000) {
  991. X                    madfriends -= 200;
  992. X                    goto pot_shot;
  993. X                }
  994. X                /* FALL THROUGH */
  995. X                case '+':
  996. X                if (attackee == nuke) {
  997. X                    if (smarts > 70) {
  998. X                    if (
  999. X                     (obj->posx + obj->velx + XSIZE00)%XSIZE
  1000. X                        == attackee->posx &&
  1001. X                     (obj->posy + obj->vely + YSIZE00)%YSIZE
  1002. X                        == attackee->posy ) {
  1003. X                        Tract(nuke,dy,dx,-1);
  1004. X                    }
  1005. X                    else
  1006. X                        while (!rand_mod(82-sm80))
  1007. X                        Tract(nuke,dy,dx,-1);
  1008. X                    }
  1009. X                    else if (smarts > 60 ||
  1010. X                      rand_mod(2+scandist-prob) <
  1011. X                      rand_mod(smarts/20+1))
  1012. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  1013. X                }
  1014. X                torps = FALSE;
  1015. X                thru_stars = FALSE;
  1016. X                break;
  1017. X                case '|': case '-': case '/': case '\\':
  1018. X                if (thru_stars)
  1019. X                    goto bombout;
  1020. X                webnear = (scandist-prob < 3);
  1021. X                torps = FALSE;
  1022. X                break;
  1023. X                case 'x':
  1024. X                if (attackee == nuke) {
  1025. X                    if (rand_mod(2+scandist-prob) <
  1026. X                      rand_mod(smarts/20+1))
  1027. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  1028. X                }
  1029. X                if (thru_stars)
  1030. X                    goto bombout;
  1031. X                torps = TRUE;
  1032. X                break;
  1033. X                case 'o': case 'O': case '0':
  1034. X                if (attackee == nuke) {
  1035. X                    if (rand_mod(2+scandist-prob) <
  1036. X                      rand_mod(smarts/20+1))
  1037. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  1038. X                }
  1039. X                if (thru_stars)
  1040. X                    goto bombout;
  1041. X                torps = TRUE;
  1042. X                if (rand_mod(99+3*scandist) < smarts+3*prob) {
  1043. X                    obj->vely = -dy + attackee->vely;
  1044. X                    obj->velx = -dx + attackee->velx;
  1045. X                    if (obj->flags & STATIC) {/* not a mover? */
  1046. X                    obj->flags &= ~STATIC;
  1047. X                    obj->prev->next = obj->next;
  1048. X                    obj->next->prev = obj->prev;
  1049. X                    root.prev->next = obj;
  1050. X                    obj->prev = root.prev;
  1051. X                    root.prev = obj;
  1052. X                    obj->next = &root;
  1053. X                    }
  1054. X                }
  1055. X                if (obj->image != '0')
  1056. X                    break;
  1057. X                /* DROP THROUGH! */
  1058. X                case 'X':
  1059. X                if (attackee == nuke) {
  1060. X                    if (rand_mod(2+scandist-prob) <
  1061. X                      rand_mod(smarts/20+1))
  1062. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  1063. X                }
  1064. X                torps = TRUE;
  1065. X                if (thru_stars)
  1066. X                    goto bombout;
  1067. X                if (prob == scandist) {
  1068. X                    int y, x;
  1069. X
  1070. X                    blast[y=(obj->posy+obj->vely+YSIZE00)%YSIZE]
  1071. X                     [x=(obj->posx+obj->velx+XSIZE00)%XSIZE]
  1072. X                      += (obj->image == '0' ? 2000 : 200);
  1073. X                    yblasted[y] |= 1;
  1074. X                    xblasted[x] |= 1;
  1075. X                    blasted = TRUE;
  1076. X                }
  1077. X                break;
  1078. X                case 'A':
  1079. X                if (attackee != nuke) {
  1080. X                    if (scandist-prob>1 && !rand_mod(51-super))
  1081. X                    Tract(obj,-dy,-dx,1);
  1082. X                }
  1083. X                /* FALL THROUGH */
  1084. X                case '*': case '@':
  1085. X                if (attackee == nuke) {
  1086. X                    if (amb[cury][curx] != '~') {
  1087. X                    if (scandist-prob < nukedist) {
  1088. X                        nukedist = scandist-prob;
  1089. X                        nukey = dy;    /* nearest food in */
  1090. X                        nukex = dx;    /*   this direction */
  1091. X                    }
  1092. X                    if (smarts > 55 && scandist-prob > 8) {
  1093. X                        if (rand_mod(30+scandist-prob) <
  1094. X                          rand_mod(smarts/20+1))
  1095. X                        Tract(nuke,dy,dx,1);
  1096. X                    }
  1097. X                    }
  1098. X                    else if (obj->vely || obj->velx) {
  1099. X                    Tract(nuke,dy,dx,1); /* for looks */
  1100. X                    obj->vely = obj->velx = 0;
  1101. X                    }
  1102. X                }
  1103. X                if (!thru_stars)
  1104. X                    if (rand_mod(97-sm95))
  1105. X                    goto bombout;
  1106. X                    else
  1107. X                    thru_stars = TRUE;
  1108. X                break;
  1109. X                case '<': case '>':
  1110. X                if (attackee == nuke) {
  1111. X                    if ((!dy && scandist-prob < 8) ||
  1112. X                      rand_mod(2+scandist-prob) <
  1113. X                      rand_mod(smarts/20+1) ) {
  1114. X                    nuke->mass += 10000;
  1115. X                    Tract(nuke,dy,dx,-1);
  1116. X                    nuke->mass -= 10000;
  1117. X                    }
  1118. X                }
  1119. X                goto bombout;
  1120. X                case 'E': case 'B':
  1121. X                if (attackee == nuke) {
  1122. X                    if (rand_mod(2+scandist-prob) <
  1123. X                      rand_mod(smarts/40+1))
  1124. X                    Tract(nuke,dy,dx,rand_mod(3)?1:-1);
  1125. X                }
  1126. X                goto bombout;
  1127. X                default:
  1128. X                goto bombout;
  1129. X                }
  1130. X            }
  1131. X            else {
  1132. X                if (thru_stars)
  1133. X                goto bombout;
  1134. X            }    
  1135. X            }
  1136. Xbombout:            ; /* end of loop */
  1137. X        }
  1138. X        }
  1139. X    }
  1140. X    if (attackee == nuke && nukedist < 100) {/* aim amoeba at nearest */
  1141. X        if (nukey < 0)            /*   free star */
  1142. X        nukey = 2;
  1143. X        if (nukex < 0)
  1144. X        nukex = 2;
  1145. X        nuke->strategy = nukey + (nukex << 2);
  1146. X    }
  1147. X    }
  1148. X}
  1149. X
  1150. Xvoid
  1151. Xfire_phaser(obj, dy, dx)
  1152. XReg7 OBJECT *obj;
  1153. XReg5 int dy;
  1154. XReg6 int dx;
  1155. X{
  1156. X    Reg1 int y;
  1157. X    Reg2 int x;
  1158. X    Reg3 int skipping;
  1159. X    Reg4 int size=5000;
  1160. X    int decr = 50, oldy, oldx;
  1161. X    static char curchar[] = "@* ";
  1162. X
  1163. X    if (obj == ent)
  1164. X    decr = 100;
  1165. X    else if (obj == base) {
  1166. X    decr = 1000;
  1167. X    size = 200;
  1168. X    }
  1169. X    if (!dy)
  1170. X    curchar[2] = '-';
  1171. X    else if (!dx)
  1172. X    curchar[2] = '!';
  1173. X    else if (dy == dx)
  1174. X    curchar[2] = '\\';
  1175. X    else
  1176. X    curchar[2] = '/';
  1177. X    if (obj->energy >= decr) {
  1178. X    obj->energy -= decr;
  1179. X    for (
  1180. X      /* initialize */
  1181. X      skipping = (obj != base),
  1182. X      y = (obj->posy+(obj==base?dy*2:dy)+YSIZE00)%YSIZE,
  1183. X      x = (obj->posx+(obj==base?dx*2:dx)+XSIZE00)%XSIZE;
  1184. X      /* while */
  1185. X      size && (!occupant[y][x]||(skipping && occupant[y][x]->type==Star));
  1186. X      /* at end of loop */
  1187. X      y = (y+dy+YSIZE00) % YSIZE,
  1188. X      x = (x+dx+XSIZE00) % XSIZE,
  1189. X      size = size * 3 / 4 ) {
  1190. X        move(y+1,x*2,0);
  1191. X        beg_qwrite();
  1192. X        if (obj == base || obj->image == 'T') {
  1193. X        *filler = '@';
  1194. X        qwrite();
  1195. X        *filler = '#';
  1196. X        qwrite();
  1197. X        *filler = '~';
  1198. X        qwrite();
  1199. X        *filler = '%';
  1200. X        qwrite();
  1201. X        *filler = ':';
  1202. X        qwrite();
  1203. X        *filler = '@';
  1204. X        }
  1205. X        else {
  1206. X        *filler = size >= 500 ?
  1207. X              *curchar : (size >= 50 ?
  1208. X                     curchar[1] :
  1209. X                     curchar[2]);
  1210. X        }
  1211. X        qwrite();
  1212. X        if (occupant[y][x])
  1213. X        qaddc(occupant[y][x]->image);
  1214. X        else {
  1215. X        if (numamoebas)
  1216. X            qaddc(amb[y][x]);
  1217. X        else
  1218. X            qaddspace();
  1219. X        if (skipping)
  1220. X            skipping = 0;
  1221. X        }
  1222. X        end_qwrite();
  1223. X    }
  1224. X    if (size) {
  1225. X        char img;
  1226. X
  1227. X        assert(occupant[y][x]);
  1228. X        img = occupant[y][x]->image;
  1229. X        if (occupant[y][x]->type == Crusher) {
  1230. X        if (dy)
  1231. X            return;
  1232. X            if (dx==(img == '<' ? 1 : -1) ) {
  1233. X            occupant[y][x]->image =
  1234. X            (occupant[y][x]->velx *= -1) < 0 ? '>' : '<';
  1235. X            return;
  1236. X        }
  1237. X        }
  1238. X        else if (occupant[y][x]->flags & FRIENDLY)
  1239. X        madfriends += 200;
  1240. X        if (numamoebas && amb[y][x] == '~' && smarts % 3 &&
  1241. X        (smarts > 70 || rand_mod(smarts) > rand_mod(20)) ) {
  1242. X        if (size > 10000)
  1243. X            modify_amoeba(y,x,1,'~',10);
  1244. X        else if (size > 1000)
  1245. X            modify_amoeba(y,x,1,'~',7);
  1246. X        else if (size > 50)
  1247. X            modify_amoeba(y,x,1,'~',5);
  1248. X        else
  1249. X            modify_amoeba(y,x,1,'~',2);
  1250. X        if (occupant[y][x] == nuke) {
  1251. X            nuke->strategy = rand_mod(30);
  1252. X            nuke->flags |= COUNTDOWN;
  1253. X        }
  1254. X        return;
  1255. X        }
  1256. X        else {
  1257. X        move(y+1,x*2,0);
  1258. X        beg_qwrite();
  1259. X        if (img == ' ') {
  1260. X            *filler = occupant[y][x]->flags & PIRATE ? 'P' : 'R';
  1261. X            occupant[y][x]->image = *filler;
  1262. X            occupant[y][x]->strategy = 0;
  1263. X            qwrite();
  1264. X            qwrite();
  1265. X        }
  1266. X        else if (img == 'C' || img == 'c') {
  1267. X            cloaked = 0;
  1268. X            img += 2;
  1269. X            occupant[y][x]->image = img;
  1270. X            *filler = img;
  1271. X            qwrite();
  1272. X            qwrite();
  1273. X        }
  1274. X        else if (img == 'K' && size > 50)
  1275. X            occupant[y][x]->strategy = 0;
  1276. X        *filler = '@';
  1277. X        qwrite();
  1278. X        *filler = '#';
  1279. X        qwrite();
  1280. X        *filler = '@';
  1281. X        qwrite();
  1282. X        *filler = '#';
  1283. X        qwrite();
  1284. X        *filler = '@';
  1285. X        qwrite();
  1286. X        qaddc(img);
  1287. X        end_qwrite();
  1288. X        oldy = y;
  1289. X        oldx = x;
  1290. X        y = (occupant[oldy][oldx]->posy + occupant[oldy][oldx]->vely +
  1291. X            YSIZE00) % YSIZE;
  1292. X        x = (occupant[oldy][oldx]->posx + occupant[oldy][oldx]->velx +
  1293. X            XSIZE00) % XSIZE;
  1294. X        if (occupant[y][x] && occupant[y][x]->type == Star) {
  1295. X            y = occupant[oldy][oldx]->posy;
  1296. X            x = occupant[oldy][oldx]->posx;
  1297. X        }
  1298. X        if (obj==base)
  1299. X            blast[y][x] += size>50 ? 15000 : (size>15 ? 1500 : 150);
  1300. X        else if (obj==ent)
  1301. X            blast[y][x] += size*4;
  1302. X        else if (obj->image=='T')
  1303. X            blast[y][x] += 15000;
  1304. X        else
  1305. X            blast[y][x] += size*smarts/25;
  1306. X        yblasted[y] |= 1;
  1307. X        xblasted[x] |= 1;
  1308. X        blasted = TRUE;
  1309. X        }
  1310. X    }
  1311. X    }
  1312. X}
  1313. X
  1314. Xint
  1315. Xtract(obj, dy, dx, to_or_fro)
  1316. XReg7 OBJECT *obj;
  1317. XReg4 int dy;
  1318. XReg5 int dx;
  1319. Xint to_or_fro;
  1320. X{
  1321. X    Reg1 int y;
  1322. X    Reg2 int x;
  1323. X    Reg3 int size=10;
  1324. X    static char ch;
  1325. X    Reg6 OBJECT *tractee;
  1326. X
  1327. X    if (!dy)
  1328. X    ch = '|';
  1329. X    else if (!dx)
  1330. X    ch = '-';
  1331. X    else if (dy == dx)
  1332. X    ch = '/';
  1333. X    else
  1334. X    ch = '\\';
  1335. X    {
  1336. X    for (
  1337. X      y = (obj->posy+dy+YSIZE00)%YSIZE,
  1338. X      x = (obj->posx+dx+XSIZE00)%XSIZE;
  1339. X      size && (!occupant[y][x]);
  1340. X      y = (y+dy+YSIZE00) % YSIZE, x = (x+dx+XSIZE00) % XSIZE, size--) {
  1341. X        move(y+1,x*2,0);
  1342. X        beg_qwrite();
  1343. X        *filler = ch;
  1344. X        qwrite();
  1345. X        qwrite();
  1346. X        if (numamoebas)
  1347. X        qaddch(amb[y][x]);
  1348. X        else
  1349. X        qaddspace();
  1350. X        end_qwrite();
  1351. X    }
  1352. X    tractee = occupant[y][x];
  1353. X    if (size) {
  1354. X        assert(tractee);
  1355. X        if (numamoebas && obj != nuke && amb[y][x] == '~') {
  1356. X        if (to_or_fro > 0)
  1357. X            modify_amoeba(y,x,2,'~',size);
  1358. X        else
  1359. X            modify_amoeba(y,x,1,' ',size);
  1360. X        }
  1361. X        if (tractee->type != Web &&
  1362. X        (tractee->mass < obj->mass * 5 ||
  1363. X         (tractee->type == Crusher && !dx) ) ) {
  1364. X        if (tractee == ent) {
  1365. X            evely -= dy * to_or_fro;
  1366. X            evelx -= dx * to_or_fro;
  1367. X        }
  1368. X        else if (tractee == base) {
  1369. X            bvely -= dy * to_or_fro;
  1370. X            bvelx -= dx * to_or_fro;
  1371. X        }
  1372. X        else {
  1373. X            tractee->vely -= dy * to_or_fro;
  1374. X            tractee->velx -= dx * to_or_fro;
  1375. X        }
  1376. X        if (tractee->type == Torp ||
  1377. X            tractee->type == Star) {
  1378. X            if (tractee->flags & STATIC) {  /* not a mover? */
  1379. X            tractee->flags &= ~STATIC;
  1380. X            tractee->prev->next = tractee->next;
  1381. X            tractee->next->prev = tractee->prev;
  1382. X            root.prev->next = tractee;
  1383. X            tractee->prev = root.prev;
  1384. X            root.prev = tractee;
  1385. X            tractee->next = &root;
  1386. X            }
  1387. X        }
  1388. X        }
  1389. X        else if (tractee->type == Crusher && !dy &&
  1390. X          dx==(tractee->image == '<' ? 1 : -1) ) {
  1391. X        setimage(tractee, (tractee->velx *= -1) < 0 ? '>' : '<');
  1392. X        }
  1393. X        if (tractee->mass * 5 > obj->mass)
  1394. X        return(1);
  1395. X    }
  1396. X    }
  1397. X    return(0);
  1398. X}
  1399. !STUFFY!FUNK!
  1400. echo Extracting init.c
  1401. sed >init.c <<'!STUFFY!FUNK!' -e 's/X//'
  1402. X/* $Header: init.c,v 7.0.1.4 86/12/12 16:58:03 lwall Exp $ */
  1403. X
  1404. X/* $Log:    init.c,v $
  1405. X * Revision 7.0.1.4  86/12/12  16:58:03  lwall
  1406. X * Baseline for net release.
  1407. X * 
  1408. X * Revision 7.0.1.3  86/10/20  14:35:31  lwall
  1409. X * Picked some lint.
  1410. X * 
  1411. X * Revision 7.0.1.2  86/10/17  15:53:30  lwall
  1412. X * Added random walk star fields.
  1413. X * 
  1414. X * Revision 7.0.1.1  86/10/16  10:51:19  lwall
  1415. X * Added Damage.  Fixed random bugs.
  1416. X * 
  1417. X * Revision 7.0  86/10/08  15:12:10  lwall
  1418. X * Split into separate files.  Added amoebas and pirates.
  1419. X * 
  1420. X */
  1421. X
  1422. X#include "EXTERN.h"
  1423. X#include "warp.h"
  1424. X#include "bang.h"
  1425. X#include "object.h"
  1426. X#include "move.h"
  1427. X#include "play.h"
  1428. X#include "score.h"
  1429. X#include "term.h"
  1430. X#include "them.h"
  1431. X#include "us.h"
  1432. X#include "util.h"
  1433. X#include "weapon.h"
  1434. X#include "INTERN.h"
  1435. X#include "init.h"
  1436. X
  1437. Xvoid
  1438. Xinitialize()
  1439. X{
  1440. X    Reg1 int i;
  1441. X    Reg2 int x;
  1442. X    Reg3 int y;
  1443. X    Reg4 int dist;
  1444. X    Reg5 int ydist;
  1445. X    Reg6 int xdist;
  1446. X    long e;
  1447. X    int yoff, xoff, ypred, xpred;
  1448. X    Reg7 OBJECT *obj;
  1449. X    char ch;
  1450. X    FILE *mapfp = NULL;
  1451. X    bool tmptholspec;
  1452. X    int inhabjackpot;
  1453. X    long inhenergy;
  1454. X    int walksplit = 200;
  1455. X    static char *distname[] =
  1456. X    {" #"," -"," \\"," /",
  1457. X     " |"," *"," `"," '"};
  1458. X
  1459. X    cloaking = madgorns = FALSE;
  1460. X    deados = madfriends = 0;
  1461. X    curscore = possiblescore = 0L;
  1462. X    yamblast = xamblast = ambsize = 0;
  1463. X    if (smarts > 90)
  1464. X    massacre = TRUE;
  1465. X    scandist = (massacre?20:15);
  1466. X    antibase = (smarts>60?1:(smarts>40?2:(smarts>25?4:100)));
  1467. X    sm35 = (smarts>35?35:smarts);
  1468. X    sm45 = (smarts>45?45:smarts);
  1469. X    sm50 = (smarts>50?50:smarts);
  1470. X    sm55 = (smarts>55?55:smarts);
  1471. X    sm80 = (smarts>80?80:smarts);
  1472. X    sm95 = (smarts>95?95:smarts);
  1473. X    super = (smarts>50?smarts-50:0);
  1474. X    enemshields = 10 + super/2;        /* (scaled by 10) 1 @ 50 .. 3 @ 90 */
  1475. X    if (smarts>90)
  1476. X    enemshields += (smarts-90)*10;    /* lay it on thick: ~13 @ 99 */
  1477. X    entmax = (smarts>=75?5000:(smarts>=50?4000:(smarts>=40?3000:2000)));
  1478. X    basemax = (smarts>=75?20000:(smarts>=50?15000:(smarts>=40?12500:10000)));
  1479. X
  1480. X    clear();
  1481. X    while (root.next != &root) {
  1482. X    root.next = root.next->next;
  1483. X    free_object(root.next->prev);
  1484. X    }
  1485. X    root.prev = &root;
  1486. X    enemies = movers = NULL;
  1487. X    numos = numxes = 0;
  1488. X#if defined(vax) && XYSIZEx4 == 3680
  1489. X    asm("movc5 $0,_occupant,$0,$3680,_occupant");
  1490. X    asm("movc5 $0,_blast,$0,$3680,_blast");    /* 3680 = XYSIZEx4 */
  1491. X    asm("movc5 $0,_amb,$32,$920,_amb");
  1492. X#else
  1493. X    for (y=0;y<YSIZE;y++)
  1494. X    for (x=0;x<XSIZE;x++) {
  1495. X        occupant[y][x] = 0;
  1496. X        blast[y][x] = 0;
  1497. X        amb[y][x] = ' ';
  1498. X    }
  1499. X#endif
  1500. X    for (y=0; y<YSIZE; y++)
  1501. X    yblasted[y] = 0;
  1502. X    for (x=0; x<XSIZE; x++)
  1503. X    xblasted[x] = 0;
  1504. X    blasted = FALSE;
  1505. X    if (!starspec)
  1506. X    if (smarts < 15)
  1507. X        inumstars = 50 + rand_mod(50);
  1508. X    else if (smarts < 50 || smarts > 85)
  1509. X        inumstars = exdis(800) + rand_mod(100) + 1;
  1510. X    else /* too few stars makes 50..85 too hard */
  1511. X        inumstars = exdis(700) + rand_mod(150-super*2) + 50+super*2;
  1512. X    tmptholspec = (smarts > 15 && inumstars < 450 && ! rand_mod(90-sm80));
  1513. X    if (!klingspec) {
  1514. X    inumenemies = rand_mod((smarts+1)/2) + 1;
  1515. X    if (massacre || tmptholspec)
  1516. X        inumenemies += 10;
  1517. X    }
  1518. X    if (!friendspec)
  1519. X    inumfriends = rand_mod(smarts/8+1);
  1520. X    if (!piratespec)
  1521. X    inumpirates = rand_mod(inumfriends/2+1);
  1522. X    if (inumfriends+inumenemies+inumstars > YSIZE*XSIZE-20)
  1523. X    inumstars = YSIZE*XSIZE-20 - inumenemies - inumfriends;
  1524. X    if (inumstars < 0) {
  1525. X    inumfriends += inumstars;
  1526. X    inumstars = 0;
  1527. X    }
  1528. X    if (inumfriends < 0) {
  1529. X    inumenemies += inumfriends;
  1530. X    inumfriends = 0;
  1531. X    }
  1532. X    if (inumenemies < 0)
  1533. X    inumenemies = 0;
  1534. X    numstars = inumstars;
  1535. X    inuminhab = numinhab = 0;
  1536. X    inumroms = inumthols = inumgorns = 0;
  1537. X    numapollos = apolspec || massacre ? 1 :
  1538. X       ((!numstars || rand_mod(2) || smarts < 10) ? 0 : 1);
  1539. X    inumapollos = apolloflag = 0;
  1540. X    realapollo = NULL;
  1541. X    inumcrushes = numcrushes =
  1542. X    crushspec||massacre?1:(rand_mod(2000) < inumstars);
  1543. X    inumenemies += inumcrushes;
  1544. X    inumamoebas = numamoebas = (amoebaspec ? 1 :
  1545. X    !rand_mod(inumcrushes?3-massacre:8) );    /* < and & are fun together */
  1546. X    inumenemies += inumamoebas;
  1547. X    if (!rand_mod(40)) {
  1548. X    inhabjackpot = 32767;
  1549. X    inumfriends += rand_mod(10);
  1550. X    inumpirates += rand_mod(10);
  1551. X    }
  1552. X    else
  1553. X    inhabjackpot = inumpirates;
  1554. X    inhenergy = 30000-super*150;
  1555. X    if (!rand_mod(10))
  1556. X    inhenergy = 50000;
  1557. X    if (!rand_mod(4))
  1558. X    inhenergy += rand_mod(3500+super*150);
  1559. X    numfriends = inumfriends;
  1560. X    numpirates = inumpirates;
  1561. X    numenemies = inumenemies;
  1562. X    deadmudds = 0;
  1563. X
  1564. X    /* do stars */
  1565. X
  1566. Xstars_again:
  1567. X    if (prespec)
  1568. X    dist = 4;
  1569. X    else if (numstars > 750)
  1570. X    dist = 0;
  1571. X    else
  1572. X    dist = rand_mod(starspec||smarts<=5?3:5);
  1573. X    if (debugging) {
  1574. X    real_y = real_x = -100;
  1575. X    printf("\r\n");
  1576. X    }
  1577. X    switch (dist) {
  1578. X    case 0:                /* uniform random */
  1579. X    ydist = xdist = 0;
  1580. X    if (inumstars < 700 && !rand_mod(3-(inumstars<50))) {
  1581. X        ydist = xdist = 6;        /* well, maybe not so random */
  1582. X        y = rand_mod(YSIZE);
  1583. X        x = rand_mod(XSIZE);
  1584. X        if (rand_mod(2))
  1585. X        walksplit = inumstars/(exdis(40)+1);
  1586. X    }
  1587. X    if (debugging)
  1588. X        printf(" R\r\n");
  1589. X    break;
  1590. X    case 1: case 2:    /* clumped, maybe skewed, maybe superposed */
  1591. X    ydist = rand_mod(4);
  1592. X    xdist = rand_mod(2);
  1593. X    if (debugging)
  1594. X        printf("%s\r\n",distname[ydist+4*xdist]);
  1595. X    yoff = rand_mod(YSIZE);
  1596. X    xoff = rand_mod(XSIZE);
  1597. X    if (dist == 2)
  1598. X        dist = numstars/2 + exdis(numstars/2) - exdis(numstars/2);
  1599. X    else
  1600. X        dist = 0;
  1601. X    break;
  1602. X    case 3: case 4:            /* predefined or residual */
  1603. X      scenario_again:
  1604. X    if (debugging)
  1605. X        printf(" P\r\n");
  1606. X    dist = 0;
  1607. X    Sprintf(spbuf,"smap.%d",
  1608. X        (prescene>=0?prescene:rand_mod(MAPS)) );
  1609. X    if ((mapfp = fopen(spbuf,"r")) != NULL &&
  1610. X        fgets(spbuf,10,mapfp) != NULL ) {
  1611. X        inumstars = numstars = atoi(spbuf);
  1612. X        if (inumenemies+inumstars > YSIZE*XSIZE-20)
  1613. X        inumstars = numstars = YSIZE*XSIZE-20 - inumenemies;
  1614. X        ydist = rand_mod(2) + 4;    /* flip y axis? */
  1615. X        xdist = rand_mod(2) + 4;    /* flip x axis? */
  1616. X        yoff = rand_mod(YSIZE);    /* how much to shift y */
  1617. X        xoff = rand_mod(XSIZE);    /* how much to shift x */
  1618. X    }
  1619. X    else {
  1620. X        prespec = FALSE;
  1621. X        prescene = -1;
  1622. X        if (rand_mod(2))
  1623. X        goto scenario_again;
  1624. X        goto stars_again;
  1625. X    }
  1626. X    break;
  1627. X    }
  1628. X    for (i = 1; i <= numstars; i++) {
  1629. X    if (dist && i == dist) {    /* flip to another skewing? */
  1630. X        ydist = rand_mod(4);
  1631. X        xdist = rand_mod(2);
  1632. X        if (!rand_mod(4)) {
  1633. X        ydist = xdist = 6;
  1634. X        if (debugging)
  1635. X            printf("&\r\n");
  1636. X        }
  1637. X        else if (debugging)
  1638. X        printf("%s\r\n",distname[ydist+4*xdist]);
  1639. X        yoff = rand_mod(YSIZE);
  1640. X        xoff = rand_mod(XSIZE);
  1641. X        dist = 0;
  1642. X    }
  1643. X    do {                /* until an open spot found */
  1644. X        switch (xdist) {
  1645. X        case 0:
  1646. X        x = rand_mod(XSIZE);    /* pick from 0..39, uniform */
  1647. X        break;
  1648. X        case 1: case 2: case 3:
  1649. X#ifndef lint
  1650. X        x = (int)((((double)(myrand()-HALFRAND)) *
  1651. X                   ((double)(myrand()-HALFRAND))/RANDRAND)
  1652. X              * 20.0) + xoff;    /* pick from -20..20, clumped */
  1653. X#endif
  1654. X        break;
  1655. X        case 4:
  1656. X        if (fscanf(mapfp,"%d %d\n",&ypred,&xpred) == EOF)
  1657. X            ydist = xdist = 0;
  1658. X        x = xpred + xoff;
  1659. X        break;
  1660. X        case 5:
  1661. X        if (fscanf(mapfp,"%d %d\n",&ypred,&xpred) == EOF)
  1662. X            ydist = xdist = 0;
  1663. X        x = -xpred + xoff;
  1664. X        break;
  1665. X        case 6:
  1666. X        x += rand_mod(3) - 1;
  1667. X        break;
  1668. X        }
  1669. X        switch (ydist) {
  1670. X        case 0:
  1671. X        y = rand_mod(YSIZE);
  1672. X        break;
  1673. X        case 1:
  1674. X#ifndef lint
  1675. X        y = (int)((((double)(myrand()-HALFRAND)) *
  1676. X                   ((double)(myrand()-HALFRAND))/RANDRAND)
  1677. X              * 12.0) + yoff;    /* pick from -12..12, clumped */
  1678. X#endif
  1679. X        break;
  1680. X        case 2:
  1681. X#ifndef lint
  1682. X        y = (int)((((double)(myrand()-HALFRAND)) *
  1683. X                   ((double)(myrand()-HALFRAND))/RANDRAND)
  1684. X              * 12.0) + yoff + x*YSIZE/XSIZE;
  1685. X                         /* clumped & skewed */
  1686. X#endif
  1687. X        break;
  1688. X        case 3:
  1689. X#ifndef lint
  1690. X        y = (int)((((double)(myrand()-HALFRAND)) *
  1691. X                   ((double)(myrand()-HALFRAND))/RANDRAND)
  1692. X              * 12.0) + yoff - x*YSIZE/XSIZE;
  1693. X                        /* clumped & skewed */
  1694. X#endif
  1695. X        break;
  1696. X        case 4:
  1697. X        y = ypred + yoff;
  1698. X        break;
  1699. X        case 5:
  1700. X        y = -ypred + yoff;
  1701. X        break;
  1702. X        case 6:
  1703. X        y += rand_mod(3) - 1;
  1704. X#ifdef lint
  1705. X        walksplit = walksplit;
  1706. X#endif
  1707. X        if (!rand_mod(walksplit)) {
  1708. X            y = rand_mod(YSIZE);
  1709. X            x = rand_mod(XSIZE);
  1710. X        }
  1711. X        break;
  1712. X        }
  1713. X        while (x<0) x += XSIZE00;
  1714. X        while (y<0) y += YSIZE00;
  1715. X        x %= XSIZE;
  1716. X        y %= YSIZE;
  1717. X    } while (occupant[y][x]);
  1718. X    e = rand_mod(32768);
  1719. X    if (--inhabjackpot > 0 || e >= inhenergy) {
  1720. X        ch = '@';
  1721. X        if (inhabjackpot && e < 10000)
  1722. X        e += 10000;
  1723. X        inuminhab = ++numinhab;
  1724. X    }
  1725. X    else {
  1726. X        ch = '*';
  1727. X    }
  1728. X    obj = make_object(Star,ch,y,x,0,0,e+rand_mod(super*100+1),e/4,&root);
  1729. X    obj->flags |= STATIC;
  1730. X    }
  1731. X    if (inumstars > 30 && inhabjackpot <= 0 &&
  1732. X     !rand_mod(3 - (inumstars > 400) - (inhenergy > 32768)) ) {
  1733. X    int initx;
  1734. X    int inity;
  1735. X
  1736. X    x = initx = obj->posx;
  1737. X    y = inity = obj->posy;
  1738. X    while (rand_mod(2) && inuminhab < inumstars/2) {
  1739. X        for (i=rand_mod(smarts)*2+20; i; i--) {
  1740. X        if ((obj = occupant[y][x]) && obj->image == '*') {
  1741. X            setimage(obj,'@');
  1742. X            if (obj->energy < 10000)
  1743. X            obj->energy += 20000; /* the benefits of civilization */
  1744. X            inuminhab = ++numinhab;
  1745. X        }
  1746. X        if (i&15) {
  1747. X            y = (y + rand_mod(3) + YSIZE99) % YSIZE;
  1748. X            x = (x + rand_mod(3) + XSIZE99) % XSIZE;
  1749. X        }
  1750. X        else {            /* don't wander too far */
  1751. X            y = inity;
  1752. X            x = initx;
  1753. X        }
  1754. X        }
  1755. X        x = initx = rand_mod(XSIZE);
  1756. X        y = inity = rand_mod(YSIZE);
  1757. X    }
  1758. X    }
  1759. X    if (mapfp != NULL)
  1760. X    Fclose(mapfp);
  1761. X    if (numcrushes) {
  1762. X    do {
  1763. X        x = rand_mod(XSIZE);
  1764. X        y = rand_mod(YSIZE);
  1765. X    } while (occupant[y][x]);
  1766. X    movers = make_object(Crusher,'<',y,x,0,1,32767L,32768L,&root);
  1767. X    possiblescore += 10000;
  1768. X    }
  1769. X    ient = (numents != 0);
  1770. X    if (ient) {
  1771. X    do {
  1772. X        x = rand_mod(XSIZE);
  1773. X        y = rand_mod(YSIZE);
  1774. X    } while (occupant[y][x]);
  1775. X    e = entmax;
  1776. X    ent = make_object(Enterprise,'E',y,x,0,0,e,e/2,&root);
  1777. X    if (!movers)
  1778. X        movers = ent;
  1779. X    }
  1780. X    ibase = (numbases != 0);
  1781. X    if (ibase) {
  1782. X    e = 52-super;
  1783. X    do {
  1784. X        x = rand_mod(XSIZE);
  1785. X        y = rand_mod(YSIZE);
  1786. X    } while (occupant[y][x] || lookaround(y,x,Star) * 7 < e--);
  1787. X    e = basemax;
  1788. X    base = make_object(Base, 'B',y,x,0,0,e,e/4,&root);
  1789. X    if (!movers)
  1790. X        movers = base;
  1791. X    }
  1792. X    if (numamoebas) {
  1793. X    do {
  1794. X        x = rand_mod(XSIZE);
  1795. X        y = rand_mod(YSIZE);
  1796. X    } while (occupant[y][x]);
  1797. X    nuke = make_object(Enemy,'&',y,x,0,0,32767L,
  1798. X      (long)entmax+entmax+rand_mod(entmax),&root);
  1799. X    possiblescore += 10000;
  1800. X    amb[y][x] = '~';
  1801. X    if (rand_mod(2))
  1802. X        modify_amoeba(y,x,2,'~',(int)rand_mod(smarts<<1));/* just make blob */
  1803. X    else {
  1804. X        for (i=smarts/10+1; i; i--) {
  1805. X        nuke->strategy = rand_mod(256);        /* random direction */
  1806. X        modify_amoeba(y,x,2,'~',(int)rand_mod(5));
  1807. X        modify_amoeba(y,x,2,'~',(int)rand_mod(5));
  1808. X        modify_amoeba(y,x,2,'~',(int)rand_mod(5));
  1809. X        modify_amoeba(y,x,2,'~',(int)rand_mod(5));    /* extend pseudopod */
  1810. X        }
  1811. X    }
  1812. X    if (!enemies)
  1813. X        enemies = nuke;
  1814. X    if (!movers)
  1815. X        movers = nuke;
  1816. X    }
  1817. X    if (rand_mod(27-sm50/2) && !romspec && !gornspec)
  1818. X    dist = 27-sm50/2;
  1819. X    else
  1820. X    dist = rand_mod(4) + 1;
  1821. X    for (i = 1+inumcrushes+inumamoebas; i <= numenemies; i++) {
  1822. X    do {
  1823. X        x = rand_mod(XSIZE);
  1824. X        y = rand_mod(YSIZE);
  1825. X    } while (occupant[y][x]);
  1826. X    if (rand_mod(dist)) {
  1827. X        if (!tholspec && !tmptholspec && rand_mod((inumstars*3)/sm50+2))
  1828. X        ch = 'K';
  1829. X        else {
  1830. X        ch = 'T';
  1831. X        inumthols++;
  1832. X        }
  1833. X    }
  1834. X    else {
  1835. X        if (romspec == gornspec)
  1836. X        e = 50;
  1837. X        else if (gornspec)
  1838. X        e = 10;
  1839. X        else
  1840. X        e = 90;
  1841. X        if (rand_mod(100) < e) {
  1842. X        ch = 'R';
  1843. X        inumroms++;
  1844. X        }
  1845. X        else {
  1846. X        ch = 'G';
  1847. X        inumgorns++;
  1848. X        }
  1849. X    }
  1850. X    if (possiblescore > ENTBOUNDARY - 10000)
  1851. X        e = (ENTBOUNDARY - possiblescore) / 5;
  1852. X    else
  1853. X        e = 250 + (sm50-1) * 30 * 20 / numenemies+1;
  1854. X#ifndef lint
  1855. X    e = exdis((int)e) + e - exdis((int)e);
  1856. X    obj = make_object(Enemy,ch,y,x,0,0,
  1857. X        e + rand_mod(super*200+2) + 10000*massacre,e/4,&root);
  1858. X#endif
  1859. X    e /= 4;
  1860. X    switch (ch) {
  1861. X    case 'K':
  1862. X        possiblescore += e;
  1863. X        break;
  1864. X    case 'T':
  1865. X        possiblescore += e*3/2;
  1866. X        break;
  1867. X    case 'G':
  1868. X        possiblescore += e*2;
  1869. X        break;
  1870. X    case 'R':
  1871. X        possiblescore += e*3;
  1872. X        obj->flags |= CLOAKS;
  1873. X        break;
  1874. X    }
  1875. X    if (!enemies)
  1876. X        enemies = obj;
  1877. X    if (!movers)
  1878. X        movers = obj;
  1879. X    }
  1880. X    numgorns = inumgorns;
  1881. X    for (i=0; i<numfriends; i++) {
  1882. X    do {
  1883. X        x = rand_mod(XSIZE);
  1884. X        y = rand_mod(YSIZE);
  1885. X    } while (occupant[y][x]);
  1886. X    e = 250 + (sm50-1) * 30 * 20 / numenemies+1;
  1887. X#ifndef lint
  1888. X    e = exdis((int)e) + e - exdis((int)e);
  1889. X#endif
  1890. X    {
  1891. X        static char let[] = "QWYUISDHJLZVMFFFFFFFFF";
  1892. X
  1893. X        dist = rand_mod(20);
  1894. X        ch = let[dist];
  1895. X    }        /* grr, venix doesn't like indexing into string */
  1896. X    obj = make_object(Enemy,ch,y,x,0,0,
  1897. X        e + rand_mod(super*200+2),e/4,&root);
  1898. X    if (numpirates-- > 0) {
  1899. X        obj->flags |= PIRATE;
  1900. X        if (smarts >= 20 && !rand_mod(10-smarts/10))
  1901. X        obj->flags |= CLOAKS;
  1902. X    }
  1903. X    obj->flags |= FRIENDLY;
  1904. X    if (!enemies)
  1905. X        enemies = obj;
  1906. X    if (!movers)
  1907. X        movers = obj;
  1908. X    }
  1909. X    if (!movers)
  1910. X    movers = &root;
  1911. X    if (!enemies)
  1912. X    enemies = &root;
  1913. X    if (ent)
  1914. X    mvaddch(ent->posy+1, ent->posx*2, ent->image);
  1915. X    if (base)
  1916. X    mvaddch(base->posy+1, base->posx*2, base->image);
  1917. X    sleep(2);
  1918. X    {
  1919. X    Reg7 OBJECT *curobj;
  1920. X
  1921. X    for (curobj = root.next; curobj != &root; curobj = curobj->next) {
  1922. X        mvaddch(curobj->posy+1, curobj->posx*2, curobj->image);
  1923. X    }
  1924. X    }
  1925. X
  1926. X    for (i=0;i<2;i++) for (y=0;y<3;y++) for (x=0;x<3;x++) 
  1927. X    isatorp[i][y][x]=0;
  1928. X
  1929. X    whenok = 0;
  1930. X    timer = 0;
  1931. X    finish = 0;
  1932. X    bombed_out = FALSE;
  1933. X    if (ent)
  1934. X    entmode = status = 0;
  1935. X    else
  1936. X    if (base)
  1937. X        status = 2;
  1938. X    else
  1939. X        status = 3;
  1940. X
  1941. X    Sprintf(spbuf,
  1942. X    "%-4s E: %4d %2d B: %5d %3d Enemies: %-3d Stars: %-3d Stardate%5d.%1d %9ld",
  1943. X    "   ", 0, 0, 0, 0, 0, 0, smarts * 100, 0, 0L);
  1944. X    mvaddstr(0,0,spbuf);
  1945. X    oldeenergy = oldbenergy = oldcurscore =
  1946. X    oldstatus = oldetorp = oldbtorp = oldstrs = oldenemies = -1;
  1947. X                    /* force everything to fill in */
  1948. X    damage = olddamage = 0;
  1949. X    for (i=0; i<MAXDAMAGE; i++)
  1950. X    damflag[i] = 0;
  1951. X    btorp = 500;
  1952. X    etorp = 50;
  1953. X}
  1954. !STUFFY!FUNK!
  1955. echo ""
  1956. echo "End of kit 3 (of 7)"
  1957. cat /dev/null >kit3isdone
  1958. config=true
  1959. for iskit in 1 2 3 4 5 6 7; do
  1960.     if test -f kit${iskit}isdone; then
  1961.     echo "You have run kit ${iskit}."
  1962.     else
  1963.     echo "You still need to run kit ${iskit}."
  1964.     config=false
  1965.     fi
  1966. done
  1967. case $config in
  1968.     true)
  1969.     echo "You have run all your kits.  Please read README and then type Configure."
  1970.     chmod 755 Configure
  1971.     ;;
  1972. esac
  1973. : Someone might mail this, so...
  1974. exit
  1975.