diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index bb01769d..906fc795 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -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 diff --git a/tests/update/99-POGO b/tests/update/99-POGO index d39009b8..8e9e6c00 100644 --- a/tests/update/99-POGO +++ b/tests/update/99-POGO @@ -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 diff --git a/tests/update/journal.log b/tests/update/journal.log index 376a0a11..b0c472f8 100644 --- a/tests/update/journal.log +++ b/tests/update/journal.log @@ -1374,10 +1374,10 @@ 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