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 * navi.c: Navigate ships and such
30 * Known contributors to this file:
31 * Ken Stevens, 1995 (rewritten)
47 struct nstr_item ni_ship;
48 struct emp_qelem ship_list;
49 double minmob, maxmob;
53 struct empobj *leader;
60 char pathtaken[1024]; /* Doubtful we'll have a path longer than this */
65 if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1]))
67 shp_sel(&ni_ship, &ship_list);
68 shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
69 if (QEMPTY(&ship_list)) {
73 leader = get_leader(&ship_list);
74 leader_uid = leader->uid;
75 pr("Flagship is %s\n", obj_nameof(leader));
76 if (player->argp[2]) {
77 strcpy(buf, player->argp[2]);
78 if (!(cp = shp_path(together, (struct shpstr *)leader, buf)))
83 while (!QEMPTY(&ship_list)) {
86 if (cp == NULL || *cp == '\0' || stopping) {
88 shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
89 if (QEMPTY(&ship_list)) {
90 pr("No ships left\n");
91 if (strlen(pathtaken) > 0) {
92 pathtaken[strlen(pathtaken) - 1] = '\0';
93 if (strlen(pathtaken) > 0)
94 pr("Path taken: %s\n", pathtaken);
98 leader = get_leader(&ship_list);
99 if (leader->uid != leader_uid) {
100 leader_uid = leader->uid;
101 pr_leader_change(leader);
106 nav_map(leader->x, leader->y,
107 !(mchr[(int)leader->type].m_flags & M_SUB));
110 sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob,
111 minmob, xyas(leader->x, leader->y, player->cnum));
112 cp = getstring(prompt, buf);
113 /* Just in case any of our ships were shelled while we were
114 * at the prompt, we call shp_nav() again.
116 shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
117 if (QEMPTY(&ship_list)) {
118 pr("No ships left\n");
119 if (strlen(pathtaken) > 0) {
120 pathtaken[strlen(pathtaken) - 1] = '\0';
121 if (strlen(pathtaken) > 0)
122 pr("Path taken: %s\n", pathtaken);
126 leader = get_leader(&ship_list);
127 if (leader->uid != leader_uid) {
128 leader_uid = leader->uid;
129 pr_leader_change(leader);
133 if (cp && !(cp = shp_path(together, (struct shpstr *)leader, buf)))
136 radmapnopr(leader->x, leader->y, (int)leader->effic,
137 (int)techfact(leader->tech,
138 mchr[(int)leader->type].m_vrnge),
139 (mchr[(int)leader->type].m_flags & M_SONAR)
140 ? techfact(leader->tech, 1.0) : 0.0);
141 if (cp == NULL || *cp == '\0')
142 cp = &dirch[DIR_STOP];
143 dir = chkdir(*cp, DIR_STOP, DIR_VIEW);
146 shp_view(&ship_list);
148 stopping |= shp_nav_one_sector(&ship_list, dir, player->cnum, together);
157 ac = parse(cp, player->argp, NULL, scanspace, NULL);
159 sprintf(dp, "%d", leader->uid);
160 player->argp[1] = dp;
165 switch (*player->argp[0]) {
172 do_map(bmap_flag, EF_SHIP, player->argp[1], player->argp[2]);
177 switch_leader(&ship_list, -1);
179 switch_leader(&ship_list, atoi(player->argp[1]));
180 leader = get_leader(&ship_list);
181 if (leader->uid != leader_uid) {
182 leader_uid = leader->uid;
183 pr_leader_change(leader);
187 shp_list(&ship_list);
190 stopping |= shp_sweep(&ship_list, 1, 1, player->cnum);
208 player->argp[2] = player->argp[1];
209 sprintf(dp, "%d", leader->uid);
210 player->argp[1] = dp;
217 direrr("`%c' to stop", ", `%c' to view, ", 0);
218 pr("`i' to list ships, `f' to change flagship,\n");
219 pr("`r' to radar, `s' to sonar, `l' to look, `M' to map, `B' to bmap,\n");
220 pr("`d' to drop mines, and `m' to minesweep\n");
223 if (strlen(pathtaken) > 0) {
224 pathtaken[strlen(pathtaken) - 1] = '\0';
225 if (strlen(pathtaken) > 0)
226 pr("Path taken: %s\n", pathtaken);
232 nav_map(int x, int y, int show_designations)
240 /* Note this is not re-entrant anyway, so we keep the buffers
242 static unsigned char *bitmap = NULL;
243 static char *wmapbuf = NULL;
244 static char **wmap = NULL;
248 wmapbuf = malloc(WORLD_Y * MAPWIDTH(1));
250 wmap = malloc(WORLD_Y * sizeof(*wmap));
251 if (wmap && wmapbuf) {
252 for (i = 0; i < WORLD_Y; i++)
253 wmap[i] = &wmapbuf[MAPWIDTH(1) * i];
260 bitmap = malloc((WORLD_X * WORLD_Y) / 8);
261 if (!wmapbuf || !wmap || !bitmap) {
262 pr("Memory error, tell the deity.\n");
263 logerror("malloc failed in navi\n");
266 memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
267 snxtsct_dist(&ns, x, y, 1);
268 np = getnatp(player->cnum);
269 xyrelrange(np, &ns.range, &range);
270 blankfill(wmapbuf, &ns.range, 1);
271 while (nxtsct(&ns, §)) {
272 ptr = &wmap[ns.dy][ns.dx];
273 *ptr = dchr[sect.sct_type].d_mnem;
274 if (!show_designations &&
275 sect.sct_own != player->cnum &&
276 sect.sct_type != SCT_WATER &&
277 sect.sct_type != SCT_BSPAN && sect.sct_type != SCT_HARBR)
279 changed += map_set(player->cnum, sect.sct_x, sect.sct_y, *ptr, 0);
281 * We do it this way so that 'x' and 'X'
282 * bdesignations will show up. This can
283 * be used to mark mined sectors. So, the
284 * player will see the current des, UNLESS
285 * they've marked the sector 'x' or 'X',
286 * in which case they'll see that.
289 *ptr = player->bmap[sctoff(sect.sct_x, sect.sct_y)];
292 writemap(player->cnum);
293 for (i = 0; i < ns.range.height; i++)