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 extern 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",
100 bcopy(path, bpath, strlen(path));
103 if ((total_mcost * weight) > mobility) {
104 pr("Not enough mobility to go all the way. Nothing moved.\n");
115 if (getsect(curx, cury, §) < 0) {
116 logerror("move_path: getsect %d,%d", curx, cury);
124 if (movstr == 0 || *movstr == 0) {
126 map(what, curx, cury, (s_char *)0);
128 move_map(what, curx, cury, (s_char *)0);
130 sprintf(prompt, "<%.1f: %c %s> ", mobility,
131 dchr[sect.sct_type].d_mnem,
132 xyas(sect.sct_x, sect.sct_y, player->cnum));
133 movstr = getstring(prompt, buf);
135 if (movstr && sarg_xy(movstr, &dx, &dy)) {
136 if (getsect(dx, dy, &dsect)) {
138 BestLandPath(buf2, §, &dsect, &mv_cost, MOB_ROAD);
140 pr("Invalid destination sector!\n");
141 movstr = (s_char *)0;
144 if (movstr == (s_char *)0) {
145 pr("Can't get to %s from here!\n",
146 xyas(dx, dy, player->cnum));
147 movstr = (s_char *)0;
149 if ((mv_cost * weight) > mobility) {
150 pr("Not enough mobility to go all the way. Nothing moved.\n");
151 movstr = (s_char *)0;
153 pr("Using best path '%s', movement cost %1.3f\n",
156 bcopy(movstr, bpath, strlen(movstr));
161 if (movstr == 0 || *movstr == 0)
163 if ((dir = chkdir(*movstr, DIR_STOP, DIR_MAP)) < 0) {
164 pr("\"%c\" is not legal...", *movstr);
165 direrr("'%c' to stop ", "'%c' to view ", "& '%c' to map\n");
170 if (dir == DIR_MAP) {
172 map(what, curx, cury, movstr + 1);
175 } else if (dir == DIR_STOP)
177 else if (dir == DIR_VIEW) {
178 pr("%d%% %s with %d civilians.\n", sect.sct_effic,
179 dchr[sect.sct_type].d_name,
180 getvar(V_CIVIL, (s_char *)§, EF_SECTOR));
184 * now see if we can move into the
185 * next sector. Mobility, terrain,
186 * or ownership may prevent us.
188 tmpx += diroff[dir][0];
189 tmpy += diroff[dir][1];
190 if (getsect(tmpx, tmpy, &next) < 0) {
191 pr("You can't go there...\n");
196 if ((next.sct_type == SCT_SANCT) &&
197 (next.sct_own != player->cnum)) {
198 pr("Converts, huh?\n");
200 intcost = (int)total_mcost;
201 if (chance(total_mcost - intcost))
205 getvec(VT_ITEM, vec, (s_char *)&next, EF_SECTOR);
206 sect_mcost = sector_mcost(&next, MOB_ROAD);
207 if ((!player->owner && (!exploring ||
208 (vec[I_MILIT] || vec[I_CIVIL]))) ||
209 sect_mcost == -1.0) {
210 /* already-owned, or prohibited terrain */
211 pr("You can't go there...\n");
215 sect_mcost *= weight;
216 if (sect_mcost > mobility) {
217 pr("Not enough mobility. ");
218 pr("You can't go there...\n");
222 mobility -= sect_mcost;
223 total_mcost += sect_mcost;
227 if (cury != start->sct_y)
229 if (curx != start->sct_x)
235 *dam += check_lmines(sect.sct_x, sect.sct_y, weight);
239 * Check and see if anyone will interdict us
241 if (takedam && chance(weight / 100.0) &&
242 ((curx != oldx) || (cury != oldy)))
244 ground_interdict(curx, cury, player->cnum, "commodities");
249 intcost = (int)total_mcost;
252 if ((start->sct_x == end->sct_x) && (start->sct_y == end->sct_y)
256 if (chance(total_mcost - intcost))
264 move_map(s_char *what, coord curx, coord cury, s_char *arg)
276 np = getnatp(player->cnum);
277 rel_x = xrel(np, curx);
278 rel_y = yrel(np, cury);
279 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
282 /* This is necessary, otherwise move_map would attempt to pay */
283 /* attention to the conditional arguments left behind by such */
284 /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */
285 /* 100% efficienct sects, and get all screwed up --ts */
286 if (!snxtsct(&ns, range))
289 while (i < 7 && nxtsct(&ns, §)) {
290 view[i] = dchr[sect.sct_type].d_mnem;
291 switch (sect.sct_type) {
299 if (sect.sct_own != player->cnum && !player->god)
303 changed += map_set(player->cnum, ns.x, ns.y, view[i], 0);
307 writemap(player->cnum);
308 if (!getsect(curx, cury, §))
310 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
311 pr(" %c %c eff mob civ mil uw food work avail\n",
313 pr(" %c %c %c %3d %3d %4d %4d %4d %4d %3d %3d\n",
314 view[2], view[3], view[4],
315 sect.sct_effic, sect.sct_mobil, vec[I_CIVIL], vec[I_MILIT],
316 vec[I_UW], vec[I_FOOD], sect.sct_work, sect.sct_avail);
317 pr(" %c %c\n", view[5], view[6]);
322 fly_map(coord curx, coord cury)
332 np = getnatp(player->cnum);
333 rel_x = xrel(np, curx);
334 rel_y = yrel(np, cury);
335 sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1,
338 /* This is necessary, otherwise move_map would attempt to pay */
339 /* attention to the conditional arguments left behind by such */
340 /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */
341 /* 100% efficienct sects, and get all screwed up --ts */
343 if (!snxtsct(&ns, range))
346 while (i < 7 && nxtsct(&ns, §)) {
347 if (!(view[i] = player->bmap[sctoff(ns.x, ns.y)]))
352 pr(" %c %c\n", view[0], view[1]);
353 pr(" %c %c %c\n", view[2], view[3], view[4]);
354 pr(" %c %c\n", view[5], view[6]);
359 check_lmines(coord x, coord y, double weight)
365 getsect(x, y, §);
366 mines = getvar(V_MINE, (s_char *)§, EF_SECTOR);
368 sect.sct_oldown != player->cnum &&
369 chance(DMINE_LHITCHANCE(mines)) && chance(weight / 100.0)) {
371 pr("Blammo! Landmines detected! in %s ",
372 xyas(sect.sct_x, sect.sct_y, player->cnum));
375 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
377 pr("%d damage sustained.\n", dam);