summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js86
1 files changed, 61 insertions, 25 deletions
diff --git a/rules.js b/rules.js
index 9697695..4d93492 100644
--- a/rules.js
+++ b/rules.js
@@ -8,13 +8,14 @@
// TODO: legal pass withdrawal moves (reduce supply net, withdraw from fortress attack)
// TOOD: reveal/hide blocks (hexes)
// TODO: group move from queue holding box to base
-// TODO: unit class/speed in battle flash
// TODO: redeployment
// TODO: return for refit
// TODO: replacements
// TODO: malta units
+// TODO: black hit outline in battles ("steploss/bad" action)
+
// RULES: may units redeploying out of battles cross enemy controlled hexsides?
// RULES: when is "fired" status cleared?
@@ -76,8 +77,13 @@ const hexcount = last_hex + 1
const sidecount = hexcount * 3
const class_name = [ "armor", "infantry", "anti-tank", "artillery" ]
+const class_name_cap = [ "Armor", "Infantry", "Anti-tank", "Artillery" ]
const firepower_name = [ "0", "1", "2", "3", "TF", "DF", "SF" ]
const speed_name = [ "zero", "leg", "motorized", "mechanized", "recon" ]
+const speed_name_cap = [ "Zero", "Leg", "Motorized", "Mechanized", "Recon" ]
+
+const die_face_hit = [ 0, '\u2776', '\u2777', '\u2778', '\u2779', '\u277A', '\u277B' ]
+const die_face_miss = [ 0, '\u2460', '\u2461', '\u2462', '\u2463', '\u2464', '\u2465' ]
const SF = 6
const DF = 5
@@ -1715,6 +1721,8 @@ states.initial_supply_check_rout = {
function goto_final_supply_check() {
set_active_player()
+ log_br()
+
capture_fortress(BARDIA, 2)
capture_fortress(BENGHAZI, 2)
capture_fortress(TOBRUK, 5)
@@ -2382,7 +2390,7 @@ states.forced_marches = {
let from = game.forced[ix][2] || via
let roll = roll_die()
if (roll >= 4) {
- log(`Forced March roll ${roll} success.`)
+ log(`Forced March roll ${die_face_hit[roll]} success.`)
if (has_enemy_unit(to)) {
engage_via(who, via, to, false)
} else {
@@ -2390,7 +2398,7 @@ states.forced_marches = {
log(`>from #${via} to #${to}`)
}
} else {
- log(`Forced March roll ${roll} failed!`)
+ log(`Forced March roll ${die_face_miss[roll]} failed!`)
if (from !== via) {
log(`>returned to #${from}`)
set_unit_hex(who, from)
@@ -2461,6 +2469,8 @@ function can_any_retreat(from) {
}
function can_all_retreat(from) {
+ if (!has_undisrupted_friendly_unit(from))
+ return false
let result = true
for_each_undisrupted_friendly_unit_in_hex(from, u => {
if (result === true && !is_unit_moved(u) && !can_unit_retreat(u))
@@ -3197,16 +3207,19 @@ function roll_battle_fire(who, tc) {
let total = 0
for (let i = 0; i < cv; ++i) {
let roll = roll_die()
- result.push(roll)
- if (roll >= fp)
+ if (roll >= fp) {
+ result.push(die_face_hit[roll])
++total
+ } else {
+ result.push(die_face_miss[roll])
+ }
}
// Double defense in minefields!
if (is_minefield_offensive_fire())
total = total / 2
- game.flash = `${unit_name(who)} fired ${firepower_name[fp]} ${result.join(", ")} at ${class_name[tc]}`
+ game.flash = `${class_name_cap[fc]} ${firepower_name[fp]} ${result.join("")} at ${class_name[tc]}`
log(game.flash)
return total
}
@@ -3274,8 +3287,8 @@ function goto_hits() {
game.hits[2] |= 0
game.hits[3] |= 0
- // TODO: if (game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] > 0) {
- if (true) {
+ // XXX if (true) {
+ if (game.hits[0] + game.hits[1] + game.hits[2] + game.hits[3] > 0) {
if (game.state === 'battle_fire')
game.state = 'battle_hits'
else
@@ -3526,7 +3539,7 @@ function goto_pursuit_fire_during_retreat(where) {
if (can_pursuit_fire(true))
game.state = 'pursuit_fire'
else
- goto_pursuit_hits()
+ end_pursuit_fire()
}
function goto_pursuit_fire_during_refuse_battle(where) {
@@ -3549,8 +3562,8 @@ function goto_rout_hits() {
function goto_pursuit_hits() {
set_enemy_player()
- // TODO: if (game.hits > 0)
- if (true)
+ // XXX if (true)
+ if (game.hits > 0)
game.state = 'pursuit_hits'
else
end_pursuit_fire()
@@ -3601,23 +3614,35 @@ function can_pursuit_fire(verbose) {
}
function roll_pursuit_fire_imp(who, n, hp) {
+ let speed = unit_speed(who)
if (n === 2) {
let a = roll_die()
let b = roll_die()
- game.flash = `${unit_name(who)} fired ${a}, ${b}`
- log(game.flash)
- if (a >= 4)
+ if (a >= 4) {
game.hits++
- if (b >= 4)
+ a = die_face_hit[a]
+ } else {
+ a = die_face_miss[a]
+ }
+ if (b >= 4) {
game.hits++
+ b = die_face_hit[b]
+ } else {
+ b = die_face_miss[b]
+ }
+ game.flash = `${speed_name_cap[speed]} fired ${a}${b}`
}
if (n === 1) {
let a = roll_die()
- game.flash = `${unit_name(who)} fired ${a}`
- log(`>%${who} pursuit fired ${a}.`)
- if (a >= 4)
+ game.flash = `${speed_name_cap[speed]} fired ${a}`
+ if (a >= 4) {
game.hits++
+ a = die_face_hit[a]
+ } else {
+ a = die_face_miss[a]
+ }
}
+ log(game.flash)
if (game.hits > hp)
game.hits = hp
return game.hits === hp
@@ -3816,7 +3841,9 @@ function init_buildup() {
game.buildup = {
// redeployment network
axis_network: axis_supply_network().slice(),
+ axis_line: axis_supply_line().slice(),
allied_network: allied_supply_network().slice(),
+ allied_line: allied_supply_line().slice(),
// extra cards purchased
axis_cards: 0,
allied_cards: 0,
@@ -4299,8 +4326,8 @@ function begin_game() {
// No buildup first month
// No initiative first month
- // XXX goto_player_turn()
- goto_buildup()
+ goto_player_turn()
+ // goto_buildup()
}
// === SETUP ===
@@ -4872,11 +4899,20 @@ exports.view = function(state, current) {
exports.query = function (state, current, q) {
if (q === 'supply') {
load_state(state)
- return {
- axis_supply: axis_supply_network(),
- axis_supply_line: axis_supply_line(),
- allied_supply: allied_supply_network(),
- allied_supply_line: allied_supply_line(),
+ if (game.buildup) {
+ return {
+ axis_supply: game.buildup.axis_network,
+ axis_supply_line: game.buildup.axis_line,
+ allied_supply: game.buildup.allien_network,
+ allied_supply_line: game.buildup.allied_line,
+ }
+ } else {
+ return {
+ axis_supply: axis_supply_network(),
+ axis_supply_line: axis_supply_line(),
+ allied_supply: allied_supply_network(),
+ allied_supply_line: allied_supply_line(),
+ }
}
}
return null