summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-02-04 22:01:26 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 11:54:52 +0100
commit88f9852fc38c3f3e08db3bc042a2f2bfab1427ec (patch)
tree02b765f5b14072bc968f491ae62642750e631804 /rules.js
parent99789e0e56bf6ff40e795f4866d7b7ecb9328b69 (diff)
downloadwilderness-war-88f9852fc38c3f3e08db3bc042a2f2bfab1427ec.tar.gz
Place and remove indian allied settlement markers.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js50
1 files changed, 43 insertions, 7 deletions
diff --git a/rules.js b/rules.js
index 038a714..8f05d28 100644
--- a/rules.js
+++ b/rules.js
@@ -13,7 +13,6 @@
// TODO: only move pieces once per campaign
// TODO: re-evaluate fortress ownership and VP when pieces move or are eliminated
-// TODO: update indian alliance markers when placing/eliminating indians
// REACTION CARDS
@@ -1535,13 +1534,23 @@ function eliminate_piece(p) {
log(piece_name(p) + " is eliminated.");
isolate_piece_from_force(p);
set_unit_reduced(p, 0);
- if (is_indian_unit(p)) {
- // TODO: remove allied marker if necessary
- }
if (is_leader(p))
game.pieces.location[p] = DEAD;
else
game.pieces.location[p] = UNUSED;
+ if (is_indian_unit(p)) {
+ let home = indian_home_settlement(p);
+ if (home) {
+ let tribe = indian_tribe[home];
+ if (is_indian_tribe_eliminated(tribe)) {
+ log(`Removed ${tribe} settlement.`);
+ if (pieces[p].faction === 'british')
+ remove_from_array(game.Britain.allied, home);
+ else
+ remove_from_array(game.France.allied, home);
+ }
+ }
+ }
}
function eliminate_indian_tribe(tribe) {
@@ -1550,6 +1559,16 @@ function eliminate_indian_tribe(tribe) {
eliminate_piece(p);
}
+function is_indian_tribe_eliminated(tribe) {
+ for (let p = first_enemy_unit; p <= last_enemy_unit; ++p) {
+ if (is_indian_tribe(p, tribe)) {
+ if (is_piece_on_map(p))
+ return false;
+ }
+ }
+ return true;
+}
+
function move_piece_to(who, to) {
game.pieces.location[who] = to;
}
@@ -1557,6 +1576,23 @@ function move_piece_to(who, to) {
function place_piece(who, to) {
log(`${piece_name(who)} placed at ${space_name(to)}.`);
game.pieces.location[who] = to;
+ if (is_indian_unit(who)) {
+ let home = indian_home_settlement(who);
+ if (home) {
+ let tribe = indian_tribe[home];
+ if (pieces[who].faction === 'british') {
+ if (!game.Britain.allied.includes(home)) {
+ log(`Placed ${tribe} settlement.`);
+ game.Britain.allied.push(home);
+ }
+ } else {
+ if (!game.France.allied.includes(home)) {
+ log(`Placed ${tribe} settlement.`);
+ game.France.allied.push(home);
+ }
+ }
+ }
+ }
}
function move_pieces_from_node_to_node(from, to) {
@@ -4642,8 +4678,8 @@ events.iroquois_alliance = {
},
}
-function find_unused_indian(tribe) {
- for (let i = 0; i < pieces.length; ++i)
+function find_friendly_unused_indian(tribe) {
+ for (let i = first_friendly_unit; i <= last_friendly_unit; ++i)
if (pieces[i].name === tribe && game.pieces.location[i] === 0)
return i;
return 0;
@@ -4663,7 +4699,7 @@ states.indian_alliance = {
if (game.count >= 1) {
for (let s of indian_spaces[a]) {
if (!has_enemy_allied_settlement(s)) {
- let p = find_unused_indian(indian_tribe[s]);
+ let p = find_friendly_unused_indian(indian_tribe[s]);
if (p && can_place_in_space(s)) {
can_place = true;
gen_action_space(s);