summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-08 23:30:07 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-08 23:30:07 +0100
commitf15dd0c0842cb3944ebc006da5b135cea6eed7b2 (patch)
treeb09e105d4b86fe439e6ea585f45a85b3c96b2c32 /rules.js
parent7895920ab6b4e34fa675c4fd520b82ca243b80ab (diff)
downloadmaria-f15dd0c0842cb3944ebc006da5b135cea6eed7b2.tar.gz
New alternating move procedure and states.
Allow movement on Bohemia map; alternate only after Flanders piece move.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js120
1 files changed, 52 insertions, 68 deletions
diff --git a/rules.js b/rules.js
index a057e56..ffafa20 100644
--- a/rules.js
+++ b/rules.js
@@ -1411,9 +1411,8 @@ const advanced_sequence_of_play = [
// alternate moves on flanders starting with pragmatic army
{ power: P_PRAGMATIC, action: init_movement },
- { power: P_PRAGMATIC, action: goto_movement_global },
+ { power: P_PRAGMATIC, action: goto_movement_flanders },
{ power: P_PRAGMATIC, action: end_movement },
- { power: P_PRAGMATIC, action: goto_movement_coop },
{ power: P_AUSTRIA, action: goto_combat },
{ power: P_PRAGMATIC, action: goto_combat },
@@ -2376,35 +2375,18 @@ function has_unmoved_piece_on_flanders_map(pow) {
return false
}
-function goto_movement_global() {
- game.state = "movement"
-}
-
-function goto_movement_coop() {
+function goto_movement_flanders() {
game.state = "movement"
- game.flags |= F_MOVE_FLANDERS
+ // save RESTART point
clear_undo()
push_undo()
game.restart = game.undo[0]
clear_undo()
-
- game.flags |= F_MOVE_COOP
-}
-
-function goto_movement_flanders() {
- game.flags |= F_MOVE_FLANDERS
- game.state = "movement"
- if (!has_unmoved_piece_on_flanders_map(game.power))
- next_sequence_of_play()
}
-function goto_movement_bohemia() {
- log_br()
- game.flags &= ~F_MOVE_FLANDERS
+function goto_movement_global() {
game.state = "movement"
- if (!has_unmoved_piece_on_bohemia_map(game.power))
- next_sequence_of_play()
}
function resume_movement() {
@@ -2420,7 +2402,7 @@ function resume_movement() {
}
function resume_movement_after_flanders_stacking() {
- flush_move_log()
+ flush_alternate_move()
set_active_to_power(coop_major_power(game.power))
game.selected = -1
game.state = "movement"
@@ -2472,6 +2454,8 @@ function can_general_move_anywhere(p) {
}
function may_dispute_flanders_movement() {
+ if (game.flags & F_MOVE_DISPUTE)
+ return false
if (game.power === P_PRAGMATIC && has_moved_piece_on_flanders_map(P_AUSTRIA))
return true
if (game.power === P_AUSTRIA)
@@ -2489,7 +2473,7 @@ states.movement_flanders_next = {
gen_action_power(P_PRAGMATIC)
},
power(pow) {
- flush_move_log()
+ flush_alternate_move()
set_active_to_power(pow)
game.state = "movement"
},
@@ -2525,6 +2509,7 @@ states.movement = {
}
}
+ // if (has_unmoved_piece_on_flanders_map(game.power)) prompt("Move your pieces on the Flanders map.") else
if (done_trains && done_generals)
prompt("Movement done.")
else if (done_generals && !done_trains)
@@ -2534,47 +2519,43 @@ states.movement = {
else
prompt("Move your generals and supply trains.")
- /*
- if (game.flags & F_MOVE_COOP) {
- if (may_dispute_flanders_movement())
- view.actions.dispute = 1
- else
- view.actions.dispute = 0
- if (game.power === P_PRAGMATIC && has_unmoved_piece_on_flanders_map(P_AUSTRIA))
- gen_action_power(P_AUSTRIA)
- if (game.power === P_AUSTRIA && has_unmoved_piece_on_flanders_map(P_PRAGMATIC))
- gen_action_power(P_PRAGMATIC)
- }
-
- if (game.flags & F_MOVE_FLANDERS) {
- if (!has_unmoved_piece_on_flanders_map(P_PRAGMATIC) && !has_unmoved_piece_on_flanders_map(P_AUSTRIA))
- view.actions.end_flanders = 1
- else
- view.actions.end_flanders = 0
- } else {
- if (DEBUG || !has_unmoved_piece(game.power)) {
- if (game.power === P_AUSTRIA && !is_two_player())
- view.actions.end_bohemia = 1
- else
- view.actions.end_movement = 1
+ // austria/pragmatic shared movement phase
+ if (!is_two_player() && !is_intro() && (game.power === P_PRAGMATIC || game.power === P_AUSTRIA)) {
+ if (has_unmoved_piece_on_flanders_map(P_AUSTRIA) || has_unmoved_piece_on_flanders_map(P_PRAGMATIC)) {
+ // pieces left to move on flanders
+ if (!(game.flags & F_MOVE_DISPUTE)) {
+ if (game.power === P_PRAGMATIC && has_unmoved_piece_on_flanders_map(P_AUSTRIA))
+ gen_action_power(P_AUSTRIA)
+ if (game.power === P_AUSTRIA && has_unmoved_piece_on_flanders_map(P_PRAGMATIC))
+ gen_action_power(P_PRAGMATIC)
+ if (may_dispute_flanders_movement())
+ view.actions.dispute = 1
+ else
+ view.actions.dispute = 0
+ }
+ if (game.restart) {
+ if (has_moved_piece_on_flanders_map(P_PRAGMATIC) || has_moved_piece_on_flanders_map(P_AUSTRIA))
+ view.actions.restart = 1
+ else
+ view.actions.restart = 0
+ }
} else {
- if (game.power === P_AUSTRIA && !is_two_player())
- view.actions.end_bohemia = 0
+ // only bohemian pieces left
+ if (!has_unmoved_piece(P_PRAGMATIC) && !has_unmoved_piece(P_AUSTRIA))
+ view.actions.end_movement = 1
+ else if (game.power === P_PRAGMATIC && has_unmoved_piece(P_AUSTRIA))
+ gen_action_power(P_AUSTRIA)
+ else if (game.power === P_AUSTRIA && has_unmoved_piece(P_PRAGMATIC))
+ gen_action_power(P_PRAGMATIC)
else
view.actions.end_movement = 0
}
-
- }
- */
-
- // austria/pragmatic shared movement phase
- if (!is_two_player() && !is_intro()) {
- if (game.restart)
- view.actions.restart = 1
+ } else {
+ if (!has_unmoved_piece(game.power))
+ view.actions.end_movement = 1
+ else
+ view.actions.end_movement = DEBUG
}
-
- if (DEBUG || !has_unmoved_piece(game.power))
- view.actions.end_movement = 1
},
piece(p) {
push_undo()
@@ -2611,7 +2592,6 @@ states.movement = {
this.end_movement()
},
end_movement() {
- delete game.restart // TODO: when?
push_undo()
next_sequence_of_play()
},
@@ -2620,19 +2600,19 @@ states.movement = {
set_active_to_power(pow)
},
restart() {
- clear_undo()
+ let dispute = game.flags & F_MOVE_DISPUTE
game.undo = [ game.restart ]
delete game.restart
pop_undo()
- goto_movement_coop()
+ goto_movement_flanders()
game.state = "restart_flanders_movement"
+ game.flags |= dispute // preserve disputed mode
},
dispute() {
- // enter non-coop mode
- clear_undo()
game.undo = [ game.restart ]
delete game.restart
pop_undo()
+ goto_movement_flanders()
game.state = "dispute_flanders_movement"
game.flags |= F_MOVE_DISPUTE
},
@@ -2656,12 +2636,16 @@ states.dispute_flanders_movement = {
view.actions.next = 1
},
next() {
- log("Alternating moves.")
- next_sequence_of_play() // jump to non-coop movement
+ log("Disputed Flanders movement.")
+ game.state = "movement"
},
}
function end_movement() {
+ game.flags &= ~F_MOVE_DISPUTE
+ game.flags &= ~F_MOVE_FLANDERS
+ delete game.restart
+
if (game.moved.length === 0)
log("Nothing moved.")
@@ -3073,7 +3057,7 @@ function is_alternating_move() {
return false
}
-function flush_move_log() {
+function flush_alternate_move() {
log_conquest(game.move_conq)
game.move_conq = []
log_br()