billr@saab.CNA.TEK.COM (Bill Randle) (08/29/90)
Submitted-by: VANCLEEF@mps.ohio-state.edu Posting-number: Volume 11, Issue 43 Archive-name: gb3/Patch2e Patch-To: gb3: Volume 10, Issue 1-14 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 5 (of 9)." # Contents: server/build.c server/fire.c server/map.c # Wrapped by billr@saab on Tue Aug 28 08:54:56 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'server/build.c' -a "${1}" != "-c" ; then echo shar: Renaming existing file \"'server/build.c'\" to \"'server/build.c.orig'\" mv -f 'server/build.c' 'server/build.c.orig' fi echo shar: Extracting \"'server/build.c'\" \(28337 characters\) sed "s/^X//" >'server/build.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. X * Restrictions in GB_copyright.h X * build -- build a ship X */ X X#include "GB_copyright.h" X X#define EXTERN extern X#include "vars.h" X#include "ships.h" X#include "races.h" X#include "shipdata.h" X#include "buffers.h" X#include <curses.h> X#include <setjmp.h> X#include <signal.h> X Xint build_shdata,build_pdata,build_sectdata,sh_data_file, build_racedata; X Xmake_mod(Playernum, APcount, argn, args, mode) Xint Playernum; Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; Xint mode; X{ Xint i, value; Xchar shipc; Xshiptype *dirship; Xfloat getmass(), cost(); Xracetype *Race; X Xif(Dir[Playernum-1].level != LEVEL_SHIP) { X notify(Playernum, "You have to change scope to a factory to program it.\n"); X return; X} X X openshdata(&build_shdata); X if (!getship(build_shdata, &dirship, Dir[Playernum-1].shipno)) { X sprintf(buf,"Illegal dir value.\n"); X notify(Playernum, buf); X close_file(build_shdata); X return; X } X close_file(build_shdata); X if (testship(Playernum,dirship, Dir[Playernum-1].shipno)) X { X free(dirship); X return; X } Xif(dirship->type != OTYPE_FACTORY) { X notify(Playernum, "That is not a factory.\n"); X free(dirship); X return; X} X Xif(dirship->on && argn > 1) { X notify(Playernum, "This factory is already online.\n"); X free(dirship); X return; X} X Xopenracedata(&build_racedata); Xgetrace(build_racedata, &Race, Playernum); Xclose_file(build_racedata); X X Xif(mode==0) { Xif(argn<2) { /* list the current settings for the factory */ Xif(!dirship->build_type) { X notify(Playernum, "No ship type specified.\n"); X free(dirship); X free(Race); X return; X } X Xnotify(Playernum, " - Current production specs -\n"); Xsprintf(buf, " Ship type: %s\n", Shipnames[dirship->build_type]); Xnotify(Playernum, buf); Xsprintf(buf, " class: %s\n", dirship->class); Xnotify(Playernum, buf); Xsprintf(buf, " tech: %.1f\n", dirship->tech); Xnotify(Playernum, buf); Xsprintf(buf, " armor: %d\n", dirship->armor); Xnotify(Playernum, buf); Xsprintf(buf, " guns: %d\n", dirship->guns); Xnotify(Playernum, buf); Xsprintf(buf, " crew: %d\n", dirship->max_crew); Xnotify(Playernum, buf); Xsprintf(buf, " max fuel: %d\n", dirship->max_fuel); Xnotify(Playernum, buf); Xsprintf(buf, " max cargo: %d\n", dirship->max_resource); Xnotify(Playernum, buf); Xsprintf(buf, " max destruct: %d\n", dirship->max_destruct); Xnotify(Playernum, buf); Xsprintf(buf, " max speed: %d\n\n", dirship->max_speed); Xnotify(Playernum, buf); X Xif(dirship->hyper_drive.has) X notify(Playernum, " Equipped with hyperdrive.\n"); Xelse X notify(Playernum, " Not equipped with hyperdrive.\n"); X Xif(Shipdata[dirship->build_type][ABIL_LASER]) { X if(dirship->laser) X notify(Playernum, " Equipped with combat lasers.\n"); X else X notify(Playernum, " Not equipped with combat lasers.\n"); X} X Xsprintf(buf, " Cost: %dr Base Mass: %.1f \n Size: %d\n", dirship->build_cost, dirship->base_mass, X dirship->size); Xnotify(Playernum, buf); Xsprintf(buf, " Status: %s\n\n", (dirship->on ? "Online" : "Offline") ); Xnotify(Playernum, buf); X Xfree(dirship); Xfree(Race); Xreturn; X} X Xshipc = args[1][0]; X X i=0; X while ((Shipltrs[i]!=shipc) && (i<NUMSTYPES)) i++; X Xif (i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) ) { X sprintf(buf, "Illegal ship letter.\n"); X notify(Playernum, buf); X free(dirship); X free(Race); X return; X } else if (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) { X sprintf(buf,"You don't have enough technology to build one of those.\n"); X notify(Playernum, buf); X free(dirship); X free(Race); X return; X } X Xif(Shipdata[i][ABIL_BUILD] != Shipdata[OTYPE_FACTORY][ABIL_CONSTRUCT]) { X notify(Playernum, "This kind of ship does not require a factory to construct.\n"); X free(dirship); X free(Race); X return; X} X Xdirship->build_type = i; Xdirship->armor = Shipdata[i][ABIL_ARMOR]; Xdirship->guns = Shipdata[i][ABIL_GUNS]; Xdirship->max_crew = Shipdata[i][ABIL_MAXCREW]; Xdirship->max_resource = Shipdata[i][ABIL_CARGO]; Xdirship->max_fuel = Shipdata[i][ABIL_FUELCAP]; Xdirship->max_destruct = Shipdata[i][ABIL_DESTCAP]; Xdirship->max_speed = Shipdata[i][ABIL_SPEED]; Xdirship->hyper_drive.has = Shipdata[i][ABIL_JUMP]; Xdirship->laser = 0; X Xdirship->size = ship_size(dirship); X Xsprintf(dirship->class, "mod %d", Dir[Playernum-1].shipno); X Xsprintf(buf, "Factory designated to produce %ss.\n", Shipnames[i]); Xnotify(Playernum, buf); X X} else if(mode==1) { X Xif(!dirship->build_type) { X notify(Playernum, "No ship design specified. Use 'make <ship type>' first.\n"); X free(dirship); X free(Race); X return; X} X Xif(argn<2) { X notify(Playernum, "You have to specify the characteristic you wish to modify.\n"); X free(dirship); X free(Race); X return; X} X Xif(argn==3) X sscanf(args[2], "%d", &value); Xelse X value = 0; X Xif(value < 0) { X notify(Playernum, "That's a ridiculous setting.\n"); X free(dirship); X free(Race); X return; X} X Xif(Shipdata[dirship->build_type][ABIL_MOD]) { X Xif(!strncmp(args[1], "armor", strlen(args[1]))) { X dirship->armor = MIN(value, 100); X} else if(!strncmp(args[1], "guns", strlen(args[1]))) { X dirship->guns = MIN(value, 1000); X} else if(!strncmp(args[1], "crew", strlen(args[1]))) { X dirship->max_crew = MIN(value, 10000); X} else if(!strncmp(args[1], "cargo", strlen(args[1]))) { X dirship->max_resource = MIN(value, 10000); X} else if(!strncmp(args[1], "fuel", strlen(args[1]))) { X dirship->max_fuel = MIN(value, 10000); X} else if(!strncmp(args[1], "destruct", strlen(args[1]))) { X dirship->max_destruct = MIN(value, 10000); X} else if(!strncmp(args[1], "speed", strlen(args[1]))) { X dirship->max_speed = MAX(1,MIN(value, 9)); X} else if(!strncmp(args[1], "hyperdrive", strlen(args[1]))) { X if (dirship->build_type == STYPE_SHUTTLE) { X notify(Playernum, "Shuttle's can't have hyperdrive.\n"); X free(dirship); X free(Race); X return; X } else X dirship->hyper_drive.has = !dirship->hyper_drive.has; X} else if(!strncmp(args[1], "laser", strlen(args[1]))) { X if(Race->tech < TECH_LASER) { X sprintf(buf, "You need a technology level of %.1f to mount lasers.\n", TECH_LASER); X notify(Playernum, buf); X free(dirship); X free(Race); X return; X } X if(Shipdata[dirship->build_type][ABIL_LASER]) X dirship->laser = !dirship->laser; X else { X notify(Playernum, "That ship cannot be fitted with combat lasers.\n"); X free(dirship); X free(Race); X return; X } X} else { X notify(Playernum, "That characteristic either doesn't exist or can't be modified.\n"); X free(dirship); X free(Race); X return; X} X X} else { X if(!strncmp(args[1], "hyperdrive", strlen(args[1]))) { X dirship->hyper_drive.has = !dirship->hyper_drive.has; X } else { X notify(Playernum, "You may only modify hyperdrive installation on this kind of ship.\n"); X free(dirship); X free(Race); X return; X } X} X X} else { X notify(Playernum, "Weird error.\n"); X free(dirship); X free(Race); X return; X} X/* compute how much it's going to cost to build the ship */ X Xif(cost(Playernum, dirship, dirship->tech) > 65535.0) { X notify(Playernum, "Woah!! YOU CHEATER!!! The max cost allowed is 65535!!! I'm Telllllllling!!!\n"); X free(dirship); X free(Race); X return; X} X Xdirship->build_cost = (int)cost(Playernum, dirship, dirship->tech); Xsprintf(buf, "The current cost of the ship is %d resources.\n", X dirship->build_cost); Xnotify(Playernum, buf); Xdirship->size = ship_size(dirship); Xdirship->base_mass = getmass(dirship); Xsprintf(buf, "The current base mass of the ship is %.1f - size is %d.\n", X dirship->base_mass, dirship->size); X X openshdata(&build_shdata); X putship(build_shdata, dirship, Dir[Playernum-1].shipno); X close_file(build_shdata); Xfree(dirship); Xfree(Race); X X} X X Xbuild(Playernum,APcount, argn,args) Xint Playernum; Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; X{ Xint j,i,x= -1 ,y= -1 ,shipno, mask; Xint load_fuel,load_crew,picked=0,cost,sh,found; Xfloat fraction; Xchar c,shipc; Xplanettype *planet; Xsectortype *sect; Xshiptype s,*s2,*dirship; XFILE *fd; Xchar temp[128]; Xfloat getmass(); Xracetype *Race; X Xbuild_shdata = build_pdata = build_sectdata = NEUTRAL_FD; X X if (Dir[Playernum-1].level==LEVEL_PLAN && argn > 1) { X if (!enufAP(Playernum,Stars[Dir[Playernum-1].snum]->AP[Playernum-1], APcount)) { X return; X } else { X openpdata(&build_pdata); X getplanet(build_pdata,&planet, Stars[Dir[Playernum-1].snum]->planetpos[Dir[Playernum-1].pnum]); X close_file(build_pdata); X shipc = args[1][0]; X } X } else if (Dir[Playernum-1].level==LEVEL_SHIP) { X openshdata(&build_shdata); X if (!getship(build_shdata, &dirship, Dir[Playernum-1].shipno)) { X sprintf(buf,"Illegal dir value.\n"); X notify(Playernum, buf); X close_file(build_shdata); X return; X } X close_file(build_shdata); X if (testship(Playernum,dirship, Dir[Playernum-1].shipno)) X { X free(dirship); X return; X } X X if (Shipdata[dirship->type][ABIL_CONSTRUCT]==0) { X sprintf(buf,"This ship cannot be used to construct other ships.\n"); X notify(Playernum, buf); X free(dirship); X return; X } X X if(dirship->type==OTYPE_FACTORY) { X if(!dirship->on) { X notify(Playernum, "This factory is not on line.\n"); X free(dirship); X return; X } X X if(dirship->damage) { X notify(Playernum, "This factory cannot produce ships until the damage is zero.\n"); X free(dirship); X return; X } X X if(!dirship->popn) { X notify(Playernum, "This factory doesn't have any crew!\n"); X free(dirship); X return; X } X X shipc = Shipltrs[dirship->build_type]; X } else X shipc = args[1][0]; X X if (dirship->is_docked && dirship->type != OTYPE_FACTORY) { X if (dirship->whatdest==LEVEL_PLAN) X { X sprintf(buf,"This ship is landed.\n"); X notify(Playernum, buf); X } else { X sprintf(buf,"There is already a ship docked here (#%d).\n", X dirship->destshipno); X notify(Playernum, buf); X } X free(dirship); X return; X } X X /* check stars, sdata for APs */ X if (dirship->whatorbits==LEVEL_UNIV) { X if (!enufAP(Playernum,Sdata.AP[Playernum-1], APcount)) X { X free(dirship); X return; X } X } else if (dirship->whatorbits==LEVEL_STAR) { X if (!enufAP(Playernum,Stars[dirship->storbits]->AP[Playernum-1], APcount)) X { X free(dirship); X return; X } X } X X/* if we are at a factory, get the planet data too */ X if(dirship->type==OTYPE_FACTORY) { X openpdata(&build_pdata); X getplanet(build_pdata,&planet, X Stars[dirship->deststar]->planetpos[dirship->destpnum]); X close_file(build_pdata); X } X } else { X sprintf(buf,"You can't build anything here.\n"); X notify(Playernum, buf); X return; X } X Xopenracedata(&build_racedata); Xgetrace(build_racedata, &Race, Playernum); Xclose_file(build_racedata); X Xif(shipc=='?') { X if (argn==2) { X notify(Playernum, " - Default ship parameters -\n"); X sprintf(buf, "ltr ship crg arm dstcap guns fcap tech ^crew speed cost\n"); X notify(Playernum, buf); X for (i=0; i<NUMSTYPES; i++) X if (Race->tech >= Shipdata[i][ABIL_TECH] || Race->God) X if ((i==STYPE_POD && Race->Thing) || i!=STYPE_POD) X if(Shipdata[i][ABIL_PROGRAMMED]) { X sprintf(buf, " %c%18s%6d%5d%7d%5d%5d%5d%5d%6d%6d\n", X Shipltrs[i], Shipnames[i], X Shipdata[i][ABIL_CARGO], X Shipdata[i][ABIL_ARMOR], Shipdata[i][ABIL_DESTCAP], X Shipdata[i][ABIL_GUNS], Shipdata[i][ABIL_FUELCAP], X Shipdata[i][ABIL_TECH], Shipdata[i][ABIL_MAXCREW], X Shipdata[i][ABIL_SPEED], Shipdata[i][ABIL_COST] ); X notify(Playernum, buf); X } X } else { X /* description of an individual object, ala' examine */ X X i = 0; X while ((Shipltrs[i]!=args[2][0]) && (i<NUMSTYPES)) X i++; X if (i<0 || i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) X || (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) ) { X sprintf(buf, "You can't examine that ship type (yet).\n"); X notify(Playernum, buf); X } else if(!Shipdata[i][ABIL_PROGRAMMED]) { X sprintf(buf, "This type of ship has not been programmed.\n"); X notify(Playernum, buf); X } else { X if ((fd=fopen(EXAM_FL, "r"))==NULL) { X perror(EXAM_FL); X free(Race); X return; X } else { X /* look through ship data file */ X sprintf(buf, "\n"); X for (j=0; j<=i; j++) X while (fgetc(fd) != '~') ; X /* give report */ X while ((c=fgetc(fd)) != '~') { X sprintf(temp, "%c", c); X strcat(buf, temp); X } X notify(Playernum, buf); X fclose(fd) ; X } X } X } X X free(Race); X return; X } X X i=0; X while ((Shipltrs[i]!=shipc) && (i<NUMSTYPES)) i++; X Xif (i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) ) { X sprintf(buf, "Illegal ship letter.\n"); X notify(Playernum, buf); X free(planet); X free(Race); X return; X } else if (Race->tech < Shipdata[i][ABIL_TECH] && !Race->God) { X sprintf(buf,"You don't have enough technology to build one of those.\n"); X notify(Playernum, buf); X free(planet); X free(Race); X return; X } else if (!Shipdata[i][ABIL_PROGRAMMED]) { X sprintf(buf, "That ship type has not been programmed into the game.\n"); X notify(Playernum, buf); X free(planet); X free(Race); X return; X } X X X X/* figure out if the ship can be constructed in the current scope */ Xif(Dir[Playernum-1].level==LEVEL_SHIP) { X Xif(dirship->type==OTYPE_FACTORY) X i = dirship->build_type; X X if(Shipdata[i][ABIL_BUILD] != Shipdata[dirship->type][ABIL_CONSTRUCT]) { X switch(Shipdata[dirship->type][ABIL_CONSTRUCT]) { X case 0 : X sprintf(buf, "%s cannot construct other ships.\n", X Shipnames[dirship->type]); X break; X case 1 : X sprintf(buf, "%s may only construct : or +.\n", X Shipnames[dirship->type]); X break; X case 2 : X sprintf(buf, "%s may only construct X, H, S, O, or m.\n", X Shipnames[dirship->type]); X break; X case 3: X sprintf(buf, "%s may only construct s, D, B, I, C, d, f, e, c, t, or =.\n", X Shipnames[dirship->type]); X break; X } X notify(Playernum, buf); X free(dirship); X free(Race); X return; X } X X} else if(Dir[Playernum-1].level == LEVEL_PLAN) { X if(Shipdata[i][ABIL_BUILD] > 1) { X switch(Shipdata[i][ABIL_BUILD]) { X case 2 : X sprintf(buf, "%s may only be constructed by s, c, S, H, or O.\n", X Shipnames[i]); X break; X case 3 : X sprintf(buf, "%s requires a factory to build it.\n", Shipnames[i]); X break; X default : X sprintf(buf, "Weird error in build.\n"); X break; X } X notify(Playernum, buf); X free(planet); X free(Race); X return; X } X X X X X} else { X notify(Playernum, "Illegal scope.\n"); X free(Race); X return; X } X X /* check for resource availability */ X if (Dir[Playernum-1].level==LEVEL_SHIP && X dirship->type != OTYPE_FACTORY && X dirship->resource < Shipdata[i][ABIL_COST]) { X sprintf(buf,"Not enough resources on this ship (you need %d).\n", Shipdata[i][ABIL_COST]); X notify(Playernum, buf); X free(dirship); X free(Race); X return; X X } else if(Dir[Playernum-1].level==LEVEL_SHIP && X dirship->type == OTYPE_FACTORY && X planet->info[Playernum-1].resource < dirship->build_cost) { X sprintf(buf,"Not enough resources (%d) available.\n", dirship->build_cost); X notify(Playernum, buf); X free(dirship); X free(Race); X free(planet); X return; X } X X /* find sector to build on (if planet) */ X X if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP X && dirship->type==OTYPE_FACTORY)) { X Xif(Dir[Playernum-1].level==LEVEL_PLAN) { X sscanf(args[argn-1], "%d,%d", &x, &y); X Xif(x < 0 || x > planet->Maxx-1 || y < 0 || y > planet->Maxy-1) { X notify(Playernum, "Illegal sector.\n"); X free(Race); X free(planet); X return; X} X} else { X/* get factory coordinates */ X x = (int)dirship->xpos; X y = (int)dirship->ypos; X } X X opensectdata(&build_sectdata); X getsector(build_sectdata, §, planet->sectormappos+(y*planet->Maxx+x)*sizeof(sectortype)); X close_file(build_sectdata); X X X if (Dir[Playernum-1].level==LEVEL_PLAN && X planet->info[Playernum-1].resource < Shipdata[i][ABIL_COST]) { X sprintf(buf, "not enough resources in stock (need %d).\n", X Shipdata[i][ABIL_COST]); X notify(Playernum, buf); X free(sect); X free(Race); X free(planet); X return; X } else if(Dir[Playernum-1].level==LEVEL_SHIP && X planet->info[Playernum-1].resource < dirship->build_cost) { X sprintf(buf, "Not enough resources in stock (need %d).\n", X dirship->build_cost); X notify(Playernum, buf); X free(sect); X free(dirship); X free(planet); X free(Race); X return; X } X X if (sect->owner != Playernum) { X sprintf(buf, "You don't own that sector.\n"); X notify(Playernum, buf); X if(Dir[Playernum-1].level==LEVEL_SHIP) X free(dirship); X free(Race); X free(sect); X free(planet); X return; X } X load_crew = 0; X load_fuel = 0; X if(Race->autoload && i!=OTYPE_TRANSDEV) { X if(Dir[Playernum-1].level==LEVEL_PLAN) { X load_crew = MIN(Shipdata[i][ABIL_MAXCREW], sect->popn); X load_fuel = MIN(Shipdata[i][ABIL_FUELCAP], planet->info[Playernum-1].fuel); X } else { X load_crew = MIN(dirship->max_crew, sect->popn); X load_fuel = MIN(dirship->max_fuel, planet->info[Playernum-1].fuel); X } X X sect->popn -= load_crew; X if (!sect->popn) X sect->owner = 0; X X planet->info[Playernum-1].fuel -= load_fuel; X } X X } else { X load_crew = 0; X load_fuel = 0; X if(Race->autoload && i!=OTYPE_TRANSDEV) { X load_crew = MIN(Shipdata[i][ABIL_MAXCREW], dirship->popn); X dirship->popn -= load_crew; X dirship->mass -= load_crew * Race->mass; X load_fuel = MIN(Shipdata[i][ABIL_FUELCAP], dirship->fuel); X dirship->fuel -= load_fuel; X dirship->mass -= load_fuel * MASS_FUEL; X } X } X X X Bzero(s); X X s.type = i; X if (Dir[Playernum-1].level==LEVEL_PLAN) { X s.xpos = (float)x; X s.ypos = (float)y; X } else { X s.xpos = dirship->xpos + (float)(!(dirship->type==OTYPE_FACTORY)); X s.ypos = dirship->ypos; X } X X if(Shipdata[i][ABIL_SPEED]) X s.speed = 1; X else X s.speed = 0; X X s.owner = Playernum; X Xif(Dir[Playernum-1].level==LEVEL_SHIP && dirship->type==OTYPE_FACTORY) { X s.tech = dirship->tech; X s.armor = dirship->armor; X s.guns = dirship->guns; X s.size = dirship->size; X s.max_crew = dirship->max_crew; X s.max_resource = dirship->max_resource; X s.max_destruct = dirship->max_destruct; X s.max_fuel = dirship->max_fuel; X s.max_speed = dirship->max_speed; X s.build_cost = dirship->build_cost; X s.build_type = dirship->build_type; X s.base_mass = dirship->base_mass; X s.hyper_drive.has = dirship->hyper_drive.has; X s.laser = dirship->laser; X sprintf(s.class, "%s", dirship->class); X /* docked on the planet */ X s.whatorbits = LEVEL_PLAN; X s.whatdest = LEVEL_PLAN; X s.deststar = dirship->deststar; X s.destpnum = dirship->destpnum; X s.storbits = dirship->storbits; X s.pnumorbits = dirship->pnumorbits; X X } else { X s.tech = Race->tech; X s.armor = Shipdata[i][ABIL_ARMOR]; X s.guns = Shipdata[i][ABIL_GUNS]; X s.max_crew = Shipdata[i][ABIL_MAXCREW]; X s.max_resource = Shipdata[i][ABIL_CARGO]; X s.max_destruct = Shipdata[i][ABIL_DESTCAP]; X s.max_fuel = Shipdata[i][ABIL_FUELCAP]; X s.max_speed = Shipdata[i][ABIL_SPEED]; X s.build_type = i; X s.build_cost = Shipdata[i][ABIL_COST]; X s.hyper_drive.has = Shipdata[i][ABIL_JUMP]; X s.laser = Shipdata[i][ABIL_LASER]; X s.size = ship_size(&s); X s.base_mass = getmass(&s); X s.mass = getmass(&s); X sprintf(s.class, "Standard"); X X if (Dir[Playernum-1].level==LEVEL_SHIP) { X s.whatdest = LEVEL_SHIP; X s.destshipno = Dir[Playernum-1].shipno; X s.whatorbits = dirship->whatorbits; X } else { X /* docked on the planet */ X s.whatorbits = LEVEL_PLAN; X s.whatdest = LEVEL_PLAN; X s.deststar = Dir[Playernum-1].snum; X s.destpnum = Dir[Playernum-1].pnum; X } X s.storbits = Dir[Playernum-1].snum; X s.pnumorbits = Dir[Playernum-1].pnum; X} X X s.fuel = load_fuel; X s.popn = load_crew; X s.destruct = s.resource = 0; X X s.mass = s.base_mass + load_crew*Race->mass + load_fuel*MASS_FUEL; X s.is_alive = 1; X s.active = 1; X X if(s.guns) X s.protect.self = 1; X else X s.protect.self = 0; X X s.hyper_drive.on = 0; X s.hyper_drive.ready = 0; X s.hyper_drive.charge = 0; X s.fire_laser = 0; X X s.is_docked = 1; X X s.rad = 0; X s.damage = Shipdata[s.type][ABIL_DAMAGE]; X s.retaliate = s.guns; X X s.object.number = 0; X s.object.number2 = 0; X s.object.number3 = 0; X s.object.number4 = 0; X X if (has_switch(&s)) X s.on = 0; X X switch (s.type) { X X case OTYPE_VN: X s.object.number = 1; /* one of them */ X s.object.number2 = 1; /* we have an assignment */ X s.on = 1; X break; X case STYPE_MINE: X s.object.number = 100; /* trigger radius */ X sprintf(buf, "Mine disarmed.\nTrigger radius set to 100.\n"); X notify(Playernum, buf); X break; X case OTYPE_TRANSDEV: X sprintf(buf, "Receive OFF. Change with order.\n"); X notify(Playernum, buf); X break; X case OTYPE_AP: X sprintf(buf, "Processor OFF.\n"); X notify(Playernum, buf); X break; X case OTYPE_TOXWC: X sprintf(buf, "Toxin concentration of the planet was %d,", X planet->conditions[TOXIC]); X notify(Playernum, buf); X if (planet->conditions[TOXIC] > TOXMAX) { X planet->conditions[TOXIC] -= TOXMAX; X s.object.number = TOXMAX; X } else { X s.object.number = planet->conditions[TOXIC]; X planet->conditions[TOXIC] = 0; X } X sprintf(buf, " now %d.\n",planet->conditions[TOXIC]); X notify(Playernum, buf); X break; X case OTYPE_STELE: X case OTYPE_GTELE: X sprintf(buf, "Telescope range is %.2f.\n", tele_range(s.type,s.tech)); X notify(Playernum, buf); X break; X default: X break; X } X X X /* deduct resource cost */ X X if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP && X dirship->type==OTYPE_FACTORY)) X planet->info[Playernum-1].resource -= s.build_cost; X else X dirship->resource -= s.build_cost; X X sprintf(buf, "Ship built at a cost of %d resources.\n", s.build_cost); X notify(Playernum, buf); X sprintf(buf, "Race/ship technologies %.1f/%.1f.\n", Race->tech, s.tech); X notify(Playernum, buf); X X /* check for dead ships in the data files */ X X /* erase any '0' entries in the dead ship file, which shouldn't be there */ X while ( (shipno = getdeadship()) == 0){ }; X X if ( shipno == -1) { X /* otherwise recycle topmost dead ship in data file. */ X /* no dead ships to recycle */ X openshdata(&build_shdata); X shipno = Numships(build_shdata) + 1; X close_file(build_shdata); X } X X sprintf(buf, "%s #%d is %s %.0f,%.0f.\n", Shipnames[s.type], shipno, X (Dir[Playernum-1].level==LEVEL_SHIP && dirship->type != OTYPE_FACTORY) X ? "at" : "on sector", s.xpos,s.ypos); X notify(Playernum, buf); X X /* insert ship into planet's orbit */ X if (Dir[Playernum-1].level==LEVEL_PLAN || (Dir[Playernum-1].level==LEVEL_SHIP X && dirship->type==OTYPE_FACTORY)) { X /* built on planet */ X /* next ship on list */ X s.nextship = planet->ships; X planet->ships = shipno; X openpdata(&build_pdata); X putplanet(build_pdata,planet, X Stars[Dir[Playernum-1].snum]->planetpos[Dir[Playernum-1].pnum]); X close_file(build_pdata); X X /* write sector to disk */ X opensectdata(&build_sectdata); X putsector(build_sectdata, sect, planet->sectormappos+ X (y*planet->Maxx+x)*sizeof(sectortype) ); X close_file(build_sectdata); X X free(planet); X free(sect); X X } else { /* was built on a ship -- insert after that ship */ X X s.nextship = dirship->nextship; X dirship->nextship = shipno; X X dirship->is_docked = 1; X dirship->whatdest = LEVEL_SHIP; X dirship->destshipno = shipno; X X openshdata(&build_shdata); X putship(build_shdata, dirship, Dir[Playernum-1].shipno); X close_file(build_shdata); X X } Xif(Shipdata[s.type][ABIL_DAMAGE]) { X sprintf(buf, "Warning: This ship is constructed with a %d%% damage level.\n", X Shipdata[s.type][ABIL_DAMAGE]); X notify(Playernum, buf); X} X X X if(Shipdata[s.type][ABIL_BUILD]) { X notify(Playernum, X "It will need resources to make fully operational.\n"); X } else { X notify(Playernum, "This ship does not need resources to repair.\n"); X if(s.type==OTYPE_FACTORY) X notify(Playernum, "This factory may not begin repair until it has been activated.\n"); X} X Xif(!s.max_crew) X notify(Playernum, "This ship is robotic and may not repair itself.\n"); X X Xopenshdata(&build_shdata); Xputship(build_shdata,&s,shipno); Xclose_file(build_shdata); X X if (Dir[Playernum-1].level==LEVEL_SHIP && dirship->whatorbits==LEVEL_UNIV) X deductAPs(Playernum, APcount, 0, 1); X else X deductAPs(Playernum, APcount, Dir[Playernum-1].snum, 0); X Xif(Dir[Playernum-1].level==LEVEL_SHIP) free(dirship); X Xif(Race->autoload) { X sprintf(buf, "Loaded with %d crew and %d fuel.\n", load_crew,load_fuel); X notify(Playernum, buf); X } Xfree(Race); X} X Xfloat getmass(s) Xshiptype *s; X{ X return 1.0 + (float)s->armor + (float)s->size/10.0 + (float)s->guns/10.0; X} X Xint ship_size(s) Xshiptype *s; X{ Xfloat size; Xsize = 0.1*s->guns + .01*s->max_crew + .03*s->max_resource + .03*s->max_fuel X + .03*s->max_destruct; Xreturn(MAX(1,(int)size)); X} X Xfloat cost(Playernum, s, tech) Xint Playernum; Xshiptype *s; Xfloat tech; X{ Xint i; Xfloat advantage, disadvantage, factor, techfactor; X Xi=s->build_type; X/* compute how much it costs to build this ship */ X Xtechfactor = (1.0 + tech/((float)Shipdata[i][ABIL_TECH] + 1.0)); Xadvantage = 0.; Xdisadvantage = 0.; X X/* armor */ Xif((float)s->armor > techfactor*((float)Shipdata[i][ABIL_ARMOR]+1.0)) { X s->armor = (int)(techfactor*((float)Shipdata[i][ABIL_ARMOR]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->armor); X notify(Playernum, buf); X} Xfactor = (((float)s->armor + 1.0)/((float)Shipdata[i][ABIL_ARMOR]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* guns */ Xif((float)s->guns > techfactor*((float)Shipdata[i][ABIL_GUNS]+1.0)) { X s->guns = (int)(techfactor*((float)Shipdata[i][ABIL_GUNS]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->guns); X notify(Playernum, buf); X} Xfactor = (((float)s->guns + 1.0)/((float)Shipdata[i][ABIL_GUNS]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* crew */ Xif((float)s->max_crew > techfactor*((float)Shipdata[i][ABIL_MAXCREW]+1.0)) { X s->max_crew = (int)(techfactor*((float)Shipdata[i][ABIL_MAXCREW]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->max_crew); X notify(Playernum, buf); X} Xfactor = (((float)s->max_crew + 1.0)/((float)Shipdata[i][ABIL_MAXCREW]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* cargo capacity */ Xif((float)s->max_resource > techfactor*((float)Shipdata[i][ABIL_CARGO]+1.0)) { X s->max_resource = (int)(techfactor*((float)Shipdata[i][ABIL_CARGO]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->max_resource); X notify(Playernum, buf); X} Xfactor = (((float)s->max_resource + 1.0)/((float)Shipdata[i][ABIL_CARGO]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* fuel capacity */ Xif((float)s->max_fuel > techfactor*((float)Shipdata[i][ABIL_FUELCAP]+1.0)) { X s->max_fuel = (int)(techfactor*((float)Shipdata[i][ABIL_FUELCAP]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->max_fuel); X notify(Playernum, buf); X} Xfactor = (((float)s->max_fuel + 1.0)/((float)Shipdata[i][ABIL_FUELCAP]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* destruct capacity */ Xif((float)s->max_destruct > techfactor*((float)Shipdata[i][ABIL_DESTCAP]+1.0)) { X s->max_destruct = (int)(techfactor*((float)Shipdata[i][ABIL_DESTCAP]+1.0)); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->max_destruct); X notify(Playernum, buf); X} Xfactor = (((float)s->max_destruct + 1.0)/((float)Shipdata[i][ABIL_DESTCAP]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X Xif((float)s->max_speed > techfactor*((float)Shipdata[i][ABIL_SPEED]+1.0)) { X s->max_speed = MIN(9, (int)(techfactor*((float)Shipdata[i][ABIL_SPEED]+1.0))); X sprintf(buf, "You can only modify to a max of %d - set.\n", X s->max_speed); X notify(Playernum, buf); X} X Xfactor = (((float)s->max_speed + 1.0)/((float)Shipdata[i][ABIL_SPEED]+1.0)) - 1.0; Xif(factor >= 0.0) X advantage += factor; Xelse X disadvantage -= factor; X X/* hyper drive is an advantage of 1 */ Xadvantage += s->hyper_drive.has; X/* laser is an advantage of 1 */ Xadvantage += s->laser; X Xfactor = (1.+advantage*(1+(s->type==STYPE_CARGO)))/(1.+disadvantage); X Xreturn (factor * (float)Shipdata[i][ABIL_COST]); X X} X X X END_OF_FILE if test 28337 -ne `wc -c <'server/build.c'`; then echo shar: \"'server/build.c'\" unpacked with wrong size! fi # end of 'server/build.c' if test -f 'server/fire.c' -a "${1}" != "-c" ; then echo shar: Renaming existing file \"'server/fire.c'\" to \"'server/fire.c.orig'\" mv -f 'server/fire.c' 'server/fire.c.orig' fi echo shar: Extracting \"'server/fire.c'\" \(20116 characters\) sed "s/^X//" >'server/fire.c' <<'END_OF_FILE' X /* Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. X * Restrictions in GB_copyright.h. X * X * fire.c -- fire at ship or planet from ship or planet X */ X X#include "GB_copyright.h" X#define EXTERN extern X#include "vars.h" X#include "ships.h" X#include "races.h" X#include "buffers.h" X#include <signal.h> X Xint fire_fromshdata,fire_toshdata, fire_shdata, X fire_frompdata,fire_topdata,fire_sectdata; Xchar temp[128]; X Xfire(Playernum,APcount, argn,args) Xint Playernum; Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; X{ Xplacetype from,to,to2; Xplanettype *fpl,*tpl,*tpl2; Xsectortype *sect; Xshiptype *ship; Xint dam=0,dam2=0,dam3=0,condition, ok, X strength,oldstrength,maxstrength,tostrength,to2strength, X i,from_firex= -1,from_firey= -1,firex= -1,firey= -1,Numplayersretaliate=0; Xint sh; Xfloat dist,tech; Xchar string[PLACENAMESIZE],buf[200]; Xchar shoot_msg[1000], retal_msg[1000]; Xboolean sameplanet = 0, fromplanetmod=0,toplanetmod=0; Xint mask; X Xfire_fromshdata = fire_toshdata = fire_frompdata = fire_topdata = X fire_sectdata = NEUTRAL_FD; X X Num_races = Numraces(); X X /* for telegramming and retaliating */ X bzero( (char *)Nuked, sizeof(Nuked) ); X X /***** get place we are firing from *****/ X Xsscanf(args[1],"%35s",string); X X from = Getplace(Playernum,string,0); X X if (from.err && from.level!=LEVEL_SHIP) { X sprintf(buf,"usage: fire\n"); X notify(Playernum, buf); X return; X } X X X if (from.level == LEVEL_UNIV || from.level == LEVEL_STAR) { X X sprintf(buf,"You can't shoot from there.\n"); X notify(Playernum, buf); X return; X } else if (from.level == LEVEL_SHIP) { X X if (from.err || from.shipptr->owner != Playernum) { X DontOwnErr(Playernum, from.shipno); X free(from.shipptr); X return; X } X X free(from.shipptr); X openshdata(&fire_fromshdata); X (void)getship(fire_fromshdata,&(from.shipptr),from.shipno); X close_file(fire_fromshdata); X if (testship(Playernum,from.shipptr, from.shipno)) { X free(from.shipptr); X return; X } X /* check for APs */ X if (from.shipptr->whatorbits==LEVEL_UNIV) { X if (!enufAP(Playernum,Sdata.AP[Playernum-1], APcount) ) X free(from.shipptr); X return; X } else X if (!enufAP(Playernum,Stars[from.shipptr->storbits]->AP[Playernum-1], APcount) ) { X free(from.shipptr); X return; X } X X /* get planet we're landed on to calculate x,y pos */ X if (from.shipptr->is_docked && from.shipptr->whatdest==LEVEL_PLAN) { X openpdata(&fire_frompdata); X getplanet(fire_frompdata,&fpl,Stars[from.snum]->planetpos[from.pnum]); X close_file(fire_frompdata); X } X X } else if (from.level==LEVEL_PLAN) { X X openpdata(&fire_frompdata); X getplanet(fire_frompdata,&fpl,Stars[from.snum]->planetpos[from.pnum]); Xclose_file(fire_frompdata); X if (!enufAP(Playernum,Stars[from.snum]->AP[Playernum-1], APcount) ) { X free(fpl); X return; X } X X if (fpl->info[Playernum-1].destruct == 0) { X sprintf(buf,"No weapons available.\n"); X notify(Playernum, buf); X free(fpl); X return; X } X if (fpl->slaved_to>0 && fpl->slaved_to!=Playernum) { X sprintf(buf,"That planet is enslaved!\n"); X notify(Playernum, buf); X free(fpl); X return; X } X X } else { X sprintf(buf,"You can't shoot from there.\n"); X notify(Playernum, buf); X return; X } X X X /******* get target *******/ X X sscanf(args[2],"%35s",string); X X to = Getplace(Playernum,string,1); X if (to.err) { X return; X } X X if (to.level==LEVEL_SHIP) { X X X X if (from.level==LEVEL_SHIP) { X if (from.shipno == to.shipno) { X sprintf(buf,"You can't do that.\n"); X notify(Playernum, buf); X free(from.shipptr); X free(to.shipptr); X return; X } X X } else if (from.level==LEVEL_PLAN && X !((to.shipptr->whatorbits == LEVEL_PLAN) && X (to.shipptr->pnumorbits == from.pnum))) { X /* planets can only fire at orbiting ships*/ X sprintf(buf,"Planets can only fire at ships in orbit.\n"); X notify(Playernum, buf); X free(fpl); X free(to.shipptr); X return; X } X X /* get ship again */ X free(to.shipptr); X openshdata(&fire_toshdata); X (void)getship(fire_toshdata, &(to.shipptr), to.shipno); X close_file(fire_toshdata); X if (!to.shipptr->is_alive) { X sprintf(buf,"that ship has already been destroyed.\n"); X notify(Playernum, buf); X free(to.shipptr); X if(from.level==LEVEL_PLAN) free(fpl); X else if(from.level==LEVEL_SHIP) free(from.shipptr); X return; X } X X/* save defense attack strength for retaliation */ X tostrength = MIN(to.shipptr->destruct, X Retaliate(to.shipptr) * X .0001*(100-to.shipptr->rad)*(100-to.shipptr->damage)); X X if ((to.shipptr->is_docked && to.shipptr->whatdest==LEVEL_PLAN) X || to.shipptr->whatorbits==LEVEL_PLAN) { X openpdata(&fire_topdata); X getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]); X close_file(fire_topdata); X } X X } else if (to.level==LEVEL_PLAN) { X X if (from.level==LEVEL_PLAN) { X if (from.snum == to.snum && from.pnum==to.pnum) { X /* same planet as firing one */ X /* disable the firing from planet to planet */ X sprintf(buf,"You cannot fire from a planet to a planet !\n"); X notify(Playernum, buf); X free(fpl); X free(tpl); X return; X } X } X X if (!sameplanet) { X openpdata(&fire_topdata); X getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]); X close(fire_topdata); X } X } else { X notify(Playernum, "You can't shoot at that.\n"); X return; X } X X X Xif(argn < 4 && from.level==LEVEL_SHIP && to.level==LEVEL_SHIP) { X if(from.shipptr->laser && from.shipptr->fire_laser) X strength = from.shipptr->fire_laser; X else X strength = from.shipptr->retaliate; X} else X sscanf(args[3],"%d",&strength); X X if(from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser) X maxstrength = MIN(from.shipptr->fuel, from.shipptr->max_fuel)/2; X else X maxstrength = (from.level==LEVEL_SHIP) ? X MIN(from.shipptr->destruct, Guns(from.shipptr) * X .0001 * (100-from.shipptr->rad)*(100-from.shipptr->damage)) X : MIN(fpl->info[Playernum-1].destruct, PLAN_FIRE_LIM); X X if (strength>maxstrength) { X strength = maxstrength; X sprintf(buf,"%s set to %d\n", X (from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser) ? X "Laser strength" : "Guns", strength); X notify(Playernum, buf); X } X X/* check to see if there is crystal overload */ X if (from.level==LEVEL_SHIP && from.shipptr->laser && from.shipptr->fire_laser) { X if(int_rand(0,strength) >=(int)from.shipptr->tech/2) { /* check to see if the ship blows up */ X notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!\n"); X notify(Playernum, "Ship DESTROYED!!!\n"); X kill_ship(from.shipptr->owner, from.shipptr); X openshdata(&fire_toshdata); X putship(fire_toshdata,from.shipptr,from.shipno); X close_file(fire_toshdata); X strength = 0; X } else if(int_rand(0,strength) >= (int)from.shipptr->tech/4) { X notify(Playernum, "Crystal damaged from overloading.\n"); X from.shipptr->fire_laser = 0; X from.shipptr->hyper_drive.mounted = 0; X openshdata(&fire_toshdata); X putship(fire_toshdata,from.shipptr,from.shipno); X close_file(fire_toshdata); X strength = 0; X } X} X X if (strength<=0) { X sprintf(buf,"no attack.\n"); X notify(Playernum, buf); X if(from.level==LEVEL_PLAN) free(fpl); X else if(from.level==LEVEL_SHIP) free(from.shipptr); X X if(to.level==LEVEL_PLAN) free(tpl); X else if(to.level==LEVEL_SHIP) free(to.shipptr); X X return; X } X X X /* get a sector the enemy place can retaliate to. */ X X if(from.level==LEVEL_PLAN) { X X sscanf(args[4],"%d,%d",&from_firex,&from_firey); X X if((from_firex < 0) || (from_firey < 0) || (from_firex > fpl->Maxx) || (from_firey > fpl->Maxy)) { X sprintf(buf,"Illegal coordinates.\n"); X notify(Playernum, buf); X free(fpl); X if(to.level==LEVEL_PLAN) free(tpl); X else if(to.level==LEVEL_SHIP) free(to.shipptr); X return; X } else { X opensectdata(&fire_sectdata); X getsector(fire_sectdata, §, fpl->sectormappos+(from_firey*fpl->Maxx+from_firex)*sizeof(sectortype)); X close_file(fire_sectdata); X } X X if (sect->owner!=Playernum) { /* has to be yours */ X sprintf(buf,"You don't own that sector.\n"); X notify(Playernum, buf); X free(fpl); X if(to.level==LEVEL_PLAN) free(tpl); X else if(to.level==LEVEL_SHIP) free(to.shipptr); X free(sect); X return; X } X free(sect); X } else if(to.level==LEVEL_PLAN) { X sscanf(args[4],"%d,%d",&firex,&firey); X X if((firex < 0) || (firey < 0) || (firex > tpl->Maxx) || (firey > tpl->Maxy)) { X sprintf(buf,"Illegal coordinates.\n"); X notify(Playernum, buf); X if(from.level==LEVEL_PLAN) free(fpl); X else if(from.level==LEVEL_SHIP) free(from.shipptr); X free(tpl); X return; X } X/* check to see if there are any planetary defense networks on the planet */ Xok = 1; X sh = tpl->ships; X openshdata(&fire_toshdata); X while(sh && ok) { X getship(fire_toshdata, &ship, sh); X ok = !(ship->is_alive && ship->type==OTYPE_PLANDEF X && ship->owner != Playernum); X sh = ship->nextship; X free(ship); X } X close_file(fire_toshdata); Xif(!ok) { Xnotify(Playernum, "Target has planetary defense networks.\nThese have to be eliminated before you can attack sectors.\n"); X if(fpl) free(fpl); X if(tpl) free(tpl); X if(from.shipptr) free(from.shipptr); X if(to.shipptr) free(to.shipptr); Xreturn; X} X X } X Xtech = 0.0; Xif(from.level == LEVEL_SHIP) X tech = from.shipptr->tech; Xelse if (from.level == LEVEL_PLAN) X tech = 100.0; X X /* block kill signals to foil cheaters */ X X dam = shoot(Playernum, from, &to, Playernum, fpl, tpl, firex, firey, strength, X &dist, tech, shoot_msg,1 ); /*1==get smap*/ X X X if (dam < 0) { X sprintf(buf,"Target out of range %.2f!\n", SYSTEMSIZE); X notify(Playernum, buf); X if(from.level==LEVEL_SHIP) free(from.shipptr); X else if(from.level==LEVEL_PLAN) free(fpl); X X if(to.level==LEVEL_SHIP) free(to.shipptr); X else if(to.level==LEVEL_PLAN) free(tpl); X X return; X } X X Xif(from.level==LEVEL_SHIP) X sprintf(telegram_buf,"%s #%u %s [%u] ",Shipnames[from.shipptr->type], X from.shipno,from.shipptr->name,from.shipptr->owner); Xelse if(from.level==LEVEL_PLAN) X sprintf(telegram_buf,"%s ", Dispplace(Playernum, &from)); X Xsprintf(temp, telegram_buf); X X if (to.level==LEVEL_SHIP) X sprintf(buf,"fired on %s #%u %s [%u] @ %s;\n", Shipnames[to.shipptr->type], X to.shipno, to.shipptr->name, to.shipptr->owner, X prin_ship_orbits(to.shipptr)); X else X sprintf(buf,"fired on %s\n",Dispplace(Playernum, &to)); X X X/* notify all players that inhabit this system of the attack */ X str_cat(temp, buf); X str_cat(telegram_buf, buf); X X for (i=1; i<=Num_races; i++) { X if (Nuked[i-1] && i!=Playernum) { X notify(i, telegram_buf); X } else X if (i!=Playernum && isset(Stars[Dir[Playernum-1].snum]->inhabited, i)) X notify(i, temp); X X push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT); X} X X sprintf(buf,"BOOM!!\n%s\n", shoot_msg); X notify(Playernum, buf); X X str_cat(telegram_buf, buf); X X for (i=1; i<=Num_races; i++) X if (Nuked[i-1] && i!=Playernum) { X if(!notify(i, telegram_buf)) X push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT); X } X X if (from.level==LEVEL_SHIP) { X if(from.shipptr->laser && from.shipptr->fire_laser) { X from.shipptr-> fuel -= 2*strength; X from.shipptr->mass -= 2*strength*MASS_FUEL; X } else { X from.shipptr->destruct -= strength; X from.shipptr->mass -= strength*MASS_DESTRUCT; X } X } else if (from.level==LEVEL_PLAN) X fpl->info[Playernum-1].destruct -= strength; X X X/* defending player retaliates if he can */ X strength = 0; X if ( to.level==LEVEL_SHIP && dam && to.shipptr->active X && to.shipptr->protect.self) { X strength = tostrength; X if(to.shipptr->laser && to.shipptr->fire_laser) { X X/* check to see if there is crystal overload */ X if(int_rand(0,strength) >=(int)to.shipptr->tech/2) { /* check to see if the ship blows up */ X notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!"); X notify(Playernum, "Defending ship DESTROYED!"); X notify(to.shipptr->owner, "Matter-antimatter explosion from overloaded crystal!!!"); X notify(to.shipptr->owner, "Defending ship DESTROYED!"); X kill_ship(to.shipptr->owner, to.shipptr); X openshdata(&fire_toshdata); X putship(fire_toshdata,to.shipptr,to.shipno); X close_file(fire_toshdata); X strength = 0; X } else if(int_rand(0,strength) >=(int)to.shipptr->tech/4) { X notify(to.shipptr->owner, "Crystal damaged from overloading.\n"); X to.shipptr->fire_laser = 0; X to.shipptr->hyper_drive.mounted = 0; X openshdata(&fire_toshdata); X putship(fire_toshdata,to.shipptr,to.shipno); X close_file(fire_toshdata); X strength = 0; X } X X to.shipptr-> fuel -= 2*strength; X to.shipptr->mass -= 2*strength*MASS_FUEL; X } else { X to.shipptr->destruct -= strength; X to.shipptr->mass -= strength*MASS_DESTRUCT; X } X X } else if (to.level==LEVEL_PLAN) { X/* all players owning planet retal. do not retaliate at long distances X since it is 'unrealistic' and easy to drain defences */ X X int strength2; X int fstrength; X X fstrength = strength; X X strength = 0; X X for (i=1; i<= Num_races; i++) X if (i!=Playernum && tpl->info[i-1].numsectsowned && X !(tpl->slaved_to>0 && tpl->slaved_to!=i) ) { X X /* add planet defense strength */ X X strength2 = tpl->info[i-1].destruct; X if(strength2 > PLAN_FIRE_LIM) X strength2 = PLAN_FIRE_LIM; X X tpl->info[i-1].destruct -= strength2; X X strength += strength2; X Numplayersretaliate++; X if(strength2) X { X sprintf(telegram_buf," BULLETIN from %s\n\n",Dispplace(Playernum, &to)); X X sprintf(buf,"Planet returns fire with %d guns\n\n", strength2); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X } X } X} X dam2=0; X Xif (strength) { X sprintf(buf,"%s retaliates with %s%d guns!!\n", Dispplace(Playernum, &to), X Numplayersretaliate>1 ? "a total of " : "", strength, X (to.level==LEVEL_SHIP && to.shipptr->laser && to.shipptr->fire_laser) ? X "combat laser strength" : "guns"); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X } else { X sprintf(buf,"%s %s does not retaliate (%d %d).\n",Dispplace(Playernum, &to), X (to.level==LEVEL_PLAN) ? (tpl->slaved_to ? "is enslaved and " : "") : "" X ,dam, tostrength); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X} X X X if(strength) X { X tech = 0.0; X if(to.level == LEVEL_SHIP) X tech = to.shipptr->tech; X else if (to.level == LEVEL_PLAN) X tech = 100.0; X X X dam2 = shoot(Playernum, to,&from, X (to.level==LEVEL_SHIP ? to.shipptr->owner : 1), X tpl,fpl,from_firex,from_firey,strength, X &dist, tech,retal_msg, 1); X X if(dam2) { X sprintf(buf,"BOOM!!\n%s\n", retal_msg); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X } X X for (i=1; i<=Num_races; i++) X if (Nuked[i-1] && i!=Playernum) X if(!notify(i, telegram_buf)) X push_message(TELEG_PLAYER_AUTO, i, telegram_buf, COMBAT); X X } X X X/* protecting ships retaliate individually, only if damage was inflicted */ X if( from.level==LEVEL_SHIP && dam) X { X X sh = 0; X if(to.level==LEVEL_SHIP) { X if(to.shipptr->whatorbits==LEVEL_STAR) /* star level ships */ X sh = Stars[to.shipptr->storbits]->ships; X if(to.shipptr->whatorbits==LEVEL_PLAN) /* planet level ships */ X { X openpdata(&fire_frompdata); X getplanet(fire_frompdata,&tpl,Stars[to.snum]->planetpos[to.pnum]); X close_file(fire_frompdata); X sh = tpl->ships; X } X } else if(to.level==LEVEL_PLAN) { X sh = tpl->ships; X } X X while (sh && from.shipptr->is_alive) X { X X sprintf(string,"#%d",sh); X X to2 = Getplace(Playernum,string,1); X X if(sh != from.shipno && sh != to.shipno) X { X X condition = 0; X if(to.level==LEVEL_SHIP) X condition = (to2.shipptr->is_alive && to2.shipptr->active X && to2.shipptr->protect.on X && (to2.shipptr->protect.ship == to.shipno)) ; X else if (to.level==LEVEL_PLAN) X condition = (to2.shipptr->is_alive && to2.shipptr->active X && to2.shipptr->protect.planet X && (from.shipptr->owner != to2.shipptr->owner)); X X if(condition) { X if(to2.level==LEVEL_SHIP && to2.shipptr->laser && to2.shipptr->fire_laser) { X to2strength = MIN((int)to2.shipptr->fuel/2, to2.shipptr->fire_laser); X to2.shipptr->fuel -= 2*to2strength; X to2.shipptr->mass -= 2*to2strength*MASS_FUEL; X X/* check to see if there is crystal overload */ X if(int_rand(0,to2strength) >=(int)to2.shipptr->tech/2) { /* check to see if the ship blows up */ X notify(Playernum, "Matter-antimatter explosion from overloaded crystal!!!"); X notify(Playernum, "Protecting ship DESTROYED!"); X notify(to2.shipptr->owner, "Matter-antimatter explosion from overloaded crystal!!!"); X notify(to2.shipptr->owner, "Protecting ship DESTROYED!"); X kill_ship(to2.shipptr->owner, to2.shipptr); X to2strength = 0; X } else if(int_rand(0,to2strength) >= (int)to2.shipptr->tech/4) { X notify(to2.shipptr->owner, "Crystal damaged from overloading.\n"); X to2.shipptr->fire_laser = 0; X to2.shipptr->hyper_drive.mounted = 0; X to2strength = 0; X } X X } else { X to2strength = MIN(to2.shipptr->destruct, X Retaliate(to2.shipptr) * X .0001 * (100-to2.shipptr->damage) * (100-to2.shipptr->rad)); X to2.shipptr->destruct -= to2strength; X to2.shipptr->mass -= strength*MASS_DESTRUCT; X } Xif (to2strength) { X sprintf(telegram_buf,"%s retaliates with %s%d %s!!\n", Dispplace(Playernum, &to2), X Numplayersretaliate>1 ? "a total of " : "", to2strength, X (to2.level==LEVEL_SHIP && to2.shipptr->laser && to2.shipptr->fire_laser) ? X "combat laser strength" : "guns"); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X X tech = to2.shipptr->tech; X X dam3 = shoot(Playernum, to2,&from,to2.shipptr->owner,tpl,fpl,from_firex,from_firey,to2strength, X &dist, tech,retal_msg, 1); X if(dam3) { X sprintf(buf,"BOOM!!\n%s\n", retal_msg); X notify(Playernum, buf); X str_cat(telegram_buf, buf); X } X if(!notify(to2.shipptr->owner, telegram_buf)) X push_message(TELEG_PLAYER_AUTO, to2.shipptr->owner, telegram_buf, COMBAT); X X } X X openshdata(&fire_toshdata); X putship(fire_toshdata,to2.shipptr,to2.shipno); X close_file(fire_toshdata); X} X X } X sh = to2.shipptr->nextship; X free(to2.shipptr); X } X } X X X/* end of fire/retaliation */ X X if (from.level==LEVEL_PLAN) { X openpdata(&fire_frompdata); X putplanet(fire_frompdata,fpl,Stars[from.snum]->planetpos[from.pnum]); X close_file(fire_frompdata); X X } else if (from.level==LEVEL_SHIP) { X openshdata(&fire_fromshdata); X putship(fire_fromshdata, from.shipptr, from.shipno); X close_file(fire_fromshdata); X } X X X if (to.level==LEVEL_PLAN && !sameplanet) { X openpdata(&fire_topdata); X putplanet(fire_topdata,tpl,Stars[to.snum]->planetpos[to.pnum]); X close_file(fire_topdata); X free(tpl); X } else if (to.level==LEVEL_SHIP) { X openshdata(&fire_toshdata); X putship(fire_toshdata,to.shipptr,to.shipno); X close_file(fire_toshdata); X free(to.shipptr); X } X X X X X X if (from.level==LEVEL_PLAN) { X /* firing from planet -- deduct APs from that star */ X deductAPs(Playernum,APcount, from.snum, 0); X free(fpl); X} else { X /* from.level==LEVEL_SHIP */ X if (from.shipptr->whatorbits==LEVEL_UNIV) X deductAPs(Playernum,APcount, 0, 1); X else { X deductAPs(Playernum,APcount, from.shipptr->storbits, 0); X } X free(from.shipptr); X } X X} X Xdetonate(Playernum,APcount, argn,args) Xint Playernum; Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; X{ Xchar c; Xshiptype *s; Xplanettype *p; Xsectortype *sect; Xplacetype where; Xint shipno,x= -1,y= -1,i, numdest; Xfloat fuel; Xdouble Dist; Xracetype *Race, *alien; X X Xsscanf(args[1]+(args[1][0]=='#'),"%d",&shipno); X X X openshdata(&fire_shdata); X if (!getship(fire_shdata, &s, shipno)) { X notify(Playernum, "The ship wasn't found.\n"); X close_file(fire_shdata); X return; X } Xclose_file(fire_shdata); X X if (testship(Playernum,s, shipno)) { X notify(Playernum, "Illegal format.\n"); X free(s); X return; X } X Xif(s->type != STYPE_MINE) { X notify(Playernum, "That is not a mine.\n"); X free(s); X return; X} else if(!s->on) { X notify(Playernum, "The mine is not activated.\n"); X free(s); X return; X} else if(s->is_docked) { X notify(Playernum, "The mine is docked or landed.\n"); X free(s); X return; X} X X Xfree(s); X Xdomine(shipno, 1); X X} X END_OF_FILE if test 20116 -ne `wc -c <'server/fire.c'`; then echo shar: \"'server/fire.c'\" unpacked with wrong size! fi # end of 'server/fire.c' if test -f 'server/map.c' -a "${1}" != "-c" ; then echo shar: Renaming existing file \"'server/map.c'\" to \"'server/map.c.orig'\" mv -f 'server/map.c' 'server/map.c.orig' fi echo shar: Extracting \"'server/map.c'\" \(5534 characters\) sed "s/^X//" >'server/map.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. X * Restrictions in GB_copyright.h. X * X * map.c -- display sector map of current planet X */ X X#define DISP_DATA 1 X X#include "GB_copyright.h" X#define EXTERN extern X#include "vars.h" X#include "ships.h" X#include "races.h" X#include <curses.h> Xextern float compatibility(); Xchar desshow(); X Xint map_racedata; Xracetype *Race; X Xmap(Playernum,APcount, argn,args) Xint Playernum; Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; X{ Xregister int i; Xint map_pdata,inv,flag; Xplanettype *p; Xplacetype where; X X where = Getplace(Playernum, args[1],0); X X if (where.err) return; X X if (where.level==LEVEL_PLAN) { X X openpdata(&map_pdata); X getplanet(map_pdata,&p,Stars[where.snum]->planetpos[where.pnum]); X close_file(map_pdata); X X show_map(Playernum, where.snum, where.pnum, p, DISP_DATA, 0); X /* 0 is begin iq*/ X X free(p); X X if (Stars[where.snum]->stability > 50) X notify(Playernum, "WARNING! This planet's primary is unstable.\n"); X X } else { X orbit(Playernum, APcount, argn,args); /* make orbit map instead */ X } X X} X X X Xshow_map(Playernum, snum, pnum, p, show,iq) Xint Playernum; Xint snum, pnum; Xplanettype *p; Xint show; Xint iq; X{ Xreg int x,y,i,f=0,address,owner, owned1; Xboolean cap_inv; Xint sh,map_sectdata,map_shdata; Xshiptype *s; Xchar shiplocs[MAX_X][MAX_Y]; Xhugestr output; Xchar temp[1024], buf[1024]; X X bzero((char *)shiplocs, sizeof(shiplocs)); X X opensectdata(&map_sectdata); X getsmap(map_sectdata, Smap, p); X close_file(map_sectdata); X /* traverse ship list on planet; find out if we can look at X ships here. */ X iq |= p->info[Playernum-1].numsectsowned; X sh = p->ships; X X openshdata(&map_shdata); X sh = p->ships; X while (sh) { X getship(map_shdata, &s, sh); X if(s->owner == Playernum && X (s->popn || (s->type==OTYPE_PROBE))) iq = 1; X if (s->is_alive && s->is_docked && (s->whatdest==LEVEL_PLAN) X && (s->xpos < p->Maxx) && (s->xpos >= 0.0) && X (s->ypos < p->Maxy) && (s->ypos >= 0.0) ) X shiplocs[(int)s->xpos][(int)s->ypos] = Shipltrs[s->type]; X X sh = s->nextship; X free(s); X } X X close_file(map_shdata); X X/* report that this is a planet map */ X sprintf(output, "$"); X X sprintf(buf, "%s;", Stars[snum]->pnames[pnum]); X str_cat(output, buf); X X sprintf(buf, "%d;%d;%d;", p->Maxx, p->Maxy,show); X str_cat(output, buf); X X openracedata(&map_racedata); X getrace(map_racedata, &Race, Playernum); X close_file(map_racedata); X X/* send map data */ X for(y=0; y<p->Maxy; y++) X for (x=0; x<p->Maxx; x++) { X owner = Sector(*p, x, y).owner; X owned1 = (owner == Race->highlight); X if (shiplocs[x][y] && iq) { X X if(Race->color) { X sprintf(buf,"%c%c", (char)(owner+48), shiplocs[x][y]); X } else { X if(owned1 && Race->inverse) X sprintf(buf,"1%c", shiplocs[x][y]); X else X sprintf(buf,"0%c", shiplocs[x][y]); X } X X } else { X X if(Race->color) { X sprintf(buf,"%c%c", (char)(owner+48), desshow(Playernum, p, x, y, Race)); X } else { X if(owned1 && Race->inverse) X sprintf(buf,"1%c", desshow(Playernum, p,x,y, Race)); X else X sprintf(buf,"0%c", desshow(Playernum, p,x,y, Race)); X } X X } X str_cat(output, buf); X } X Xnotify(Playernum, output); X X if (show){ X X sprintf(temp, " Sects %s: %u", Race->Thing ? "covered" : "owned", X p->info[Playernum-1].numsectsowned); X sprintf(buf, " Aliens:"); X str_cat(temp, buf); X if (p->is_explored || Race->tech >= TECH_EXPLORE) { X f=0; X for (i=1; i<MAXPLAYERS; i++) X if (p->info[i-1].numsectsowned && i!=Playernum) { X f=1; X sprintf(buf, "%c%d", isset(Race->atwar,i) ? '*' : ' ', i); X str_cat(temp, buf); X } X if (!f) str_cat(temp, "(none)"); X } else { X str_cat(temp, "\?\?\?"); X } Xstr_cat(temp, "\n"); Xnotify(Playernum, temp); X X sprintf(temp, " Mobilization : %3d (%3d) Compatibility: %.2f%%", X p->info[Playernum-1].comread, X p->info[Playernum-1].mob_set, X compatibility(p,Race)); X if(p->conditions[TOXIC]>50) { X sprintf(buf," (%d%% TOXIC)",p->conditions[TOXIC]); X str_cat(temp, buf); X } X Xstr_cat(temp, "\n"); Xnotify(Playernum, temp); X X sprintf(temp, "Resource stockpile : %-9u Fuel stockpile: %u\n", X p->info[Playernum-1].resource, X p->info[Playernum-1].fuel); Xnotify(Playernum, temp); X X sprintf(temp, " Destruct cap : %u%26s: %u (%u/%u)\n",p->info[Playernum-1].destruct, X Race->Thing ? "Tons of biomass" : "Total Population", X p->info[Playernum-1].popn, p->popn, X round_rand(.01*(100.-p->conditions[TOXIC])*p->maxpopn) ); Xnotify(Playernum, temp); X X sprintf(temp, " %d Crystals\n", p->info[Playernum-1].crystals); X notify(Playernum, temp); X X } Xfree(Race); X} X X X Xchar desshow(Playernum, p,x,y,r) Xint Playernum; Xreg planettype *p; Xreg int x,y; Xracetype *r; X{ Xreg sectortype *s; X Xs = &Sector(*p,x,y); X Xif (s->VN) X return Shipltrs[OTYPE_VN]; X Xif(s->owner && (!r->geography && !r->color)) X if(!r->inverse || s->owner != r->highlight) X if(!r->double_digits) X return s->owner %10 + '0'; X else { X if (s->owner < 10 || x % 2) X return s->owner % 10 + '0'; X else X return s->owner / 10 + '0'; X } X X if (s->is_wasted) X return CHAR_WASTELAND; X X if (s->crystals) X return CHAR_CRYSTAL; X X switch (s->des) { X case DES_SEA: return CHAR_SEA; X case DES_LAND: return CHAR_LAND; X case DES_MOUNT: return CHAR_MOUNT; X case DES_GAS: return CHAR_GAS; X case DES_PLATED: return CHAR_PLATED; X case DES_ICE: return CHAR_ICE; X default: return('!'); X } X X X} X END_OF_FILE if test 5534 -ne `wc -c <'server/map.c'`; then echo shar: \"'server/map.c'\" unpacked with wrong size! fi # end of 'server/map.c' echo shar: End of archive 5 \(of 9\). cp /dev/null ark5isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 9 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0