]> git.pond.sub.org Git - empserver/commitdiff
(att_move_in_off): When boarding from a sector, mil entering the ship
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Jun 2005 16:52:17 +0000 (16:52 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 18 Jun 2005 16:52:17 +0000 (16:52 +0000)
less one were not removed from the sector.  The problem is putsect()
overwriting data from prior put_combat() with old data.  Broken in
rev. 1.17.  Change lunchbox code to match that of 1.16.  Closes
#1219918, reported by Doug Wescott.

src/lib/subs/attsub.c

index 040b2423f4cec5d8cbce372dfe864dd9ff00b3c6..57c22dc81163db086949eca75e0460ace2333d79 100644 (file)
@@ -2461,13 +2461,11 @@ att_move_in_off(int combat_mode, struct combat *off,
 {
     struct sctstr sect;
     struct shpstr ship;
-    int troops;
-    int n, lunchbox;
+    int troops, n;
+    int lunchbox = 0;
 
     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;
@@ -2477,25 +2475,29 @@ att_move_in_off(int combat_mode, struct combat *off,
        def->mil += troops;
        put_combat(off + n);
        if (combat_mode == A_ASSAULT) {
-           if (off[n].type != EF_SHIP || def->type != EF_SECTOR) {
-               logerror("att_move_in_off: strange assault");
+           if (CANT_HAPPEN(off[n].type != EF_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));
-           if (lunchbox > ITEM_MAX - sect.sct_item[I_FOOD])
-               lunchbox = ITEM_MAX - sect.sct_item[I_FOOD];
+           lunchbox += (int)((troops + 1) * ship.shp_item[I_FOOD]
+                             / (ship.shp_item[I_MILIT] + troops
+                                + ship.shp_item[I_CIVIL] + 0.5));
 
            ship.shp_item[I_FOOD] -= lunchbox;
-           sect.sct_item[I_FOOD] += lunchbox;
            putship(ship.shp_uid, &ship);
        }
     }
 
-    putsect(&sect);
     put_combat(def);
+
+    if (combat_mode == A_ASSAULT) {
+       if (CANT_HAPPEN(def->type != EF_SECTOR))
+           return;
+       getsect(def->x, def->y, &sect);
+       if (lunchbox > ITEM_MAX - sect.sct_item[I_FOOD])
+           lunchbox = ITEM_MAX - sect.sct_item[I_FOOD];
+       sect.sct_item[I_FOOD] += lunchbox;
+       putsect(&sect);
+    }
 }