home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part13 < prev    next >
Encoding:
Internet Message Format  |  1993-03-20  |  54.6 KB

  1. Path: uunet!news.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v17i025:  gbp - Galactic Bloodshed+, an empire-like war game, Part13/21
  5. Message-ID: <4553@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:31:59 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1986
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1704
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 25
  14. Archive-name: gbp/Part13
  15. Supersedes: gb3: Volume 10, Issue 1-14
  16. Environment: sockets, curses
  17.  
  18.  
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 13 (of 21)."
  27. # Contents:  server/files_shl.c user/analysis.c user/land.c
  28. #   utils/enrol.c
  29. # Wrapped by billr@saab on Fri Feb 12 09:14:27 1993
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'server/files_shl.c' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'server/files_shl.c'\"
  33. else
  34. echo shar: Extracting \"'server/files_shl.c'\" \(13655 characters\)
  35. sed "s/^X//" >'server/files_shl.c' <<'END_OF_FILE'
  36. X/*
  37. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  38. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  39. X * GB_copyright.h.
  40. X * 
  41. X * disk input/output routines & msc stuff all read routines lock the data they
  42. X * just accessed (the file is not closed).  write routines close and thus
  43. X * unlock that area.
  44. X * 
  45. X */
  46. X#include <strings.h>
  47. X#include <signal.h>
  48. X#include <errno.h>
  49. X#include <sys/types.h>
  50. X#include <sys/stat.h>
  51. X
  52. X#include "GB_copyright.h"
  53. X#define EXTERN extern
  54. X#define SHIP_CONSISTENCY
  55. X#include "vars.h"
  56. X#include "ships.h"
  57. X#include "races.h"
  58. X#include "power.h"
  59. X#include "buffers.h"
  60. X
  61. Xint             commoddata, pdata, racedata, sectdata, shdata, stdata;
  62. X
  63. Xextern int      errno;
  64. Xint             sys_nerr;
  65. Xextern char    *sys_errlist[];
  66. X
  67. Xvoid            close_file(int);
  68. Xvoid            open_data_files(void);
  69. Xvoid            close_data_files(void);
  70. Xvoid            openstardata(int *);
  71. Xvoid            openshdata(int *);
  72. Xvoid            opencommoddata(int *);
  73. Xvoid            openpdata(int *);
  74. Xvoid            opensectdata(int *);
  75. Xvoid            openracedata(int *);
  76. Xvoid            getsdata(struct stardata * S);
  77. X#ifdef DEBUG
  78. Xvoid            DEBUGgetrace(racetype **, int, char *, int);
  79. Xvoid            DEBUGgetstar(startype **, int, char *, int);
  80. Xvoid            DEBUGgetplanet(planettype **, int, int, char *, int);
  81. Xint             DEBUGgetship(shiptype **, int, char *, int);
  82. Xint             DEBUGgetcommod(commodtype **, int, char *, int);
  83. X#else
  84. Xvoid            getrace(racetype **, int);
  85. Xvoid            getstar(startype **, int);
  86. Xvoid            getplanet(planettype **, int, int);
  87. Xint             getship(shiptype **, int);
  88. Xint             getcommod(commodtype **, int);
  89. X#endif
  90. Xvoid            getsector(sectortype **, planettype *, int, int);
  91. Xvoid            getsmap(sectortype *, planettype *);
  92. Xint             getdeadship(void);
  93. Xint             getdeadcommod(void);
  94. Xvoid            putsdata(struct stardata *);
  95. Xvoid            putrace(racetype *);
  96. Xvoid            putstar(startype *, int);
  97. Xvoid            putplanet(planettype *, int, int);
  98. Xvoid            putsector(sectortype *, planettype *, int, int);
  99. Xvoid            putsmap(sectortype *, planettype *);
  100. Xvoid            putship(shiptype *);
  101. Xvoid            putcommod(commodtype *, int);
  102. Xint             Numraces(void);
  103. Xint             Numships(void);
  104. Xint             Numcommods(void);
  105. Xint             Newslength(int);
  106. Xvoid            clr_shipfree(void);
  107. Xvoid            clr_commodfree(void);
  108. Xvoid            makeshipdead(int);
  109. Xvoid            makecommoddead(int);
  110. Xvoid            Putpower(struct power[MAXPLAYERS]);
  111. Xvoid            Getpower(struct power[MAXPLAYERS]);
  112. Xvoid            Putblock(struct block[MAXPLAYERS]);
  113. Xvoid            Getblock(struct block[MAXPLAYERS]);
  114. X#include "proto.h"
  115. X
  116. Xvoid 
  117. Xclose_file(int fd)
  118. X{
  119. X    close(fd);
  120. X}
  121. X
  122. Xvoid 
  123. Xopen_data_files(void)
  124. X{
  125. X    opencommoddata(&commoddata);
  126. X    openpdata(&pdata);
  127. X    openracedata(&racedata);
  128. X    opensectdata(§data);
  129. X    openshdata(&shdata);
  130. X    openstardata(&stdata);
  131. X}
  132. X
  133. Xvoid 
  134. Xclose_data_files(void)
  135. X{
  136. X    close_file(commoddata);
  137. X    close_file(pdata);
  138. X    close_file(racedata);
  139. X    close_file(sectdata);
  140. X    close_file(shdata);
  141. X    close_file(stdata);
  142. X}
  143. X
  144. Xvoid 
  145. Xopenstardata(int *fd)
  146. X{
  147. X    /* printf(" openstardata\n"); */
  148. X    if ((*fd = open(STARDATAFL, O_RDWR, 0777)) < 0) {
  149. X        perror("openstardata");
  150. X        printf("unable to open %s\n", STARDATAFL);
  151. X        exit(-1);
  152. X    }
  153. X}
  154. X
  155. Xvoid 
  156. Xopenshdata(int *fd)
  157. X{
  158. X    if ((*fd = open(SHIPDATAFL, O_RDWR, 0777)) < 0) {
  159. X        perror("openshdata");
  160. X        printf("unable to open %s\n", SHIPDATAFL);
  161. X        exit(-1);
  162. X    }
  163. X}
  164. X
  165. Xvoid 
  166. Xopencommoddata(int *fd)
  167. X{
  168. X    if ((*fd = open(COMMODDATAFL, O_RDWR, 0777)) < 0) {
  169. X        perror("opencommoddata");
  170. X        printf("unable to open %s\n", COMMODDATAFL);
  171. X        exit(-1);
  172. X    }
  173. X}
  174. X
  175. Xvoid 
  176. Xopenpdata(int *fd)
  177. X{
  178. X    if ((*fd = open(PLANETDATAFL, O_RDWR, 0777)) < 0) {
  179. X        perror("openpdata");
  180. X        printf("unable to open %s\n", PLANETDATAFL);
  181. X        exit(-1);
  182. X    }
  183. X}
  184. X
  185. Xvoid 
  186. Xopensectdata(int *fd)
  187. X{
  188. X    if ((*fd = open(SECTORDATAFL, O_RDWR, 0777)) < 0) {
  189. X        perror("opensectdata");
  190. X        printf("unable to open %s\n", SECTORDATAFL);
  191. X        exit(-1);
  192. X    }
  193. X}
  194. X
  195. Xvoid 
  196. Xopenracedata(int *fd)
  197. X{
  198. X    if ((*fd = open(RACEDATAFL, O_RDWR, 0777)) < 0) {
  199. X        perror("openrdata");
  200. X        printf("unable to open %s\n", RACEDATAFL);
  201. X        exit(-1);
  202. X    }
  203. X}
  204. X
  205. Xvoid 
  206. Xgetsdata(struct stardata * S)
  207. X{
  208. X    Fileread(stdata, (char *) S, sizeof(struct stardata), 0);
  209. X}
  210. X
  211. X
  212. X#ifdef DEBUG
  213. Xvoid 
  214. XDEBUGgetrace(racetype ** r, int rnum, char *fname, int lineno)
  215. X#else
  216. Xvoid 
  217. Xgetrace(racetype ** r, int rnum)
  218. X#endif
  219. X{
  220. X#ifdef DEBUG
  221. X    *r = (racetype *) DEBUGmalloc(sizeof(racetype), fname, lineno);
  222. X#else
  223. X    *r = (racetype *) malloc(sizeof(racetype));
  224. X#endif
  225. X    Fileread(racedata, (char *) *r, sizeof(racetype), (rnum - 1) * sizeof(racetype));
  226. X}
  227. X
  228. X#ifdef DEBUG
  229. Xvoid 
  230. XDEBUGgetstar(startype ** s, int star, char *fname, int lineno)
  231. X#else
  232. Xvoid 
  233. Xgetstar(startype ** s, int star)
  234. X#endif
  235. X{
  236. X    if (s >= &Stars[0] && s < &Stars[NUMSTARS - 1]);    /* Do nothing */
  237. X    else {
  238. X#ifdef DEBUG
  239. X        *s = (startype *) DEBUGmalloc(sizeof(startype), fname, lineno);
  240. X#else
  241. X        *s = (startype *) malloc(sizeof(startype));
  242. X#endif
  243. X    }
  244. X    Fileread(stdata, (char *) *s, sizeof(startype), (int) (sizeof(Sdata) + star * sizeof(startype)));
  245. X}
  246. X
  247. X
  248. X#ifdef DEBUG
  249. Xvoid 
  250. XDEBUGgetplanet(planettype ** p, int star, int pnum, char *fname, int lineno)
  251. X#else
  252. Xvoid 
  253. Xgetplanet(planettype ** p, int star, int pnum)
  254. X#endif
  255. X{
  256. X    int             filepos;
  257. X    if (p >= &planets[0][0] && p < &planets[NUMSTARS - 1][MAXPLANETS - 1]);    /* Do nothing */
  258. X    else {            /* Allocate space for others */
  259. X#ifdef DEBUG
  260. X        *p = (planettype *) DEBUGmalloc(sizeof(planettype), fname, lineno);
  261. X#else
  262. X        *p = (planettype *) malloc(sizeof(planettype));
  263. X#endif
  264. X    }
  265. X    filepos = Stars[star]->planetpos[pnum];
  266. X    Fileread(pdata, (char *) *p, sizeof(planettype), filepos);
  267. X}
  268. X
  269. X
  270. Xvoid 
  271. Xgetsector(sectortype ** s, planettype * p, int x, int y)
  272. X{
  273. X    int             filepos;
  274. X    filepos = p->sectormappos + (y * p->Maxx + x) * sizeof(sectortype);
  275. X    *s = (sectortype *) malloc(sizeof(sectortype));
  276. X    Fileread(sectdata, (char *) *s, sizeof(sectortype), filepos);
  277. X}
  278. X
  279. Xvoid 
  280. Xgetsmap(sectortype * map, planettype * p)
  281. X{
  282. X    Fileread(sectdata, (char *) map, p->Maxx * p->Maxy * sizeof(sectortype),
  283. X         p->sectormappos);
  284. X}
  285. X
  286. X
  287. X#ifdef DEBUG
  288. Xint 
  289. XDEBUGgetship(shiptype ** s, int shipnum, char *fname, int lineno)
  290. X#else
  291. Xint 
  292. Xgetship(shiptype ** s, int shipnum)
  293. X#endif
  294. X{
  295. X    struct stat     buffer;
  296. X
  297. X    if (shipnum <= 0)
  298. X        return 0;
  299. X
  300. X    fstat(shdata, &buffer);
  301. X    if (buffer.st_size / sizeof(shiptype) < shipnum)
  302. X        return 0;
  303. X    else {
  304. X
  305. X#ifdef DEBUG
  306. X        if ((*s = (shiptype *) DEBUGmalloc(sizeof(shiptype), fname, lineno)) == NULL)
  307. X#else
  308. X        if ((*s = (shiptype *) malloc(sizeof(shiptype))) == NULL)
  309. X#endif
  310. X            printf("getship:Malloc() error \n"), exit(0);
  311. X
  312. X        Fileread(shdata, (char *) *s, sizeof(shiptype), (shipnum - 1) * sizeof(shiptype));
  313. X        return 1;
  314. X    }
  315. X}
  316. X
  317. X#ifdef DEBUG
  318. Xint 
  319. XDEBUGgetcommod(commodtype ** c, int commodnum, char *fname, int lineno)
  320. X#else
  321. Xint 
  322. Xgetcommod(commodtype ** c, int commodnum)
  323. X#endif
  324. X{
  325. X    struct stat     buffer;
  326. X
  327. X    if (commodnum <= 0)
  328. X        return 0;
  329. X
  330. X    fstat(commoddata, &buffer);
  331. X    if (buffer.st_size / sizeof(commodtype) < commodnum)
  332. X        return 0;
  333. X    else {
  334. X
  335. X#ifdef DEBUG
  336. X        if ((*c = (commodtype *) DEBUGmalloc(sizeof(commodtype), fname, lineno)) == NULL)
  337. X#else
  338. X        if ((*c = (commodtype *) malloc(sizeof(commodtype))) == NULL)
  339. X#endif
  340. X            printf("getcommod:Malloc() error \n"), exit(0);
  341. X
  342. X        Fileread(commoddata, (char *) *c, sizeof(commodtype), (commodnum - 1) * sizeof(commodtype));
  343. X        return 1;
  344. X    }
  345. X}
  346. X
  347. X
  348. X/*
  349. X * gets the ship # listed in the top of the file SHIPFREEDATAFL. this * might
  350. X * have no other uses besides build().
  351. X */
  352. Xint 
  353. Xgetdeadship(void)
  354. X{
  355. X    struct stat     buffer;
  356. X    short           shnum;
  357. X    int             fd;
  358. X    int             abort;
  359. X
  360. X    if ((fd = open(SHIPFREEDATAFL, O_RDWR, 0777)) < 0) {
  361. X        perror("getdeadship");
  362. X        printf("unable to open %s\n", SHIPFREEDATAFL);
  363. X        exit(-1);
  364. X    }
  365. X    abort = 1;
  366. X    fstat(fd, &buffer);
  367. X
  368. X    if (buffer.st_size && (abort == 1)) {
  369. X        /* put topmost entry in fpos */
  370. X        Fileread(fd, (char *) &shnum, sizeof(short), buffer.st_size - sizeof(short));
  371. X        /* erase that entry, since it will now be filled */
  372. X        ftruncate(fd, (long) (buffer.st_size - sizeof(short)));
  373. X        close_file(fd);
  374. X        return (int) shnum;
  375. X    } else
  376. X        close_file(fd);
  377. X    return -1;
  378. X}
  379. X
  380. Xint 
  381. Xgetdeadcommod(void)
  382. X{
  383. X    struct stat     buffer;
  384. X    short           commodnum;
  385. X    int             fd;
  386. X    int             abort;
  387. X
  388. X    if ((fd = open(COMMODFREEDATAFL, O_RDWR, 0777)) < 0) {
  389. X        perror("getdeadcommod");
  390. X        printf("unable to open %s\n", COMMODFREEDATAFL);
  391. X        exit(-1);
  392. X    }
  393. X    abort = 1;
  394. X    fstat(fd, &buffer);
  395. X
  396. X    if (buffer.st_size && (abort == 1)) {
  397. X        /* put topmost entry in fpos */
  398. X        Fileread(fd, (char *) &commodnum, sizeof(short), buffer.st_size - sizeof(short));
  399. X        /* erase that entry, since it will now be filled */
  400. X        ftruncate(fd, (long) (buffer.st_size - sizeof(short)));
  401. X        close_file(fd);
  402. X        return (int) commodnum;
  403. X    } else
  404. X        close_file(fd);
  405. X    return -1;
  406. X}
  407. X
  408. X
  409. Xvoid 
  410. Xputsdata(struct stardata * S)
  411. X{
  412. X    Filewrite(stdata, (char *) S, sizeof(struct stardata), 0);
  413. X}
  414. X
  415. X
  416. Xvoid 
  417. Xputrace(racetype * r)
  418. X{
  419. X    Filewrite(racedata, (char *) r, sizeof(racetype), (r->Playernum - 1) * sizeof(racetype));
  420. X}
  421. X
  422. Xvoid 
  423. Xputstar(startype * s, int snum)
  424. X{
  425. X    Filewrite(stdata, (char *) s, sizeof(startype), (int) (sizeof(Sdata) + snum * sizeof(startype)));
  426. X}
  427. X
  428. Xvoid 
  429. Xputplanet(planettype * p, int star, int pnum)
  430. X{
  431. X    int             filepos;
  432. X    filepos = Stars[star]->planetpos[pnum];
  433. X    Filewrite(pdata, (char *) p, sizeof(planettype), filepos);
  434. X}
  435. X
  436. Xvoid 
  437. Xputsector(sectortype * s, planettype * p, int x, int y)
  438. X{
  439. X    int             filepos;
  440. X    filepos = p->sectormappos + (y * p->Maxx + x) * sizeof(sectortype);
  441. X    Filewrite(sectdata, (char *) s, sizeof(sectortype), filepos);
  442. X}
  443. X
  444. Xvoid 
  445. Xputsmap(sectortype * map, planettype * p)
  446. X{
  447. X    Filewrite(sectdata, (char *) map,
  448. X          p->Maxx * p->Maxy * sizeof(sectortype), p->sectormappos);
  449. X}
  450. X
  451. Xvoid 
  452. Xputship(shiptype * s)
  453. X{
  454. X    Filewrite(shdata, (char *) s, sizeof(shiptype), (s->number - 1) * sizeof(shiptype));
  455. X}
  456. X
  457. Xvoid 
  458. Xputcommod(commodtype * c, int commodnum)
  459. X{
  460. X    Filewrite(commoddata, (char *) c, sizeof(commodtype), (commodnum - 1) * sizeof(commodtype));
  461. X}
  462. X
  463. Xint 
  464. XNumraces(void)
  465. X{
  466. X    struct stat     buffer;
  467. X
  468. X    fstat(racedata, &buffer);
  469. X    return ((int) (buffer.st_size / sizeof(racetype)));
  470. X}
  471. X
  472. Xint 
  473. XNumships(void)
  474. X{                /* return number of ships */
  475. X    struct stat     buffer;
  476. X
  477. X    fstat(shdata, &buffer);
  478. X    return ((int) (buffer.st_size / sizeof(shiptype)));
  479. X}
  480. X
  481. Xint 
  482. XNumcommods(void)
  483. X{
  484. X    struct stat     buffer;
  485. X
  486. X    fstat(commoddata, &buffer);
  487. X    return ((int) (buffer.st_size / sizeof(commodtype)));
  488. X}
  489. X
  490. Xint 
  491. XNewslength(int type)
  492. X{
  493. X    struct stat     buffer;
  494. X    FILE           *fp;
  495. X
  496. X    switch (type) {
  497. X    case DECLARATION:
  498. X        if ((fp = fopen(DECLARATIONFL, "r")) == NULL)
  499. X            fp = fopen(DECLARATIONFL, "w+");
  500. X        break;
  501. X
  502. X    case TRANSFER:
  503. X        if ((fp = fopen(TRANSFERFL, "r")) == NULL)
  504. X            fp = fopen(TRANSFERFL, "w+");
  505. X        break;
  506. X    case COMBAT:
  507. X        if ((fp = fopen(COMBATFL, "r")) == NULL)
  508. X            fp = fopen(COMBATFL, "w+");
  509. X        break;
  510. X    case ANNOUNCE:
  511. X        if ((fp = fopen(ANNOUNCEFL, "r")) == NULL)
  512. X            fp = fopen(ANNOUNCEFL, "w+");
  513. X        break;
  514. X    default:
  515. X        return 0;
  516. X    }
  517. X    fstat(fileno(fp), &buffer);
  518. X    fclose(fp);
  519. X    return ((int) buffer.st_size);
  520. X}
  521. X
  522. X/* delete contents of dead ship file */
  523. Xvoid 
  524. Xclr_shipfree(void)
  525. X{
  526. X    fclose(fopen(SHIPFREEDATAFL, "w+"));
  527. X}
  528. X
  529. Xvoid 
  530. Xclr_commodfree(void)
  531. X{
  532. X    fclose(fopen(COMMODFREEDATAFL, "w+"));
  533. X}
  534. X
  535. X/*
  536. X * * writes the ship to the dead ship file at its end.
  537. X */
  538. Xvoid 
  539. Xmakeshipdead(int shipnum)
  540. X{
  541. X    int             fd;
  542. X    unsigned short  shipno;
  543. X    struct stat     buffer;
  544. X
  545. X    shipno = shipnum;    /* conv to u_short */
  546. X
  547. X    if (shipno == 0)
  548. X        return;
  549. X
  550. X    if ((fd = open(SHIPFREEDATAFL, O_WRONLY, 0777)) < 0) {
  551. X        printf("fd = %d \n", fd);
  552. X        printf("errno = %d \n", errno);
  553. X        perror("openshfdata");
  554. X        printf("unable to open %s\n", SHIPFREEDATAFL);
  555. X        exit(-1);
  556. X    }
  557. X    /* write the ship # at the very end of SHIPFREEDATAFL */
  558. X    fstat(fd, &buffer);
  559. X
  560. X    Filewrite(fd, (char *) &shipno, sizeof(shipno), buffer.st_size);
  561. X    close_file(fd);
  562. X}
  563. X
  564. Xvoid 
  565. Xmakecommoddead(int commodnum)
  566. X{
  567. X    int             fd;
  568. X    unsigned short  commodno;
  569. X    struct stat     buffer;
  570. X
  571. X    commodno = commodnum;    /* conv to u_short */
  572. X
  573. X    if (commodno == 0)
  574. X        return;
  575. X
  576. X    if ((fd = open(COMMODFREEDATAFL, O_WRONLY, 0777)) < 0) {
  577. X        printf("fd = %d \n", fd);
  578. X        printf("errno = %d \n", errno);
  579. X        perror("opencommodfdata");
  580. X        printf("unable to open %s\n", COMMODFREEDATAFL);
  581. X        exit(-1);
  582. X    }
  583. X    /* write the commod # at the very end of COMMODFREEDATAFL */
  584. X    fstat(fd, &buffer);
  585. X
  586. X    Filewrite(fd, (char *) &commodno, sizeof(commodno), buffer.st_size);
  587. X    close_file(fd);
  588. X}
  589. X
  590. Xvoid 
  591. XPutpower(struct power p[MAXPLAYERS])
  592. X{
  593. X    int             power_fd;
  594. X
  595. X    if ((power_fd = open(POWFL, O_RDWR, 0777)) < 0) {
  596. X        perror("open power data");
  597. X        printf("unable to open %s\n", POWFL);
  598. X        return;
  599. X    }
  600. X    write(power_fd, (char *) p, sizeof(*p) * MAXPLAYERS);
  601. X    close_file(power_fd);
  602. X}
  603. X
  604. Xvoid 
  605. XGetpower(struct power p[MAXPLAYERS])
  606. X{
  607. X    int             power_fd;
  608. X
  609. X    if ((power_fd = open(POWFL, O_RDONLY, 0777)) < 0) {
  610. X        perror("open power data");
  611. X        printf("unable to open %s\n", POWFL);
  612. X        return;
  613. X    } else {
  614. X        read(power_fd, (char *) p, sizeof(*p) * MAXPLAYERS);
  615. X        close_file(power_fd);
  616. X    }
  617. X}
  618. X
  619. Xvoid 
  620. XPutblock(struct block b[MAXPLAYERS])
  621. X{
  622. X    int             block_fd;
  623. X
  624. X    if ((block_fd = open(BLOCKDATAFL, O_RDWR, 0777)) < 0) {
  625. X        perror("open block data");
  626. X        printf("unable to open %s\n", BLOCKDATAFL);
  627. X        return;
  628. X    }
  629. X    write(block_fd, (char *) b, sizeof(*b) * MAXPLAYERS);
  630. X    close_file(block_fd);
  631. X}
  632. X
  633. Xvoid 
  634. XGetblock(struct block b[MAXPLAYERS])
  635. X{
  636. X    int             block_fd;
  637. X
  638. X    if ((block_fd = open(BLOCKDATAFL, O_RDONLY, 0777)) < 0) {
  639. X        perror("open block data");
  640. X        printf("unable to open %s\n", BLOCKDATAFL);
  641. X        return;
  642. X    } else {
  643. X        read(block_fd, (char *) b, sizeof(*b) * MAXPLAYERS);
  644. X        close_file(block_fd);
  645. X    }
  646. X}
  647. END_OF_FILE
  648. if test 13655 -ne `wc -c <'server/files_shl.c'`; then
  649.     echo shar: \"'server/files_shl.c'\" unpacked with wrong size!
  650. fi
  651. # end of 'server/files_shl.c'
  652. fi
  653. if test -f 'user/analysis.c' -a "${1}" != "-c" ; then 
  654.   echo shar: Will not clobber existing file \"'user/analysis.c'\"
  655. else
  656. echo shar: Extracting \"'user/analysis.c'\" \(10337 characters\)
  657. sed "s/^X//" >'user/analysis.c' <<'END_OF_FILE'
  658. X /* Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  659. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  660. X * GB_copyright.h. 
  661. X *
  662. X * anal.c 
  663. X */
  664. X
  665. X#include "GB_copyright.h"
  666. X#define EXTERN extern
  667. X#include "vars.h"
  668. X#include "ships.h"
  669. X#include "races.h"
  670. X#include "power.h"
  671. X#include "buffers.h"
  672. X#include <string.h>
  673. X#include <ctype.h>
  674. X
  675. Xextern char    *Desnames[];
  676. Xextern char    Dessymbols[];
  677. X
  678. X#define CARE 5
  679. Xstruct anal_sect {
  680. X    int             x, y;
  681. X    int             value;
  682. X    int        des;
  683. X};
  684. X
  685. Xvoid analysis(int, int, int);
  686. Xvoid do_analysis(int, int, int, int, int, int, int);
  687. Xvoid Insert(int, struct anal_sect [], int, int, int, int);
  688. Xvoid PrintTop(int, int, struct anal_sect [], char *);
  689. X#include "proto.h"
  690. X
  691. X
  692. Xvoid analysis(int Playernum, int Governor, int APcount)
  693. X{
  694. X    int pnum;
  695. X    int sector_type = -1;       /* -1 does analysis on all types */
  696. X    placetype       where;      /* otherwise on specific type */
  697. X    int             i;
  698. X    int             do_player = -1;
  699. X    char           *p;
  700. X    int             mode = 1;    /* does top five. 0 does low five */
  701. X
  702. X    i = 1;
  703. X    do {
  704. X     where.level = Dir[Playernum - 1][Governor].level;
  705. X     where.snum = Dir[Playernum - 1][Governor].snum;
  706. X     where.pnum = Dir[Playernum - 1][Governor].pnum;
  707. X    
  708. X          p = args[1];
  709. X            if (*p == '-')     /*  Must use 'd' to do an analysis on */
  710. X            {                  /*  desert sectors to avoid confusion */
  711. X               p++;            /*  with the '-' for the mode type    */
  712. X               i++;
  713. X               mode = 0;
  714. X            }
  715. X            switch (*p) {
  716. X               case CHAR_SEA   : sector_type = SEA;   break;
  717. X               case CHAR_LAND  : sector_type = LAND;  break; 
  718. X               case CHAR_MOUNT : sector_type = MOUNT; break;
  719. X               case CHAR_GAS   : sector_type = GAS;   break;
  720. X               case CHAR_ICE   : sector_type = ICE;   break;
  721. X               case CHAR_FOREST: sector_type = FOREST;break;
  722. X               case 'd'        : sector_type = DESERT;break;
  723. X               case CHAR_PLATED: sector_type = PLATED;break;
  724. X               case CHAR_WASTED: sector_type = WASTED;break;
  725. X            }
  726. X            if (sector_type != -1 && mode == 1)
  727. X            {
  728. X               i++;
  729. X            }
  730. X
  731. X            p = args[i];
  732. X        if (isdigit(*p)) {
  733. X        do_player = atoi(p);
  734. X        if (do_player > Num_races) {
  735. X            notify(Playernum, Governor, "No such player #.\n");
  736. X            return;
  737. X        }
  738. X        where.level = Dir[Playernum - 1][Governor].level;
  739. X        where.snum = Dir[Playernum - 1][Governor].snum;
  740. X        where.pnum = Dir[Playernum - 1][Governor].pnum;
  741. X                i++;
  742. X        } 
  743. X            p = args[i];
  744. X            if (i<argn && (isalpha (*p) || *p == '/'))
  745. X            {
  746. X        where = Getplace(Playernum, Governor, args[i], 0);
  747. X        if (where.err)
  748. X            continue;
  749. X        }
  750. X
  751. X    switch (where.level) {
  752. X      case LEVEL_UNIV:
  753. X        notify(Playernum, Governor, "You can only analyze planets.\n");
  754. X        break;
  755. X      case LEVEL_PLAN:
  756. X        do_analysis(Playernum, Governor, do_player, mode, sector_type,
  757. X            (int)where.snum, (int)where.pnum);
  758. X        break;
  759. X      case LEVEL_STAR:
  760. X        for (pnum = 0; pnum < Stars[where.snum]->numplanets; pnum++)
  761. X        do_analysis(Playernum, Governor, do_player, mode, sector_type,
  762. X                (int)where.snum, pnum);
  763. X        break;
  764. X    }
  765. X    } while (0);
  766. X    return;
  767. X}
  768. X
  769. X
  770. Xvoid do_analysis(int Playernum, int Governor, int ThisPlayer, int mode,
  771. X         int sector_type, int Starnum, int Planetnum)
  772. X{
  773. X  planettype     *planet;
  774. X  sectortype     *sect;
  775. X  racetype       *Race;
  776. X  int             x, y;
  777. X  int             p;
  778. X  int             i;
  779. X  double          compat;
  780. X  struct anal_sect Res[CARE], Eff[CARE], Frt[CARE], Mob[CARE];
  781. X  struct anal_sect Troops[CARE], Popn[CARE], mPopn[CARE];
  782. X  int             TotalCrys, PlayCrys[MAXPLAYERS + 1];
  783. X  int             TotalTroops, PlayTroops[MAXPLAYERS + 1];
  784. X  int             TotalPopn, PlayPopn[MAXPLAYERS + 1];
  785. X  int             TotalMob, PlayMob[MAXPLAYERS + 1];
  786. X  int             TotalEff, PlayEff[MAXPLAYERS + 1];
  787. X  int             TotalRes, PlayRes[MAXPLAYERS + 1];
  788. X  int             TotalSect, PlaySect[MAXPLAYERS + 1][WASTED + 1];
  789. X  int             PlayTSect[MAXPLAYERS + 1];
  790. X  int             TotalWasted, WastedSect[MAXPLAYERS + 1];
  791. X  int             Sect[WASTED + 1];
  792. X  static char     SectTypes[] = {CHAR_SEA, CHAR_LAND, CHAR_MOUNT,
  793. X                     CHAR_GAS, CHAR_ICE, CHAR_FOREST,
  794. X                     CHAR_DESERT, CHAR_PLATED, CHAR_WASTED};
  795. X
  796. X  for (i = 0; i < CARE; i++)
  797. X      Res[i].value = Eff[i].value = Frt[i].value = Mob[i].value =
  798. X      Troops[i].value = Popn[i].value = mPopn[i].value = -1;
  799. X
  800. X  TotalWasted = TotalCrys = TotalPopn = TotalMob =
  801. X      TotalTroops = TotalEff = TotalRes = TotalSect = 0;
  802. X  for (p = 0; p <= Num_races; p++) {
  803. X      PlayTroops[p] = PlayPopn[p] = PlayMob[p] = PlayEff[p] = PlayCrys[p] =
  804. X      PlayRes[p] = PlayTSect[p] = 0;
  805. X      WastedSect[p] = 0;
  806. X      for (i = 0; i <= WASTED; i++)
  807. X      PlaySect[p][i] = 0;
  808. X  }
  809. X
  810. X  for (i = 0; i <= WASTED; i++)
  811. X      Sect[i] = 0;
  812. X
  813. X  Race = races[Playernum-1];
  814. X  getplanet(&planet, Starnum, Planetnum);
  815. X
  816. X  if (!planet->info[Playernum - 1].explored) {
  817. X      free(planet);
  818. X      return;
  819. X  }
  820. X  getsmap(Smap, planet);
  821. X
  822. X  compat = compatibility(planet, Race);
  823. X
  824. X  TotalSect = planet->Maxx * planet->Maxy;
  825. X  for (x = planet->Maxx - 1; x >= 0; x--) {
  826. X      for (y = planet->Maxy - 1; y >= 0; y--) {
  827. X      sect = &Sector(*planet, x, y);
  828. X      p = sect->owner;
  829. X
  830. X      PlayEff[p] += sect->eff;
  831. X      PlayMob[p] += sect->mobilization;
  832. X      PlayRes[p] += sect->resource;
  833. X      PlayPopn[p] += sect->popn;
  834. X      PlayTroops[p] += sect->troops;
  835. X      PlaySect[p][sect->condition]++;
  836. X      PlayTSect[p]++;
  837. X      TotalEff += sect->eff;
  838. X      TotalMob += sect->mobilization;
  839. X      TotalRes += sect->resource;
  840. X      TotalPopn += sect->popn;
  841. X      TotalTroops += sect->troops;
  842. X      Sect[sect->condition]++;
  843. X
  844. X          if (sect->condition==WASTED) {
  845. X             WastedSect[p]++;
  846. X             TotalWasted++;
  847. X          }
  848. X      if (sect->crystals && Race->tech >= TECH_CRYSTAL) {
  849. X         PlayCrys[p]++;
  850. X         TotalCrys++;
  851. X      }
  852. X
  853. X          if (sector_type == -1 || sector_type == sect->condition)
  854. X          {
  855. X         if (ThisPlayer < 0 || ThisPlayer == p) 
  856. X             {
  857. X            Insert(mode, Res, x, y, sect->condition, (int)sect->resource);
  858. X            Insert(mode, Eff, x, y, sect->condition, (int)sect->eff);
  859. X            Insert(mode, Mob, x, y, sect->condition,
  860. X             (int)sect->mobilization);
  861. X            Insert(mode, Frt, x, y, sect->condition, (int)sect->fert);
  862. X            Insert(mode, Popn, x, y, sect->condition, (int)sect->popn);
  863. X            Insert(mode, Troops, x, y, sect->condition, (int)sect->troops);
  864. X            Insert(mode, mPopn, x, y, sect->condition, 
  865. X             maxsupport(Race, sect, compat,
  866. X                (int)planet->conditions[TOXIC]));
  867. X             }
  868. X      }
  869. X      }
  870. X  }
  871. X
  872. X  sprintf(buf, "\nAnalysis of /%s/%s:\n", Stars[Starnum]->name,
  873. X      Stars[Starnum]->pnames[Planetnum]);
  874. X  notify(Playernum, Governor, buf);
  875. X  sprintf(buf, "%s %d",
  876. X      (mode ? "Highest" : "Lowest"), CARE, ThisPlayer);
  877. X  switch (sector_type) 
  878. X  {
  879. X     case -1     : sprintf (buf, "%s of all", buf); break;
  880. X     case SEA    : sprintf (buf, "%s Ocean", buf); break;
  881. X     case LAND   : sprintf (buf, "%s Land", buf); break;
  882. X     case MOUNT  : sprintf (buf, "%s Mountain", buf); break;
  883. X     case GAS    : sprintf (buf, "%s Gas", buf); break;
  884. X     case ICE    : sprintf (buf, "%s Ice", buf); break;
  885. X     case FOREST : sprintf (buf, "%s Forest", buf); break;
  886. X     case DESERT : sprintf (buf, "%s Desert", buf); break;
  887. X     case PLATED : sprintf (buf, "%s Plated", buf); break;
  888. X     case WASTED : sprintf (buf, "%s Wasted", buf); break;
  889. X  }
  890. X  notify (Playernum, Governor, buf);
  891. X  if (ThisPlayer < 0)
  892. X     sprintf (buf, " sectors.\n");
  893. X  else if (ThisPlayer == 0)
  894. X     sprintf (buf, " sectors that are unoccupied.\n");
  895. X  else
  896. X     sprintf (buf, " sectors owned by %d.\n", ThisPlayer);
  897. X  notify(Playernum, Governor, buf);
  898. X
  899. X  PrintTop(Playernum, Governor, Troops, "Troops");
  900. X  PrintTop(Playernum, Governor, Res, "Res");
  901. X  PrintTop(Playernum, Governor, Eff, "Eff");
  902. X  PrintTop(Playernum, Governor, Frt, "Frt");
  903. X  PrintTop(Playernum, Governor, Mob, "Mob");
  904. X  PrintTop(Playernum, Governor, Popn, "Popn");
  905. X  PrintTop(Playernum, Governor, mPopn, "^Popn");
  906. X
  907. X  notify(Playernum, Governor, "\n");
  908. X  sprintf(buf, "%2s %3s %7s %6s %5s %5s %5s %2s",
  909. X      "Pl", "sec", "popn", "troops", "a.eff", "a.mob", "res", "x");
  910. X  notify(Playernum, Governor, buf);
  911. X
  912. X  for (i = 0; i <= WASTED; i++) {
  913. X      sprintf(buf, "%4c", SectTypes[i]);
  914. X      notify(Playernum, Governor, buf);
  915. X  }
  916. X  notify(Playernum, Governor,
  917. X     "\n-------------------------------------------------------------------------------\n");
  918. X  for (p = 0; p <= Num_races; p++)
  919. X      if (PlayTSect[p] != 0) {
  920. X      sprintf(buf, "%2d %3d %7d %6d %5.1lf %5.1lf %5d %2d",
  921. X          p, PlayTSect[p], PlayPopn[p], PlayTroops[p],
  922. X          (double)PlayEff[p] / PlayTSect[p],
  923. X          (double)PlayMob[p] / PlayTSect[p], PlayRes[p], PlayCrys[p]);
  924. X      notify(Playernum, Governor, buf);
  925. X      for (i = 0; i <= WASTED; i++) {
  926. X          sprintf(buf, "%4d", PlaySect[p][i]);
  927. X          notify(Playernum, Governor, buf);
  928. X      }
  929. X      notify(Playernum, Governor, "\n");
  930. X      }
  931. X  notify(Playernum, Governor,
  932. X     "-------------------------------------------------------------------------------\n");
  933. X  sprintf(buf, "%2s %3d %7d %6d %5.1lf %5.1lf %5d %2d",
  934. X      "Tl", TotalSect, TotalPopn, TotalTroops, (double)TotalEff / TotalSect,
  935. X      (double)TotalMob / TotalSect, TotalRes, TotalCrys);
  936. X  notify(Playernum, Governor, buf);
  937. X  for (i = 0; i <= WASTED; i++) {
  938. X      sprintf(buf, "%4d", Sect[i]);
  939. X      notify(Playernum, Governor, buf);
  940. X  }
  941. X  notify(Playernum, Governor, "\n");
  942. X  free(planet);
  943. X}
  944. X
  945. Xvoid Insert(int mode, struct anal_sect arr[], int x, int y, int des, int value)
  946. X{
  947. Xint             i, j;
  948. X
  949. Xfor (i = 0; i < CARE; i++)
  950. X    if ((mode && arr[i].value < value) ||
  951. X    (!mode && (arr[i].value > value || arr[i].value == -1))) {
  952. X    for (j = CARE - 1; j > i; j--)
  953. X        arr[j] = arr[j - 1];
  954. X    arr[i].value = value;
  955. X    arr[i].x = x;
  956. X    arr[i].y = y;
  957. X    arr[i].des =des;
  958. X    return;
  959. X    }
  960. X}
  961. X
  962. Xvoid PrintTop(int Playernum, int Governor, struct anal_sect arr[], char *name)
  963. X{
  964. Xint             i;
  965. X
  966. Xsprintf(buf, "%8s:", name);
  967. Xnotify(Playernum, Governor, buf);
  968. Xfor (i = 0; i < CARE && arr[i].value != -1; i++) {
  969. X    sprintf(buf, "%5d%c(%2d,%2d)", arr[i].value, Dessymbols[arr[i].des], arr[i].x, arr[i].y);
  970. X    notify(Playernum, Governor, buf);
  971. X}
  972. Xnotify(Playernum, Governor, "\n");
  973. X}
  974. X
  975. X
  976. X
  977. END_OF_FILE
  978. if test 10337 -ne `wc -c <'user/analysis.c'`; then
  979.     echo shar: \"'user/analysis.c'\" unpacked with wrong size!
  980. fi
  981. # end of 'user/analysis.c'
  982. fi
  983. if test -f 'user/land.c' -a "${1}" != "-c" ; then 
  984.   echo shar: Will not clobber existing file \"'user/land.c'\"
  985. else
  986. echo shar: Extracting \"'user/land.c'\" \(12809 characters\)
  987. sed "s/^X//" >'user/land.c' <<'END_OF_FILE'
  988. X/*
  989. X * * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, *
  990. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. * Restrictions in
  991. X * GB_copyright.h. *
  992. X * 
  993. X *  land.c -- land a ship *  also.... dock -- dock a ship w/ another ship *
  994. X * and..... assault -- a very un-PC version of land/dock
  995. X */
  996. X
  997. X#include "GB_copyright.h"
  998. X#define EXTERN extern
  999. X#include "vars.h"
  1000. X#include "ships.h"
  1001. X#include "races.h"
  1002. X#include "power.h"
  1003. X#include "buffers.h"
  1004. X#include <signal.h>
  1005. X#include <math.h>
  1006. X
  1007. Xextern long     Shipdata[NUMSTYPES][NUMABILS];
  1008. Xint             roll;
  1009. X
  1010. Xvoid            land(int, int, int);
  1011. Xint             crash(shiptype *, double);
  1012. Xint             docked(shiptype *);
  1013. Xint             overloaded(shiptype *);
  1014. X#include "proto.h"
  1015. X
  1016. Xvoid 
  1017. Xland(int Playernum, int Governor, int APcount)
  1018. X{
  1019. X    shiptype       *s, *s2;
  1020. X    planettype     *p;
  1021. X    sectortype     *sect;
  1022. X
  1023. X    int             shipno, ship2no, x = -1, y = -1, i, numdest, strength,
  1024. X                    damage;
  1025. X    double          fuel;
  1026. X    double          Dist;
  1027. X    racetype       *Race, *alien;
  1028. X    int             nextshipno;
  1029. X
  1030. X    if (argn < 2) {
  1031. X        notify(Playernum, Governor, "Land what?\n");
  1032. X        return;
  1033. X    }
  1034. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  1035. X
  1036. X    while (shipno = do_shiplist(&s, &nextshipno))
  1037. X        if (in_list(Playernum, args[1], s, &nextshipno) &&
  1038. X            authorized(Governor, s)) {
  1039. X            if (overloaded(s)) {
  1040. X                sprintf(buf, "%s is too overloaded to land.\n", Ship(s));
  1041. X                notify(Playernum, Governor, buf);
  1042. X                free(s);
  1043. X                continue;
  1044. X            }
  1045. X            
  1046. X            if (!Shipdata[s->type][ABIL_CANDOCK]) {
  1047. X                sprintf(buf, "This ship is not equipped to be docked.\n");
  1048. X                notify(Playernum, Governor, buf);
  1049. X                free(s);
  1050. X                continue;
  1051. X            }
  1052. X
  1053. X            if (s->type == OTYPE_QUARRY) {
  1054. X                notify(Playernum, Governor, "You can't load quarries onto ship.\n");
  1055. X                free(s);
  1056. X                continue;
  1057. X            }
  1058. X            if (docked(s)) {
  1059. X                notify(Playernum, Governor, "That ship is docked to another ship.\n");
  1060. X                free(s);
  1061. X                continue;
  1062. X            }
  1063. X            if (args[2][0] == '#') {
  1064. X                /*
  1065. X                 * attempting to land on a friendly ship (for
  1066. X                 * carriers/stations/etc)
  1067. X                 */
  1068. X                sscanf(args[2] + 1, "%d", &ship2no);
  1069. X                if (!getship(&s2, ship2no)) {
  1070. X                    sprintf(buf, "Ship #%d wasn't found.\n", ship2no);
  1071. X                    notify(Playernum, Governor, buf);
  1072. X                    free(s);
  1073. X                    continue;
  1074. X                }
  1075. X                if (testship(Playernum, Governor, s2)) {
  1076. X                    notify(Playernum, Governor, "Illegal format.\n");
  1077. X                    free(s);
  1078. X                    free(s2);
  1079. X                    continue;
  1080. X                }
  1081. X                if (s2->type == OTYPE_FACTORY) {
  1082. X                    notify(Playernum, Governor, "Can't land on factories.\n");
  1083. X                    free(s);
  1084. X                    free(s2);
  1085. X                    continue;
  1086. X                }
  1087. X                if (landed(s)) {
  1088. X                    if (!landed(s2)) {
  1089. X                        sprintf(buf, "%s is not landed on a planet.\n", Ship(s2));
  1090. X                        notify(Playernum, Governor, buf);
  1091. X                        free(s);
  1092. X                        free(s2);
  1093. X                        continue;
  1094. X                    }
  1095. X                    if (s2->storbits != s->storbits) {
  1096. X                        notify(Playernum, Governor, "These ships are not in the same star system.\n");
  1097. X                        free(s);
  1098. X                        free(s2);
  1099. X                        continue;
  1100. X                    }
  1101. X                    if (s2->pnumorbits != s->pnumorbits) {
  1102. X                        notify(Playernum, Governor, "These ships are not landed on the same planet.\n");
  1103. X                        free(s);
  1104. X                        free(s2);
  1105. X                        continue;
  1106. X                    }
  1107. X                    if ((s2->land_x != s->land_x) ||
  1108. X                        (s2->land_y != s->land_y)) {
  1109. X                        notify(Playernum, Governor, "These ships are not in the same sector.\n");
  1110. X                        free(s);
  1111. X                        free(s2);
  1112. X                        continue;
  1113. X                    }
  1114. X                    if (s->on) {
  1115. X                        sprintf(buf, "%s must be turned off before loading.\n",
  1116. X                            Ship(s));
  1117. X                        notify(Playernum, Governor, buf);
  1118. X                        free(s);
  1119. X                        free(s2);
  1120. X                        continue;
  1121. X                    }
  1122. X                    if (Size(s) > Hanger(s2)) {
  1123. X                        sprintf(buf, "Mothership does not have %d hanger space available to load ship.\n",
  1124. X                            Size(s));
  1125. X                        notify(Playernum, Governor, buf);
  1126. X                        free(s);
  1127. X                        free(s2);
  1128. X                        continue;
  1129. X                    }
  1130. X                    /* ok, load 'em up */
  1131. X                    remove_sh_plan(s);
  1132. X                    /*
  1133. X                     * get the target ship again because
  1134. X                     * it had a pointer changed (and put
  1135. X                     * to disk) in the remove routines
  1136. X                     */
  1137. X                    free(s2);
  1138. X                    (void) getship(&s2, ship2no);
  1139. X                    insert_sh_ship(s, s2);
  1140. X                    /* increase mass of mothership */
  1141. X                    s2->mass += s->mass;
  1142. X                    s2->hanger += Size(s);
  1143. X                    fuel = 0.0;
  1144. X                    sprintf(buf, "%s loaded onto %s using %.1f fuel.\n",
  1145. X                        Ship(s), Ship(s2), fuel);
  1146. X                    notify(Playernum, Governor, buf);
  1147. X                    s->docked = 1;
  1148. X                    putship(s2);
  1149. X                    free(s2);
  1150. X                } else if (s->docked) {
  1151. X                    sprintf(buf, "%s is already docked or landed.\n", Ship(s));
  1152. X                    notify(Playernum, Governor, buf);
  1153. X                    free(s);
  1154. X                    free(s2);
  1155. X                    continue;
  1156. X                } else {
  1157. X                    /*
  1158. X                     * Check if the ships are in the same
  1159. X                     * scope level. Maarten
  1160. X                     */
  1161. X                    if (s->whatorbits != s2->whatorbits) {
  1162. X                        notify(Playernum, Governor, "Those ships are not in the same scope.\n");
  1163. X                        free(s);
  1164. X                        free(s2);
  1165. X                        continue;
  1166. X                    }
  1167. X                    /*
  1168. X                     * check to see if close enough to
  1169. X                     * land
  1170. X                     */
  1171. X                    Dist = sqrt((double) Distsq(s2->xpos, s2->ypos, s->xpos, s->ypos));
  1172. X                    if (Dist > DIST_TO_DOCK) {
  1173. X                        sprintf(buf, "%s must be %.2f or closer to %s.\n",
  1174. X                            Ship(s), DIST_TO_DOCK, Ship(s2));
  1175. X                        notify(Playernum, Governor, buf);
  1176. X                        free(s);
  1177. X                        free(s2);
  1178. X                        continue;
  1179. X                    }
  1180. X                    fuel = 0.05 + Dist * 0.025 * sqrt(s->mass);
  1181. X                    if (s->fuel < fuel) {
  1182. X                        sprintf(buf, "Not enough fuel.\n");
  1183. X                        notify(Playernum, Governor, buf);
  1184. X                        free(s);
  1185. X                        free(s2);
  1186. X                        continue;
  1187. X                    }
  1188. X                    if (Size(s) > Hanger(s2)) {
  1189. X                        sprintf(buf, "Mothership does not have %d hanger space available to load ship.\n",
  1190. X                            Size(s));
  1191. X                        notify(Playernum, Governor, buf);
  1192. X                        free(s);
  1193. X                        free(s2);
  1194. X                        continue;
  1195. X                    }
  1196. X                    use_fuel(s, fuel);
  1197. X
  1198. X                    /*
  1199. X                     * remove the ship from whatever
  1200. X                     * scope it is currently in
  1201. X                     */
  1202. X                    if (s->whatorbits == LEVEL_PLAN)
  1203. X                        remove_sh_plan(s);
  1204. X                    else if (s->whatorbits == LEVEL_STAR)
  1205. X                        remove_sh_star(s);
  1206. X                    else {
  1207. X                        notify(Playernum, Governor, "Ship is not in planet or star scope.\n");
  1208. X                        free(s);
  1209. X                        free(s2);
  1210. X                        continue;
  1211. X                    }
  1212. X                    /*
  1213. X                     * get the target ship again because
  1214. X                     * it had a pointer changed (and put
  1215. X                     * to disk) in the remove routines
  1216. X                     */
  1217. X                    free(s2);
  1218. X                    (void) getship(&s2, ship2no);
  1219. X                    insert_sh_ship(s, s2);
  1220. X                    /* increase mass of mothership */
  1221. X                    s2->mass += s->mass;
  1222. X                    s2->hanger += Size(s);
  1223. X                    sprintf(buf, "%s landed on %s using %.1f fuel.\n",
  1224. X                        Ship(s), Ship(s2), fuel);
  1225. X                    notify(Playernum, Governor, buf);
  1226. X                    s->docked = 1;
  1227. X                    putship(s2);
  1228. X                    free(s2);
  1229. X                }
  1230. X            } else {/* attempting to land on a planet */
  1231. X                if (s->docked) {
  1232. X                    sprintf(buf, "%s is docked.\n", Ship(s));
  1233. X                    notify(Playernum, Governor, buf);
  1234. X                    free(s);
  1235. X                    continue;
  1236. X                }
  1237. X                sscanf(args[2], "%d,%d", &x, &y);
  1238. X                if (s->whatorbits != LEVEL_PLAN) {
  1239. X                    sprintf(buf, "%s doesn't orbit a planet.\n", Ship(s));
  1240. X                    notify(Playernum, Governor, buf);
  1241. X                    free(s);
  1242. X                    continue;
  1243. X                }
  1244. X                if (!Shipdata[s->type][ABIL_CANLAND]) {
  1245. X                    sprintf(buf, "This ship is not equipped to land.\n");
  1246. X                    notify(Playernum, Governor, buf);
  1247. X                    free(s);
  1248. X                    continue;
  1249. X                }
  1250. X                if ((s->storbits != Dir[Playernum - 1][Governor].snum) ||
  1251. X                    (s->pnumorbits != Dir[Playernum - 1][Governor].pnum)) {
  1252. X                    sprintf(buf, "You have to cs to the planet it orbits.\n");
  1253. X                    notify(Playernum, Governor, buf);
  1254. X                    free(s);
  1255. X                    continue;
  1256. X                }
  1257. X                if (!speed_rating(s)) {
  1258. X                    sprintf(buf, "This ship is not rated for maneuvering.\n");
  1259. X                    notify(Playernum, Governor, buf);
  1260. X                    free(s);
  1261. X                    continue;
  1262. X                }
  1263. X                if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount)) {
  1264. X                    free(s);
  1265. X                    continue;
  1266. X                }
  1267. X                getplanet(&p, (int) s->storbits, (int) s->pnumorbits);
  1268. X
  1269. X                sprintf(buf, "Planet /%s/%s has gravity field of %.2f.\n",
  1270. X                    Stars[s->storbits]->name,
  1271. X                    Stars[s->storbits]->pnames[s->pnumorbits], gravity(p));
  1272. X                notify(Playernum, Governor, buf);
  1273. X
  1274. X                sprintf(buf, "Distance to planet: %.2f.\n",
  1275. X                    Dist = sqrt((double) Distsq(Stars[s->storbits]->xpos + p->xpos,
  1276. X                     Stars[s->storbits]->ypos + p->ypos,
  1277. X                            s->xpos, s->ypos)));
  1278. X                notify(Playernum, Governor, buf);
  1279. X
  1280. X                if (Dist > DIST_TO_LAND) {
  1281. X                    sprintf(buf, "%s must be %.3g or closer to the planet (%.2f).\n",
  1282. X                        Ship(s), DIST_TO_LAND, Dist);
  1283. X                    notify(Playernum, Governor, buf);
  1284. X                    free(s);
  1285. X                    free(p);
  1286. X                    continue;
  1287. X                }
  1288. X                fuel = s->mass * gravity(p) * LAND_GRAV_MASS_FACTOR;
  1289. X
  1290. X                if ((x < 0) || (y < 0) || (x > p->Maxx - 1) || (y > p->Maxy - 1)) {
  1291. X                    sprintf(buf, "Illegal coordinates.\n");
  1292. X                    notify(Playernum, Governor, buf);
  1293. X                    free(s);
  1294. X                    free(p);
  1295. X                    continue;
  1296. X                }
  1297. X#ifdef DEFENSE
  1298. X                /*
  1299. X                 * people who have declared war on you will
  1300. X                 * fire at your landing ship
  1301. X                 */
  1302. X                for (i = 1; i <= Num_races; i++)
  1303. X                    if (s->alive && i != Playernum && p->info[i - 1].popn &&
  1304. X                        p->info[i - 1].guns && p->info[i - 1].destruct) {
  1305. X                        alien = races[i - 1];
  1306. X                        if (isset(alien->atwar, (int) s->owner)) {
  1307. X                            /*
  1308. X                             * attack the landing
  1309. X                             * ship
  1310. X                             */
  1311. X                            strength = MIN((int) p->info[i - 1].guns,
  1312. X                                       (int) p->info[i - 1].destruct);
  1313. X                            if (strength) {
  1314. X                                damage = shoot_planet_to_ship(alien, p, s, strength,
  1315. X                                 buf, temp);
  1316. X                                post(temp, COMBAT);
  1317. X                                notify_star(0, 0, (int) s->owner,
  1318. X                                        (int) s->storbits, temp);
  1319. X                                warn(i, (int) Stars[s->storbits]->governor[i - 1], buf);
  1320. X                                notify((int) s->owner, (int) s->governor, buf);
  1321. X                                p->info[i - 1].destruct -= strength;
  1322. X                            }
  1323. X                        }
  1324. X                    }
  1325. X                if (!s->alive) {
  1326. X                    putplanet(p, (int) s->storbits, (int) s->pnumorbits);
  1327. X                    putship(s);
  1328. X                    free(p);
  1329. X                    free(s);
  1330. X                    continue;
  1331. X                }
  1332. X#endif
  1333. X                /*
  1334. X                 * check to see if the ship crashes from lack
  1335. X                 * of fuel or damage
  1336. X                 */
  1337. X                if (crash(s, fuel)) {
  1338. X                    /*
  1339. X                     * damaged ships stand of chance of
  1340. X                     * crash landing
  1341. X                     */
  1342. X                    numdest = shoot_ship_to_planet(s, p,
  1343. X                                       round_rand((double) (s->destruct) / 3.),
  1344. X                                       x, y, 1, 0, HEAVY, long_buf, short_buf);
  1345. X                    sprintf(buf, "BOOM!! %s crashes on sector %d,%d with blast radius of %d.\n",
  1346. X                        Ship(s), x, y, numdest);
  1347. X                    for (i = 1; i <= Num_races; i++)
  1348. X                        if (p->info[i - 1].numsectsowned || i == Playernum)
  1349. X                            warn(i, (int) Stars[s->storbits]->governor[i - 1], buf);
  1350. X                    if (roll)
  1351. X                        sprintf(buf, "Ship damage %d%% (you rolled a %d)\n",
  1352. X                             (int) s->damage, roll);
  1353. X                    else
  1354. X                        sprintf(buf, "You had %.1ff while the landing required %.1ff\n",
  1355. X                            s->fuel, fuel);
  1356. X                    notify(Playernum, Governor, buf);
  1357. X                    kill_ship((int) s->owner, s);
  1358. X                } else {
  1359. X                    s->land_x = x;
  1360. X                    s->land_y = y;
  1361. X                    s->xpos = p->xpos + Stars[s->storbits]->xpos;
  1362. X                    s->ypos = p->ypos + Stars[s->storbits]->ypos;
  1363. X                    use_fuel(s, fuel);
  1364. X                    s->docked = 1;
  1365. X                    s->whatdest = LEVEL_PLAN;    /* no destination */
  1366. X                    s->deststar = s->storbits;
  1367. X                    s->destpnum = s->pnumorbits;
  1368. X                }
  1369. X
  1370. X                getsector(§, p, x, y);
  1371. X
  1372. X                if (sect->condition == WASTED) {
  1373. X                    sprintf(buf, "Warning: That sector is a wasteland!\n");
  1374. X                    notify(Playernum, Governor, buf);
  1375. X                } else if (sect->owner && sect->owner != Playernum) {
  1376. X                    Race = races[Playernum - 1];
  1377. X                    alien = races[sect->owner - 1];
  1378. X                    if (!(isset(Race->allied, sect->owner) &&
  1379. X                     isset(alien->allied, Playernum))) {
  1380. X                        sprintf(buf, "You have landed on an alien sector (%s).\n", alien->name);
  1381. X                        notify(Playernum, Governor, buf);
  1382. X                    } else {
  1383. X                        sprintf(buf, "You have landed on allied sector (%s).\n", alien->name);
  1384. X                        notify(Playernum, Governor, buf);
  1385. X                    }
  1386. X                }
  1387. X                if (s->whatorbits == LEVEL_UNIV)
  1388. X                    deductAPs(Playernum, Governor, APcount, 0, 1);
  1389. X                else
  1390. X                    deductAPs(Playernum, Governor, APcount, (int) s->storbits, 0);
  1391. X
  1392. X                putplanet(p, (int) s->storbits, (int) s->pnumorbits);
  1393. X
  1394. X                if (numdest)
  1395. X                    putsector(sect, p, x, y);
  1396. X
  1397. X                /* send messages to anyone there */
  1398. X                sprintf(buf, "%s observed landing on sector %d,%d,planet /%s/%s.\n",
  1399. X                    Ship(s), s->land_x, s->land_y,
  1400. X                    Stars[s->storbits]->name,
  1401. X                 Stars[s->storbits]->pnames[s->pnumorbits]);
  1402. X                for (i = 1; i <= Num_races; i++)
  1403. X                    if (p->info[i - 1].numsectsowned && i != Playernum)
  1404. X                        notify(i, (int) Stars[s->storbits]->governor[i - 1], buf);
  1405. X
  1406. X                sprintf(buf, "%s landed on planet.\n", Ship(s));
  1407. X                notify(Playernum, Governor, buf);
  1408. X
  1409. X                free(sect);
  1410. X                free(p);
  1411. X            }
  1412. X            putship(s);
  1413. X            free(s);
  1414. X        } else
  1415. X            free(s);
  1416. X}
  1417. X
  1418. Xint 
  1419. Xcrash(shiptype * s, double fuel)
  1420. X{
  1421. X    roll = 0;
  1422. X
  1423. X    if (s->fuel < fuel)
  1424. X        return 1;
  1425. X    else if ((roll = int_rand(1, 100)) <= (int) s->damage)
  1426. X        return 1;
  1427. X    else
  1428. X        return 0;
  1429. X}
  1430. X
  1431. Xint 
  1432. Xdocked(shiptype * s)
  1433. X{
  1434. X    return (s->docked && s->whatdest == LEVEL_SHIP);
  1435. X}
  1436. X
  1437. Xint 
  1438. Xoverloaded(shiptype * s)
  1439. X{
  1440. X    return ((s->resource > Max_resource(s)) || (s->fuel > Max_fuel(s)) ||
  1441. X        (s->popn + s->troops > s->max_crew) || (s->destruct > Max_destruct(s)));
  1442. X}
  1443. END_OF_FILE
  1444. if test 12809 -ne `wc -c <'user/land.c'`; then
  1445.     echo shar: \"'user/land.c'\" unpacked with wrong size!
  1446. fi
  1447. # end of 'user/land.c'
  1448. fi
  1449. if test -f 'utils/enrol.c' -a "${1}" != "-c" ; then 
  1450.   echo shar: Will not clobber existing file \"'utils/enrol.c'\"
  1451. else
  1452. echo shar: Extracting \"'utils/enrol.c'\" \(13967 characters\)
  1453. sed "s/^X//" >'utils/enrol.c' <<'END_OF_FILE'
  1454. X/*
  1455. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  1456. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  1457. X * Restrictions in GB_copyright.h.
  1458. X * enrol.c -- initializes to owner one sector and planet. 
  1459. X */
  1460. X
  1461. X#include "GB_copyright.h"
  1462. X#include <stdio.h>
  1463. X#include <signal.h>
  1464. X#include <strings.h>
  1465. X#include <curses.h>
  1466. X#include <errno.h>
  1467. X#define EXTERN
  1468. X#include "vars.h"
  1469. X#include "ships.h"
  1470. X#include "shipdata.h"
  1471. X#include "races.h"
  1472. X#include "buffers.h"
  1473. Xextern int errno;
  1474. Xchar desshow();
  1475. Xracetype *Race;
  1476. X
  1477. Xstruct stype {
  1478. X  char here;
  1479. X  char x,y;
  1480. X  int count;
  1481. X};
  1482. X#define RACIAL_TYPES 10
  1483. X
  1484. X/* racial types (10 racial types ) */
  1485. Xint Thing[RACIAL_TYPES] = {
  1486. X  1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
  1487. Xdouble db_Mass[RACIAL_TYPES] = {
  1488. X  .1,.15,.2,.125,.125,.125,.125,.125,.125,.125};
  1489. Xdouble db_Birthrate[RACIAL_TYPES] = {
  1490. X  0.9, 0.85, 0.8, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8};
  1491. Xint db_Fighters[RACIAL_TYPES] = {
  1492. X  9, 10, 11, 2, 3, 4, 5, 6, 7, 8};
  1493. Xint db_Intelligence[RACIAL_TYPES] = {
  1494. X  0, 0, 0, 190, 180, 170, 160, 150, 140, 130};
  1495. Xdouble db_Adventurism[RACIAL_TYPES] = {
  1496. X  0.89, 0.89, 0.89, .6, .65, .7, .7, .75, .75, .8};
  1497. Xint Min_Sexes[RACIAL_TYPES] = {
  1498. X  1, 1, 1, 2, 2, 2, 2, 2, 2, 2};
  1499. Xint Max_Sexes[RACIAL_TYPES] = {
  1500. X  1, 1, 1, 2, 2, 4, 4, 4, 4, 4};
  1501. Xdouble db_Metabolism[RACIAL_TYPES] = {
  1502. X  3.0, 2.7, 2.4, 1.0, 1.15, 1.30, 1.45, 1.6, 1.75, 1.9};
  1503. X
  1504. X#define RMass(x) (db_Mass[(x)] + .001*(double)int_rand(-25, 25))
  1505. X#define Birthrate(x) (db_Birthrate[(x)] + .01*(double)int_rand(-10, 10))
  1506. X#define Fighters(x) (db_Fighters[(x)] + int_rand(-1, 1))
  1507. X#define Intelligence(x) (db_Intelligence[(x)] + int_rand(-10, 10))
  1508. X#define Adventurism(x) (db_Adventurism[(x)] + 0.01*(double)int_rand(-10,10))
  1509. X#define Sexes(x) (int_rand(Min_Sexes[(x)], int_rand(Min_Sexes[(x)], Max_Sexes[(x)])))
  1510. X#define Metabolism(x) (db_Metabolism[(x)] + .01*(double)int_rand(-15, 15))
  1511. X
  1512. X/* compatibility schematic for sectors.  Note that plated sectors are
  1513. X   compatible with everything.  */
  1514. Xdouble Likes[15] = {
  1515. X  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9
  1516. X};
  1517. X
  1518. Xchar *Desnames[] = {
  1519. X  "ocean",
  1520. X  "land",
  1521. X  "mountainous",
  1522. X  "gaseous",
  1523. X  "ice",
  1524. X  "forest",
  1525. X  "desert",
  1526. X  "plated",
  1527. X  "error in des type!",  /* (illegal values) */
  1528. X  "err in des type!"
  1529. X};
  1530. X
  1531. Xmain()
  1532. X{
  1533. X  int x,y, or;
  1534. X  int pnum,star=0,found=0,check,vacant,count,i,j,Playernum;
  1535. X  int ifd, mask,ppref = -1;
  1536. X  int s, idx, k;
  1537. X  char str[100], c;
  1538. X  char racepass[MAXCOMMSTRSIZE], govpass[MAXCOMMSTRSIZE];
  1539. X  sectortype *sect;
  1540. X  struct stype secttypes[WASTED+1];
  1541. X  planettype *planet;
  1542. X  unsigned char not_found[TYPE_GASGIANT+1];
  1543. X  startype *star_arena;
  1544. X  FILE *fd;
  1545. X
  1546. X  open_data_files();    
  1547. X
  1548. X  srandom(getpid());
  1549. X
  1550. X  if ( (Playernum=Numraces()+1) >= MAXPLAYERS) {
  1551. X    printf("There are already %d players; No more allowed.\n",MAXPLAYERS-1);
  1552. X    exit(-1);
  1553. X  }
  1554. X
  1555. X
  1556. X  printf("Enter racial type to be created (1-%d):", RACIAL_TYPES);
  1557. X  scanf("%d", &idx);
  1558. X  getchr();
  1559. X
  1560. X  if(idx <= 0 || idx > RACIAL_TYPES) {
  1561. X    printf("Bad racial index.\n");
  1562. X    exit(1);
  1563. X  }
  1564. X  idx=idx-1;
  1565. X  
  1566. X  getsdata(&Sdata);
  1567. X
  1568. X  star_arena = (startype *)malloc(Sdata.numstars * sizeof(startype));
  1569. X  for (s=0; s<Sdata.numstars; s++) {
  1570. X    Stars[s] = &star_arena[s];
  1571. X    getstar(&(Stars[s]),s);
  1572. X  }
  1573. X  printf("There is still space for player %d.\n", Playernum);
  1574. X
  1575. X  bzero((char *)not_found, sizeof(not_found));
  1576. X  do {
  1577. X    printf("\nLive on what type planet:\n     (e)arth, (g)asgiant, (m)ars, (i)ce, (w)ater, (d)esert, (f)orest? ");
  1578. X    c=getchr();
  1579. X    getchr();
  1580. X
  1581. X    switch (c) {
  1582. X    case 'w': 
  1583. X      ppref = TYPE_WATER;
  1584. X      break;
  1585. X    case 'e': 
  1586. X      ppref = TYPE_EARTH;
  1587. X      break;
  1588. X    case 'm': 
  1589. X      ppref = TYPE_MARS;
  1590. X      break;
  1591. X    case 'g': 
  1592. X      ppref = TYPE_GASGIANT;
  1593. X      break;
  1594. X    case 'i': 
  1595. X      ppref = TYPE_ICEBALL;
  1596. X      break;
  1597. X    case 'd': 
  1598. X      ppref = TYPE_DESERT;
  1599. X      break;
  1600. X    case 'f': 
  1601. X      ppref = TYPE_FOREST;
  1602. X      break;
  1603. X    default: 
  1604. X      printf("Oh well.\n");
  1605. X      exit(-1);
  1606. X      break;
  1607. X    }
  1608. X
  1609. X    printf("Looking for type %d planet...\n", ppref);
  1610. X
  1611. X    /* find first planet of right type */
  1612. X    count = 0;
  1613. X    found = 0;
  1614. X
  1615. X    for (star=0; star<Sdata.numstars && !found && count < 100; ) {
  1616. X
  1617. X      check = 1;
  1618. X      /* skip over inhabited stars - or stars with just one planet! */
  1619. X      if (Stars[star]->inhabited[0]+Stars[star]->inhabited[1] ||
  1620. X      Stars[star]->numplanets<2)
  1621. X        check = 0;
  1622. X
  1623. X      /* look for uninhabited planets */
  1624. X      if (check) {
  1625. X        pnum = 0;
  1626. X        while (!found && pnum<Stars[star]->numplanets) {
  1627. X          getplanet(&planet,star,pnum);
  1628. X
  1629. X          if (planet->type==ppref && Stars[star]->numplanets!=1) {
  1630. X            vacant = 1;
  1631. X            for (i=1; i<=Playernum; i++ )
  1632. X              if (planet->info[i-1].numsectsowned)
  1633. X                vacant = 0;
  1634. X            if (vacant && planet->conditions[RTEMP] >= -50 && planet->conditions[RTEMP]
  1635. X                <= 50)
  1636. X            {
  1637. X              found = 1;
  1638. X            }
  1639. X          }
  1640. X          if (!found) {
  1641. X            free(planet);
  1642. X            pnum++;
  1643. X          }
  1644. X        }
  1645. X      }
  1646. X
  1647. X      if (!found) {
  1648. X        count++;
  1649. X        star = int_rand(0,Sdata.numstars-1);
  1650. X      }
  1651. X
  1652. X    }
  1653. X
  1654. X    if (!found) {
  1655. X      printf("planet type not found in any free systems.\n");
  1656. X      not_found[ppref] = 1;
  1657. X      for (found=1,i=TYPE_EARTH; i<=TYPE_DESERT; i++)
  1658. X        found &= not_found[i];
  1659. X      if (found) {
  1660. X        printf("Looks like there aren't any free planets left.  bye..\n");
  1661. X        endwin();
  1662. X        exit(-1);
  1663. X      } else
  1664. X        printf("  Try a different one...\n");
  1665. X      found = 0;
  1666. X    }
  1667. X
  1668. X  } while (!found);
  1669. X
  1670. X  Race = Malloc(racetype);
  1671. X  Bzero(*Race);
  1672. X
  1673. X  printf("\n\tDeity/Guest/Normal (d/g/n) ?");
  1674. X  c=getchr();
  1675. X  getchr();
  1676. X
  1677. X  Race->God = (c=='d');
  1678. X  Race->Guest = (c=='g');
  1679. X  strcpy(Race->name, "Unknown");
  1680. X
  1681. X  for(i=0; i<=MAXGOVERNORS; i++) {
  1682. X      Race->governor[0].money = 0;
  1683. X  }
  1684. X  Race->governor[0].homelevel = Race->governor[0].deflevel = LEVEL_PLAN;
  1685. X  Race->governor[0].homesystem = Race->governor[0].defsystem = star;
  1686. X  Race->governor[0].homeplanetnum = Race->governor[0].defplanetnum = pnum;
  1687. X  /* display options */
  1688. X  Race->governor[0].toggle.highlight = Playernum;
  1689. X  Race->governor[0].toggle.inverse = 1;
  1690. X  Race->governor[0].toggle.color = 0;
  1691. X  Race->governor[0].active = 1;
  1692. X  printf("Enter the password for this race:");
  1693. X  scanf("%s", Race->password);
  1694. X  getchr();
  1695. X  printf("Enter the password for this leader:");
  1696. X  scanf("%s", Race->governor[0].password);
  1697. X  getchr();
  1698. X
  1699. X
  1700. X  /* make conditions preferred by your people set to (more or less) 
  1701. X     those of the planet : higher the concentration of gas, the higher
  1702. X     percentage difference between planet and race (commented out) */
  1703. X  for (j=0; j<=OTHER; j++)
  1704. X    Race->conditions[j] = planet->conditions[j];
  1705. X  /*+ int_rand( round_rand(-planet->conditions[j]*2.0), round_rand(planet->conditions[j]*2.0) )*/
  1706. X
  1707. X
  1708. X  for (i=0; i<MAXPLAYERS; i++) {
  1709. X    /* messages from autoreport, player #1 are decodable */
  1710. X    if ((i==Playernum || Playernum==1) || Race->God)
  1711. X      Race->translate[i-1] = 100;  /* you can talk to own race */
  1712. X    else
  1713. X      Race->translate[i-1] = 1;
  1714. X  }
  1715. X
  1716. X  /* assign racial characteristics */
  1717. X  for(i=0; i<100; i++)
  1718. X    Race->discoveries[i] = 0;
  1719. X  Race->tech = 0.0;
  1720. X  Race->morale = 0;
  1721. X  Race->turn = 0;
  1722. X  Race->allied[0] = Race->allied[1] = 0;
  1723. X  Race->atwar[0] = Race->atwar[1] = 0;
  1724. X  do {
  1725. X    Race->mass = RMass(idx);
  1726. X    Race->birthrate = Birthrate(idx);
  1727. X    Race->fighters = Fighters(idx);
  1728. X    if(Thing[idx]) {
  1729. X    Race->IQ = 0;
  1730. X    Race->Metamorph = Race->absorb = Race->collective_iq = Race->pods = 1;
  1731. X    } else {
  1732. X    Race->IQ = Intelligence(idx);
  1733. X    Race->Metamorph = Race->absorb = Race->collective_iq = Race->pods = 0;
  1734. X    }
  1735. X    Race->adventurism = Adventurism(idx);
  1736. X    Race->number_sexes = Sexes(idx);
  1737. X    Race->metabolism = Metabolism(idx);
  1738. X
  1739. X    printf("%s\n", Race->Metamorph ? "METAMORPHIC" : "");
  1740. X    printf("       Birthrate: %.3f\n",Race->birthrate);
  1741. X    printf("Fighting ability: %d\n",Race->fighters);
  1742. X    printf("              IQ: %d\n",Race->IQ);
  1743. X    printf("      Metabolism: %.2f\n",Race->metabolism);
  1744. X    printf("     Adventurism: %.2f\n",Race->adventurism);
  1745. X    printf("            Mass: %.2f\n",Race->mass);
  1746. X    printf(" Number of sexes: %d (min req'd for colonization)\n",Race->number_sexes);
  1747. X
  1748. X    printf("\n\nLook OK(y/n)\?");
  1749. X    if(gets(str)==NULL)
  1750. X      exit(1);
  1751. X  } while (str[0] != 'y');
  1752. X
  1753. X  bzero((char *)secttypes, sizeof(secttypes));
  1754. X
  1755. X  getsmap(Smap,planet);
  1756. X
  1757. X  printf("\nChoose a primary sector preference. This race will prefer to live\non this type of sector.\n");
  1758. X
  1759. X  PermuteSects(planet);
  1760. X  Getxysect(planet, 0, 0, 1);
  1761. X  while (Getxysect(planet,&x,&y,0)) {
  1762. X    secttypes[Sector(*planet,x,y).condition].count++;
  1763. X    if (!secttypes[Sector(*planet,x,y).condition].here) {
  1764. X        secttypes[Sector(*planet,x,y).condition].here = 1;
  1765. X        secttypes[Sector(*planet,x,y).condition].x = x;
  1766. X        secttypes[Sector(*planet,x,y).condition].y = y;
  1767. X    }
  1768. X}
  1769. X  planet->explored = 1;
  1770. X  for (i=SEA; i<=WASTED; i++)
  1771. X    if (secttypes[i].here) {
  1772. X      printf("(%2d): %c (%d, %d) (%s, %d sectors)\n", i,
  1773. X          desshow(planet, secttypes[i].x,secttypes[i].y),
  1774. X         secttypes[i].x, secttypes[i].y,
  1775. X         Desnames[i], secttypes[i].count);
  1776. X    }
  1777. X  planet->explored = 0;
  1778. X
  1779. X  found = 0;
  1780. X  do {
  1781. X    printf("\nchoice (enter the number): ");
  1782. X    scanf("%d", &i);
  1783. X    getchr();
  1784. X    if (i<SEA || i>WASTED || !secttypes[i].here) {
  1785. X      printf("There are none of that type here..\n");
  1786. X    } else
  1787. X      found = 1;
  1788. X  } while (!found);
  1789. X
  1790. X  sect = &Sector(*planet,secttypes[i].x,secttypes[i].y);
  1791. X  Race->likesbest = i;
  1792. X  Race->likes[i] = 1.0;
  1793. X  Race->likes[PLATED] = 1.0;
  1794. X  Race->likes[WASTED] = 0.0;
  1795. X  printf("\nEnter compatibilities of other sectors -\n");
  1796. X  for (j=SEA; j<PLATED; j++)
  1797. X    if(i!=j) {
  1798. X      printf("%6s (%3d sectors) :", Desnames[j], secttypes[j].count);
  1799. X      scanf("%d", &k);
  1800. X      Race->likes[j]=(double)k/100.0;
  1801. X    }
  1802. X  printf("Numraces = %d\n", Numraces());
  1803. X  Playernum = Race->Playernum = Numraces() + 1;
  1804. X  
  1805. X  mask = sigblock(SIGBLOCKS);
  1806. X  /* build a capital ship to run the government */
  1807. X  {
  1808. X    shiptype s;
  1809. X    int shipno;
  1810. X
  1811. X    Bzero(s);
  1812. X    shipno = Numships() + 1;
  1813. X    printf("Creating government ship %d...\n", shipno);
  1814. X    Race->Gov_ship = shipno;
  1815. X    planet->ships = shipno;
  1816. X    s.nextship = 0;
  1817. X
  1818. X    s.type = OTYPE_GOV;
  1819. X    s.xpos = Stars[star]->xpos + planet->xpos;
  1820. X    s.ypos = Stars[star]->ypos + planet->ypos;
  1821. X    s.land_x = (char)secttypes[i].x;
  1822. X    s.land_y = (char)secttypes[i].y;
  1823. X
  1824. X    s.speed = 0;
  1825. X    s.owner = Playernum;
  1826. X    s.race = Playernum;
  1827. X    s.governor = 0;
  1828. X
  1829. X    s.tech = 100.0;
  1830. X
  1831. X    s.build_type = OTYPE_GOV;
  1832. X    s.armor = Shipdata[OTYPE_GOV][ABIL_ARMOR];
  1833. X    s.guns = PRIMARY;
  1834. X    s.primary = Shipdata[OTYPE_GOV][ABIL_GUNS];
  1835. X    s.primtype = Shipdata[OTYPE_GOV][ABIL_PRIMARY];
  1836. X    s.secondary = Shipdata[OTYPE_GOV][ABIL_GUNS];
  1837. X    s.sectype = Shipdata[OTYPE_GOV][ABIL_SECONDARY];
  1838. X    s.max_crew = Shipdata[OTYPE_GOV][ABIL_MAXCREW];
  1839. X    s.max_destruct = Shipdata[OTYPE_GOV][ABIL_DESTCAP];
  1840. X    s.max_resource = Shipdata[OTYPE_GOV][ABIL_CARGO];
  1841. X    s.max_fuel = Shipdata[OTYPE_GOV][ABIL_FUELCAP];
  1842. X    s.max_speed = Shipdata[OTYPE_GOV][ABIL_SPEED];
  1843. X    s.build_cost = Shipdata[OTYPE_GOV][ABIL_COST];
  1844. X    s.size = 100;
  1845. X    s.base_mass = 100.0;
  1846. X    sprintf(s.class, "Standard");
  1847. X
  1848. X    s.fuel = 0.0;
  1849. X    s.popn = Shipdata[s.type][ABIL_MAXCREW];
  1850. X    s.troops = 0;
  1851. X    s.mass = s.base_mass + Shipdata[s.type][ABIL_MAXCREW]*Race->mass;
  1852. X    s.destruct = s.resource = 0;
  1853. X
  1854. X    s.alive = 1;
  1855. X    s.active = 1;
  1856. X    s.protect.self = 1;
  1857. X
  1858. X    s.docked = 1;
  1859. X    /* docked on the planet */
  1860. X    s.whatorbits = LEVEL_PLAN;
  1861. X    s.whatdest = LEVEL_PLAN;
  1862. X    s.deststar = star;
  1863. X    s.destpnum = pnum;
  1864. X    s.storbits = star;
  1865. X    s.pnumorbits = pnum;
  1866. X    s.rad = 0;
  1867. X    s.damage = 0;  /*Shipdata[s.type][ABIL_DAMAGE];*/
  1868. X    /* (first capital is 100% efficient */
  1869. X    s.retaliate = 0;
  1870. X
  1871. X    s.ships = 0;
  1872. X
  1873. X    s.on = 1;
  1874. X
  1875. X    s.name[0] = '\0';
  1876. X    s.number = shipno;
  1877. X    printf("Created on sector %d,%d on /%s/%s\n",
  1878. X       s.land_x, s.land_y, Stars[s.storbits]->name,
  1879. X       Stars[s.storbits]->pnames[s.pnumorbits]);
  1880. X    putship(&s);
  1881. X  }
  1882. X
  1883. X  for(j=0; j<MAXPLAYERS; j++) Race->points[j]=0;
  1884. X  
  1885. X  putrace(Race);
  1886. X
  1887. X  planet->info[Playernum-1].numsectsowned = 1;
  1888. X  planet->explored = 0;
  1889. X  planet->info[Playernum-1].explored = 1;
  1890. X  /*planet->info[Playernum-1].autorep = 1;*/
  1891. X
  1892. X  sect->owner = Playernum;
  1893. X  sect->race = Playernum;
  1894. X  sect->popn = planet->popn = Race->number_sexes;
  1895. X  sect->fert = 100;
  1896. X  sect->eff = 10;
  1897. X  sect->troops = planet->troops = 0;
  1898. X  planet->maxpopn = maxsupport(Race, sect, 100.0,0)
  1899. X      * planet->Maxx * planet->Maxy / 2;
  1900. X  /* (approximate) */
  1901. X
  1902. X  putsector(sect, planet, secttypes[i].x, secttypes[i].y);
  1903. X  putplanet(planet,star,pnum);
  1904. X
  1905. X  /* make star explored and stuff */
  1906. X  getstar(&Stars[star],star);
  1907. X  setbit(Stars[star]->explored,Playernum);
  1908. X  setbit(Stars[star]->inhabited,Playernum);
  1909. X  Stars[star]->AP[Playernum-1] = 5;
  1910. X  putstar(Stars[star],star);
  1911. X  close_data_files();
  1912. X
  1913. X  sigsetmask(mask);
  1914. X
  1915. X  printf("\nYou are player %d.\n\n",Playernum);
  1916. X  printf("Your race has been created on sector %d,%d on\n",
  1917. X      secttypes[i].x,secttypes[i].y);
  1918. X  printf("%s/%s.\n\n",Stars[star]->name, Stars[star]->pnames[pnum]);
  1919. X
  1920. X}
  1921. X
  1922. Xchar desshow(p,x,y) /* copied from map.c */
  1923. Xreg planettype *p;
  1924. Xreg int x,y;
  1925. X{
  1926. X  reg sectortype *s;
  1927. X
  1928. X  s = &Sector(*p,x,y);
  1929. X
  1930. X  switch (s->condition) {
  1931. X    case WASTED:
  1932. X      return CHAR_WASTED;
  1933. X    case SEA: 
  1934. X      return CHAR_SEA;
  1935. X    case LAND: 
  1936. X      return CHAR_LAND;
  1937. X    case MOUNT: 
  1938. X      return CHAR_MOUNT;
  1939. X    case GAS: 
  1940. X      return CHAR_GAS;
  1941. X    case PLATED: 
  1942. X      return CHAR_PLATED;
  1943. X    case DESERT: 
  1944. X      return CHAR_DESERT;
  1945. X    case FOREST:
  1946. X      return CHAR_FOREST;
  1947. X    case ICE: 
  1948. X      return CHAR_ICE;
  1949. X    default: 
  1950. X      return('!');
  1951. X  }
  1952. X}
  1953. X
  1954. Xvoid notify(who, gov, msg)
  1955. Xint who, gov;
  1956. Xchar *msg;
  1957. X{
  1958. X  /* this is a dummy routine */
  1959. X}
  1960. X
  1961. Xvoid warn(who, gov, msg)
  1962. Xint who, gov;
  1963. Xchar *msg;
  1964. X{
  1965. X  /* this is a dummy routine */
  1966. X}
  1967. X
  1968. Xvoid push_message(what, who, msg)
  1969. Xint what, who;
  1970. Xchar *msg;
  1971. X{
  1972. X  /* this is a dummy routine */
  1973. X}
  1974. END_OF_FILE
  1975. if test 13967 -ne `wc -c <'utils/enrol.c'`; then
  1976.     echo shar: \"'utils/enrol.c'\" unpacked with wrong size!
  1977. fi
  1978. # end of 'utils/enrol.c'
  1979. fi
  1980. echo shar: End of archive 13 \(of 21\).
  1981. cp /dev/null ark13isdone
  1982. MISSING=""
  1983. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
  1984.     if test ! -f ark${I}isdone ; then
  1985.     MISSING="${MISSING} ${I}"
  1986.     fi
  1987. done
  1988. if test "${MISSING}" = "" ; then
  1989.     echo You have unpacked all 21 archives.
  1990.     echo "Now type './buildfiles.sh'"
  1991.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1992. else
  1993.     echo You still need to unpack the following archives:
  1994.     echo "        " ${MISSING}
  1995. fi
  1996. ##  End of shell archive.
  1997. exit 0
  1998.