[comp.sources.games] v06i053: GB - Galactic Bloodshed, an empire-like war game, Part02/07

games@tekred.CNA.TEK.COM (04/27/89)

Submitted-by: Robert Chansky <smq@ssyx.ucsc.edu>
Posting-number: Volume 6, Issue 53
Archive-name: GB/Part02



#! /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 2 (of 7)."
# Contents:  Docs/overview.doc fire.c fix.c makeplanet.c order.c
# Wrapped by billr@saab on Wed Apr 26 14:41:32 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Docs/overview.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Docs/overview.doc'\"
else
echo shar: Extracting \"'Docs/overview.doc'\" \(5054 characters\)
sed "s/^X//" >'Docs/overview.doc' <<'END_OF_FILE'
X
X
X
X
X                       Galactic Bloodshed
X                         (working title)
X
X
X                               by
X
X                         Robert Chansky
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
XOverview This game was originally inspired by  the  Unix  wargame
XEmpire.   In Empire conquest is represented by the amount of ter-
Xritory a player occupies as well as the resources and  workforces
Xhe  posesses.   Galactic  Bloodshed  is  much  the  same in these
Xrespects, as are many other games.  But, where Empire takes place
Xon one world, Galactic Bloodshed employs many seperate worlds for
Xplayers to explore and exploit.  In this way  the  game  is  more
Xversatile than Empire, and there are many more avenues to explore
Xin game development.  Finance, cooperation and war  (of  course),
Xdevelopment  of  technology,  and randomizing factors will all be
Ximportant areas of the game.  While free trade  would  ordinarily
Xbe  difficult in a simulation constrained by the mechanics of in-
Xterstellar travel, Galactic Bloodshed will circumvent this by in-
Xtroducing  various  'shortcuts'  to  travel.  Among these are FTL
Xvehicles, instantaneous transport devices,  and  a  smaller-than-
Xscale travel distance for starships.  Another factor to stimulate
Xfree trade is the economic leverage  inherent  in  the  disparate
Xraces and cultures that arise from evolution (or creation, which-
Xever you happen to believe [more on  this  later]).   Thus  goods
Xsuch as priceless art treasures, examples of fiction, technologi-
Xcal discoveries, new strains of food animals,  etc.(the  list  is
Xendless)  can  all  be carried in a starship of limited capacity.
XCommunication is possible between races via  long-distance  radio
X(telegrams).   Opportunities  for  profit  can be utilized by any
Xplayer.  While the game is designed primarily to be  peaceful  in
Xintent  (the  name is sarcastic), it is necessary that there also
Xbe an alternative to friendly competition.  Thus war and conflict
Xare  born.   In  addition  to trade cargoes a ship can also carry
Xdestructive capacity.  this can represent anything  from  nuclear
Xweaponry  to  propaganda, and when unloaded it can be devastating
Xto its intended target.  Ships, planets, and people  all  can  be
Xmobilized  to  preserve  their  culture's  manifest destiny while
Xcurbing another's expansionist imperialism.  The above so far  is
Xassuming  that  each culture in the game develops along the lines
Xthat our own seems to be.  This view is a narrow one  considering
Xthe disparity of even the one known planet we have to model.  The
Xtechnologically dominant European culture of Earth  arose  merely
Xby  chance,  and it is equally possible that another, differently
Xmotivated culture could have come about in its place -- a culture
Xthat,  perhaps,  uses  the  principles  of  magic, mind power, or
Xprayer to influence its environment in the same way that machines
Xand  such  are  used  today.  We have only theoretical experience
Xwith such methods, but they are nevertheless  applicable  to  the
Xworkings  of  the  game.   Instead of developing newer and better
Xmachines these cultures may explore  the  possibilities  of  more
Xcomplicated  and powerful spells, a greater unity of the mind and
Xthe body, or a transcendant understanding of God.  Lasers and nu-
Xclear weapons clash with the concentrated might of a racial mind,
Xwhile the magic spells of another culture might vy with the power
Xof  a  god.  It is possible for any game to become unbalanced, as
Xone player becomes more experienced in the game  and  forces  the
Xothers  to  extinction.   This  can  easily  happen with Galactic
XBloodshed as well.  Randomizing factors are necessary to keep the
Xgame balanced, without reducing playability as well.  I introduce
XBerserkers, wandering death machines attempting  to  destroy  all
Xlife,  as one such option.  These devices can be randomly created
Xanywhere (or alternatively built at a central  base  which  could
Xserve  as  a  quest to destroy for the players) to deal crippling
Xblows at important supply routes.  They can be directed anywhere,
Xor  programmed  to  move  randomly or towards the most advantaged
Xplayer.  But this is not the only option; many factors  can  con-
Xtribute  to  keeping players on their toes.  Someone may invent a
Xsupernova device (effectively ending the game...) and use  it  on
Xyour  system;   a  viral plague may break out;  A gamma-ray laser
Xaimed at one of your planets may  render  its  population  nearly
Xsterile;   Rival supernatural beings may choose your territory in
Xwhich to 'duke it  out';  your  scientists  may  invent  a  self-
Xreproducing machine which immediately proceeds to convert all the
Xresources of your system into copies of itself.   Any  number  of
Xthings  may  happen.   Progress  on Galactic Bloodshed so far has
Xbeen fairly steady; and I hope to  have  a  working  multi-player
Xcopy of the game (ver 0.9) up by the beginning of the summer.
X
X        Robert Paul Chansky
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
END_OF_FILE
if test 5054 -ne `wc -c <'Docs/overview.doc'`; then
    echo shar: \"'Docs/overview.doc'\" unpacked with wrong size!
fi
# end of 'Docs/overview.doc'
fi
if test -f 'fire.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fire.c'\"
else
echo shar: Extracting \"'fire.c'\" \(11944 characters\)
sed "s/^X//" >'fire.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@ucscb.ucsc.edu)
X * fire.c -- fire at ship or planet from ship or planet
X */
X
X#include "vars.h"
X#include "ships.h"
X#include "races.h"
X#include <signal.h>
X#include <setjmp.h>
X#include <curses.h>
Xextern char telegram_buf[AUTO_TELEG_SIZE];
Xextern jmp_buf main_jenv;
Xextern int Shipdata[NUMSTYPES][NUMABILS];
Xextern int Ignore_filelocks;
Xint fire_stardata,fire_fromshdata,fire_toshdata,
X    fire_frompdata,fire_topdata,fire_sectdata;
X
Xextern bool Nuked[MAXPLAYERS];
X
Xfire(APcount, argn,args)
Xint APcount;
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xplacetype from,to;
Xplanettype *fpl,*tpl;
Xsectortype *sect;
Xint dam=0,dam2=0,strength,oldstrength,maxstrength,
X    i,from_firex= -1,from_firey= -1,firex= -1,firey= -1,Numplayersretaliate=0;
Xchar string[PLACENAMESIZE],buf[100];
Xbool sameplanet = 0, fromplanetmod=0,toplanetmod=0,starmod=0,sdatamod=0;
Xint mask,APdeductstar;
Xint fire_handler();
X
X
Xfire_stardata = fire_fromshdata = fire_toshdata = fire_frompdata = 
X	fire_topdata = fire_sectdata = NEUTRAL_FD;
Xsignal(SIGINT, fire_handler);
X
X
X	/***** get place we are firing from *****/
X
X if (argn!=4) {
X   printf("fire (from) ship or planet ");
X   scanf("%35s",string);
X } else sscanf(args[1],"%35s",string);
X
X from = Getplace(string,0);
X
X if (from.err && from.level!=LEVEL_SHIP) { 
X	printf("usage: fire [ (from path) (to path) [strength] ]\n");
X	return; 
X }
X if (from.level == LEVEL_UNIV || from.level == LEVEL_STAR) {
X    printf("You can't shoot from there.\n");
X    fire_handler();
X } else if (from.level == LEVEL_SHIP) {
X    if (from.err || from.shipptr->owner != Playernum) {
X	DontOwnErr();
X	return;
X    }
X    free(from.shipptr);		/* erase/get ship again to lock ship file */
X    openshdata(&fire_fromshdata);
X    getship(fire_fromshdata,&(from.shipptr),from.shipno);
X
X    if (from.shipptr->rad) {
X	printf("%s #%d is inactive.\n", Shipnames[from.shipptr->type], from.shipno);
X	fire_handler();
X    }
X    if (!from.shipptr->popn && Shipdata[from.shipptr->type][ABIL_MAXCREW]) {
X	printf("%s #%d has no crew.\n", Shipnames[from.shipptr->type], from.shipno);
X	fire_handler();
X    }
X
X    if (from.shipptr->whatorbits==LEVEL_UNIV) {
X		printf("There is nothing here to fire upon.\n");
X		fire_handler();
X    } else if (from.shipptr->whatorbits==LEVEL_STAR) {
X	openstardata(&fire_stardata);
X	getstar(fire_stardata, &Stars[from.snum], from.snum);
X	if (!enufAP(Stars[from.shipptr->storbits]->AP, APcount) )
X			fire_handler();
X    } else if (from.shipptr->whatorbits==LEVEL_PLAN) {
X	openpdata(&fire_frompdata);
X   	getplanet(fire_frompdata,&fpl,
X		Stars[from.shipptr->storbits]->planetpos[from.shipptr->pnumorbits]);
X	if (!enufAP(Stars[from.shipptr->storbits]->AP, APcount) )
X			fire_handler();
X
X    } else {
X	/* from.shipptr->whatorbits==LEVEL_UNIV) {*/
X	openstardata(&fire_stardata);
X	getsdata(fire_stardata,&Sdata);
X	if (!enufAP(Sdata.AP, APcount) )
X		fire_handler();
X    }
X } else if (from.level==LEVEL_PLAN) {
X   openpdata(&fire_frompdata);
X   getplanet(fire_frompdata,&fpl,Stars[from.snum]->planetpos[from.pnum]);
X
X   if (!enufAP(Stars[from.snum]->AP, APcount) ) 
X		fire_handler();
X
X   if (!(fpl->info[Playernum-1].destruct)) {
X	printf("No weapons available.\n");
X	fire_handler();
X   }
X
X     /* get a sector the enemy place can retaliate to. */
X
X   do {
X
X     printf("Fire from");
X     GetMapSector(fpl, &from_firex,&from_firey);
X
X	opensectdata(&fire_sectdata);
X	getsector(fire_sectdata, &sect, fpl->sectormappos+(from_firey*fpl->Maxx+from_firex)*sizeof(sectortype) );
X	close(fire_sectdata);
X
X      if (sect->owner!=Playernum)	/* has to be yours */
X	   printf("You don't own that sector.\n");
X
X   } while (sect->owner!=Playernum);
X
X   free(sect);
X
X } else {
X	printf("You can't shoot from there.\n");
X	return;
X }
X
X
X  /******* get target *******/
X
X
X if (argn!=4) {
X   printf("fire (at) ship or planet ");
X   scanf("%35s",string);
X } else sscanf(args[2],"%35s",string);
X
X Ignore_filelocks = 1;
X to = Getplace(string,1);
X Ignore_filelocks = 0;
X
X if (to.err)
X	fire_handler();
X
X
X if (to.level==LEVEL_SHIP) {
X	if (from.level==LEVEL_SHIP) {
X		if (from.shipno == to.shipno) {
X			printf("You can't do that.\n");
X			fire_handler();
X		} else
X			Ignore_filelocks = 1;	
X				/* ship file will already be locked */
X	}
X	openshdata(&fire_toshdata);
X	free(to.shipptr);
X	getship(fire_toshdata, &(to.shipptr), to.shipno);
X	Ignore_filelocks = 0;
X
X	if (to.shipptr->whatorbits==LEVEL_PLAN) {
X		Ignore_filelocks = 1;	/* planet file will already be locked */
X		if ( (from.snum==to.snum && from.pnum==to.pnum)
X		    		|| from.level==LEVEL_PLAN ) {
X			/* this ship orbits the same planet as the firing one */
X		   sameplanet = 1;
X		   tpl = fpl;
X		} else {
X		   openpdata(&fire_topdata);
X		   getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
X		}
X		Ignore_filelocks = 0;
X
X	} else if (to.shipptr->whatorbits==LEVEL_STAR) {
X		if (from.shipptr->whatorbits!=LEVEL_STAR) {
X			openstardata(&fire_stardata);
X			getstar(fire_stardata, &Stars[to.snum], to.snum);
X			if (!enufAP(Stars[to.shipptr->storbits]->AP, APcount) )
X					fire_handler();
X		}
X	} else {
X		/*(to.shipptr->whatorbits==LEVEL_UNIV) {*/
X		if (!(from.level==LEVEL_SHIP && from.shipptr->whatorbits==LEVEL_UNIV) ) {
X			/* not already gotten in from */
X			openstardata(&fire_stardata);
X			getsdata(fire_stardata, &Sdata);
X		}
X	}
X } else if (to.level==LEVEL_PLAN) {
X	if (from.level==LEVEL_PLAN) {
X		Ignore_filelocks = 1;
X		if (from.snum == to.snum && from.pnum==to.pnum) {
X	        	/* same planet as firing one */
X		   sameplanet = 1;
X		   tpl = fpl;
X		} else {
X		   openpdata(&fire_topdata);
X		   getplanet(fire_topdata,&tpl,Stars[to.snum]->
X							planetpos[to.pnum]);
X		}
X		Ignore_filelocks = 0;
X	} else if (from.level==LEVEL_SHIP && 
X			from.shipptr->whatorbits==LEVEL_PLAN) {
X		Ignore_filelocks = 1;	/* planet data file also locked */
X		if (from.shipptr->storbits==to.snum && 
X				from.shipptr->pnumorbits==to.pnum) {
X		   sameplanet = 1;
X		   tpl = fpl;
X		} else {
X		   openpdata(&fire_topdata);
X		   getplanet(fire_topdata,&tpl,Stars[to.snum]->
X							planetpos[to.pnum]);
X		}
X		Ignore_filelocks = 0;
X	} else {
X	   openpdata(&fire_topdata);
X	   getplanet(fire_topdata,&tpl,Stars[to.snum]->planetpos[to.pnum]);
X	}
X } else {
X	printf("You can't shoot at that.\n");
X	fire_handler();
X }
X
X	/* ask user for sector of planet to shoot at */
X if (to.level==LEVEL_PLAN) {
X    printf("aim at");
X    GetMapSector(tpl, &firex, &firey);
X  }
X
X	/* prompt if hes your ally */
X  if ( to.level==LEVEL_SHIP && isset(Race->allied, to.shipptr->owner) ) {
X	printf("Fire on your ally? (y/n)");
X	tty_on();
X	if (getchr()!='y') {
X		tty_off();
X		fire_handler();
X	}
X	tty_off();
X  }
X
X  maxstrength = (from.level==LEVEL_SHIP) ? 
X		MIN(from.shipptr->destruct,   
X			Shipdata[from.shipptr->type][ABIL_GUNS]) :
X		MIN(fpl->info[Playernum-1].destruct, PLAN_FIRE_LIM);
X
X if (argn!=4) {
X    printf("strength (max %d):",maxstrength );
X    scanf("%d",&strength);
X    getchr();
X } else sscanf(args[3],"%d",&strength);
X if (strength>maxstrength) {
X	printf("Too large.\n");
X   	fire_handler();
X } else if (strength<=0) {
X   	printf("wimp.\n");
X   	fire_handler();
X }
X
X	/* block kill signals to foil cheaters */
X mask = sigblock(SIGINT | SIGQUIT | SIGSTOP);
X
X if (from.level==LEVEL_SHIP) {
X			from.shipptr->destruct -= strength;
X			from.shipptr->mass -= strength*MASS_DESTRUCT;
X } else if (from.level==LEVEL_PLAN) 
X			fpl->info[Playernum-1].destruct -= strength;
X
X dam = shoot(from,&to,fpl,tpl,firex,firey,strength, &sdatamod,&starmod, &fromplanetmod);
X if (dam < 0) {
X	printf("Target out of range!  must be %d or closer.\n", SYSTEMSIZE);
X	fire_handler();
X }
X
X  /* enemy retaliates with twice the strength (if he can) */
X
X if ( to.level==LEVEL_SHIP && !to.shipptr->is_dead) {
X	strength = MIN(to.shipptr->destruct,Shipdata[to.shipptr->type][ABIL_GUNS]);
X	to.shipptr->destruct -= strength;
X	to.shipptr->mass -= strength*MASS_DESTRUCT;
X } else if (to.level==LEVEL_PLAN) {	/* all players owning planet retal */
X    int strength2;
X	oldstrength = strength*2;
X	strength = 0;
X	for (i=1; i<MAXPLAYERS; i++)
X	   if (tpl->info[i-1].destruct>0 && i!=Playernum && Nuked[i]) {
X	     strength2 = MIN(oldstrength, tpl->info[i-1].destruct);
X	     if (strength2 > PLAN_FIRE_LIM)
X		strength2 = PLAN_FIRE_LIM;
X	     tpl->info[i-1].destruct -= strength2;
X	     printf("Player %d returns fire, strength %d.\n", i, strength2);
X	     strength += strength2;
X	     Numplayersretaliate++;
X	   }
X }
X
X	/* enemy fires at shooting sector */
X if ( !(to.level==LEVEL_SHIP && to.shipptr->is_dead) )
X 	dam2 = shoot(to,&from,tpl,fpl,from_firex,from_firey,strength, &sdatamod,&starmod, &toplanetmod);
X
X
X if (from.level==LEVEL_PLAN) {
X 	putplanet(fire_frompdata,fpl,Stars[from.snum]->planetpos[from.pnum]);
X	free(fpl);
X	close(fire_frompdata);
X } else if (from.level==LEVEL_SHIP) {
X	if (from.shipptr->whatorbits == LEVEL_PLAN) {
X	   if (fromplanetmod || (sameplanet && toplanetmod) ) {
X			/* can only mean that the from ship is dead */
X			/* and that both ships don't orbit the same planet */
X		putplanet(fire_frompdata, fpl, Stars[from.shipptr->storbits]->planetpos[from.shipptr->pnumorbits] );
X		free(fpl);
X	   }
X	   close(fire_frompdata);
X	}
X
X	putship(fire_fromshdata,from.shipptr,from.shipno);
X	close(fire_fromshdata);
X	free(from.shipptr);
X }
X
X
X if (to.level==LEVEL_PLAN && !sameplanet) {
X 	putplanet(fire_topdata,tpl,Stars[to.snum]->planetpos[to.pnum]);
X	free(tpl);
X	close(fire_topdata);
X
X } else if (to.level==LEVEL_SHIP) {
X	if (!sameplanet) {
X	   if (toplanetmod)
X		putplanet(fire_topdata, tpl, Stars[to.shipptr->storbits]->planetpos[to.shipptr->pnumorbits] );
X	   close(fire_topdata);
X	}
X
X	putship(fire_toshdata,to.shipptr,to.shipno);
X	free(to.shipptr);
X	close(fire_toshdata);
X }
X
X
X if (starmod) {
X	 /* this means both ships (if from is a ship) orbit same star */
X	if (from.level==LEVEL_SHIP)
X		putstar(fire_stardata,Stars[from.shipptr->storbits],from.shipptr->storbits);
X	else if (to.level==LEVEL_SHIP)  /* it should */
X		putstar(fire_stardata,Stars[to.shipptr->storbits],to.shipptr->storbits);
X }
X if (sdatamod)
X	putsdata(fire_stardata);
X
X close(fire_stardata);
X
X printf("BOOM!!\007  %d%s.\n", dam, 
X		to.level==LEVEL_SHIP ? 
X		 (to.shipptr->type==OTYPE_VN ? " Von Neumann machines destroyed"
X		 : "% damage done") : " sectors destroyed" );
X
X teleg_add("",telegram_buf);
X sprintf(buf," BULLETIN from %s\n\n",Dispplace(&from));
X teleg_add(buf,telegram_buf);
X sprintf(buf,"%s%s ",from.level==LEVEL_SHIP ? "ship " : "", Dispplace(&from));
X teleg_add(buf,telegram_buf);
X sprintf(buf,"fired on %s%s; %d%s.",
X		to.level==LEVEL_SHIP ? "ship " : "", Dispplace(&to),
X		dam, to.level==LEVEL_SHIP ? 
X		 (to.shipptr->type==OTYPE_VN ? " Von Neumann machines destroyed"
X		 : "% damage done") : " sectors destroyed" );
X teleg_add(buf,telegram_buf);
X if (to.level==LEVEL_SHIP && to.shipptr->is_dead) {
X	sprintf(buf,"Ship #%d DESTROYED.\n", to.shipno);
X	teleg_add(buf,telegram_buf);
X }
X for (i=1; i<MAXPLAYERS; i++)
X    if (Nuked[i] && i!=Playernum) {
X	 printf("notifying player %d\n",i);
X	 teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf);
X    }
X
X
X if (dam2) {
X   	printf("%s retaliates with %sstrength %d!! %d%s.\n", Dispplace(&to), 
X		Numplayersretaliate>1 ? "total " : "",
X		strength, dam2, 
X  		(from.level==LEVEL_SHIP) ? 
X	    		"% damage done" : " sectors destroyed" );
X } else printf("%s cannot retaliate.\n",Dispplace(&to) );
X
X
X if (from.level==LEVEL_PLAN) {
X   /* firing from planet -- deduct APs from that star */
X	   APdeductstar = from.snum;
X } else if (from.level==LEVEL_SHIP && from.shipptr->whatorbits!=LEVEL_UNIV) {
X   /* firing from ship -- deduct APs from star ship orbits */
X	   APdeductstar = from.shipptr->storbits;
X }
X
X deductAPs(APcount, APdeductstar, 0);
X
X sigsetmask(mask);	/* reset mask */
X}
X
X
X
Xfire_handler(sig, code, scp)
Xint sig,code;
Xstruct sigcontext *scp;
X{
X close(fire_stardata);
X close(fire_fromshdata);
X close(fire_toshdata);
X close(fire_frompdata);
X close(fire_topdata);
X close(fire_sectdata);
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 11944 -ne `wc -c <'fire.c'`; then
    echo shar: \"'fire.c'\" unpacked with wrong size!
fi
# end of 'fire.c'
fi
if test -f 'fix.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fix.c'\"
else
echo shar: Extracting \"'fix.c'\" \(12202 characters\)
sed "s/^X//" >'fix.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X *	fix.c -- allows manager to edit various stuff.
X *		   -not to be used by players cuz it will get boring fast
X *			note: may not work under machines w/ 
X *				sizeof(int) <> sizeof(float).
X */
X
X#define FLOAT 0	/* to tell query what to input for */
X#define INT 1
X#define CHAR 2
X#define SHORT 3
X#define LONG 4
X#define DOUBLE 5
X
X#include "vars.h"
X#include "tweakables.h"
X#include "ships.h"
X#include "races.h"
X#include <strings.h>
X#include <ctype.h>
X#include <signal.h>
X#include <setjmp.h>
Xextern jmp_buf main_jenv;
Xint fix_stardata,fix_shdata,fix_pdata,fix_sectdata;
Xchar s[40];
Xextern char *Shipnames[];
X
Xbool fix_mod;
X
Xfix(argn,args)
Xint argn;
Xchar args[MAXARGS][COMMANDSIZE];
X{
Xchar ch;
Xshort shrt;
Xfloat f;
Xint i;
Xunsigned long unl;
Xplanettype *p;
Xsectortype *sect;
Xshiptype *sh;
Xint fix_handler();
X
Xfix_mod = 0;
Xfix_stardata = fix_shdata = fix_pdata = fix_sectdata = NEUTRAL_FD;
X	/* so closure does not cause wanted files to close (like stdin 
X		or stdout) -- should not cause probs most vers. of UNIX */
Xsignal(SIGINT, fix_handler);
X
Xif (argn==2 && !strcmp(args[1],"race")) {
X	query(FLOAT,"tech",&Race->tech,0,0,0,0);
X	query(FLOAT,"birthrate",&Race->birthrate,0,0,0,0);
X	query(FLOAT,"mass",&Race->mass,0,0,0,0);
X	query(FLOAT,"adventurists",&Race->nonhomebodies,0,0,0,0);
X	query(FLOAT,"metabolism",&Race->metabolism,0,0,0,0);
X	query(FLOAT,"overbirthrate",&Race->overbirthrate,0,0,0,0);
X	query(INT, "Playernum",0,&Race->Playernum,0,0,0);
X	query(CHAR, "fighters",0,0,&Race->fighters,0,0);
X	query(CHAR, "IQ",0,0,&Race->IQ,0,0);
X	query(CHAR, "# sexes",0,0,&Race->number_sexes,0,0);
X	  ch = Race->Thing;
X	query(CHAR, "Race is like 'The Thing'",0,0,&ch,0,0);
X	  Race->Thing = ch;
X	    /*float metabolism;*/
X	    /*char homelevel,homesystem,homeplanetnum;	/* home place */
X	printf("atmospheric cond preferred\n");
X	query(CHAR, "Temp",0,0,&Race->conditions[TEMP],0,0);
X	query(CHAR, "Rtemp",0,0,&Race->conditions[RTEMP],0,0);
X	query(CHAR, "Methane",0,0,&Race->conditions[METHANE],0,0);
X	query(CHAR, "Oxygen",0,0,&Race->conditions[OXYGEN],0,0);
X	query(CHAR, "CO2",0,0,&Race->conditions[CO2],0,0);
X	query(CHAR, "Hydrogen",0,0,&Race->conditions[HYDROGEN],0,0);
X	query(CHAR, "Nitrogen",0,0,&Race->conditions[NITROGEN],0,0);
X	query(CHAR, "Sulfur",0,0,&Race->conditions[SULFUR],0,0);
X	query(CHAR, "Helium",0,0,&Race->conditions[HELIUM],0,0);
X	query(CHAR, "Other",0,0,&Race->conditions[OTHER],0,0);
X	if (fix_mod)
X		putrace(Race);
X} else {
X
X switch (Dir.level) {
X
X  case LEVEL_UNIV:
X	openstardata(&fix_stardata);
X	getsdata(fix_stardata, &Sdata);
X
X	query(CHAR, "ActionPoints",0,0,&Sdata.AP[Playernum],0,0);
X	if (fix_mod) {
X		printf("Saving...\n");
X		putsdata(fix_stardata, &Sdata);
X	}
X	close(fix_stardata);
X	break;
X
X  case LEVEL_STAR:
X	openstardata(&fix_stardata);
X	getstar(fix_stardata, &Stars[Dir.snum], Dir.snum);
X
X	printf("Star #%d : %s\n\n", Dir.snum, Stars[Dir.snum]->name );
X
X	 printf("(limit %d) ",MAXSSHIPS);
X	/*query(CHAR, "# ships orbiting",0,0,&Stars[Dir.snum]->numships,0,0);*/
X	for (ch=MAXSSHIPS-1; ch>1 && !Stars[Dir.snum]->shipnums[ch]; ch--) ;
X	printf("last ship slot is %d\n",ch);
X	for (i=0; i<MAXSSHIPS && i<ch; i++)
X	 if (Stars[Dir.snum]->shipnums[i]) {
X	   printf("Ship slot #%d is ",i);
X	   query(SHORT, "ship number",0,0,0,&Stars[Dir.snum]->shipnums[i],0);
X	 }
X    	/*char explored[howmanybytes(MAXPLAYERS)];*/
X    	/*char inhabited[howmanybytes(MAXPLAYERS)];*/
X	query(CHAR, "ActionPoints",0,0,&Stars[Dir.snum]->AP[Playernum],0,0);
X
X	query(FLOAT,"x position",&Stars[Dir.snum]->xpos,0,0,0,0);
X	query(FLOAT,"y position",&Stars[Dir.snum]->ypos,0,0,0,0);
X	 printf("(limit %d) ",MAXPLANETS);
X	/*query(CHAR, "# planets",0,0,&Stars[Dir.snum]->numplanets,0,0);*/
X	query(CHAR, "stability",0,0,&Stars[Dir.snum]->stability,0,0);
X	ch = Stars[Dir.snum]->nova_stage;
X	query(CHAR, "nova stage",0,0,&ch,0,0);
X		Stars[Dir.snum]->nova_stage = ch;
X	/*for (i=0; i<Stars[Dir.snum]->numplanets; i++) {
X		printf("Planet #%d (%s) ", i, Stars[Dir.snum]->pnames[i]);
X		query(INT, "file position",0,&Stars[Dir.snum]->planetpos[i],0,0,0);
X	}*/
X
X	if (fix_mod) {
X		putstar(fix_stardata, Stars[Dir.snum], Dir.snum);
X		printf("Saving...\n");
X	}
X	close(fix_stardata);
X	break;
X
X  case LEVEL_PLAN:
X	openpdata(&fix_pdata);
X	getplanet(fix_pdata, &p, Stars[Dir.snum]->planetpos[Dir.pnum]);
X
X	if (argn==1) {
X		printf("\nPlanet / %s / %s\n", Stars[Dir.snum]->name, Stars[Dir.snum]->pnames[Dir.pnum]);
X		unl = p->info[Playernum-1].resource;
X		query(LONG, "\nstockpile resources",0,0,0,0,&unl);
X			p->info[Playernum-1].resource = unl;
X		unl = p->info[Playernum-1].destruct;
X		query(LONG, "stockpile destruct",0,0,0,0,&unl);
X			p->info[Playernum-1].destruct = unl;
X		unl = p->info[Playernum-1].fuel;
X		query(LONG, "stockpile fuel",0,0,0,0,&unl);
X			p->info[Playernum-1].fuel = unl;
X		unl = p->popn;
X		query(LONG, "total population(altered after turn)",0,0,0,0,&unl);
X			p->popn = unl;
X		ch = p->info[Playernum-1].numsectsowned;
X		query(CHAR, "numsectsowned",0,0,&ch,0,0);
X		p->info[Playernum-1].numsectsowned = ch;
X		ch = p->info[Playernum-1].explored;
X		query(CHAR, "explored",0,0,&ch,0,0);
X		  p->info[Playernum-1].explored;
X		 printf("atmospheric cond\n");
X		query(CHAR, "Temp",0,0,&p->conditions[TEMP],0,0);
X		query(CHAR, "Rtemp",0,0,&p->conditions[RTEMP],0,0);
X		query(CHAR, "Methane",0,0,&p->conditions[METHANE],0,0);
X		query(CHAR, "Oxygen",0,0,&p->conditions[OXYGEN],0,0);
X		query(CHAR, "CO2",0,0,&p->conditions[CO2],0,0);
X		query(CHAR, "Hydrogen",0,0,&p->conditions[HYDROGEN],0,0);
X		query(CHAR, "Nitrogen",0,0,&p->conditions[NITROGEN],0,0);
X		query(CHAR, "Sulfur",0,0,&p->conditions[SULFUR],0,0);
X		query(CHAR, "Helium",0,0,&p->conditions[HELIUM],0,0);
X		query(CHAR, "Other",0,0,&p->conditions[OTHER],0,0);
X		query(CHAR, "Toxicity",0,0,&p->conditions[TOXIC],0,0);
X
X		for (ch=MAXSSHIPS-1; ch>1 && !p->shipnums[ch]; ch--) ;
X		printf("last ship slot is %d\n",ch);
X		for (i=0; i<MAXPSHIPS && i<ch; i++)
X		 if (p->shipnums[i]) {
X		   printf("Ship slot #%d is ",i);
X		   query(SHORT, "ship number",0,0,0,&p->shipnums[i],0);
X		 }
X		 /*printf("(limit %d) ", MAX_X);
X		query(CHAR, "sectormap size x",0,0,&p->Maxx,0,0);*/
X		 /*printf("(limit %d) ", MAX_Y,0);
X		query(CHAR, "sectormap size y",0,0,&p->Maxy,0,0);*/
X		/*query(INT, "sect map file position",0,&p->sectormappos,0,0,0);*/
X		query(FLOAT,"x position",&p->xpos,0,0,0,0);
X		query(FLOAT,"y position",&p->ypos,0,0,0,0);
X		ch = p->slaved_to;
X		query(CHAR, "enslaved to player #",0,0,&ch,0,0);
X			p->slaved_to = ch;
X		/*ch = p->is_cloaked;
X		query(CHAR, "cloaked",0,0,&ch,0,0);
X		  p->is_cloaked = ch;*/
X
X		ch = p->type;
X		query(CHAR, "planet type",0,0,&ch,0,0);
X		  p->type = ch;
X		ch = p->info[Playernum-1].comread;
X		query(CHAR, "combat readiness",0,0,&ch,0,0);
X		  p->info[Playernum-1].comread = ch;
X		ch = p->is_explored;
X		query(CHAR, "is_explored by owner",0,0,&ch,0,0);
X		  p->is_explored = ch;
X
X		if (fix_mod) {
X			putplanet(fix_pdata, p, Stars[Dir.snum]->planetpos[Dir.pnum]);
X			printf("Saving...\n");
X		}
X		close(fix_pdata);
X
X	} else {
X			/* fix sector */
X		int x,y;
X		close(fix_pdata);
X		sscanf(args[1],"%d,%d", &x, &y);
X		printf("  sector %d,%d\n",x,y);
X		opensectdata(&fix_sectdata);
X		getsector(fix_sectdata,&sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
X
X		ch = sect->eff;
X		query(CHAR, "efficiency",0,0,&ch,0,0);
X		  sect->eff = ch;
X		ch = sect->resource;
X		query(CHAR, "resource deposits",0,0,&ch,0,0);
X		  sect->resource = ch;
X		ch = sect->fert;
X		query(CHAR, "fertility",0,0,&ch,0,0);
X		  sect->fert = ch;
X		ch = sect->mobilization;
X		query(CHAR, "mobilization",0,0,&ch,0,0);
X		  sect->mobilization = ch;
X		printf("(limit %d)",MAX_SECT_POPN);
X		i = sect->popn;
X		query(INT, "population",0,&i,0,0,0);
X		  sect->popn = i;
X		i = sect->owner;
X		query(INT, "owner",0,&i,0,0,0);
X		  sect->owner = i;
X		ch = sect->is_wasted;
X		query(CHAR, "is_wasted",0,0,&ch,0,0);
X		  sect->is_wasted = ch;
X		ch = sect->des;
X		query(CHAR, "designation",0,0,&ch,0,0);
X		  sect->des = ch;
X	    /*unsigned is_cloaked : 1;	/* 1 bit: is cloaked sector */
X		if (fix_mod) {
X			putsector(fix_sectdata,sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
X			printf("Saving...\n");
X		}
X		close(fix_sectdata);
X	}
X	free(p);
X	break;
X
X  case LEVEL_SHIP:
X	openshdata(&fix_shdata);
X	getship(fix_shdata, &sh, Dir.shipno);
X
X	printf("\n%s #%d.\n", Shipnames[sh->type], Dir.shipno);
X
X	ch = sh->owner;
X	query(CHAR, "owner",0,0,&ch,0,0);
X		sh->owner = ch;
X	query(FLOAT,"x position",&sh->xpos,0,0,0,0);
X	query(FLOAT,"y position",&sh->ypos,0,0,0,0);
X	query(FLOAT,"mass",&sh->mass,0,0,0,0);
X
X	query(FLOAT,"fuel",&sh->fuel,0,0,0,0);
X	 unl = sh->destruct;
X	query(LONG, "destruct cap",0,0,0,0,&unl);
X	 sh->destruct = unl;
X	 unl = sh->resource;
X	query(LONG, "resource",0,0,0,0,&unl);
X	 sh->resource = unl;
X	 unl = sh->popn;
X	query(LONG, "crew",0,0,0,0,&unl);
X	 sh->popn = unl;
X
X	 unl = sh->rad;
X	query(LONG, "irradiated",0,0,0,0,&unl);
X	 sh->rad = unl;
X	 unl = sh->damage;
X	query(LONG, "damage",0,0,0,0,&unl);
X	 sh->damage = unl;
X
X	ch = sh->whatorbits;
X	query(CHAR, "what orbits level",0,0,&ch,0,0);
X	  sh->whatorbits = ch;
X	query(CHAR, "orbits what star ",0,0,&sh->storbits,0,0);
X	ch = sh->pnumorbits;
X	query(CHAR, "orbits what planet",0,0,&ch,0,0);
X	  sh->pnumorbits = ch;
X	ch = sh->whatdest;
X	query(CHAR, "what destination level",0,0,&ch,0,0);
X	  sh->whatdest = ch;
X	query(CHAR, "what star dest",0,0,&sh->deststar,0,0);
X	ch = sh->destpnum;
X	query(CHAR, "what planet dest",0,0,&ch,0,0);
X	  sh->destpnum = ch;
X	ch = sh->is_docked;
X	query(CHAR, "is docked",0,0,&ch,0,0);
X	  sh->is_docked = ch;
X	query(SHORT, "what ship dest",0,0,0,&sh->destshipno,0);
X	/*query(SHORT, "abil_cargo",0,0,0,&sh->abils[ABIL_CARGO],0);
X	query(SHORT, "abil_stealth",0,0,0,&sh->abils[ABIL_STEALTH],0);
X	query(SHORT, "abil_destruct cap",0,0,0,&sh->abils[ABIL_DESTCAP],0);
X	query(SHORT, "abil_num guns",0,0,0,&sh->abils[ABIL_GUNS],0);
X	query(SHORT, "abil_fuel cap",0,0,0,&sh->abils[ABIL_FUELCAP],0);
X	query(SHORT, "abil_tech level",0,0,0,&sh->abils[ABIL_MINTECH],0);
X	query(SHORT, "abil_max crew",0,0,0,&sh->abils[ABIL_MAXCREW],0);
X	query(SHORT, "abil_armor",0,0,0,&sh->abils[ABIL_ARMOR],0);*/
X
X	if (is_object(sh)) {
X	  query(SHORT, "object:number",0,0,0,&sh->orders.object.number,0);
X	  query(SHORT, "object:number2",0,0,0,&sh->orders.object.number2,0);
X	  /*query(SHORT, "object:number3",0,0,0,&sh->orders.object.number3,0);*/
X	}
X
X	if (fix_mod) {
X		printf("Saving...\n");
X		putship(fix_shdata, sh, Dir.shipno);
X	}
X	close(fix_shdata);
X	break;
X
X
X    /*ordertype orders;		/* standing orders for ship */
X    /*unsigned augmented : 4;	/* # of times augmented (max 10) */
X    /*unsigned whatdest : 2;	/* where going (same as Dir) */
X    /*unsigned whatorbits : 2;	/* where orbited (same as Dir) */
X    /*unsigned type : 4;		/* what type ship is */
X    /*unsigned is_sheep : 1;	/* 1 bit: is under influence of mind control */
X    /*unsigned is_docked : 1;	/* 1 bit: is landed on a planet or docked */
X    /*unsigned has_moved : 1;	/* 1 bit: has been moved by user */
X    /*unsigned outtafuel_notified:1; /* 1bit: has been notified of no fuel */
X
X
X }
X}
X
X}
X
X
Xquery( kind, quest, fprev, iprev, cprev, sprev, lprev)
Xint kind;
Xchar *quest;
Xfloat *fprev;
Xint *iprev;
Xchar *cprev;
Xshort *sprev;
Xlong *lprev;
X{
X float f;
X int i;
X char c,ch;
X short s;
X long l;
X
X printf("%s (", quest);
X switch (kind) {
X  case FLOAT:
X	printf("%f", *fprev);
X	break;
X  case INT:
X	printf("%d", *iprev);
X	break;
X  case CHAR:
X	printf("%d", *cprev);
X	break;
X  case SHORT:
X	printf("%d", *sprev);
X	break;
X  case LONG:
X	printf("%ld", *lprev);
X	break;
X }
X printf(") : ");
X
X if ( isdigit(ch=getchr()) || ch=='-' || ch=='.') {
X	ungetc(ch, stdin);
X	fix_mod = 1;	/* set mod so fix knows to save data */
X	switch (kind) {
X	 case FLOAT:
X		scanf("%f",fprev);
X		break;
X	 case INT:
X		scanf("%d",iprev);
X		break;
X	 case CHAR:
X		scanf("%d",&i);
X		*cprev = i;  /* don't want to copy a whole int's worth */
X		break;
X	 case SHORT:
X		scanf("%hd",sprev);
X		break;
X	 case LONG:
X		scanf("%ld",lprev);
X		break;
X	}
X	getchr();
X  }
X}
X
X
Xfix_handler(sig, code, scp)
Xint sig,code;
Xstruct sigcontext *scp;
X{
X close(fix_stardata);
X close(fix_shdata);
X close(fix_pdata);
X close(fix_sectdata);
X printf("changes not saved!\n");
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 12202 -ne `wc -c <'fix.c'`; then
    echo shar: \"'fix.c'\" unpacked with wrong size!
fi
# end of 'fix.c'
fi
if test -f 'makeplanet.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makeplanet.c'\"
else
echo shar: Extracting \"'makeplanet.c'\" \(9536 characters\)
sed "s/^X//" >'makeplanet.c' <<'END_OF_FILE'
X/*
X * Galactic Bloodshed (Robert Chansky, smq@b)
X *	makeplanet.c -- makes one planet.  used with makeuniv
X */
X
X#include "tweakables.h"
X#include "vars.h"
X#include <math.h>
Xlong random();
Xdouble Distmap();	/* (different distmap from the shell one */
X
X
Xplanettype Makeplanet(type)
Xint type;
X{
Xregister int x,y;
Xsectortype *s;
Xplanettype planet;
Xint i, atmos;
X
X  Bzero(planet);
X  bzero((char *)Smap, sizeof(Smap));
X  planet.type = type;
X  planet.expltimer = 5;
X
Xif (type==TYPE_GASGIANT) {			/* gas giant */
X  planet.Maxx = GASGIANT_RANGE;
X  planet.Maxy = round_rand((float)planet.Maxx / RATIOXY);
X
X  planet.conditions[TEMP] = 		/* change to more real range */
X  	planet.conditions[RTEMP] = int_rand(-50,50);	
X	/* either lots of meth or not too much */
X  if (random()&01) {	/* methane planet */
X    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
X    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[HELIUM] = 1;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = 1;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  } else {
X    atmos = 100 - (planet.conditions[HYDROGEN] = int_rand(30,55));
X    atmos -= planet.conditions[HELIUM] = int_rand(30,atmos/2);
X    atmos -= planet.conditions[METHANE] = random()&01;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = random()&01;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  }
X
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_GAS;	/* for gasgiant */
X	s->fert=1;
X     }
X if (planet.Maxx > MAP_GASGIANT_BANDMIN) {
X    int nbands;
X    nbands = MAX(1,planet.Maxy/5);
X    for (i=1; i<=nbands; i++) {
X     y=int_rand(1,planet.Maxy-2);
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_SEA;	/* make random bands of water */
X	s->fert += int_rand(2,3);
X     }
X    }
X    for (i=0; i<=MAP_ISLANDS*2; i++) {
X     y=int_rand(1,planet.Maxy-2);
X     x=int_rand(1,planet.Maxx-2);
X	s = &Sector(planet,x,y);
X	s->des = DES_SEA;	/* make random spots of water */
X	s->fert += int_rand(2,3);
X    }
X } else {
X    for (i=0; i<MAP_ISLANDS*2; i++) {
X	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
X	if (random()&01) {
X		s->des=DES_MOUNT;
X		s->is_wasted = 1;
X		s->resource=int_rand(5,12);
X		s->fert=int_rand(5,12);
X	} else {
X		s->des=DES_SEA;
X		s->fert=int_rand(5,12);
X	}
X    }
X  Smashup(&planet,int_rand(2,4),DES_SEA,0,0,0);
X  Smashup(&planet,int_rand(1,2),DES_LAND,2,3,1);
X }
X
X} else if (type==TYPE_AIRLESS) {	/* make airless wasted planet */
X    planet.conditions[RTEMP] = 
X    	planet.conditions[TEMP] = int_rand(-50,50);
X    planet.conditions[HYDROGEN] = 0;
X    planet.conditions[HELIUM] = 0;
X    planet.conditions[METHANE] = 0;
X    planet.conditions[OXYGEN] = 0;
X    atmos = 100 - (planet.conditions[CO2] = int_rand(30,45));
X    atmos -= planet.conditions[NITROGEN] = int_rand(10, atmos/2);
X    atmos-=planet.conditions[SULFUR] = random()&01 ? 0 : int_rand(20, atmos/2);
X    atmos-=planet.conditions[OTHER] = atmos;
X
X  planet.Maxx = AIRLESS_RANGE;
X  planet.Maxy = round_rand(planet.Maxx / RATIOXY);
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = DES_MOUNT;	/* for airless */
X	/*s->is_wasted=1;	/* is wasteland */
X	s->resource=int_rand(25,35);
X	s->fert=1;
X     }
X     for (i=0; i<MAP_ISLANDS; i++) {
X	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
X	s->des = DES_LAND;
X	s->fert += random()&01;
X	s->resource+=int_rand(15,22);
X     }
X  Smashup(&planet,6,DES_LAND,5,1,1);	/* make meteor impacts */
X
X} else if (type==TYPE_ASTEROID) {   /* asteroid */
X	/* no atmosphere */
X    planet.conditions[HYDROGEN] = 0;
X    planet.conditions[HELIUM] = 0;
X    planet.conditions[METHANE] = 0;
X    planet.conditions[OXYGEN] = 0;
X    planet.conditions[CO2] = 0;
X    planet.conditions[NITROGEN] = 0;
X    planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = 0;
X  planet.Maxx = ASTEROID_RANGE_X;
X  planet.Maxy = ASTEROID_RANGE_Y;
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des = int_rand(0,3) ? DES_MOUNT : DES_LAND;
X	s->is_wasted=1;
X	s->resource=int_rand(55,85);
X	s->fert=(char)random()&01;
X     }
X  
X} else if (type==TYPE_EARTH) {	/* make an earthtype planet */
X  int i,landsects,Numlandsects;
X    planet.conditions[RTEMP] =
X    	planet.conditions[TEMP] = int_rand(-50,50);
X  if (random()&01) {
X	/* oxygen-reducing atmosphere (Earth type) */
X    atmos = 100 - (planet.conditions[OXYGEN] = int_rand(10,25));
X    atmos -= planet.conditions[NITROGEN] = int_rand(20,atmos/2);
X    atmos -= planet.conditions[CO2] = int_rand(20,atmos/2);
X    atmos -= planet.conditions[HELIUM] = int_rand(2,atmos/8+1);
X    atmos -= planet.conditions[METHANE] = random()&01;
X    atmos -= planet.conditions[SULFUR] = 0;
X    atmos -= planet.conditions[HYDROGEN] = 0;
X    planet.conditions[OTHER] = atmos;
X  } else {
X	/* methane atmosphere */
X    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
X    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[HELIUM] = 1;
X    atmos -= planet.conditions[OXYGEN] = 0;
X    atmos -= planet.conditions[CO2] = 1;
X    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
X    atmos -= planet.conditions[SULFUR] = 0;
X    planet.conditions[OTHER] = atmos;
X  }
X  planet.Maxx=EARTHTYPE_RANGE;
X  planet.Maxy=round_rand(planet.Maxx/RATIOXY);	/* may haveta change this */
X  Numlandsects=planet.Maxx*planet.Maxy*LANDPERCENTAGE;
X
X  for (y=0; y<planet.Maxy; y++)
X     for (x=0; x<planet.Maxx; x++) {
X	s = &Sector(planet,x,y);
X	s->des=DES_SEA;	/* make all water first */
X     }
X		/* make first isolated islands */
X  for (i=0; i<=MAP_ISLANDS; i++) {
X     s = &Sector(planet, int_rand(planet.Maxx/5,planet.Maxx-planet.Maxx/5),
X	     int_rand(1,planet.Maxy-2));
X     s->des = DES_LAND;  
X     s->resource = 100;
X     s->fert = int_rand(6,20);
X  }
X
X  PermuteSects(&planet);	/* mix up map */
X  (void)Getxysect(&planet,0,0,1);	/* reset index */
X
X  landsects=0;
X  while (landsects<=Numlandsects)
X       landsects += Volcano(&planet,landsects,Numlandsects); 
X		   /* pick rndm locn, return whether island or not */
X
X
X		/* make more isolated islands */
X  for (i=0; i<=MAP_ISLANDS*4; i++) {
X     x=int_rand(0,planet.Maxx-1);
X     y=int_rand(0,planet.Maxy-1);
X     s = &Sector(planet,x,y);
X     s->des = DES_LAND;
X     s->resource = 55;	/* nice odd number */
X		  /* min content prop to dist from sea */
X     s->fert = 45;
X  }
X	/* make some wasteland sectors (polar caps ) */
X	/* do s pole */
X  for (y=planet.Maxy; y>=planet.Maxy-4; y--)
X     for (x=0; x<planet.Maxx; x++)
X	if ( ((y==planet.Maxy-1) && int_rand(0,1)) ||
X		((y==planet.Maxy-2) && !int_rand(0,2) && Sector(planet,x,planet.Maxy).is_wasted) ) {
X	  Sector(planet,x,y).is_wasted=1;
X	  Smap[y*planet.Maxx+x].fert /= 6;
X     	}
X	/* do n pole */
X  for (y=0; y<=3; y++)
X     for (x=0; x<planet.Maxx; x++)
X	if ( ((y==0) && int_rand(0,1)) ||
X		((y==1) && !int_rand(0,2) && Smap[x].is_wasted) ) {
X	  Smap[y*planet.Maxx+x].is_wasted=1;
X	  Smap[y*planet.Maxx+x].fert /= 6;
X        }
X }
X/*###222 [lint] syntax error at or near word "return"%%%*/
X return ( planet );
X/*###223 [lint] syntax error at or near symbol }%%%*/
X}
X
X
XSmashup(pptr,n,desig,res,fert,waste)	
Xplanettype *pptr;
Xint n;
Xchar desig;
Xbool res,fert,waste;
X		/* smash psuedo-meteors into the place */
X{
Xchar r,x,y;
Xregister int x2,y2;
Xsectortype *s;
X
X while (n--) {
X    x=int_rand(1,pptr->Maxx-2);
X    y=int_rand(1,pptr->Maxy-2);
X    r=int_rand(2,int_rand(2,pptr->Maxy/3+1));
X    for (y2=y-r-1; y2<=y+r+1; y2++)
X       for (x2=x-r-1; x2<=x+r+1; x2++)
X	  if (Distmap(x,y,x2,y2) < r) 
X	     if ((x2<pptr->Maxx)&&(x2>=0)&&(y2<pptr->Maxy)&&(y2>=0)) {
X		s = (&(Smap[y2*pptr->Maxx+x2]));
X		if (desig==DES_LAND && s->des==DES_MOUNT)
X			s->des = DES_LAND;
X		else if (desig==DES_LAND && s->des==DES_LAND)
X			s->des = DES_MOUNT;
X		if (waste) s->is_wasted=1;
X		if (res) s->resource+=int_rand(res/2,res*2);
X		if (fert) s->fert+=int_rand(fert/2,fert*2);
X	     }
X }
X
X}
X
X
X
Xdouble Distmap(x,y,x2,y2)
Xregister int x,y,x2,y2;
X{
X return fabs((double)x-x2) / RATIOXY + fabs( (double)y-y2);
X}
X
X
Xint Volcano(pptr,landsectors,Numlandsects)
Xplanettype *pptr;
Xint landsectors,Numlandsects;
X{
Xint x,y;
Xsectortype *s;
X
X  (void)Getxysect(pptr,&x,&y,0);
X  /*x = int_rand(0,pptr->Maxx-1);
X  y = int_rand(0,pptr->Maxy-1);*/
X  s = &Sector(*pptr,x,y);
X
X  if (s->des==DES_SEA) {
X    if (Numneighbors(pptr,x,y,DES_LAND)||Numneighbors(pptr,x,y,DES_MOUNT)) {
X	s->des=(landsectors>(MAP_MOUNT_PERCENT*Numlandsects))?DES_LAND:DES_MOUNT;
X	s->resource = round_rand((float)(Numlandsects - landsectors + 5) / (float)Numlandsects * 100);
X		  /* min content prop to dist from sea */
X	s->fert = (float)(landsectors + 5) / (float)Numlandsects * 100;
X		  /* fert content prop to dist from center of continent */
X       return(1);
X    } else return(0);
X   } else return(0);
X}
X
X
X
X/* return # of neighbors of a given designation that a sector has. */
Xint Numneighbors(p,x,y,des)
Xplanettype *p;
Xregister int x,y,des;
X{
Xregister int d;
X  return (Sector(*p,mod(x-1,p->Maxx,d),y).des==des) + 
X  	 (Sector(*p,mod(x+1,p->Maxx,d),y).des==des) + 
X  	 ((y==0) ? 0 : (Sector(*p,x,y-1).des==des)) + 
X  	 ((y==p->Maxy-1) ? 0 : (Sector(*p,x,y+1).des==des));
X}
END_OF_FILE
if test 9536 -ne `wc -c <'makeplanet.c'`; then
    echo shar: \"'makeplanet.c'\" unpacked with wrong size!
fi
# end of 'makeplanet.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'\" \(12137 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 <curses.h>
X#include <ctype.h>
X#include <setjmp.h>
X#include <signal.h>
Xextern jmp_buf main_jenv;
X
Xextern char *Shipnames[];
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 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, 1);
X	} else {
X		printf("usage: order [#shipnum]\n");
X		return;
X	}
X} else {
X /* no ship specified, order all ships,planets in scope */
X
X  switch (Dir.level) {
X
X   case LEVEL_UNIV:
X      for (i=0; i<MAXUSHIPS; i++)
X	if (Sdata.shipnums[i] && enufAP(Sdata.AP, APcount))
X		Sdatamod |= give_orders(APcount, Sdata.shipnums[i], 0);
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   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, 1);	/* 1 == objects are ok */
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 4
X#define SWpromptx 2
X#define Bprompty 6
X
X
Xint give_orders(APcount, shipno, obj)
Xint APcount;
Xint shipno,obj;
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	/* cannot order docked ships */
X	/* or objects, when object option is on */
X if (ship->owner==Playernum) {
X 
X    if (is_object(ship) && !obj) {
X	printw("%s #%d is not a ship. (order with ``order #%d'')\n",
X		Shipnames[ship->type], shipno, shipno);
X	i = 1;
X    }
X    if (ship->is_docked && !is_object(ship)) {
X	printw("%s #%d is docked.\n",Shipnames[ship->type], shipno);
X	i = 1;
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->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    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	return;
X    }
X
X    do {
X
X      if (redraw) {
X	redraw = 0;
X
X	if (first || was_obj!=is_object(ship)) {
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 (can_move(ship)) {
X		move(2,0);
X		printw("(d)estination: %*s", -PLACENAMESIZE, prin_ship_dest(ship));
X		if (ship->type!=STYPE_POD) {
X			move(Sprompty,Spromptx-9);
X			printw("(s)peed: %d\n",ship->speed);
X		}
X	}
X	if (ship->type==STYPE_MIRROR) {
X		was_obj = 1;
X		move(4,0);
X	   	printw("(a)imed at: %s", prin_aimed_at(ship));
X		printw("\n (i)ntensity: %3d",ship->orders.aimed_at.intensity);
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_move(ship) && Shipdata[ship->type][ABIL_DESTCAP]) {
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->orders.object.on ? "n" : "ff");
X	}
X
X	move(Oprompty,0);
X	printw("orders (");
X	if (can_move(ship))
X		printw("dsi%s ESC?):",ship->type==STYPE_MIRROR ? "a" : "tm");
X	else
X		printw("O%s ESC?):",ship->type==STYPE_MINE?"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');
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();
X		    } break;
X
X		case 'o':
X			/* on/off switch */
X		    if (has_switch(ship)) {
X		      move(SWprompty,SWpromptx);
X		      ship->orders.object.on = !ship->orders.object.on;
X		      printw("(o)%s", ship->orders.object.on ? "n " : "ff");
X		      Mod = 1;
X		      if (ship->orders.object.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			      }
X		      }
X		    }
X		    break;
X
X		case 'd':
X		    if (can_move(ship)) {
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		      where = Getplace(s, 1);
X		      if (!where.err) {
X			    ship->whatdest = where.level;
X			    ship->deststar = where.snum;
X			    ship->destpnum = where.pnum;
X			    ship->destshipno = where.shipno;
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 's':
X		    if (can_move(ship) && ship->type!=STYPE_POD) {
X		     do {
X		      mvaddch(Sprompty, Spromptx, '?');
X		      move(Sprompty, Spromptx);
X		      refresh();
X		      c = getchr();
X		      if (c=='?') {
X			move(10,0);
X			clrtobot();
X			printw("Speed:\n 0 -- Full stop\n 1 -- Slow (fuel efficient)\n 2 -- Standard\n 3 -- Flank (wastes fuel)\n 4 -- RAMMING SPEED, MR. SULU!!");
X			move(Sprompty, Spromptx);
X			refresh();
X		      } else if (isspace(c)) {
X			  c = ship->speed + '0';
X		      } else if (c<'0' || c>'4') {
X			  move(Sprompty,Spromptx);
X			  printw("Bad value %c.",c);
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);
X			refresh(); tty_off();
X			scanw("%hd", &ship->orders.object.number);
X			tty_on();
X			if (ship->orders.object.number > 200)
X				ship->orders.object.number = 200;
X			else if (ship->orders.object.number < 0)
X				ship->orders.object.number = 0;
X			move(Tprompty,Tpromptx);
X			printw("%d  ",ship->orders.object.number);
X		    } else
X			makerr(c);
X		    break;
X
X		case 'a':
X		    if (ship->type==STYPE_MIRROR) {
X		      if (ship->fuel >= 0.3) {
X			move(4,12); 
X		        printw("%*s", PLACENAMESIZE-1, " ");
X			refresh();
X			tty_off();
X			if ((c=getchr())!='\n') {
X			  ungetc(c,stdin);
X			  scanw("%43s", s);
X			  move(Erry,0);
X			  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				ship->fuel -= 0.3;
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 fuel (%.2f).",ship->fuel);
X		      }
X		    }
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 (!is_object(ship) && ship->type!=STYPE_MIRROR && ship->type!=STYPE_MINE && Shipdata[ship->type][ABIL_DESTCAP]) {
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(10,0); clrtobot();
X		    if (can_move(ship))
X		        printw(" d -- destination\n s -- speed\n");
X		    if (ship->type==STYPE_MIRROR)
X			printw(" a -- object aimed at\n i -- intensity\n");
X		    else if (has_switch(ship))
X			printf(" o -- turn object on/off\n");
X		    if (ship->type==STYPE_MINE)
X			printf(" t -- trigger radius\n");
X		    printw("ESC-- reset all orders\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    } while (c!=' ');
X
X    putship(order_shdata,ship,shipno);
X
X }
X
X close(order_shdata);
X free(ship);
X free(oldship);
X
X return Mod;
X}
X
X
Xint plan_give_orders(APcount, filepos)
Xint APcount;
Xregister int filepos;	/* filepos of planet */
X{
X register int i;
X planettype *p;
X int plan_give_orders_pdata,Planmod=0;
X
X openpdata(&plan_give_orders_pdata);
X getplanet(plan_give_orders_pdata,&p,filepos);
X close(plan_give_orders_pdata);
X
X for (i=0; i<MAXPSHIPS; i++)
X   if (p->shipnums[i])
X	Planmod |= give_orders(APcount, p->shipnums[i]);
X
X free(p);
X return Planmod;
X}
X
X
Xint star_give_orders(APcount, num)
Xint APcount;
Xregister int num;
X{
X register int i=0,Starmod=0;
X
X  while (i<MAXSSHIPS)
X     if (Stars[num]->shipnums[i++])
X        Starmod |= give_orders(APcount, Stars[num]->shipnums[i-1]);
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
Xorder_handler(sig, code, scp)
Xint sig,code;
Xstruct sigcontext *scp;
X{
X close(order_shdata);
X close(order_pdata);
X close(order_stardata);
X longjmp(main_jenv,1);
X}
END_OF_FILE
if test 12137 -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 2 \(of 7\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0