2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * skyw.c: Look at satellites in the sky.
30 * Known contributors to this file:
53 static int showsat(struct sky **skypp, int x, int y);
56 * format: skywatch [<SECTS>]
62 struct nstr_sect nstr;
64 struct sky *list[TSIZE];
68 int mink, minj, maxk, maxj;
73 if (snxtsct(&nstr, player->argp[1]) == 0)
75 for (i = 0; i < TSIZE; i++)
77 skyp = malloc(sizeof(*skyp));
78 snxtitem_all(&ni, EF_PLANE);
79 while (nxtitem(&ni, &skyp->s_sat)) {
80 if (!skyp->s_sat.pln_own)
82 if (!(skyp->s_sat.pln_flags & PLN_LAUNCHED))
84 getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §);
85 n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE);
87 skyp->s_next = list[n];
89 skyp = malloc(sizeof(*skyp));
92 /* get that last one! */
94 pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum));
95 pr(" %18s%20s %s\n", "Country", "Satellite", "Location");
96 tech = tfact(player->cnum, 1.0);
97 while (nxtsct(&nstr, §) && nsat) {
98 if (sect.sct_own != player->cnum)
100 see = sect.sct_type == SCT_RADAR ? 14 : 4;
101 vrange = (int)(sect.sct_effic / 100.0 * see * tech);
109 for (j = minj; j <= maxj && nsat; j++) {
110 x = xnorm(sect.sct_x + j);
111 for (k = mink; k <= maxk && nsat; k++) {
114 /* quick range check to save time... */
115 if (vrange < (j * j + 3 * k * k) / 4)
117 y = ynorm(sect.sct_y + k);
118 n = scthash(x, y, TSIZE);
121 nsat -= showsat(&list[n], x, y);
125 /* free up the sky structs calloc'ed above */
126 for (i = 0; i < TSIZE; i++) {
127 while (NULL != (skyp = list[i])) {
128 list[i] = skyp->s_next;
136 showsat(struct sky **skypp, int x, int y)
139 struct sky *todelete = 0;
141 struct plchrstr *pcp;
149 /* we delete it, we free it. */
154 if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) {
155 prev = &(*prev)->s_next;
158 pcp = &plchr[(int)skyp->s_sat.pln_type];
160 pr(" %12.12s (#%d) %20s %s\n",
161 cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own,
162 name, xyas(x, y, player->cnum));
164 /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */
165 setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST);
167 *prev = skyp->s_next;
170 } while (NULL != (skyp = skyp->s_next));
171 /* check that last one! */