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