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