2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * move.c: Move commodities around
29 * Known contributors to this file:
44 static int cmd_move_map(coord, coord, char *, char *);
51 struct sctstr endsect;
74 istest = *player->argp[0] == 't';
75 if (!(ip = whatitem(player->argp[1], "move what? ")))
78 if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
80 if (!sarg_xy(p, &x, &y))
82 if (!getsect(x, y, §) || !player->owner) {
87 * military control necessary to move
88 * goodies in occupied territory.
90 if (!istest && sect.sct_oldown != player->cnum && vtype != I_MILIT) {
91 if (!military_control(§)) {
92 pr("Military control required to move goods.\n");
96 infected = sect.sct_pstage == PLG_INFECT;
97 amt_src = sect.sct_item[vtype];
98 if (!istest && amt_src <= 0) {
99 pr("No %s in %s\n", ip->i_name,
100 xyas(sect.sct_x, sect.sct_y, player->cnum));
104 mob = sect.sct_mobil;
105 if (!istest && vtype == I_CIVIL && sect.sct_oldown != own) {
106 pr("You can't move conquered populace!\n");
110 pr("No mobility in %s\n",
111 xyas(sect.sct_x, sect.sct_y, player->cnum));
115 /* only used when moving civs; but prevent spurious compiler warnings */
116 work = sect.sct_work;
117 loyal = sect.sct_loyal;
118 if (vtype == I_CIVIL && work != 100)
119 pr("Warning: civil unrest\n");
122 sprintf(prompt, "Number of %s to test move? ", ip->i_name);
124 sprintf(prompt, "Number of %s to move? (max %d) ",
125 ip->i_name, amt_src);
126 if ((amount = onearg(player->argp[3], prompt)) < 0)
128 if (!check_sect_ok(§))
130 if (amount > amt_src) {
132 pr("Note: there are actually only %d %s in %s,\n"
133 "but the test will be made for %d %s as you requested.\n",
135 xyas(sect.sct_x, sect.sct_y, player->cnum),
139 pr("Only moving %d.\n", amount);
143 if (!istest && !want_to_abandon(§, vtype, amount, NULL)) {
144 pr("Move cancelled.\n");
148 if (!check_sect_ok(§))
153 packing = sect.sct_effic >= 60 ? dchr[sect.sct_type].d_pkg : IPKG;
154 weight = (double)amount * ip->i_lbs / ip->i_pkg[packing];
157 * First remove stuff from source sector
160 getsect(x, y, &start);
161 if (start.sct_own != player->cnum) {
162 pr("Somebody has captured that sector!\n");
165 amt_src = start.sct_item[vtype];
166 if (amt_src < amount) {
167 pr("Only %d %s left in %s!\n",
169 xyas(start.sct_x, start.sct_y, player->cnum));
175 start.sct_item[vtype] = amt_src;
176 start.sct_flags |= MOVE_IN_PROGRESS;
181 * Now parse the path and return ending sector.
183 dam = !istest && !(opt_SUPER_BARS && vtype == I_BAR);
184 if (dam && !chance(weight / 200.0))
186 mcost = move_ground(§, &endsect, weight, player->argp[4],
187 cmd_move_map, 0, &dam);
190 left = commdamage(amount, dam, ip->i_uid);
193 pr("%d of the %s you were moving were destroyed!\n"
194 "Only %d %s made it to %s\n",
195 amount - left, ip->i_name, left, ip->i_name,
196 xyas(endsect.sct_x, endsect.sct_y, player->cnum));
198 pr("All of the %s you were moving were destroyed!\n",
206 pr("Total movement cost = %d\n", mcost);
208 pr("No mobility used\n");
212 pr("Move aborted\n");
213 getsect(x, y, §);
214 sect.sct_mobil = mob;
219 * Decrement mobility appropriately.
221 getsect(x, y, &start);
222 mob = start.sct_mobil;
228 start.sct_mobil = mob;
229 left = start.sct_mobil;
232 getsect(endsect.sct_x, endsect.sct_y, §);
236 * Check for lotsa stuff
238 if (sect.sct_own != player->cnum) {
239 if (sect.sct_own != 0)
240 pr("Somebody has captured that sector!\n");
241 getsect(x, y, §);
243 if (vtype == I_CIVIL && sect.sct_item[I_CIVIL]
244 && sect.sct_oldown != player->cnum) {
245 pr("Your civilians don't want to stay!\n");
246 getsect(x, y, §);
249 amt_dst = sect.sct_item[vtype];
250 if (amount > ITEM_MAX - amt_dst) {
251 pr("Only enough room for %d in %s. The goods will be returned.\n",
252 ITEM_MAX - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum));
253 /* FIXME Not nice. Move what we can and return the rest. */
254 getsect(x, y, §);
260 pr("%d mob left in %s\n", left,
261 xyas(start.sct_x, start.sct_y, player->cnum));
264 getsect(x, y, &start);
265 start.sct_flags &= ~MOVE_IN_PROGRESS;
271 * If the sector that things are going to is no longer owned by
272 * the player, and it was the starting sector, try to find
273 * somewhere to dump the stuff. If nowhere to dump it, it
276 if (sect.sct_own != player->cnum && sect.sct_x == x && sect.sct_y == y) {
277 pr("Can't return the goods, since the starting point is no longer\n");
278 pr("owned by you.\n");
279 /* First lets see if there is one with room */
280 for (n = DIR_FIRST; n <= DIR_LAST; n++) {
281 getsect(x + diroff[n][0], y + diroff[n][1], &tsct);
282 if (tsct.sct_own != player->cnum)
284 amt_dst = tsct.sct_item[vtype];
285 if (amount > ITEM_MAX - amt_dst)
291 /* Find any sector if none with room */
292 for (n = DIR_FIRST; n <= DIR_LAST; n++) {
293 getsect(x + diroff[n][0], y + diroff[n][1], &tsct);
294 if (tsct.sct_own != player->cnum)
300 pr("The goods had nowhere to go, and were destroyed.\n");
301 sect.sct_flags &= ~MOVE_IN_PROGRESS;
306 pr("The goods were dumped into %s.\n",
307 xyas(tsct.sct_x, tsct.sct_y, player->cnum));
308 getsect(tsct.sct_x, tsct.sct_y, §);
311 amt_dst = sect.sct_item[vtype];
312 if (amount > ITEM_MAX - amt_dst) {
313 amount = ITEM_MAX - amt_dst;
314 pr("Only room for %d, the rest were lost.\n", amount);
316 sect.sct_item[vtype] = amount + amt_dst;
318 * Now add commodities to destination sector,
319 * along with plague that came along for the ride.
320 * Takeover unowned sectors if not deity.
322 if (infected && sect.sct_pstage == PLG_HEALTHY)
323 sect.sct_pstage = PLG_EXPOSED;
324 if (vtype == I_CIVIL) {
326 = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
328 = (amt_dst * sect.sct_work + amount * work) / (amt_dst + amount);
331 getsect(x, y, &start);
332 start.sct_flags &= ~MOVE_IN_PROGRESS;
338 * Pretty tacky, but it works.
339 * If more commands start doing this, then
340 * rewrite map to do the right thing.
344 cmd_move_map(coord curx, coord cury, char *arg1, char *arg2)
346 return display_region_map(0, EF_SHIP, curx, cury, arg1, arg2);
350 want_to_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
355 * First, would we be abandoning it? If not, just return that
356 * it's ok to move out.
358 if (!would_abandon(sp, vtype, amnt, lp))
361 sprintf(prompt, "Do you really want to abandon %s [yn]? ",
362 xyas(sp->sct_x, sp->sct_y, player->cnum));
364 return askyn(prompt);
368 would_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
372 if (vtype != I_CIVIL && vtype != I_MILIT)
375 mil = sp->sct_item[I_MILIT];
376 civs = sp->sct_item[I_CIVIL];
378 if (vtype == I_MILIT)
380 if (vtype == I_CIVIL)
383 return sp->sct_own != 0 && civs <= 0 && mil <= 0
384 && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, lp);