From 6712cd379fed39db080c5f1ec8b2fe1317e61ca8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 12 May 2024 12:04:24 +0200 Subject: report shared great ships/hay wains. share great ships to reach all ports. --- rules.js | 49 +++++++++++++++++++++++++++++++++++-------------- rules.ts | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/rules.js b/rules.js index 232df2b..15854dd 100644 --- a/rules.js +++ b/rules.js @@ -222,12 +222,19 @@ function find_sea_mask(here) { return 4; return 0; } +function find_disembark_ports(here) { + if (here === data.sea_1) + return data.port_1; + if (here === data.sea_2) + return data.port_2; + if (here === data.sea_3) + return data.port_3; + throw "IMPOSSIBLE"; +} function find_ports(here, lord) { - // for Parley, Supply, and Tax purposes only (not Disembark) - if (lord !== NOBODY) { - if ((lord_has_capability(lord, AOW_YORK_GREAT_SHIPS) || lord_has_capability(lord, AOW_LANCASTER_GREAT_SHIPS))) - return data.all_ports; - } + // for Parley, Supply, and Tax purposes only + if ((shared_has_capability(lord, AOW_YORK_GREAT_SHIPS) || shared_has_capability(lord, AOW_LANCASTER_GREAT_SHIPS))) + return data.all_ports; if (here === data.sea_1) return data.port_1; if (here === data.sea_2) @@ -862,6 +869,20 @@ function lord_has_capability_card(lord, c) { return true; return false; } +function group_has_capability(group, card_or_list) { + for (let lord of group) + if (lord_has_capability(lord, card_or_list)) + return true; + return false; +} +function shared_has_capability(lord, card_or_list) { + let loc = get_lord_locale(lord); + for (let lord of all_friendly_lords()) + if (get_lord_locale(lord) === loc) + if (lord_has_capability(lord, card_or_list)) + return true; + return false; +} function lord_has_capability(lord, card_or_list) { if (Array.isArray(card_or_list)) { for (let card of card_or_list) @@ -3455,7 +3476,7 @@ states.supply_source = { }; function use_stronghold_supply(source, amount) { log(`Supply ${amount} from S${source}.`); - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (shared_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS); add_lord_assets(game.command, PROV, amount); if (chamberlains_eligible_supply(source)) @@ -3467,11 +3488,11 @@ function use_stronghold_supply(source, amount) { } function use_port_supply(source, amount) { log(`Supply ${amount} from S${source} (Port).`); - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (shared_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS); - if (lord_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) + if (shared_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) logcap(AOW_YORK_GREAT_SHIPS); - if (lord_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) + if (shared_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) logcap(AOW_LANCASTER_GREAT_SHIPS); add_lord_assets(game.command, PROV, amount); } @@ -3644,9 +3665,9 @@ function do_sail(to) { log(`Sail to S${to}${format_group_move()}.`); if (!is_marshal(game.command) && !is_lieutenant(game.command) && game.group.length > 1) logcap(AOW_YORK_CAPTAIN); - if (lord_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) + if (group_has_capability(game.group, AOW_YORK_GREAT_SHIPS)) logcap(AOW_YORK_GREAT_SHIPS); - if (lord_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) + if (group_has_capability(game.group, AOW_LANCASTER_GREAT_SHIPS)) logcap(AOW_LANCASTER_GREAT_SHIPS); game.sail_from = get_lord_locale(game.command); clear_flag(FLAG_MARCH_TO_PORT); @@ -4318,7 +4339,7 @@ function march_with_group_2() { log(`March to S${to}${format_group_move()}.`); if (!is_marshal(game.command) && !is_lieutenant(game.command) && game.group.length > 1) logcap(AOW_YORK_CAPTAIN); - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (group_has_capability(game.group, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS); if (game.group.length === 1 && type === "road") { if (lord_has_capability(game.command, AOW_YORK_YORKISTS_NEVER_WAIT)) { @@ -7898,7 +7919,7 @@ function roll_disembark() { } } function has_safe_ports(sea) { - for (let loc of find_ports(sea, NOBODY)) + for (let loc of find_disembark_ports(sea)) if (!has_enemy_lord(loc)) if (is_move_allowed(game.who, loc)) return true; @@ -7945,7 +7966,7 @@ states.disembark_to = { inactive: "Disembark", prompt() { view.prompt = `Disembark: Land ${lord_name[game.who]} at a port.`; - for (let loc of find_ports(get_lord_locale(game.who), NOBODY)) + for (let loc of find_disembark_ports(get_lord_locale(game.who))) if (!has_enemy_lord(loc) && is_move_allowed(game.who, loc)) gen_action_locale(loc); }, diff --git a/rules.ts b/rules.ts index 4945c17..7da03f1 100644 --- a/rules.ts +++ b/rules.ts @@ -533,13 +533,18 @@ function find_sea_mask(here: Locale) { return 0 } +function find_disembark_ports(here: Locale): Locale[] { + if (here === data.sea_1) return data.port_1 + if (here === data.sea_2) return data.port_2 + if (here === data.sea_3) return data.port_3 + throw "IMPOSSIBLE" +} + function find_ports(here: Locale, lord: Lord): Locale[] { + // for Parley, Supply, and Tax purposes only - // for Parley, Supply, and Tax purposes only (not Disembark) - if (lord !== NOBODY) { - if ((lord_has_capability(lord, AOW_YORK_GREAT_SHIPS) || lord_has_capability(lord, AOW_LANCASTER_GREAT_SHIPS))) - return data.all_ports - } + if ((shared_has_capability(lord, AOW_YORK_GREAT_SHIPS) || shared_has_capability(lord, AOW_LANCASTER_GREAT_SHIPS))) + return data.all_ports if (here === data.sea_1) return data.port_1 if (here === data.sea_2) return data.port_2 @@ -1223,6 +1228,22 @@ function lord_has_capability_card(lord: Lord, c: Card) { return false } +function group_has_capability(group: Lord[], card_or_list: Card | Card[]) { + for (let lord of group) + if (lord_has_capability(lord, card_or_list)) + return true + return false +} + +function shared_has_capability(lord: Lord, card_or_list: Card | Card[]) { + let loc = get_lord_locale(lord) + for (let lord of all_friendly_lords()) + if (get_lord_locale(lord) === loc) + if (lord_has_capability(lord, card_or_list)) + return true + return false +} + function lord_has_capability(lord: Lord, card_or_list: Card | Card[]) { if (Array.isArray(card_or_list)) { for (let card of card_or_list) @@ -4209,7 +4230,7 @@ states.supply_source = { function use_stronghold_supply(source: Locale, amount: number) { log(`Supply ${amount} from S${source}.`) - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (shared_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS) add_lord_assets(game.command, PROV, amount) @@ -4224,11 +4245,11 @@ function use_stronghold_supply(source: Locale, amount: number) { function use_port_supply(source: Locale, amount: number) { log(`Supply ${amount} from S${source} (Port).`) - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (shared_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS) - if (lord_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) + if (shared_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) logcap(AOW_YORK_GREAT_SHIPS) - if (lord_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) + if (shared_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) logcap(AOW_LANCASTER_GREAT_SHIPS) add_lord_assets(game.command, PROV, amount) @@ -4420,9 +4441,9 @@ function do_sail(to: Locale) { if (!is_marshal(game.command) && !is_lieutenant(game.command) && game.group.length > 1) logcap(AOW_YORK_CAPTAIN) - if (lord_has_capability(game.command, AOW_YORK_GREAT_SHIPS)) + if (group_has_capability(game.group, AOW_YORK_GREAT_SHIPS)) logcap(AOW_YORK_GREAT_SHIPS) - if (lord_has_capability(game.command, AOW_LANCASTER_GREAT_SHIPS)) + if (group_has_capability(game.group, AOW_LANCASTER_GREAT_SHIPS)) logcap(AOW_LANCASTER_GREAT_SHIPS) game.sail_from = get_lord_locale(game.command) @@ -5197,7 +5218,7 @@ function march_with_group_2() { if (!is_marshal(game.command) && !is_lieutenant(game.command) && game.group.length > 1) logcap(AOW_YORK_CAPTAIN) - if (lord_has_capability(game.command, AOW_LANCASTER_HAY_WAINS)) + if (group_has_capability(game.group, AOW_LANCASTER_HAY_WAINS)) logcap(AOW_LANCASTER_HAY_WAINS) if (game.group.length === 1 && type === "road") { @@ -9260,7 +9281,7 @@ function roll_disembark() { } function has_safe_ports(sea: Locale) { - for (let loc of find_ports(sea, NOBODY)) + for (let loc of find_disembark_ports(sea)) if (!has_enemy_lord(loc)) if (is_move_allowed(game.who, loc)) return true @@ -9306,7 +9327,7 @@ states.disembark_to = { inactive: "Disembark", prompt() { view.prompt = `Disembark: Land ${lord_name[game.who]} at a port.` - for (let loc of find_ports(get_lord_locale(game.who), NOBODY)) + for (let loc of find_disembark_ports(get_lord_locale(game.who))) if (!has_enemy_lord(loc) && is_move_allowed(game.who, loc)) gen_action_locale(loc) }, -- cgit v1.2.3