summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-07-24 17:35:41 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:26 +0100
commit3b594c56a46ca24fa90a923864a4123c3d968b00 (patch)
tree51f0999bac23c16a016978f4e1d77940cbe18ee2
parentf05d21d531e0685918a506c6274e8821be8b2366 (diff)
downloadrommel-in-the-desert-3b594c56a46ca24fa90a923864a4123c3d968b00.tar.gz
zoop!
-rw-r--r--play.js8
-rw-r--r--rules.js134
2 files changed, 72 insertions, 70 deletions
diff --git a/play.js b/play.js
index 5c9601e..96b12a8 100644
--- a/play.js
+++ b/play.js
@@ -152,6 +152,8 @@ function is_unit_action(unit) {
}
function is_unit_selected(unit) {
+ if (Array.isArray(view.selected))
+ return view.selected.includes(unit)
return view.selected === unit
}
@@ -622,13 +624,13 @@ function on_update() {
else
ui.pursuit.classList.add("hide")
+ action_button("select_all", "Select all")
+
action_button("overrun", "Overrun")
action_button("rommel", "Rommel")
action_button("retreat", "Retreat")
- action_button("partial_retreat", "Partial retreat")
- action_button("full_retreat", "Full retreat")
- action_button("probe_combat", "Probe combat")
+ action_button("probe", "Probe")
action_button("group", "Group")
action_button("regroup", "Regroup")
diff --git a/rules.js b/rules.js
index f740ab4..afb16ef 100644
--- a/rules.js
+++ b/rules.js
@@ -1696,7 +1696,7 @@ states.move_who = {
retreat() {
push_undo()
log_br()
- game.state = 'retreat_select_from'
+ game.state = 'retreat_from'
},
end_move() {
clear_undo()
@@ -1734,7 +1734,7 @@ function can_select_retreat_hex() {
return result
}
-states.retreat_select_from = {
+states.retreat_from = {
prompt() {
view.prompt = `Retreat: Select hex to retreat from.`
if (game.from1) {
@@ -1763,88 +1763,96 @@ states.retreat_select_from = {
hex(x) {
push_undo()
game.retreat = x
- game.state = 'retreat_select_who'
+ game.state = 'retreat_who'
+ game.retreat_units = []
}
}
-states.retreat_select_who = {
+states.retreat_who = {
prompt() {
- view.prompt = `Retreat: Select unit to move.`
+ view.prompt = `Retreat: Select units to retreat.`
let full_retreat = true
for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
- if (!set_has(game.selected, u))
+ if (!set_has(game.retreat_units, u))
full_retreat = false
gen_action_unit(u)
})
- // No Partial Retreat allowed for Pass turn option.
- if (game.turn_option !== 'pass' && game.selected.length > 0)
- gen_action('partial_retreat')
- gen_action('full_retreat')
+ if (full_retreat) {
+ view.actions.retreat = 1
+ } else {
+ gen_action('select_all')
+ if (game.retreat_units.length > 0 && game.turn_option !== 'pass')
+ view.actions.retreat = 1
+ else
+ view.actions.retreat = 0
+ }
+ view.selected = game.retreat_units
},
unit(u) {
- console.log("set toggle", u)
- set_toggle(game.selected, u)
+ set_toggle(game.retreat_units, u)
},
- full_retreat() {
- clear_undo()
+ select_all() {
for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
- set_add(game.selected, u)
+ set_add(game.retreat_units, u)
})
- game.retreat_units = game.selected
- game.selected = []
- goto_pursuit_fire_during_retreat(game.retreat)
},
- partial_retreat() {
+ retreat() {
clear_undo()
- set_add(game.partial_retreats, game.retreat)
- set_passive_player()
- game.state = 'provoke_probe_combat'
+ let full_retreat = true
+ 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]}.`
- gen_action('probe_combat')
+ gen_action('probe')
gen_action('pass')
},
- // TODO: probe_combat
+ // TODO: probe
pass() {
set_active_player()
- game.retreat_units = game.selected
- game.selected = []
let shielded = false
for_each_undisrupted_friendly_unit_in_hex(game.retreat, u => {
if (!set_has(game.retreat_units, u))
shielded = true
})
if (shielded)
- goto_retreat_who()
+ goto_retreat_move()
else
goto_pursuit_fire_during_retreat(game.retreat)
},
}
-function goto_retreat_who() {
+function goto_retreat_move() {
set_active_player()
- game.state = 'retreat_who'
+ game.state = 'retreat_move'
}
-states.retreat_who = {
+states.retreat_move = {
prompt() {
view.prompt = `Retreat!`
-
- let done = true
- for (let u of game.retreat_units) {
- if (unit_hex(u) === game.retreat) {
- gen_action_unit(u)
- done = false
+ if (game.selected < 0) {
+ let done = true
+ for (let u of game.retreat_units) {
+ if (unit_hex(u) === game.retreat) {
+ gen_action_unit(u)
+ done = false
+ }
}
- }
- if (done)
- gen_action('end_retreat')
-
- if (game.selected.length > 0) {
+ if (done)
+ gen_action('end_retreat')
+ } else {
if (game.turn_option === 'pass')
gen_move(search_withdraw_retreat)
else
@@ -1852,22 +1860,22 @@ states.retreat_who = {
}
},
unit(who) {
- set_toggle(game.selected, who)
+ apply_select(who)
},
hex(to) {
- let list = game.selected
- game.selected = []
+ let who = pop_selected()
push_undo()
- for (let who of list) {
- set_unit_hex(who, to)
- set_unit_moved(who)
- set_unit_disrupted(who)
- }
+ set_unit_hex(who, to)
+ set_unit_moved(who)
+ set_unit_disrupted(who)
},
end_retreat() {
clear_undo()
+ if (!is_battle_hex(game.retreat))
+ release_hex_control(game.retreat)
+ game.retreat_units = null
if (can_select_retreat_hex())
- game.state = 'retreat_select_from'
+ game.state = 'retreat_from'
else
end_move_phase()
}
@@ -1875,9 +1883,6 @@ states.retreat_who = {
// === REFUSE BATTLE ===
-function gen_withdraw_group_move(who, from) {
-}
-
function goto_refuse_battle() {
clear_undo()
if (game.active_battles.length > 0) {
@@ -1908,7 +1913,7 @@ states.refuse_battle = {
}
}
-states.refuse_battle_withdraw = {
+states.refuse_battle_move = {
inactive: "refuse battle (withdraw group move)",
prompt() {
view.prompt = `Withdraw: Select unit to move.`
@@ -2071,8 +2076,7 @@ function goto_battle(x) {
}
function apply_battle_fire(tc) {
- let firing = game.selected[0]
- game.selected.length = 0
+ let firing = pop_selected()
let fp = FIREPOWER_MATRIX[unit_class(firing)][tc]
let cv = unit_cv(firing)
@@ -2124,7 +2128,7 @@ function gen_battle_target() {
for (let i = 0; i < 4; ++i)
hp[i] -= game.hits[i]
- let who = game.selected[0]
+ let who = game.selected
let fc = unit_class(who)
gen_action_unit(who) // deselect
@@ -2195,17 +2199,13 @@ states.battle_fire = {
view.prompt = `Offensive Fire!`
else
view.prompt = `Defensive Fire!`
- if (game.selected.length > 0) {
- gen_battle_target()
- } else {
+ if (game.selected < 0)
gen_battle_fire()
- }
+ else
+ gen_battle_target()
},
unit(who) {
- if (game.selected.length > 0)
- game.selected.length = 0
- else
- game.selected.push(who)
+ apply_select(who)
},
armor() {
apply_battle_fire(ARMOR)
@@ -2423,9 +2423,9 @@ function end_pursuit_fire() {
game.from1 = game.pursuit
game.pursuit = 0
if (game.retreat) {
- game.state = 'retreat_who'
+ game.state = 'retreat_move'
} else {
- game.state = 'refuse_battle_withdraw'
+ game.state = 'refuse_battle_move'
}
}