summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js10
-rw-r--r--rules.js41
2 files changed, 33 insertions, 18 deletions
diff --git a/play.js b/play.js
index d9f402a..a8f675c 100644
--- a/play.js
+++ b/play.js
@@ -231,17 +231,11 @@ function is_side_allied_supply_line(side) {
}
function is_hex_selected(hex) {
+ if (hex === view.pursuit || hex === view.battle)
+ return true
return set_has(view.selected_hexes, hex)
}
-function is_hex_assault(hex) {
- return set_has(view.assaults, hex)
-}
-
-function is_hex_current(hex) {
- return hex === view.pursuit || hex === view.battle
-}
-
function focus_stack(stack) {
if (ui.focus !== stack) {
console.log("FOCUS STACK", stack)
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)
}