From 816d85811156e3853ca8e40dc791e4e2c6cd1022 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 29 Mar 2020 15:45:33 +0300 Subject: [PATCH] v1.3.11a --- modules/ui/regiment-editor.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/ui/regiment-editor.js b/modules/ui/regiment-editor.js index 01b5f6a9..73345a6e 100644 --- a/modules/ui/regiment-editor.js +++ b/modules/ui/regiment-editor.js @@ -142,17 +142,16 @@ function editRegiment(selector) { function splitRegiment() { const reg = regiment(), u1 = reg.u; - if (reg.a < 2) return; // nothing to split - const state = elSelected.dataset.state, military = pack.states[state].military; const i = last(military).i + 1, u2 = Object.assign({}, u1); // u clone - Object.keys(u1).forEach(u => u1[u] = Math.ceil(u1[u]/2)); // halved old reg Object.keys(u2).forEach(u => u2[u] = Math.floor(u2[u]/2)); // halved new reg - reg.a = d3.sum(Object.values(u1)); // old reg total const a = d3.sum(Object.values(u2)); // new reg total + if (!a) {tip("Not enough forces to split", false, "error"); return}; // nothing to add // update old regiment + Object.keys(u1).forEach(u => u1[u] = Math.ceil(u1[u]/2)); // halved old reg + reg.a = d3.sum(Object.values(u1)); // old reg total regimentComposition.querySelectorAll("input").forEach(el => el.value = reg.u[el.dataset.u]||0); elSelected.querySelector("text").innerHTML = Military.getTotal(reg);