summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-02-15 18:03:10 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 11:54:52 +0100
commitb2fa7d98accd285974f615898049e2f13190ea86 (patch)
treed3dd226b19e0ded88c0b858cde5cf6946420d2c0
parentac0abd53fa35807bbc06e45c06ceb563fbb24bf9 (diff)
downloadwilderness-war-b2fa7d98accd285974f615898049e2f13190ea86.tar.gz
Indians and leaders go home cleanup.
-rw-r--r--rules.js54
1 files changed, 33 insertions, 21 deletions
diff --git a/rules.js b/rules.js
index cdef794..633627a 100644
--- a/rules.js
+++ b/rules.js
@@ -2231,12 +2231,7 @@ function end_late_season() {
log("");
delete game.events.no_amphib;
delete game.events.blockhouses;
- set_active(FRANCE);
- game.state = 'indians_and_leaders_go_home';
- game.go_home = {
- indians: {}
- };
- resume_indians_and_leaders_go_home();
+ goto_indians_and_leaders_go_home();
}
function start_action_phase() {
@@ -5187,6 +5182,37 @@ states.raiders_go_home = {
// LATE SEASON - INDIANS AND LEADERS GO HOME
+function goto_indians_and_leaders_go_home() {
+ set_active(FRANCE);
+ game.state = 'indians_and_leaders_go_home';
+ game.go_home = {
+ indians: {}
+ };
+ resume_indians_and_leaders_go_home();
+ if (!game.go_home.who)
+ end_indians_and_leaders_go_home();
+}
+
+function resume_indians_and_leaders_go_home() {
+ let who = game.go_home.who = next_indian_and_leader_to_go_home();
+ if (who && is_leader(who))
+ game.go_home.closest = find_closest_friendly_unbesieged_fortification(piece_space(who));
+}
+
+function end_indians_and_leaders_go_home() {
+ clear_undo();
+ if (game.active === FRANCE) {
+ set_active(BRITAIN);
+ resume_indians_and_leaders_go_home();
+ if (!game.go_home.who)
+ end_indians_and_leaders_go_home();
+ } else {
+ set_active(FRANCE);
+ delete game.go_home;
+ goto_remove_raided_markers();
+ }
+}
+
function next_indian_and_leader_to_go_home() {
// Indians go home first
for (let p = first_friendly_unit; p <= last_friendly_unit; ++p) {
@@ -5207,12 +5233,6 @@ function next_indian_and_leader_to_go_home() {
}
}
-function resume_indians_and_leaders_go_home() {
- let who = game.go_home.who = next_indian_and_leader_to_go_home();
- if (who && is_leader(who))
- game.go_home.closest = find_closest_friendly_unbesieged_fortification(piece_space(who));
-}
-
states.indians_and_leaders_go_home = {
prompt() {
let who = game.go_home.who;
@@ -5258,15 +5278,7 @@ states.indians_and_leaders_go_home = {
resume_indians_and_leaders_go_home();
},
next() {
- clear_undo();
- if (game.active === FRANCE) {
- set_active(BRITAIN);
- resume_indians_and_leaders_go_home();
- } else {
- set_active(FRANCE);
- delete game.go_home;
- goto_remove_raided_markers();
- }
+ end_indians_and_leaders_go_home();
}
}