[comp.sources.games] v10i007: gb3 - Galactic Bloodshed, an empire-like war game [Ver. 2.0], Part07/14

billr@saab.CNA.TEK.COM (Bill Randle) (06/02/90)

Submitted-by: VANCLEEF@mps.ohio-state.edu
Posting-number: Volume 10, Issue 7
Archive-name: gb3/Part07
Supersedes: GB2: Volume 7, Issue 44-51



#! /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 7 (of 14)."
# Contents:  Docs/build.doc server/VN.c server/moveship.c
#   server/orbit.c server/rst.c
# Wrapped by billr@saab on Fri Jun  1 11:53:37 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Docs/build.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Docs/build.doc'\"
else
echo shar: Extracting \"'Docs/build.doc'\" \(4606 characters\)
sed "s/^X//" >'Docs/build.doc' <<'END_OF_FILE'
XBUILD			Galactic Bloodshed			BUILD
X
X
XNAME
X  [1] build -- construct a ship
X
XSYNTAX
X	build [<type>] [<x,y>]
X
XDESCRIPTION
X  The 'build' command enables the user to construct a ship on the current scope 
X(ship or planet) provided there are enough resources there to do so.
XSome ship types require a factory designated to construct it. Some ships may
Xonly be constructed in space, while other types can be constructed without
Xand additional help. Specifically, there are 4 ship build classes.
X
X   These ships may only be constructed at a factory 'F':
X	s, D, B, I, C, d, f, e, c, t, =.
X
X   These ships may only be constructed in space:
X	X, H, S, O, m.
X
X   These ships can be constructed on a planet without need of a factory 'F':
X	p, !, +, \, -, a, g, v, V, Q, L, w, :, G, F, T, &, A, [, R, P.
X
X   In addition, these ships can be constructed on board warships
X	+, :.
X
X   The following ships may construct ships in space
X	s, H, S, O, c, !.
X   
X   If your ship type can be used to construct other types of ships (and isn't a
Xfactory 'F') you must first 'cs' to that ship. Then use the 'build' command to 
Xinitiate construction. Note that you must have enough resources on board the
Xvessel required to build the ship. If you try to build an illegal
Xship type, the program will remind you.
X
X   If your ship is a factory 'F', you must 'cs' to the factory, and type 'build'. If the 
Xfactory is online (turned on via the 'order' command) and has been programmed
Xto build a specific ship design, it will construct the ship in the same sector
Xas the factory. Resources must be available to construct the ship at the
Xplanet where the factory is located. See help on the 'make' command and
X'modify' command for details on ship design. When a factory is turned online
Xvia the 'order' command, twice the resource cost of the ship being produced at 
Xthe factory will be deducted form the planetary stockpile. Once online, a factory
Xcannot be turned 'off' (via order). The factory is then committed to producing
Xthe class of ships it has been programmed. Players should therefore be warned
Xto make absolutely sure that the ship type and parameters are acceptable before
Xturning the factory online.
X
X
X  A player may do 'build ?' for details on the types of ships available at his
Xcurrent technology level. Ships are identified by their letter.  The player can also 
Xget a short paragraph description of a ship by typing a '?' and the ship letter.
X
X   If the ship type does not need another ship type to construct it, the player
Xmust specify the sector to put the newly made ship in.This sector must belong to the
Xplayer and be an area that can support his race.
X
X  At this point the resource point cost will be deducted from the player's
Xstockpiles.  The ``load'' should be used after building, since many ships
Xrequire at least one crew member to operate, and the player may wish to
Xput fuel and weapons aboard.
X
X   War ships are typically built with 50% damage level. This damage level
Xcan be reduced by the normal repair procedure. Basically, you need to
Xhave resources loaded onto the ship, since repair uses up resources.
XSome ships have no resource capacity. These ships may repair for free.
XSpace stations and ships docked with them also repair damage for free.
XThe maximum damage that can be repaired in an update is computed
Xby maxrep = %of maximum crew * REPAIR_RATE wherethe repair rate
Xis usually 25%. The cost in resources is 0.005 * maxrep * ship build cost.
X
X
X  A short explanation of ship capabilities:
X
Xltr           ship  carg armr dstcap guns  mass fuelcap ^crew tech speed cost
X s         Shuttle    40    1      2    1    10      20    25   15    2    50
X
X ltr: Ship letter used to identfy the ship.  This is the letter you must
X	type in to choose that ship.
X ship: A short descriptive name for that type of ship.
X carg: Maximum cargo (resources) the ship can carry (see ``load'').
X armr: Resistance to damage in a straight ratio; the higher, the better.
X dstcap: Maximum destructive capacity (weapons) the ship can carry.
X guns: Amount of destructive capacity the ship can fire at once.
X mass: Weight of the ship (in Standard Units).  Heavier ships move slower.  This
X	value changes as things are loaded/unloaded on the ship.
X fuelcap: Maximum fuel the ship can carry.
X mintech: You must be at this tech or above to build the ship.
X cost: Amount of resource points required to build.
X speed: the speed rating of the ship; it cannot be ordered to a value
X	greater than this number.
X ^crew: Maximum number of crew (or tons of biomass) the ship can carry.
X
X
XSEE ALSO
X load, stock, report, ship, make, modify
X
END_OF_FILE
if test 4606 -ne `wc -c <'Docs/build.doc'`; then
    echo shar: \"'Docs/build.doc'\" unpacked with wrong size!
fi
# end of 'Docs/build.doc'
fi
if test -f 'server/VN.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'server/VN.c'\"
else
echo shar: Extracting \"'server/VN.c'\" \(10695 characters\)
sed "s/^X//" >'server/VN.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
X * Restrictions in GB_copyright.h.
X *
X * VN.c -- assorted Von Neumann machine code:
X *  do_VN() -- called by doship()
X *  planet_doVN() -- called by doplanet()
X */
X#include "GB_copyright.h"
X#define EXTERN extern
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include "doturn.h"
X#include "power.h"
X#include "buffers.h"
X
Xdo_VN(ship,shipno)
Xshiptype *ship;
Xint shipno;
X{
Xint r; 
Xplanettype *p;
Xchar buf[300];
X
X  if (ship->on) {
X
X    if (ship->whatorbits==LEVEL_PLAN)
X    	p = planets[ship->storbits][ship->pnumorbits];
X
X    if (ship->whatorbits==LEVEL_PLAN &&
X	ship->is_docked && ship->whatdest==LEVEL_PLAN) {
X		/* make sure the planet is updated */
X	Stinfo[ship->storbits][ship->pnumorbits].inhab = 1;
X
X		/* launch if no assignment */
X	if (ship->object.number2 == 0) {
X		if (ship->fuel >= Shipdata[OTYPE_VN][ABIL_FUELCAP]) {
X			/* launch. */
X		   ship->object.number2 = 0; /* no current assignment */
X		   ship->xpos = Stars[ship->storbits]->xpos + planets[ship->storbits][ship->pnumorbits]->xpos + int_rand(-10,10);
X		   ship->ypos = Stars[ship->storbits]->ypos + planets[ship->storbits][ship->pnumorbits]->ypos + int_rand(-10,10);
X		   ship->is_docked = 0;
X		   ship->whatdest = LEVEL_UNIV;
X		} else {
X		   /* instead of stealing, wait until we have enough fuel */
X		 /*for (r=1; !f && r<=Num_races; r++)
X		  if (p->info[r-1].fuel >= Shipdata[OTYPE_VN][ABIL_FUELCAP])
X			f = r;
X	          if (f) {
X			 /* we found a player to steal fuel from */
X			/*ship->fuel += Shipdata[OTYPE_VN][ABIL_FUELCAP];
X			ship->mass += Shipdata[OTYPE_VN][ABIL_FUELCAP]*MASS_FUEL;
X		  	p->info[f-1].fuel -= Shipdata[OTYPE_VN][ABIL_FUELCAP];
X			sprintf(buf,"%d fuel stolen by %s #%d on planet /%s/%s!\n",
X			   Shipdata[OTYPE_VN][ABIL_FUELCAP],
X			   Shipnames[OTYPE_VN],
X			   shipno, Stars[ship->storbits]->name,
X			   Stars[ship->storbits]->pnames[ship->pnumorbits]);
X			notify(f, buf);
X		   }*/
X
X	     }
X	} else {
X		/* VNs: I decided to take out this stuff, since from now
X		 *  on they get pissed at people.  They will be much
X		 *  more low-profile, taking resources from the player
X		 *  only indirectly.  I'll keep this stuff in comments,
X		 *  though, for posterity, I guess.
X		 */
X
X		/* we have an assignment.  Since we are landed, this means
X		   we are engaged in building up resources/fuel. */
X		/* steal resources from other players */
Xreg int i,f; int nums[MAXPLAYERS+1];
X		  /* permute list of people to steal from */
X
X/* I kind of like this stuff -Garrett */
X		for (i=1; i<=Num_races; i++)
X			nums[i] = i;
X		for (i=1; i<=Num_races; i++) {
X			f = int_rand(1,Num_races);
X			swap(nums[i], nums[f]);
X		}
X		for (f=0,i=1; i<=Num_races; i++)
X			if (p->info[nums[i]-1].resource)
X				f = nums[i];
X		if (f) {
X		  	p->info[f-1].resource -= 
X				MIN( p->info[f-1].resource, 
X					Shipdata[OTYPE_VN][ABIL_COST]);
X			ship->resource += Shipdata[OTYPE_VN][ABIL_COST];
X			ship->mass += Shipdata[OTYPE_VN][ABIL_COST] * MASS_RESOURCE;
X			sprintf(buf,"%d resources stolen by %s #%d\non planet ",
X			     Shipdata[OTYPE_VN][ABIL_COST],
X			     Shipnames[OTYPE_VN], shipno);
X			notify(f, buf);
X			sprintf(buf,"%s!\n", prin_ship_orbits(ship) );
X			notify(f, buf);
X		} else {
X		 /*if no resources to steal, more will be produced in doplanet*/
X		}
X	}
X  } else {
X	/* we are not landed */
X	if (ship->object.number2) {
X		/* we've arrived from somewhere -- look for a place to land.  
X		   this is done on planet turn since we need to scan the
X		   sectormap for a landing spot */
X	} else {
X		/* we were just built & launched */
X		reg int s,min=0,min2=0;
X		  /* find closest unexplored star */
X		for (s=1; s<Sdata.numstars; s++)
X			if (s != ship->storbits &&
X				Distsq(Stars[s]->xpos,Stars[s]->ypos,ship->xpos,ship->ypos) < 
X				Distsq(Stars[min]->xpos,Stars[min]->ypos,ship->xpos,ship->ypos))
X				   min2 = min,min = s;
X			/* don't go there if we have a choice, 
X			   and we have VN's there already */
X		if (isset(Stars[min]->inhabited,1))
X		  if (isset(Stars[min2]->inhabited,1))
X			ship->deststar = int_rand(0,Sdata.numstars-1);
X		  else
X			ship->deststar = min2;	/* 2nd closest star */
X		else
X		      ship->deststar = min;
X		if (Stars[ship->deststar]->numplanets) {
X			ship->destpnum =
X				int_rand(0,Stars[ship->deststar]->numplanets-1);
X		 	ship->whatdest = LEVEL_PLAN;
X			ship->object.number2 = 1;
X		} else {
X			/* no good; find someplace else. */
X			ship->object.number2 = 0;
X		}
X		ship->speed = 1;	/* VN's are very fastidious */
X		fprintf(stderr,"VN #%d headed for star %d, pl %d.\n",shipno,ship->deststar, ship->destpnum);
X			/* we are assigned to go */
X	}
X  }
X 
X }
X
X}
X
X
X
X/*
X *  planet_doVN() : run a VN on a planet.  called by doplanet().
X *    if we're landed on the planet, we check if we have enough resources.
X *	 if we have enough, and we have fuel, build another machine and
X *	 	launch ourselves, and find a place to go to.
X *       if we don't have enough, rove around some and find some.
X *    if we're orbiting a planet, find a place to land there.
X *
X */
X
Xplanet_doVN(ship, shipno, planet)
Xshiptype *ship;
Xint shipno;
Xplanettype *planet;
X{
X reg int i;
X
X     if (ship->on) {
X
X      if (ship->is_docked && ship->whatdest==LEVEL_PLAN) {
X
X	if (ship->object.number2) {
X		/* we are currently trying to construct another
X		   machine */
X	  reg int x,y,a,dum,shipbuild;
X
X	     /* spread VN's all over the planet for display */
X	  /*for (i=1; i<253 && i<=ship->object.number; i++) {
X	    a = round_rand(sqrt((double)ship->object.number));
X	    x = mod(int_rand((int)(ship->xpos-a),(int)(ship->xpos+a)),(int)planet->xpos,dum);
X	    y = mod(int_rand((int)(ship->ypos-a),(int)(ship->ypos+a)),(int)planet->ypos,dum);
X	    Sectinfo[x][y].VN= 1;
X	  }*/
X
X	  shipbuild = (VN_brain.Total_mad > 900 && random()&01) ? OTYPE_BERS : OTYPE_VN;
X	  if ((ship->type==OTYPE_VN) && (ship->resource >= Shipdata[shipbuild][ABIL_COST])) {
X		 shiptype *s2; reg int n;
X
X	   ship->resource -= Shipdata[shipbuild][ABIL_COST];
X	   ship->mass -= Shipdata[shipbuild][ABIL_COST]*MASS_RESOURCE;
X
X		  /* must change size of ships pointer */
X	   ++Num_ships;
X	   ships = (shiptype **)realloc(ships, (Num_ships+1)*sizeof(shiptype*)); 
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(-2,2)) % planet->Maxx;
X	   s2->xpos = abs(s2->xpos);
X	   s2->ypos = ((int)ship->ypos + rposneg()) % 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 = shipbuild;
X
X	s2->armor = Shipdata[shipbuild][ABIL_ARMOR];
X	s2->guns = Shipdata[shipbuild][ABIL_GUNS];
X	s2->size = Shipdata[shipbuild][ABIL_TARGET];
X	s2->max_crew = Shipdata[shipbuild][ABIL_MAXCREW];
X	s2->max_resource = Shipdata[shipbuild][ABIL_CARGO];
X	s2->max_fuel = Shipdata[shipbuild][ABIL_FUELCAP];
X	s2->max_destruct = Shipdata[shipbuild][ABIL_DESTCAP];
X	s2->max_speed = Shipdata[shipbuild][ABIL_SPEED];
X	   s2->base_mass = getmass(s2);
X
X	   s2->mass = s2->base_mass;
X			/* is not dead */
X	   s2->is_alive = 1;
X
X	   if (shipbuild==OTYPE_BERS) {
X		  fprintf(stderr,"VN #%d constructed Bers #%d.\n",shipno,Num_ships);
X		  s2->owner = 1;
X		  s2->on = 1;
X			/* target = person killed the most VN's */
X		  s2->object.number = VN_brain.Most_mad;
X		  sprintf(s2->name,"%d",s2->object.number);
X		  s2->speed = Shipdata[OTYPE_BERS][ABIL_SPEED];
X		  s2->tech = ship->tech + 1.0;
X		  s2->bombard = 1;
X		  s2->protect.self = 1;
X		  s2->protect.planet = 1;
X	   } else {
X		  fprintf(stderr,"VN #%d constructed VN #%d.\n",shipno,Num_ships);
X		  s2->tech = ship->tech + 1.0;
X
X	   	  n = int_rand(3,MIN(10,SHIP_NAMESIZE));	/* for name */
X	   	  s2->name[n] = '\0';
X	   	  while (n--)
X			s2->name[n] = (random()&01) + '0';
X
X		  s2->owner = (int_rand(0,1) ? ship->owner : 1);
X			/* one of them */
X		  s2->object.number = 1;
X			/* is not building any VN's */
X		  ship->object.number2 = 0;
X			/* turn it on */
X		  s2->on = 1;
X			/* set speed */
X		  s2->speed = 1;
X		  s2->bombard = 0;
X	   }
X
X	} else {
X		/* try and make some resources(VNs)/detruct(Bers) by ourselves.
X		   more might be stolen in doship */
X		sectortype *s; reg int oldres,xa,ya,dum,prod;
X		s = &Sector(*planet,(int)ship->xpos, (int)ship->ypos);
X
X		if ((oldres = s->resource) == 0) {
X		   /* move to another sector */
X		   xa = int_rand(-1,1);
X		   ship->xpos = mod((int)ship->xpos+xa,planet->Maxx,dum);
X		   ya = (ship->ypos==0.0) ? 1 : 
X		      ( (ship->ypos==planet->Maxy-1) ? -1 : rposneg());
X		   ship->ypos += ya;
X		} else {
X		   /* mine the sector */
X			s->resource *= VN_RES_TAKE;
X			prod = oldres - s->resource; /* poor way for a player to mine resources */
X		if(ship->type==OTYPE_VN) {
X			ship->resource += prod;
X			ship->mass += prod * MASS_RESOURCE;
X		} else {
X			ship->destruct += prod; /* Berserkers need weapons */
X			ship->mass += prod * MASS_DESTRUCT;
X			}
X		
X			ship->fuel += prod;
X			ship->mass += prod * MASS_FUEL;
X		}
X	}
X       } else {
X	/* we have no assignment -- we must launch. taken care of
X	   in doship */
X       }
X
X      } else {	/* orbiting a planet */
X
X	if (ship->object.number2) {
X
X	 if (ship->whatdest==LEVEL_PLAN && ship->deststar==ship->storbits && 
X		ship->destpnum==ship->pnumorbits) {
X			/* we just arrived from somewhere */
X	    if (planet->type==TYPE_GASGIANT) {
X	      if (ship->fuel >= Shipdata[OTYPE_VN][ABIL_FUELCAP])
X		ship->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
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			ship->xpos = x;
X			ship->ypos = y;
X			ship->object.number2 = 1;
X			/* number2 means we are currently
X			   busy here */
X		} else {
X			 /* head somewhere else */
X			ship->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}
END_OF_FILE
if test 10695 -ne `wc -c <'server/VN.c'`; then
    echo shar: \"'server/VN.c'\" unpacked with wrong size!
fi
# end of 'server/VN.c'
fi
if test -f 'server/moveship.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'server/moveship.c'\"
else
echo shar: Extracting \"'server/moveship.c'\" \(11933 characters\)
sed "s/^X//" >'server/moveship.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
X * Restrictions in GB_copyright.h.
X *
X *  moveship -- moves specified ship according to its orders.
X *	also deducts fuel from the ship's stores.
X */
X
X#include "GB_copyright.h"
X#define EXTERN extern
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include "doturn.h"
X#include "buffers.h"
X#include <math.h>
X
X
X/* amount to move for each dir level. I arrived on these #'s only after
X	hours of dilligent tweaking */
X  /* amount to move for each directory level  */
Xfloat MoveConsts[] = { 500.0, 200.0, 30.0 };
X  /* amnt to move for each ship speed level (ordered) */
Xfloat SpeedConsts[] = { 0.0, 0.61, 1.26, 1.50, 1.73, 1.81, 1.90, 1.93, 1.96, 1.97};
X  /* amount of fuel it costs to move at speed level */
X
X
XMoveship(shipno,s)
Xint shipno;
Xshiptype *s;
X{
X double stardist,movedist,truedist,dist,xdest,ydest,sn,cs;
X float fuse,mfactor,heading;
X int destlevel,deststar=0,destpnum=0;
X boolean move_err = 0;
X shiptype *dsh;
X startype *ost,*dst;
X planettype *opl,*dpl;
X
Xif(fabs(s->xpos) > 999999999. || fabs(s->ypos) > 999999999.)
X	{
X	printf("we got a problem here!\n");
X	return;
X	}
X
Xif(s->hyper_drive.on) { 	/* do a hyperspace jump */
X/* printf("hyperspace ship #%d\n", shipno); */
X	if(s->hyper_drive.ready) {
X/* uses up fuel to jump. This is dependent on the mass of the ship - if you don't have
X	enough fuel for the jump - jump is cancelled and a message sent to the owner */
X	 dist = sqrt( Distsq(s->xpos, s->ypos, Stars[s->deststar]->xpos, Stars[s->deststar]->ypos));
X	fuse = HYPER_DRIVE_FUEL_USE * s->mass 
X		* (dist/HYPER_DIST_FACTOR) * (dist/HYPER_DIST_FACTOR);
X	if(s->fuel < fuse) {
X		  sprintf(telegram_buf,
X			   "%s #%d %s at system %s does not have %.1ff to do hyperspace jump.\n",
X			   Shipnames[s->type], shipno, s->name, prin_ship_orbits(s), fuse);
X			push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf);
X		s->hyper_drive.on = 0;
X		return;
X		}
X
X   		s->fuel -= fuse;
X   		s->mass -= fuse * MASS_FUEL;
X
X   		heading = atan2( Stars[s->deststar]->xpos - s->xpos, Stars[s->deststar]->ypos - s->ypos);
X		sn = sin(heading);
X		cs = cos(heading);
X	 	s->xpos = Stars[s->deststar]->xpos + 	sn * 0.9 * SYSTEMSIZE;
X	 	s->ypos = Stars[s->deststar]->ypos + cs * 0.9 * SYSTEMSIZE;
X
X		s->whatdest = LEVEL_UNIV;
X		s->whatorbits = LEVEL_STAR;
X		s->storbits = s->deststar;
X
X		s->hyper_drive.on = 0;
X		s->hyper_drive.ready = 0;
X		s->hyper_drive.charge = 0;
X		  sprintf(telegram_buf,"%s #%d %sarrived at system %s.\n",
X			   Shipnames[s->type], shipno, s->name,
X				prin_ship_orbits(s));
X			str_cat(telegram_buf, buf);
X		push_message(TELEG_PLAYER_AUTO, s->owner, buf);
X		} else {
X			if(s->hyper_drive.charge==HYPER_DRIVE_READY_CHARGE)
X				s->hyper_drive.ready = 1;
X			else		
X				s->hyper_drive.charge += 1;
X			  }
X	return;
X	}
X
X if (s->speed && !s->is_docked && s->is_alive && (s->whatdest!=LEVEL_UNIV
X		|| s->navigate.on) ) {
X
X /*printf("moving ship #%d\n",shipno);*/
X
X    /* subtract fuel from the ship */
X   fuse = 0.5 * s->speed * (1 + s->protect.evade) * s->mass * FUEL_USE;
X
X   if (s->fuel < fuse) {
X	  /* ship is out of fuel; do whatever it is to do */
X	if (!s->notified) {
X	  s->notified = 1;
X	  s->fuel = 0.0;		/* in case it's negative */
X	  msg_OOF(s, shipno, telegram_buf);	/* send OOF notify */
X
X		/* kill the ship if we lost it and it's expendable */
X	  if (s->whatorbits == LEVEL_UNIV && Shipdata[s->type][ABIL_COST]<=50) {
X	    sprintf(telegram_buf,"Ship #%d has been lost in deep space.\n",shipno);
X	push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf);
X	    kill_ship(s);
X	  }
X	}
X	return;
X   }
X
X/*******   move the ship towards dest ******/
X	if(s->navigate.on){   /* follow navigational orders */
X	heading = .0174329252*s->navigate.bearing;
X   mfactor = SHIP_MOVE_SCALE * (1. - .01 * s->rad) * (1. - .01 * s->damage) 
X        * SpeedConsts[s->speed] * MoveConsts[s->whatorbits];
X
X   	s->fuel -= fuse;
X   	s->mass -= fuse * MASS_FUEL;
X
X	sn = sin(heading);
X	cs = cos(heading);
X   	xdest = sn * mfactor;
X   	ydest = cs * mfactor;
X
X   	s->xpos += xdest;
X   	s->ypos -= ydest;
X
X	s->navigate.turns --;
X	if(s->navigate.turns == 0) s->navigate.on = 0; 
X
X} else {  /*		navigate is off            */
X
X   switch (s->whatdest) {
X      case LEVEL_STAR:
X	 destlevel = LEVEL_STAR;
X	 deststar = s->deststar;
X	 xdest = Stars[deststar]->xpos;
X	 ydest = Stars[deststar]->ypos;
X	 break;
X      case LEVEL_PLAN:
X	 destlevel = LEVEL_PLAN;
X	 deststar = s->deststar;
X	 destpnum = s->destpnum;
X	 xdest = Stars[deststar]->xpos + planets[deststar][destpnum]->xpos;
X	 ydest = Stars[deststar]->ypos + planets[deststar][destpnum]->ypos;
X	 if(sqrt( Distsq(s->xpos, s->ypos, xdest, ydest)) <= DIST_TO_LAND)
X	   destlevel = LEVEL_UNIV;
X	 break;
X      case LEVEL_SHIP:
X	 dsh = ships[s->destshipno];
X	 destlevel = LEVEL_SHIP;
X	 deststar = dsh->storbits;
X	 destpnum = dsh->pnumorbits;
X	 xdest = dsh->xpos;
X	 ydest = dsh->ypos;
X	 if(sqrt( Distsq(s->xpos, s->ypos, xdest, ydest))==0.0)destlevel = LEVEL_UNIV;
X	 break;
X      default:
X	 printf("wow, seriously bad error.\n");
X	 return;
X	 break;
X   }
X   dst = Stars[deststar];
X   ost = Stars[s->storbits];
X   dpl = planets[deststar][destpnum];
X   opl = planets[s->storbits][s->pnumorbits];
X
X
X/*  update new xpos,ypos */
X   heading = atan2( xdest-s->xpos, 
X	((ydest - s->ypos)==0.0) ? 0.000001 : (ydest-s->ypos) );
X   mfactor = SHIP_MOVE_SCALE * (1. - .01 * s->rad) * (1. - .01 * s->damage)
X       * SpeedConsts[s->speed] * MoveConsts[s->whatorbits];
X
X
X   truedist = movedist = sqrt( Distsq(s->xpos, s->ypos, xdest, ydest));
X
X
X    /* keep from ending up in the middle of the system. */
X	/* Change the distance so that we
X	   don't go all the way into the system. */
X   if (s->whatorbits==LEVEL_UNIV ||
X	  (destlevel==LEVEL_STAR && s->storbits!=deststar) ||
X	  (destlevel==LEVEL_PLAN && s->storbits!=deststar) &&
X	   truedist >= SYSTEMSIZE)
X   	movedist -= SYSTEMSIZE * 0.90;
X   else if (destlevel==LEVEL_PLAN && s->whatorbits==LEVEL_STAR &&
X		s->storbits==deststar && truedist >= PLORBITSIZE)
X	 /* we're in a system, don't go all the way into a planetary
X	    orbit */
X	movedist -= PLORBITSIZE * 0.90;
X
X
X   if (s->whatdest==LEVEL_SHIP && s->owner!=ships[s->destshipno]->owner
X	&& !isset(races[s->owner-1]->allied, ships[s->destshipno]->owner)
X   	   && truedist > SYSTEMSIZE*4.0) {
X	  /* (an allied ship lets you follow it..) */
X	  /* we lost sight of the destination ship. */
X	  /* should change SYSTEMSIZE*1.0 to calculated gun range.. */
X	s->whatdest = LEVEL_UNIV;
X	s->protect.evade = 0;
X   	sprintf(telegram_buf,"Telecomm from ship #%d at %s\n\n", 
X				shipno, prin_ship_orbits(s));
X    	sprintf(buf,"%s #%d %s lost sight of destination ship #%d.\n", 
X			Shipnames[s->type],shipno,s->name,s->destshipno);
X		str_cat(telegram_buf, buf); 
X	push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf);
X	return;
X   }
X
X
X   if (truedist > DIST_TO_LAND) {
X   	s->fuel -= fuse;
X   	s->mass -= fuse * MASS_FUEL;
X
X		/* dont overshoot */
X	sn = sin(heading);
X	cs = cos(heading);
X   	xdest = sn * mfactor;
X   	ydest = cs * mfactor;
X    	if (hypot(xdest, ydest) > movedist) {
X		xdest = sn * movedist;
X		ydest = cs * movedist;
X	}
X   	s->xpos += xdest;
X   	s->ypos += ydest;
X   }
X
X/*****  check if far enough away from object it's orbiting to break orbit *****/
X
X  if (s->whatorbits==LEVEL_PLAN) {
X		dist = sqrt( Distsq(s->xpos, s->ypos, 
X			ost->xpos+opl->xpos, ost->ypos+opl->ypos ) );
X/*	 printf("dist from orbts planet is %lf\n", dist);*/
X	 if (dist > PLORBITSIZE) {
X		s->whatorbits = LEVEL_STAR;
X/*	 	printf("ship #%d departed from planet /%s/%s.\n",shipno, ost->name, ost->pnames[s->pnumorbits]);*/
X	 }
X
X   } else if (s->whatorbits==LEVEL_STAR) {
X	dist = sqrt( Distsq(s->xpos, s->ypos, ost->xpos, ost->ypos ) );
X/*	 printf("star orbits dist is %lf\n", dist); */
X	 if (dist > SYSTEMSIZE) {
X		s->whatorbits = LEVEL_UNIV;
X		s->protect.evade = 0;
X/*	 	printf("ship #%d departed from system %s.\n",shipno, ost->name); */
X	 }
X   }
X
X	/*******   check for arriving at destination *******/
X
X   if (destlevel==LEVEL_STAR || (destlevel==LEVEL_PLAN
X	&& !(s->whatorbits!=LEVEL_UNIV && s->storbits==deststar) ) ) {
X       		/* not in same star system as deststar */
X
X	 stardist = sqrt(Distsq(s->xpos,s->ypos,dst->xpos,dst->ypos));
X/*	 printf("dist from dest syst is %g\n",stardist); */
X	 if (stardist <= SYSTEMSIZE * 1.5) {
X	   if (s->type == STYPE_POD)
X		s->notified = 1;	/* signal to explode */
X	    /* mark as explored & inhabited by that player */
X	   setbit(dst->explored, s->owner);
X	   setbit(dst->inhabited, s->owner);
X/*	   printf(" ship #%d arrived at system %s.\n",shipno,dst->name); */
X	   s->whatorbits = LEVEL_STAR;
X	   s->storbits = deststar;
X	   if (destlevel == LEVEL_STAR) {
X		  sprintf(telegram_buf,"%s #%d %sarrived at system %s.\n",
X			   Shipnames[s->type], shipno, s->name,
X			prin_ship_orbits(s));
X			str_cat(telegram_buf, buf);
X	push_message(TELEG_PLAYER_AUTO, s->owner, buf);
X		/* clear orders if the ship is not headed to a planet in
X		   this system */
X	   	  s->whatdest = LEVEL_UNIV;
X	   }
X	 }
X
X   } else if ( destlevel==LEVEL_PLAN && 
X		 (s->whatorbits!=LEVEL_UNIV && deststar==s->storbits  &&
X		!(s->whatorbits==LEVEL_PLAN && s->pnumorbits==destpnum)) ) {
X	/* headed for a planet in the same system, & not already there.. */
X		dist = sqrt( Distsq(s->xpos, s->ypos, 
X			dst->xpos+dpl->xpos, dst->ypos+dpl->ypos ) ) ;
X/*	 printf("dist from target planet is %lf\n",dist ); */
X	 if (dist<=PLORBITSIZE) {
X		 /* mark planet as explored by that player */
X	   dpl->info[s->owner-1].explored = 1;
X		 /* mark sun as explored too, if the ship might have bypassed it
X		    (we are trying to be thorough here) */
X	   setbit(dst->explored, s->owner);
X	   setbit(dst->inhabited, s->owner);
X	   s->whatorbits = LEVEL_PLAN;
X	   s->pnumorbits = destpnum;	
X
X	   sprintf(telegram_buf,"Telecomm from ship #%d\n\n",shipno);
X/* 	   printf("%s #%d arrived at planet /%s/%s.\n", Shipnames[s->type],
X		shipno, ost->name, ost->pnames[s->pnumorbits]); */
X
X	if(dist<=DIST_TO_LAND) {
X	   sprintf(buf,"%s #%d %sarrived at planet %s.\n This ship is close enough to land.\n",Shipnames[s->type],shipno, s->name, prin_ship_orbits(s));
X	} else {
X	   sprintf(buf,"%s #%d %sarriving at planet %s.\n This ship is %4.1f units away.\n",
X				Shipnames[s->type],shipno, s->name, prin_ship_orbits(s),dist);
X		}
X
X
X	str_cat(telegram_buf, buf);
X	   if (s->type==STYPE_ASS) {
X	   	sprintf(buf,"\nEnslavement of the planet is now possible.\n");
X		str_cat(telegram_buf, buf);
X			}
X	push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf);
X	 }
X
X  } 
X
X }
X
X} /* if 'destination' orders */
X
X}
X
X
X
X/* 
X * insert the ship into wherever it's supposed to be.
X *  this is done every turn, for every ship; as a bonus it puts them in
X *  alphabetical order.
X */
Xinsert_sh(sdata, star, pl, s, shipno)
Xstruct stardata *sdata;
Xstartype *star;
Xplanettype *pl;
Xshiptype *s;
Xint shipno;
X{
X
X if (s->is_alive)
X    switch (s->whatorbits) {
X	case LEVEL_UNIV:
X		s->nextship = sdata->ships;
X		sdata->ships = shipno;
X		break;
X	case LEVEL_STAR:
X		s->nextship = star->ships;
X		star->ships = shipno;
X		break;
X	case LEVEL_PLAN:
X		s->nextship = pl->ships;
X		pl->ships = shipno;
X		break;
X	default:
X		break;
X    }
X
X}
X
X
X/* deliver an "out of fuel" message.  Used by a number of ship-updating
X *  code segments; so that code isn't duplicated.
X */
Xmsg_OOF(s, shipno, tbuf)
Xshiptype *s;
Xint shipno;
Xchar *tbuf;
X{
X char buf[200];
X
X	sprintf(buf,"%s #%d is out of fuel at %s\n", Shipnames[s->type],
X				shipno, prin_ship_orbits(s));
X	push_message(TELEG_PLAYER_AUTO, s->owner, buf);
X}
X
X
Xinsert_sh_univ(sdata, s, shipno)
Xshiptype *s;
Xstruct stardata *sdata;
X{
X	s->nextship = sdata->ships;
X	sdata->ships = shipno;
X}
X
X
Xinsert_sh_star(star, s, shipno)
Xstartype *star;
Xshiptype *s;
Xint shipno;
X{
X	s->nextship = star->ships;
X	star->ships = shipno;
X}
X
X
Xinsert_sh_plan(pl, s, shipno)
Xplanettype *pl;
Xshiptype *s;
Xint shipno;
X{
X	s->nextship = pl->ships;
X	pl->ships = shipno;
X}
END_OF_FILE
if test 11933 -ne `wc -c <'server/moveship.c'`; then
    echo shar: \"'server/moveship.c'\" unpacked with wrong size!
fi
# end of 'server/moveship.c'
fi
if test -f 'server/orbit.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'server/orbit.c'\"
else
echo shar: Extracting \"'server/orbit.c'\" \(11740 characters\)
sed "s/^X//" >'server/orbit.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
X * Restrictions in GB_copyright.h.
X *
X *  orbit.c -- display orbits of planets (graphic representation)
X *
X * OPTIONS
X *  -p : If this option is set, ``orbit'' will not display planet names.
X *
X *  -S : Do not display star names.
X *
X *  -s : Do not display ships.
X *
X *  -(number) : Do not display that #'d ship or planet (in case it obstructs
X * 		the view of another object)
X */
X
X#include "GB_copyright.h"
X#define EXTERN extern
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include <curses.h>
X#include <stdio.h>
Xextern char Shipltrs[];
Xfloat Lastx, Lasty, Zoom;
Xint SCALE = 100;
Xint orbit_racedata;
X
Xorbit(Playernum, APcount, argn, args)
Xint Playernum;
Xint APcount;
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xregister int sh,i,iq;
Xint DontDispNum= -1, t, flag;
Xplanettype *p;
Xshiptype *s;
Xplacetype where,shipwhere;
Xboolean err, DontDispPlanets, DontDispShips, DontDispStars;
Xchar str[PLACENAMESIZE];
Xint orbit_shdata,orbit_pdata,orbit_stardata;
Xchar buf[1024];
Xhugestr output;
X
X DontDispPlanets = DontDispShips = DontDispStars = 0;
X
X free(Race);
Xopenracedata(&orbit_racedata);
Xgetrace(orbit_racedata, &Race, Playernum);
Xclose_file(orbit_racedata);
X
X /* find options, set flags accordingly */
X for (flag=1; flag<=argn-1; flag++)
X    if (*args[flag]=='-') {
X      for (i=1; args[flag][i]!='\0'; i++)
X	 switch (args[flag][i]) {
X	    case 's': DontDispShips = 1;
X		      break;
X	    case 'S': DontDispStars = 1;
X		      break;
X	    case 'p': DontDispPlanets = 1;
X		      break;
X       	    default : if (sscanf(args[flag]+1,"%d",&DontDispNum)!=1) {
X			notify(Playernum, "Bad number %s.\n",args[flag]+1);
X			DontDispNum = -1;
X		      }
X		      if (DontDispNum)
X		        DontDispNum--;	/* make a '1' into a '0' */
X		      break;
X	  }
X    }
X
X if (argn==1) {
X   where = Getplace(Playernum, ":",0);
X	i = (Dir[Playernum-1].level==LEVEL_UNIV); 
X   Lastx = Dir[Playernum-1].lastx[i];
X   Lasty = Dir[Playernum-1].lasty[i];
X   Zoom = Dir[Playernum-1].zoom[i];
X } else {
X   where = Getplace(Playernum, args[argn-1],0);
X   Lastx = Lasty = 0.0;
X   Zoom = 1.1;
X }
X
X if (where.err) {
X   notify(Playernum, "orbit: error in args.\n");
X   return;
X }
X
X	/* orbit type of map */
X	sprintf(output, "#");
X
X  switch (where.level) {
X    case LEVEL_UNIV:
X      for (i=0; i<Sdata.numstars; i++)
X	 if (DontDispNum!=i) {
X	   DispStar(Playernum, LEVEL_UNIV,Stars[i],DontDispStars, Race->God, buf);
X		str_cat(output, buf);
X		}
X
X      if (!DontDispShips && (sh = Sdata.ships)) {
X       openshdata(&orbit_shdata);
X
X       while (sh) {
X	   (void)getship(orbit_shdata, &s, sh);
X	   if (DontDispNum != sh) {
X	     DispShip(Playernum, &where, s, sh, NULL, Race->God, buf );
X		str_cat(output, buf);
X		}
X	   sh = s->nextship;
X	   free(s);
X       }
X
X       close_file(orbit_shdata);
X      }
X      break;
X
X   case LEVEL_STAR:
X      DispStar(Playernum, LEVEL_STAR, Stars[where.snum], DontDispStars, Race->God, buf);
X	str_cat(output, buf);
X
X      openpdata(&orbit_pdata);
X
X
X      for (i=0; i<Stars[where.snum]->numplanets; i++)
X	 if (DontDispNum!=i) {
X	   getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[i]);
X	   DispPlanet(Playernum, LEVEL_STAR,p,Stars[where.snum]->pnames[i],DontDispPlanets, 
X				Race->God, buf);
X		str_cat(output, buf);
X	   free(p);
X	 }
X 
X      close_file(orbit_pdata);
X
X/* check to see if you have ships at orbiting the star, if so you can
Xsee enemy ships */
X	iq = 0;
X	if(sh = Stars[where.snum]->ships){
X	openshdata(&orbit_shdata);
X	while (sh && !iq) {
X	   (void)getship(orbit_shdata, &s, sh);
X		if(s->owner == Playernum && Shipdata[s->type][ABIL_SIGHT])
X			iq = 1; /* you are there to sight, need a crew */
X		sh = s->nextship;
X		free(s);
X		}
X       close_file(orbit_shdata);
X	}
X
X
X      if (!DontDispShips && (sh = Stars[where.snum]->ships)) {
X       openshdata(&orbit_shdata);
X
X       while (sh) {
X	   (void)getship(orbit_shdata, &s, sh);
X	   if (DontDispNum != sh && !(s->owner != Playernum && s->type == STYPE_MINE) ) {
X
X		if((s->owner == Playernum) || (iq == 1)) {
X	     DispShip(Playernum, &where, s, sh, NULL, Race->God, buf);
X		str_cat(output, buf);
X		}
X		}
X	   sh = s->nextship;
X	   free(s);
X       }
X       close_file(orbit_shdata);
X      }
X      break;
X
X   case LEVEL_PLAN:
X
X      openpdata(&orbit_pdata);
X      getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[where.pnum]);
X      close_file(orbit_pdata);
X      DispPlanet(Playernum, LEVEL_PLAN, p, Stars[where.snum]->pnames[where.pnum],
X			 DontDispPlanets, Race->God, buf);
X	str_cat(output, buf);
X
X/* check to see if you have ships at landed or
X	orbiting the planet, if so you can see orbiting enemy ships */
X	iq = 0;
X
X	if(sh = p->ships){
X	openshdata(&orbit_shdata);
X	while (sh && !iq) {
X	   (void)getship(orbit_shdata, &s, sh);
X		if(s->owner == Playernum && Shipdata[s->type][ABIL_SIGHT])
X			iq = 1; /* you are there to sight, need a crew */
X		sh = s->nextship;
X		free(s);
X		}
X       close_file(orbit_shdata);
X	}
X
X/* end check */
X
X      if (!DontDispShips && (sh = p->ships)) {
X       openshdata(&orbit_shdata);
X       while (sh) {
X	   (void)getship(orbit_shdata, &s, sh);
X	   if (DontDispNum != sh) {
X	     	if( !(s->is_docked && s->whatdest==LEVEL_PLAN) ) {
X		if((s->owner == Playernum) || (iq ==1)) {
X	 		    DispShip(Playernum, &where, s, sh, p, Race->God, buf);
X			str_cat(output, buf);
X			}
X			}
X		}
X	   sh = s->nextship;
X	   free(s);
X       }
X       close_file(orbit_shdata);
X      }
X      free(p);
X      break;
X
X   default:
X      notify(Playernum,"Bad scope.\n");
X	return;	 
X  }
X
X	notify(Playernum, output);
X}
X
X
XDispStar(Playernum, level, star, DontDispStars, God, string)
Xint Playernum;
Xint level, God;
Xstartype *star;
Xint DontDispStars;
Xchar *string;
X{
Xplanettype *p;
Xshiptype *s;
X int x,y,i,col,orbit_pdata;
X int populated, stand;
X int iq, orbit_shdata, sh;
X register int x2,y2;
X float fac;
X char *c;
Xchar temp[1024];
X
X*string = 0; 
X
Xif (level==LEVEL_UNIV) {
X   fac = 1.0;
X   x = (int)(SCALE+((SCALE*(star->xpos-Lastx))/(UNIVSIZE*Zoom)));
X   y = (int)(SCALE+((SCALE*(star->ypos-Lasty))/(UNIVSIZE*Zoom)));
X } else if (level==LEVEL_STAR) {
X   fac = 1000.0;
X   x = (int)(SCALE+(SCALE*(-Lastx))/(SYSTEMSIZE*Zoom));
X   y = (int)(SCALE+(SCALE*(-Lasty))/(SYSTEMSIZE*Zoom));
X }
X/*
X if (star->nova_stage)
X	DispArray(x, y, 11,7, Novae[star->nova_stage-1], fac);
X else */
Xif (y>=0 && x>=0) {
X
X	iq = 0;
X	/*
X	if (isset(star->inhabited, Playernum)) {
X		sh = star->ships;
X       		openshdata(&orbit_shdata);
X       		while (sh && !iq) {
X	   		(void)getship(orbit_shdata, &s, sh);
X			if(s->owner == Playernum)
X				iq = 1;
X		sh = s->nextship;
X	   	free(s);
X       		}
X       		close_file(orbit_shdata);
X
X	}
X       */
X		if (isset(star->explored,Playernum)) stand=1;
X			else stand = 0;	
X	sprintf(temp, "%d %d %d 0 * ",stand,x,y);
X	str_cat(string, temp);
X
X/* check to see if the any planets are populated here. If so,
X	standout() the name of it */
X
X	sprintf(temp, "%d %s ;",isset(star->inhabited, Playernum), star->name);
X	str_cat(string, temp);
X	   }
X}
X
XDispPlanet(Playernum, level, p, name, DontDispPlanets, God, string)
Xint Playernum;
Xint level, God;
Xplanettype *p;
Xchar *name;
Xint DontDispPlanets;
Xchar *string;
X{
Xint x,y;
Xint stand;
Xchar temp[1024];
X
X*string = 0;
X
X if (level==LEVEL_STAR) {
X   y = (int)(SCALE+(SCALE*(p->ypos-Lasty))/(SYSTEMSIZE*Zoom));
X   x = (int)(SCALE+(SCALE*(p->xpos-Lastx))/(SYSTEMSIZE*Zoom));
X } else if (level==LEVEL_PLAN) {
X   y = (int)(SCALE+(SCALE*(-Lasty))/(PLORBITSIZE*Zoom));
X   x = (int)(SCALE+(SCALE*(-Lastx))/(PLORBITSIZE*Zoom));
X }
X if (x>=0 && y>=0) {
X
X		if(p->info[Playernum-1].explored)stand=1;
X			else stand = 0;
X
X	sprintf(temp, "%d %d %d 0 @ ",stand,x,y);
X	str_cat(string, temp);
X
X	if(p->info[Playernum-1].numsectsowned)stand=1;
X		else stand=0;
X
X	sprintf(temp, "%d %s;",stand, name);
X	str_cat(string, temp);
X
X }
X}
X
X
X
XDispShip(Playernum, where, ship, shipno, pl , God, string)
Xint Playernum;
Xplacetype *where;
Xshiptype *ship;
Xint shipno, God;
Xplanettype *pl;
Xchar *string;
X{
X int x,y,x2,y2, xa, xb, wm,pdata,shipdata;
X int stand;
X shiptype *aship;
X planettype *apl;
X float xt,yt,slope;
X char *c, temp[1024];
X
X*string = 0;
X
X if (!ship->is_alive)
X	return;
X
X switch (where->level) {
X	case LEVEL_PLAN:
X		x = (int)(SCALE + (SCALE*(ship->xpos-(Stars[where->snum]->xpos+pl->xpos) - Lastx))
X			/(PLORBITSIZE*Zoom));
X		y = (int)(SCALE + (SCALE*(ship->ypos-(Stars[where->snum]->ypos+pl->ypos) - Lasty))
X			/(PLORBITSIZE*Zoom));
X		break;
X	case LEVEL_STAR:
X		x = (int)(SCALE + (SCALE*(ship->xpos-Stars[where->snum]->xpos - Lastx))
X			/(SYSTEMSIZE*Zoom));
X		y = (int)(SCALE + (SCALE*(ship->ypos-Stars[where->snum]->ypos - Lasty))
X			/(SYSTEMSIZE*Zoom));
X		break;
X	case LEVEL_UNIV:
X	     	x = (int)(SCALE + (SCALE*(ship->xpos-Lastx))/(UNIVSIZE*Zoom));
X		y = (int)(SCALE + (SCALE*(ship->ypos-Lasty))/(UNIVSIZE*Zoom));
X		break;
X	default:
X		notify(Playernum, "WHOA! error in DispShip.\n");
X		return;
X }
X
X switch (ship->type) {
X
X  case STYPE_MIRROR:
X    if (ship->aimed_at.level==LEVEL_STAR) {
X	xt = Stars[ship->aimed_at.snum]->xpos;
X	yt = Stars[ship->aimed_at.snum]->ypos;
X    } else if (ship->aimed_at.level==LEVEL_PLAN) {
X	if (where->level==LEVEL_PLAN && 
X			ship->aimed_at.pnum == where->pnum) {  
X				/* same planet */
X		xt = Stars[ship->aimed_at.snum]->xpos + pl->xpos;
X		yt = Stars[ship->aimed_at.snum]->ypos + pl->ypos;
X	} else {	/* different planet */
X		openpdata(&pdata);
X		getplanet(pdata,&apl,Stars[where->snum]->planetpos[where->pnum]);
X		close_file(pdata);
X		xt = Stars[ship->aimed_at.snum]->xpos + apl->xpos;
X		yt = Stars[ship->aimed_at.snum]->ypos + apl->ypos;
X		free(apl);
X	}
X    } else if (ship->aimed_at.level==LEVEL_SHIP) {
X	openshdata(&shipdata);
X	if (getship(shipdata,&aship,ship->aimed_at.shipno)) {
X		xt = aship->xpos;
X		yt = aship->ypos;
X	} else
X		xt = yt = 0.0;
X	close_file(shipdata);
X	free(aship);
X    } else
X	xt = yt = 0.0;
X
X    wm=0;
X
X    if(xt == ship->xpos){
X		wm=0;
X		if(yt > ship->ypos)wm=4;
X	} else {
X		slope = (yt - ship->ypos) / (xt - ship->xpos);
X		if(yt == ship->ypos){
X			wm=6;
X			if(xt > ship->xpos)wm=2;
X			}
X
X		if(yt > ship->ypos) {
X			if(slope < -2.414)wm=4;
X			if(slope > -2.414)wm=5;
X			if(slope > -0.414)wm=6;
X			if(slope >  0.000)wm=2;
X			if(slope >  0.414)wm=3;
X			if(slope >  2.414)wm=4;
X			}
X		if(yt < ship->ypos) {
X			if(slope < -2.414)wm=0;
X			if(slope > -2.414)wm=1;
X			if(slope > -0.414)wm=2;
X			if(slope >  0.000)wm=6;
X			if(slope >  0.414)wm=7;
X			if(slope >  2.414)wm=0;
X			}
X	}
X
X				/* (magnification) */
X    if (x>=0 && y>=0) {
X	if(ship->owner==Playernum)stand=1;
X	else stand = 0;
X
X	sprintf(string, "%d %d %d %d %c %d %d;",stand,x,y,wm,Shipltrs[ship->type],stand,shipno);
X    }
X    break;
X
X  case OTYPE_CANIST:
X    break;
X
X  case OTYPE_VN: { 
X		register int n,xa,ya;
X		   register float fac;
X	wm = 0;
X	/* make a cloud of Von Neumann machines */
X    if (ship->whatorbits!=LEVEL_UNIV || (ship->owner == Playernum || God)) {
X	fac = ship->object.number / 
X		((ship->whatorbits==LEVEL_UNIV ? 100.0 : 
X		(ship->whatorbits==LEVEL_STAR ? 30.0 : 4.0)) * Zoom);
X	for (n=1; n<=ship->object.number && n<267; n++) {
X		xa = int_rand(x - (int)fac, x + (int)fac);
X		ya = int_rand(y - (int)fac, y + (int)fac);
X		if (xa>=0 && ya>=0) {
X		if(ship->owner==Playernum)stand=1;
X			else stand = 0;
X	sprintf(temp, "%d %d %d %d %c %d %d;",stand,xa,ya,wm,Shipltrs[ship->type],
X				stand,shipno);
X
X	str_cat(string, temp);
X		}
X     	}
X    }
X   }
X   break;
X
X  default:
X	/* other ships can only be seen when in system */
X	wm=0;
X    if (ship->whatorbits!=LEVEL_UNIV || (ship->owner == Playernum || God))
X       if (x>=0 && y>=0) {
X		if(ship->owner==Playernum)stand=1;
X			else stand = 0;
X	sprintf(string, "%d %d %d %d %c %d %d;",stand,x,y,wm,Shipltrs[ship->type],stand,shipno);
X
X       }
X    break;
X }
X
X
X}
X
X
X
END_OF_FILE
if test 11740 -ne `wc -c <'server/orbit.c'`; then
    echo shar: \"'server/orbit.c'\" unpacked with wrong size!
fi
# end of 'server/orbit.c'
fi
if test -f 'server/rst.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'server/rst.c'\"
else
echo shar: Extracting \"'server/rst.c'\" \(11757 characters\)
sed "s/^X//" >'server/rst.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
X * Restrictions in GB_copyright.h.
X *
X *  ship -- report -- stock -- tactical -- stuff on ship
X */
X
X#define REPORT	0
X#define STOCK	1
X#define TACTICAL 2
X#define SHIP	3
X#define OBJECT	4
X
X#define PLANET 1
X
X#include "GB_copyright.h"
X#define EXTERN extern
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include "buffers.h"
X#include <math.h>
X#include <ctype.h>
Xextern char Shipltrs[];
X
Xchar *prin_aimed_at(), *prin_ship_dest();
X
Xstatic boolean Object,Ship,Stock,Report,Tactical,first;
Xint rst_racedata;
X
Xextern float Kill_factor();
X
Xstruct reportdata {
X	unsigned type : 1;	/* ship or planet */
X	shiptype *s;
X	planettype *p;
X	short n;
X	unsigned char star,pnum;
X	float x,y;
X};
X
Xrst(Playernum,APcount, argn,args,Rst)
Xint Playernum;
Xint APcount;
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
Xint Rst;
X{
X int shdata,shipno;
X reg int shn,i;
X struct reportdata *rd;
X int n_ships, num;
X boolean Report_types[NUMSTYPES];
X
X for (i=0; i<NUMSTYPES; i++) Report_types[i]=1;
X Num_ships = 0;
X first = 1;
X switch (Rst) {
X	case REPORT:	Report = 1;
X			Object = Stock = Ship = Tactical = 0;
X			break;
X	case STOCK:	Stock = 1;
X			Object = Report = Ship = Tactical = 0;
X			break;
X	case TACTICAL:	Tactical = 1;
X			Object = Report = Ship = Stock = 0;
X			break;
X	case SHIP:	Ship = Report = Stock = 1;
X			Tactical = 0;
X			Object = 0;
X			break;
X	case OBJECT:	Object = Report = Stock = Tactical = 1;
X			Ship = 0;
X			break;
X }
X
X openshdata(&shdata);
X  n_ships = Numships(shdata);
X close_file(shdata);
X
X rd = (struct reportdata *)malloc(sizeof(struct reportdata) * 
X	(n_ships + Sdata.numstars * MAXPLANETS));
X	/* (one list entry for each ship, planet in universe) */
X
X
X if (argn>=2) {
X
X   if (*args[1] == '#' || isdigit(*args[1])) {
X	/* report on a couple ships */
X	 int l=1;
X      while (l<MAXARGS && *args[l]!='\0') {
X
X      	sscanf(args[l] + (*args[l]=='#'),"%d",&shipno);
X
X      	if ( shipno > n_ships || shipno<1) {
X	   sprintf (buf,"rst: no such ship #%d \n",shipno);
X		notify(Playernum, buf);
X	   return ;
X       	}
X
X      	openshdata(&shdata);
X      	Getrship(Playernum,shdata,rd, shipno);
X      	close_file(shdata);
X	num = Num_ships;
X	if(rd[Num_ships-1].s->whatorbits != LEVEL_UNIV)
X		{
X      			star_getrships(Playernum,rd,rd[num-1].s->storbits);
X      			ship_report(Playernum,rd,num-1,Report_types);
X		}
X	else 
X   			ship_report(Playernum,rd,num-1,Report_types);
X
X	l++;
X      }
X
X      return;
X
X   } else {
X	int l;
X	l = strlen(args[1]);
X	for (i=0; i<NUMSTYPES; i++) Report_types[i]=0;
X
X	while (l--) {
X	   i = NUMSTYPES;
X	   while (--i && Shipltrs[i]!=args[1][l]) 
X		;
X	   if (Shipltrs[i]!=args[1][l]) {
X		sprintf(buf,"'%c' -- no such ship letter\n",args[1][l]);
X			notify(Playernum, buf);
X	   } else
X		Report_types[i] = 1;
X	}
X   }
X
X  }
X
X  switch (Dir[Playernum-1].level) {
X   case LEVEL_UNIV:
X	  openshdata(&shdata);
X	  shn = Sdata.ships;
X	  while (shn) {
X	      Getrship(Playernum,shdata,rd, shn);
X	      shn = rd[Num_ships-1].s->nextship;
X	  }
X	  close_file(shdata);
X      for (i=0; i<Sdata.numstars; i++)
X        star_getrships(Playernum,rd,i);
X      for (i=0; i<Num_ships; i++)
X        ship_report(Playernum,rd,i,Report_types);
X      break;
X   case LEVEL_PLAN:
X      plan_getrships(Playernum,rd, Dir[Playernum-1].snum, Dir[Playernum-1].pnum);
X      for (i=0; i<Num_ships; i++)
X        ship_report(Playernum,rd,i,Report_types);
X      break; 
X   case LEVEL_STAR:
X      star_getrships(Playernum,rd,Dir[Playernum-1].snum);
X      for (i=0; i<Num_ships; i++)
X        ship_report(Playernum,rd,i,Report_types);
X      break; 
X   case LEVEL_SHIP:
X      openshdata(&shdata);
X      Getrship(Playernum,shdata,rd, Dir[Playernum-1].shipno);
X      ship_report(Playernum,rd,0,Report_types);		/* first ship report */
X
X	if(rd[0].s->type == STYPE_CARRIER) /* list attached fighter groups */
X	{
X	  shn = rd[0].s->object.number;
X	   Num_ships = 0;	
X	  while (shn) {
X	      Getrship(Playernum,shdata,rd, shn);
X	      shn = rd[Num_ships-1].s->object.number;
X	  }
X
X	for (i=0; i<Num_ships; i++)
X		ship_report(Playernum,rd,i,Report_types);
X	}
X
X      close_file(shdata);
X      break;
X  }
X
X  Free_shiplist(rd);
X
X}
X
X
Xship_report(Playernum,rd,indx,rep_on)
Xint Playernum;
Xstruct reportdata rd[];
Xint indx;
Xboolean rep_on[];
X{
X shiptype *s;
X planettype *p;
X int shipno,test;
X reg int i,sight;
X placetype where;
X char orb[PLACENAMESIZE];
X char strng[COMMANDSIZE],locstrn[COMMANDSIZE];
X float Dist;
X
X	/* last ship gotten from disk */
X  s = rd[indx].s;
X  p = rd[indx].p;
X  shipno = rd[indx].n;
X
Xfree(Race);
Xopenracedata(&rst_racedata);
Xgetrace(rst_racedata, &Race, Playernum);
Xclose_file(rst_racedata);
X
X	/* launched canister, non-owned ships don't show up */
X    if ( (rd[indx].type==PLANET && p->info[Playernum-1].numsectsowned)
X      || (rd[indx].type!=PLANET && s->owner==Playernum &&
X	 rep_on[s->type] &&
X	!(s->type==OTYPE_CANIST && !s->is_docked) && s->is_alive) ) {
X
X   if (rd[indx].type!=PLANET && Stock) {
X    if (first) {
X      sprintf(buf,"  #       name     mass armor size   resources destructive   fuel      crew     class\n");
X		notify(Playernum, buf);
X      if (!Ship && !Object)
X	      first=0;
X    }
X
X
X      sprintf(buf,"%3d %c %13.13s%5.1f%6u%5u%5u(%4d)%5u(%4d)%5.1f(%4d)%5u(%4d) %c %s ",
X	shipno, Shipltrs[s->type], s->name, s->mass, s->armor, s->size, 
X	s->resource, Max_resource(s),
X	s->destruct, Max_destruct(s),
X	s->fuel, Max_fuel(s),
X	s->popn, Max_crew(s), Shipltrs[s->build_type],  s->class);
X		notify(Playernum, buf);
X      if (!s->active) {
X	sprintf(buf," INACTIVE(%d)",s->rad);
X		notify(Playernum, buf);
X		}
X      sprintf(buf,"\n");
X		notify(Playernum, buf);
X
X   }
X
X
X
X   if (rd[indx].type!=PLANET && Report) {
X         if (first) {
X		sprintf(buf,"  #                crew dam dest fuel spd            orbits       destination\n");
X		notify(Playernum, buf);
X		 if (!Ship && !Object)
X		      first=0;
X	 }
X
X	if(s->navigate.on)
X		sprintf(strng,"nav: %d (%d)",s->navigate.bearing,
X				s->navigate.turns);
X
X	  sprintf(locstrn,"%2.0f,%-2.0f",s->xpos,s->ypos);
X
X 	  sprintf(buf,"%4d %c %12.12s%4u%4u%5u%5.0f%3u%c%5s%16s%16s",
X		shipno, 
X		Shipltrs[s->type], 
X		s->name,
X		s->popn,
X		s->damage, 
X		s->destruct, 
X		s->fuel,
X		s->speed, 
X		s->is_docked ? ( (s->whatdest==LEVEL_SHIP) ? 'D' : 'L') : ' ',
X		(s->is_docked&&s->whatdest==LEVEL_PLAN) ? locstrn : "",
X		prin_ship_orbits(s), 
X		(s->navigate.on) ? strng : prin_ship_dest(Playernum, s) );
X		notify(Playernum, buf);
X      if (!s->active) {
X	sprintf(buf," INACTIVE(%d)",s->rad);
X		notify(Playernum, buf);
X		}
X         sprintf(buf,"\n");
X		notify(Playernum, buf);
X
X   }
X
X   if (Tactical) {
X
Xint fev=0,fspeed=0;
Xfloat tech;
X	sprintf(buf,"\n  #         name        tech guns armor size dest   fuel dam spd evad               orbits\n");
X		notify(Playernum, buf);
X
X	if (rd[indx].type==PLANET) {
X			tech = Race->tech;
X		/* tac report from planet */
X		sprintf(buf,"(planet)%15.15s%4.0f %4d           %5u %6u\n",
X			Stars[rd[indx].star]->pnames[rd[indx].pnum],
X			 tech,PLAN_FIRE_LIM,p->info[Playernum-1].destruct,
X			p->info[Playernum-1].fuel);
X		notify(Playernum, buf);
X	} else {
X
X 	  where.level = s->whatorbits;
X 	  where.snum = s->storbits;
X 	  where.pnum = s->pnumorbits;
X	  tech = s->tech;
X
X	  if((s->whatdest != LEVEL_UNIV || s->navigate.on) && !s->is_docked && s->active) {
X		fspeed = s->speed;
X		fev = s->protect.evade;
X	  }
X	  sprintf(orb, "%30.30s", Dispplace(Playernum, &where));
X	  sprintf(buf,"%3d %c%19.19s%4.0f%5d%6d%5d%5u%7.1f%3d%%  %d  %3s%21.22", 
X		shipno, Shipltrs[s->type], s->name, s->tech,
X		Guns(s), s->armor, s->size,
X		s->destruct, s->fuel, s->damage, fspeed,(fev ? "yes" : "   "),
X		orb );
X		notify(Playernum, buf);
X
X	  if (s->is_docked && s->whatorbits==LEVEL_PLAN) {
X	    sprintf(buf," (%.0f,%.0f)",s->xpos,s->ypos);
X		notify(Playernum, buf);
X		}
X          if (!s->active) {
X		sprintf(buf," INACTIVE(%d)",s->rad);
X		notify(Playernum, buf);
X			}
X	  sprintf(buf,"\n");
X		notify(Playernum, buf);
X
X	}
X
X	sight = 0;
X	if(rd[indx].type==PLANET) {
X		sight = 1;
X	} else if(Shipdata[s->type][ABIL_SIGHT]) sight = 1;
X
X		/* tactical display */
X	sprintf(buf,"\n  Tactical: #  own typ        name   rng   (50%%) size spd evade hit  dam  loc\n");
X		notify(Playernum, buf);
X
X	if(sight)
X	for (i=0; i<Num_ships; i++) {
X	   if (i!=indx && (Dist = sqrt(Distsq(rd[indx].x, rd[indx].y, 
X				rd[i].x, rd[i].y))) < gun_range(Race, NULL))
X	      if (rd[i].type==PLANET) {
X		/* tac report at planet */
X		sprintf(buf," %13s(planet)          %8.0f\n", 
X			Stars[rd[i].star]->pnames[rd[i].pnum], Dist);
X		notify(Playernum, buf);
X
X	      } else {
X			/* tac report at ship */
X		if (rd[i].s->owner!=Playernum && rd[i].s->is_alive
X			&& rd[i].s->type != OTYPE_CANIST)
X			 {
X		int tev=0, tspeed=0, body=0,prob=0;
X		int factor=0;		
X		if((rd[i].s->whatdest != LEVEL_UNIV || rd[i].s->navigate.on) && !rd[i].s->is_docked && rd[i].s->active)
X					{
X					tspeed = rd[i].s->speed;
X					tev = rd[i].s->protect.evade;
X					}
X					
X		body = Size(rd[i].s);
X
X			 prob = hit_odds(Dist,&factor,tech,fev,tev,fspeed,tspeed,body);
X		   sprintf(buf,"%13d %4d %c%15.15s %4.0f  %4d   %5d%d  %3s  %3d%% %3u%%",
X			rd[i].n, rd[i].s->owner, Shipltrs[rd[i].s->type], 
X			rd[i].s->name, Dist,factor,body,tspeed,(tev ? "yes" : "   "), prob,rd[i].s->damage);
X		notify(Playernum, buf);
X	  if (rd[i].s->is_docked && rd[i].s->whatorbits==LEVEL_PLAN) {
X	    sprintf(buf," (%.0f,%.0f)",rd[i].s->xpos,rd[i].s->ypos);
X		notify(Playernum, buf);
X	  } else {
X	    sprintf(buf,"     ");
X		notify(Playernum, buf);
X		}
X
X	sprintf(buf, "\n");
X		notify(Playernum, buf);
X		}
X	      }
X
X	}
X   }
X
X
X  }
X
X}
X
X
X
Xplan_getrships(Playernum,rd,snum,pnum)
Xint Playernum;
Xstruct reportdata rd[];
Xint snum, pnum;
X{
X reg int i,shn;
X planettype *p;
X int shdata,pdata;
X
X openpdata(&pdata);
X   getplanet(pdata, &rd[Num_ships].p, Stars[snum]->planetpos[pnum]);
X close_file(pdata);
X p = rd[Num_ships].p;
X	/* add this planet into the ship list */
X rd[Num_ships].star = snum;
X rd[Num_ships].pnum = pnum;
X rd[Num_ships].type = PLANET;
X rd[Num_ships].n = 0;
X rd[Num_ships].x = Stars[snum]->xpos + p->xpos;
X rd[Num_ships].y = Stars[snum]->ypos + p->ypos;
X    Num_ships++;
X
X if (p->info[Playernum-1].explored) {
X
X   openshdata(&shdata);
X   shn = p->ships;
X   while (shn) {
X
X	Getrship(Playernum,shdata, rd, shn);
X		/* add offsets for docked ships */
X	if (rd[Num_ships-1].s->is_docked && 
X			rd[Num_ships-1].s->whatdest==LEVEL_PLAN) {
X		rd[Num_ships-1].x += Stars[snum]->xpos + p->xpos;
X		rd[Num_ships-1].y += Stars[snum]->ypos + p->ypos;
X	}
X	shn = rd[Num_ships-1].s->nextship;
X   }
X   close_file(shdata);
X }
X 
X}
X
X
X
Xstar_getrships(Playernum,rd,snum)
Xint Playernum;
Xstruct reportdata rd[];
Xint snum;
X{
X reg int shn;
X int i,shdata;
X
X
X if (isset(Stars[snum]->explored, Playernum)) {
X   openshdata(&shdata);
X   shn = Stars[snum]->ships;
X   while (shn) {
X	Getrship(Playernum,shdata, rd, shn);
X	shn = rd[Num_ships-1].s->nextship;
X   }
X   close_file(shdata);
X   for (i=0; i<Stars[snum]->numplanets; i++)
X     plan_getrships(Playernum,rd, snum, i);
X }
X}
X
X
X/* get a ship from the disk and add it to the ship list we're maintaining. */
XGetrship(Playernum,shdata,rd, shipno)
Xint Playernum;
Xint shdata,shipno;
Xstruct reportdata rd[];
X{
Xint noerr;
X
X 
X   if (getship(shdata,&rd[Num_ships].s,shipno)) {
X	   rd[Num_ships].type = 0;
X	   rd[Num_ships].n = shipno;
X	   rd[Num_ships].x = rd[Num_ships].s->xpos;
X	   rd[Num_ships].y = rd[Num_ships].s->ypos;
X 	   Num_ships++;
X   } else {
X	sprintf(buf,"Getrship: error on ship get (%d).\n",shipno);
X		notify(Playernum, buf);
X   }
X}
X
X
X
XFree_shiplist(rd)
Xstruct reportdata rd[];
X{
X reg int i;
X
X for (i=0; i<Num_ships; i++)
X	if (rd[i].type==PLANET)
X		free(rd[i].p);
X	else
X		free(rd[i].s);
X
X free(rd);
X}
X
X/* 
X * return what the ship is aimed at, if it's a mirror 
X */
X
X
END_OF_FILE
if test 11757 -ne `wc -c <'server/rst.c'`; then
    echo shar: \"'server/rst.c'\" unpacked with wrong size!
fi
# end of 'server/rst.c'
fi
echo shar: End of archive 7 \(of 14\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 14 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0