[comp.sources.games] v07i046: GB2 - Galactic Bloodshed, an empire-like war game [Ver. 1.0], Part03/08

billr@saab.CNA.TEK.COM (Bill Randle) (07/19/89)

Submitted-by: VANCLEEF@mps.ohio-state.edu
Posting-number: Volume 7, Issue 46
Archive-name: GB2/Part03



#! /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 3 (of 8)."
# Contents:  enrol.c exam.dat fire.c fix.c makeplanet.c misc.c
# Wrapped by billr@saab on Thu Jul  6 07:39:49 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'enrol.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'enrol.c'\"
else
echo shar: Extracting \"'enrol.c'\" \(8768 characters\)
sed "s/^X//" >'enrol.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X * enrol.c -- initializes to owner one sector and planet. 
X */
X
X#include "vars.h"
X#include "races.h"
X#include <signal.h>
X#include <strings.h>
X#include <curses.h>
X#include <errno.h>
Xextern int errno;
Xextern char desshow();
Xextern int Ignore_lockfile;
X
Xstruct stype {
X	char here;
X	char x,y;
X	int count;
X};
X
X/* compatibility schematic for sectors.  Note that plated sectors are
X   compatible with everything.  */
Xfloat Likes[DES_PLATED+1][DES_PLATED+1] = {
X               /* DES_SEA     DES_LAND   DES_MOUNT  DES_GAS DES_ICE DES_PLATED*/
X/*DES_SEA  */      1.0,        0.0,        0.0,       0.3,     0.05,    1.0,
X/*DES_LAND */      0.0,        1.0,        0.5,       0.0,     0.1,     1.0,
X/*DES_MOUNT*/      0.0,        0.5,        1.0,       0.0,     0.3,     1.0,
X/*DES_GAS  */      0.5,        0.0,        0.0,       1.0,     0.0,     1.0,
X/*DES_ICE  */      0.05,       0.15,       0.3,       0.0,     1.0,     1.0,
X/*DES_PLATED*/     1.0,        1.0,        1.0,       1.0,     1.0,     1.0
X};
X
Xchar *Desnames[] = {
X	"ocean",
X	"land",
X	"mountainous",
X	"gaseous",
X	"ice",
X	"plated",
X	"error in des type!",	/* (illegal values) */
X	"err in des type!"
X};
X
Xenroll(loginname)
Xchar *loginname;
X{
Xint x,y, or;
Xint pnum,star=0,found=0,i,j,enroll_pdata,
X	ifd, enroll_sectdata, enroll_stardata,mask,ppref = -1;
Xchar str[100], c;
Xsectortype *sect;
Xstruct stype secttypes[DES_PLATED+1];
Xplanettype *planet;
Xbool not_found[TYPE_GASGIANT+1];
XFILE *fd;
X
X
X if ( (Playernum=Numraces()+1) >= MAXPLAYERS) {
X	printf("There are already %d players; No more allowed.\n",Playernum);
X	exit(-1);
X }
X
X
X
X printf("There is still space for player %d.", Playernum);
X printf("\n\tenroll(y/n)\?");
X
X c = getchr(); getchr();
X if (c!='y') {
X	printf("why did you come here, then?\n");
X	endwin();
X	exit(0);
X }
X
X   /* look at enroll screen */
X sprintf(str, "%s %s", PAGER, ENROLL_FL);
X system(str);
X
X
X bzero((char *)not_found, sizeof(not_found));
X do {
X
X    printf("\nLive on what type planet:(e)arthtype, (g)asgiant, (a)irless, (i)ceball? ");
X    c = getchr(); getchr();
X    switch (c) {
X	case 'e': ppref = TYPE_EARTH;
X		 break;
X	case 'a': ppref = TYPE_AIRLESS;
X		 break;
X	case 'g': ppref = TYPE_GASGIANT;
X		 break;
X	case 'i': ppref = TYPE_ICEBALL;
X		 break;
X	default: printf("Oh well.\n");
X		 exit(-1);
X		 break;
X    }
X
X	/* find first planet of right type */
X  star = 0; found = 0;
X  while (!found && star<Sdata.numstars) {
X   for (or=i=0; i<howmanybytes(Playernum); i++ )
X	or |= Stars[star]->explored[i];
X	  /* make sure no one has explored the star */
X   if (!or) {
X	 pnum = 0;
X	 while (!found && pnum<Stars[star]->numplanets) {
X		openpdata(&enroll_pdata);
X		getplanet(enroll_pdata,&planet,Stars[star]->planetpos[pnum]);
X		if (planet->type==ppref) {
X			found = 1;
X		} else {
X			close(enroll_pdata);
X			free(planet);
X			pnum++;
X		}
X	 }
X   }
X   if (!found)
X	 star++;
X  }
X
X
X   if (!found) {
X	printf(" Uhoh, there don't seem to be any of that type of planet left.\n");
X	not_found[ppref] = 1;
X	for (found=1,i=TYPE_EARTH; i<=TYPE_GASGIANT; i++)
X		found &= not_found[i];
X	if (found) {
X	     printf("Looks like there aren't any free planets left.  bye..\n");
X	     endwin();
X	     exit(-1);
X	} else
X	     printf("  Try a different one...\n");
X	found = 0;
X   }
X
X } while (!found);
X
X Race = Malloc(racetype);
X Bzero(*Race);
X
X tty_off();
X printf("\n\nEnter a name for your race:");
X dots(RNAMESIZE);
X scanf("%[^\n]",str); 
X getchr();
X
X strncpy(Race->name, str, RNAMESIZE-1);
X
X Race->homelevel = Race->deflevel = LEVEL_PLAN;
X Race->homesystem = Race->defsystem = star;
X Race->homeplanetnum = Race->defplanetnum = pnum;
X
X	/* make conditions preferred by your people set to (more or less) 
X	   those of the planet : higher the concentration of gas, the higher
X	   percentage difference between planet and race */
X for (j=0; j<=OTHER; j++)
X	Race->conditions[j] = planet->conditions[j]; 
X	/*+ int_rand( round_rand(-planet->conditions[j]*2.0), round_rand(planet->conditions[j]*2.0) )*/
X
X
X for (i=0; i<MAXPLAYERS; i++) {
X   /* messages from autoreport, player #1 are decodable */
X	if (i==Playernum || i==1)
X		Race->translate[i] = 100;	/* you can talk to own race */
X	else
X		Race->translate[i] = 1;
X }
X
X  i = 5; found = 0;
X  tty_on();
X  do {
X	if (i<=0) {
X		printf("Too long.  bye\n");
X		tty_off();
X		exit(0);
X	}
X
X	Race->tech = 0;
X	Race->overbirthrate = float_rand() * 0.01;
X		/* your race is like "the Thing" */
X	if (Race->Thing = !int_rand(0,10) ) {
X		Race->mass = 1.0;
X		Race->birthrate = float_rand()*0.19 + 0.30;
X				/* (should be < 0.5) */
X		Race->fighters = int_rand(7,9);
X		Race->IQ = int_rand(50,80);
X		Race->nonhomebodies = 0.99;
X		Race->number_sexes = 1;
X		Race->metabolism = float_rand() * 0.25 + 0.52;
X	} else {
X		Race->birthrate = float_rand()*0.15 + 0.25;
X		Race->mass = 0.5 + 1.5 * float_rand();
X		Race->fighters = int_rand(1,3)+int_rand(1,3);
X		Race->IQ = int_rand(int_rand(140,175),int_rand(175,215));
X		Race->nonhomebodies = 0.70 + float_rand()*0.20;
X		Race->metabolism = float_rand() * 0.25 + 0.875;
X		Race->number_sexes = int_rand(1,int_rand(2,int_rand(3,9)));
X	}
X		     
X	clear();
X	move(0,0); 
X	printw("%s\n", Race->Thing ? "MESOMORPHIC" : "");
X	printw("       Birthrate: %.3f\n",Race->birthrate);
X	printw("Fighting ability: %d\n",Race->fighters);
X	printw("              IQ: %d\n",Race->IQ);
X	printw("      Metabolism: %.2f\n",Race->metabolism);
X	printw("    Adventurists: %.2f\n",Race->nonhomebodies);
X	printw("            Mass: %.2f\n",Race->mass);
X	printw(" Number of sexes: %d (min req'd for colonization)\n",Race->number_sexes);
X	printw("\n\n  (%d re-rolls left) * type spacebar ' ' to reroll	:", --i);
X	refresh();
X	if (getchr()!=' ')
X		found = 1;
X   } while (!found);
X   tty_off();
X
X bzero((char *)secttypes, sizeof(secttypes));
X
X opensectdata(&enroll_sectdata);
X getsmap(enroll_sectdata,Smap,planet);
X
X printf("\nChoose a primary sector preference.  Your race will prefer to live\non this type of sector.\n");
X
X PermuteSects(planet);
X Getxysect(planet, 0, 0, 1);
X while (Getxysect(planet,&x,&y,0)) {
X	secttypes[Sector(*planet,x,y).des].count++;
X	if (!secttypes[Sector(*planet,x,y).des].here)
X	  if ( !(planet->type==TYPE_GASGIANT && y<planet->Maxy-2 && y>0) ) {
X		secttypes[Sector(*planet,x,y).des].here = 1;
X		secttypes[Sector(*planet,x,y).des].x = x;
X		secttypes[Sector(*planet,x,y).des].y = y;
X	  }
X }
X
X Playernum = 1;
X planet->is_explored = 1;
X for (i=DES_SEA; i<=DES_PLATED; i++)
X	if (secttypes[i].here) {
X		Sector(*planet,secttypes[i].x,secttypes[i].y).is_wasted = 0;
X		printf("(%2d): %c  (%s, %d sectors)\n", i,
X		     desshow(planet, secttypes[i].x,secttypes[i].y),
X		     Desnames[i], secttypes[i].count);
X	}
X planet->is_explored = 0;
X
X printf("\nchoice (enter the number): ");
X found = 0;
X do {
X   scanf("%d", &i);
X   getchr();
X   if (i<DES_SEA || i>DES_PLATED || !secttypes[i].here) {
X	printf("There are none of that type here..\n");
X   } else
X	found = 1;
X } while (!found);
X
X sect = &Sector(*planet,secttypes[i].x,secttypes[i].y);
X Race->likesbest = i;
X for (j=DES_SEA; j<=DES_PLATED; j++)
X	Race->likes[j] = Likes[i][j];
X
X Playernum = Race->Playernum = Numraces() + 1;
X
X mask = sigblock(SIGINT | SIGQUIT | SIGSTOP);
X	/* create lock file that locks all file reads */
X if ( (ifd = open(LOCK_ALL, O_EXCL|O_CREAT, 0000) ) < 0) {
X	printf("whoops.. lock file already exists, please try again later..\n");
X	endwin();
X	exit(-1);
X }
X close(ifd);
X Ignore_lockfile = 1;
X
X putrace(Race);
X
X planet->info[Playernum-1].numsectsowned = 1;
X planet->is_explored = 0;
X planet->info[Playernum-1].explored = 1;
X planet->info[Playernum-1].autorep = 1;
X
X
X sect->owner = Playernum;
X sect->popn = planet->popn = Race->number_sexes * 5;
X sect->fert = 100;
X sect->eff = 10;
X planet->maxpopn = maxsupport(Race, sect, 100.0) 
X		* planet->Maxx * planet->Maxy / 2;
X			/* (approximate) */
X
X putsector(enroll_sectdata,sect,planet->sectormappos+(secttypes[i].y*planet->Maxx+secttypes[i].x)*sizeof(sectortype));
X close(enroll_sectdata);
X
X putplanet(enroll_pdata,planet,Stars[star]->planetpos[pnum]);
X close(enroll_pdata);
X
X	/* make star explored and stuff */
X openstardata(&enroll_stardata);
X  getstar(enroll_stardata,&Stars[star],star);
X   setbit(Stars[star]->explored,Playernum);
X   setbit(Stars[star]->inhabited,Playernum);
X   Stars[star]->AP[Playernum] = 5;
X  putstar(enroll_stardata,Stars[star],star);
X close(enroll_stardata);
X
X fd = fopen(PLAYERDATAFL,"a");
X fprintf(fd,"%s\n",loginname );
X fclose(fd);
X
X sigsetmask(mask);
X
X Ignore_lockfile = 0;
X unlink(LOCK_ALL);	/* get rid of lock file */
X
X printf("\nYou are player %d.\n\n",Playernum);
X printf("Your race has been created on sector %d,%d on\n",
X				secttypes[i].x,secttypes[i].y);
X printf("Planet %d of star %s.\n\n",pnum+1,Stars[star]->name);
X
X	/* chdir to your new home planet */
X docommand("cs");
X
X}
END_OF_FILE
if test 8768 -ne `wc -c <'enrol.c'`; then
    echo shar: \"'enrol.c'\" unpacked with wrong size!
fi
# end of 'enrol.c'
fi
if test -f 'exam.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'exam.dat'\"
else
echo shar: Extracting \"'exam.dat'\" \(9200 characters\)
sed "s/^X//" >'exam.dat' <<'END_OF_FILE'
X~
XSpore pod
X	This is a small seed pod grown by a mesomorphic race.  On reaching its
Xdestination, solar warming will cause it to explode, showering spores across 
Xthe system which have a chance of reaching some of the planets in that system.
X~
XShuttle
X	This is a small, short-range spacecraft, intended for interplanetary
Xexploration and for shuttling things between ground and orbit.  This ship is
Xalso useful for assembling other ships in space, as resources can be
Xtransferred from another shuttle using the load command until it is carrying
Xmore than the maximum cargo.  The shuttle, however, cannot take off or land
Xwith this extra cargo.  Shuttles are one of the few classes of ships that can
Xconstruct other ships.
X~
XDreadnaught
X	This is a well-armored but large (and slow due to it's mass) 
Xinterstellar warship.
X
X~
X
XBattleship
X	With its high armor class, this ship works well for general-purpose 
Xassaults.
X~
XInterceptor
X
X	This ship is designed to deliver relatively high fire power to
Xa hot spot quickly. It's like the "Porsche" of the battle fleet.
X
X~
XCruiser
X
X	This is a medium class escort/battle vessels. It is useful for
Xinterstellar excursions, reconnisance as well as fleet escort.
X
X~
XDestroyer
X	This is a well-protected and fast light cruiser, suitable for
Xescort.
X~
XFighter
X	A small fuel capacity and high armor class makes this ship ideal
Xfor in-system combat.
X~
XCargo ship
X	This is a long-range interstellar transport craft, with little
Xweapons or armor.
X~
XExplorer
X	This is a small and fast long-range exploration craft with almost no
Xweapons capacity but some armor.
X~
XTanker
X	This ship can carry large amounts of fuel; it can also receive more
Xfuel by orbiting a gas giant.
X~
X
XSpace Station
X
X	This is an orbital military installation useful as a military depot
Xas well as a planetary defense perimeter.
X
X
X~
X
XOrbital Assault Platform
X	This is a huge station-like construction, bristling with weapons.
XIts horribly impressive weaponry system makes it useful for enslaving 
Xrecalcitrant worlds (with the 'enslave' command).  It can also be used
Xfor constructing other ships as can shuttles and habitats, however it
Xcannot reproduce citizens or manufacture resources.
X	This device cannot be used to enslave.
X~
XGODSHIP
X	This entity pulsates, throbs with power.  Don't mess with it.
X~
XSpace mine
X	This device is a proximity mine, exploding on contact with enemy
Xships and showering them with deadly radiation.  It gives damage appropriate
Xto the amount of destructive capacity it is carrying.  Affected ships, when
Xirradiated, become immobile for a certain amount of time; each turn, an 
Xaffected ship's crew is reduced by about 10%.
X	The mine can be armed/disarmed with order, and its trigger radius 
X(0 <= trigger radius <= 200) also altered with the order command.  
X~
XSpace mirror
X	This is a large plane of reflecting material, suitable for altering 
Xthe ambient temperature of a planet if aimed at one.  Intensity can also
Xbe modified.  The mirror also has attitude jets for maneuvering.  
X
X~
X
XSpace Habitat
X	This is a residential platform, a space colony.  It can be used to
Xmanufacture other ships, as well as safeguard your race against extinction,
Xif you choose to send it into interstellar space as an insurance measure.
X	Habitats also have sophisticated manufacturing and refining
Xequipment, enabling the habitat to multiply resources it is carrying, in
Xproportion to the number of people staffing it.
X	Habitats are the only ships in which citizens feel comfortable 
Xenough to reproduce freely, although at a reduced rate because of the 
Xcrowded conditions.
X~
X
XSpace telescope
X	This is a space-based astronomical facility, with fuel and engines
Xfor launching it into orbit. it has a much longer range than a 
Xground-based telescope.
X
X~
XGround telescope
X	This is a ground-based astronomical facility.  It is able to survey
Xthe nearest planets for mapping purposes.
X
X~
XTractor/repulsor beam
X	When this device can be aimed at a ship or planet and activated,
Xit will attract/repel the other object.  Newton's Law, however, requires
Xthat the smaller of the two objects move more than the larger.
X	This is a non-functional device.
X~
XAtmosphere processor
X	This is a large machine (of the type in _Aliens_) that sucks in
Xthe atmosphere of a planet, converting it to the type of air preferred by its
Xowner.  This process has a cost of 4 fuel units per turn.
X~
XCanister of dust
X	This is a small canister of light-absorbing dust.  When launched it
Xwill spread into the atmosphere of the planet, lowering its ambient
Xtemperature.  This can be used to terraforming purposes, when the temperature
Xis too high for comfort.
X~
XV.Neumann machine
X	This machine exists to construct copies of itself.  This it will do,
Xresources permitting.  It seems capable of stealing resources from other 
Xplayers in the game, as well as manufacturing its own.  Von Neumann machines 
Xprefer to travel in wolfpacks of 20-50, and, unlike other ships, are capable
Xof making their own decisions.  First-generation Von Neumann machines can
Xbe ordered by the building player, but second-generation machines (built by 
Xother VN's) and above, may not be.
X~
XPlanet bomb
X	This device, when detomated, can destroy a planet.
X	This is a non-functional device.
X~
XCloaking device
X	This device uses an amount of fuel every turn to render whatever
Xcarries it invisible.  The higher the tech of the owning player, the greater
Xcloak radius, until whole systems can be cloaked.
X	This is a non-functional device.
X~
Xemotion suppressor
XOrbital Mind-control laser
X	This device, when aimed at a ship, produces resonating vibrations
Xwithin the ship's hull, to cause the mental attitude of the crew to
Xbe altered.  The crew's response to influence is dependant on the
Xarmor of the affected ship, becoming more and more difficult for the
Xvibrations to be produced as the target ship's armor increases.  The laser has
Xa range similar to the player's gun range.
X	Response can be toggled by the "desired response" register
Xin the order command: from convincing the crew to trigger their aggressive
Xresponse and kill each other, to converting them to sympathy for your
Xrace and its motivations; each response has a percentage chance of
Xconversion.
X	The orbital mind-control lasers are currently only effective on
Xplanets, and have one setting: to suppress emotion, which causes no fighting
Xor migrations to take place.
X~
X
XToxic Waste Container
X	This is a sealed container used to store environmental poisons.
XWhen toxicity of a planet becomes too high, constructing one of these
Xcontainers will reduce the poison level by 20%.  If the container is
Xbreached, however, the toxic waste inside it will escape.
X
X~
X
XAmulet of Yendor
X	This is a brilliant necklace of obvious power.
X	This is a non-functional device.
X~
Xgamma ray laser
X	This device fires a deadly stream of radiation at its target when
Xfired.  It uses destructive capacity in the same manner other ships use it
Xfor their guns.  Radiation is not accumulated in target ships; if a ship's
Xradiation level is 10, a more powerful shot from the laser may increase the
Xradiation level.  A weaker shot will have no effect at all.
X~
XSpace Amoeba
X	This viscious creature inhabits the vacuum of space, moving slowly
Xfrom one solar system to another in search of yummy planets to digest.
XOnce established on a planet, its voracious appetite consumes it quickly,
Xsometimes bloating the amoeba enough that it can divide and produce another
Xof its kind.  Space Amoebae are difficult creatures to deal with, but rumor
Xhas it they can be driven off, and even controlled to some extent...
X~
XGround Transport fleet
X	This represents a massive building effort on the part of your
Xrace, to construct surface transportation devices.  A fleet such as this
Xcan represent anything from crude ox carts to the latest model turbobus,
Xdepending on the tech at which it is constructed.  This fleet can not, of
Xcourse, leave the planet by any means, but it can rove the surface far and
Xwide, possibly distributing citizens as it goes.  It can more over the 
Xfollowing sector types: land, mountainous, plated, and ice, and can move
Xinto others that border one of these sector types.  It uses 1 fuel point
Xto move.
X	This is a non-functional device.
X~
XOceanic Transport fleet
X	This is an equivalent to the ground transport fleet, however it
Xrepresents a fleet of ocean-going ships.  This fleet can only move over
Xwater, at a cost of 1 fuel point, however it can 'dock' with a different
Xtype of sector, as long as it borders an ocean sector.
X	This is a non-functional device.
X~
XDirigible Transport fleet
X	This is a fleet of lighter-than-air vehicles.  It costs more resources
Xto assemble and cannot hold as much as the other planetary transport types,
Xbut it is free to roam over the surface of any planet (provided, of course,
Xthat planet has an atmosphere).
X	This is a non-functional device.
X~
Xaudio-vibatory-physio-molecular transport device
X	This device has a hopper for the loading of material.  When it detects
Xthe presence of something in the hopper, it will transport this material into
Xthe hopper of its target device.  This process takes fuel.  The target device
Xcan be specified with the order command.
X~
END_OF_FILE
if test 9200 -ne `wc -c <'exam.dat'`; then
    echo shar: \"'exam.dat'\" unpacked with wrong size!
fi
# end of 'exam.dat'
fi
if test -f 'fire.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fire.c'\"
else
echo shar: Extracting \"'fire.c'\" \(8840 characters\)
sed "s/^X//" >'fire.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@ucscb.ucsc.edu)
X * fire.c -- fire at ship or planet from ship or planet
X */
X
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include <signal.h>
X#include <setjmp.h>
Xextern char telegram_buf[AUTO_TELEG_SIZE];
Xextern jmp_buf main_jenv;
Xint fire_fromshdata,fire_toshdata,
X    fire_frompdata,fire_topdata,fire_sectdata;
X
Xextern bool Nuked[MAXPLAYERS];
X
Xfire(APcount, argn,args)
Xint APcount;
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xplacetype from,to;
Xplanettype *fpl,*tpl;
Xsectortype *sect;
Xint dam=0,dam2=0,strength,oldstrength,maxstrength,
X    i,from_firex= -1,from_firey= -1,firex= -1,firey= -1,Numplayersretaliate=0;
Xfloat dist;
Xchar string[PLACENAMESIZE],buf[200];
Xchar shoot_msg[1000], retal_msg[1000];
Xbool sameplanet = 0, fromplanetmod=0,toplanetmod=0;
Xint mask;
Xint fire_handler();
X
X
Xfire_fromshdata = fire_toshdata = fire_frompdata = fire_topdata = 
X		fire_sectdata = NEUTRAL_FD;
Xsignal(SIGINT, fire_handler);
X
X	/* for telegramming and retaliating */
X bzero( (char *)Nuked, sizeof(Nuked) );
X
X	/***** get place we are firing from *****/
X
X if (argn!=4) {
X   printf("fire (from) ship or planet ");
X   scanf("%35s",string);
X } else sscanf(args[1],"%35s",string);
X
X from = Getplace(string,0);
X
X if (from.err && from.level!=LEVEL_SHIP) { 
X	printf("usage: fire\n");
X	return; 
X }
X if (from.level == LEVEL_UNIV || from.level == LEVEL_STAR) {
X    printf("You can't shoot from there.\n");
X    fire_handler();
X } else if (from.level == LEVEL_SHIP) {
X    if (from.err || from.shipptr->owner != Playernum) {
X	DontOwnErr();
X	return;
X    }
X    free(from.shipptr);		/* erase/get ship again to lock ship file */
X    openshdata(&fire_fromshdata);
X    getship(fire_fromshdata,&(from.shipptr),from.shipno);
X
X    if (testship(from.shipptr, from.shipno))
X	fire_handler();
X
X     /* check for APs */
X    if (from.shipptr->whatorbits==LEVEL_UNIV) {
X	if (!enufAP(Sdata.AP, APcount) )
X		fire_handler();
X    } else
X	if (!enufAP(Stars[from.shipptr->storbits]->AP, APcount) )
X			fire_handler();
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(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]);
X
X   if (!enufAP(Stars[from.snum]->AP, APcount) ) 
X		fire_handler();
X
X   if (fpl->info[Playernum-1].destruct == 0) {
X	printf("No weapons available.\n");
X	fire_handler();
X   }
X
X     /* get a sector the enemy place can retaliate to. */
X
X   do {
X
X     printf("Fire from");
X     from_firex = -1;
X     GetMapSector(fpl, &from_firex,&from_firey);
X
X	opensectdata(&fire_sectdata);
X	getsector(fire_sectdata, &sect, fpl->sectormappos+(from_firey*fpl->Maxx+from_firex)*sizeof(sectortype) );
X	close(fire_sectdata);
X
X      if (sect->owner!=Playernum)	/* has to be yours */
X	   printf("You don't own that sector.\n");
X
X   } while (sect->owner!=Playernum);
X
X   free(sect);
X
X } else {
X	printf("You can't shoot from there.\n");
X	return;
X }
X
X
X  /******* get target *******/
X
X
X if (argn!=4) {
X   printf("fire (at) ship or planet ");
X   scanf("%35s",string);
X } else sscanf(args[2],"%35s",string);
X
X Locks(1);
X to = Getplace(string,1);
X Locks(0);
X
X if (to.err)
X	fire_handler();
X
X
X if (to.level==LEVEL_SHIP) {
X	if (from.level==LEVEL_SHIP) {
X		if (from.shipno == to.shipno) {
X			printf("You can't do that.\n");
X			fire_handler();
X		} else
X			Locks(1);	/* ship file will already be locked */
X	}
X		/* get ship again */
X	openshdata(&fire_toshdata);
X	free(to.shipptr);
X	(void)getship(fire_toshdata, &(to.shipptr), to.shipno);
X	Locks(0);
X
X	if (to.shipptr->is_dead) {
X		printf("that ship has already been destroyed.\n");
X		fire_handler();
X	}
X
X	if (to.shipptr->is_docked && to.shipptr->whatdest==LEVEL_PLAN) {
X			Locks(1);
X			openpdata(&fire_topdata);
X			getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
X			close(fire_topdata);
X			Locks(0);
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		   sameplanet = 1;
X		   tpl = fpl;
X		} else
X		   Locks(1);
X	}
X
X	if (!sameplanet) {
X		openpdata(&fire_topdata);
X		getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
X	}
X	Locks(0);
X
X	 /* ask user for sector of planet to shoot at */
X    	printf("Aim at");
X    	firex = -1;
X    	GetMapSector(tpl, &firex, &firey);
X
X } else {
X	printf("You can't shoot at that.\n");
X	fire_handler();
X }
X
X
X	/* prompt if hes your ally */
X  if ( to.level==LEVEL_SHIP && isset(Race->allied, to.shipptr->owner) ) {
X	tty_on();
X	printf("Fire on your ally? (y/n)");
X	if (getchr()!='y') {
X		fire_handler();
X	}
X	tty_off();
X  }
X
X  maxstrength = (from.level==LEVEL_SHIP) ? 
X		MIN(from.shipptr->destruct,   
X			Shipdata[from.shipptr->type][ABIL_GUNS]*(100-from.shipptr->damage)/100.) :
X		MIN(fpl->info[Playernum-1].destruct, PLAN_FIRE_LIM);
X
X if (argn!=4) {
X    printf("strength (max %d):",maxstrength );
X    scanf("%d",&strength);
X    getchr();
X } else sscanf(args[3],"%d",&strength);
X if (strength>maxstrength) {
X	printf("Too large.\n");
X   	fire_handler();
X } else if (strength<=0) {
X   	printf("wimp.\n");
X   	fire_handler();
X }
X
X	/* block kill signals to foil cheaters */
X mask = sigblock(SIGINT | SIGQUIT | SIGSTOP);
X
X dam = shoot(from,&to,fpl,tpl,firex,firey,strength, &dist, shoot_msg,
X		1 );	/*1==get smap*/
X printf("Distance to target: %.0f, maximum distance: %d.\n",dist, SYSTEMSIZE);
X if (dam < 0) {
X	printf("Target out of range!\n", SYSTEMSIZE);
X	fire_handler();
X }
X
X if (from.level==LEVEL_SHIP) {
X	from.shipptr->destruct -= strength;
X	from.shipptr->mass -= strength*MASS_DESTRUCT;
X } else if (from.level==LEVEL_PLAN) 
X	fpl->info[Playernum-1].destruct -= strength;
X
X
X  /* enemy retaliates (if he can) */
X
X	strength = 0;
X if ( to.level==LEVEL_SHIP ) {
X	strength = MIN(to.shipptr->destruct,Shipdata[to.shipptr->type][ABIL_GUNS] *(100-to.shipptr->damage)/100.);
X
X	to.shipptr->destruct -= strength;
X	to.shipptr->mass -= strength*MASS_DESTRUCT;
X
X } else if (to.level==LEVEL_PLAN) {	/* all players owning planet retal */
X
X    int strength2;
X	oldstrength = strength;
X	strength = 0;
X	for (i=1; i<MAXPLAYERS; i++)
X	   if (tpl->info[i-1].destruct>0 && i!=Playernum && Nuked[i]) {
X	     strength2 = MIN(oldstrength, tpl->info[i-1].destruct);
X	     if (strength2 > PLAN_FIRE_LIM)
X		strength2 = PLAN_FIRE_LIM;
X	     tpl->info[i-1].destruct -= strength2;
X	     strength += strength2;
X	     Numplayersretaliate++;
X	     printf("Player %d returns fire, strength %d.\n", i, strength2);
X	   }
X }
X
X	/* enemy fires at shooting sector */
X if ( !(to.level==LEVEL_SHIP && to.shipptr->is_dead) )
X	dam2=0;
X 	if(strength>0)dam2 = shoot(to,&from,tpl,fpl,from_firex,from_firey,strength, &dist, 
X		retal_msg, 1);
X
X
X if (from.level==LEVEL_PLAN) {
X 	putplanet(fire_frompdata,fpl,Stars[from.snum]->planetpos[from.pnum]);
X	close(fire_frompdata);
X
X } else if (from.level==LEVEL_SHIP) {
X	putship(fire_fromshdata,from.shipptr,from.shipno);
X	close(fire_fromshdata);
X }
X
X
X if (to.level==LEVEL_PLAN && !sameplanet) {
X 	putplanet(fire_topdata,tpl,Stars[to.snum]->planetpos[to.pnum]);
X	close(fire_topdata);
X
X } else if (to.level==LEVEL_SHIP) {
X	putship(fire_toshdata,to.shipptr,to.shipno);
X	close(fire_toshdata);
X }
X
X
X
X printf("BO\007OM!!\n%s", shoot_msg);
X
X teleg_add("",telegram_buf);
X sprintf(buf," BULLETIN from %s\n\n",Dispplace(&from));
X teleg_add(buf,telegram_buf);
X sprintf(buf,"%s%s ",from.level==LEVEL_SHIP ? "ship " : "", Dispplace(&from));
X teleg_add(buf,telegram_buf);
X if (to.level==LEVEL_SHIP)
X    sprintf(buf,"fired on ship #%u @ %s;\n", to.shipno,
X			prin_ship_orbits(to.shipptr));
X else
X    sprintf(buf,"fired on planet %s;\n", Dispplace(&to));
X
X teleg_add(buf,telegram_buf);
X  /* add telegram message */
X teleg_add(shoot_msg, telegram_buf);
X
X for (i=1; i<MAXPLAYERS; i++)
X    if (Nuked[i] && i!=Playernum)
X	 teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf);
X
X
X if (dam2 > 0) {
X   	printf("%s retaliates with %sstrength %d!!\n", Dispplace(&to), 
X		Numplayersretaliate>1 ? "total " : "", strength, dam2);
X	puts(retal_msg);
X
X } else printf("%s cannot retaliate.\n",Dispplace(&to) );
X
X
X if (from.level==LEVEL_PLAN) {
X   /* firing from planet -- deduct APs from that star */
X 	deductAPs(APcount, from.snum, 0);
X	free(fpl);
X } else {
X		/* from.level==LEVEL_SHIP */
X	if (from.shipptr->whatorbits==LEVEL_UNIV)
X		deductAPs(APcount, 0, 1);
X	else {
X	 	deductAPs(APcount, from.shipptr->storbits, 0);
X	}
X	free(from.shipptr);
X }
X
X
X sigsetmask(mask);	/* reset mask */
X
X}
X
X
X
Xfire_handler()
X{
X tty_off();
X close(fire_fromshdata);
X close(fire_toshdata);
X close(fire_frompdata);
X close(fire_topdata);
X close(fire_sectdata);
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 8840 -ne `wc -c <'fire.c'`; then
    echo shar: \"'fire.c'\" unpacked with wrong size!
fi
# end of 'fire.c'
fi
if test -f 'fix.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fix.c'\"
else
echo shar: Extracting \"'fix.c'\" \(12399 characters\)
sed "s/^X//" >'fix.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X *	fix.c -- allows manager to edit various stuff.
X *		   -not to be used by players cuz it will get boring fast
X *			note: may not work under machines w/ 
X *				sizeof(int) <> sizeof(float).
X */
X
X#define FLOAT 0	/* to tell query what to input for */
X#define INT 1
X#define CHAR 2
X#define SHORT 3
X#define LONG 4
X#define DOUBLE 5
X
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include <strings.h>
X#include <ctype.h>
X#include <signal.h>
X#include <setjmp.h>
Xextern jmp_buf main_jenv;
Xint fix_stardata,fix_shdata,fix_pdata,fix_sectdata;
Xchar s[40];
Xextern char *Shipnames[];
X
Xbool fix_mod;
X
Xfix(argn,args)
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xchar ch;
Xint i;
Xunsigned long unl;
Xplanettype *p;
Xsectortype *sect;
Xshiptype *sh;
Xint fix_handler();
X
Xfix_mod = 0;
Xfix_stardata = fix_shdata = fix_pdata = fix_sectdata = NEUTRAL_FD;
X	/* so closure does not cause wanted files to close (like stdin 
X		or stdout) -- should not cause probs most vers. of UNIX */
Xsignal(SIGINT, fix_handler);
X
X
Xif (argn==2 && !strcmp(args[1],"race")) {
X	query(FLOAT,"tech",&Race->tech,0,0,0,0);
X	query(FLOAT,"birthrate",&Race->birthrate,0,0,0,0);
X	query(FLOAT,"mass",&Race->mass,0,0,0,0);
X	query(FLOAT,"adventurists",&Race->nonhomebodies,0,0,0,0);
X	query(FLOAT,"metabolism",&Race->metabolism,0,0,0,0);
X	query(FLOAT,"overbirthrate",&Race->overbirthrate,0,0,0,0);
X	query(INT, "Playernum",0,&Race->Playernum,0,0,0);
X	query(CHAR, "fighters",0,0,&Race->fighters,0,0);
X	query(CHAR, "IQ",0,0,&Race->IQ,0,0);
X	query(CHAR, "# sexes",0,0,&Race->number_sexes,0,0);
X	query(CHAR, "likesbest",0,0,&Race->likesbest,0,0);
X	  ch = Race->Thing;
X	query(CHAR, "Race is like 'The Thing'",0,0,&ch,0,0);
X	  Race->Thing = ch;
X	    /*float metabolism;*/
X	    /*char homelevel,homesystem,homeplanetnum;	/* home place */
X	printf("atmospheric cond preferred\n");
X	query(CHAR, "Temp",0,0,&Race->conditions[TEMP],0,0);
X	query(CHAR, "Rtemp",0,0,&Race->conditions[RTEMP],0,0);
X	query(CHAR, "Methane",0,0,&Race->conditions[METHANE],0,0);
X	query(CHAR, "Oxygen",0,0,&Race->conditions[OXYGEN],0,0);
X	query(CHAR, "CO2",0,0,&Race->conditions[CO2],0,0);
X	query(CHAR, "Hydrogen",0,0,&Race->conditions[HYDROGEN],0,0);
X	query(CHAR, "Nitrogen",0,0,&Race->conditions[NITROGEN],0,0);
X	query(CHAR, "Sulfur",0,0,&Race->conditions[SULFUR],0,0);
X	query(CHAR, "Helium",0,0,&Race->conditions[HELIUM],0,0);
X	query(CHAR, "Other",0,0,&Race->conditions[OTHER],0,0);
X	if (fix_mod)
X		putrace(Race);
X} else {
X
X switch (Dir.level) {
X
X  case LEVEL_UNIV:
X	openstardata(&fix_stardata);
X	getsdata(fix_stardata, &Sdata);
X
X	query(CHAR, "ActionPoints",0,0,&Sdata.AP[Playernum],0,0);
X	query(SHORT, "shiplist start",0,0,0,&Sdata.ships,0);
X	/*for (ch=MAXUSHIPS-1; ch>1 && Sdata.shipnums[ch]; ch--) ;
X	printf("last ship slot is %d\n",ch);
X	for (i=0; i<=ch && i<MAXUSHIPS; i++) {
X		   printf("Ship slot #%d is ",i);
X		   query(SHORT, "ship number",0,0,0,&Sdata.shipnums[i],0);
X	}*/
X	if (fix_mod) {
X		printf("Saving...\n");
X		putsdata(fix_stardata, &Sdata);
X	}
X	close(fix_stardata);
X	break;
X
X  case LEVEL_STAR:
X	openstardata(&fix_stardata);
X	getstar(fix_stardata, &Stars[Dir.snum], Dir.snum);
X
X	printf("Star #%d : %s\n\n", Dir.snum, Stars[Dir.snum]->name );
X
X	query(SHORT, "shiplist start",0,0,0,&Stars[Dir.snum]->ships,0);
X	query(CHAR, "ActionPoints",0,0,&Stars[Dir.snum]->AP[Playernum],0,0);
X
X	query(FLOAT,"x position",&Stars[Dir.snum]->xpos,0,0,0,0);
X	query(FLOAT,"y position",&Stars[Dir.snum]->ypos,0,0,0,0);
X	query(CHAR, "stability",0,0,&Stars[Dir.snum]->stability,0,0);
X	ch = !!isset(Stars[Dir.snum]->explored, Playernum);
X	  query(CHAR, "explored",0,0,&ch,0,0);
X	if (ch)
X		setbit(Stars[Dir.snum]->explored, Playernum);
X	ch = !!isset(Stars[Dir.snum]->inhabited, Playernum);
X	  query(CHAR, "inhabited",0,0,&ch,0,0);
X	if (ch)
X		setbit(Stars[Dir.snum]->inhabited, Playernum);
X	ch = Stars[Dir.snum]->nova_stage;
X	query(CHAR, "nova stage",0,0,&ch,0,0);
X		Stars[Dir.snum]->nova_stage = ch;
X	 printf("(limit %d) ",MAXPLANETS);
X	query(CHAR, "# planets",0,0,&Stars[Dir.snum]->numplanets,0,0);
X	for (i=0; i<Stars[Dir.snum]->numplanets; i++) {
X		printf("Planet #%d (%s) ", i, Stars[Dir.snum]->pnames[i]);
X		query(INT, "file position",0,&Stars[Dir.snum]->planetpos[i],0,0,0);
X	}
X
X	if (fix_mod) {
X		putstar(fix_stardata, Stars[Dir.snum], Dir.snum);
X		printf("Saving...\n");
X	}
X	close(fix_stardata);
X	break;
X
X  case LEVEL_PLAN:
X
X	openpdata(&fix_pdata);
X	getplanet(fix_pdata, &p, Stars[Dir.snum]->planetpos[Dir.pnum]);
X
X
X	if (argn==1) {
X		printf("\nPlanet / %s / %s\n", Stars[Dir.snum]->name, Stars[Dir.snum]->pnames[Dir.pnum]);
X		unl = p->info[Playernum-1].resource;
X		query(LONG, "\nstockpile resources",0,0,0,0,&unl);
X			p->info[Playernum-1].resource = unl;
X		unl = p->info[Playernum-1].destruct;
X		query(LONG, "stockpile destruct",0,0,0,0,&unl);
X			p->info[Playernum-1].destruct = unl;
X		unl = p->info[Playernum-1].fuel;
X		query(LONG, "stockpile fuel",0,0,0,0,&unl);
X			p->info[Playernum-1].fuel = unl;
X		unl = p->popn;
X		query(LONG, "total population(altered after turn)",0,0,0,0,&unl);
X			p->popn = unl;
X
X	i=p->info[Playernum-1].numsectsowned;
X	query(INT, "numsectsowned",0,&i,0,0,0);
X		p->info[Playernum-1].numsectsowned = i; 
X
X		ch = p->info[Playernum-1].explored;
X		query(CHAR, "explored",0,0,&ch,0,0);
X		  p->info[Playernum-1].explored = ch;
X		 printf("atmospheric cond\n");
X		query(CHAR, "Temp",0,0,&p->conditions[TEMP],0,0);
X		query(CHAR, "Rtemp",0,0,&p->conditions[RTEMP],0,0);
X		query(CHAR, "Methane",0,0,&p->conditions[METHANE],0,0);
X		query(CHAR, "Oxygen",0,0,&p->conditions[OXYGEN],0,0);
X		query(CHAR, "CO2",0,0,&p->conditions[CO2],0,0);
X		query(CHAR, "Hydrogen",0,0,&p->conditions[HYDROGEN],0,0);
X		query(CHAR, "Nitrogen",0,0,&p->conditions[NITROGEN],0,0);
X		query(CHAR, "Sulfur",0,0,&p->conditions[SULFUR],0,0);
X		query(CHAR, "Helium",0,0,&p->conditions[HELIUM],0,0);
X		query(CHAR, "Other",0,0,&p->conditions[OTHER],0,0);
X		query(CHAR, "Toxicity",0,0,&p->conditions[TOXIC],0,0);
X
X		query(SHORT, "shiplist start",0,0,0,&p->ships,0);
X		 /*printf("(limit %d) ", MAX_X);
X		query(CHAR, "sectormap size x",0,0,&p->Maxx,0,0);*/
X		 /*printf("(limit %d) ", MAX_Y,0);
X		query(CHAR, "sectormap size y",0,0,&p->Maxy,0,0);*/
X		query(INT, "sect map file position",0,&p->sectormappos,0,0,0);
X		query(FLOAT,"x position",&p->xpos,0,0,0,0);
X		query(FLOAT,"y position",&p->ypos,0,0,0,0);
X		/*ch = p->slaved_to;
X		query(CHAR, "enslaved to player #",0,0,&ch,0,0);
X			p->slaved_to = ch;*/
X		/*ch = p->is_cloaked;
X		query(CHAR, "cloaked",0,0,&ch,0,0);
X		  p->is_cloaked = !!ch;*/
X
X		ch = p->type;
X		query(CHAR, "planet type",0,0,&ch,0,0);
X		  p->type = ch;
X		ch = p->info[Playernum-1].comread;
X		query(CHAR, "combat readiness",0,0,&ch,0,0);
X		  p->info[Playernum-1].comread = ch;
X		ch = p->is_explored;
X		query(CHAR, "is_explored by owner",0,0,&ch,0,0);
X		  p->is_explored = !!ch;
X		query(CHAR, "rotate timer",0,0,&p->rottimer,0,0);
X
X		if (fix_mod) {
X			putplanet(fix_pdata, p, Stars[Dir.snum]->planetpos[Dir.pnum]);
X			printf("Saving...\n");
X		}
X		close(fix_pdata);
X
X	} else {
X			/* fix sector */
X		int x,y;
X		close(fix_pdata);
X		sscanf(args[1],"%d,%d", &x, &y);
X		printf(" sector %d,%d\n",x,y);
X		opensectdata(&fix_sectdata);
X		getsector(fix_sectdata,&sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
X
X		ch = sect->eff;
X		query(CHAR, "efficiency",0,0,&ch,0,0);
X		  sect->eff = ch;
X		ch = sect->resource;
X		query(CHAR, "resource deposits",0,0,&ch,0,0);
X		  sect->resource = ch;
X		ch = sect->fert;
X		query(CHAR, "fertility",0,0,&ch,0,0);
X		  sect->fert = ch;
X		ch = sect->mobilization;
X		query(CHAR, "mobilization",0,0,&ch,0,0);
X		  sect->mobilization = ch;
X		printf("(limit %d)",MAX_SECT_POPN);
X		i = sect->popn;
X		query(INT, "population",0,&i,0,0,0);
X		  sect->popn = i;
X		i = sect->owner;
X		query(INT, "owner",0,&i,0,0,0);
X		  sect->owner = i;
X		ch = sect->is_wasted;
X		query(CHAR, "is_wasted",0,0,&ch,0,0);
X		  sect->is_wasted = !!ch;
X		ch = sect->des;
X		query(CHAR, "designation",0,0,&ch,0,0);
X		  sect->des = ch;
X		ch = sect->amoeba;
X		query(CHAR, "infected by amoeba",0,0,&ch,0,0);
X		  sect->amoeba = !!ch;
X	    /*unsigned is_cloaked : 1;	/* 1 bit: is cloaked sector */
X		if (fix_mod) {
X			putsector(fix_sectdata,sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
X			printf("Saving...\n");
X		}
X		close(fix_sectdata);
X	}
X	free(p);
X	break;
X
X  case LEVEL_SHIP:
X	openshdata(&fix_shdata);
X	getship(fix_shdata, &sh, Dir.shipno);
X
X	printf("\n%s #%d.\n", Shipnames[sh->type], Dir.shipno);
X
X	ch = sh->owner;
X	query(CHAR, "owner",0,0,&ch,0,0);
X		sh->owner = ch;
X	query(FLOAT,"x position",&sh->xpos,0,0,0,0);
X	query(FLOAT,"y position",&sh->ypos,0,0,0,0);
X	query(FLOAT,"mass",&sh->mass,0,0,0,0);
X
X	query(FLOAT,"fuel",&sh->fuel,0,0,0,0);
X	 unl = sh->destruct;
X	query(LONG, "destruct cap",0,0,0,0,&unl);
X	 sh->destruct = unl;
X	 unl = sh->resource;
X	query(LONG, "resource",0,0,0,0,&unl);
X	 sh->resource = unl;
X	 unl = sh->popn;
X	query(LONG, "crew",0,0,0,0,&unl);
X	 sh->popn = unl;
X
X	 unl = sh->rad;
X	query(LONG, "irradiated",0,0,0,0,&unl);
X	 sh->rad = unl;
X	 unl = sh->damage;
X	query(LONG, "damage",0,0,0,0,&unl);
X	 sh->damage = unl;
X
X	ch = sh->whatorbits;
X	query(CHAR, "what orbits level",0,0,&ch,0,0);
X	  sh->whatorbits = ch;
X	query(CHAR, "orbits what star ",0,0,&sh->storbits,0,0);
X	ch = sh->pnumorbits;
X	query(CHAR, "orbits what planet",0,0,&ch,0,0);
X	  sh->pnumorbits = ch;
X	ch = sh->whatdest;
X	query(CHAR, "what destination level",0,0,&ch,0,0);
X	  sh->whatdest = ch;
X	query(CHAR, "what star dest",0,0,&sh->deststar,0,0);
X	ch = sh->destpnum;
X	query(CHAR, "what planet dest",0,0,&ch,0,0);
X	  sh->destpnum = ch;
X	query(SHORT, "what ship dest",0,0,0,&sh->destshipno,0);
X	ch = sh->is_dead;
X	query(CHAR, "is dead",0,0,&ch,0,0);
X	  sh->is_dead = !!ch;
X	ch = sh->notified;
X	query(CHAR, "notified",0,0,&ch,0,0);
X	  sh->notified = !!ch;
X	ch = sh->is_docked;
X	query(CHAR, "is docked",0,0,&ch,0,0);
X	  sh->is_docked = !!ch;
X	query(SHORT, "nextship",0,0,0,&sh->nextship,0);
X	/*query(SHORT, "abil_cargo",0,0,0,&sh->abils[ABIL_CARGO],0);
X	query(SHORT, "abil_stealth",0,0,0,&sh->abils[ABIL_STEALTH],0);
X	query(SHORT, "abil_destruct cap",0,0,0,&sh->abils[ABIL_DESTCAP],0);
X	query(SHORT, "abil_num guns",0,0,0,&sh->abils[ABIL_GUNS],0);
X	query(SHORT, "abil_fuel cap",0,0,0,&sh->abils[ABIL_FUELCAP],0);
X	query(SHORT, "abil_tech level",0,0,0,&sh->abils[ABIL_MINTECH],0);
X	query(SHORT, "abil_max crew",0,0,0,&sh->abils[ABIL_MAXCREW],0);
X	query(SHORT, "abil_armor",0,0,0,&sh->abils[ABIL_ARMOR],0);*/
X
X	if (is_object(sh)) {
X	  query(SHORT, "object:number",0,0,0,&sh->orders.object.number,0);
X	  query(SHORT, "object:number2",0,0,0,&sh->orders.object.number2,0);
X	}
X
X	if (fix_mod) {
X		printf("Saving...\n");
X		putship(fix_shdata, sh, Dir.shipno);
X	}
X	close(fix_shdata);
X	break;
X
X
X    /*ordertype orders;		/* standing orders for ship */
X    /*unsigned augmented : 4;	/* # of times augmented (max 10) */
X    /*unsigned whatdest : 2;	/* where going (same as Dir) */
X    /*unsigned whatorbits : 2;	/* where orbited (same as Dir) */
X    /*unsigned type : 4;		/* what type ship is */
X    /*unsigned is_sheep : 1;	/* 1 bit: is under influence of mind control */
X    /*unsigned is_docked : 1;	/* 1 bit: is landed on a planet or docked */
X    /*unsigned has_moved : 1;	/* 1 bit: has been moved by user */
X    /*unsigned outtafuel_notified:1; /* 1bit: has been notified of no fuel */
X
X
X }
X}
X
X
X}
X
X
Xquery( kind, quest, fprev, iprev, cprev, sprev, lprev)
Xint kind;
Xchar *quest;
Xfloat *fprev;
Xint *iprev;
Xchar *cprev;
Xshort *sprev;
Xlong *lprev;
X{
X float f;
X int i;
X char c,ch;
X short s;
X long l;
X
X printf("%s (", quest);
X switch (kind) {
X  case FLOAT:
X	printf("%f", *fprev);
X	break;
X  case INT:
X	printf("%d", *iprev);
X	break;
X  case CHAR:
X	printf("%d", *cprev);
X	break;
X  case SHORT:
X	printf("%d", *sprev);
X	break;
X  case LONG:
X	printf("%ld", *lprev);
X	break;
X }
X printf(") : ");
X
X if ( isdigit(ch=getchr()) || ch=='-' || ch=='.') {
X	ungetc(ch, stdin);
X	fix_mod = 1;	/* set mod so fix knows to save data */
X	switch (kind) {
X	 case FLOAT:
X		scanf("%f",fprev);
X		break;
X	 case INT:
X		scanf("%d",iprev);
X		break;
X	 case CHAR:
X		scanf("%d",&i);
X		*cprev = i;  /* don't want to copy a whole int's worth */
X		break;
X	 case SHORT:
X		scanf("%hd",sprev);
X		break;
X	 case LONG:
X		scanf("%ld",lprev);
X		break;
X	}
X	getchr();
X  }
X}
X
X
X
X
Xfix_handler()
X{
X close(fix_stardata);
X close(fix_shdata);
X close(fix_pdata);
X close(fix_sectdata);
X printf("changes not saved!\n");
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 12399 -ne `wc -c <'fix.c'`; then
    echo shar: \"'fix.c'\" unpacked with wrong size!
fi
# end of 'fix.c'
fi
if test -f 'makeplanet.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makeplanet.c'\"
else
echo shar: Extracting \"'makeplanet.c'\" \(11295 characters\)
sed "s/^X//" >'makeplanet.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X *	makeplanet.c -- makes one planet.  used with makeuniv
X */
X
X#define MAP_ISLANDS 10		/* # of beginning islands for makeuniv */
X#define MAP_MOUNT_PERCENT 0.22	/* percentage of mountain areas */
X#define MAP_GASGIANT_BANDMIN 20  /* min size gasgiants that have bands */
X#define LANDPERCENTAGE 0.45
X
X#define EARTHTYPE_RANGE int_rand(36,39)
X#define AIRLESS_RANGE int_rand(int_rand(16,20),25)
X#define GASGIANT_RANGE int_rand(27,MAX_X-10)
X#define ASTEROID_RANGE_X int_rand(int_rand(2,4),6)	/* asteroids have */
X#define ASTEROID_RANGE_Y int_rand(int_rand(2,5),8)	/*  funny shapes */
X#define ICEBALL_RANGE int_rand(int_rand(18,23),26)
X
X
X#include "vars.h"
X#include <math.h>
Xlong random();
Xdouble Distmap();	/* (different distmap from the shell one) */
X
X
Xplanettype Makeplanet(type)
Xint type;
X{
Xreg int x,y;
Xsectortype *s;
Xplanettype planet;
Xint i, atmos,landsects,Numlandsects;
X
X  Bzero(planet);
X  bzero((char *)Smap, sizeof(Smap));
X  planet.type = type;
X  planet.expltimer = 5;
X
Xswitch (type) {
X case TYPE_GASGIANT:		/* gas giant planet */
X
X  planet.Maxx = GASGIANT_RANGE;
X  planet.Maxy = round_rand((float)planet.Maxx / RATIOXY) + 1;
X
X  planet.conditions[TEMP] = 		/* change to more real range */
X  	planet.conditions[RTEMP] = int_rand(-50,50);	
X	/* either lots of meth or not too much */
X  if (random()&01) {	/* methane planet */
X    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
X    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[HELIUM] = 1;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = 1;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  } else {
X    atmos = 100 - (planet.conditions[HYDROGEN] = int_rand(30,55));
X    atmos -= planet.conditions[HELIUM] = int_rand(30,atmos/2);
X    atmos -= planet.conditions[METHANE] = random()&01;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = random()&01;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  }
X
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_GAS;	/* for gasgiant */
X	s->fert = int_rand(35,55);
X	s->resource = int_rand(3,20);
X     }
X if (planet.Maxx > MAP_GASGIANT_BANDMIN) {
X    int nbands;
X    nbands = MAX(1,planet.Maxy/5);
X    for (i=1; i<=nbands; i++) {
X     y=int_rand(1,planet.Maxy-2);
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_SEA;	/* make random bands of water */
X	s->fert += int_rand(10,24);
X	s->resource += int_rand(30,40);
X     }
X    }
X    for (i=0; i<=MAP_ISLANDS*2; i++) {
X     y=int_rand(1,planet.Maxy-2);
X     x=int_rand(1,planet.Maxx-2);
X	s = &Sector(planet,x,y);
X	s->des = DES_SEA;	/* make random spots of water */
X	s->fert += int_rand(12,24);
X    }
X } else {
X    for (i=0; i<MAP_ISLANDS*2; i++) {
X	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
X	if (random()&01) {
X		s->des=DES_MOUNT;
X		s->is_wasted = 1;
X		s->resource += int_rand(9,21);
X		s->fert = int_rand(10,21);
X	} else {
X		s->des=DES_SEA;
X		s->fert=int_rand(10,22);
X	}
X    }
X  Smashup(&planet,int_rand(2,4),DES_SEA,0,0,0);
X  Smashup(&planet,int_rand(1,2),DES_LAND,2,3,1);
X }
X /*planet.Maxy--;		/* squish a bit for rotation */
X /*planet.rottimer = planet.Maxx;*/
X
X break;
X
Xcase TYPE_AIRLESS:		 /* make airless wasted planet */
X
X    planet.conditions[RTEMP] = 
X    	planet.conditions[TEMP] = int_rand(-50,50);
X    planet.conditions[HYDROGEN] = 0;
X    planet.conditions[HELIUM] = 0;
X    planet.conditions[METHANE] = 0;
X    planet.conditions[OXYGEN] = 0;
X    atmos = 100 - (planet.conditions[CO2] = int_rand(30,45));
X    atmos -= planet.conditions[NITROGEN] = int_rand(10, atmos/2);
X    atmos-=planet.conditions[SULFUR] = random()&01 ? 0 : int_rand(20, atmos/2);
X    atmos-=planet.conditions[OTHER] = atmos;
X
X  planet.Maxx = AIRLESS_RANGE;
X  planet.Maxy = round_rand(planet.Maxx / RATIOXY);
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_MOUNT;	/* for airless */
X	s->resource=int_rand(54,78);
X	s->fert=int_rand(0,int_rand(3,10));
X     }
X
X     for (i=0; i<MAP_ISLANDS; i++) {
X	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
X	s->des = DES_LAND;
X	s->fert += int_rand(3,17);
X	s->resource += int_rand(30,43);
X     }
X  Smashup(&planet,6,DES_LAND,5,1,0);	/* make meteor impacts */
X
X  break;
X
Xcase TYPE_ASTEROID: 		/* asteroid */
X
X	/* no atmosphere */
X    planet.conditions[HYDROGEN] = 0;
X    planet.conditions[HELIUM] = 0;
X    planet.conditions[METHANE] = 0;
X    planet.conditions[OXYGEN] = 0;
X    planet.conditions[CO2] = 0;
X    planet.conditions[NITROGEN] = 0;
X    planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = 0;
X    planet.conditions[RTEMP] =
X    	planet.conditions[TEMP] = int_rand(-50,50);
X  planet.Maxx = ASTEROID_RANGE_X;
X  planet.Maxy = ASTEROID_RANGE_Y;
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = int_rand(0,3) ? DES_MOUNT : DES_LAND;
X	s->is_wasted = 0;
X	s->resource = int_rand(151,500);
X	s->fert = 1 + random()&01;
X     }
X
X     break;
X  
Xcase TYPE_EARTH:
X
X    planet.conditions[RTEMP] =
X    	planet.conditions[TEMP] = int_rand(-50,50);
X  if (random()&01) {
X	/* oxygen-reducing atmosphere (Earth type) */
X    atmos = 100 - (planet.conditions[OXYGEN] = int_rand(10,25));
X    atmos -= planet.conditions[NITROGEN] = int_rand(20,atmos/2);
X    atmos -= planet.conditions[CO2] = int_rand(20,atmos/2);
X    atmos -= planet.conditions[HELIUM] = int_rand(2,atmos/8+1);
X    atmos -= planet.conditions[METHANE] = random()&01;
X    atmos -= planet.conditions[SULFUR] = 0;
X    atmos -= planet.conditions[HYDROGEN] = 0;
X    planet.conditions[OTHER] = atmos;
X  } else {
X	/* methane atmosphere */
X    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
X    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[HELIUM] = 1;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = 1;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  }
X  planet.Maxx = EARTHTYPE_RANGE;
X  planet.Maxy = round_rand(planet.Maxx/RATIOXY);   /* may haveta change this */
X  Numlandsects = planet.Maxx*planet.Maxy*LANDPERCENTAGE;
X
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des=DES_SEA;	/* make all water first */
X	s->fert = int_rand(20,43);
X	s->resource = int_rand(15,25);
X     }
X		/* make first isolated islands */
X  for (i=0; i<=MAP_ISLANDS; i++) {
X     s = &Sector(planet, int_rand(planet.Maxx/5,planet.Maxx-planet.Maxx/5),
X	     int_rand(1,planet.Maxy-2));
X     s->des = DES_LAND;  
X     s->resource = 100;
X     s->fert = int_rand(6,20);
X  }
X
X  /*PermuteSects(&planet);	/* mix up map */
X  /*(void)Getxysect(&planet,0,0,1);	/* reset index */
X
X  landsects=0;
X  while (landsects<=Numlandsects)
X       landsects += Volcano(&planet,landsects,Numlandsects); 
X		   /* pick rndm locn, return whether island or not */
X
X
X		/* make more isolated islands */
X  for (i=0; i<=MAP_ISLANDS*3; i++) {
X     x=int_rand(0,planet.Maxx-1);
X     y=int_rand(0,planet.Maxy-1);
X     s = &Sector(planet,x,y);
X     s->des = DES_LAND;
X     s->resource = 55;	/* nice odd number */
X		  /* min content prop to dist from sea */
X     s->fert = 45;
X  }
X
X   break;
X
Xcase TYPE_ICEBALL:		/* ball of ice */
X	/* no atmosphere */
X    planet.conditions[HYDROGEN] = 0;
X    planet.conditions[HELIUM] = 0;
X    planet.conditions[METHANE] = 0;
X    planet.conditions[OXYGEN] = 0;
X    planet.conditions[CO2] = 0;
X    planet.conditions[NITROGEN] = 0;
X    planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = 0;
X    planet.conditions[RTEMP] =
X    	planet.conditions[TEMP] = int_rand(-50,50);
X
X    planet.Maxx = ICEBALL_RANGE;
X    planet.Maxy = round_rand(planet.Maxx / RATIOXY);
X
X    for (y=0; y<planet.Maxy; y++)
X       for (x=0; x<planet.Maxx; x++) {
X	    Sector(planet,x,y).des = DES_ICE;
X	    Sector(planet,x,y).resource = int_rand(45,67);
X	    Sector(planet,x,y).fert = int_rand(10,25);
X       }
X 
X     /* make some random mountains */
X    for (i=0; i<MAP_ISLANDS; i++) {
X	x = int_rand(0,planet.Maxx-1);
X	y = int_rand(0,planet.Maxy-1);
X	Sector(planet,x,y).des = DES_MOUNT;
X	Sector(planet,x,y).resource += int_rand(30,55);
X	Sector(planet,x,y).fert *= 0.3;
X    }
X    Smashup(&planet, 3, DES_MOUNT, 20, 0, 0);
X       
X    break;
X
Xdefault:
X    break;
X
X }
X
X return planet;
X
X}
X
X
X	/* smash psuedo-meteors into the planet */
XSmashup(pptr,n,desig,res,fert,waste)	
Xplanettype *pptr;
Xint n;			/* # iterations */
Xchar desig;		/* des to make target sectors */
Xint res,fert,waste;	/* resources,fert to add, whether to waste */
X{
Xreg int r,x,y;
Xreg int x2,y2;
Xreg sectortype *s;
X
X while (n--) {
X    x=int_rand(1,pptr->Maxx-2);
X    y=int_rand(1,pptr->Maxy-2);
X    r=int_rand(2,int_rand(2,pptr->Maxy/3+1));
X    for (y2=y-r-1; y2<=y+r+1; y2++)
X       for (x2=x-r-1; x2<=x+r+1; x2++)
X	  if (Distmap(x,y,x2,y2) < r) 
X	     if ((x2<pptr->Maxx)&&(x2>=0)&&(y2<pptr->Maxy)&&(y2>=0)) {
X		s = (&(Smap[y2*pptr->Maxx+x2]));
X		if (desig==DES_LAND && s->des==DES_MOUNT)
X			s->des = DES_LAND;
X		else if (desig==DES_LAND && s->des==DES_LAND)
X			s->des = DES_MOUNT;
X		if (waste) s->is_wasted=1;
X		if (res) s->resource+=int_rand(res/2,res*2);
X		if (fert) s->fert+=int_rand(fert/2,fert*2);
X	     }
X }
X
X}
X
X
X
Xdouble Distmap(x,y,x2,y2)
Xreg int x,y,x2,y2;
X{
X return fabs((double)x-x2) / RATIOXY + fabs( (double)y-y2);
X}
X
X
Xint Volcano(pptr,landsectors,Numlandsects)
Xplanettype *pptr;
Xint landsectors,Numlandsects;
X{
Xreg int x,y;
Xsectortype *s;
X
X  x = int_rand(0,pptr->Maxx-1);
X  y = int_rand(0,pptr->Maxy-1);
X  s = &Sector(*pptr,x,y);
X
X    if (y > pptr->Maxy/2) {
X      if (y==pptr->Maxy-1) {
X	s->des = DES_ICE;
X	return(random()&01);
X      } else {
X	if ((Sector(*pptr,x,y+1).des==DES_ICE) && 
X		 (int_rand(-50,50)>pptr->conditions[RTEMP])) {
X		s->des = DES_ICE;
X		return(random()&01);
X	}
X      }
X    } else {
X      if (y==0) {
X	s->des = DES_ICE;
X	return(random()&01);
X      } else if ((Sector(*pptr,x,y-1).des==DES_ICE) && 
X		 (int_rand(-50,50)>pptr->conditions[RTEMP])) {
X		s->des = DES_ICE;
X		return(random()&01);
X	}
X    }
X
X  if (s->des==DES_SEA) {
X    if (Numneighbors(pptr,x,y,DES_LAND)||Numneighbors(pptr,x,y,DES_MOUNT)) {
X	s->des=(landsectors>(MAP_MOUNT_PERCENT*Numlandsects))?DES_LAND:DES_MOUNT;
X	s->resource = round_rand((float)(Numlandsects - landsectors + 5) / (float)Numlandsects * 100);
X		  /* min content prop to dist from sea */
X	s->fert = (float)(landsectors + 5) / (float)Numlandsects * 100;
X		  /* fert content prop to dist from center of continent */
X       return(1);
X    } else return(0);
X   } else return(0);
X}
X
X
X
X/* return # of neighbors of a given designation that a sector has. */
Xint Numneighbors(p,x,y,des)
Xplanettype *p;
Xreg int x,y,des;
X{
Xreg int d;
X  return (Sector(*p,mod(x-1,p->Maxx,d),y).des==des) + 
X  	 (Sector(*p,mod(x+1,p->Maxx,d),y).des==des) + 
X  	 ((y==0) ? 0 : (Sector(*p,x,y-1).des==des)) + 
X  	 ((y==p->Maxy-1) ? 0 : (Sector(*p,x,y+1).des==des));
X}
END_OF_FILE
if test 11295 -ne `wc -c <'makeplanet.c'`; then
    echo shar: \"'makeplanet.c'\" unpacked with wrong size!
fi
# end of 'makeplanet.c'
fi
if test -f 'misc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'misc.c'\"
else
echo shar: Extracting \"'misc.c'\" \(334 characters\)
sed "s/^X//" >'misc.c' <<'END_OF_FILE'
X/* 
X * Galactic Bloodshed (Robert Chansky, smq@b)
X * scales used in production efficiency etc.
X * input both: int 0-100
X * output both: float 0.0 - 1.0 (logscale 0.5 - .95)
X */
X
Xfloat powscale(x)
Xregister int x;
X{
X register float f;
X return (f=(float)x/100.0)*f;
X}
X
Xfloat logscale(x)
Xregister int x;
X{
X return (x+5.0) / (x+10.0);
X}
X
X
END_OF_FILE
if test 334 -ne `wc -c <'misc.c'`; then
    echo shar: \"'misc.c'\" unpacked with wrong size!
fi
# end of 'misc.c'
fi
echo shar: End of archive 3 \(of 8\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 8 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