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);
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(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];
100 pr("with %s%d civ ", player->owner ? "" : "approx ",
101 player->owner ? civ : roundintby(civ, 10));
103 pr("with %s%d mil ", player->owner ? "" : "approx ",
104 player->owner ? mil : roundintby(mil, 10));
105 pr("@ %s\n", xyas(x, y, player->cnum));
107 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
112 writemap(player->cnum);
118 look_ship(struct shpstr *lookship)
121 struct mchrstr *smcp;
122 struct mchrstr *tmcp;
129 range = (int)techfact(lookship->shp_tech,
130 (double)mchr[(int)lookship->shp_type].m_vrnge);
131 range = range * (lookship->shp_effic / 100.0);
132 smcp = &mchr[(int)lookship->shp_type];
133 if (smcp->m_flags & M_SUB)
134 range = MIN(range, 1);
135 for (i = 0; NULL != (sp = getshipp(i)); i++) {
136 if (sp->shp_own == player->cnum || sp->shp_own == 0)
138 dist = mapdist(sp->shp_x, sp->shp_y,
139 lookship->shp_x, lookship->shp_y);
140 if (dist > ship_max_interdiction_range)
142 tmcp = &mchr[(int)sp->shp_type];
143 if (smcp->m_flags & M_SUB)
144 vrange = (int)(sp->shp_visib * range / 30.0);
146 vrange = (int)(sp->shp_visib * range / 20.0);
147 getsect(sp->shp_x, sp->shp_y, §);
148 if (sect.sct_type != SCT_WATER)
149 vrange = MAX(1, vrange);
152 if (smcp->m_flags & M_SUB) {
153 if (tmcp->m_flags & M_SONAR && dist < 2) {
154 if (sp->shp_own != 0)
156 "%s detected surfacing noises in %s.\n",
158 xyas(lookship->shp_x, lookship->shp_y,
161 if (dist == 0 && (tmcp->m_flags & M_SUB) == 0)
162 if (sp->shp_own != 0)
164 "Periscope spotted in %s by %s\n",
165 xyas(lookship->shp_x, lookship->shp_y,
166 sp->shp_own), prship(sp));
168 /* subs at sea only seen by sonar */
169 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
171 pr("%s (#%d) %s @ %s\n",
172 cname(sp->shp_own), sp->shp_own, prship(sp),
173 xyas(sp->shp_x, sp->shp_y, player->cnum));
175 setcont(player->cnum, sp->shp_own, FOUND_LOOK);
184 struct lndstr myland;
192 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
194 if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
195 logerror("malloc failed in llook\n");
196 pr("Memory error. Tell the deity.\n");
199 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
200 while (nxtitem(&ni, &myland)) {
203 if (myland.lnd_ship >= 0)
205 if (myland.lnd_land >= 0)
207 /* Spies don't need military to do a "llook". Other
209 if ((lnd_getmil(&myland) <= 0) &&
210 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
213 for (i = 0; i <= 6; i++) {
214 x = diroff[i][0] + myland.lnd_x;
215 y = diroff[i][1] + myland.lnd_y;
216 if (emp_getbit(x, y, bitmap))
218 emp_setbit(x, y, bitmap);
219 getsect(x, y, §);
220 if (sect.sct_type == SCT_WATER)
225 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
226 pr(dchr[sect.sct_type].d_name);
227 changed += map_set(player->cnum, x, y,
228 dchr[sect.sct_type].d_mnem, 0);
229 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
230 roundintby((int)sect.sct_effic, 10));
231 civ = sect.sct_item[I_CIVIL];
232 mil = sect.sct_item[I_MILIT];
234 pr("with %s%d civ ", player->owner ? "" :
235 "approx ", player->owner ? civ : roundintby(civ, 10));
237 pr("with %s%d mil ", player->owner ? "" :
238 "approx ", player->owner ? mil : roundintby(mil, 10));
239 pr("@ %s\n", xyas(x, y, player->cnum));
241 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
246 writemap(player->cnum);
252 look_land(struct lndstr *lookland)
262 drange = techfact(lookland->lnd_tech, (double)lookland->lnd_spy);
263 drange = (drange * ((double)lookland->lnd_effic / 100.0));
264 range = ldround(drange, 1);
269 for (i = 0; NULL != (lp = getlandp(i)); i++) {
270 if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
272 if (lp->lnd_ship >= 0)
274 /* Don't always see spies */
275 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
276 /* If it's on a ship or unit, assume it's hidden
277 enough not to be seen */
278 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
280 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
283 vrange = ldround((double)((lp->lnd_vis * range) / 20.0), 1);
284 dist = mapdist(lp->lnd_x, lp->lnd_y,
285 lookland->lnd_x, lookland->lnd_y);
289 pr("%s (#%d) %s (approx %d mil) @ %s\n",
290 cname(lp->lnd_own), lp->lnd_own,
291 prland(lp), ldround((double)total_mil(lp), 20),
292 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
294 setcont(player->cnum, lp->lnd_own, FOUND_LOOK);
296 for (i = 0; NULL != (pp = getplanep(i)); i++) {
297 if (pp->pln_own == player->cnum || pp->pln_own == 0)
299 if (pp->pln_ship >= 0)
301 if (pp->pln_flags & PLN_LAUNCHED)
303 vrange = ldround((double)((10 * range) / 20.0), 1);
304 dist = mapdist(pp->pln_x, pp->pln_y,
305 lookland->lnd_x, lookland->lnd_y);
309 pr("%s (#%d) %s @ %s\n",
310 cname(pp->pln_own), pp->pln_own,
311 prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));
313 setcont(player->cnum, pp->pln_own, FOUND_LOOK);