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

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

Submitted-by: VANCLEEF@mps.ohio-state.edu
Posting-number: Volume 7, Issue 44
Archive-name: GB2/Part01
Supersedes: GB: Volume 6, Issue 52-58,67-69

	[This represents a parallel development of GB.  It is based on
	 the original GB posting with many bug fixes and some enhance-
	 ments.  -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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 8)."
# Contents:  README MANIFEST Docs Docs/land.doc README2 doplanet.c
#   order.c
# Wrapped by billr@saab on Thu Jul  6 07:39:47 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(7098 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X	This is a game of interstellar exploration/conquest.  By the time I
Xrealized there really wasn't going to be much fighting going on in the game, I
Xwas so in love with the title that I just couldn't change it...
X
X	Players begin the game as members of a randomly generated race, with
Xattributes (intelligence, birth rate, size, metabolism, etc) that affect
Xdevelopment later.  Each turn, population will migrate to unpopulated areas
Xof the planet.
X
X	Currently I have the following features:
X
X	Exploration: players can build many types of ships with which to 
Xcolonize other planets.
X	Terraforming: planets have atmospheres, composed of different amounts
Xof gases.  players can build machines to alter the atmosphere to one more
Xsuited to their race.
X	Von Neumann machines: This is a ship-type that can be built.  It
Xexists to reproduce itself using whatever resources are available, and can be
Xuseful to send to other players.  I got this idea after reading _The Forge of
XGod_.
X	Co-existance: There are several types of terrain: land, ice, ocean,
Xmountainous, and gas(gasgiant).  Each player has a type which he preferrs; if
Xone race's preference differs from another, both races can co-exist on the same
Xplanet.
X	Communication: players can communicate with each other, but only if
Xthey sacrifice valuable resources to translate another language.
X	Combat: If the above breaks down.
X
X
X	The game is not (of course) complete, but it's fixed up enough to post
XI think.  It runs pretty good on 4.3 and 4.2, but as our versions of
Xboth here are a little funky, it may require some tweaking before it runs to
Xa game keeper's satisfaction.
X
X
X	GB can be found via anonymous ftp to the machine ssyx.ucsc.edu
X(128.114.133.1).  (Look in pub/games).
X
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 might have problems.
X	Well the Space Amoebae are new, there may be some foulups involved with 
Xthem as well, such as not digesting planets properly.
X	Mirrors face the wrong way.
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 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, and 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.  
X	Once the game is up, you, as the diety player, must enroll
Xfirst.  (several objects in the game are owned by player 1, it would be better
Xif this were you..)  To make the game more interesting, you can build (yes
Xbuild) a space amoeba or two (be sure to send it somewhere else so it doesnt
Xeat YOUR planet); also you could make a couple fleets of Von Neumann machines
Xto generally become a nuisance to everybody.  (To make yourself some resources,
Xuse the fix command.)  Occasionally you might tweak a star or two to go nova
X(fix its stability to 100); this is especially useful for recalcitrant 
Xgame-players complaining about bugs.  Put the fear of god into them.
X
X	Please send me information on trends in the game; what tends to
Xhappen here and there.
X
X
XFIXES/ADDITIONS:
X	We are now at Version .975.  The datafiles are *NOT* compatible
X	with previous versions (.95-) you may have.  
X
X	Some recent fixes (over .95) are:
X
X	Ships are now stored in a list, instead of slots in planets.  This 
Xmakes a lot of things much faster, as well as more efficient, and you won't
Xrun into the barrier of 25 ships max in orbit around every planet.
X	Alterations in some algorithms make it now impossible for ships to 
Xbe in two lists at once, or in the wrong list.
X	Load used to not check for the other ship overflowing its 
Xbounds; I fixed this since you could load a whole colony onto an
Xexplorer.  You can, however, load as many resource points as you want, onto 
Xshuttles only.  this makes it possible for two shuttles to construct something
Xlarger.
X	Only shuttles, space habitats (used to be space stations), and
Xorbital assault platforms can assemble other ships.
X	There have been changes to the behavior of space habitats:
Xthey reproduce resources and also people.  Because of some new restrictions
XI've put in, the only way to really build them (at least the first one)
Xis to build two shuttles, load them with resources, launch them and dock
Xthem together and transfer all the resources of one to the other, land the
Xempty one and fill it again, and continue transferring them until the
Xshuttle has enough to build a habitat.  Hey, it's the way WE have to do
Xit..
X
X	Planets are now moved in their orbits before ships are moved;
Xthis makes them more efficient in interplanetary navigation, and ships won't
Xfollow them around anymore.
X	New ship type: toxic waste canister, which reduces your toxicity
Xof the planet you build it on-- but what do you do with all the canisters?
X	more new ships: ground and space telescopes.  ground telescopes are
Xway cheap and have a much lower tech, while space telescopes cost more
Xbut have a longer range.  range is proportional to your tech.  These
Xwere put in so people don't have to send ships out blindly.  Once you've
Xsurveyed someplace with one of these, you can then map and 'cs' to it.
X	New ships: orbital mind control lasers, some ground, sea, and air
Xtransportation ships (which don't work yet).
X
X	There is now an 'enslave' command.  Check the docs.
X
X	tactical works better, it uses planets as part of its display.
X	the bug where sector maps got randomly switched around sometimes
Xhalting the game, has been fixed.  This was a MAJOR pain, and the main problem
Xof the moment in GB.
X
X
X	Many thanks to Steven Grimm (koreth@ssyx), without whose help
Xin the early stages of the game, development would not have been possible,
Xand Evan Schaffer admin of ssyx, whose tolerance of huge CPU usages by a lowly
Xundergrad making a game is greatly appreciated.
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 7098 -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'\" \(3586 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X Docs                       1	
X Docs/actionpoints.doc      8	
X Docs/assault.doc           8	
X Docs/autoreport.doc        8	
X Docs/build.doc             7	
X Docs/cs.doc                8	
X Docs/daemon.doc            8	
X Docs/declare.doc           7	
X Docs/dock.doc              8	
X Docs/enslave.doc           7	
X Docs/examine.doc           8	
X Docs/explore.doc           8	
X Docs/fire.doc              8	
X Docs/fix.doc               8	
X Docs/god.doc               8	
X Docs/help.doc              7	
X Docs/install.doc           8	
X Docs/land.doc              1	
X Docs/launch.doc            8	
X Docs/load.doc              8	
X Docs/makeuniv.doc          8	
X Docs/map.doc               6	
X Docs/message.doc           8	
X Docs/mobilize.doc          4	
X Docs/name.doc              8	
X Docs/news.doc              8	
X Docs/orbit.doc             7	
X Docs/order.doc             7	
X Docs/power.doc             2	
X Docs/profile.doc           7	
X Docs/read.doc              8	
X Docs/relation.doc          8	
X Docs/report.doc            8	
X Docs/scope.doc             7	
X Docs/scrap.doc             8	
X Docs/ship.doc              8	
X Docs/stock.doc             8	
X Docs/survey.doc            7	
X Docs/tactical.doc          8	
X Docs/telegram.doc          8	
X Docs/undock.doc            8	
X Docs/zoom.doc              8	
X GB.c                       7	
X MANIFEST                   1	This shipping list
X Makefile                   6	
X README                     1	
X README2                    1	
X autoreport.c               7	
X autoshoot.c                6	
X build.c                    4	
X cs.c                       6	
X daemon.c                   8	
X declare.c                  7	
X docommand.c                5	
X doplanet.c                 1	
X dosector.c                 4	
X doship.c                   2	
X doturn.c                   5	
X doturn.h                   8	
X enrol.c                    3	
X enroll.dat                 7	
X enslave.c                  6	
X exam.dat                   3	
X examine.c                  7	
X explore.c                  7	
X files.h                    8	
X files_rw.c                 7	
X files_shl.c                4	
X fire.c                     3	
X fix.c                      3	
X get4args.c                 8	
X getplace.c                 5	
X help.c                     8	
X land.c                     4	
X launch.c                   6	
X load.c                     2	
X makeplanet.c               3	
X makeuniv.c                 2	
X map.c                      5	
X max.c                      7	
X misc.c                     3	
X mobiliz.c                  7	
X more.c                     7	
X moveplanet.c               7	
X moveship.c                 4	
X name.c                     6	
X orbit.c                    2	
X order.c                    1	
X perm.c                     8	
X planet.list                5	
X power.c                    8	
X power.h                    8	
X prof.c                     7	
X races.h                    8	
X rand.c                     8	
X read_teleg.c               5	
X relation.c                 8	
X rst.c                      4	
X scrap.c                    6	
X ship.dat                   8	
X shipdata.h                 6	
X ships.h                    6	
X shlmisc.c                  6	
X shootblast.c               5	
X sizes.c                    8	
X survey.c                   5	
X teleg_send.c               8	
X telegram.c                 7	
X traverse.c                 8	
X tweakables.h               5	
X vars.h                     6	
X zoom.c                     8	
END_OF_FILE
if test 3586 -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 'Docs/land.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Docs/land.doc'\"
else
echo shar: Extracting \"'Docs/land.doc'\" \(1002 characters\)
sed "s/^X//" >'Docs/land.doc' <<'END_OF_FILE'
XLAND			Galactic Bloodshed		LAND
X
X
XNAME
X  [1] land -- land a ship
X 
XSYNTAX
X      land [#shipnum] [x,y]
X
XDESCRIPTION
X  This command lands ships on planets.  To do so the ship must be
Xcloser than 10 distance units away from the planet it is orbiting.  Land
Xwill prompt the player for what sector on which to land.
X
X  This maneuver costs an amount of fuel proportional to the mass of the
Xship and the gravitational field of the planet below.  If the ship does not
Xhave enough fuel it will crash.  This will give damage to the planet in
Xproportion to the mass of the ship, the gravitational field of the planet, and
Xthe amount of destructive capacity the ship happens to be carrying.
X
X  A player's ships can not land on sectors on which that player has a
Xcompatibility index of 0; for instance, a race that prefers mountain sectors
Xcannot land on water or gasgiant sectors, and vice versa.  Information on
Xsector compatibility can be found in the profile command.
X
X
XSEE ALSO
X  dock, launch, undock, profile
END_OF_FILE
if test 1002 -ne `wc -c <'Docs/land.doc'`; then
    echo shar: \"'Docs/land.doc'\" unpacked with wrong size!
fi
# end of 'Docs/land.doc'
fi
if test -f 'README2' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README2'\"
else
echo shar: Extracting \"'README2'\" \(474 characters\)
sed "s/^X//" >'README2' <<'END_OF_FILE'
XI modifed load.c, fire.c, land.c, makeuniv.c and shlmisc.c to
Xreplace embedded control characters with their '\0nn' equivalent.  The file
Xplanet.list had two embedded control-Z characters in it, which were removed.
XI also modified the Makefile to save the files in the specified paths, rather
Xthan the current directory and put all of the .doc files into a subdirectory
Xof the source dir.
X
X	-Bill Randle
X	Moderator, comp.sources.games
X	billr@saab.CNA.TEK.COM
X
X	July 6, 1989
END_OF_FILE
if test 474 -ne `wc -c <'README2'`; then
    echo shar: \"'README2'\" unpacked with wrong size!
fi
# end of 'README2'
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'\" \(19934 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 <math.h>
Xextern bool Nuked[];
X
Xextern int Ignore_lockfile;
X
Xchar telegram_buf[AUTO_TELEG_SIZE];
X
Xint tot_resdep, prod_eff, prod_res[MAXPLAYERS], prod_fuel[MAXPLAYERS],
X	prod_destruct[MAXPLAYERS], tot_captured, prod_mob,
X	populations[MAXPLAYERS];
Xfloat avg_mob[MAXPLAYERS];
X
Xchar sects_gained[MAXPLAYERS], sects_lost[MAXPLAYERS];
Xfloat Compat[MAXPLAYERS];
Xbool Claims;
X
X	/* types of accidents that can occur on a toxic planet. */
Xchar *Accidents_uninhab[] = {
X	 /* on water sectors */
X	"Widespread waste spill",
X	"Ecological instability",
X	 /* on land sectors */
X	"Massive volcanic eruptions",
X	"Ecological instability",
X	 /* on mountain sectors */
X	"Massive volcanic eruptions",
X	"Ecological instability",
X	 /* gas sectors */
X	"Lethal toxin concentration",
X	"Ecological instability",
X	 /* ice */
X	"Leak in isolated chemical plant",
X	"Continental warming cause glacial melting",
X	 /* plate */
X	"Nuclear accident",
X	"Untended nuclear plant explodes"
X};
X
Xchar *Accidents_inhab[] = {
X	"Nuclear accident",
X	"Terrorists trigger nuclear weapon",
X	"Release of toxic waste",
X	"Weapons dump explosion",
X	"Massive starvation",
X	"Virus epidemic",
X	"famine",
X	"starvation",
X	"Widespread cultist suicide",
X	"Atomic experiment gone wrong",
X	"Great Hrung collapse"
X};
X
X
Xint doplanet(starnum,planet, planetnum, command)
Xint starnum;
Xplanettype *planet;
Xint planetnum;
Xint command;
X{
Xint shipno,x,y,nukex,nukey;
Xint o=0,j;
Xchar *nukem;
Xreg int i;
Xsectortype *p;
Xshiptype *ship;
Xfloat madd,fadd;
Xint sectdata,timer=20;
Xint oldplanetpopn, oldplanetmaxpopn;
Xbool allamoeba=1,allmod=0,allexp=0;
Xchar buf[200]; 
X
X
Xif (!StarsInhab[starnum])
X	return 0;	/* no one's here now */
X
Xif (Stinfo[starnum][planetnum].inhab) {
X	printf(" getting sectmap pos %d\n",planet->sectormappos);
X	opensectdata(&sectdata);
X	getsmap(sectdata,Smap,planet);
X	close(sectdata);
X
X	PermuteSects(planet);
X	bzero((char *)Sectinfo, sizeof(Sectinfo) );
X}
X
X
X
X
X  shipno = planet->ships;
X  while (shipno) {
X	if ( ((ship = ships[shipno])!=NULL) && !ship->is_dead && !ship->rad) {
X	   if ( !(ship->is_docked && ship->whatdest==LEVEL_PLAN)) {
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_HABITAT) {
X		    fadd = FUEL_GAS_ADD_HABITAT;
X		    madd = FUEL_GAS_ADD_HABITAT*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->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		     /* spread VN's all over the planet */
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
X
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(3,50)) {
X			/* enough to start a new VN 'herd'. build another
X			   ship. */
X		     	 shiptype *s2;
X			Num_ships++;
X			printf("VN #%d constructed VN #%d.\n",shipno,Num_ships);
X			ships[Num_ships] = Malloc(shiptype);
X			s2 = ships[Num_ships];
X			bzero((char *)s2,sizeof(shiptype));
X
X			s2->nextship = planet->ships;
X			planet->ships = Num_ships;
X
X			s2->whatorbits = LEVEL_PLAN;
X			s2->storbits = ship->storbits;
X			s2->pnumorbits = ship->pnumorbits;
X			s2->is_docked = 1;
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->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 = (random()&01) ? ship->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				/* turn it on */
X			s2->on = 1;
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			/* try and make some resources by ourselves.
X			   more might be stolen in doship */
X			ship->resource += 
X			  Sector(*planet,(int)ship->xpos, (int)ship->ypos).resource;
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).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
X
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		    }
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	   }
X
X			/* bombard the planet */
X	   if (can_bombard(ship) && ship->orders.o.bombard
X			&& ship->whatorbits==LEVEL_PLAN
X			&& ship->whatdest==LEVEL_PLAN
X			&& ship->deststar==starnum
X			&& ship->storbits==starnum
X			&& ship->destpnum==planetnum
X			&& ship->pnumorbits==planetnum) {
X				/* ship bombards planet */
X		Bombard(ship, shipno, planet);
X		allmod = 1;	/* save smap */
X	   }
X
X	}
X  	shipno = ship->nextship;
X  }
X
X
X if (!Stinfo[starnum][planetnum].inhab && !Stinfo[starnum][planetnum].Thing_add 
X    && !Stinfo[starnum][planetnum].amoeba_add)
X	return 0;	/* (no one's explored the planet) */
X
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
Xif (planet->slaved_to)
X	planet->is_sheep = 1;	/* this is set to 0 at the end of ea. turn */
X
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	planet->info[Stinfo[starnum][planetnum].Thing_add-1].numsectsowned = 1;
X	planet->info[Stinfo[starnum][planetnum].Thing_add-1].explored = 1;
X	Sector(*planet,x,y).des = 
X			races[Stinfo[starnum][planetnum].Thing_add]->likesbest;
X	Sector(*planet,x,y).popn = 1;
X	Sector(*planet,x,y).owner = Stinfo[starnum][planetnum].Thing_add;
X	Sector(*planet,x,y).is_wasted = 0;
X}
Xif (Stinfo[starnum][planetnum].amoeba_add) {
X	x = int_rand(0,planet->Maxx-1);
X	y = int_rand(0,planet->Maxy-1);
X	planet->info[1-1].numsectsowned = 1;
X	Sector(*planet,x,y).amoeba = 1;
X	Sector(*planet,x,y).popn = 0;
X	Sector(*planet,x,y).owner = 1;
X}
X
X
Xbzero((char *)avg_mob, sizeof(avg_mob) );
Xbzero((char *)sects_gained, sizeof(sects_gained) );
Xbzero((char *)sects_lost, sizeof(sects_lost) );
Xbzero((char *)populations, sizeof(populations) );
Xbzero((char *)prod_res, sizeof(prod_res) );
Xbzero((char *)prod_fuel, sizeof(prod_fuel) );
Xbzero((char *)prod_destruct, sizeof(prod_destruct) );
X
Xtot_resdep = prod_eff= prod_mob = tot_captured = 0;
XClaims = 0;
X
Xoldplanetmaxpopn = planet->maxpopn;
Xplanet->maxpopn = 0; 
X
Xoldplanetpopn = planet->popn;
Xplanet->popn = 0;	/* initialize population for recount */ 
XCompat[0] = 100;
X
Xfor (i=1; i<=Num_races; i++)
X
X/* gvc hack */
X	if (planet->info[i-1].numsectsowned) {
X	printf("numsects %d %d \n",i,planet->info[i-1].numsectsowned);
X		Compat[i] = compatibility(planet, races[i]);
X		planet->info[i-1].numsectsowned = 0;
X	}
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->amoeba) {
X	    planet->info[1-1].numsectsowned++;
X	    allamoeba &= 1;
X	    allmod = 1;	
X	    spread(planet,p,x,y);	/* spread amoeba on the planet */
X       } else if (p->owner) {
X		/* (all modified; sectors belonging to that player modified) */
X	    allmod = 1;	
X	    allamoeba = 0;
X	    if (!p->popn) {
X		  p->owner=0;	/* make wasted/unowned sects go to player 0 */
X	    } else {
X	      if (!Stars[starnum]->nova_stage) {
X	       		/* spread excess popn to surrounding sects */
X	      		produce(planet,p);	/* produce stuff there */
X	      		spread(planet,p,x,y);	
X	      } else {
X			/* damage sector from supernova */
X			if (p->owner==2)
X				printf(" ha found pl 2\n");
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 = round_rand((float)p->popn * .80);
X	      }
X	      planet->info[p->owner-1].numsectsowned++;
X	      Sectinfo[x][y].done = 1;
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] += populations[p->owner] += p->popn;
X	    }
X       }
X
X
X
X       planet->maxpopn += maxsupport(races[p->owner],p,Compat[p->owner]);
X
X       if (Sectinfo[x][y].VN)
X	       p->VN = 1;
X       else
X	       p->VN = 0;
X
X       if (p->is_wasted) {
X	 	if (x>1 && x<planet->Maxx-2) {
X			if (p->des==DES_SEA || p->des==DES_GAS) {
X				/* don't reclaim pole sectors */
X		  		if ( y>1 && y<planet->Maxy-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 || p->des==DES_ICE) {
X				if ( y>1 && y<planet->Maxy-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)
X       if (p->des==DES_ICE)
X	   p->des = DES_LAND;
X       else if (p->des==DES_SEA)
X
X	  if ( (x>0 && (p-1)->des==DES_LAND) ||
X	     (x<planet->Maxx-1 && (p+1)->des==DES_LAND) || 
X	     (y>0 && (p-planet->Maxx)->des==DES_LAND) ||
X	     (y<planet->Maxy-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 numsects %d compat %f\n",i,planet->info[i-1].numsectsowned,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		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;
X			p = &Sector(*planet,x,y);
X			if (( (Sectinfo[x][y].explored==i) && !(random()&02) ) 
X			    && (!p->owner && !p->is_wasted && !p->amoeba && p->des==races[i]->likesbest) ) {
X				 /*  explorations have found an island */
X			printf(" got here 2\n");
X				printf("found island @ %d,%d\n",x,y);
X				Claims = i;
X				 /* give them some free people there */
X				p->popn = races[i]->number_sexes;
X				p->owner = i;
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		/* environment nukes a random sector */
X   if (planet->conditions[TOXIC] > ENVIR_DAMAGE_TOX) {
X	nukex = int_rand(0,planet->Maxx-1);
X	nukey = int_rand(0,planet->Maxy-1);
X	p = &Sector(*planet,nukex,nukey);
X	planet->info[p->owner-1].numsectsowned--;
X	p->is_wasted = 1;
X		/* index into accident type array */
X	nukem = p->popn ? 
X			/* random disaster */
X		Accidents_inhab[int_rand(0,sizeof(Accidents_inhab)/sizeof(char *))]
X				/* random of two disasters for that sec type*/
X		: Accidents_uninhab[p->des * 2 + (random()&01)];
X	p->popn = p->owner = 0;
X   }
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("Production:\npopn maxpopn  res  fuel  dest mob.pt.\n",	
X	 	 telegram_buf);
X	  sprintf(buf,"%4d%8d%5d%6d%6d%8d\n", planet->popn - oldplanetpopn,
X		planet->maxpopn - oldplanetmaxpopn,
X		prod_res[i], prod_fuel[i], prod_destruct[i],prod_mob);
X	  teleg_add(buf,telegram_buf);
X	  if (tot_resdep) {
X		  sprintf(buf,"resource deposit depletion: %d\n", tot_resdep);
X		  teleg_add(buf,telegram_buf);
X	  }
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.", 
X			Stars[starnum]->nova_stage);
X		teleg_add(buf,telegram_buf);
X	  }
X
X		/* remind the player that he should clean up the environment. */
X	  if (planet->conditions[TOXIC] > ENVIR_DAMAGE_TOX) {
X		teleg_add("\nEnvironmental damage:\n", telegram_buf);
X		sprintf(buf,"%s on sector %d,%d!\n", nukem, nukex, nukey);
X		teleg_add(buf,telegram_buf);
X	  }
X
X	  if (planet->slaved_to) {
X		sprintf(buf, "\nThis planet is ENSLAVED to player %d,\n with a garrison of %d.\n", planet->slaved_to, populations[planet->slaved_to]);
X		teleg_add(buf,telegram_buf);
X		sprintf(buf, "All resources, fuel, weapons given to %s.\n",
X			races[planet->slaved_to]->name);
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
X	if(planet->maxpopn > 0)
X   planet->conditions[TOXIC] = planet->conditions[TOXIC] + 
X		     planet->popn / planet->maxpopn;
X
X	/* deal with enslaved planets */
X   if (planet->slaved_to) {
X	if (populations[planet->slaved_to] >= planet->popn * 0.001) {
X		for (i=1; i<=Num_races; i++)
X		    /* add production to slave holder of planet */
X		  if (planet->info[i-1].numsectsowned) {
X			planet->info[planet->slaved_to-1].resource += 
X					prod_res[i];
X			planet->info[planet->slaved_to-1].fuel += 
X					prod_fuel[i];
X			planet->info[planet->slaved_to-1].destruct += 
X					prod_destruct[i];
X		  }
X	} else {
X		 /* slave revolt! */
X
X		 /* first nuke some random sectors from the revolt */
X		i = planet->popn / 10000 + 1;
X		while (--i) {
X			p = &Sector(*planet,int_rand(0,planet->Maxx),
X					int_rand(0,planet->Maxy));
X			if (p->popn) {
X				p->owner = p->popn = 0;
X				p->is_wasted = 1;
X			}
X		}
X		 /* now nuke all sectors belonging to former master */
X		Getxysect(planet, &x, &y, 1);
X		while (Getxysect(planet, &x, &y, 0)) {
X			p =  &Sector(*planet,x,y);
X			if (p->owner==planet->slaved_to) {
X				p->owner = p->popn = 0;
X				p->is_wasted = 1;
X			}
X		}
X		teleg_add("", telegram_buf);
X		sprintf(buf,"NOTICE from planet /%s/%s!\n",
X				Stars[starnum]->name,
X				Stars[starnum]->pnames[planetnum]);
X		teleg_add(buf, telegram_buf);
X		teleg_add("\nThere has been a SLAVE REVOLT on this planet!\n",
X			telegram_buf);
X		sprintf(buf,"%s on the planet have all been killed!\n");
X		teleg_add(buf,telegram_buf);
X		teleg_add("Productions now go to their rightful owners.\n",
X			telegram_buf);
X		for (i=1; i<=Num_races; i++)
X		  if (planet->info[i-1].numsectsowned && i!=planet->slaved_to)
X			teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf);
X
X		 /* send to previous slave holders */
X		teleg_send(TELEG_PLAYER_AUTO, planet->slaved_to, telegram_buf);
X
X		planet->slaved_to = 0;
X		planet->is_sheep = 0;
X	}
X
X   } else {
X	 /* add production to all people here */
X	for (i=1; i<=Num_races; i++){
X
X
X	  if (planet->info[i-1].numsectsowned) {
X	 	if (planet->info[i-1].fuel + prod_fuel[i] > 100000)
X		  planet->info[i-1].fuel = 100000;
X		else
X		  planet->info[i-1].fuel += prod_fuel[i];
X
X	 	if (planet->info[i-1].resource + prod_res[i] > 100000)
X		  planet->info[i-1].resource = 100000;
X		else
X		  planet->info[i-1].resource += prod_res[i];
X
X	 	if (planet->info[i-1].destruct + prod_destruct[i] > 100000)
X		  planet->info[i-1].destruct = 100000;
X		else
X		  planet->info[i-1].destruct += prod_destruct[i];
X	  }
X	}
X   }
X
X
X    /* the amoeba here has digested the planet. */
X   if (allamoeba)
X	planet->digested = 1;
X
X   planet->is_sheep = 0;
X
X }
X return allmod;
X}
END_OF_FILE
if test 19934 -ne `wc -c <'doplanet.c'`; then
    echo shar: \"'doplanet.c'\" unpacked with wrong size!
fi
# end of 'doplanet.c'
fi
if test -f 'order.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'order.c'\"
else
echo shar: Extracting \"'order.c'\" \(15738 characters\)
sed "s/^X//" >'order.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X *  order.c -- give orders to ship
X */
X
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include <curses.h>
X#include <ctype.h>
X#include <setjmp.h>
X#include <signal.h>
X#include <math.h>
Xextern jmp_buf main_jenv;
X
Xchar *prin_aimed_at(), *prin_ship_dest();
X
Xint order_shdata,order_pdata,order_stardata;
Xstatic bool first,prerror,was_obj = 0;
X
Xorder(APcount, argn,args)
Xint APcount;
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xint sh,i,shipno,Sdatamod=0;
Xint order_handler();
Xbool err;
X
Xorder_shdata = order_pdata = order_stardata = NEUTRAL_FD;
Xsignal(SIGINT, order_handler);
X
Xfirst = 1;
Xprerror = 0;
X
Xclear(); move(0,0);
X
Xif (argn>=2) {
X	if (args[1][0]=='#') { 
X		  /* a ship was specified, order only that ship */
X  		if (sscanf(args[1],"#%d",&shipno)!=1) 
X			DontOwnErr(shipno);
X	  	else
X		   give_orders(APcount, shipno, &sh);
X	} else {
X		printf("usage: order [#shipnum]\n");
X		return;
X	}
X
X} else {
X /* no ship specified, order all ships,planets in scope */
X
X  switch (Dir.level) {
X
X   case LEVEL_UNIV:
X      sh = Sdata.ships;
X      if (enufAP(Sdata.AP, APcount))
X      	while (sh)
X		Sdatamod |= give_orders(APcount, sh, &sh);
X			/* (sh comes back with nextship value) */
X
X      for (i=0; i<Sdata.numstars; i++)
X        	star_give_orders(APcount, i);
X
X      if (Sdatamod)
X	      deductAPs(APcount, 0, 1);
X      break;
X
X   case LEVEL_STAR:
X      if (enufAP(Stars[Dir.snum]->AP, APcount)) {
X	      if (star_give_orders(APcount, Dir.snum))
X		      deductAPs(APcount, Stars[Dir.snum], 1);
X      }
X      break;
X   case LEVEL_PLAN:
X      if (enufAP(Stars[Dir.snum]->AP, APcount)) {
X	      if (plan_give_orders(APcount, Stars[Dir.snum]->planetpos[Dir.pnum]))
X		      deductAPs(APcount, Stars[Dir.snum], 1);
X      }
X      break;
X   case LEVEL_SHIP:
X      give_orders(APcount, Dir.shipno, &sh);
X      break;
X  }
X
X }
X	/* move to bottom of screen */
X move(stdscr->_maxy-2,0);
X refresh();
X
X}
X
X
X /* various prompt locations so we don't have to remember the #'s */
X#define Opromptx 19
X#define Oprompty 7
X#define Erry (Oprompty+1)
X#define Spromptx (25+PLACENAMESIZE)
X#define Sprompty 2
X#define Tpromptx Spromptx
X#define Tprompty 4
X#define Dprompty 2
X#define Dpromptx 15
X#define SWprompty 5
X#define SWpromptx 2
X#define Bprompty 6
X
X
Xint give_orders(APcount, shipno, nextship)
Xint APcount;
Xint shipno;
Xint *nextship;
X{
X bool Mod=0,q=0,redraw=1;
X placetype where,pl;
X int i = 0;
X shiptype *ship, *oldship, ship2;
X char c,s[PLACENAMESIZE];
X 
X openshdata(&order_shdata);
X if (!getship(order_shdata,&ship,shipno)) {
X	order_handler();
X }
X ship2 = *ship;		/* copy for ESC command */
X oldship = &ship2;
X
X if (ship->owner==Playernum) {
X 
X    if (ship->is_dead) {
X	printw("%s #%d has been destroyed.\n", Shipnames[ship->type], shipno);
X	i = 1;
X    } else {
X
X      if (ship->rad) {
X	printw("%s #%d has been irradiated; it cannot respond to orders.\n",
X		Shipnames[ship->type], shipno);
X	i = 1;
X      }
X      if (ship->type != OTYPE_TRANSDEV && !ship->popn && Shipdata[ship->type][ABIL_MAXCREW] > 0) {
X	printw("%s #%d has no crew and is not a robotic ship.\n",
X		Shipnames[ship->type], shipno);
X	i = 1;
X      }
X
X    }
X    if (i) {
X	free(ship); close(order_shdata);
X	printw("\nhit a key to continue: ");
X	refresh();
X	tty_on(); getchr(); tty_off();
X	putchr('\n');
X
X    } else {
X
X     do {
X
X      if (redraw) {
X	redraw = 0;
X
X	if (first) {
X		clear();
X		first = 0;
X	} else if (prerror) {
X		move(Oprompty,Opromptx);	/* clear error message */
X		clrtoeol();
X	}
X
X	move(0,0);
X	printw("%13s #%-4d at '%s'. (%2d APs)",
X		Shipnames[ship->type], shipno, prin_ship_orbits(ship),
X		ship->whatorbits==LEVEL_UNIV ? Sdata.AP[Playernum] : 
X		Stars[ship->storbits]->AP[Playernum]);
X	if (speed_rating(ship)) {
X		move(2,0);
X		printw("(d)estination: %*s", -PLACENAMESIZE, prin_ship_dest(ship));
X		if (ship->type==OTYPE_OMCL) {
X			move(Sprompty,Spromptx-11);
X			printw("(r)esponse: %d\n", ship->speed);
X		} else {
X			move(Sprompty,Spromptx-9);
X			printw("(s)peed: %d\n",ship->speed);
X		}
X	}
X	if (can_aim(ship)) {
X		was_obj = 1;
X		move(4,0);
X	   	printw("(a)imed at: %s", prin_aimed_at(ship));
X		if (ship->type==STYPE_MIRROR)
X		  printw("\n (i)ntensity: %3d",ship->orders.aimed_at.intensity);
X	} else if (ship->type==OTYPE_TRANSDEV) {
X		move(Tprompty,Tpromptx-18);
X		printw("(t)arget  ship   #%d", ship->orders.object.number);
X	} else if (ship->type==STYPE_MINE) {
X		move(Tprompty,Tpromptx-18);
X		printw("(t)rigger radius: %d", ship->orders.object.number);
X	} else if (can_bombard(ship)) {
X		was_obj = 0;
X		move(Bprompty,0); clrtoeol();
X		if (ship->orders.o.bombard)
X		   if (ship->whatdest==LEVEL_PLAN)
X			printw("(b)OMBARD planet %s", 
X				ship->whatdest==LEVEL_PLAN ? 
X				prin_ship_dest(ship) : "" );
X		   else
X			printw("(b)OMBARD ON (no planet specified)");
X		else
X			printw("(b)ombard off");
X	}
X	if (has_switch(ship)) {
X		move(SWprompty,SWpromptx);
X		printw("(o)%s", ship->on ? "n" : "ff");
X	}
X
X	move(Oprompty,0);
X	printw("orders (%s", can_bombard(ship) ? "b" : "");
X	if (speed_rating(ship))
X		printw("d%c%s%s ESC?):", 
X			ship->type==OTYPE_OMCL ? 'r' : 's',
X			can_aim(ship) ? "a" : "",
X			ship->type==STYPE_MIRROR ? "i" : "");
X	else
X		printw("%s%s ESC?):", has_switch(ship) ? "o" : "",
X			ship->type==STYPE_MINE ? "t" : "", ship->type==OTYPE_TRANSDEV ? "t" : "" );
X
X     }
X
X     move(Oprompty,Opromptx);
X     clrtoeol();
X     refresh();
X
X     tty_on();
X     do {
X		  c = getchr();
X     } while (iscntrl(c) && c!='\033');		/* \033 = ESC */
X     switch (c) {
X		case '\033': { shiptype *tempship;
X		    tempship = oldship;
X		    ship = oldship;
X		    oldship = tempship;
X		    redraw = 1;
X		    Mod=0;
X		    touchwin(stdscr);
X		    } break;
X
X		case 'o':
X			/* on/off switch */
X		    if (has_switch(ship)) {
X		      move(SWprompty,SWpromptx);
X		      ship->on = !ship->on;
X		      printw("(o)%s", ship->on ? "n " : "ff");
X		      Mod = 1;
X		      if (ship->on) {
X			      move(SWprompty+1,SWpromptx);
X			      switch (ship->type) {
X				case STYPE_MINE:
X					printw("Mine armed and ready.");
X					break;
X				case OTYPE_TRANSDEV:
X					printw("Ready to receive.");
X					break;
X				default: break;
X			      }
X		      }
X		    } else
X			makerr(c);
X		    break;
X
X		case 'd':
X		    if (speed_rating(ship)) {
X      			if (ship->is_docked) {
X			    move(Erry,0);
X			    printw("docked; use undock or launch first.\n");
X			    break;
X      			}
X		     move(Dprompty,Dpromptx); 
X		     printw("%*s", PLACENAMESIZE-1, " ");
X		     move(Dprompty,Dpromptx); 
X		     refresh();
X		     tty_off(); 
X		     if ((c = getchr())!='\n') {
X		      ungetc(c,stdin);
X		      scanw("%43s",s); 
X		      move(Erry,0); refresh();
X		      Locks(1);
X		      where = Getplace(s, 1);
X		      Locks(0);
X		      if (!where.err) {
X			if (where.level==LEVEL_SHIP) {
X			    	ship->destshipno = where.shipno;
X				ship->whatdest = LEVEL_SHIP;
X			} else {
X			    ship->whatdest = where.level;
X			    ship->deststar = where.snum;
X			    ship->destpnum = where.pnum;
X			}
X		      }
X		     }
X		     tty_on();
X		     move(Dprompty,Dpromptx);
X		     printw("%*s", -PLACENAMESIZE, prin_ship_dest(ship) );
X		     Mod=1;
X		    } else
X			makerr(c);
X		    break;
X
X		case 'r':
X		case 's':
X		    if (speed_rating(ship)) {
X		     do {
X		      mvaddch(Sprompty, Spromptx, '?');
X		      move(Sprompty, Spromptx);
X		      refresh();
X		      c = getchr();
X		      if (c=='?') {
X			move(10,0);
X		       if (ship->type==OTYPE_OMCL) {
X			clrtobot();
X			printw("Desired responses:\n");
X			printw("1 -- Suppress emotions\n");
X		       } else {
X			printw("Speed rating for this ship is %d.\n\n", speed_rating(ship));
X			clrtobot();
X			printw("Speed settings:\n0 -- Full stop\n");
X			printw("1 -- Slow (fuel efficient)\n");
X			if (speed_rating(ship) >= 2)
X				printw("2 -- Standard\n");
X			if (speed_rating(ship) >= 3)
X				printw("3 -- Three quarter\n");
X			if (speed_rating(ship) >= 4)
X				printw("4 -- Flank (wastes fuel)\n");
X			if (speed_rating(ship) >= 5)
X				printw("5 -- RAMMING SPEED, MR. SULU!!");
X		       }
X		       move(Sprompty, Spromptx);
X		       refresh();
X		      } else if (isspace(c)) {
X			  c = ship->speed + '0';
X		      } else if (c < '0' || c > speed_rating(ship) + '0') {
X			  move(Erry,0);
X			  printw("Maximum speed is %c.",speed_rating(ship) + '0');
X			  refresh();
X			  c = '?';
X		      }
X		     } while (c=='?');
X		     ship->speed = c - '0';
X		     Mod=1;
X		    } else
X			makerr(c);
X		    break;
X
X		case 't':
X		    if (ship->type==STYPE_MINE) {
X			move(Tprompty,Tpromptx); clrtoeol();
X			refresh(); tty_off();
X
X	ship->orders.object.number = 0;
X
X			scanw("%hd", &ship->orders.object.number);
X			tty_on();
X			if (ship->orders.object.number < 0)
X				ship->orders.object.number = 0;
X			move(Tprompty,Tpromptx);
X			printw("%d",ship->orders.object.number); clrtoeol();
X
X		    } else if (ship->type==OTYPE_TRANSDEV) {
X
X			move(Tprompty,Tpromptx); clrtoeol();
X			refresh(); tty_off();
X
X	ship->orders.object.number = 0;
X
X			scanw("%hd", &ship->orders.object.number);
X			tty_on();
X			move(Tprompty,Tpromptx);
X			printw("%d",ship->orders.object.number); clrtoeol();
X
X			} else
X			makerr(c);
X
X		    break;
X
X		case 'a':
X		    if (can_aim(ship)) {
X		      if (ship->type==OTYPE_GTELE || ship->type==OTYPE_TRACT 
X				  || ship->fuel>=FUEL_MANEUVER) {
X			move(4,12); clrtoeol(); refresh();
X			tty_off();
X			if ((c=getchr())!='\n') {
X			  ungetc(c,stdin);
X			  scanw("%43s", s);
X			  move(Erry,0); refresh();
X			  pl = Getplace(s,1);
X			  if (pl.err) {
X				break;
X			  } else {
X				ship->orders.aimed_at.level = pl.level;
X				ship->orders.aimed_at.pnum = pl.pnum;
X				ship->orders.aimed_at.snum = pl.snum;
X				ship->orders.aimed_at.shipno = pl.shipno;
X				if (ship->type!=OTYPE_TRACT && 
X						ship->type!=OTYPE_GTELE)
X					ship->fuel -= FUEL_MANEUVER;
X				if (ship->type==OTYPE_GTELE || 
X						ship->type==OTYPE_STELE)
X					mk_expl_aimed_at(ship);
X				Mod=1;
X			  }
X			}
X			move(4,12);
X		        printw("%*s", -PLACENAMESIZE, prin_aimed_at(ship) );
X		      } else {
X			move(Erry,0);
X			printw("Not enough maneuvering fuel (%.2f).",FUEL_MANEUVER);
X		      }
X		    } else
X			makerr(c);
X		    break;
X
X		case 'i':
X		    if (ship->type==STYPE_MIRROR) { unsigned i;
X			    move(5,14); refresh();
X			    tty_off(); 	/* unset cbreak */
X			    if ((c=getchr())!='\n') {
X			      ungetc(c,stdin);
X			      scanw("%u",&i); 
X			      ship->orders.aimed_at.intensity = i;
X			      Mod=1;
X			      if (ship->orders.aimed_at.intensity>100)
X				  ship->orders.aimed_at.intensity=100;
X			      else if (ship->orders.aimed_at.intensity<0)
X				  ship->orders.aimed_at.intensity=0;
X			    }
X			    move(5,14);
X			    printw("%3d",ship->orders.aimed_at.intensity); 
X			    tty_on(); 
X		    } else 
X			makerr(c);
X		    break;
X
X		case 'b':
X		    if (can_bombard(ship)) {
X			move(Bprompty,0);
X			clrtoeol();
X			ship->orders.o.bombard = !ship->orders.o.bombard;
X			Mod=1;
X			if (ship->orders.o.bombard)
X			   if (ship->whatdest==LEVEL_PLAN)
X				printw("(b)OMBARD planet %s", 
X					ship->whatdest==LEVEL_PLAN ? 
X					prin_ship_dest(ship) : "" );
X			   else
X				printw("(b)OMBARD ON (no planet specified)");
X			else
X			      printw("(b)ombard off");
X		    } else
X			makerr(c);
X		    break;
X
X		case '?':
X		    move(13,0); clrtobot();
X		    if (speed_rating(ship))
X		        printw(" d -- destination\n s -- speed\n");
X		    if (can_aim(ship)) {
X			printw(" a -- object aimed at\n");
X		    	if (ship->type==STYPE_MIRROR)
X				printw(" i -- intensity\n");
X		    }
X		    if (has_switch(ship))
X			printw(" o -- turn object on/off\n");
X		    if (ship->type==STYPE_MINE)
X			printw(" t -- trigger radius\n");
X		    if (ship->type==OTYPE_TRANSDEV)
X			printw(" t -- transporter target\n");
X		    if (can_bombard(ship))
X			printw(" b -- bombard of destination planet on/off\n");
X		    printw("ESC-- reset all orders made\n");
X		    printw("' '-- adv to next ship/object\n");
X		    printw(" ? -- help\n");
X		    printw("^C -- quit order\n");
X		    break;
X
X		case ' ':	 /* no orders */
X		    break;
X		
X		default:
X		    makerr(c);
X		    break;
X       }
X      putship(order_shdata,ship,shipno);
X
X    } while (c!=' ');
X
X    if (Mod) {
X      ship->notified = 0;
X      putship(order_shdata,ship,shipno);
X    }
X
X  }
X
X }
X
X *nextship = ship->nextship;
X
X close(order_shdata);
X free(ship);
X free(oldship);
X tty_off();
X
X return Mod;
X
X}
X
X
Xint plan_give_orders(APcount, filepos)
Xint APcount;
Xregister int filepos;	/* filepos of planet */
X{
X int sh;
X planettype *p;
X int plan_give_orders_pdata,Planmod=0;
X
X Locks(1);	/* we are only looking up data unchanged by the shell */
X openpdata(&plan_give_orders_pdata);
X getplanet(plan_give_orders_pdata,&p,filepos);
X close(plan_give_orders_pdata);
X Locks(0);
X
X sh = p->ships;
X while (sh)
X	Planmod |= give_orders(APcount, sh, &sh);
X
X free(p);
X return Planmod;
X
X}
X
X
Xint star_give_orders(APcount, num)
Xint APcount;
Xreg int num;
X{
X int sh,Starmod=0;
X reg int i;
X
X  sh = Stars[num]->ships;
X  while (sh)
X        Starmod |= give_orders(APcount, sh, &sh);
X
X  for (i=0; i<Stars[num]->numplanets; i++)
X     Starmod |= plan_give_orders(APcount, Stars[num]->planetpos[i]);
X
X  return Starmod;
X}
X
X
X
X/* 
X * return what the ship is aimed at, if it's a mirror 
X */
Xchar *prin_aimed_at(ship)
Xshiptype *ship;
X{
X placetype targ;
X
X  targ.level = ship->orders.aimed_at.level;
X  targ.snum = ship->orders.aimed_at.snum;
X  targ.pnum = ship->orders.aimed_at.pnum;
X  targ.shipno = ship->orders.aimed_at.shipno;
X  return Dispplace(&targ);
X}
X
X
X
Xchar *prin_ship_dest(ship)
Xshiptype *ship;
X{
X placetype dest;
X
X  dest.level = ship->whatdest;
X  dest.snum = ship->deststar;
X  dest.pnum = ship->destpnum;
X  dest.shipno = ship->destshipno;
X  return Dispplace(&dest);
X}
X
X
X
Xmakerr(c)
Xchar c;
X{
X   move(Oprompty,Opromptx);
X   printw("'%c':illegal order.",c);
X   move(Oprompty,Opromptx);
X   refresh();
X}
X
X
X
X
X/* 
X * mark wherever the ship is aimed at, as explored by the owning player.
X */
Xmk_expl_aimed_at(s)
Xshiptype *s;
X{
Xdouble dist;
Xstartype *str;
Xplanettype *p;
Xint sdata,pdata;
Xfloat xf,yf;
X
X str = Stars[s->orders.aimed_at.snum];
X
X if (s->is_docked && s->whatdest==LEVEL_PLAN) {
X	openpdata(&pdata);
X	getplanet(pdata, &p, Stars[s->storbits]->planetpos[s->pnumorbits]);
X	close(pdata);
X	xf = Stars[s->storbits]->xpos + p->xpos + s->xpos;
X	yf = Stars[s->storbits]->ypos + p->ypos + s->ypos;
X	free(p);
X } else {
X	xf = s->xpos;
X	yf = s->ypos;
X }
X
X switch (s->orders.aimed_at.level) {
X	case LEVEL_UNIV:
X		move(Erry,0);
X		printw("There is nothing out here to aim at.");
X		break;
X	case LEVEL_STAR:
X		move(Erry,0);
X		printw("Star %s ", prin_aimed_at(s));
X		if ((dist=sqrt(Distsq(xf, yf, str->xpos, str->ypos))) <= tele_range(Race, s) ) {
X			openstardata(&sdata);
X			getstar(sdata, &str, s->orders.aimed_at.snum);
X			 setbit(str->explored,Playernum);
X			putstar(sdata, str, s->orders.aimed_at.snum);
X			close(sdata);	/* don't need to care about Stars */
X			printw("has been surveyed, distance %g.\n",dist);
X		} else {
X			printw("is too far to see (%g, max %g).\n", 
X						dist, tele_range(Race, s) );
X		}
X		break;
X	case LEVEL_PLAN:
X		move(Erry,0);
X		printw("Planet %s ", prin_aimed_at(s));
X		openpdata(&pdata);
X		getplanet(pdata, &p, str->planetpos[s->orders.aimed_at.pnum]);
X		if ((dist=sqrt(Distsq(xf, yf, str->xpos+p->xpos, str->ypos+p->ypos))) <= tele_range(Race, s) ) {
X			setbit(str->explored,Playernum);
X			p->info[Playernum-1].explored = 1;
X			putplanet(pdata, p, str->planetpos[s->orders.aimed_at.pnum]);
X			free(p);
X			printw("has been surveyed, distance %g.\n", dist);
X		} else {
X			printw("is too far to see (%g, max %g).\n", 
X						dist, tele_range(Race, s) );
X		}
X		close(pdata);
X		break;
X	case LEVEL_SHIP:
X		move(Erry,0);
X		printw("You can't see anything of use there.\n");
X		break;
X }
X}
X
X
X
Xorder_handler()
X{
X tty_off();
X Locks(0);
X close(order_shdata);
X close(order_pdata);
X close(order_stardata);
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 15738 -ne `wc -c <'order.c'`; then
    echo shar: \"'order.c'\" unpacked with wrong size!
fi
# end of 'order.c'
fi
echo shar: End of archive 1 \(of 8\).
cp /dev/null ark1isdone
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