diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2024-12-29 12:49:18 -0500 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2024-12-29 12:49:18 -0500 |
commit | 0cc290407e8792ee79c918d528e500237173da97 (patch) | |
tree | cc867416d1b20e313b54056f383f486bd7aa7690 | |
parent | ea22a43c2f0507cdc25494c896f577475d6f0971 (diff) | |
download | vijayanagara-0cc290407e8792ee79c918d528e500237173da97.tar.gz |
Conspire automation
-rw-r--r-- | play.js | 11 | ||||
-rw-r--r-- | rules.js | 199 |
2 files changed, 116 insertions, 94 deletions
@@ -1064,6 +1064,7 @@ function on_update() { // Command buttons action_button("attack", "Attack") + action_button("end_attack", "End Attack") action_button("migrate", "Migrate") action_button("end_migrate", "End Migrate") action_button("rally", "Rally") @@ -1385,7 +1386,7 @@ function on_log(text) { text = text.substring(4) p.className = "h2 ds" } - else if (text.match(/^\.h2 ds/)) { + else if (text.match(/^\.h2 DS/)) { text = text.substring(6) p.className = "h2 ds" } @@ -1393,7 +1394,7 @@ function on_log(text) { text = text.substring(4) p.className = "h2 bk" } - else if (text.match(/^\.h2 bk/)) { + else if (text.match(/^\.h2 BK/)) { text = text.substring(6) p.className = "h2 bk" } @@ -1401,7 +1402,7 @@ function on_log(text) { text = text.substring(4) p.className = "h2 ve" } - else if (text.match(/^\.h2 ve/)) { + else if (text.match(/^\.h2 VE/)) { text = text.substring(6) p.className = "h2 ve" } @@ -1409,6 +1410,10 @@ function on_log(text) { text = text.substring(4) p.className = "h2 mi" } + else if (text.match(/^\.h2 MI/)) { + text = text.substring(4) + p.className = "h2 mi" + } else if (text.match(/^\.h2 /)) { text = text.substring(3) p.className = "h2" @@ -47,7 +47,7 @@ const last_space = S_PUNJAB const last_province = S_TAMILAKAM const faction_name = [ "Delhi Sultanate", "Bahmani Kingdom", "Vijayanagara Empire", "Mongol Invaders" ] -const faction_acronyms = [ "ds", "bk", "ve", "mi" ] +const faction_acronyms = [ "DS", "BK", "VE", "MI" ] const AD = [ "0", '\u2776', '\u2777', '\u2778', '\u2779', '\u277A', '\u277B' ] const DD = [ "0", '\u2460', '\u2461', '\u2462', '\u2463', '\u2464', '\u2465' ] @@ -770,19 +770,16 @@ states.strategic_assistance = { states.tax = { prompt() { - if (game.decree.count === 1) { - view.prompt = `Tax: Collect ${tax_count()} from Controlled Prosperity and Temples.` + view.prompt = `Tax: Collect ${tax_count()} from Controlled Prosperity and Temples.` + if (game.decree.count > 0) gen_action_resources(VE) - } else { - view.prompt = "Tax: Done." - view.actions.end_tax = 1 - } + view.actions.end_tax = prompt_end_decree() }, resources(f) { let t = tax_count() add_resources(game.current, t) - logi_resources(VE, t) + log_resources(VE, t) game.decree.count = 0 }, end_tax: end_decree @@ -821,6 +818,36 @@ function can_select_cmd_space(cost) { return true } +function end_command() { + if (game.summary && game.summary.length > 0) { + pop_summary() + } + log_br() + game.cmd = null + game.state = "main_phase" +} + +function end_decree() { + if (game.summary && game.summary.length > 0) { + pop_summary() + } + log_br() + game.decree = null + game.state = "main_phase" +} + +function prompt_end_cmd(cost) { + if (!view.actions.space) { + if (game.cmd.limited && game.cmd.spaces && game.cmd.spaces.length > 0) + view.prompt = game.cmd.type + ": Done." + else if (!game.cmd.free && game.resources[game.current] < cost) + view.prompt = game.cmd.type + ": No resources." + else + view.prompt = game.cmd.type + ": Done." + } + return (game.cmd.spaces.length > 0) ? 1 : 0 +} + function select_cmd_space(s, cost) { set_add(game.cmd.spaces, s) if (!game.cmd.free) @@ -857,36 +884,6 @@ function can_rebel_in_space(s) { return false } -function prompt_end_cmd(cost) { - if (!view.actions.space) { - if (game.cmd.limited && game.cmd.spaces && game.cmd.spaces.length > 0) - view.prompt = game.cmd.type + ": Done." - else if (!game.cmd.free && game.resources[game.current] < cost) - view.prompt = game.cmd.type + ": No resources." - else - view.prompt = game.cmd.type + ": Done." - } - return (game.cmd.spaces.length > 0) ? 1 : 0 -} - -function end_command() { - if (game.summary && game.summary.length > 0) { - pop_summary() - } - log_br() - game.cmd = null - game.state = "main_phase" -} - -function end_decree() { - if (game.summary && game.summary.length > 0) { - pop_summary() - } - log_br() - game.decree = null - game.state = "main_phase" -} - /* SHARED COMMANDS */ function can_attack() { @@ -1016,9 +1013,8 @@ states.attack = { if (!is_selected_cmd_space(s) && can_attack_in_space(s)) gen_action_space(s) } - } else { - view.prompt = "Attack: Done." } + view.actions.end_attack = prompt_end_cmd(1) }, space(s) { push_undo() @@ -1027,7 +1023,8 @@ states.attack = { set_add(game.cmd.spaces, game.cmd.where) log_space(game.cmd.where, "Attack") goto_attack_select() - } + }, + end_attack: end_command } states.attack_select = { @@ -1175,7 +1172,7 @@ states.attack_cavalry = { }, die(d) { if (!game.cmd.cavalry) { - log(`${faction_name[game.current]} is using Cavalry.`) + log(`${faction_acronyms[game.current]} is using Cavalry.`) game.cmd.cavalry = true } @@ -1215,7 +1212,7 @@ states.attack_casualties = { game.cmd.count > 0 && game.cmd.selected.filter(p => piece_faction(p) === game.current).length > 0 ) { - view.prompt = `Attack: ${faction_name[game.current]} must remove ${game.cmd.count} pieces as casualties.` + view.prompt = `Attack: ${faction_acronyms[game.current]} must remove ${game.cmd.count} pieces as casualties.` for (let p of game.cmd.selected) if (piece_faction(p) === game.current) @@ -1474,9 +1471,7 @@ states.migrate = { if (!is_selected_cmd_space(s) && can_migrate_in_space(s)) gen_action_space(s) - if (game.cmd.spaces) - view.actions.end_migrate = 1 - + view.actions.end_migrate = prompt_end_cmd(1) }, space(s) { game.cmd.where = s @@ -1612,10 +1607,19 @@ states.rally_space = { /* DECREES */ +function prompt_end_decree() { + if (game.decree.count === 0) { + view.prompt = game.decree.type + ": Done." + return 1 + } + return 0 +} + function init_decree(type) { push_undo() log_h2(faction_name[game.current] + " - " + type) game.decree = {} + game.decree.type = type } function gen_any_decree() { @@ -1665,25 +1669,23 @@ function collect_count() { } function goto_collect() { - init_decree("Collect") + init_decree("Collect Tribute") game.decree.count = 1 game.state = "collect" } states.collect = { prompt() { - if (game.decree.count > 0) { - view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity` + view.prompt = `Collect Tribute: Collect ${collect_count()} from half the Tributaries prosperity` + if (game.decree.count > 0) gen_action_resources(DS) - } else { - view.prompt = "Collect Tribute: Done." - view.actions.end_collect = 1 - } + + view.actions.end_collect = prompt_end_decree() }, resources(f) { let c = collect_count() add_resources(DS, c) - logi_resources(DS, c) + log_resources(DS, c) game.decree.count = 0 goto_cavalry(2, "collect") }, @@ -1816,15 +1818,12 @@ states.build = { else if (game.current === VE) view.prompt = "Build: Select a Province with a Raja." - if (game.decree.count === 1) { - for (let s = first_space; s <= last_space; ++s) { + if (game.decree.count === 1) + for (let s = first_space; s <= last_space; ++s) if (can_build_in_space(s)) gen_action_space(s) - } - } else { - view.prompt = "Build: Done." - view.actions.end_build = 1 - } + + view.actions.end_build = prompt_end_decree() }, space(s) { push_undo() @@ -1952,36 +1951,62 @@ function can_conspire_in_space(s) { function goto_conspire() { init_decree("Conspire") game.decree.count = 2 + game.decree.spaces = [] game.state = "conspire" } states.conspire = { prompt() { - if (game.decree.count === 0 || !can_conspire()) { + if ((!has_piece(AVAILABLE, BK, ELITE))) { + view.prompt = "Conspire: No Available Amir." + } else if (game.decree.count === 0 || !can_conspire()) { view.prompt = "Conspire: Done." - view.actions.end_conspire = 1 } else { - if (game.decree.count === 1) - view.actions.end_conspire = 1 + if (game.decree.count === 2) + view.actions.end_conspire = 0 - if (game.inf[BK] < 2) - view.prompt = "Conspire: Select Province with your presence to convert a Governor." - else - view.prompt = "Conspire: Select Province with or adjacent to your presence to convert a Governor or Raja." + view.prompt = game.inf[BK] < 2 + ? "Conspire: Select Province with your presence to convert a Governor." + : "Conspire: Select Province with or adjacent to your presence to convert a Governor or Raja."; for (let s = first_space; s <= last_province; ++s) - if (can_conspire_in_space(s)) + if (can_conspire_in_space(s) && !set_has(game.decree.spaces, s)) gen_action_space(s) } + view.actions.end_conspire ??= 1 }, space(s) { - log_space(s, "Conspire") - game.decree.where = s - game.state = "conspire_space" + push_undo() + goto_conspire_space(s) }, end_conspire: end_decree } +function goto_conspire_space(s) { + log_space(s, "Conspire") + game.decree.where = s + set_add(game.decree.spaces, s) + + let is_ds = has_piece(s, DS, ELITE) + let is_ve = has_piece(s, VE, ELITE) + if (is_ds && !is_ve) + conspire_piece(find_piece(s, DS, ELITE)) + else if (is_ve && !is_ds) + conspire_piece(find_piece(s, VE, ELITE)) + else + game.state = "conspire_space" +} + +function conspire_piece(p) { + logi("1 " + piece_name(p)) + log_br() + remove_piece(p) + let amir = find_piece(AVAILABLE, BK, ELITE) + place_piece(amir, game.decree.where) + game.decree.count -= 1 + game.state = "conspire" +} + states.conspire_space = { // TODO: Make sure that the rebel status carry over // TODO: Simply non-choices? @@ -1996,13 +2021,7 @@ states.conspire_space = { } }, piece(p) { - logi("1 " + piece_name(p)) - log_br() - remove_piece(p) - let amir = find_piece(AVAILABLE, BK, ELITE) - place_piece(amir, game.decree.where) - game.decree.count -= 1 - game.state = "conspire" + conspire_piece(p) } } @@ -2025,18 +2044,16 @@ function goto_trade() { states.trade = { prompt() { - if (game.decree.count === 1) { - view.prompt = `Trade: Collect ${trade_count()} from Provinces with your presence.` + view.prompt = `Trade: Collect ${trade_count()} from Provinces with your presence.` + if (game.decree.count === 1) gen_action_resources(BK) - } else { - view.prompt = "Trade: Done." - view.actions.end_trade = 1 - } + + view.actions.end_trade = prompt_end_decree() }, resources(f) { let t = trade_count() add_resources(game.current, t) - logi_resources(BK, t) + log_resources(BK, t) game.decree.count = 0 goto_cavalry(trade_cavalry_count(), "trade") }, @@ -2677,16 +2694,16 @@ function log_summary_remove(p) { function logi_resources(faction, n) { if (n > 0) - logi(faction_name[faction] + " Resources +" + n) + logi(faction_acronyms[faction] + " Resources +" + n) else - logi(faction_name[faction] + " Resources " + n) + logi(faction_acronyms[faction] + " Resources " + n) } function log_resources(faction, n) { if (n > 0) - log(faction_name[faction] + " Resources +" + n + ".") + log(faction_acronyms[faction] + " Resources +" + n + ".") else - log(faction_name[faction] + " Resources " + n + ".") + log(faction_acronyms[faction] + " Resources " + n + ".") } // === MISC PIECE QUERIES === |