home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part17 < prev    next >
Encoding:
Internet Message Format  |  1993-03-20  |  55.1 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: v17i029:  gbp - Galactic Bloodshed+, an empire-like war game, Part17/21
  5. Message-ID: <4557@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:32:54 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1922
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1708
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 29
  14. Archive-name: gbp/Part17
  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 17 (of 21)."
  27. # Contents:  hdrs/tweakables.h server/getplace.c user/fuel.c
  28. #   user/launch.c utils/GB_racegen.c utils/exship.c
  29. # Wrapped by billr@saab on Fri Feb 12 09:14:29 1993
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'hdrs/tweakables.h' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'hdrs/tweakables.h'\"
  33. else
  34. echo shar: Extracting \"'hdrs/tweakables.h'\" \(9356 characters\)
  35. sed "s/^X//" >'hdrs/tweakables.h' <<'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.c, enroll.dat.
  39. X * Restrictions in GB.c.
  40. X *  tweakable constants & other things -- changing the following may cause GB 
  41. X *    to freak if
  42. X *    the functions using them are not recompiled so be careful.
  43. X */
  44. X
  45. X#define VERSION "1.1.4 1/30/93"
  46. X
  47. X#define MOVE_FACTOR    1 
  48. X
  49. X#define DEFAULT_UPDATE_TIME    (4 * 60)    /* update time (minutes!) */
  50. X#define    DEFAULT_RANDOM_UPDATE_RANGE    0    /* again, in minutes. */
  51. X#define    DEFAULT_RANDOM_SEGMENT_RANGE    0    /* again, in minutes. */
  52. X#define    MOVES_PER_UPDATE    3
  53. X/* If MOVES_PER_UPDATE is set to 1, there will be no movement segments */
  54. X/* between updates; the move is counted as part of the update. */
  55. X/* Set this to something higher to have evenly spaced movement segments. */
  56. X
  57. X#define LOGIN_NAME_SIZE 64
  58. X
  59. X#define NUM_TIMES_TO_WAIT_FOR_LOCK 200
  60. X#define NEUTRAL_FD 1000
  61. X
  62. X#define MAXCOMMSTRSIZE 250
  63. X#define COMMANDSIZE 42
  64. X#define MAXARGS 256
  65. X
  66. X#define CHAR_CURR_SCOPE ':'    /* for getplace */
  67. X
  68. X#define RTEMP       0        /* regular temp for planet */
  69. X#define TEMP       1        /* temperature */
  70. X#define METHANE   2        /* %age of gases for terraforming */
  71. X#define OXYGEN       3
  72. X#define CO2       4
  73. X#define HYDROGEN  5
  74. X#define NITROGEN  6
  75. X#define SULFUR       7
  76. X#define HELIUM       8
  77. X#define OTHER       9
  78. X#define TOXIC     10
  79. X
  80. X#define CHAR_LAND         '*'
  81. X#define CHAR_SEA         '.'
  82. X#define CHAR_MOUNT         '^'
  83. X#define CHAR_DIFFOWNED         '?'
  84. X#define CHAR_PLATED         'o'
  85. X#define CHAR_WASTED         '%'
  86. X#define CHAR_GAS         '~'
  87. X#define CHAR_CLOAKED         ' '
  88. X#define CHAR_ICE        '#'
  89. X#define CHAR_CRYSTAL        'x'
  90. X#define CHAR_DESERT        '-'
  91. X#define CHAR_FOREST        ')'
  92. X
  93. X#define CHAR_MY_TROOPS        'X'
  94. X#define CHAR_ALLIED_TROOPS    'A'
  95. X#define CHAR_ATWAR_TROOPS    'E'
  96. X#define CHAR_NEUTRAL_TROOPS    'N'
  97. X
  98. X/* 3.0 feature */
  99. X#define LIMITED_RESOURCES    1 /* set to 0 if you want unlimited resource
  100. X                     availability (pre 3.0)*/
  101. X
  102. X#define NAMESIZE 18
  103. X#define RNAMESIZE 35
  104. X#define MOTTOSIZE 64
  105. X#define PERSONALSIZE 128
  106. X#define PLACENAMESIZE (NAMESIZE + NAMESIZE + 13)
  107. X#define NUMSTARS 256
  108. X#define MAXPLANETS 10
  109. X/*#define MAXMOONS 3*/
  110. X
  111. X
  112. X#define MAX_X 45    /* top range for planet */
  113. X#define MAX_Y 19
  114. X#define RATIOXY 3.70        /* map ratio between x and y */
  115. X                /* ranges of map sizes (x usually ) */
  116. X
  117. X
  118. X#define UNIVSIZE    150000
  119. X#define SYSTEMSIZE    2000
  120. X#define PLORBITSIZE    50
  121. X
  122. X#define WEEKLY        300
  123. X#define DAILY        180
  124. X
  125. X#define VICTORY_PERCENT    10
  126. X#define VICTORY_UPDATES    5
  127. X
  128. X#define AUTO_TELEG_SIZE        2000
  129. X#define UNTRANS_MSG        "[ ? ]"
  130. X/*#define TELEG_TRANS_APCOST    1*/
  131. X#define TELEG_TRANS_RPCOST    5
  132. X#define TELEG_TRANS_AMT        0.45
  133. X#define TELEG_LETTERS        7
  134. X#define TELEG_PLAYER_AUTO    (-2)
  135. X#define TELEG_MAX_AUTO        7   /* when changing, alter field in plinfo */
  136. X#define TELEG_DELIM        '~'
  137. X#define TELEG_NDELIM        "%[^~]"
  138. X
  139. X#define MASS_FUEL     0.05
  140. X#define MASS_RESOURCE     0.1
  141. X#define MASS_DESTRUCT     0.15
  142. X#define MASS_ARMOR    1.0
  143. X#define MASS_SIZE    0.2
  144. X#define MASS_HANGER    0.1
  145. X#define MASS_GUNS    0.2
  146. X
  147. X#define SIZE_GUNS    0.1
  148. X#define SIZE_CREW    0.01
  149. X#define SIZE_RESOURCE    0.02
  150. X#define SIZE_FUEL    0.01
  151. X#define SIZE_DESTRUCT    0.02
  152. X#define SIZE_HANGER    0.1
  153. X
  154. X/* Constants for Factory mass and size */
  155. X#define HAB_FACT_SIZE  0.2
  156. X
  157. X/* Cost factors for factory activation cost */
  158. X#define HAB_FACT_ON_COST        4
  159. X#define PLAN_FACT_ON_COST       2
  160. X
  161. X#define SECTOR_DAMAGE    0.3
  162. X#define SHIP_DAMAGE    2.0
  163. X
  164. X#define VN_RES_TAKE    0.5    /* amt of resource of a sector the VN's take */
  165. X
  166. X#define LAUNCH_GRAV_MASS_FACTOR 0.18    /* fuel use modifier for taking off */
  167. X#define LAND_GRAV_MASS_FACTOR 0.0145
  168. X
  169. X#define FUEL_GAS_ADD 5.0    /* amt of fuel to add to ea ships tanks */
  170. X#define FUEL_GAS_ADD_TANKER 100.0
  171. X#define FUEL_GAS_ADD_HABITAT 200.0
  172. X#define FUEL_GAS_ADD_STATION 100.0
  173. X#define FUEL_USE 0.02        /* fuel use per ship mass pt. per speed
  174. X                   factor */
  175. X#define HABITAT_PROD_RATE        0.05
  176. X#define HABITAT_POP_RATE        0.20
  177. X
  178. X#define REPAIR_RATE 25.0    /* rate at which ships get repaired */
  179. X#define SECTOR_REPAIR_COST 10 /* how much it costs to remove a wasted status from a sector */
  180. X#define NATURAL_REPAIR    5    /* chance of the wasted status being removed/update */
  181. X
  182. X#define CREAT_UNIV_ITERAT 10    /* iterations for star movement */
  183. X
  184. X
  185. X#define GRAV_FACTOR 0.0025    /* not sure as to what this should be*/
  186. X
  187. X
  188. X#define FACTOR_FERT_SUPPORT 1
  189. X                   /* # of people/fert pt sector supports*/
  190. X#define EFF_PROD         0.20        /* production of effcncy/pop*/
  191. X#define RESOURCE_PRODUCTION     0.00008 /* adjust these to change prod*/
  192. X#define FUEL_PRODUCTION        0.00008
  193. X
  194. X#define DEST_PRODUCTION     0.00008
  195. X#define POPN_PROD        0.3
  196. X
  197. X#define HYPER_DRIVE_READY_CHARGE 1
  198. X#define HYPER_DRIVE_FUEL_USE 5.0
  199. X#define HYPER_DIST_FACTOR 200.0
  200. X
  201. X#define TECH_INVEST        0.01    /* invest factor */
  202. X#define TECH_SCALE        2.0 /* investment scale */
  203. X
  204. X#define MOB_COST        0.00   /* mobiliz.c, doplanet.c cost/mob points*/
  205. X/*#define RESOURCE_DEPLETION     0.015 */
  206. X#define RESOURCE_DEPLETION      0.0
  207. X#define FACTOR_MOBPROD         0.06    /* mobilization production/person */
  208. X#define MESO_POP_SCALE        20000.0
  209. X
  210. X#define FUEL_COST_TERRA        3.0    /* cost to terraform */
  211. X#define FUEL_COST_QUARRY    2.0    /* cost to mine resources */
  212. X#define FUEL_COST_PLOW        2.0
  213. X#define RES_COST_DOME        1
  214. X#define RES_COST_WPLANT        1
  215. X#define FUEL_COST_WPLANT    1.0
  216. X
  217. X#define ENLIST_TROOP_COST    5    /* money it costs to pay a trooper */
  218. X#define UPDATE_TROOP_COST    1
  219. X
  220. X#define PLAN_FIRE_LIM        20    /* max fire strength from planets */
  221. X
  222. X#define TECH_SEE_STABILITY 15    /* min tech to see star stability */
  223. X
  224. X#define TECH_EXPLORE        10    /* min tech to see your whole planet */
  225. X
  226. X#define ENVIR_DAMAGE_TOX    70
  227. X    /* min tox to damage planet */
  228. X
  229. X#define PLANETGRAVCONST     0.05
  230. X#define SYSTEMGRAVCONST     150000.0
  231. X
  232. X
  233. X#define FUEL_MANEUVER    0.3    /* order.c-- fuel it costs to change aim */
  234. X#define DIST_TO_LAND     10.0     /* moveship.c,land.c -- */
  235. X#define DIST_TO_DOCK     10.0     /* changed to fix a bug. Maarten */
  236. X/* description: you could when you just entered planet scope assaault/dock
  237. X   with a ship in close orbit, and then immediately land. */
  238. X
  239. X/*#define DIST_TO_BURN 50     /* distance from sun needed to destroy ship */
  240. X
  241. X
  242. X#define FACTOR_DAMAGE         2.0
  243. X#define FACTOR_DESTPLANET     0.35
  244. X
  245. X    /* various compiler options that may save cpu time/disk space */
  246. X#define NO_SLIDING_SCALE_AUTOMOVE 0    /* move to all four adjacent spots */
  247. X#define POPN_MOVE_SCALE_1 400        /* limit at which popn moves to all */
  248. X#define POPN_MOVE_SCALE_2 3000        /* " " " popn moves to 2 adj. spaces */
  249. X                    /* otherwise move to only 1 adj. space*/
  250. X#define SHIP_MOVE_SCALE 3.0
  251. X
  252. X#define reg register
  253. X /* to save object code */
  254. X#define getchr() fgetc(stdin)
  255. X#define putchr(c) fputc((c),stdout)
  256. X/* assorted macros */
  257. X /* sign,abs val of number */
  258. X#define sgn(x) ( ((x)>=0) ? 1 : -1)
  259. X#define abs(x) ( ( (x)<0) ? -(x) : (x) )
  260. X#define MIN(x,y) ( ((x)>(y)) ? (y) : (x) )
  261. X#define MAX(x,y) ( ((x)<(y)) ? (y) : (x) )
  262. X /* positive modulus */
  263. X#define mod(a,b,dum) ((dum)=(a)%(b),abs(dum))
  264. X /* swap two variables */
  265. X#define    swap(a, b)  ((a) ^= (b), (b) ^= (a), (a) ^= (b))
  266. X /* euclidean distance */
  267. X#define Distsq(x1,y1,x2,y2) ( ((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2)) )
  268. X
  269. X/* look up sector */
  270. X#define Sector(pl,x,y) (Smap[(x) + (y)*(pl).Maxx])
  271. X/* adjust temperature to displayed */
  272. X#define Temp(x) ((int)(x))
  273. X
  274. X /* number of AP's to add to each player in ea. system */
  275. X /*   (look in doturn)  */
  276. X#define LIMIT_APs 255    /* max # of APs you can have */
  277. X
  278. X#define TYPE_EARTH     0
  279. X#define TYPE_ASTEROID     1
  280. X#define TYPE_MARS     2
  281. X#define TYPE_ICEBALL    3
  282. X#define TYPE_GASGIANT     4
  283. X#define TYPE_WATER    5
  284. X#define TYPE_FOREST    6
  285. X#define TYPE_DESERT    7
  286. X
  287. X/* number of global APs each planet is worth */
  288. X#define EARTH_POINTS    int_rand(5,8)
  289. X#define ASTEROID_POINTS    1
  290. X#define MARS_POINTS    int_rand(2,3)
  291. X#define ICEBALL_POINTS    int_rand(2,3)
  292. X#define GASGIANT_POINTS    int_rand(8,20)
  293. X#define WATER_POINTS    int_rand(2,3)
  294. X#define FOREST_POINTS    int_rand(2,3)
  295. X#define DESERT_POINTS    int_rand(2,3)
  296. X
  297. X#define SEA     0
  298. X#define LAND     1
  299. X#define MOUNT     2
  300. X#define GAS     3
  301. X#define ICE    4
  302. X#define FOREST    5
  303. X#define DESERT    6
  304. X#define PLATED     7
  305. X#define WASTED    8
  306. X
  307. X#define CIV        0
  308. X#define MIL        1
  309. X
  310. X#define MAX_SECT_POPN 32767
  311. X
  312. X#define TOXMAX        20    /* max a toxwc can hold */
  313. X
  314. X#define SIGBLOCKS (SIGHUP|SIGTERM|SIGINT|SIGQUIT|SIGSTOP|SIGTSTP)
  315. X                /* signals to block... */
  316. X
  317. X#define Bzero(x)  bzero( (char *)&(x), sizeof(x) )
  318. X#define Malloc(x) (x *)malloc( sizeof(x) )
  319. X
  320. X
  321. X#define _STDLIB_H    /* for compiling on NeXt machines */
  322. X
  323. X#define RESOURCE 0  /* for market */
  324. X#define DESTRUCT 1
  325. X#define FUEL     2
  326. X#define CRYSTAL  3
  327. X
  328. X#define MERCHANT_LENGTH    200000.0
  329. X#define INCOME_FACTOR    0.002
  330. X#define INSURG_FACTOR    1
  331. X#define UP_BID        0.10
  332. X
  333. X#define GUN_COST    1.00
  334. X#define CREW_COST          0.05
  335. X#define CARGO_COST    0.05
  336. X#define FUEL_COST    0.05
  337. X#define AMMO_COST    0.05
  338. X#define SPEED_COST    0.50
  339. X#define CEW_COST    0.003
  340. X#define ARMOR_COST    3.50
  341. X#define HANGER_COST    0.50
  342. X
  343. X#define AFV_FUEL_COST    1.0
  344. X
  345. X#define MECH_ATTACK    3.0
  346. X
  347. X# define VICT_SECT     1000
  348. X# define VICT_SHIP      333
  349. X# define VICT_TECH      .10
  350. X# define VICT_MORALE      200
  351. X# define VICT_RES      100
  352. X# define VICT_FUEL       15
  353. X# define VICT_MONEY        5
  354. X# define VICT_DIVISOR    10000
  355. X
  356. X#define STRIKE_DISTANCE_FACTOR    5.5
  357. X#define COMPLEXITY_FACTOR    10.0  /* determines steepness of design complexity function */
  358. X
  359. X#define REPEAT_CHARACTER ' '    /* this character makes the previous command to
  360. X                   repeat */
  361. X#define MAXGOVERNORS    5
  362. X#define POD_THRESHOLD    18
  363. X#define POD_DECAY    4
  364. X#define AP_FACTOR    50.0    /* how planet size affects the rate of atmosphere processing */
  365. X#define DISSIPATE    80    /* updates to dissipate dust and gases */
  366. X
  367. END_OF_FILE
  368. if test 9356 -ne `wc -c <'hdrs/tweakables.h'`; then
  369.     echo shar: \"'hdrs/tweakables.h'\" unpacked with wrong size!
  370. fi
  371. # end of 'hdrs/tweakables.h'
  372. fi
  373. if test -f 'server/getplace.c' -a "${1}" != "-c" ; then 
  374.   echo shar: Will not clobber existing file \"'server/getplace.c'\"
  375. else
  376. echo shar: Extracting \"'server/getplace.c'\" \(7768 characters\)
  377. sed "s/^X//" >'server/getplace.c' <<'END_OF_FILE'
  378. X/*
  379. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  380. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  381. X * GB_copyright.h.
  382. X * 
  383. X * Getplace -- returns directory level from string and current Dir Dispplace --
  384. X * returns string from directory level testship(ship) -- tests various things
  385. X * for the ship.
  386. X */
  387. X
  388. X#include <ctype.h>
  389. X
  390. X#include "GB_copyright.h"
  391. X#define EXTERN extern
  392. X#include "vars.h"
  393. X#include "races.h"
  394. X#include "ships.h"
  395. X#include "power.h"
  396. X#include "buffers.h"
  397. X
  398. Xchar            Disps[PLACENAMESIZE];
  399. Xplacetype       Getplace(int, int, char *, int);
  400. Xplacetype       Getplace2(int, int, char *, placetype *, int, int);
  401. Xchar           *Dispshiploc_brief(shiptype *);
  402. Xchar           *Dispshiploc(shiptype *);
  403. Xchar           *Dispplace(int, int, placetype *);
  404. Xint             testship(int, int, shiptype *);
  405. X#include "proto.h"
  406. X
  407. Xplacetype 
  408. XGetplace(int Playernum, int Governor, char *string, int ignoreexpl)
  409. X{
  410. X    placetype       where;    /* return value */
  411. X    racetype       *Race;
  412. X    int             God;
  413. X
  414. X    Bzero(where);
  415. X
  416. X    Race = races[Playernum - 1];
  417. X    God = Race->God;
  418. X
  419. X    where.err = 0;
  420. X
  421. X    switch (*string) {
  422. X    case '/':
  423. X        where.level = LEVEL_UNIV;    /* scope = root (universe) */
  424. X        where.snum = 0;
  425. X        where.pnum = where.shipno = 0;
  426. X        return (Getplace2(Playernum, Governor, string + 1, &where, ignoreexpl, God));
  427. X    case '#':
  428. X        sscanf(++string, "%hd", &where.shipno);
  429. X        if (!getship(&where.shipptr, where.shipno)) {
  430. X            DontOwnErr(Playernum, Governor, where.shipno);
  431. X            where.err = 1;
  432. X            return where;
  433. X        }
  434. X        if ((where.shipptr->owner == Playernum || ignoreexpl || God)
  435. X            && (where.shipptr->alive || God)) {
  436. X            where.level = LEVEL_SHIP;
  437. X            where.snum = where.shipptr->storbits;
  438. X            where.pnum = where.shipptr->pnumorbits;
  439. X            free(where.shipptr);
  440. X            return where;
  441. X        } else {
  442. X            where.err = 1;
  443. X            free(where.shipptr);
  444. X            return where;
  445. X        }
  446. X    case '-':
  447. X        /* no destination */
  448. X        where.level = LEVEL_UNIV;
  449. X        return where;
  450. X    default:
  451. X        /* copy current scope to scope */
  452. X        where.level = Dir[Playernum - 1][Governor].level;
  453. X        where.snum = Dir[Playernum - 1][Governor].snum;
  454. X        where.pnum = Dir[Playernum - 1][Governor].pnum;
  455. X        if (where.level == LEVEL_SHIP)
  456. X            where.shipno = Dir[Playernum - 1][Governor].shipno;
  457. X        if (*string == CHAR_CURR_SCOPE)
  458. X            return where;
  459. X        else
  460. X            return Getplace2(Playernum, Governor, string, &where, ignoreexpl, God);
  461. X    }
  462. X}
  463. X
  464. Xplacetype 
  465. XGetplace2(int Playernum, int Governor, char *string,
  466. X      placetype * where, int ignoreexpl, int God)
  467. X{
  468. X    char            substr[NAMESIZE];
  469. X    planettype     *p;
  470. X    register int    i, l;
  471. X    int             tick;
  472. X
  473. X    if (where->err || *string == '\0' || *string == '\n')
  474. X        return (*where);/* base cases */
  475. X    else if (*string == '.') {
  476. X        if (where->level == LEVEL_UNIV) {
  477. X            sprintf(buf, "Can't go higher.\n");
  478. X            notify(Playernum, Governor, buf);
  479. X            where->err = 1;
  480. X            return (*where);
  481. X        } else {
  482. X            if (where->level == LEVEL_SHIP) {
  483. X                (void) getship(&where->shipptr, where->shipno);
  484. X                where->level = where->shipptr->whatorbits;
  485. X                /* Fix 'cs .' for ships within ships. Maarten */
  486. X                if (where->level == LEVEL_SHIP)
  487. X                    where->shipno = where->shipptr->destshipno;
  488. X                free(where->shipptr);
  489. X            } else
  490. X                where->level--;
  491. X            while (*string == '.')
  492. X                string++;
  493. X            while (*string == '/')
  494. X                string++;
  495. X            return (Getplace2(Playernum, Governor, string, where, ignoreexpl, God));
  496. X        }
  497. X    } else {
  498. X        /* is a char string, name of something */
  499. X        sscanf(string, "%[^/ \n]", substr);
  500. X        do {
  501. X            /*
  502. X             * if (isupper(*string) ) (*string) =
  503. X             * tolower(*string);
  504. X             */
  505. X            string++;
  506. X        } while (*string != '/' && *string != '\n' && *string != '\0');
  507. X        l = strlen(substr);
  508. X        if (where->level == LEVEL_UNIV) {
  509. X            for (i = 0; i < Sdata.numstars; i++)
  510. X                if (!strncmp(substr, Stars[i]->name, l)) {
  511. X                    where->level = LEVEL_STAR;
  512. X                    where->snum = i;
  513. X                    if (ignoreexpl ||
  514. X                        isset(Stars[where->snum]->explored, Playernum) || God) {
  515. X                        tick = (*string == '/');
  516. X                        return (Getplace2(Playernum, Governor, string + tick, where, ignoreexpl, God));
  517. X                    }
  518. X                    sprintf(buf, "You have not explored %s yet.\n",
  519. X                        Stars[where->snum]->name);
  520. X                    notify(Playernum, Governor, buf);
  521. X                    where->err = 1;
  522. X                    return (*where);
  523. X                }
  524. X            if (i >= Sdata.numstars) {
  525. X                sprintf(buf, "No such star %s.\n", substr);
  526. X                notify(Playernum, Governor, buf);
  527. X                where->err = 1;
  528. X                return (*where);
  529. X            }
  530. X        } else if (where->level == LEVEL_STAR) {
  531. X            for (i = 0; i < Stars[where->snum]->numplanets; i++)
  532. X                if ((!strncmp(substr, Stars[where->snum]->pnames[i], l)) ||
  533. X                    atoi(substr) == i+1) /* JPD && SKF */ {
  534. X                    where->level = LEVEL_PLAN;
  535. X                    where->pnum = i;
  536. X                    getplanet(&p, (int) where->snum, i);
  537. X                    if (ignoreexpl || p->info[Playernum - 1].explored || God) {
  538. X                        free(p);
  539. X                        tick = (*string == '/');
  540. X                        return (Getplace2(Playernum, Governor, string + tick, where, ignoreexpl, God));
  541. X                    }
  542. X                    sprintf(buf, "You have not explored %s yet.\n",
  543. X                         Stars[where->snum]->pnames[i]);
  544. X                    notify(Playernum, Governor, buf);
  545. X                    where->err = 1;
  546. X                    free(p);
  547. X                    return (*where);
  548. X                }
  549. X            if (i >= Stars[where->snum]->numplanets) {
  550. X                sprintf(buf, "No such planet %s.\n", substr);
  551. X                notify(Playernum, Governor, buf);
  552. X                where->err = 1;
  553. X                return (*where);
  554. X            }
  555. X        } else {
  556. X            sprintf(buf, "Can't descend to %s.\n", substr);
  557. X            notify(Playernum, Governor, buf);
  558. X            where->err = 1;
  559. X            return (*where);
  560. X        }
  561. X    }
  562. X}
  563. X
  564. Xchar           *
  565. XDispshiploc_brief(shiptype * ship)
  566. X{
  567. X    int             i;
  568. X
  569. X    switch (ship->whatorbits) {
  570. X    case LEVEL_STAR:
  571. X        sprintf(Disps, "/%-4.4s", Stars[ship->storbits]->name);
  572. X        return (Disps);
  573. X    case LEVEL_PLAN:
  574. X        sprintf(Disps, "/%s", Stars[ship->storbits]->name);
  575. X        for (i = 2; (Disps[i] && (i < 5)); i++);
  576. X        sprintf(Disps + i, "/%-4.4s",
  577. X            Stars[ship->storbits]->pnames[ship->pnumorbits]);
  578. X        return (Disps);
  579. X    case LEVEL_SHIP:
  580. X        sprintf(Disps, "#%d", ship->destshipno);
  581. X        return (Disps);
  582. X    case LEVEL_UNIV:
  583. X        strcat(Disps, "/");
  584. X        return (Disps);
  585. X    default:
  586. X        strcat(Disps, "error");
  587. X        return (Disps);
  588. X    }
  589. X}
  590. X
  591. Xchar           *
  592. XDispshiploc(shiptype * ship)
  593. X{
  594. X    switch (ship->whatorbits) {
  595. X        case LEVEL_STAR:
  596. X        sprintf(Disps, "/%s", Stars[ship->storbits]->name);
  597. X        return (Disps);
  598. X    case LEVEL_PLAN:
  599. X        sprintf(Disps, "/%s/%s", Stars[ship->storbits]->name,
  600. X            Stars[ship->storbits]->pnames[ship->pnumorbits]);
  601. X        return (Disps);
  602. X    case LEVEL_SHIP:
  603. X        sprintf(Disps, "#%d", ship->destshipno);
  604. X        return (Disps);
  605. X    case LEVEL_UNIV:
  606. X        sprintf(Disps, "/");
  607. X        return (Disps);
  608. X    default:
  609. X        sprintf(Disps, "error");
  610. X        return (Disps);
  611. X    }
  612. X}
  613. X
  614. Xchar           *
  615. XDispplace(int Playernum, int Governor, placetype * where)
  616. X{
  617. X    switch (where->level) {
  618. X        case LEVEL_STAR:
  619. X        sprintf(Disps, "/%s", Stars[where->snum]->name);
  620. X        return (Disps);
  621. X    case LEVEL_PLAN:
  622. X        sprintf(Disps, "/%s/%s", Stars[where->snum]->name,
  623. X            Stars[where->snum]->pnames[where->pnum]);
  624. X        return (Disps);
  625. X    case LEVEL_SHIP:
  626. X        sprintf(Disps, "#%d", where->shipno);
  627. X        return (Disps);
  628. X    case LEVEL_UNIV:
  629. X        return ("/");
  630. X    default:
  631. X        sprintf(buf, "illegal Dispplace val = %d\n", where->level);
  632. X        notify(Playernum, Governor, buf);
  633. X        where->err = 1;
  634. X        return ("/");
  635. X    }
  636. X}
  637. X
  638. Xint 
  639. Xtestship(int Playernum, int Governor, shiptype * s)
  640. X{
  641. X    reg int         r;
  642. X
  643. X    r = 0;
  644. X
  645. X    if (!s->alive) {
  646. X        sprintf(buf, "%s has been destroyed.\n", Ship(s));
  647. X        notify(Playernum, Governor, buf);
  648. X        r = 1;
  649. X    } else if (s->owner != Playernum || !authorized(Governor, s)) {
  650. X        DontOwnErr(Playernum, Governor, (int) s->number);
  651. X        r = 1;
  652. X    } else {
  653. X        if (!s->active) {
  654. X            sprintf(buf, "%s is irradiated %d%% and inactive.\n", Ship(s), s->rad);
  655. X            notify(Playernum, Governor, buf);
  656. X            r = 1;
  657. X        }
  658. X        /*
  659. X         * if (!s->popn && s->max_crew) { sprintf(buf,"%s has no crew
  660. X         * and is not a robotic ship.\n", Ship(s)); notify(Playernum,
  661. X         * Governor, buf); r = 1; }
  662. X         */
  663. X    }
  664. X    return r;
  665. X}
  666. END_OF_FILE
  667. if test 7768 -ne `wc -c <'server/getplace.c'`; then
  668.     echo shar: \"'server/getplace.c'\" unpacked with wrong size!
  669. fi
  670. # end of 'server/getplace.c'
  671. fi
  672. if test -f 'user/fuel.c' -a "${1}" != "-c" ; then 
  673.   echo shar: Will not clobber existing file \"'user/fuel.c'\"
  674. else
  675. echo shar: Extracting \"'user/fuel.c'\" \(9244 characters\)
  676. sed "s/^X//" >'user/fuel.c' <<'END_OF_FILE'
  677. X/*
  678. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  679. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  680. X * GB_copyright.h.
  681. X * 
  682. X * fuel.c -- See estimations in fuel consumption and travel time.
  683. X * 
  684. X * Programmed by varneyml@gb.dorm.clarkson.edu
  685. X */
  686. X
  687. X#include <math.h>
  688. X#include <time.h>
  689. X
  690. X#include "GB_copyright.h"
  691. X#define EXTERN extern
  692. X#include "vars.h"
  693. X#include "ships.h"
  694. X#include "races.h"
  695. X#include "power.h"
  696. X
  697. X/*
  698. X * extern long next_segment_time; extern long next_update_time; extern long
  699. X * nsegments_done; extern int update_time;
  700. X */
  701. X
  702. Xchar            plan_buf[1024];
  703. X
  704. Xint             number_segments;
  705. Xdouble          x_0, y_0, x_1, y_1;
  706. Xshiptype       *tmpship;
  707. Xplacetype       tmpdest;
  708. X
  709. Xvoid            proj_fuel(int, int, int);
  710. Xvoid            fuel_output(int, int, double, double, double, double, int);
  711. Xint             do_trip(double, double);
  712. X#include "proto.h"
  713. X
  714. Xvoid 
  715. Xproj_fuel(int Playernum, int Governor, int APcount)
  716. X{
  717. X    int             shipno, trip_resolved, opt_settings, current_settings,
  718. X                    current_segs, computing = 1;
  719. X    double          fuel_usage, level, dist;
  720. X    shiptype       *ship;
  721. X    planettype     *p;
  722. X    char            buf[1024];
  723. X    double          current_fuel = 0.0, gravity_factor = 0.0, gravity_fuel = 0.0;
  724. X
  725. X    if ((argn < 2) || (argn > 3)) {
  726. X        notify(Playernum, Governor, "Invalid number of options.\n\"fuel #<shipnumber> [destination]\"...\n");
  727. X        return;
  728. X    }
  729. X    if (args[1][0] != '#') {
  730. X        notify(Playernum, Governor, "Invalid first option.\n\"fuel #<shipnumber> [destination]\"...\n");
  731. X        return;
  732. X    }
  733. X    sscanf(args[1] + (args[1][0] == '#'), "%d", &shipno);
  734. X    if (shipno > Numships() || shipno < 1) {
  735. X        sprintf(buf, "rst: no such ship #%d \n", shipno);
  736. X        notify(Playernum, Governor, buf);
  737. X        return;
  738. X    }
  739. X    (void) getship(&ship, shipno);
  740. X    if (ship->owner != Playernum) {
  741. X        notify(Playernum, Governor, "You do not own this ship.\n");
  742. X        free(ship);
  743. X        return;
  744. X    }
  745. X    if (landed(ship) && (argn == 2)) {
  746. X        notify(Playernum, Governor, "You must specify a destination for landed or docked ships...\n");
  747. X        free(ship);
  748. X        return;
  749. X    }
  750. X    if (!ship->speed) {
  751. X        notify(Playernum, Governor, "That ship is not moving!\n");
  752. X        free(ship);
  753. X        return;
  754. X    }
  755. X    if ((!speed_rating(ship)) || (ship->type == OTYPE_FACTORY)) {
  756. X        notify(Playernum, Governor, "That ship does not have a speed rating...\n");
  757. X        free(ship);
  758. X        return;
  759. X    }
  760. X    if (landed(ship) && (ship->whatorbits == LEVEL_PLAN)) {
  761. X        getplanet(&p, (int) ship->storbits, (int) ship->pnumorbits);
  762. X        gravity_factor = gravity(p);
  763. X        sprintf(plan_buf, "/%s/%s", Stars[(int) ship->storbits]->name,
  764. X        Stars[(int) ship->storbits]->pnames[(int) ship->pnumorbits]);
  765. X        free(p);
  766. X    }
  767. X    if (argn == 2)
  768. X        strcpy(args[2], prin_ship_dest(Playernum, Governor, ship));
  769. X    tmpdest = Getplace(Playernum, Governor, args[2], 1);
  770. X    if (tmpdest.err) {
  771. X        notify(Playernum, Governor, "fuel:  bad scope.\n");
  772. X        free(ship);
  773. X        return;
  774. X    }
  775. X    if (tmpdest.level == LEVEL_SHIP) {
  776. X        (void) getship(&tmpship, tmpdest.shipno);
  777. X        if (!followable(ship, tmpship)) {
  778. X            notify(Playernum, Governor, "The ship's destination is out of range.\n");
  779. X            free(tmpship);
  780. X            free(ship);
  781. X            return;
  782. X        }
  783. X        free(tmpship);
  784. X    }
  785. X    if (tmpdest.level != LEVEL_UNIV && tmpdest.level != LEVEL_SHIP &&
  786. X    ((ship->storbits != tmpdest.snum) && tmpdest.level != LEVEL_STAR) &&
  787. X        isclr(Stars[tmpdest.snum]->explored, ship->owner)) {
  788. X        notify(Playernum, Governor, "You haven't explored the destination system.\n");
  789. X        free(ship);
  790. X        return;
  791. X    }
  792. X    if (tmpdest.level == LEVEL_UNIV) {
  793. X        notify(Playernum, Governor, "Invalid ship destination.\n");
  794. X        free(ship);
  795. X        return;
  796. X    }
  797. X    x_0 = y_0 = x_1 = y_1 = 0.0;
  798. X
  799. X    x_0 = ship->xpos;
  800. X    y_0 = ship->ypos;
  801. X    free(ship);
  802. X
  803. X    if (tmpdest.level == LEVEL_UNIV) {
  804. X        notify(Playernum, Governor, "That ship currently has no destination orders...\n");
  805. X        return;
  806. X    }
  807. X    if (tmpdest.level == LEVEL_SHIP) {
  808. X        (void) getship(&tmpship, tmpdest.shipno);
  809. X        if (tmpship->owner != Playernum) {
  810. X            notify(Playernum, Governor, "Nice try.\n");
  811. X            return;
  812. X        }
  813. X        x_1 = tmpship->xpos;
  814. X        y_1 = tmpship->ypos;
  815. X        free(tmpship);
  816. X    } else if (tmpdest.level == LEVEL_PLAN) {
  817. X        getplanet(&p, (int) tmpdest.snum, (int) tmpdest.pnum);
  818. X        x_1 = p->xpos + Stars[tmpdest.snum]->xpos;
  819. X        y_1 = p->ypos + Stars[tmpdest.snum]->ypos;
  820. X        free(p);
  821. X    } else if (tmpdest.level == LEVEL_STAR) {
  822. X        x_1 = Stars[tmpdest.snum]->xpos;
  823. X        y_1 = Stars[tmpdest.snum]->ypos;
  824. X    } else
  825. X        printf("ERROR 99\n");
  826. X
  827. X    /* compute the distance */
  828. X    dist = sqrt(Distsq(x_0, y_0, x_1, y_1));
  829. X
  830. X    if (dist <= DIST_TO_LAND) {
  831. X        notify(Playernum, Governor, "That ship is within 10.0 units of the destination.\n");
  832. X        return;
  833. X    }
  834. X    /* First get the results based on current fuel load.  */
  835. X    (void) getship(&tmpship, shipno);
  836. X    level = tmpship->fuel;
  837. X    current_settings = do_trip(tmpship->fuel, gravity_factor);
  838. X    current_segs = number_segments;
  839. X    if (current_settings)
  840. X        current_fuel = level - tmpship->fuel;
  841. X
  842. X    /* 2nd loop to determine lowest fuel needed...  */
  843. X    fuel_usage = level = tmpship->max_fuel;
  844. X    opt_settings = 0;
  845. X    while (computing) {
  846. X        (void) getship(&tmpship, shipno);
  847. X        computing = do_trip(level, gravity_factor);
  848. X        if ((computing) && (tmpship->fuel >= 0.05)) {
  849. X            fuel_usage = level;
  850. X            opt_settings = 1;
  851. X            level -= tmpship->fuel;
  852. X        } else if (computing) {
  853. X            computing = 0;
  854. X            fuel_usage = level;
  855. X        }
  856. X    }
  857. X
  858. X    (void) getship(&tmpship, shipno);
  859. X    sprintf(buf, "\n  ----- ===== FUEL ESTIMATES ===== ----\n\nAt Current Fuel Cargo (%.2ff):\n", tmpship->fuel);
  860. X    domass(tmpship);
  861. X    notify(Playernum, Governor, buf);
  862. X    if (!current_settings) {
  863. X        sprintf(buf, "The ship will not be able to complete the trip.\n");
  864. X        notify(Playernum, Governor, buf);
  865. X    } else
  866. X        fuel_output(Playernum, Governor, dist, current_fuel, gravity_factor, tmpship->mass, current_segs);
  867. X    sprintf(buf, "At Optimum Fuel Level (%.2ff):\n", fuel_usage);
  868. X    notify(Playernum, Governor, buf);
  869. X    if (!opt_settings) {
  870. X        sprintf(buf, "The ship will not be able to complete the trip.\n");
  871. X        notify(Playernum, Governor, buf);
  872. X    } else {
  873. X        tmpship->fuel = fuel_usage;
  874. X        domass(tmpship);
  875. X        fuel_output(Playernum, Governor, dist, fuel_usage, gravity_factor, tmpship->mass, number_segments);
  876. X    }
  877. X    free(tmpship);
  878. X}
  879. X
  880. X
  881. Xvoid 
  882. Xfuel_output(int Playernum, int Governor, double dist, double fuel,
  883. X        double grav, double mass, int segs)
  884. X{
  885. X    long            effective_time;
  886. X    double          gravity_fuel = 0.0;
  887. X    char            buf[1024], grav_buf[1024];
  888. X
  889. X    if (grav > 0.00)
  890. X        sprintf(grav_buf, " (%.2f used to launch from %s)\n",
  891. X          (double) (grav * mass * (double) LAUNCH_GRAV_MASS_FACTOR),
  892. X            plan_buf);
  893. X    else
  894. X        sprintf(grav_buf, " ");
  895. X    sprintf(buf, "Total Distance = %.2f   Number of Segments = %d\nFuel = %.2f%s  ", dist, segs, fuel, grav_buf);
  896. X    notify(Playernum, Governor, buf);
  897. X    if (nsegments_done > segments)
  898. X        notify(Playernum, Governor, "Estimated arrival time not available due to segment # discrepancy.\n");
  899. X    else {
  900. X        effective_time = next_segment_time + (long) ((segs - 1) * (update_time / segments) * 60);
  901. X        if (segments == 1)
  902. X            effective_time = next_update_time + (long) ((segs - 1) * (update_time * 60));
  903. X        sprintf(buf, "ESTIMATED Arrival Time: %s\n", ctime(&effective_time));
  904. X        notify(Playernum, Governor, buf);
  905. X        return;
  906. X    }
  907. X}
  908. X
  909. Xint 
  910. Xdo_trip(double fuel, double gravity_factor)
  911. X{
  912. X    int             effective_segment_number, trip_resolved, i;
  913. X    double          gravity_fuel, tmpdist, fuel_level1;
  914. X
  915. X    tmpship->fuel = fuel;    /* load up the pseudo-ship */
  916. X    effective_segment_number = nsegments_done;
  917. X
  918. X    /* Set our temporary destination.... */
  919. X    tmpship->destshipno = (unsigned short) tmpdest.shipno;
  920. X    tmpship->whatdest = tmpdest.level;
  921. X    tmpship->deststar = tmpdest.snum;
  922. X    tmpship->destpnum = tmpdest.pnum;
  923. X    if (tmpship->whatdest == LEVEL_SHIP || tmpship->ships) {
  924. X        /* Bring in the other ships.  Moveship() uses ships[]. */
  925. X        Num_ships = Numships();
  926. X        ships = (shiptype **) malloc(sizeof(shiptype *) * (Num_ships) + 1);
  927. X        for (i = 1; i <= Num_ships; i++)
  928. X            (void) getship(&ships[i], i);
  929. X    }
  930. X    trip_resolved = 0;
  931. X    number_segments = 0;    /* Reset counter.  */
  932. X
  933. X    /* Launch the ship if it's on a planet.  */
  934. X    gravity_fuel = gravity_factor * tmpship->mass * LAUNCH_GRAV_MASS_FACTOR;
  935. X    tmpship->fuel -= gravity_fuel;
  936. X    tmpship->docked = 0;
  937. X
  938. X    while (trip_resolved == 0) {
  939. X        domass(tmpship);
  940. X        fuel_level1 = tmpship->fuel;
  941. X        Moveship(tmpship, (effective_segment_number == segments), 0, 1);
  942. X        number_segments++;
  943. X        effective_segment_number++;
  944. X        if (effective_segment_number == (segments + 1))
  945. X            effective_segment_number = 1;
  946. X        x_0 = (double) tmpship->xpos;
  947. X        y_0 = (double) tmpship->ypos;
  948. X        tmpdist = sqrt(Distsq(x_0, y_0, x_1, y_1));
  949. X        switch ((int) tmpship->whatdest) {
  950. X        case LEVEL_STAR:
  951. X            if (tmpdist <= (double) SYSTEMSIZE)
  952. X                trip_resolved = 1;
  953. X            break;
  954. X        case LEVEL_PLAN:
  955. X            if (tmpdist <= (double) PLORBITSIZE)
  956. X                trip_resolved = 1;
  957. X            break;
  958. X        case LEVEL_SHIP:
  959. X            if (tmpdist <= (double) DIST_TO_LAND)
  960. X                trip_resolved = 1;
  961. X            break;
  962. X        default:
  963. X            trip_resolved = 1;
  964. X        }
  965. X        if (((tmpship->fuel == fuel_level1) && (!tmpship->hyper_drive.on)) && (trip_resolved == 0)) {
  966. X            if (tmpship->whatdest == LEVEL_SHIP) {
  967. X                for (i = 1; i <= Num_ships; i++)
  968. X                    free(ships[i]);
  969. X                free(ships);
  970. X            }
  971. X            return (0);
  972. X        }
  973. X    }
  974. X    if (tmpship->whatdest == LEVEL_SHIP || tmpship->ships) {
  975. X        for (i = 1; i <= Num_ships; i++)
  976. X            free(ships[i]);
  977. X        free(ships);
  978. X    }
  979. X    return (1);
  980. X}
  981. END_OF_FILE
  982. if test 9244 -ne `wc -c <'user/fuel.c'`; then
  983.     echo shar: \"'user/fuel.c'\" unpacked with wrong size!
  984. fi
  985. # end of 'user/fuel.c'
  986. fi
  987. if test -f 'user/launch.c' -a "${1}" != "-c" ; then 
  988.   echo shar: Will not clobber existing file \"'user/launch.c'\"
  989. else
  990. echo shar: Extracting \"'user/launch.c'\" \(7962 characters\)
  991. sed "s/^X//" >'user/launch.c' <<'END_OF_FILE'
  992. X/*
  993. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  994. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  995. X * GB_copyright.h.
  996. X * 
  997. X * launch.c -- launch or undock a ship (also undock)
  998. X */
  999. X
  1000. X#include "GB_copyright.h"
  1001. X#define EXTERN extern
  1002. X#include "vars.h"
  1003. X#include "ships.h"
  1004. X#include "races.h"
  1005. X#include "power.h"
  1006. X#include "buffers.h"
  1007. X#include <signal.h>
  1008. X
  1009. Xvoid            launch(int, int, int);
  1010. X#include "proto.h"
  1011. X
  1012. Xvoid 
  1013. Xlaunch(int Playernum, int Governor, int APcount)
  1014. X{
  1015. X    int             sh2;
  1016. X    shiptype       *s, *s2;
  1017. X    planettype     *p;
  1018. X    int             shipno, i, nextshipno;
  1019. X    double          fuel;
  1020. X
  1021. X    if (argn < 2) {
  1022. X        notify(Playernum, Governor, "Launch what?\n");
  1023. X        return;
  1024. X    }
  1025. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  1026. X
  1027. X    while (shipno = do_shiplist(&s, &nextshipno))
  1028. X        if (in_list(Playernum, args[1], s, &nextshipno) &&
  1029. X            authorized(Governor, s)) {
  1030. X            if (!speed_rating(s) && landed(s)) {
  1031. X                sprintf(buf, "That ship is not designed to be launched.\n");
  1032. X                notify(Playernum, Governor, buf);
  1033. X                free(s);
  1034. X                continue;
  1035. X            }
  1036. X            if (!(s->docked || s->whatorbits == LEVEL_SHIP)) {
  1037. X                sprintf(buf, "%s is not landed or docked.\n", Ship(s));
  1038. X                notify(Playernum, Governor, buf);
  1039. X                free(s);
  1040. X                continue;
  1041. X            }
  1042. X            if (!landed(s))
  1043. X                APcount = 0;
  1044. X            if (landed(s) && s->resource > Max_resource(s)) {
  1045. X                sprintf(buf, "%s is too overloaded to launch.\n", Ship(s));
  1046. X                notify(Playernum, Governor, buf);
  1047. X                free(s);
  1048. X                continue;
  1049. X            }
  1050. X            if (s->whatorbits == LEVEL_SHIP) {
  1051. X                /*
  1052. X                 * Factories cannot be launched once turned
  1053. X                 * on. Maarten
  1054. X                 */
  1055. X                if (s->type == OTYPE_FACTORY && s->on) {
  1056. X                    notify(Playernum, Governor, "Factories cannot be launched once turned on.\n");
  1057. X                    notify(Playernum, Governor, "Consider using 'scrap'.\n");
  1058. X                    free(s);
  1059. X                    continue;
  1060. X                }
  1061. X                sh2 = s->destshipno;
  1062. X                (void) getship(&s2, sh2);
  1063. X                if (landed(s2)) {
  1064. X                    remove_sh_ship(s, s2);
  1065. X                    getplanet(&p, (int) s2->storbits, (int) s2->pnumorbits);
  1066. X                    insert_sh_plan(p, s);
  1067. X                    putplanet(p, (int) s2->storbits, (int) s2->pnumorbits);
  1068. X                    s->storbits = s2->storbits;
  1069. X                    s->pnumorbits = s2->pnumorbits;
  1070. X                    s->destpnum = s2->pnumorbits;
  1071. X                    s->deststar = s2->deststar;
  1072. X                    s->xpos = s2->xpos;
  1073. X                    s->ypos = s2->ypos;
  1074. X                    s->land_x = s2->land_x;
  1075. X                    s->land_y = s2->land_y;
  1076. X                    s->docked = 1;
  1077. X                    s->whatdest = LEVEL_PLAN;
  1078. X                    s2->mass -= s->mass;
  1079. X                    s2->hanger -= Size(s);
  1080. X                    sprintf(buf, "Landed on %s/%s.\n", Stars[s->storbits]->name,
  1081. X                        Stars[s->storbits]->pnames[s->pnumorbits]);
  1082. X                    notify(Playernum, Governor, buf);
  1083. X                    free(p);
  1084. X                    putship(s);
  1085. X                    putship(s2);
  1086. X                } else if (s2->whatorbits == LEVEL_PLAN) {
  1087. X                    remove_sh_ship(s, s2);
  1088. X                    sprintf(buf, "%s launched from %s.\n", Ship(s), Ship(s2));
  1089. X                    notify(Playernum, Governor, buf);
  1090. X                    s->xpos = s2->xpos;
  1091. X                    s->ypos = s2->ypos;
  1092. X                    s->docked = 0;
  1093. X                    s->whatdest = LEVEL_UNIV;
  1094. X                    s2->mass -= s->mass;
  1095. X                    s2->hanger -= Size(s);
  1096. X                    getplanet(&p, (int) s2->storbits, (int) s2->pnumorbits);
  1097. X                    insert_sh_plan(p, s);
  1098. X                    s->storbits = s2->storbits;
  1099. X                    s->pnumorbits = s2->pnumorbits;
  1100. X                    putplanet(p, (int) s2->storbits, (int) s2->pnumorbits);
  1101. X                    sprintf(buf, "Orbiting %s/%s.\n", Stars[s->storbits]->name,
  1102. X                        Stars[s->storbits]->pnames[s->pnumorbits]);
  1103. X                    notify(Playernum, Governor, buf);
  1104. X                    free(p);
  1105. X                    putship(s);
  1106. X                    putship(s2);
  1107. X                } else if (s2->whatorbits == LEVEL_STAR) {
  1108. X                    remove_sh_ship(s, s2);
  1109. X                    sprintf(buf, "%s launched from %s.\n", Ship(s), Ship(s2));
  1110. X                    notify(Playernum, Governor, buf);
  1111. X                    s->xpos = s2->xpos;
  1112. X                    s->ypos = s2->ypos;
  1113. X                    s->docked = 0;
  1114. X                    s->whatdest = LEVEL_UNIV;
  1115. X                    s2->mass -= s->mass;
  1116. X                    s2->hanger -= Size(s);
  1117. X                    getstar(&(Stars[s2->storbits]), (int) s2->storbits);
  1118. X                    insert_sh_star(Stars[s2->storbits], s);
  1119. X                    s->storbits = s2->storbits;
  1120. X                    putstar(Stars[s2->storbits], (int) s2->storbits);
  1121. X                    sprintf(buf, "Orbiting %s.\n", Stars[s->storbits]->name);
  1122. X                    notify(Playernum, Governor, buf);
  1123. X                    putship(s);
  1124. X                    putship(s2);
  1125. X                } else if (s2->whatorbits == LEVEL_UNIV) {
  1126. X                    remove_sh_ship(s, s2);
  1127. X                    sprintf(buf, "%s launched from %s.\n", Ship(s), Ship(s2));
  1128. X                    notify(Playernum, Governor, buf);
  1129. X                    s->xpos = s2->xpos;
  1130. X                    s->ypos = s2->ypos;
  1131. X                    s->docked = 0;
  1132. X                    s->whatdest = LEVEL_UNIV;
  1133. X                    s2->mass -= s->mass;
  1134. X                    s2->hanger -= Size(s);
  1135. X                    getsdata(&Sdata);
  1136. X                    insert_sh_univ(&Sdata, s);
  1137. X                    notify(Playernum, Governor, "Universe level.\n");
  1138. X                    putsdata(&Sdata);
  1139. X                    putship(s);
  1140. X                    putship(s2);
  1141. X                } else {
  1142. X                    notify(Playernum, Governor, "You can't launch that ship.\n");
  1143. X                    free(s2);
  1144. X                    free(s);
  1145. X                    continue;
  1146. X                }
  1147. X                free(s2);
  1148. X                free(s);
  1149. X            } else if (s->whatdest == LEVEL_SHIP) {
  1150. X                sh2 = s->destshipno;
  1151. X                (void) getship(&s2, sh2);
  1152. X                if (s2->whatorbits == LEVEL_UNIV) {
  1153. X                    if (!enufAP(Playernum, Governor, Sdata.AP[Playernum - 1], APcount)) {
  1154. X                        free(s);
  1155. X                        free(s2);
  1156. X                        continue;
  1157. X                    } else
  1158. X                        deductAPs(Playernum, Governor, APcount, 0, 1);
  1159. X                } else {
  1160. X                    if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount)) {
  1161. X                        free(s);
  1162. X                        free(s2);
  1163. X                        continue;
  1164. X                    } else
  1165. X                        deductAPs(Playernum, Governor, APcount, (int) s->storbits, 0);
  1166. X                }
  1167. X                s->docked = 0;
  1168. X                s->whatdest = LEVEL_UNIV;
  1169. X                s->destshipno = 0;
  1170. X                s2->docked = 0;
  1171. X                s2->whatdest = LEVEL_UNIV;
  1172. X                s2->destshipno = 0;
  1173. X                sprintf(buf, "%s undocked from %s.\n", Ship(s), Ship(s2));
  1174. X                notify(Playernum, Governor, buf);
  1175. X                putship(s);
  1176. X                putship(s2);
  1177. X                free(s);
  1178. X                free(s2);
  1179. X            } else {
  1180. X                if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount)) {
  1181. X                    free(s);
  1182. X                    return;
  1183. X                } else
  1184. X                    deductAPs(Playernum, Governor, APcount, (int) s->storbits, 0);
  1185. X
  1186. X                /* adjust x,ypos to absolute coords */
  1187. X                getplanet(&p, (int) s->storbits, (int) s->pnumorbits);
  1188. X                sprintf(buf, "Planet /%s/%s has gravity field of %.2f\n", Stars[s->storbits]->name,
  1189. X                    Stars[s->storbits]->pnames[s->pnumorbits], gravity(p));
  1190. X                notify(Playernum, Governor, buf);
  1191. X                s->xpos = Stars[s->storbits]->xpos + p->xpos +
  1192. X                    (double) int_rand((int) (-DIST_TO_LAND / 4), (int) (DIST_TO_LAND / 4));
  1193. X                s->ypos = Stars[s->storbits]->ypos + p->ypos +
  1194. X                    (double) int_rand((int) (-DIST_TO_LAND / 4), (int) (DIST_TO_LAND / 4));
  1195. X
  1196. X                /* subtract fuel from ship */
  1197. X                fuel = gravity(p) * s->mass * LAUNCH_GRAV_MASS_FACTOR;
  1198. X                if (s->fuel < fuel) {
  1199. X                    sprintf(buf, "%s does not have enough fuel! (%.1f)\n",
  1200. X                        Ship(s), fuel);
  1201. X                    notify(Playernum, Governor, buf);
  1202. X                    free(p);
  1203. X                    free(s);
  1204. X                    return;
  1205. X                }
  1206. X                use_fuel(s, fuel);
  1207. X                s->docked = 0;
  1208. X                s->whatdest = LEVEL_UNIV;    /* no destination */
  1209. X                switch (s->type) {
  1210. X                case OTYPE_CANIST:
  1211. X                case OTYPE_GREEN:
  1212. X                    s->special.timer.count = 0;
  1213. X                    break;
  1214. X                default:
  1215. X                    break;
  1216. X                }
  1217. X                s->notified = 0;
  1218. X                putship(s);
  1219. X                if (!p->explored) {
  1220. X                    /*
  1221. X                     * not yet explored by owner; space
  1222. X                     * exploration causes the player to
  1223. X                     * see a whole map
  1224. X                     */
  1225. X                    p->explored = 1;
  1226. X                    putplanet(p, (int) s->storbits, (int) s->pnumorbits);
  1227. X                }
  1228. X                sprintf(buf, "%s observed launching from planet /%s/%s.\n",
  1229. X                    Ship(s), Stars[s->storbits]->name,
  1230. X                 Stars[s->storbits]->pnames[s->pnumorbits]);
  1231. X                for (i = 1; i <= Num_races; i++)
  1232. X                    if (p->info[i - 1].numsectsowned && i != Playernum)
  1233. X                        notify(i, (int) Stars[s->storbits]->governor[i - 1], buf);
  1234. X                free(p);
  1235. X
  1236. X                sprintf(buf, "%s launched from planet,", Ship(s));
  1237. X                notify(Playernum, Governor, buf);
  1238. X                sprintf(buf, " using %.1f fuel.\n", fuel);
  1239. X                notify(Playernum, Governor, buf);
  1240. X
  1241. X                switch (s->type) {
  1242. X                case OTYPE_CANIST:
  1243. X                    notify(Playernum, Governor, "A cloud of dust envelopes your planet.\n");
  1244. X                    break;
  1245. X                case OTYPE_GREEN:
  1246. X                    notify(Playernum, Governor, "Green house gases surround the planet.\n");
  1247. X                    break;
  1248. X                default:
  1249. X                    break;
  1250. X                }
  1251. X                free(s);
  1252. X            }
  1253. X        } else
  1254. X            free(s);
  1255. X}
  1256. END_OF_FILE
  1257. if test 7962 -ne `wc -c <'user/launch.c'`; then
  1258.     echo shar: \"'user/launch.c'\" unpacked with wrong size!
  1259. fi
  1260. # end of 'user/launch.c'
  1261. fi
  1262. if test -f 'utils/GB_racegen.c' -a "${1}" != "-c" ; then 
  1263.   echo shar: Will not clobber existing file \"'utils/GB_racegen.c'\"
  1264. else
  1265. echo shar: Extracting \"'utils/GB_racegen.c'\" \(9313 characters\)
  1266. sed "s/^X//" >'utils/GB_racegen.c' <<'END_OF_FILE'
  1267. X/* GB_enroll.c -- GB file interace for GB race enrollment program.
  1268. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  1269. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  1270. X * Restrictions in GB_copyright.h.
  1271. X */
  1272. X#include <signal.h>
  1273. X#include "GB_copyright.h"
  1274. X
  1275. X#define EXTERN
  1276. X#include "vars.h"
  1277. X#include "power.h"
  1278. X#include "ships.h"
  1279. X#include "shipdata.h"
  1280. X#include "races.h"
  1281. X#include "buffers.h"
  1282. X
  1283. X#include "racegen.h"
  1284. X
  1285. Xextern int errno;
  1286. Xracetype *Race;
  1287. X
  1288. X
  1289. Xint planet_translate[N_HOME_PLANET_TYPES] =  {0, 6, 7, 5, 2, 3, 4} ;
  1290. X
  1291. X
  1292. X
  1293. X#ifdef __STDC__
  1294. Xvoid srandom(int seed) ;
  1295. Xlong random(void) ;
  1296. X
  1297. Xint getpid(void) ;
  1298. X
  1299. Xvoid modify_print_loop(int level) ;
  1300. X
  1301. X
  1302. X#else
  1303. X#define const
  1304. X#endif
  1305. X
  1306. Xvoid notify(who, gov, msg)
  1307. X     int who, gov;
  1308. Xchar *msg;
  1309. X{
  1310. X  /* this is a dummy routine */
  1311. X  }
  1312. X
  1313. Xvoid warn(who, gov, msg)
  1314. X     int who, gov;
  1315. Xchar *msg;
  1316. X{
  1317. X  /* this is a dummy routine */
  1318. X  }
  1319. X
  1320. Xvoid push_message(what, who, msg)
  1321. X     int what, who;
  1322. Xchar *msg;
  1323. X{
  1324. X  /* this is a dummy routine */
  1325. X  }
  1326. X
  1327. X
  1328. Xvoid init_enroll()
  1329. X{
  1330. X  srandom(getpid()) ;
  1331. X  }
  1332. X
  1333. X
  1334. X/* 
  1335. X * Returns 0 if successfully enrolled, or 1 if failure. */
  1336. Xint enroll_valid_race()
  1337. X{
  1338. X  int mask, x, y, star, pnum, i, ppref, Playernum ;
  1339. X  int last_star_left, indirect[NUMSTARS] ;
  1340. X  sectortype *sect;
  1341. X  planettype *planet;
  1342. X  startype *star_arena;
  1343. X/*
  1344. X  if (race.status == STATUS_ENROLLED) {
  1345. X    sprintf(race.rejection, "This race has already been enrolled!\n") ;
  1346. X    return 1 ;
  1347. X    }
  1348. X*/
  1349. X  open_data_files();    
  1350. X  Playernum = Numraces() + 1 ;
  1351. X  if ((Playernum == 1) && (race.priv_type != P_GOD)) {
  1352. X    close_data_files() ;
  1353. X    sprintf(race.rejection,
  1354. X       "The first race enrolled must have God privileges.\n") ;
  1355. X    return 1 ;
  1356. X    }
  1357. X  if (Playernum >= MAXPLAYERS) {
  1358. X    close_data_files() ;
  1359. X    sprintf(race.rejection,
  1360. X       "There are already %d players; No more allowed.\n", MAXPLAYERS-1);
  1361. X    race.status = STATUS_UNENROLLABLE ;
  1362. X    return 1 ;
  1363. X    }
  1364. X
  1365. X  getsdata(&Sdata);
  1366. X  star_arena = (startype *)malloc(Sdata.numstars * sizeof(startype));
  1367. X  for (star=0; star<Sdata.numstars; star++) {
  1368. X    Stars[star] = &star_arena[star];
  1369. X    getstar(&(Stars[star]),star);
  1370. X    }
  1371. X
  1372. X  printf("Looking for %s..", planet_print_name[race.home_planet_type]);
  1373. X  fflush(stdout) ;
  1374. X
  1375. X  ppref = planet_translate[race.home_planet_type] ;
  1376. X  for (i=0; i < Sdata.numstars; i++)
  1377. X    indirect[i] = i ;
  1378. X  last_star_left = Sdata.numstars - 1 ;
  1379. X  while (last_star_left >= 0) {
  1380. X    i = int_rand(0, last_star_left) ;
  1381. X    star = indirect[i] ;
  1382. X
  1383. X    printf(".", star) ;
  1384. X    fflush(stdout) ;
  1385. X    /* 
  1386. X     * Skip over inhabited stars and stars with few planets. */
  1387. X    if ((Stars[star]->numplanets < 2) ||
  1388. X    Stars[star]->inhabited[0] || Stars[star]->inhabited[1]) {
  1389. X      }
  1390. X    else {
  1391. X      /* look for uninhabited planets */
  1392. X      for (pnum = 0; pnum < Stars[star]->numplanets; pnum++) {
  1393. X    getplanet(&planet, star, pnum) ;
  1394. X    if ((planet->type == ppref) &&
  1395. X        (planet->conditions[RTEMP] >= -200) && 
  1396. X        (planet->conditions[RTEMP] <= 100))
  1397. X      goto found_planet ;
  1398. X    free(planet);
  1399. X    }
  1400. X      }
  1401. X    /*
  1402. X     * Since we are here, this star didn't work out: */
  1403. X    indirect[i] = indirect[last_star_left--] ;
  1404. X    }
  1405. X
  1406. X  /*
  1407. X   * If we get here, then we did not find any good planet. */
  1408. X  printf(" failed!\n") ;
  1409. X  sprintf(race.rejection,
  1410. X      "Didn't find any free %s; choose another home planet type.\n",
  1411. X      planet_print_name[race.home_planet_type]);
  1412. X  close_data_files();
  1413. X  race.status = STATUS_UNENROLLABLE ;
  1414. X  return 1 ;
  1415. X
  1416. X found_planet:
  1417. X  printf(" found!\n") ;
  1418. X  Race = Malloc(racetype);
  1419. X  Bzero(*Race);
  1420. X
  1421. X  Race->Playernum = Playernum ;
  1422. X  Race->God   = (race.priv_type == P_GOD) ;
  1423. X  Race->Guest = (race.priv_type == P_GUEST) ;
  1424. X  strcpy(Race->name, race.name) ;
  1425. X  strcpy(Race->password, race.password) ;
  1426. X
  1427. X  strcpy(Race->governor[0].password, "0");
  1428. X  Race->governor[0].homelevel = Race->governor[0].deflevel = LEVEL_PLAN;
  1429. X  Race->governor[0].homesystem = Race->governor[0].defsystem = star;
  1430. X  Race->governor[0].homeplanetnum = Race->governor[0].defplanetnum = pnum;
  1431. X  /* display options */
  1432. X  Race->governor[0].toggle.highlight = Playernum;
  1433. X  Race->governor[0].toggle.inverse = 1;
  1434. X  Race->governor[0].toggle.color = 0;
  1435. X  Race->governor[0].active = 1;
  1436. X
  1437. X  for (i=0; i<=OTHER; i++)
  1438. X    Race->conditions[i] = planet->conditions[i];
  1439. X#if 0
  1440. X  /* make conditions preferred by your people set to (more or less) 
  1441. X     those of the planet : higher the concentration of gas, the higher
  1442. X     percentage difference between planet and race */
  1443. X  for (j=0; j<=OTHER; j++)
  1444. X    Race->conditions[j] = planet->conditions[j]
  1445. X      + int_rand(round_rand(-planet->conditions[j]*2.0), 
  1446. X         round_rand(planet->conditions[j]*2.0) ) ;
  1447. X#endif
  1448. X
  1449. X  for (i=0; i<MAXPLAYERS; i++) {
  1450. X    /* messages from autoreport, player #1 are decodable */
  1451. X    if ((i==Playernum) || (Playernum==1) || Race->God)
  1452. X      Race->translate[i-1] = 100;  /* you can talk to own race */
  1453. X    else
  1454. X      Race->translate[i-1] = 1;
  1455. X    }
  1456. X
  1457. X#if 0
  1458. X  /* All of the following zeros are not really needed, because the race
  1459. X     was bzero'ed out above. */
  1460. X  for (i=0; i<80; i++)
  1461. X    Race->discoveries[i] = 0;
  1462. X  Race->tech = 0.0;
  1463. X  Race->morale = 0;
  1464. X  Race->turn = 0;
  1465. X  Race->allied[0] = Race->allied[1] = 0;
  1466. X  Race->atwar[0] = Race->atwar[1] = 0;
  1467. X  for (i=0; i<MAXPLAYERS; i++) 
  1468. X    Race->points[i]=0;
  1469. X#endif
  1470. X
  1471. X  /* 
  1472. X   * Assign racial characteristics. */
  1473. X  Race->absorb        = race.attr[ABSORB] ;
  1474. X  Race->collective_iq = race.attr[COL_IQ] ;
  1475. X  Race->Metamorph     = (race.race_type == R_METAMORPH) ;
  1476. X  Race->pods          = race.attr[PODS] ;
  1477. X  
  1478. X  Race->fighters      = race.attr[FIGHT] ;
  1479. X  if (race.attr[COL_IQ] == 1.0)
  1480. X    Race->IQ_limit    = race.attr[A_IQ] ;
  1481. X  else
  1482. X    Race->IQ          = race.attr[A_IQ] ;
  1483. X  Race->number_sexes  = race.attr[SEXES] ;
  1484. X
  1485. X  Race->fertilize     = race.attr[FERT] * 100;
  1486. X
  1487. X  Race->adventurism   = race.attr[ADVENT] ;
  1488. X  Race->birthrate     = race.attr[BIRTH] ;
  1489. X  Race->mass          = race.attr[MASS] ;
  1490. X  Race->metabolism    = race.attr[METAB] ;
  1491. X
  1492. X  /* 
  1493. X   * Assign sector compats and determine a primary sector type. */
  1494. X  for (i = FIRST_SECTOR_TYPE; i<=LAST_SECTOR_TYPE; i++) {
  1495. X    Race->likes[i] = race.compat[i] / 100.0 ;
  1496. X    if ((100 == race.compat[i]) &&
  1497. X    (1.0 == planet_compat_cov[race.home_planet_type][i]))
  1498. X      Race->likesbest = i ;
  1499. X    }
  1500. X
  1501. X  /*
  1502. X   * Find sector to build capital on, and populate it: */
  1503. X  getsmap(Smap,planet);
  1504. X  PermuteSects(planet);
  1505. X  Getxysect(planet, 0, 0, 1);
  1506. X  while (i = Getxysect(planet, &x, &y, 0))
  1507. X    if (Sector(*planet, x, y).condition == Race->likesbest)
  1508. X      break ;
  1509. X  if (! i)
  1510. X    x = y = 0 ;
  1511. X  sect = &Sector(*planet, x, y) ;
  1512. X  sect->owner = Playernum ;
  1513. X  sect->race = Playernum;
  1514. X  sect->popn = planet->popn = Race->number_sexes ;
  1515. X  sect->fert = 100 ;
  1516. X  sect->eff = 10 ;
  1517. X  sect->troops = planet->troops = 0;
  1518. X
  1519. X  Race->governors = 0;
  1520. X  
  1521. X  mask = sigblock(SIGBLOCKS);
  1522. X  /* build a capital ship to run the government */
  1523. X  {
  1524. X  shiptype s;
  1525. X  int shipno;
  1526. X  
  1527. X  Bzero(s);
  1528. X  shipno = Numships() + 1;
  1529. X  Race->Gov_ship = shipno;
  1530. X  planet->ships = shipno;
  1531. X  s.nextship = 0;
  1532. X  
  1533. X  s.type = OTYPE_GOV;
  1534. X  s.xpos = Stars[star]->xpos + planet->xpos;
  1535. X  s.ypos = Stars[star]->ypos + planet->ypos;
  1536. X  s.land_x = x ;
  1537. X  s.land_y = y ;
  1538. X  
  1539. X  s.speed = 0;
  1540. X  s.owner = Playernum;
  1541. X  s.race = Playernum;
  1542. X  s.governor = 0;
  1543. X  
  1544. X  s.tech = 100.0;
  1545. X  
  1546. X  s.build_type = OTYPE_GOV;
  1547. X  s.armor = Shipdata[OTYPE_GOV][ABIL_ARMOR];
  1548. X  s.guns = PRIMARY;
  1549. X  s.primary = Shipdata[OTYPE_GOV][ABIL_GUNS];
  1550. X  s.primtype = Shipdata[OTYPE_GOV][ABIL_PRIMARY];
  1551. X  s.secondary = Shipdata[OTYPE_GOV][ABIL_GUNS];
  1552. X  s.sectype = Shipdata[OTYPE_GOV][ABIL_SECONDARY];
  1553. X  s.max_crew = Shipdata[OTYPE_GOV][ABIL_MAXCREW];
  1554. X  s.max_destruct = Shipdata[OTYPE_GOV][ABIL_DESTCAP];
  1555. X  s.max_resource = Shipdata[OTYPE_GOV][ABIL_CARGO];
  1556. X  s.max_fuel = Shipdata[OTYPE_GOV][ABIL_FUELCAP];
  1557. X  s.max_speed = Shipdata[OTYPE_GOV][ABIL_SPEED];
  1558. X  s.build_cost = Shipdata[OTYPE_GOV][ABIL_COST];
  1559. X  s.size = 100;
  1560. X  s.base_mass = 100.0;
  1561. X  sprintf(s.class, "Standard");
  1562. X  
  1563. X  s.fuel = 0.0;
  1564. X  s.popn = Shipdata[s.type][ABIL_MAXCREW];
  1565. X  s.troops = 0;
  1566. X  s.mass = s.base_mass + Shipdata[s.type][ABIL_MAXCREW]*Race->mass;
  1567. X  s.destruct = s.resource = 0;
  1568. X  
  1569. X  s.alive = 1;
  1570. X  s.active = 1;
  1571. X  s.protect.self = 1;
  1572. X  
  1573. X  s.docked = 1;
  1574. X  /* docked on the planet */
  1575. X  s.whatorbits = LEVEL_PLAN;
  1576. X  s.whatdest = LEVEL_PLAN;
  1577. X  s.deststar = star;
  1578. X  s.destpnum = pnum;
  1579. X  s.storbits = star;
  1580. X  s.pnumorbits = pnum;
  1581. X  s.rad = 0;
  1582. X  s.damage = 0;  /*Shipdata[s.type][ABIL_DAMAGE];*/
  1583. X  /* (first capital is 100% efficient */
  1584. X  s.retaliate = 0;
  1585. X  
  1586. X  s.ships = 0;
  1587. X  
  1588. X  s.on = 1;
  1589. X  
  1590. X  s.name[0] = '\0';
  1591. X  s.number = shipno;
  1592. X  putship(&s);
  1593. X  }
  1594. X
  1595. X  putrace(Race);
  1596. X
  1597. X  planet->info[Playernum-1].numsectsowned = 1;
  1598. X  planet->explored = 0;
  1599. X  planet->info[Playernum-1].explored = 1;
  1600. X  /*planet->info[Playernum-1].autorep = 1;*/
  1601. X
  1602. X  planet->maxpopn = maxsupport(Race, sect, 100.0,0)
  1603. X      * planet->Maxx * planet->Maxy / 2;
  1604. X  /* (approximate) */
  1605. X
  1606. X  putsector(sect, planet, x, y) ;
  1607. X  putplanet(planet,star,pnum);
  1608. X
  1609. X  /* make star explored and stuff */
  1610. X  getstar(&Stars[star],star);
  1611. X  setbit(Stars[star]->explored,Playernum);
  1612. X  setbit(Stars[star]->inhabited,Playernum);
  1613. X  Stars[star]->AP[Playernum-1] = 5;
  1614. X  putstar(Stars[star],star);
  1615. X  close_data_files();
  1616. X
  1617. X  sigsetmask(mask);
  1618. X
  1619. X  printf("Player %d (%s) created on sector %d,%d on %s/%s.\n", Playernum, 
  1620. X     race.name, x, y, Stars[star]->name, Stars[star]->pnames[pnum]);
  1621. X  race.status = STATUS_ENROLLED ;
  1622. X  return 0 ;
  1623. X  }
  1624. END_OF_FILE
  1625. if test 9313 -ne `wc -c <'utils/GB_racegen.c'`; then
  1626.     echo shar: \"'utils/GB_racegen.c'\" unpacked with wrong size!
  1627. fi
  1628. # end of 'utils/GB_racegen.c'
  1629. fi
  1630. if test -f 'utils/exship.c' -a "${1}" != "-c" ; then 
  1631.   echo shar: Will not clobber existing file \"'utils/exship.c'\"
  1632. else
  1633. echo shar: Extracting \"'utils/exship.c'\" \(6945 characters\)
  1634. sed "s/^X//" >'utils/exship.c' <<'END_OF_FILE'
  1635. X#ident  "@(#)exship.c    1.3 1/7/93 "
  1636. X/***********************************************
  1637. X * exship.c
  1638. X *
  1639. X * Created: Fri Jan  1 19:34:23 EST 1993
  1640. X * Author:  J. Deragon (deragon@jethro.nyu.edu)
  1641. X *
  1642. X * Version: 1.3 17:02:19
  1643. X *
  1644. X *    This software is provided "as is" and without any express or
  1645. X *    implied warranties, including, without limitation, the implied
  1646. X *    warranties of merchantibility and fitness for a particular
  1647. X *    purpose.
  1648. X *
  1649. X ***********************************************/
  1650. X
  1651. X/*
  1652. X * includes
  1653. X */
  1654. X#include <strings.h>
  1655. X#include <signal.h>
  1656. X#include <sys/file.h>
  1657. X#include <errno.h>
  1658. X#include <sys/types.h>
  1659. X#include <sys/stat.h>
  1660. X#define EXTERN extern
  1661. X#include "vars.h"
  1662. X#include "ships.h"
  1663. X#include "shipdata.h"
  1664. X
  1665. X
  1666. X#define DATAFILE "ship"
  1667. X
  1668. X/*
  1669. X * Prototypes
  1670. X */
  1671. X
  1672. Xvoid            check_ship();
  1673. Xvoid            check_size();
  1674. Xvoid            display_ship();
  1675. X#ifdef __STDC__
  1676. Xvoid            main(int, char **);
  1677. Xvoid            readship(shiptype **, int);
  1678. X#else
  1679. Xvoid            main();
  1680. Xvoid            readship();
  1681. X#endif
  1682. X
  1683. X
  1684. X/*
  1685. X * Global vars
  1686. X */
  1687. X
  1688. Xstatic int      ship_fd;    /* the file descriptor of the datafile     */
  1689. Xstruct stat     buffer;        /* used for getting the size of the file   */
  1690. Xint             num_ships;    /* number of total ships in database       */
  1691. Xint             bad_ship_count = 0;    /* the number of bad ships in the
  1692. X                     * database */
  1693. Xshiptype       *display;    /* this ship we are currently working on   */
  1694. X
  1695. X/*
  1696. X * main:
  1697. X * 
  1698. X * arguments: shipnumber
  1699. X * 
  1700. X * called by:
  1701. X * 
  1702. X * description:  If invoked with zero arguments, it will open the ship datafile
  1703. X * and go through looking for obvious errors. If invoked with a ship number
  1704. X * it will print out a very verbose listing of the requested ship.
  1705. X * 
  1706. X */
  1707. Xvoid
  1708. Xmain(argc, argv)
  1709. X    int             argc;
  1710. X    char           *argv[];
  1711. X{
  1712. X    int             i;
  1713. X
  1714. X    if ((ship_fd = open(DATAFILE, 000, 0777)) < 0) {
  1715. X        perror(main);
  1716. X        printf("unable to open %s\n", DATAFILE);
  1717. X        exit(-1);
  1718. X    }
  1719. X    check_size();
  1720. X
  1721. X    if (argc == 1) {    /* check the whole database for errors */
  1722. X        for (i = 1; i <= num_ships; i++) {
  1723. X            readship(&display, i);
  1724. X            check_ship();
  1725. X            free(display);
  1726. X        }
  1727. X        printf("I found a total of %d bad ships out of %d\n",
  1728. X               bad_ship_count, num_ships);
  1729. X    } else {        /* we want a specific ship display */
  1730. X        readship(&display, atoi(argv[1]));
  1731. X        display_ship();
  1732. X    }
  1733. X    printf("All Done \n");
  1734. X
  1735. X    exit(3);
  1736. X}
  1737. X
  1738. X/*
  1739. X * readship:
  1740. X * 
  1741. X * arguments: shiptype structure, shipnumber
  1742. X * 
  1743. X * called by:
  1744. X * 
  1745. X * description:  This funtion reads the actual data from the file.
  1746. X * 
  1747. X */
  1748. X
  1749. Xvoid
  1750. Xreadship(s, shipnum)
  1751. X    shiptype      **s;
  1752. X    int             shipnum;
  1753. X{
  1754. X    int             n;
  1755. X
  1756. X    if (shipnum <= 0)
  1757. X        exit(1);
  1758. X
  1759. X    if ((*s = (shiptype *) malloc(sizeof(shiptype))) == 0) {
  1760. X        printf("getship:Malloc() error\n");
  1761. X        exit(0);
  1762. X    }
  1763. X    if (lseek(ship_fd, (shipnum - 1) * sizeof(shiptype), L_SET) < 0) {
  1764. X        perror(lseek);
  1765. X        exit(1);
  1766. X    }
  1767. X    if ((n = read(ship_fd, (char *) *s, sizeof(shiptype))) != sizeof(shiptype))
  1768. X        perror(read);
  1769. X
  1770. X
  1771. X
  1772. X}
  1773. X
  1774. X/*
  1775. X * check_size:
  1776. X * 
  1777. X * arguments: none
  1778. X * 
  1779. X * called by: main
  1780. X * 
  1781. X * description:  gets the number of ships in the current database
  1782. X * 
  1783. X */
  1784. Xvoid
  1785. Xcheck_size()
  1786. X{
  1787. X
  1788. X
  1789. X    fstat(ship_fd, &buffer);
  1790. X    num_ships = buffer.st_size / sizeof(shiptype);
  1791. X    printf("Number of ships in database is %d\n", num_ships);
  1792. X}
  1793. X
  1794. X/*
  1795. X * check_ship:
  1796. X * 
  1797. X * arguments: none
  1798. X * 
  1799. X * called by: main
  1800. X * 
  1801. X * description:  checks basic cargo to make sure its within limits of ships
  1802. X * ability.
  1803. X * 
  1804. X */
  1805. Xvoid
  1806. Xcheck_ship()
  1807. X{
  1808. X    int             ship_ok = 1;
  1809. X    int             pop, troops, res, des, fu, speed, hanger;
  1810. X
  1811. X    pop = troops = res = des = fu = speed = hanger = 1;
  1812. X
  1813. X    if (display->type == OTYPE_FACTORY) {
  1814. X        if (display->popn > Shipdata[(display)->type][ABIL_MAXCREW])
  1815. X            ship_ok = pop = 0;
  1816. X        if (display->troops > Shipdata[(display)->type][ABIL_MAXCREW])
  1817. X            ship_ok = troops = 0;
  1818. X        if ((display->popn + display->troops) >
  1819. X            Shipdata[(display)->type][ABIL_MAXCREW])
  1820. X            ship_ok = pop = troops = 0;
  1821. X    } else {
  1822. X        if (display->popn > display->max_crew)
  1823. X            ship_ok = pop = 0;
  1824. X        if (display->troops > display->max_crew)
  1825. X            ship_ok = troops = 0;
  1826. X        if ((display->popn + display->troops) > display->max_crew)
  1827. X            ship_ok = pop = troops = 0;
  1828. X    }
  1829. X    if (display->resource > Max_resource(display))
  1830. X        ship_ok = res = 0;
  1831. X    if (display->destruct > Max_destruct(display))
  1832. X        ship_ok = des = 0;
  1833. X    if ((int) display->fuel > Max_fuel(display))
  1834. X        ship_ok = fu = 0;
  1835. X    if (display->speed > Max_speed(display))
  1836. X        ship_ok = speed = 0;
  1837. X    if (display->hanger > display->max_hanger)
  1838. X        ship_ok = hanger = 0;
  1839. X
  1840. X    if (!ship_ok) {
  1841. X        bad_ship_count++;
  1842. X
  1843. X        printf("Problem with ship number %d\n", display->number);
  1844. X        printf("\t\tOwner: %d\n", display->owner);
  1845. X        printf("\t\tGovernor: %d\n", display->governor);
  1846. X        printf("\t\tName: %s\n", display->name);
  1847. X        printf("\t\tType: %c\n", Shipltrs[display->type]);
  1848. X        printf("\n");
  1849. X
  1850. X        printf("\t %s popn: %d\t max_popn: %d:\n",
  1851. X        pop ? "      " : "----->", display->popn, display->max_crew);
  1852. X        printf("\t %s troops: %d\t max_troops: %d\n",
  1853. X               troops ? "      " : "----->", display->troops, display->max_crew);
  1854. X        printf("\t %s resources: %d\t max_resources: %d\n",
  1855. X               res ? "      " : "----->", display->resource,
  1856. X               display->max_resource);
  1857. X        printf("\t %s destruct: %d\t max_destruct: %d\n",
  1858. X               des ? "      " : "----->", display->destruct,
  1859. X               display->max_destruct);
  1860. X        printf("\t %s fuel: %d\t max_fuel: %d\n",
  1861. X               fu ? "      " : "----->", (int) display->fuel,
  1862. X               (int) display->max_fuel);
  1863. X        printf("\t %s speed: %d\t max_speed: %d\n",
  1864. X               speed ? "      " : "----->", display->speed, display->max_speed);
  1865. X        printf("\t %s hanger: %d\t max_hanger: %d\n",
  1866. X               hanger ? "      " : "----->", display->hanger,
  1867. X               display->max_hanger);
  1868. X    }
  1869. X}
  1870. X
  1871. X/*
  1872. X * display_ship:
  1873. X * 
  1874. X * arguments: none
  1875. X * 
  1876. X * called by: main
  1877. X * 
  1878. X * description:  Prints a _long_ description a a specific ship.
  1879. X * 
  1880. X */
  1881. Xvoid
  1882. Xdisplay_ship()
  1883. X{
  1884. X    printf("Ship Number: %d\tShip Type: %c\tShip Owner: %d\tShip Governor %d\n",
  1885. X           display->number, Shipltrs[display->type],
  1886. X           display->owner, display->governor);
  1887. X    printf("Ship Name: %s\n", display->name);
  1888. X
  1889. X    printf("\nCrew: %-9d\t  Troops: %-6d\tArmor: %d\n",
  1890. X           display->popn, display->troops, display->armor);
  1891. X    printf("Size: %-9d\t  Base Mass: %-4.1f\tBase Tech: %4.1f\n",
  1892. X           display->size, display->base_mass, display->tech);
  1893. X    printf("Destruct: %-6d  Resources: %-6d\tCrystals: %d\n",
  1894. X           display->destruct, display->resource, display->crystals);
  1895. X    printf("Fuel: 4.1f\n", display->fuel);
  1896. X    printf("\n");
  1897. X    printf("Guns:\tPrimary: %-3d%c\n", display->primary,
  1898. X           (display->primtype == LIGHT ? 'L' :
  1899. X        display->primtype == MEDIUM ? 'M' :
  1900. X        display->primtype == HEAVY ? 'H' : 'N'));
  1901. X    printf("     \tSecondary:  %-3d%c\n", display->primary,
  1902. X           (display->primtype == LIGHT ? 'L' :
  1903. X        display->primtype == MEDIUM ? 'M' :
  1904. X        display->primtype == HEAVY ? 'H' : 'N'));
  1905. X
  1906. X    printf("\nNextship: %-6d\t (%s)\n", display->nextship,
  1907. X           display->alive ? "ALIVE" : "DEAD");
  1908. X}
  1909. END_OF_FILE
  1910. if test 6945 -ne `wc -c <'utils/exship.c'`; then
  1911.     echo shar: \"'utils/exship.c'\" unpacked with wrong size!
  1912. fi
  1913. # end of 'utils/exship.c'
  1914. fi
  1915. echo shar: End of archive 17 \(of 21\).
  1916. cp /dev/null ark17isdone
  1917. MISSING=""
  1918. 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
  1919.     if test ! -f ark${I}isdone ; then
  1920.     MISSING="${MISSING} ${I}"
  1921.     fi
  1922. done
  1923. if test "${MISSING}" = "" ; then
  1924.     echo You have unpacked all 21 archives.
  1925.     echo "Now type './buildfiles.sh'"
  1926.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1927. else
  1928.     echo You still need to unpack the following archives:
  1929.     echo "        " ${MISSING}
  1930. fi
  1931. ##  End of shell archive.
  1932. exit 0
  1933.