diff --git a/src/SecExp/unitsBattleReport.tw b/src/SecExp/unitsBattleReport.tw index a414236c72c93006ccd876f72de1899aa68d8aef..87f3874b8461941f712f8b3071ff29a615d0dfb5 100644 --- a/src/SecExp/unitsBattleReport.tw +++ b/src/SecExp/unitsBattleReport.tw @@ -70,7 +70,8 @@ <<set _count += _lossesList[_i]>> <</for>> <<if _count < $losses>> - <<set _lossesList[random(_lossesList.length - 1)] += $losses - _count>> + <<set _rand = random(_lossesList.length - 1)>> + <<set _lossesList[_rand] += $losses - _count>> <<elseif _count > $losses>> <br>@@.red;Error: assigned losses higher than actual losses@@ <</if>> diff --git a/src/SecExp/unitsRebellionReport.tw b/src/SecExp/unitsRebellionReport.tw index 6f764c6746b4348a5a16818e2b47c708d74925b8..3054156b4337bf9b887e0e183d99bdb94969e8c9 100644 --- a/src/SecExp/unitsRebellionReport.tw +++ b/src/SecExp/unitsRebellionReport.tw @@ -283,6 +283,21 @@ <</if>> <<set _lossesList.shuffle()>> + /* sanity check for losses */ + <<set _count = 0>> + <<for _i = 0; _i < _lossesList.length; _i++>> + <<if !isInt(_lossesList[_i])>> + <<set _lossesList[_i] = 0>> + <</if>> + <<set _count += _lossesList[_i]>> + <</for>> + <<if _count < $losses>> + <<set _rand = random(_lossesList.length - 1)>> + <<set _lossesList[_rand] += $losses - _count>> + <<elseif _count > $losses>> + <br>@@.red;Error: assigned losses higher than actual losses@@ + <</if>> + /* assigns the losses and notify the player */ <<if $irregulars > 0>> <br>