diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-07-28 01:47:15 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:26 +0100 |
commit | 0e0d5664045ce234b75a5cfe91dc4121c93b4bed (patch) | |
tree | 5e4d1513572c9415e04d4358d1fa6d6b4666574f /rules.js | |
parent | 1251e90775534849ef2f57a70a808d4626ccbf6d (diff) | |
download | rommel-in-the-desert-0e0d5664045ce234b75a5cfe91dc4121c93b4bed.tar.gz |
Cleanups
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 186 |
1 files changed, 103 insertions, 83 deletions
@@ -177,9 +177,11 @@ function is_map_hex(x) { function is_hex_or_adjacent_to(x, where) { if (x === where) return true - for (let s = 0; s < 6; ++s) - if (x === where + hexnext[s]) + for (let s = 0; s < 6; ++s) { + let y = where + hexnext[s] + if (is_map_hex(y) && x === y) return true + } return false } @@ -205,6 +207,42 @@ var supply_allied_line = new Array(sidecount).fill(0) var first_friendly_unit, last_friendly_unit var first_enemy_unit, last_enemy_unit +function set_active_player() { + game.active = game.phasing + update_aliases() +} + +function set_passive_player() { + if (game.phasing === AXIS) + game.active = ALLIED + else + game.active = AXIS + update_aliases() +} + +function set_enemy_player() { + if (is_active_player()) + set_passive_player() + else + set_active_player() +} + +function is_active_player() { + return game.active === game.phasing +} + +function is_passive_player() { + return game.active !== game.phasing +} + +function is_axis_player() { + return game.active === AXIS +} + +function is_allied_player() { + return game.active === ALLIED +} + function update_aliases() { if (game.active === AXIS) { first_friendly_unit = first_axis_unit @@ -1333,82 +1371,7 @@ function find_valid_regroup_destinations(from, rommel) { } } -// === TURN === - -function set_active_player() { - game.active = game.phasing - update_aliases() -} - -function set_passive_player() { - if (game.phasing === AXIS) - game.active = ALLIED - else - game.active = AXIS - update_aliases() -} - -function set_enemy_player() { - if (is_active_player()) - set_passive_player() - else - set_active_player() -} - -function is_active_player() { - return game.active === game.phasing -} - -function is_passive_player() { - return game.active !== game.phasing -} - -function is_axis_player() { - return game.active === AXIS -} - -function is_allied_player() { - return game.active === ALLIED -} - -function end_player_turn() { - // Forget partial retreats - set_clear(game.partial_retreats) - - // Reveal supply cards - log_br() - log(`Supply Cards Played:\n${game.commit[0]} real and ${game.commit[1]} dummy.`) - game.commit = [ 0, 0 ] - - if (game.passed === 2) - return end_month() - - if (game.phasing === AXIS) - game.phasing = ALLIED - else - game.phasing = AXIS - set_active_player() - goto_player_turn() -} - -function goto_player_turn() { - log_h2(game.phasing) - - // paranoid resetting of state - game.side_limit = {} - game.rommel = 0 - game.from1 = game.from2 = 0 - game.to1 = game.to2 = 0 - - // reset moved and fired flags - game.forced = [] - set_clear(game.fired) - set_clear(game.moved) - - game.commit = [ 0, 0 ] - - goto_initial_supply_check() -} +// === SUPPLY COMMITMENT === function goto_supply_commitment() { game.state = 'supply_commitment' @@ -1446,6 +1409,18 @@ states.supply_commitment = { function goto_turn_option() { set_active_player() + + let n = game.commit[0] + game.commit[1] + if (n === 0) + log(`Played zero supply cards.`) + else if (n === 1) + log(`Played one supply card.`) + else if (n === 2) + log(`Played two supply cards.`) + else if (n === 3) + log(`Played three supply cards.`) + log_br() + game.state = 'turn_option' } @@ -1502,6 +1477,49 @@ states.turn_option = { }, } +// === PLAYER TURN === + +function goto_player_turn() { + set_active_player() + + log_h2(game.phasing) + + // paranoid resetting of state + game.side_limit = {} + game.rommel = 0 + game.from1 = game.from2 = 0 + game.to1 = game.to2 = 0 + + // reset moved and fired flags + game.forced = [] + set_clear(game.fired) + set_clear(game.moved) + + game.commit = [ 0, 0 ] + + goto_initial_supply_check() +} + +function end_player_turn() { + // Forget partial retreats + set_clear(game.partial_retreats) + + // Reveal supply cards + log_br() + log(`Supply Cards Revealed:\n${game.commit[0]} real and ${game.commit[1]} dummy.`) + game.commit = [ 0, 0 ] + + if (game.passed === 2) + return end_month() + + if (game.phasing === AXIS) + game.phasing = ALLIED + else + game.phasing = AXIS + + goto_player_turn() +} + // === INITIAL & FINAL SUPPLY CHECK === function goto_initial_supply_check() { @@ -3116,7 +3134,8 @@ function goto_hits() { game.hits[2] |= 0 game.hits[3] |= 0 - if (game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] > 0) { + // TODO: if (game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] > 0) { + if (true) { if (game.state === 'battle_fire') game.state = 'battle_hits' else @@ -3377,7 +3396,7 @@ function goto_pursuit_fire_during_refuse_battle(where) { if (can_pursuit_fire(true)) game.state = 'pursuit_fire' else - goto_pursuit_hits() + end_pursuit_fire() } function goto_rout_hits() { @@ -3390,7 +3409,8 @@ function goto_rout_hits() { function goto_pursuit_hits() { set_enemy_player() - if (game.hits > 0) + // TODO: if (game.hits > 0) + if (true) game.state = 'pursuit_hits' else end_pursuit_fire() @@ -3420,7 +3440,7 @@ function can_rout_fire(verbose) { let result = false let slowest = slowest_enemy_unit_speed(game.pursuit) if (verbose) - log(`Slowest routing unit was ${speed_name[slowest]} ${game.active} at #${game.pursuit}.`) + log(`Slowest was ${speed_name[slowest]} unit.`) for_each_undisrupted_friendly_unit_in_hex(game.pursuit, u => { if (unit_speed(u) >= slowest && !is_unit_fired(u)) result = true @@ -3432,7 +3452,7 @@ function can_pursuit_fire(verbose) { let result = false let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) if (verbose) - log(`Slowest retreating unit was ${speed_name[slowest]} ${game.active} at #${game.pursuit}.`) + log(`Slowest was ${speed_name[slowest]} unit.`) for_each_undisrupted_friendly_unit_in_hex(game.pursuit, u => { if (unit_speed(u) >= slowest && !is_unit_fired(u)) result = true |