]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/move.c
Update copyright notice
[empserver] / src / lib / commands / move.c
index 4fabbe9b76db7be6604fe232feba8aef3a917d3b..7c915b8ff6f1b724e79c63663db201df5b10b6f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  move.c: Move commodities around
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
-#include "misc.h"
-#include "player.h"
-#include "var.h"
-#include "sect.h"
+#include <config.h>
+
+#include "commands.h"
 #include "item.h"
-#include "file.h"
-#include "xy.h"
-#include "nat.h"
-#include "nsc.h"
 #include "land.h"
 #include "optlist.h"
 #include "path.h"
-#include "commands.h"
+#include "plague.h"
 
 
-static int cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg);
+static int cmd_move_map(coord curx, coord cury, char *arg);
 
 int
 move(void)
 {
-    register int amount;
+    int amount;
     struct sctstr sect;
     struct sctstr endsect;
     struct sctstr start;
@@ -61,7 +56,7 @@ move(void)
     int left;
     int mcost, dam;
     int infected;
-    int vtype;
+    i_type vtype;
     int amt_src;
     int amt_dst;
     struct ichrstr *ip;
@@ -71,15 +66,15 @@ move(void)
     int istest = 0;
     int n;
     coord x, y;
-    s_char *p;
-    s_char prompt[1024];
-    s_char buf[1024];
+    char *p;
+    char prompt[1024];
+    char buf[1024];
 
 
     istest = *player->argp[0] == 't';
     if ((ip = whatitem(player->argp[1], "move what? ")) == 0)
        return RET_SYN;
-    vtype = ip->i_vtype;
+    vtype = ip->i_uid;
     if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
        return RET_SYN;
     if (!sarg_xy(p, &x, &y))
@@ -106,7 +101,7 @@ move(void)
        return RET_FAIL;
     }
     own = sect.sct_own;
-    mob = (int)sect.sct_mobil;
+    mob = sect.sct_mobil;
     if (!istest && vtype == I_CIVIL && sect.sct_oldown != own) {
        pr("You can't move conquered populace!\n");
        return RET_FAIL;
@@ -134,7 +129,11 @@ move(void)
        return RET_FAIL;
     if (amount > amt_src) {
        if (istest) {
-           pr("Note: there are actually only %d %s in %s,\nbut the test will be made for %d %s as you requested.\n", amt_src, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum), amount, ip->i_name);
+           pr("Note: there are actually only %d %s in %s,\n"
+              "but the test will be made for %d %s as you requested.\n",
+              amt_src, ip->i_name,
+              xyas(sect.sct_x, sect.sct_y, player->cnum),
+              amount, ip->i_name);
        } else {
            amount = amt_src;
            pr("Only moving %d.\n", amount);
@@ -153,8 +152,9 @@ move(void)
        return RET_SYN;
     packing = sect.sct_effic >= 60 ? dchr[sect.sct_type].d_pkg : IPKG;
     weight = (double)amount * ip->i_lbs / ip->i_pkg[packing];
+
     /*
-     * First remove commodities from source sector
+     * First remove stuff from source sector
      */
     if (!istest) {
        getsect(x, y, &start);
@@ -164,8 +164,9 @@ move(void)
        }
        amt_src = start.sct_item[vtype];
        if (amt_src < amount) {
-           pr("Only %d %s left in %s!\n", amt_src,
-              ip->i_name, xyas(start.sct_x, start.sct_y, player->cnum));
+           pr("Only %d %s left in %s!\n",
+              amt_src, ip->i_name,
+              xyas(start.sct_x, start.sct_y, player->cnum));
            amount = amt_src;
            amt_src = 0;
        } else
@@ -179,18 +180,20 @@ 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((s_char *)ip, &sect, &endsect,
-                       weight, player->argp[4],
+    mcost = move_ground(&sect, &endsect, weight, player->argp[4],
                        cmd_move_map, 0, &dam);
 
     if (dam) {
-       left = commdamage(amount, dam, ip->i_vtype);
+       left = commdamage(amount, dam, ip->i_uid);
        if (left < amount) {
            if (left) {
-               pr("%d of the %s you were moving were destroyed!\nOnly %d %s made it to %s\n", amount - left, ip->i_name, left, ip->i_name, xyas(endsect.sct_x, endsect.sct_y, player->cnum));
+               pr("%d of the %s you were moving were destroyed!\n"
+                  "Only %d %s made it to %s\n",
+                  amount - left, ip->i_name, left, ip->i_name,
+                  xyas(endsect.sct_x, endsect.sct_y, player->cnum));
            } else {
                pr("All of the %s you were moving were destroyed!\n",
                   ip->i_name);
@@ -208,22 +211,24 @@ move(void)
     if (mcost < 0) {
        pr("Move aborted\n");
        getsect(x, y, &sect);
-       sect.sct_mobil = (u_char)mob;
+       sect.sct_mobil = mob;
        left = mob;
-    } else if (!istest) {
-       /*
-        * decrement mobility appropriately.
-        */
-       getsect(x, y, &start);
-       mob = start.sct_mobil;
-       if (mob < mcost) {
-           if (mob > 0)
-               mob = 0;
-       } else
-           mob -= mcost;
-       start.sct_mobil = (u_char)mob;
-       left = start.sct_mobil;
-       putsect(&start);
+    } else {
+       if (!istest) {
+           /*
+            * Decrement mobility appropriately.
+            */
+           getsect(x, y, &start);
+           mob = start.sct_mobil;
+           if (mob < mcost) {
+               if (mob > 0)
+                   mob = 0;
+           } else
+               mob -= mcost;
+           start.sct_mobil = mob;
+           left = start.sct_mobil;
+           putsect(&start);
+       }
        getsect(endsect.sct_x, endsect.sct_y, &sect);
     }
 
@@ -249,9 +254,11 @@ move(void)
        getsect(x, y, &sect);
     }
 
-    if (!istest)
-       pr("%d mob left in %s\n", left,
-          xyas(start.sct_x, start.sct_y, player->cnum));
+    if (istest)
+       return RET_OK;
+
+    pr("%d mob left in %s\n", left,
+       xyas(start.sct_x, start.sct_y, player->cnum));
 
     if (amount <= 0) {
        getsect(x, y, &start);
@@ -260,10 +267,12 @@ move(void)
        return RET_OK;
     }
 
-/* If the sector that things are going to is no longer
-   owned by the player, and was the starting sector,
-   try to find somewhere to dump the stuff.  If nowhere
-   to dump it, it disappears. */
+    /*
+     * If the sector that things are going to is no longer owned by
+     * the player, and it was the starting sector, try to find
+     * somewhere to dump the stuff.  If nowhere to dump it, it
+     * disappears.
+     */
     if (sect.sct_own != player->cnum && sect.sct_x == x && sect.sct_y == y) {
        pr("Can't return the goods, since the starting point is no longer\n");
        pr("owned by you.\n");
@@ -304,8 +313,6 @@ move(void)
        amount = ITEM_MAX - amt_dst;
        pr("Only room for %d, the rest were lost.\n", amount);
     }
-    if (istest)
-       return RET_OK;
     sect.sct_item[vtype] = amount + amt_dst;
     /*
      * Now add commodities to destination sector,
@@ -332,47 +339,37 @@ move(void)
  * If more commands start doing this, then
  * rewrite map to do the right thing.
  */
-/* I think this is no longer used, check subs/move.c:move_ground() */
 /*ARGSUSED*/
 static int
-cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg)
+cmd_move_map(coord curx, coord cury, char *arg)
 {
-    player->argp[1] = arg;
-    player->argp[2] = "";
-    player->argp[3] = "";
-    player->argp[4] = "";
-    player->argp[5] = "";
-    player->condarg = 0;
-    return map();
+    return display_region_map(0, EF_SHIP, curx, cury, arg);
 }
 
 int
-want_to_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
+want_to_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
 {
     char prompt[80];
 
-    /* First, would we be abandoning it?  If not, just return that it's
-       ok to move out */
+    /*
+     * 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));
 
-    /* now, if they say yes that it's ok, just return 1 */
-    if (askyn(prompt))
-       return 1;
-
-    /* Nope, not ok */
-    return 0;
+    return askyn(prompt);
 }
 
 int
-would_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
+would_abandon(struct sctstr *sp, i_type vtype, int amnt, struct lndstr *lp)
 {
-    int mil, civs, loyalcivs;
+    int mil, civs;
 
-    if ((vtype != I_CIVIL) && (vtype != I_MILIT))
+    if (vtype != I_CIVIL && vtype != I_MILIT)
        return 0;
 
     mil = sp->sct_item[I_MILIT];
@@ -380,20 +377,9 @@ would_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp)
 
     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 sp->sct_own != 0 && civs <= 0 && mil <= 0
+       && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, lp);
 }