summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js37
1 files changed, 8 insertions, 29 deletions
diff --git a/rules.js b/rules.js
index 6556386..c109de0 100644
--- a/rules.js
+++ b/rules.js
@@ -260,11 +260,13 @@ var first_friendly_unit, last_friendly_unit
var first_enemy_unit, last_enemy_unit
function set_active_player() {
+ clear_undo()
game.active = game.phasing
update_aliases()
}
function set_passive_player() {
+ clear_undo()
if (game.phasing === AXIS)
game.active = ALLIED
else
@@ -273,6 +275,7 @@ function set_passive_player() {
}
function set_enemy_player() {
+ clear_undo()
if (is_active_player())
set_passive_player()
else
@@ -1051,6 +1054,7 @@ function count_hp_in_rout() {
// === SUPPLY CARDS ===
function draw_supply_card(pile) {
+ clear_undo()
let x = random(pile[0] + pile[1])
if (x < pile[0]) {
pile[0] --
@@ -1084,6 +1088,7 @@ function deal_allied_supply_cards(n) {
}
function shuffle_cards() {
+ clear_undo()
let real = game.axis_hand[REAL] + game.allied_hand[REAL]
let dummy = game.axis_hand[DUMMY] + game.axis_hand[DUMMY]
game.draw_pile[0] = 28 - real
@@ -2347,8 +2352,6 @@ function goto_player_turn() {
}
function end_player_turn() {
- clear_undo()
-
// Forget partial retreats
set_clear(game.partial_retreats)
@@ -2942,7 +2945,6 @@ states.select_moves = {
goto_regroup()
},
end_turn() {
- clear_undo()
game.summary = null
goto_final_supply_check()
},
@@ -3331,7 +3333,6 @@ states.move = {
}
},
end_move() {
- clear_undo()
flush_move_summary()
if (game.turn_option === 'pass')
game.withdraw = null
@@ -3954,7 +3955,6 @@ states.retreat_from = {
goto_retreat_who(x)
},
end_move() {
- clear_undo()
log_br()
end_movement()
}
@@ -4007,7 +4007,6 @@ states.retreat_who = {
})
},
retreat() {
- clear_undo()
apply_retreat()
},
}
@@ -4162,7 +4161,6 @@ function can_select_refuse_battle_hex() {
}
function goto_refuse_battle() {
- clear_undo()
set_passive_player()
if (can_select_refuse_battle_hex()) {
game.state = 'refuse_battle'
@@ -4259,8 +4257,6 @@ function end_refuse_battle_move_2() {
// eliminated if cannot
function goto_rout(from, enemy, after) {
- clear_undo()
-
// remember state and callback so we can resume after routing
if (after)
after = after.name
@@ -4463,7 +4459,6 @@ states.select_active_battles = {
set_add(game.active_battles, x)
},
next() {
- clear_undo()
if (game.active_battles.length > 0) {
if (game.turn_option === 'assault')
game.state = 'select_assault_battles'
@@ -4490,7 +4485,6 @@ states.select_assault_battles = {
set_add(game.assault_battles, x)
},
next() {
- clear_undo()
goto_select_battle()
}
}
@@ -4883,7 +4877,6 @@ states.battle_hits = {
apply_battle_hit(who)
},
end_hits() {
- clear_undo()
end_battle_hits()
},
}
@@ -4952,7 +4945,6 @@ states.probe_hits = {
apply_battle_hit(who)
},
end_hits() {
- clear_undo()
end_probe_hits()
},
}
@@ -5236,7 +5228,6 @@ states.pursuit_hits = {
game.hits -= reduce_unit(who)
},
end_hits() {
- clear_undo()
end_pursuit_fire()
},
}
@@ -5255,7 +5246,6 @@ states.rout_hits = {
game.hits -= reduce_unit(who)
},
end_hits() {
- clear_undo()
end_rout_fire()
},
}
@@ -5468,7 +5458,6 @@ states.buildup_discard = {
game.summary++
},
next() {
- clear_undo()
log(`${game.active} discarded ${game.summary} dummy supply.`)
goto_buildup_reinforcements()
},
@@ -5865,7 +5854,6 @@ states.spending_bps = {
function end_buildup_spending() {
game.selected = -1
- clear_undo()
print_buildup_summary()
@@ -6213,8 +6201,6 @@ states.free_deployment = {
set_unit_hex(who, to)
},
end_deployment() {
- clear_undo()
-
log(`Deployed`)
let keys = Object.keys(game.summary).sort((a,b)=>a-b)
for (let x of keys)
@@ -6947,18 +6933,10 @@ function random(range) {
}
function roll_die() {
+ clear_undo()
return random(6) + 1
}
-function shuffle(deck) {
- for (let i = deck.length - 1; i > 0; --i) {
- let j = random(i + 1)
- let tmp = deck[j]
- deck[j] = deck[i]
- deck[i] = tmp
- }
-}
-
// Sorted array treated as Set (for JSON)
function set_index(set, item) {
let a = 0
@@ -7061,7 +7039,8 @@ function pop_undo() {
}
function clear_undo() {
- game.undo = []
+ if (game.undo.length > 0)
+ game.undo = []
}
function log_br() {