diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-09-18 10:44:21 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:27 +0100 |
commit | 620f03818f45aaadf283e554677bec8300836945 (patch) | |
tree | 7cb5e4298ca6b70af63caa3c4455eb9826ac54f3 /rules.js | |
parent | 6e448b431b2f501832e0a85cbfbc05f9a7892d20 (diff) | |
download | rommel-in-the-desert-620f03818f45aaadf283e554677bec8300836945.tar.gz |
Log step losses and elimination during rout attrition.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 48 |
1 files changed, 41 insertions, 7 deletions
@@ -442,6 +442,10 @@ function eliminate_unit(u) { hide_unit(u) } +function is_unit_eliminated(u) { + return unit_hex(u) === ELIMINATED +} + function reduce_unit(u) { let s = unit_steps(u) let hp = unit_hp_per_step(u) @@ -3867,10 +3871,13 @@ states.forced_marches = { } else { log(`>${die_face_miss[roll]} disrupted at #${from}`) set_unit_hex(who, from) - if (is_unit_disrupted(who)) + if (is_unit_disrupted(who)) { reduce_unit(who) // was a retreating unit - else + if (is_unit_eliminated(who)) + log(`Eliminated at #${from}.`) + } else { set_unit_disrupted(who) + } } game.forced.splice(ix, 1) @@ -4418,10 +4425,12 @@ function goto_rout(from, enemy, after) { set_delete(game.recover, u) }) - if (can_all_units_disengage_and_withdraw(from)) + if (can_all_units_disengage_and_withdraw(from)) { game.state = 'rout_attrition' - else + } else { game.state = 'rout_elimination' + game.summary = 0 + } } states.rout_elimination = { @@ -4433,10 +4442,13 @@ states.rout_elimination = { }) }, unit(who) { - log(`Eliminated at #${game.rout.from}.`) + game.summary++ eliminate_unit(who) - if (!has_friendly_unit(game.rout.from)) + if (!has_friendly_unit(game.rout.from)) { + log(`Eliminated ${game.summary} at #${game.rout.from}.`) + game.summary = null end_rout() + } }, } @@ -4458,8 +4470,22 @@ states.rout_attrition = { done = false }) if (done) { + let d = 0, e = 0 + for (let u of game.rout.attrition) + if (is_unit_eliminated(u)) + ++e + else + ++d + if (d > 0) + log(`Reduced ${e} at #${game.rout.from}.`) + if (e > 0) + log(`Eliminated ${e} at #${game.rout.from}.`) game.rout.attrition = null - goto_rout_fire(game.rout.from) + + if (has_friendly_unit(game.rout.from)) + goto_rout_fire(game.rout.from) + else + end_rout() } }, } @@ -5421,7 +5447,11 @@ states.pursuit_hits = { }, unit_hit(who) { push_undo() + // TODO: flash? + let where = unit_hex(who) game.hits -= reduce_unit(who) + if (is_unit_eliminated(who)) + log(`Eliminated at #${where}.`) }, end_hits() { end_pursuit_fire() @@ -5439,7 +5469,11 @@ states.rout_hits = { }, unit_hit(who) { push_undo() + // TODO: flash? + let where = unit_hex(who) game.hits -= reduce_unit(who) + if (is_unit_eliminated(who)) + log(`Eliminated at #${where}.`) }, end_hits() { end_rout_fire() |