1*da121b33Sdholland /* $NetBSD: srscan.c,v 1.11 2009/08/12 08:54:54 dholland Exp $ */
2887dd216Scgd
361f28255Scgd /*
4887dd216Scgd * Copyright (c) 1980, 1993
5887dd216Scgd * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
15e5aeb4eaSagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32ef383c95Schristos #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
34887dd216Scgd #if 0
35887dd216Scgd static char sccsid[] = "@(#)srscan.c 8.1 (Berkeley) 5/31/93";
36887dd216Scgd #else
37*da121b33Sdholland __RCSID("$NetBSD: srscan.c,v 1.11 2009/08/12 08:54:54 dholland Exp $");
38887dd216Scgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd
41ef383c95Schristos #include <stdio.h>
4261f28255Scgd #include "trek.h"
4361f28255Scgd #include "getpar.h"
4461f28255Scgd
4561f28255Scgd /*
4661f28255Scgd ** SHORT RANGE SENSOR SCAN
4761f28255Scgd **
4861f28255Scgd ** A short range scan is taken of the current quadrant. If the
4961f28255Scgd ** flag 'f' is one, it is an "auto srscan", which is not done
5061f28255Scgd ** unless in 'fast' mode. It does a status report and a srscan.
5161f28255Scgd ** If 'f' is -1, you get a status report only. If it is zero,
5261f28255Scgd ** you get a srscan and an optional status report. The status
5361f28255Scgd ** report is taken if you enter "srscan yes"; for all srscans
5461f28255Scgd ** thereafter you get a status report with your srscan until
5561f28255Scgd ** you type "srscan no". It defaults to on.
5661f28255Scgd **
5761f28255Scgd ** The current quadrant is filled in on the computer chart.
5861f28255Scgd */
5961f28255Scgd
60*da121b33Sdholland static const char *const Color[4] = {
6161f28255Scgd "GREEN",
6261f28255Scgd "DOCKED",
6361f28255Scgd "YELLOW",
6461f28255Scgd "RED"
6561f28255Scgd };
6661f28255Scgd
67ef383c95Schristos void
srscan(int f)68bf0917b6Sdholland srscan(int f)
6961f28255Scgd {
70ef383c95Schristos int i, j;
71ef383c95Schristos int statinfo;
72b7e11e5cShubertf const char *s;
7361f28255Scgd int percent;
74ef383c95Schristos struct quad *q = NULL;
75b7e11e5cShubertf const struct cvntab *p;
7661f28255Scgd
7750b862e2Sdholland if (f >= 0 && check_out(SRSCAN)) {
7861f28255Scgd return;
7961f28255Scgd }
8050b862e2Sdholland if (f) {
8161f28255Scgd statinfo = 1;
8250b862e2Sdholland } else {
8361f28255Scgd if (!testnl())
8461f28255Scgd Etc.statreport = getynpar("status report");
8561f28255Scgd statinfo = Etc.statreport;
8661f28255Scgd }
8750b862e2Sdholland if (f > 0) {
8861f28255Scgd Etc.statreport = 1;
8961f28255Scgd if (!Etc.fast)
9061f28255Scgd return;
9161f28255Scgd }
9250b862e2Sdholland if (f >= 0) {
9361f28255Scgd printf("\nShort range sensor scan\n");
9461f28255Scgd q = &Quad[Ship.quadx][Ship.quady];
9561f28255Scgd q->scanned = q->klings * 100 + q->bases * 10 + q->stars;
9661f28255Scgd printf(" ");
9750b862e2Sdholland for (i = 0; i < NSECTS; i++) {
9861f28255Scgd printf("%d ", i);
9961f28255Scgd }
10061f28255Scgd printf("\n");
10161f28255Scgd }
10261f28255Scgd
10350b862e2Sdholland for (i = 0; i < NSECTS; i++) {
10450b862e2Sdholland if (f >= 0) {
10561f28255Scgd printf("%d ", i);
10661f28255Scgd for (j = 0; j < NSECTS; j++)
10761f28255Scgd printf("%c ", Sect[i][j]);
10861f28255Scgd printf("%d", i);
10961f28255Scgd if (statinfo)
11061f28255Scgd printf(" ");
11161f28255Scgd }
11261f28255Scgd if (statinfo)
11350b862e2Sdholland switch (i) {
11461f28255Scgd case 0:
11561f28255Scgd printf("stardate %.2f", Now.date);
11661f28255Scgd break;
11761f28255Scgd case 1:
11861f28255Scgd printf("condition %s", Color[Ship.cond]);
11961f28255Scgd if (Ship.cloaked)
12061f28255Scgd printf(", CLOAKED");
12161f28255Scgd break;
12261f28255Scgd case 2:
12361357867Sdholland printf("position %d,%d/%d,%d", Ship.quadx,
12461357867Sdholland Ship.quady, Ship.sectx, Ship.secty);
12561f28255Scgd break;
12661f28255Scgd case 3:
12761f28255Scgd printf("warp factor %.1f", Ship.warp);
12861f28255Scgd break;
12961f28255Scgd case 4:
13061f28255Scgd printf("total energy %d", Ship.energy);
13161f28255Scgd break;
13261f28255Scgd case 5:
13361f28255Scgd printf("torpedoes %d", Ship.torped);
13461f28255Scgd break;
13561f28255Scgd case 6:
13661f28255Scgd s = "down";
13761f28255Scgd if (Ship.shldup)
13861f28255Scgd s = "up";
13961f28255Scgd if (damaged(SHIELD))
14061f28255Scgd s = "damaged";
14161f28255Scgd percent = 100.0 * Ship.shield / Param.shield;
14261f28255Scgd printf("shields %s, %d%%", s, percent);
14361f28255Scgd break;
14461f28255Scgd case 7:
14561f28255Scgd printf("Klingons left %d", Now.klings);
14661f28255Scgd break;
14761f28255Scgd case 8:
14861f28255Scgd printf("time left %.2f", Now.time);
14961f28255Scgd break;
15061f28255Scgd case 9:
15161f28255Scgd printf("life support ");
15250b862e2Sdholland if (damaged(LIFESUP)) {
15361357867Sdholland printf("damaged, reserves = %.2f",
15461357867Sdholland Ship.reserves);
15561f28255Scgd break;
15661f28255Scgd }
15761f28255Scgd printf("active");
15861f28255Scgd break;
15961f28255Scgd }
16061f28255Scgd printf("\n");
16161f28255Scgd }
16250b862e2Sdholland if (f < 0) {
16361f28255Scgd printf("current crew %d\n", Ship.crew);
16461f28255Scgd printf("brig space %d\n", Ship.brigfree);
16561f28255Scgd printf("Klingon power %d\n", Param.klingpwr);
16661f28255Scgd p = &Lentab[Game.length - 1];
16761f28255Scgd if (Game.length > 2)
16861f28255Scgd p--;
169869c9375Sdholland printf("Length, Skill %s%s, ", p->abbrev, p->full);
17061f28255Scgd p = &Skitab[Game.skill - 1];
171869c9375Sdholland printf("%s%s\n", p->abbrev, p->full);
17261f28255Scgd return;
17361f28255Scgd }
17461f28255Scgd printf(" ");
17561f28255Scgd for (i = 0; i < NSECTS; i++)
17661f28255Scgd printf("%d ", i);
17761f28255Scgd printf("\n");
17861f28255Scgd
17961f28255Scgd if (q->qsystemname & Q_DISTRESSED)
18061f28255Scgd printf("Distressed ");
18161f28255Scgd if (q->qsystemname)
18261f28255Scgd printf("Starsystem %s\n", systemname(q));
18361f28255Scgd }
184