diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 64 |
1 files changed, 25 insertions, 39 deletions
@@ -11,9 +11,15 @@ exports.roles = [ "Pompeius", ] -const { - CARDS, SPACES, EDGES, BLOCKS, block_index, space_index, -} = require('./data') +const { CARDS, SPACES, EDGES, BLOCKS } = require('./data') + +function find_block(name) { + return BLOCKS.findIndex(b => b.name === name) +} + +function find_space(name) { + return SPACES.findIndex(s => s.name === name) +} const block_count = BLOCKS.length const space_count = SPACES.length @@ -32,18 +38,18 @@ const BOTH = "Both" const CAESAR = "Caesar" const POMPEIUS = "Pompeius" -const B_CAESAR = block_index["Caesar"] -const B_POMPEIUS = block_index["Pompeius"] -const B_CLEOPATRA = block_index["Cleopatra"] -const B_OCTAVIAN = block_index["Octavian"] -const B_BRUTUS = block_index["Brutus"] -const B_ANTONIUS = block_index["Antonius"] -const B_SCIPIO = block_index["Scipio"] +const B_CAESAR = find_block("Caesar") +const B_POMPEIUS = find_block("Pompeius") +const B_CLEOPATRA = find_block("Cleopatra") +const B_OCTAVIAN = find_block("Octavian") +const B_BRUTUS = find_block("Brutus") +const B_ANTONIUS = find_block("Antonius") +const B_SCIPIO = find_block("Scipio") -const ALEXANDRIA = space_index["Alexandria"] -const ROMA = space_index["Roma"] -const DEAD = space_index["Dead"] -const LEVY = space_index["Levy"] +const ALEXANDRIA = find_space("Alexandria") +const ROMA = find_space("Roma") +const DEAD = find_space("Dead") +const LEVY = find_space("Levy") // serif cirled numbers const DIE_HIT = [ 0, '\u2776', '\u2777', '\u2778', '\u2779', '\u277A', '\u277B' ] @@ -73,10 +79,6 @@ function logi(s) { game.log.push(">" + s) } -function logii(s) { - game.log.push(">>" + s) -} - function log_battle(s) { game.log.push(game.active[0] + ": " + s) } @@ -277,7 +279,9 @@ function move_to(who, from, to) { } function block_original_owner(who) { - return BLOCKS[who].owner + if (who >= B_CLEOPATRA) + return POMPEIUS + return CAESAR } function block_owner(who) { @@ -2681,9 +2685,9 @@ exports.setup = function (seed, scenario, options) { function deploy_block(owner, location, name) { for (let b = 0; b < block_count; ++b) { - if (BLOCKS[b].owner === owner && BLOCKS[b].name === name) { + if (block_original_owner(b) === owner && BLOCKS[b].name === name) { game.steps[b] = BLOCKS[b].steps - game.location[b] = space_index[location] + game.location[b] = find_space(location) return } } @@ -2732,24 +2736,6 @@ exports.action = function (state, current, action, arg) { game = state let S = states[game.state] if (action in S) { - switch (action) { - case 'block': - case 'battle_fire': - case 'battle_retreat': - case 'battle_pass': - case 'battle_hit': - if (typeof arg === 'string') - arg = block_index[arg] - break - case 'space': - if (typeof arg === 'string') - arg = space_index[arg] - break - case 'secret': - if (typeof arg[0] === 'string') - arg[0] = space_index[arg[0]] - break - } S[action](arg, current) } else { throw new Error("Invalid action: " + action) |