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 * move.c: Move something somewhere.
30 * Known contributors to this file:
47 #include "prototypes.h"
49 static int move_map(s_char *what, coord curx, coord cury, s_char *arg);
52 move_ground(s_char *what, struct sctstr *start, struct sctstr *end,
53 double mobility, double weight, s_char *path,
54 int (*map) (s_char *, coord, coord, s_char *), int exploring,
60 struct sctstr sect, ending_sect;
61 struct sctstr next, dsect;
63 coord curx, cury, oldx, oldy;
66 s_char *movstr, *BestLandPath(s_char *, struct sctstr *,
67 struct sctstr *, double *, int);
73 int takedam = (*dam), out = 0;
82 if (path && sarg_xy(path, &dx, &dy) && getsect(dx, dy, &ending_sect)) {
83 if ((ending_sect.sct_x == start->sct_x) &&
84 (ending_sect.sct_y == start->sct_y)) {
85 pr("Start sector is ending sector!\n");
88 pr("Looking for best path to %s\n", path);
90 BestLandPath(buf2, start, &ending_sect, &total_mcost,
92 if (exploring && (path != (s_char *)0)) /* take off the 'h' */
93 *(path + strlen(path) - 1) = '\0';
94 if (path == (s_char *)0)
95 pr("No owned path exists!\n");
97 pr("Using best path '%s', movement cost %1.3f\n",
99 strncpy(bpath, path, sizeof(bpath));
102 if ((total_mcost * weight) > mobility) {
103 pr("Not enough mobility to go all the way. Nothing moved.\n");
114 if (getsect(curx, cury, §) < 0) {
115 logerror("move_path: getsect %d,%d", curx, cury);
123 if (movstr == 0 || *movstr == 0) {
125 map(what, curx, cury, (s_char *)0);
127 move_map(what, curx, cury, (s_char *)0);
129 sprintf(prompt, "<%.1f: %c %s> ", mobility,
130 dchr[sect.sct_type].d_mnem,
131 xyas(sect.sct_x, sect.sct_y, player->cnum));
132 movstr = getstring(prompt, buf);
134 if (movstr && sarg_xy(movstr, &dx, &dy)) {
135 if (getsect(dx, dy, &dsect)) {
137 BestLandPath(buf2, §, &dsect, &mv_cost, MOB_ROAD);
139 pr("Invalid destination sector!\n");
140 movstr = (s_char *)0;
143 if (movstr == (s_char *)0) {
144 pr("Can't get to %s from here!\n",
145 xyas(dx, dy, player->cnum));
146 movstr = (s_char *)0;
148 if ((mv_cost * weight) > mobility) {
149 pr("Not enough mobility to go all the way. Nothing moved.\n");
150 movstr = (s_char *)0;
152 pr("Using best path '%s', movement cost %1.3f\n",
154 strncpy(bpath, movstr, sizeof(bpath));
159 if (movstr == 0 || *movstr == 0)
161 if ((dir = chkdir(*movstr, DIR_STOP, DIR_MAP)) < 0) {
162 pr("\"%c\" is not legal...", *movstr);
163 direrr("'%c' to stop ", "'%c' to view ", "& '%c' to map\n");
168 if (dir == DIR_MAP) {
170 map(what, curx, cury, movstr + 1);
173 } else if (dir == DIR_STOP)
175 else if (dir == DIR_VIEW) {
176 pr("%d%% %s with %d civilians.\n", sect.sct_effic,
177 dchr[sect.sct_type].d_name,
178 getvar(V_CIVIL, (s_char *)§, EF_SECTOR));
182 * now see if we can move into the
183 * next sector. Mobility, terrain,
184 * or ownership may prevent us.
186 tmpx += diroff[dir][0];
187 tmpy += diroff[dir][1];
188 if (getsect(tmpx, tmpy, &next) < 0) {
189 pr("You can't go there...\n");
194 if ((next.sct_type == SCT_SANCT) &&
195 (next.sct_own != player->cnum)) {
196 pr("Converts, huh?\n");
198 intcost = (int)total_mcost;
199 if (chance(total_mcost - intcost))
203 getvec(VT_ITEM, vec, (s_char *)&next, EF_SECTOR);
204 sect_mcost = sector_mcost(&next, MOB_ROAD);
205 if ((!player->owner && (!exploring ||
206 (vec[I_MILIT] || vec[I_CIVIL]))) ||
207 sect_mcost == -1.0) {
208 /* already-owned, or prohibited terrain */
209 pr("You can't go there...\n");
213 sect_mcost *= weight;
214 if (sect_mcost > mobility) {
215 pr("Not enough mobility. ");
216 pr("You can't go there...\n");
220 mobility -= sect_mcost;
221 total_mcost += sect_mcost;
225 if (cury != start->sct_y)
227 if (curx != start->sct_x)
233 *dam += check_lmines(sect.sct_x, sect.sct_y, weight);
237 * Check and see if anyone will interdict us
239 if (takedam && chance(weight / 100.0) &&
240 ((curx != oldx) || (cury != oldy)))
242 ground_interdict(curx, cury, player->cnum, "commodities");
247 intcost = (int)total_mcost;
250 if ((start->sct_x == end->sct_x) && (start->sct_y == end->sct_y)
254 if (chance(total_mcost - intcost))
262 move_map(s_char *what, coord curx, coord cury, s_char *arg)
274 np = getnatp(player->cnum);
275 rel_x = xrel(np, curx);
276 rel_y = yrel(np, cury);
277 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
280 /* This is necessary, otherwise move_map would attempt to pay */
281 /* attention to the conditional arguments left behind by such */
282 /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */
283 /* 100% efficienct sects, and get all screwed up --ts */
284 if (!snxtsct(&ns, range))
287 while (i < 7 && nxtsct(&ns, §)) {
288 view[i] = dchr[sect.sct_type].d_mnem;
289 switch (sect.sct_type) {
297 if (sect.sct_own != player->cnum && !player->god)
301 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
305 writemap(player->cnum);
306 if (!getsect(curx, cury, §))
308 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
309 pr(" %c %c eff mob civ mil uw food work avail\n",
311 pr(" %c %c %c %3d %3d %4d %4d %4d %4d %3d %3d\n",
312 view[2], view[3], view[4],
313 sect.sct_effic, sect.sct_mobil, vec[I_CIVIL], vec[I_MILIT],
314 vec[I_UW], vec[I_FOOD], sect.sct_work, sect.sct_avail);
315 pr(" %c %c\n", view[5], view[6]);
320 fly_map(coord curx, coord cury)
330 np = getnatp(player->cnum);
331 rel_x = xrel(np, curx);
332 rel_y = yrel(np, cury);
333 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
336 /* This is necessary, otherwise move_map would attempt to pay */
337 /* attention to the conditional arguments left behind by such */
338 /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */
339 /* 100% efficienct sects, and get all screwed up --ts */
341 if (!snxtsct(&ns, range))
344 while (i < 7 && nxtsct(&ns, §)) {
345 if (!(view[i] = player->bmap[sctoff(ns.x, ns.y)]))
350 pr(" %c %c\n", view[0], view[1]);
351 pr(" %c %c %c\n", view[2], view[3], view[4]);
352 pr(" %c %c\n", view[5], view[6]);
357 check_lmines(coord x, coord y, double weight)
363 getsect(x, y, §);
364 mines = getvar(V_MINE, (s_char *)§, EF_SECTOR);
366 sect.sct_oldown != player->cnum &&
367 chance(DMINE_LHITCHANCE(mines)) && chance(weight / 100.0)) {
369 pr("Blammo! Landmines detected! in %s ",
370 xyas(sect.sct_x, sect.sct_y, player->cnum));
373 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
375 pr("%d damage sustained.\n", dam);