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 bzero((s_char *)bitmap, (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),
91 pr(dchr[sect.sct_type].d_name);
92 changed += map_set(player->cnum, x, y,
93 dchr[sect.sct_type].d_mnem, 0);
94 pr(" %d%% efficient ", player->owner ? sect.sct_effic :
95 roundintby((int)sect.sct_effic, 10));
96 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
97 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
99 pr("with %s%d civ ", player->owner ? "" : "approx ",
100 player->owner ? civ : roundintby(civ, 10));
102 pr("with %s%d mil ", player->owner ? "" : "approx ",
103 player->owner ? mil : roundintby(mil, 10));
104 pr("@ %s\n", xyas(x, y, player->cnum));
106 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
111 writemap(player->cnum);
112 free((s_char *)bitmap);
117 look_ship(register struct shpstr *lookship)
119 register struct shpstr *sp;
120 register struct mchrstr *smcp;
121 register struct mchrstr *tmcp;
122 extern int ship_max_interdiction_range;
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) {
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)
164 "Periscope spotted in %s by %s\n",
165 xyas(lookship->shp_x, lookship->shp_y,
169 /* subs at sea only seen by sonar */
170 if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER)
172 pr("%s (#%d) %s @ %s\n",
173 cname(sp->shp_own), sp->shp_own, prship(sp),
174 xyas(sp->shp_x, sp->shp_y, player->cnum));
178 static void look_land(register struct lndstr *lookland);
185 struct lndstr myland;
193 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
195 if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
196 logerror("malloc failed in llook\n");
197 pr("Memory error. Tell the deity.\n");
200 bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8);
201 while (nxtitem(&ni, (s_char *)&myland)) {
204 if (myland.lnd_ship >= 0)
206 if (myland.lnd_land >= 0)
208 /* Spies don't need military to do a "llook". Other
210 if ((lnd_getmil(&myland) <= 0) &&
211 !(lchr[(int)myland.lnd_type].l_flags & L_SPY))
214 for (i = 0; i <= 6; i++) {
215 x = diroff[i][0] + myland.lnd_x;
216 y = diroff[i][1] + myland.lnd_y;
217 if (emp_getbit(x, y, bitmap))
219 emp_setbit(x, y, bitmap);
220 getsect(x, y, §);
221 if (sect.sct_type == SCT_WATER)
226 pr("%s (#%d) ", cname(sect.sct_own),
228 pr(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 = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
234 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
236 pr("with %s%d civ ", player->owner ? "" :
238 player->owner ? civ : roundintby(civ, 10));
240 pr("with %s%d mil ", player->owner ? "" :
242 player->owner ? mil : roundintby(mil, 10));
243 pr("@ %s\n", xyas(x, y, player->cnum));
245 setcont(player->cnum, sect.sct_own, FOUND_LOOK);
250 writemap(player->cnum);
251 free((s_char *)bitmap);
256 look_land(register struct lndstr *lookland)
258 register struct plnstr *pp;
259 register struct lndstr *lp;
265 double techfact(int, double);
268 drange = techfact(lookland->lnd_tech,
269 (double) lookland->lnd_spy);
270 drange = (drange * ((double)lookland->lnd_effic / 100.0));
271 range = ldround(drange,1);
276 for (i=0; NULL != (lp = getlandp(i)); i++) {
277 if (lp->lnd_own == player->cnum || lp->lnd_own == 0)
279 if (lp->lnd_ship >= 0)
281 /* Don't always see spies */
282 if (lchr[(int)lp->lnd_type].l_flags & L_SPY) {
283 /* If it's on a ship or unit, assume it's hidden
284 enough not to be seen */
285 if (lp->lnd_ship >= 0 || lp->lnd_land >= 0)
287 odds = (double)(100 - lp->lnd_effic) + 0.10;
291 vrange = ldround((double)((lp->lnd_vis
293 dist = mapdist(lp->lnd_x, lp->lnd_y,
294 lookland->lnd_x, lookland->lnd_y);
298 pr("%s (#%d) %s (approx %d mil) @ %s\n",
299 cname(lp->lnd_own), lp->lnd_own,
300 prland(lp), ldround((double)total_mil(lp), 20),
301 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
303 for (i=0; NULL != (pp = getplanep(i)); i++) {
304 if (pp->pln_own == player->cnum || pp->pln_own == 0)
306 if (pp->pln_ship >= 0)
308 if (pp->pln_flags & PLN_LAUNCHED)
310 vrange = ldround((double)((10* range)/20.0),1);
311 dist = mapdist(pp->pln_x, pp->pln_y,
312 lookland->lnd_x, lookland->lnd_y);
316 pr("%s (#%d) %s @ %s\n",
317 cname(pp->pln_own), pp->pln_own,
319 xyas(pp->pln_x, pp->pln_y, player->cnum));