home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume10 / gb3 / patch2e < prev    next >
Encoding:
Internet Message Format  |  1990-08-28  |  57.4 KB

  1. Path: uunet!zephyr.ens.tek.com!tekred!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v11i043:  gb3 - Galactic Bloodshed, an empire-like war game [Ver. 2.0], Patch2e
  5. Message-ID: <6230@tekred.CNA.TEK.COM>
  6. Date: 28 Aug 90 19:35:46 GMT
  7. Sender: news@tekred.CNA.TEK.COM
  8. Lines: 2086
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: VANCLEEF@mps.ohio-state.edu
  12. Posting-number: Volume 11, Issue 43
  13. Archive-name: gb3/Patch2e
  14. Patch-To: gb3: Volume 10, Issue 1-14
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 5 (of 9)."
  25. # Contents:  server/build.c server/fire.c server/map.c
  26. # Wrapped by billr@saab on Tue Aug 28 08:54:56 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'server/build.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Renaming existing file \"'server/build.c'\" to \"'server/build.c.orig'\"
  30.   mv -f 'server/build.c' 'server/build.c.orig'
  31. fi
  32. echo shar: Extracting \"'server/build.c'\" \(28337 characters\)
  33. sed "s/^X//" >'server/build.c' <<'END_OF_FILE'
  34. X/*
  35. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  36. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  37. X * Restrictions in GB_copyright.h
  38. X * build -- build a ship
  39. X */
  40. X
  41. X#include "GB_copyright.h"
  42. X
  43. X#define EXTERN extern
  44. X#include "vars.h"
  45. X#include "ships.h"
  46. X#include "races.h"
  47. X#include "shipdata.h"
  48. X#include "buffers.h"
  49. X#include <curses.h>
  50. X#include <setjmp.h>
  51. X#include <signal.h>
  52. X
  53. Xint build_shdata,build_pdata,build_sectdata,sh_data_file, build_racedata;
  54. X
  55. Xmake_mod(Playernum, APcount, argn, args, mode)
  56. Xint Playernum;
  57. Xint APcount;
  58. Xint argn;
  59. Xchar args[MAXARGS][COMMANDSIZE];
  60. Xint mode;
  61. X{
  62. Xint i, value;
  63. Xchar shipc;
  64. Xshiptype *dirship;
  65. Xfloat getmass(), cost();
  66. Xracetype *Race;
  67. X
  68. Xif(Dir[Playernum-1].level != LEVEL_SHIP) {
  69. X    notify(Playernum, "You have to change scope to a factory to program it.\n");
  70. X    return;
  71. X}
  72. X
  73. X     openshdata(&build_shdata);
  74. X     if (!getship(build_shdata, &dirship, Dir[Playernum-1].shipno)) {
  75. X        sprintf(buf,"Illegal dir value.\n");
  76. X        notify(Playernum, buf);
  77. X        close_file(build_shdata);
  78. X        return;
  79. X    }
  80. X    close_file(build_shdata);
  81. X    if (testship(Playernum,dirship, Dir[Playernum-1].shipno))
  82. X        {
  83. X            free(dirship);
  84. X            return;
  85. X        }
  86. Xif(dirship->type != OTYPE_FACTORY) {
  87. X    notify(Playernum, "That is not a factory.\n");
  88. X    free(dirship);
  89. X    return;
  90. X}
  91. X
  92. Xif(dirship->on && argn > 1) {
  93. X    notify(Playernum, "This factory is already online.\n");
  94. X    free(dirship);
  95. X    return;
  96. X}
  97. X
  98. Xopenracedata(&build_racedata);
  99. Xgetrace(build_racedata, &Race, Playernum);
  100. Xclose_file(build_racedata);
  101. X
  102. X
  103. Xif(mode==0) {
  104. Xif(argn<2) {    /* list the current settings for the factory */
  105. Xif(!dirship->build_type) {
  106. X    notify(Playernum, "No ship type specified.\n");
  107. X    free(dirship);
  108. X    free(Race);
  109. X    return;
  110. X    }
  111. X
  112. Xnotify(Playernum, "    - Current production specs -\n");
  113. Xsprintf(buf, "         Ship type: %s\n", Shipnames[dirship->build_type]);
  114. Xnotify(Playernum, buf);
  115. Xsprintf(buf, "           class: %s\n", dirship->class);
  116. Xnotify(Playernum, buf);
  117. Xsprintf(buf, "            tech: %.1f\n", dirship->tech);
  118. Xnotify(Playernum, buf);
  119. Xsprintf(buf, "           armor: %d\n", dirship->armor);
  120. Xnotify(Playernum, buf);
  121. Xsprintf(buf, "            guns: %d\n", dirship->guns);
  122. Xnotify(Playernum, buf);
  123. Xsprintf(buf, "            crew: %d\n", dirship->max_crew);
  124. Xnotify(Playernum, buf);
  125. Xsprintf(buf, "        max fuel: %d\n", dirship->max_fuel);
  126. Xnotify(Playernum, buf);
  127. Xsprintf(buf, "        max cargo: %d\n", dirship->max_resource);
  128. Xnotify(Playernum, buf);
  129. Xsprintf(buf, "        max destruct: %d\n", dirship->max_destruct);
  130. Xnotify(Playernum, buf);
  131. Xsprintf(buf, "        max speed: %d\n\n", dirship->max_speed);
  132. Xnotify(Playernum, buf);
  133. X
  134. Xif(dirship->hyper_drive.has)
  135. X    notify(Playernum, "    Equipped with hyperdrive.\n");
  136. Xelse
  137. X    notify(Playernum, "    Not equipped with hyperdrive.\n");
  138. X
  139. Xif(Shipdata[dirship->build_type][ABIL_LASER]) {
  140. X    if(dirship->laser)
  141. X        notify(Playernum, "    Equipped with combat lasers.\n");
  142. X    else
  143. X        notify(Playernum, "    Not equipped with combat lasers.\n");
  144. X}
  145. X
  146. Xsprintf(buf, "    Cost: %dr  Base Mass: %.1f \n    Size: %d\n", dirship->build_cost, dirship->base_mass,
  147. X        dirship->size);
  148. Xnotify(Playernum, buf);
  149. Xsprintf(buf, "  Status: %s\n\n", (dirship->on ? "Online" : "Offline") );
  150. Xnotify(Playernum, buf);
  151. X
  152. Xfree(dirship);
  153. Xfree(Race);
  154. Xreturn;
  155. X}
  156. X
  157. Xshipc = args[1][0];
  158. X
  159. X    i=0;
  160. X    while ((Shipltrs[i]!=shipc) && (i<NUMSTYPES)) i++;
  161. X
  162. Xif (i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) ) {
  163. X    sprintf(buf, "Illegal ship letter.\n");
  164. X    notify(Playernum, buf);
  165. X    free(dirship);
  166. X    free(Race);
  167. X    return;
  168. X    } else if (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) {
  169. X    sprintf(buf,"You don't have enough technology to build one of those.\n");
  170. X    notify(Playernum, buf);
  171. X    free(dirship);
  172. X    free(Race);
  173. X    return;
  174. X    } 
  175. X
  176. Xif(Shipdata[i][ABIL_BUILD] != Shipdata[OTYPE_FACTORY][ABIL_CONSTRUCT]) {
  177. X    notify(Playernum, "This kind of ship does not require a factory to construct.\n");
  178. X    free(dirship);
  179. X    free(Race);
  180. X    return;
  181. X}
  182. X
  183. Xdirship->build_type = i;
  184. Xdirship->armor = Shipdata[i][ABIL_ARMOR];
  185. Xdirship->guns = Shipdata[i][ABIL_GUNS];
  186. Xdirship->max_crew = Shipdata[i][ABIL_MAXCREW];
  187. Xdirship->max_resource = Shipdata[i][ABIL_CARGO];
  188. Xdirship->max_fuel = Shipdata[i][ABIL_FUELCAP];
  189. Xdirship->max_destruct = Shipdata[i][ABIL_DESTCAP];
  190. Xdirship->max_speed = Shipdata[i][ABIL_SPEED];
  191. Xdirship->hyper_drive.has = Shipdata[i][ABIL_JUMP];
  192. Xdirship->laser = 0;
  193. X
  194. Xdirship->size = ship_size(dirship);
  195. X
  196. Xsprintf(dirship->class, "mod %d", Dir[Playernum-1].shipno);
  197. X
  198. Xsprintf(buf, "Factory designated to produce %ss.\n", Shipnames[i]);
  199. Xnotify(Playernum, buf);
  200. X
  201. X} else if(mode==1) {
  202. X
  203. Xif(!dirship->build_type) {
  204. X    notify(Playernum, "No ship design specified. Use 'make <ship type>' first.\n");
  205. X    free(dirship);
  206. X    free(Race);
  207. X    return;
  208. X}
  209. X
  210. Xif(argn<2) {
  211. X    notify(Playernum, "You have to specify the characteristic you wish to modify.\n");
  212. X    free(dirship);
  213. X    free(Race);
  214. X    return;
  215. X} 
  216. X
  217. Xif(argn==3)
  218. X       sscanf(args[2], "%d", &value);
  219. Xelse
  220. X    value = 0;
  221. X
  222. Xif(value < 0) {
  223. X    notify(Playernum, "That's a ridiculous setting.\n");
  224. X    free(dirship);
  225. X    free(Race);
  226. X    return;
  227. X}
  228. X
  229. Xif(Shipdata[dirship->build_type][ABIL_MOD]) {
  230. X
  231. Xif(!strncmp(args[1], "armor", strlen(args[1]))) {
  232. X    dirship->armor = MIN(value, 100);
  233. X} else if(!strncmp(args[1], "guns", strlen(args[1]))) {
  234. X    dirship->guns = MIN(value, 1000);
  235. X} else if(!strncmp(args[1], "crew", strlen(args[1]))) {
  236. X    dirship->max_crew = MIN(value, 10000);
  237. X} else if(!strncmp(args[1], "cargo", strlen(args[1]))) {
  238. X    dirship->max_resource = MIN(value, 10000);
  239. X} else if(!strncmp(args[1], "fuel", strlen(args[1]))) {
  240. X    dirship->max_fuel = MIN(value, 10000);
  241. X} else if(!strncmp(args[1], "destruct", strlen(args[1]))) {
  242. X   dirship->max_destruct = MIN(value, 10000);
  243. X} else if(!strncmp(args[1], "speed", strlen(args[1]))) {
  244. X    dirship->max_speed = MAX(1,MIN(value, 9));
  245. X} else if(!strncmp(args[1], "hyperdrive", strlen(args[1]))) {
  246. X    if (dirship->build_type == STYPE_SHUTTLE) {
  247. X        notify(Playernum, "Shuttle's can't have hyperdrive.\n");
  248. X        free(dirship);
  249. X        free(Race);
  250. X        return;
  251. X    } else
  252. X        dirship->hyper_drive.has = !dirship->hyper_drive.has;
  253. X} else if(!strncmp(args[1], "laser", strlen(args[1]))) {
  254. X    if(Race->tech < TECH_LASER) {
  255. X        sprintf(buf, "You need a technology level of %.1f to mount lasers.\n", TECH_LASER);
  256. X        notify(Playernum, buf);
  257. X        free(dirship);
  258. X        free(Race);
  259. X        return;
  260. X    }
  261. X    if(Shipdata[dirship->build_type][ABIL_LASER])
  262. X            dirship->laser = !dirship->laser;
  263. X        else {
  264. X        notify(Playernum, "That ship cannot be fitted with combat lasers.\n");
  265. X        free(dirship);
  266. X        free(Race);
  267. X        return;
  268. X        }
  269. X} else {
  270. X    notify(Playernum, "That characteristic either doesn't exist or can't be modified.\n");
  271. X    free(dirship);
  272. X    free(Race);
  273. X    return;
  274. X}
  275. X
  276. X} else {
  277. X    if(!strncmp(args[1], "hyperdrive", strlen(args[1]))) {
  278. X    dirship->hyper_drive.has = !dirship->hyper_drive.has;
  279. X        } else {
  280. X        notify(Playernum, "You may only modify hyperdrive installation on this kind of ship.\n");
  281. X        free(dirship);
  282. X        free(Race);
  283. X        return;
  284. X    }
  285. X}
  286. X
  287. X} else {
  288. X    notify(Playernum, "Weird error.\n");
  289. X    free(dirship);
  290. X    free(Race);
  291. X    return;
  292. X}
  293. X/* compute how much it's going to cost to build the ship */
  294. X
  295. Xif(cost(Playernum, dirship, dirship->tech) > 65535.0) {
  296. X    notify(Playernum, "Woah!! YOU CHEATER!!!  The max cost allowed is 65535!!! I'm Telllllllling!!!\n");
  297. X    free(dirship);
  298. X    free(Race);
  299. X    return;
  300. X}
  301. X
  302. Xdirship->build_cost = (int)cost(Playernum, dirship, dirship->tech);
  303. Xsprintf(buf, "The current cost of the ship is %d resources.\n",
  304. X    dirship->build_cost);
  305. Xnotify(Playernum, buf);
  306. Xdirship->size = ship_size(dirship);
  307. Xdirship->base_mass = getmass(dirship);
  308. Xsprintf(buf, "The current base mass of the ship is %.1f - size is %d.\n",
  309. X    dirship->base_mass, dirship->size);
  310. X
  311. X        openshdata(&build_shdata);
  312. X        putship(build_shdata, dirship, Dir[Playernum-1].shipno);
  313. X        close_file(build_shdata);
  314. Xfree(dirship);
  315. Xfree(Race);
  316. X
  317. X}
  318. X
  319. X
  320. Xbuild(Playernum,APcount, argn,args)
  321. Xint Playernum;
  322. Xint APcount;
  323. Xint argn;
  324. Xchar args[MAXARGS][COMMANDSIZE];
  325. X{
  326. Xint j,i,x= -1 ,y= -1 ,shipno, mask;
  327. Xint load_fuel,load_crew,picked=0,cost,sh,found;
  328. Xfloat fraction;
  329. Xchar c,shipc;
  330. Xplanettype *planet;
  331. Xsectortype *sect;
  332. Xshiptype s,*s2,*dirship;
  333. XFILE *fd;
  334. Xchar temp[128];
  335. Xfloat getmass();
  336. Xracetype *Race;
  337. X
  338. Xbuild_shdata = build_pdata = build_sectdata = NEUTRAL_FD;
  339. X
  340. X if (Dir[Playernum-1].level==LEVEL_PLAN  && argn > 1) {
  341. X    if (!enufAP(Playernum,Stars[Dir[Playernum-1].snum]->AP[Playernum-1], APcount)) {
  342. X        return;
  343. X     } else {
  344. X             openpdata(&build_pdata);
  345. X             getplanet(build_pdata,&planet, Stars[Dir[Playernum-1].snum]->planetpos[Dir[Playernum-1].pnum]);
  346. X        close_file(build_pdata);
  347. X        shipc = args[1][0];
  348. X        }
  349. X } else if (Dir[Playernum-1].level==LEVEL_SHIP) {
  350. X     openshdata(&build_shdata);
  351. X     if (!getship(build_shdata, &dirship, Dir[Playernum-1].shipno)) {
  352. X        sprintf(buf,"Illegal dir value.\n");
  353. X        notify(Playernum, buf);
  354. X        close_file(build_shdata);
  355. X        return;
  356. X    }
  357. X    close_file(build_shdata);
  358. X    if (testship(Playernum,dirship, Dir[Playernum-1].shipno))
  359. X        {
  360. X            free(dirship);
  361. X            return;
  362. X        }
  363. X
  364. X     if (Shipdata[dirship->type][ABIL_CONSTRUCT]==0) {
  365. X        sprintf(buf,"This ship cannot be used to construct other ships.\n");
  366. X        notify(Playernum, buf);
  367. X        free(dirship);
  368. X        return;
  369. X    }
  370. X
  371. X    if(dirship->type==OTYPE_FACTORY) {
  372. X        if(!dirship->on) {
  373. X            notify(Playernum, "This factory is not on line.\n");
  374. X            free(dirship);
  375. X            return;
  376. X            }
  377. X
  378. X        if(dirship->damage) {
  379. X            notify(Playernum, "This factory cannot produce ships until the damage is zero.\n");
  380. X            free(dirship);
  381. X            return;
  382. X            }
  383. X
  384. X        if(!dirship->popn) {
  385. X            notify(Playernum, "This factory doesn't have any crew!\n");
  386. X            free(dirship);
  387. X            return;
  388. X            }
  389. X
  390. X        shipc = Shipltrs[dirship->build_type];
  391. X    } else
  392. X        shipc = args[1][0];
  393. X
  394. X    if (dirship->is_docked && dirship->type != OTYPE_FACTORY) {
  395. X        if (dirship->whatdest==LEVEL_PLAN)
  396. X            {
  397. X            sprintf(buf,"This ship is landed.\n");
  398. X        notify(Playernum, buf);
  399. X            } else {
  400. X            sprintf(buf,"There is already a ship docked here (#%d).\n",
  401. X                    dirship->destshipno);
  402. X        notify(Playernum, buf);
  403. X            }
  404. X        free(dirship);
  405. X        return;
  406. X    }
  407. X
  408. X     /* check stars, sdata for APs */
  409. X     if (dirship->whatorbits==LEVEL_UNIV) {
  410. X         if (!enufAP(Playernum,Sdata.AP[Playernum-1], APcount))
  411. X            {
  412. X            free(dirship);
  413. X            return;
  414. X            }
  415. X     } else if (dirship->whatorbits==LEVEL_STAR) {
  416. X         if (!enufAP(Playernum,Stars[dirship->storbits]->AP[Playernum-1], APcount))
  417. X            {
  418. X            free(dirship);
  419. X            return;
  420. X            }
  421. X    }
  422. X
  423. X/* if we are at a factory, get the planet data too */
  424. X    if(dirship->type==OTYPE_FACTORY) {
  425. X             openpdata(&build_pdata);
  426. X             getplanet(build_pdata,&planet,
  427. X        Stars[dirship->deststar]->planetpos[dirship->destpnum]);
  428. X        close_file(build_pdata);
  429. X    }
  430. X } else {
  431. X    sprintf(buf,"You can't build anything here.\n");
  432. X        notify(Playernum, buf);
  433. X    return;
  434. X }
  435. X
  436. Xopenracedata(&build_racedata);
  437. Xgetrace(build_racedata, &Race, Playernum);
  438. Xclose_file(build_racedata);
  439. X
  440. Xif(shipc=='?') {
  441. X     if (argn==2) {
  442. X    notify(Playernum, "     - Default ship parameters -\n");
  443. X       sprintf(buf, "ltr             ship   crg  arm dstcap guns fcap tech ^crew speed cost\n");
  444. X    notify(Playernum, buf);
  445. X       for (i=0; i<NUMSTYPES; i++)
  446. X      if (Race->tech >= Shipdata[i][ABIL_TECH] || Race->God)
  447. X        if ((i==STYPE_POD && Race->Thing) || i!=STYPE_POD)
  448. X          if(Shipdata[i][ABIL_PROGRAMMED]) {
  449. X          sprintf(buf, " %c%18s%6d%5d%7d%5d%5d%5d%5d%6d%6d\n",
  450. X          Shipltrs[i], Shipnames[i],
  451. X          Shipdata[i][ABIL_CARGO],
  452. X          Shipdata[i][ABIL_ARMOR], Shipdata[i][ABIL_DESTCAP],
  453. X          Shipdata[i][ABIL_GUNS], Shipdata[i][ABIL_FUELCAP], 
  454. X          Shipdata[i][ABIL_TECH], Shipdata[i][ABIL_MAXCREW], 
  455. X          Shipdata[i][ABIL_SPEED], Shipdata[i][ABIL_COST] );
  456. X    notify(Playernum, buf);
  457. X    }
  458. X     } else {
  459. X    /* description of an individual object, ala' examine */
  460. X
  461. X    i = 0;
  462. X        while ((Shipltrs[i]!=args[2][0]) && (i<NUMSTYPES)) 
  463. X        i++;
  464. X        if (i<0 || i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing)
  465. X        || (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) ) {
  466. X        sprintf(buf, "You can't examine that ship type (yet).\n");
  467. X        notify(Playernum, buf);
  468. X    } else if(!Shipdata[i][ABIL_PROGRAMMED]) {
  469. X      sprintf(buf, "This type of ship has not been programmed.\n");
  470. X      notify(Playernum, buf);
  471. X    } else {
  472. X           if ((fd=fopen(EXAM_FL, "r"))==NULL) {
  473. X        perror(EXAM_FL);
  474. X        free(Race);
  475. X        return;
  476. X           } else {
  477. X             /* look through ship data file */
  478. X    sprintf(buf, "\n");
  479. X              for (j=0; j<=i; j++)
  480. X                    while (fgetc(fd) != '~') ;
  481. X           /* give report */
  482. X              while ((c=fgetc(fd)) != '~') {
  483. X        sprintf(temp, "%c", c);
  484. X        strcat(buf, temp);
  485. X        }
  486. X    notify(Playernum, buf);
  487. X              fclose(fd) ;
  488. X       }
  489. X    }
  490. X     }
  491. X
  492. X     free(Race);
  493. X     return;
  494. X }
  495. X
  496. X    i=0;
  497. X    while ((Shipltrs[i]!=shipc) && (i<NUMSTYPES)) i++;
  498. X
  499. Xif (i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) ) {
  500. X    sprintf(buf, "Illegal ship letter.\n");
  501. X    notify(Playernum, buf);
  502. X    free(planet);
  503. X    free(Race);
  504. X    return;
  505. X    } else if (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) {
  506. X    sprintf(buf,"You don't have enough technology to build one of those.\n");
  507. X    notify(Playernum, buf);
  508. X    free(planet);
  509. X    free(Race);
  510. X    return;
  511. X    } else if (!Shipdata[i][ABIL_PROGRAMMED]) {
  512. X    sprintf(buf, "That ship type has not been programmed into the game.\n");
  513. X    notify(Playernum, buf);
  514. X    free(planet);
  515. X    free(Race);
  516. X    return;
  517. X    }
  518. X
  519. X
  520. X
  521. X/* figure out if the ship can be constructed in the current scope */
  522. Xif(Dir[Playernum-1].level==LEVEL_SHIP) {
  523. X
  524. Xif(dirship->type==OTYPE_FACTORY)
  525. X    i = dirship->build_type;
  526. X
  527. X    if(Shipdata[i][ABIL_BUILD] != Shipdata[dirship->type][ABIL_CONSTRUCT]) {
  528. X    switch(Shipdata[dirship->type][ABIL_CONSTRUCT]) {
  529. X        case 0 :
  530. X            sprintf(buf, "%s cannot construct other ships.\n",
  531. X                Shipnames[dirship->type]);
  532. X            break;
  533. X        case 1 :
  534. X            sprintf(buf, "%s may only construct : or +.\n",
  535. X                Shipnames[dirship->type]);
  536. X            break;
  537. X        case 2 :
  538. X            sprintf(buf, "%s may only construct X, H, S, O, or m.\n",
  539. X                Shipnames[dirship->type]);
  540. X            break;
  541. X        case 3:
  542. X            sprintf(buf, "%s may only construct s, D, B, I, C, d, f, e, c, t, or =.\n",
  543. X                Shipnames[dirship->type]);
  544. X            break;
  545. X        }
  546. X        notify(Playernum, buf);
  547. X    free(dirship);
  548. X    free(Race);
  549. X    return;
  550. X        }
  551. X
  552. X} else if(Dir[Playernum-1].level == LEVEL_PLAN) {
  553. X    if(Shipdata[i][ABIL_BUILD] > 1) {
  554. X        switch(Shipdata[i][ABIL_BUILD]) {
  555. X        case 2 :
  556. X            sprintf(buf, "%s may only be constructed by s, c, S, H, or O.\n",
  557. X                Shipnames[i]);
  558. X            break;
  559. X        case 3 :
  560. X            sprintf(buf, "%s requires a factory to build it.\n", Shipnames[i]);
  561. X            break;
  562. X        default :
  563. X            sprintf(buf, "Weird error in build.\n");
  564. X            break;
  565. X        }
  566. X            notify(Playernum, buf);
  567. X        free(planet);
  568. X        free(Race);
  569. X        return;
  570. X    }
  571. X
  572. X
  573. X
  574. X
  575. X} else {
  576. X    notify(Playernum, "Illegal scope.\n");
  577. X    free(Race);
  578. X    return;
  579. X    }
  580. X
  581. X    /* check for resource availability */
  582. X     if (Dir[Playernum-1].level==LEVEL_SHIP && 
  583. X        dirship->type != OTYPE_FACTORY &&
  584. X        dirship->resource < Shipdata[i][ABIL_COST]) {
  585. X    sprintf(buf,"Not enough resources on this ship (you need %d).\n", Shipdata[i][ABIL_COST]);
  586. X    notify(Playernum, buf);
  587. X    free(dirship);
  588. X    free(Race);
  589. X    return;
  590. X     
  591. X     } else if(Dir[Playernum-1].level==LEVEL_SHIP &&
  592. X        dirship->type == OTYPE_FACTORY &&
  593. X        planet->info[Playernum-1].resource < dirship->build_cost) {
  594. X    sprintf(buf,"Not enough resources (%d) available.\n", dirship->build_cost);
  595. X    notify(Playernum, buf);
  596. X    free(dirship);
  597. X    free(Race);
  598. X    free(planet);
  599. X    return;
  600. X    }
  601. X
  602. X    /* find sector to build on (if planet) */
  603. X
  604. X     if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP
  605. X            && dirship->type==OTYPE_FACTORY)) {
  606. X
  607. Xif(Dir[Playernum-1].level==LEVEL_PLAN) {
  608. X       sscanf(args[argn-1], "%d,%d", &x, &y);
  609. X
  610. Xif(x < 0 || x > planet->Maxx-1 || y < 0 || y > planet->Maxy-1) {
  611. X    notify(Playernum, "Illegal sector.\n");
  612. X    free(Race);
  613. X    free(planet);
  614. X    return;
  615. X}
  616. X} else {
  617. X/* get factory coordinates */
  618. X    x = (int)dirship->xpos;
  619. X    y = (int)dirship->ypos;
  620. X    }
  621. X
  622. X       opensectdata(&build_sectdata);
  623. X       getsector(build_sectdata, §, planet->sectormappos+(y*planet->Maxx+x)*sizeof(sectortype));
  624. X    close_file(build_sectdata);
  625. X
  626. X
  627. X     if (Dir[Playernum-1].level==LEVEL_PLAN &&
  628. X        planet->info[Playernum-1].resource < Shipdata[i][ABIL_COST]) {
  629. X        sprintf(buf, "not enough resources in stock (need %d).\n", 
  630. X                Shipdata[i][ABIL_COST]);
  631. X        notify(Playernum, buf);
  632. X        free(sect);
  633. X        free(Race);
  634. X        free(planet);
  635. X        return;
  636. X     } else if(Dir[Playernum-1].level==LEVEL_SHIP &&
  637. X            planet->info[Playernum-1].resource < dirship->build_cost) {
  638. X        sprintf(buf, "Not enough resources in stock (need %d).\n", 
  639. X                dirship->build_cost);
  640. X        notify(Playernum, buf);
  641. X        free(sect);
  642. X        free(dirship);
  643. X        free(planet);
  644. X        free(Race);
  645. X        return;
  646. X        }
  647. X
  648. X    if (sect->owner != Playernum) {
  649. X        sprintf(buf, "You don't own that sector.\n");
  650. X        notify(Playernum, buf);
  651. X        if(Dir[Playernum-1].level==LEVEL_SHIP)
  652. X                free(dirship);
  653. X        free(Race);
  654. X        free(sect);
  655. X        free(planet);
  656. X        return;
  657. X       }
  658. X       load_crew = 0;
  659. X       load_fuel = 0;
  660. X     if(Race->autoload && i!=OTYPE_TRANSDEV) {
  661. X    if(Dir[Playernum-1].level==LEVEL_PLAN) {
  662. X       load_crew = MIN(Shipdata[i][ABIL_MAXCREW], sect->popn);
  663. X       load_fuel = MIN(Shipdata[i][ABIL_FUELCAP], planet->info[Playernum-1].fuel);
  664. X    } else {
  665. X       load_crew = MIN(dirship->max_crew, sect->popn);
  666. X       load_fuel = MIN(dirship->max_fuel, planet->info[Playernum-1].fuel);
  667. X    }
  668. X
  669. X       sect->popn -= load_crew;
  670. X       if (!sect->popn)
  671. X        sect->owner = 0;
  672. X
  673. X       planet->info[Playernum-1].fuel -= load_fuel;
  674. X     }
  675. X
  676. X    } else {
  677. X      load_crew = 0;
  678. X      load_fuel = 0;
  679. X      if(Race->autoload && i!=OTYPE_TRANSDEV) {
  680. X       load_crew = MIN(Shipdata[i][ABIL_MAXCREW], dirship->popn);
  681. X       dirship->popn -= load_crew;
  682. X       dirship->mass -= load_crew * Race->mass;
  683. X       load_fuel = MIN(Shipdata[i][ABIL_FUELCAP], dirship->fuel);
  684. X       dirship->fuel -= load_fuel;
  685. X       dirship->mass -= load_fuel * MASS_FUEL;
  686. X     }
  687. X    }
  688. X
  689. X
  690. X     Bzero(s);
  691. X
  692. X    s.type = i;
  693. X    if (Dir[Playernum-1].level==LEVEL_PLAN) {
  694. X        s.xpos = (float)x;
  695. X        s.ypos = (float)y;
  696. X    } else {
  697. X        s.xpos = dirship->xpos + (float)(!(dirship->type==OTYPE_FACTORY));
  698. X        s.ypos = dirship->ypos;
  699. X    }
  700. X
  701. X    if(Shipdata[i][ABIL_SPEED])
  702. X        s.speed = 1;
  703. X    else
  704. X        s.speed = 0;
  705. X
  706. X    s.owner = Playernum;
  707. X
  708. Xif(Dir[Playernum-1].level==LEVEL_SHIP && dirship->type==OTYPE_FACTORY) {
  709. X        s.tech = dirship->tech;
  710. X    s.armor = dirship->armor;
  711. X    s.guns = dirship->guns;
  712. X    s.size = dirship->size;
  713. X    s.max_crew = dirship->max_crew;
  714. X    s.max_resource = dirship->max_resource;
  715. X    s.max_destruct = dirship->max_destruct;
  716. X    s.max_fuel = dirship->max_fuel;
  717. X    s.max_speed = dirship->max_speed;
  718. X    s.build_cost = dirship->build_cost;
  719. X    s.build_type = dirship->build_type;
  720. X    s.base_mass = dirship->base_mass;
  721. X    s.hyper_drive.has = dirship->hyper_drive.has;
  722. X    s.laser = dirship->laser;
  723. X    sprintf(s.class, "%s", dirship->class);
  724. X            /* docked on the planet */
  725. X        s.whatorbits = LEVEL_PLAN;
  726. X        s.whatdest = LEVEL_PLAN;
  727. X        s.deststar = dirship->deststar;
  728. X        s.destpnum = dirship->destpnum;
  729. X        s.storbits = dirship->storbits;
  730. X        s.pnumorbits = dirship->pnumorbits;
  731. X
  732. X    } else {
  733. X    s.tech = Race->tech;
  734. X    s.armor = Shipdata[i][ABIL_ARMOR];
  735. X    s.guns = Shipdata[i][ABIL_GUNS];
  736. X    s.max_crew = Shipdata[i][ABIL_MAXCREW];
  737. X    s.max_resource = Shipdata[i][ABIL_CARGO];
  738. X    s.max_destruct = Shipdata[i][ABIL_DESTCAP];
  739. X    s.max_fuel = Shipdata[i][ABIL_FUELCAP];
  740. X    s.max_speed = Shipdata[i][ABIL_SPEED];
  741. X    s.build_type = i;
  742. X    s.build_cost = Shipdata[i][ABIL_COST];
  743. X    s.hyper_drive.has = Shipdata[i][ABIL_JUMP];
  744. X    s.laser = Shipdata[i][ABIL_LASER];
  745. X    s.size = ship_size(&s);
  746. X    s.base_mass = getmass(&s);
  747. X    s.mass = getmass(&s);
  748. X    sprintf(s.class, "Standard");
  749. X
  750. X    if (Dir[Playernum-1].level==LEVEL_SHIP) {
  751. X        s.whatdest = LEVEL_SHIP;
  752. X        s.destshipno = Dir[Playernum-1].shipno;
  753. X        s.whatorbits = dirship->whatorbits;
  754. X    } else {
  755. X            /* docked on the planet */
  756. X        s.whatorbits = LEVEL_PLAN;
  757. X        s.whatdest = LEVEL_PLAN;
  758. X        s.deststar = Dir[Playernum-1].snum;
  759. X        s.destpnum = Dir[Playernum-1].pnum;
  760. X    }
  761. X    s.storbits = Dir[Playernum-1].snum;
  762. X    s.pnumorbits = Dir[Playernum-1].pnum;
  763. X}
  764. X
  765. X    s.fuel = load_fuel;
  766. X    s.popn = load_crew;
  767. X    s.destruct = s.resource = 0;
  768. X
  769. X    s.mass = s.base_mass + load_crew*Race->mass + load_fuel*MASS_FUEL;
  770. X    s.is_alive = 1;
  771. X     s.active = 1;
  772. X
  773. X    if(s.guns)
  774. X         s.protect.self = 1;
  775. X    else
  776. X        s.protect.self = 0;
  777. X
  778. X    s.hyper_drive.on = 0;
  779. X    s.hyper_drive.ready = 0;
  780. X    s.hyper_drive.charge = 0;
  781. X    s.fire_laser = 0;
  782. X
  783. X    s.is_docked = 1;
  784. X
  785. X    s.rad = 0;
  786. X    s.damage = Shipdata[s.type][ABIL_DAMAGE];
  787. X        s.retaliate = s.guns;
  788. X
  789. X    s.object.number = 0;
  790. X    s.object.number2 = 0;
  791. X    s.object.number3 = 0;
  792. X    s.object.number4 = 0;
  793. X
  794. X    if (has_switch(&s))
  795. X        s.on = 0;
  796. X
  797. X    switch (s.type) {
  798. X
  799. X        case OTYPE_VN:
  800. X        s.object.number = 1;    /* one of them */
  801. X        s.object.number2 = 1;    /* we have an assignment */
  802. X        s.on = 1;
  803. X        break;
  804. X        case STYPE_MINE:
  805. X        s.object.number = 100;    /* trigger radius */
  806. X        sprintf(buf, "Mine disarmed.\nTrigger radius set to 100.\n");
  807. X        notify(Playernum, buf);
  808. X        break;
  809. X        case OTYPE_TRANSDEV:
  810. X        sprintf(buf, "Receive OFF.  Change with order.\n");
  811. X        notify(Playernum, buf);
  812. X        break;
  813. X        case OTYPE_AP:
  814. X        sprintf(buf, "Processor OFF.\n");
  815. X        notify(Playernum, buf);
  816. X        break;
  817. X        case OTYPE_TOXWC:
  818. X        sprintf(buf, "Toxin concentration of the planet was %d,",
  819. X                planet->conditions[TOXIC]);
  820. X        notify(Playernum, buf);
  821. X        if (planet->conditions[TOXIC] > TOXMAX) {
  822. X            planet->conditions[TOXIC] -= TOXMAX;
  823. X            s.object.number = TOXMAX;
  824. X        } else {
  825. X            s.object.number = planet->conditions[TOXIC];
  826. X            planet->conditions[TOXIC] = 0;
  827. X        }
  828. X        sprintf(buf, " now %d.\n",planet->conditions[TOXIC]);
  829. X        notify(Playernum, buf);
  830. X        break;
  831. X        case OTYPE_STELE:
  832. X        case OTYPE_GTELE:
  833. X        sprintf(buf, "Telescope range is %.2f.\n", tele_range(s.type,s.tech));
  834. X        notify(Playernum, buf);
  835. X        break;
  836. X        default:
  837. X        break;
  838. X    }
  839. X
  840. X
  841. X        /* deduct resource cost */
  842. X
  843. X    if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP &&
  844. X            dirship->type==OTYPE_FACTORY))
  845. X        planet->info[Playernum-1].resource -= s.build_cost;
  846. X    else
  847. X        dirship->resource -= s.build_cost;
  848. X
  849. X    sprintf(buf, "Ship built at a cost of %d resources.\n", s.build_cost);
  850. X    notify(Playernum, buf);
  851. X    sprintf(buf, "Race/ship technologies %.1f/%.1f.\n", Race->tech, s.tech);
  852. X    notify(Playernum, buf);
  853. X
  854. X        /* check for dead ships in the data files */
  855. X
  856. X     /* erase any '0' entries in the dead ship file, which shouldn't be there */
  857. X    while ( (shipno = getdeadship()) == 0){ };
  858. X
  859. X    if ( shipno == -1) {
  860. X            /* otherwise recycle topmost dead ship in data file. */
  861. X            /* no dead ships to recycle */
  862. X        openshdata(&build_shdata);
  863. X        shipno = Numships(build_shdata) + 1;
  864. X        close_file(build_shdata);
  865. X    }
  866. X
  867. X    sprintf(buf, "%s #%d is %s %.0f,%.0f.\n", Shipnames[s.type], shipno,
  868. X        (Dir[Playernum-1].level==LEVEL_SHIP && dirship->type != OTYPE_FACTORY)
  869. X                 ? "at" : "on sector", s.xpos,s.ypos);
  870. X        notify(Playernum, buf);
  871. X
  872. X        /* insert ship into planet's orbit */
  873. X    if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP
  874. X        && dirship->type==OTYPE_FACTORY)) {
  875. X         /* built on planet */
  876. X         /* next ship on list */
  877. X        s.nextship = planet->ships;
  878. X        planet->ships = shipno;
  879. X        openpdata(&build_pdata);
  880. X        putplanet(build_pdata,planet,
  881. X            Stars[Dir[Playernum-1].snum]->planetpos[Dir[Playernum-1].pnum]);
  882. X        close_file(build_pdata);
  883. X
  884. X          /* write sector to disk */
  885. X        opensectdata(&build_sectdata);
  886. X           putsector(build_sectdata, sect, planet->sectormappos+
  887. X                (y*planet->Maxx+x)*sizeof(sectortype) );
  888. X         close_file(build_sectdata);
  889. X
  890. X             free(planet);
  891. X           free(sect);
  892. X
  893. X    } else {    /* was built on a ship -- insert after that ship */
  894. X
  895. X        s.nextship = dirship->nextship;
  896. X        dirship->nextship = shipno;
  897. X
  898. X        dirship->is_docked = 1;
  899. X        dirship->whatdest = LEVEL_SHIP;
  900. X        dirship->destshipno = shipno;
  901. X
  902. X        openshdata(&build_shdata);
  903. X        putship(build_shdata, dirship, Dir[Playernum-1].shipno);
  904. X        close_file(build_shdata);
  905. X
  906. X        }
  907. Xif(Shipdata[s.type][ABIL_DAMAGE]) {
  908. X  sprintf(buf, "Warning: This ship is constructed with a %d%% damage level.\n",
  909. X        Shipdata[s.type][ABIL_DAMAGE]);
  910. X    notify(Playernum, buf);
  911. X}
  912. X  
  913. X
  914. X    if(Shipdata[s.type][ABIL_BUILD]) {
  915. X    notify(Playernum,
  916. X           "It will need resources to make fully operational.\n");
  917. X    } else {
  918. X    notify(Playernum, "This ship does not need resources to repair.\n");
  919. X    if(s.type==OTYPE_FACTORY)
  920. X    notify(Playernum, "This factory may not begin repair until it has been activated.\n");
  921. X}
  922. X
  923. Xif(!s.max_crew)
  924. X    notify(Playernum, "This ship is robotic and may not repair itself.\n");
  925. X
  926. X
  927. Xopenshdata(&build_shdata);
  928. Xputship(build_shdata,&s,shipno);
  929. Xclose_file(build_shdata);
  930. X
  931. X    if (Dir[Playernum-1].level==LEVEL_SHIP && dirship->whatorbits==LEVEL_UNIV)
  932. X        deductAPs(Playernum, APcount, 0, 1);
  933. X    else 
  934. X        deductAPs(Playernum, APcount, Dir[Playernum-1].snum, 0);
  935. X
  936. Xif(Dir[Playernum-1].level==LEVEL_SHIP) free(dirship);
  937. X
  938. Xif(Race->autoload) {
  939. X    sprintf(buf, "Loaded with %d crew and %d fuel.\n", load_crew,load_fuel);
  940. X     notify(Playernum, buf);
  941. X    }
  942. Xfree(Race);
  943. X}
  944. X
  945. Xfloat getmass(s)
  946. Xshiptype *s;
  947. X{
  948. X return 1.0 + (float)s->armor + (float)s->size/10.0 + (float)s->guns/10.0;
  949. X}
  950. X
  951. Xint ship_size(s)
  952. Xshiptype *s;
  953. X{
  954. Xfloat size;
  955. Xsize = 0.1*s->guns + .01*s->max_crew + .03*s->max_resource + .03*s->max_fuel 
  956. X        + .03*s->max_destruct;
  957. Xreturn(MAX(1,(int)size));
  958. X}
  959. X
  960. Xfloat cost(Playernum, s, tech)
  961. Xint Playernum;
  962. Xshiptype *s;
  963. Xfloat tech;
  964. X{
  965. Xint i;
  966. Xfloat advantage, disadvantage, factor, techfactor;
  967. X
  968. Xi=s->build_type;
  969. X/* compute how much it costs to build this ship */
  970. X
  971. Xtechfactor = (1.0 + tech/((float)Shipdata[i][ABIL_TECH] + 1.0));
  972. Xadvantage = 0.;
  973. Xdisadvantage = 0.;
  974. X
  975. X/* armor */
  976. Xif((float)s->armor > techfactor*((float)Shipdata[i][ABIL_ARMOR]+1.0)) {
  977. X    s->armor = (int)(techfactor*((float)Shipdata[i][ABIL_ARMOR]+1.0));
  978. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  979. X        s->armor);
  980. X    notify(Playernum, buf);
  981. X}
  982. Xfactor = (((float)s->armor + 1.0)/((float)Shipdata[i][ABIL_ARMOR]+1.0)) - 1.0;
  983. Xif(factor >= 0.0)
  984. X    advantage += factor;
  985. Xelse
  986. X    disadvantage -= factor;
  987. X
  988. X/* guns */
  989. Xif((float)s->guns > techfactor*((float)Shipdata[i][ABIL_GUNS]+1.0)) {
  990. X    s->guns = (int)(techfactor*((float)Shipdata[i][ABIL_GUNS]+1.0));
  991. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  992. X        s->guns);
  993. X    notify(Playernum, buf);
  994. X}
  995. Xfactor = (((float)s->guns + 1.0)/((float)Shipdata[i][ABIL_GUNS]+1.0)) - 1.0;
  996. Xif(factor >= 0.0)
  997. X    advantage += factor;
  998. Xelse
  999. X    disadvantage -= factor;
  1000. X
  1001. X/* crew */
  1002. Xif((float)s->max_crew > techfactor*((float)Shipdata[i][ABIL_MAXCREW]+1.0)) {
  1003. X    s->max_crew = (int)(techfactor*((float)Shipdata[i][ABIL_MAXCREW]+1.0));
  1004. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  1005. X        s->max_crew);
  1006. X    notify(Playernum, buf);
  1007. X}
  1008. Xfactor = (((float)s->max_crew + 1.0)/((float)Shipdata[i][ABIL_MAXCREW]+1.0)) - 1.0;
  1009. Xif(factor >= 0.0)
  1010. X    advantage += factor;
  1011. Xelse
  1012. X    disadvantage -= factor;
  1013. X
  1014. X/* cargo capacity */
  1015. Xif((float)s->max_resource > techfactor*((float)Shipdata[i][ABIL_CARGO]+1.0)) {
  1016. X    s->max_resource = (int)(techfactor*((float)Shipdata[i][ABIL_CARGO]+1.0));
  1017. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  1018. X        s->max_resource);
  1019. X    notify(Playernum, buf);
  1020. X}
  1021. Xfactor = (((float)s->max_resource + 1.0)/((float)Shipdata[i][ABIL_CARGO]+1.0)) - 1.0;
  1022. Xif(factor >= 0.0)
  1023. X    advantage += factor;
  1024. Xelse
  1025. X    disadvantage -= factor;
  1026. X
  1027. X/* fuel capacity */
  1028. Xif((float)s->max_fuel > techfactor*((float)Shipdata[i][ABIL_FUELCAP]+1.0)) {
  1029. X    s->max_fuel = (int)(techfactor*((float)Shipdata[i][ABIL_FUELCAP]+1.0));
  1030. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  1031. X        s->max_fuel);
  1032. X    notify(Playernum, buf);
  1033. X}
  1034. Xfactor = (((float)s->max_fuel + 1.0)/((float)Shipdata[i][ABIL_FUELCAP]+1.0)) - 1.0;
  1035. Xif(factor >= 0.0)
  1036. X    advantage += factor;
  1037. Xelse
  1038. X    disadvantage -= factor;
  1039. X
  1040. X/* destruct capacity */
  1041. Xif((float)s->max_destruct > techfactor*((float)Shipdata[i][ABIL_DESTCAP]+1.0)) {
  1042. X    s->max_destruct = (int)(techfactor*((float)Shipdata[i][ABIL_DESTCAP]+1.0));
  1043. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  1044. X        s->max_destruct);
  1045. X    notify(Playernum, buf);
  1046. X}
  1047. Xfactor = (((float)s->max_destruct + 1.0)/((float)Shipdata[i][ABIL_DESTCAP]+1.0)) - 1.0;
  1048. Xif(factor >= 0.0)
  1049. X    advantage += factor;
  1050. Xelse
  1051. X    disadvantage -= factor;
  1052. X
  1053. Xif((float)s->max_speed > techfactor*((float)Shipdata[i][ABIL_SPEED]+1.0)) {
  1054. X    s->max_speed = MIN(9, (int)(techfactor*((float)Shipdata[i][ABIL_SPEED]+1.0)));
  1055. X    sprintf(buf, "You can only modify to a max of %d - set.\n",
  1056. X        s->max_speed);
  1057. X    notify(Playernum, buf);
  1058. X}
  1059. X
  1060. Xfactor = (((float)s->max_speed + 1.0)/((float)Shipdata[i][ABIL_SPEED]+1.0)) - 1.0;
  1061. Xif(factor >= 0.0)
  1062. X    advantage += factor;
  1063. Xelse
  1064. X    disadvantage -= factor;
  1065. X
  1066. X/* hyper drive is an advantage of 1 */
  1067. Xadvantage += s->hyper_drive.has;
  1068. X/* laser is an advantage of 1 */
  1069. Xadvantage += s->laser;
  1070. X
  1071. Xfactor = (1.+advantage*(1+(s->type==STYPE_CARGO)))/(1.+disadvantage);
  1072. X
  1073. Xreturn (factor * (float)Shipdata[i][ABIL_COST]);
  1074. X
  1075. X}
  1076. X
  1077. X
  1078. X
  1079. END_OF_FILE
  1080. if test 28337 -ne `wc -c <'server/build.c'`; then
  1081.     echo shar: \"'server/build.c'\" unpacked with wrong size!
  1082. fi
  1083. # end of 'server/build.c'
  1084. if test -f 'server/fire.c' -a "${1}" != "-c" ; then 
  1085.   echo shar: Renaming existing file \"'server/fire.c'\" to \"'server/fire.c.orig'\"
  1086.   mv -f 'server/fire.c' 'server/fire.c.orig'
  1087. fi
  1088. echo shar: Extracting \"'server/fire.c'\" \(20116 characters\)
  1089. sed "s/^X//" >'server/fire.c' <<'END_OF_FILE'
  1090. X /* Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  1091. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  1092. X * Restrictions in GB_copyright.h.
  1093. X *
  1094. X * fire.c -- fire at ship or planet from ship or planet
  1095. X */
  1096. X
  1097. X#include "GB_copyright.h"
  1098. X#define EXTERN extern
  1099. X#include "vars.h"
  1100. X#include "ships.h"
  1101. X#include "races.h"
  1102. X#include "buffers.h"
  1103. X#include <signal.h>
  1104. X
  1105. Xint fire_fromshdata,fire_toshdata, fire_shdata,
  1106. X    fire_frompdata,fire_topdata,fire_sectdata;
  1107. Xchar temp[128];
  1108. X
  1109. Xfire(Playernum,APcount, argn,args)
  1110. Xint Playernum;
  1111. Xint APcount;
  1112. Xint argn;
  1113. Xchar args[MAXARGS][COMMANDSIZE];
  1114. X{
  1115. Xplacetype from,to,to2;
  1116. Xplanettype *fpl,*tpl,*tpl2;
  1117. Xsectortype *sect;
  1118. Xshiptype *ship;
  1119. Xint dam=0,dam2=0,dam3=0,condition, ok,
  1120. X    strength,oldstrength,maxstrength,tostrength,to2strength,
  1121. X    i,from_firex= -1,from_firey= -1,firex= -1,firey= -1,Numplayersretaliate=0;
  1122. Xint sh;
  1123. Xfloat dist,tech;
  1124. Xchar string[PLACENAMESIZE],buf[200];
  1125. Xchar shoot_msg[1000], retal_msg[1000];
  1126. Xboolean sameplanet = 0, fromplanetmod=0,toplanetmod=0;
  1127. Xint mask;
  1128. X
  1129. Xfire_fromshdata = fire_toshdata = fire_frompdata = fire_topdata = 
  1130. X        fire_sectdata = NEUTRAL_FD;
  1131. X
  1132. X    Num_races = Numraces();
  1133. X
  1134. X    /* for telegramming and retaliating */
  1135. X bzero( (char *)Nuked, sizeof(Nuked) );
  1136. X
  1137. X    /***** get place we are firing from *****/
  1138. X
  1139. Xsscanf(args[1],"%35s",string);
  1140. X
  1141. X from = Getplace(Playernum,string,0);
  1142. X
  1143. X if (from.err && from.level!=LEVEL_SHIP) { 
  1144. X    sprintf(buf,"usage: fire\n");
  1145. X        notify(Playernum, buf);
  1146. X    return; 
  1147. X }
  1148. X
  1149. X
  1150. X if (from.level == LEVEL_UNIV || from.level == LEVEL_STAR) {
  1151. X
  1152. X    sprintf(buf,"You can't shoot from there.\n");
  1153. X    notify(Playernum, buf);
  1154. X    return;
  1155. X } else if (from.level == LEVEL_SHIP) {
  1156. X
  1157. X    if (from.err || from.shipptr->owner != Playernum) {
  1158. X    DontOwnErr(Playernum, from.shipno);
  1159. X    free(from.shipptr);
  1160. X    return;
  1161. X    }
  1162. X
  1163. X     free(from.shipptr);        
  1164. X     openshdata(&fire_fromshdata);
  1165. X     (void)getship(fire_fromshdata,&(from.shipptr),from.shipno);
  1166. X    close_file(fire_fromshdata);
  1167. X   if (testship(Playernum,from.shipptr, from.shipno)) {
  1168. X    free(from.shipptr);
  1169. X    return;
  1170. X    }
  1171. X     /* check for APs */
  1172. X    if (from.shipptr->whatorbits==LEVEL_UNIV) {
  1173. X    if (!enufAP(Playernum,Sdata.AP[Playernum-1], APcount) )
  1174. X        free(from.shipptr);
  1175. X        return;
  1176. X    } else
  1177. X    if (!enufAP(Playernum,Stars[from.shipptr->storbits]->AP[Playernum-1], APcount) ) {
  1178. X            free(from.shipptr);
  1179. X            return;
  1180. X        }
  1181. X
  1182. X     /* get planet we're landed on to calculate x,y pos */
  1183. X    if (from.shipptr->is_docked && from.shipptr->whatdest==LEVEL_PLAN) {
  1184. X        openpdata(&fire_frompdata);
  1185. X        getplanet(fire_frompdata,&fpl,Stars[from.snum]->planetpos[from.pnum]);
  1186. X        close_file(fire_frompdata);
  1187. X    }
  1188. X
  1189. X } else if (from.level==LEVEL_PLAN) {
  1190. X
  1191. X   openpdata(&fire_frompdata);
  1192. X    getplanet(fire_frompdata,&fpl,Stars[from.snum]->planetpos[from.pnum]);
  1193. Xclose_file(fire_frompdata);
  1194. X   if (!enufAP(Playernum,Stars[from.snum]->AP[Playernum-1], APcount) ) { 
  1195. X    free(fpl);
  1196. X    return;
  1197. X    }
  1198. X
  1199. X   if (fpl->info[Playernum-1].destruct == 0) {
  1200. X    sprintf(buf,"No weapons available.\n");
  1201. X        notify(Playernum, buf);
  1202. X    free(fpl);
  1203. X    return;
  1204. X   }
  1205. X   if (fpl->slaved_to>0 && fpl->slaved_to!=Playernum) {
  1206. X    sprintf(buf,"That planet is enslaved!\n");
  1207. X        notify(Playernum, buf);
  1208. X    free(fpl);
  1209. X    return;
  1210. X   }
  1211. X
  1212. X } else {
  1213. X    sprintf(buf,"You can't shoot from there.\n");
  1214. X        notify(Playernum, buf);
  1215. X    return;
  1216. X }
  1217. X
  1218. X
  1219. X  /******* get target *******/
  1220. X
  1221. X sscanf(args[2],"%35s",string); 
  1222. X
  1223. X  to = Getplace(Playernum,string,1);
  1224. X if (to.err) {
  1225. X    return;
  1226. X    }
  1227. X
  1228. X if (to.level==LEVEL_SHIP) {
  1229. X
  1230. X
  1231. X
  1232. X    if (from.level==LEVEL_SHIP) {
  1233. X        if (from.shipno == to.shipno) {
  1234. X            sprintf(buf,"You can't do that.\n");
  1235. X                notify(Playernum, buf);
  1236. X            free(from.shipptr);
  1237. X            free(to.shipptr);
  1238. X            return;
  1239. X        } 
  1240. X
  1241. X    } else if (from.level==LEVEL_PLAN &&
  1242. X               !((to.shipptr->whatorbits == LEVEL_PLAN) &&
  1243. X                 (to.shipptr->pnumorbits == from.pnum))) { 
  1244. X          /* planets can only fire at orbiting ships*/
  1245. X                sprintf(buf,"Planets can only fire at ships in orbit.\n");
  1246. X                notify(Playernum, buf);
  1247. X            free(fpl);
  1248. X            free(to.shipptr);
  1249. X            return;
  1250. X              }
  1251. X
  1252. X        /* get ship again */
  1253. X    free(to.shipptr);
  1254. X    openshdata(&fire_toshdata);
  1255. X    (void)getship(fire_toshdata, &(to.shipptr), to.shipno);
  1256. X    close_file(fire_toshdata);
  1257. X    if (!to.shipptr->is_alive) {
  1258. X        sprintf(buf,"that ship has already been destroyed.\n");
  1259. X        notify(Playernum, buf);
  1260. X        free(to.shipptr);
  1261. X        if(from.level==LEVEL_PLAN) free(fpl);
  1262. X        else if(from.level==LEVEL_SHIP) free(from.shipptr);
  1263. X        return;
  1264. X    }
  1265. X
  1266. X/* save defense attack strength for retaliation */
  1267. X  tostrength = MIN(to.shipptr->destruct,   
  1268. X        Retaliate(to.shipptr) *
  1269. X           .0001*(100-to.shipptr->rad)*(100-to.shipptr->damage));
  1270. X
  1271. X    if ((to.shipptr->is_docked && to.shipptr->whatdest==LEVEL_PLAN)
  1272. X        || to.shipptr->whatorbits==LEVEL_PLAN) {
  1273. X        openpdata(&fire_topdata);
  1274. X        getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
  1275. X        close_file(fire_topdata);
  1276. X    }
  1277. X
  1278. X } else if (to.level==LEVEL_PLAN) {
  1279. X
  1280. X    if (from.level==LEVEL_PLAN) {
  1281. X        if (from.snum == to.snum && from.pnum==to.pnum) {
  1282. X                /* same planet as firing one */
  1283. X                   /* disable the firing from planet to planet */
  1284. X              sprintf(buf,"You cannot fire from a planet to a planet !\n");
  1285. X            notify(Playernum, buf);
  1286. X           free(fpl);
  1287. X           free(tpl);
  1288. X           return;
  1289. X        }
  1290. X    }
  1291. X
  1292. X    if (!sameplanet) {
  1293. X        openpdata(&fire_topdata);
  1294. X        getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
  1295. X        close(fire_topdata);
  1296. X        }
  1297. X } else {
  1298. X    notify(Playernum, "You can't shoot at that.\n");
  1299. X    return;
  1300. X }
  1301. X
  1302. X
  1303. X
  1304. Xif(argn < 4 && from.level==LEVEL_SHIP && to.level==LEVEL_SHIP) {
  1305. X    if(from.shipptr->laser && from.shipptr->fire_laser)
  1306. X        strength = from.shipptr->fire_laser;
  1307. X    else
  1308. X        strength = from.shipptr->retaliate;
  1309. X} else
  1310. X    sscanf(args[3],"%d",&strength);
  1311. X
  1312. X    if(from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser)
  1313. X          maxstrength = MIN(from.shipptr->fuel, from.shipptr->max_fuel)/2;
  1314. X    else
  1315. X          maxstrength = (from.level==LEVEL_SHIP) ? 
  1316. X            MIN(from.shipptr->destruct,   Guns(from.shipptr) *
  1317. X            .0001 * (100-from.shipptr->rad)*(100-from.shipptr->damage))
  1318. X          : MIN(fpl->info[Playernum-1].destruct, PLAN_FIRE_LIM);
  1319. X
  1320. X if (strength>maxstrength) {
  1321. X        strength = maxstrength;
  1322. X        sprintf(buf,"%s set to %d\n", 
  1323. X            (from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser) ?
  1324. X                "Laser strength" : "Guns", strength);
  1325. X        notify(Playernum, buf);
  1326. X }
  1327. X/* check to see if there is crystal overload */
  1328. X if (from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser) {
  1329. X        if(int_rand(0,strength) >=(int)from.shipptr->tech/2) {        /* check to see if the ship blows up */
  1330. X            notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!\n");
  1331. X            notify(Playernum, "Ship DESTROYED!!!\n");
  1332. X            kill_ship(from.shipptr->owner, from.shipptr);
  1333. X            openshdata(&fire_toshdata);
  1334. X              putship(fire_toshdata,from.shipptr,from.shipno); 
  1335. X              close_file(fire_toshdata);
  1336. X            strength = 0;
  1337. X        } else if(int_rand(0,strength) >= (int)from.shipptr->tech/4) {
  1338. X            notify(Playernum, "Crystal damaged from overloading.\n");
  1339. X            from.shipptr->fire_laser = 0;
  1340. X            from.shipptr->hyper_drive.mounted = 0;
  1341. X            openshdata(&fire_toshdata);
  1342. X              putship(fire_toshdata,from.shipptr,from.shipno); 
  1343. X              close_file(fire_toshdata);
  1344. X            strength = 0;
  1345. X        }
  1346. X}
  1347. X
  1348. X if (strength<=0) {
  1349. X       sprintf(buf,"no attack.\n");
  1350. X        notify(Playernum, buf);
  1351. X    if(from.level==LEVEL_PLAN) free(fpl);
  1352. X    else if(from.level==LEVEL_SHIP) free(from.shipptr);
  1353. X
  1354. X    if(to.level==LEVEL_PLAN) free(tpl);
  1355. X    else if(to.level==LEVEL_SHIP) free(to.shipptr);
  1356. X
  1357. X    return;
  1358. X }
  1359. X
  1360. X
  1361. X     /* get a sector the enemy place can retaliate to. */
  1362. X
  1363. X    if(from.level==LEVEL_PLAN) {
  1364. X
  1365. X    sscanf(args[4],"%d,%d",&from_firex,&from_firey);
  1366. X
  1367. X    if((from_firex < 0) || (from_firey < 0) || (from_firex > fpl->Maxx) || (from_firey > fpl->Maxy)) {
  1368. X        sprintf(buf,"Illegal coordinates.\n");
  1369. X            notify(Playernum, buf);
  1370. X        free(fpl);
  1371. X        if(to.level==LEVEL_PLAN) free(tpl);
  1372. X        else if(to.level==LEVEL_SHIP) free(to.shipptr);
  1373. X        return;
  1374. X    } else {
  1375. X    opensectdata(&fire_sectdata);
  1376. X    getsector(fire_sectdata, §, fpl->sectormappos+(from_firey*fpl->Maxx+from_firex)*sizeof(sectortype));
  1377. X    close_file(fire_sectdata);
  1378. X    }
  1379. X
  1380. X      if (sect->owner!=Playernum) {    /* has to be yours */
  1381. X       sprintf(buf,"You don't own that sector.\n");
  1382. X        notify(Playernum, buf);
  1383. X       free(fpl);
  1384. X    if(to.level==LEVEL_PLAN) free(tpl);
  1385. X    else if(to.level==LEVEL_SHIP) free(to.shipptr);
  1386. X    free(sect);
  1387. X        return;
  1388. X        }
  1389. X    free(sect);
  1390. X        } else if(to.level==LEVEL_PLAN) {
  1391. X    sscanf(args[4],"%d,%d",&firex,&firey);
  1392. X
  1393. X    if((firex < 0) || (firey < 0) || (firex > tpl->Maxx) || (firey > tpl->Maxy)) {
  1394. X        sprintf(buf,"Illegal coordinates.\n");
  1395. X            notify(Playernum, buf);
  1396. X    if(from.level==LEVEL_PLAN) free(fpl);
  1397. X    else if(from.level==LEVEL_SHIP) free(from.shipptr);
  1398. X    free(tpl);
  1399. X            return;
  1400. X        }
  1401. X/* check to see if there are any planetary defense networks on the planet */
  1402. Xok = 1;
  1403. X    sh = tpl->ships;
  1404. X    openshdata(&fire_toshdata);
  1405. X    while(sh && ok) {
  1406. X        getship(fire_toshdata, &ship, sh);
  1407. X    ok = !(ship->is_alive && ship->type==OTYPE_PLANDEF
  1408. X           && ship->owner != Playernum);
  1409. X    sh = ship->nextship;
  1410. X    free(ship);
  1411. X    }
  1412. X    close_file(fire_toshdata);
  1413. Xif(!ok) {
  1414. Xnotify(Playernum, "Target has planetary defense networks.\nThese have to be eliminated before you can attack sectors.\n");    
  1415. X    if(fpl) free(fpl);
  1416. X    if(tpl) free(tpl);
  1417. X    if(from.shipptr) free(from.shipptr);
  1418. X    if(to.shipptr) free(to.shipptr);
  1419. Xreturn;
  1420. X}
  1421. X
  1422. X    }
  1423. X
  1424. Xtech = 0.0;
  1425. Xif(from.level == LEVEL_SHIP)
  1426. X        tech = from.shipptr->tech;
  1427. Xelse if (from.level == LEVEL_PLAN)
  1428. X        tech = 100.0;    
  1429. X
  1430. X    /* block kill signals to foil cheaters */
  1431. X
  1432. X dam = shoot(Playernum, from, &to, Playernum, fpl, tpl, firex, firey, strength,
  1433. X         &dist, tech, shoot_msg,1 );    /*1==get smap*/
  1434. X
  1435. X
  1436. X if (dam < 0) {
  1437. X    sprintf(buf,"Target out of range  %.2f!\n", SYSTEMSIZE);
  1438. X        notify(Playernum, buf);
  1439. X    if(from.level==LEVEL_SHIP) free(from.shipptr);
  1440. X    else if(from.level==LEVEL_PLAN) free(fpl);
  1441. X
  1442. X    if(to.level==LEVEL_SHIP) free(to.shipptr);
  1443. X    else if(to.level==LEVEL_PLAN) free(tpl);
  1444. X
  1445. X    return;
  1446. X } 
  1447. X
  1448. X
  1449. Xif(from.level==LEVEL_SHIP)
  1450. X    sprintf(telegram_buf,"%s #%u %s [%u] ",Shipnames[from.shipptr->type],
  1451. X            from.shipno,from.shipptr->name,from.shipptr->owner);
  1452. Xelse if(from.level==LEVEL_PLAN)
  1453. X    sprintf(telegram_buf,"%s ", Dispplace(Playernum, &from));
  1454. X
  1455. Xsprintf(temp, telegram_buf);
  1456. X
  1457. X if (to.level==LEVEL_SHIP)
  1458. X    sprintf(buf,"fired on %s #%u %s [%u] @ %s;\n", Shipnames[to.shipptr->type],
  1459. X            to.shipno, to.shipptr->name, to.shipptr->owner,
  1460. X            prin_ship_orbits(to.shipptr));
  1461. X else
  1462. X    sprintf(buf,"fired on %s\n",Dispplace(Playernum, &to));
  1463. X
  1464. X    
  1465. X/* notify all players that inhabit this system of the attack */
  1466. X    str_cat(temp, buf);
  1467. X    str_cat(telegram_buf, buf);
  1468. X
  1469. X for (i=1; i<=Num_races; i++) {
  1470. X    if (Nuked[i-1] && i!=Playernum) {
  1471. X    notify(i, telegram_buf);
  1472. X    } else
  1473. X    if (i!=Playernum && isset(Stars[Dir[Playernum-1].snum]->inhabited, i))
  1474. X    notify(i, temp);
  1475. X
  1476. X    push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT);
  1477. X}
  1478. X
  1479. X  sprintf(buf,"BOOM!!\n%s\n", shoot_msg);
  1480. X    notify(Playernum, buf);
  1481. X
  1482. X    str_cat(telegram_buf, buf);
  1483. X
  1484. X for (i=1; i<=Num_races; i++)
  1485. X    if (Nuked[i-1] && i!=Playernum) {
  1486. X    if(!notify(i, telegram_buf))
  1487. X        push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT);
  1488. X    }
  1489. X
  1490. X if (from.level==LEVEL_SHIP) {
  1491. X    if(from.shipptr->laser && from.shipptr->fire_laser) {
  1492. X        from.shipptr-> fuel -= 2*strength;
  1493. X        from.shipptr->mass -= 2*strength*MASS_FUEL;
  1494. X    } else {
  1495. X        from.shipptr->destruct -= strength;
  1496. X        from.shipptr->mass -= strength*MASS_DESTRUCT;
  1497. X    }
  1498. X } else if (from.level==LEVEL_PLAN) 
  1499. X    fpl->info[Playernum-1].destruct -= strength;
  1500. X
  1501. X
  1502. X/* defending player retaliates if he can */
  1503. X    strength = 0;
  1504. X if ( to.level==LEVEL_SHIP && dam && to.shipptr->active
  1505. X        && to.shipptr->protect.self) {
  1506. X    strength = tostrength;
  1507. X    if(to.shipptr->laser && to.shipptr->fire_laser) {
  1508. X
  1509. X/* check to see if there is crystal overload */
  1510. X        if(int_rand(0,strength) >=(int)to.shipptr->tech/2) {        /* check to see if the ship blows up */
  1511. X            notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!");
  1512. X            notify(Playernum, "Defending ship DESTROYED!");
  1513. X            notify(to.shipptr->owner, "Matter-antimatter explosion from overloaded crystal!!!");
  1514. X            notify(to.shipptr->owner, "Defending ship DESTROYED!");
  1515. X            kill_ship(to.shipptr->owner, to.shipptr);
  1516. X            openshdata(&fire_toshdata);
  1517. X              putship(fire_toshdata,to.shipptr,to.shipno); 
  1518. X              close_file(fire_toshdata);
  1519. X            strength = 0;
  1520. X        } else if(int_rand(0,strength) >=(int)to.shipptr->tech/4) {
  1521. X            notify(to.shipptr->owner, "Crystal damaged from overloading.\n");
  1522. X            to.shipptr->fire_laser = 0;
  1523. X            to.shipptr->hyper_drive.mounted = 0;
  1524. X            openshdata(&fire_toshdata);
  1525. X              putship(fire_toshdata,to.shipptr,to.shipno); 
  1526. X              close_file(fire_toshdata);
  1527. X            strength = 0;
  1528. X        }
  1529. X
  1530. X        to.shipptr-> fuel -= 2*strength;
  1531. X        to.shipptr->mass -= 2*strength*MASS_FUEL;
  1532. X    } else {
  1533. X        to.shipptr->destruct -= strength;
  1534. X        to.shipptr->mass -= strength*MASS_DESTRUCT;
  1535. X    }
  1536. X
  1537. X } else if (to.level==LEVEL_PLAN) {    
  1538. X/* all players owning planet retal. do not retaliate at long distances
  1539. X    since it is 'unrealistic' and easy to drain defences */
  1540. X
  1541. X int strength2;
  1542. X int fstrength;
  1543. X fstrength = strength;
  1544. X
  1545. X strength = 0;
  1546. X      for (i=1; i<= Num_races; i++)
  1547. X       if (i!=Playernum && tpl->info[i-1].numsectsowned &&
  1548. X        !(tpl->slaved_to>0 && tpl->slaved_to!=i) ) {
  1549. X
  1550. X              /* add planet defense strength */
  1551. X
  1552. X         strength2 = tpl->info[i-1].destruct;
  1553. X            if(strength2 > PLAN_FIRE_LIM)
  1554. X          strength2 = PLAN_FIRE_LIM;
  1555. X
  1556. X         tpl->info[i-1].destruct -= strength2;
  1557. X
  1558. X             strength += strength2;
  1559. X         Numplayersretaliate++;
  1560. X         if(strength2)
  1561. X           {
  1562. X  sprintf(telegram_buf," BULLETIN from %s\n\n",Dispplace(Playernum, &to));
  1563. X  sprintf(buf,"Planet returns fire with %d guns\n\n", strength2);
  1564. X        notify(Playernum, buf);
  1565. X        str_cat(telegram_buf, buf);
  1566. X           }
  1567. X       }
  1568. X}
  1569. X    dam2=0;
  1570. X
  1571. Xif (strength) {
  1572. X       sprintf(buf,"%s retaliates with %s%d guns!!\n", Dispplace(Playernum, &to), 
  1573. X        Numplayersretaliate>1 ? "a total of " : "", strength,
  1574. X        (to.level==LEVEL_SHIP && to.shipptr->laser && to.shipptr->fire_laser) ?
  1575. X        "combat laser strength" : "guns");
  1576. X        notify(Playernum, buf);
  1577. X        str_cat(telegram_buf, buf);
  1578. X } else {
  1579. X   sprintf(buf,"%s %s does not retaliate (%d %d).\n",Dispplace(Playernum, &to),
  1580. X    (to.level==LEVEL_PLAN) ? (tpl->slaved_to ? "is enslaved and " : "") : ""
  1581. X    ,dam, tostrength);
  1582. X    notify(Playernum, buf);
  1583. X    str_cat(telegram_buf, buf); 
  1584. X}
  1585. X
  1586. X
  1587. X     if(strength)
  1588. X    {
  1589. X        tech = 0.0;
  1590. X        if(to.level == LEVEL_SHIP)
  1591. X            tech = to.shipptr->tech;
  1592. X        else if (to.level == LEVEL_PLAN)
  1593. X            tech = 100.0;    
  1594. X
  1595. X
  1596. X        dam2 = shoot(Playernum, to,&from, 
  1597. X             (to.level==LEVEL_SHIP ? to.shipptr->owner : 1),
  1598. X             tpl,fpl,from_firex,from_firey,strength,
  1599. X             &dist, tech,retal_msg, 1);
  1600. X
  1601. X                if(dam2) {
  1602. X                  sprintf(buf,"BOOM!!\n%s\n", retal_msg);
  1603. X            notify(Playernum, buf);
  1604. X        str_cat(telegram_buf, buf);
  1605. X        }
  1606. X
  1607. X for (i=1; i<=Num_races; i++)
  1608. X    if (Nuked[i-1] && i!=Playernum)
  1609. X    if(!notify(i, telegram_buf))
  1610. X        push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT);
  1611. X
  1612. X    }
  1613. X
  1614. X
  1615. X/* protecting ships retaliate individually, only if damage was inflicted */
  1616. X        if( from.level==LEVEL_SHIP && dam)
  1617. X            {
  1618. X
  1619. X    sh = 0;
  1620. X        if(to.level==LEVEL_SHIP) {
  1621. X    if(to.shipptr->whatorbits==LEVEL_STAR) /* star level ships */
  1622. X        sh = Stars[to.shipptr->storbits]->ships;
  1623. X    if(to.shipptr->whatorbits==LEVEL_PLAN) /* planet level ships */
  1624. X        {
  1625. X        openpdata(&fire_frompdata);
  1626. X        getplanet(fire_frompdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
  1627. X        close_file(fire_frompdata);
  1628. X        sh = tpl->ships;
  1629. X        }
  1630. X    } else if(to.level==LEVEL_PLAN) {
  1631. X        sh = tpl->ships;
  1632. X                    }
  1633. X
  1634. X    while (sh && from.shipptr->is_alive) 
  1635. X            {
  1636. X    
  1637. X    sprintf(string,"#%d",sh);
  1638. X
  1639. X     to2 = Getplace(Playernum,string,1);
  1640. X
  1641. X    if(sh != from.shipno && sh != to.shipno)
  1642. X    {
  1643. X
  1644. X    condition = 0;
  1645. X    if(to.level==LEVEL_SHIP)
  1646. X        condition = (to2.shipptr->is_alive && to2.shipptr->active
  1647. X                && to2.shipptr->protect.on
  1648. X                && (to2.shipptr->protect.ship == to.shipno)) ;
  1649. X     else if (to.level==LEVEL_PLAN)
  1650. X        condition = (to2.shipptr->is_alive && to2.shipptr->active
  1651. X                && to2.shipptr->protect.planet
  1652. X                && (from.shipptr->owner != to2.shipptr->owner));
  1653. X                
  1654. X    if(condition) {
  1655. X    if(to2.level==LEVEL_SHIP && to2.shipptr->laser && to2.shipptr->fire_laser) {
  1656. X        to2strength = MIN((int)to2.shipptr->fuel/2, to2.shipptr->fire_laser);
  1657. X        to2.shipptr->fuel -= 2*to2strength;
  1658. X        to2.shipptr->mass -= 2*to2strength*MASS_FUEL;
  1659. X
  1660. X/* check to see if there is crystal overload */
  1661. X        if(int_rand(0,to2strength) >=(int)to2.shipptr->tech/2) {        /* check to see if the ship blows up */
  1662. X            notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!");
  1663. X            notify(Playernum, "Protecting ship DESTROYED!");
  1664. X            notify(to2.shipptr->owner, "Matter-antimatter explosion from overloaded crystal!!!");
  1665. X            notify(to2.shipptr->owner, "Protecting ship DESTROYED!");
  1666. X            kill_ship(to2.shipptr->owner, to2.shipptr);
  1667. X            to2strength = 0;
  1668. X        } else if(int_rand(0,to2strength) >= (int)to2.shipptr->tech/4) {
  1669. X            notify(to2.shipptr->owner, "Crystal damaged from overloading.\n");
  1670. X            to2.shipptr->fire_laser = 0;
  1671. X            to2.shipptr->hyper_drive.mounted = 0;
  1672. X            to2strength = 0;
  1673. X        }
  1674. X
  1675. X    } else {
  1676. X          to2strength = MIN(to2.shipptr->destruct,   
  1677. X            Retaliate(to2.shipptr) *
  1678. X           .0001 * (100-to2.shipptr->damage) * (100-to2.shipptr->rad));
  1679. X        to2.shipptr->destruct -= to2strength;
  1680. X        to2.shipptr->mass -= strength*MASS_DESTRUCT;
  1681. X    }
  1682. Xif (to2strength) {
  1683. X   sprintf(telegram_buf,"%s retaliates with  %s%d %s!!\n", Dispplace(Playernum, &to2), 
  1684. X        Numplayersretaliate>1 ? "a total of " : "", to2strength, 
  1685. X        (to2.level==LEVEL_SHIP && to2.shipptr->laser && to2.shipptr->fire_laser) ?
  1686. X        "combat laser strength" : "guns");
  1687. X    notify(Playernum, buf);
  1688. X    str_cat(telegram_buf, buf);
  1689. X
  1690. X    tech = to2.shipptr->tech;
  1691. X
  1692. X    dam3 = shoot(Playernum, to2,&from,to2.shipptr->owner,tpl,fpl,from_firex,from_firey,to2strength, 
  1693. X           &dist, tech,retal_msg, 1);
  1694. X        if(dam3) {
  1695. X        sprintf(buf,"BOOM!!\n%s\n", retal_msg);
  1696. X        notify(Playernum, buf);
  1697. X        str_cat(telegram_buf, buf);
  1698. X        }
  1699. X  if(!notify(to2.shipptr->owner, telegram_buf))
  1700. X      push_message(TELEG_PLAYER_AUTO, to2.shipptr->owner, telegram_buf, COMBAT);
  1701. X
  1702. X    }
  1703. X  
  1704. X    openshdata(&fire_toshdata);
  1705. X      putship(fire_toshdata,to2.shipptr,to2.shipno); 
  1706. X      close_file(fire_toshdata);
  1707. X}
  1708. X
  1709. X        }
  1710. X        sh = to2.shipptr->nextship;
  1711. X            free(to2.shipptr);
  1712. X    }
  1713. X    }
  1714. X
  1715. X
  1716. X/* end of fire/retaliation */
  1717. X
  1718. X if (from.level==LEVEL_PLAN) {
  1719. X     openpdata(&fire_frompdata);
  1720. X     putplanet(fire_frompdata,fpl,Stars[from.snum]->planetpos[from.pnum]);
  1721. X    close_file(fire_frompdata);
  1722. X
  1723. X } else if (from.level==LEVEL_SHIP) {
  1724. X     openshdata(&fire_fromshdata);
  1725. X     putship(fire_fromshdata, from.shipptr, from.shipno);
  1726. X    close_file(fire_fromshdata);
  1727. X }
  1728. X
  1729. X
  1730. X if (to.level==LEVEL_PLAN && !sameplanet) {
  1731. X     openpdata(&fire_topdata);
  1732. X     putplanet(fire_topdata,tpl,Stars[to.snum]->planetpos[to.pnum]);
  1733. X    close_file(fire_topdata);
  1734. X     free(tpl);
  1735. X } else if (to.level==LEVEL_SHIP) {
  1736. X     openshdata(&fire_toshdata);
  1737. X     putship(fire_toshdata,to.shipptr,to.shipno);
  1738. X    close_file(fire_toshdata);
  1739. X     free(to.shipptr);
  1740. X }
  1741. X
  1742. X
  1743. X
  1744. X
  1745. X
  1746. X if (from.level==LEVEL_PLAN) {
  1747. X   /* firing from planet -- deduct APs from that star */
  1748. X     deductAPs(Playernum,APcount, from.snum, 0);
  1749. X    free(fpl);
  1750. X} else {
  1751. X        /* from.level==LEVEL_SHIP */
  1752. X    if (from.shipptr->whatorbits==LEVEL_UNIV)
  1753. X        deductAPs(Playernum,APcount, 0, 1);
  1754. X    else {
  1755. X         deductAPs(Playernum,APcount, from.shipptr->storbits, 0);
  1756. X    }
  1757. X    free(from.shipptr);
  1758. X    }
  1759. X
  1760. X}
  1761. X
  1762. Xdetonate(Playernum,APcount, argn,args)
  1763. Xint Playernum;
  1764. Xint APcount;
  1765. Xint argn;
  1766. Xchar args[MAXARGS][COMMANDSIZE];
  1767. X{
  1768. Xchar c;
  1769. Xshiptype *s;
  1770. Xplanettype *p;
  1771. Xsectortype *sect;
  1772. Xplacetype where;
  1773. Xint shipno,x= -1,y= -1,i, numdest;
  1774. Xfloat fuel;
  1775. Xdouble Dist;
  1776. Xracetype *Race, *alien;
  1777. X
  1778. X
  1779. Xsscanf(args[1]+(args[1][0]=='#'),"%d",&shipno);
  1780. X
  1781. X
  1782. X openshdata(&fire_shdata);
  1783. X  if (!getship(fire_shdata, &s, shipno)) {
  1784. X      notify(Playernum, "The ship wasn't found.\n");
  1785. X    close_file(fire_shdata);
  1786. X    return;
  1787. X  }
  1788. Xclose_file(fire_shdata);
  1789. X
  1790. X  if (testship(Playernum,s, shipno)) {
  1791. X      notify(Playernum, "Illegal format.\n");
  1792. X      free(s);
  1793. X      return;
  1794. X    }
  1795. X
  1796. Xif(s->type != STYPE_MINE) {
  1797. X    notify(Playernum, "That is not a mine.\n");
  1798. X    free(s);
  1799. X    return;
  1800. X} else if(!s->on) {
  1801. X    notify(Playernum, "The mine is not activated.\n");
  1802. X    free(s);
  1803. X    return;
  1804. X} else if(s->is_docked) {
  1805. X    notify(Playernum, "The mine is docked or landed.\n");
  1806. X    free(s);
  1807. X    return;
  1808. X}
  1809. X
  1810. X
  1811. Xfree(s);
  1812. X
  1813. Xdomine(shipno, 1);
  1814. X
  1815. X}
  1816. X
  1817. END_OF_FILE
  1818. if test 20116 -ne `wc -c <'server/fire.c'`; then
  1819.     echo shar: \"'server/fire.c'\" unpacked with wrong size!
  1820. fi
  1821. # end of 'server/fire.c'
  1822. if test -f 'server/map.c' -a "${1}" != "-c" ; then 
  1823.   echo shar: Renaming existing file \"'server/map.c'\" to \"'server/map.c.orig'\"
  1824.   mv -f 'server/map.c' 'server/map.c.orig'
  1825. fi
  1826. echo shar: Extracting \"'server/map.c'\" \(5534 characters\)
  1827. sed "s/^X//" >'server/map.c' <<'END_OF_FILE'
  1828. X/*
  1829. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  1830. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  1831. X * Restrictions in GB_copyright.h.
  1832. X *
  1833. X *  map.c -- display sector map of current planet
  1834. X */
  1835. X
  1836. X#define DISP_DATA 1
  1837. X
  1838. X#include "GB_copyright.h"
  1839. X#define EXTERN extern
  1840. X#include "vars.h"
  1841. X#include "ships.h"
  1842. X#include "races.h"
  1843. X#include <curses.h>
  1844. Xextern float compatibility();
  1845. Xchar desshow();
  1846. X
  1847. Xint map_racedata;
  1848. Xracetype *Race;
  1849. X
  1850. Xmap(Playernum,APcount, argn,args)
  1851. Xint Playernum;
  1852. Xint APcount;
  1853. Xint argn;
  1854. Xchar args[MAXARGS][COMMANDSIZE];
  1855. X{
  1856. Xregister int i;
  1857. Xint map_pdata,inv,flag;
  1858. Xplanettype *p;
  1859. Xplacetype where;
  1860. X
  1861. X   where = Getplace(Playernum, args[1],0);
  1862. X
  1863. X   if (where.err) return;
  1864. X
  1865. X   if (where.level==LEVEL_PLAN) {
  1866. X  
  1867. X      openpdata(&map_pdata);
  1868. X      getplanet(map_pdata,&p,Stars[where.snum]->planetpos[where.pnum]);
  1869. X      close_file(map_pdata);
  1870. X      show_map(Playernum, where.snum, where.pnum, p, DISP_DATA, 0);    
  1871. X                    /* 0 is begin iq*/
  1872. X
  1873. X      free(p);
  1874. X
  1875. X    if (Stars[where.snum]->stability > 50)
  1876. X        notify(Playernum, "WARNING! This planet's primary is unstable.\n");
  1877. X
  1878. X   } else {
  1879. X    orbit(Playernum, APcount, argn,args);    /* make orbit map instead */
  1880. X   }
  1881. X
  1882. X}
  1883. X
  1884. X
  1885. X
  1886. Xshow_map(Playernum, snum, pnum, p, show,iq)
  1887. Xint Playernum;
  1888. Xint snum, pnum;
  1889. Xplanettype *p;
  1890. Xint show;
  1891. Xint iq;
  1892. X{
  1893. Xreg int x,y,i,f=0,address,owner, owned1;
  1894. Xboolean cap_inv;
  1895. Xint sh,map_sectdata,map_shdata;
  1896. Xshiptype *s;
  1897. Xchar shiplocs[MAX_X][MAX_Y];
  1898. Xhugestr output;
  1899. Xchar temp[1024], buf[1024];
  1900. X
  1901. X  bzero((char *)shiplocs, sizeof(shiplocs));
  1902. X
  1903. X  opensectdata(&map_sectdata);
  1904. X  getsmap(map_sectdata, Smap, p);
  1905. X  close_file(map_sectdata);
  1906. X   /* traverse ship list on planet; find out if we can look at 
  1907. X       ships here. */
  1908. X    iq |= p->info[Playernum-1].numsectsowned;
  1909. X    sh = p->ships;
  1910. X    
  1911. X  openshdata(&map_shdata);
  1912. X        sh = p->ships;
  1913. X      while (sh) {
  1914. X        getship(map_shdata, &s, sh);
  1915. X        if(s->owner == Playernum && 
  1916. X            (s->popn || (s->type==OTYPE_PROBE))) iq = 1;
  1917. X              if (s->is_alive && s->is_docked && (s->whatdest==LEVEL_PLAN)
  1918. X            &&  (s->xpos < p->Maxx) && (s->xpos >= 0.0) &&
  1919. X            (s->ypos < p->Maxy) && (s->ypos >= 0.0) )
  1920. X          shiplocs[(int)s->xpos][(int)s->ypos] = Shipltrs[s->type];
  1921. X
  1922. X        sh = s->nextship;
  1923. X        free(s);
  1924. X      }
  1925. X
  1926. X  close_file(map_shdata);
  1927. X
  1928. X/* report that this is a planet map */
  1929. X    sprintf(output, "$");
  1930. X
  1931. X    sprintf(buf, "%s;", Stars[snum]->pnames[pnum]);    
  1932. X    str_cat(output, buf);
  1933. X
  1934. X    sprintf(buf, "%d;%d;%d;", p->Maxx, p->Maxy,show);
  1935. X    str_cat(output, buf);
  1936. X
  1937. X    openracedata(&map_racedata);
  1938. X    getrace(map_racedata, &Race, Playernum);
  1939. X    close_file(map_racedata);
  1940. X
  1941. X/* send map data */
  1942. X for(y=0; y<p->Maxy; y++)
  1943. X     for (x=0; x<p->Maxx; x++) {
  1944. X    owner = Sector(*p, x, y).owner;
  1945. X    owned1 = (owner == Race->highlight);
  1946. X    if (shiplocs[x][y] && iq) {
  1947. X
  1948. X    if(Race->color) { 
  1949. X        sprintf(buf,"%c%c", (char)(owner+48), shiplocs[x][y]);
  1950. X    } else {
  1951. X        if(owned1 && Race->inverse)
  1952. X            sprintf(buf,"1%c", shiplocs[x][y]);
  1953. X        else
  1954. X            sprintf(buf,"0%c", shiplocs[x][y]);
  1955. X        }
  1956. X
  1957. X        } else {
  1958. X
  1959. X    if(Race->color) { 
  1960. X        sprintf(buf,"%c%c", (char)(owner+48), desshow(Playernum, p, x, y, Race));
  1961. X        } else {
  1962. X        if(owned1 && Race->inverse)
  1963. X                sprintf(buf,"1%c", desshow(Playernum, p,x,y, Race));
  1964. X        else
  1965. X                sprintf(buf,"0%c", desshow(Playernum, p,x,y, Race));
  1966. X        }
  1967. X
  1968. X        }
  1969. X    str_cat(output, buf);
  1970. X     }
  1971. X
  1972. Xnotify(Playernum, output);
  1973. X
  1974. X     if (show){
  1975. X
  1976. X    sprintf(temp, "    Sects %s: %u", Race->Thing ? "covered" : "owned", 
  1977. X            p->info[Playernum-1].numsectsowned);
  1978. X    sprintf(buf, "  Aliens:");
  1979. X    str_cat(temp, buf);
  1980. X      if (p->is_explored || Race->tech >= TECH_EXPLORE) {
  1981. X            f=0;
  1982. X          for (i=1; i<MAXPLAYERS; i++)
  1983. X            if (p->info[i-1].numsectsowned && i!=Playernum) {
  1984. X               f=1;
  1985. X               sprintf(buf, "%c%d", isset(Race->atwar,i) ? '*' : ' ', i);
  1986. X                str_cat(temp, buf);
  1987. X            }
  1988. X          if (!f) str_cat(temp, "(none)");
  1989. X      } else {
  1990. X        str_cat(temp, "\?\?\?");
  1991. X    }
  1992. Xstr_cat(temp, "\n");
  1993. Xnotify(Playernum, temp);
  1994. X
  1995. X       sprintf(temp, "      Mobilization : %3d (%3d)     Compatibility: %.2f%%",
  1996. X        p->info[Playernum-1].comread,
  1997. X        p->info[Playernum-1].mob_set,
  1998. X        compatibility(p,Race));
  1999. X       if(p->conditions[TOXIC]>50) {
  2000. X           sprintf(buf,"    (%d%% TOXIC)",p->conditions[TOXIC]);
  2001. X        str_cat(temp, buf);
  2002. X        }
  2003. X
  2004. Xstr_cat(temp, "\n");
  2005. Xnotify(Playernum, temp);
  2006. X
  2007. X       sprintf(temp, "Resource stockpile : %-9u    Fuel stockpile: %u\n",
  2008. X        p->info[Playernum-1].resource,
  2009. X        p->info[Playernum-1].fuel);
  2010. Xnotify(Playernum, temp);
  2011. X
  2012. X       sprintf(temp, "      Destruct cap : %u%26s: %u (%u/%u)\n",p->info[Playernum-1].destruct,
  2013. X                Race->Thing ? "Tons of biomass" : "Total Population", 
  2014. X        p->info[Playernum-1].popn, p->popn, 
  2015. X        round_rand(.01*(100.-p->conditions[TOXIC])*p->maxpopn) );
  2016. Xnotify(Playernum, temp);
  2017. X
  2018. X            sprintf(temp, "      %d Crystals\n", p->info[Playernum-1].crystals);
  2019. X            notify(Playernum, temp);
  2020. X
  2021. X }
  2022. Xfree(Race);
  2023. X}
  2024. X
  2025. X
  2026. X
  2027. Xchar desshow(Playernum, p,x,y,r)
  2028. Xint Playernum;
  2029. Xreg planettype *p;
  2030. Xreg int x,y;
  2031. Xracetype *r;
  2032. X{
  2033. Xreg sectortype *s;
  2034. X
  2035. Xs = &Sector(*p,x,y);
  2036. X
  2037. Xif (s->VN)
  2038. X    return Shipltrs[OTYPE_VN];
  2039. X
  2040. Xif(s->owner && (!r->geography && !r->color))
  2041. X    if(!r->inverse || s->owner != r->highlight)
  2042. X        if(!r->double_digits)
  2043. X            return s->owner %10 + '0'; 
  2044. X        else {
  2045. X            if (s->owner < 10 || x % 2)
  2046. X                return s->owner % 10 + '0';
  2047. X            else
  2048. X                return s->owner / 10 + '0';
  2049. X            }
  2050. X
  2051. X   if (s->is_wasted) 
  2052. X    return CHAR_WASTELAND;
  2053. X
  2054. X    if (s->crystals)
  2055. X    return CHAR_CRYSTAL;
  2056. X
  2057. X   switch (s->des) {
  2058. X         case DES_SEA: return CHAR_SEA;
  2059. X         case DES_LAND: return CHAR_LAND;
  2060. X         case DES_MOUNT: return CHAR_MOUNT;
  2061. X         case DES_GAS: return CHAR_GAS;
  2062. X         case DES_PLATED: return CHAR_PLATED;
  2063. X         case DES_ICE: return CHAR_ICE;
  2064. X         default: return('!');
  2065. X   }
  2066. X
  2067. X
  2068. X}
  2069. X
  2070. END_OF_FILE
  2071. if test 5534 -ne `wc -c <'server/map.c'`; then
  2072.     echo shar: \"'server/map.c'\" unpacked with wrong size!
  2073. fi
  2074. # end of 'server/map.c'
  2075. echo shar: End of archive 5 \(of 9\).
  2076. cp /dev/null ark5isdone
  2077. MISSING=""
  2078. for I in 1 2 3 4 5 6 7 8 9 ; do
  2079.     if test ! -f ark${I}isdone ; then
  2080.     MISSING="${MISSING} ${I}"
  2081.     fi
  2082. done
  2083. if test "${MISSING}" = "" ; then
  2084.     echo You have unpacked all 9 archives.
  2085.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2086. else
  2087.     echo You still need to unpack the following archives:
  2088.     echo "        " ${MISSING}
  2089. fi
  2090. ##  End of shell archive.
  2091. exit 0
  2092.