2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * satmap.c: Do a satellite map given an x,y location, effic and other
30 * Known contributors to this file:
46 #include "prototypes.h"
55 satmap(int x, int y, int eff, int range, int flags, int type)
69 signed char noise[100];
76 radbuf = malloc(WORLD_Y * MAPWIDTH(1));
78 rad = malloc(WORLD_Y * sizeof(char *));
80 for (rx = 0; rx < WORLD_Y; rx++)
81 rad[rx] = &radbuf[(WORLD_X + 1) * rx];
85 if (!radbuf || !rad) {
86 pr("Memory error in satmap, tell the deity.\n");
90 range = range * (eff / 100.0);
91 pr("%s efficiency %d%%, max range %d\n",
92 xyas(x, y, player->cnum), eff, range);
93 memset(noise, 0, sizeof(noise));
95 pr("Some noise on the transmission...\n");
96 for (n = 0; n < (100 - eff); ++n)
97 noise[100 * n / (100 - eff)] = 1;
100 /* Have to convert to player coords, since it gets converted
102 sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range);
104 if (type == EF_BAD || type == EF_SECTOR) {
105 if (type == EF_SECTOR) /* Use ?conditionals */
106 snxtsct(&ns, selection);
108 snxtsct_dist(&ns, x, y, range);
110 blankfill(radbuf, &ns.range, 1);
112 pr("Satellite sector report\n");
115 acc = (flags & P_I) ? 5 : 50;
118 while (nxtsct(&ns, §)) {
119 if (++crackle == 100)
124 if (sect.sct_own && sect.sct_own != player->cnum) {
125 satdisp_sect(§, acc);
128 setcont(player->cnum, sect.sct_own, FOUND_FLY);
132 sect.sct_type == SCT_WATER || sect.sct_type == SCT_MOUNT) {
133 rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
135 rad[ns.dy][ns.dx] = '?';
137 map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0);
140 writemap(player->cnum);
142 pr(" %d sectors\n\n", count);
145 if ((type == EF_BAD || type == EF_SHIP) &&
146 (flags & P_S || flags & P_I)) {
148 snxtitem(&ni, EF_SHIP, selection, NULL);
150 snxtitem_dist(&ni, EF_SHIP, x, y, range);
154 pr("Satellite ship report\n");
156 pr(" own shp# ship type sector eff\n");
158 while (nxtitem(&ni, &ship)) {
159 if (ship.shp_own == 0)
161 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
162 ((flags & (P_S | P_I)) != (P_S | P_I)))
164 if (++crackle == 100)
169 pr("%4d %4d %-16.16s %-25.25s ",
170 ship.shp_own, ship.shp_uid,
171 mchr[(int)ship.shp_type].m_name, ship.shp_name);
172 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
173 pr("%3d%%\n", ship.shp_effic);
176 setcont(player->cnum, ship.shp_own, FOUND_FLY);
178 /* If we are imaging *and* drawing the map */
179 if ((flags & P_I) && (type == EF_BAD)) {
180 rx = deltx(&ns.range, ship.shp_x);
181 ry = delty(&ns.range, ship.shp_y);
182 /* &~0x20 makes it a cap letter */
183 rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
187 pr(" %d ships\n\n", count);
190 if ((type == EF_BAD || type == EF_LAND) &&
191 (flags & P_S || flags & P_I)) {
193 snxtitem(&ni, EF_LAND, selection, NULL);
195 snxtitem_dist(&ni, EF_LAND, x, y, range);
199 pr("Satellite unit report\n");
201 pr(" own lnd# unit type sector eff\n");
203 while (nxtitem(&ni, &land)) {
204 if (land.lnd_own == 0)
206 if (lchr[(int)land.lnd_type].l_flags & L_SPY)
208 if (!chance(land.lnd_effic / 20.0))
210 if (++crackle == 100)
215 pr("%4d %4d %-16.16s ",
216 land.lnd_own, land.lnd_uid,
217 lchr[(int)land.lnd_type].l_name);
218 prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum);
219 pr("%3d%%\n", land.lnd_effic);
222 setcont(player->cnum, land.lnd_own, FOUND_FLY);
224 /* If we are imaging *and* drawing the map */
225 if ((flags & P_I) && (type == EF_BAD)) {
226 rx = deltx(&ns.range, land.lnd_x);
227 ry = delty(&ns.range, land.lnd_y);
228 /* &~0x20 makes it a cap letter */
229 rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20;
233 pr(" %d units\n\n", count);
236 /* Ok, have we made the map? If so, display it */
237 if (type == EF_BAD) {
240 * We have to make the center a '0' for ve
241 * ve needs a garbage line to terminate the map
243 rad[delty(&ns.range, y)][deltx(&ns.range, y)] = '0';
245 pr("Satellite radar report\n");
247 for (row = 0; row < n; row++)
248 pr("%s\n", rad[row]);
249 pr("\n(c) 1989 Imaginative Images Inc.\n");
256 pr(" sct rd rl def\n");
257 pr(" sect type own eff eff eff eff civ mil shl gun iron pet food\n");
261 satdisp_sect(struct sctstr *sp, int acc)
263 prxy("%4d,%-4d ", sp->sct_x, sp->sct_y, player->cnum);
264 pr("%c %3d %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n",
265 dchr[sp->sct_type].d_mnem,
266 sp->sct_own, roundintby((int)sp->sct_effic, acc / 2),
267 roundintby((int)sp->sct_road, acc / 2),
268 opt_RAILWAYS ? !!sct_rail_track(sp) : roundintby(sp->sct_rail, acc / 2),
269 roundintby((int)sp->sct_defense, acc / 2),
270 roundintby(sp->sct_item[I_CIVIL], acc),
271 roundintby(sp->sct_item[I_MILIT], acc),
272 roundintby(sp->sct_item[I_SHELL], acc),
273 roundintby(sp->sct_item[I_GUN], acc),
274 roundintby(sp->sct_item[I_IRON], acc),
275 roundintby(sp->sct_item[I_PETROL], acc),
276 roundintby(sp->sct_item[I_FOOD], acc));
277 map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem,
282 satdisp_units(coord x, coord y)
289 snxtitem_xy(&ni, EF_SHIP, x, y);
291 while (nxtitem(&ni, &ship)) {
292 if (ship.shp_own == 0)
294 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
297 pr("\t own shp# ship type sector eff\n");
300 pr("\t%4d %4d %-16.16s %-25.25s ",
301 ship.shp_own, ship.shp_uid,
302 mchr[(int)ship.shp_type].m_name, ship.shp_name);
303 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
304 pr("%3d%%\n", ship.shp_effic);
310 snxtitem_xy(&ni, EF_LAND, x, y);
313 while (nxtitem(&ni, &land)) {
314 if (land.lnd_own == 0)
316 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
318 if (lchr[(int)land.lnd_type].l_flags & L_SPY)
320 if (!chance(land.lnd_effic / 20.0))
324 pr("\t own lnd# unit type sector eff\n");
328 pr("\t%4d %4d %-16.16s ",
329 land.lnd_own, land.lnd_uid, lchr[(int)land.lnd_type].l_name);
330 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
331 pr("%3d%%\n", land.lnd_effic);