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

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

Submitted by: Peer Schmitz <peer@cs.kl.ac.uk>
Comp.sources.games: Volume 5, Issue 8
Archive-name: mpss/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 4)."
# Contents:  Rules.ms cursor.c processinput.c slave.c
# Wrapped by billr@saab on Wed Jul 20 17:00:26 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Rules.ms' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Rules.ms'\"
else
echo shar: Extracting \"'Rules.ms'\" \(17509 characters\)
sed "s/^X//" >'Rules.ms' <<'END_OF_FILE'
XFrom @RELAY.CS.NET:mcvax!cs.kl.ac.uk!peer@uunet.uu.net Tue Jul 19 22:19:29 1988
XReceived: from tekred.CNA.TEK.COM by saab.CNA.TEK.COM (3.2/6.24)
X	id AA03363; Tue, 19 Jul 88 22:19:25 PDT
XReceived: by tekred.CNA.TEK.COM (5.51/6.24)
X	id AA20859; Tue, 19 Jul 88 22:14:45 PDT
XReceived: by tektronix.TEK.COM (5.51/6.24)
X	id AA28791; Tue, 19 Jul 88 22:15:03 PDT
XReceived: from relay.cs.net by RELAY.CS.NET id ae18314; 20 Jul 88 0:37 EDT
XReceived: from uunet.uu.net by RELAY.CS.NET id aa29075; 20 Jul 88 0:28 EDT
XReceived: from mcvax.UUCP by uunet.UU.NET (5.59/1.14) with UUCP 
X	id AA25713; Wed, 20 Jul 88 00:25:43 EDT
XReceived: by mcvax.cwi.nl; Wed, 20 Jul 88 05:39:51 +0200 (MET)
XReceived: from cs.kl.ac.uk by kestrel.Ukc.AC.UK   via Janet (UKC CAMEL FTP)
X           id aa03533; 19 Jul 88 15:26 BST
XFrom: Peer Schmitz <uunet.uu.net!mcvax!cs.kl.ac.uk!peer@tektronix>
XDate: Tue, 19 Jul 88 15:12:35 GMT
XMessage-Id: <13089.8807191512@derek.cs.kl.ac.uk>
XTo: games@tekred.CNA.TEK.com
XStatus: OR
X
X
XHello Bill.
XGlad you like the source. I trust you have made the correction in 
Xprocessinput.c at your end yourself. (I think this problem was only
Xdetectable on suns if I remember..) 
XI have made corrections here alright.
XSo. Here is the nroff source rules file.
X
XLive Long and Prosper.
X
XPeer.
X
X--------------------------CUT HERE----------------------------------------
X.ll 75
X.pl 2000
X.TH
X                  MULTI-PLAYER-STAR-TREK,
X.LP
X  written by Peer Schmitz, University of Keele, May 1988.
X.LP
XWelcome to the final frontier. Mpss is a multi player star trek, chase
Xadventure destroy game. Every terminal is one ships flight console.
XTo invoke mpss type '/usr/games/mpss'. If this fails to work, type '/usr/games/mpssclean', which will get rid of any loose files hanging around. If you try again, and it still
Xdoesnt work, tell peer. Note that 'mpssclean' kills off any game that
Xis currently in progress. Sometimes, two games are created at once, if two
Xplayers enter at exactly the same instant. If this happens, one player is not allowed into the game, and must simply try again. ('mpssclean' is NOT a remedy for this.)
XOnce invoked, you are 
Xallocated a ship and enter the game.
XIf you are the first player beginning a game, starting up can take
Xup to 1/2 minute. You will then see your console with various readouts
Xas well as a visual window which allows you to look into the universe.
XTyping 'H' or '?' displays a help screen.
XYour ship is in the middle of the cross displayed in the visual window.
XThe object of the game is to obtain the highest score by A) blasting
Xother players and B) exploring planets. If you get tired of the introduction,
Xtype "mpss -i". This will avoid it. 
X.SH
XSAY WHAT TYPE OF TERMINAL YOU HAVE!!! / THE -t OPTION.
X.LP
XTo be able to talk to your terminal, mpss finds what your TERM variable is set to. If this value is catered for by the program, execution proceeds. If this
Xvalue is not catered for by the program YOU WILL BE ASKED what kind of terminal
Xyou have. If your terminal is in the list, type which one you have and all is well. Now. If you do not know what terminal you have, type 0. This will make the
Xprogram search the /etc/termcap file for an entry of your terminal.
XOnly if this last resort fails (i.e. no entry is found in termcap), will you not be able to play.
XIn this case, you must modify the code so the program caters for your terminal,
Xand how this is done is described in the file INSTALLRULES.(see how to add
Xanother terminal.)
X.LP
XThis order of events was chosen because if you execute mpss with a terminal
Xthat the program knows about (i.e. NOT USING TERMCAP) execution speed is
Xmuch, much, faster. 
XIf you use the termcap facility the program will run SLOW and
Xwith 3 or more players it gets pretty boring. However, if you insist to use
Xtermcap, specify the -t option. The program always tells you when it uses /etc/termcap.
X.SH
XThe mail file.
X.LP
XIn the directory '~/mpsslib' is a file by the name of 'mpssmail'. This file
Xis executed whenever a new game starts. So, if you wish to be told whenever
Xa game starts, edit the file, and put in an entry like :
X"write <whatever your loginname is> Star Trek is starting!"
XMake sure not to delete other peoples entries, as this will upset real trekkies.
X.SH
XThe universe.
X.LP
XThe universe is two dimensional and spans from X coordinate approx.0-890, and
XY coordinate approx.0-890. If you try to leave the universe, you will bounce
Xoff the walls, and be sent flying in the opposite direction. Note that torpedos also bounce, so if you are near the edge, be careful not to shoot yourself.
XSeveral
Xdifferent objects exist in the universe.
X.DS L
X"K" - a KLINGON
X"R" - a ROMULAN
X"@" - a black hole. 
X"." - a star.       
X"*" - a starbase.
X"O" - a planet.
X"#" - a romulan warning buoy.
X"k" - a klingon mevisic mine.
X"o" - a plasmodic ustabitular time warp.
Xany other lower case letter - Another ship running with shields down.
Xany other upper case letter - The same ship running with shields up.
X.DE
X.LP
XThe universe is divided into four sectors, as shown below.
X.DS L
X-
X-
X-
X-
X-
X-
X-
X-
X-
X-
X-
X------------------------------------------------------------------------900
X|                                |                                     |
X|                                |                                     |
X|              *                 |                 *                   |
X|                                |                                     |
X|     Federation space.          |         Klingon Space.              |
X|                                |                                     |
X---------------------------------+--------------------------------------450
X|                                |                                     |
X|                                |                                     |
X|              *                 |                 *                   |
X|                                |                                     |
X|     Mutara Nebula Zone.        |         Neutral Zone.               |
X|                                |                                     |
X------------------------------------------------------------------------0
X0                               450                                   900
X.DE
X.LP
XIn the middle of each sector is a starbase. Starbases are fixed in their 
Xpositions in every game, and their positions are always the same. Every
Xgame has exactly 4 starbases. There are 40 planets which also have
Xfixed positions in every game. Black holes and stars are placed in random
Xpositions. At the start of each game, you are placed close to the federation
Xstarbase.
X.SH
XMOVING USING THE WARP DRIVE.
X.DS L
XUP is "k",
XDOWN is "j",
XLEFT is "h",
XRIGHT is "l".
XDIAGONAL MOVEMENTS are "y","u","b","n".
X.DE
X.LP
XBe careful. Typing "l" once, sends you travelling at warp 1 right.
XTo stop yourself you must press "h" once. Keeping a letter pressed down
Xwill result in accelerating. Hence to stop yourself flying right
Xat warp 5, you must press "h" five times. A quick way to stop, in whatever
Xdirection/speed youre flying is to press "s". That will stop you
Xinstantly. In the beginning of the game, your ship will only fly
XWARP 1. This will change as you find matter-antimatter boosters on planets.
X.SH
XMOVING USING THE MANOEVERING IMPULSE ENGINES.
X.DS L
XKeys : The same as for the WARP DRIVE but upper case, i.e. :
X
X"H","J","K","L","Y","U","B","N" .
X.DE
X.LP
XThe manoevering impulse thrusters are provided to manoever safely towards
Xobjects, for example a planet, without crashing into it. Pressing "H" once,
Xwill move you left by exactly one klick. Impulse thrusters can only be used
Xfrom a stationary position. Keeping your finger on the "H" key to cause a
Xrepeat function results in an "impulse engine overheat" and you will be
Xstopped dead in your tracks. Only once stopped can you move again. So,
Xflying with "repeat key function impulse drive" is not possible.
XNote that when orbiting a planet you must type "o" to orbit first.
XThis switches all engines off. To leave a planet you must invoke
Xthe aft impulse thrusters first. This is done by typing "i", andhas nothing to do with Manoevering impulse thrusters. After having pressed "i" to leave
Xorbit, you can WARP away, or use Manoevering Impulse thrusters to get away.
X.SH
XThe READOUTS.
X.LP
XQUAD- this shows your current Quadrant/ x,y position. To show position
Xtype "q". Usually, the position is NOT automatically updated. Only if
Xyou are flying through space and there is nothing to see on your screen,
Xis the position updated. "q" - This will always tell you the right position 
Xat any time.
X.LP
XWARP - This shows you x/y velocity. Warp is not automatically updated.
XTo show your warp type "w".
X.LP
XENERGY - This shows your energy. The energy is not automatically
Xupdated. To get an update type "e". HOWEVER-if you energy drops below 100,
Xthis is shown. (In which case its usually time to panic.)
X.LP
XMAXENERGY - This shows the maximum amount of energy you are alowed to 
Xhold at any time. This changes at various times throughout the game,
Xand IS automatically updated.
X.LP
XCLOAKING DEVICE - Use "c" to switch it on/off. If on, others will not
Xsee your ship, but you will use up more energy. You cannot cloak during
Xan ion storm,
Xwhile docked, in orbit, or while your'e in the Mutara Nebula.
XThis IS automatically updated.
X.LP
XSHIELDS - Use "v" to switch on/off. This will change your ship to
Xappear as an upper case letter to others. The advantage is that when attacked,
Xyou only get half the hammering otherwise incurred. If your energy drops
Xbelow 200 though, your shields collapse. (And then your'e in for it!!)
XShields are automatically updated. While your shields are up, you can not
Xbe scanned by other players. (See Scanning below.) Shields don't work
Xif your'e docked, in orbit or in the Mutara Nebula.
X.SH
XWEAPONS......
X.LP
XPhasers or Photon Torpedos are available. Torpedos are circa 50% more powerful.
XFor each weapon, its range (i.e. How far you can shoot) is shown. If the 
Xrange of phasers is say, 6, in any DIAGONAL direction it is only half that,
Xi.e. 3. MAX shows how many shots/torpedos you can hold. PHASERS/TORPS shows
Xhow many you still have left. An attribute of weapons not shown is their
XPOWER. This varies depending on skill. (It usually increases.) At the start
XPhaser power is 40, and torpedo power is 60. (These values are subtracted
Xfrom the energy of the ship that is hit. If shields are up, only half will
Ximpact.) All weapons statusses are automatically updated. The little
X"s" beside either Phasers or Torpedos shows which weapon is currently
Xselected. "p" is used to change the weapons. Phasers look like this :
X< > - | / \\. Photon torpedos look like this : + . Fireing does NOT
Xcost you energy. When something explodes beside you, it is possible
Xto be hit by debris which will damage your ship. Debris looks like
Xphaser shots. (Its usually the ammo chamber blowing up.)
XUse 1,2,3,4,6,7,8,9 to fire in the desired direction.
X.SH
XSTATUS AND SCORE.
X.LP
XSTATUS shows what youre doing at the moment. If a function, ex. SHIELDS
Xdoes not seem to work, LOOK AT STATUS. You are then probably not allowed
Xthat function in that status. Ex. Youre in orbit and wish to put on shields.
X.LP
XSCORE is updated as you go. Killing someone is worth 100 pts!!!.(plus
Xa pint of Romulan ale.) exploring a planet successfully is worth 10 pts, plus
Xany bonuses that particular planet can give you.
X.SH
XENERGY CONSUMPTION.
X.LP
XIf you stand still with cloaking devices and shields off you gain energy.
XIf you stand still with either cloaking devices or shields or both on,
Xyour energy stays the same. When moving at warp 1 with devices off your
Xenergy stays the same.
XWhen moving faster than warp 1 you loose energy. When moving faster than warp 1
Xwith devices on
Xyou loose even more energy. When zapping thru the galaxy at Warp 10,
Xcloaked and with shields up, youre dead!
XShooting does NOT cost energy.
X.SH 
XALIENS
X.LP
XRomulans (R) and Klingons (K) will be present ONLY if you are the
Xonly player in the game. Killed aliens will be reinstated somewhere
Xelse in the Universe. To avoid being attacked by aliens, RAISE SHIELDS.
XTo lure an alien to attack you, shoot anything that is in either the 
XKlingon sector or the Neutral Zone. You get 100 pts for killing
Xan alien. Do not mistake (R) and (K) for other players.
XRomulans, are rare, and more powerful when they get you.
X
X.SH
XSTARBASES AND DOCKING.
X.LP
XTo dock at a starbase you must be exactly over it. Then type "d".
XThis refills the ammo and energy. If MAXENERGY is smaller than 
X500, it is updated to
X500. If MAXENERGY is greater than 400, it is left alone. To leave a starbase,
Xtype "f" to FREE yourself. (i.e. undock.) When docked the other players
Xwill see the starbase, not you. You can fire when docked.
X.SH
XEXPLORING PLANETS AND MISSIONS.
X.LP
XThere are 30 planets in the game to explore. To orbit one you must
Xbe EXACTLY 2 places away from it. If you orbit to close, you bounce off the
Xatmosphere. To orbit type "o". Then, to beam doen type "z". Some
Xplanets are surrounded by energy shields which make it impossible to beam
Xdown until you have been to other planets. Once down on a planet,
Xyou will find things that can improve your ship, or give you tactical hints.
XPress "z" to beam up again, and "i" to invoke aft impulse thrusters
Xto leave orbit. You can fire when in orbit, but not when your'e on a  
Xplanets surface. All planet scenarios to do with star trek, have
Xsimilarities to the real episodes/films. Some planets have been
Xbrought in from other sci-fi movies/stories to add a bit of spice
Xto the game. There are several planet missions to complete, the largest one
Xof which is very rewarding.
X.SH
XSCANNING OTHERS.....
X.LP
XThe hyperventilated long range sound track scanners allow you to scan
Xother ships. To do that, type "S" and you are in scanning mode.
XThen type the lowercase letter of the ship you wish to scan, and the
Xscan will inform you about the position and status of other players.
XYou can only scan someone if their shields are down. Otherwise the
Xpulse waves are reflected. The only way to leave scan mode is 
Xto press "S" again. When scanning a ship, it tells you its PREFIX CODE.
XFor all those of you who have had the misfortune of not seeing STAR TREK
XII - The Wrath of Khan, if a FEDERATION ship receives its prefix code,
Xit will lower its shields and cloaking device automatically. To send a
Xprefix code type "P", the ships lowercase letter, and the 5 digit code, then
Xreturn. Hey presto, his shields will go down. Only federation vessels
Xhave a prefix code. Klingon/Romulan/shuttle vessels dont have one and
Xyou cannot lower their shields.
X.SH
XThe COM LINK.
X.LP
XTo send insulting messages to enemies Starfleet has provided a COM LINK.
XType "C", the lower case letter of the destination ship, and
Xa one line message and return. 
X.SH
XTractor beams.
X.LP
XWhen you are directly over an object you can press "t" followed by a 
Xnumber between 1-4. This will lock you on to the object. (perhaps a
Xplayer or a starbase.) If later you wish to return there type "a"
Xfor auto-pilot, and the tractor beam number. When locked on to a player,
Xthe auto pilot takes you to him whereever he is. "T" will show you what
Xyour tractor beams are currently locked on to. The auto-pilot always travels
Xat warp 1. To stop the auto-pilot, press any key. You can lock on to
Xany position in the universe. (i.e. you mustnt be over something.) The 
XAuto pilot also tells you what you have locked on to. The auto-pilot does
Xnot avoid obstacles, so be on the lookout for things like planets in your
Xpath.
X.SH
XOTHER COMMANDS
X.LP
XHELP - Press '?' to get the instant help sheet. 
X.LP
XWHO - press 'W'. Shows you who else is in the game. If others are running
Xwith shields up, they are displayed in uppercase characters.
X.LP
XREDRAW SCREEN - press 'R' to do that.
X.LP
XBEEPING ON/OFF - To switch beep on or off type 'G'.
X.LP
XQUIT - Type '+'. This will activate your ships self destruct mechanism, no questions asked.
X.SH
XION STORMS...
X.LP
XThese occur at random intervals. When up, Cloaking devices are
Xinoperative. You are not told, when an ion storm stops.
X.SH
XTHESE RULES..
X.LP
Xare all your'e gonna get. The rest is up to you and your experience.
Xif you want a quick reference sheet for the commands, print out these rules.
X(see below).
X.ce 2
XLIVE LONG AND PROSPER.
XP. Schmitz, May 1988.
X.SH
XSUMMARY OF KEYS......
X.DS L
X+  =>  Self destruct ship/Quit (AND THIS DOES NOT ASK IF YOU ARE SURE!),
XG  =>  beep on/off,
XR  =>  Redraw Screen
X
XWARP DRIVE :
Xh,j,k,l  =>  left,down,up,right,movements
Xy,u,b,n  =>  diagonal movements,
Xs  =>  full stop
X
XMANOEVERING IMPULSE THRUSTERS :
XH,J,K,L,Y,U,B,N => one klick at a time in the same direction as the WARP drive.
X
XAFT IMPULSE THRUSTERS :
Xo,i  =>  orbit/cancel orbit
X
Xd,f  =>  dock/undock,
Xz    =>  beamto/from planet,
X1,2,3,4,6,7,8,9  =>  fire weapon,
Xp  =>  weapon select
Xq  =>  show quadrant,
Xw  =>  show warp,
Xe  =>  show energy,
Xc  =>  cloaking device on/off,
Xv  =>  shields on/off
Xt<1,2,3,4>  =>  lock tractorbeam,
Xa<1,2,3,4>  =>  auto-pilot to beam
XT  =>  show tractorbeams
XW  =>  who is playing?,
XC<A>  =>  Comlink/send message,
XP<A>  =>  send Prefixcode
XS<A>  =>  Scanship on/off (This will show prefix codes.)
X ?    =>  the help function.
XKey to command notation:
X<1,2,3,4>  =>  a number between 1-4 inclusive,
X<A>  =>  a shipname in the form of a lowercase letter.
XNB:If a function doesn't seem to work,you cannot do it
Xwhile you are in that particular status.
X.DE
X
X
END_OF_FILE
if test 17509 -ne `wc -c <'Rules.ms'`; then
    echo shar: \"'Rules.ms'\" unpacked with wrong size!
fi
# end of 'Rules.ms'
fi
if test -f 'cursor.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cursor.c'\"
else
echo shar: Extracting \"'cursor.c'\" \(4171 characters\)
sed "s/^X//" >'cursor.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
X#define SPACE "                                                                                \n"
X
Xslaveoutc(c)
Xchar c;
X{
Xwrite(1,&c,1);
X}
X
Xoutc(c)
Xchar c;
X{
Xwrite(v,&c,1);
X}
X
Xgettermcapentry(cl,cm,bon,boff)
Xchar *cl,*cm,*bon,*boff;
X{
Xchar *CL,*CM,*BON,*BOFF;
X	switch(tgetent(bp,getenv("TERM")))
X	{
X	case -1 :
X		fprintf(stderr,"Cannot open your termcap file!!\n");
X		return(0);
X		break;
X	case 0 : 
X		fprintf(stderr,"Your terminal has no entry in /etc/termcap..sorry!!\n");
X		return(0);
X		break;
X	case 1 :
Xfprintf(stderr,"                 Found entry for automatic terminal option\n");
X		break;
X	default:
X		fprintf(stderr,"get_termcap_entry:Somethings wrong!!\n");
X		return(0);
X		break;
X	}
X
X	termp=tbp;
X	if ((CM=tgetstr("cm",&termp))==NULL) 
X			{
X			fprintf(stderr,"cm problems.\n");
X			return(0);
X			}
X
X	if ((CL=tgetstr("cl",&termp))==NULL) 
X			{
X			fprintf(stderr,"cl problems.\n");
X			return(0);
X			}
X
X	BON=tgetstr("md",&termp);
X
X	BOFF=tgetstr("me",&termp);
X	
X	strcpy(cl,CL);
X	strcpy(cm,CM);
X	strcpy(bon,BON);
X	strcpy(boff,BOFF);
X	return(1);
X}
X
X
Xassignterminal(tty_type,cl,cm)
Xint tty_type;
Xchar *cl,*cm;
X{
X	switch(tty_type)
X	{
X	case 1:
X		cm[0] = '\033';
X		cm[1] = 'Y';
X		cm[2] = 0+32;
X		cm[3] = 0+32;
X		cl[0] = '\033';
X		cl[1] = 'w';
X		break;
X	case 2: cm[0] = '\033';
X		cm[1] = '=';
X		cm[2] = 0+32;
X		cm[3] = 0+32;
X		cl[0] = '\033';
X		cl[1] = '*';
X		break;
X	 case 3:
X		cm[0]='\033';
X		cm[1]='[';
X		cm[2]='0';
X		cm[3]='0';
X		cm[4]=';';
X		cm[5]='0';
X		cm[6]='0';
X		cm[7]='H';
X		cl[0]='\033';
X		cl[1]='[';
X		cl[2]='2';
X		cl[3]='J';
X		break;
X	 case 4:
X		cm[0]='\033';
X		cm[1]='[';
X		cm[2]='0';
X		cm[3]='0';
X		cm[4]=';';
X		cm[5]='0';
X		cm[6]='0';
X		cm[7]='H';
X		cl[0]='N';
X		break;
X	  default:
X		break;
X	  }
X}
X
X/***************************************************************************
XPosition cursor routines!!!-> 1) VT200/ADDS 2)Televideo 910/905/ADM3 3) VT100
X4)SUN's
X****************************************************************************/
X
Xposcursslave(cm,tty_type,x,y)
Xchar *cm;
Xint tty_type,x,y;
X{
Xchar *b;
Xswitch(tty_type){
X case 0:
X	b=tgoto(cm,x,y);
X	tputs(b,1,slaveoutc);
X	break;	
X case 1:
X	cm[2]=y+32;
X	cm[3]=x+32;
X	write(1,cm,4);
X	break;
X  case 2:
X	cm[2] = y+32;
X	cm[3] = x+32;
X	write(1,cm,4);
X	break;
X  case 3:
X  case 4:
X	++y;
X	cm[5]=x/10+'0';
X	cm[6]=x%10+'0';
X	cm[2]=y/10+'0';
X	cm[3]=y%10+'0';
X	write(1,cm,10);
X	break;
X  default:
X	break;
X  }
X}
X
Xposcurs(cp,x,y)
Xregister struct player *cp;
Xregister int x,y;
X{
Xchar *b;
Xswitch(cp->tty_type){
X	
X case 0:
X	v=cp->fd;
X	b=tgoto(cp->cm,x,y);
X	tputs(b,1,outc);
X	break;
X case 1:
X	cp->cm[2]=y+32;
X	cp->cm[3]=x+32;
X	write(cp->fd,cp->cm,4);
X	break;
X  case 2:
X	cp->cm[2] = y+32;
X	cp->cm[3] = x+32;
X	write(cp->fd,cp->cm,4);
X	break;
X  case 3:
X  case 4:
X	++y;
X	cp->cm[5]=x/10+'0';
X	cp->cm[6]=x%10+'0';
X	cp->cm[2]=y/10+'0';
X	cp->cm[3]=y%10+'0';
X	write(cp->fd,cp->cm,10);
X	break;
X  default:
X	break;
X  }
X}
X
Xnewgame()
X{
Xsrand((time(0)%10));
X}
X/*
X *beep() Routine to emit a beep
X */
X
Xbeep(cp)
Xregister struct player *cp;
X{
X if (cp->beeping) 
X 	write(cp->fd,"\7",1);
X}
X
X
X
X/*
X*to clear the screen
X*/
Xclrscreen(cp)
Xregister struct player *cp;
X{
X
Xif (cp->tty_type==0)
X	{
X	v=cp->fd;
X	tputs(cp->cl,1,outc);
X	}
X	else
X{
Xif (cp->cl[0]=='N')
X	{
X	for(i=0;i<25;++i) write(cp->fd,SPACE,81); 
X	} else
X	write(cp->fd,cp->cl,10);
X}
X}
X
Xclrscreenslave(cl,tty_type)
Xchar *cl;
Xint tty_type;
X{
X
Xif (tty_type==0)
X	tputs(cl,1,slaveoutc);
X	else
X	{
X	if (cl[0]=='N')
X		{
X		for(i=0;i<27;++i) write(1,SPACE,81); 
X		} else
X		write(1,cl,10);
X	}
X}
X
END_OF_FILE
if test 4171 -ne `wc -c <'cursor.c'`; then
    echo shar: \"'cursor.c'\" unpacked with wrong size!
fi
# end of 'cursor.c'
fi
if test -f 'processinput.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'processinput.c'\"
else
echo shar: Extracting \"'processinput.c'\" \(16396 characters\)
sed "s/^X//" >'processinput.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 "ships.h"
X
Xprocessinput(cp,ptrnoofchars)
Xregister struct player *cp;
Xlong *ptrnoofchars;
X{
Xregister struct player *x,*o;
Xint z;
Xunsigned char c;	/* override "char c" in header.h  -- br */
X
Xgetbuf(cp,ptrnoofchars);
Xwhile ((c=getchr(cp))!='\0')
X{
X	if (c=='+')
X		  {
X	plot1(cp,"Self Destruct Activated!!!!!!!!!!!!! Abandon Ship........");
X	plot2(cp,"Abandon Ship..Abandon Ship..Abandon Ship...........Aaargh");
X		  if (cp->reason>0) cp->reason= -3;
X		  finish(cp);
X		  continue;
X		  }
X	if (c=='G')
X		  { if (cp->beeping) 
X			{
X			cp->beeping=OFF;
Xplot1(cp,"                  Beep switched off.                     ");
Xplot2(cp,"                                                         ");
X			}
X			else 	
X			{
X			cp->beeping=ON;
Xplot1(cp,"                  Beep switched on.                      ");
Xplot2(cp,"                                                         ");
X			beep(cp);
X			}
X		   continue;
X		   }
Xif (((c=='?'))&&(cp->stat!=0)&&(cp->stat!=1)&&(cp->stat!=6)&&(cp->stat<9)&&(cp->stat!=5))
X		{
X		cp->xvel=0;
X		cp->yvel=0;
X		cp->oldstat=cp->stat;
X		plotstatus(cp,11);
X		display_sheet(cp);
X		continue;
X		}
X
X
Xif ((cp->stat==11)||(cp->stat==10))
X		{
X		drawcross(cp);
X		if (cp->stat==10) {
X					updateship(cp);
X					cp->score+=10;
X					plotscore(cp);
X				}
X		plotstatus(cp,cp->oldstat);
X		continue;
X		}
X
Xif (cp->stat==1)
X	{
X	if ((c!='\n') && (cp->messindex<6))
X		{
X		cp->message[cp->messindex]=c;
X		poscurs(cp,(69+cp->messindex),22);
X		write(cp->fd,&c,1);
X		++(cp->messindex);
X		continue;
X		}
X		else
X		{
X		c=cp->message[0];
X		if (c==ROMID || c==(ROMID+32))
X			{
X	plot1(cp,"       Since when do Romulan ships have prefix codes?    ");
X	plot2(cp,"                                                         ");
X			plotstatus(cp,cp->oldstat);
X			continue;
X			}
X		if (c==KLINGID || c==(KLINGID+32))
X			{
X	plot1(cp,"       Since when do Klingon ships have prefix codes?    ");
X	plot2(cp,"                                                         ");
X			plotstatus(cp,cp->oldstat);
X			continue;
X			}
X		x=startlist;
X		o=NULL;
X		while (x!=NULL) 
X		{
X		if ((c==x->id)||(c==(char)(x->id+32)))
X				{
X				o=x;
X				x=NULL;
X				} else
X				x=x->next;
X		}
X		if (o==NULL)
X			{
X	plot1(cp,"       Uhura : Unknown destination ship sir.             ");
X	plot2(cp,"       (The player probably died recently.)              ");
X			plotstatus(cp,cp->oldstat);
X			continue;
X			} else
X		{
X		j=1;
X		for (i=0;i<5;++i)
X		if (cp->message[j]!=ship[o->shipno].prefixcode[i]) j=15; 
X								else ++j;
X		if ((o->shipno)>24) {i=15; j=15;}
X		if (j==15)
X		{
X	if (i!=15)
X	{
X	plot1(cp,"        Uhura : That prefix code didn't work sir.        ");
X	plot2(cp,"        We must have the wrong combination......         ");
X	} else
X	{
X	plot1(cp,"      Spock : We cannot lower the shields of this        ");
X	plot2(cp,"    alien vessel, as it does not have a prefix code.     ");  
X	}
X			plotstatus(cp,cp->oldstat);
X			continue;
X		} else
X		{
X	plot1(cp,"       Uhura : prefix code sent sir.                     ");
X	plot2(cp,"       Spock : It seems to work sir.                     "); 
X	plot1(o,"Spock : Our shields and cloaking device are dropping.... ");
X	plot2(o,"   It looks like our ship received its prefix code!      "); 
X		o->cloakingdevice=OFF;
X		o->shields=OFF;
X		if (o->id<72) o->id=(char)(o->id+32);
X		plotshields(o);
X		plotcloakingdevice(o);
X		if (o->stat<12) o->chflg=FLAG;
X		plotstatus(cp,cp->oldstat);
X		continue;
X		}
X	     }
X	}
X}
X
Xif (cp->stat==0)
X	{
X	if ((c!='\n') && (cp->messindex<57))
X		{
X		cp->message[cp->messindex]=c;
X		poscurs(cp,(20+cp->messindex),22);
X		write(cp->fd,&c,1);
X		++(cp->messindex);
X		continue;
X		}
X		else
X		{
X		c=cp->message[0];
X	if ((c==(ROMID+32))||(c==(KLINGID+32))||(c==ROMID)||(c==KLINGID))
X			{
X	plot1(cp,"     Uhura : I cannot contact enemy captain.             ");
X	plot2(cp,"     They are jamming all frequencies.......             ");
X			plotstatus(cp,cp->oldstat);
X			continue;
X			}
X		x=startlist;
X		o=NULL;
X		while (x!=NULL) 
X		{
X		if ((c==x->id)||(c==(char)(x->id+32)))
X				{
X				o=x;
X				x=NULL;
X				} else
X				x=x->next;
X		}
X		if (o==NULL)
X			{
X	plot1(cp,"       Uhura : Unknown destination ship sir.             ");
X	plot2(cp,"       (The player probably died recently.)              ");
X			plotstatus(cp,cp->oldstat);
X			continue;
X			} else
X		{
X	plot1(cp,"             Uhura : Message sent sir.                   ");
X	plot2(cp,"                                                         ");
X	plot1(o," Uhura : Message from the                                ");
X	poscurs(o,46,21);
X	write(o->fd,ship[cp->shipno].name,27);
X	poscurs(o,70,21);
X	write(o->fd,"(",1);
X	c=cp->id;
X	if ((c>=65)&&(c<=90)) c+=32;
X	poscurs(o,71,21);
X	write(o->fd,&c,1);
X	poscurs(o,72,21);
X	write(o->fd,")",1);
X	cp->message[0]=' ';
X	plot2(o,cp->message);
X	plotstatus(cp,cp->oldstat);
X	continue;
X		}
X	}
X}
X		
Xif (cp->stat==9)
X	{
X	if (c=='S') {drawcross(cp); plotstatus(cp,cp->oldstat); continue;}
X	if ((c>=97)&&(c<=128)) 
X	{
X	o=NULL;
X	x=startlist;
X	while (x!=NULL)
X	{
X	if ((c==x->id)||(c==((char)(x->id)+32)))
X		{
X		o=x;
X		x=NULL;
X		} else x=x->next;
X	}
X	if (o==NULL)
X		{
X	plot1(cp,"       There is no such ship in scanning range.          ");
X	plot2(cp,"       Scan cancelled. Use 'S' to abort Scan.            ");
X		continue;
X		} else
X	{
X	if ((o->id!=ROMID)&&(o->id!=KLINGID)&&(o->shields))
X		{
X	plot1(cp,"       We cannot scan through another ships shields.     ");
X	plot2(cp,"           Scan cancelled. Use 'S' to abort Scan.        ");
X		}
X		else scan(cp,o);
X	}
X	}
X	}
Xif (cp->stat==6)
X	{
X	switch (c)
X	{
X	case '1':lock_on(cp,0); break;
X	case '2':lock_on(cp,1); break;
X	case '3':lock_on(cp,2); break;
X	case '4':lock_on(cp,3); break;
X	default:
X	plot1(cp,"            Invalid tractor beam number!                 ");
X	plot2(cp,"                                                         ");
X	break;
X	}
X	plotstatus(cp,3);
X	continue;
X	}
X
Xif (cp->stat==5)
X	{
X	cp->flyto= -1;
X	switch (c) {
X	case '1' : cp->flyto=0; break;
X	case '2' : cp->flyto=1; break;
X	case '3' : cp->flyto=2; break;
X	case '4' : cp->flyto=3; break;
X	default :
X		{
Xplot1(cp,"                    Invalid Channel number.              ");
Xplot2(cp,"                    Auto-Pilot Cancelled.                ");
X		cp->xvel=0;
X		cp->yvel=0;
X		cp->flyto= -1;
X		plotvelocity(cp);
X		plotstatus(cp,3);
X		break;
X		}
X		}
Xz=cp->flyto;
Xif ((z>=0)&&(z<=3)&&(cp->channel[z].xloc==0)&&(cp->channel[z].yloc==0)&&(cp->channel[z].enemy==NULL))
X		{
Xplot1(cp,"                 That beam  isn't programmed.            ");
Xplot2(cp,"                    Auto-Pilot Cancelled.                ");
X		cp->xvel=0;
X		cp->yvel=0;
X		cp->flyto= -1;
X		plotvelocity(cp);
X		plotstatus(cp,3);
X		}
X	continue;
X	}
X
X
Xif(((cp->stat>1)&&(cp->stat<5))||(cp->stat==7)||(cp->stat==8))
X	{
X	switch (c) {
X	case 'l':if (cp->stat>6) {move_message(cp); break;} 
X		++(cp->xvel); if (cp->stat<12) cp->chflg=FLAG; 
X		checkvelocity(cp); 
X		break;
X	case 'k':if (cp->stat>6) {move_message(cp); break;} 
X		++(cp->yvel); if (cp->stat<12) cp->chflg=FLAG; 
X		checkvelocity(cp); 
X		break;
X	case 'j':if (cp->stat>6) {move_message(cp); break;} 
X		--(cp->yvel); if (cp->stat<12) cp->chflg=FLAG; 
X		checkvelocity(cp); break;
X	case 'h':if (cp->stat>6) {move_message(cp); break;} 
X		--(cp->xvel); if (cp->stat<12) cp->chflg=FLAG; 
X		checkvelocity(cp); break;
X	case 'y':if (cp->stat>6) {move_message(cp); break;} 
X		--(cp->xvel); ++(cp->yvel); if (cp->stat<12) 
X		cp->chflg=FLAG; checkvelocity(cp);  break;
X	case 'b':if (cp->stat>6) {move_message(cp); break;} 
X		--(cp->xvel); --(cp->yvel); if (cp->stat<12) 
X		cp->chflg=FLAG; checkvelocity(cp);  break;
X	case 'n':if (cp->stat>6) {move_message(cp); break;} 
X		++(cp->xvel); --(cp->yvel); if (cp->stat<12) 
X		cp->chflg=FLAG; checkvelocity(cp);  break;
X	case 'u':if (cp->stat>6) {move_message(cp); break;} 
X		++(cp->xvel); ++(cp->yvel); if (cp->stat<12) 
X		cp->chflg=FLAG; checkvelocity(cp);  break;
X	case 's':if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel=0; cp->yvel=0; if (cp->stat<12) 
X		cp->chflg=FLAG; checkvelocity(cp); 
X		plotvelocity(cp); break;
X	case 'L':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel=1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'H':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel= -1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'J':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->yvel= -1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'K':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->yvel=1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'Y':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel= -1; 
X		cp->yvel= 1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'U':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel=1; 
X		cp->yvel=1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'B':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel= -1; 
X		cp->yvel= -1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'N':
X		if (cp->xvel!=0 || cp->yvel!=0) {impulse_message(cp); break;}
X		if (cp->stat>6) {move_message(cp); break;} 
X		cp->xvel= 1; 
X		cp->yvel= -1; 
X		cp->impulsemove=1;
X		if (cp->stat<12) cp->chflg=FLAG; 
X		break;
X	case 'p': if (cp->weaponselect==0)
X	{
X			cp->weaponselect=1;
X	plot1(cp,"                                                         ");
X	plot2(cp,"           Photon Torpedos ready Captain!!               ");
X	}
X			else
X	{
X			cp->weaponselect=0;
X	plot1(cp,"           Locking Phasers Captain!                      ");
X	plot2(cp,"                                                         ");
X	}
X		  plotphaserbanks(cp);
X		  plotphotontorpedos(cp);
X		  break;
X        case 'D': if (debug) debug=OFF; else debug=ON;
X		  break;
X	case 'c': { if (cp->cloakingdevice)
X			{
X			cp->cloakingdevice=OFF;
X			}
X			else
X			{
X			if ((which_sector(cp->xpos,cp->ypos,cp->xvel,cp->yvel)==3))
X			{
X	plot1(cp,"           You are in the Mutara Nebula!!                ");
X	plot2(cp,"          Cloaking  Device is inoperative!               ");
X			} else
X			{
X			if (storm)
X			{
X	plot1(cp,"           That ion storm is still out there.            ");
X	plot2(cp,"           We cannot cloak while it's around.            ");
X			} else
X			{
X			if (cp->stat<7)
X				{
X				cp->cloakingdevice=ON;
X				cp->clflg=ON;
X				}
X			}
X			}
X			}
X			if (cp->stat<12) cp->chflg=FLAG;
X		   	plotcloakingdevice(cp);
X		   break;
X		   }
X	case 'z':
X		if (cp->stat==8) { beamdown(cp); } else
X		{
X	plot1(cp,"           We are not in orbit !!                        ");
X	plot2(cp,"                                                         ");
X		}
X		break;
X	case 'v': { if (cp->shields)
X			{
X			cp->shields=OFF;
X			cp->id=(char)(cp->id+32);
X			}
X			else
X			{
X			if ((which_sector(cp->xpos,cp->ypos,cp->xvel,cp->yvel)==3))
X			{
X	plot1(cp,"           You are in the Mutara Nebula!!                ");
X	plot2(cp,"              Shields are inoperative!                   ");
X			} else
X			{
X			if (cp->stat<7)
X				{
X				cp->shields=ON;
X				cp->id=(char)(cp->id-32);
X				}
X			}
X			}
X			if (cp->stat<12) cp->chflg=FLAG;
X		   	plotshields(cp);
X		   break;
X		   }
X	case 'W': {
X			x=startlist;
X	plot1(cp,"Starfleet says that the following ships exist as well :  ");
X	plot2(cp,"                                                         ");
X			poscurs(cp,30,22);
X			while (x!=NULL)
X				{
X				if (x==cp) { x=x->next; continue;}
X				write(cp->fd,&(x->id),1);
X				write(cp->fd,"  ",2);
X				x=x->next;
X				}
X		  break;
X		  }
X	case 'q': plotposition(cp);
X		  break;
X	case 'a': 
X		 if (cp->stat>6) {move_message(cp); break;}
X		  plotstatus(cp,5);
X		  cp->xvel=0;
X		  cp->yvel=0;
X	plot1(cp,"               Where to? (1,2,3 or 4)                    ");
X	plot2(cp,"                                                         ");
X		  displaybeams(cp);
X		  plotvelocity(cp);
X		  break;
X	case 't': if ((cp->stat==7)||(cp->stat==8))
X			{
X			lockmessage(cp);
X			break;
X			} else
X			plotstatus(cp,6); 
X	plot1(cp,"   Which tractor beam? (1,2,3 or 4) Currently they are : ");
X	plot2(cp,"                                                         ");
X		  displaybeams(cp);
X		  break;
X	case 'T': 
X	plot1(cp,"Tractor beams are currently locked on to the following : ");
X	plot2(cp,"                                                         ");
X		  displaybeams(cp);
X		  break;
X	case 'P':
X		cp->oldstat=cp->stat;
X		plotstatus(cp,1);
X	plot1(cp,"To transmit enemy prefix code type the ships letter      ");
X	plot2(cp,"followed by the 5 digit prefix code and return :         ");
X	for (i=0;i<57;++i)
X		cp->message[i]=' ';
X		cp->messindex=0;
X		break;
X	case 'C':
X		cp->oldstat=cp->stat;
X		plotstatus(cp,0);
X	plot1(cp,"Uhura :Type ship letter & 56 chars (max) message & return");
X	plot2(cp,"                                                         ");
X	for (i=0;i<57;++i)
X		cp->message[i]=' ';
X		cp->messindex=0;
X		break;
X	case 'w': plotvelocity(cp);
X		  break;
X	case 'e': plotenergy(cp);
X		  break;
X	case 'd': if (cp->stat!=7) dock(cp);
X		  break;
X	case 'f': undock(cp);
X		  break;
X	case 'S': 
X		  cp->xvel=0; cp->yvel=0;
X		  cp->oldstat=cp->stat;
X		  plotstatus(cp,9); 
Xplot1(cp,"               Which Ship ?                              ");
Xplot2(cp,"                                                         ");
X		  break;
X	case 'o': orbit(cp);
X		  break;
X	case 'i': unorbit(cp);
X		  break;
X	case 'R': cp->oldstat=cp->stat;
X		  redrawconsole(cp);
X		  plotstatus(cp,cp->oldstat);
X		  break;
X	case '1': fire_torpedo(cp,c,0); break;
X	case '4': fire_torpedo(cp,c,0); break;
X	case '7': fire_torpedo(cp,c,0); break;
X	case '8': fire_torpedo(cp,c,0); break;
X	case '9': fire_torpedo(cp,c,0); break;
X	case '6': fire_torpedo(cp,c,0); break;
X	case '3': fire_torpedo(cp,c,0); break;
X	case '2': fire_torpedo(cp,c,0); break;
X	default : 
X		{	
Xplot1(cp,"            That key isn't in use!                       ");
Xplot2(cp,"                                                         ");
X		beep(cp); break;
X		}
X	} /*switch*/
X	} /*if - then*/
X} /*while loop*/
X}
X
Xmove_message(cp)
Xregister struct player *cp;
X{
X   if (cp->stat==7)
X	{
X		plotvelocity(cp);
X		plot1(cp,"   You can't move when you're docked captain! Press      ");
X		plot2(cp,"   f to undock. Will you ever get the hang of this?      ");
X	}
X   if (cp->stat==8)
X	{
X		plotvelocity(cp);
X		plot1(cp,"  You can't leave orbit just like that. We need reverse  ");
X		plot2(cp," impulse thrusters to get out. Press 'i' to kill  orbit. ");
X	}
X}
X
Ximpulse_message(cp)
Xregister struct player *cp;
X{
X		plotvelocity(cp);
X		plot1(cp,"   Manoevering Impulse Thrusters only function from      ");
X		plot2(cp,"   a stationary position..thrusters are overheated.      ");
X}
X
Xlockmessage(cp)
Xregister struct player *cp;
X{
X		plot1(cp,"You can't lock tractor beams when you're docked or in    ");
X		plot2(cp,"    orbit. Will you ever get the hang of this?           ");
X}
X
Xcheckvelocity(cp)
Xregister struct player *cp;
X{
Xif ((abs(cp->xvel)>cp->maxvel)||(abs(cp->yvel)>cp->maxvel))
X	{
X		plot1(cp,"  Scott to Captain: The dilithium crystals are melting!  ");
X		plot2(cp,"       I canna make 'er go faster than that Captain.     ");
X		if (abs(cp->xvel)>cp->maxvel)
X			{
X			if (cp->xvel<0) ++(cp->xvel); else --(cp->xvel);
X			} else
X			{
X			if (cp->yvel<0) ++(cp->yvel); else --(cp->yvel);
X			}
X	}
X}
END_OF_FILE
if test 16396 -ne `wc -c <'processinput.c'`; then
    echo shar: \"'processinput.c'\" unpacked with wrong size!
fi
# end of 'processinput.c'
fi
if test -f 'slave.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'slave.c'\"
else
echo shar: Extracting \"'slave.c'\" \(13242 characters\)
sed "s/^X//" >'slave.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 "files.h"
X#include "ships.h"
X#include <stdio.h>
X#include <signal.h>
X#include <sgtty.h>
X
X#define ON 1
X#define OFF 0
X
XFILE *f, *fopen();
X/*variables for extracting termcap info*/
Xchar cm[20];
Xchar cl[20];
Xchar bon[20];
Xchar boff[20];
Xint shipnumber,x,y,tty_type;
Xint nointro, termcap;
Xstruct sgttyb params;
Xchar masterpidname[15];
Xchar *tnam;
Xint statflg;
Xint fd,pid,masterpid,status; 
Xchar terminalfile[14];
Xextern char *ttyname();
Xextern void slaveoutc();
Xchar *p;
Xstruct scores {
X		int reason;
X		int sno;
X		char name[10];
X		int score;
X	      } sb[50];
X 
Xreadinscores()
X{
Xint reason,score,i;
Xchar string[50];
Xchar *getpwuid(), *getlogin();
Xchar c;
X
Xif ((f=fopen(PLAYERSCOREFILE,"r"))!=NULL)
X	{
X		fgets(string,50,f);
X        	sscanf(string,"%d %d\n",&reason,&score);
X		fclose(f);
X	sleep(3);
X	clrscreenslave(cl,tty_type);
X	} else
X	{
X	sleep(3);
X	clrscreenslave(cl,tty_type);
X	fprintf(stdout,"Two games were created at once. Please try again. That should work.\n");
X	return(0);
X	}
X
Xfor (i=0;i<50;++i)
X	{
X	sb[i].reason=0;
X	sb[i].sno=0;
X	for (y=0;y<10;y++)
X	    sb[i].name[y]=' ';
X	sb[i].score=0;
X	}
X
Xif ((f=fopen(SCOREFILE,"r"))!=NULL)
X	{
X	for (i=0;i<50;++i)
X		{
X		fgets(string,50,f);
X        	sscanf(string,"%d %d %s %d\n",&sb[i].sno,&sb[i].reason,sb[i].name,&sb[i].score);
X		}
X	fclose(f);
X	}
Xi=0;
Xwhile ((i<50)&&(score<=sb[i].score)) ++i;
X
Xif (i>=50)
X	{
X	fprintf(stdout,"\nYou did so badly, that you didn't even make the scoreboard!\n");
X	unlink(PLAYERSCOREFILE);
X	return(0);
X	}
X
Xx=48;
Xwhile(x>(i-1))
X	{
X	sb[x+1].score=sb[x].score;
X	sb[x+1].sno=sb[x].sno;
X	sb[x+1].reason=sb[x].reason;
X	for (y=0;y<10;y++)
X		sb[x+1].name[y]=sb[x].name[y];
X	x--;
X	}
X	
Xsb[i].reason=reason;
Xsb[i].score=score;
Xfor (y=0;y<10;y++)
X	sb[i].name[y]=' ';
X
X	if ((p=getlogin())==NULL)/*can we get it from /etc/utmp?*/
X	{
X	if ((p=getpwuid(getuid()))==NULL)/*can we get it from /etc/utmp?*/
X		{
X		  write(2, "Can't find your logname.  Who Are You?\n",39);
X		  unlink(PLAYERSCOREFILE);
X		  return(0);
X		}
X	}
X
Xstrcpy(sb[i].name,p);
Xsb[i].sno=shipnumber;
X/*write out scoreboard*/
Xunlink(SCOREFILE);
Xx=creat(SCOREFILE,0666);
Xif ((f=fopen(SCOREFILE,"w"))!=NULL)
X	{
X	for (x=0;x<50;++x)
X		{
X        	sprintf(string,"%d %d %s %d\n",sb[x].sno,sb[x].reason,sb[x].name,sb[x].score);
X		fputs(string,f);
X		}
X	fclose(f);
X	}
Xunlink(PLAYERSCOREFILE);
X
X/*display scores*/
Xfprintf(stdout,"\n");
Xtputs(bon,1,slaveoutc);
Xfprintf(stdout,"*****************************************************************************\n");
Xfprintf(stdout,"*                MULTI-PLAYER-STAR-TREK's ALL TIME HIGHS                    *\n");
Xfprintf(stdout,"*****************************************************************************\n");
Xtputs(boff,1,slaveoutc);
Xfprintf(stdout,"*Position Name     Ships name          Cause of Death                 Score *\n");
Xfprintf(stdout,"*****************************************************************************\n");
Xy=i+6;
Xfor (x=(i-6); x<y; ++x)
X	{
X	if (x>49) break;
X	if (x<0) {y++; 
X		continue;
X		}
X	if (x==i)
X	{
X	tputs(bon,1,slaveoutc);
Xfprintf(stdout,"*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\n");
X	}
X	sprintf(string,"* %2d      ",(x+1));
X	write(0,string,10);
X	if (sb[x].reason==0)
X	{
X	write(0,"JT Kirk  ",9);
X	} else
X	{
X	write(0,sb[x].name,10);
X	}
X	write(0,ship[sb[x].sno].name,20);
X	switch (sb[x].reason)
X	{	
X	case -1:
X		write(0,"Rammed the ship into a planet",29);
X		break;
X	case -2:
X		write(0,"Ran out of energy in flight!!",29);
X		break;
X	case -3:
X		write(0,"activated Selfdestruct & quit",29);
X		break;
X	case -4:
X		write(0,"Blew up under heavy attack...",29);
X		break;
X	case -5:
X		write(0,"Tried time warping twice.....",29);
X		break;
X	default:
X		write(0,"Burnt up over Genesis........",29);
X		break;
X	}
X	fprintf(stdout," %6d *\n",sb[x].score);
X	if (x==i)
X	{
Xfprintf(stdout,"*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\n");
X	tputs(boff,1,slaveoutc);
X	}
X	}
Xfprintf(stdout,"*****************************************************************************\n");
X}
X
Xdie()
X{
X	readinscores();
X	fprintf(stdout,"                       Live long and Prosper!\n");
X	unsetrawmode();
X	exit(0);
X}
X
X
X/*
X *	setrawmode()	Function to set cbreak -echo for the terminal
X */
X
Xsetrawmode()
X	{
X	ioctl(0,TIOCGETP,&params); /*get terminal sgttyb structure*/
X	params.sg_flags |= CBREAK;
X	params.sg_flags &= ~ECHO;
X	ioctl(0,TIOCSETP,&params); /*write out sgttyb structure*/
X	signal(SIGINT, SIG_IGN);
X	signal(SIGHUP, SIG_IGN);
X	}
X
X/*
X *	unsetrawmode()	Function to set -cbreak echo for the terminal
X */
X
Xunsetrawmode()
X	{
X	ioctl(0,TIOCGETP,&params); /*get terminal sgttyb structure*/
X	params.sg_flags &= ~CBREAK;
X	params.sg_flags |= ECHO;
X	ioctl(0,TIOCSETP,&params); /*write out sgttyb structure*/
X	signal(SIGINT, SIG_DFL);
X	signal(SIGHUP, SIG_DFL);
X	}
X
Xgettermdata()
X{
Xchar *u;
Xchar *getenv();
X	
X	if((u=getenv("TERM"))==NULL) goto label1;
X	if (strcmp(u,"vt200")==0) tty_type=1;
X	if (strcmp(u,"a980")==0) tty_type=1;
X	if (strcmp(u,"tvi910")==0) tty_type=2;
X	if (strcmp(u,"tvi905")==0) tty_type=2;
X	if (strcmp(u,"adm3")==0) tty_type=2;
X	if (strcmp(u,"vt100")==0) tty_type=3;
X	if (strcmp(u,"sun")==0) tty_type=4;
X
Xlabel1:
X
X	while ((tty_type<0) || (tty_type>4))
X	{
X	fprintf(stdout,"                 ******************************************\n");
X	fprintf(stdout,"                 *PLEASE   SPECIFY   YOUR  TERMINAL  TYPE!*\n");
X	fprintf(stdout,"                 ******************************************\n");
X	fprintf(stdout,"                 *1 for vt200/adds Terminals..............*\n");
X	fprintf(stdout,"                 *2 for Televideo 910's/905's & adm3......*\n");
X	fprintf(stdout,"                 *3 for vt100.............................*\n");
X	fprintf(stdout,"                 *4 for Sun Workstations..................*\n");
X	fprintf(stdout,"                 *0 NONE OF THE ABOVE / DONT KNOW.........*\n");
X	fprintf(stdout,"                 *Input value now. If in doubt type 0.....*\n");
X	fprintf(stdout,"                 ******************************************\n");
X	fprintf(stdout,"                                  Input:");
X	scanf("%d",&tty_type);
X	if ((tty_type<0) || (tty_type>4))
X	{
X	fprintf(stdout,"\n\n                 ******************************************\n");
X	fprintf(stdout,"                 * INVALID TERMINAL...TRY AGAIN PLASE.    *\n");
X	fprintf(stdout,"                 ******************************************\n\n");
X	}
X	}
X	if (tty_type==0) 
X		{
X		if (gettermcapentry(cl,cm,bon,boff)!=1)
X				{
Xif(!termcap)
X{
Xfprintf(stderr,"This means you will haveto modify the code of the program to cater for\n");
Xfprintf(stderr,"your specific terminal. Otherwise you cannot play.\n");
X}
Xelse
X{
Xfprintf(stderr,"Try again without the -t option. If you get the same result,\n");
Xfprintf(stderr,"you must modify the code. (See rules)\n");
X}
X				exit(0);
X				}
X		} else
X		{
X		assignterminal(tty_type,cl,cm);
X		return(1);
X		}
X}
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
Xchar string[80];
Xint childpid,i;
Xchar *s;
Xchar c;
X	nointro=0; termcap=0;
X	while(--argc>0 && (*++argv)[0]=='-')
X		for (s=argv[0]+1; *s!='\0'; s++)
X			switch (*s) {
X			case 'i':
X				nointro=1;
X				break;
X			case 't':
X				termcap=1;
X				break;
X			default :
X			fprintf(stderr,"Usage: mpss {-i} {-t}\n");
X			exit(0);
X			}
X			
X
X	tnam=ttyname(1);
X	strcpy(terminalfile,tnam);
X	
X	tty_type=999;
X	if ((termcap)&&(gettermcapentry(cl,cm,bon,boff)==1))
X				{
X				tty_type=0;
X				} else
X				{
X				tty_type=999;
X				gettermdata();
X				}
X	setrawmode();
X
X	srand(time()%10);
X	sleep(rand()%10);
X	
X	while ((f=fopen(LOCK,"r"))!=NULL) 
X	{ 
X	fclose(f); 
X	fprintf(stdout,"                 Your'e in the queue to join. Please wait..\n");
X	sleep(rand()%10);
X	}
X
X	if ((i=creat(LOCK,0666))<0)
X		fprintf(stdout,"                  Cant create LOCK file.\n");
X	
X	statflg=OFF;
X	/*CHECK IF THE MASTER IS ALREADY RUNNING!!!*/
X	if ((f=fopen(MASTERPIDFILE,"r"))==NULL)
X	{
X	/*tell others the game is starting......*/
X	char run[80];
X	sprintf(run,"%s",MAILFILE);
X	system(run);
X	/*tell others the game is starting......*/
X	clrscreenslave(cl,tty_type);
X	
X	fprintf(stdout,"                 Invoking the game for the first player....\n");
X	fprintf(stdout,"                 This takes about 30 seconds...............\n");
X	if ((pid=fork())==0) {
X		execl(MASTERPROGRAM,"peer",">&!/dev/null","&",(char *) 0);
X		fprintf(stderr,"cannot invoke master process!");
X				exit();
X			     } 
X	statflg=ON;
X	i=0;
X	while ((i<20)&&(f=fopen(MASTERPIDFILE,"r"))==NULL)
X		{
X		fprintf(stdout,"                          Wait a bit longer.......\n");
X		sleep(5);
X		i++;
X		}
X	if (i==20) {
X		fprintf(stdout,"                          mpss : timed out waiting.\n");
X		 unlink(LOCK);
X		 exit(0);
X		}
X	} 
X	fgets(masterpidname,15,f);
X	fclose(f);
X	sscanf(masterpidname,"%d\n",&masterpid);
X	for (i=0;i<15;++i) masterpidname[i]='\0';
X	if ((f=fopen(SHIPNOFILE,"r"))==NULL)
X		{
X		i=creat(SHIPNOFILE,0666);
X		close(i);
X		f=fopen(SHIPNOFILE,"w");
X		sprintf(masterpidname,"%d\n",0);
X		fputs(masterpidname,f);
X		shipnumber=0;
X		fclose(f);
X		}
X		else
X		{
X		fgets(masterpidname,15,f);
X		fclose(f);
X		sscanf(masterpidname,"%d\n",&shipnumber);
X		shipnumber++;
X		if (shipnumber>30) shipnumber=0;
X		f=fopen(SHIPNOFILE,"w");
X		sprintf(masterpidname,"%d\n",shipnumber);
X		fputs(masterpidname,f);
X		fclose(f);
X		 }
X	clrscreenslave(cl,tty_type);
X	if (nointro) goto nextlabel;
X	poscursslave(cm,tty_type,0,0);
X	tputs(bon,1,slaveoutc);
X	fprintf(stdout,"                  \n\n\n\n\n                                  Space.                           \n");
X	tputs(boff,1,slaveoutc);
X	sleep(3);
X	fprintf(stdout,"                            The final frontier.                  \n");
X	sleep(3);
X	fprintf(stdout,"              These are the voyages of the Starship  Enterprise,\n");
X	sleep(3);
X	fprintf(stdout,"              her ongoing mission to explore strange,new worlds.\n");
X	sleep(3);
X	fprintf(stdout,"              To seekout new lifeforms, and  new  civilizations,\n");
X	sleep(3);
X	fprintf(stdout,"              To boldly go where no man has gone................\n");
X	sleep(4);
X	fprintf(stdout,"                                before.....\n");
X	sleep(3);
X	poscursslave(cm,tty_type,0,0);
X	fprintf(stdout,"\n");
X	fprintf(stdout,"\n");
X	fprintf(stdout,"\n");
X	fprintf(stdout,"     *****************************************************************\n");
X	fprintf(stdout,"     *     Your     vessel    details     are     as     follows.    *\n");
X	fprintf(stdout,"     *****************************************************************\n");
X	fprintf(stdout,"     *    Ships   Name       : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].name);
X	fprintf(stdout,"     *   Ships Registration  : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].registration);
X	fprintf(stdout,"     *          Class        : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].class);
X	fprintf(stdout,"     *      Ships   origin   : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].flag);
X	fprintf(stdout,"     *      Number of crew   : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].noofcrew);
X	fprintf(stdout,"     *      Commision  date  : ");
X	fprintf(stdout," %s*\n",ship[shipnumber].commissiondate);
X	fprintf(stdout,"     *     Mission Objective :  Blast anything in sight.             *\n");
X	fprintf(stdout,"     *                                                               *\n");
X	fprintf(stdout,"     * Written by Peer Schmitz, University of Keele, Keele, Staffs,  *\n");
X	fprintf(stdout,"     * ST5-5BG, Jan. - Jul 88, due to a lack of STAR TREK on the box.*\n");
X	fprintf(stdout,"     *                       Version 1.3....                         *\n");
X	fprintf(stdout,"     *****************************************************************\n");
X	tputs(bon,1,slaveoutc);
X	fprintf(stdout,"\n                                Hit any key\n");
X	tputs(boff,1,slaveoutc);
X	read(0,&c,1);
Xnextlabel:
X	if ((pid=fork())==0)
X		{
X		childpid=getpid();
X		while ((f=fopen(PLAYERFILE,"r"))!=NULL)
X						{
X						fclose(f);
X						sleep(((int)(time()%10)));
X						}
X		/*Now we know the file isnt there yet*/
X		i=creat(PLAYERFILE,0666);
X		if ((f=fopen(PLAYERFILE,"w"))==NULL)
X			{
X			fprintf(stdout,"CANNOT OPEN PLAYERFILE\n");
X			exit(0);
X			} else
X			{
X			char c;
Xsprintf(string,"%s#%s#%s#%d#%d#%d#\n",terminalfile,cm,cl,shipnumber,childpid,tty_type);
X			fputs(string,f);
X			fclose(f);
X	/*
X	for (i=0;i<20;i++) fprintf(stderr,"*%c*",cm[i]); 
X	read(0,&c,1);
X	fprintf(stderr,"\n\n");
X	for (i=0;i<80;i++) fprintf(stderr,"*%c*",string[i]); 
X	read(0,&c,1);
X	*/
X			clrscreenslave(cl,tty_type);
X			kill(masterpid,29);
X			while(1);
X			}
X		}
Xwhile(wait(&status)!=pid);
Xdie();
X}
END_OF_FILE
if test 13242 -ne `wc -c <'slave.c'`; then
    echo shar: \"'slave.c'\" unpacked with wrong size!
fi
# end of 'slave.c'
fi
echo shar: End of archive 2 \(of 4\).
cp /dev/null ark2isdone
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