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:
51 static void look_ship(struct shpstr *lookship);
52 static void look_land(struct lndstr *lookland);
64 unsigned char *bitmap;
67 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
69 if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
70 logerror("malloc failed in look\n");
71 pr("Memory error. Tell the deity.\n");
74 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
75 while (nxtitem(&ni, &myship)) {
79 for (i = 0; i <= 6; i++) {
80 x = diroff[i][0] + myship.shp_x;
81 y = diroff[i][1] + myship.shp_y;
82 if (emp_getbit(x, y, bitmap))
84 emp_setbit(x, y, bitmap);
86 if (sect.sct_type == SCT_WATER)
91 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
92 pr("%s", dchr[sect.sct_type].d_name);
93 changed += map_set(player->cnum, x, y,
94 dchr[sect.sct_type].d_mnem, 0);
95 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
96 roundintby((int)sect.sct_effic, 10));
97 civ = sect.sct_item[I_CIVIL];
98 mil = sect.sct_item[I_MILIT];
101 player->owner ? "" : "approx ",
102 player->owner ? civ : roundintby(civ, 10));
105 player->owner ? "" : "approx ",
106 player->owner ? mil : roundintby(mil, 10));
107 pr("@ %s\n", xyas(x, y, player->cnum));
109 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
114 writemap(player->cnum);
120 look_ship(struct shpstr *lookship)
123 struct mchrstr *smcp;
124 struct mchrstr *tmcp;
131 range = (int)techfact(lookship->shp_tech,
132 mchr[(int)lookship->shp_type].m_vrnge);
133 range = range * (lookship->shp_effic / 100.0);
134 smcp = &mchr[(int)lookship->shp_type];
135 if (smcp->m_flags & M_SUB)
136 range = MIN(range, 1);
137 for (i = 0; NULL != (sp = getshipp(i)); i++) {
138 if (sp->shp_own == player->cnum || sp->shp_own == 0)
140 dist = mapdist(sp->shp_x, sp->shp_y,
141 lookship->shp_x, lookship->shp_y);
142 if (dist > ship_max_interdiction_range)
144 tmcp = &mchr[(int)sp->shp_type];
145 if (smcp->m_flags & M_SUB)
146 vrange = (int)(sp->shp_visib * range / 30.0);
148 vrange = (int)(sp->shp_visib * range / 20.0);
149 getsect(sp->shp_x, sp->shp_y, §);
150 if (sect.sct_type != SCT_WATER)
151 vrange = MAX(1, vrange);
154 if (smcp->m_flags & M_SUB) {
155 if (tmcp->m_flags & M_SONAR && dist < 2) {
156 if (sp->shp_own != 0)
158 "%s detected surfacing noises in %s.\n",
160 xyas(lookship->shp_x, lookship->shp_y,
163 if (dist == 0 && (tmcp->m_flags & M_SUB) == 0)
164 if (sp->shp_own != 0)
166 "Periscope spotted in %s by %s\n",
167 xyas(lookship->shp_x, lookship->shp_y,
168 sp->shp_own), prship(sp));
170 /* subs at sea only seen by sonar */
171 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
173 pr("%s (#%d) %s @ %s\n",
174 cname(sp->shp_own), sp->shp_own, prship(sp),
175 xyas(sp->shp_x, sp->shp_y, player->cnum));
177 setcont(player->cnum, sp->shp_own, FOUND_LOOK);
186 struct lndstr myland;
191 unsigned char *bitmap;
194 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
196 if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
197 logerror("malloc failed in llook\n");
198 pr("Memory error. Tell the deity.\n");
201 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
202 while (nxtitem(&ni, &myland)) {
205 if (myland.lnd_ship >= 0)
207 if (myland.lnd_land >= 0)
209 /* Spies don't need military to do a "llook". Other
211 if ((myland.lnd_item[I_MILIT] <= 0) &&
212 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
215 for (i = 0; i <= 6; i++) {
216 x = diroff[i][0] + myland.lnd_x;
217 y = diroff[i][1] + myland.lnd_y;
218 if (emp_getbit(x, y, bitmap))
220 emp_setbit(x, y, bitmap);
221 getsect(x, y, §);
222 if (sect.sct_type == SCT_WATER)
227 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
228 pr("%s", dchr[sect.sct_type].d_name);
229 changed += map_set(player->cnum, x, y,
230 dchr[sect.sct_type].d_mnem, 0);
231 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
232 roundintby((int)sect.sct_effic, 10));
233 civ = sect.sct_item[I_CIVIL];
234 mil = sect.sct_item[I_MILIT];
236 pr("with %s%d civ ", player->owner ? "" :
237 "approx ", player->owner ? civ : roundintby(civ, 10));
239 pr("with %s%d mil ", player->owner ? "" :
240 "approx ", player->owner ? mil : roundintby(mil, 10));
241 pr("@ %s\n", xyas(x, y, player->cnum));
243 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
248 writemap(player->cnum);
254 look_land(struct lndstr *lookland)
264 drange = techfact(lookland->lnd_tech, lookland->lnd_spy);
265 drange *= lookland->lnd_effic / 100.0;
266 range = ldround(drange, 1);
271 for (i = 0; NULL != (lp = getlandp(i)); i++) {
272 if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
274 if (lp->lnd_ship >= 0)
276 /* Don't always see spies */
277 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
278 /* If it's on a ship or unit, assume it's hidden
279 enough not to be seen */
280 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
282 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
285 vrange = ldround((lp->lnd_vis * range) / 20.0, 1);
286 dist = mapdist(lp->lnd_x, lp->lnd_y,
287 lookland->lnd_x, lookland->lnd_y);
291 pr("%s (#%d) %s (approx %d mil) @ %s\n",
292 cname(lp->lnd_own), lp->lnd_own,
293 prland(lp), roundintby(lp->lnd_item[I_MILIT], 20),
294 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
296 setcont(player->cnum, lp->lnd_own, FOUND_LOOK);
298 for (i = 0; NULL != (pp = getplanep(i)); i++) {
299 if (pp->pln_own == player->cnum || pp->pln_own == 0)
301 if (pp->pln_ship >= 0)
303 if (pp->pln_flags & PLN_LAUNCHED)
305 vrange = ldround((10 * range) / 20.0, 1);
306 dist = mapdist(pp->pln_x, pp->pln_y,
307 lookland->lnd_x, lookland->lnd_y);
311 pr("%s (#%d) %s @ %s\n",
312 cname(pp->pln_own), pp->pln_own,
313 prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));
315 setcont(player->cnum, pp->pln_own, FOUND_LOOK);