summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js41
1 files changed, 31 insertions, 10 deletions
diff --git a/rules.js b/rules.js
index 3720c0d..1009f4b 100644
--- a/rules.js
+++ b/rules.js
@@ -2,9 +2,6 @@
// TODO: RAIDERS
-// TODO: group move from queue holding box to base
-// TODO: 1942 malta group (reinforce, reduce supply card draw)
-
// TODO: MINEFIELDS
// TODO: create minefields
// TODO: tear down 2 minefields to create new minefield
@@ -3919,6 +3916,33 @@ function gen_battle_target() {
}
}
+function apply_auto_target() {
+ let hp = count_hp_in_battle()
+ for (let i = 0; i < 4; ++i)
+ hp[i] -= game.hits[i]
+
+ let who = game.selected
+ let fc = unit_class[who]
+
+ // armor must target armor if possible
+ if (fc === ARMOR && hp[ARMOR] > 0)
+ return apply_battle_fire(ARMOR)
+
+ // infantry must target infantry if possible
+ if (fc === INFANTRY && hp[INFANTRY] > 0)
+ return apply_battle_fire(INFANTRY)
+
+ // only one class remains
+ if (hp[ARMOR] > 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0)
+ return apply_battle_fire(ARMOR)
+ if (hp[ARMOR] === 0 && hp[INFANTRY] > 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] === 0)
+ return apply_battle_fire(INFANTRY)
+ if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] > 0 && hp[ARTILLERY] === 0)
+ return apply_battle_fire(ANTITANK)
+ if (hp[ARMOR] === 0 && hp[INFANTRY] === 0 && hp[ANTITANK] === 0 && hp[ARTILLERY] > 0)
+ return apply_battle_fire(ARTILLERY)
+}
+
function gen_battle_hits() {
let normal_steps = count_normal_steps_in_battle()
let elite_steps = count_elite_steps_in_battle()
@@ -3968,6 +3992,8 @@ states.battle_fire = {
},
unit(who) {
apply_select(who)
+ if (game.selected >= 0)
+ apply_auto_target(who)
},
armor() {
apply_battle_fire(ARMOR)
@@ -5783,15 +5809,10 @@ exports.view = function(state, current) {
if (game.battle || game.pursuit) {
view.hits = game.hits
view.flash = game.flash
+ if (game.fired.length > 0)
+ view.fired = game.fired
}
- if (game.fired.length > 0 && (game.battle || game.pursuit))
- view.fired = game.fired
- if (game.active_battles.length > 0)
- view.battles = game.active_battles
- if (game.assault_battles.length > 0)
- view.assaults = game.assault_battles
-
return common_view(current)
}