2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * skyw.c: Look at satellites in the sky.
29 * Known contributors to this file:
47 static int showsat(struct sky **skypp, int x, int y);
50 * format: skywatch [<SECTS>]
56 struct nstr_sect nstr;
58 struct sky *list[TSIZE];
61 int x, y, dx, dy, dxmax;
66 if (!snxtsct(&nstr, player->argp[1]))
68 for (i = 0; i < TSIZE; i++)
70 skyp = malloc(sizeof(*skyp));
71 snxtitem_all(&ni, EF_PLANE);
72 while (nxtitem(&ni, &skyp->s_sat)) {
73 if (!skyp->s_sat.pln_own)
75 if (!pln_is_in_orbit(&skyp->s_sat))
77 getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §);
78 n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE);
80 skyp->s_next = list[n];
82 skyp = malloc(sizeof(*skyp));
85 /* get that last one! */
87 pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum));
88 pr(" Country Satellite Location\n");
89 tech = tfact(player->cnum, 1.0);
90 while (nxtsct(&nstr, §) && nsat) {
91 if (sect.sct_own != player->cnum)
93 see = sect.sct_type == SCT_RADAR ? 14 : 4;
94 vrange = (int)(sect.sct_effic / 100.0 * see * tech);
97 for (dy = -vrange; dy <= vrange; dy++) {
98 y = ynorm(sect.sct_y + dy);
99 dxmax = 2 * vrange - abs(dy);
100 for (dx = -dxmax; dx <= dxmax; dx += 2) {
101 x = xnorm(sect.sct_x + dx);
102 n = scthash(x, y, TSIZE);
105 nsat -= showsat(&list[n], x, y);
109 /* free up the sky structs calloc'ed above */
110 for (i = 0; i < TSIZE; i++) {
111 while (NULL != (skyp = list[i])) {
112 list[i] = skyp->s_next;
120 showsat(struct sky **skypp, int x, int y)
123 struct sky *todelete = NULL;
131 /* we delete it, we free it. */
136 if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) {
137 prev = &(*prev)->s_next;
140 pr(" %12.12s (#%3d) %s @ %s\n",
141 cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own,
142 prplane(&skyp->s_sat), xyas(x, y, player->cnum));
144 /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */
145 setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST);
147 *prev = skyp->s_next;
150 } while (NULL != (skyp = skyp->s_next));
151 /* check that last one! */