]> git.pond.sub.org Git - empserver/commitdiff
update/revolt: Simplify take_casualties()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 18 Sep 2016 15:45:59 +0000 (17:45 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:19 +0000 (20:09 +0200)
Since the previous commit fixed the update of mc, mc + taken remain
invariant.  Don't bother changing mc, use mc - taken instead.

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

index 183289a6dfdd39172b64d2231af27c00f84807ed..b6ea43cb7f4a76f40df55983113c22011b877cc7 100644 (file)
@@ -432,10 +432,6 @@ take_casualties(struct sctstr *sp, int mc)
     }
     sp->sct_item[I_MILIT] = 0;
 
-    /* remaining casualites */
-    mc -= orig_mil;
-    taken = orig_mil;
-
     /*
      * Need to take total_casualties and divide
      * them amongst the land units in the sector
@@ -452,9 +448,10 @@ take_casualties(struct sctstr *sp, int mc)
     }
 
     if (CANT_HAPPEN(!nunits))
-       return taken;
+       return orig_mil;
 
-    each = (mc / nunits) + 2;
+    taken = orig_mil;
+    each = (mc - taken) / nunits + 2;
 
     /* kill some security troops */
     snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
@@ -472,13 +469,12 @@ take_casualties(struct sctstr *sp, int mc)
        if (deq <= 0)
            continue;
 
-       mc -= deq;
        taken += deq;
        dam = ((double)deq / lp->lnd_item[I_MILIT]) * 100.0;
        lp->lnd_effic -= dam;
        lp->lnd_mobil -= dam / 2;
        lnd_submil(lp, deq);
-       if (mc <= 0)
+       if (taken >= mc)
            return taken;
     }
 
@@ -498,13 +494,12 @@ take_casualties(struct sctstr *sp, int mc)
        if (deq <= 0)
            continue;
 
-       mc -= deq;
        taken += deq;
        dam = ((double)deq / lp->lnd_item[I_MILIT]) * 100.0;
        lp->lnd_effic -= dam;
        lp->lnd_mobil -= dam / 2;
        lnd_submil(lp, deq);
-       if (mc <= 0)
+       if (taken >= mc)
            return taken;
     }
 
@@ -519,10 +514,9 @@ take_casualties(struct sctstr *sp, int mc)
        if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
            continue;
 
-       mc -= lp->lnd_item[I_MILIT];
        taken += lp->lnd_item[I_MILIT];
        lnd_dies_fighting_che(lp);
-       if (mc <= 0)
+       if (taken >= mc)
            return taken;
     }
 
@@ -537,10 +531,9 @@ take_casualties(struct sctstr *sp, int mc)
        if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
            continue;
 
-       mc -= lp->lnd_item[I_MILIT];
        taken += lp->lnd_item[I_MILIT];
        lnd_dies_fighting_che(lp);
-       if (mc <= 0)
+       if (taken >= mc)
            return taken;
     }