home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part10 < 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: v17i022:  gbp - Galactic Bloodshed+, an empire-like war game, Part10/21
  5. Message-ID: <4550@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:31:20 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1841
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1701
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 22
  14. Archive-name: gbp/Part10
  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 10 (of 21)."
  27. # Contents:  server/doship.c server/doturn.c user/mobiliz.c
  28. # Wrapped by billr@saab on Fri Feb 12 09:14:26 1993
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'server/doship.c' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'server/doship.c'\"
  32. else
  33. echo shar: Extracting \"'server/doship.c'\" \(24721 characters\)
  34. sed "s/^X//" >'server/doship.c' <<'END_OF_FILE'
  35. X/*
  36. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  37. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  38. X * GB_copyright.h. doship -- do one ship turn.
  39. X */
  40. X
  41. X#include "GB_copyright.h"
  42. X#define EXTERN extern
  43. X#include "vars.h"
  44. X#include "ships.h"
  45. X#include "races.h"
  46. X#include "doturn.h"
  47. X#include "power.h"
  48. X#include "buffers.h"
  49. X#include <math.h>
  50. X#include <strings.h>
  51. X
  52. Xextern long     Shipdata[NUMSTYPES][NUMABILS];
  53. X
  54. Xvoid            doship(shiptype *, int);
  55. Xvoid            domass(shiptype *);
  56. Xvoid            doown(shiptype *);
  57. Xvoid            domissile(shiptype *);
  58. Xvoid            domine(int, int);
  59. Xvoid            doabm(shiptype *);
  60. Xvoid            do_repair(shiptype *);
  61. Xvoid            do_habitat(shiptype *);
  62. Xvoid            do_pod(shiptype *);
  63. Xint             infect_planet(int, int, int);
  64. Xvoid            do_meta_infect(int, planettype *);
  65. Xvoid            do_canister(shiptype *);
  66. Xvoid            do_greenhouse(shiptype *);
  67. Xvoid            do_mirror(shiptype *);
  68. Xvoid            do_god(shiptype *);
  69. Xvoid            do_ap(shiptype *);
  70. Xdouble          crew_factor(shiptype *);
  71. Xdouble          ap_planet_factor(planettype *);
  72. Xvoid            do_oap(shiptype *);
  73. Xint             do_weapon_plant(shiptype *);
  74. X#include "proto.h"
  75. X
  76. Xvoid
  77. Xdoship(shiptype * ship, int update)
  78. X{
  79. X    racetype       *Race;
  80. X    shiptype       *ship2;
  81. X
  82. X    /* ship is active */
  83. X    ship->active = 1;
  84. X
  85. X    if (!ship->owner)
  86. X        ship->alive = 0;
  87. X
  88. X    if (ship->alive) {
  89. X        /* repair radiation */
  90. X        if (ship->rad) {
  91. X            ship->active = 1;
  92. X            /* irradiated ships are immobile.. */
  93. X            /* kill off some people */
  94. X            /* check to see if ship is active */
  95. X            if (success(ship->rad))
  96. X                ship->active = 0;
  97. X            if (update) {
  98. X                ship->popn = round_rand(ship->popn * .80);
  99. X                ship->troops = round_rand(ship->troops * .80);
  100. X                if (ship->rad >= (int) REPAIR_RATE)
  101. X                    ship->rad -= int_rand(0, (int) REPAIR_RATE);
  102. X                else
  103. X                    ship->rad -= int_rand(0, (int) ship->rad);
  104. X            }
  105. X        } else
  106. X            ship->active = 1;
  107. X
  108. X        if (!ship->popn && Max_crew(ship) && !ship->docked)
  109. X            ship->whatdest = LEVEL_UNIV;
  110. X
  111. X        if (ship->whatorbits != LEVEL_UNIV
  112. X            && Stars[ship->storbits]->nova_stage > 0) {
  113. X            /* damage ships from supernovae */
  114. X            /*
  115. X             * Maarten: modified to take into account
  116. X             * MOVES_PER_UPDATE
  117. X             */
  118. X            ship->damage += 5 * Stars[ship->storbits]->nova_stage /
  119. X                ((Armor(ship) + 1) * segments);
  120. X            if (ship->damage >= 100) {
  121. X                kill_ship((int) (ship->owner), ship);
  122. X                return;
  123. X            }
  124. X        }
  125. X        if (ship->type == OTYPE_FACTORY && !ship->on) {
  126. X            Race = races[ship->owner - 1];
  127. X            ship->tech = Race->tech;
  128. X        }
  129. X        if (ship->active)
  130. X            Moveship(ship, update, 1, 0);
  131. X
  132. X        ship->size = ship_size(ship);    /* for debugging */
  133. X
  134. X        if (ship->whatorbits == LEVEL_SHIP) {
  135. X            (void) getship(&ship2, (int) ship->destshipno);
  136. X            if (ship2->owner != ship->owner) {
  137. X                ship2->owner = ship->owner;
  138. X                ship2->governor = ship->governor;
  139. X                putship(ship2);
  140. X            }
  141. X            free(ship2);
  142. X            /* just making sure */
  143. X        } else if (ship->whatorbits != LEVEL_UNIV &&
  144. X               (ship->popn || ship->type == OTYPE_PROBE)) {
  145. X            /*
  146. X             * Though I have often used TWCs for exploring, I
  147. X             * don't think it is right
  148. X             */
  149. X            /*
  150. X             * to be able to map out worlds with this type of
  151. X             * junk. Either a manned ship,
  152. X             */
  153. X            /*
  154. X             * or a probe, which is designed for this kind of
  155. X             * work.  Maarten
  156. X             */
  157. X            StarsInhab[ship->storbits] = 1;
  158. X            setbit(Stars[ship->storbits]->inhabited, ship->owner);
  159. X            setbit(Stars[ship->storbits]->explored, ship->owner);
  160. X            if (ship->whatorbits == LEVEL_PLAN) {
  161. X                planets[ship->storbits][ship->pnumorbits]->info[ship->owner - 1].explored = 1;
  162. X            }
  163. X        }
  164. X        /* add ships, popn to total count to add AP's */
  165. X        if (update) {
  166. X            Power[ship->owner - 1].ships_owned++;
  167. X            Power[ship->owner - 1].resource += ship->resource;
  168. X            Power[ship->owner - 1].fuel += ship->fuel;
  169. X            Power[ship->owner - 1].destruct += ship->destruct;
  170. X            Power[ship->owner - 1].popn += ship->popn;
  171. X            Power[ship->owner - 1].troops += ship->troops;
  172. X        }
  173. X        if (ship->whatorbits == LEVEL_UNIV) {
  174. X            Sdatanumships[ship->owner - 1]++;
  175. X            Sdatapopns[ship->owner] += ship->popn;
  176. X        } else {
  177. X            starnumships[ship->storbits][ship->owner - 1]++;
  178. X            /* add popn of ships to popn */
  179. X            starpopns[ship->storbits][ship->owner - 1] += ship->popn;
  180. X            /* set inhabited for ship */
  181. X            /* only if manned or probe.  Maarten */
  182. X            if (ship->popn || ship->type == OTYPE_PROBE) {
  183. X                StarsInhab[ship->storbits] = 1;
  184. X                setbit(Stars[ship->storbits]->inhabited, ship->owner);
  185. X                setbit(Stars[ship->storbits]->explored, ship->owner);
  186. X            }
  187. X        }
  188. X
  189. X        if (ship->active) {
  190. X            /* bombard the planet */
  191. X            if (can_bombard(ship) && ship->bombard
  192. X                && ship->whatorbits == LEVEL_PLAN
  193. X                && ship->whatdest == LEVEL_PLAN
  194. X                && ship->deststar == ship->storbits
  195. X                && ship->destpnum == ship->pnumorbits) {
  196. X                /* ship bombards planet */
  197. X                Stinfo[ship->storbits][ship->pnumorbits].inhab = 1;
  198. X            }
  199. X            /* repair ship by the amount of crew it has */
  200. X            /*
  201. X             * industrial complexes can repair (robot ships and
  202. X             * offline factories can't repair)
  203. X             */
  204. X            if (ship->damage && Repair(ship))
  205. X                do_repair(ship);
  206. X
  207. X            if (update)
  208. X                switch (ship->type) {    /* do this stuff during
  209. X                             * updates only */
  210. X                case OTYPE_CANIST:
  211. X                    do_canister(ship);
  212. X                    break;
  213. X                case OTYPE_GREEN:
  214. X                    do_greenhouse(ship);
  215. X                    break;
  216. X                case STYPE_MIRROR:
  217. X                    do_mirror(ship);
  218. X                    break;
  219. X                case OTYPE_AP:
  220. X                    do_ap(ship);
  221. X                    break;
  222. X                case STYPE_OAP:
  223. X                    do_oap(ship);
  224. X                    break;
  225. X                case STYPE_HABITAT:
  226. X                    do_habitat(ship);
  227. X                    break;
  228. X                default:
  229. X                    break;
  230. X                }
  231. X            if (ship->type == STYPE_POD)
  232. X                do_pod(ship);
  233. X        }
  234. X    }
  235. X}
  236. X
  237. Xvoid
  238. Xdomass(shiptype * ship)
  239. X{
  240. X    double          rmass;
  241. X    int             sh;
  242. X
  243. X    rmass = races[ship->owner - 1]->mass;
  244. X
  245. X    sh = ship->ships;
  246. X    ship->mass = 0.0;
  247. X    ship->hanger = 0;
  248. X    while (sh) {
  249. X        domass(ships[sh]);    /* recursive call */
  250. X        ship->mass += ships[sh]->mass;
  251. X        ship->hanger += ships[sh]->size;
  252. X        sh = ships[sh]->nextship;
  253. X    }
  254. X    ship->mass += getmass(ship);
  255. X    ship->mass += (double) (ship->popn + ship->troops) * rmass;
  256. X    ship->mass += (double) ship->destruct * MASS_DESTRUCT;
  257. X    ship->mass += ship->fuel * MASS_FUEL;
  258. X    ship->mass += (double) ship->resource * MASS_RESOURCE;
  259. X}
  260. X
  261. Xvoid
  262. Xdoown(shiptype * ship)
  263. X{
  264. X    int             sh;
  265. X    sh = ship->ships;
  266. X    while (sh) {
  267. X        doown(ships[sh]);    /* recursive call */
  268. X        ships[sh]->owner = ship->owner;
  269. X        ships[sh]->governor = ship->governor;
  270. X        sh = ships[sh]->nextship;
  271. X    }
  272. X}
  273. X
  274. Xvoid
  275. Xdomissile(shiptype * ship)
  276. X{
  277. X    int             sh2;
  278. X    int             bombx, bomby, numdest, pdn, i;
  279. X    planettype     *p;
  280. X    double          dist;
  281. X    placetype       where;
  282. X
  283. X    if (!ship->alive || !ship->owner)
  284. X        return;
  285. X    if (!ship->on || ship->docked)
  286. X        return;
  287. X
  288. X    /* check to see if it has arrived at it's destination */
  289. X    if (ship->whatdest == LEVEL_PLAN && ship->whatorbits == LEVEL_PLAN &&
  290. X        ship->destpnum == ship->pnumorbits) {
  291. X        p = planets[ship->storbits][ship->pnumorbits];
  292. X        /* check to see if PDNs are present */
  293. X        pdn = 0;
  294. X        sh2 = p->ships;
  295. X        while (sh2 && !pdn) {
  296. X            if (ships[sh2]->alive && ships[sh2]->type == OTYPE_PLANDEF) {
  297. X                /* attack the PDN instead */
  298. X                ship->whatdest = LEVEL_SHIP;    /* move missile to PDN
  299. X                                 * for attack */
  300. X                ship->xpos = ships[sh2]->xpos;
  301. X                ship->ypos = ships[sh2]->ypos;
  302. X                ship->destshipno = sh2;
  303. X                pdn = sh2;
  304. X            }
  305. X            sh2 = ships[sh2]->nextship;
  306. X        }
  307. X        if (!pdn) {
  308. X            if (ship->special.impact.scatter) {
  309. X                bombx = int_rand(1, (int) p->Maxx) - 1;
  310. X                bomby = int_rand(1, (int) p->Maxy) - 1;
  311. X            } else {
  312. X                bombx = ship->special.impact.x % p->Maxx;
  313. X                bomby = ship->special.impact.y % p->Maxy;
  314. X            }
  315. X            sprintf(buf, "%s dropped on sector %d,%d at planet %s.\n",
  316. X              Ship(ship), bombx, bomby, prin_ship_orbits(ship));
  317. X            where.level = LEVEL_PLAN;
  318. X            where.snum = ship->storbits;
  319. X            where.pnum = ship->pnumorbits;
  320. X
  321. X            numdest = shoot_ship_to_planet(ship, p, (int) ship->destruct,
  322. X                          bombx, bomby, 1, 0, HEAVY,
  323. X                               long_buf, short_buf);
  324. X            push_telegram((int) ship->owner, (int) ship->governor, long_buf);
  325. X            kill_ship((int) ship->owner, ship);
  326. X            sprintf(buf, "%s dropped on %s.\n\t%d sectors destroyed.\n",
  327. X                Ship(ship), prin_ship_orbits(ship), numdest);
  328. X            for (i = 1; i <= Num_races; i++)
  329. X                if (p->info[i - 1].numsectsowned && i != ship->owner)
  330. X                    push_telegram(i, Stars[ship->storbits]->governor[i - 1], buf);
  331. X            if (numdest) {
  332. X                sprintf(buf, "%s dropped on %s.\n", Ship(ship),
  333. X                    prin_ship_orbits(ship));
  334. X                post(buf, COMBAT);
  335. X            }
  336. X        }
  337. X    } else if (ship->whatdest == LEVEL_SHIP) {
  338. X        sh2 = ship->destshipno;
  339. X        dist = sqrt(Distsq(ship->xpos, ship->ypos,
  340. X                   ships[sh2]->xpos, ships[sh2]->ypos));
  341. X        if (dist <= ((double) ship->speed * STRIKE_DISTANCE_FACTOR
  342. X                 * (100.0 - (double) ship->damage) / 100.0)) {
  343. X            /* do the attack */
  344. X            (void) shoot_ship_to_ship(ship, ships[sh2], (int) ship->destruct, 0, 0,
  345. X                          long_buf, short_buf);
  346. X            push_telegram((int) ship->owner, (int) ship->governor, long_buf);
  347. X            push_telegram((int) ships[sh2]->owner, (int) ships[sh2]->governor,
  348. X                      long_buf);
  349. X            kill_ship((int) ship->owner, ship);
  350. X            post(short_buf, COMBAT);
  351. X        }
  352. X    }
  353. X}
  354. X
  355. Xvoid
  356. Xdomine(int shipno, int detonate)
  357. X{
  358. X    int             sh, sh2, i;
  359. X    shiptype       *s, *ship;
  360. X    planettype     *planet;
  361. X    racetype       *r;
  362. X
  363. X    (void) getship(&ship, shipno);
  364. X
  365. X    if (ship->type != STYPE_MINE || !ship->alive || !ship->owner) {
  366. X        free(ship);
  367. X        return;
  368. X    }
  369. X    /* check around and see if we should explode. */
  370. X    if (ship->on || detonate) {
  371. X        int             rad = 0;
  372. X        double          xd, yd, range;
  373. X
  374. X        switch (ship->whatorbits) {
  375. X        case LEVEL_STAR:
  376. X            sh = Stars[ship->storbits]->ships;
  377. X            break;
  378. X        case LEVEL_PLAN:
  379. X            getplanet(&planet, (int) ship->storbits, (int) ship->pnumorbits);
  380. X            sh = planet->ships;
  381. X            free(planet);
  382. X            break;
  383. X        default:
  384. X            free(ship);
  385. X            return;
  386. X        }
  387. X        sh2 = sh;
  388. X        /*
  389. X         * traverse the list, look for ships that are closer than the
  390. X         * trigger radius...
  391. X         */
  392. X        rad = 0;
  393. X        if (!detonate) {
  394. X            r = races[ship->owner - 1];
  395. X            while (sh && !rad) {
  396. X                (void) getship(&s, sh);
  397. X                xd = s->xpos - ship->xpos;
  398. X                yd = s->ypos - ship->ypos;
  399. X                range = sqrt(xd * xd + yd * yd);
  400. X                if (!isset(r->allied, s->owner) && (s->owner != ship->owner) &&
  401. X                    ((int) range <= ship->special.trigger.radius))
  402. X                    rad = 1;
  403. X                else
  404. X                    sh = s->nextship;
  405. X                free(s);
  406. X            }
  407. X        } else
  408. X            rad = 1;
  409. X
  410. X        if (rad) {
  411. X            int             rez;    /* result from shoot */
  412. X            sh = sh2;
  413. X            while (sh && ship->alive) {
  414. X                getship(&s, sh);
  415. X                if ((s->type == STYPE_SWEEPER) && (sh != shipno) && s->alive) {
  416. X                    int             amount_to_use;
  417. X                    int             chance_to_see;
  418. X                    int             roll;
  419. X
  420. X                    chance_to_see = (int) (5 + (2 * (sqrt(s->tech))));
  421. X                    if (s->guns == PRIMARY)
  422. X                        amount_to_use = MIN(s->popn, s->primary);
  423. X                    else
  424. X                        amount_to_use = MIN(s->popn, s->secondary);
  425. X                    roll = int_rand(1, 100);
  426. X                    sprintf(buf, "Mine exploding: Minesweeper detect chance %d/%d \n",
  427. X                        chance_to_see, roll);
  428. X                    warn((int)s->owner, (int)s->governor, buf);
  429. X                    if (roll <= chance_to_see) {
  430. X                        rez = shoot_ship_to_ship(s, ship, amount_to_use, 0, 0,
  431. X                               long_buf, short_buf);
  432. X                        warn_star(s->owner, ship->owner, (int) s->storbits, short_buf);
  433. X                        warn((int)s->owner, (int)s->governor, long_buf);
  434. X                        warn((int)ship->owner, (int)ship->governor, long_buf);
  435. X                        use_destruct(s, amount_to_use);
  436. X                        putship(s);
  437. X                    }    /* chance_to_see */
  438. X                }
  439. X                    sh = s->nextship;
  440. X                    free(s);
  441. X            }
  442. X        }
  443. X
  444. X        if (ship->alive) {
  445. X            if (rad) {
  446. X         sprintf(buf, "Mine %s detonated at %s\n", Ship(ship), 
  447. X            prin_ship_orbits(ship));
  448. X         post(buf, COMBAT);
  449. X         warn((int)ship->owner, (int)ship->governor, buf);
  450. X         notify_star((int)ship->owner, (int)ship->governor, 0,
  451. X             (int)ship->storbits, buf);
  452. X
  453. X            /* kill off the ships nearby */
  454. X
  455. X            sh = sh2;
  456. X            while (sh) {
  457. X                getship(&s, sh);
  458. X                if (sh != shipno && s->alive &&
  459. X                   (s->type != OTYPE_CANIST) && (s->type != OTYPE_GREEN)
  460. X                    && (s->owner != ship->owner)) {
  461. X                    rad = shoot_ship_to_ship(ship, s, (int)(ship->destruct), 
  462. X                        0, 0, long_buf, short_buf);
  463. X                    if (rad > 0) {
  464. X                        post(short_buf, COMBAT);    
  465. X                        warn((int)s->owner, (int)s->governor, long_buf);
  466. X                        warn((int)ship->owner, (int)ship->governor, long_buf);
  467. X                        putship(s);
  468. X                    }
  469. X                }
  470. X              sh = s->nextship;
  471. X              free(s);
  472. X            }
  473. X            /*
  474. X             * if the mine is in orbit around a planet, nuke the
  475. X             * planet too!
  476. X             */
  477. X            if (ship->whatorbits == LEVEL_PLAN) {
  478. X                /* pick a random sector to nuke */
  479. X                reg int         x, y, numdest;
  480. X                getplanet(&planet, (int) ship->storbits, (int) ship->pnumorbits);
  481. X                if (landed(ship)) {
  482. X                    x = ship->land_x;
  483. X                    y = ship->land_y;
  484. X                } else {
  485. X                    x = int_rand(0, (int) planet->Maxx - 1);
  486. X                    y = int_rand(0, (int) planet->Maxy - 1);
  487. X                }
  488. X                numdest = shoot_ship_to_planet(ship, planet,
  489. X                  (int) (ship->destruct), x, y, 1, 0, LIGHT,
  490. X                               long_buf, short_buf);
  491. X                putplanet(planet, (int) ship->storbits, (int) ship->pnumorbits);
  492. X                
  493. X                post(short_buf, COMBAT);    
  494. X                warn((int)s->owner, (int)s->governor, long_buf);
  495. X
  496. X                sprintf(telegram_buf, "%s", buf);
  497. X                if (numdest > 0) {
  498. X                    sprintf(buf, " - %d sectors destroyed.", numdest);
  499. X                    strcat(telegram_buf, buf);
  500. X                }
  501. X                strcat(telegram_buf, "\n");
  502. X                for (i = 1; i <= Num_races; i++)
  503. X                    if (Nuked[i - 1])
  504. X                        warn(i, (int) Stars[ship->storbits]->governor[i - 1],
  505. X                             telegram_buf);
  506. X                notify((int) (ship->owner), (int) ship->governor, telegram_buf);
  507. X                free(planet);
  508. X            }
  509. X            kill_ship((int) (ship->owner), ship);
  510. X        }
  511. X      } /* if alive */
  512. X        putship(ship);
  513. X    }
  514. X    free(ship);
  515. X}
  516. X
  517. Xvoid
  518. Xdoabm(shiptype * ship)
  519. X{
  520. X    int             sh2;
  521. X    int             numdest, caliber;
  522. X    planettype     *p;
  523. X
  524. X    if (!ship->alive || !ship->owner)
  525. X        return;
  526. X    if (!ship->on || !ship->retaliate || !ship->destruct)
  527. X        return;
  528. X
  529. X    if (landed(ship)) {
  530. X        p = planets[ship->storbits][ship->pnumorbits];
  531. X        caliber = current_caliber(ship);
  532. X        /* check to see if missiles/mines are present */
  533. X        sh2 = p->ships;
  534. X        while (sh2 && ship->destruct) {
  535. X            if (ships[sh2]->alive &&
  536. X                ((ships[sh2]->type == STYPE_MISSILE) ||
  537. X                 (ships[sh2]->type == STYPE_MINE)) &&
  538. X                (ships[sh2]->owner != ship->owner) &&
  539. X                !(isset(races[ship->owner - 1]->allied, ships[sh2]->owner) &&
  540. X                  isset(races[ships[sh2]->owner - 1]->allied, ship->owner))) {
  541. X                /*
  542. X                 * added last two tests to prevent mutually
  543. X                 * allied missiles getting shot up.
  544. X                 */
  545. X                /* attack the missile/mine */
  546. X                numdest = retal_strength(ship);
  547. X                numdest = MIN(numdest, ship->destruct);
  548. X                numdest = MIN(numdest, ship->retaliate);
  549. X                ship->destruct -= numdest;
  550. X                (void) shoot_ship_to_ship(ship, ships[sh2], numdest, 0, 0,
  551. X                               long_buf, short_buf);
  552. X                push_telegram((int) (ship->owner), (int) ship->governor, long_buf);
  553. X                push_telegram((int) (ships[sh2]->owner),
  554. X                      (int) ships[sh2]->governor, long_buf);
  555. X                post(short_buf, COMBAT);
  556. X            }
  557. X            sh2 = ships[sh2]->nextship;
  558. X        }
  559. X    }
  560. X}
  561. X
  562. Xvoid
  563. Xdo_repair(shiptype * ship)
  564. X{
  565. X    reg int         drep, cost;
  566. X    reg double      maxrep;
  567. X
  568. X    maxrep = REPAIR_RATE / (double) segments;
  569. X    /* stations repair for free, and ships docked with them */
  570. X    if (Shipdata[ship->type][ABIL_REPAIR])
  571. X        cost = 0;
  572. X    else if (ship->docked && ship->whatdest == LEVEL_SHIP &&
  573. X         ships[ship->destshipno]->type == STYPE_STATION)
  574. X        cost = 0;
  575. X    else if (ship->docked && ship->whatorbits == LEVEL_SHIP &&
  576. X         ships[ship->destshipno]->type == STYPE_STATION)
  577. X        cost = 0;
  578. X    else {
  579. X        maxrep *= (double) (ship->popn) / (double) ship->max_crew;
  580. X        cost = (int) (0.005 * maxrep * Cost(ship));
  581. X    }
  582. X    if (cost <= ship->resource) {
  583. X        use_resource(ship, cost);
  584. X        drep = (int) maxrep;
  585. X        ship->damage = MAX(0, (int) (ship->damage) - drep);
  586. X    } else {
  587. X        /* use up all of the ships resources */
  588. X        drep = (int) (maxrep * ((double) ship->resource / (int) cost));
  589. X        use_resource(ship, ship->resource);
  590. X        ship->damage = MAX(0, (int) (ship->damage) - drep);
  591. X    }
  592. X}
  593. X
  594. Xvoid
  595. Xdo_habitat(shiptype * ship)
  596. X{
  597. X    reg int         sh;
  598. X    int             add;
  599. X    double          fuse;
  600. X
  601. X    /* In v5.0+ Habitats make resources out of fuel */
  602. X    if (ship->on) {
  603. X        fuse = ship->fuel * ((double) ship->popn / (double) ship->max_crew)
  604. X            * (1.0 - .01 * (double) ship->damage);
  605. X        add = (int) fuse / HABITAT_PROD_RATE;
  606. X        if (ship->resource + add > ship->max_resource)
  607. X            add = ship->max_resource - ship->resource;
  608. X        fuse = HABITAT_PROD_RATE * (double) add;
  609. X        rcv_resource(ship, add);
  610. X        use_fuel(ship, fuse);
  611. X
  612. X        sh = ship->ships;
  613. X        while (sh) {
  614. X            if (ships[sh]->type == OTYPE_WPLANT)
  615. X                rcv_destruct(ship, do_weapon_plant(ships[sh]));
  616. X            sh = ships[sh]->nextship;
  617. X        }
  618. X    }
  619. X    add = round_rand((double) ship->popn * races[ship->owner - 1]->birthrate);
  620. X    if (ship->popn + add > Max_crew(ship))
  621. X        add = Max_crew(ship) - ship->popn;
  622. X    rcv_popn(ship, add, races[ship->owner - 1]->mass);
  623. X}
  624. X
  625. Xvoid
  626. Xdo_pod(shiptype * ship)
  627. X{
  628. X    reg int         i;
  629. X
  630. X    if (ship->whatorbits == LEVEL_STAR) {
  631. X        if (ship->special.pod.temperature >= POD_THRESHOLD) {
  632. X            i = int_rand(0, (int) Stars[ship->storbits]->numplanets - 1);
  633. X            sprintf(telegram_buf, "%s has warmed and exploded at %s\n",
  634. X                Ship(ship), prin_ship_orbits(ship));
  635. X            if (infect_planet((int) ship->owner, (int) ship->storbits, i)) {
  636. X                sprintf(buf, "\tmeta-colony established on %s.",
  637. X                    Stars[ship->storbits]->pnames[i]);
  638. X            } else
  639. X                strcat(buf, "        no spores have survived.");
  640. X            strcat(telegram_buf, buf);
  641. X            push_telegram((int) (ship->owner), (int) ship->governor, telegram_buf);
  642. X            kill_ship((int) (ship->owner), ship);
  643. X        } else
  644. X            ship->special.pod.temperature +=
  645. X                round_rand((double) Stars[ship->storbits]->temperature /
  646. X                       (double) segments);
  647. X    } else if (ship->whatorbits == LEVEL_PLAN) {
  648. X        if (ship->special.pod.decay >= POD_DECAY) {
  649. X            sprintf(telegram_buf, "%s has decayed at %s\n", Ship(ship),
  650. X                prin_ship_orbits(ship));
  651. X            push_telegram((int) ship->owner, (int) ship->governor, telegram_buf);
  652. X            kill_ship((int) ship->owner, ship);
  653. X        } else {
  654. X            ship->special.pod.decay += round_rand(1.0 / (double) segments);
  655. X        }
  656. X    }
  657. X}
  658. X
  659. Xint
  660. Xinfect_planet(int who, int star, int p)
  661. X{
  662. X    if (success(SPORE_SUCCESS_RATE)) {
  663. X        do_meta_infect(who, planets[star][p]);
  664. X        return 1;
  665. X    } else
  666. X        return 0;
  667. X}
  668. X
  669. Xvoid
  670. Xdo_meta_infect(int who, planettype * p)
  671. X{
  672. X    int             owner, x, y;
  673. X
  674. X    getsmap(Smap, p);
  675. X    PermuteSects(p);
  676. X    bzero((char *) Sectinfo, sizeof(Sectinfo));
  677. X    x = int_rand(0, p->Maxx - 1);
  678. X    y = int_rand(0, p->Maxy - 1);
  679. X    owner = Sector(*p, x, y).owner;
  680. X    if (!owner || (who != owner && (double) int_rand(1, 100) >
  681. X            100.0 * (1.0 - exp(-((double) (Sector(*p, x, y).troops *
  682. X                   races[owner - 1]->fighters / 50.0)))))) {
  683. X        p->info[who - 1].explored = 1;
  684. X        p->info[who - 1].numsectsowned += 1;
  685. X        Sector(*p, x, y).troops = 0;
  686. X        Sector(*p, x, y).popn = races[who - 1]->number_sexes;
  687. X        Sector(*p, x, y).owner = who;
  688. X        Sector(*p, x, y).condition = Sector(*p, x, y).type;
  689. X#ifdef POD_TERRAFORM
  690. X        Sector(*p, x, y).condition = races[who - 1]->likesbest;
  691. X#endif
  692. X        putsmap(Smap, p);
  693. X    }
  694. X}
  695. X
  696. Xvoid
  697. Xdo_canister(shiptype * ship)
  698. X{
  699. X    if (ship->whatorbits == LEVEL_PLAN && !landed(ship)) {
  700. X        if (++ship->special.timer.count < DISSIPATE) {
  701. X            if (Stinfo[ship->storbits][ship->pnumorbits].temp_add < -90)
  702. X                Stinfo[ship->storbits][ship->pnumorbits].temp_add = -100;
  703. X            else
  704. X                Stinfo[ship->storbits][ship->pnumorbits].temp_add -= 10;
  705. X        } else {    /* timer expired; destroy canister */
  706. X            reg int         j = 0;
  707. X            kill_ship((int) (ship->owner), ship);
  708. X            sprintf(telegram_buf, "Canister of dust previously covering %s has dissipated.\n",
  709. X                prin_ship_orbits(ship));
  710. X            for (j = 1; j <= Num_races; j++)
  711. X                if (planets[ship->storbits][ship->pnumorbits]->info[j - 1].numsectsowned)
  712. X                    push_telegram(j, (int) Stars[ship->storbits]->governor[j - 1],
  713. X                              telegram_buf);
  714. X        }
  715. X    }
  716. X}
  717. X
  718. Xvoid
  719. Xdo_greenhouse(shiptype * ship)
  720. X{
  721. X    if (ship->whatorbits == LEVEL_PLAN && !landed(ship)) {
  722. X        if (++ship->special.timer.count < DISSIPATE) {
  723. X            if (Stinfo[ship->storbits][ship->pnumorbits].temp_add > 90)
  724. X                Stinfo[ship->storbits][ship->pnumorbits].temp_add = 100;
  725. X            else
  726. X                Stinfo[ship->storbits][ship->pnumorbits].temp_add += 10;
  727. X        } else {    /* timer expired; destroy canister */
  728. X            reg int         j = 0;
  729. X
  730. X            kill_ship((int) (ship->owner), ship);
  731. X            sprintf(telegram_buf, "Greenhouse gases at %s have dissipated.\n",
  732. X                prin_ship_orbits(ship));
  733. X            for (j = 1; j <= Num_races; j++)
  734. X                if (planets[ship->storbits][ship->pnumorbits]->info[j - 1].numsectsowned)
  735. X                    push_telegram(j, (int) Stars[ship->storbits]->governor[j - 1],
  736. X                              telegram_buf);
  737. X        }
  738. X    }
  739. X}
  740. X
  741. Xvoid
  742. Xdo_mirror(shiptype * ship)
  743. X{
  744. X    switch (ship->special.aimed_at.level) {
  745. X        case LEVEL_SHIP:/* ship aimed at is a legal ship now */
  746. X        /* if in the same system */
  747. X        if ((ship->whatorbits == LEVEL_STAR || ship->whatorbits == LEVEL_PLAN)
  748. X            && (ships[ship->special.aimed_at.shipno] != NULL)
  749. X            && (ships[ship->special.aimed_at.shipno]->whatorbits == LEVEL_STAR ||
  750. X            ships[ship->special.aimed_at.shipno]->whatorbits == LEVEL_PLAN)
  751. X            && ship->storbits == ships[ship->special.aimed_at.shipno]->storbits
  752. X            && ships[ship->special.aimed_at.shipno]->alive) {
  753. X            shiptype       *s;
  754. X            reg int         i;
  755. X            double          range;
  756. X            s = ships[ship->special.aimed_at.shipno];
  757. X            range = sqrt(Distsq(ship->xpos, ship->ypos, s->xpos, s->ypos));
  758. X            i = int_rand(0, round_rand((2. / ((double) (Body(s))))
  759. X                           * (double) (ship->special.aimed_at.intensity) / (range / PLORBITSIZE + 1.0)));
  760. X            sprintf(telegram_buf, "%s aimed at %s\n", Ship(ship), Ship(s));
  761. X            s->damage += i;
  762. X            if (i) {
  763. X                sprintf(buf, "%d%% damage done.\n", i);
  764. X                strcat(telegram_buf, buf);
  765. X            }
  766. X            if (s->damage >= 100) {
  767. X                sprintf(buf, "%s DESTROYED!!!\n", Ship(s));
  768. X                strcat(telegram_buf, buf);
  769. X                kill_ship((int) (ship->owner), s);
  770. X            }
  771. X            push_telegram((int) s->owner, (int) s->governor, telegram_buf);
  772. X            push_telegram((int) ship->owner, (int) ship->governor, telegram_buf);
  773. X        }
  774. X        break;
  775. X    case LEVEL_PLAN:{
  776. X            reg int         i;
  777. X            double          range;
  778. X            range = sqrt(Distsq(ship->xpos, ship->ypos,
  779. X                        Stars[ship->storbits]->xpos
  780. X              + planets[ship->storbits][ship->pnumorbits]->xpos,
  781. X                        Stars[ship->storbits]->ypos
  782. X            + planets[ship->storbits][ship->pnumorbits]->ypos));
  783. X            if (range > PLORBITSIZE)
  784. X                i = PLORBITSIZE * ship->special.aimed_at.intensity / range;
  785. X            else
  786. X                i = ship->special.aimed_at.intensity;
  787. X
  788. X            i = round_rand(.01 * (100.0 - (double) (ship->damage)) * (double) i);
  789. X            Stinfo[ship->storbits][ship->special.aimed_at.pnum].temp_add += i;
  790. X        } break;
  791. X    case LEVEL_STAR:{
  792. X            /*
  793. X             * have to be in the same system as the star;
  794. X             * otherwise it's not too fair..
  795. X             */
  796. X            if (ship->special.aimed_at.snum > 0 && ship->special.aimed_at.snum < Sdata.numstars &&
  797. X                ship->whatorbits > LEVEL_UNIV &&
  798. X                ship->special.aimed_at.snum == ship->storbits)
  799. X                Stars[ship->special.aimed_at.snum]->stability += random() & 01;
  800. X        } break;
  801. X    case LEVEL_UNIV:
  802. X        break;
  803. X    }
  804. X}
  805. X
  806. Xvoid
  807. Xdo_god(shiptype * ship)
  808. X{
  809. X    /* gods have infinite power.... heh heh heh */
  810. X    if (races[ship->owner - 1]->God) {
  811. X        ship->fuel = Max_fuel(ship);
  812. X        ship->destruct = Max_destruct(ship);
  813. X        ship->resource = Max_resource(ship);
  814. X    }
  815. X}
  816. X
  817. Xvoid
  818. Xdo_ap(shiptype * ship)
  819. X{
  820. X    racetype       *Race;
  821. X
  822. X    /* if landed on planet, change conditions to be like race */
  823. X    if (landed(ship) && ship->on) {
  824. X        int             j, d;
  825. X        planettype     *p;
  826. X        p = planets[ship->storbits][ship->pnumorbits];
  827. X        Race = races[ship->owner - 1];
  828. X        if (ship->fuel >= 3.0) {
  829. X            use_fuel(ship, 3.0);
  830. X            for (j = RTEMP + 1; j <= OTHER; j++) {
  831. X                d = round_rand(ap_planet_factor(p) * crew_factor(ship) *
  832. X                           (double) (Race->conditions[j] - p->conditions[j]));
  833. X                if (d)
  834. X                    p->conditions[j] += d;
  835. X            }
  836. X        } else if (!ship->notified) {
  837. X            ship->notified = 1;
  838. X            ship->on = 0;
  839. X            msg_OOF(ship);
  840. X        }
  841. X    }
  842. X}
  843. X
  844. Xdouble
  845. Xcrew_factor(shiptype * ship)
  846. X{
  847. X    int             maxcrew;
  848. X
  849. X    if (!(maxcrew = Shipdata[ship->type][ABIL_MAXCREW]))
  850. X        return 0.0;
  851. X    return ((double) ship->popn / (double) maxcrew);
  852. X}
  853. X
  854. Xdouble
  855. Xap_planet_factor(planettype * p)
  856. X{
  857. X    double          x;
  858. X
  859. X    x = (double) p->Maxx * (double) p->Maxy;
  860. X    return (AP_FACTOR / (AP_FACTOR + x));
  861. X}
  862. X
  863. Xvoid
  864. Xdo_oap(shiptype * ship)
  865. X{
  866. X    /* "indimidate" the planet below, for enslavement purposes. */
  867. X    if (ship->whatorbits == LEVEL_PLAN)
  868. X        Stinfo[ship->storbits][ship->pnumorbits].intimidated = 1;
  869. X}
  870. X
  871. Xint
  872. Xdo_weapon_plant(shiptype * ship)
  873. X{
  874. X    int             maxrate, rate;
  875. X    maxrate = (int) (races[ship->owner - 1]->tech / 2.0);
  876. X
  877. X    rate = round_rand(MIN((double) ship->resource / (double) RES_COST_WPLANT,
  878. X                  ship->fuel / FUEL_COST_WPLANT)
  879. X              * (1. - .01 * (double) ship->damage)
  880. X              * (double) ship->popn / (double) ship->max_crew);
  881. X    rate = MIN(rate, maxrate);
  882. X    use_resource(ship, (rate * RES_COST_WPLANT));
  883. X    use_fuel(ship, ((double) rate * FUEL_COST_WPLANT));
  884. X    return rate;
  885. X}
  886. END_OF_FILE
  887. if test 24721 -ne `wc -c <'server/doship.c'`; then
  888.     echo shar: \"'server/doship.c'\" unpacked with wrong size!
  889. fi
  890. # end of 'server/doship.c'
  891. fi
  892. if test -f 'server/doturn.c' -a "${1}" != "-c" ; then 
  893.   echo shar: Will not clobber existing file \"'server/doturn.c'\"
  894. else
  895. echo shar: Extracting \"'server/doturn.c'\" \(22753 characters\)
  896. sed "s/^X//" >'server/doturn.c' <<'END_OF_FILE'
  897. X#ident  "@(#)doturn.c    1.5 1/31/93 "
  898. X/*
  899. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  900. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  901. X * GB_copyright.h. doturn -- does one turn.
  902. X */
  903. X
  904. X#include <math.h>
  905. X#include <ctype.h>
  906. X
  907. X#include "GB_copyright.h"
  908. X#define EXTERN extern
  909. X#include "vars.h"
  910. X#include "ships.h"
  911. X#include "races.h"
  912. X#include "doturn.h"
  913. X#include "power.h"
  914. X#include "buffers.h"
  915. X
  916. XFILE           *fopen();
  917. Xextern char    *Commod[];
  918. Xextern long     Shipdata[NUMSTYPES][NUMABILS];
  919. X
  920. Xvoid            do_turn(int);
  921. Xint             APadd(int, int, racetype *);
  922. Xint             governed(racetype *);
  923. Xvoid            fix_stability(startype *);
  924. Xvoid            do_reset(int);
  925. Xvoid            handle_victory(void);
  926. Xvoid            make_discoveries(racetype *);
  927. X#ifdef MARKET
  928. Xvoid            maintain(racetype *, int, int);
  929. X#endif
  930. Xint             attack_planet(shiptype *);
  931. Xvoid            output_ground_attacks(void);
  932. Xint             planet_points(planettype *);
  933. X#include "proto.h"
  934. X
  935. Xvoid 
  936. Xdo_turn(int update)
  937. X{
  938. X    int             star, i, j;
  939. X    commodtype     *c;
  940. X    int             dummy[2], temp;
  941. X    double          dist;
  942. X    struct victstruct {
  943. X        int             numsects;
  944. X        int             shipcost;
  945. X        int             shiptech;
  946. X        int             morale;
  947. X        int             res;
  948. X        int             des;
  949. X        int             fuel;
  950. X        int             money;
  951. X    }              *victory;
  952. X
  953. X    /* make all 0 for first iteration of doplanet */
  954. X    if (update) {
  955. X        bzero((char *) starpopns, sizeof(starpopns));
  956. X        bzero((char *) starnumships, sizeof(starnumships));
  957. X        bzero((char *) Sdatanumships, sizeof(Sdatanumships));
  958. X        bzero((char *) Stinfo, sizeof(Stinfo));
  959. X        bzero((char *) StarsInhab, sizeof(StarsInhab));
  960. X        bzero((char *) Power, sizeof(Power));
  961. X        bzero((char *) inhabited, sizeof(inhabited));
  962. X    }
  963. X    Num_ships = Numships();
  964. X
  965. X    for (i = 1; i <= Num_ships; i++)
  966. X        domine(i, 0);
  967. X
  968. X    ships = (shiptype **) malloc(sizeof(shiptype *) * (Num_ships + 1));
  969. X    for (i = 1; i <= Num_ships; i++)
  970. X        (void) getship(&ships[i], i);
  971. X
  972. X    /* get all stars and planets */
  973. X    getsdata(&Sdata);
  974. X    Planet_count = 0;
  975. X    for (star = 0; star < Sdata.numstars; star++) {
  976. X        getstar(&Stars[star], star);
  977. X        if (update)
  978. X            fix_stability(Stars[star]);    /* nova */
  979. X
  980. X        for (i = 0; i < Stars[star]->numplanets; i++) {
  981. X            getplanet(&planets[star][i], star, i);
  982. X            if (planets[star][i]->type != TYPE_ASTEROID)
  983. X                Planet_count++;
  984. X            if (update)
  985. X                moveplanet(star, planets[star][i], i);
  986. X            if (Stars[star]->pnames[i] == '\0')
  987. X                sprintf(Stars[star]->pnames[i], "NULL-%d", i);
  988. X        }
  989. X        if (Stars[star]->name[0] == '\0')
  990. X            sprintf(Stars[star]->name, "NULL-%d", star);
  991. X    }
  992. X
  993. X    for (i = 1; i <= Num_races; i++) {
  994. X        /* increase tech; change to something else */
  995. X        if (update) {
  996. X            reg int         j;
  997. X            /* Reset controlled planet count */
  998. X            races[i - 1]->controlled_planets = 0;
  999. X            races[i - 1]->planet_points = 0;
  1000. X            for (j = 0; j <= MAXGOVERNORS; j++)
  1001. X                if (races[i - 1]->governor[j].active) {
  1002. X#ifdef MARKET
  1003. X                    races[i - 1]->governor[j].maintain = 0;
  1004. X                    races[i - 1]->governor[j].cost_market = 0;
  1005. X                    races[i - 1]->governor[j].profit_market = 0;
  1006. X#endif
  1007. X                    races[i - 1]->governor[j].cost_tech = 0;
  1008. X                    races[i - 1]->governor[j].income = 0;
  1009. X                }
  1010. X        }
  1011. X#ifdef VOTING
  1012. X        /* Reset their vote for Update go. */
  1013. X        races[i - 1]->votes &= ~VOTE_UPDATE_GO;
  1014. X#endif
  1015. X    }
  1016. X    output_ground_attacks();
  1017. X#ifdef MARKET
  1018. X    if (update) {
  1019. X        /* reset market */
  1020. X        Num_commods = Numcommods();
  1021. X        clr_commodfree();
  1022. X        for (i = Num_commods; i >= 1; i--) {
  1023. X            getcommod(&c, i);
  1024. X            if (!c->deliver) {
  1025. X                c->deliver = 1;
  1026. X                putcommod(c, i);
  1027. X                free(c);
  1028. X                continue;
  1029. X            }
  1030. X            if (c->owner && c->bidder &&
  1031. X                (races[c->bidder - 1]->governor[c->bidder_gov].money >= c->bid)) {
  1032. X                races[c->bidder - 1]->governor[c->bidder_gov].money -= c->bid;
  1033. X                races[c->owner - 1]->governor[c->governor].money += c->bid;
  1034. X                temp = shipping_cost((int) c->star_to,
  1035. X                   (int) c->star_from, &dist, (int) c->bid);
  1036. X                races[c->bidder - 1]->governor[c->bidder_gov].cost_market +=
  1037. X                    c->bid + temp;
  1038. X                races[c->owner - 1]->governor[c->governor].profit_market += c->bid;
  1039. X                maintain(races[c->bidder - 1], (int) c->bidder_gov, temp);
  1040. X                switch (c->type) {
  1041. X                case RESOURCE:
  1042. X                    planets[c->star_to][c->planet_to]->info[c->bidder - 1].resource += c->amount;
  1043. X                    break;
  1044. X                case FUEL:
  1045. X                    planets[c->star_to][c->planet_to]->info[c->bidder - 1].fuel += c->amount;
  1046. X                    break;
  1047. X                case DESTRUCT:
  1048. X                    planets[c->star_to][c->planet_to]->info[c->bidder - 1].destruct += c->amount;
  1049. X                    break;
  1050. X                case CRYSTAL:
  1051. X                    planets[c->star_to][c->planet_to]->info[c->bidder - 1].crystals += c->amount;
  1052. X                    break;
  1053. X                }
  1054. X                sprintf(buf, "Lot %d purchased from %s [%d] at a cost of %d.\n   %d %s arrived at /%s/%s\n",
  1055. X                     i, races[c->owner - 1]->name, c->owner,
  1056. X                    c->bid, c->amount, Commod[c->type],
  1057. X                    Stars[c->star_to]->name,
  1058. X                   Stars[c->star_to]->pnames[c->planet_to]);
  1059. X                push_telegram((int) c->bidder, (int) c->bidder_gov, buf);
  1060. X                sprintf(buf, "Lot %d (%d %s) sold to %s [%d] at a cost of %d.\n",
  1061. X                    i, c->amount, Commod[c->type],
  1062. X                      races[c->bidder - 1]->name, c->bidder,
  1063. X                    c->bid);
  1064. X                push_telegram((int) c->owner, (int) c->governor, buf);
  1065. X                c->owner = c->governor = 0;
  1066. X                c->bidder = c->bidder_gov = 0;
  1067. X            } else {
  1068. X                c->bidder = c->bidder_gov = 0;
  1069. X                c->bid = 0;
  1070. X            }
  1071. X            if (!c->owner)
  1072. X                makecommoddead(i);
  1073. X            putcommod(c, i);
  1074. X            free(c);
  1075. X        }
  1076. X    }
  1077. X#endif
  1078. X
  1079. X    /* check ship masses - ownership */
  1080. X    for (i = 1; i <= Num_ships; i++)
  1081. X        if (ships[i]->alive) {
  1082. X            domass(ships[i]);
  1083. X            doown(ships[i]);
  1084. X        }
  1085. X    /* do all ships one turn - do slower ships first */
  1086. X    for (j = 0; j <= 9; j++)
  1087. X        for (i = 1; i <= Num_ships; i++) {
  1088. X            if (ships[i]->alive && ships[i]->speed == j) {
  1089. X                doship(ships[i], update);
  1090. X                if ((ships[i]->type == STYPE_MISSILE) && !attack_planet(ships[i]))
  1091. X                    domissile(ships[i]);
  1092. X            }
  1093. X        }
  1094. X
  1095. X#ifdef MARKET
  1096. X    /* do maintenance costs */
  1097. X    if (update)
  1098. X        for (i = 1; i <= Num_ships; i++)
  1099. X            if (ships[i]->alive && Shipdata[ships[i]->type][ABIL_MAINTAIN]) {
  1100. X                if (ships[i]->popn)
  1101. X                    races[ships[i]->owner - 1]->governor[ships[i]->governor].maintain +=
  1102. X                        ships[i]->build_cost;
  1103. X                if (ships[i]->troops)
  1104. X                    races[ships[i]->owner - 1]->governor[ships[i]->governor].maintain +=
  1105. X                        UPDATE_TROOP_COST * ships[i]->troops;
  1106. X            }
  1107. X#endif
  1108. X
  1109. X    /* prepare dead ships for recycling */
  1110. X    clr_shipfree();
  1111. X    for (i = 1; i <= Num_ships; i++)
  1112. X        if (!ships[i]->alive)
  1113. X            makeshipdead(i);
  1114. X
  1115. X    /* erase next ship pointers - reset in insert_sh_... */
  1116. X    for (i = 1; i <= Num_ships; i++) {
  1117. X        ships[i]->nextship = 0;
  1118. X        ships[i]->ships = 0;
  1119. X    }
  1120. X    /* clear ship list for insertion */
  1121. X    Sdata.ships = 0;
  1122. X    for (star = 0; star < Sdata.numstars; star++) {
  1123. X        Stars[star]->ships = 0;
  1124. X        for (i = 0; i < Stars[star]->numplanets; i++)
  1125. X            planets[star][i]->ships = 0;
  1126. X    }
  1127. X
  1128. X    /* insert ship into the list of wherever it might be */
  1129. X    for (i = Num_ships; i >= 1; i--) {
  1130. X        if (ships[i]->alive) {
  1131. X            switch (ships[i]->whatorbits) {
  1132. X            case LEVEL_UNIV:
  1133. X                insert_sh_univ(&Sdata, ships[i]);
  1134. X                break;
  1135. X            case LEVEL_STAR:
  1136. X                insert_sh_star(Stars[ships[i]->storbits], ships[i]);
  1137. X                break;
  1138. X            case LEVEL_PLAN:
  1139. X                insert_sh_plan(planets[ships[i]->storbits][ships[i]->pnumorbits], ships[i]);
  1140. X                break;
  1141. X            case LEVEL_SHIP:
  1142. X                insert_sh_ship(ships[i], ships[ships[i]->destshipno]);
  1143. X                break;
  1144. X            default:
  1145. X                break;
  1146. X            }
  1147. X        }
  1148. X    }
  1149. X
  1150. X    /*
  1151. X     * put ABMs and surviving missiles here because ABMs need to have the
  1152. X     * missile in the shiplist of the target planet  Maarten
  1153. X     */
  1154. X    for (i = 1; i <= Num_ships; i++)    /* ABMs defend planet */
  1155. X        if ((ships[i]->type == OTYPE_ABM) && ships[i]->alive)
  1156. X            doabm(ships[i]);
  1157. X
  1158. X    for (i = 1; i <= Num_ships; i++)
  1159. X        if ((ships[i]->type == STYPE_MISSILE) && ships[i]->alive
  1160. X            && attack_planet(ships[i]))
  1161. X            domissile(ships[i]);
  1162. X
  1163. X    for (i = Num_ships; i >= 1; i--)
  1164. X        putship(ships[i]);
  1165. X
  1166. X    for (star = 0; star < Sdata.numstars; star++) {
  1167. X        for (i = 0; i < Stars[star]->numplanets; i++) {
  1168. X            /* store occupation for VPs */
  1169. X            for (j = 1; j <= Num_races; j++) {
  1170. X                if (planets[star][i]->info[j - 1].numsectsowned) {
  1171. X                    setbit(inhabited[star], j);
  1172. X                    setbit(Stars[star]->inhabited, j);
  1173. X                }
  1174. X                if (planets[star][i]->type != TYPE_ASTEROID &&
  1175. X                    (planets[star][i]->info[j - 1].numsectsowned >
  1176. X                     planets[star][i]->Maxx * planets[star][i]->Maxy / 2))
  1177. X                    races[j - 1]->controlled_planets++;
  1178. X
  1179. X                if (planets[star][i]->info[j - 1].numsectsowned)
  1180. X                    races[j - 1]->planet_points += planet_points(planets[star][i]);
  1181. X            }
  1182. X            if (update) {
  1183. X                if (doplanet(star, planets[star][i], i)) {
  1184. X                    /*
  1185. X                     * save smap gotten & altered by
  1186. X                     * doplanet only if the planet is
  1187. X                     * expl
  1188. X                     */
  1189. X                    putsmap(Smap, planets[star][i]);
  1190. X                }
  1191. X            }
  1192. X            putplanet(planets[star][i], star, i);
  1193. X        }
  1194. X        /* do AP's for ea. player  */
  1195. X        if (update)
  1196. X            for (i = 1; i <= Num_races; i++) {
  1197. X                if (starpopns[star][i - 1])
  1198. X                    setbit(Stars[star]->inhabited, i);
  1199. X                else
  1200. X                    clrbit(Stars[star]->inhabited, i);
  1201. X
  1202. X                if (isset(Stars[star]->inhabited, i)) {
  1203. X                    reg int         APs;
  1204. X
  1205. X                    APs = Stars[star]->AP[i - 1] +
  1206. X                        APadd((int) starnumships[star][i - 1],
  1207. X                              (int) starpopns[star][i - 1], races[i - 1]);
  1208. X                    if (APs < LIMIT_APs)
  1209. X                        Stars[star]->AP[i - 1] = APs;
  1210. X                    else
  1211. X                        Stars[star]->AP[i - 1] = LIMIT_APs;
  1212. X                }
  1213. X                /* compute victory points for the block */
  1214. X                if (inhabited[star][0] + inhabited[star][1]) {
  1215. X                    dummy[0] = (Blocks[i - 1].invite[0] & Blocks[i - 1].pledge[0]);
  1216. X                    dummy[1] = (Blocks[i - 1].invite[1] & Blocks[i - 1].pledge[1]);
  1217. X                    Blocks[i - 1].systems_owned += ((inhabited[star][0] | dummy[0]) == dummy[0]) && ((inhabited[star][1] | dummy[1]) == dummy[1]);
  1218. X                }
  1219. X            }
  1220. X        putstar(Stars[star], star);
  1221. X    }
  1222. X
  1223. X    /* add APs to sdata for ea. player */
  1224. X    if (update)
  1225. X        for (i = 1; i <= Num_races; i++) {
  1226. X            Blocks[i - 1].systems_owned = 0;    /* recount systems owned */
  1227. X            if (governed(races[i - 1])) {
  1228. X                reg int         APs;
  1229. X
  1230. X                APs = Sdata.AP[i - 1] + races[i - 1]->planet_points;
  1231. X                if (APs < LIMIT_APs)
  1232. X                    Sdata.AP[i - 1] = APs;
  1233. X                else
  1234. X                    Sdata.AP[i - 1] = LIMIT_APs;
  1235. X            }
  1236. X        }
  1237. X
  1238. X    putsdata(&Sdata);
  1239. X
  1240. X    /* here is where we do victory calculations. */
  1241. X    if (update) {
  1242. X        victory = (struct victstruct *) malloc(Num_races *
  1243. X                         sizeof(struct victstruct));
  1244. X        for (i = 1; i <= Num_races; i++) {
  1245. X            victory[i - 1].numsects = 0;
  1246. X            victory[i - 1].shipcost = 0;
  1247. X            victory[i - 1].shiptech = 0;
  1248. X            victory[i - 1].morale = races[i - 1]->morale;
  1249. X            victory[i - 1].res = 0;
  1250. X            victory[i - 1].des = 0;
  1251. X            victory[i - 1].fuel = 0;
  1252. X            victory[i - 1].money = races[i - 1]->governor[0].money;
  1253. X            for (j = 1; j <= MAXGOVERNORS; j++)
  1254. X                if (races[i - 1]->governor[j].active)
  1255. X                    victory[i - 1].money += races[i - 1]->governor[j].money;
  1256. X        }
  1257. X
  1258. X        for (star = 0; star < Sdata.numstars; star++) {
  1259. X            /* do planets in the star next */
  1260. X            for (i = 0; i < Stars[star]->numplanets; i++) {
  1261. X                for (j = 0; j < Num_races; j++) {
  1262. X                    if (!planets[star][i]->info[j].explored)
  1263. X                        continue;
  1264. X                    victory[j].numsects += (int) planets[star][i]->info[j].numsectsowned;
  1265. X                    victory[j].res += (int) planets[star][i]->info[j].resource;
  1266. X                    victory[j].des += (int) planets[star][i]->info[j].destruct;
  1267. X                    victory[j].fuel += (int) planets[star][i]->info[j].fuel;
  1268. X                }
  1269. X            }    /* end of planet searchings */
  1270. X        }        /* end of star searchings */
  1271. X
  1272. X        for (i = 1; i <= Num_ships; i++) {
  1273. X            if (!ships[i]->alive)
  1274. X                continue;
  1275. X            victory[ships[i]->owner - 1].shipcost += ships[i]->build_cost;
  1276. X            victory[ships[i]->owner - 1].shiptech += ships[i]->tech;
  1277. X            victory[ships[i]->owner - 1].res += ships[i]->resource;
  1278. X            victory[ships[i]->owner - 1].des += ships[i]->destruct;
  1279. X            victory[ships[i]->owner - 1].fuel += ships[i]->fuel;
  1280. X        }
  1281. X        /* now that we have the info.. calculate the raw score */
  1282. X
  1283. X        for (i = 0; i < Num_races; i++) {
  1284. X            races[i]->victory_score = (VICT_SECT * (int) victory[i].numsects) +
  1285. X                (VICT_SHIP * ((int) victory[i].shipcost +
  1286. X                 (VICT_TECH * (int) victory[i].shiptech))) +
  1287. X                (VICT_RES * ((int) victory[i].res +
  1288. X                         (int) victory[i].des)) +
  1289. X                (VICT_FUEL * (int) victory[i].fuel) +
  1290. X                (VICT_MONEY * (int) victory[i].money);
  1291. X            races[i]->victory_score /= VICT_DIVISOR;
  1292. X            races[i]->victory_score
  1293. X                = (int) (morale_factor((double) victory[i].morale) *
  1294. X                     races[i]->victory_score);
  1295. X
  1296. X        }
  1297. X        free(victory);
  1298. X    }            /* end of if (update) */
  1299. X    for (i = 1; i <= Num_ships; i++) {
  1300. X        putship(ships[i]);
  1301. X        free(ships[i]);
  1302. X    }
  1303. X
  1304. X    if (update) {
  1305. X        for (i = 1; i <= Num_races; i++) {
  1306. X            /* collective intelligence */
  1307. X            if (races[i - 1]->collective_iq) {
  1308. X                double          x = ((2. / 3.14159265) *
  1309. X                             atan((double) Power[i - 1].popn / MESO_POP_SCALE));
  1310. X                races[i - 1]->IQ = races[i - 1]->IQ_limit * x * x;
  1311. X            }
  1312. X            races[i - 1]->tech += (double) (races[i - 1]->IQ) / 100.0;
  1313. X            races[i - 1]->morale += Power[i - 1].planets_owned;
  1314. X            make_discoveries(races[i - 1]);
  1315. X            races[i - 1]->turn += 1;
  1316. X            if (races[i - 1]->controlled_planets >=
  1317. X                Planet_count * VICTORY_PERCENT / 100)
  1318. X                races[i - 1]->victory_turns++;
  1319. X            else
  1320. X                races[i - 1]->victory_turns = 0;
  1321. X
  1322. X            if (races[i - 1]->controlled_planets >= Planet_count * VICTORY_PERCENT / 200)
  1323. X                for (j = 1; j <= Num_races; j++)
  1324. X                    races[j - 1]->translate[i - 1] = 100;
  1325. X
  1326. X            Blocks[i - 1].VPs = 10 * Blocks[i - 1].systems_owned;
  1327. X#ifdef MARKET
  1328. X            for (j = 0; j <= MAXGOVERNORS; j++)
  1329. X                if (races[i - 1]->governor[j].active)
  1330. X                    maintain(races[i - 1], j, (int) races[i - 1]->governor[j].maintain);
  1331. X#endif
  1332. X        }
  1333. X        for (i = 1; i <= Num_races; i++)
  1334. X            putrace(races[i - 1]);
  1335. X    }
  1336. X    free(ships);
  1337. X
  1338. X    if (update) {
  1339. X        compute_power_blocks();
  1340. X        for (i = 1; i <= Num_races; i++) {
  1341. X            Power[i - 1].money = 0;
  1342. X            for (j = 0; j <= MAXGOVERNORS; j++)
  1343. X                if (races[i - 1]->governor[j].active)
  1344. X                    Power[i - 1].money += races[i - 1]->governor[j].money;
  1345. X        }
  1346. X        Putpower(Power);
  1347. X        Putblock(Blocks);
  1348. X    }
  1349. X    for (j = 1; j <= Num_races; j++) {
  1350. X        if (update)
  1351. X            notify_race(j, "Finished with update.\n");
  1352. X        else
  1353. X            notify_race(j, "Finished with movement segment.\n");
  1354. X    }
  1355. X}
  1356. X
  1357. X/*
  1358. X * routine for number of AP's to add to each player in ea. system,scaled by
  1359. X * amount of crew in their palace
  1360. X */
  1361. X
  1362. Xint 
  1363. XAPadd(int sh, int popn, racetype * race)
  1364. X{
  1365. X    int             APs;
  1366. X
  1367. X    APs = round_rand((double) sh / 10.0 + 5. * log10(1.0 + (double) popn));
  1368. X
  1369. X    if (governed(race))
  1370. X        return APs;
  1371. X    else            /* dont have an active gov center */
  1372. X        return round_rand((double) APs / 20.);
  1373. X}
  1374. X
  1375. Xint 
  1376. Xgoverned(racetype * race)
  1377. X{
  1378. X    return (race->Gov_ship && race->Gov_ship <= Num_ships &&
  1379. X        ships[race->Gov_ship] != NULL && ships[race->Gov_ship]->alive &&
  1380. X        ships[race->Gov_ship]->docked &&
  1381. X        (ships[race->Gov_ship]->whatdest == LEVEL_PLAN ||
  1382. X         (ships[race->Gov_ship]->whatorbits == LEVEL_SHIP &&
  1383. X      ships[ships[race->Gov_ship]->destshipno]->type == STYPE_HABITAT &&
  1384. X          (ships[ships[race->Gov_ship]->destshipno]->whatorbits == LEVEL_PLAN ||
  1385. X           ships[ships[race->Gov_ship]->destshipno]->whatorbits == LEVEL_STAR))));
  1386. X}
  1387. X
  1388. X/* fix stability for stars */
  1389. Xvoid 
  1390. Xfix_stability(startype * s)
  1391. X{
  1392. X    int             a, i;
  1393. X
  1394. X    if (s->nova_stage > 0) {
  1395. X        if (s->nova_stage > 14) {
  1396. X            s->stability = 20;
  1397. X            s->nova_stage = 0;
  1398. X            sprintf(telegram_buf, "Notice\n");
  1399. X            sprintf(buf, "\n  Scientists report that star %s\n",
  1400. X                s->name);
  1401. X            strcat(telegram_buf, buf);
  1402. X            sprintf(buf, "is no longer undergoing nova.\n");
  1403. X            strcat(telegram_buf, buf);
  1404. X            for (i = 1; i <= Num_races; i++)
  1405. X                push_telegram_race(i, telegram_buf);
  1406. X
  1407. X            /* telegram everyone when nova over? */
  1408. X        } else
  1409. X            s->nova_stage++;
  1410. X    } else if (s->stability > 20) {
  1411. X        a = int_rand(-1, 3);
  1412. X        /* nova just starting; notify everyone */
  1413. X        if ((s->stability + a) > 100) {
  1414. X            s->stability = 100;
  1415. X            s->nova_stage = 1;
  1416. X            sprintf(telegram_buf, "***** BULLETIN! ******\n");
  1417. X            sprintf(buf, "\n  Scientists report that star %s\n", s->name);
  1418. X            strcat(telegram_buf, buf);
  1419. X            sprintf(buf, "is undergoing nova.\n");
  1420. X            strcat(telegram_buf, buf);
  1421. X            for (i = 1; i <= Num_races; i++)
  1422. X                push_telegram_race(i, telegram_buf);
  1423. X        } else
  1424. X            s->stability += a;
  1425. X    } else {
  1426. X        a = int_rand(-1, 1);
  1427. X        if (((int) s->stability + a) < 0)
  1428. X            s->stability = 0;
  1429. X        else
  1430. X            s->stability += a;
  1431. X    }
  1432. X}
  1433. X
  1434. Xvoid 
  1435. Xdo_reset(int time_reset)
  1436. X{
  1437. X    int             star, i;
  1438. X
  1439. X    Num_ships = Numships();
  1440. X
  1441. X    ships = (shiptype **) malloc(sizeof(shiptype *) * (Num_ships + 1));
  1442. X    for (i = 1; i <= Num_ships; i++)
  1443. X        (void) getship(&ships[i], i);
  1444. X
  1445. X    /* get all stars and planets */
  1446. X    getsdata(&Sdata);
  1447. X    for (star = 0; star < Sdata.numstars; star++) {
  1448. X        getstar(&Stars[star], star);
  1449. X        for (i = 0; i < Stars[star]->numplanets; i++)
  1450. X            getplanet(&planets[star][i], star, i);
  1451. X    }
  1452. X    output_ground_attacks();
  1453. X
  1454. X    /* erase next ship pointers - reset in insert_sh_... */
  1455. X    for (i = 1; i <= Num_ships; i++) {
  1456. X        ships[i]->nextship = 0;
  1457. X        ships[i]->ships = 0;
  1458. X    }
  1459. X
  1460. X    /* clear ship list for insertion */
  1461. X    Sdata.ships = 0;
  1462. X    for (star = 0; star < Sdata.numstars; star++) {
  1463. X        Stars[star]->ships = 0;
  1464. X        for (i = 0; i < Stars[star]->numplanets; i++)
  1465. X            planets[star][i]->ships = 0;
  1466. X    }
  1467. X
  1468. X    /* insert ship into the list of wherever it might be */
  1469. X    for (i = Num_ships; i >= 1; i--) {
  1470. X        if (ships[i]->alive) {
  1471. X            switch (ships[i]->whatorbits) {
  1472. X            case LEVEL_UNIV:
  1473. X                insert_sh_univ(&Sdata, ships[i]);
  1474. X                break;
  1475. X            case LEVEL_STAR:
  1476. X                insert_sh_star(Stars[ships[i]->storbits], ships[i]);
  1477. X                break;
  1478. X            case LEVEL_PLAN:
  1479. X                insert_sh_plan(planets[ships[i]->storbits][ships[i]->pnumorbits], ships[i]);
  1480. X                ships[i]->xpos = planets[ships[i]->storbits][ships[i]->pnumorbits]->xpos
  1481. X                    + Stars[ships[i]->storbits]->xpos;
  1482. X                ships[i]->ypos = planets[ships[i]->storbits][ships[i]->pnumorbits]->ypos
  1483. X                    + Stars[ships[i]->storbits]->ypos;
  1484. X                break;
  1485. X            case LEVEL_SHIP:
  1486. X                insert_sh_ship(ships[i], ships[ships[i]->destshipno]);
  1487. X                break;
  1488. X            default:
  1489. X                break;
  1490. X            }
  1491. X        }
  1492. X    }
  1493. X
  1494. X    /* check ship masses */
  1495. X    for (i = 1; i <= Num_ships; i++)
  1496. X        if (ships[i]->alive) {
  1497. X            domass(ships[i]);
  1498. X            doown(ships[i]);
  1499. X        }
  1500. X    for (star = 0; star < Sdata.numstars; star++) {
  1501. X        if (!isascii(*Stars[star]->name))
  1502. X            sprintf(Stars[star]->name, "%d", star);
  1503. X        for (i = 0; i < Stars[star]->numplanets; i++) {
  1504. X            if (!isascii(*Stars[star]->pnames[i]))
  1505. X                sprintf(Stars[star]->pnames[i], "%d", i);
  1506. X            putplanet(planets[star][i], star, i);
  1507. X        }
  1508. X        putstar(Stars[star], star);
  1509. X    }
  1510. X    putsdata(&Sdata);
  1511. X
  1512. X    for (i = 1; i <= Num_ships; i++) {
  1513. X        putship(ships[i]);
  1514. X        free(ships[i]);
  1515. X    }
  1516. X    free(ships);
  1517. X
  1518. X    for (i = 1; i <= Num_races; i++) {
  1519. X        putrace(races[i - 1]);
  1520. X        if (!send_special_string(i, RESET_END))
  1521. X            notify_race(i, "Finished with reset.\n");
  1522. X    }
  1523. X}
  1524. X
  1525. X#define BIG_WINNER 1
  1526. X#define LITTLE_WINNER 2
  1527. X
  1528. Xvoid 
  1529. Xhandle_victory(void)
  1530. X{
  1531. X    int             i, j;
  1532. X    int             game_over = 0;
  1533. X    int             win_category[64];
  1534. X
  1535. X#ifndef VICTORY
  1536. X    return;
  1537. X#endif
  1538. X
  1539. X    for (i = 1; i <= Num_races; i++) {
  1540. X        win_category[i - 1] = 0;
  1541. X        if (races[i - 1]->controlled_planets >=
  1542. X            Planet_count * VICTORY_PERCENT / 100) {
  1543. X            win_category[i - 1] = LITTLE_WINNER;
  1544. X        }
  1545. X        if (races[i - 1]->victory_turns >= VICTORY_UPDATES) {
  1546. X            game_over++;
  1547. X            win_category[i - 1] = BIG_WINNER;
  1548. X        }
  1549. X    }
  1550. X    if (game_over) {
  1551. X        for (i = 1; i <= Num_races; i++) {
  1552. X            strcat(telegram_buf, "*** Attention ***");
  1553. X            push_telegram_race(i, telegram_buf);
  1554. X            strcat(telegram_buf,
  1555. X               "This game of Galactic Bloodshed is now *over*");
  1556. X            push_telegram_race(i, telegram_buf);
  1557. X            sprintf(telegram_buf, "The big winner%s",
  1558. X                (game_over == 1) ? " is" : "s are");
  1559. X            push_telegram_race(i, telegram_buf);
  1560. X            for (j = 1; j <= Num_races; j++)
  1561. X                if (win_category[j - 1] == BIG_WINNER) {
  1562. X                    sprintf(telegram_buf, "*** [%2d] %-30.30s ***",
  1563. X                        j, races[j - 1]->name);
  1564. X                    push_telegram_race(i, telegram_buf);
  1565. X                }
  1566. X            strcat(telegram_buf, "Lesser winners:");
  1567. X            push_telegram_race(i, telegram_buf);
  1568. X            for (j = 1; j <= Num_races; j++)
  1569. X                if (win_category[j - 1] == LITTLE_WINNER) {
  1570. X                    sprintf(telegram_buf, "+++ [%2d] %-30.30s +++", j, races[j - 1]->name);
  1571. X                    push_telegram_race(i, telegram_buf);
  1572. X                }
  1573. X        }
  1574. X    }
  1575. X}
  1576. X
  1577. Xvoid 
  1578. Xmake_discoveries(racetype * r)
  1579. X{
  1580. X    /* would be nicer to do this with a loop of course - but it's late */
  1581. X    if (!Hyper_drive(r) && r->tech >= TECH_HYPER_DRIVE) {
  1582. X        push_telegram_race(r->Playernum,
  1583. X                "You have discovered HYPERDRIVE technology.\n");
  1584. X        r->discoveries[D_HYPER_DRIVE] = 1;
  1585. X    }
  1586. X    if (!Laser(r) && r->tech >= TECH_LASER) {
  1587. X        push_telegram_race(r->Playernum,
  1588. X                 "You have discovered LASER technology.\n");
  1589. X        r->discoveries[D_LASER] = 1;
  1590. X    }
  1591. X    if (!Cew(r) && r->tech >= TECH_CEW) {
  1592. X        push_telegram_race(r->Playernum,
  1593. X                   "You have discovered CEW technology.\n");
  1594. X        r->discoveries[D_CEW] = 1;
  1595. X    }
  1596. X    if (!Tractor_beam(r) && r->tech >= TECH_TRACTOR_BEAM) {
  1597. X        push_telegram_race(r->Playernum,
  1598. X              "You have discovered TRACTOR BEAM technology.\n");
  1599. X        r->discoveries[D_TRACTOR_BEAM] = 1;
  1600. X    }
  1601. X    if (!Transporter(r) && r->tech >= TECH_TRANSPORTER) {
  1602. X        push_telegram_race(r->Playernum,
  1603. X               "You have discovered TRANSPORTER technology.\n");
  1604. X        r->discoveries[D_TRANSPORTER] = 1;
  1605. X    }
  1606. X    if (!Avpm(r) && r->tech >= TECH_AVPM) {
  1607. X        push_telegram_race(r->Playernum,
  1608. X                   "You have discovered AVPM technology.\n");
  1609. X        r->discoveries[D_AVPM] = 1;
  1610. X    }
  1611. X    if (!Cloak(r) && r->tech >= TECH_CLOAK) {
  1612. X        push_telegram_race(r->Playernum,
  1613. X                 "You have discovered CLOAK technology.\n");
  1614. X        r->discoveries[D_CLOAK] = 1;
  1615. X    }
  1616. X    if (!Wormhole(r) && r->tech >= TECH_WORMHOLE) {
  1617. X        push_telegram_race(r->Playernum,
  1618. X                  "You have discovered WORMHOLE technology.\n");
  1619. X        r->discoveries[D_WORMHOLE] = 1;
  1620. X    }
  1621. X    if (!Crystal(r) && r->tech >= TECH_CRYSTAL) {
  1622. X        push_telegram_race(r->Playernum,
  1623. X                   "You have discovered CRYSTAL technology.\n");
  1624. X        r->discoveries[D_CRYSTAL] = 1;
  1625. X    }
  1626. X}
  1627. X
  1628. X#ifdef MARKET
  1629. Xvoid 
  1630. Xmaintain(racetype * r, int gov, int amount)
  1631. X{
  1632. X    if (r->governor[gov].money >= amount)
  1633. X        r->governor[gov].money -= amount;
  1634. X    else {
  1635. X        r->morale -= (amount - r->governor[gov].money) / 10;
  1636. X        r->governor[gov].money = 0;
  1637. X    }
  1638. X}
  1639. X#endif
  1640. X
  1641. Xint 
  1642. Xattack_planet(shiptype * ship)
  1643. X{
  1644. X    if (ship->whatdest == LEVEL_PLAN)
  1645. X        return 1;
  1646. X    else
  1647. X        return 0;
  1648. X}
  1649. X
  1650. Xvoid 
  1651. Xoutput_ground_attacks(void)
  1652. X{
  1653. X    int             star, i, j;
  1654. X
  1655. X    for (star = 0; star < Sdata.numstars; star++)
  1656. X        for (i = 1; i <= Num_races; i++)
  1657. X            for (j = 1; j <= Num_races; j++)
  1658. X                if (ground_assaults[i - 1][j - 1][star]) {
  1659. X                    sprintf(buf, "%s: %s [%d] assaults %s [%d] %d times.\n",
  1660. X                        Stars[star]->name,
  1661. X                        races[i - 1]->name, i, races[j - 1]->name, j,
  1662. X                    ground_assaults[i - 1][j - 1][star]);
  1663. X                    post(buf, COMBAT);
  1664. X                    ground_assaults[i - 1][j - 1][star] = 0;
  1665. X                }
  1666. X}
  1667. X
  1668. Xint 
  1669. Xplanet_points(planettype * p)
  1670. X{
  1671. X    switch (p->type) {
  1672. X        case TYPE_ASTEROID:return ASTEROID_POINTS;
  1673. X    case TYPE_EARTH:
  1674. X        return EARTH_POINTS;
  1675. X    case TYPE_MARS:
  1676. X        return MARS_POINTS;
  1677. X    case TYPE_ICEBALL:
  1678. X        return ICEBALL_POINTS;
  1679. X    case TYPE_GASGIANT:
  1680. X        return GASGIANT_POINTS;
  1681. X    case TYPE_WATER:
  1682. X        return WATER_POINTS;
  1683. X    case TYPE_FOREST:
  1684. X        return FOREST_POINTS;
  1685. X    case TYPE_DESERT:
  1686. X        return DESERT_POINTS;
  1687. X    default:
  1688. X        return 0;
  1689. X    }
  1690. X}
  1691. END_OF_FILE
  1692. if test 22753 -ne `wc -c <'server/doturn.c'`; then
  1693.     echo shar: \"'server/doturn.c'\" unpacked with wrong size!
  1694. fi
  1695. # end of 'server/doturn.c'
  1696. fi
  1697. if test -f 'user/mobiliz.c' -a "${1}" != "-c" ; then 
  1698.   echo shar: Will not clobber existing file \"'user/mobiliz.c'\"
  1699. else
  1700. echo shar: Extracting \"'user/mobiliz.c'\" \(3604 characters\)
  1701. sed "s/^X//" >'user/mobiliz.c' <<'END_OF_FILE'
  1702. X/*
  1703. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  1704. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  1705. X * GB_copyright.h.
  1706. X * 
  1707. X * mobiliz.c -- persuade people to build military stuff. Sectors that are
  1708. X * mobilized produce Destructive Potential in proportion to the % they are
  1709. X * mobilized.  they are also more damage-resistant.
  1710. X */
  1711. X
  1712. X#include "GB_copyright.h"
  1713. X#define EXTERN extern
  1714. X#include "vars.h"
  1715. X#include "ships.h"
  1716. X#include "buffers.h"
  1717. X#include "races.h"
  1718. X#include "power.h"
  1719. X#include <signal.h>
  1720. X#include <ctype.h>
  1721. X
  1722. Xvoid            mobilize(int, int, int);
  1723. Xvoid            tax(int, int, int);
  1724. Xint             control(int, int, startype *);
  1725. X#include "proto.h"
  1726. X
  1727. Xvoid 
  1728. Xmobilize(int Playernum, int Governor, int APcount)
  1729. X{
  1730. X    int             sum_mob = 0;
  1731. X    planettype     *p;
  1732. X
  1733. X    if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  1734. X        sprintf(buf, "scope must be a planet.\n");
  1735. X        notify(Playernum, Governor, buf);
  1736. X        return;
  1737. X    }
  1738. X    if (!control(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum])) {
  1739. X        notify(Playernum, Governor, "You are not authorized to do this here.\n");
  1740. X        return;
  1741. X    }
  1742. X    if (!enufAP(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1], APcount)) {
  1743. X        return;
  1744. X    }
  1745. X    getplanet(&p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1746. X
  1747. X    getsmap(Smap, p);
  1748. X
  1749. X    if (argn < 2) {
  1750. X        sprintf(buf, "Current mobilization: %d    Quota: %d\n",
  1751. X            p->info[Playernum - 1].comread, p->info[Playernum - 1].mob_set);
  1752. X        notify(Playernum, Governor, buf);
  1753. X        free(p);
  1754. X        return;
  1755. X    }
  1756. X    sum_mob = atoi(args[1]);
  1757. X
  1758. X    if (sum_mob > 100 || sum_mob < 0) {
  1759. X        sprintf(buf, "Illegal value.\n");
  1760. X        notify(Playernum, Governor, buf);
  1761. X        free(p);
  1762. X        return;
  1763. X    }
  1764. X    p->info[Playernum - 1].mob_set = sum_mob;
  1765. X    putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1766. X    deductAPs(Playernum, Governor, APcount, Dir[Playernum - 1][Governor].snum, 0);
  1767. X
  1768. X    free(p);
  1769. X}
  1770. X
  1771. Xvoid 
  1772. Xtax(int Playernum, int Governor, int APcount)
  1773. X{
  1774. X    int             sum_tax = 0;
  1775. X    planettype     *p;
  1776. X    racetype       *Race;
  1777. X
  1778. X    if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  1779. X        sprintf(buf, "scope must be a planet.\n");
  1780. X        notify(Playernum, Governor, buf);
  1781. X        return;
  1782. X    }
  1783. X    if (!control(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum])) {
  1784. X        notify(Playernum, Governor, "You are not authorized to do that here.\n");
  1785. X        return;
  1786. X    }
  1787. X    Race = races[Playernum - 1];
  1788. X    if (!Race->Gov_ship) {
  1789. X        notify(Playernum, Governor, "You have no government center active.\n");
  1790. X        return;
  1791. X    }
  1792. X    if (Race->Guest) {
  1793. X        notify(Playernum, Governor, "Sorry, but you can't do this when you are a guest.\n");
  1794. X        return;
  1795. X    }
  1796. X    if (!enufAP(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1], APcount)) {
  1797. X        return;
  1798. X    }
  1799. X    getplanet(&p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1800. X
  1801. X    if (argn < 2) {
  1802. X        sprintf(buf, "Current tax rate: %d%%    Target: %d%%\n",
  1803. X         p->info[Playernum - 1].tax, p->info[Playernum - 1].newtax);
  1804. X        notify(Playernum, Governor, buf);
  1805. X        free(p);
  1806. X        return;
  1807. X    }
  1808. X    sum_tax = atoi(args[1]);
  1809. X
  1810. X    if (sum_tax > 100 || sum_tax < 0) {
  1811. X        sprintf(buf, "Illegal value.\n");
  1812. X        notify(Playernum, Governor, buf);
  1813. X        free(p);
  1814. X        return;
  1815. X    }
  1816. X    p->info[Playernum - 1].newtax = sum_tax;
  1817. X    putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1818. X
  1819. X    deductAPs(Playernum, Governor, APcount, Dir[Playernum - 1][Governor].snum, 0);
  1820. X    notify(Playernum, Governor, "Set.\n");
  1821. X    free(p);
  1822. X}
  1823. X
  1824. Xint 
  1825. Xcontrol(int Playernum, int Governor, startype * star)
  1826. X{
  1827. X    return (!Governor || star->governor[Playernum - 1] == Governor);
  1828. X}
  1829. END_OF_FILE
  1830. if test 3604 -ne `wc -c <'user/mobiliz.c'`; then
  1831.     echo shar: \"'user/mobiliz.c'\" unpacked with wrong size!
  1832. fi
  1833. # end of 'user/mobiliz.c'
  1834. fi
  1835. echo shar: End of archive 10 \(of 21\).
  1836. cp /dev/null ark10isdone
  1837. MISSING=""
  1838. 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
  1839.     if test ! -f ark${I}isdone ; then
  1840.     MISSING="${MISSING} ${I}"
  1841.     fi
  1842. done
  1843. if test "${MISSING}" = "" ; then
  1844.     echo You have unpacked all 21 archives.
  1845.     echo "Now type './buildfiles.sh'"
  1846.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1847. else
  1848.     echo You still need to unpack the following archives:
  1849.     echo "        " ${MISSING}
  1850. fi
  1851. ##  End of shell archive.
  1852. exit 0
  1853.