]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/move.c
commands: Rename the command functions
[empserver] / src / lib / commands / move.c
index ae4f41447738d863d77fbcd0945cb5280b5b9b59..91b55edf895df91441a7f83e768461ee628accad 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  move.c: Move commodities around
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "plague.h"
-#include "sect.h"
+#include "chance.h"
+#include "commands.h"
 #include "item.h"
-#include "file.h"
-#include "xy.h"
-#include "nat.h"
-#include "nsc.h"
-#include "land.h"
+#include "map.h"
+#include "optlist.h"
 #include "path.h"
-#include "commands.h"
+#include "plague.h"
 
 
-static int cmd_move_map(coord curx, coord cury, char *arg);
+static int cmd_move_map(coord, coord, char *, char *);
 
 int
-move(void)
+c_move(void)
 {
     int amount;
     struct sctstr sect;
@@ -78,7 +72,7 @@ move(void)
 
 
     istest = *player->argp[0] == 't';
-    if ((ip = whatitem(player->argp[1], "move what? ")) == 0)
+    if (!(ip = whatitem(player->argp[1], "move what? ")))
        return RET_SYN;
     vtype = ip->i_uid;
     if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
@@ -146,7 +140,7 @@ move(void)
        }
     }
 
-    if (!istest && !want_to_abandon(&sect, vtype, amount, 0)) {
+    if (!istest && !abandon_askyn(&sect, vtype, amount, NULL)) {
        pr("Move cancelled.\n");
        return RET_FAIL;
     }
@@ -186,7 +180,7 @@ move(void)
     /*
      * Now parse the path and return ending sector.
      */
-    dam = (istest ? 0 : 1);
+    dam = !istest && !(opt_SUPER_BARS && vtype == I_BAR);
     if (dam && !chance(weight / 200.0))
        dam = 0;
     mcost = move_ground(&sect, &endsect, weight, player->argp[4],
@@ -256,7 +250,7 @@ move(void)
     if (amount > ITEM_MAX - amt_dst) {
        pr("Only enough room for %d in %s.  The goods will be returned.\n",
           ITEM_MAX - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum));
-       /* FIXME Not nice.  Move what we can and return the rest.  */
+       /* FIXME Not nice.  Move what we can and return the rest. */
        getsect(x, y, &sect);
     }
 
@@ -347,60 +341,7 @@ move(void)
  */
 /*ARGSUSED*/
 static int
-cmd_move_map(coord curx, coord cury, char *arg)
-{
-    player->argp[0] = "map";
-    player->argp[1] = arg;
-    player->argp[2] = NULL;
-    player->condarg = NULL;
-    return map();
-}
-
-int
-want_to_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
+cmd_move_map(coord curx, coord cury, char *arg1, char *arg2)
 {
-    char prompt[80];
-
-    /*
-     * First, would we be abandoning it?  If not, just return that
-     * it's ok to move out.
-     */
-    if (!would_abandon(sp, vtype, amnt, lp))
-       return 1;
-
-    sprintf(prompt, "Do you really want to abandon %s [yn]? ",
-           xyas(sp->sct_x, sp->sct_y, player->cnum));
-
-    return askyn(prompt);
-}
-
-int
-would_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
-{
-    int mil, civs, loyalcivs;
-
-    if ((vtype != I_CIVIL) && (vtype != I_MILIT))
-       return 0;
-
-    mil = sp->sct_item[I_MILIT];
-    civs = sp->sct_item[I_CIVIL];
-
-    if (vtype == I_MILIT)
-       mil -= amnt;
-
-    if (vtype == I_CIVIL)
-       civs -= amnt;
-
-    if (sp->sct_own == sp->sct_oldown)
-       loyalcivs = civs;
-    else
-       loyalcivs = 0;
-
-    /* If they have a military unit there, they still own it */
-    if (sp->sct_own != 0
-       && ((loyalcivs == 0) && (mil == 0)
-           && (has_units(sp->sct_x, sp->sct_y, sp->sct_own, lp) == 0)))
-       return 1;
-
-    return 0;
+    return display_region_map(0, EF_SHIP, curx, cury, arg1, arg2);
 }