home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part09 < prev    next >
Encoding:
Internet Message Format  |  1993-03-20  |  53.9 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: v17i021:  gbp - Galactic Bloodshed+, an empire-like war game, Part09/21
  5. Message-ID: <4549@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:31:08 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1794
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1700
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 21
  14. Archive-name: gbp/Part09
  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 9 (of 21)."
  27. # Contents:  server/shlmisc.c user/move.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/shlmisc.c' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'server/shlmisc.c'\"
  32. else
  33. echo shar: Extracting \"'server/shlmisc.c'\" \(22987 characters\)
  34. sed "s/^X//" >'server/shlmisc.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.
  39. X * 
  40. X * miscellaneous stuff included in the shell
  41. X */
  42. X
  43. X#include "GB_copyright.h"
  44. X#define EXTERN extern
  45. X#include "vars.h"
  46. X#include "races.h"
  47. X#include "power.h"
  48. X#include "ships.h"
  49. X#include "buffers.h"
  50. X#include <curses.h>
  51. X#include <signal.h>
  52. X#include <ctype.h>
  53. X#include <stdio.h>
  54. X#include <math.h>
  55. X#include <time.h>
  56. X
  57. Xchar           *Ship(shiptype * s);
  58. Xvoid            grant(int, int, int);
  59. Xvoid            governors(int, int, int);
  60. Xvoid            do_revoke(racetype *, int, int);
  61. Xint             authorized(int, shiptype *);
  62. Xint             start_shiplist(int, int, char *);
  63. Xint             do_shiplist(shiptype **, int *);
  64. Xint             in_list(int, char *, shiptype *, int *);
  65. Xvoid            fix(int, int);
  66. Xint             match(char *, char *);
  67. Xvoid            DontOwnErr(int, int, int);
  68. Xint             enufAP(int, int, unsigned short, int);
  69. Xint             Getracenum(char *, char *, int *, int *);
  70. Xint             GetPlayer(char *);
  71. Xvoid            allocateAPs(int, int, int);
  72. Xvoid            deductAPs(int, int, int, int, int);
  73. Xvoid            list(int, int);
  74. Xdouble          morale_factor(double);
  75. X#if DEBUG
  76. Xchar           *DEBUGmalloc(int, char *, int);
  77. Xvoid            DEBUGfree(char *);
  78. Xchar           *DEBUGrealloc(char *, int, char *, int);
  79. Xvoid            DEBUGcheck(int, int);
  80. Xvoid            DEBUGreset(int, int);
  81. X#endif
  82. X#include "proto.h"
  83. X
  84. Xchar           *
  85. XShip(shiptype * s)
  86. X{
  87. X    adr = !adr;        /* switch between 0 and 1 - adr is a global
  88. X                 * variable */
  89. X    sprintf(junk[adr], "%c%d %s [%d]",
  90. X        Shipltrs[s->type], s->number, s->name, s->owner);
  91. X    return junk[adr];    /* junk is a global buffer */
  92. X}
  93. X
  94. Xvoid 
  95. Xgrant(int Playernum, int Governor, int APcount)
  96. X{
  97. X    racetype       *Race;
  98. X    int             gov, nextshipno, shipno;
  99. X    shiptype       *ship;
  100. X
  101. X
  102. X    Race = races[Playernum - 1];
  103. X    if (argn < 3) {
  104. X        notify(Playernum, Governor, "Syntax: grant <governor> star\n");
  105. X        notify(Playernum, Governor, "        grant <governor> ship <shiplist>\n");
  106. X        notify(Playernum, Governor, "        grant <governor> money <amount>\n");
  107. X        return;
  108. X    }
  109. X    if ((gov = atoi(args[1])) < 0 || gov > MAXGOVERNORS) {
  110. X        notify(Playernum, Governor, "Bad governor number.\n");
  111. X        return;
  112. X    } else if (!Race->governor[gov].active) {
  113. X        notify(Playernum, Governor, "That governor is not active.\n");
  114. X        return;
  115. X    } else if (match(args[2], "star")) {
  116. X        int             snum;
  117. X        if (Dir[Playernum - 1][Governor].level != LEVEL_STAR) {
  118. X            notify(Playernum, Governor, "Please cs to the star system first.\n");
  119. X            return;
  120. X        }
  121. X        snum = Dir[Playernum - 1][Governor].snum;
  122. X        Stars[snum]->governor[Playernum - 1] = gov;
  123. X        sprintf(buf, "\"%s\" has granted you control of the /%s star system.\n",
  124. X            Race->governor[Governor].name, Stars[snum]->name);
  125. X        warn(Playernum, gov, buf);
  126. X        putstar(Stars[snum], snum);
  127. X    } else if (match(args[2], "ship")) {
  128. X        nextshipno = start_shiplist(Playernum, Governor, args[3]);
  129. X        while (shipno = do_shiplist(&ship, &nextshipno))
  130. X            if (in_list(Playernum, args[3], ship, &nextshipno) &&
  131. X                authorized(Governor, ship)) {
  132. X                ship->governor = gov;
  133. X                sprintf(buf, "\"%s\" granted you %s at %s\n",
  134. X                  Race->governor[Governor].name, Ship(ship),
  135. X                    prin_ship_orbits(ship));
  136. X                warn(Playernum, gov, buf);
  137. X                putship(ship);
  138. X                sprintf(buf, "%s granted to \"%s\"\n",
  139. X                      Ship(ship), Race->governor[gov].name);
  140. X                notify(Playernum, Governor, buf);
  141. X                free(ship);
  142. X            } else
  143. X                free(ship);
  144. X    } else if (match(args[2], "money")) {
  145. X        int             amount;
  146. X        if (argn < 4) {
  147. X            notify(Playernum, Governor, "Indicate the amount of money.\n");
  148. X            return;
  149. X        }
  150. X        amount = atoi(args[3]);
  151. X        if (amount < 0 && Governor) {
  152. X            notify(Playernum, Governor, "Only leaders may make take away money.\n");
  153. X            return;
  154. X        }
  155. X
  156. X/*
  157. X        if (amount > Race->governor[Governor].money)
  158. X            amount = Race->governor[Governor].money;
  159. X        else if (-amount > (int)Race->governor[gov].money)
  160. X            amount = (int)-Race->governor[gov].money; 
  161. X*/
  162. X
  163. X    if ((long)amount > Race->governor[Governor].money &&
  164. X        (long)-amount > -Race->governor[Governor].money) {
  165. X            notify(Playernum, Governor, "Illegal amount\n");
  166. X            return;
  167. X    }
  168. X        
  169. X        printf("Amount is %d\n", amount);    
  170. X
  171. X        if (amount > 0) { /* add to a gov */
  172. X            sprintf(buf, "\"%s\" granted you %d money.\n",
  173. X                Race->governor[Governor].name, amount);
  174. X            warn(Playernum, gov, buf);
  175. X            Race->governor[Governor].money -= abs(amount);
  176. X            Race->governor[gov].money += abs(amount);
  177. X        } else if (amount < 0) {  /* deduct from a gov */
  178. X            sprintf(buf, "\"%s\" docked you %d money.\n",
  179. X                Race->governor[Governor].name, -amount);
  180. X            warn(Playernum, gov, buf);
  181. X            Race->governor[Governor].money += abs(amount);
  182. X            Race->governor[gov].money -= abs(amount);
  183. X            
  184. X        }
  185. X        putrace(Race);
  186. X        return;
  187. X    } else
  188. X        notify(Playernum, Governor, "You can't grant that.\n");
  189. X
  190. X}
  191. X
  192. Xvoid 
  193. Xgovernors(int Playernum, int Governor, int APcount)
  194. X{
  195. X    racetype       *Race;
  196. X    reg int         i;
  197. X    int             gov;
  198. X
  199. X    Race = races[Playernum - 1];
  200. X    if (Governor || argn < 3) {    /* the only thing governors can do
  201. X                     * with this */
  202. X        for (i = 0; i <= MAXGOVERNORS; i++) {
  203. X            if (Governor)
  204. X                sprintf(buf, "%d %-15.15s %8s %10d %s",
  205. X                    i, Race->governor[i].name,
  206. X                    Race->governor[i].active ? "ACTIVE" : "INACTIVE",
  207. X                    Race->governor[i].money,
  208. X                    ctime(&Race->governor[i].login));
  209. X            else
  210. X                sprintf(buf, "%d %-15.15s %-10.10s %8s %10d %s",
  211. X                    i, Race->governor[i].name,
  212. X                    Race->governor[i].password,
  213. X                    Race->governor[i].active ? "ACTIVE" : "INACTIVE",
  214. X                    Race->governor[i].money,
  215. X                    ctime(&Race->governor[i].login));
  216. X            notify(Playernum, Governor, buf);
  217. X        }
  218. X    } else if ((gov = atoi(args[1])) < 0 || gov > MAXGOVERNORS) {
  219. X        notify(Playernum, Governor, "No such governor.\n");
  220. X        return;
  221. X    } else if (match(args[0], "appoint")) {
  222. X        /* Syntax: 'appoint <gov> <password>' */
  223. X        if (Race->governor[gov].active) {
  224. X            notify(Playernum, Governor, "That governor is already appointed.\n");
  225. X            return;
  226. X        }
  227. X        Race->governor[gov].active = 1;
  228. X        Race->governor[gov].homelevel = Race->governor[gov].deflevel =
  229. X            Race->governor[0].deflevel;
  230. X        Race->governor[gov].homesystem = Race->governor[gov].defsystem =
  231. X            Race->governor[0].defsystem;
  232. X        Race->governor[gov].homeplanetnum = Race->governor[gov].defplanetnum =
  233. X            Race->governor[0].defplanetnum;
  234. X        Race->governor[gov].money = 0;
  235. X        Race->governor[gov].toggle.highlight = Playernum;
  236. X        Race->governor[gov].toggle.inverse = 1;
  237. X        strncpy(Race->governor[gov].password, args[2], RNAMESIZE - 1);
  238. X        putrace(Race);
  239. X        notify(Playernum, Governor, "Governor activated.\n");
  240. X        return;
  241. X    } else if (match(args[0], "revoke")) {
  242. X        reg int         j;
  243. X        if (!gov) {
  244. X            notify(Playernum, Governor, "You can't revoke your leadership!\n");
  245. X            return;
  246. X        }
  247. X        if (!Race->governor[gov].active) {
  248. X            notify(Playernum, Governor, "That governor is not active.\n");
  249. X            return;
  250. X        }
  251. X        if (argn < 4)
  252. X            j = 0;
  253. X        else
  254. X            j = atoi(args[3]);    /* who gets this governors
  255. X                         * stuff */
  256. X        if (j < 0 || j > MAXGOVERNORS) {
  257. X            notify(Playernum, Governor, "You can't give stuff to that governor!\n");
  258. X            return;
  259. X        }
  260. X        if (!strcmp(Race->governor[gov].password, args[2])) {
  261. X            notify(Playernum, Governor, "Incorrect password.\n");
  262. X            return;
  263. X        }
  264. X        if (!Race->governor[j].active || j == gov) {
  265. X            notify(Playernum, Governor, "Bad target governor.\n");
  266. X            return;
  267. X        }
  268. X        do_revoke(Race, gov, j);    /* give stuff from gov to j */
  269. X        putrace(Race);
  270. X        notify(Playernum, Governor, "Done.\n");
  271. X        return;
  272. X    } else if (match(args[2], "password")) {
  273. X        if (Race->Guest) {
  274. X            notify(Playernum, Governor, "Guest races cannot change passwords.\n");
  275. X            return;
  276. X        }
  277. X        if (argn < 4) {
  278. X            notify(Playernum, Governor, "You must give a password.\n");
  279. X            return;
  280. X        }
  281. X        if (!Race->governor[gov].active) {
  282. X            notify(Playernum, Governor, "That governor is inactive.\n");
  283. X            return;
  284. X        }
  285. X        strncpy(Race->governor[gov].password, args[3], RNAMESIZE - 1);
  286. X        putrace(Race);
  287. X        notify(Playernum, Governor, "Password changed.\n");
  288. X        return;
  289. X    } else
  290. X        notify(Playernum, Governor, "Bad option.\n");
  291. X}
  292. X
  293. Xvoid 
  294. Xdo_revoke(racetype * Race, int gov, int j)
  295. X{
  296. X    register int    i;
  297. X    char            revoke_buf[1024];
  298. X    shiptype       *ship;
  299. X
  300. X    sprintf(revoke_buf, "*** Transferring [%d,%d]'s ownings to [%d,%d] ***\n\n", Race->Playernum, gov, Race->Playernum, j);
  301. X    notify(Race->Playernum, 0, revoke_buf);
  302. X
  303. X    /* First do stars....  */
  304. X
  305. X    for (i = 0; i < Sdata.numstars; i++)
  306. X        if (Stars[i]->governor[Race->Playernum - 1] == gov) {
  307. X            Stars[i]->governor[Race->Playernum - 1] = j;
  308. X            sprintf(revoke_buf, "Changed juridiction of /%s...\n", Stars[i]->name);
  309. X            notify(Race->Playernum, 0, revoke_buf);
  310. X            putstar(Stars[i], i);
  311. X        }
  312. X    /* Now do ships....  */
  313. X    Num_ships = Numships();
  314. X    for (i = 1; i <= Num_ships; i++) {
  315. X        (void) getship(&ship, i);
  316. X        if (ship->alive && (ship->owner == Race->Playernum) &&
  317. X            (ship->governor == gov)) {
  318. X            ship->governor = j;
  319. X            sprintf(revoke_buf, "Changed ownership of %c%d...\n", Shipltrs[ship->type], i);
  320. X            notify(Race->Playernum, 0, revoke_buf);
  321. X            putship(ship);
  322. X        }
  323. X        free(ship);
  324. X    }
  325. X
  326. X    /* And money too....  */
  327. X
  328. X    sprintf(revoke_buf, "Transferring %d money...\n", Race->governor[gov].money);
  329. X    notify(Race->Playernum, 0, revoke_buf);
  330. X    Race->governor[j].money = Race->governor[j].money + Race->governor[gov].money;
  331. X    Race->governor[gov].money = 0;
  332. X
  333. X    /* And last but not least, flag the governor as inactive.... */
  334. X
  335. X    Race->governor[gov].active = 0;
  336. X    strcpy(Race->governor[gov].password, "");
  337. X    strcpy(Race->governor[gov].name, "");
  338. X    sprintf(revoke_buf, "\n*** Governor [%d,%d]'s powers have been REVOKED ***\n", Race->Playernum, gov);
  339. X    notify(Race->Playernum, 0, revoke_buf);
  340. X    sprintf(revoke_buf, "rm %s.%d.%d", TELEGRAMFL, Race->Playernum, gov);
  341. X    system(revoke_buf);    /* Remove the telegram file too....  */
  342. X
  343. X    return;
  344. X}
  345. X
  346. Xint 
  347. Xauthorized(int Governor, shiptype * ship)
  348. X{
  349. X    return (!Governor || ship->governor == Governor);
  350. X}
  351. X
  352. Xint 
  353. Xstart_shiplist(int Playernum, int Governor, char *string)
  354. X{
  355. X    char           *p;
  356. X    planettype     *planet;
  357. X    shiptype       *ship;
  358. X    int             st, pl, sh;
  359. X    p = string;
  360. X
  361. X    if (*p == '#')
  362. X        return (atoi(++p));
  363. X    if (isdigit(*p))
  364. X        return (atoi(p));
  365. X
  366. X    /* ship number not given */
  367. X    st = Dir[Playernum - 1][Governor].snum;
  368. X    pl = Dir[Playernum - 1][Governor].pnum;
  369. X    switch (Dir[Playernum - 1][Governor].level) {
  370. X    case LEVEL_UNIV:
  371. X        getsdata(&Sdata);
  372. X        return Sdata.ships;
  373. X    case LEVEL_STAR:
  374. X        getstar(&Stars[st], st);    /* Stars doesn't need to be
  375. X                         * freed */
  376. X        return Stars[st]->ships;
  377. X    case LEVEL_PLAN:
  378. X        getplanet(&planet, st, pl);
  379. X        sh = planet->ships;
  380. X        free(planet);
  381. X        return sh;
  382. X    case LEVEL_SHIP:
  383. X        (void) getship(&ship, Dir[Playernum - 1][Governor].shipno);
  384. X        sh = ship->ships;
  385. X        free(ship);
  386. X        return sh;
  387. X    default:
  388. X        break;
  389. X    }
  390. X    return 0;
  391. X}
  392. X
  393. X/* Step through linked list at current player scope */
  394. Xint 
  395. Xdo_shiplist(shiptype ** s, int *nextshipno)
  396. X{
  397. X    int             shipno;
  398. X
  399. X    if (!(shipno = *nextshipno))
  400. X        return 0;
  401. X
  402. X    if (!getship(s, shipno))/* allocate memory, free in loop */
  403. X        return 0;
  404. X
  405. X    if (!(*s)->alive)    /* this prevents it from returning a dead
  406. X                 * ship */
  407. X        return 0;    /* ie: try to scrap a dead ship   JPD          */
  408. X
  409. X    *nextshipno = (*s)->nextship;
  410. X    return shipno;
  411. X}
  412. X
  413. Xint 
  414. Xin_list(int Playernum, char *list, shiptype * s, int *nextshipno)
  415. X{
  416. X    char           *p, q;
  417. X    if (s->owner != Playernum || !s->alive)
  418. X        return 0;
  419. X    q = Shipltrs[s->type];
  420. X    p = list;
  421. X    if (*p == '#' || isdigit(*p)) {
  422. X        if (s->owner != Playernum || !s->alive)
  423. X            return 0;
  424. X        *nextshipno = 0;
  425. X        return s->number;
  426. X    }
  427. X    for (; *p; p++)
  428. X        if (*p == q || *p == '*')
  429. X            return s->number;    /* '*' is a wildcard */
  430. X    return 0;
  431. X}
  432. X
  433. X/* Deity fix-it utilities */
  434. Xvoid 
  435. Xfix(int Playernum, int Governor)
  436. X{
  437. X    planettype     *p;
  438. X    shiptype       *s;
  439. X
  440. X    if (match(args[1], "planet")) {
  441. X        if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  442. X            notify(Playernum, Governor, "Change scope to the planet first.\n");
  443. X            return;
  444. X        }
  445. X        getplanet(&p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  446. X        if (match(args[2], "Maxx")) {
  447. X            if (argn > 3)
  448. X                p->Maxx = atoi(args[3]);
  449. X            sprintf(buf, "Maxx = %d\n", p->Maxx);
  450. X        } else if (match(args[2], "Maxy")) {
  451. X            if (argn > 3)
  452. X                p->Maxy = atoi(args[3]);
  453. X            sprintf(buf, "Maxy = %d\n", p->Maxy);
  454. X        } else if (match(args[2], "xpos")) {
  455. X            if (argn > 3)
  456. X                p->xpos = (double) atoi(args[3]);
  457. X            sprintf(buf, "xpos = %f\n", p->xpos);
  458. X        } else if (match(args[2], "ypos")) {
  459. X            if (argn > 3)
  460. X                p->ypos = (double) atoi(args[3]);
  461. X            sprintf(buf, "ypos = %f\n", p->ypos);
  462. X        } else if (match(args[2], "ships")) {
  463. X            if (argn > 3)
  464. X                p->ships = atoi(args[3]);
  465. X            sprintf(buf, "ships = %d\n", p->ships);
  466. X        } else if (match(args[2], "sectormappos")) {
  467. X            if (argn > 3)
  468. X                p->sectormappos = atoi(args[3]);
  469. X            sprintf(buf, "sectormappos = %d\n", p->sectormappos);
  470. X        } else if (match(args[2], "rtemp")) {
  471. X            if (argn > 3)
  472. X                p->conditions[RTEMP] = atoi(args[3]);
  473. X            sprintf(buf, "RTEMP = %d\n", p->conditions[RTEMP]);
  474. X        } else if (match(args[2], "temperature")) {
  475. X            if (argn > 3)
  476. X                p->conditions[TEMP] = atoi(args[3]);
  477. X            sprintf(buf, "TEMP = %d\n", p->conditions[TEMP]);
  478. X        } else if (match(args[2], "methane")) {
  479. X            if (argn > 3)
  480. X                p->conditions[METHANE] = atoi(args[3]);
  481. X            sprintf(buf, "METHANE = %d\n", p->conditions[METHANE]);
  482. X        } else if (match(args[2], "oxygen")) {
  483. X            if (argn > 3)
  484. X                p->conditions[OXYGEN] = atoi(args[3]);
  485. X            sprintf(buf, "OXYGEN = %d\n", p->conditions[OXYGEN]);
  486. X        } else if (match(args[2], "co2")) {
  487. X            if (argn > 3)
  488. X                p->conditions[CO2] = atoi(args[3]);
  489. X            sprintf(buf, "CO2 = %d\n", p->conditions[CO2]);
  490. X        } else if (match(args[2], "hydrogen")) {
  491. X            if (argn > 3)
  492. X                p->conditions[HYDROGEN] = atoi(args[3]);
  493. X            sprintf(buf, "HYDROGEN = %d\n", p->conditions[HYDROGEN]);
  494. X        } else if (match(args[2], "nitrogen")) {
  495. X            if (argn > 3)
  496. X                p->conditions[NITROGEN] = atoi(args[3]);
  497. X            sprintf(buf, "NITROGEN = %d\n", p->conditions[NITROGEN]);
  498. X        } else if (match(args[2], "sulfur")) {
  499. X            if (argn > 3)
  500. X                p->conditions[SULFUR] = atoi(args[3]);
  501. X            sprintf(buf, "SULFUR = %d\n", p->conditions[SULFUR]);
  502. X        } else if (match(args[2], "helium")) {
  503. X            if (argn > 3)
  504. X                p->conditions[HELIUM] = atoi(args[3]);
  505. X            sprintf(buf, "HELIUM = %d\n", p->conditions[HELIUM]);
  506. X        } else if (match(args[2], "other")) {
  507. X            if (argn > 3)
  508. X                p->conditions[OTHER] = atoi(args[3]);
  509. X            sprintf(buf, "OTHER = %d\n", p->conditions[OTHER]);
  510. X        } else if (match(args[2], "toxic")) {
  511. X            if (argn > 3)
  512. X                p->conditions[TOXIC] = atoi(args[3]);
  513. X            sprintf(buf, "TOXIC = %d\n", p->conditions[TOXIC]);
  514. X        } else {
  515. X            notify(Playernum, Governor, "No such option for 'fix planet'.\n");
  516. X            free(p);
  517. X            return;
  518. X        }
  519. X        notify(Playernum, Governor, buf);
  520. X        if (argn > 3)
  521. X            putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  522. X        free(p);
  523. X        return;
  524. X    } if (match(args[1], "ship")) {
  525. X        if (Dir[Playernum - 1][Governor].level != LEVEL_SHIP) {
  526. X            notify(Playernum, Governor, "Change scope to the ship you wish to fix.\n");
  527. X            return;
  528. X        }
  529. X        (void) getship(&s, Dir[Playernum - 1][Governor].shipno);
  530. X        if (match(args[2], "fuel")) {
  531. X            if (argn > 3)
  532. X                s->fuel = (double) atoi(args[3]);
  533. X            sprintf(buf, "fuel = %f\n", s->fuel);
  534. X        } else if (match(args[2], "max_fuel")) {
  535. X            if (argn > 3)
  536. X                s->max_fuel = atoi(args[3]);
  537. X            sprintf(buf, "fuel = %d\n", s->max_fuel);
  538. X        } else if (match(args[2], "destruct")) {
  539. X            if (argn > 3)
  540. X                s->destruct = atoi(args[3]);
  541. X            sprintf(buf, "destruct = %d\n", s->destruct);
  542. X        } else if (match(args[2], "resource")) {
  543. X            if (argn > 3)
  544. X                s->resource = atoi(args[3]);
  545. X            sprintf(buf, "resource = %d\n", s->resource);
  546. X        } else if (match(args[2], "damage")) {
  547. X            if (argn > 3)
  548. X                s->damage = atoi(args[3]);
  549. X            sprintf(buf, "damage = %d\n", s->damage);
  550. X        } else if (match(args[2], "alive")) {
  551. X            s->alive = 1;
  552. X            s->damage = 0;
  553. X            sprintf(buf, "%s resurrected\n", Ship(s));
  554. X        } else if (match(args[2], "dead")) {
  555. X            s->alive = 0;
  556. X            s->damage = 100;
  557. X            sprintf(buf, "%s destroyed\n", Ship(s));
  558. X        } else {
  559. X            notify(Playernum, Governor, "No such option for 'fix ship'.\n");
  560. X            free(s);
  561. X            return;
  562. X        }
  563. X        notify(Playernum, Governor, buf);
  564. X        putship(s);
  565. X        free(s);
  566. X        return;
  567. X    } else
  568. X        notify(Playernum, Governor, "Fix what?\n");
  569. X}
  570. X
  571. Xint 
  572. Xmatch(char *p, char *q)
  573. X{
  574. X    return (!strncmp(p, q, strlen(p)));
  575. X}
  576. X
  577. Xvoid 
  578. XDontOwnErr(int Playernum, int Governor, int shipno)
  579. X{
  580. X    sprintf(buf, "You don't own ship #%d.\n", shipno);
  581. X    notify(Playernum, Governor, buf);
  582. X}
  583. X
  584. Xint 
  585. XenufAP(int Playernum, int Governor, unsigned short AP, int x)
  586. X{
  587. X    reg int         blah;
  588. X
  589. X    if (blah = (AP < x)) {
  590. X        sprintf(buf, "You don't have %d action points there.\n", x);
  591. X        notify(Playernum, Governor, buf);
  592. X    }
  593. X    return (!blah);
  594. X}
  595. X
  596. Xint 
  597. XGetracenum(char *racepass, char *govpass, int *racenum, int *govnum)
  598. X{
  599. X    reg int         i, j;
  600. X    for (i = 1; i <= Num_races; i++) {
  601. X        if (!strcmp(racepass, races[i - 1]->password)) {
  602. X            *racenum = i;
  603. X            for (j = 0; j <= MAXGOVERNORS; j++) {
  604. X                if (*races[i - 1]->governor[j].password &&
  605. X                    !strcmp(govpass, races[i - 1]->governor[j].password)) {
  606. X                    *govnum = j;
  607. X                    return;
  608. X                }
  609. X            }
  610. X        }
  611. X    }
  612. X    *racenum = *govnum = 0;
  613. X}
  614. X
  615. X/* returns player # from string containing that players name or #. */
  616. X
  617. Xint 
  618. XGetPlayer(char *name)
  619. X{
  620. X    int             rnum;
  621. X    reg int         i;
  622. X
  623. X    rnum = 0;
  624. X
  625. X    if (isdigit(*name)) {
  626. X        if ((rnum = atoi(name)) < 1 || rnum > Num_races)
  627. X            return 0;
  628. X        return rnum;
  629. X    } else {
  630. X        for (i = 1; i <= Num_races; i++)
  631. X            if (match(name, races[i - 1]->name))
  632. X                return i;
  633. X        return 0;
  634. X    }
  635. X}
  636. X
  637. Xvoid 
  638. XallocateAPs(int Playernum, int Governor, int APcount)
  639. X{
  640. X    int             maxalloc;
  641. X    int             alloc;
  642. X
  643. X    if (Dir[Playernum - 1][Governor].level == LEVEL_UNIV) {
  644. X        sprintf(buf, "Change scope to the system you which to transfer global APs to.\n");
  645. X        notify(Playernum, Governor, buf);
  646. X        return;
  647. X    }
  648. X    alloc = atoi(args[1]);
  649. X    if (alloc <= 0) {
  650. X        notify(Playernum, Governor, "You must specify a positive amount of APs to allocate.\n");
  651. X        return;
  652. X    }
  653. X    getsdata(&Sdata);
  654. X    maxalloc = MIN(Sdata.AP[Playernum - 1], LIMIT_APs -
  655. X           Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1]);
  656. X    if (alloc > maxalloc) {
  657. X        sprintf(buf, "Illegal value (%d) - maximum = %d\n", alloc, maxalloc);
  658. X        notify(Playernum, Governor, buf);
  659. X        return;
  660. X    }
  661. X    Sdata.AP[Playernum - 1] -= alloc;
  662. X    putsdata(&Sdata);
  663. X    getstar(&Stars[Dir[Playernum - 1][Governor].snum], Dir[Playernum - 1][Governor].snum);
  664. X    Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1] =
  665. X        MIN(LIMIT_APs, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1]
  666. X            + alloc);
  667. X    putstar(Stars[Dir[Playernum - 1][Governor].snum], Dir[Playernum - 1][Governor].snum);
  668. X    sprintf(buf, "Allocated\n");
  669. X    notify(Playernum, Governor, buf);
  670. X}
  671. X
  672. Xvoid 
  673. XdeductAPs(int Playernum, int Governor, int n, int snum, int sdata)
  674. X{
  675. X    if (n) {
  676. X
  677. X        if (!sdata) {
  678. X            getstar(&Stars[snum], snum);
  679. X
  680. X            if (Stars[snum]->AP[Playernum - 1] >= n)
  681. X                Stars[snum]->AP[Playernum - 1] -= n;
  682. X            else {
  683. X                Stars[snum]->AP[Playernum - 1] = 0;
  684. X                sprintf(buf, "WHOA!  You cheater!  Oooohh!  OOOOH!\n  I'm tellllllllliiiiiiinnnnnnnnnggggggggg!!!!!!!\n");
  685. X                notify(Playernum, Governor, buf);
  686. X            }
  687. X
  688. X            putstar(Stars[snum], snum);
  689. X
  690. X            if (Dir[Playernum - 1][Governor].level != LEVEL_UNIV && Dir[Playernum - 1][Governor].snum == snum) {
  691. X                /* fix the prompt */
  692. X                sprintf(Dir[Playernum - 1][Governor].prompt + 5, "%02d", Stars[snum]->AP[Playernum - 1]);
  693. X                Dir[Playernum - 1][Governor].prompt[7] = ']';    /* fix bracket (made
  694. X                                         * '\0' by sprintf) */
  695. X            }
  696. X        } else {
  697. X            getsdata(&Sdata);
  698. X            Sdata.AP[Playernum - 1] = MAX(0, Sdata.AP[Playernum - 1] - n);
  699. X            putsdata(&Sdata);
  700. X
  701. X            if (Dir[Playernum - 1][Governor].level == LEVEL_UNIV) {
  702. X                sprintf(Dir[Playernum - 1][Governor].prompt + 2, "%02d", Sdata.AP[Playernum - 1]);
  703. X                Dir[Playernum - 1][Governor].prompt[3] = ']';
  704. X            }
  705. X        }
  706. X    }
  707. X}
  708. X
  709. X/* lists all ships in current scope for debugging purposes */
  710. Xvoid 
  711. Xlist(int Playernum, int Governor)
  712. X{
  713. X    shiptype       *ship;
  714. X    planettype     *p;
  715. X    int             sh;
  716. X
  717. X    switch (Dir[Playernum - 1][Governor].level) {
  718. X    case LEVEL_UNIV:
  719. X        sh = Sdata.ships;
  720. X        break;
  721. X    case LEVEL_STAR:
  722. X        getstar(&Stars[Dir[Playernum - 1][Governor].snum], Dir[Playernum - 1][Governor].snum);
  723. X        sh = Stars[Dir[Playernum - 1][Governor].snum]->ships;
  724. X        break;
  725. X    case LEVEL_PLAN:
  726. X        getplanet(&p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  727. X        sh = p->ships;
  728. X        free(p);
  729. X        break;
  730. X    case LEVEL_SHIP:
  731. X        sh = Dir[Playernum - 1][Governor].shipno;
  732. X        break;
  733. X    }
  734. X
  735. X    while (sh) {
  736. X        (void) getship(&ship, sh);
  737. X        sprintf(buf, "%15s #%d '%s' (pl %d) -> #%d %s\n", Shipnames[ship->type],
  738. X            sh, ship->name, ship->owner, ship->nextship,
  739. X            ship->alive ? "" : "(dead)");
  740. X        notify(Playernum, Governor, buf);
  741. X        sh = ship->nextship;
  742. X        free(ship);
  743. X    }
  744. X
  745. X}
  746. X
  747. Xdouble 
  748. Xmorale_factor(double x)
  749. X{
  750. X    return (atan((double) x / 10000.) / 3.14159565 + .5);
  751. X}
  752. X
  753. X
  754. X#ifdef DEBUG
  755. X/* Debugging malloc routines, check for leaks, by Brian Scearce */
  756. X#undef malloc
  757. X#undef realloc
  758. X#undef free
  759. X
  760. X#define FNAMESIZE 20
  761. X#define DEBUGGING_STACK 100
  762. Xstruct allocated {
  763. X    char           *addr;
  764. X    char            fname[FNAMESIZE + 1];
  765. X    int             lineno;
  766. X};
  767. X
  768. Xstatic struct allocated current[DEBUGGING_STACK];
  769. Xstatic char     error_buf[1024];
  770. X
  771. Xchar           *
  772. XDEBUGmalloc(int size, char *fname, int lineno)
  773. X{
  774. X    char           *p;
  775. X    int             i;
  776. X
  777. X    if ((p = malloc(size)) == 0) {
  778. X        /* DEBUGcheck(0); /* send to noone */
  779. X        sprintf(error_buf, "Out of memory on malloc call from %s line %d\n",
  780. X            fname, lineno);
  781. X        /* panic(error_buf); */
  782. X        exit(-1);
  783. X    } else {
  784. X        for (i = 0; i < DEBUGGING_STACK; i++)
  785. X            if (current[i].addr == 0)
  786. X                break;
  787. X        if (i < DEBUGGING_STACK) {    /* We found one */
  788. X            current[i].addr = p;
  789. X            current[i].lineno = lineno;
  790. X            strncpy(current[i].fname, fname, FNAMESIZE);
  791. X        }
  792. X    }
  793. X    return p;
  794. X}
  795. X
  796. X
  797. Xvoid 
  798. XDEBUGfree(char *p)
  799. X{
  800. X    int             i;
  801. X
  802. X    for (i = 0; i < DEBUGGING_STACK; i++)
  803. X        if (current[i].addr == p)
  804. X            break;
  805. X
  806. X    if (i < DEBUGGING_STACK)/* We found it */
  807. X        current[i].addr = 0;
  808. X
  809. X    free(p);
  810. X}
  811. X
  812. X
  813. Xchar           *
  814. XDEBUGrealloc(char *p, int newsize, char *fname, int lineno)
  815. X{
  816. X    int             i;
  817. X    char           *q;
  818. X
  819. X    if ((q = realloc(p, newsize)) == 0) {
  820. X        /* DEBUGcheck(0); /* send to noone */
  821. X        sprintf(error_buf, "Out of memory on realloc call from %s line %d\n",
  822. X            fname, lineno);
  823. X        /* panic(error_buf); */
  824. X        exit(-1);
  825. X    } else {
  826. X        for (i = 0; i < DEBUGGING_STACK; i++)
  827. X            if (current[i].addr == p)
  828. X                break;
  829. X        if (i < DEBUGGING_STACK) {
  830. X            current[i].addr = q;
  831. X            current[i].lineno = lineno;
  832. X            strncpy(current[i].fname, fname, FNAMESIZE);
  833. X        }
  834. X    }
  835. X    return q;
  836. X}
  837. X
  838. Xvoid 
  839. XDEBUGcheck(int Playernum, int Governor)
  840. X{
  841. X    int             i;
  842. X
  843. X    if (Playernum) {
  844. X        for (i = DEBUGGING_STACK - 1; i >= 0; i--)
  845. X            if (current[i].addr != 0) {
  846. X                sprintf(buf, "%3d malloc in %s l.%d not freed\n",
  847. X                    i, current[i].fname, current[i].lineno);
  848. X                notify(Playernum, Governor, buf);
  849. X            }
  850. X    }
  851. X}
  852. X
  853. Xvoid 
  854. XDEBUGreset(int Playernum, int Governor)
  855. X{
  856. X    int             i;
  857. X
  858. X    for (i = 0; i < DEBUGGING_STACK; i++)
  859. X        current[i].addr = 0;
  860. X}
  861. X#endif
  862. END_OF_FILE
  863. if test 22987 -ne `wc -c <'server/shlmisc.c'`; then
  864.     echo shar: \"'server/shlmisc.c'\" unpacked with wrong size!
  865. fi
  866. # end of 'server/shlmisc.c'
  867. fi
  868. if test -f 'user/move.c' -a "${1}" != "-c" ; then 
  869.   echo shar: Will not clobber existing file \"'user/move.c'\"
  870. else
  871. echo shar: Extracting \"'user/move.c'\" \(28104 characters\)
  872. sed "s/^X//" >'user/move.c' <<'END_OF_FILE'
  873. X/*
  874. X * * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, *
  875. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. * Restrictions in
  876. X * GB_copyright.h. *
  877. X * 
  878. X *  move.c -- move population and assault aliens on target sector
  879. X */
  880. X
  881. X#include <signal.h>
  882. X#include <math.h>
  883. X#include <strings.h>
  884. X
  885. X#include "GB_copyright.h"
  886. X#define EXTERN extern
  887. X#include "vars.h"
  888. X#include "ships.h"
  889. X#include "races.h"
  890. X#include "power.h"
  891. X#include "buffers.h"
  892. X
  893. X/* defense 5 is inpenetrable */
  894. Xint             Defensedata[] = {1, 1, 3, 2, 2, 3, 2, 4, 0};
  895. X
  896. Xextern char    *Desnames[];
  897. Xextern char     Dessymbols[];
  898. X
  899. Xvoid            arm(int, int, int, int);
  900. Xvoid            move_popn(int, int, int);
  901. Xvoid            walk(int, int, int);
  902. Xint             get_move(char, int, int, int *, int *, planettype *);
  903. Xvoid 
  904. Xmech_defend(int, int, int *, int, planettype *, int, int, sectortype *,
  905. X        int, int, sectortype *);
  906. Xvoid 
  907. Xmech_attack_people(shiptype *, int *, int *, racetype *, racetype *,
  908. X           sectortype *, int, int, int, char *, char *);
  909. Xvoid 
  910. Xpeople_attack_mech(shiptype *, int, int, racetype *, racetype *,
  911. X           sectortype *, int, int, char *, char *);
  912. Xvoid 
  913. Xground_attack(racetype *, racetype *, int *, int, unsigned short *,
  914. X          unsigned short *, unsigned int, unsigned int,
  915. X          double, double, double *, double *, int *, int *, int *);
  916. X#include "proto.h"
  917. X
  918. X
  919. Xvoid 
  920. Xarm(int Playernum, int Governor, int APcount, int mode)
  921. X{
  922. X    planettype     *planet;
  923. X    sectortype     *sect;
  924. X    racetype       *Race;
  925. X    int             x = -1, y = -1, amount = 0, cost = 0, enlist_cost,
  926. X                    max_allowed;
  927. X
  928. X    if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  929. X        notify(Playernum, Governor, "Change scope to planet level first.\n");
  930. X        return;
  931. X    }
  932. X    if (!control(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum])) {
  933. X        notify(Playernum, Governor, "You are not authorized to do that here.\n");
  934. X        return;
  935. X    }
  936. X    getplanet(&planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  937. X
  938. X    if (planet->slaved_to > 0 && planet->slaved_to != Playernum) {
  939. X        notify(Playernum, Governor, "That planet has been enslaved!\n");
  940. X        free(planet);
  941. X        return;
  942. X    }
  943. X    sscanf(args[1], "%d,%d", &x, &y);
  944. X    if (x < 0 || y < 0 || x > planet->Maxx - 1 || y > planet->Maxy - 1) {
  945. X        notify(Playernum, Governor, "Illegal coordinates.\n");
  946. X        free(planet);
  947. X        return;
  948. X    }
  949. X    getsector(§, planet, x, y);
  950. X    if (sect->owner != Playernum) {
  951. X        notify(Playernum, Governor, "You don't own that sector.\n");
  952. X        free(planet);
  953. X        free(sect);
  954. X        return;
  955. X    }
  956. X    if (mode) {
  957. X        max_allowed = MIN(sect->popn,
  958. X                  planet->info[Playernum - 1].destruct * (sect->mobilization + 1));
  959. X        if (argn < 3)
  960. X            amount = max_allowed;
  961. X        else {
  962. X            sscanf(args[2], "%d", &amount);
  963. X            if (amount <= 0) {
  964. X                notify(Playernum, Governor, "You must specify a positive number of civs to arm.\n");
  965. X                free(planet);
  966. X                free(sect);
  967. X                return;
  968. X            }
  969. X        }
  970. X        amount = MIN(amount, max_allowed);
  971. X        if (!amount) {
  972. X            notify(Playernum, Governor, "You can't arm any civilians now.\n");
  973. X            free(planet);
  974. X            free(sect);
  975. X            return;
  976. X        }
  977. X        Race = races[Playernum - 1];
  978. X        /* enlist_cost = ENLIST_TROOP_COST * amount; */
  979. X        enlist_cost = Race->fighters * amount;
  980. X        if (enlist_cost > Race->governor[Governor].money) {
  981. X            sprintf(buf, "You need %d money to enlist %d troops.\n",
  982. X                enlist_cost, amount);
  983. X            notify(Playernum, Governor, buf);
  984. X            free(planet);
  985. X            free(sect);
  986. X            return;
  987. X        }
  988. X        Race->governor[Governor].money -= enlist_cost;
  989. X        putrace(Race);
  990. X
  991. X        cost = MAX(1, amount / (sect->mobilization + 1));
  992. X        sect->troops += amount;
  993. X        sect->popn -= amount;
  994. X        planet->popn -= amount;
  995. X        planet->info[Playernum - 1].popn -= amount;
  996. X        planet->troops += amount;
  997. X        planet->info[Playernum - 1].troops += amount;
  998. X        planet->info[Playernum - 1].destruct -= cost;
  999. X        sprintf(buf, "%d population armed at a cost of %dd (now %d civilians, %d military)\n",
  1000. X            amount, cost, sect->popn, sect->troops);
  1001. X        notify(Playernum, Governor, buf);
  1002. X        sprintf(buf, "This mobilization cost %d money.\n", enlist_cost);
  1003. X        notify(Playernum, Governor, buf);
  1004. X    } else {
  1005. X        if (argn < 3)
  1006. X            amount = sect->troops;
  1007. X        else {
  1008. X            sscanf(args[2], "%d", &amount);
  1009. X            if (amount <= 0) {
  1010. X                notify(Playernum, Governor, "You must specify a positive number of civs to arm.\n");
  1011. X                free(planet);
  1012. X                free(sect);
  1013. X                return;
  1014. X            }
  1015. X            amount = MIN(sect->troops, amount);
  1016. X        }
  1017. X        sect->popn += amount;
  1018. X        sect->troops -= amount;
  1019. X        planet->popn += amount;
  1020. X        planet->troops -= amount;
  1021. X        planet->info[Playernum - 1].popn += amount;
  1022. X        planet->info[Playernum - 1].troops -= amount;
  1023. X        sprintf(buf, "%d troops disarmed (now %d civilians, %d military)\n",
  1024. X            amount, sect->popn, sect->troops);
  1025. X        notify(Playernum, Governor, buf);
  1026. X    }
  1027. X    putsector(sect, planet, x, y);
  1028. X    putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1029. X    free(sect);
  1030. X    free(planet);
  1031. X}
  1032. X
  1033. Xvoid 
  1034. Xmove_popn(int Playernum, int Governor, int what)
  1035. X{
  1036. X    int             Assault, APcost;    /* unfriendly movement */
  1037. X    int             casualties, casualties2, casualties3;
  1038. X
  1039. X    planettype     *planet;
  1040. X    sectortype     *sect, *sect2;
  1041. X    int             people, oldpopn, old2popn, old3popn, x = -1, y = -1,
  1042. X                    x2 = -1, y2 = -1;
  1043. X    int             old2owner, old2gov, absorbed, n, done;
  1044. X    double          astrength, dstrength;
  1045. X    racetype       *Race, *alien;
  1046. X
  1047. X    if (Dir[Playernum - 1][Governor].level != LEVEL_PLAN) {
  1048. X        sprintf(buf, "Wrong scope\n");
  1049. X        return;
  1050. X    }
  1051. X    if (!control(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum])) {
  1052. X        notify(Playernum, Governor, "You are not authorized to do that here.\n");
  1053. X        return;
  1054. X    }
  1055. X    getplanet(&planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1056. X
  1057. X    if (planet->slaved_to > 0 && planet->slaved_to != Playernum) {
  1058. X        sprintf(buf, "That planet has been enslaved!\n");
  1059. X        notify(Playernum, Governor, buf);
  1060. X        free(planet);
  1061. X        return;
  1062. X    }
  1063. X    sscanf(args[1], "%d,%d", &x, &y);
  1064. X    if (x < 0 || y < 0 || x > planet->Maxx - 1 || y > planet->Maxy - 1) {
  1065. X        sprintf(buf, "Origin coordinates illegal.\n");
  1066. X        notify(Playernum, Governor, buf);
  1067. X        free(planet);
  1068. X        return;
  1069. X    }
  1070. X    /* movement loop */
  1071. X    done = 0;
  1072. X    n = 0;
  1073. X    while (!done) {
  1074. X        getsector(§, planet, x, y);
  1075. X        if (sect->owner != Playernum) {
  1076. X            sprintf(buf, "You don't own sector %d,%d!\n", x, y);
  1077. X            notify(Playernum, Governor, buf);
  1078. X            free(planet);
  1079. X            free(sect);
  1080. X            return;
  1081. X        }
  1082. X        if (!get_move(args[2][n++], x, y, &x2, &y2, planet)) {
  1083. X            notify(Playernum, Governor, "Finished.\n");
  1084. X            putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1085. X            free(sect);
  1086. X            free(planet);
  1087. X            return;
  1088. X        }
  1089. X        if (x2 < 0 || y2 < 0 || x2 > planet->Maxx - 1 || y2 > planet->Maxy - 1) {
  1090. X            sprintf(buf, "Illegal coordinates %d,%d.\n", x2, y2);
  1091. X            notify(Playernum, Governor, buf);
  1092. X            putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1093. X            free(sect);
  1094. X            free(planet);
  1095. X            return;
  1096. X        }
  1097. X        if (!adjacent(x, y, x2, y2, planet)) {
  1098. X            sprintf(buf, "Illegal move - to adjacent sectors only!\n");
  1099. X            notify(Playernum, Governor, buf);
  1100. X            free(planet);
  1101. X            free(sect);
  1102. X            return;
  1103. X        }
  1104. X        /* ok, the move is legal */
  1105. X        getsector(§2, planet, x2, y2);
  1106. X        if (argn >= 4) {
  1107. X            sscanf(args[3], "%d", &people);
  1108. X            if (people < 0)
  1109. X                if (what == CIV)
  1110. X                    people = sect->popn + people;
  1111. X                else if (what == MIL)
  1112. X                    people = sect->troops + people;
  1113. X        } else {
  1114. X            if (what == CIV)
  1115. X                people = sect->popn;
  1116. X            else if (what == MIL)
  1117. X                people = sect->troops;
  1118. X        }
  1119. X
  1120. X        if ((what == CIV && (abs(people) > sect->popn)) ||
  1121. X            (what == MIL && (abs(people) > sect->troops)) ||
  1122. X            people <= 0) {
  1123. X            if (what == CIV)
  1124. X                sprintf(buf, "Bad value - %d civilians in [%d,%d]\n",
  1125. X                    sect->popn, x, y);
  1126. X            else if (what == MIL)
  1127. X                sprintf(buf, "Bad value - %d troops in [%d,%d]\n", sect->troops, x, y);
  1128. X            notify(Playernum, Governor, buf);
  1129. X            putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1130. X            free(sect);
  1131. X            free(sect2);
  1132. X            free(planet);
  1133. X            return;
  1134. X        }
  1135. X        sprintf(buf, "%d %s moved.\n", people, what == CIV ? "population" : "troops");
  1136. X        notify(Playernum, Governor, buf);
  1137. X
  1138. X        /* check for defending mechs */
  1139. X        mech_defend(Playernum, Governor, &people, what, planet, x, y, sect, x2, y2, sect2);
  1140. X        if (!people) {
  1141. X            putsector(sect, planet, x, y);
  1142. X            putsector(sect2, planet, x2, y2);
  1143. X            putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1144. X            free(sect);
  1145. X            free(sect2);
  1146. X            free(planet);
  1147. X            notify(Playernum, Governor, "Attack aborted.\n");
  1148. X            return;
  1149. X        }
  1150. X        if (sect2->owner && (sect2->owner != Playernum))
  1151. X            Assault = 1;
  1152. X        else
  1153. X            Assault = 0;
  1154. X
  1155. X        /*
  1156. X         * action point cost depends on the size of the group being
  1157. X         * moved
  1158. X         */
  1159. X        if (what == CIV)
  1160. X            APcost = MOVE_FACTOR * ((int) log(1.0 + (double) people) + Assault) + 1;
  1161. X        else if (what == MIL)
  1162. X            APcost = MOVE_FACTOR * ((int) log10(1.0 + (double) people) + Assault) + 1;
  1163. X
  1164. X        if (!enufAP(Playernum, Governor, Stars[Dir[Playernum - 1][Governor].snum]->AP[Playernum - 1],
  1165. X                APcost)) {
  1166. X            free(sect);
  1167. X            free(sect2);
  1168. X            putplanet(planet, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1169. X            free(planet);
  1170. X            return;
  1171. X        }
  1172. X        if (Assault) {
  1173. X            ground_assaults[Playernum - 1][sect2->owner - 1][Dir[Playernum - 1][Governor].snum] += 1;
  1174. X            Race = races[Playernum - 1];
  1175. X            alien = races[sect2->owner - 1];
  1176. X            /* races find out about each other */
  1177. X            alien->translate[Playernum - 1] = MIN(alien->translate[Playernum - 1] + 5,
  1178. X                                  100);
  1179. X            Race->translate[sect2->owner - 1] = MIN(Race->translate[sect2->owner - 1] + 5,
  1180. X                                100);
  1181. X
  1182. X            old2owner = (int) (sect2->owner);
  1183. X            old2gov = Stars[Dir[Playernum - 1][Governor].snum]->governor[sect2->owner - 1];
  1184. X            if (what == CIV)
  1185. X                sect->popn = MAX(0, sect->popn - people);
  1186. X            else if (what == MIL)
  1187. X                sect->troops = MAX(0, sect->troops - people);
  1188. X
  1189. X            if (what == CIV)
  1190. X                sprintf(buf, "%d civ assault %d civ/%d mil\n",
  1191. X                    people, sect2->popn, sect2->troops);
  1192. X            else if (what == MIL)
  1193. X                sprintf(buf, "%d mil assault %d civ/%d mil\n",
  1194. X                    people, sect2->popn, sect2->troops);
  1195. X            notify(Playernum, Governor, buf);
  1196. X            oldpopn = people;
  1197. X            old2popn = sect2->popn;
  1198. X            old3popn = sect2->troops;
  1199. X
  1200. X            ground_attack(Race, alien, &people, what, §2->popn, §2->troops,
  1201. X                      Defensedata[sect->condition],
  1202. X                      Defensedata[sect2->condition],
  1203. X                      Race->likes[sect->condition],
  1204. X                      alien->likes[sect2->condition],
  1205. X                      &astrength, &dstrength,
  1206. X                   &casualties, &casualties2, &casualties3);
  1207. X
  1208. X            sprintf(buf, "Attack: %.2f   Defense: %.2f.\n", astrength, dstrength);
  1209. X            notify(Playernum, Governor, buf);
  1210. X
  1211. X            if (!(sect2->popn + sect2->troops)) {    /* we got 'em */
  1212. X                sect2->owner = Playernum;
  1213. X                /*
  1214. X                 * mesomorphs absorb the bodies of their
  1215. X                 * victims
  1216. X                 */
  1217. X                absorbed = 0;
  1218. X                if (Race->absorb) {
  1219. X                    absorbed = int_rand(0, old2popn + old3popn);
  1220. X                    sprintf(buf, "%d alien bodies absorbed.\n", absorbed);
  1221. X                    notify(Playernum, Governor, buf);
  1222. X                    sprintf(buf, "Metamorphs have absorbed %d bodies!!!\n",
  1223. X                        absorbed);
  1224. X                    notify(old2owner, old2gov, buf);
  1225. X                }
  1226. X                if (what == CIV)
  1227. X                    sect2->popn = people + absorbed;
  1228. X                else if (what == MIL) {
  1229. X                    sect2->popn = absorbed;
  1230. X                    sect2->troops = people;
  1231. X                }
  1232. X                adjust_morale(Race, alien, (int) alien->fighters);
  1233. X            } else {/* retreat */
  1234. X                absorbed = 0;
  1235. X                if (alien->absorb) {
  1236. X                    absorbed = int_rand(0, oldpopn - people);
  1237. X                    sprintf(buf, "%d alien bodies absorbed.\n",
  1238. X                        absorbed);
  1239. X                    notify(old2owner, old2gov, buf);
  1240. X                    sprintf(buf, "Metamorphs have absorbed %d bodies!!!\n",
  1241. X                        absorbed);
  1242. X                    notify(Playernum, Governor, buf);
  1243. X                    sect2->popn += absorbed;
  1244. X                }
  1245. X                if (what == CIV)
  1246. X                    sect->popn += people;
  1247. X                else if (what == MIL)
  1248. X                    sect->troops += people;
  1249. X                adjust_morale(alien, Race, (int) Race->fighters);
  1250. X            }
  1251. X
  1252. X            sprintf(telegram_buf, "/%s/%s: %s [%d] %c(%d,%d) assaults %s [%d] %c(%d,%d) %s\n",
  1253. X                 Stars[Dir[Playernum - 1][Governor].snum]->name,
  1254. X                Stars[Dir[Playernum - 1][Governor].snum]->pnames[Dir[Playernum - 1][Governor].pnum],
  1255. X                Race->name, Playernum, Dessymbols[sect->condition], x, y,
  1256. X                alien->name, alien->Playernum,
  1257. X                Dessymbols[sect2->condition], x2, y2,
  1258. X            (sect2->owner == Playernum ? "VICTORY" : "DEFEAT"));
  1259. X
  1260. X            if (sect2->owner == Playernum) {
  1261. X                sprintf(buf, "VICTORY! The sector is yours!\n");
  1262. X                notify(Playernum, Governor, buf);
  1263. X                sprintf(buf, "Sector CAPTURED!\n");
  1264. X                strcat(telegram_buf, buf);
  1265. X                if (people) {
  1266. X                    sprintf(buf, "%d %s move in.\n",
  1267. X                        people, what == CIV ? "civilians" : "troops");
  1268. X                    notify(Playernum, Governor, buf);
  1269. X                }
  1270. X                planet->info[Playernum - 1].mob_points += (int) sect2->mobilization;
  1271. X                planet->info[old2owner - 1].mob_points -= (int) sect2->mobilization;
  1272. X            } else {
  1273. X                sprintf(buf, "The invasion was repulsed; try again.\n");
  1274. X                notify(Playernum, Governor, buf);
  1275. X                sprintf(buf, "You fought them off!\n");
  1276. X                strcat(telegram_buf, buf);
  1277. X                done = 1;    /* end loop */
  1278. X            }
  1279. X
  1280. X            if (!(sect->popn + sect->troops + people)) {
  1281. X                sprintf(buf, "You killed all of them!\n");
  1282. X                strcat(telegram_buf, buf);
  1283. X                /* increase modifier */
  1284. X                Race->translate[old2owner - 1] = MIN(Race->translate[old2owner - 1] + 5,
  1285. X                                     100);
  1286. X            }
  1287. X            if (!people) {
  1288. X                sprintf(buf, "Oh no! They killed your party to the last man!\n");
  1289. X                notify(Playernum, Governor, buf);
  1290. X                /* increase modifier */
  1291. X                alien->translate[Playernum - 1] = MIN(alien->translate[Playernum - 1] + 5,
  1292. X                                      100);
  1293. X            }
  1294. X            putrace(alien);
  1295. X            putrace(Race);
  1296. X
  1297. X            sprintf(buf, "Casualties: You: %d civ/%d mil, Them: %d %s\n",
  1298. X                casualties2, casualties3,
  1299. X                casualties, what == CIV ? "civ" : "mil");
  1300. X            strcat(telegram_buf, buf);
  1301. X            warn(old2owner, old2gov, telegram_buf);
  1302. X            sprintf(buf, "Casualties: You: %d %s, Them: %d civ/%d mil\n",
  1303. X                casualties, what == CIV ? "civ" : "mil",
  1304. X                casualties2, casualties3);
  1305. X            notify(Playernum, Governor, buf);
  1306. X        } else {
  1307. X            if (what == CIV) {
  1308. X                sect->popn -= people;
  1309. X                sect2->popn += people;
  1310. X            } else if (what == MIL) {
  1311. X                sect->troops -= people;
  1312. X                sect2->troops += people;
  1313. X            }
  1314. X            if (!sect2->owner)
  1315. X                planet->info[Playernum - 1].mob_points += (int) sect2->mobilization;
  1316. X            sect2->owner = Playernum;
  1317. X        }
  1318. X
  1319. X        if (!(sect->popn + sect->troops)) {
  1320. X            planet->info[Playernum - 1].mob_points -= (int) sect->mobilization;
  1321. X            sect->owner = 0;
  1322. X        }
  1323. X        if (!(sect2->popn + sect2->troops)) {
  1324. X            sect2->owner = 0;
  1325. X            done = 1;
  1326. X        }
  1327. X        putsector(sect, planet, x, y);
  1328. X        putsector(sect2, planet, x2, y2);
  1329. X        free(sect);
  1330. X        free(sect2);
  1331. X
  1332. X        deductAPs(Playernum, Governor, APcost, Dir[Playernum - 1][Governor].snum, 0);
  1333. X        x = x2;
  1334. X        y = y2;        /* get ready for the next round */
  1335. X    }
  1336. X    notify(Playernum, Governor, "Finished.\n");
  1337. X    free(planet);
  1338. X}
  1339. X
  1340. Xvoid 
  1341. Xwalk(int Playernum, int Governor, int APcount)
  1342. X{
  1343. X    shiptype       *ship, *ship2, dummy;
  1344. X    planettype     *p;
  1345. X    sectortype     *sect;
  1346. X    int             shipno, x, y, i, sh, succ = 0, civ, mil;
  1347. X    int             damage, oldowner, oldgov;
  1348. X    int             strength, strength1;
  1349. X    racetype       *Race, *alien;
  1350. X
  1351. X    if (argn < 2) {
  1352. X        notify(Playernum, Governor, "Walk what?\n");
  1353. X        return;
  1354. X    }
  1355. X    sscanf(args[1] + (args[1][0] == '#'), "%d", &shipno);
  1356. X    if (!getship(&ship, shipno)) {
  1357. X        notify(Playernum, Governor, "No such ship.\n");
  1358. X        return;
  1359. X    }
  1360. X    if (testship(Playernum, Governor, ship)) {
  1361. X        notify(Playernum, Governor, "You do not control this ship.\n");
  1362. X        free(ship);
  1363. X        return;
  1364. X    }
  1365. X    if (ship->type != OTYPE_AFV) {
  1366. X        notify(Playernum, Governor, "This ship doesn't walk!\n");
  1367. X        free(ship);
  1368. X        return;
  1369. X    }
  1370. X    if (!landed(ship)) {
  1371. X        notify(Playernum, Governor, "This ship is not landed on a planet.\n");
  1372. X        free(ship);
  1373. X        return;
  1374. X    }
  1375. X    if (!ship->popn) {
  1376. X        notify(Playernum, Governor, "No crew.\n");
  1377. X        free(ship);
  1378. X        return;
  1379. X    }
  1380. X    if (ship->fuel < AFV_FUEL_COST) {
  1381. X        sprintf(buf, "You don't have %.1f fuel to move it.\n", AFV_FUEL_COST);
  1382. X        notify(Playernum, Governor, buf);
  1383. X        free(ship);
  1384. X        return;
  1385. X    }
  1386. X    if (!enufAP(Playernum, Governor, Stars[ship->storbits]->AP[Playernum - 1], APcount)) {
  1387. X        free(ship);
  1388. X        return;
  1389. X    }
  1390. X    getplanet(&p, (int) ship->storbits, (int) ship->pnumorbits);
  1391. X    Race = races[Playernum - 1];
  1392. X
  1393. X    if (!get_move(args[2][0], (int) ship->land_x, (int) ship->land_y, &x, &y, p)) {
  1394. X        notify(Playernum, Governor, "Illegal move.\n");
  1395. X        free(p);
  1396. X        free(ship);
  1397. X        return;
  1398. X    }
  1399. X    if (x < 0 || y < 0 || x > p->Maxx - 1 || y > p->Maxy - 1) {
  1400. X        sprintf(buf, "Illegal coordinates %d,%d.\n", x, y);
  1401. X        notify(Playernum, Governor, buf);
  1402. X        free(ship);
  1403. X        putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1404. X        free(p);
  1405. X        return;
  1406. X    }
  1407. X    /* check to see if player is permited on the sector type */
  1408. X    getsector(§, p, x, y);
  1409. X    if (!Race->likes[sect->condition]) {
  1410. X        notify(Playernum, Governor, "Your ships cannot walk into that sector type!\n");
  1411. X        free(ship);
  1412. X        free(p);
  1413. X        free(sect);
  1414. X        return;
  1415. X    }
  1416. X    /*
  1417. X     * if the sector is occupied by non-aligned AFVs, each one will
  1418. X     * attack
  1419. X     */
  1420. X    sh = p->ships;
  1421. X    while (sh && ship->alive) {
  1422. X        (void) getship(&ship2, sh);
  1423. X        if (ship2->owner != Playernum && ship2->type == OTYPE_AFV &&
  1424. X            landed(ship2) && retal_strength(ship2) &&
  1425. X            (ship2->land_x == x) && (ship2->land_y == y)) {
  1426. X            alien = races[ship2->owner - 1];
  1427. X            if (!isset(Race->allied, (int) ship2->owner) ||
  1428. X                !isset(alien->allied, Playernum)) {
  1429. X                while ((strength = retal_strength(ship2)) &&
  1430. X                       (strength1 = retal_strength(ship))) {
  1431. X                    bcopy(ship, &dummy, sizeof(shiptype));
  1432. X                    damage = shoot_ship_to_ship(ship2, ship,
  1433. X                    strength, 0, 0, long_buf, short_buf);
  1434. X                    use_destruct(ship2, strength);
  1435. X                    notify(Playernum, Governor, long_buf);
  1436. X                    warn((int) ship2->owner, (int) ship2->governor, long_buf);
  1437. X                    if (!ship2->alive)
  1438. X                        post(short_buf, COMBAT);
  1439. X                    notify_star(Playernum, Governor, (int) ship2->owner,
  1440. X                       (int) ship->storbits, short_buf);
  1441. X                    if (strength1) {
  1442. X                        damage = shoot_ship_to_ship(&dummy, ship2,
  1443. X                                        strength1, 0, 1, long_buf, short_buf);
  1444. X                        use_destruct(ship, strength1);
  1445. X                        notify(Playernum, Governor, long_buf);
  1446. X                        warn((int) ship2->owner, (int) ship2->governor, long_buf);
  1447. X                        if (!ship2->alive)
  1448. X                            post(short_buf, COMBAT);
  1449. X                        notify_star(Playernum, Governor, (int) ship2->owner,
  1450. X                                (int) ship->storbits, short_buf);
  1451. X                    }
  1452. X                }
  1453. X                putship(ship2);
  1454. X            }
  1455. X        }
  1456. X        sh = ship2->nextship;
  1457. X        free(ship2);
  1458. X    }
  1459. X    /* if the sector is occupied by non-aligned player, attack them first */
  1460. X    if (ship->popn && ship->alive && sect->owner && sect->owner != Playernum) {
  1461. X        oldowner = sect->owner;
  1462. X        oldgov = Stars[ship->storbits]->governor[sect->owner - 1];
  1463. X        alien = races[oldowner - 1];
  1464. X        if (!isset(Race->allied, oldowner) || !isset(alien->allied, Playernum)) {
  1465. X            if (!retal_strength(ship)) {
  1466. X                notify(Playernum, Governor, "You have nothing to attack with!\n");
  1467. X                free(ship);
  1468. X                free(p);
  1469. X                free(sect);
  1470. X                return;
  1471. X            }
  1472. X            while ((sect->popn + sect->troops) && retal_strength(ship)) {
  1473. X                civ = (int) sect->popn;
  1474. X                mil = (int) sect->troops;
  1475. X                mech_attack_people(ship, &civ, &mil,
  1476. X                         Race, alien, sect, x, y, 0,
  1477. X                           long_buf, short_buf);
  1478. X                notify(Playernum, Governor, long_buf);
  1479. X                warn(alien->Playernum, oldgov, long_buf);
  1480. X                notify_star(Playernum, Governor, oldowner, (int) ship->storbits,
  1481. X                        short_buf);
  1482. X                post(short_buf, COMBAT);
  1483. X
  1484. X                people_attack_mech(ship, (int) sect->popn,
  1485. X                           (int) sect->troops,
  1486. X                           alien, Race, sect, x, y,
  1487. X                           long_buf, short_buf);
  1488. X                notify(Playernum, Governor, long_buf);
  1489. X                warn(alien->Playernum, oldgov, long_buf);
  1490. X                notify_star(Playernum, Governor, oldowner, (int) ship->storbits,
  1491. X                        short_buf);
  1492. X                if (!ship->alive)
  1493. X                    post(short_buf, COMBAT);
  1494. X
  1495. X                sect->popn = civ;
  1496. X                sect->troops = mil;
  1497. X                if (!(sect->popn + sect->troops)) {
  1498. X                    p->info[sect->owner - 1].mob_points -=
  1499. X                        (int) sect->mobilization;
  1500. X                    sect->owner = 0;
  1501. X                }
  1502. X            }
  1503. X        }
  1504. X        putrace(alien);
  1505. X        putrace(Race);
  1506. X        putplanet(p, Dir[Playernum - 1][Governor].snum, Dir[Playernum - 1][Governor].pnum);
  1507. X        putsector(sect, p, x, y);
  1508. X    }
  1509. X    if ((sect->owner == Playernum || isset(Race->allied, (int) sect->owner) ||
  1510. X         !sect->owner) && ship->alive)
  1511. X        succ = 1;
  1512. X
  1513. X    if (ship->alive && ship->popn && succ) {
  1514. X        sprintf(buf, "%s moving from %d,%d to %d,%d on %s.\n", Ship(ship),
  1515. X            (int) ship->land_x, (int) ship->land_y, x, y, Dispshiploc(ship));
  1516. X        ship->land_x = x;
  1517. X        ship->land_y = y;
  1518. X        use_fuel(ship, AFV_FUEL_COST);
  1519. X        for (i = 1; i <= Num_races; i++)
  1520. X            if (i != Playernum && p->info[i - 1].numsectsowned)
  1521. X                notify(i, (int) Stars[Dir[Playernum - 1][Governor].snum]->governor[i - 1], buf);
  1522. X    }
  1523. X    putship(ship);
  1524. X    deductAPs(Playernum, Governor, APcount, (int) ship->storbits, 0);
  1525. X    free(ship);
  1526. X    free(p);
  1527. X    free(sect);
  1528. X}
  1529. X
  1530. Xint 
  1531. Xget_move(char direction, int x, int y, int *x2, int *y2,
  1532. X     planettype * planet)
  1533. X{
  1534. X    switch (direction) {
  1535. X        case '1':
  1536. X        case 'b':
  1537. X        *x2 = x - 1;
  1538. X        *y2 = y + 1;
  1539. X        if (*x2 == -1)
  1540. X            *x2 = planet->Maxx - 1;
  1541. X        return 1;
  1542. X    case '2':
  1543. X    case 'k':
  1544. X        *x2 = x;
  1545. X        *y2 = y + 1;
  1546. X        return 1;
  1547. X    case '3':
  1548. X    case 'n':
  1549. X        *x2 = x + 1;
  1550. X        *y2 = y + 1;
  1551. X        if (*x2 == planet->Maxx)
  1552. X            *x2 = 0;
  1553. X        return 1;
  1554. X    case '4':
  1555. X    case 'h':
  1556. X        *x2 = x - 1;
  1557. X        *y2 = y;
  1558. X        if (*x2 == -1)
  1559. X            *x2 = planet->Maxx - 1;
  1560. X        return 1;
  1561. X    case '6':
  1562. X    case 'l':
  1563. X        *x2 = x + 1;
  1564. X        *y2 = y;
  1565. X        if (*x2 == planet->Maxx)
  1566. X            *x2 = 0;
  1567. X        return 1;
  1568. X    case '7':
  1569. X    case 'y':
  1570. X        *x2 = x - 1;
  1571. X        *y2 = y - 1;
  1572. X        if (*x2 == -1)
  1573. X            *x2 = planet->Maxx - 1;
  1574. X        return 1;
  1575. X    case '8':
  1576. X    case 'j':
  1577. X        *x2 = x;
  1578. X        *y2 = y - 1;
  1579. X        return 1;
  1580. X    case '9':
  1581. X    case 'u':
  1582. X        *x2 = x + 1;
  1583. X        *y2 = y - 1;
  1584. X        if (*x2 == planet->Maxx)
  1585. X            *x2 = 0;
  1586. X        return 1;
  1587. X    default:
  1588. X        *x2 = x;
  1589. X        *y2 = y;
  1590. X        return 0;
  1591. X    }
  1592. X}
  1593. X
  1594. Xvoid 
  1595. Xmech_defend(int Playernum, int Governor, int *people, int type,
  1596. X        planettype * p, int x, int y, sectortype * s, int x2, int y2,
  1597. X        sectortype * s2)
  1598. X{
  1599. X    int             sh;
  1600. X    shiptype       *ship;
  1601. X    int             civ = 0, mil = 0;
  1602. X    int             oldgov;
  1603. X    racetype       *Race, *alien;
  1604. X
  1605. X    if (type == CIV)
  1606. X        civ = *people;
  1607. X    else
  1608. X        mil = *people;
  1609. X
  1610. X    sh = p->ships;
  1611. X    Race = races[Playernum - 1];
  1612. X    while (sh && (civ + mil)) {
  1613. X        (void) getship(&ship, sh);
  1614. X        if (ship->owner != Playernum && ship->type == OTYPE_AFV && landed(ship) &&
  1615. X            retal_strength(ship) && (ship->land_x == x2) && (ship->land_y == y2)) {
  1616. X            alien = races[ship->owner - 1];
  1617. X            if (!isset(Race->allied, (int) ship->owner) ||
  1618. X                !isset(alien->allied, Playernum)) {
  1619. X                while ((civ + mil) && retal_strength(ship)) {
  1620. X                    oldgov = Stars[ship->storbits]->governor[alien->Playernum - 1];
  1621. X                    mech_attack_people(ship, &civ, &mil,
  1622. X                         alien, Race, s2, x2, y2, 1,
  1623. X                               long_buf, short_buf);
  1624. X                    notify(Playernum, Governor, long_buf);
  1625. X                    warn(alien->Playernum, oldgov, long_buf);
  1626. X                    if (civ + mil) {
  1627. X                        people_attack_mech(ship, civ, mil,
  1628. X                            Race, alien, s2, x2, y2,
  1629. X                               long_buf, short_buf);
  1630. X                        notify(Playernum, Governor, long_buf);
  1631. X                        warn(alien->Playernum, oldgov, long_buf);
  1632. X                    }
  1633. X                }
  1634. X            }
  1635. X            putship(ship);
  1636. X        }
  1637. X        sh = ship->nextship;
  1638. X        free(ship);
  1639. X    }
  1640. X    *people = civ + mil;
  1641. X}
  1642. X
  1643. Xvoid 
  1644. Xmech_attack_people(shiptype * ship, int *civ, int *mil, racetype * Race,
  1645. X           racetype * alien, sectortype * sect, int x, int y,
  1646. X           int ignore, char *long_msg, char *short_msg)
  1647. X{
  1648. X    int             strength, oldciv, oldmil;
  1649. X    double          astrength, dstrength;
  1650. X    int             cas_civ, cas_mil, ammo;
  1651. X
  1652. X    oldciv = *civ;
  1653. X    oldmil = *mil;
  1654. X
  1655. X    strength = retal_strength(ship);
  1656. X    astrength = MECH_ATTACK * ship->tech * (double) strength
  1657. X        * ((double) ship->armor + 1.0)
  1658. X        * .01 * (100.0 - (double) ship->damage)
  1659. X        * .01 * (Race->likes[sect->condition] + 1.0)
  1660. X        * morale_factor((double) (Race->morale - alien->morale));
  1661. X
  1662. X    dstrength =
  1663. X        (double) (10 * oldmil * alien->fighters + oldciv) * 0.01 * alien->tech
  1664. X        * .01 * (alien->likes[sect->condition] + 1.0)
  1665. X        * ((double) Defensedata[sect->condition] + 1.0)
  1666. X        * morale_factor((double) (alien->morale - Race->morale));
  1667. X
  1668. X    if (ignore) {
  1669. X        ammo = (int) log10((double) dstrength + 1.0) - 1;
  1670. X        ammo = MIN(MAX(ammo, 0), strength);
  1671. X        use_destruct(ship, ammo);
  1672. X    } else
  1673. X        use_destruct(ship, strength);
  1674. X
  1675. X    cas_civ = int_rand(0, round_rand((double) oldciv * astrength / dstrength));
  1676. X    cas_civ = MIN(oldciv, cas_civ);
  1677. X    cas_mil = int_rand(0, round_rand((double) oldmil * astrength / dstrength));
  1678. X    cas_mil = MIN(oldmil, cas_mil);
  1679. X    *civ -= cas_civ;
  1680. X    *mil -= cas_mil;
  1681. X    sprintf(short_msg, "%s: %s %s %s [%d]\n",
  1682. X        Dispshiploc(ship), Ship(ship),
  1683. X        (*civ + *mil) ? "attacked" : "slaughtered",
  1684. X        alien->name, alien->Playernum);
  1685. X    strcpy(long_msg, short_msg);
  1686. X    sprintf(buf, "\tBattle at %d,%d %s: %d guns fired on %d civ/%d mil\n",
  1687. X        x, y, Desnames[sect->condition], strength, oldciv, oldmil);
  1688. X    strcat(long_msg, buf);
  1689. X    sprintf(buf, "\tAttack: %.3f   Defense: %.3f.\n", astrength, dstrength);
  1690. X    strcat(long_msg, buf);
  1691. X    sprintf(buf, "\t%d civ/%d mil killed.\n", cas_civ, cas_mil);
  1692. X    strcat(long_msg, buf);
  1693. X}
  1694. X
  1695. Xvoid 
  1696. Xpeople_attack_mech(shiptype * ship, int civ, int mil, racetype * Race,
  1697. X           racetype * alien, sectortype * sect, int x, int y,
  1698. X           char *long_msg, char *short_msg)
  1699. X{
  1700. X    int             strength;
  1701. X    double          astrength, dstrength;
  1702. X    int             cas_civ, cas_mil, pdam, sdam, damage;
  1703. X    int             ammo;
  1704. X
  1705. X    strength = retal_strength(ship);
  1706. X
  1707. X    dstrength = MECH_ATTACK * ship->tech * (double) strength
  1708. X        * ((double) ship->armor + 1.0)
  1709. X        * .01 * (100.0 - (double) ship->damage)
  1710. X        * .01 * (alien->likes[sect->condition] + 1.0)
  1711. X        * morale_factor((double) (alien->morale - Race->morale));
  1712. X
  1713. X    astrength =
  1714. X        (double) (10 * mil * Race->fighters + civ) * .01 * Race->tech
  1715. X        * .01 * (Race->likes[sect->condition] + 1.0)
  1716. X        * ((double) Defensedata[sect->condition] + 1.0)
  1717. X        * morale_factor((double) (Race->morale - alien->morale));
  1718. X    ammo = (int) log10((double) astrength + 1.0) - 1;
  1719. X    ammo = MIN(strength, MAX(0, ammo));
  1720. X    use_destruct(ship, ammo);
  1721. X    damage = int_rand(0, round_rand(100.0 * astrength / dstrength));
  1722. X    damage = MIN(100, damage);
  1723. X    ship->damage += damage;
  1724. X    if (ship->damage >= 100) {
  1725. X        ship->damage = 100;
  1726. X        kill_ship(Race->Playernum, ship);
  1727. X    }
  1728. X    do_collateral(ship, damage, &cas_civ, &cas_mil, &pdam, &sdam);
  1729. X    sprintf(short_msg, "%s: %s [%d] %s %s\n",
  1730. X        Dispshiploc(ship), Race->name, Race->Playernum,
  1731. X        ship->alive ? "attacked" : "DESTROYED", Ship(ship));
  1732. X    strcpy(long_msg, short_msg);
  1733. X    sprintf(buf, "\tBattle at %d,%d %s: %d civ/%d mil assault %s\n",
  1734. X      x, y, Desnames[sect->condition], civ, mil, Shipnames[ship->type]);
  1735. X    strcat(long_msg, buf);
  1736. X    sprintf(buf, "\tAttack: %.3f   Defense: %.3f.\n", astrength, dstrength);
  1737. X    strcat(long_msg, buf);
  1738. X    sprintf(buf, "\t%d%% damage inflicted for a total of %d%%\n",
  1739. X        damage, ship->damage);
  1740. X    strcat(long_msg, buf);
  1741. X    sprintf(buf, "\t%d civ/%d mil killed   %d prim/%d sec guns knocked out\n",
  1742. X        cas_civ, cas_mil, pdam, sdam);
  1743. X    strcat(long_msg, buf);
  1744. X}
  1745. X
  1746. Xvoid 
  1747. Xground_attack(racetype * Race, racetype * alien, int *people, int what,
  1748. X          unsigned short *civ, unsigned short *mil,
  1749. X          unsigned int def1, unsigned int def2,
  1750. X          double alikes, double dlikes, double *astrength,
  1751. X          double *dstrength, int *casualties, int *casualties2,
  1752. X          int *casualties3)
  1753. X{
  1754. X    int             casualty_scale;
  1755. X
  1756. X    *astrength = (double) (*people * Race->fighters * (what == MIL ? 10 : 1))
  1757. X        * (alikes + 1.0) * ((double) def1 + 1.0)
  1758. X        * morale_factor((double) (Race->morale - alien->morale));
  1759. X    *dstrength = (double) ((*civ + *mil * 10) * alien->fighters)
  1760. X        * (dlikes + 1.0) * ((double) def2 + 1.0)
  1761. X        * morale_factor((double) (alien->morale - Race->morale));
  1762. X    /* nuke both populations */
  1763. X    casualty_scale = MIN(*people * (what == MIL ? 10 : 1) * Race->fighters,
  1764. X                 (*civ + *mil * 10) * alien->fighters);
  1765. X
  1766. X    *casualties = int_rand(0, round_rand((double) ((casualty_scale /
  1767. X                             (what == MIL ? 10 : 1))
  1768. X                           * *dstrength / *astrength)));
  1769. X    *casualties = MIN(*people, *casualties);
  1770. X    *people -= *casualties;
  1771. X
  1772. X    *casualties2 = int_rand(0, round_rand((double) casualty_scale
  1773. X                          * *astrength / *dstrength));
  1774. X    *casualties2 = MIN(*civ, *casualties2);
  1775. X    *civ -= *casualties2;
  1776. X    /* and for troops */
  1777. X    *casualties3 = int_rand(0, round_rand((double) (casualty_scale / 10)
  1778. X                          * *astrength / *dstrength));
  1779. X    *casualties3 = MIN(*mil, *casualties3);
  1780. X    *mil -= *casualties3;
  1781. X}
  1782. END_OF_FILE
  1783. if test 28104 -ne `wc -c <'user/move.c'`; then
  1784.     echo shar: \"'user/move.c'\" unpacked with wrong size!
  1785. fi
  1786. # end of 'user/move.c'
  1787. fi
  1788. echo shar: End of archive 9 \(of 21\).
  1789. cp /dev/null ark9isdone
  1790. MISSING=""
  1791. 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
  1792.     if test ! -f ark${I}isdone ; then
  1793.     MISSING="${MISSING} ${I}"
  1794.     fi
  1795. done
  1796. if test "${MISSING}" = "" ; then
  1797.     echo You have unpacked all 21 archives.
  1798.     echo "Now type './buildfiles.sh'"
  1799.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1800. else
  1801.     echo You still need to unpack the following archives:
  1802.     echo "        " ${MISSING}
  1803. fi
  1804. ##  End of shell archive.
  1805. exit 0
  1806.