summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events.txt2
-rw-r--r--rules.js62
2 files changed, 31 insertions, 33 deletions
diff --git a/events.txt b/events.txt
index fa1387d..5508655 100644
--- a/events.txt
+++ b/events.txt
@@ -626,7 +626,7 @@ EVENT 28
remove_influence VE
current BK
prompt "Spend a Cavalry token to place 2 Amirs and remove a Raja in Andhra."
- space 1 ((s === S_ANDHRA) && (n_cavalry(BK) > 0))
+ space_opt 1 ((s === S_ANDHRA) && (n_cavalry(BK) > 0))
spend_cavalry 1
prompt "Place 2 Amirs in Andhra."
place 2 BK ELITE
diff --git a/rules.js b/rules.js
index 63498aa..4f10f9e 100644
--- a/rules.js
+++ b/rules.js
@@ -83,6 +83,13 @@ function is_current_role(role) {
return false
}
+function change_current(f) {
+ if (game.current != f) {
+ clear_undo()
+ game.current = f
+ }
+}
+
function load_game(state) {
game = state
}
@@ -265,9 +272,6 @@ exports.setup = function (seed, scenario, _options) {
if (scenario === "Solo")
game.solo = 1
- game.current = DS
- game.state = "todo"
-
// Setup
setup_standard()
update_control()
@@ -405,7 +409,7 @@ function end_card() {
}
function goto_eligible() {
- game.current = next_eligible_faction()
+ change_current(next_eligible_faction())
if (game.current < 0) {
end_card()
} else {
@@ -582,7 +586,7 @@ function goto_mongol_invaders(faction) {
free: 2,
sa_faction: faction
}
- game.current = faction
+ change_current(faction)
goto_strategic_assistance()
}
@@ -611,7 +615,7 @@ function goto_tax() {
/* SUCCESSION */
function succession() {
- game.current = DS
+ change_current(DS)
if (game.succ > 0)
game.succ += 1
@@ -1379,7 +1383,7 @@ function goto_attack_cavalry(curr) {
game.cmd.step += 1
next_attack_cavalry_step()
} else {
- game.current = curr
+ change_current(curr)
game.state = "attack_cavalry"
}
}
@@ -1447,7 +1451,7 @@ function goto_attack_casualties() {
remove_mi_casualties(game.cmd.where)
end_attack_casualties()
} else {
- game.current = curr
+ change_current(curr)
if (game.cmd.count > 0) {
push_summary()
game.state = "attack_casualties"
@@ -1514,8 +1518,7 @@ function goto_attack_resolution() {
if (is_rebel_faction(game.cmd.target) && is_rebel_faction(game.cmd.attacker))
attack_influence_shift()
else if (game.cmd.attacker === MI && !is_timurid()) {
- game.current = game.cmd.sa_faction
- clear_undo()
+ change_current(game.cmd.sa_faction)
game.state = "plunder"
} else if (game.vm) {
vm_next()
@@ -2777,7 +2780,7 @@ function goto_plunder_remove() {
if (game.cmd.where === S_DELHI)
game.cmd.count *= 2
push_summary()
- game.current = DS
+ change_current(DS)
game.state = "plunder_remove"
}
}
@@ -2831,8 +2834,7 @@ function end_plunder() {
log_br()
log(`${n} Invaders returned from ${SPACE_NAME[game.cmd.where]} with spoils.`)
}
-
- game.current = game.cmd.sa_faction
+ change_current(game.cmd.sa_faction)
goto_strategic_assistance()
}
@@ -3413,8 +3415,7 @@ function goto_return_troops(faction, n_troops, s) {
game.inf_shift.n = n_troops
game.inf_shift.s = s
game.inf_shift.save_current = game.current
- game.current = faction
- clear_undo()
+ change_current(faction)
game.state = "return_troops"
}
@@ -3444,9 +3445,7 @@ states.return_troops = {
},
end_return() {
pop_summary()
- if (game.current != game.inf_shift.save_current)
- clear_undo()
- game.current = game.inf_shift.save_current
+ change_current(game.inf_shift.save_current)
end_influence()
}
}
@@ -3575,7 +3574,7 @@ states.ask_resources = {
gen_action_resources(VE)
},
resources(faction) {
- game.current = faction
+ change_current(faction)
game.state = "give_resources"
},
}
@@ -3690,12 +3689,12 @@ states.ask_cavalry = {
}
},
token(c) {
- game.current = game.cavalry[c]
+ change_current(game.cavalry[c])
game.state = "give_cavalry"
},
space(s) {
let f = s - 17
- game.current = f
+ change_current(f)
game.state = "give_cavalry"
}
}
@@ -3775,7 +3774,7 @@ states.transfer_cavalry = {
}
function end_negotiation() {
- game.current = game.transfer.current
+ change_current(game.transfer.current)
game.state = game.transfer.state
delete game.transfer
}
@@ -3802,15 +3801,15 @@ states.ping = {
view.actions.undo = 1
},
ds() {
- game.current = DS
+ change_current(DS)
game.state = "pong"
},
bk() {
- game.current = BK
+ change_current(BK)
game.state = "pong"
},
ve() {
- game.current = VE
+ change_current(VE)
game.state = "pong"
},
undo() {
@@ -3827,7 +3826,7 @@ states.pong = {
view.actions.undo = 0
},
resume() {
- game.current = game.ping.save_current
+ change_current(game.ping.save_current)
game.state = game.ping.save_state
delete game.ping
},
@@ -4544,29 +4543,28 @@ states.vm_current = {
ds() {
if (game.current !== DS)
clear_undo()
- game.current = DS
+ change_current(DS)
log_transfer(faction_name[game.current] + "...")
vm_next()
},
bk() {
if (game.current !== BK)
clear_undo()
- game.current = BK
+ change_current(BK)
log_transfer(faction_name[game.current] + "...")
vm_next()
},
ve() {
if (game.current !== VE)
clear_undo()
- game.current = VE
+ change_current(VE)
log_transfer(faction_name[game.current] + "...")
vm_next()
}
}
function vm_force_current() {
- game.current = vm_operand(1)
- clear_undo()
+ change_current(vm_operand(1))
vm_next()
}
@@ -6672,7 +6670,7 @@ CODE[28 * 2 + 0] = [
[ vm_remove_influence, VE ],
[ vm_current, BK ],
[ vm_prompt, "Spend a Cavalry token to place 2 Amirs and remove a Raja in Andhra." ],
- [ vm_space, true, 1, 1, (s)=>((s === S_ANDHRA) && (n_cavalry(BK) > 0)) ],
+ [ vm_space, true, 0, 1, (s)=>((s === S_ANDHRA) && (n_cavalry(BK) > 0)) ],
[ vm_spend_cavalry, 1 ],
[ vm_prompt, "Place 2 Amirs in Andhra." ],
[ vm_place, false, 0, 2, BK, ELITE ],