2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 * satmap.c: Do a satellite map given an x,y location, effic and other
30 * Known contributors to this file:
46 #include "prototypes.h"
49 void satdisp(struct sctstr *sp, int acc, int showstuff);
52 static s_char *radbuf;
55 satmap(int x, int y, int eff, int range, int flags, int type)
70 s_char selection[1024];
76 radbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) *
79 rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
81 for (rx = 0; rx < WORLD_Y; rx++)
82 rad[rx] = &radbuf[(WORLD_X + 1) * rx];
86 if (!radbuf || !rad) {
87 pr("Memory error in satmap, tell the deity.\n");
91 range = range * (eff / 100.0);
92 pr("%s efficiency %d%%, max range %d\n", xyas(x, y, player->cnum),
94 bzero(noise, sizeof(noise));
96 pr("Some noise on the transmission...\n");
97 for (n = 0; n < (100 - eff); ++n)
98 noise[100 * n / (100 - eff)] = 1;
101 /* Have to convert to player coords, since it gets converted
103 sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range);
105 if (type == EF_BAD || type == EF_SECTOR) {
106 if (type == EF_SECTOR) /* Use ?conditionals */
107 snxtsct(&ns, selection);
109 snxtsct_dist(&ns, x, y, range);
111 blankfill((s_char *)radbuf, &ns.range, 1);
113 pr("Satellite sector report\n");
116 acc = (flags & P_I) ? 5 : 50;
119 while (nxtsct(&ns, §)) {
120 if (++crackle == 100)
125 if (sect.sct_type > SCT_RURAL) {
126 satdisp(§, acc, 0);
130 setcont(player->cnum, sect.sct_own, FOUND_FLY);
134 sect.sct_type == SCT_WATER || sect.sct_type == SCT_MOUNT) {
135 rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
137 rad[ns.dy][ns.dx] = '?';
139 map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0);
142 writemap(player->cnum);
144 pr(" %d sectors\n\n", count);
147 if ((type == EF_BAD || type == EF_SHIP) &&
148 (flags & P_S || flags & P_I)) {
150 snxtitem(&ni, EF_SHIP, selection);
152 snxtitem_dist(&ni, EF_SHIP, x, y, range);
156 pr("Satellite ship report\n");
159 pr(" own shp# ship type sector eff\n");
161 pr(" own shp# ship type sector eff\n");
164 while (nxtitem(&ni, (caddr_t)&ship)) {
165 if (ship.shp_own == 0)
167 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
168 ((flags & (P_S | P_I)) != (P_S | P_I)))
170 if (++crackle == 100)
175 pr("%4d %4d %-16.16s ",
176 ship.shp_own, ship.shp_uid,
177 mchr[(int)ship.shp_type].m_name);
179 pr("%-25.25s ", ship.shp_name);
180 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
181 pr("%3d%%\n", ship.shp_effic);
184 setcont(player->cnum, ship.shp_own, FOUND_FLY);
187 /* If we are imaging *and* drawing the map */
188 if ((flags & P_I) && (type == EF_BAD)) {
189 /* Figure out where to put the ship */
190 /* First, figure out the distance from the two */
191 rx = diffx((int)ship.shp_x, x);
192 ry = diffy((int)ship.shp_y, y);
193 /* Next, determine which direction to add it to the center */
194 /* We can only do this if imaging and we have gotten the center
195 up above by imaging the sectors. */
196 rx = deltax(x, ns.range.lx) + rx;
197 ry = deltay(y, ns.range.ly) + ry;
198 /* &~0x20 makes it a cap letter */
199 rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
203 pr(" %d ships\n\n", count);
206 if ((type == EF_BAD || type == EF_LAND) &&
207 (flags & P_S || flags & P_I)) {
209 snxtitem(&ni, EF_LAND, selection);
211 snxtitem_dist(&ni, EF_LAND, x, y, range);
215 pr("Satellite unit report\n");
217 pr(" own lnd# unit type sector eff\n");
219 while (nxtitem(&ni, (caddr_t)&land)) {
220 if (land.lnd_own == 0)
222 if (!chance((double)land.lnd_effic / 20.0))
224 if (++crackle == 100)
229 pr("%4d %4d %-16.16s ",
230 land.lnd_own, land.lnd_uid,
231 lchr[(int)land.lnd_type].l_name);
232 prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum);
233 pr("%3d%%\n", land.lnd_effic);
236 /* If we are imaging *and* drawing the map */
237 if ((flags & P_I) && (type == EF_BAD)) {
238 /* Figure out where to put the unit */
239 /* First, figure out the distance from the two */
240 rx = diffx((int)land.lnd_x, x);
241 ry = diffy((int)land.lnd_y, y);
242 /* Next, determine which direction to add it to the center */
243 /* We can only do this if imaging and we have gotten the center
244 up above by imaging the sectors. */
245 rx = deltax(x, ns.range.lx) + rx;
246 ry = deltay(y, ns.range.ly) + ry;
247 /* &~0x20 makes it a cap letter */
248 rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20;
252 pr(" %d units\n\n", count);
255 /* Ok, have we made the map? If so, display it */
256 if (type == EF_BAD) {
259 * We have to make the center a '0' for ve
260 * ve needs a garbage line to terminate the map
262 rad[deltay(y, ns.range.ly)][deltax(x, ns.range.lx)] = '0';
264 pr("Satellite radar report\n");
266 /* This is wrong for small, hitech worlds. */
267 n = deltay(ns.range.hy, ns.range.ly);
269 /* This is already available, so why not use it. */
272 for (row = 0; row < n; row++)
273 pr("%s\n", rad[row]);
274 pr("\n(c) 1989 Imaginative Images Inc.\n");
281 pr(" sct rd rl def\n");
282 pr(" sect type own eff eff eff eff civ mil shl gun iron pet food\n");
286 satdisp(struct sctstr *sp, int acc, int showstuff)
288 int vec[I_MAX + 1], first;
293 if (getvec(VT_ITEM, vec, (caddr_t)sp, EF_SECTOR) < 0)
295 prxy("%4d,%-4d ", sp->sct_x, sp->sct_y, player->cnum),
296 pr("%c %3d %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n",
297 dchr[sp->sct_type].d_mnem,
298 sp->sct_own, roundintby((int)sp->sct_effic, acc / 2),
299 roundintby((int)sp->sct_road, acc / 2),
300 roundintby((int)sp->sct_rail, acc / 2),
301 roundintby((int)sp->sct_defense, acc / 2),
302 roundintby(vec[I_CIVIL], acc), roundintby(vec[I_MILIT], acc),
303 roundintby(vec[I_SHELL], acc), roundintby(vec[I_GUN], acc),
304 roundintby(vec[I_IRON], acc), roundintby(vec[I_PETROL], acc),
305 roundintby(vec[I_FOOD], acc));
306 map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem,
310 snxtitem_xy(&ni, EF_SHIP, sp->sct_x, sp->sct_y);
312 while (nxtitem(&ni, (caddr_t)&ship)) {
313 if (ship.shp_own == 0)
315 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
319 pr("\t own shp# ship type sector eff\n");
321 pr("\t own shp# ship type sector eff\n");
325 pr("\t%4d %4d %-16.16s ", ship.shp_own, ship.shp_uid,
326 mchr[(int)ship.shp_type].m_name);
328 pr("%-25.25s ", ship.shp_name);
329 prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum);
330 pr("%3d%%\n", ship.shp_effic);
336 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
339 while (nxtitem(&ni, (caddr_t)&land)) {
340 if (land.lnd_own == 0)
342 if (!chance((double)land.lnd_effic / 20.0))
346 pr("\t own lnd# unit type sector eff\n");
350 pr("\t%4d %4d %-16.16s ", land.lnd_own, land.lnd_uid,
351 lchr[(int)land.lnd_type].l_name);
352 prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum);
353 pr("%3d%%\n", land.lnd_effic);