]> git.pond.sub.org Git - empserver/commitdiff
(buy, move, prod, dodistribute, produce): Obey ITEM_MAX. Previous
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 16 Mar 2004 18:56:14 +0000 (18:56 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 16 Mar 2004 18:56:14 +0000 (18:56 +0000)
change to move() was incomplete.

src/lib/commands/buy.c
src/lib/commands/move.c
src/lib/commands/prod.c
src/lib/update/distribute.c
src/lib/update/produce.c

index 92f3c856c6dcafdcb7053c5af305c37c00081692..e17edc4df3f5b25c78a17dc891c4620582a35f9e 100644 (file)
@@ -163,7 +163,7 @@ buy(void)
     ip = whichitem(comm.com_type);
     n = sect.sct_item[ip->i_vtype];
     qty = comm.com_amount;
-    if (qty + n > 9990) {
+    if (qty + n > ITEM_MAX) {
        pr("That sector cannot hold %d more %s. It currently holds %d.\n",
           qty, ip->i_name, n);
        return RET_FAIL;
index f68e1fc2612c9459163c8aae1b939d1b0807c6bd..fb4372a4ef88c8ebf93ea6fe45b84a09a8bc66ef 100644 (file)
@@ -228,7 +228,7 @@ move(void)
        left = mob;
     } else if (!istest) {
        /*
-          * decrement mobility appropriately.
+        * decrement mobility appropriately.
         */
        getsect(x, y, &start);
        mob = start.sct_mobil;
@@ -258,9 +258,10 @@ move(void)
     }
 
     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);
     }
 
@@ -281,7 +282,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;
index 34b220704359a7d74d651146df87e94e78f9038b..bd9f285c1e7660dba4181e87f6ada5caef7efd7f 100644 (file)
@@ -286,11 +286,9 @@ prod(void)
            if (real < 0.0)
                real = 0.0;
            /* production backlog? */
-           if ((there = sect.sct_item[vtype]) >= 9999) {
-               there = 9999;
-           }
-           act = min(act, (9999 - there));
-           max = min(max, (9999 - there));
+           there = min(ITEM_MAX, sect.sct_item[vtype]);
+           act = min(act, ITEM_MAX - there);
+           max = min(max, ITEM_MAX - there);
        }
 
        if (prodeff != 0) {
index 1b518d8c0aeaaf3e905297e07c4ddf6c4681a2c2..7017c30bd8aa82ce82e09710979bad657f89d78e 100644 (file)
@@ -178,8 +178,8 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
                amt = amt_sect;
            if (sp->sct_mobil < excost * amt)
                amt = sp->sct_mobil / excost;
-           if (amt + amt_dist > 9999)
-               amt = 9999 - amt_dist;
+           if (amt > ITEM_MAX - amt_dist)
+               amt = ITEM_MAX - amt_dist;
            if (amt == 0)
                continue;
            /* XXX replace with vector assign and putvec() */
index 0a9d2ecb22eb9a80f4e635d9aea40afe83c6ebb3..0d459431f90fc787a0a18cab0b43cc458a63a768 100644 (file)
@@ -138,20 +138,19 @@ produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
            actual = 999;
            material_consume = (int)(actual / (product->p_effic * 0.01));
        }
-       vec[item] += actual;
-       if (vec[item] > 9999) {
+       if (vec[item] + actual > ITEM_MAX) {
            material_consume =
-               roundavg((9999.0 - vec[item] + actual) *
-                        material_consume / actual);
+               roundavg((ITEM_MAX - vec[item]) * material_consume / actual);
            if (material_consume < 0)
                material_consume = 0;
-           vec[item] = 9999;
+           vec[item] = ITEM_MAX;
            if (( /* vtype != V_FOOD && */ sp->sct_own) &&
                (!player->simulation))
                wu(0, sp->sct_own,
                   "%s production backlog in %s\n",
                   product->p_name, ownxy(sp));
-       }
+       } else
+           vec[item] += actual;
     }
     /*
      * Reset produced amount by commodity production ratio