]> git.pond.sub.org Git - empserver/commitdiff
update/revolt: Fix body count report
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Sep 2016 09:27:30 +0000 (11:27 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:19 +0000 (20:09 +0200)
The body count reflects what take_casualties() should do, not what it
actually does.  It can be quite off, as the update test's changed
output shows.  Mostly because take_casualties() is utterly confused.
That'll be fixed next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/update/revolt.c
tests/update/99-POGO
tests/update/journal.log

index bb01769d913ed8aca1980b91d0741347bb7ab4af..906fc79537a3c9c0d1c56a65c6261d667f0ad5e3 100644 (file)
@@ -47,7 +47,7 @@
 #include "sect.h"
 #include "update.h"
 
-static void take_casualties(struct sctstr *, int);
+static int take_casualties(struct sctstr *, int);
 static void lnd_dies_fighting_che(struct lndstr *);
 
 void
@@ -234,16 +234,13 @@ guerrilla(struct sctstr *sp)
         * If loyalty bad enough, then take the sector over,
         * and enlist 5% of civ as military force.
         */
-       while (che > 0 && mil > 0) {
-           if (chance(odds)) {
+       while (che > cc && mil > mc) {
+           if (chance(odds))
                mc++;
-               mil--;
-           } else {
+           else
                cc++;
-               che--;
-           }
        }
-       if (mil > 0) {
+       if (mil > mc) {
            /* military won.  */
            n = sp->sct_loyal - roll0(15);
            if (n < 0)
@@ -253,7 +250,9 @@ guerrilla(struct sctstr *sp)
            convert++;
            recruit++;
        }
-       take_casualties(sp, mc);
+       mc = take_casualties(sp, mc);
+       che -= cc;
+       mil -= mc;
     } else if (ratio < 5) {
        /*
         * guerrillas have to resort to blowing things up.
@@ -285,16 +284,14 @@ guerrilla(struct sctstr *sp)
            n = (mil / 5) + 1;
            odds = (double)che / (n + security_bonus / 5 + che);
            odds /= hap_fact(tnat, getnatp(sp->sct_oldown));
-           while (che > 0 && n > 0) {
-               if (chance(odds)) {
+           while (che > cc && n > mc) {
+               if (chance(odds))
                    mc++;
-                   n--;
-               } else {
+               else
                    cc++;
-                   che--;
-               }
            }
-           take_casualties(sp, mc);
+           mc = take_casualties(sp, mc);
+           che -= cc;
            mil -= mc;
            recruit = 0;
        }
@@ -417,10 +414,10 @@ domove:
           xyas(sp->sct_x, sp->sct_y, victim));
 }
 
-static void
+static int
 take_casualties(struct sctstr *sp, int mc)
 {
-    int orig_mil;
+    int orig_mil, taken;
     int cantake;
     int nunits = 0, each, deq;
     struct lndstr *lp;
@@ -431,12 +428,13 @@ take_casualties(struct sctstr *sp, int mc)
 
     if (mc <= orig_mil) {
        sp->sct_item[I_MILIT] = orig_mil - mc;
-       return;
+       return mc;
     }
     sp->sct_item[I_MILIT] = 0;
 
     /* remaining casualites */
     mc -= orig_mil;
+    taken = orig_mil;
 
     /*
      * Need to take total_casualties and divide
@@ -454,7 +452,7 @@ take_casualties(struct sctstr *sp, int mc)
     }
 
     if (nunits == 0)
-       return;
+       return taken;
 
     each = (mc / nunits) + 2;
 
@@ -482,9 +480,10 @@ take_casualties(struct sctstr *sp, int mc)
        lp->lnd_effic -= deq;
        lp->lnd_mobil -= deq / 2;
        deq = lchr[(int)lp->lnd_type].l_item[I_MILIT] * (deq / 100.0);
+       taken += MIN(deq, lp->lnd_item[I_MILIT]);
        lnd_submil(lp, deq);
        if (mc <= 0)
-           return;
+           return taken;
     }
 
     /* kill some normal troops */
@@ -511,9 +510,10 @@ take_casualties(struct sctstr *sp, int mc)
        lp->lnd_effic -= deq;
        lp->lnd_mobil -= deq / 2;
        deq = lchr[(int)lp->lnd_type].l_item[I_MILIT] * (deq / 100.0);
+       taken += MIN(deq, lp->lnd_item[I_MILIT]);
        lnd_submil(lp, deq);
        if (mc <= 0)
-           return;
+           return taken;
     }
 
     /* Hmm.. still some left.. kill off units now */
@@ -528,9 +528,10 @@ take_casualties(struct sctstr *sp, int mc)
            continue;
 
        mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT];
+       taken += lp->lnd_item[I_MILIT];
        lnd_dies_fighting_che(lp);
        if (mc <= 0)
-           return;
+           return taken;
     }
 
     /* Hmm.. still some left.. kill off units now */
@@ -545,12 +546,14 @@ take_casualties(struct sctstr *sp, int mc)
            continue;
 
        mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT];
+       taken += lp->lnd_item[I_MILIT];
        lnd_dies_fighting_che(lp);
        if (mc <= 0)
-           return;
+           return taken;
     }
 
     /* Hmm.. everyone dead.. too bad */
+    return taken;
 }
 
 static void
index d39009b8a9c66c51aaa5d785849ddba0b8206717..8e9e6c00bc151bd3da73cd192347f78db1dd7ac5 100644 (file)
@@ -182,10 +182,8 @@ land 0:31,-16:-1
 | BUG: "Sector -12,-8 has been retaken!" instead of takeover
 | -10,-8 che win, don't take over
 | -8,-8 che lose
-| BUG: body count off, claims 7m, actually 11m
 | BUG: che kill 4m more than they should
 | -6,-8 che lose
-| BUG: body count off, claims 26m, actually 50m
 | BUG: inf#29 shouldn't die
 | plague stage 4 (dying) -16:-1,-6 ship#10 land#10
 | -16,-6 reverts to deity
index 376a0a1113a77c0143d5e48b702268b1066e7075..b0c472f83607e2accfae98e7659442d86a4b657f 100644 (file)
     Play#0 output Play#0 1 Guerrilla warfare in -10,-8
     Play#0 output Play#0 1   body count: troops: 10, rebels: 5
     Play#0 output Play#0 1 Guerrilla warfare in -8,-8
-    Play#0 output Play#0 1   body count: troops: 7, rebels: 22
+    Play#0 output Play#0 1   body count: troops: 11, rebels: 22
     Play#0 output Play#0 1 inf  infantry #29 dies fighting guerrillas in -6,-8
     Play#0 output Play#0 1 Guerrilla warfare in -6,-8
-    Play#0 output Play#0 1   body count: troops: 26, rebels: 52
+    Play#0 output Play#0 1   body count: troops: 50, rebels: 52
     Play#0 output Play#0 1 Revolutionary subversion reported in -13,-7!
     Play#0 output Play#0 1 PLAGUE deaths reported in -16,-6
     Play#0 output Play#0 1 PLAGUE deaths reported in -14,-6