2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 * look.c: Lookout from a ship or land unit
30 * Known contributors to this file:
44 static void look_ship(struct shpstr *lookship);
45 static void look_land(struct lndstr *lookland);
57 unsigned char *bitmap;
60 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
62 if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
63 logerror("malloc failed in look\n");
64 pr("Memory error. Tell the deity.\n");
67 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
68 while (nxtitem(&ni, &myship)) {
72 for (i = 0; i <= 6; i++) {
73 x = diroff[i][0] + myship.shp_x;
74 y = diroff[i][1] + myship.shp_y;
75 if (emp_getbit(x, y, bitmap))
77 emp_setbit(x, y, bitmap);
79 if (sect.sct_type == SCT_WATER)
84 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
85 pr("%s", dchr[sect.sct_type].d_name);
86 changed += map_set(player->cnum, x, y,
87 dchr[sect.sct_type].d_mnem, 0);
88 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
89 roundintby((int)sect.sct_effic, 10));
90 civ = sect.sct_item[I_CIVIL];
91 mil = sect.sct_item[I_MILIT];
94 player->owner ? "" : "approx ",
95 player->owner ? civ : roundintby(civ, 10));
98 player->owner ? "" : "approx ",
99 player->owner ? mil : roundintby(mil, 10));
100 pr("@ %s\n", xyas(x, y, player->cnum));
102 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
107 writemap(player->cnum);
113 look_ship(struct shpstr *lookship)
116 struct mchrstr *smcp;
117 struct mchrstr *tmcp;
124 range = (int)techfact(lookship->shp_tech,
125 mchr[(int)lookship->shp_type].m_vrnge);
126 range = range * (lookship->shp_effic / 100.0);
127 smcp = &mchr[(int)lookship->shp_type];
128 if (smcp->m_flags & M_SUB)
129 range = MIN(range, 1);
130 for (i = 0; NULL != (sp = getshipp(i)); i++) {
131 if (sp->shp_own == player->cnum || sp->shp_own == 0)
133 dist = mapdist(sp->shp_x, sp->shp_y,
134 lookship->shp_x, lookship->shp_y);
135 if (dist > ship_max_interdiction_range)
137 tmcp = &mchr[(int)sp->shp_type];
138 if (smcp->m_flags & M_SUB)
139 vrange = (int)(sp->shp_visib * range / 30.0);
141 vrange = (int)(sp->shp_visib * range / 20.0);
142 getsect(sp->shp_x, sp->shp_y, §);
143 if (sect.sct_type != SCT_WATER)
144 vrange = MAX(1, vrange);
147 if (smcp->m_flags & M_SUB) {
148 if (tmcp->m_flags & M_SONAR && dist < 2) {
149 if (sp->shp_own != 0)
151 "%s detected surfacing noises in %s.\n",
153 xyas(lookship->shp_x, lookship->shp_y,
156 if (dist == 0 && (tmcp->m_flags & M_SUB) == 0)
157 if (sp->shp_own != 0)
159 "Periscope spotted in %s by %s\n",
160 xyas(lookship->shp_x, lookship->shp_y,
161 sp->shp_own), prship(sp));
163 /* subs at sea only seen by sonar */
164 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
166 pr("%s (#%d) %s @ %s\n",
167 cname(sp->shp_own), sp->shp_own, prship(sp),
168 xyas(sp->shp_x, sp->shp_y, player->cnum));
170 setcont(player->cnum, sp->shp_own, FOUND_LOOK);
179 struct lndstr myland;
184 unsigned char *bitmap;
187 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
189 if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
190 logerror("malloc failed in llook\n");
191 pr("Memory error. Tell the deity.\n");
194 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
195 while (nxtitem(&ni, &myland)) {
198 if (myland.lnd_ship >= 0)
200 if (myland.lnd_land >= 0)
202 /* Spies don't need military to do a "llook". Other
204 if ((myland.lnd_item[I_MILIT] <= 0) &&
205 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
208 for (i = 0; i <= 6; i++) {
209 x = diroff[i][0] + myland.lnd_x;
210 y = diroff[i][1] + myland.lnd_y;
211 if (emp_getbit(x, y, bitmap))
213 emp_setbit(x, y, bitmap);
214 getsect(x, y, §);
215 if (sect.sct_type == SCT_WATER)
220 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
221 pr("%s", dchr[sect.sct_type].d_name);
222 changed += map_set(player->cnum, x, y,
223 dchr[sect.sct_type].d_mnem, 0);
224 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
225 roundintby((int)sect.sct_effic, 10));
226 civ = sect.sct_item[I_CIVIL];
227 mil = sect.sct_item[I_MILIT];
229 pr("with %s%d civ ", player->owner ? "" :
230 "approx ", player->owner ? civ : roundintby(civ, 10));
232 pr("with %s%d mil ", player->owner ? "" :
233 "approx ", player->owner ? mil : roundintby(mil, 10));
234 pr("@ %s\n", xyas(x, y, player->cnum));
236 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
241 writemap(player->cnum);
247 look_land(struct lndstr *lookland)
257 drange = techfact(lookland->lnd_tech, lookland->lnd_spy);
258 drange *= lookland->lnd_effic / 100.0;
259 range = ldround(drange, 1);
264 for (i = 0; NULL != (lp = getlandp(i)); i++) {
265 if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
267 if (lp->lnd_ship >= 0)
269 /* Don't always see spies */
270 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
271 /* If it's on a ship or unit, assume it's hidden
272 enough not to be seen */
273 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
275 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
278 vrange = ldround((lp->lnd_vis * range) / 20.0, 1);
279 dist = mapdist(lp->lnd_x, lp->lnd_y,
280 lookland->lnd_x, lookland->lnd_y);
284 pr("%s (#%d) %s (approx %d mil) @ %s\n",
285 cname(lp->lnd_own), lp->lnd_own,
286 prland(lp), roundintby(lp->lnd_item[I_MILIT], 20),
287 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
289 setcont(player->cnum, lp->lnd_own, FOUND_LOOK);
291 for (i = 0; NULL != (pp = getplanep(i)); i++) {
292 if (pp->pln_own == player->cnum || pp->pln_own == 0)
294 if (pp->pln_ship >= 0)
296 if (pp->pln_flags & PLN_LAUNCHED)
298 vrange = ldround((10 * range) / 20.0, 1);
299 dist = mapdist(pp->pln_x, pp->pln_y,
300 lookland->lnd_x, lookland->lnd_y);
304 pr("%s (#%d) %s @ %s\n",
305 cname(pp->pln_own), pp->pln_own,
306 prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));
308 setcont(player->cnum, pp->pln_own, FOUND_LOOK);