xref: /csrg-svn/games/trek/main.c (revision 42606)
125993Smckusick /*
225993Smckusick  * Copyright (c) 1980 Regents of the University of California.
334205Sbostic  * All rights reserved.
434205Sbostic  *
5*42606Sbostic  * %sccs.include.redist.c%
625993Smckusick  */
725993Smckusick 
811683Smckusick #ifndef lint
925993Smckusick char copyright[] =
1025993Smckusick "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1125993Smckusick  All rights reserved.\n";
1234205Sbostic #endif /* not lint */
1311683Smckusick 
1425993Smckusick #ifndef lint
15*42606Sbostic static char sccsid[] = "@(#)main.c	5.5 (Berkeley) 06/01/90";
1634205Sbostic #endif /* not lint */
1725993Smckusick 
1811683Smckusick # include	"trek.h"
1912738Slayer # include	<stdio.h>
2012738Slayer # include	<sgtty.h>
2112738Slayer # define	PRIO		00	/* default priority */
2211683Smckusick 
2312738Slayer int	Mother	= 51 + (51 << 8);
2411683Smckusick 
2511683Smckusick /*
2611683Smckusick **	 ####  #####    #    ####          #####  ####   #####  #   #
2711683Smckusick **	#        #     # #   #   #           #    #   #  #      #  #
2811683Smckusick **	 ###     #    #####  ####            #    ####   ###    ###
2911683Smckusick **	    #    #    #   #  #  #            #    #  #   #      #  #
3011683Smckusick **	####     #    #   #  #   #           #    #   #  #####  #   #
3111683Smckusick **
3211683Smckusick **	C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
3311683Smckusick **		from Jeff Poskanzer and Pete Rubinstein.
3411683Smckusick **
3511683Smckusick **	I also want to thank everyone here at Berkeley who
3611683Smckusick **	where crazy enough to play the undebugged game.  I want to
3711683Smckusick **	particularly thank Nick Whyte, who made considerable
3811683Smckusick **	suggestions regarding the content of the game.  Why, I'll
3911683Smckusick **	never forget the time he suggested the name for the
4011683Smckusick **	"capture" command.
4111683Smckusick **
4211683Smckusick **	Please send comments, questions, and suggestions about this
4311683Smckusick **		game to:
4411683Smckusick **			Eric P. Allman
4511683Smckusick **			Project INGRES
4611683Smckusick **			Electronics Research Laboratory
4711683Smckusick **			Cory Hall
4811683Smckusick **			University of California
4911683Smckusick **			Berkeley, California  94720
5011683Smckusick **
5111683Smckusick **	If you make ANY changes in the game, I sure would like to
5211683Smckusick **	know about them.  It is sort of an ongoing project for me,
5311683Smckusick **	and I very much want to put in any bug fixes and improvements
5411683Smckusick **	that you might come up with.
5511683Smckusick **
5611683Smckusick **	FORTRASH version by Kay R. Fisher (DEC) "and countless others".
5711683Smckusick **	That was adapted from the "original BASIC program" (ha!) by
5811683Smckusick **		Mike Mayfield (Centerline Engineering).
5911683Smckusick **
6011683Smckusick **	Additional inspiration taken from FORTRAN version by
6111683Smckusick **		David Matuszek and Paul Reynolds which runs on the CDC
6211683Smckusick **		7600 at Lawrence Berkeley Lab, maintained there by
6311683Smckusick **		Andy Davidson.  This version is also available at LLL
6411683Smckusick **		and at LMSC.  In all fairness, this version was the
6511683Smckusick **		major inspiration for this version of the game (trans-
6611683Smckusick **		lation:  I ripped off a whole lot of code).
6711683Smckusick **
6811683Smckusick **	Minor other input from the "Battelle Version 7A" by Joe Miller
6911683Smckusick **		(Graphics Systems Group, Battelle-Columbus Labs) and
7011683Smckusick **		Ross Pavlac (Systems Programmer, Battelle Memorial
7111683Smckusick **		Institute).  That version was written in December '74
7211683Smckusick **		and extensively modified June '75.  It was adapted
7311683Smckusick **		from the FTN version by Ron Williams of CDC Sunnyvale,
7411683Smckusick **		which was adapted from the Basic version distributed
7511683Smckusick **		by DEC.  It also had "neat stuff swiped" from T. T.
7611683Smckusick **		Terry and Jim Korp (University of Texas), Hicks (Penn
7711683Smckusick **		U.), and Rick Maus (Georgia Tech).  Unfortunately, it
7811683Smckusick **		was not as readable as it could have been and so the
7911683Smckusick **		translation effort was severely hampered.  None the
8011683Smckusick **		less, I got the idea of inhabited starsystems from this
8111683Smckusick **		version.
8211683Smckusick **
8311683Smckusick **	Permission is given for use, copying, and modification of
8411683Smckusick **		all or part of this program and related documentation,
8511683Smckusick **		provided that all reference to the authors are maintained.
8611683Smckusick **
8711683Smckusick **
8811683Smckusick **********************************************************************
8911683Smckusick **
9011683Smckusick **  NOTES TO THE MAINTAINER:
9111683Smckusick **
9211683Smckusick **	There is a compilation option xTRACE which must be set for any
9311683Smckusick **	trace information to be generated.  It is probably defined in
9411683Smckusick **	the version that you get.  It can be removed, however, if you
9511683Smckusick **	have trouble finding room in core.
9611683Smckusick **
9711683Smckusick **	Many things in trek are not as clear as they might be, but are
9811683Smckusick **	done to reduce space.  I compile with the -f and -O flags.  I
9911683Smckusick **	am constrained to running with non-seperated I/D space, since
10012738Slayer **	we don't have doubleing point hardware here; even if we did, I
10111683Smckusick **	would like trek to be available to the large number of people
10211683Smckusick **	who either have an 11/40 or do not have FP hardware.  I also
10311683Smckusick **	found it desirable to make the code run reentrant, so this
10411683Smckusick **	added even more space constraints.
10511683Smckusick **
10611683Smckusick **	I use the portable C library to do my I/O.  This is done be-
10711683Smckusick **	cause I wanted the game easily transportable to other C
10812738Slayer **	implementations, and because I was too lazy to do the doubleing
10911683Smckusick **	point input myself.  Little did I know.  The portable C library
11011683Smckusick **	released by Bell Labs has more bugs than you would believe, so
11111683Smckusick **	I ended up rewriting the whole blessed thing.  Trek excercises
11211683Smckusick **	many of the bugs in it, as well as bugs in some of the section
11311683Smckusick **	III UNIX routines.  We have fixed them here.  One main problem
11411683Smckusick **	was a bug in alloc() that caused it to always ask for a large
11511683Smckusick **	hunk of memory, which worked fine unless you were almost out,
11611683Smckusick **	which I inevitably was.  If you want the code for all of this
11711683Smckusick **	stuff, it is also available through me.
11811683Smckusick **
11911683Smckusick ***********************************************************************
12011683Smckusick */
12111683Smckusick 
12211683Smckusick main(argc, argv)
12311683Smckusick int	argc;
12411683Smckusick char	**argv;
12511683Smckusick {
12612738Slayer 	long			vect;
12712738Slayer 	/* extern FILE		*f_log; */
12811683Smckusick 	register char		opencode;
12911683Smckusick 	int			prio;
13011683Smckusick 	register int		ac;
13111683Smckusick 	register char		**av;
13212738Slayer 	struct	sgttyb		argp;
13312738Slayer 	int			been_here = 0;
13411683Smckusick 
13511683Smckusick 	av = argv;
13611683Smckusick 	ac = argc;
13711683Smckusick 	av++;
13812738Slayer 	time(&vect);
13912738Slayer 	srand(vect);
14011683Smckusick 	opencode = 'w';
14111683Smckusick 	prio = PRIO;
14212738Slayer 	if (gtty(1, &argp) == 0)
14311683Smckusick 	{
14412738Slayer 		if ((argp.sg_ispeed ) < B1200)
14511683Smckusick 			Etc.fast++;
14611683Smckusick 	}
14711683Smckusick 	while (ac > 1 && av[0][0] == '-')
14811683Smckusick 	{
14911683Smckusick 		switch (av[0][1])
15011683Smckusick 		{
15111683Smckusick 		  case 'a':	/* append to log file */
15211683Smckusick 			opencode = 'a';
15311683Smckusick 			break;
15411683Smckusick 
15511683Smckusick 		  case 'f':	/* set fast mode */
15611683Smckusick 			Etc.fast++;
15711683Smckusick 			break;
15811683Smckusick 
15911683Smckusick 		  case 's':	/* set slow mode */
16011683Smckusick 			Etc.fast = 0;
16111683Smckusick 			break;
16211683Smckusick 
16311683Smckusick #		ifdef xTRACE
16411683Smckusick 		  case 't':	/* trace */
16511683Smckusick 			if (getuid() != Mother)
16611683Smckusick 				goto badflag;
16711683Smckusick 			Trace++;
16811683Smckusick 			break;
16911683Smckusick #		endif
17011683Smckusick 
17111683Smckusick 		  case 'p':	/* set priority */
17211683Smckusick 			if (getuid() != Mother)
17311683Smckusick 				goto badflag;
17411683Smckusick 			if (scanf(-1, &av[0][2], "%d", &prio) > 0)
17511683Smckusick 				break;
17611683Smckusick 
17711683Smckusick 		  default:
17811683Smckusick 		  badflag:
17911683Smckusick 			printf("Invalid option: %s\n", av[0]);
18011683Smckusick 
18111683Smckusick 		}
18211683Smckusick 		ac--;
18311683Smckusick 		av++;
18411683Smckusick 	}
18511683Smckusick 	if (ac > 2)
18611683Smckusick 		syserr(0, "arg count");
18712738Slayer 		/*
18811683Smckusick 	if (ac > 1)
18912738Slayer 		f_log = fopen(av[0], opencode);
19012738Slayer 		*/
19111683Smckusick 
19234591Sbostic 	printf("\n   * * *   S T A R   T R E K   * * *\n\nPress return to continue.\n");
19311683Smckusick 
19411683Smckusick 	setexit();
19512738Slayer 	if ( been_here == 1 )
19611683Smckusick 	{
19712738Slayer 		if ( !getynpar("Another game") )
19812738Slayer 			exit(0);
19912738Slayer 	}
20012738Slayer 	been_here = 1;
20112738Slayer 	do
20212738Slayer 	{
20311683Smckusick 		setup();
20411683Smckusick 		play();
20512738Slayer 	} while (getynpar("Another game"));
20612738Slayer 
20712738Slayer 	fflush(stdout);
20811683Smckusick }
209