[comp.sources.games] v05i010: mpss - multi-player Star Trek game, Part04/04

games@tekred.TEK.COM (07/21/88)

Submitted by: Peer Schmitz <peer@cs.kl.ac.uk>
Comp.sources.games: Volume 5, Issue 10
Archive-name: mpss/Part04



#! /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 4 (of 4)."
# Contents:  InstallRules.ms aliens.c auto.c collision.c dock.c files.h
#   header.h keyscan.c makefile.dist mpssclean.c mpssmail planets.h
#   setupuniverse.c ships.h
# Wrapped by billr@saab on Wed Jul 20 17:00:28 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'InstallRules.ms' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'InstallRules.ms'\"
else
echo shar: Extracting \"'InstallRules.ms'\" \(3781 characters\)
sed "s/^X//" >'InstallRules.ms' <<'END_OF_FILE'
X.TH
XHow to install or alter MPSS.
X.SH
XSETIING UP THE FILES
X.LP
XIf mpss lives in one directory, a subdirectory called "mpsslib" must
Xbe created. "mpsslib" must have permissions 0777 (rwx for all!). Before
Xcompiling the program make sure that all file names in the file "files.h"
Xhave been altered accordingly. Make sure that this file contains the
XFULL pathnames of any files accessed.
Xinside mpsslib we put 3 files, with permissions as follows and owner
Xof all three being daemon. (ALL THIS MUST BE FOR THE GAME TO WORK!!)
XAll files in mpsslib must have permission 4755 or 4777 as shown below.
X(i.e. they set uid as soon as they are invoked.)
X
X"mpsslib" should look like this :
X.DS L
X
Xtotal 144
X-rwsrwxrwx  1 daemon         59 May 11 15:06 mpssmail (file exec. on a new game)
X-rwsr-xr-x  1 daemon      44032 May 12 11:07 slave (invoked by ../mpss)
X-rwsr-xr-x  1 daemon      98304 May 12 11:11 startrek (the master game&process!)
X
Xthe directory above mpsslib should look like this :
X
X-rwsr-xr-x 1 daemon      mpssclean (to clean up a mess if there is one)
X-rwxr-xr-x 1 anyone      mpss (proggie to invoke the full game)
X-rwxr-xr-x 1 anyone      mpssrules (nroff -ms format)
Xdrwxrwxrwx 1 anyone      mpsslib (subdirectory for all files.)
X
X.DE
X.SH
XHow to change mpss.
X.LP
XTo add another type of terminal.
X.LP
XAll the terminal control strings are defined in cursor.c . So, if you wish
Xto add another terminal, put in another case for it in all 3 relevant
Xprocedures in that file. Then edit slave.c and allow the variable tty_type
Xto get that value. (look in procedure gettermdata() ).
XMake sure not to mess about with case 0, which is to exit the proggie in case
Xof doubt. After that invoke mpss not using the -t option and choose the terminal
Xyou have implemented.
X.SH
XStructure of the game..
X.LP
XFirst note that the entire game is controlled by one main master process.
XHeres a sample run of what goes on. (The file main.c contains the main game iteration loop.)
X.LP
XA guy invokes mpss. This tiny proggie only sets the players umask to 000 and
Xopens the /dev/ttyxx file of the player and makes it rw access for all, so
Xthe master proggie can write/read from that terminal. Mpss then execls 
X/mpsslib/slave which is owned by daemon so it can send signals to the
Xmaster-star-trek proggie that is also owned by daemon.  Now, slave starts running. If the mpsslib/masterpid (MASTERPIDFILE) isnt there, this means that the
Xmaster process isnt running yet. Slave makes a LOCK file and if the master
Xisnt there, invokes it. If it is there (i.e. masterpid is present) it 
Xcarries on. After waiting until the masterpidfile appears, slave makes
Xa PLAYERFILE, mpss/player, reads the master process id out of masterpid,
Xand signals the masterprocess that a playerfile is there. The master process
Xgets the signal, reads the playerfile enters the player into the list of players and starts to play him. The master removes the playerfile then, and 
Xthen slave removes the LOCK file. No other slave will make a player file
Xif the lock file is present. The playerfile contains the shipnumber,cursor motion and clear screen strings, as well as the players terminal name. After
Xa player starts playing, if he dies, a playerscorefile is made, and the
Xwaiting slave process is signalled. It reads the playerscorefile, then the
Xscore file (which contains the scoreboard) adds him in, writes back the
Xscoreboard and removes the playerscorefile.r
XOther files in the game are "shipnumber" wich only contains a number between
X0-28 keeping track of which ship is to be allocated next. omakefile makes
Xeverything with the -O option, gmakefile makes everything with the -g option.
X
XLIVE LONG & PROSPER
XAny problems? ask Peer Schmitz, Department of Computer Science
XUniversity of Keele, Keele, Staffs, ST5-5BG
X
X
X
END_OF_FILE
if test 3781 -ne `wc -c <'InstallRules.ms'`; then
    echo shar: \"'InstallRules.ms'\" unpacked with wrong size!
fi
# end of 'InstallRules.ms'
fi
if test -f 'aliens.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aliens.c'\"
else
echo shar: Extracting \"'aliens.c'\" \(3833 characters\)
sed "s/^X//" >'aliens.c' <<'END_OF_FILE'
X#include "ships.h"
X#include "header.h"
X
Xmakealien(cp)
Xregister struct player *cp;
X{
Xchar *malloc(); 
Xstruct player *aa;
X
Xaa=(struct player *)malloc(sizeof(struct player));
X
Xi=(int)rnd(0,10);
Xif (i>5) {
X		aa->id=ROMID;
X		aa->xpos=600;
X		aa->ypos=100;
X	   } else
X	   {
X		aa->id=KLINGID;
X		aa->xpos=600;
X		aa->ypos=575;
X	   }
X
Xaa->impulsemove=0;
Xaa->cm[0]='\0';
Xaa->cl[0]='\0';
Xaa->cm[0]='\0';
Xaa->terminalfile[0]='\0';
Xaa->shipno=28;
Xaa->tty_type= -1;
Xaa->pid=99999;
Xaa->doneit=0;
Xaa->reason=10;
Xaa->oldxpos=aa->xpos;
Xaa->oldypos=aa->ypos;
Xaa->beeping=ON;
Xaa->maxvel=MAXWARP;
Xaa->xvel=0;
Xaa->yvel=0;
Xaa->chflg=FLAG;
Xaa->clflg=OFF;
Xaa->stat=3;
Xaa->energy=STARTENERGY;
Xaa->maxenergy=STARTENERGY;
Xaa->phaserbanks=STARTPHASER;
Xaa->maxphaser=STARTPHASER;
Xaa->photontorpedos=STARTPHOTON;
Xaa->maxphoton=STARTPHOTON;
Xaa->photonpower=PHOTONPOWER;
Xaa->phaserpower=PHASERPOWER;
Xif (aa->id==ROMID) 
X	{
X	aa->photonpower= aa->photonpower+20;
X	aa->phaserpower= aa->phaserpower+20;
X	}
Xaa->photonreach=WEAPONREACH+4;
Xaa->phaserreach=WEAPONREACH+4;
Xaa->weaponselect=0;
Xaa->score=0;
Xaa->cloakingdevice=OFF;
Xaa->shields=OFF;
Xfor(k=0;k<30;++k)
X	aa->planets[k]=0;
Xaa->planetno=0;
Xfor (k=0; k<=3; k++)
X	{
X	aa->channel[k].enemy=NULL;
X	aa->channel[k].xloc=0;
X	aa->channel[k].yloc=0;
X	}
Xaa->flyto= -1;
Xaa->messindex=0;
X	addtolist(aa);
X++noofaliens;
X}
X
Xservicealien(cp)
Xregister struct player *cp;
X{
X	
Xif (cp->messindex==1) 
X	{ 
X	if (autopilotalien(cp)==0) goto movealien; 
X	 	else
X		{
X		/*we have arrived. Now attack the guy*/
X		if (cp->weaponselect==0)
X			{
X			i=rand()%100;
X			if (i<6)
X				{
X				fire_torpedo(cp,'6',0);
X				cp->messindex=0;
X				i=rand()%100;
X				if (i<50)
X					cp->yvel=1;
X				}
X			} else
X			{
X			i=rand()%100;
X			if (i<6)
X				{
X				fire_torpedo(cp,'4',0);
X				cp->messindex=0;
X				i=rand()%100;
X				if (i<50)
X					{
X					cp->yvel=1;
X					cp->xvel=1;
X					}
X				}
X			}
X		}
X	}
Xi=rand()%10000;
Xif (i==9995) {
X	     j=rand()%10;
X	     if (cp->messindex==0 && j<2) lockonalien(cp,NULL); else cp->messindex=0;
X	     }
Xif (i<9920) {goto movealien;}
Xif ((i>=9920)&&(i<9995)) {cp->xvel=0; cp->yvel=0; goto movealien;}
Xif (i==9996) {cp->xvel = -1; goto movealien;}
Xif (i==9997) {cp->xvel = 1; goto movealien;}
Xif (i==9998) {cp->yvel = 1; goto movealien;}
Xif (i==9999) cp->yvel = -1; 
X
Xmovealien :
X
Xcp->oldxpos=cp->xpos;
Xcp->oldypos=cp->ypos;
Xcp->xpos+=cp->xvel;
Xcp->ypos+=cp->yvel;
Xif (((cp->yvel!=0)||(cp->xvel!=0))&&(cp->stat<12)) cp->chflg=FLAG;
X}
X
Xgethim(who,enemyid)
Xregister struct player *who;
Xchar enemyid;
X{
Xregister struct player *x;
Xif (noofplayers>1) return(0);
Xx=startlist;
Xwhile (x!=NULL && x->id!=enemyid) x=x->next;
Xif (x!=NULL) lockonalien(x,who);
X}
X
Xlockonalien(cp,who)
Xregister struct player *cp,*who;
X{
Xregister struct player *x;
X
Xif (cp->stat==12) return(0);
X
Xi=rand()%1000;
Xif (i>500) cp->weaponselect=0; else cp->weaponselect=1;
Xif (who==NULL)
X	{
X	x=startlist;
X	while (x!=NULL)
X	{
X	if (x==cp) {x=x->next; continue;}
X	if ((x->shields==OFF)&&(x->id!=ROMID)&&(x->id!=KLINGID))
X		{
X		cp->channel[1].enemy=x;
X		cp->channel[1].xloc=0;
X		cp->channel[1].yloc=0;
X		cp->messindex=1;
X		} 
X	x=x->next;
X	}  
X	} else
X	{
X		cp->channel[1].enemy=who;
X		cp->channel[1].xloc=0;
X		cp->channel[1].yloc=0;
X		cp->messindex=1;
X	}
X}
X
Xautopilotalien(cp)
Xregister struct player *cp;
X{
Xif (cp->weaponselect==0)
X	{
X	if (cp->xpos!=(cp->channel[1].enemy->xpos-7))
X		{
X	if (cp->xpos<(cp->channel[1].enemy->xpos-7)) cp->xvel=1; else cp->xvel= -1;
X		} else cp->xvel=0;
X	} else
X	{
X	if (cp->xpos!=(cp->channel[1].enemy->xpos+6))
X		{
X	if (cp->xpos<(cp->channel[1].enemy->xpos+6)) cp->xvel=1; else cp->xvel= -1;
X		} else cp->xvel=0;
X	}
Xif (cp->ypos!=cp->channel[1].enemy->ypos)
X		{
X	if (cp->ypos<cp->channel[1].enemy->ypos) cp->yvel=1; else cp->yvel= -1;
X		} else cp->yvel=0;
X
X/* arrival at location*/
Xif ((cp->xvel==0)&&(cp->yvel==0)) return(1); else return(0);
X}
X
END_OF_FILE
if test 3833 -ne `wc -c <'aliens.c'`; then
    echo shar: \"'aliens.c'\" unpacked with wrong size!
fi
# end of 'aliens.c'
fi
if test -f 'auto.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'auto.c'\"
else
echo shar: Extracting \"'auto.c'\" \(3194 characters\)
sed "s/^X//" >'auto.c' <<'END_OF_FILE'
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
X#include "header.h"
X
Xlock_on(cp,chno) 
Xregister struct player *cp;
Xint chno;
X{
Xregister struct player *x;
Xint lockok;
X
Xlockok=OFF;
Xx=startlist;
Xwhile (x!=NULL)
X{
X	if (x==cp) {x=x->next; continue;}
X	if ((cp->xpos==x->xpos)&&(cp->ypos==x->ypos))
X		{
X		cp->channel[chno].enemy=x;
X		cp->channel[chno].xloc=0;
X		cp->channel[chno].yloc=0;
X		lockok=ON;
Xplot1(cp,"        Tractor beam locked onto enemy captain!          ");
Xplot2(cp,"                                                         ");
X		x=NULL;
X		} else
X		x=x->next;
X}
Xif (lockok==OFF)
X	{
X	cp->channel[chno].enemy=NULL;
X	cp->channel[chno].xloc=cp->xpos;
X	cp->channel[chno].yloc=cp->ypos;
X	if (inuniv(cp->xpos,cp->ypos)=='*')
X	{
Xplot1(cp,"         Tractor beam locked onto starbase captain!      ");
Xplot2(cp,"                                                         ");
X	} else
X	{
Xplot1(cp,"    Tractor beam locked onto this quadrant captain!      ");
Xplot2(cp,"                                                         ");
X	}
X	}
X	
X}
X
Xdisplaybeams(cp) 
Xregister struct player *cp;
X{
Xchar str[7];
Xint i;
Xposcurs(cp,23,22);
Xfor (i=0; i<4; i++)
X{
Xsprintf(str,"%1d)",(i+1));
Xwrite(cp->fd,str,2);
Xif (cp->channel[i].enemy==NULL)
X	{
X	if (inuniv(cp->channel[i].xloc,cp->channel[i].yloc)=='*')
X		write(cp->fd,"*:",2);
X	sprintf(str,"%3d,",cp->channel[i].xloc);
X	write(cp->fd,str,4);
X	sprintf(str,"%3d ",cp->channel[i].yloc);
X	write(cp->fd,str,4);
X	} else
X	{
X	sprintf(str,"%1c:",cp->channel[i].enemy->id);
X	write(cp->fd,str,2);
X	sprintf(str,"%3d,",cp->channel[i].enemy->xpos);
X	write(cp->fd,str,4);
X	sprintf(str,"%3d ",cp->channel[i].enemy->ypos);
X	write(cp->fd,str,4);
X	}
X}
X}
X
Xauto_pilot(cp)
Xregister struct player *cp;
X{
Xint x;
Xx=cp->flyto;
Xif (cp->channel[x].enemy==NULL)
X{
Xif (cp->xpos!=cp->channel[x].xloc)
X		{
X		if (cp->xpos<cp->channel[x].xloc) cp->xvel=1; else cp->xvel= -1;		} else cp->xvel=0;
Xif (cp->ypos!=cp->channel[x].yloc)
X		{
X		if (cp->ypos<cp->channel[x].yloc) cp->yvel=1; else cp->yvel= -1;
X		} else cp->yvel=0;
X} else
X{
Xif (cp->xpos!=cp->channel[x].enemy->xpos)
X		{
X	if (cp->xpos<cp->channel[x].enemy->xpos) cp->xvel=1; else cp->xvel= -1;
X		} else cp->xvel=0;
Xif (cp->ypos!=cp->channel[x].enemy->ypos)
X		{
X	if (cp->ypos<cp->channel[x].enemy->ypos) cp->yvel=1; else cp->yvel= -1;
X		} else cp->yvel=0;
X}
X
X/* arrival at location*/
Xif ((cp->xvel==0)&&(cp->yvel==0))
X	{
X	plotstatus(cp,3);
X	cp->flyto= -1;
X	plot1(cp," Sulu : We have arrived at the programmed location Sir.  ");
X	plot2(cp,"                                                         ");
X	}
X}
X
END_OF_FILE
if test 3194 -ne `wc -c <'auto.c'`; then
    echo shar: \"'auto.c'\" unpacked with wrong size!
fi
# end of 'auto.c'
fi
if test -f 'collision.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'collision.c'\"
else
echo shar: Extracting \"'collision.c'\" \(3656 characters\)
sed "s/^X//" >'collision.c' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X#include "header.h"
X
Xcollision(cp,c)
Xregister struct player *cp;
Xchar c;
X{
X/*check for any collisions*/
Xswitch (c)
X	{
X	
Xcase '@' :
X	{
X	plot1(cp,"You were sucked into a black hole and whirled out again. ");
X	plot2(cp,"This means your weapons have been damaged.   Better dock!");
X	cp->phaserbanks=0;
X	cp->photontorpedos=0;
X	plotphaserbanks(cp);
X	plotphotontorpedos(cp);
X	if (cp->stat!=5) plotstatus(cp,4);
X	break;
X	}
Xcase 'O' :
X	{
X	plot1(cp,"   You  crashed  into  a planet.  Oh  dear,  Oh  dear,   ");
X	plot2(cp,"   The crater you left was 12 miles wide. Your'e Dead!   ");
X	if (cp->reason>0) cp->reason= -1;
X	finish(cp);
X	break;
X	}
Xcase '.' :
X	{
X	cp->maxenergy -= 30;
X	cp->energy -= 30;
X	plotenergy(cp);
X	plotmaxenergy(cp);
X	plot1(cp,"    You collided with a star. Warp capability has been   ");
X	plot2(cp,"    reduced by 30, and your  energy  is  30 lower now.   ");
X	if (cp->stat!=5) plotstatus(cp,4);
X	break;
X	}
Xcase 'k' :
X	{
X	cp->maxenergy -= 100;
X	cp->energy -= 100;
X	plotenergy(cp);
X	plotmaxenergy(cp);
X	plot1(cp,"    You collided with a klingon mevisic mine...          ");
X	plot2(cp,"    Energy and Maxenergy have dropped by 100.            ");
X	if (cp->stat!=5) plotstatus(cp,4);
X	break;
X	}
Xcase '#' :
X	{
X	cp->maxenergy -= 400;
X	cp->energy -= 400;
X	plotenergy(cp);
X	plotmaxenergy(cp);
X	plot1(cp,"    You collided with a Romulan Warning buoy.            ");
X	plot2(cp,"    Energy and Maxenergy have dropped by 400.            ");
X	if (cp->stat!=5) plotstatus(cp,4);
X	break;
X	}
Xcase 'o' :
X	{
X	if (cp->doneit==1) 
X	{
X	plot1(cp,"    You CANNOT try that again you moron!!! That would    ");
X	plot2(cp,"    allow anyone to get any score.....bye bye........    ");
X	if (cp->reason>0) cp->reason= -5;
X	finish(cp);
X	break;
X	} else
X	{
X	cp->maxvel+=1;
X	cp->score+=100;
X	plotscore(cp);
X	cp->maxphaser += 10;
X	cp->maxphoton += 10;
X	cp->photonpower +=20;
X	cp->phaserpower += 20;
X	cp->phaserreach +=5;
X	cp->photonreach +=5;
X	plotphaserbanks(cp);
X	plotphotontorpedos(cp);
X	cp->doneit=1;
X	cp->maxenergy += 110;
X	cp->energy += 110;
X	plotenergy(cp);
X	plotmaxenergy(cp);
X	plot1(cp," You fell through a time warp.  Just look what this has  ");
X	plot2(cp," done to your ship. You obviously went into the future!! ");
X	break;
X	}
X	}
Xdefault : break;
X	}
X}
X
Xfinish(x)
Xregister struct player *x;
X{
Xstruct player *r;
X
Xif (x->stat<12)
X	{
X	x->chflg=FLAG;
X	fire_torpedo(x,'1',1);
X	fire_torpedo(x,'2',1);
X	fire_torpedo(x,'3',1);
X	fire_torpedo(x,'4',1);
X	fire_torpedo(x,'8',1);
X	fire_torpedo(x,'6',1);
X	fire_torpedo(x,'7',1);
X	fire_torpedo(x,'9',1);
X	plotstatus(x,12);
X	x->messindex= -1;
X	}
Xif (x->id!=ROMID && x->id!=KLINGID)
X	{
X	beep(x);
X	beep(x);
X	}
X}
X
Xwhich_sector(x,y,xv,yv)
Xint x,y,xv,yv;
X{
X	x+=xv;
X	x+=xv;
X	y+=yv;
X	y+=yv;
X	if ((x<58)||(x>899)||(y<19)||(y>899)) return(0);
X	if ((x>450)&&(x<899))
X		{
X		if ((y<450)&&(y>19)) return(4);
X		else 
X		if ((y>450)&&(y<899)) return(2);
X		}
X	if ((x<450)&&(x>58))
X		{
X		if ((y>450)&&(y<899)) return(1);
X		else 
X		if ((y<450)&&(y>19)) return(3);
X		}
X}
X
END_OF_FILE
if test 3656 -ne `wc -c <'collision.c'`; then
    echo shar: \"'collision.c'\" unpacked with wrong size!
fi
# end of 'collision.c'
fi
if test -f 'dock.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dock.c'\"
else
echo shar: Extracting \"'dock.c'\" \(2328 characters\)
sed "s/^X//" >'dock.c' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
X#include "header.h"
X
Xdock(cp)
Xregister struct player *cp;
X{
Xint dockingok;
X
Xdockingok=OFF;
Xi=cp->xpos;
Xj=cp->ypos;
Xif ((inuniv(i,j)=='*') && ((cp->xvel==0) && (cp->yvel==0)))
X		dockingok=ON;
Xif (dockingok==OFF)
X	{
X	plot1(cp,"   Your'e not beside a federation starbase Captain.      ");
X	plot2(cp,"                                                         ");
X	} else
X	{
X	if ((cp->cloakingdevice)||(cp->shields))
X		{
X		if (cp->shields)
X		{
X	plot1(cp,"                                                         ");
X	plot2(cp,"   While you have your shields are up? Youre kidding!    ");
X		}
X		else
X		{
X	plot1(cp,"                                                         ");
X	plot2(cp,"          While you are cloaked? -come off it!           ");
X		} 
X	} else
X		{
X		plot1(cp,"               Docking procedure completed.              ");
X		plot2(cp,"         Weapons and Crystal Units recharged Captain.    ");
X		plotstatus(cp,7);
X
X		if (cp->maxenergy>=STARTENERGY)
X			cp->energy=cp->maxenergy;
X			else
X			{
X			cp->energy=STARTENERGY;
X			cp->maxenergy=STARTENERGY;
X			}
X		cp->phaserbanks=cp->maxphaser;
X		cp->photontorpedos=cp->maxphoton;
X		plotenergy(cp);
X		plotmaxenergy(cp);
X		plotphaserbanks(cp);
X		plotphotontorpedos(cp);
X		}
X	}
X}
X
Xundock(cp)
Xregister struct player *cp;
X{
Xif ((cp->stat==7) && (cp->xvel==0) && (cp->yvel==0)) 
X{
Xplot1(cp," Un-docking successful Captain. No casualties this time. ");
Xplot2(cp,"                   Your'e improving...                   ");
Xplotstatus(cp,3);
X} else
X{
Xplot1(cp,"Tell me :- How can you un-dock when your'e not docked??? ");
Xplot2(cp,"                                                         ");
X}
X}
X
X
END_OF_FILE
if test 2328 -ne `wc -c <'dock.c'`; then
    echo shar: \"'dock.c'\" unpacked with wrong size!
fi
# end of 'dock.c'
fi
if test -f 'files.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'files.h'\"
else
echo shar: Extracting \"'files.h'\" \(1126 characters\)
sed "s/^X//" >'files.h' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
X
X#define SLAVEPROGRAM "/usr/games/mpsslib/slave"
X#define MASTERPROGRAM "/usr/games/mpsslib/startrek"
X
X#define PLAYERFILE "/usr/games/mpsslib/player"
X#define MASTERPIDFILE "/usr/games/mpsslib/masterpid"
X#define LOCK "/usr/games/mpsslib/lock"
X#define SHIPNOFILE "/usr/games/mpsslib/shipnumber"
X#define SCOREFILE "/usr/games/mpsslib/score"
X#define PLAYERSCOREFILE "/usr/games/mpsslib/playerscore"
X#define MAILFILE "/usr/games/mpsslib/mpssmail"
X
END_OF_FILE
if test 1126 -ne `wc -c <'files.h'`; then
    echo shar: \"'files.h'\" unpacked with wrong size!
fi
# end of 'files.h'
fi
if test -f 'header.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'header.h'\"
else
echo shar: Extracting \"'header.h'\" \(3100 characters\)
sed "s/^X//" >'header.h' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
X
X#include <stdio.h>
X#include <sys/ioctl.h>
X#include <sgtty.h>
X#include <signal.h>
X
X#define STARTENERGY 500 
X#define STARTPHASER 15
X#define STARTPHOTON 10
X#define WEAPONREACH 6
X#define PHOTONPOWER 60
X#define PHASERPOWER 40
X#define MAXWARP 1
X#define FLAG 2 
X#define ON 1
X#define OFF 0
X#define ROMID 'R'
X#define KLINGID 'K'
X#define MAXALIENS 3
X
X
Xstruct sgttyb params;
X
Xchar *tgoto();
Xchar *tgetstr();
Xextern char *BC;
Xextern char *UP;
Xchar bp[1024];
Xchar tbp[1024];
Xchar *termp;
X
X/*variables for unbuffered input&output*/
X#define BUFSIZE 512
Xlong noofchars;
X/*variables for unbuffered input&output*/
X
X/*variables for universe array*/
Xstruct thing  {
X		int x;
X		char c;
X		struct thing *next_thing;
X	      };
X
Xstruct thing *univ[918],*xp;
X/*variables for universe array*/
X
X/*variables for the torpedos*/
Xstruct torpedo {
X		char weapon;
X		int life;
X		int xpos;
X		int ypos;
X		int oldxpos;
X		int oldypos;
X		int xvel;
X		int yvel;
X		struct player *whofrom;
X		struct torpedo *next;
X	       };
X
Xstruct torpedo *tstartlist,*ttaillist,*txp,*ta;
X/*variables for the torpedos*/
X
X/*variables for a player*/
Xstruct player {
X	int reason;
X	char id; /*playing id*/
X	char buf[BUFSIZE]; /*persons input buffer*/
X	char message[57]; /*to radio others!*/
X	int messindex;
X	int buftop,bufptr; /*pointers to buffer for that person*/
X	char terminalfile[14];
X	char cm[20];
X	char cl[20];
X	int tty_type;
X	int shipno;
X	int fd; /*file descriptor to the tty file */
X	/*horizontal size of window, IT MUST BE AN ODD NO!*/
X	int pid; /*pid of process to be killed if this guy leaves the game*/
X	/* plus all the other stuff a player needs!!! */
X	int oldxpos;
X	int oldypos;
X	int xpos;
X	int ypos;
X	int xvel;
X	int yvel;
X	int maxvel;
X	int energy;
X	int maxenergy;
X	int cloakingdevice;
X	int beeping;
X	int phaserbanks;
X	int maxphaser;
X	int photontorpedos;
X	int maxphoton;
X	int photonreach;
X	int photonpower;
X	int phaserreach;
X	int phaserpower;
X	int weaponselect; /*0=phaser, 1=photon*/
X	int score;
X	int shields;
X	int oldstat;
X	int stat;
X	int chflg;
X	int clflg;
X	struct lock_on
X		{
X		struct player *enemy;
X		int xloc;
X		int yloc;
X		} channel[4];
X	int flyto;
X	int planets[30];
X	int planetno;
X	int doneit;
X	int impulsemove;
X	struct player *next;
X	};
X
X	struct player *player,*startlist,*taillist;
X
Xint players[10];
X/*variables for a player*/
Xint debug;
Xint noofaliens,noofsignals,noofplayers;
X
X/*global general usage variables*/
X
Xint v,i,j,z,r,k,l,x,y,storm;
Xchar c;
X
END_OF_FILE
if test 3100 -ne `wc -c <'header.h'`; then
    echo shar: \"'header.h'\" unpacked with wrong size!
fi
# end of 'header.h'
fi
if test -f 'keyscan.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'keyscan.c'\"
else
echo shar: Extracting \"'keyscan.c'\" \(1263 characters\)
sed "s/^X//" >'keyscan.c' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X#include "header.h"
X
X/*******************USEFUL ROUTINES FOR LOW LEVEL I/O**************************/
X
Xgetbuf(cp,ptrnoofchars)
Xregister struct player *cp;
Xlong *ptrnoofchars;
X{
Xif (*ptrnoofchars>0)
X{
X/* get buffer from terminal */
Xread(cp->fd,cp->buf,*ptrnoofchars);
Xcp->buftop=(int)(*ptrnoofchars);
Xcp->bufptr=0;
X} 
X}
X
Xflushbuf(cp)
Xregister struct player *cp;
X{
Xcp->buf[0]='\0';
Xcp->buftop=0;
Xcp->bufptr=0;
X}
X
Xgetchr(cp)
Xregister struct player *cp;
X{
Xif (cp->bufptr==cp->buftop) /*is buffer empty?*/
X	{	
X	flushbuf(cp); 
X	return('\0');
X	} else
X	return(cp->buf[cp->bufptr++]);
X}
X
X
END_OF_FILE
if test 1263 -ne `wc -c <'keyscan.c'`; then
    echo shar: \"'keyscan.c'\" unpacked with wrong size!
fi
# end of 'keyscan.c'
fi
if test -f 'makefile.dist' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'makefile.dist'\"
else
echo shar: Extracting \"'makefile.dist'\" \(1919 characters\)
sed "s/^X//" >'makefile.dist' <<'END_OF_FILE'
Xall:	mpss slave startrek mpssclean
X
Xstartrek:	ships.h planets.h header.h files.h aliens.o ships.o planets.o scan.o cross.o torpedo.o consoleplots.o cursor.o auto.o dock.o orbit.o keyscan.o main.o newplayer.o processinput.o collision.o setupuniverse.o
X	cc -O aliens.o ships.o planets.o scan.o cross.o torpedo.o consoleplots.o cursor.o auto.o dock.o orbit.o keyscan.o main.o newplayer.o processinput.o collision.o setupuniverse.o -o startrek -ltermcap -lm
X
Xslave:	ships.h files.h cursor.o ships.o slave.o
X	cc -O cursor.o ships.o slave.o -o slave -ltermcap  
X
Xmpss: files.h mpss.o
X	cc -O mpss.o -o mpss
X
Xmpss.o: files.h mpss.c
X	cc -O -c mpss.c
X
Xmpssclean : files.h mpssclean.o
X	cc -O mpssclean.o -o mpssclean
X
Xmpssclean.o:  files.h mpssclean.c
X	      cc -O -c mpssclean.c
X
Xslave.o:  ships.h files.h slave.c
X	      cc -O -c slave.c -ltermcap
X
Xcollision.o:  header.h collision.c
X	      cc -O -c collision.c 
X
Xcross.o:  header.h cross.c
X	      cc -O -c cross.c 
X
Xconsoleplots.o:  header.h consoleplots.c
X	      cc -O -c consoleplots.c 
X
Xtorpedo.o:  header.h torpedo.c
X	      cc -O -c torpedo.c 
X
Xcursor.o:  header.h cursor.c
X	      cc -O -c cursor.c -ltermcap 
X
Xauto.o:  header.h auto.c
X	      cc -O -c auto.c 
X
Xdock.o:  header.h dock.c
X	      cc -O -c dock.c 
X
Xorbit.o:  planets.h header.h orbit.c
X	      cc -O -c orbit.c 
X
Xkeyscan.o:  header.h keyscan.c
X	      cc -O -c keyscan.c 
X
Xmain.o:  header.h files.h main.c
X	      cc -O -c main.c 
X
Xnewplayer.o:  ships.h header.h files.h newplayer.c
X	      cc -O -c newplayer.c 
X
Xaliens.o:  ships.h header.h aliens.c
X	      cc -O -c aliens.c 
X
Xprocessinput.o: ships.h header.h processinput.c
X	      cc -O -c processinput.c 
X
Xscan.o:  ships.h header.h scan.c
X	      cc -O -c scan.c 
X
Xships.o:  ships.h ships.c
X	      cc -O -c ships.c 
X
Xplanets.o:  planets.h planets.c
X	      cc -O -c planets.c 
X
Xsetupuniverse.o:  planets.h header.h setupuniverse.c
X	      cc -O -c setupuniverse.c 
X
END_OF_FILE
if test 1919 -ne `wc -c <'makefile.dist'`; then
    echo shar: \"'makefile.dist'\" unpacked with wrong size!
fi
# end of 'makefile.dist'
fi
if test -f 'mpssclean.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mpssclean.c'\"
else
echo shar: Extracting \"'mpssclean.c'\" \(548 characters\)
sed "s/^X//" >'mpssclean.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include "files.h"
X#include <signal.h>
X
X
Xmain()
X{
Xint rpid;
Xchar string[15];
Xchar remove[80];
XFILE *f, *fopen();
X
Xsprintf(remove,"rm %s\n",PLAYERFILE);
Xsystem(remove);
Xsprintf(remove,"rm %s\n",LOCK);
Xsystem(remove);
Xsprintf(remove,"rm %s\n",PLAYERSCOREFILE);
Xsystem(remove);
Xsystem("stty -cbreak echo");
Xif ((f=fopen(MASTERPIDFILE,"r"))!=NULL) 
X	{
X	fgets(string,15,f); /*get pid*/
X	sscanf(string,"%d\n",&rpid);
X	kill(rpid,9);
X	fprintf(stdout,"killed\n");
X	fclose(f);
X	}
Xsprintf(remove,"rm %s\n",MASTERPIDFILE);
Xsystem(remove);
X}
END_OF_FILE
if test 548 -ne `wc -c <'mpssclean.c'`; then
    echo shar: \"'mpssclean.c'\" unpacked with wrong size!
fi
# end of 'mpssclean.c'
fi
if test -f 'mpssmail' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mpssmail'\"
else
echo shar: Extracting \"'mpssmail'\" \(0 characters\)
sed "s/^X//" >'mpssmail' <<'END_OF_FILE'
END_OF_FILE
if test 0 -ne `wc -c <'mpssmail'`; then
    echo shar: \"'mpssmail'\" unpacked with wrong size!
fi
chmod +x 'mpssmail'
# end of 'mpssmail'
fi
if test -f 'planets.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'planets.h'\"
else
echo shar: Extracting \"'planets.h'\" \(790 characters\)
sed "s/^X//" >'planets.h' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
Xstruct plans {
X		int planno;
X		int xpos;
X		int ypos;
X		char *orbit;
X		char *land[19];
X	       }  plan[];
X
END_OF_FILE
if test 790 -ne `wc -c <'planets.h'`; then
    echo shar: \"'planets.h'\" unpacked with wrong size!
fi
# end of 'planets.h'
fi
if test -f 'setupuniverse.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'setupuniverse.c'\"
else
echo shar: Extracting \"'setupuniverse.c'\" \(2254 characters\)
sed "s/^X//" >'setupuniverse.c' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
X
X#include "header.h"
X#include "planets.h"
X
X/*rand number between 0 and X*/
Xrnd(s,x) 
Xint s,x;
X{
Xint i;
X
Xdo
X{
Xi=(int)(abs(rand()%100));
X}
Xwhile ((i<s)||(i>x));
Xreturn(i);
X}
X
Xadd(xx,y,cc) 
X int xx,y;
X char cc;
X{
X 	char *malloc();
X	struct thing *a,*p,*r;
X
Xif (univ[y]==NULL)
X	{
X	univ[y]=(struct thing *)malloc(sizeof(struct thing));
X	univ[y]->x=xx;
X	univ[y]->c=cc;
X	univ[y]->next_thing=NULL;
X	} else
X	{
X	r=(struct thing *)malloc(sizeof(struct thing));
X	r->x=xx;
X	r->c=cc;
X
X	a=univ[y]; p=a->next_thing;
X	while ((p!=NULL)&&(p->x<=xx)) 
X		{
X		a=p;
X		p=p->next_thing;
X		}
X	if ((a==univ[y])&&(a->x>xx))
X		{
X		univ[y]=r;
X		r->next_thing=a;
X		} else
X		{
X		a->next_thing=r;
X		r->next_thing=p;
X		}
X	}
X}
X
Xsetupuniverse()
X{
X
Xnewgame();
X
Xfor (i=0; i<10; ++i)
X	players[i]=0;
X
Xfor (i=0; i<918; ++i) 
X	{
X	univ[i]=NULL;
X	}
X
Xadd(225,225,'*');
Xadd(225,675,'*');
Xadd(675,225,'*');
Xadd(675,675,'*');
X
Xadd(680,680,'k');
Xadd(670,670,'k');
Xadd(564,662,'k');
Xadd(470,488,'k');
X
Xadd(498,199,'#');
Xadd(501,197,'#');
Xadd(504,199,'#');
Xadd(498,203,'#');
Xadd(501,205,'#');
Xadd(504,203,'#');
X
Xadd(501,201,'o');
X
X
X/*planets*/
X
Xfor (r=0; r<30; ++r)
X	{
X	/*draw a planet....*/
X	add(plan[r].xpos,plan[r].ypos,'O');
X	}
X
X/*set up stars*/
Xfor (x=100; x<770; x+=60)
X	{
X	for (y=100; y<770; y+=25)
X	{
X		do
X		{
X			i=rnd(0,10);
X			j=rnd(0,15);
X		}
X		while (!(inuniv(x+i,y+j)==NULL));
X	k=rnd(0,100);
X	if (k<50) 
X		add(x+i,y+j,'.'); else
X		add(x+i,y+j,'@');
X	}
X	}
X}
X
Xinuniv(xx,y) 
Xint xx,y;
X{
Xregister struct thing *p;
X
Xp=univ[y];
X
Xwhile (p!=NULL)
X	{
X	if (p->x==xx) return(p->c);
X	p=p->next_thing;
X	}
X
Xreturn(NULL);
X}
X
END_OF_FILE
if test 2254 -ne `wc -c <'setupuniverse.c'`; then
    echo shar: \"'setupuniverse.c'\" unpacked with wrong size!
fi
# end of 'setupuniverse.c'
fi
if test -f 'ships.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ships.h'\"
else
echo shar: Extracting \"'ships.h'\" \(844 characters\)
sed "s/^X//" >'ships.h' <<'END_OF_FILE'
X
X/*******************************************************************************
X********************************************************************************
X********************************************************************************
X
XPERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
XTHIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
X
X		P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
X
X
X********************************************************************************
X********************************************************************************
X*******************************************************************************/
Xstruct ships {
X		char *name;
X		char *registration;
X		char *class; 
X		char *flag;
X		char *noofcrew;
X		char *prefixcode;
X		char *commissiondate;
X	     }  ship[];
X
END_OF_FILE
if test 844 -ne `wc -c <'ships.h'`; then
    echo shar: \"'ships.h'\" unpacked with wrong size!
fi
# end of 'ships.h'
fi
echo shar: End of archive 4 \(of 4\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 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