diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 495 |
1 files changed, 240 insertions, 255 deletions
@@ -383,6 +383,13 @@ function card_event_name(c) { return "None" } +function can_play_card_event(c) { + return false +} + +function play_card_event(c) { +} + function add_card_ip(c) { if (c >= CARD_M1[0] && c <= CARD_M1[1]) return game.ip[MILITARY] += 1 if (c >= CARD_M2[0] && c <= CARD_M2[1]) return game.ip[MILITARY] += 2 @@ -1101,127 +1108,102 @@ function goto_take_actions() { game.placed = 0 // only place governor once (and no place if recalled) } -function prompt(s) { - view.prompt = s -} +states.take_actions = { + prompt() { + let [ mip, sip, pip ] = game.ip -function prompt_take_actions(label, sel_gov, sel_gen) { - let [ mip, sip, pip ] = game.ip + prompt(`Take Actions: ${mip} Military, ${sip} Senate, ${pip} Populace.`) - prompt(`${label}: ${mip} Military, ${sip} Senate, ${pip} Populace.`) + let where = UNAVAILABLE - if (sel_gov >= 0) - view.selected_governor = sel_gov - if (sel_gen >= 0) - view.selected_general = sel_gen + view.actions.end_actions = 1 - for (let c of current_hand()) - gen_action_card(c) + // Play cards for IP + for (let c of current_hand()) + gen_action_card(c) - for (let i = 0; i < 6; ++i) { - let id = game.current * 6 + i - if (id !== sel_gov) { - let where = get_governor_location(id) - if ((where === UNAVAILABLE) && (sip >= i)) - gen_action_governor(id) - if ((where === AVAILABLE) && (sip >= 1)) - gen_action_governor(id) - if (is_region(where) && (sip >= 2 || pip >= 2)) - gen_action_governor(id) + // Use events on played cards + for (let c of game.played) + if (!set_has(game.used, c) && can_play_card_event(c)) + gen_action_card(c) + + if (game.selected_governor >= 0) { + view.selected_governor = game.selected_governor + where = get_governor_location(game.selected_governor) } - } - for (let i = 0; i < 6; ++i) { - let id = game.current * 6 + i - if (id !== sel_gen) { - let where = get_general_location(id) - if (where === UNAVAILABLE && mip >= i) - gen_action_general(id) - if (where === AVAILABLE && mip >= 1) - gen_action_general(id) - if (is_region(where)) { - if (mip >= 1) - gen_action_general(id) - else if (is_province(where)) { - if (is_general_inside_capital(id) || can_enter_capital(where)) - gen_action_general(id) + if (game.selected_general >= 0) { + view.selected_general = game.selected_general + where = get_general_location(game.selected_general) + } + + // Select Governor + for (let i = 0; i < 6; ++i) { + let id = game.current * 6 + i + if (id !== game.selected_governor) { + switch (get_governor_location(id)) { + case UNAVAILABLE: + if (sip >= i) + gen_action_governor(id) + break + case AVAILABLE: + if (sip >= 1) + gen_action_governor(id) + break + default: + gen_action_governor(id) + break } } } - } - - view.actions.end_actions = 1 -} - -function action_take_actions_card(c) { - push_undo() - let hand = current_hand() - if (set_has(hand, c)) { - set_delete(hand, c) - set_add(game.played, c) - add_card_ip(c) - } else if (set_has(game.played, c)) { - log("TODO - use event") - set_delete(game.played, c) - set_add(current_discard(), c) - } -} - -function action_take_actions_governor(id) { - game.who = id - game.state = "take_actions_governor" -} - -function action_take_actions_general(id) { - if (is_own_general(id)) { - game.who = id - game.state = "take_actions_general" - } else { - if (game.state === "take_actions_general") - goto_battle_vs_general(get_general_location(game.who), game.who, id) - else - goto_battle_vs_general(get_general_location(game.who), -1, id) - } -} -function action_take_actions_end_actions() { - push_undo() - goto_support_check() -} - -states.take_actions = { - prompt() { - let player = game.current - let [ mip, sip, pip ] = game.ip - prompt_take_actions("Take Actions", -1, -1) - }, - end_actions: action_take_actions_end_actions, - card: action_take_actions_card, - governor: action_take_actions_governor, - general: action_take_actions_general, -} - -states.take_actions_governor = { - prompt() { - let [ mip, sip, pip ] = game.ip - - let where = get_governor_location(game.who) - - prompt_take_actions("Take Actions", game.who, -1) + // Select General + for (let i = 0; i < 6; ++i) { + let id = game.current * 6 + i + if (id !== game.selected_general) { + switch (get_general_location(id)) { + case UNAVAILABLE: + if (mip >= i) + gen_action_general(id) + break + case AVAILABLE: + if (mip >= 1) + gen_action_general(id) + break + default: + gen_action_general(id) + break + } + } + } // Recruit Governor - if (where === UNAVAILABLE) { + if (game.selected_governor >= 0 && where === UNAVAILABLE) { view.actions.recruit_governor = 0 - if (sip >= game.who % 6) + if (sip >= game.selected_governor % 6) view.actions.recruit_governor = 1 } + // Recruit General + if (game.selected_general >= 0 && where === UNAVAILABLE) { + view.actions.recruit_general = 0 + if (mip >= game.selected_general % 6) + view.actions.recruit_general = 1 + } + // Place Governor - if (where === AVAILABLE) { + if (game.selected_governor >= 0 && where === AVAILABLE) { gen_place_governor() } - if (is_province(where)) { + // Create Army + if (game.selected_general >= 0 && where === AVAILABLE) { + if (mip >= 1 && find_unused_legion() >= 0) + gen_create_army() + } + + // Governor Actions + if (game.selected_governor >= 0 && is_province(where)) { view.actions.place_militia = 0 view.actions.amphitheater = 0 view.actions.basilica = 0 @@ -1229,7 +1211,7 @@ states.take_actions_governor = { // Recall Governor if (sip >= 2) - gen_action_support(where, 0) + gen_action_recall(where) // Increase Support Level let support = game.support[where] @@ -1272,107 +1254,9 @@ states.take_actions_governor = { gen_initiate_battle(where) } } - }, - - end_actions: action_take_actions_end_actions, - card: action_take_actions_card, - governor: action_take_actions_governor, - general: action_take_actions_general, - - recruit_governor() { - push_undo() - log("Recruited Governor " + (game.who % 6) + ".") - spend_ip(SENATE, game.who % 6) - set_governor_location(game.who, AVAILABLE) - }, - - support(arg) { - push_undo() - let level = arg & 7 - if (level > 0) - improve_support() - else - recall_governor() - }, - - place_militia() { - push_undo() - let where = get_governor_location(game.who) - spend_ip(POPULACE, 2) - add_militia(where) - }, - capital() { - this.place_militia() - }, - - hold_games() { - push_undo() - let where = get_governor_location(game.who) - log("Held Games in S" + where + ".") - spend_ip(POPULACE, 3) - remove_one_mob(where) - }, - - region(where) { - push_undo() - spend_ip(SENATE, 1) - game.misc = { spend: 1, where: where } - game.state = "place_governor" - }, - - amphitheater() { - push_undo() - spend_ip(POPULACE, 3) - let where = get_governor_location(game.who) - add_amphitheater(where) - log("Built Amphitheater in S" + where + ".") - }, - basilica() { - push_undo() - spend_ip(POPULACE, 3) - let where = get_governor_location(game.who) - add_basilica(where) - log("Built Basilica in S" + where + ".") - }, - limes() { - push_undo() - spend_ip(POPULACE, 3) - let where = get_governor_location(game.who) - add_limes(where) - log("Built Limes in S" + where + ".") - }, - - barbarian(id) { - push_undo() - goto_battle_vs_barbarian(get_governor_location(game.who), -1, id) - }, - rival_emperor(id) { - push_undo() - goto_battle_vs_rival_emperor(get_governor_location(game.who), -1, id) - }, -} - -states.take_actions_general = { - prompt() { - let [ mip, sip, pip ] = game.ip - let where = get_general_location(game.who) - - prompt_take_actions("Take Actions", -1, game.who) - - // Recruit General - if (where === UNAVAILABLE) { - view.actions.recruit_general = 0 - if (mip >= game.who % 6) - view.actions.recruit_general = 1 - } - - // Create Army - if (where === AVAILABLE) { - if (mip >= 1 && find_unused_legion() >= 0) - gen_create_army() - } - if (is_region(where)) { + // General Actions + if (game.selected_general >= 0 && is_region(where)) { view.actions.disperse_mob = 0 view.actions.train_legions = 0 view.actions.add_legion_to_army = 0 @@ -1384,19 +1268,19 @@ states.take_actions_general = { } // Train Legions - if (has_reduced_legions_in_army(game.who)) { + if (has_reduced_legions_in_army(game.selected_general)) { if (mip >= 1) view.actions.train_legions = 1 } // Add Legion to Army if (is_own_province(where)) { - let cost = count_legions_in_army(game.who) + 1 + let cost = count_legions_in_army(game.selected_general) + 1 if (mip >= cost) view.actions.add_legion_to_army = 1 } - if (!has_general_battled(game.who)) { + if (!has_general_battled(game.selected_general)) { // Move Army gen_move_army() @@ -1405,7 +1289,7 @@ states.take_actions_general = { // Free Action: Enter/Leave Capital if (is_province(where)) { - if (is_general_inside_capital(game.who)) { + if (is_general_inside_capital(game.selected_general)) { view.actions.leave = 1 } else if (can_enter_capital(where)) { view.actions.enter = 1 @@ -1414,78 +1298,171 @@ states.take_actions_general = { } } } + + }, + + end_actions() { + push_undo() + goto_support_check() }, - end_actions: action_take_actions_end_actions, - card: action_take_actions_card, - governor: action_take_actions_governor, - general: action_take_actions_general, + card(c) { + push_undo() + let hand = current_hand() + if (set_has(hand, c)) { + set_delete(hand, c) + set_add(game.played, c) + add_card_ip(c) + } else if (set_has(game.played, c)) { + log("TODO - use event") + set_delete(game.played, c) + set_add(game.used, c) + action_play_card_event(c) + } + }, + + governor(id) { + game.selected_governor = id + game.selected_general = -1 + }, + + general(id) { + if (is_own_general(id)) { + game.selected_governor = -1 + game.selected_general = id + } else { + goto_battle_vs_general(get_general_location(game.selected_general), game.selected_general, id) + } + }, + + recruit_governor() { + push_undo() + log("Recruited Governor " + (game.selected_governor % 6) + ".") + spend_ip(SENATE, game.selected_governor % 6) + set_governor_location(game.selected_governor, AVAILABLE) + }, recruit_general() { push_undo() - log("Recruited General " + (game.who % 6) + ".") - spend_ip(MILITARY, game.who % 6) - set_general_location(game.who, AVAILABLE) + log("Recruited General " + (game.selected_general % 6) + ".") + spend_ip(MILITARY, game.selected_general % 6) + set_general_location(game.selected_general, AVAILABLE) + }, + + recall() { + push_undo() + recall_governor() + }, + + support() { + push_undo() + improve_support() + }, + + place_militia() { + push_undo() + let where = get_governor_location(game.selected_governor) + spend_ip(POPULACE, 2) + add_militia(where) + }, + + hold_games() { + push_undo() + let where = get_governor_location(game.selected_governor) + log("Held Games in S" + where + ".") + spend_ip(POPULACE, 3) + remove_one_mob(where) + }, + + amphitheater() { + push_undo() + spend_ip(POPULACE, 3) + let where = get_governor_location(game.selected_governor) + add_amphitheater(where) + log("Built Amphitheater in S" + where + ".") + }, + + basilica() { + push_undo() + spend_ip(POPULACE, 3) + let where = get_governor_location(game.selected_governor) + add_basilica(where) + log("Built Basilica in S" + where + ".") + }, + + limes() { + push_undo() + spend_ip(POPULACE, 3) + let where = get_governor_location(game.selected_governor) + add_limes(where) + log("Built Limes in S" + where + ".") }, add_legion_to_army() { push_undo() log("Added Legion to Army.") - let cost = count_legions_in_army(game.who) + 1 + let cost = count_legions_in_army(game.selected_general) + 1 spend_ip(MILITARY, cost) - set_legion_location(find_unused_legion(), ARMY + game.who) + set_legion_location(find_unused_legion(), ARMY + game.selected_general) }, + train_legions() { push_undo() log("Trained Legions.") spend_ip(MILITARY, 1) - set_legion_full_strength(find_reduced_legion_in_army(game.who)) - }, - region(to) { - push_undo() - if (get_general_location(game.who) === AVAILABLE) - create_army(to) - else - // XXX move_army_to(game.who, to, false) - move_army_to(game.who, to, true) + set_legion_full_strength(find_reduced_legion_in_army(game.selected_general)) }, - capital(to) { + + capital(where) { push_undo() - if (get_general_location(game.who) === to) - set_general_inside_capital(game.who) - else if (get_general_location(game.who) === AVAILABLE) - create_army(to) - else - move_army_to(game.who, to, true) + set_general_inside_capital(game.selected_general) }, enter() { push_undo() - set_general_inside_capital(game.who) + set_general_inside_capital(game.selected_general) }, + leave() { push_undo() - set_general_outside_capital(game.who) + set_general_outside_capital(game.selected_general) + }, + + region(where) { + push_undo() + if (game.selected_governor >= 0) { + spend_ip(SENATE, 1) + game.misc = { spend: 1, where: where } + game.state = "place_governor" + } + if (game.selected_general >= 0) { + if (get_general_location(game.selected_general) === AVAILABLE) + create_army(where) + else + move_army_to(game.selected_general, where, true) + } }, barbarian(id) { push_undo() - goto_battle_vs_barbarian(get_general_location(game.who), game.who, id) + goto_battle_vs_barbarian(get_general_location(game.selected_general), game.selected_general, id) }, + rival_emperor(id) { push_undo() - goto_battle_vs_rival_emperor(get_general_location(game.who), game.who, id) + goto_battle_vs_rival_emperor(get_general_location(game.selected_general), game.selected_general, id) }, + militia(where) { push_undo() - goto_battle_vs_militia(get_general_location(game.who), game.who) + goto_battle_vs_militia(get_general_location(game.selected_general), game.selected_general) }, } // ACTION: IMPROVE SUPPORT function improve_support() { - let where = get_governor_location(game.who) + let where = get_governor_location(game.selected_governor) let support = game.support[where] log("Built Support in S" + where + ".") spend_ip(POPULACE, support + 1) @@ -1495,7 +1472,7 @@ function improve_support() { // ACTION: RECALL GOVERNOR function recall_governor() { - let where = get_governor_location(game.who) + let where = get_governor_location(game.selected_governor) log("Recalled Governor from S" + where + ".") spend_ip(SENATE, 2) set_placed_governor(where) @@ -1594,7 +1571,7 @@ states.place_governor = { let votes = game.misc.spend if (game.misc.where === ITALIA) votes += count_own_basilicas() - view.selected_governor = game.who + view.selected_governor = game.selected_governor view.selected_region = game.misc.where prompt(`Place Governor: ${sip} Senate. Rolling ${votes} dice. ${need} votes needed.`) @@ -1627,13 +1604,13 @@ states.place_governor = { if (have >= need) { logi("Success!") - place_governor(game.misc.where, game.who) + place_governor(game.misc.where, game.selected_governor) } else { logi("Failed!") } game.misc = null - game.state = "take_actions_governor" + game.state = "take_actions" }, } @@ -1650,18 +1627,18 @@ function gen_create_army() { function create_army(where) { spend_ip(MILITARY, 1) log("Created Army in S" + where + ".") - set_general_location(game.who, where) + set_general_location(game.selected_general, where) if (can_enter_capital(where)) - set_general_inside_capital(game.who) - set_legion_location(find_unused_legion(), ARMY + game.who) - game.state = "take_actions_general" + set_general_inside_capital(game.selected_general) + set_legion_location(find_unused_legion(), ARMY + game.selected_general) + game.state = "take_actions" } // ACTION: MOVE ARMY function gen_move_army() { let mip = game.ip[MILITARY] - let from = get_general_location(game.who) + let from = get_general_location(game.selected_general) if (mip >= 1) { for (let to of ADJACENT[from]) { if (!is_sea(to)) @@ -1682,17 +1659,17 @@ states.move_army_at_sea = { prompt() { let [ mip, sip, pip ] = game.ip prompt("Move Army.") - view.selected_general = game.who + view.selected_general = game.selected_general gen_move_army() }, region(to) { push_undo() - // XXX move_army_to(game.who, to, false) - move_army_to(game.who, to, true) + // XXX move_army_to(game.selected_general, to, false) + move_army_to(game.selected_general, to, true) }, capital(to) { push_undo() - move_army_to(game.who, to, true) + move_army_to(game.selected_general, to, true) }, } @@ -1707,10 +1684,10 @@ function move_army_to(who, to, go_inside) { if (is_sea(to)) game.state = "move_army_at_sea" else - game.state = "take_actions_general" + game.state = "take_actions" } -// === ACTION: INITIATE BATTLE === +// === COMBAT === function goto_battle_vs_general(where, attacker, target) { log("Initiate Battle vs " + GENERAL_NAME[target] + " in S" + where) @@ -2011,7 +1988,7 @@ states.assign_hits_on_defender = { function end_battle() { // TODO: retreat / advance into capital - game.state = "take_actions_general" + game.state = "take_actions" } // === SUPPORT CHECK === @@ -2047,9 +2024,8 @@ function count_political_points() { function goto_buy_trash_cards() { let discard = current_discard() - for (let c of game.played) { + for (let c of game.played) set_add(discard, c) - } game.played.length = 0 game.misc = { count: 0, @@ -2233,7 +2209,8 @@ exports.setup = function (seed, scenario, options) { active_events: [], ip: [], - who: -1, + selected_governor: -1, + selected_general: -1, played: [], used: [], placed: 0, @@ -2420,6 +2397,10 @@ exports.view = function (state, player_name) { // === MISC === +function prompt(s) { + view.prompt = s +} + function log(msg) { game.log.push(msg) } @@ -2494,6 +2475,10 @@ function gen_action_capital(where) { gen_action("capital", where) } +function gen_action_recall(where) { + gen_action("recall", where) +} + function gen_action_support(where, level) { gen_action("support", where << 3 | level) } |