summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-10-17 16:31:15 +0200
committerTor Andersson <tor@ccxvii.net>2024-10-17 16:31:23 +0200
commit71a7bac00a296c5de994fe4d92d0b46d8c01d069 (patch)
tree446d3b9cf126ef0684d712c68ff09e160bf2e59a
parent9d4e9253df7b3430bbe7e8313320388970ae494f (diff)
downloadmaria-71a7bac00a296c5de994fe4d92d0b46d8c01d069.tar.gz
remove dead code and simplify game.moved handling
-rw-r--r--rules.js73
1 files changed, 12 insertions, 61 deletions
diff --git a/rules.js b/rules.js
index 4fa6c6a..5461392 100644
--- a/rules.js
+++ b/rules.js
@@ -167,8 +167,6 @@ const piece_name = [
"hussar", "hussar",
]
-const all_power_generals_rev = all_power_generals.map(list => list.slice().reverse())
-
const all_pieces = [ ...all_power_generals.flat(), ...all_power_trains.flat() ]
const all_generals = [ ...all_power_generals.flat() ]
@@ -639,42 +637,6 @@ function add_one_troop(p) {
}
}
-function remove_one_troop(p) {
- for (let x of all_power_generals_rev[game.power]) {
- if (game.pos[x] === game.pos[p] && game.troops[x] > 1) {
- game.troops[x] --
- break
- }
- }
-}
-
-function retire_general(p) {
- // save troops if possible
- let s = game.pos[p]
- let n = game.troops[p]
- game.pos[p] = REMOVED
- game.troops[p] = 0
- set_in_supply(p)
-
- if (is_map_space(s)) {
- for (let p of all_power_generals[game.power]) {
- if (game.pos[p] === s) {
- let x = Math.min(n, 8 - game.troops[p])
- game.troops[p] += x
- n -= x
- }
- }
- if (n > 1)
- log("P" + p + " retired with " + n + " troops.")
- else if (n === 1)
- log("P" + p + " retired with 1 troop.")
- else
- log("P" + p + " retired.")
- } else {
- log("P" + p + " retired.")
- }
-}
-
function eliminate_general(p, indent) {
if (indent)
log(">P" + p + " eliminated")
@@ -1162,7 +1124,6 @@ function move_general_to(to, is_force_march) {
let from = game.pos[who]
let stop = false
- set_add(game.moved, game.selected)
game.pos[game.selected] = to
// Cannot conquer if force marching.
@@ -1202,10 +1163,9 @@ function move_general_to(to, is_force_march) {
}
}
- // uniting stacks: flag all as moved and stop moving
+ // uniting stacks: stop moving
for (let p of all_coop_generals(pow)) {
if (game.pos[p] === to && game.selected !== p) {
- set_add(game.moved, p)
stop = true
}
}
@@ -1249,8 +1209,6 @@ states.move_supply_train = {
this.stop()
},
stop() {
- let who = game.selected
- set_add(game.moved, who)
end_move_piece()
},
space(to) {
@@ -1262,7 +1220,6 @@ states.move_supply_train = {
if (!set_has(data.cities.main_roads[from], to))
game.main = 0
- set_add(game.moved, who)
game.pos[who] = to
if (++game.count === 2 + game.main)
@@ -1326,7 +1283,6 @@ states.move_general = {
}
},
stop() {
- set_add(game.moved, game.selected)
end_move_piece()
},
space(to) {
@@ -1457,6 +1413,17 @@ states.move_give = {
}
function end_move_piece() {
+ let here = game.pos[game.selected]
+
+ // uniting stacks: flag all as moved
+ if (is_general(game.selected)) {
+ for (let p of all_coop_generals(game.power))
+ if (game.pos[p] === here)
+ set_add(game.moved, p)
+ } else {
+ set_add(game.moved, game.selected)
+ }
+
log_move_path()
if (game.move_elim) {
@@ -1591,13 +1558,6 @@ function has_re_entry_space(p) {
return false
}
-function is_attack_position(s) {
- for (let p of all_enemy_generals(game.power))
- if (set_has(data.cities.adjacent[s], game.pos[p]))
- return true
- return false
-}
-
function can_recruit_anything_in_theory() {
let unused_everywhere = max_power_troops(game.power) - count_used_troops()
return unused_everywhere > 0 || count_eliminated_trains() > 0
@@ -2122,13 +2082,6 @@ function set_active_winner() {
set_active_defender()
}
-function set_active_loser() {
- if (game.count > 0)
- set_active_defender()
- else
- set_active_attacker()
-}
-
function remove_stack_from_combat(s) {
for (let i = game.combat.length - 2; i >= 0; i -= 2)
if (game.combat[i] === s || game.combat[i + 1] === s)
@@ -2140,8 +2093,6 @@ function goto_retreat() {
let lost = [ 0, 0, 0, 0, 0, 0 ] // per power!
let loser = get_loser()
- let loser_power = get_stack_power(loser)
- let winner_power = get_stack_power(get_winner())
// no more fighting for the loser
remove_stack_from_combat(loser)