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 * look.c: Lookout from a ship or land unit
30 * Known contributors to this file:
50 static void look_ship(register struct shpstr *lookship);
65 if (!snxtitem(&ni, EF_SHIP, player->argp[1]))
67 if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
68 logerror("malloc failed in look\n");
69 pr("Memory error. Tell the deity.\n");
72 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
73 while (nxtitem(&ni, (s_char *)&myship)) {
77 for (i = 0; i <= 6; i++) {
78 x = diroff[i][0] + myship.shp_x;
79 y = diroff[i][1] + myship.shp_y;
80 if (emp_getbit(x, y, bitmap))
82 emp_setbit(x, y, bitmap);
84 if (sect.sct_type == SCT_WATER)
89 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
90 pr(dchr[sect.sct_type].d_name);
91 changed += map_set(player->cnum, x, y,
92 dchr[sect.sct_type].d_mnem, 0);
93 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
94 roundintby((int)sect.sct_effic, 10));
95 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
96 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
98 pr("with %s%d civ ", player->owner ? "" : "approx ",
99 player->owner ? civ : roundintby(civ, 10));
101 pr("with %s%d mil ", player->owner ? "" : "approx ",
102 player->owner ? mil : roundintby(mil, 10));
103 pr("@ %s\n", xyas(x, y, player->cnum));
105 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
110 writemap(player->cnum);
111 free((s_char *)bitmap);
116 look_ship(register struct shpstr *lookship)
118 register struct shpstr *sp;
119 register struct mchrstr *smcp;
120 register struct mchrstr *tmcp;
127 range = (int)techfact(lookship->shp_tech,
128 (double)mchr[(int)lookship->shp_type].m_vrnge);
129 range = range * (lookship->shp_effic / 100.0);
130 smcp = &mchr[(int)lookship->shp_type];
131 if (smcp->m_flags & M_SUB)
132 range = min(range, 1);
133 for (i = 0; NULL != (sp = getshipp(i)); i++) {
134 if (sp->shp_own == player->cnum || sp->shp_own == 0)
136 dist = mapdist(sp->shp_x, sp->shp_y,
137 lookship->shp_x, lookship->shp_y);
138 if (dist > ship_max_interdiction_range)
140 tmcp = &mchr[(int)sp->shp_type];
141 if (smcp->m_flags & M_SUB)
142 vrange = (int)(sp->shp_visib * range / 30.0);
144 vrange = (int)(sp->shp_visib * range / 20.0);
145 getsect(sp->shp_x, sp->shp_y, §);
146 if (sect.sct_type != SCT_WATER)
147 vrange = max(1, vrange);
150 if (smcp->m_flags & M_SUB) {
151 if (tmcp->m_flags & M_SONAR && dist < 2) {
152 if (sp->shp_own != 0)
154 "%s detected surfacing noises in %s.\n",
156 xyas(lookship->shp_x, lookship->shp_y,
159 if (dist == 0 && (tmcp->m_flags & M_SUB) == 0)
160 if (sp->shp_own != 0)
162 "Periscope spotted in %s by %s\n",
163 xyas(lookship->shp_x, lookship->shp_y,
164 sp->shp_own), prship(sp));
166 /* subs at sea only seen by sonar */
167 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
169 pr("%s (#%d) %s @ %s\n",
170 cname(sp->shp_own), sp->shp_own, prship(sp),
171 xyas(sp->shp_x, sp->shp_y, player->cnum));
175 static void look_land(register struct lndstr *lookland);
182 struct lndstr myland;
190 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
192 if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
193 logerror("malloc failed in llook\n");
194 pr("Memory error. Tell the deity.\n");
197 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
198 while (nxtitem(&ni, (s_char *)&myland)) {
201 if (myland.lnd_ship >= 0)
203 if (myland.lnd_land >= 0)
205 /* Spies don't need military to do a "llook". Other
207 if ((lnd_getmil(&myland) <= 0) &&
208 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
211 for (i = 0; i <= 6; i++) {
212 x = diroff[i][0] + myland.lnd_x;
213 y = diroff[i][1] + myland.lnd_y;
214 if (emp_getbit(x, y, bitmap))
216 emp_setbit(x, y, bitmap);
217 getsect(x, y, §);
218 if (sect.sct_type == SCT_WATER)
223 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
224 pr(dchr[sect.sct_type].d_name);
225 changed += map_set(player->cnum, x, y,
226 dchr[sect.sct_type].d_mnem, 0);
227 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
228 roundintby((int)sect.sct_effic, 10));
229 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
230 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
232 pr("with %s%d civ ", player->owner ? "" :
233 "approx ", player->owner ? civ : roundintby(civ, 10));
235 pr("with %s%d mil ", player->owner ? "" :
236 "approx ", player->owner ? mil : roundintby(mil, 10));
237 pr("@ %s\n", xyas(x, y, player->cnum));
239 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
244 writemap(player->cnum);
245 free((s_char *)bitmap);
250 look_land(register struct lndstr *lookland)
252 register struct plnstr *pp;
253 register struct lndstr *lp;
260 drange = techfact(lookland->lnd_tech, (double)lookland->lnd_spy);
261 drange = (drange * ((double)lookland->lnd_effic / 100.0));
262 range = ldround(drange, 1);
267 for (i = 0; NULL != (lp = getlandp(i)); i++) {
268 if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
270 if (lp->lnd_ship >= 0)
272 /* Don't always see spies */
273 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
274 /* If it's on a ship or unit, assume it's hidden
275 enough not to be seen */
276 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
278 if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
281 vrange = ldround((double)((lp->lnd_vis * range) / 20.0), 1);
282 dist = mapdist(lp->lnd_x, lp->lnd_y,
283 lookland->lnd_x, lookland->lnd_y);
287 pr("%s (#%d) %s (approx %d mil) @ %s\n",
288 cname(lp->lnd_own), lp->lnd_own,
289 prland(lp), ldround((double)total_mil(lp), 20),
290 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
292 for (i = 0; NULL != (pp = getplanep(i)); i++) {
293 if (pp->pln_own == player->cnum || pp->pln_own == 0)
295 if (pp->pln_ship >= 0)
297 if (pp->pln_flags & PLN_LAUNCHED)
299 vrange = ldround((double)((10 * range) / 20.0), 1);
300 dist = mapdist(pp->pln_x, pp->pln_y,
301 lookland->lnd_x, lookland->lnd_y);
305 pr("%s (#%d) %s @ %s\n",
306 cname(pp->pln_own), pp->pln_own,
307 prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));