diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 69 |
1 files changed, 34 insertions, 35 deletions
@@ -149,8 +149,8 @@ function gen_action(view, action, argument) { if (!(action in view.actions)) { view.actions[action] = [ argument ] } else { - if (!view.actions[action].includes(argument)) - view.actions[action].push(argument) + if (!set_has(view.actions[action], argument)) + set_add(view.actions[action], argument) } } else { view.actions[action] = 1 @@ -475,7 +475,7 @@ function can_defect(source, target) { // Clarence and Exeter can't defect if they are the king or pretender if (target === game.king || target === game.pretender) return false - return block_loyalty(source, target) > 0 && !game.defected[target] + return block_loyalty(source, target) > 0 && !set_has(game.defected, target) } function can_attempt_treason_event() { @@ -500,7 +500,7 @@ function treachery_tag(who) { function can_attempt_treachery(who) { let once = treachery_tag(who) - if (game.battle_list.includes(who) && !game.treachery[once]) { + if (set_has(game.battle_list, who) && !set_has(game.treachery, once)) { for (let b of BLOCKLIST) { if (game.active === game.attacker[game.where]) { if (is_defender(b) && can_defect(who, b)) @@ -1003,7 +1003,7 @@ function count_defenders() { function count_blocks_exclude_mercenaries(where) { let count = 0 for (let b of BLOCKLIST) - if (!(game.reduced && game.reduced[b]) && game.location[b] === where && !is_mercenary(b)) + if (game.location[b] === where && !is_mercenary(b) && !(game.reduced && set_has(game.reduced, b))) ++count return count } @@ -1011,21 +1011,21 @@ function count_blocks_exclude_mercenaries(where) { function count_blocks(where) { let count = 0 for (let b of BLOCKLIST) - if (!(game.reduced && game.reduced[b]) && game.location[b] === where) + if (game.location[b] === where && !(game.reduced && set_has(game.reduced, b))) ++count return count } function add_blocks_exclude_mercenaries(list, where) { for (let b of BLOCKLIST) - if (!(game.reduced && game.reduced[b]) && game.location[b] === where && !is_mercenary(b)) - list.push(b) + if (game.location[b] === where && !is_mercenary(b) && !(game.reduced && set_has(game.reduced, b))) + set_add(list, b) } function add_blocks(list, where) { for (let b of BLOCKLIST) - if (!(game.reduced && game.reduced[b]) && game.location[b] === where) - list.push(b) + if (game.location[b] === where && !(game.reduced && set_has(game.reduced, b))) + set_add(list, b) } function check_supply_penalty() { @@ -1491,7 +1491,7 @@ function goto_event_card(event) { break case 'piracy': game.piracy = game.active - game.is_pirate = {} + game.is_pirate = [] goto_action_phase(2) break case 'plague': @@ -1524,7 +1524,7 @@ states.plague_event = { game.plague = [] for (let b of BLOCKLIST) if (game.location[b] === where) - game.plague.push(b) + set_add(game.plague, b) game.active = ENEMY[game.active] game.state = 'apply_plague' }, @@ -1543,7 +1543,7 @@ states.apply_plague = { }, block: function (b) { reduce_block(b) - remove_from_array(game.plague, b) + set_delete(game.plague, b) if (game.plague.length === 0) { delete game.plague game.active = ENEMY[game.active] @@ -1733,7 +1733,7 @@ states.action_phase = { } if (can_block_land_move(b)) { if (game.moves === 0) { - if (game.activated.includes(from)) + if (set_has(game.activated, from)) gen_action(view, 'block', b) } else { gen_action(view, 'block', b) @@ -1898,7 +1898,7 @@ states.sea_move_to = { if (game.active === game.piracy && is_contested_area(to)) { // Can attack with piracy, but no port-to-port bonus. log_move_continue(to, ATTACK_MARK) - game.is_pirate[game.who] = true + set_add(game.is_pirate, game.who) if (!game.attacker[to]) game.attacker[to] = game.active logp("sea moved.") @@ -1925,9 +1925,9 @@ states.sea_move_to = { function end_move() { if (game.distance > 0) { log_move_end() - if (!game.activated.includes(game.origin)) { + if (!set_has(game.activated, game.origin)) { logp("activated " + game.origin + ".") - game.activated.push(game.origin) + set_add(game.activated, game.origin) game.moves -- } set_add(game.moved, game.who) @@ -1975,8 +1975,8 @@ function start_battle(where) { log("Battle in " + where + ".") game.where = where game.battle_round = 0 - game.defected = {} - game.treachery = {} + game.defected = [] + game.treachery = [] if (game.treason && can_attempt_treason_event()) { game.active = game.treason @@ -2003,8 +2003,8 @@ function end_battle() { game.battle_round = 0 reset_border_limits() set_clear(game.moved) - game.defected = {} - game.treachery = {} + game.defected = [] + game.treachery = [] goto_regroup() } @@ -2109,7 +2109,7 @@ function pump_battle_round() { if (block_initiative(b) === ci) { if (!output) output = [] - output.push(b) + set_add(output, b) } } } @@ -2150,7 +2150,7 @@ function pass_with_block(b) { function can_retreat_with_block(who) { if (game.location[who] === game.where) { if (game.battle_round > 1) { - if (game.active === game.piracy && game.is_pirate[who]) { + if (game.active === game.piracy && set_has(game.is_pirate, who)) { return true } else { for (let to of AREAS[game.where].exits) @@ -2223,7 +2223,7 @@ function fire_with_block(b) { function attempt_treachery(source, target) { if (source) { let once = treachery_tag(source) - game.treachery[once] = true + set_add(game.treachery, once) set_add(game.moved, source) } let n = block_loyalty(source, target) @@ -2245,7 +2245,7 @@ function attempt_treachery(source, target) { if (result) { game.flash += " converted " + block_name(target) + "!" target = swap_blocks(target) - game.defected[target] = true + set_add(game.defected, target) set_add(game.reserves, target) } else { game.flash += " failed to convert " + block_name(target) + "." @@ -2367,9 +2367,8 @@ states.battle_round = { } let heir = can_heir_charge() - if (heir && game.battle_list.includes(heir)) { + if (heir && set_has(game.battle_list, heir)) gen_action(view, 'battle_charge', heir) - } if (can_attempt_treachery(game.king)) gen_action(view, 'battle_treachery', game.king) if (can_attempt_treachery(game.pretender)) @@ -2515,7 +2514,7 @@ function list_victims(p) { let list = [] for (let b of BLOCKLIST) if (is_candidate(b) && game.steps[b] === max) - list.push(b) + set_add(list, b) return list } @@ -2544,7 +2543,7 @@ states.retreat_in_battle = { return view.prompt = "Waiting for " + game.active + " to retreat." gen_action(view, 'undo') gen_action(view, 'block', game.who) - if (game.active === game.piracy && game.is_pirate[game.who]) { + if (game.active === game.piracy && set_has(game.is_pirate, game.who)) { view.prompt = "Retreat: Move the army to a friendly or vacant areas in the same sea zone." for (let to of AREAS[game.where].exits) if (is_sea_area(to)) @@ -2633,7 +2632,7 @@ states.regroup = { for (let b of BLOCKLIST) { if (game.location[b] === game.where) { if (game.active === game.piracy) { - if (game.is_pirate[b]) + if (set_has(game.is_pirate, b)) gen_action(view, 'block', b) } else { if (can_block_regroup(b)) @@ -2658,7 +2657,7 @@ states.regroup = { states.regroup_to = { prompt: function (view, current) { - if (game.active === game.piracy && game.is_pirate[game.who]) { + if (game.active === game.piracy && set_has(game.is_pirate, game.who)) { if (is_inactive_player(current)) return view.prompt = "Waiting for " + game.active + " to regroup." view.prompt = "Regroup: Move the army to a friendly or vacant area in the same sea zone." @@ -2831,7 +2830,7 @@ states.enter_pretender_heir = { } function goto_supply_limits_pretender() { - game.reduced = {} + game.reduced = [] game.active = block_owner(game.pretender) if (check_supply_penalty()) { game.state = 'supply_limits_pretender' @@ -2858,7 +2857,7 @@ states.supply_limits_pretender = { block: function (who) { push_undo() game.turn_log.push([game.location[who]]) - game.reduced[who] = true + set_add(game.reduced, who) reduce_block(who) check_supply_penalty() }, @@ -2918,7 +2917,7 @@ states.enter_royal_heir = { } function goto_supply_limits_king() { - game.reduced = {} + game.reduced = [] game.active = block_owner(game.king) if (check_supply_penalty()) { game.state = 'supply_limits_king' @@ -2945,7 +2944,7 @@ states.supply_limits_king = { block: function (who) { push_undo() game.turn_log.push([game.location[who]]) - game.reduced[who] = true + set_add(game.reduced, who) reduce_block(who) check_supply_penalty() }, |