xref: /original-bsd/games/trek/srscan.c (revision 65ba69af)
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 static char sccsid[] = "@(#)srscan.c	5.3 (Berkeley) 06/18/88";
20 #endif /* not lint */
21 
22 # include	"trek.h"
23 # include	"getpar.h"
24 
25 /*
26 **  SHORT RANGE SENSOR SCAN
27 **
28 **	A short range scan is taken of the current quadrant.  If the
29 **	flag 'f' is one, it is an "auto srscan", which is not done
30 **	unless in 'fast' mode.  It does a status report and a srscan.
31 **	If 'f' is -1, you get a status report only.  If it is zero,
32 **	you get a srscan and an optional status report.  The status
33 **	report is taken if you enter "srscan yes"; for all srscans
34 **	thereafter you get a status report with your srscan until
35 **	you type "srscan no".  It defaults to on.
36 **
37 **	The current quadrant is filled in on the computer chart.
38 */
39 
40 char	*Color[4] =
41 {
42 	"GREEN",
43 	"DOCKED",
44 	"YELLOW",
45 	"RED"
46 };
47 
48 srscan(f)
49 int	f;
50 {
51 	register int		i, j;
52 	register int		statinfo;
53 	char			*s;
54 	int			percent;
55 	struct quad		*q;
56 	extern struct cvntab	Skitab[];
57 	extern struct cvntab	Lentab[];
58 	struct cvntab		*p;
59 
60 	if (f >= 0 && check_out(SRSCAN))
61 	{
62 		return;
63 	}
64 	if (f)
65 		statinfo = 1;
66 	else
67 	{
68 		if (!testnl())
69 			Etc.statreport = getynpar("status report");
70 		statinfo = Etc.statreport;
71 	}
72 	if (f > 0)
73 	{
74 		Etc.statreport = 1;
75 		if (!Etc.fast)
76 			return;
77 	}
78 	if (f >= 0)
79 	{
80 		printf("\nShort range sensor scan\n");
81 		q = &Quad[Ship.quadx][Ship.quady];
82 		q->scanned = q->klings * 100 + q->bases * 10 + q->stars;
83 		printf("  ");
84 		for (i = 0; i < NSECTS; i++)
85 		{
86 			printf("%d ", i);
87 		}
88 		printf("\n");
89 	}
90 
91 	for (i = 0; i < NSECTS; i++)
92 	{
93 		if (f >= 0)
94 		{
95 			printf("%d ", i);
96 			for (j = 0; j < NSECTS; j++)
97 				printf("%c ", Sect[i][j]);
98 			printf("%d", i);
99 			if (statinfo)
100 				printf("   ");
101 		}
102 		if (statinfo)
103 			switch (i)
104 			{
105 			  case 0:
106 				printf("stardate      %.2f", Now.date);
107 				break;
108 			  case 1:
109 				printf("condition     %s", Color[Ship.cond]);
110 				if (Ship.cloaked)
111 					printf(", CLOAKED");
112 				break;
113 			  case 2:
114 				printf("position      %d,%d/%d,%d",Ship.quadx, Ship.quady, Ship.sectx, Ship.secty);
115 				break;
116 			  case 3:
117 				printf("warp factor   %.1f", Ship.warp);
118 				break;
119 			  case 4:
120 				printf("total energy  %d", Ship.energy);
121 				break;
122 			  case 5:
123 				printf("torpedoes     %d", Ship.torped);
124 				break;
125 			  case 6:
126 				s = "down";
127 				if (Ship.shldup)
128 					s = "up";
129 				if (damaged(SHIELD))
130 					s = "damaged";
131 				percent = 100.0 * Ship.shield / Param.shield;
132 				printf("shields       %s, %d%%", s, percent);
133 				break;
134 			  case 7:
135 				printf("Klingons left %d", Now.klings);
136 				break;
137 			  case 8:
138 				printf("time left     %.2f", Now.time);
139 				break;
140 			  case 9:
141 				printf("life support  ");
142 				if (damaged(LIFESUP))
143 				{
144 					printf("damaged, reserves = %.2f", Ship.reserves);
145 					break;
146 				}
147 				printf("active");
148 				break;
149 			}
150 		printf("\n");
151 	}
152 	if (f < 0)
153 	{
154 		printf("current crew  %d\n", Ship.crew);
155 		printf("brig space    %d\n", Ship.brigfree);
156 		printf("Klingon power %d\n", Param.klingpwr);
157 		p = &Lentab[Game.length - 1];
158 		if (Game.length > 2)
159 			p--;
160 		printf("Length, Skill %s%s, ", p->abrev, p->full);
161 		p = &Skitab[Game.skill - 1];
162 		printf("%s%s\n", p->abrev, p->full);
163 		return;
164 	}
165 	printf("  ");
166 	for (i = 0; i < NSECTS; i++)
167 		printf("%d ", i);
168 	printf("\n");
169 
170 	if (q->qsystemname & Q_DISTRESSED)
171 		printf("Distressed ");
172 	if (q->qsystemname)
173 		printf("Starsystem %s\n", systemname(q));
174 }
175