xref: /netbsd/games/trek/srscan.c (revision bf9ec67e)
1 /*	$NetBSD: srscan.c,v 1.5 1999/07/21 13:19:11 hubertf Exp $	*/
2 
3 /*
4  * Copyright (c) 1980, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)srscan.c	8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: srscan.c,v 1.5 1999/07/21 13:19:11 hubertf Exp $");
42 #endif
43 #endif /* not lint */
44 
45 #include <stdio.h>
46 #include "trek.h"
47 #include "getpar.h"
48 
49 /*
50 **  SHORT RANGE SENSOR SCAN
51 **
52 **	A short range scan is taken of the current quadrant.  If the
53 **	flag 'f' is one, it is an "auto srscan", which is not done
54 **	unless in 'fast' mode.  It does a status report and a srscan.
55 **	If 'f' is -1, you get a status report only.  If it is zero,
56 **	you get a srscan and an optional status report.  The status
57 **	report is taken if you enter "srscan yes"; for all srscans
58 **	thereafter you get a status report with your srscan until
59 **	you type "srscan no".  It defaults to on.
60 **
61 **	The current quadrant is filled in on the computer chart.
62 */
63 
64 const char	*const Color[4] =
65 {
66 	"GREEN",
67 	"DOCKED",
68 	"YELLOW",
69 	"RED"
70 };
71 
72 void
73 srscan(f)
74 int	f;
75 {
76 	int		i, j;
77 	int		statinfo;
78 	const char	*s;
79 	int		percent;
80 	struct quad	*q = NULL;
81 	const struct cvntab	*p;
82 
83 	if (f >= 0 && check_out(SRSCAN))
84 	{
85 		return;
86 	}
87 	if (f)
88 		statinfo = 1;
89 	else
90 	{
91 		if (!testnl())
92 			Etc.statreport = getynpar("status report");
93 		statinfo = Etc.statreport;
94 	}
95 	if (f > 0)
96 	{
97 		Etc.statreport = 1;
98 		if (!Etc.fast)
99 			return;
100 	}
101 	if (f >= 0)
102 	{
103 		printf("\nShort range sensor scan\n");
104 		q = &Quad[Ship.quadx][Ship.quady];
105 		q->scanned = q->klings * 100 + q->bases * 10 + q->stars;
106 		printf("  ");
107 		for (i = 0; i < NSECTS; i++)
108 		{
109 			printf("%d ", i);
110 		}
111 		printf("\n");
112 	}
113 
114 	for (i = 0; i < NSECTS; i++)
115 	{
116 		if (f >= 0)
117 		{
118 			printf("%d ", i);
119 			for (j = 0; j < NSECTS; j++)
120 				printf("%c ", Sect[i][j]);
121 			printf("%d", i);
122 			if (statinfo)
123 				printf("   ");
124 		}
125 		if (statinfo)
126 			switch (i)
127 			{
128 			  case 0:
129 				printf("stardate      %.2f", Now.date);
130 				break;
131 			  case 1:
132 				printf("condition     %s", Color[Ship.cond]);
133 				if (Ship.cloaked)
134 					printf(", CLOAKED");
135 				break;
136 			  case 2:
137 				printf("position      %d,%d/%d,%d",Ship.quadx, Ship.quady, Ship.sectx, Ship.secty);
138 				break;
139 			  case 3:
140 				printf("warp factor   %.1f", Ship.warp);
141 				break;
142 			  case 4:
143 				printf("total energy  %d", Ship.energy);
144 				break;
145 			  case 5:
146 				printf("torpedoes     %d", Ship.torped);
147 				break;
148 			  case 6:
149 				s = "down";
150 				if (Ship.shldup)
151 					s = "up";
152 				if (damaged(SHIELD))
153 					s = "damaged";
154 				percent = 100.0 * Ship.shield / Param.shield;
155 				printf("shields       %s, %d%%", s, percent);
156 				break;
157 			  case 7:
158 				printf("Klingons left %d", Now.klings);
159 				break;
160 			  case 8:
161 				printf("time left     %.2f", Now.time);
162 				break;
163 			  case 9:
164 				printf("life support  ");
165 				if (damaged(LIFESUP))
166 				{
167 					printf("damaged, reserves = %.2f", Ship.reserves);
168 					break;
169 				}
170 				printf("active");
171 				break;
172 			}
173 		printf("\n");
174 	}
175 	if (f < 0)
176 	{
177 		printf("current crew  %d\n", Ship.crew);
178 		printf("brig space    %d\n", Ship.brigfree);
179 		printf("Klingon power %d\n", Param.klingpwr);
180 		p = &Lentab[Game.length - 1];
181 		if (Game.length > 2)
182 			p--;
183 		printf("Length, Skill %s%s, ", p->abrev, p->full);
184 		p = &Skitab[Game.skill - 1];
185 		printf("%s%s\n", p->abrev, p->full);
186 		return;
187 	}
188 	printf("  ");
189 	for (i = 0; i < NSECTS; i++)
190 		printf("%d ", i);
191 	printf("\n");
192 
193 	if (q->qsystemname & Q_DISTRESSED)
194 		printf("Distressed ");
195 	if (q->qsystemname)
196 		printf("Starsystem %s\n", systemname(q));
197 }
198