summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.html4
-rw-r--r--rules.js81
2 files changed, 48 insertions, 37 deletions
diff --git a/play.html b/play.html
index 24acbc8..beffffe 100644
--- a/play.html
+++ b/play.html
@@ -369,7 +369,7 @@ svg .hex.allied_supply {
}
svg .side.axis_supply {
- stroke: darkslategray;
+ stroke: darkslategray !important;
stroke-width: 122px;
stroke-width: 121.5px;
stroke-width: 72px;
@@ -380,7 +380,7 @@ svg .side.axis_supply {
}
svg .side.allied_supply {
- stroke: darkred;
+ stroke: darkred !important;
stroke-width: 122px;
stroke-width: 121.5px;
stroke-width: 72px;
diff --git a/rules.js b/rules.js
index 184e081..bfbcdeb 100644
--- a/rules.js
+++ b/rules.js
@@ -1,8 +1,8 @@
"use strict"
-// TODO: valid pass withdrawal moves (reduce supply net, withdraw from fortress attack)
-// TODO: fortress combat in pass turns (must withdraw)
+// TODO: withdrawal pass regroup moves
+// TODO: clean up withdraw calculations and search_withdraw (pass supply source directly, not sample unit)
// TODO: log summaries (deploy, rebuild, move, etc)
// TODO: put initial deployment stack somewhere more accessible (spread out along the top?)
@@ -1908,7 +1908,6 @@ function is_valid_withdrawal_from(x) {
return can_all_units_disengage_and_withdraw(x);
} else {
// non-retreat withdrawal, check if network is reduced after we leave this hex
- // TODO: mixed supply source in hex (supplied and unsupplied)
if (can_all_units_withdraw(x)) {
let who = fastest_undisrupted_friendly_unit(x)
if (is_unit_supplied(who)) {
@@ -2738,6 +2737,7 @@ function goto_move() {
else if (game.from2)
log(`Group move\nfrom #${game.from2}.`)
}
+
log_br()
game.state = 'move'
}
@@ -2850,8 +2850,7 @@ states.move = {
},
retreat() {
push_undo()
- log_br()
- game.state = 'retreat_from'
+ goto_retreat()
},
overrun() {
let n = 0
@@ -3417,6 +3416,15 @@ function can_select_retreat_hex() {
return false
}
+function goto_retreat() {
+ log_br()
+ game.state = 'retreat_from'
+
+ // only one valid retreat hex
+ if (!game.to1 && !game.from2 && is_valid_retreat_hex(game.from1))
+ goto_retreat_who(game.from1)
+}
+
states.retreat_from = {
prompt() {
view.prompt = `Retreat: Select hex to retreat from.`
@@ -3449,9 +3457,7 @@ states.retreat_from = {
},
hex(x) {
push_undo()
- game.retreat = x
- game.state = 'retreat_who'
- game.retreat_units = []
+ goto_retreat_who(x)
},
end_move() {
clear_undo()
@@ -3460,6 +3466,19 @@ states.retreat_from = {
}
}
+function goto_retreat_who(from) {
+ game.retreat = from
+ game.state = 'retreat_who'
+ game.retreat_units = []
+ if (game.turn_option === 'pass') {
+ for_each_undisrupted_and_unmoved_friendly_unit_in_hex(game.retreat, u => {
+ if (can_unit_retreat(u))
+ game.retreat_units.push(u)
+ })
+ apply_retreat()
+ }
+}
+
states.retreat_who = {
prompt() {
view.prompt = `Retreat: Select units to retreat.`
@@ -3475,7 +3494,7 @@ states.retreat_who = {
view.actions.retreat = 1
} else {
gen_action('select_all')
- if (game.retreat_units.length > 0 && game.turn_option !== 'pass')
+ if (game.retreat_units.length > 0)
view.actions.retreat = 1
else
view.actions.retreat = 0
@@ -3494,23 +3513,27 @@ states.retreat_who = {
},
retreat() {
clear_undo()
- let full_retreat = true
- for (let u of game.retreat_units)
- hide_unit(u)
- for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
- if (!set_has(game.retreat_units, u))
- full_retreat = false
- })
- if (full_retreat) {
- goto_pursuit_fire_during_retreat(game.retreat)
- } else {
- set_add(game.partial_retreats, game.retreat)
- set_passive_player()
- game.state = 'provoke_probe_combat'
- }
+ apply_retreat()
},
}
+function apply_retreat() {
+ let full_retreat = true
+ for (let u of game.retreat_units)
+ hide_unit(u)
+ for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
+ if (!set_has(game.retreat_units, u))
+ full_retreat = false
+ })
+ if (full_retreat) {
+ goto_pursuit_fire_during_retreat(game.retreat)
+ } else {
+ set_add(game.partial_retreats, game.retreat)
+ set_passive_player()
+ game.state = 'provoke_probe_combat'
+ }
+}
+
states.provoke_probe_combat = {
prompt() {
view.prompt = `Retreat: You may provoke probe combat at ${hex_name[game.retreat]}.`
@@ -3731,17 +3754,6 @@ function end_refuse_battle_move_2() {
// withdraw by group move
// eliminated if cannot
-function can_disengage_from(from) {
- // TODO: check supply lines too...
- let n = 0
- for_each_adjacent_hex(from, to => {
- let side = to_side_id(from, to)
- if (side_limit[side] > 0 && !is_enemy_hexside(side))
- ++n
- })
- return n > 0
-}
-
function goto_rout(from, enemy, after) {
// remember state and callback so we can resume after routing
@@ -5000,7 +5012,6 @@ function replacement_cost(who) {
function can_redeploy_from(from) {
if (is_battle_hex(from)) {
let n = 0
- // TODO: can leave disrupted units behind to be routed?
for_each_undisrupted_friendly_unit_in_hex(from, u => {
n++
})