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