2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2014, 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:
31 * Markus Armbruster, 2010
48 static int showsat(struct sky **skypp, int x, int y);
51 * format: skywatch [<SECTS>]
57 struct nstr_sect nstr;
59 struct sky *list[TSIZE];
62 int x, y, dx, dy, dxmax;
67 if (!snxtsct(&nstr, player->argp[1]))
69 for (i = 0; i < TSIZE; i++)
71 skyp = malloc(sizeof(*skyp));
72 snxtitem_all(&ni, EF_PLANE);
73 while (nxtitem(&ni, &skyp->s_sat)) {
74 if (!skyp->s_sat.pln_own)
76 if (!pln_is_in_orbit(&skyp->s_sat))
78 getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §);
79 n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE);
81 skyp->s_next = list[n];
83 skyp = malloc(sizeof(*skyp));
86 /* get that last one! */
88 pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum));
89 pr(" Country Satellite Location\n");
90 tech = tfact(player->cnum, 1.0);
91 while (nxtsct(&nstr, §) && nsat) {
92 if (sect.sct_own != player->cnum)
94 see = sect.sct_type == SCT_RADAR ? 14 : 4;
95 vrange = (int)(sect.sct_effic / 100.0 * see * tech);
98 for (dy = -vrange; dy <= vrange; dy++) {
99 y = ynorm(sect.sct_y + dy);
100 dxmax = 2 * vrange - abs(dy);
101 for (dx = -dxmax; dx <= dxmax; dx += 2) {
102 x = xnorm(sect.sct_x + dx);
103 n = scthash(x, y, TSIZE);
106 nsat -= showsat(&list[n], x, y);
110 /* free up the sky structs calloc'ed above */
111 for (i = 0; i < TSIZE; i++) {
112 while (NULL != (skyp = list[i])) {
113 list[i] = skyp->s_next;
121 showsat(struct sky **skypp, int x, int y)
124 struct sky *todelete = NULL;
132 /* we delete it, we free it. */
137 if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) {
138 prev = &(*prev)->s_next;
141 pr(" %12.12s (#%3d) %s @ %s\n",
142 cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own,
143 prplane(&skyp->s_sat), xyas(x, y, player->cnum));
145 /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */
146 setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST);
148 *prev = skyp->s_next;
151 } while (NULL != (skyp = skyp->s_next));
152 /* check that last one! */