summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-07-14 15:54:02 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:25 +0100
commit652e53b4286bfc99466f5b13133f2c31cd877d0e (patch)
treee86f239f779bcd64c2b9699d3af0de922c455f95
parentc226f6393a3dc16b358ce58daf2dedb63d2a8da4 (diff)
downloadrommel-in-the-desert-652e53b4286bfc99466f5b13133f2c31cd877d0e.tar.gz
elite hit assignment
-rw-r--r--rules.js52
1 files changed, 45 insertions, 7 deletions
diff --git a/rules.js b/rules.js
index 48b62ee..7808384 100644
--- a/rules.js
+++ b/rules.js
@@ -1,5 +1,7 @@
"use strict"
+// TODO: partial moves during regroup (to allow deciding entry hex-side)
+
// unit state: location (8 bits), steps (2 bits), supplied, disrupted, moved
const max = Math.max
@@ -1567,14 +1569,32 @@ const xxx_fire = {
},
}
+function count_normal_steps() {
+ let steps = [ 0, 0, 0, 0 ]
+ for (let u = 0; u < units.length; ++u)
+ if (is_enemy_unit(u) && unit_hex(u) === game.battle)
+ steps[unit_class(u)] += unit_steps(u)
+}
+
+function count_elite_steps() {
+ let steps = [ 0, 0, 0, 0 ]
+ for (let u = 0; u < units.length; ++u)
+ if (is_enemy_unit(u) && unit_hex(u) === game.battle)
+ steps[unit_class(u)] += unit_steps(u)
+}
+
+function count_hp() {
+ let hp = [ 0, 0, 0, 0 ]
+ for (let u = 0; u < units.length; ++u)
+ if (is_enemy_unit(u) && unit_hex(u) === game.battle)
+ hp[unit_class(u)] += unit_hp(u)
+}
+
const xxx_fire_target = {
prompt() {
view.prompt = `Select a target class.`
- let hp = [ 0, 0, 0, 0 ]
- for (let u = 0; u < units.length; ++u)
- if (is_enemy_unit(u) && unit_hex(u) === game.battle)
- hp[unit_class(u)] += unit_hp(u)
+ let hp = count_hp()
for (let i = 0; i < 4; ++i)
hp[i] -= game.hits[i]
@@ -1638,12 +1658,30 @@ const xxx_fire_target = {
const xxx_fire_hits = {
prompt() {
view.prompt = `Apply hits.`
+
+ let normal_steps = count_normal_steps()
+ let elite_steps = count_elite_steps()
+
let done = true
for (let u = 0; u < units.length; ++u) {
if (is_friendly_unit(u) && unit_hex(u) === game.battle) {
- if (game.hits[unit_class(u)] > 0) {
- gen_action_unit(u)
- done = false
+ let c = unit_class(u)
+ if (is_unit_elite(u)) {
+ if (game.hits[c] >= 2) {
+ gen_action_unit(u)
+ done = false
+ }
+ } else {
+ if (game.hits[c] >= 1) {
+ // If mixed elite and non-elite: must assign ALL damage.
+ if (elite_steps[c] > 0 && normal_steps[c] === 1 && (game.hits[c] & 1) === 0) {
+ // Eliminating the last non-elite must not leave an odd
+ // number of hits remaining.
+ } else {
+ gen_action_unit(u)
+ done = false
+ }
+ }
}
}
}