From 0896110768cfa63710c362a4dfa3b15de551b882 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 18 Oct 2024 00:52:03 +0200 Subject: Protect from conquests. --- rules.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index b2ebc3a..390494b 100644 --- a/rules.js +++ b/rules.js @@ -4,7 +4,6 @@ /* TODO -victory & elector marker victory check supreme commander in mixed stacks supply phase @@ -537,6 +536,13 @@ function is_friendly_minor_home_country(s) { return false } +function get_home_power(s) { + for (let pow of all_powers) + if (set_has(all_home_country_fortresses[pow], s)) + return pow + return -1 +} + function is_enemy_controlled_fortress(s) { for (let other of all_enemy_powers(game.power)) if (is_power_controlled_fortress(other, s)) @@ -575,14 +581,14 @@ function is_space_protected_by_piece(s, p) { } function is_protected_from_conquest(s) { - /* - TODO - for (let pow of all_powers) { - for (let p of all_power_generals[pow]) - if (is_space_protected_by_piece(s, p)) - return true - } - */ + let owner = map_get(game.elector, s, -1) + if (owner < 0) + owner = map_get(game.victory, s, -1) + if (owner < 0) + owner = get_home_power(s) + for (let p of all_coop_generals(owner)) + if (is_space_protected_by_piece(s, p)) + return true return false } -- cgit v1.2.3