From 88eabb2b84ff90377630a722a0f593189c6704ad Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 2 Jul 2021 20:48:01 +0200 Subject: crusader: Merge move phases and make sea moves by sea. --- data.js | 4 +- play.html | 90 ++++++++++++++++++++++++++++++++++++++++-- rules.js | 131 ++++++++++++++++++++++++++++++++++++++++---------------------- ui.js | 11 +++++- 4 files changed, 185 insertions(+), 51 deletions(-) diff --git a/data.js b/data.js index 0af45a8..0255d5a 100644 --- a/data.js +++ b/data.js @@ -128,8 +128,9 @@ const TOWNS = { "Germania":{"x":140,"y":272}, "France":{"x":140,"y":573}, "England":{"x":140,"y":873}, + "Sea":{"x":320,"y":900}, "FP":{"x":50,"y":2150}, - "SP":{"x":50,"y":2150}, + "SP":{"x":125,"y":2150}, "Dead":{"x":50,"y":80}, }; @@ -266,6 +267,7 @@ const PORTS = []; town('Y', 0.0, 0.0, 30, "Pool", "FP", 0, "pool"); town('Y', 0.0, 0.0, 30, "Pool", "SP", 0, "pool"); town('Y', 1.0, 1.0, 30, "Pool", "Dead", 0, "pool"); + town('Y', 1.0, 1.0, 30, "Pool", "Sea", 0, "pool"); town('Y', 1.0, 0.5, 3, "Staging", "England", 3, "staging"); town('Y', 1.0, 0.5, 3, "Staging", "France", 3, "staging"); diff --git a/play.html b/play.html index 0128af5..ac6ab2b 100644 --- a/play.html +++ b/play.html @@ -105,7 +105,7 @@ .map.tall { width: 1275px; height: 2475px; - background-image: url("map-v.jpg"); + background-color: #224467; } .map.wide { @@ -153,6 +153,14 @@ box-shadow: 0 0 0px 4px white; } +#sea { + fill: skyblue; + fill-opacity: 0.4; +} + +#sea { visibility: hidden; } +#sea.highlight { visibility: visible; cursor: pointer; } + /* BLOCKS */ body.shift .block.known:hover { @@ -185,8 +193,8 @@ body.shift .block.known:hover { .block.Franks.highlight { border-color: white; } .block.Saracens.highlight { border-color: lightgreen; } -.block.Franks.selected { border-color: gold; } -.block.Saracens.selected { border-color: gold; } +.block.Franks.selected { border-color: hotpink; } +.block.Saracens.selected { border-color: yellow; } .block.Assassins.selected { border-color: hotpink; } .block.Franks.highlight:not(.selected) { box-shadow: 0 0 4px 1px white; } @@ -478,6 +486,82 @@ X#FR { background-image: linear-gradient(182deg, tan 30%, olivedrab 35%); }
+ + + + + + + +
diff --git a/rules.js b/rules.js index f368858..df581e5 100644 --- a/rules.js +++ b/rules.js @@ -23,6 +23,7 @@ const BOTH = "Both"; const DEAD = "Dead"; const F_POOL = "FP"; const S_POOL = "SP"; +const SEA = "Sea"; const ENGLAND = "England"; const FRANCE = "France"; const GERMANIA = "Germania"; @@ -70,6 +71,7 @@ const NO_MARK = ""; delete TOWNS[DEAD]; delete TOWNS[F_POOL]; delete TOWNS[S_POOL]; +delete TOWNS[SEA]; let states = {}; @@ -1536,9 +1538,10 @@ states.move_phase = { gen_action_undo(view); gen_action(view, 'end_move_phase'); if (game.moves > 0) { - gen_action(view, 'group_move'); - if (can_sea_move_anywhere()) - gen_action(view, 'sea_move'); + let sea_moves_allowed = (game.active != game.guide && game.active != game.jihad); + for (let b in BLOCKS) + if (can_block_land_move(b) || (sea_moves_allowed && can_block_sea_move(b))) + gen_action(view, 'block', b); if (can_muster_anywhere()) gen_action(view, 'muster'); if (game.winter_campaign == game.active) @@ -1550,31 +1553,88 @@ states.move_phase = { --game.moves; game.state = 'winter_campaign'; }, - group_move: function () { - push_undo(); - --game.moves; - game.state = 'group_move_first'; - game.summary = []; - }, - sea_move: function () { - push_undo(); - game.state = 'sea_move'; - }, muster: function () { push_undo(); --game.moves; game.state = 'muster'; }, + block: function (who) { + game.summary = []; + push_undo(); + game.who = who; + game.where = game.location[who]; + if (game.where == GERMANIA || game.where == FRANCE || game.where == ENGLAND) { + game.state = 'sea_move_to'; + } else { + game.state = 'move_phase_to'; + } + }, end_move_phase: end_move_phase, undo: pop_undo } +// Start new group move or sea move. +states.move_phase_to = { + prompt: function (view, current) { + if (is_inactive_player(current)) + return view.prompt = "Move Phase: Waiting for " + game.active + "."; + view.prompt = "Move Phase: Move " + block_name(game.who); + gen_action_undo(view); + gen_action(view, 'block', game.who); + let from = game.location[game.who]; + let can_group_move = false; + let can_sea_move = false; + for (let to of TOWNS[from].exits) { + if (can_block_land_move_to(game.who, from, to)) { + gen_action(view, 'town', to); + can_group_move = true; + } + } + if (can_block_sea_move(game.who)) { + gen_action(view, 'town', SEA); + can_sea_move = true; + } + if (can_group_move && can_sea_move) + view.prompt += " by road or by sea."; + else if (can_sea_move) + view.prompt += " by sea."; + else + view.prompt += " by road."; + }, + town: function (to) { + let from = game.location[game.who]; + if (to == SEA) { + log_move_start(from); + log_move_continue(to); + game.location[game.who] = SEA; + game.state = 'sea_move_to'; + return; + } + -- game.moves; + game.distance = 0; + log_move_start(from); + let mark = move_block(game.who, from, to); + if (mark) + log_move_continue(to + mark); + else + log_move_continue(to); + lift_siege(from); + game.last_from = from; + if (!can_block_continue(game.who, from, to)) + end_move(); + else { + game.state = 'group_move_to'; + } + }, + block: pop_undo, + undo: pop_undo +} + // GROUP MOVE -function group_move_phase(inactive = 0) { +function group_move_name(inactive = 0) { if (game.active == game.jihad) return "Jihad: "; if (game.active == game.guide) return "Guide: "; - if (inactive) return "Move Phase: "; return "Group Move: "; } @@ -1589,8 +1649,8 @@ function can_group_move_more() { states.group_move_first = { prompt: function (view, current) { if (is_inactive_player(current)) - return view.prompt = group_move_phase(1) + "Waiting for " + game.active + "."; - view.prompt = group_move_phase(0) + "Choose a block to group move."; + return view.prompt = group_move_name(1) + "Waiting for " + game.active + "."; + view.prompt = group_move_name(0) + "Choose a block to group move."; gen_action_undo(view); if (game.active == game.guide || game.active == game.jihad) gen_action(view, 'end_move_phase'); @@ -1613,8 +1673,8 @@ states.group_move_first = { states.group_move_who = { prompt: function (view, current) { if (is_inactive_player(current)) - return view.prompt = group_move_phase(1) + "Waiting for " + game.active + "."; - view.prompt = group_move_phase(0) + "Choose a block to group move."; + return view.prompt = group_move_name(1) + "Waiting for " + game.active + "."; + view.prompt = group_move_name(0) + "Move blocks from " + game.where + "."; gen_action_undo(view); if (game.active == game.guide || game.active == game.jihad) gen_action(view, 'end_move_phase'); @@ -1640,8 +1700,8 @@ states.group_move_who = { states.group_move_to = { prompt: function (view, current) { if (is_inactive_player(current)) - return view.prompt = group_move_phase(1) + "Waiting for " + game.active + "."; - view.prompt = group_move_phase(0) + "Move " + block_name(game.who) + "."; + return view.prompt = group_move_name(1) + "Waiting for " + game.active + "."; + view.prompt = group_move_name(0) + "Move " + block_name(game.who) + "."; gen_action_undo(view); if (game.distance == 0) gen_action(view, 'block', game.who); @@ -1706,32 +1766,14 @@ function end_group_move() { // SEA MOVE -states.sea_move = { - prompt: function (view, current) { - if (is_inactive_player(current)) - return view.prompt = "Move Phase: Waiting for " + game.active + "."; - view.prompt = "Sea Move: Choose a block to move."; - gen_action_undo(view); - for (let b in BLOCKS) - if (can_block_sea_move(b)) - gen_action(view, 'block', b); - }, - end_sea_move: function () { - game.state = 'move_phase'; - }, - block: function (who) { - game.who = who; - game.state = 'sea_move_to'; - }, - undo: pop_undo -} - states.sea_move_to = { prompt: function (view, current) { if (is_inactive_player(current)) return view.prompt = "Move Phase: Waiting for " + game.active + "."; if (is_english_crusader(game.who)) view.prompt = "Sea Move: Move " + block_name(game.who) + " to a port."; + else if (game.where == GERMANIA) + view.prompt = "Move Phase: Move " + block_name(game.who) + " to Aleppo, Antioch, or St. Simeon."; else view.prompt = "Sea Move: Move " + block_name(game.who) + " to a friendly port."; gen_action_undo(view); @@ -1744,7 +1786,7 @@ states.sea_move_to = { gen_action(view, 'town', ST_SIMEON); } else { for (let to of PORTS) - if (to != from && can_block_sea_move_to(game.who, to)) + if (to != game.where && can_block_sea_move_to(game.who, to)) gen_action(view, 'town', to); } }, @@ -1787,10 +1829,7 @@ states.sea_move_to = { game.who = null; game.state = 'move_phase'; }, - block: function () { - game.who = null; - game.state = 'sea_move'; - }, + block: pop_undo, undo: pop_undo, } diff --git a/ui.js b/ui.js index 90c8ac0..1460612 100644 --- a/ui.js +++ b/ui.js @@ -375,7 +375,16 @@ function build_map() { for (let name in TOWNS) { let town = TOWNS[name]; - ui.towns[name] = build_town(name, town); + if (name == "Sea") { + element = document.getElementById("svgmap").getElementById("sea"); + element.town = "Sea"; + element.addEventListener("mouseenter", on_focus_town); + element.addEventListener("mouseleave", on_blur_town); + element.addEventListener("click", on_click_town); + ui.towns[name] = element; + } else { + ui.towns[name] = build_town(name, town); + } } for (let b in BLOCKS) { -- cgit v1.2.3