From bfe3843eaac76ccc42547ba898eea3187628966e Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 23 Sep 2022 17:02:51 +0200 Subject: Add gen_action_space and gen_action_block helpers. --- rules.js | 94 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/rules.js b/rules.js index 0d4442d..abff25b 100644 --- a/rules.js +++ b/rules.js @@ -162,6 +162,14 @@ function gen_action(view, action, argument) { } } +function gen_action_block(view, b) { + gen_action(view, 'block', b) +} + +function gen_action_space(view, s) { + gen_action(view, 'space', s) +} + function edge_id(A, B) { if (A > B) return B + "/" + A @@ -752,7 +760,7 @@ states.free_deployment = { } for (let b of BLOCKLIST) if (block_owner(b) === game.active && is_map_space(game.location[b])) - gen_action(view, 'block', b) + gen_action_block(view, b) }, block: function (who) { push_undo() @@ -784,15 +792,15 @@ states.free_deployment_to = { format_deployment_error(view) } gen_action_undo(view) - gen_action(view, 'block', game.who) + gen_action_block(view, game.who) for (let space of SPACELIST) { if (space in game.setup_limit && space !== game.location[game.who]) { if (!is_enemy_city(space)) { if (block_type(game.who) === 'navis') { if (is_port(space)) - gen_action(view, 'space', space) + gen_action_space(view, space) } else { - gen_action(view, 'space', space) + gen_action_space(view, space) } } } @@ -1139,7 +1147,7 @@ function jupiter_block(b) { reduce_block(b) end_player_turn() } else { - game.owner[b] = game.active + set_toggle(game.traitor, b) game.who = b game.state = 'jupiter_to' } @@ -1195,7 +1203,7 @@ states.jupiter_to = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (is_friendly_city(to)) - gen_action(view, 'space', to) + gen_action_space(view, to) }, space: function (to) { log(block_name(game.who) + " joined " + game.active + ":\n" + @@ -1213,7 +1221,7 @@ states.vulcan = { view.prompt = "Vulcan: Choose an enemy city to suffer a volcanic eruption." for (let s of SPACELIST) if (is_enemy_city(s)) - gen_action(view, 'space', s) + gen_action_space(view, s) }, space: function (city) { log("Vulcan struck " + city + "!") @@ -1243,7 +1251,7 @@ states.apply_vulcan = { return view.prompt = "Waiting for " + game.active + "..." view.prompt = "Apply Vulcan hits in " + game.where + "." for (let i = 0; i < game.vulcan.length; ++i) - gen_action(view, 'block', game.vulcan[i]) + gen_action_block(view, game.vulcan[i]) }, block: function (who) { reduce_block(who) @@ -1285,7 +1293,7 @@ states.mars_and_neptune = { return view.prompt = god + ": Waiting for " + game.active + "." view.prompt = god + "Select battle for surprise attack." for (let space of game.surprise_list) - gen_action(view, 'space', space) + gen_action_space(view, space) }, space: function (where) { game.surprise = where @@ -1344,7 +1352,7 @@ states.move_who = { let from = game.location[b] if (game.activated.includes(from)) if (can_block_move(b)) - gen_action(view, 'block', b) + gen_action_block(view, b) } } else { let have_amphibious = false @@ -1357,7 +1365,7 @@ states.move_who = { if (can_block_move(b)) can_move = true if (can_move) - gen_action(view, 'block', b) + gen_action_block(view, b) } if (!have_amphibious) game.amphibious_available = false @@ -1393,9 +1401,9 @@ states.move_where = { if (can_block_move_to(game.who, to)) can_move_to = true if (can_move_to) - gen_action(view, 'space', to) + gen_action_space(view, to) } - gen_action(view, 'block', game.who); // for canceling move + gen_action_block(view, game.who); // for canceling move gen_action_undo(view) }, space: function (to) { @@ -1446,8 +1454,8 @@ states.move_where_2 = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (to !== game.last_from && can_block_continue_to(game.who, to)) - gen_action(view, 'space', to) - gen_action(view, 'space', from); // For ending move early. + gen_action_space(view, to) + gen_action_space(view, from); // For ending move early. gen_action_undo(view) }, space: function (to) { @@ -1472,7 +1480,7 @@ states.amphibious_move_to = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (to !== game.last_from && can_amphibious_move_to(game.who, from, to)) - gen_action(view, 'space', to) + gen_action_space(view, to) gen_action_undo(view) }, space: function (to) { @@ -1501,7 +1509,7 @@ states.mercury_move_1 = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (can_block_move_to(game.who, to)) - gen_action(view, 'space', to) + gen_action_space(view, to) gen_action_undo(view) }, space: function (to) { @@ -1532,8 +1540,8 @@ states.mercury_move_2 = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (to !== game.last_from && can_block_move_to(game.who, to)) - gen_action(view, 'space', to) - gen_action(view, 'space', from); // For ending move early. + gen_action_space(view, to) + gen_action_space(view, from); // For ending move early. gen_action_undo(view) }, space: function (to) { @@ -1567,8 +1575,8 @@ states.mercury_move_3 = { let from = game.location[game.who] for (let to of SPACES[from].exits) if (to !== game.last_from && can_block_continue_to(game.who, to)) - gen_action(view, 'space', to) - gen_action(view, 'space', from); // For ending move early. + gen_action_space(view, to) + gen_action_space(view, from); // For ending move early. gen_action_undo(view) }, space: function (to) { @@ -1609,7 +1617,7 @@ states.levy = { if (game.levies > 0) { for (let b of BLOCKLIST) { if (can_levy(b)) { - gen_action(view, 'block', b) + gen_action_block(view, b) is_levy_possible = true } } @@ -1651,8 +1659,8 @@ states.levy_where = { view.prompt = "Choose a friendly city to levy " + block_name(game.who) + " in." for (let to of SPACELIST) if (can_levy_to(game.who, to)) - gen_action(view, 'space', to) - gen_action(view, 'block', game.who); // for canceling levy + gen_action_space(view, to) + gen_action_block(view, game.who); // for canceling levy gen_action_undo(view) }, space: function (to) { @@ -1696,7 +1704,7 @@ states.pick_battle = { view.prompt = "Choose the next battle to fight!" for (let s of SPACELIST) if (is_contested_city(s) || is_contested_sea(s)) - gen_action(view, 'space', s) + gen_action_space(view, s) }, space: function (where) { game.where = where @@ -1803,8 +1811,8 @@ states.disrupt_reserves = { view.prompt = "Apply disruption hits to reserves." for (let b of game.disrupted) { gen_action(view, 'battle_hit', b) - gen_action(view, 'block', b) - gen_action(view, 'block', b) + gen_action_block(view, b) + gen_action_block(view, b) } }, block: disrupt_block, @@ -2021,7 +2029,7 @@ states.battle_round = { if (must_retreat || (can_retreat && can_retreat_with_block(b))) gen_action(view, 'battle_retreat', b) if (can_pass) gen_action(view, 'battle_pass', b) - gen_action(view, 'block', b) + gen_action_block(view, b) } }, block: function (who) { @@ -2108,7 +2116,7 @@ states.battle_hits = { view.prompt = "Assign " + game.hits + (game.hits !== 1 ? " hits" : " hit") + " to your armies." for (let b of game.battle_list) { gen_action(view, 'battle_hit', b) - gen_action(view, 'block', b) + gen_action_block(view, b) } }, block: function (who) { @@ -2129,14 +2137,14 @@ states.retreat = { for (let to of SPACES[from].exits) { if (block_owner(game.who) === game.attacker[from]) { if (can_attacker_retreat_to(game.who, from, to)) - gen_action(view, 'space', to) + gen_action_space(view, to) } else { if (can_defender_retreat_to(game.who, from, to)) - gen_action(view, 'space', to) + gen_action_space(view, to) } } gen_action(view, 'undo') - gen_action(view, 'block', game.who) + gen_action_block(view, game.who) }, space: function (to) { let from = game.location[game.who] @@ -2171,7 +2179,7 @@ states.sea_retreat = { let from = game.location[game.who] for (let to of SPACES[from].exits) { if (is_friendly_city(to)) - gen_action(view, 'space', to) + gen_action_space(view, to) } gen_action(view, 'undo') }, @@ -2206,7 +2214,7 @@ states.regroup = { for (let b of BLOCKLIST) { if (game.location[b] === game.where) { if (can_regroup(b)) - gen_action(view, 'block', b) + gen_action_block(view, b) } } gen_action_pass(view, "End regroup") @@ -2234,9 +2242,9 @@ states.regroup_to = { let from = game.location[game.who] for (let to of SPACES[from].exits) { if (can_regroup_to(game.who, from, to)) - gen_action(view, 'space', to) + gen_action_space(view, to) } - gen_action(view, 'block', game.who); // for canceling move + gen_action_block(view, game.who); // for canceling move gen_action_undo(view) }, space: function (to) { @@ -2266,9 +2274,9 @@ function cleopatra_goes_home() { if (game.location[CLEOPATRA] !== ALEXANDRIA) log("Cleopatra went home to Alexandria.") if (is_friendly_space(ALEXANDRIA)) - game.owner[CLEOPATRA] = CAESAR + set_add(game.traitor, CLEOPATRA) else - game.owner[CLEOPATRA] = POMPEIUS + set_delete(game.traitor, CLEOPATRA) game.location[CLEOPATRA] = ALEXANDRIA } @@ -2348,7 +2356,7 @@ states.navis_to_port = { if (block_owner(b) === game.active && BLOCKS[b].type === 'navis') { if (SPACES[game.location[b]].type === 'sea') { if (can_navis_move_to_port(b)) { - gen_action(view, 'block', b) + gen_action_block(view, b) ++count } } @@ -2380,9 +2388,9 @@ states.navis_to_port_where = { let from = game.location[game.who] for (let to of SPACES[from].exits) { if (is_friendly_city(to)) - gen_action(view, 'space', to) + gen_action_space(view, to) } - gen_action(view, 'block', game.who); // for canceling move + gen_action_block(view, game.who); // for canceling move gen_action_undo(view) }, space: function (to) { @@ -2412,7 +2420,7 @@ states.disband = { if (block_owner(b) === game.active && is_map_space(game.location[b]) && b !== CLEOPATRA) { if (is_over_supply_limit(game.location[b])) { okay_to_end = false - gen_action(view, 'block', b) + gen_action_block(view, b) } } } @@ -2424,7 +2432,7 @@ states.disband = { for (let b of BLOCKLIST) { if (is_map_space(game.location[b])) if (block_owner(b) === game.active && b !== CLEOPATRA) - gen_action(view, 'block', b) + gen_action_block(view, b) } gen_action_pass(view, "End disbanding") -- cgit v1.2.3