summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-10-05 15:15:25 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-30 13:26:51 +0100
commit44e59893bb32d9976fc45b79f00f993759408dce (patch)
treea631f48f6aa038f69f11a549ba8c6fbaefd71d15
parent11016ba45398d98a02e063de65e1e1fa9d73a58c (diff)
downloadcrusader-rex-44e59893bb32d9976fc45b79f00f993759408dce.tar.gz
Use broken highlight for placing drawn blocks at reduced strength.
-rw-r--r--play.css3
-rw-r--r--play.js15
-rw-r--r--rules.js47
3 files changed, 47 insertions, 18 deletions
diff --git a/play.css b/play.css
index 982fc4f..fd7dd13 100644
--- a/play.css
+++ b/play.css
@@ -144,6 +144,9 @@ body.Saracens header.your_turn { background-color: lightgreen; }
opacity: 0.6;
z-index: 9;
}
+.town.highlight.bad {
+ border-style: dashed;
+}
.town.tip {
opacity: 1;
border-color: yellow;
diff --git a/play.js b/play.js
index b675d31..6929382 100644
--- a/play.js
+++ b/play.js
@@ -181,7 +181,7 @@ function on_blur_town(evt) {
function on_click_town(evt) {
let where = evt.target.town
- send_action('town', where)
+ send_action('town', where) || send_action('townb', where)
}
const STEP_TEXT = [ 0, "I", "II", "III", "IIII" ]
@@ -652,11 +652,20 @@ function update_map() {
if (ui.towns[t]) {
ui.towns[t].classList.remove('highlight')
ui.towns[t].classList.remove('muster')
+ ui.towns[t].classList.remove('bad')
}
}
- if (view.actions && view.actions.town)
- for (let t of view.actions.town)
+ if (view.actions && view.actions.town) {
+ for (let t of view.actions.town) {
ui.towns[t].classList.add('highlight')
+ }
+ }
+ if (view.actions && view.actions.townb) {
+ for (let t of view.actions.townb) {
+ ui.towns[t].classList.add('highlight')
+ ui.towns[t].classList.add('bad')
+ }
+ }
if (view.muster)
ui.towns[view.muster].classList.add('muster')
diff --git a/rules.js b/rules.js
index 4b0798c..e40caa5 100644
--- a/rules.js
+++ b/rules.js
@@ -93,6 +93,27 @@ const ATTACK_MARK = "*"
const RESERVE_MARK_1 = "\u2020"
const RESERVE_MARK_2 = "\u2021"
+const block_seats = []
+const block_seat_names = []
+const block_seat_names_or = []
+
+function list_seats(who) {
+ if (block_type(who) === 'nomads')
+ return [ block_home(who) ]
+ let list = []
+ for (let town = first_town; town <= last_town; ++town)
+ if (set_has(SHIELDS[town], who))
+ list.push(town)
+ return list
+}
+
+for (let b = 0; b <= last_block; ++b) {
+ block_seats[b] = list_seats(b)
+ let names = block_seats[b].map(town_name)
+ block_seat_names[b] = names.join(", ")
+ block_seat_names_or[b] = join(names, "or")
+}
+
let states = {}
let game = null
@@ -279,16 +300,6 @@ function block_home(who) {
return BLOCKS[who].home
}
-function list_seats(who) {
- if (block_type(who) === 'nomads')
- return [ block_home(who) ]
- let list = []
- for (let town = first_town; town <= last_town; ++town)
- if (set_has(SHIELDS[town], who))
- list.push(town)
- return list
-}
-
function is_home_seat(where, who) {
if (block_type(who) === 'nomads')
return where === block_home(who)
@@ -1009,7 +1020,7 @@ states.frank_deployment = {
gen_action(view, 'next')
for (let b = 0; b <= last_block; ++b) {
if (block_owner(b) === game.active && is_block_on_land(b))
- if (list_seats(b).length > 1)
+ if (block_seats[b].length > 1)
gen_action(view, 'block', b)
}
if (errors.length > 0)
@@ -1033,11 +1044,11 @@ states.frank_deployment_to = {
prompt: function (view, current) {
if (is_inactive_player(current))
return view.prompt = "Deployment: Waiting for " + game.active + "."
- view.prompt = "Deployment: Move " + game.who + " to " + join(list_seats(game.who).map(town_name), "or") + "."
+ view.prompt = "Deployment: Move " + game.who + " to " + block_seat_names_or[game.who] + "."
gen_action_undo(view)
gen_action(view, 'block', game.who)
let from = game.location[game.who]
- for (let town of list_seats(game.who))
+ for (let town of block_seats[game.who])
if (town !== from)
gen_action(view, 'town', town)
},
@@ -3263,13 +3274,16 @@ states.draw_phase = {
case 'emirs':
case 'nomads':
view.prompt = "Draw Phase: Place " + block_name(game.who) + " at full strength in "
- + list_seats(game.who).map(town_name).join(", ") + " or at strength 1 in any friendly town."
+ + block_seat_names[game.who] + " or at strength 1 in any friendly town."
for (let town = first_town; town <= last_town; ++town) {
if (town === ENGLAND || town === FRANCE || town === GERMANIA)
continue
// FAQ claims besieger controls town for draw purposes
if (is_friendly_field(town)) {
- gen_action(view, 'town', town)
+ if (set_has(block_seats[game.who], town))
+ gen_action(view, 'town', town)
+ else
+ gen_action(view, 'townb', town)
can_place = true
}
}
@@ -3278,6 +3292,9 @@ states.draw_phase = {
if (!can_place)
gen_action(view, 'next')
},
+ townb: function (where) {
+ this.town(where)
+ },
town: function (where) {
let type = block_type(game.who)