]> git.pond.sub.org Git - empserver/commitdiff
(att_move_in_off): Don't put more than ITEM_MAX food into the
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 5 Mar 2004 13:14:28 +0000 (13:14 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 5 Mar 2004 13:14:28 +0000 (13:14 +0000)
assaulted sector.  Simplify some more.

src/lib/subs/attsub.c

index b44128bdfe5f7f796069823dd4d039f6198ec8f4..eb9d3b3de2bc97ae522af5cff93ca9f34690ddf2 100644 (file)
@@ -2465,10 +2465,12 @@ att_move_in_off(int combat_mode, struct combat *off,
     struct sctstr sect;
     struct shpstr ship;
     int troops;
     struct sctstr sect;
     struct shpstr ship;
     int troops;
-    int n, lunchbox = 0;
+    int n, lunchbox;
 
     move_in_land(combat_mode, off, olist, def);
 
 
     move_in_land(combat_mode, off, olist, def);
 
+    getsect(def->x, def->y, &sect);
+
     for (n = 0; n <= off->last; ++n) {
        if (off[n].type == EF_BAD || !off[n].troops)
            continue;
     for (n = 0; n <= off->last; ++n) {
        if (off[n].type == EF_BAD || !off[n].troops)
            continue;
@@ -2483,24 +2485,20 @@ att_move_in_off(int combat_mode, struct combat *off,
                continue;
            }
            getship(off[n].shp_uid, &ship);
                continue;
            }
            getship(off[n].shp_uid, &ship);
-           lunchbox += (int)((troops + 1) * ship.shp_item[I_FOOD]
-                             / (ship.shp_item[I_MILIT] + troops
-                                + ship.shp_item[I_CIVIL] + 0.5));
+           lunchbox = (int)((troops + 1) * ship.shp_item[I_FOOD]
+                            / (ship.shp_item[I_MILIT] + troops
+                               + ship.shp_item[I_CIVIL] + 0.5));
+           if (lunchbox > ITEM_MAX - sect.sct_item[I_FOOD])
+               lunchbox = ITEM_MAX - sect.sct_item[I_FOOD];
+
            ship.shp_item[I_FOOD] -= lunchbox;
            ship.shp_item[I_FOOD] -= lunchbox;
+           sect.sct_item[I_FOOD] += lunchbox;
            putship(ship.shp_uid, &ship);
        }
     }
            putship(ship.shp_uid, &ship);
        }
     }
-    put_combat(def);
-    if (!lunchbox)
-       return;
-    if (def->type != EF_SECTOR) {
-       pr("Please tell the deity that you got the 'hungry mole' error\n");
-       logerror("att_move_in_off: hungry mole");
-       return;
-    }
-    getsect(def->x, def->y, &sect);
-    sect.sct_item[I_FOOD] += lunchbox;
+
     putsect(&sect);
     putsect(&sect);
+    put_combat(def);
 }
 
 
 }