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 * satmap.c: Do a satellite map given an x,y location, effic and other
29 * Known contributors to this file:
45 #include "prototypes.h"
54 satmap(int x, int y, int eff, int range, int flags, int type)
67 signed char noise[100];
74 radbuf = malloc(WORLD_Y * MAPWIDTH(1));
76 rad = malloc(WORLD_Y * sizeof(char *));
78 for (rx = 0; rx < WORLD_Y; rx++)
79 rad[rx] = &radbuf[(WORLD_X + 1) * rx];
83 if (!radbuf || !rad) {
84 pr("Memory error in satmap, tell the deity.\n");
88 range = range * (eff / 100.0);
89 pr("%s efficiency %d%%, max range %d\n",
90 xyas(x, y, player->cnum), eff, range);
91 memset(noise, 0, sizeof(noise));
93 pr("Some noise on the transmission...\n");
94 for (n = 0; n < (100 - eff); ++n)
95 noise[100 * n / (100 - eff)] = 1;
98 /* Have to convert to player coords, since it gets converted
100 sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range);
102 if (type == EF_BAD || type == EF_SECTOR) {
103 if (type == EF_SECTOR) /* Use ?conditionals */
104 snxtsct(&ns, selection);
106 snxtsct_dist(&ns, x, y, range);
108 blankfill(radbuf, &ns.range, 1);
110 pr("Satellite sector report\n");
115 while (nxtsct(&ns, §)) {
116 if (++crackle == 100)
121 if (sect.sct_own && sect.sct_own != player->cnum) {
122 satdisp_sect(§, (flags & P_I) ? 5 : 50);
123 changed += map_set(player->cnum, sect.sct_x, sect.sct_y,
124 dchr[sect.sct_type].d_mnem, 0);
127 setcont(player->cnum, sect.sct_own, FOUND_FLY);
131 sect.sct_type == SCT_WATER || sect.sct_type == SCT_MOUNT) {
132 rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
134 rad[ns.dy][ns.dx] = '?';
136 map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0);
139 writemap(player->cnum);
141 pr(" %d sectors\n\n", count);
144 if ((type == EF_BAD || type == EF_SHIP) &&
145 (flags & P_S || flags & P_I)) {
147 snxtitem(&ni, EF_SHIP, selection, NULL);
149 snxtitem_dist(&ni, EF_SHIP, x, y, range);
153 pr("Satellite ship report\n");
155 pr(" own shp# ship type sector eff\n");
157 while (nxtitem(&ni, &ship)) {
158 if (ship.shp_own == 0)
160 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
161 ((flags & (P_S | P_I)) != (P_S | P_I)))
163 if (++crackle == 100)
168 pr("%4d %4d %-16.16s %-25.25s ",
169 ship.shp_own, ship.shp_uid,
170 mchr[(int)ship.shp_type].m_name, ship.shp_name);
171 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
172 pr("%3d%%\n", ship.shp_effic);
175 setcont(player->cnum, ship.shp_own, FOUND_FLY);
177 /* If we are imaging *and* drawing the map */
178 if ((flags & P_I) && (type == EF_BAD)) {
179 rx = deltx(&ns.range, ship.shp_x);
180 ry = delty(&ns.range, ship.shp_y);
181 /* &~0x20 makes it a cap letter */
182 rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
186 pr(" %d ships\n\n", count);
189 if ((type == EF_BAD || type == EF_LAND) &&
190 (flags & P_S || flags & P_I)) {
192 snxtitem(&ni, EF_LAND, selection, NULL);
194 snxtitem_dist(&ni, EF_LAND, x, y, range);
198 pr("Satellite unit report\n");
200 pr(" own lnd# unit type sector eff\n");
202 while (nxtitem(&ni, &land)) {
203 if (land.lnd_own == 0)
205 if (lchr[(int)land.lnd_type].l_flags & L_SPY)
207 if (!chance(land.lnd_effic / 20.0))
209 if (++crackle == 100)
214 pr("%4d %4d %-16.16s ",
215 land.lnd_own, land.lnd_uid,
216 lchr[(int)land.lnd_type].l_name);
217 prxy("%4d,%-4d", land.lnd_x, land.lnd_y);
218 pr("%3d%%\n", land.lnd_effic);
221 setcont(player->cnum, land.lnd_own, FOUND_FLY);
223 /* If we are imaging *and* drawing the map */
224 if ((flags & P_I) && (type == EF_BAD)) {
225 rx = deltx(&ns.range, land.lnd_x);
226 ry = delty(&ns.range, land.lnd_y);
227 /* &~0x20 makes it a cap letter */
228 rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20;
232 pr(" %d units\n\n", count);
235 /* Ok, have we made the map? If so, display it */
236 if (type == EF_BAD) {
239 * We have to make the center a '0' for ve
240 * ve needs a garbage line to terminate the map
242 rad[delty(&ns.range, y)][deltx(&ns.range, y)] = '0';
244 pr("Satellite radar report\n");
246 for (row = 0; row < n; row++)
247 pr("%s\n", rad[row]);
248 pr("\n(c) 1989 Imaginative Images Inc.\n");
255 pr(" sct rd rl def\n");
256 pr(" sect type own eff eff eff eff civ mil shl gun iron pet food\n");
260 satdisp_sect(struct sctstr *sp, int acc)
262 prxy("%4d,%-4d ", sp->sct_x, sp->sct_y);
263 pr("%c %3d %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n",
264 dchr[sp->sct_type].d_mnem,
265 sp->sct_own, roundintby((int)sp->sct_effic, acc / 2),
266 roundintby((int)sp->sct_road, acc / 2),
267 opt_RAILWAYS ? !!sct_rail_track(sp) : roundintby(sp->sct_rail, acc / 2),
268 roundintby((int)sp->sct_defense, acc / 2),
269 roundintby(sp->sct_item[I_CIVIL], acc),
270 roundintby(sp->sct_item[I_MILIT], acc),
271 roundintby(sp->sct_item[I_SHELL], acc),
272 roundintby(sp->sct_item[I_GUN], acc),
273 roundintby(sp->sct_item[I_IRON], acc),
274 roundintby(sp->sct_item[I_PETROL], acc),
275 roundintby(sp->sct_item[I_FOOD], acc));
279 satdisp_units(coord x, coord y)
286 snxtitem_xy(&ni, EF_SHIP, x, y);
288 while (nxtitem(&ni, &ship)) {
289 if (ship.shp_own == 0)
291 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
294 pr("\t own shp# ship type sector eff\n");
297 pr("\t%4d %4d %-16.16s %-25.25s ",
298 ship.shp_own, ship.shp_uid,
299 mchr[(int)ship.shp_type].m_name, ship.shp_name);
300 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
301 pr("%3d%%\n", ship.shp_effic);
307 snxtitem_xy(&ni, EF_LAND, x, y);
310 while (nxtitem(&ni, &land)) {
311 if (land.lnd_own == 0)
313 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
315 if (lchr[(int)land.lnd_type].l_flags & L_SPY)
317 if (!chance(land.lnd_effic / 20.0))
321 pr("\t own lnd# unit type sector eff\n");
325 pr("\t%4d %4d %-16.16s ",
326 land.lnd_own, land.lnd_uid, lchr[(int)land.lnd_type].l_name);
327 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y);
328 pr("%3d%%\n", land.lnd_effic);