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