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 * radmap.c: Do a radar map given an x,y location, effic, and other
30 * Known contributors to this file:
44 #include "prototypes.h"
48 radmap(int cx, int cy, int eff, int range, double seesub)
50 radmap2(player->cnum, cx, cy, eff, range, seesub, 1);
54 radmapnopr(int cx, int cy, int eff, int range, double seesub)
56 radmap2(player->cnum, cx, cy, eff, range, seesub, 0);
60 radmapupd(int own, int cx, int cy, int eff, int range, double seesub)
62 radmap2(own, cx, cy, eff, range, seesub, 0);
65 /* More dynamic world sized buffers. We create 'em once, and then
66 * never again. No need to keep creating/tearint apart. We may
67 * want to do this in other places too where it doesn't matter. */
69 static s_char *radbuf;
71 static s_char *visbuf;
94 radbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) *
97 visbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) *
100 rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
102 for (x = 0; x < WORLD_Y; x++)
103 rad[x] = &radbuf[(WORLD_X + 1) * x];
107 vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *));
109 for (x = 0; x < WORLD_Y; x++)
110 vis[x] = &visbuf[(WORLD_X + 1) * x];
113 if (!radbuf || !visbuf || !rad || !vis) {
114 pr("Memory error in radmap2, tell the deity.\n");
118 bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1)));
119 range = (int) (range * (eff / 100.0));
123 pr("%s efficiency %d%%, max range %d\n",
124 xyas(cx, cy, owner), eff, range);
125 snxtsct_dist(&ns, cx, cy, range);
126 blankfill((s_char *)radbuf, &ns.range, 1);
127 while (nxtsct(&ns, §)) {
128 if (sect.sct_own == owner ||
129 (sect.sct_type <= SCT_RURAL && sect.sct_type != SCT_SANCT)
130 || ns.curdist <= range/3)
131 rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem;
133 rad[ns.dy][ns.dx] = '?';
134 changed += map_set(owner, ns.x, ns.y, rad[ns.dy][ns.dx],0);
140 snxtitem_dist(&ni, EF_PLANE, cx, cy, range);
141 while (nxtitem(&ni, (caddr_t)&plane)) {
142 if (plane.pln_own == 0)
144 /* Used to have 'ghosts' when scanning whole world --ts */
145 x = deltx(&ns.range,(int)plane.pln_x);
146 y = delty(&ns.range,(int)plane.pln_y);
148 if ((plane.pln_flags & PLN_LAUNCHED) &&
149 plane.pln_own != owner) {
150 vis[y][x] = (s_char) 100;
154 snxtitem_dist(&ni, EF_SHIP, cx, cy, range);
155 while (nxtitem(&ni, (caddr_t)&ship)) {
156 if (ship.shp_own == 0)
158 /* Used to have 'ghosts' when scanning whole world --ts */
159 x = deltx(&ns.range,(int)ship.shp_x);
160 y = delty(&ns.range,(int)ship.shp_y);
162 rng = (int) (range * ship.shp_visib / 20.0);
163 if (ni.curdist > rng)
165 if ((mchr[(int)ship.shp_type].m_flags & M_SUB) &&
166 ni.curdist > rng * seesub)
168 if (ship.shp_visib > vis[y][x]) {
169 vis[y][x] = ship.shp_visib;
170 /* &~0x20 makes it a cap letter */
171 rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
175 * make the center of the display 0
176 * so ve et al can find it.
178 rad[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx)] = '0';
179 /* won't work for radar maps > WORLD_Y/2 */
181 /* This is not correct for small, hitech worlds. */
182 n = deltay(ns.range.hy, ns.range.ly);
184 /* This is already available, so why not use it. */
187 for (row=0; row < n; row++)
188 pr("%s\n", rad[row]);
193 deltx(struct range *r, coord x)
201 return x+WORLD_X-r->lx;
205 delty(struct range *r, coord y)
213 return y+WORLD_Y-r->ly;