From decwrl!labrea!agate!bionet!ames!lll-winken!uunet!tektronix!tekgen!tekred!games Wed May 3 08:32:30 PDT 1989 Article 561 of comp.sources.games: Path: decwrl!labrea!agate!bionet!ames!lll-winken!uunet!tektronix!tekgen!tekred!games From: games@tekred.CNA.TEK.COM Newsgroups: comp.sources.games Subject: v06i052: GB - Galactic Bloodshed, an empire-like war game, Part01/07 Message-ID: <3889@tekred.CNA.TEK.COM> Date: 26 Apr 89 21:50:18 GMT Sender: billr@tekred.CNA.TEK.COM Lines: 1878 Approved: billr@saab.CNA.TEK.COM Submitted-by: Robert Chansky Posting-number: Volume 6, Issue 52 Archive-name: GB/Part01 [The author indicates that this has only been tested on 4.2bsd and 4.3bsd. Mileage may vary with other OS's. This version is apparently a single player version; a multi-player version is in the works. I compiled it, but haven't play tested it. -br] #! /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 'README' <<'END_OF_FILE' XThis is a game of interstellar exploration/conquest. It's not (of Xcourse) complete, but it's fixed up enough to post I think. XIt runs pretty good on 4.3 and 4.2, but as our versions of both here Xare a little funky, it may require some tweaking before it runs to a game Xkeeper's satisfaction. Be sure to adjust the PATH macro in the file Xfiles.h to fit your system. X XBUGS: X None serious that I know of, however there are a few things that need Xto be fixed up in the near future: X X Mines are pretty recently put in, they might have problems. X I know I should have used a linked list instead of the slots in Xthe planet/star data, but that part was written at a time when I didn't Xknow any better, I was going through psychological trauma, one of my Xkeyboard's keys stuck and I had to implement something that didn't use Xthat key, take your pick. X The stuff with "bombard" only telegrams the users that it was Xdone, but it doesn't actually do anything besides that. X It says in the docs that you can dock ships together, but you can't. Xthe best you can do is land. When this is fixed the mirrors (and some of the Xlarger ships) will not be able to be built on a planet. X Mirrors face the wrong way. X Some of the stuff with zoom doesn't work; ships sometimes get Xmisplaced. X There may be weird things doing with the Von Neumann machines Xand how they behave. X Likewise with spore pods. X Likewise with ground combat; not enough testing. X Please disregard all that stuff in the overview about berserkers (my Xdesigns with the VN's cover most of that), magic, religion, etc. XThat was all written back in my boundless youthful enthusiasm. X Ships with "*" before their names (shipdata.h) don't work as yet. Xdon't build them. X Probably shouldn't have used a square grid implementation for Xplanet maps, but I wanted the simplest thing possible for that. I'm Xthinking of adding new planet types if I can get information on their Xgeneration. Any help on this point (once you have seen the game and know how Xit is done here) would be appreciated. Ideas of mine on this point cover Xthings such as Ringworlds, Dyson spheres, space elevators, artificial Xhollow planets, the list goes on.. X X X New versions will be posted/added to/however this is done, Xwhen I have the time to write same. I've spent two years writing Xthis program, I hope it is enjoyed by everyone using it. X X Suggestions are welcome, as are bug reports, but don't expect Xreally fantastic and difficult ideas to be implemented, unless Xof course they are really fascinating.. X X X XSTARTING THE GAME: X This was done on two seperate machines, one running 4.2 and the other Xrunning a tweaked version of 4.3. edit the Makefile and delete the Xwrong one. when it's done making, try this: X Makeuniv < planet.list (wait about 20 minutes) X This will set up a fair-sized game with 30 stars and 30 planets, Xshould be good for a decent system. GB_daemon updates every 3 hours, Xwhich is kinda slow at the beginning, but once the game gets more mature, Xthings tend to pick up. This was not intended to be as intense a game as, Xsay, multi-trek or empire. I don't want anyone academically floundering Xbecause of GB. X Please send me information on trends in the game; what tends to Xhappen here and there. X X X Rob Chansky X smq@ucscb.ucsc.edu X smq@ssyx.ucsc.edu X ...!ucbvax!ucscc!ssyx!smq X ...!ucbvax!ucscc!ucscb!smq X END_OF_FILE if test 3357 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'MANIFEST' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'MANIFEST'\" else echo shar: Extracting \"'MANIFEST'\" \(3165 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X Docs 1 X Docs/actionpoints.doc 7 X Docs/assault.doc 7 X Docs/autoreport.doc 5 X Docs/build.doc 6 X Docs/cs.doc 7 X Docs/declare.doc 6 X Docs/dock.doc 7 X Docs/examine.doc 7 X Docs/fire.doc 7 X Docs/help.doc 6 X Docs/land.doc 7 X Docs/launch.doc 7 X Docs/load.doc 7 X Docs/makeuniv.doc 7 X Docs/map.doc 5 X Docs/mobilize.doc 7 X Docs/name.doc 7 X Docs/object.doc 7 X Docs/orbit.doc 6 X Docs/order.doc 6 X Docs/overview.doc 2 X Docs/profile.doc 6 X Docs/read.doc 7 X Docs/report.doc 7 X Docs/scope.doc 6 X Docs/scrap.doc 7 X Docs/ship.doc 7 X Docs/stock.doc 7 X Docs/survey.doc 6 X Docs/tactical.doc 7 X Docs/telegram.doc 7 X Docs/undock.doc 7 X Docs/zoom.doc 7 X GB.6 3 X GB.c 6 X MANIFEST 1 X MANIFEST.BAK 6 X Makefile 5 X README 1 X autoreport.c 6 X autoshoot.c 6 X build.c 4 X cs.c 5 X daemon.c 7 X declare.c 6 X docommand.c 5 X doplanet.c 1 X dosector.c 3 X doship.c 1 X doturn.c 4 X doturn.h 7 X enrol.c 5 X exam.dat 5 X examine.c 7 X files.h 7 X files_rw.c 1 X files_shl.c 3 X fire.c 2 X fix.c 2 X get4args.c 7 X getplace.c 4 X help.c 7 X land.c 3 X launch.c 6 X load.c 3 X makeplanet.c 2 X makeuniv.c 4 X map.c 5 X max.c 6 X misc.c 7 X mobiliz.c 6 X more.c 6 X moveship.c 3 X name.c 5 X orbit.c 1 X order.c 2 X overview.nr 5 X perm.c 6 X planet.list 4 X power.c 7 X power.h 7 X prof.c 6 X races.h 7 X rand.c 7 X read_teleg.c 4 X rst.c 4 X scrap.c 6 X shipdata.h 6 X ships.h 5 X shlmisc.c 5 X shootblast.c 4 X sizes.c 7 X survey.c 3 X teleg_send.c 7 X telegram.c 6 X tweakables.h 4 X vars.h 5 X zoom.c 7 END_OF_FILE if test 3165 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test ! -d 'Docs' ; then echo shar: Creating directory \"'Docs'\" mkdir 'Docs' fi if test -f 'doplanet.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'doplanet.c'\" else echo shar: Extracting \"'doplanet.c'\" \(15732 characters\) sed "s/^X//" >'doplanet.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed (Robert Chansky, smq@b) X * doplanet.c -- do one turn on a planet. X */ X X#include "vars.h" X#include "ships.h" X#include "races.h" X#include "doturn.h" X#include "power.h" Xextern struct power Power[]; X#include Xextern bool Nuked[]; X Xextern int Ignore_lockfile; X Xchar telegram_buf[AUTO_TELEG_SIZE]; X Xint tot_resdep,tot_eff,tot_res,tot_fuel,tot_destruct,tot_captured,tot_mob; Xfloat avg_mob[MAXPLAYERS]; X Xchar sects_gained[MAXPLAYERS], sects_lost[MAXPLAYERS]; Xfloat Compat[MAXPLAYERS]; Xbool Claims; X X Xint doplanet(starnum,planet, planetnum, command) Xint starnum; Xplanettype *planet; Xint planetnum; Xint command; X{ Xint inhab=0,x,y; Xreg int i; Xint shipno,o=0,j; Xsectortype *p; Xshiptype *ship; Xdouble att; Xfloat xadd,yadd,dist,t,madd,fadd; Xint sectdata,timer=20; Xint oldplanetpopn, oldplanetmaxpopn, allmod=0,allexp=0; Xchar buf[200]; X X Xfor (i=1; i<=Num_races; i++) { X o |= isset(Stars[starnum]->inhabited,i); X inhab |= planet->info[i-1].numsectsowned; X} Xif (!o) X return 0; /* no one's explored the star yet */ X Xif (inhab) { X printf(" getting sectmap pos %d\n",planet->sectormappos); X opensectdata(§data); X getsmap(sectdata,Smap,planet->sectormappos,planet->Maxx*planet->Maxy); X close(sectdata); X X PermuteSects(planet); X bzero((char *)Sectinfo, sizeof(Sectinfo) ); X} X X X Xdist = hypot((double)planet->ypos, (double)planet->xpos); X /* closer planets orbit faster */ Xt = atan2((double)planet->ypos, (double)planet->xpos) - SYSTEMGRAVCONST * SYSTEMSIZE / dist; Xxadd = planet->xpos - dist * cos(t); Xyadd = planet->ypos - dist * sin(t); X X Xprintf("xadd %g yadd %g \n", xadd, yadd); X X /* adjust ships in orbit around the planet */ X Xfor (shipno=0; shipnoshipnums[shipno] && ((ship=ships[planet->shipnums[shipno]])!=NULL) && !ship->is_dead && !ship->rad) { X if ( !(ship->is_docked && ship->whatdest==LEVEL_PLAN)) { X /* adjust fuel, orbit for ships that are not landed */ X ship->xpos += xadd; X ship->ypos += yadd; X /* add fuel to ships orbiting gas giants */ X if (planet->type == TYPE_GASGIANT && !is_object(ship)) { X if (ship->type == STYPE_TANKER) { X fadd = FUEL_GAS_ADD_TANKER; X madd = FUEL_GAS_ADD_TANKER*MASS_FUEL; X } else if (ship->type == STYPE_STATION) { X fadd = FUEL_GAS_ADD_STATION; X madd = FUEL_GAS_ADD_STATION*MASS_FUEL; X } else { X fadd = FUEL_GAS_ADD; X madd = FUEL_GAS_ADD*MASS_FUEL; X } X if (ship->fuel + fadd > Shipdata[ship->type][ABIL_FUELCAP]) { X madd -= (Shipdata[ship->type][ABIL_FUELCAP] - (ship->fuel+fadd))*MASS_FUEL; X fadd = Shipdata[ship->type][ABIL_FUELCAP]-(ship->fuel+fadd); X } X ship->fuel += fadd; X ship->mass += madd; X } X } X X if ( (is_object(ship) && !ship->orders.object.on) || !is_object(ship)) { X if (ship->type == OTYPE_VN) { X /* Von Neumann machine */ X if (ship->is_docked && ship->whatdest==LEVEL_PLAN) { X if (ship->orders.object.number2) { X /* we are currently trying to construct another X machine */ X reg int x,y,a,dum; X for (i=1; i<253 && i<=ship->orders.object.number; i++) { X a = round_rand(sqrt((double)ship->orders.object.number)); X x = mod(int_rand((int)(ship->xpos-a),(int)(ship->xpos+a)),(int)planet->xpos,dum); X y = mod(int_rand((int)(ship->ypos-a),(int)(ship->ypos+a)),(int)planet->ypos,dum); X Sectinfo[x][y].VN= 1; X } X if (ship->resource >= Shipdata[OTYPE_VN][ABIL_COST]) { X ship->resource -= Shipdata[OTYPE_VN][ABIL_COST]; X ship->mass -= Shipdata[OTYPE_VN][ABIL_COST]*MASS_RESOURCE; X if (ship->orders.object.number > int_rand(5,50)) { X /* enough to start a new VN 'herd'. build another X ship. */ X for (i=0; ishipnums[i]; i++) ; X if (ishipnums[i] = Num_ships; X ships[Num_ships] = (shiptype *)malloc(sizeof(shiptype)); X s2 = ships[Num_ships]; X bzero((char *)s2,sizeof(shiptype)); X s2->whatorbits = LEVEL_PLAN; X s2->storbits = ship->storbits; X s2->pnumorbits = ship->pnumorbits; X s2->xpos = ((int)ship->xpos + int_rand(-9,9)) % planet->Maxx; X s2->xpos = abs(s2->xpos); X s2->ypos = ((int)ship->ypos + int_rand(-4,4)) % planet->Maxy; X s2->ypos = abs(s2->ypos); X s2->is_docked = 1; X s2->whatdest = ship->whatdest; X s2->deststar = ship->deststar; X s2->destpnum = ship->destpnum; X s2->type = OTYPE_VN; X s2->mass = Shipdata[OTYPE_VN][ABIL_MASS]; X s2->owner = 1; X s2->orders.object.number = 1; X /* is not building any VN's */ X /* no assignment now */ X ship->orders.object.number2 = 0; X } else X fprintf(stderr,"#%d can't slot insert new VN!!\n",shipno); X } else { X /* we don't have too many in this herd, so make X some more */ X ship->orders.object.number++; X } X } else { X /* if there are no players to steal from, try X and make some resources by ourselves */ X reg int i,f=0; X for (i=Num_races-1; !f && i>0; i--) X if (planet->info[i-1].resource) X f=i; X if (!f) { X /* nobody here */ X/*# ifdef UV_4.3*/ X sectortype tmp; X int tmp2; X tmp = Sector(*planet,(int)(ship->xpos), (int)(ship->ypos)); X tmp2 = tmp.resource /5; X ship->resource += tmp2; X /*ship->resource += (Sector(*planet,(int)(ship->xpos), (int)(ship->ypos)).resource) / 5; X ship->mass += ((Sector(*planet,(int)(ship->xpos), (int)(ship->ypos)).resource) / 5) * MASS_RESOURCE;*/ X/*# else X ship->resource += 7; X ship->mass += 7 * MASS_RESOURCE; X# endif*/ X } X } X } else { X /* we have no assignment -- we must launch. taken care of X in doship */ X } X } else { /* orbiting a planet */ X if (ship->orders.object.number2) { X if (ship->whatdest==LEVEL_PLAN && ship->deststar==starnum && X ship->destpnum==planetnum) { X /* we just arrived from somewhere */ X if (planet->type==TYPE_GASGIANT) { X if (ship->fuel >= Shipdata[OTYPE_VN][ABIL_FUELCAP]) X ship->orders.object.number2 = 0; X /* gas giants are of no use to us; X doship() will head us somewhere else */ X } else { X /* find a place on the planet to land */ X int x,y; reg int d; /* auto vars for & */ X printf(" VN finding a place to land\n"); X Getxysect(planet,&x,&y,1); X while ((d=Getxysect(planet,&x,&y,0)) && X Sector(*planet,x,y).des!=DES_LAND && X Sector(*planet,x,y).des!=DES_MOUNT && X Sector(*planet,x,y).resource==0) X ; X if (d) { X printf(" VN landed.\n"); X ship->is_docked = 1; X ship->whatdest = LEVEL_PLAN; X ship->deststar = ship->storbits; X ship->destpnum = ship->pnumorbits; X ship->xpos = x; X ship->ypos = y; X ship->orders.object.number2 = 1; X /* number2 means we are currently X busy here */ X } else X /* head somewhere else */ X ship->orders.object.number2 = 0; X printf("turning off; can't find place 2land\n"); X } X } else { X /* we just launched from this planet -- pick X someplace to go to (taken care of in doship) */ X } X } else { X /* okay, we don't know what the hell we are doing here. X wait for doship to give further orders. */ X } X } X } X } X X /* bombard the planet */ X if (!is_object(ship) && ship->orders.o.bombard X && ship->whatorbits==LEVEL_PLAN X && ship->whatdest==LEVEL_PLAN X && ship->storbits==ship->deststar X && ship->pnumorbits==ship->destpnum) X Bombard(ship,shipno,planet); /* ship bombards planet */ X X if (ship==NULL) { X fprintf(stderr,"null ship #%d slot %d .\n",planet->shipnums[shipno],shipno); X planet->shipnums[shipno] = 0; X } X } Xplanet->xpos += xadd; Xplanet->ypos += yadd; Xif (planet->xpos>SYSTEMSIZE) planet->xpos *= .5; Xelse if (planet->xpos< -SYSTEMSIZE) planet->xpos *= .5; Xif (planet->ypos>SYSTEMSIZE) planet->ypos *= .5; Xelse if (planet->ypos< -SYSTEMSIZE) planet->ypos *= .5; X Xif (!inhab && !Stinfo[starnum][planetnum].Thing_add) X return 0; /* (no one's explored the planet) */ X X /* check for space mirrors (among other things) warming the planet */ X /* if a change in any artificial warming/cooling trends */ Xif (Stinfo[starnum][planetnum].temp_add) X planet->conditions[TEMP] = planet->conditions[RTEMP] + X Stinfo[starnum][planetnum].temp_add + int_rand(-2,2); Xelse X planet->conditions[TEMP] = planet->conditions[RTEMP] + int_rand(-2,2); X X Xbzero((char *)avg_mob, sizeof(avg_mob) ); Xbzero((char *)sects_gained, sizeof(sects_gained) ); Xbzero((char *)sects_lost, sizeof(sects_lost) ); XClaims = 0; X Xif (Stinfo[starnum][planetnum].Thing_add) { X /* start a meso colony */ X x = int_rand(0,planet->Maxx-1); X y = int_rand(0,planet->Maxy-1); X Sector(*planet,x,y).des = DES_LAND; /* cheating. so what. */ X Sector(*planet,x,y).popn = 1; X Sector(*planet,x,y).owner = Stinfo[starnum][planetnum].Thing_add; X} Xtot_resdep=tot_eff=tot_res=tot_fuel=tot_destruct=tot_mob=tot_captured=0; X Xoldplanetmaxpopn = planet->maxpopn; Xplanet->maxpopn = 0; X Xoldplanetpopn = planet->popn; Xplanet->popn = 0; /* initialize population for recount */ Xfor (i=1; i<=Num_races; i++) { X Compat[i] = compatibility(planet, races[i]); X planet->info[i-1].numsectsowned = 0; X} X Xprintf(" while %d\n",Getxysect(planet, &x, &y, 1)); /* reset */ Xwhile (Getxysect(planet, &x, &y, 0)) { X p = &Sector(*planet,x,y); X if (p->owner) { X /* (all modified; sectors belonging to that player modified) */ X allmod = 1; X if (!p->popn ) { X p->owner=0; /* make wasted/unowned sects go to player 0 */ X } else { X planet->info[p->owner-1].numsectsowned++; X if (!Stars[starnum]->nova_stage) { X /* spread excess popn to surrounding sects */ X spread(planet,p,x,y); X produce(planet,p); /* produce stuff there */ X planet->popn += p->popn; X Power[p->owner].popn += p->popn; X Power[p->owner].sum_eff += p->eff; X starpopns[starnum][p->owner] += p->popn; X } else { X /* damage sector from supernova */ X p->resource++; X if (p->fert) X --p->fert; X if (Stars[starnum]->nova_stage == 14) X p->popn = 0; X else X p->popn *= .80; X } X } X } X X planet->maxpopn += maxsupport(p); X X if (Sectinfo[x][y].VN) X p->VN = 1; X else X p->VN = 0; X if (p->is_wasted) { X if (x>1 && xMaxx-2) { X if (p->des==DES_SEA || p->des==DES_GAS) { X /* don't reclaim pole sectors */ X if ( y>1 && yMaxy-2 && X (!(p-1)->is_wasted || !(p+1)->is_wasted) X && !random()%5) X p->is_wasted = 0; X } else if (p->des==DES_LAND || p->des==DES_MOUNT) { X if ( y>1 && yMaxy-2 && X ((p-1)->popn || (p+1)->popn) X && !random()%10) X p->is_wasted = 0; X } X } X } X X /* evaporate the oceans on novae */ X if (Stars[starnum]->nova_stage && p->des==DES_SEA) X X if ( (x>0 && (p-1)->des==DES_LAND) || X (xMaxx-1 && (p+1)->des==DES_LAND) || X (y>0 && (p-planet->Maxx)->des==DES_LAND) || X (yMaxy-1 && (p+planet->Maxx)->des==DES_LAND ) ) { X p->des = DES_LAND; X p->popn = p->owner = 0; X p->resource += 3; X p->fert = int_rand(1,4); X printf("sect %d,%d evaporated.\n",x,y); X } X} X Xif (allmod) { /* ( >= 1 inhabited sector on the planet) */ X X if (planet->expltimer >= 1) X planet->expltimer--; X if (!Stars[starnum]->nova_stage && !planet->expltimer) { X if (!planet->expltimer) X planet->expltimer = 5; X for (i=1; !Claims && !allexp && i<=Num_races; i++) { X printf("pl %d numsectsowned %d Claims %d allexp %d compat %f\n",i,planet->info[i-1].numsectsowned,Claims,allexp,Compat[i]); X /* sectors have been modified for this player*/ X /* & planet is compatible enough */ X if (planet->info[i-1].numsectsowned && Compat[i] > 40.0) X while (!Claims && !allexp && --timer) { X printf("exploring ... timer=%d\n",timer); X /*printf("exploring player %d\n",i);*/ X o = 1; X Getxysect(planet, &x, &y, 1); X while (!Claims && Getxysect(planet, &x, &y, 0)) { X /* find out if all sectors have been explored */ X o &= Sectinfo[x][y].explored[i]; X p = &Sector(*planet,x,y); X if (!p->owner && !p->is_wasted && p->des==DES_LAND && Sectinfo[x][y].explored[i]) { X /* (water) explorations have found an island */ X printf("found an island @ %d,%d\n",x,y); X Claims = i; X /* give them some free people there */ X p->popn = races[i]->number_sexes; X tot_captured = 1; X } else X explore(planet, p, x, y, i); X } X allexp |= o; /* all sectors explored for this player */ X X } X } X } X if (allexp) X planet->expltimer = 5; X X X for (i=1; i<=Num_races; i++) X if (planet->info[i-1].autorep) { X X planet->info[i-1].autorep--; X teleg_add("",telegram_buf); /* clear buf */ X sprintf(buf,"****** Report: Planet /%s/%s ******\n", X Stars[starnum]->name, Stars[starnum]->pnames[planetnum] ); X teleg_add(buf,telegram_buf); X if (Stinfo[starnum][planetnum].temp_add) { X sprintf(buf,"\nGlobal temperature alteration: %d to %d.\n\n", X Temp(planet->conditions[RTEMP]), Temp(planet->conditions[TEMP])); X teleg_add(buf,telegram_buf); X } X teleg_add("resource prod. fuel prod. weapons prod. mob.pt prod.\n",telegram_buf); X sprintf(buf,"%12d%12d%15d%13d\n", tot_res, tot_fuel, tot_destruct,tot_mob); X teleg_add(buf,telegram_buf); X sprintf(buf,"resource deposit depletion: %d\n", tot_resdep); X teleg_add(buf,telegram_buf); X teleg_add("total births (%%) growth of max popn support (%%)\n",telegram_buf); X sprintf(buf,"%9d (%.2f%%)%23d (%.2f%%)\n", X planet->popn - oldplanetpopn, X ((float)planet->popn-oldplanetpopn)/oldplanetpopn, X planet->maxpopn - oldplanetmaxpopn, X ((float)planet->maxpopn-oldplanetmaxpopn)/oldplanetmaxpopn); X teleg_add(buf,telegram_buf); X sprintf(buf,"sectors owned on this planet: %d.\n", tot_captured); X teleg_add(buf,telegram_buf); X if (sects_gained[i] || sects_lost[i]) { X teleg_add("\nWAR STATUS: ",telegram_buf); X sprintf(buf,"%d sectors gained, %d sectors lost.\n", X sects_gained[i],sects_lost[i]); X teleg_add(buf,telegram_buf); X } X if (Stars[starnum]->nova_stage) { X sprintf(buf,"\nThis planet's primary is in a Stage %d nova.", Stars[starnum]->nova_stage); X teleg_add(buf,telegram_buf); X } X X teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf); X X } X X /* find out who is on this planet, for nova notification */ X if (Stars[starnum]->nova_stage == 1) { X teleg_add("",telegram_buf); /* initialize telegram counter */ X sprintf(buf,"BULLETIN from /%s/%s\n", Stars[starnum]->name, Stars[starnum]->pnames[planetnum]); X teleg_add(buf,telegram_buf); X sprintf(buf,"\nStar %s is undergoing nova.\n", Stars[starnum]->name); X teleg_add(buf,telegram_buf); X if (planet->type==TYPE_EARTH) X teleg_add("Seas and rivers are boiling!\n",telegram_buf); X sprintf(buf, "This planet must be evacuated immediately!\n%c", TELEG_DELIM); X teleg_add(buf,telegram_buf); X for (i=1; i<=Num_races; i++) X if (planet->info[i-1].numsectsowned) X teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf); X } X X X for (i=1; i<=Num_races; i++) { X Power[i].resource += planet->info[i-1].resource; X Power[i].destruct += planet->info[i-1].destruct; X Power[i].fuel += planet->info[i-1].fuel; X Power[i].planets_owned += !!planet->info[i-1].numsectsowned; X if (planet->info[i-1].numsectsowned) { X Power[i].sectors_owned += planet->info[i-1].numsectsowned; X Power[i].sum_mob += avg_mob[i]; X /* combat readiness naturally moves towards the avg mobilization */ X avg_mob[i] /= planet->info[i-1].numsectsowned; X planet->info[i-1].comread += X sgn(avg_mob[i] - planet->info[i-1].comread); X } X } X planet->conditions[TOXIC] = (planet->conditions[TOXIC]*50 + X 100.0 * planet->popn / planet->maxpopn) / 51.0; X X } X return allmod; X} END_OF_FILE if test 15732 -ne `wc -c <'doplanet.c'`; then echo shar: \"'doplanet.c'\" unpacked with wrong size! fi # end of 'doplanet.c' fi if test -f 'doship.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'doship.c'\" else echo shar: Extracting \"'doship.c'\" \(12675 characters\) sed "s/^X//" >'doship.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed (Robert Chansky, smq@b) X * doship -- do one ship turn. X */ X X#include "vars.h" X#include "ships.h" X#include "races.h" X#include "doturn.h" X#include "power.h" X#include Xextern struct power Power[]; X Xextern int Ignore_lockfile; X Xdoship(shipno,ship) Xint shipno; Xshiptype *ship; X{ X int j,t; X char buf[200]; X X if (!ship->is_dead) { X X /* add ships, popn to total count to add AP's */ X Power[ship->owner].ships_owned++; X Power[ship->owner].resource += ship->resource; X Power[ship->owner].fuel += ship->fuel; X Power[ship->owner].destruct += ship->destruct; X Power[ship->owner].popn += ship->popn; X if (ship->whatorbits==LEVEL_UNIV) { X Sdatanumships[ship->owner]++; X Sdatapopns[ship->owner] += ship->popn; X } else { X starnumships[ship->storbits][ship->owner] += (ship->type==OTYPE_VN) ? ship->orders.object.number : 1; X /* add popn of ships to popn */ X starpopns[ship->storbits][ship->owner] += ship->popn; X } X X /* repair radiation */ X if (ship->rad) { X /* kill off some people */ X ship->popn = round_rand(ship->popn * .80); X if (ship->rad > REPAIR_RATE) X ship->rad = 0; X else X ship->rad -= REPAIR_RATE; X } else { X /* irradiated ships are immobile */ X X Moveship(shipno, ship, Stars[ship->storbits], X Stars[ship->deststar], X planets[ship->storbits][ship->pnumorbits], X planets[ship->deststar][ship->destpnum], X ships[ship->destshipno]); X X /* repair ship by the amount of crew it has */ X if (ship->damage && ship->popn) { reg int d; X if ((d = ((float)ship->popn / X Shipdata[ship->type][ABIL_MAXCREW]) * REPAIR_RATE) X > ship->damage) X ship->damage = 0; X else X ship->damage -= d; X } X X switch (ship->type) { X X case OTYPE_CANIST: X if (ship->whatorbits == LEVEL_PLAN && !ship->is_docked) { char *t; X if (--ship->orders.object.number) { X t = &Stinfo[ship->storbits][ship->pnumorbits].temp_add; X if (*t - 10 < -120) X *t = -120; X else X *t -= 10; X } else { /* timer expired; destroy canister */ X int fd,j=0; X ship->is_dead = 1; X while (jstorbits][ship->pnumorbits]->shipnums[j] != shipno) X j++; X if (jstorbits][ship->pnumorbits]->shipnums[j] = 0; X openshfdata(&fd); destroyship(fd,shipno); close(fd); X teleg_add("",telegram_buf); X sprintf(buf,"Notice from /%s/%s\n\n", X Stars[ship->storbits]->name, X Stars[ship->storbits]->pnames[ship->pnumorbits]); X teleg_add(buf,telegram_buf); X teleg_add("Canister of dust previously covering this planet has dissipated.\n",telegram_buf); X for (j=1; j<=Num_races; j++) X if (planets[ship->storbits][ship->pnumorbits]->info[j-1].numsectsowned) X teleg_send(TELEG_PLAYER_AUTO, j, telegram_buf); X } else fprintf(stderr,"can't delete canister #%d!\n",shipno); X } X } X break; X X case STYPE_MINE:{ reg int i,rad=0; float xd[MAXSSHIPS],yd[MAXSSHIPS]; X int p,shfdata; X /* check around and see if we should explode. */ X if (ship->orders.object.on && ship->whatorbits==LEVEL_STAR) { X for (i=0; istorbits]->shipnums[i]) { X xd[i] = ships[Stars[ship->storbits]->shipnums[i]]->xpos- ship->xpos; X yd[i] = ships[Stars[ship->storbits]->shipnums[i]]->ypos- ship->ypos; X if (Stars[ship->storbits]->shipnums[i]==shipno) X p = i; X else X if (isset(races[ship->owner]->atwar,ships[Stars[ship->storbits]->shipnums[i]]->owner) && X (abs(xd[i])+abs(yd[i])) < ship->orders.object.number) X rad = 1; X if (rad) { X /* we've found someone we don't like, X detonate and irradiate them */ X Stars[ship->storbits]->shipnums[p] = 0; X openshfdata(&shfdata); X destroyship(shfdata, shipno); X close(shfdata); X teleg_add("",telegram_buf); X sprintf(buf, "BULLETIN!\n mine #%d triggered at system /%s",shipno,Stars[ship->storbits]->name); X teleg_add(buf, telegram_buf); X teleg_send(TELEG_PLAYER_AUTO,ship->owner,telegram_buf); X for (i=0; i<=MAXSSHIPS; i++) X if (Stars[ship->storbits]->shipnums[i] && X Stars[ship->storbits]->shipnums[i]!=shipno && X (abs(xd[i])+abs(yd[i]))orders.object.number) { X rad = round_rand(((float)Shipdata[STYPE_MINE][ABIL_DESTCAP] / ship->destruct)*.5); X if (ships[Stars[ship->storbits]->shipnums[i]]->rad + rad > 100) X ships[Stars[ship->storbits]->shipnums[i]]->rad = 100; X else X ships[Stars[ship->storbits]->shipnums[i]]->rad += rad; X teleg_add("",telegram_buf); X sprintf(buf, "BULLETIN!\n ship #%d irradiated by mine at system /%s", Stars[ship->storbits]->shipnums[i], X Stars[ship->storbits]->name); X teleg_add(buf, telegram_buf); X teleg_send(TELEG_PLAYER_AUTO,ships[Stars[ship->storbits]->shipnums[i]]->owner,telegram_buf); X } X } X } X }/* else if (ship->whatorbits==LEVEL_PLAN) {}*/ X } break; X X case STYPE_MIRROR: X switch (ship->orders.aimed_at.level) { X case LEVEL_SHIP: /* ship aimed at is a legal ship now */ X /* if in the same system */ X if ( (ship->whatorbits==LEVEL_STAR || ship->whatorbits==LEVEL_PLAN) X && (ships[ship->orders.aimed_at.shipno]!=NULL) X && (ships[ship->orders.aimed_at.shipno]->whatorbits==LEVEL_STAR || X ships[ship->orders.aimed_at.shipno]->whatorbits==LEVEL_PLAN) X && ship->storbits == ships[ship->orders.aimed_at.shipno]->storbits X && !ships[ship->orders.aimed_at.shipno]->is_dead ) X ships[ship->orders.aimed_at.shipno]->damage += 10; X break; X case LEVEL_PLAN: { reg char *t; X t = &Stinfo[ship->storbits][ship->orders.aimed_at.pnum].temp_add; X if (*t + ship->orders.aimed_at.intensity > 120) X *t = 120; X else if (*t + ship->orders.aimed_at.intensity < -120) X *t = -120; X else X *t += ship->orders.aimed_at.intensity; X } X break; X case LEVEL_STAR: X Stars[ship->storbits]->stability += random()&01; X break; X case LEVEL_UNIV: X break; X } X break; X case STYPE_GOD: X /* gods have infinite power.... heh heh heh */ X ship->fuel = Shipdata[ship->type][ABIL_FUELCAP]; X ship->popn = Shipdata[ship->type][ABIL_MAXCREW]; X ship->destruct = Shipdata[ship->type][ABIL_DESTCAP]; X ship->resource = Shipdata[ship->type][ABIL_CARGO]; X break; X X case OTYPE_TERRA: /* terraforming device */ X /* if landed on planet, change conditions to be like race */ X if (ship->is_docked && ship->whatdest==LEVEL_PLAN && ship->orders.object.on) { X int j,d,a;planettype *p; X p = planets[ship->storbits][ship->pnumorbits]; X if (p->info[ship->owner-1].fuel >= 3) { X p->info[ship->owner-1].fuel-= 3; X for (j=RTEMP+1; j<=OTHER; j++) { X d = races[ship->owner]->conditions[j] - p->conditions[j]; X a = int_rand(sgn(d)*3,-sgn(d)); X if (p->conditions[j] + a < 0) X p->conditions[j] = 0; X else if (p->conditions[j] + a > 100) X p->conditions[j] = 100; X else p->conditions[j] += a; X } X } X } X break; X X case OTYPE_VN: /* Von Neumann machine */ X do_VN(ship,shipno); X break; X X case STYPE_POD: X if (ship->notified) { X /* we just arrived at this system -- explode */ X int shfdata; X reg int i,f= -1; X for (i=0; istorbits]->shipnums[i]!=shipno; i++) ; X if (i==MAXSSHIPS) X fprintf(stderr,"cannot del pod #%d!\n",shipno); X else { X Stars[ship->storbits]->shipnums[i] = 0; X ship->is_dead = 1; X openshfdata(&shfdata); X destroyship(shfdata, shipno); X close(shfdata); X for (i=0; f== -1 && istorbits]->numplanets; i++) X if (sqrt((double)Distsq(ship->xpos, ship->ypos, X Stars[ship->storbits]->xpos + planets[ship->storbits][i]->xpos, X Stars[ship->storbits]->ypos + planets[ship->storbits][i]->ypos))/SYSTEMSIZE < float_rand()*2) X f = i; X teleg_add("",telegram_buf); X sprintf(buf, "Bulletin\n\nSpore pod #%d has warmed and exploded.\n",shipno); X teleg_add(buf,telegram_buf); X if (f != -1) { X sprintf(buf,"A spore has landed on planet %s.\n",Stars[ship->storbits]->pnames[f]); X Stinfo[ship->storbits][f].Thing_add = ship->owner; X /* so doplanet does not pass over it */ X setbit(Stars[ship->storbits]->inhabited,ship->owner); X planets[ship->storbits][f]->info[ship->owner-1].explored = 1; X } else { X sprintf(buf,"No spores have survived.\n"); X } X teleg_add(buf,telegram_buf); X teleg_send(TELEG_PLAYER_AUTO, ship->owner, telegram_buf); X teleg_add("",telegram_buf); X sprintf(buf,"BULLETIN!\n\n A spore pod has exploded in system /%s.\n",Stars[ship->storbits]->name); X teleg_add(buf,telegram_buf); X teleg_add("Spores may have drifted to planets here.\n",telegram_buf); X for (i=1; i<=Num_races; i++) X if (i!=ship->owner && isset(Stars[ship->storbits]->inhabited,i)) X teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf); X } X } X break; X X default: X break; X } X X } X } X X} X X X Xdo_VN(ship,shipno) Xshiptype *ship; Xint shipno; X{ Xint j,n,r; Xplanettype *p; Xchar buf[150]; X X if (ship->orders.object.on) { X X p = planets[ship->storbits][ship->pnumorbits]; X X if (ship->is_docked && ship->whatdest==LEVEL_PLAN && ship->whatorbits==LEVEL_PLAN) { X /* try to launch it */ X if (ship->orders.object.number2 == 0) { /* launch if no assignment */ X /* steal some fuel from other players,telegram */ X bool f=0; X for (r=Num_races-1; !f && r>0; r--) X if (p->info[r-1].fuel >= Shipdata[OTYPE_VN][ABIL_COST]) { X p->info[ship->owner-1].fuel += X Shipdata[OTYPE_VN][ABIL_FUELCAP]; X p->info[r-1].fuel -= Shipdata[OTYPE_VN][ABIL_FUELCAP]; X f = r; X } X if (f) { X /*if (f!=1) {*/ X teleg_add("",telegram_buf); X teleg_add("Bulletin!\n\n",telegram_buf); X sprintf(buf,"%d fuel stolen by %s #%d on planet /%s/%s!\n", X Shipdata[OTYPE_VN][ABIL_FUELCAP], X Shipnames[OTYPE_VN], X shipno, Stars[ship->storbits]->name, X Stars[ship->storbits]->pnames[ship->pnumorbits]); X teleg_add(buf,telegram_buf); X teleg_send(TELEG_PLAYER_AUTO, f, telegram_buf); X teleg_send(TELEG_PLAYER_AUTO, 1, telegram_buf); X /*}*/ X X ship->orders.object.number2 = 0; /* no current assignment */ X ship->xpos = Stars[ship->storbits]->xpos + planets[ship->storbits][ship->pnumorbits]->xpos + int_rand(-10,10); X ship->ypos = Stars[ship->storbits]->ypos + planets[ship->storbits][ship->pnumorbits]->ypos + int_rand(-10,10); X ship->is_docked = 0; X ship->whatdest = LEVEL_UNIV; X } X } else { X /* we have an assignment. Since we are landed, this means X we are engaged in building up resources/fuel. */ X /* steal resources from other players,telegram */ X bool f=0; X for (r=Num_races-1; !f && r>0; r--) X if (p->info[r-1].resource >= Shipdata[OTYPE_VN][ABIL_COST]) X f = r; X if (f) { X /*if (f!=1) {*/ X ship->resource += Shipdata[OTYPE_VN][ABIL_COST]; X ship->mass += Shipdata[OTYPE_VN][ABIL_COST] * MASS_RESOURCE; X p->info[f-1].resource -= Shipdata[OTYPE_VN][ABIL_COST]; X teleg_add("",telegram_buf); X teleg_add("Bulletin!\n\n",telegram_buf); X sprintf(buf,"%d resources stolen by %s #%d\non planet ", X Shipdata[OTYPE_VN][ABIL_COST], X Shipnames[OTYPE_VN], shipno); X teleg_add(buf,telegram_buf); X sprintf(buf,"/%s/%s!\n", X Stars[ship->storbits]->name, X Stars[ship->storbits]->pnames[ship->pnumorbits]); X teleg_add(buf,telegram_buf); X teleg_send(TELEG_PLAYER_AUTO, f, telegram_buf); X /* remove */ X teleg_send(TELEG_PLAYER_AUTO, 1, telegram_buf); X /*}*/ X /* if no resources to steal, more will be produced in doplanet*/ X } X } X } else { X /* we are not landed */ X if (ship->orders.object.number2) { X /* we've arrived from somewhere -- look for a place to land. X this is done on planet turn */ X } else { X /* we were just built & launched */ X reg int s,min=0,min2=0; X /* find closest unexplored star */ X for (s=1; sstorbits && X Distsq(Stars[s]->xpos,Stars[s]->ypos,ship->xpos,ship->ypos) < X Distsq(Stars[min]->xpos,Stars[min]->ypos,ship->xpos,ship->ypos)) X min2 = min,min = s; X /* don't go there if we have a choice, X and we have VN's there already */ X if (isset(Stars[min]->inhabited,1)) X if (isset(Stars[min2]->inhabited,1)) X ship->deststar = int_rand(0,Sdata.numstars-1); X else X ship->deststar = min2; /* 2nd closest star */ X else X ship->deststar = min; X if (Stars[ship->deststar]->numplanets) { X ship->destpnum = X int_rand(0,Stars[ship->deststar]->numplanets-1); X ship->whatdest = LEVEL_PLAN; X } else { X ship->whatdest = LEVEL_STAR; X } X fprintf(stderr,"VN #%d headed for star %d, pl %d.\n",shipno,ship->deststar, ship->destpnum); X ship->orders.object.number2 = 1; X /* we are assigned to go */ X } X } X X } X X} END_OF_FILE if test 12675 -ne `wc -c <'doship.c'`; then echo shar: \"'doship.c'\" unpacked with wrong size! fi # end of 'doship.c' fi if test -f 'files_rw.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'files_rw.c'\" else echo shar: Extracting \"'files_rw.c'\" \(2701 characters\) sed "s/^X//" >'files_rw.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed (Robert Chansky, smq@b) X * disk input/output routines X * most read routines lock the data they just accessed (the file is not X * closed). write routines close and thus unlock that area. X * Neither will work if the file LOCK_ALL exists, unless Ignore_lockfile X * is true, or Ignore_file_locks. X * X * Fileread(p, num, file, posn, routine); -- generic file read X * Filewrite(p, num, file, posn, routine); -- generic file write X * X */ X X#include "tweakables.h" X#include X#include X#include Xint sys_nerr; Xchar *sys_errlist[]; Xextern int errno; X X Xint Ignore_lockfile=0,Ignore_filelocks=0,Ignore_readerrors=0; X XFileread(fd, p, num, file, posn) Xint fd; Xchar *p; Xint num; Xchar *file; Xint posn; X{ X int lockt = NUM_TIMES_TO_WAIT_FOR_LOCK; X int lerr,n2; X X/* printf(" fread fd=%d,reading %d bytes %s posn %d \n",fd,num,file,posn);*/ Xif (!Ignore_lockfile) { /* we are running for the shell filestuff */ X X if (access(LOCK_ALL, F_OK)==0) { /* if file exists */ X printf("doing update. Please come back later.\n"); X exit(0); X } X X X X/*#ifdef UNIX_VERSION4.3 X lseek(fd, posn, L_SET); X if (!Ignore_filelocks) { X while ((lerr=lockf(fd, F_TLOCK, (long)num))== -1 && errno==EACCES) { X close(fd); X if (!lockt--) { X printf("too long. exit.\n"); X exit(); X } X printf("waiting on %s lock...\n",file); X sleep(2); X fd = open(file,O_RDWR,0777); X lseek(fd, posn, L_SET); X } X if (lerr<0 && errno!=EACCES) { X printf("weird error.\n"); X perror("Fileread 2"); X exit(); X } X } X#else*/ X if (!Ignore_filelocks) { X while ((lerr=flock(fd, LOCK_SH|LOCK_EX|LOCK_NB ))== -1 && errno==EWOULDBLOCK) { X if (!lockt--) { X printf("too long. exit.\n"); X exit(-1); X } X printf("waiting on %s lock...\n",file); X sleep(2); X } X if (lerr<0 && errno!=EWOULDBLOCK) { X perror("Fileread 2"); X exit(-1); X } X } X X } X X if (lseek(fd, posn, L_SET) < 0) { X perror("file read"); X return; X } X if ((n2=read(fd,p,num))!=num && !Ignore_readerrors) { X printf("read: bad # of bytes read (%d != %d).\n",n2,num); X perror("fileread"); X return; X } X X} X X XFilewrite(fd, p, num, file, posn) Xint fd; Xchar *p; Xint num; Xchar *file; Xint posn; X{ Xint mask; Xint lockfd,n2; X X if (!Ignore_lockfile) { X if (access(LOCK_ALL, F_OK)==0) { X printf("doing update. Please come back later.\n"); X exit(-1); X } X mask = sigblock(SIGINT | SIGQUIT | SIGSTOP); X } X X /*printf(" fd =%d writing %d bytes to %s posn %d.\n",fd,num,file,posn);*/ X X if (lseek(fd, posn, L_SET) < 0) { X perror(file); X return; X } X X if ((n2=write(fd,p,num))!=num && !Ignore_readerrors) { X printf("write: bad # of bytes written. (%d!=%d)\n",n2,num); X perror(file); X return; X } X X if (!Ignore_lockfile) X sigsetmask(mask); X} END_OF_FILE if test 2701 -ne `wc -c <'files_rw.c'`; then echo shar: \"'files_rw.c'\" unpacked with wrong size! fi # end of 'files_rw.c' fi if test -f 'orbit.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'orbit.c'\" else echo shar: Extracting \"'orbit.c'\" \(12715 characters\) sed "s/^X//" >'orbit.c' <<'END_OF_FILE' X/* X * Galactic Bloodshed (Robert Chansky, smq@b) X * orbit.c -- display orbits of planets (graphic representation) X * X * OPTIONS X * -p : If this option is set, ``orbit'' will not display planet names. X * X * -S : Do not display star names. X * X * -s : Do not display ships. X * X * -(number) : Do not display that #'d ship or planet (in case it obstructs X * the view of another object) X */ X X X#define Midx ((stdscr->_maxx-NAMESIZE)/2.0) X#define Midy ((stdscr->_maxy-1)/2.0) X#define S_X (stdscr->_maxx-NAMESIZE) X#define S_Y (stdscr->_maxy) X X#include "vars.h" X#include "ships.h" X#include Xextern char Shipltrs[]; Xfloat Lastx, Lasty, Zoom; X X Xorbit(APcount, argn,args) Xint APcount; Xint argn; Xchar args[MAXARGS][COMMANDSIZE]; X{ Xregister int i; Xint DontDispNum= -1, t, flag; Xplanettype *p; Xshiptype *s; Xplacetype where,shipwhere; Xbool err, DontDispPlanets, DontDispShips, DontDispStars; Xchar str[PLACENAMESIZE]; Xint orbit_shdata,orbit_pdata,orbit_stardata; X X DontDispPlanets = DontDispShips = DontDispStars = 0; X printf(" orbit:called |%s|\n",args[1]); X X /* find options, set flags accordingly */ X for (flag=1; flag<=argn-1; flag++) X if (*args[flag]=='-') { X for (i=1; args[flag][i]!='\0'; i++) X switch (args[flag][i]) { X case 's': DontDispShips = 1; X break; X case 'S': DontDispStars = 1; X break; X case 'p': DontDispPlanets = 1; X break; X default : if (sscanf(args[flag]+1,"%d",&DontDispNum)!=1) { X printf("Bad number %s.\n",args[flag]+1); X DontDispNum = -1; X } X if (DontDispNum) X DontDispNum--; /* make a '1' into a '0' */ X break; X } X } X X if (argn==1) { X where = Getplace(":",0); X Lastx = Dir.lastx; X Lasty = Dir.lasty; X Zoom = Dir.zoom; X } else { X printf(" trying to orbit %s\n",args[argn-1]); X where = Getplace(args[argn-1],0); X Lastx = Lasty = 0.0; X Zoom = 1.0; X } X X if (where.err) { X printf("orbit: error in args.\n"); X return; X } X X X clear(); X X switch (where.level) { X case LEVEL_UNIV: X /* may be necessary to put (below) */ X openstardata(&orbit_stardata); X getsdata(orbit_stardata,&Sdata); X close(orbit_stardata); X X for (i=0; inumplanets; i++) { X if (DontDispNum!=i) { X getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[i]); X DispPlanet(LEVEL_STAR,p,Stars[where.snum]->pnames[i],DontDispPlanets); X free(p); X } X } X close(orbit_pdata); X X if (!DontDispShips && Stars[where.snum]->numships) { X openshdata(&orbit_shdata); X for (i=0; ishipnums[i]) X if (DontDispNum != Stars[where.snum]->shipnums[i]) { X (void)getship(orbit_shdata,&s,Stars[where.snum]->shipnums[i]); X DispShip(&where, s, Stars[where.snum]->shipnums[i], NULL ); X free(s); X } X close(orbit_shdata); X } X break; X X case LEVEL_PLAN: X openpdata(&orbit_pdata); X getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[where.pnum]); X close(orbit_pdata); X DispPlanet(LEVEL_PLAN, p, Stars[where.snum]->pnames[where.pnum], DontDispPlanets); X X if (!DontDispShips && p->numships) { X openshdata(&orbit_shdata); X for (i=0; ishipnums[i]) { X if (DontDispNum!=p->shipnums[i]) { X (void)getship(orbit_shdata,&s,p->shipnums[i]); X /* don't print out landed ships */ X if ( DontDispNum != p->shipnums[i] && X !(s->is_docked && s->whatdest==LEVEL_PLAN) ) { X DispShip(&where, s, p->shipnums[i], p); X } X free(s); X } X } X close(orbit_shdata); X } X free(p); X break; X X case LEVEL_SHIP: { X char gs[MAXARGS][COMMANDSIZE]; X shipwhere.level = where.shipptr->whatorbits; X shipwhere.snum = where.shipptr->storbits; X shipwhere.pnum = where.shipptr->pnumorbits; X sprintf(gs[1],"%s",Dispplace(&shipwhere) ); X printf(" orbiting %s\n",gs[1]); X orbit(0,2,gs); X } break; X X default: X printf("bleah!!!\n"); X exit(-1); X } X /* move to bottom of screen and draw */ X move(S_Y-1,0); X refresh(); X X} X Xchar *Novae[16][7] = { X " ", X " ", X " ", X " %* ", X " ", X " ", X " ", X X " ", X " ", X " % ", X " %*% ", X " % ", X " ", X " ", X X " ", X " ", X " %% ", X " %%*%% ", X " %% ", X " ", X " ", X X " ", X " ", X " %%% ", X " %*%%% ", X " %%% ", X " ", X " ", X X " ", X " ", X " %%% ", X " %%*%%% ", X " %%%% ", X " ", X " ", X X " ", X " % ", X " %%%% ", X " %%%*%%% ", X " %%%%% ", X " ", X " ", X X " ", X " % ", X " %%%%% ", X " %% *%%% ", X " %%%%% ", X " % ", X " ", X X " ", X " % ", X " %%%%%%% ", X " %%% * %%% ", X " %%%%% ", X " %% ", X " ", X X " ", X " %%% ", X " %%%%%%% ", X " %%% * %%% ", X " %%% %%% ", X " %%% ", X " ", X X " ", X " %%%% ", X " %%% %%% ", X " %%% * %%% ", X " %%% %%%% ", X " %%%%%% ", X " %% ", X X " ", X " %%%% ", X " %%% %%% ", X " %%% * %%% ", X " %%% %%% ", X " %%%%%% ", X " %% ", X X " %% ", X " %%%%%% ", X " %% %%% ", X " %%% * %%%", X " %%%% %%% ", X " %%%%%%%% ", X " %%% ", X X " %%%% ", X " %%%%%%%% ", X " %%% % %%%", X " %% * %%", X " %%% %%%", X " %%%%%% % ", X " % %%% ", X X " %%% %% ", X " %%% %% %% ", X "%% %%%", X "%%% * % %%", X " % % %%", X " %%% % % % ", X " %%%%%%% ", X X "% % % %% ", X " % % ", X "%% % %", X "% * % ", X " % %", X " % % % ", X " % %%% ", X X " % % ", X " %", X "% ", X " * %", X "% ", X " % %", X " % % % " X}; X X X XDispStar(level, star, DontDispStars) Xint level; Xstartype *star; Xint DontDispStars; X{ X int x,y; X register int x2,y2; X float fac; X char *c; X X if (level==LEVEL_UNIV) { X fac = 1.0; X x = (int)(Midx+(star->xpos-Lastx)*(Midx/UNIVSIZE) / Zoom); X y = (int)(Midy+(star->ypos-Lasty)*(Midy/UNIVSIZE) / Zoom); X } else if (level==LEVEL_STAR) { X fac = 1000.0; X x = (int)(Midx+(-Lastx)*(Midx/SYSTEMSIZE) / Zoom); X y = (int)(Midy+(-Lasty)*(Midy/SYSTEMSIZE) / Zoom); X } X if (star->nova_stage) X DispArray(x, y, 11,7, Novae[star->nova_stage-1], fac); X else if (y>=0 && y<=S_Y && x>=0 && x<=S_X) { X move(y,x); X addch('*'); X if (!DontDispStars) { X move(y, x+2); X addstr(star->name); X } X } X X} X X XDispPlanet(level, p, name, DontDispPlanets) Xint level; Xplanettype *p; Xchar *name; Xint DontDispPlanets; X{ Xint x,y; X X if (level==LEVEL_STAR) { X y = (int)(Midy +(p->ypos-Lasty)*(Midy/SYSTEMSIZE) / Zoom); X x = (int)(Midx +(p->xpos-Lastx)*(Midx/SYSTEMSIZE) / Zoom); X } else if (level==LEVEL_PLAN) { X y = (int)(Midy +(-Lasty)*(Midy/PLORBITSIZE) / Zoom); X x = (int)(Midx +(-Lastx)*(Midx/PLORBITSIZE) / Zoom); X } X if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { X mvaddch(y,x,'@'); X if (!DontDispPlanets) { X addch(' '); X addstr(name); X } X } X} X X Xchar *Mirror[8][5] = { X X " ", X " ", X "\\===m===/", X " ", X " ", X X " | ", X " \\\\ ", X " m ", X " \\\\ ", X " \\__", X X " / ", X " || ", X " m ", X " || ", X " \\ ", X X " __", X " // ", X " m ", X " // ", X " | ", X X " ", X " ", X "/===m===\\", /* cc thinks this is a quoted " w/o the \ */ X " ", X " ", X X "__ ", X " \\\\ ", /* weird stuff again */ X " m ", X " \\\\ ", X " | ", X X " \\ ", X " || ", X " m ", X " || ", X " / ", X X " | ", X " // ", X " m ", X "__// ", X " " X}; X X XDispShip(where, ship, shipnum, pl ) Xplacetype *where; Xshiptype *ship; Xint shipnum; Xplanettype *pl; /* orbits planet */ X{ X int x,y,x2,y2,wm,pdata,shipdata; X shiptype *aship; X planettype *apl; X float xt,yt,slope; X char *c; X X if (ship->is_dead) X return; X X switch (where->level) { X case LEVEL_PLAN: X x = Midx + (ship->xpos-(Stars[where->snum]->xpos+pl->xpos) - Lastx)*(Midx/PLORBITSIZE) / Zoom; X y = Midy + (ship->ypos-(Stars[where->snum]->ypos+pl->ypos) - Lasty)*(Midy/PLORBITSIZE) / Zoom; X break; X case LEVEL_STAR: X x = Midx + (ship->xpos-Stars[where->snum]->xpos - Lastx)*(Midx/SYSTEMSIZE) / Zoom; X y = Midy + (ship->ypos-Stars[where->snum]->ypos - Lasty)*(Midy/SYSTEMSIZE) / Zoom; X break; X case LEVEL_UNIV: X x = Midx + (ship->xpos-Lastx)*(Midx/UNIVSIZE) / Zoom; X y = Midy + (ship->ypos-Lasty)*(Midy/UNIVSIZE) / Zoom; X break; X default: X printf("WHOA! error.\n"); X exit(-1); X } X X switch (ship->type) { X X case STYPE_MIRROR: X if (ship->orders.aimed_at.level==LEVEL_STAR) { X xt = Stars[ship->orders.aimed_at.snum]->xpos; X yt = Stars[ship->orders.aimed_at.snum]->ypos; X } else if (ship->orders.aimed_at.level==LEVEL_PLAN) { X if (ship->orders.aimed_at.pnum == where->pnum) { /* same planet */ X xt = Stars[ship->orders.aimed_at.snum]->xpos + pl->xpos; X yt = Stars[ship->orders.aimed_at.snum]->ypos + pl->ypos; X } else { /* different planet */ X openpdata(&pdata); X getplanet(pdata,&apl,Stars[where->snum]->planetpos[where->pnum]); X close(pdata); X xt = Stars[ship->orders.aimed_at.snum]->xpos + apl->xpos; X yt = Stars[ship->orders.aimed_at.snum]->ypos + apl->ypos; X free(apl); X } X } else if (ship->orders.aimed_at.level==LEVEL_SHIP) { X openshdata(&shipdata); X if (getship(shipdata,&aship,ship->orders.aimed_at.shipno)) { X xt = aship->xpos; X yt = aship->ypos; X } else X xt = yt = 0.0; X close(shipdata); X free(aship); X } X X slope = (xt - ship->xpos) / (yt - ship->ypos); X X if (yt - ship->ypos > 0) { X if (slope > 0) { X if (slope > 1) { X if (slope > 2) X wm = 0; X else X wm = 1; X } else { X if (slope > .5) X wm = 1; X else X wm = 2; X } X } else { X if (slope < -1) { X if (slope < -2) X wm = 0; X else X wm = 7; X } else { X if (slope < .5) X wm = 7; X else X wm = 6; X } X } X } else { X if (slope > 0) { X if (slope > 1) { X if (slope > 2) X wm = 4; X else X wm = 5; X } else { X if (slope > .5) X wm = 5; X else X wm = 6; X } X } else { X if (slope < -1) { X if (slope < -2) X wm = 4; X else X wm = 3; X } else { X if (slope < .5) X wm = 3; X else X wm = 2; X } X } X } X X DispArray(x,y, 9,5, Mirror[wm], X ship->whatorbits==LEVEL_UNIV ? (float)100.0 : X (ship->whatorbits==LEVEL_STAR ? (float)10.0 : X (ship->whatorbits==LEVEL_PLAN ? (float)1.0 :0))); X /* (magnification) */ X if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { X move(y,x+1); X printw("%d",shipnum); X } X break; X X case OTYPE_CANIST: X break; X X case OTYPE_VN: { register int n,xa,ya; X register float fac; X /* make a cloud of Von Neumann machines */ X fac = ship->orders.object.number / X ((ship->whatorbits==LEVEL_UNIV ? 100.0 : X (ship->whatorbits==LEVEL_STAR ? 30.0 : 4.0)) * Zoom); X for (n=1; n<=ship->orders.object.number && n<267; n++) { X xa = int_rand(x - (int)fac, x + (int)fac); X ya = int_rand(y - (int)(fac*S_Y/S_X), X y + (int)(fac*S_Y/S_X)); X if (xa>=0 && xa<=S_X && ya>=0 && ya<=S_Y) { X mvaddch(ya,xa, Shipltrs[ship->type]); X printw("%d",shipnum); X } X } X } X break; X X default: X if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { X mvaddch(y,x, Shipltrs[ship->type]); X printw("%d",shipnum); X } X break; X } X X X} X X X X/* display array on screen. at the moment magnification is not X * implemented. X */ XDispArray(x, y, maxx,maxy, array, mag) Xint x,y; Xint maxx,maxy; Xchar *array[]; Xfloat mag; X{ Xregister int x2,y2,curx,cury, Cx,Cy,cx,cy; X X for (cury=y-maxy/2,y2=0; y2= 0 && cury <= S_Y) { X move(cury, curx = x - maxx / 2 ); X for (x2=0; x2=0 && curx <= S_X) X if (inch()==' ') X addch( array[y2][x2] ); X else X move(cury, curx); /* one to right */ X x2++; X } X } X y2++; X } X X} END_OF_FILE if test 12715 -ne `wc -c <'orbit.c'`; then echo shar: \"'orbit.c'\" unpacked with wrong size! fi # end of 'orbit.c' fi echo shar: End of archive 1 \(of 7\). cp /dev/null ark1isdone MISSING="" for I in 1 2 3 4 5 6 7 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 7 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0