xref: /csrg-svn/games/trek/main.c (revision 11683)
1*11683Smckusick #ifndef lint
2*11683Smckusick static char sccsid[] = "@(#)main.c	4.1	(Berkeley)	03/23/83";
3*11683Smckusick #endif not lint
4*11683Smckusick 
5*11683Smckusick # include	"trek.h"
6*11683Smckusick # define	PRIO		10	/* default priority */
7*11683Smckusick 
8*11683Smckusick int	Mother	51 + (51 << 8);
9*11683Smckusick 
10*11683Smckusick /*
11*11683Smckusick **	 ####  #####    #    ####          #####  ####   #####  #   #
12*11683Smckusick **	#        #     # #   #   #           #    #   #  #      #  #
13*11683Smckusick **	 ###     #    #####  ####            #    ####   ###    ###
14*11683Smckusick **	    #    #    #   #  #  #            #    #  #   #      #  #
15*11683Smckusick **	####     #    #   #  #   #           #    #   #  #####  #   #
16*11683Smckusick **
17*11683Smckusick **	C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
18*11683Smckusick **		from Jeff Poskanzer and Pete Rubinstein.
19*11683Smckusick **
20*11683Smckusick **	I also want to thank everyone here at Berkeley who
21*11683Smckusick **	where crazy enough to play the undebugged game.  I want to
22*11683Smckusick **	particularly thank Nick Whyte, who made considerable
23*11683Smckusick **	suggestions regarding the content of the game.  Why, I'll
24*11683Smckusick **	never forget the time he suggested the name for the
25*11683Smckusick **	"capture" command.
26*11683Smckusick **
27*11683Smckusick **	Please send comments, questions, and suggestions about this
28*11683Smckusick **		game to:
29*11683Smckusick **			Eric P. Allman
30*11683Smckusick **			Project INGRES
31*11683Smckusick **			Electronics Research Laboratory
32*11683Smckusick **			Cory Hall
33*11683Smckusick **			University of California
34*11683Smckusick **			Berkeley, California  94720
35*11683Smckusick **
36*11683Smckusick **	If you make ANY changes in the game, I sure would like to
37*11683Smckusick **	know about them.  It is sort of an ongoing project for me,
38*11683Smckusick **	and I very much want to put in any bug fixes and improvements
39*11683Smckusick **	that you might come up with.
40*11683Smckusick **
41*11683Smckusick **	FORTRASH version by Kay R. Fisher (DEC) "and countless others".
42*11683Smckusick **	That was adapted from the "original BASIC program" (ha!) by
43*11683Smckusick **		Mike Mayfield (Centerline Engineering).
44*11683Smckusick **
45*11683Smckusick **	Additional inspiration taken from FORTRAN version by
46*11683Smckusick **		David Matuszek and Paul Reynolds which runs on the CDC
47*11683Smckusick **		7600 at Lawrence Berkeley Lab, maintained there by
48*11683Smckusick **		Andy Davidson.  This version is also available at LLL
49*11683Smckusick **		and at LMSC.  In all fairness, this version was the
50*11683Smckusick **		major inspiration for this version of the game (trans-
51*11683Smckusick **		lation:  I ripped off a whole lot of code).
52*11683Smckusick **
53*11683Smckusick **	Minor other input from the "Battelle Version 7A" by Joe Miller
54*11683Smckusick **		(Graphics Systems Group, Battelle-Columbus Labs) and
55*11683Smckusick **		Ross Pavlac (Systems Programmer, Battelle Memorial
56*11683Smckusick **		Institute).  That version was written in December '74
57*11683Smckusick **		and extensively modified June '75.  It was adapted
58*11683Smckusick **		from the FTN version by Ron Williams of CDC Sunnyvale,
59*11683Smckusick **		which was adapted from the Basic version distributed
60*11683Smckusick **		by DEC.  It also had "neat stuff swiped" from T. T.
61*11683Smckusick **		Terry and Jim Korp (University of Texas), Hicks (Penn
62*11683Smckusick **		U.), and Rick Maus (Georgia Tech).  Unfortunately, it
63*11683Smckusick **		was not as readable as it could have been and so the
64*11683Smckusick **		translation effort was severely hampered.  None the
65*11683Smckusick **		less, I got the idea of inhabited starsystems from this
66*11683Smckusick **		version.
67*11683Smckusick **
68*11683Smckusick **	Permission is given for use, copying, and modification of
69*11683Smckusick **		all or part of this program and related documentation,
70*11683Smckusick **		provided that all reference to the authors are maintained.
71*11683Smckusick **
72*11683Smckusick **
73*11683Smckusick **********************************************************************
74*11683Smckusick **
75*11683Smckusick **  NOTES TO THE MAINTAINER:
76*11683Smckusick **
77*11683Smckusick **	There is a compilation option xTRACE which must be set for any
78*11683Smckusick **	trace information to be generated.  It is probably defined in
79*11683Smckusick **	the version that you get.  It can be removed, however, if you
80*11683Smckusick **	have trouble finding room in core.
81*11683Smckusick **
82*11683Smckusick **	Many things in trek are not as clear as they might be, but are
83*11683Smckusick **	done to reduce space.  I compile with the -f and -O flags.  I
84*11683Smckusick **	am constrained to running with non-seperated I/D space, since
85*11683Smckusick **	we don't have floating point hardware here; even if we did, I
86*11683Smckusick **	would like trek to be available to the large number of people
87*11683Smckusick **	who either have an 11/40 or do not have FP hardware.  I also
88*11683Smckusick **	found it desirable to make the code run reentrant, so this
89*11683Smckusick **	added even more space constraints.
90*11683Smckusick **
91*11683Smckusick **	I use the portable C library to do my I/O.  This is done be-
92*11683Smckusick **	cause I wanted the game easily transportable to other C
93*11683Smckusick **	implementations, and because I was too lazy to do the floating
94*11683Smckusick **	point input myself.  Little did I know.  The portable C library
95*11683Smckusick **	released by Bell Labs has more bugs than you would believe, so
96*11683Smckusick **	I ended up rewriting the whole blessed thing.  Trek excercises
97*11683Smckusick **	many of the bugs in it, as well as bugs in some of the section
98*11683Smckusick **	III UNIX routines.  We have fixed them here.  One main problem
99*11683Smckusick **	was a bug in alloc() that caused it to always ask for a large
100*11683Smckusick **	hunk of memory, which worked fine unless you were almost out,
101*11683Smckusick **	which I inevitably was.  If you want the code for all of this
102*11683Smckusick **	stuff, it is also available through me.
103*11683Smckusick **
104*11683Smckusick ***********************************************************************
105*11683Smckusick */
106*11683Smckusick 
107*11683Smckusick main(argc, argv)
108*11683Smckusick int	argc;
109*11683Smckusick char	**argv;
110*11683Smckusick {
111*11683Smckusick 	int			vect[3];
112*11683Smckusick 	extern int		f_log;
113*11683Smckusick 	register char		opencode;
114*11683Smckusick 	int			prio;
115*11683Smckusick 	register int		ac;
116*11683Smckusick 	register char		**av;
117*11683Smckusick 
118*11683Smckusick 	av = argv;
119*11683Smckusick 	ac = argc;
120*11683Smckusick 	av++;
121*11683Smckusick 	time(vect);
122*11683Smckusick 	srand(vect[1]);
123*11683Smckusick 	opencode = 'w';
124*11683Smckusick 	prio = PRIO;
125*11683Smckusick 	if (gtty(1, vect) == 0)
126*11683Smckusick 	{
127*11683Smckusick 		if ((vect[0] & 0377) > 8)
128*11683Smckusick 			Etc.fast++;
129*11683Smckusick 	}
130*11683Smckusick 	while (ac > 1 && av[0][0] == '-')
131*11683Smckusick 	{
132*11683Smckusick 		switch (av[0][1])
133*11683Smckusick 		{
134*11683Smckusick 		  case 'a':	/* append to log file */
135*11683Smckusick 			opencode = 'a';
136*11683Smckusick 			break;
137*11683Smckusick 
138*11683Smckusick 		  case 'f':	/* set fast mode */
139*11683Smckusick 			Etc.fast++;
140*11683Smckusick 			break;
141*11683Smckusick 
142*11683Smckusick 		  case 's':	/* set slow mode */
143*11683Smckusick 			Etc.fast = 0;
144*11683Smckusick 			break;
145*11683Smckusick 
146*11683Smckusick #		ifdef xTRACE
147*11683Smckusick 		  case 't':	/* trace */
148*11683Smckusick 			if (getuid() != Mother)
149*11683Smckusick 				goto badflag;
150*11683Smckusick 			Trace++;
151*11683Smckusick 			break;
152*11683Smckusick #		endif
153*11683Smckusick 
154*11683Smckusick 		  case 'p':	/* set priority */
155*11683Smckusick 			if (getuid() != Mother)
156*11683Smckusick 				goto badflag;
157*11683Smckusick 			if (scanf(-1, &av[0][2], "%d", &prio) > 0)
158*11683Smckusick 				break;
159*11683Smckusick 
160*11683Smckusick 		  default:
161*11683Smckusick 		  badflag:
162*11683Smckusick 			printf("Invalid option: %s\n", av[0]);
163*11683Smckusick 
164*11683Smckusick 		}
165*11683Smckusick 		ac--;
166*11683Smckusick 		av++;
167*11683Smckusick 	}
168*11683Smckusick 	if (ac > 2)
169*11683Smckusick 		syserr(0, "arg count");
170*11683Smckusick 	if (ac > 1)
171*11683Smckusick 		f_log = copen(av[0], opencode);
172*11683Smckusick 
173*11683Smckusick 	printf("\n   * * *   S T A R   T R E K   * * *\n\n");
174*11683Smckusick 	ungetc('\n', 0);		/* prime the standard input */
175*11683Smckusick 	ungetc('y', 0);
176*11683Smckusick 	nice(prio);
177*11683Smckusick 
178*11683Smckusick 	setexit();
179*11683Smckusick 	while (getynpar("Another game"))
180*11683Smckusick 	{
181*11683Smckusick 		setup();
182*11683Smckusick 		play();
183*11683Smckusick 	}
184*11683Smckusick 	flush();
185*11683Smckusick }
186