summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js99
1 files changed, 76 insertions, 23 deletions
diff --git a/rules.js b/rules.js
index af4bf3e..2228f8a 100644
--- a/rules.js
+++ b/rules.js
@@ -127,7 +127,9 @@ const GOTHS = 2
const NOMADS = 3
const SASSANIDS = 4
-const TRIBE_COUNT = [ 0, 5, 3, 4, 5 ]
+const BARBARIAN_COUNT = [ 0, 50, 30, 40, 50 ]
+const first_barbarian = [ 0, 10, 20, 30, 40 ]
+const last_barbarian = [ 9, 19, 29, 39, 49 ]
const BARBARIAN_NAME = [
"Alamanni",
@@ -645,29 +647,26 @@ function can_place_governor(where) {
function find_active_barbarian_at_home(tribe) {
let home = BARBARIAN_HOMELAND[tribe]
- for (let i = 0; i < 10; ++i)
- if (get_barbarian_location(tribe * 10 + i) === home)
- if (is_barbarian_active(tribe * 10 + i))
- return tribe * 10 + i
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id)
+ if (get_barbarian_location(id) === home && is_barbarian_active(id))
+ return id
return -1
}
function count_active_barbarians_at_home(tribe) {
let home = BARBARIAN_HOMELAND[tribe]
let n = 0
- for (let i = 0; i < 10; ++i)
- if (get_barbarian_location(tribe * 10 + i) === home)
- if (is_barbarian_active(tribe * 10 + i))
- n += 1
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id)
+ if (get_barbarian_location(id) === home && is_barbarian_active(id))
+ n += 1
return n
}
function find_inactive_barbarian_at_home(tribe) {
let home = BARBARIAN_HOMELAND[tribe]
- for (let i = 0; i < 10; ++i)
- if (get_barbarian_location(tribe * 10 + i) === home)
- if (is_barbarian_inactive(tribe * 10 + i))
- return tribe * 10 + i
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id)
+ if (get_barbarian_location(id) === home && is_barbarian_inactive(id))
+ return id
return -1
}
@@ -679,8 +678,8 @@ function activate_one_barbarian(tribe) {
function count_barbarians_in_province(tribe, where) {
let n = 0
- for (let i = 0; i < 10; ++i)
- if (get_barbarian_location(tribe * 10 + i) === where)
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id)
+ if (get_barbarian_location(id) === where)
n += 1
return n
}
@@ -901,9 +900,9 @@ function goto_barbarian_crisis(tribe) {
function invade_with_active_barbarian(tribe, where) {
// TODO: move leaders first
- let b = find_active_barbarian_at_home(tribe)
- if (b >= 0)
- set_barbarian_location(tribe * 10 + b, where)
+ let id = find_active_barbarian_at_home(tribe)
+ if (id >= 0)
+ set_barbarian_location(id, where)
}
function goto_barbarian_invasion(tribe, black, white) {
@@ -1532,13 +1531,68 @@ states.initiate_battle = {
}
},
general(id) {
+ push_undo()
log("Initiate Battle vs Gen" + id)
+ game.misc.target = id
+ game.state = "battle_general"
},
barbarian(id) {
+ push_undo()
log("Initiate Battle vs B" + id)
+ game.misc.target = id
+ game.state = "battle_barbarians"
+ },
+ rival_emperor(id) {
+ push_undo()
+ log("Initiate Battle vs B" + id)
+ game.misc.target = id
+ game.state = "battle_rival_emperor"
},
militia(where) {
+ push_undo()
log("Initiate Battle vs Militia" + id)
+ game.misc.target = -1
+ game.state = "battle_militia"
+ },
+}
+
+states.battle_general = {
+ prompt() {
+ prompt("Battle vs General.")
+ view.actions.roll = 1
+ },
+ roll() {
+ clear_undo()
+ },
+}
+
+states.battle_barbarians = {
+ prompt() {
+ prompt("Battle vs Barbarians.")
+ view.actions.roll = 1
+ },
+ roll() {
+ clear_undo()
+ },
+}
+
+states.battle_rival_emperor = {
+ prompt() {
+ prompt("Battle vs Rival Emperor.")
+ view.actions.roll = 1
+ },
+ roll() {
+ clear_undo()
+ },
+}
+
+states.battle_militia = {
+ prompt() {
+ prompt("Battle vs Militia.")
+ view.actions.roll = 1
+ },
+ roll() {
+ clear_undo()
},
}
@@ -1730,9 +1784,9 @@ function setup_market_pile(cards) {
}
function setup_barbarians(tribe, home) {
- for (let i = 0; i < 10; ++i) {
- set_barbarian_location(tribe * 10 + i, home)
- set_barbarian_inactive(tribe * 10 + i)
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) {
+ set_barbarian_location(id, home)
+ set_barbarian_inactive(id)
}
}
@@ -1741,7 +1795,6 @@ exports.setup = function (seed, scenario, options) {
let player_count = real_player_count
if (player_count === 1)
player_count = 4
- let tribe_count = TRIBE_COUNT[player_count]
game = {
seed: seed,
@@ -1779,7 +1832,7 @@ exports.setup = function (seed, scenario, options) {
governors: new Array(6 * player_count).fill(UNAVAILABLE),
generals: new Array(6 * player_count).fill(UNAVAILABLE),
legions: new Array(LEGION_COUNT).fill(AVAILABLE),
- barbarians: new Array(10 * tribe_count).fill(0),
+ barbarians: new Array(BARBARIAN_COUNT[player_count]).fill(AVAILABLE),
rival_emperors: [ UNAVAILABLE, UNAVAILABLE, UNAVAILABLE ],
barbarian_leaders: [ UNAVAILABLE, UNAVAILABLE, UNAVAILABLE ],