]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/move.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / move.c
index f68e1fc2612c9459163c8aae1b939d1b0807c6bd..3b6d9991ed399e4a7d9f3cd797d822e96c441b54 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *     
  */
 
+#include <config.h>
+
 #include "misc.h"
 #include "player.h"
-#include "var.h"
+#include "plague.h"
 #include "sect.h"
 #include "item.h"
 #include "file.h"
@@ -41,7 +43,6 @@
 #include "nat.h"
 #include "nsc.h"
 #include "land.h"
-#include "optlist.h"
 #include "path.h"
 #include "commands.h"
 
@@ -51,7 +52,7 @@ static int cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg);
 int
 move(void)
 {
-    register int amount;
+    int amount;
     struct sctstr sect;
     struct sctstr endsect;
     struct sctstr start;
@@ -61,11 +62,9 @@ move(void)
     int left;
     int mcost, dam;
     int infected;
-    int stype;
-    int vtype;
+    i_type vtype;
     int amt_src;
     int amt_dst;
-    struct dchrstr *dp;
     struct ichrstr *ip;
     int work;
     int loyal;
@@ -94,22 +93,12 @@ move(void)
      * military control necessary to move
      * goodies in occupied territory.
      */
-    if (!istest && sect.sct_oldown != player->cnum && vtype != V_MILIT) {
-       int tot_mil = 0;
-       struct nstr_item ni;
-       struct lndstr land;
-       snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
-       while (nxtitem(&ni, (s_char *)&land)) {
-           if (land.lnd_own == player->cnum)
-               tot_mil += total_mil(&land);
-       }
-       if ((sect.sct_item[I_MILIT] + tot_mil) * 10 < sect.sct_item[I_CIVIL]) {
+    if (!istest && sect.sct_oldown != player->cnum && vtype != I_MILIT) {
+       if (!military_control(&sect)) {
            pr("Military control required to move goods.\n");
            return RET_FAIL;
        }
     }
-    stype = sect.sct_type;
-    dp = &dchr[stype];
     infected = sect.sct_pstage == PLG_INFECT;
     amt_src = sect.sct_item[vtype];
     if (!istest && amt_src <= 0) {
@@ -119,7 +108,7 @@ move(void)
     }
     own = sect.sct_own;
     mob = (int)sect.sct_mobil;
-    if (!istest && vtype == V_CIVIL && sect.sct_oldown != own) {
+    if (!istest && vtype == I_CIVIL && sect.sct_oldown != own) {
        pr("You can't move conquered populace!\n");
        return RET_FAIL;
     }
@@ -128,15 +117,13 @@ move(void)
           xyas(sect.sct_x, sect.sct_y, player->cnum));
        return RET_SYN;
     }
-    if (vtype == V_CIVIL) {
-       work = sect.sct_work;
-       if (work != 100)
-           pr("Warning: civil unrest\n");
-       loyal = sect.sct_loyal;
-    } else if (vtype == V_MILIT) {
-       work = 100;
-       loyal = 0;
-    }
+
+    /* only used when moving civs; but prevent spurious compiler warnings */
+    work = sect.sct_work;
+    loyal = sect.sct_loyal;
+    if (vtype == I_CIVIL && work != 100)
+       pr("Warning: civil unrest\n");
+
     if (istest)
        sprintf(prompt, "Number of %s to test move? ", ip->i_name);
     else
@@ -148,14 +135,18 @@ 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);
        }
     }
 
-    if (!want_to_abandon(&sect, vtype, amount, 0)) {
+    if (!istest && !want_to_abandon(&sect, vtype, amount, 0)) {
        pr("Move cancelled.\n");
        return RET_FAIL;
     }
@@ -165,12 +156,11 @@ move(void)
 
     if (amount <= 0)
        return RET_SYN;
-    packing = ip->i_pkg[dp->d_pkg];
-    if (packing > 1 && sect.sct_effic < 60)
-       packing = 1;
-    weight = (double)amount *ip->i_lbs / packing;
+    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);
@@ -206,7 +196,10 @@ move(void)
        left = commdamage(amount, dam, ip->i_vtype);
        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);
@@ -226,20 +219,22 @@ move(void)
        getsect(x, y, &sect);
        sect.sct_mobil = (u_char)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 = (u_char)mob;
+           left = start.sct_mobil;
+           putsect(&start);
+       }
        getsect(endsect.sct_x, endsect.sct_y, &sect);
     }
 
@@ -251,27 +246,39 @@ move(void)
            pr("Somebody has captured that sector!\n");
        getsect(x, y, &sect);
     }
-    if (vtype == V_CIVIL && sect.sct_item[I_CIVIL]
+    if (vtype == I_CIVIL && sect.sct_item[I_CIVIL]
        && sect.sct_oldown != player->cnum) {
        pr("Your civilians don't want to stay!\n");
        getsect(x, y, &sect);
     }
 
     amt_dst = sect.sct_item[vtype];
-    if (32767 - amt_dst < amount) {
+    if (amount > ITEM_MAX - amt_dst) {
        pr("Only enough room for %d in %s.  The goods will be returned.\n",
-          32767 - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum));
+          ITEM_MAX - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum));
+       /* FIXME Not nice.  Move what we can and return the rest.  */
        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 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 (amount <= 0) {
+       getsect(x, y, &start);
+       start.sct_flags &= ~MOVE_IN_PROGRESS;
+       putsect(&start);
+       return RET_OK;
+    }
+
+    /*
+     * 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");
@@ -281,7 +288,7 @@ move(void)
            if (tsct.sct_own != player->cnum)
                continue;
            amt_dst = tsct.sct_item[vtype];
-           if (32767 - amt_dst < amount)
+           if (amount > ITEM_MAX - amt_dst)
                continue;
            n = -1;
            break;
@@ -312,8 +319,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,
@@ -322,7 +327,7 @@ move(void)
      */
     if (infected && sect.sct_pstage == PLG_HEALTHY)
        sect.sct_pstage = PLG_EXPOSED;
-    if (vtype == V_CIVIL) {
+    if (vtype == I_CIVIL) {
        sect.sct_loyal
            = (amt_dst * sect.sct_loyal + amount * loyal) / (amt_dst + amount);
        sect.sct_work
@@ -355,41 +360,38 @@ cmd_move_map(s_char *what, coord curx, coord cury, s_char *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;
 
-    if ((vtype != V_CIVIL) && (vtype != V_MILIT))
+    if ((vtype != I_CIVIL) && (vtype != I_MILIT))
        return 0;
 
     mil = sp->sct_item[I_MILIT];
     civs = sp->sct_item[I_CIVIL];
 
-    if (vtype == V_MILIT)
+    if (vtype == I_MILIT)
        mil -= amnt;
 
-    if (vtype == V_CIVIL)
+    if (vtype == I_CIVIL)
        civs -= amnt;
 
     if (sp->sct_own == sp->sct_oldown)