summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-04-25 13:27:49 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:23 +0200
commit390c2cda3e78be50b20d227348cce355e599db35 (patch)
tree37c9d70c9a0776f90b1b6b3e1c36c4b55d5c76dd /rules.js
parent66546310e557dd10e7c2a682ec5947eca9b836a6 (diff)
downloadtime-of-crisis-390c2cda3e78be50b20d227348cce355e599db35.tar.gz
More setup constants.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js232
1 files changed, 159 insertions, 73 deletions
diff --git a/rules.js b/rules.js
index a1290e2..3562286 100644
--- a/rules.js
+++ b/rules.js
@@ -1,21 +1,27 @@
"use strict"
+// === CONSTANTS AND DATA ===
+
const P1 = "Red"
const P2 = "Blue"
const P3 = "Yellow"
const P4 = "Green"
+const PLAYER_NAMES = [ P1, P2, P3, P4 ]
+
+const PLAYER_INDEX = {
+ [P1]: 0,
+ [P2]: 1,
+ [P3]: 2,
+ [P4]: 3,
+ "Observer": -1,
+}
+
const NO_PLACE_GOVERNOR = -1
const OFF_MAP = -1
const AVAILABLE = -1
const UNAVAILABLE = -2
-const ALAMANNI = 0
-const FRANKS = 1
-const GOTHS = 2
-const NOMADS = 3
-const SASSANIDS = 4
-
const ITALIA = 0
const AEGYPTUS = 1
const AFRICA = 2
@@ -28,25 +34,11 @@ const MACEDONIA = 8
const PANNONIA = 9
const SYRIA = 10
const THRACIA = 11
-
-const ITALIA_CAPITAL = 12
-const AEGYPTUS_CAPITAL = 13
-const AFRICA_CAPITAL = 14
-const ASIA_CAPITAL = 15
-const BRITANNIA_CAPITAL = 16
-const GALATIA_CAPITAL = 17
-const GALLIA_CAPITAL = 18
-const HISPANIA_CAPITAL = 19
-const MACEDONIA_CAPITAL = 20
-const PANNONIA_CAPITAL = 21
-const SYRIA_CAPITAL = 22
-const THRACIA_CAPITAL = 23
-
-const ALAMANNI_HOME = 51
-const FRANKS_HOME = 52
-const GOTHS_HOME = 53
-const NOMADS_HOME = 54
-const SASSANIDS_HOME = 55
+const ALAMANNI_HOMELAND = 12
+const FRANKS_HOMELAND = 13
+const GOTHS_HOMELAND = 14
+const NOMADS_HOMELAND = 15
+const SASSANIDS_HOMELAND = 16
const ARMY = [
[ 100, 101, 102, 103, 104, 105 ],
@@ -55,21 +47,63 @@ const ARMY = [
[ 400, 401, 402, 403, 404, 405 ]
]
-const EVENT_PLAGUE_OF_CYPRIAN = 1
-const EVENT_ARDASHIR = 2
-const EVENT_PRIEST_KING = 3
-const EVENT_PALMYRA_ALLIES = 4
-const EVENT_SHAPUR_I = 5
-const EVENT_POSTUMUS = 6
-const EVENT_LUDI_SAECULARES = 7
-const EVENT_CNIVA = 8
-const EVENT_ZENOBIA = 9
-const EVENT_BAD_AUGURIES = 10
-const EVENT_RAIDING_PARTIES = 11
-const EVENT_PREPARING_FOR_WAR = 12
-const EVENT_INFLATION = 13
-const EVENT_GOOD_AUGURIES = 14
-const EVENT_DIOCLETIAN = 15
+const REGION_NAME = [
+ "Italia",
+ "Aegyptus",
+ "Africa",
+ "Asia",
+ "Britannia",
+ "Galatia",
+ "Gallia",
+ "Hispania",
+ "Macedonia",
+ "Pannonia",
+ "Syria",
+ "Thracia",
+ "Alamanni Homeland",
+ "Franks Homeland",
+ "Goths Homeland",
+ "Nomads Homeland",
+ "Sassanids Homeland",
+]
+
+const ALAMANNI = 0
+const FRANKS = 1
+const GOTHS = 2
+const NOMADS = 3
+const SASSANIDS = 4
+
+const BARBARIAN_NAME = [
+ "Alamanni",
+ "Franks",
+ "Goths",
+ "Nomads",
+ "Sassanids",
+]
+
+const ALAMANNI_UNITS = [ 0, 9 ]
+const FRANKS_UNITS = [ 10, 19 ]
+const GOTHS_UNITS = [ 20, 29 ]
+const NOMADS_UNITS = [ 30, 39 ]
+const SASSANIDS_UNITS = [ 40, 49 ]
+
+const LEGION_UNITS = [ 50, 82 ]
+
+const BARBARIAN_UNITS = [
+ ALAMANNI_UNITS,
+ FRANKS_UNITS,
+ GOTHS_UNITS,
+ NOMADS_UNITS,
+ SASSANIDS_UNITS,
+]
+
+const BARBARIAN_HOMELAND = [
+ ALAMANNI_HOMELAND,
+ FRANKS_HOMELAND,
+ GOTHS_HOMELAND,
+ NOMADS_HOMELAND,
+ SASSANIDS_HOMELAND,
+]
// 12x
const CARD_M1 = [ 1, 12 ]
@@ -91,15 +125,65 @@ const CARD_M4 = [ 88, 93 ]
const CARD_S4 = [ 94, 99 ]
const CARD_P4 = [ 100, 105 ]
-const player_names = [ P1, P2, P3, P4 ]
+const EVENT_PLAGUE_OF_CYPRIAN = 1
+const EVENT_ARDASHIR = 2
+const EVENT_PRIEST_KING = 3
+const EVENT_PALMYRA_ALLIES = 4
+const EVENT_SHAPUR_I = 5
+const EVENT_POSTUMUS = 6
+const EVENT_LUDI_SAECULARES = 7
+const EVENT_CNIVA = 8
+const EVENT_ZENOBIA = 9
+const EVENT_BAD_AUGURIES = 10
+const EVENT_RAIDING_PARTIES = 11
+const EVENT_PREPARING_FOR_WAR = 12
+const EVENT_INFLATION = 13
+const EVENT_GOOD_AUGURIES = 14
+const EVENT_DIOCLETIAN = 15
+
+const CRISIS_TABLE_4P = [ 0, 0,
+ "Ira Deorum",
+ SASSANIDS,
+ FRANKS,
+ SASSANIDS,
+ GOTHS,
+ "Event",
+ ALAMANNI,
+ NOMADS,
+ FRANKS,
+ NOMADS,
+ "Pax Deorum"
+]
-const player_index = {
- [P1]: 0,
- [P2]: 1,
- [P3]: 2,
- [P4]: 3,
- "Observer": -1,
-}
+const CRISIS_TABLE_3P = [ 0, 0,
+ "Ira Deorum",
+ FRANKS,
+ SASSANIDS,
+ SASSANIDS,
+ FRANKS,
+ "Event",
+ ALAMANNI,
+ GOTHS,
+ GOTHS,
+ ALAMANNI,
+ "Pax Deorum"
+]
+
+const CRISIS_TABLE_2P = [ 0, 0,
+ "Ira Deorum",
+ FRANKS,
+ ALAMANNI,
+ FRANKS,
+ GOTHS,
+ "Event",
+ GOTHS,
+ FRANKS,
+ ALAMANNI,
+ ALAMANNI,
+ "Pax Deorum"
+]
+
+// ===
var game
var view
@@ -145,6 +229,16 @@ function setup_market_pile(cards) {
return pile
}
+function setup_barbarians(tribe) {
+ for (let i = BARBARIAN_UNITS[0]; i <= BARBARIAN_UNITS[1]; ++i)
+ game.barbarians[i] = BARBARIAN_HOMELAND[i]
+}
+
+function remove_barbarians(tribe) {
+ for (let i = BARBARIAN_UNITS[0]; i <= BARBARIAN_UNITS[1]; ++i)
+ game.barbarians[i] = OFF_MAP
+}
+
exports.setup = function (seed, scenario, options) {
let player_count = options.players || 4
@@ -160,21 +254,9 @@ exports.setup = function (seed, scenario, options) {
has_militia: new Array(12).fill(0),
support: new Array(12).fill(1),
legions: new Array(33).fill(OFF_MAP),
- barbarians: [
- new Array(10).fill(ALAMANNI_HOME),
- new Array(10).fill(FRANKS_HOME),
- new Array(10).fill(GOTHS_HOME),
- new Array(10).fill(NOMADS_HOME),
- new Array(10).fill(SASSANIDS_HOME),
- ],
is_legion_reduced: new Array(33).fill(0),
- is_barbarian_inactive: [
- new Array(10).fill(1),
- new Array(10).fill(1),
- new Array(10).fill(1),
- new Array(10).fill(1),
- new Array(10).fill(1),
- ],
+ barbarians: new Array(50).fill(OFF_MAP),
+ is_barbarian_inactive: new Array(50).fill(0),
barbarian_leaders: [ OFF_MAP, OFF_MAP, OFF_MAP ],
rival_emperors: [ OFF_MAP, OFF_MAP, OFF_MAP ],
market: [
@@ -190,6 +272,12 @@ exports.setup = function (seed, scenario, options) {
],
}
+ setup_barbarians(ALAMANNI)
+ setup_barbarians(FRANKS)
+ setup_barbarians(GOTHS)
+ setup_barbarians(NOMADS)
+ setup_barbarians(SASSANIDS)
+
for (let pi = 0; pi < player_count; ++pi) {
game.players[pi] = {
legacy: 0,
@@ -211,7 +299,7 @@ exports.setup = function (seed, scenario, options) {
game.support[HISPANIA] = NO_PLACE_GOVERNOR
game.support[AFRICA] = NO_PLACE_GOVERNOR
game.support[AEGYPTUS] = NO_PLACE_GOVERNOR
- game.barbarians[NOMADS].fill(OFF_MAP)
+ remove_barbarians(NOMADS)
}
if (player_count === 2) {
@@ -222,22 +310,20 @@ exports.setup = function (seed, scenario, options) {
game.support[AEGYPTUS] = NO_PLACE_GOVERNOR
game.support[SYRIA] = NO_PLACE_GOVERNOR
game.support[GALATIA] = NO_PLACE_GOVERNOR
- game.barbarians[NOMADS].fill(OFF_MAP)
- game.barbarians[SASSANIDS].fill(OFF_MAP)
+ remove_barbarians(NOMADS)
+ remove_barbarians(SASSANIDS)
}
- log("DEBUG EVENT DECK: " + game.events)
-
return save_game()
}
function load_game(state) {
game = state
- game.active = player_index[game.active]
+ game.active = PLAYER_INDEX[game.active]
}
function save_game() {
- game.active = player_names[game.active]
+ game.active = PLAYER_NAMES[game.active]
return game
}
@@ -256,13 +342,13 @@ exports.action = function (state, player, action, arg) {
}
exports.view = function (state, player_name) {
- let player = player_index[player_name]
+ let player = PLAYER_INDEX[player_name]
load_game(state)
view = {
log: game.log,
- active: player_names[game.active],
+ active: PLAYER_NAMES[game.active],
prompt: null,
}
@@ -270,11 +356,11 @@ exports.view = function (state, player_name) {
view.prompt = game.victory
} else if (game.active !== player) {
let inactive = states[game.state].inactive || game.state
- view.prompt = `Waiting for ${player_names[game.active]} \u2014 ${inactive}...`
+ view.prompt = `Waiting for ${PLAYER_NAMES[game.active]} \u2014 ${inactive}...`
} else {
view.actions = {}
states[game.state].prompt()
- view.prompt = player_names[game.active] + ": " + view.prompt
+ view.prompt = PLAYER_NAMES[game.active] + ": " + view.prompt
if (game.undo && game.undo.length > 0)
view.actions.undo = 1
else