summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-06-23 15:23:22 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-21 00:28:20 +0200
commit59992c96a30db765689a713ebc373c67c06bc26f (patch)
tree4921ea3cd49eb88189f0db35d7551c9fda61cee4 /play.js
parentd34beb24b0202b00bb2523a16ab7275534bcedc9 (diff)
downloadwashingtons-war-59992c96a30db765689a713ebc373c67c06bc26f.tar.gz
move
Diffstat (limited to 'play.js')
-rw-r--r--play.js101
1 files changed, 81 insertions, 20 deletions
diff --git a/play.js b/play.js
index 4c37ce5..297866a 100644
--- a/play.js
+++ b/play.js
@@ -288,6 +288,10 @@ function on_init() {
ui.a_mcu = build_piece("marker cu american", 60+2, 60+2)
ui.f_mcu = build_piece("marker cu french", 60+2, 60+2)
+ ui.b_rcu = build_piece("marker cu british", 60+2, 60+2)
+ ui.a_rcu = build_piece("marker cu american", 60+2, 60+2)
+ ui.f_rcu = build_piece("marker cu french", 60+2, 60+2)
+
for (let s = 0; s < 7; ++s) {
let e = ui.seas[s] = document.createElement("div")
let [ x, y, w, h ] = data.layout.sea[s]
@@ -377,6 +381,8 @@ function general_offset(g) {
for (let i = 0; i < g; ++i) {
if (view.move && view.move.who === i)
continue
+ if (view.react && view.react.who === i)
+ continue
if (view.loca[i] === view.loca[g])
++n
}
@@ -388,12 +394,40 @@ function general_total(g) {
for (let i = 0; i < general_count; ++i) {
if (view.move && view.move.who === i)
continue
+ if (view.react && view.react.who === i)
+ continue
if (view.loca[i] === view.loca[g])
++n
}
return n
}
+function get_army_xy_lerp(s1, s2) {
+ let x, y
+ if (s1 >= 66) {
+ x = data.spaces[s1].x
+ y = data.spaces[s1].y - 40
+ } else {
+ x = (data.spaces[s1].x + data.spaces[s2].x) >> 1
+ y = (data.spaces[s1].y + data.spaces[s2].y) >> 1
+ }
+ if (s1 === s2)
+ y -= 40
+ return [ x, y ]
+}
+
+function get_army_xy(s) {
+ let x, y
+ if (s >= 66) {
+ x = data.spaces[s].x
+ y = data.spaces[s].y - 80
+ } else {
+ x = data.spaces[s].x
+ y = data.spaces[s].y - 40
+ }
+ return [ x, y ]
+}
+
function on_update() {
let e
@@ -404,6 +438,9 @@ function on_update() {
remember_position(ui.b_mcu)
remember_position(ui.a_mcu)
remember_position(ui.f_mcu)
+ remember_position(ui.b_rcu)
+ remember_position(ui.a_rcu)
+ remember_position(ui.f_rcu)
for (let g = 0; g < general_count; ++g)
remember_position(ui.generals[g])
@@ -432,32 +469,49 @@ function on_update() {
show_marker_at(ui.french_navy, data.layout.sea[view.french_navy][0]-15, data.layout.sea[view.french_navy][1]+42)
for (let s = 0; s < data.spaces.length; ++s) {
+ let acu = count_american_cu(s)
+ let fcu = count_french_cu(s)
+ let bcu = count_british_cu(s)
+
if (view.move && view.move.to === s) {
- toggle_marker_with_number(ui.a_cu[s], count_american_cu(s) - view.move.carry_american)
- toggle_marker_with_number(ui.f_cu[s], count_french_cu(s) - view.move.carry_french)
- toggle_marker_with_number(ui.b_cu[s], count_british_cu(s) - view.move.carry_british)
- } else {
- toggle_marker_with_number(ui.a_cu[s], count_american_cu(s))
- toggle_marker_with_number(ui.f_cu[s], count_french_cu(s))
- toggle_marker_with_number(ui.b_cu[s], count_british_cu(s))
+ acu -= view.move.carry_american
+ fcu -= view.move.carry_french
+ bcu -= view.move.carry_british
+ }
+ if (view.react && view.react.from === s) {
+ acu -= view.react.carry_american
+ fcu -= view.react.carry_french
+ bcu -= view.react.carry_british
}
+ toggle_marker_with_number(ui.a_cu[s], acu)
+ toggle_marker_with_number(ui.f_cu[s], fcu)
+ toggle_marker_with_number(ui.b_cu[s], bcu)
}
if (view.move) {
- let s = view.move.to
- let x = data.spaces[s].x
- let y = data.spaces[s].y
- if (s >= 66)
- y -= 40
+ let [ x, y ] = get_army_xy_lerp(view.move.from, view.move.to)
if (view.move.carry_american > 0 && view.move.carry_french > 0) {
- toggle_marker_with_number_at(ui.a_mcu, view.move.carry_american, x-15, y - 40)
- toggle_marker_with_number_at(ui.f_mcu, view.move.carry_french, x+15, y - 40)
+ toggle_marker_with_number_at(ui.a_mcu, view.move.carry_american, x-15, y)
+ toggle_marker_with_number_at(ui.f_mcu, view.move.carry_french, x+15, y)
} else {
- toggle_marker_with_number_at(ui.a_mcu, view.move.carry_american, x, y - 40)
- toggle_marker_with_number_at(ui.f_mcu, view.move.carry_french, x, y - 40)
+ toggle_marker_with_number_at(ui.a_mcu, view.move.carry_american, x, y)
+ toggle_marker_with_number_at(ui.f_mcu, view.move.carry_french, x, y)
}
- toggle_marker_with_number_at(ui.b_mcu, view.move.carry_british, x, y - 40)
+ toggle_marker_with_number_at(ui.b_mcu, view.move.carry_british, x, y)
+ }
+
+ if (view.react) {
+ let [ x, y ] = get_army_xy_lerp(view.react.from, view.react.to)
+
+ if (view.react.carry_american > 0 && view.react.carry_french > 0) {
+ toggle_marker_with_number_at(ui.a_rcu, view.react.carry_american, x-15, y)
+ toggle_marker_with_number_at(ui.f_rcu, view.react.carry_french, x+15, y)
+ } else {
+ toggle_marker_with_number_at(ui.a_rcu, view.react.carry_american, x, y)
+ toggle_marker_with_number_at(ui.f_rcu, view.react.carry_french, x, y)
+ }
+ toggle_marker_with_number_at(ui.b_rcu, view.react.carry_british, x, y)
}
for (let g = 0; g < general_count; ++g) {
@@ -466,15 +520,19 @@ function on_update() {
continue
let { x, y } = data.spaces[s]
+ if (view.move && view.move.who === g)
+ [ x, y ] = get_army_xy_lerp(view.move.from, view.move.to)
+ if (view.react && view.react.who === g)
+ [ x, y ] = get_army_xy_lerp(view.react.from, view.react.to)
if (s !== FRENCH_REINFORCEMENTS && count_french_cu(s) > 0)
x += 30
if (view.move && view.move.who === g) {
ui.generals[g].classList.add("selected")
- if (s >= 66)
- y -= 40
- y -= 40
+ x += 30
+ } else if (view.react && view.react.who === g) {
+ ui.generals[g].classList.add("selected")
x += 30
} else {
ui.generals[g].classList.remove("selected")
@@ -560,11 +618,14 @@ function on_update() {
action_button("drop_british_cu", "Drop CU")
action_button("drop_american_cu", "Drop CU")
+ action_button("no_general", "No General")
+
action_button("britain_first", "Britain")
action_button("america_first", "America")
action_button("surrender", "Surrender")
action_button("stop", "Stop")
+ action_button("roll", "Roll")
action_button("next", "Next")
action_button("done", "Done")
action_button("pass", "Pass")