home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part05 < prev    next >
Encoding:
Internet Message Format  |  1993-03-20  |  54.3 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: v17i017:  gbp - Galactic Bloodshed+, an empire-like war game, Part05/21
  5. Message-ID: <4545@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:30:25 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1786
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1696
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 17
  14. Archive-name: gbp/Part05
  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 5 (of 21)."
  27. # Contents:  doc/VERSION server/moveship.c user/load.c
  28. # Wrapped by billr@saab on Fri Feb 12 09:14:24 1993
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'doc/VERSION' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'doc/VERSION'\"
  32. else
  33. echo shar: Extracting \"'doc/VERSION'\" \(53 characters\)
  34. sed "s/^X//" >'doc/VERSION' <<'END_OF_FILE'
  35. XThis release can be refered to as GBDT GB+ Ver 1.1.4
  36. END_OF_FILE
  37. if test 53 -ne `wc -c <'doc/VERSION'`; then
  38.     echo shar: \"'doc/VERSION'\" unpacked with wrong size!
  39. fi
  40. # end of 'doc/VERSION'
  41. fi
  42. if test -f 'server/moveship.c' -a "${1}" != "-c" ; then 
  43.   echo shar: Will not clobber existing file \"'server/moveship.c'\"
  44. else
  45. echo shar: Extracting \"'server/moveship.c'\" \(16801 characters\)
  46. sed "s/^X//" >'server/moveship.c' <<'END_OF_FILE'
  47. X#ident  "@(#)moveship.c    1.5 1/31/93 "
  48. X/*
  49. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  50. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  51. X * GB_copyright.h.
  52. X * 
  53. X * moveship -- moves specified ship according to its orders. also deducts fuel
  54. X * from the ship's stores.
  55. X */
  56. X#include <math.h>
  57. X
  58. X
  59. X#include "GB_copyright.h"
  60. X#define EXTERN extern
  61. X#include "vars.h"
  62. X#include "power.h"
  63. X#include "ships.h"
  64. X#include "races.h"
  65. X#include "doturn.h"
  66. X#include "buffers.h"
  67. X
  68. X/*
  69. X * amount to move for each dir level. I arrived on these #'s only after hours
  70. X * of dilligent tweaking
  71. X */
  72. X/* amount to move for each directory level  */
  73. Xdouble          MoveConsts[] = {600.0, 300.0, 50.0};
  74. X/* amnt to move for each ship speed level (ordered) */
  75. Xdouble          SpeedConsts[] = {0.0, 0.61, 1.26, 1.50, 1.73, 1.81, 1.90, 1.93, 1.96, 1.97};
  76. X/* amount of fuel it costs to move at speed level */
  77. X
  78. Xvoid            Moveship(shiptype *, int, int, int);
  79. Xvoid            msg_OOF(shiptype *);
  80. Xint             followable(shiptype *, shiptype *);
  81. Xint             do_merchant(shiptype *, planettype *);
  82. X#include "proto.h"
  83. X
  84. Xvoid 
  85. XMoveship(shiptype * s, int mode, int send_messages, int checking_fuel)
  86. X{
  87. X    double          stardist, movedist, truedist, dist, xdest, ydest,
  88. X                    sn, cs;
  89. X    double          mfactor, heading, distfac;
  90. X    double          fuse;
  91. X    int             destlevel, deststar = 0, destpnum = 0;
  92. X    shiptype       *dsh;
  93. X    startype       *ost, *dst;
  94. X    planettype     *opl, *dpl;
  95. X
  96. X    if (s->hyper_drive.has && s->hyper_drive.on) {    /* do a hyperspace jump */
  97. X        if (!mode)
  98. X            return;    /* we're not ready to jump until the update */
  99. X        if (s->hyper_drive.ready) {
  100. X            dist = sqrt(Distsq(s->xpos, s->ypos,
  101. X            Stars[s->deststar]->xpos, Stars[s->deststar]->ypos));
  102. X            distfac = HYPER_DIST_FACTOR * (s->tech + 100.0);
  103. X            if (s->mounted && dist > distfac)
  104. X                fuse = HYPER_DRIVE_FUEL_USE * sqrt(s->mass) * (dist / distfac);
  105. X            else
  106. X                fuse = HYPER_DRIVE_FUEL_USE * sqrt(s->mass)
  107. X                    * (dist / distfac) * (dist / distfac);
  108. X
  109. X            if (s->fuel < fuse) {
  110. X                sprintf(telegram_buf,
  111. X                    "%s at system %s does not have %.1ff to do hyperspace jump.",
  112. X                    Ship(s), prin_ship_orbits(s), fuse);
  113. X                if (send_messages)
  114. X                    push_telegram((int) (s->owner),
  115. X                       (int) s->governor, telegram_buf);
  116. X                s->hyper_drive.on = 0;
  117. X                return;
  118. X            }
  119. X            use_fuel(s, fuse);
  120. X            heading = atan2(Stars[s->deststar]->xpos - s->xpos,
  121. X                    Stars[s->deststar]->ypos - s->ypos);
  122. X            sn = sin(heading);
  123. X            cs = cos(heading);
  124. X            s->xpos = Stars[s->deststar]->xpos - sn * 0.9 * SYSTEMSIZE;
  125. X            s->ypos = Stars[s->deststar]->ypos - cs * 0.9 * SYSTEMSIZE;
  126. X            s->whatorbits = LEVEL_STAR;
  127. X            s->storbits = s->deststar;
  128. X            s->protect.planet = 0;
  129. X            s->hyper_drive.on = 0;
  130. X            s->hyper_drive.ready = 0;
  131. X            s->hyper_drive.charge = 0;
  132. X            sprintf(telegram_buf, "%s arrived at %s.", Ship(s), prin_ship_orbits(s));
  133. X            if (send_messages)
  134. X                push_telegram((int) (s->owner),
  135. X                       (int) s->governor, telegram_buf);
  136. X        } else if (s->mounted) {
  137. X            s->hyper_drive.ready = 1;
  138. X            s->hyper_drive.charge = HYPER_DRIVE_READY_CHARGE;
  139. X        } else {
  140. X            if (s->hyper_drive.charge == HYPER_DRIVE_READY_CHARGE)
  141. X                s->hyper_drive.ready = 1;
  142. X            else
  143. X                s->hyper_drive.charge += 1;
  144. X        }
  145. X        return;
  146. X    } else if (s->speed && !s->docked && s->alive
  147. X           && (s->whatdest != LEVEL_UNIV || s->navigate.on)) {
  148. X        fuse = 0.5 * s->speed * (1 + s->protect.evade)
  149. X            * s->mass * FUEL_USE / (double) segments;
  150. X        if (s->fuel < fuse) {
  151. X            if (send_messages)
  152. X                msg_OOF(s);    /* send OOF notify */
  153. X            if (s->whatorbits == LEVEL_UNIV && (s->build_cost <= 50)) {
  154. X                sprintf(telegram_buf, "%s has been lost in deep space.",
  155. X                    Ship(s));
  156. X                if (send_messages)
  157. X                    push_telegram((int) (s->owner),
  158. X                       (int) s->governor, telegram_buf);
  159. X                if (send_messages)
  160. X                    kill_ship((int) (s->owner), s);
  161. X            }
  162. X            return;
  163. X        }
  164. X        if (s->navigate.on) {    /* follow navigational orders */
  165. X            heading = .0174329252 * s->navigate.bearing;
  166. X            mfactor = SHIP_MOVE_SCALE * (1.0 - .01 * s->rad)
  167. X                * (1.0 - .01 * s->damage)
  168. X                * SpeedConsts[s->speed] * MoveConsts[s->whatorbits]
  169. X                / (double) segments;
  170. X            use_fuel(s, (double) fuse);
  171. X            sn = sin(heading);
  172. X            cs = cos(heading);
  173. X            xdest = sn * mfactor;
  174. X            ydest = -cs * mfactor;
  175. X            s->xpos += xdest;
  176. X            s->ypos += ydest;
  177. X            s->navigate.turns--;
  178. X            if (!s->navigate.turns)
  179. X                s->navigate.on = 0;
  180. X            /* check here for orbit breaking as well. Maarten */
  181. X            ost = Stars[s->storbits];
  182. X            opl = planets[s->storbits][s->pnumorbits];
  183. X            if (s->whatorbits == LEVEL_PLAN) {
  184. X                dist = sqrt(Distsq(s->xpos, s->ypos,
  185. X                           ost->xpos + opl->xpos, ost->ypos + opl->ypos));
  186. X                if (dist > PLORBITSIZE) {
  187. X                    s->whatorbits = LEVEL_STAR;
  188. X                    s->protect.planet = 0;
  189. X                }
  190. X            } else if (s->whatorbits == LEVEL_STAR) {
  191. X                dist = sqrt(Distsq(s->xpos, s->ypos, ost->xpos, ost->ypos));
  192. X                if (dist > SYSTEMSIZE) {
  193. X                    s->whatorbits = LEVEL_UNIV;
  194. X                    s->protect.evade = 0;
  195. X                    s->protect.planet = 0;
  196. X                }
  197. X            }
  198. X        } else {    /* navigate is off            */
  199. X            destlevel = s->whatdest;
  200. X            if (destlevel == LEVEL_SHIP) {
  201. X                dsh = ships[s->destshipno];
  202. X                s->deststar = dsh->storbits;
  203. X                s->destpnum = dsh->pnumorbits;
  204. X                xdest = dsh->xpos;
  205. X                ydest = dsh->ypos;
  206. X                switch (dsh->whatorbits) {
  207. X                case LEVEL_UNIV:
  208. X                    break;
  209. X                case LEVEL_PLAN:
  210. X                    if (s->whatorbits != dsh->whatorbits ||
  211. X                        s->pnumorbits != dsh->pnumorbits)
  212. X                        destlevel = LEVEL_PLAN;
  213. X                    break;
  214. X                case LEVEL_STAR:
  215. X                    if (s->whatorbits != dsh->whatorbits ||
  216. X                        s->storbits != dsh->storbits)
  217. X                        destlevel = LEVEL_STAR;
  218. X                    break;
  219. X                }
  220. X                /*
  221. X                 * if (sqrt( (double)Distsq(s->xpos, s->ypos,
  222. X                 * xdest, ydest)) <= DIST_TO_LAND ||
  223. X                 * !(dsh->alive)) { destlevel = LEVEL_UNIV;
  224. X                 * s->whatdest=LEVEL_UNIV; }
  225. X                 */
  226. X            }
  227. X            /* else */
  228. X            if (destlevel == LEVEL_STAR ||
  229. X                (destlevel == LEVEL_PLAN &&
  230. X                 (s->storbits != s->deststar || s->whatorbits == LEVEL_UNIV))) {
  231. X                destlevel = LEVEL_STAR;
  232. X                deststar = s->deststar;
  233. X                xdest = Stars[deststar]->xpos;
  234. X                ydest = Stars[deststar]->ypos;
  235. X            } else if (destlevel == LEVEL_PLAN && s->storbits == s->deststar) {
  236. X                destlevel = LEVEL_PLAN;
  237. X                deststar = s->deststar;
  238. X                destpnum = s->destpnum;
  239. X                xdest = Stars[deststar]->xpos + planets[deststar][destpnum]->xpos;
  240. X                ydest = Stars[deststar]->ypos + planets[deststar][destpnum]->ypos;
  241. X                if (sqrt(Distsq(s->xpos, s->ypos, xdest, ydest)) <= DIST_TO_LAND)
  242. X                    destlevel = LEVEL_UNIV;
  243. X            }
  244. X            dst = Stars[deststar];
  245. X            ost = Stars[s->storbits];
  246. X            dpl = planets[deststar][destpnum];
  247. X            opl = planets[s->storbits][s->pnumorbits];
  248. X            truedist = movedist = sqrt(Distsq(s->xpos, s->ypos, xdest, ydest));
  249. X            /*
  250. X             * Save some unneccesary calculation and domain
  251. X             * errors for atan2 Maarten
  252. X             */
  253. X            if (truedist < DIST_TO_LAND && s->whatorbits == destlevel &&
  254. X            s->storbits == deststar && s->pnumorbits == destpnum)
  255. X                return;
  256. X            heading = atan2((double) (xdest - s->xpos), (double) (-ydest + s->ypos));
  257. X            mfactor = SHIP_MOVE_SCALE * (1. - .01 * (double) s->rad)
  258. X                * (1. - .01 * (double) s->damage)
  259. X                * SpeedConsts[s->speed] * MoveConsts[s->whatorbits]
  260. X                / (double) segments;
  261. X
  262. X            /* keep from ending up in the middle of the system. */
  263. X            if (destlevel == LEVEL_STAR &&
  264. X                (s->storbits != deststar || s->whatorbits == LEVEL_UNIV))
  265. X                movedist -= SYSTEMSIZE * 0.90;
  266. X            else if (destlevel == LEVEL_PLAN && s->whatorbits == LEVEL_STAR &&
  267. X             s->storbits == deststar && truedist >= PLORBITSIZE)
  268. X                movedist -= PLORBITSIZE * 0.90;
  269. X
  270. X            if (s->whatdest == LEVEL_SHIP &&
  271. X                !followable(s, ships[s->destshipno])) {
  272. X                s->whatdest = LEVEL_UNIV;
  273. X                s->protect.evade = 0;
  274. X                sprintf(telegram_buf,
  275. X                    "%s at %s lost sight of destination ship #%d.",
  276. X                Ship(s), prin_ship_orbits(s), s->destshipno);
  277. X                if (send_messages)
  278. X                    push_telegram((int) (s->owner),
  279. X                       (int) s->governor, telegram_buf);
  280. X                return;
  281. X            }
  282. X            if (truedist > DIST_TO_LAND) {
  283. X                use_fuel(s, (double) fuse);
  284. X                /* dont overshoot */
  285. X                sn = sin(heading);
  286. X                cs = cos(heading);
  287. X                xdest = sn * mfactor;
  288. X                ydest = -cs * mfactor;
  289. X                if (hypot(xdest, ydest) > movedist) {
  290. X                    xdest = sn * movedist;
  291. X                    ydest = -cs * movedist;
  292. X                }
  293. X                s->xpos += xdest;
  294. X                s->ypos += ydest;
  295. X            }
  296. X            /***** check if far enough away from object it's orbiting to break orbit *****/
  297. X            if (s->whatorbits == LEVEL_PLAN) {
  298. X                dist = sqrt(Distsq(s->xpos, s->ypos,
  299. X                           ost->xpos + opl->xpos, ost->ypos + opl->ypos));
  300. X                if (dist > PLORBITSIZE) {
  301. X                    s->whatorbits = LEVEL_STAR;
  302. X                    s->protect.planet = 0;
  303. X                }
  304. X            } else if (s->whatorbits == LEVEL_STAR) {
  305. X                dist = sqrt(Distsq(s->xpos, s->ypos, ost->xpos, ost->ypos));
  306. X                if (dist > SYSTEMSIZE) {
  307. X                    s->whatorbits = LEVEL_UNIV;
  308. X                    s->protect.evade = 0;
  309. X                    s->protect.planet = 0;
  310. X                }
  311. X            }
  312. X            /*******   check for arriving at destination *******/
  313. X            if (destlevel == LEVEL_STAR ||
  314. X                (destlevel == LEVEL_PLAN &&
  315. X                 (s->storbits != deststar || s->whatorbits == LEVEL_UNIV))) {
  316. X                stardist = sqrt(Distsq(s->xpos, s->ypos, dst->xpos, dst->ypos));
  317. X                if (stardist <= SYSTEMSIZE * 1.5) {
  318. X                    s->whatorbits = LEVEL_STAR;
  319. X                    s->protect.planet = 0;
  320. X                    s->storbits = deststar;
  321. X                    /*
  322. X                     * if this system isn't inhabited by
  323. X                     * you, give it to the governor of
  324. X                     * the ship
  325. X                     */
  326. X                    if (!checking_fuel && (s->popn || s->type == OTYPE_PROBE)) {
  327. X                        if (!isset(dst->inhabited, (int) s->owner))
  328. X                            dst->governor[s->owner - 1] = s->governor;
  329. X                        setbit(dst->explored, (int) s->owner);
  330. X                        setbit(dst->inhabited, (int) s->owner);
  331. X                    }
  332. X                    sprintf(telegram_buf, "%s arrived at %s.", Ship(s),
  333. X                        prin_ship_orbits(s));
  334. X                    if (send_messages)
  335. X                        push_telegram((int) (s->owner),
  336. X                                  (int) s->governor, telegram_buf);
  337. X                    if (s->whatdest == LEVEL_STAR)
  338. X                        s->whatdest = LEVEL_UNIV;
  339. X                }
  340. X            } else if (destlevel == LEVEL_PLAN && deststar == s->storbits) {
  341. X                /*
  342. X                 * headed for a planet in the same system, &
  343. X                 * not already there..
  344. X                 */
  345. X                dist = sqrt(Distsq(s->xpos, s->ypos,
  346. X                           dst->xpos + dpl->xpos, dst->ypos + dpl->ypos));
  347. X                if (dist <= PLORBITSIZE) {
  348. X                    if (!checking_fuel && (s->popn || s->type == OTYPE_PROBE)) {
  349. X                        dpl->info[s->owner - 1].explored = 1;
  350. X                        setbit(dst->explored, (int) (s->owner));
  351. X                        setbit(dst->inhabited, (int) (s->owner));
  352. X                    }
  353. X                    s->whatorbits = LEVEL_PLAN;
  354. X                    s->pnumorbits = destpnum;
  355. X                    if (dist <= (double) DIST_TO_LAND) {
  356. X                        sprintf(telegram_buf, "%s within landing distance of %s.",
  357. X                            Ship(s), prin_ship_orbits(s));
  358. X                        if (checking_fuel || !do_merchant(s, dpl))
  359. X                            if (s->whatdest == LEVEL_PLAN)
  360. X                                s->whatdest = LEVEL_UNIV;
  361. X                    } else {
  362. X                        sprintf(telegram_buf, "%s arriving at %s.",
  363. X                            Ship(s), prin_ship_orbits(s));
  364. X                    }
  365. X                    if (s->type == STYPE_OAP) {
  366. X                        sprintf(buf, "\nEnslavement of the planet is now possible.");
  367. X                        strcat(telegram_buf, buf);
  368. X                    }
  369. X                    if (send_messages)
  370. X                        push_telegram((int) (s->owner), (int) s->governor, telegram_buf);
  371. X                }
  372. X            } else if (destlevel == LEVEL_SHIP) {
  373. X                dist = sqrt(Distsq(s->xpos, s->ypos, dsh->xpos, dsh->ypos));
  374. X                if (dist <= PLORBITSIZE) {
  375. X                    if (dsh->whatorbits == LEVEL_PLAN) {
  376. X                        s->whatorbits = LEVEL_PLAN;
  377. X                        s->storbits = dsh->storbits;
  378. X                        s->pnumorbits = dsh->pnumorbits;
  379. X                    } else if (dsh->whatorbits == LEVEL_STAR) {
  380. X                        s->whatorbits = LEVEL_STAR;
  381. X                        s->storbits = dsh->storbits;
  382. X                        s->protect.planet = 0;
  383. X                    }
  384. X                }
  385. X            }
  386. X        }        /* 'destination' orders */
  387. X    }            /* if impulse drive */
  388. X}
  389. X
  390. X
  391. X/*
  392. X * deliver an "out of fuel" message.  Used by a number of ship-updating code
  393. X * segments; so that code isn't duplicated.
  394. X */
  395. Xvoid 
  396. Xmsg_OOF(shiptype * s)
  397. X{
  398. X    sprintf(buf, "%s is out of fuel at %s.", Ship(s), prin_ship_orbits(s));
  399. X    push_telegram((int) (s->owner), (int) s->governor, buf);
  400. X}
  401. X
  402. X
  403. X/* followable: returns 1 iff s1 can follow s2 */
  404. Xint 
  405. Xfollowable(shiptype * s1, shiptype * s2)
  406. X{
  407. X    double          dx, dy;
  408. X    racetype       *r;
  409. X    double          range;
  410. X    int             allied[2];
  411. X
  412. X    if (!s2->alive || !s1->active || s2->whatorbits == LEVEL_SHIP)
  413. X        return 0;
  414. X
  415. X    dx = s1->xpos - s2->xpos;
  416. X    dy = s1->ypos - s2->ypos;
  417. X
  418. X    range = 4.0 * logscale((int) (s1->tech + 1.0)) * SYSTEMSIZE;
  419. X
  420. X    r = races[s2->owner - 1];
  421. X    allied[0] = r->allied[0];
  422. X    allied[1] = r->allied[1];
  423. X    /* You can follow your own ships, your allies' ships, or nearby ships */
  424. X    return (s1->owner == s2->owner) ||
  425. X        (isset(allied, (int) s1->owner)) ||
  426. X        (sqrt(dx * dx + dy * dy) <= range);
  427. X}
  428. X
  429. X
  430. X/*
  431. X * this routine will do landing, launching, loading, unloading, etc for
  432. X * merchant ships. The ship is within landing distance of the target planet
  433. X */
  434. Xint 
  435. Xdo_merchant(shiptype * s, planettype * p)
  436. X{
  437. X    reg int         i, j;
  438. X    double          fuel;
  439. X    char            load, unload;
  440. X    int             amount;
  441. X    sectortype     *sect;
  442. X
  443. X    i = s->owner - 1;
  444. X    j = s->merchant - 1;    /* try to speed things up a bit */
  445. X
  446. X    if (!s->merchant || !p->info[i].route[j].set)    /* not on shipping route */
  447. X        return 0;
  448. X    /* check to see if the sector is owned by the player */
  449. X    getsector(§, p, p->info[i].route[j].x, p->info[i].route[j].y);
  450. X    if (sect->owner && (sect->owner != s->owner)) {
  451. X        free(sect);
  452. X        return 0;
  453. X    }
  454. X    free(sect);
  455. X
  456. X    if (!landed(s)) {    /* try to land the ship */
  457. X        fuel = s->mass * gravity(p) * LAND_GRAV_MASS_FACTOR;
  458. X        if (s->fuel < fuel) {    /* ship can't land - cancel all
  459. X                     * orders */
  460. X            s->whatdest = LEVEL_UNIV;
  461. X            strcat(telegram_buf, "\t\tNot enough fuel to land!\n");
  462. X            return 1;
  463. X        }
  464. X        s->land_x = p->info[i].route[j].x;
  465. X        s->land_y = p->info[i].route[j].y;
  466. X        sprintf(buf, "\t\tLanded on sector %d,%d\n",
  467. X            s->land_x, s->land_y);
  468. X        strcat(telegram_buf, buf);
  469. X        s->xpos = p->xpos + Stars[s->storbits]->xpos;
  470. X        s->ypos = p->ypos + Stars[s->storbits]->ypos;
  471. X        use_fuel(s, fuel);
  472. X        s->docked = 1;
  473. X        s->whatdest = LEVEL_PLAN;
  474. X        s->deststar = s->storbits;
  475. X        s->destpnum = s->pnumorbits;
  476. X    }
  477. X    /* load and unload supplies specified by the planet */
  478. X    load = p->info[i].route[j].load;
  479. X    unload = p->info[i].route[j].unload;
  480. X    if (load) {
  481. X        strcat(telegram_buf, "\t\t");
  482. X        if (Fuel(load)) {
  483. X            amount = (int) s->max_fuel - (int) s->fuel;
  484. X            if (amount > p->info[i].fuel)
  485. X                amount = p->info[i].fuel;
  486. X            p->info[i].fuel -= amount;
  487. X            rcv_fuel(s, (double) amount);
  488. X            sprintf(buf, "%df ", amount);
  489. X            strcat(telegram_buf, buf);
  490. X        }
  491. X        if (Resources(load)) {
  492. X            amount = (int) s->max_resource - (int) s->resource;
  493. X            if (amount > p->info[i].resource)
  494. X                amount = p->info[i].resource;
  495. X            p->info[i].resource -= amount;
  496. X            rcv_resource(s, amount);
  497. X            sprintf(buf, "%dr ", amount);
  498. X            strcat(telegram_buf, buf);
  499. X        }
  500. X        if (Crystals(load)) {
  501. X            amount = p->info[i].crystals;
  502. X            p->info[i].crystals -= amount;
  503. X            s->crystals += amount;
  504. X            sprintf(buf, "%dx ", amount);
  505. X            strcat(telegram_buf, buf);
  506. X        }
  507. X        if (Destruct(load)) {
  508. X            amount = (int) s->max_destruct - (int) s->destruct;
  509. X            if (amount > p->info[i].destruct)
  510. X                amount = p->info[i].destruct;
  511. X            p->info[i].destruct -= amount;
  512. X            rcv_destruct(s, amount);
  513. X            sprintf(buf, "%dd ", amount);
  514. X            strcat(telegram_buf, buf);
  515. X        }
  516. X        strcat(telegram_buf, "loaded\n");
  517. X    }
  518. X    if (unload) {
  519. X        strcat(telegram_buf, "\t\t");
  520. X        if (Fuel(unload)) {
  521. X            amount = (int) s->fuel;
  522. X            p->info[i].fuel += amount;
  523. X            sprintf(buf, "%df ", amount);
  524. X            strcat(telegram_buf, buf);
  525. X            use_fuel(s, (double) amount);
  526. X        }
  527. X        if (Resources(unload)) {
  528. X            amount = s->resource;
  529. X            p->info[i].resource += amount;
  530. X            sprintf(buf, "%dr ", amount);
  531. X            strcat(telegram_buf, buf);
  532. X            use_resource(s, amount);
  533. X        }
  534. X        if (Crystals(unload)) {
  535. X            amount = s->crystals;
  536. X            p->info[i].crystals += amount;
  537. X            sprintf(buf, "%dx ", amount);
  538. X            strcat(telegram_buf, buf);
  539. X            s->crystals -= amount;
  540. X        }
  541. X        if (Destruct(unload)) {
  542. X            amount = s->destruct;
  543. X            p->info[i].destruct += amount;
  544. X            sprintf(buf, "%dd ", amount);
  545. X            strcat(telegram_buf, buf);
  546. X            use_destruct(s, amount);
  547. X        }
  548. X        strcat(telegram_buf, "unloaded\n");
  549. X    }
  550. X    /* launch the ship */
  551. X    fuel = s->mass * gravity(p) * LAUNCH_GRAV_MASS_FACTOR;
  552. X    if (s->fuel < fuel) {
  553. X        strcat(telegram_buf, "\t\tNot enough fuel to launch!\n");
  554. X        return 1;
  555. X    }
  556. X    /* ship is ready to fly - order the ship to its next destination */
  557. X    s->whatdest = LEVEL_PLAN;
  558. X    s->deststar = p->info[i].route[j].dest_star;
  559. X    s->destpnum = p->info[i].route[j].dest_planet;
  560. X    s->docked = 0;
  561. X    use_fuel(s, fuel);
  562. X    sprintf(buf, "\t\tDestination set to %s\n",
  563. X        prin_ship_dest((int) s->owner, (int) s->governor, s));
  564. X    strcat(telegram_buf, buf);
  565. X    if (s->hyper_drive.has) {    /* order the ship to jump if it can */
  566. X        if (s->storbits != s->deststar) {
  567. X            s->navigate.on = 0;
  568. X            s->hyper_drive.on = 1;
  569. X            if (s->mounted) {
  570. X                s->hyper_drive.charge = 1;
  571. X                s->hyper_drive.ready = 1;
  572. X            } else {
  573. X                s->hyper_drive.charge = 0;
  574. X                s->hyper_drive.ready = 0;
  575. X            }
  576. X            strcat(telegram_buf, "\t\tJump orders set\n");
  577. X        }
  578. X    }
  579. X    return 1;
  580. X}
  581. END_OF_FILE
  582. if test 16801 -ne `wc -c <'server/moveship.c'`; then
  583.     echo shar: \"'server/moveship.c'\" unpacked with wrong size!
  584. fi
  585. # end of 'server/moveship.c'
  586. fi
  587. if test -f 'user/load.c' -a "${1}" != "-c" ; then 
  588.   echo shar: Will not clobber existing file \"'user/load.c'\"
  589. else
  590. echo shar: Extracting \"'user/load.c'\" \(34277 characters\)
  591. sed "s/^X//" >'user/load.c' <<'END_OF_FILE'
  592. X/*
  593. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  594. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  595. X * GB_copyright.h.
  596. X * 
  597. X * load.c -- load/unload stuff
  598. X */
  599. X#include <signal.h>
  600. X
  601. X#include "GB_copyright.h"
  602. X#define EXTERN extern
  603. X#include "vars.h"
  604. X#include "ships.h"
  605. X#include "races.h"
  606. X#include "power.h"
  607. X#include "buffers.h"
  608. X
  609. Xextern char     Dessymbols[];
  610. Xextern char    *Desnames[];
  611. Xextern int      Defensedata[];
  612. Xchar            buff[128], bufr[128], bufd[128], bufc[128], bufx[128],
  613. X                bufm[128];
  614. X
  615. Xvoid            load(int, int, int, int);
  616. Xvoid            jettison(int, int, int);
  617. Xint             jettison_check(int, int, int, int);
  618. Xvoid            dump(int, int, int);
  619. Xvoid            transfer(int, int, int);
  620. Xvoid            mount(int, int, int, int);
  621. Xvoid            use_fuel(shiptype *, double);
  622. Xvoid            use_destruct(shiptype *, int);
  623. Xvoid            use_resource(shiptype *, int);
  624. Xvoid            use_popn(shiptype *, int, double);
  625. Xvoid            rcv_fuel(shiptype *, double);
  626. Xvoid            rcv_resource(shiptype *, int);
  627. Xvoid            rcv_destruct(shiptype *, int);
  628. Xvoid            rcv_popn(shiptype *, int, double);
  629. Xvoid            rcv_troops(shiptype *, int, double);
  630. Xvoid            do_transporter(racetype *, int, shiptype *);
  631. Xint             landed_on(shiptype *, int);
  632. Xvoid 
  633. Xunload_onto_alien_sector(int, int, planettype *, shiptype *,
  634. X             sectortype *, int, int);
  635. X#include "proto.h"
  636. X
  637. Xvoid 
  638. Xload(int Playernum, int Governor, int APcount, int mode)
  639. X{
  640. X    char            commod;
  641. X    unsigned char   sh = 0, diff = 0;
  642. X    int             lolim, uplim, amt;
  643. X    int             transfercrew;
  644. X    shiptype       *s, *s2;
  645. X    planettype     *p;
  646. X    sectortype     *sect;
  647. X    racetype       *Race;
  648. X    int             shipno, nextshipno;
  649. X
  650. X    if (argn < 2) {
  651. X        notify(Playernum, Governor, "Load what?\n");
  652. X        return;
  653. X    }
  654. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  655. X
  656. X    while (shipno = do_shiplist(&s, &nextshipno))
  657. X        if (in_list(Playernum, args[1], s, &nextshipno) &&
  658. X            authorized(Governor, s)) {
  659. X            if (s->owner != Playernum || !s->alive) {
  660. X                free(s);
  661. X                continue;
  662. X            }
  663. X            if (!s->active) {
  664. X                sprintf(buf, "%s is irradiated and inactive.\n", Ship(s));
  665. X                notify(Playernum, Governor, buf);
  666. X                free(s);
  667. X                continue;
  668. X            }
  669. X            if (s->whatorbits == LEVEL_UNIV) {
  670. X                if (!enufAP(Playernum, Governor, Sdata.AP[Playernum - 1], APcount)) {
  671. X                    free(s);
  672. X                    continue;
  673. X                }
  674. X            } else if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount))
  675. X                continue;
  676. X            if (!s->docked) {
  677. X                sprintf(buf, "%s is not landed or docked.\n", Ship(s));
  678. X                notify(Playernum, Governor, buf);
  679. X                free(s);
  680. X                continue;
  681. X            } else {/* ship has a recipient */
  682. X                if (s->whatdest == LEVEL_PLAN) {
  683. X                    sprintf(buf, "%s at %d,%d\n", Ship(s), s->land_x, s->land_y);
  684. X                    notify(Playernum, Governor, buf);
  685. X                    if (s->storbits != Dir[Playernum - 1][Governor].snum ||
  686. X                        s->pnumorbits != Dir[Playernum - 1][Governor].pnum) {
  687. X                        notify(Playernum, Governor, "Change scope to the planet this ship is landed on.\n");
  688. X                        free(s);
  689. X                        continue;
  690. X                    }
  691. X                } else {    /* ship is docked */
  692. X                    if (!s->destshipno) {
  693. X                        sprintf(buf, "%s is not docked.\n", Ship(s));
  694. X                        free(s);
  695. X                        continue;
  696. X                    }
  697. X                    if (!getship(&s2, (int) s->destshipno)) {
  698. X                        notify(Playernum, Governor, "Destination ship is bogus.\n");
  699. X                        free(s);
  700. X                        continue;
  701. X                    }
  702. X                    if (!s2->alive ||
  703. X                        !(s->whatorbits == LEVEL_SHIP || s2->destshipno == shipno)) {
  704. X                        /*
  705. X                         * the ship it was docked
  706. X                         * with died or undocked with
  707. X                         * it or something.
  708. X                         */
  709. X                        s->docked = 0;
  710. X                        s->whatdest = LEVEL_UNIV;
  711. X                        putship(s);
  712. X                        sprintf(buf, "%s is not docked.\n", Ship(s2));
  713. X                        notify(Playernum, Governor, buf);
  714. X                        free(s);
  715. X                        free(s2);
  716. X                        continue;
  717. X                    }
  718. X                    if (overloaded(s2) && s2->whatorbits == LEVEL_SHIP) {
  719. X                        sprintf(buf, "%s is overloaded!\n", Ship(s2));
  720. X                        notify(Playernum, Governor, buf);
  721. X                        free(s);
  722. X                        free(s2);
  723. X                        continue;
  724. X                    }
  725. X                    sprintf(buf, "%s docked with %s\n", Ship(s), Ship(s2));
  726. X                    notify(Playernum, Governor, buf);
  727. X                    sh = 1;
  728. X                    if (s2->owner != Playernum) {
  729. X                        sprintf(buf, "Player %d owns that ship.\n", s2->owner);
  730. X                        notify(Playernum, Governor, buf);
  731. X                        diff = 1;
  732. X                    }
  733. X                }
  734. X            }
  735. X
  736. X            commod = args[2][0];
  737. X            if (argn > 3)
  738. X                amt = atoi(args[3]);
  739. X            else
  740. X                amt = 0;
  741. X
  742. X            if (mode)
  743. X                amt = -amt;    /* unload */
  744. X
  745. X            if (!sh)
  746. X                getplanet(&p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  747. X
  748. X            if (!sh && (commod == 'c' || commod == 'm'))
  749. X                getsector(§, p, (int) s->land_x, (int) s->land_y);
  750. X
  751. X            switch (commod) {
  752. X            case 'x':
  753. X            case '&':
  754. X                if (sh) {
  755. X                    uplim = diff ? 0 : MIN(s2->crystals, Max_crystals(s) - s->crystals);
  756. X                    lolim = diff ? 0 : -MIN(s->crystals, Max_crystals(s2) - s2->crystals);
  757. X                } else {
  758. X                    uplim = MIN(p->info[Playernum - 1].crystals, Max_crystals(s) - s->crystals);
  759. X                    lolim = -s->crystals;
  760. X                }
  761. X                break;
  762. X            case 'c':
  763. X                if (sh) {
  764. X                    uplim = diff ? 0 : MIN(s2->popn, Max_crew(s) - s->popn);
  765. X                    lolim = diff ? 0 : -MIN(s->popn, Max_crew(s2) - s2->popn);
  766. X                } else {
  767. X                    uplim = MIN(sect->popn, Max_crew(s) - s->popn);
  768. X                    lolim = -s->popn;
  769. X                }
  770. X                break;
  771. X            case 'm':
  772. X                if (sh) {
  773. X                    uplim = diff ? 0 : MIN(s2->troops, Max_mil(s) - s->troops);
  774. X                    lolim = diff ? 0 : -MIN(s->troops, Max_mil(s2) - s2->troops);
  775. X                } else {
  776. X                    uplim = MIN(sect->troops, Max_mil(s) - s->troops);
  777. X                    lolim = -s->troops;
  778. X                }
  779. X                break;
  780. X            case 'd':
  781. X                if (sh) {
  782. X                    uplim = diff ? 0 : MIN(s2->destruct, Max_destruct(s) - s->destruct);
  783. X                    lolim = -MIN(s->destruct, Max_destruct(s2) - s2->destruct);
  784. X                } else {
  785. X                    uplim = MIN(p->info[Playernum - 1].destruct, Max_destruct(s) - s->destruct);
  786. X                    lolim = -s->destruct;
  787. X                }
  788. X                break;
  789. X            case 'f':
  790. X                if (sh) {
  791. X                    uplim = diff ? 0 : MIN((int) s2->fuel, (int) Max_fuel(s) - (int) s->fuel);
  792. X                    lolim = -MIN((int) s->fuel, (int) Max_fuel(s2) - (int) s2->fuel);
  793. X                } else {
  794. X                    uplim = MIN((int) p->info[Playernum - 1].fuel, (int) Max_fuel(s) - (int) s->fuel);
  795. X                    lolim = -(int) s->fuel;
  796. X                }
  797. X                break;
  798. X            case 'r':
  799. X                if (sh) {
  800. X                    if (s->type == STYPE_SHUTTLE && s->whatorbits != LEVEL_SHIP)
  801. X                        uplim = diff ? 0 : s2->resource;
  802. X                    else
  803. X                        uplim = diff ? 0 : MIN(s2->resource, Max_resource(s) - s->resource);
  804. X                    if (s2->type == STYPE_SHUTTLE && s->whatorbits != LEVEL_SHIP)
  805. X                        lolim = -s->resource;
  806. X                    else
  807. X                        lolim = -MIN(s->resource, Max_resource(s2) - s2->resource);
  808. X                } else {
  809. X                    uplim = MIN(p->info[Playernum - 1].resource, Max_resource(s) - s->resource);
  810. X                    lolim = -s->resource;
  811. X                }
  812. X                break;
  813. X            default:
  814. X                notify(Playernum, Governor, "No such commodity valid.\n");
  815. X                if (sh)
  816. X                    free(s2);
  817. X                else
  818. X                    free(p);
  819. X                free(s);
  820. X                continue;
  821. X            }
  822. X
  823. X            if (amt < lolim || amt > uplim) {
  824. X                sprintf(buf, "you can only transfer between %d and %d.\n", lolim, uplim);
  825. X                notify(Playernum, Governor, buf);
  826. X
  827. X                if (sh)
  828. X                    free(s2);
  829. X                else
  830. X                    free(p);
  831. X                free(s);
  832. X                continue;
  833. X            }
  834. X            Race = races[Playernum - 1];
  835. X
  836. X            if (amt == 0)
  837. X                amt = (mode ? lolim : uplim);
  838. X
  839. X            switch (commod) {
  840. X            case 'c':
  841. X                if (sh) {
  842. X                    s2->popn -= amt;
  843. X                    if (!landed_on(s, sh))
  844. X                        s2->mass -= amt * Race->mass;
  845. X                    transfercrew = 1;
  846. X                } else if (sect->owner && sect->owner != Playernum) {
  847. X                    sprintf(buf, "That sector is already occupied by another player!\n");
  848. X                    notify(Playernum, Governor, buf);
  849. X                    /* fight a land battle */
  850. X                    unload_onto_alien_sector(Playernum, Governor, p, s, sect, CIV, -amt);
  851. X                    putship(s);
  852. X                    putsector(sect, p, (int) s->land_x, (int) s->land_y);
  853. X                    putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  854. X                    free(s);
  855. X                    free(sect);
  856. X                    free(p);
  857. X                    return;
  858. X                } else {
  859. X                    transfercrew = 1;
  860. X                    if (!sect->popn && !sect->troops && amt < 0) {
  861. X                        p->info[Playernum - 1].numsectsowned++;
  862. X                        p->info[Playernum - 1].mob_points += sect->mobilization;
  863. X                        sect->owner = Playernum;
  864. X                        sprintf(buf, "sector %d,%d COLONIZED.\n",
  865. X                              s->land_x, s->land_y);
  866. X                        notify(Playernum, Governor, buf);
  867. X                    }
  868. X                    sect->popn -= amt;
  869. X                    p->popn -= amt;
  870. X                    p->info[Playernum - 1].popn -= amt;
  871. X                    if (!sect->popn && !sect->troops) {
  872. X                        p->info[Playernum - 1].numsectsowned--;
  873. X                        p->info[Playernum - 1].mob_points -= sect->mobilization;
  874. X                        sect->owner = 0;
  875. X                        sprintf(buf, "sector %d,%d evacuated.\n",
  876. X                              s->land_x, s->land_y);
  877. X                        notify(Playernum, Governor, buf);
  878. X                    }
  879. X                }
  880. X                if (transfercrew) {
  881. X                    s->popn += amt;
  882. X                    s->mass += amt * Race->mass;
  883. X                    sprintf(buf, "crew complement of %s is now %u.\n",
  884. X                        Ship(s), s->popn);
  885. X                    notify(Playernum, Governor, buf);
  886. X                }
  887. X                break;
  888. X            case 'm':
  889. X                if (sh) {
  890. X                    s2->troops -= amt;
  891. X                    if (!landed_on(s, sh))
  892. X                        s2->mass -= amt * Race->mass;
  893. X                    transfercrew = 1;
  894. X                } else if (sect->owner && sect->owner != Playernum) {
  895. X                    sprintf(buf, "That sector is already occupied by another player!\n");
  896. X                    notify(Playernum, Governor, buf);
  897. X                    unload_onto_alien_sector(Playernum, Governor, p, s, sect, MIL, -amt);
  898. X                    putship(s);
  899. X                    putsector(sect, p, (int) s->land_x, (int) s->land_y);
  900. X                    putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  901. X                    free(s);
  902. X                    free(sect);
  903. X                    free(p);
  904. X                    return;
  905. X                } else {
  906. X                    transfercrew = 1;
  907. X                    if (!(sect->popn + sect->troops) && amt < 0) {
  908. X                        p->info[Playernum - 1].numsectsowned++;
  909. X                        p->info[Playernum - 1].mob_points += sect->mobilization;
  910. X                        sect->owner = Playernum;
  911. X                        sprintf(buf, "sector %d,%d OCCUPIED.\n",
  912. X                              s->land_x, s->land_y);
  913. X                        notify(Playernum, Governor, buf);
  914. X                    }
  915. X                    sect->troops -= amt;
  916. X                    p->troops -= amt;
  917. X                    p->info[Playernum - 1].troops -= amt;
  918. X                    if (!(sect->troops + sect->popn)) {
  919. X                        p->info[Playernum - 1].numsectsowned--;
  920. X                        p->info[Playernum - 1].mob_points -= sect->mobilization;
  921. X                        sect->owner = 0;
  922. X                        sprintf(buf, "sector %d,%d evacuated.\n",
  923. X                              s->land_x, s->land_y);
  924. X                        notify(Playernum, Governor, buf);
  925. X                    }
  926. X                }
  927. X                if (transfercrew) {
  928. X                    s->troops += amt;
  929. X                    s->mass += amt * Race->mass;
  930. X                    sprintf(buf, "troop complement of %s is now %u.\n",
  931. X                        Ship(s), s->troops);
  932. X                    notify(Playernum, Governor, buf);
  933. X                }
  934. X                break;
  935. X            case 'd':
  936. X                if (sh) {
  937. X                    s2->destruct -= amt;
  938. X                    if (!landed_on(s, sh))
  939. X                        s2->mass -= amt * MASS_DESTRUCT;
  940. X                } else
  941. X                    p->info[Playernum - 1].destruct -= amt;
  942. X
  943. X                s->destruct += amt;
  944. X                s->mass += amt * MASS_DESTRUCT;
  945. X                sprintf(buf, "%d destruct transferred.\n", amt);
  946. X                notify(Playernum, Governor, buf);
  947. X                if (!Max_crew(s)) {
  948. X                    sprintf(buf, "\n%s ", Ship(s));
  949. X                    notify(Playernum, Governor, buf);
  950. X                    if (s->destruct) {
  951. X                        sprintf(buf, "now boobytrapped.\n");
  952. X                    } else {
  953. X                        sprintf(buf, "no longer boobytrapped.\n");
  954. X                    }
  955. X                    notify(Playernum, Governor, buf);
  956. X                }
  957. X                break;
  958. X            case 'x':
  959. X                if (sh) {
  960. X                    s2->crystals -= amt;
  961. X                } else
  962. X                    p->info[Playernum - 1].crystals -= amt;
  963. X                s->crystals += amt;
  964. X                sprintf(buf, "%d crystal(s) transferred.\n", amt);
  965. X                notify(Playernum, Governor, buf);
  966. X                break;
  967. X            case 'f':
  968. X                if (sh) {
  969. X                    s2->fuel -= (double) amt;
  970. X                    if (!landed_on(s, sh))
  971. X                        s2->mass -= (double) amt *MASS_FUEL;
  972. X                } else
  973. X                    p->info[Playernum - 1].fuel -= amt;
  974. X                rcv_fuel(s, (double) amt);
  975. X                sprintf(buf, "%d fuel transferred.\n", amt);
  976. X                notify(Playernum, Governor, buf);
  977. X                break;
  978. X            case 'r':
  979. X                if (sh) {
  980. X                    s2->resource -= amt;
  981. X                    if (!landed_on(s, sh))
  982. X                        s2->mass -= amt * MASS_RESOURCE;
  983. X                } else
  984. X                    p->info[Playernum - 1].resource -= amt;
  985. X                rcv_resource(s, amt);
  986. X                sprintf(buf, "%d resources transferred.\n", amt);
  987. X                notify(Playernum, Governor, buf);
  988. X                break;
  989. X            default:
  990. X                notify(Playernum, Governor, "No such commodity.\n");
  991. X
  992. X                if (sh)
  993. X                    free(s2);
  994. X                else
  995. X                    free(p);
  996. X                free(s);
  997. X                continue;
  998. X            }
  999. X
  1000. X            if (sh) {
  1001. X                /* ship to ship transfer */
  1002. X                buff[0] = bufr[0] = bufd[0] = bufc[0] = '\0';
  1003. X                switch (commod) {
  1004. X                case 'r':
  1005. X                    sprintf(buf, "%d resources transferred.\n", amt);
  1006. X                    notify(Playernum, Governor, buf);
  1007. X                    sprintf(bufr, "%d Resources\n", amt);
  1008. X                    break;
  1009. X                case 'f':
  1010. X                    sprintf(buf, "%d fuel transferred.\n", amt);
  1011. X                    notify(Playernum, Governor, buf);
  1012. X                    sprintf(buff, "%d Fuel\n", amt);
  1013. X                    break;
  1014. X                case 'd':
  1015. X                    sprintf(buf, "%d destruct transferred.\n", amt);
  1016. X                    notify(Playernum, Governor, buf);
  1017. X                    sprintf(bufd, "%d Destruct\n", amt);
  1018. X                    break;
  1019. X                case 'x':
  1020. X                case '&':
  1021. X                    sprintf(buf, "%d crystals transferred.\n", amt);
  1022. X                    notify(Playernum, Governor, buf);
  1023. X                    sprintf(bufd, "%d Crystal(s)\n", amt);
  1024. X                    break;
  1025. X                case 'c':
  1026. X                    sprintf(buf, "%d popn transferred.\n", amt);
  1027. X                    notify(Playernum, Governor, buf);
  1028. X                    sprintf(bufc, "%d %s\n", amt,
  1029. X                        Race->Metamorph ? "tons of biomass" : "population");
  1030. X                    break;
  1031. X                case 'm':
  1032. X                    sprintf(buf, "%d military transferred.\n", amt);
  1033. X                    notify(Playernum, Governor, buf);
  1034. X                    sprintf(bufm, "%d %s\n", amt,
  1035. X                        Race->Metamorph ? "tons of biomass" : "population");
  1036. X                    break;
  1037. X                default:
  1038. X                    break;
  1039. X                }
  1040. X                putship(s2);
  1041. X                free(s2);
  1042. X            } else {
  1043. X                if (commod == 'c' || commod == 'm') {
  1044. X                    putsector(sect, p, (int) s->land_x, (int) s->land_y);
  1045. X                    free(sect);
  1046. X                }
  1047. X                putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1048. X                free(p);
  1049. X            }
  1050. X
  1051. X            /* do transporting here */
  1052. X            if (s->type == OTYPE_TRANSDEV && s->special.transport.target && s->on)
  1053. X                do_transporter(Race, Governor, s);
  1054. X
  1055. X            putship(s);
  1056. X            free(s);
  1057. X        } else
  1058. X            free(s);/* make sure you do this! */
  1059. X}
  1060. X
  1061. Xvoid 
  1062. Xjettison(int Playernum, int Governor, int APcount)
  1063. X{
  1064. X    int             Mod = 0;
  1065. X    int             shipno, nextshipno;
  1066. X    int             amt;
  1067. X    char            commod;
  1068. X    shiptype       *s;
  1069. X    racetype       *Race;
  1070. X
  1071. X    if (argn < 2) {
  1072. X        notify(Playernum, Governor, "Jettison what?\n");
  1073. X        return;
  1074. X    }
  1075. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  1076. X
  1077. X    while (shipno = do_shiplist(&s, &nextshipno))
  1078. X        if (in_list(Playernum, args[1], s, &nextshipno) &&
  1079. X            authorized(Governor, s)) {
  1080. X            if (s->owner != Playernum || !s->alive) {
  1081. X                free(s);
  1082. X                continue;
  1083. X            }
  1084. X            if (landed(s)) {
  1085. X                notify(Playernum, Governor, "Ship is landed, cannot jettison.\n");
  1086. X                free(s);
  1087. X                continue;
  1088. X            }
  1089. X            if (!s->active) {
  1090. X                sprintf(buf, "%s is irradiated and inactive.\n", Ship(s));
  1091. X                notify(Playernum, Governor, buf);
  1092. X                free(s);
  1093. X                continue;
  1094. X            }
  1095. X            if (s->whatorbits == LEVEL_UNIV) {
  1096. X                if (!enufAP(Playernum, Governor, Sdata.AP[Playernum - 1], APcount)) {
  1097. X                    free(s);
  1098. X                    continue;
  1099. X                }
  1100. X            } else if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount)) {
  1101. X                free(s);
  1102. X                continue;
  1103. X            }
  1104. X            if (argn > 3)
  1105. X                amt = atoi(args[3]);
  1106. X            else
  1107. X                amt = 0;
  1108. X
  1109. X            Race = races[Playernum - 1];
  1110. X
  1111. X            commod = args[2][0];
  1112. X            switch (commod) {
  1113. X            case 'x':
  1114. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->crystals))) > 0) {
  1115. X                    s->crystals -= amt;
  1116. X                    sprintf(buf, "%d crystal%s jettisoned.\n", amt, (amt == 1) ? "" : "s");
  1117. X                    notify(Playernum, Governor, buf);
  1118. X                    Mod = 1;
  1119. X                }
  1120. X                break;
  1121. X            case 'c':
  1122. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->popn))) > 0) {
  1123. X                    s->popn -= amt;
  1124. X                    s->mass -= amt * Race->mass;
  1125. X                    sprintf(buf, "%d crew %s into deep space.\n",
  1126. X                        amt, (amt == 1) ? "hurls itself" : "hurl themselves");
  1127. X                    notify(Playernum, Governor, buf);
  1128. X                    sprintf(buf, "Complement of %s is now %u.\n", Ship(s), s->popn);
  1129. X                    notify(Playernum, Governor, buf);
  1130. X                    Mod = 1;
  1131. X                }
  1132. X                break;
  1133. X            case 'm':
  1134. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->troops))) > 0) {
  1135. X                    sprintf(buf, "%d military %s into deep space.\n",
  1136. X                        amt, (amt == 1) ? "hurls itself" : "hurl themselves");
  1137. X                    notify(Playernum, Governor, buf);
  1138. X                    sprintf(buf, "Complement of ship #%d is now %u.\n",
  1139. X                        shipno, s->troops - amt);
  1140. X                    notify(Playernum, Governor, buf);
  1141. X                    s->troops -= amt;
  1142. X                    s->mass -= amt * Race->mass;
  1143. X                    Mod = 1;
  1144. X                }
  1145. X                break;
  1146. X            case 'd':
  1147. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->destruct))) > 0) {
  1148. X                    use_destruct(s, amt);
  1149. X                    sprintf(buf, "%d destruct jettisoned.\n", amt);
  1150. X                    notify(Playernum, Governor, buf);
  1151. X                    if (!Max_crew(s)) {
  1152. X                        sprintf(buf, "\n%s ", Ship(s));
  1153. X                        notify(Playernum, Governor, buf);
  1154. X                        if (s->destruct) {
  1155. X                            notify(Playernum, Governor, "still boobytrapped.\n");
  1156. X                        } else {
  1157. X                            notify(Playernum, Governor, "no longer boobytrapped.\n");
  1158. X                        }
  1159. X                    }
  1160. X                    Mod = 1;
  1161. X                }
  1162. X                break;
  1163. X            case 'f':
  1164. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->fuel))) > 0) {
  1165. X                    use_fuel(s, (double) amt);
  1166. X                    sprintf(buf, "%d fuel jettisoned.\n", amt);
  1167. X                    notify(Playernum, Governor, buf);
  1168. X                    Mod = 1;
  1169. X                }
  1170. X                break;
  1171. X            case 'r':
  1172. X                if ((amt = jettison_check(Playernum, Governor, amt, (int) (s->resource))) > 0) {
  1173. X                    use_resource(s, amt);
  1174. X                    sprintf(buf, "%d resources jettisoned.\n", amt);
  1175. X                    notify(Playernum, Governor, buf);
  1176. X                    Mod = 1;
  1177. X                }
  1178. X                break;
  1179. X            default:
  1180. X                notify(Playernum, Governor, "No such commodity valid.\n");
  1181. X                return;
  1182. X            }
  1183. X            if (Mod)
  1184. X                putship(s);
  1185. X            free(s);
  1186. X        } else
  1187. X            free(s);
  1188. X}
  1189. X
  1190. Xint 
  1191. Xjettison_check(int Playernum, int Governor, int amt, int max)
  1192. X{
  1193. X    if (amt == 0)
  1194. X        amt = max;
  1195. X    if (amt < 0) {
  1196. X        notify(Playernum, Governor, "Nice try.\n");
  1197. X        return -1;
  1198. X    } else if (amt > max) {
  1199. X        sprintf(buf, "You can jettison at most %d\n", max);
  1200. X        notify(Playernum, Governor, buf);
  1201. X        return -1;
  1202. X    }
  1203. X    return amt;
  1204. X}
  1205. X
  1206. Xvoid 
  1207. Xdump(int Playernum, int Governor, int APcount)
  1208. X{
  1209. X    int             player, star, i, j;
  1210. X    racetype       *Race, *r;
  1211. X    placetype       where;
  1212. X
  1213. X    if (!enufAP(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1], APcount))
  1214. X        return;
  1215. X
  1216. X    if (!(player = GetPlayer(args[1]))) {
  1217. X        sprintf(buf, "No such player.\n");
  1218. X        notify(Playernum, Governor, buf);
  1219. X        return;
  1220. X    }
  1221. X    r = races[player - 1];
  1222. X
  1223. X    if (r->Guest) {
  1224. X        notify(Playernum, Governor, "Cheater!\n");
  1225. X        return;
  1226. X    }
  1227. X    /* transfer all planet and star knowledge to the player */
  1228. X    /* get all stars and planets */
  1229. X    Race = races[Playernum - 1];
  1230. X    if (Race->Guest) {
  1231. X        notify(Playernum, Governor, "Cheater!\n");
  1232. X        return;
  1233. X    }
  1234. X    if (Governor) {
  1235. X        notify(Playernum, Governor, "Only leaders are allowed to use dump.\n");
  1236. X        return;
  1237. X    }
  1238. X    getsdata(&Sdata);
  1239. X
  1240. X    if (argn < 3) {
  1241. X        for (star = 0; star < Sdata.numstars; star++) {
  1242. X            getstar(&Stars[star], star);
  1243. X
  1244. X            if (isset(Stars[star]->explored, Playernum)) {
  1245. X                setbit(Stars[star]->explored, player);
  1246. X
  1247. X                for (i = 0; i < Stars[star]->numplanets; i++) {
  1248. X                    getplanet(&planets[star][i], star, i);
  1249. X                    if (planets[star][i]->info[Playernum - 1].explored) {
  1250. X                        planets[star][i]->info[player - 1].explored = 1;
  1251. X                        putplanet(planets[star][i], star, i);
  1252. X                    }
  1253. X                }
  1254. X                putstar(Stars[star], star);
  1255. X            }
  1256. X        }
  1257. X    } else {        /* list of places given */
  1258. X        for (i = 2; i < argn; i++) {
  1259. X            where = Getplace(Playernum, Governor, args[i], 1);
  1260. X            if (!where.err && where.level != LEVEL_UNIV &&
  1261. X                where.level != LEVEL_SHIP) {
  1262. X                star = where.snum;
  1263. X                getstar(&Stars[star], star);
  1264. X
  1265. X                if (isset(Stars[star]->explored, Playernum)) {
  1266. X                    setbit(Stars[star]->explored, player);
  1267. X
  1268. X                    for (j = 0; j < Stars[star]->numplanets; j++) {
  1269. X                        getplanet(&planets[star][j], star, j);
  1270. X                        if (planets[star][j]->info[Playernum - 1].explored) {
  1271. X                            planets[star][j]->info[player - 1].explored = 1;
  1272. X                            putplanet(planets[star][j], star, j);
  1273. X                        }
  1274. X                    }
  1275. X                    putstar(Stars[star], star);
  1276. X                }
  1277. X            }
  1278. X        }
  1279. X    }
  1280. X
  1281. X    deductAPs(Playernum, Governor, APcount, Dir[Playernum - 1][Governor].snum, 0);
  1282. X
  1283. X    sprintf(buf, "%s [%d] has given you exploration data.\n", Race->name, Playernum);
  1284. X    warn_race(player, buf);
  1285. X    notify(Playernum, Governor, "Exploration Data transferred.\n");
  1286. X}
  1287. X
  1288. Xvoid 
  1289. Xtransfer(int Playernum, int Governor, int APcount)
  1290. X{
  1291. X    int             Mod = 0, player, give;
  1292. X    planettype     *planet;
  1293. X    char            commod = 0;
  1294. X    racetype       *r;
  1295. X
  1296. X    if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  1297. X        sprintf(buf, "You need to be in planet scope to do this.\n");
  1298. X        notify(Playernum, Governor, buf);
  1299. X        return;
  1300. X    }
  1301. X    if (!enufAP(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1], APcount))
  1302. X        return;
  1303. X
  1304. X    if (!(player = GetPlayer(args[1]))) {
  1305. X        sprintf(buf, "No such player.\n");
  1306. X        notify(Playernum, Governor, buf);
  1307. X        return;
  1308. X    }
  1309. X    r = races[player - 1];
  1310. X
  1311. X    getplanet(&planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1312. X
  1313. X    sscanf(args[2], "%c", &commod);
  1314. X    give = atoi(args[3]);
  1315. X
  1316. X    if (give < 0) {
  1317. X        notify(Playernum, Governor, "You must specify a positive amount.\n");
  1318. X        free(planet);
  1319. X        return;
  1320. X    }
  1321. X    sprintf(temp, "%s/%s:", Stars[Dir[Playernum - 1][Governor].snum]->name,
  1322. X        Stars[Dir[Playernum - 1][Governor].snum]->pnames[Dir[Playernum - 1][Governor].pnum]);
  1323. X    switch (commod) {
  1324. X    case 'r':
  1325. X        if (give > planet->info[Playernum - 1].resource) {
  1326. X            sprintf(buf, "You don't have %d on this planet.\n", give);
  1327. X            notify(Playernum, Governor, buf);
  1328. X        } else {
  1329. X            planet->info[Playernum - 1].resource -= give;
  1330. X            planet->info[player - 1].resource += give;
  1331. X            sprintf(buf, "%s %d resources transferred from player %d to player #%d\n",
  1332. X                temp, give, Playernum, player);
  1333. X            notify(Playernum, Governor, buf);
  1334. X            warn_race(player, buf);
  1335. X        }
  1336. X        break;
  1337. X    case 'x':
  1338. X    case '&':
  1339. X        if (give > planet->info[Playernum - 1].crystals) {
  1340. X            sprintf(buf, "You don't have %d on this planet.\n", give);
  1341. X            notify(Playernum, Governor, buf);
  1342. X        } else {
  1343. X            planet->info[Playernum - 1].crystals -= give;
  1344. X            planet->info[player - 1].crystals += give;
  1345. X            sprintf(buf, "%s %d crystal(s) transferred from player %d to player #%d\n",
  1346. X                temp, give, Playernum, player);
  1347. X            notify(Playernum, Governor, buf);
  1348. X            warn_race(player, buf);
  1349. X        }
  1350. X        break;
  1351. X    case 'f':
  1352. X        if (give > planet->info[Playernum - 1].fuel) {
  1353. X            sprintf(buf, "You don't have %d fuel on this planet.\n", give);
  1354. X            notify(Playernum, Governor, buf);
  1355. X        } else {
  1356. X            planet->info[Playernum - 1].fuel -= give;
  1357. X            planet->info[player - 1].fuel += give;
  1358. X            sprintf(buf, "%s %d fuel transferred from player %d to player #%d\n",
  1359. X                temp, give, Playernum, player);
  1360. X            notify(Playernum, Governor, buf);
  1361. X            warn_race(player, buf);
  1362. X        }
  1363. X        break;
  1364. X    case 'd':
  1365. X        if (give > planet->info[Playernum - 1].destruct) {
  1366. X            sprintf(buf, "You don't have %d destruct on this planet.\n", give);
  1367. X            notify(Playernum, Governor, buf);
  1368. X        } else {
  1369. X            planet->info[Playernum - 1].destruct -= give;
  1370. X            planet->info[player - 1].destruct += give;
  1371. X            sprintf(buf, "%s %d destruct transferred from player %d to player #%d\n",
  1372. X                temp, give, Playernum, player);
  1373. X            notify(Playernum, Governor, buf);
  1374. X            warn_race(player, buf);
  1375. X        }
  1376. X        break;
  1377. X    default:
  1378. X        sprintf(buf, "What?\n");
  1379. X        notify(Playernum, Governor, buf);
  1380. X    }
  1381. X
  1382. X    putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1383. X
  1384. X    free(planet);
  1385. X    Mod = 1;
  1386. X
  1387. X    deductAPs(Playernum, Governor, APcount, Dir[Playernum - 1][Governor].snum, 0);
  1388. X
  1389. X}
  1390. X
  1391. Xvoid 
  1392. Xmount(int Playernum, int Governor, int APcount, int mnt)
  1393. X{
  1394. X    shiptype       *ship;
  1395. X    int             shipno, nextshipno;
  1396. X
  1397. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  1398. X    while (shipno = do_shiplist(&ship, &nextshipno))
  1399. X        if (in_list(Playernum, args[1], ship, &nextshipno) &&
  1400. X            authorized(Governor, ship)) {
  1401. X            if (!ship->mount) {
  1402. X                notify(Playernum, Governor, "This ship is not equipped with a crystal mount.\n");
  1403. X                free(ship);
  1404. X                continue;
  1405. X            }
  1406. X            if (ship->mounted && mnt) {
  1407. X                notify(Playernum, Governor, "You already have a crystal mounted.\n");
  1408. X                free(ship);
  1409. X                continue;
  1410. X            } else if (!ship->mounted && !mnt) {
  1411. X                notify(Playernum, Governor, "You don't have a crystal mounted.\n");
  1412. X                free(ship);
  1413. X                continue;
  1414. X            } else if (!ship->mounted && mnt) {
  1415. X                if (!ship->crystals) {
  1416. X                    notify(Playernum, Governor, "You have no crystals on board.\n");
  1417. X                    free(ship);
  1418. X                    continue;
  1419. X                }
  1420. X                ship->mounted = 1;
  1421. X                ship->crystals--;
  1422. X                notify(Playernum, Governor, "Mounted.\n");
  1423. X            } else if (ship->mounted && !mnt) {
  1424. X                if (ship->crystals == Max_crystals(ship)) {
  1425. X                    notify(Playernum, Governor, "You can't dismount the crystal. Max allowed already on board.\n");
  1426. X                    free(ship);
  1427. X                    continue;
  1428. X                }
  1429. X                ship->mounted = 0;
  1430. X                ship->crystals++;
  1431. X                notify(Playernum, Governor, "Dismounted.\n");
  1432. X                if (ship->hyper_drive.charge || ship->hyper_drive.ready) {
  1433. X                    ship->hyper_drive.charge = 0;
  1434. X                    ship->hyper_drive.ready = 0;
  1435. X                    notify(Playernum, Governor, "Discharged.\n");
  1436. X                }
  1437. X                if (ship->laser && ship->fire_laser) {
  1438. X                    ship->fire_laser = 0;
  1439. X                    notify(Playernum, Governor, "Laser deactivated.\n");
  1440. X                }
  1441. X            } else {
  1442. X                notify(Playernum, Governor, "Weird error in 'mount'.\n");
  1443. X                free(ship);
  1444. X                continue;
  1445. X            }
  1446. X            putship(ship);
  1447. X            free(ship);
  1448. X        } else
  1449. X            free(ship);
  1450. X}
  1451. X
  1452. Xvoid 
  1453. Xuse_fuel(shiptype * s, double amt)
  1454. X{
  1455. X    s->fuel -= amt;
  1456. X    s->mass -= amt * MASS_FUEL;
  1457. X}
  1458. X
  1459. Xvoid 
  1460. Xuse_destruct(shiptype * s, int amt)
  1461. X{
  1462. X    s->destruct -= amt;
  1463. X    s->mass -= (double) amt *MASS_DESTRUCT;
  1464. X}
  1465. X
  1466. Xvoid 
  1467. Xuse_resource(shiptype * s, int amt)
  1468. X{
  1469. X    s->resource -= amt;
  1470. X    s->mass -= (double) amt *MASS_RESOURCE;
  1471. X}
  1472. X
  1473. Xvoid 
  1474. Xuse_popn(shiptype * s, int amt, double mass)
  1475. X{
  1476. X    s->popn -= amt;
  1477. X    s->mass -= (double) amt *mass;
  1478. X}
  1479. X
  1480. Xvoid 
  1481. Xrcv_fuel(shiptype * s, double amt)
  1482. X{
  1483. X    s->fuel += amt;
  1484. X    s->mass += amt * MASS_FUEL;
  1485. X}
  1486. X
  1487. Xvoid 
  1488. Xrcv_resource(shiptype * s, int amt)
  1489. X{
  1490. X    s->resource += amt;
  1491. X    s->mass += (double) amt *MASS_RESOURCE;
  1492. X}
  1493. X
  1494. Xvoid 
  1495. Xrcv_destruct(shiptype * s, int amt)
  1496. X{
  1497. X    s->destruct += amt;
  1498. X    s->mass += (double) amt *MASS_DESTRUCT;
  1499. X}
  1500. X
  1501. Xvoid 
  1502. Xrcv_popn(shiptype * s, int amt, double mass)
  1503. X{
  1504. X    s->popn += amt;
  1505. X    s->mass += (double) amt *mass;
  1506. X}
  1507. X
  1508. Xvoid 
  1509. Xrcv_troops(shiptype * s, int amt, double mass)
  1510. X{
  1511. X    s->troops += amt;
  1512. X    s->mass += (double) amt *mass;
  1513. X}
  1514. X
  1515. Xvoid 
  1516. Xdo_transporter(racetype * Race, int Governor, shiptype * s)
  1517. X{
  1518. X    int             Playernum;
  1519. X    shiptype       *s2;
  1520. X
  1521. X    Playernum = Race->Playernum;
  1522. X
  1523. X    if (!landed(s)) {
  1524. X        notify(Playernum, Governor, "Origin ship not landed.\n");
  1525. X        return;
  1526. X    }
  1527. X    if (s->storbits != Dir[Playernum - 1][Governor].snum ||
  1528. X        s->pnumorbits != Dir[Playernum - 1][Governor].pnum) {
  1529. X        sprintf(buf, "Change scope to the planet the ship is landed on!\n");
  1530. X        notify(Playernum, Governor, buf);
  1531. X        return;
  1532. X    }
  1533. X    if (s->damage) {
  1534. X        notify(Playernum, Governor, "Origin device is damaged.\n");
  1535. X        return;
  1536. X    }
  1537. X    if (!getship(&s2, (int) s->special.transport.target)) {
  1538. X        sprintf(buf, "The hopper seems to be blocked.\n");
  1539. X        notify(Playernum, Governor, buf);
  1540. X        return;
  1541. X    }
  1542. X    if (!s2->alive || s2->type != OTYPE_TRANSDEV || !s2->on) {
  1543. X        sprintf(buf, "The target device is not receiving.\n");
  1544. X        notify(Playernum, Governor, buf);
  1545. X        free(s2);
  1546. X        return;
  1547. X    }
  1548. X    if (!landed(s2)) {
  1549. X        notify(Playernum, Governor, "Target ship not landed.\n");
  1550. X        free(s2);
  1551. X        return;
  1552. X    }
  1553. X    if (s2->damage) {
  1554. X        notify(Playernum, Governor, "Target device is damaged.\n");
  1555. X        free(s2);
  1556. X        return;
  1557. X    }
  1558. X    sprintf(buf, "Zap\07!\n");    /* ^G */
  1559. X    notify(Playernum, Governor, buf);
  1560. X    /* send stuff to other ship (could be transport device) */
  1561. X    if (s->resource) {
  1562. X        rcv_resource(s2, (int) s->resource);
  1563. X        sprintf(buf, "%d resources transferred.\n", s->resource);
  1564. X        notify(Playernum, Governor, buf);
  1565. X        sprintf(bufr, "%d Resources\n", s->resource);
  1566. X        use_resource(s, (int) s->resource);
  1567. X    } else
  1568. X        bufr[0] = '\0';
  1569. X    if (s->fuel) {
  1570. X        rcv_fuel(s2, s->fuel);
  1571. X        sprintf(buf, "%g fuel transferred.\n", s->fuel);
  1572. X        notify(Playernum, Governor, buf);
  1573. X        sprintf(buff, "%g Fuel\n", s->fuel);
  1574. X        use_fuel(s, s->fuel);
  1575. X    } else
  1576. X        buff[0] = '\0';
  1577. X
  1578. X    if (s->destruct) {
  1579. X        rcv_destruct(s2, (int) s->destruct);
  1580. X        sprintf(buf, "%d destruct transferred.\n", s->destruct);
  1581. X        notify(Playernum, Governor, buf);
  1582. X        sprintf(bufd, "%d Destruct\n", s->destruct);
  1583. X        use_destruct(s, (int) s->destruct);
  1584. X    } else
  1585. X        bufd[0] = '\0';
  1586. X
  1587. X    if (s->popn) {
  1588. X        s2->mass += s->popn * Race->mass;
  1589. X        s2->popn += s->popn;
  1590. X
  1591. X        sprintf(buf, "%d population transferred.\n", s->popn);
  1592. X        notify(Playernum, Governor, buf);
  1593. X        sprintf(bufc, "%d %s\n", s->popn,
  1594. X            Race->Metamorph ? "tons of biomass" : "population");
  1595. X        s->mass -= s->popn * Race->mass;
  1596. X        s->popn -= s->popn;
  1597. X    } else
  1598. X        bufc[0] = '\0';
  1599. X
  1600. X    if (s->crystals) {
  1601. X        s2->crystals += s->crystals;
  1602. X
  1603. X        sprintf(buf, "%d crystal(s) transferred.\n", s->crystals);
  1604. X        notify(Playernum, Governor, buf);
  1605. X        sprintf(bufx, "%d crystal(s)\n", s->crystals);
  1606. X
  1607. X        s->crystals = 0;
  1608. X    } else
  1609. X        bufx[0] = '\0';
  1610. X
  1611. X    if (s2->owner != s->owner) {
  1612. X        sprintf(telegram_buf, "Audio-vibatory-physio-molecular transport device #");
  1613. X        sprintf(buf, "%s gave your ship %s the following:\n", Ship(s), Ship(s2));
  1614. X        strcat(telegram_buf, buf);
  1615. X        strcat(telegram_buf, bufr);
  1616. X        strcat(telegram_buf, bufd);
  1617. X        strcat(telegram_buf, buff);
  1618. X        strcat(telegram_buf, bufc);
  1619. X        strcat(telegram_buf, bufm);
  1620. X        strcat(telegram_buf, bufx);
  1621. X        warn((int) s2->owner, (int) s2->governor, telegram_buf);
  1622. X    }
  1623. X    putship(s2);
  1624. X    free(s2);
  1625. X}
  1626. X
  1627. Xint 
  1628. Xlanded_on(shiptype * s, int shipno)
  1629. X{
  1630. X    return (s->whatorbits == LEVEL_SHIP && s->destshipno == shipno);
  1631. X}
  1632. X
  1633. Xvoid 
  1634. Xunload_onto_alien_sector(int Playernum, int Governor, planettype * planet,
  1635. X             shiptype * ship, sectortype * sect, int what,
  1636. X             int people)
  1637. X{
  1638. X    double          astrength, dstrength;
  1639. X    int             oldowner, oldgov, oldpopn, old2popn, old3popn;
  1640. X    int             casualties, casualties2, casualties3;
  1641. X    int             absorbed, defense;
  1642. X    racetype       *Race, *alien;
  1643. X
  1644. X    if (people <= 0) {
  1645. X        notify(Playernum, Governor, "You have to unload to assault alien sectors.\n");
  1646. X        return;
  1647. X    }
  1648. X    ground_assaults[Playernum - 1][sect->owner - 1][Dir[Playernum - 1][Governor].snum] += 1;
  1649. X    Race = races[Playernum - 1];
  1650. X    alien = races[sect->owner - 1];
  1651. X    /* races find out about each other */
  1652. X    alien->translate[Playernum - 1] = MIN(alien->translate[Playernum - 1] + 5, 100);
  1653. X    Race->translate[sect->owner - 1] = MIN(Race->translate[sect->owner - 1] + 5, 100);
  1654. X
  1655. X    oldowner = (int) sect->owner;
  1656. X    oldgov = Stars[Dir[Playernum - 1][Governor].snum]->governor[sect->owner - 1];
  1657. X
  1658. X    if (what == CIV)
  1659. X        ship->popn -= people;
  1660. X    else
  1661. X        ship->troops -= people;
  1662. X    ship->mass -= people * Race->mass;
  1663. X    sprintf(buf, "%d %s unloaded...\n", people, what == CIV ? "civ" : "mil");
  1664. X    notify(Playernum, Governor, buf);
  1665. X    sprintf(buf, "Crew compliment %d civ  %d mil\n", ship->popn, ship->troops);
  1666. X    notify(Playernum, Governor, buf);
  1667. X
  1668. X    sprintf(buf, "%d %s assault %d civ/%d mil\n",
  1669. X         people, what == CIV ? "civ" : "mil", sect->popn, sect->troops);
  1670. X
  1671. X    notify(Playernum, Governor, buf);
  1672. X    oldpopn = people;
  1673. X    old2popn = sect->popn;
  1674. X    old3popn = sect->troops;
  1675. X
  1676. X    defense = Defensedata[sect->condition];
  1677. X    ground_attack(Race, alien, &people, what, §->popn, §->troops,
  1678. X              (int) ship->armor, defense,
  1679. X     1.0 - (double) ship->damage / 100.0, alien->likes[sect->condition],
  1680. X              &astrength, &dstrength,
  1681. X              &casualties, &casualties2, &casualties3);
  1682. X    sprintf(buf, "Attack: %.2f   Defense: %.2f.\n", astrength, dstrength);
  1683. X    notify(Playernum, Governor, buf);
  1684. X
  1685. X    if (!(sect->popn + sect->troops)) {    /* we got 'em */
  1686. X        /* mesomorphs absorb the bodies of their victims */
  1687. X        absorbed = 0;
  1688. X        if (Race->absorb) {
  1689. X            absorbed = int_rand(0, old2popn + old3popn);
  1690. X            sprintf(buf, "%d alien bodies absorbed.\n", absorbed);
  1691. X            notify(Playernum, Governor, buf);
  1692. X            sprintf(buf, "Metamorphs have absorbed %d bodies!!!\n",
  1693. X                absorbed);
  1694. X            notify(oldowner, oldgov, buf);
  1695. X        }
  1696. X        if (what == CIV)
  1697. X            sect->popn = people + absorbed;
  1698. X        else if (what == MIL) {
  1699. X            sect->popn = absorbed;
  1700. X            sect->troops = people;
  1701. X        }
  1702. X        sect->owner = Playernum;
  1703. X        adjust_morale(Race, alien, (int) alien->fighters);
  1704. X    } else {        /* retreat */
  1705. X        absorbed = 0;
  1706. X        if (alien->absorb) {
  1707. X            absorbed = int_rand(0, oldpopn - people);
  1708. X            sprintf(buf, "%d alien bodies absorbed.\n", absorbed);
  1709. X            notify(oldowner, oldgov, buf);
  1710. X            sprintf(buf, "Metamorphs have absorbed %d bodies!!!\n", absorbed);
  1711. X            notify(Playernum, Governor, buf);
  1712. X            sect->popn += absorbed;
  1713. X        }
  1714. X        /* load them back up */
  1715. X        sprintf(buf, "Loading %d %s\n", people, what == CIV ? "civ" : "mil");
  1716. X        notify(Playernum, Governor, buf);
  1717. X        if (what == CIV)
  1718. X            ship->popn += people;
  1719. X        else
  1720. X            ship->troops += people;
  1721. X        ship->mass -= people * Race->mass;
  1722. X        adjust_morale(alien, Race, (int) Race->fighters);
  1723. X    }
  1724. X    sprintf(telegram_buf, "/%s/%s: %s [%d] %s assaults %s [%d] %c(%d,%d) %s\n",
  1725. X        Stars[Dir[Playernum - 1][Governor].snum]->name,
  1726. X        Stars[Dir[Playernum - 1][Governor].snum]->pnames[Dir[Playernum - 1][Governor].pnum],
  1727. X       Race->name, Playernum, Ship(ship), alien->name, alien->Playernum,
  1728. X        Dessymbols[sect->condition], ship->land_x, ship->land_y,
  1729. X        (sect->owner == Playernum ? "VICTORY" : "DEFEAT"));
  1730. X
  1731. X    if (sect->owner == Playernum) {
  1732. X        sprintf(buf, "VICTORY! The sector is yours!\n");
  1733. X        notify(Playernum, Governor, buf);
  1734. X        sprintf(buf, "Sector CAPTURED!\n");
  1735. X        strcat(telegram_buf, buf);
  1736. X        if (people) {
  1737. X            sprintf(buf, "%d %s move in.\n", people, what == CIV ? "civilians" : "troops");
  1738. X            notify(Playernum, Governor, buf);
  1739. X        }
  1740. X        planet->info[Playernum - 1].numsectsowned++;
  1741. X        planet->info[Playernum - 1].mob_points += (int) sect->mobilization;
  1742. X        planet->info[oldowner - 1].numsectsowned--;
  1743. X        planet->info[oldowner - 1].mob_points -= (int) sect->mobilization;
  1744. X    } else {
  1745. X        sprintf(buf, "The invasion was repulsed; try again.\n");
  1746. X        notify(Playernum, Governor, buf);
  1747. X        sprintf(buf, "You fought them off!\n");
  1748. X        strcat(telegram_buf, buf);
  1749. X    }
  1750. X    if (!(sect->popn + sect->troops + people)) {
  1751. X        sprintf(buf, "You killed all of them!\n");
  1752. X        strcat(telegram_buf, buf);
  1753. X        /* increase modifier */
  1754. X        Race->translate[oldowner - 1] = MIN(Race->translate[oldowner - 1] + 5, 100);
  1755. X    }
  1756. X    if (!people) {
  1757. X        sprintf(buf, "Oh no! They killed your party to the last man!\n");
  1758. X        notify(Playernum, Governor, buf);
  1759. X        /* increase modifier */
  1760. X        alien->translate[Playernum - 1] = MIN(alien->translate[Playernum - 1] + 5, 100);
  1761. X    }
  1762. X    putrace(alien);
  1763. X    putrace(Race);
  1764. X
  1765. X    sprintf(buf, "Casualties: You: %d civ/%d mil, Them: %d %s\n",
  1766. X     casualties2, casualties3, casualties, what == CIV ? "civ" : "mil");
  1767. X    strcat(telegram_buf, buf);
  1768. X    warn(oldowner, oldgov, telegram_buf);
  1769. X    sprintf(buf, "Casualties: You: %d %s, Them: %d civ/%d mil\n",
  1770. X     casualties, what == CIV ? "civ" : "mil", casualties2, casualties3);
  1771. X    notify(Playernum, Governor, buf);
  1772. X    return;
  1773. X}
  1774. END_OF_FILE
  1775. if test 34277 -ne `wc -c <'user/load.c'`; then
  1776.     echo shar: \"'user/load.c'\" unpacked with wrong size!
  1777. fi
  1778. # end of 'user/load.c'
  1779. fi
  1780. echo shar: End of archive 5 \(of 21\).
  1781. cp /dev/null ark5isdone
  1782. MISSING=""
  1783. 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
  1784.     if test ! -f ark${I}isdone ; then
  1785.     MISSING="${MISSING} ${I}"
  1786.     fi
  1787. done
  1788. if test "${MISSING}" = "" ; then
  1789.     echo You have unpacked all 21 archives.
  1790.     echo "Now type './buildfiles.sh'"
  1791.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1792. else
  1793.     echo You still need to unpack the following archives:
  1794.     echo "        " ${MISSING}
  1795. fi
  1796. ##  End of shell archive.
  1797. exit 0
  1798.