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;
121 extern int ship_max_interdiction_range;
128 range = (int)techfact(lookship->shp_tech,
129 (double)mchr[(int)lookship->shp_type].m_vrnge);
130 range = range * (lookship->shp_effic / 100.0);
131 smcp = &mchr[(int)lookship->shp_type];
132 if (smcp->m_flags & M_SUB)
133 range = min(range, 1);
134 for (i = 0; NULL != (sp = getshipp(i)); i++) {
135 if (sp->shp_own == player->cnum || sp->shp_own == 0)
137 dist = mapdist(sp->shp_x, sp->shp_y,
138 lookship->shp_x, lookship->shp_y);
139 if (dist > ship_max_interdiction_range)
141 tmcp = &mchr[(int)sp->shp_type];
142 if (smcp->m_flags & M_SUB)
143 vrange = (int)(sp->shp_visib * range / 30.0);
145 vrange = (int)(sp->shp_visib * range / 20.0);
146 getsect(sp->shp_x, sp->shp_y, §);
147 if (sect.sct_type != SCT_WATER)
148 vrange = max(1, vrange);
151 if (smcp->m_flags & M_SUB) {
152 if (tmcp->m_flags & M_SONAR && dist < 2) {
153 if (sp->shp_own != 0)
155 "%s detected surfacing noises in %s.\n",
157 xyas(lookship->shp_x, lookship->shp_y,
160 if (dist == 0 && (tmcp->m_flags & M_SUB) == 0)
161 if (sp->shp_own != 0)
163 "Periscope spotted in %s by %s\n",
164 xyas(lookship->shp_x, lookship->shp_y,
165 sp->shp_own), prship(sp));
167 /* subs at sea only seen by sonar */
168 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
170 pr("%s (#%d) %s @ %s\n",
171 cname(sp->shp_own), sp->shp_own, prship(sp),
172 xyas(sp->shp_x, sp->shp_y, player->cnum));
176 static void look_land(register struct lndstr *lookland);
183 struct lndstr myland;
191 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
193 if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
194 logerror("malloc failed in llook\n");
195 pr("Memory error. Tell the deity.\n");
198 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
199 while (nxtitem(&ni, (s_char *)&myland)) {
202 if (myland.lnd_ship >= 0)
204 if (myland.lnd_land >= 0)
206 /* Spies don't need military to do a "llook". Other
208 if ((lnd_getmil(&myland) <= 0) &&
209 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
212 for (i = 0; i <= 6; i++) {
213 x = diroff[i][0] + myland.lnd_x;
214 y = diroff[i][1] + myland.lnd_y;
215 if (emp_getbit(x, y, bitmap))
217 emp_setbit(x, y, bitmap);
218 getsect(x, y, §);
219 if (sect.sct_type == SCT_WATER)
224 pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own);
225 pr(dchr[sect.sct_type].d_name);
226 changed += map_set(player->cnum, x, y,
227 dchr[sect.sct_type].d_mnem, 0);
228 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
229 roundintby((int)sect.sct_effic, 10));
230 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
231 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
233 pr("with %s%d civ ", player->owner ? "" :
234 "approx ", player->owner ? civ : roundintby(civ, 10));
236 pr("with %s%d mil ", player->owner ? "" :
237 "approx ", player->owner ? mil : roundintby(mil, 10));
238 pr("@ %s\n", xyas(x, y, player->cnum));
240 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
245 writemap(player->cnum);
246 free((s_char *)bitmap);
251 look_land(register struct lndstr *lookland)
253 register struct plnstr *pp;
254 register struct lndstr *lp;
260 double techfact(int, double);
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 for (i = 0; NULL != (pp = getplanep(i)); i++) {
295 if (pp->pln_own == player->cnum || pp->pln_own == 0)
297 if (pp->pln_ship >= 0)
299 if (pp->pln_flags & PLN_LAUNCHED)
301 vrange = ldround((double)((10 * range) / 20.0), 1);
302 dist = mapdist(pp->pln_x, pp->pln_y,
303 lookland->lnd_x, lookland->lnd_y);
307 pr("%s (#%d) %s @ %s\n",
308 cname(pp->pln_own), pp->pln_own,
309 prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum));