diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-01-06 12:36:26 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-16 19:12:55 +0100 |
commit | 043d001a97f8e0a793a066b1cf17ba65a6a960b6 (patch) | |
tree | 859cef2d1e68765c74e2161b420b96070d12c538 /rules.js | |
parent | f55843621918f9b28ed03111b535d934508f9a38 (diff) | |
download | richard-iii-043d001a97f8e0a793a066b1cf17ba65a6a960b6.tar.gz |
Update for new server version.
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 42 |
1 files changed, 13 insertions, 29 deletions
@@ -129,7 +129,7 @@ function clear_undo() { function push_undo() { game.undo.push(JSON.stringify(game, (k,v) => { - if (k === 'undo') return undefined; + if (k === 'undo') return 0; if (k === 'log') return v.length; return v; })); @@ -138,7 +138,7 @@ function push_undo() { function pop_undo() { let undo = game.undo; let save_log = game.log; - Object.assign(game, JSON.parse(undo.pop())); + game = JSON.parse(undo.pop()); game.undo = undo; save_log.length = game.log; game.log = save_log; @@ -1332,8 +1332,10 @@ function start_campaign() { } function start_game_turn() { + game.turn = 8 - game.l_hand.length; + log(""); - log("Start Turn " + (8-game.l_hand.length) + " of campaign " + game.campaign + "."); + log("Start Turn " + game.turn + " of campaign " + game.campaign + "."); // Reset movement and attack tracking state reset_border_limits(); @@ -3336,7 +3338,7 @@ function make_battle_view() { function fill_cell(cell, owner, fn) { for (let b in BLOCKS) if (game.location[b] === game.where & block_owner(b) === owner && !game.dead[b] && fn(b)) - cell.push([b, game.steps[b], game.moved[b]?1:0]) + cell.push(b); } fill_cell(battle.LR, LANCASTER, b => is_battle_reserve(b)); @@ -3397,7 +3399,7 @@ exports.action = function (state, current, action, arg) { S[action](arg, current); else throw new Error("Invalid action: " + action); - return state; + return game; } exports.resign = function (state, current) { @@ -3410,7 +3412,7 @@ exports.resign = function (state, current) { game.victory = current + " resigned."; game.result = ENEMY[current]; } - return state; + return game; } function observer_hand() { @@ -3420,6 +3422,8 @@ function observer_hand() { return hand; } +exports.is_checkpoint = (a, b) => a.turn !== b.turn; + exports.view = function(state, current) { game = state; @@ -3434,8 +3438,9 @@ exports.view = function(state, current) { hand: (current === LANCASTER) ? game.l_hand : (current === YORK) ? game.y_hand : observer_hand(), who: (game.active === current) ? game.who : null, where: game.where, - known: {}, - secret: { York: {}, Lancaster: {}, Rebel: {} }, + location: game.location, + steps: game.steps, + moved: game.moved, battle: null, prompt: null, actions: null, @@ -3446,26 +3451,5 @@ exports.view = function(state, current) { if (states[game.state].show_battle) view.battle = make_battle_view(); - for (let b in BLOCKS) { - let a = game.location[b]; - if (!a) - continue; - - let is_known = false; - if (current === block_owner(b) || (game.dead[b] && is_block_on_map(b)) || game.state === 'game_over') - is_known = true; - - if (is_known) { - view.known[b] = [a, game.steps[b], (game.moved[b] || game.dead[b]) ? 1 : 0]; - } else { - let list = view.secret[BLOCKS[b].owner]; - if (!(a in list)) - list[a] = [0, 0]; - list[a][0]++; - if (game.moved[b] || game.dead[b]) - list[a][1]++; - } - } - return view; } |