summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoël Simoneau <simoneaujoel@gmail.com>2024-10-30 15:12:06 -0400
committerJoël Simoneau <simoneaujoel@gmail.com>2024-10-30 15:12:06 -0400
commitddb3b77446db8393b5ad8b5270a145b23132f40f (patch)
treeb3709a22d2b902bef3ed56cee09cc7c4f7982736
parent622c6f7083e0eb6192211dd87cb7b32cf7825268 (diff)
downloadvijayanagara-ddb3b77446db8393b5ad8b5270a145b23132f40f.tar.gz
Trade.
-rw-r--r--play.js1
-rw-r--r--rules.js36
2 files changed, 36 insertions, 1 deletions
diff --git a/play.js b/play.js
index 5ffdfa1..1712cc4 100644
--- a/play.js
+++ b/play.js
@@ -994,6 +994,7 @@ function on_update() {
// Decree buttons
action_button("build", "Build")
action_button("tax", "Tax")
+ action_button("trade", "Trade")
action_button("next", "Next")
action_button("undo", "Undo")
diff --git a/rules.js b/rules.js
index 2c18d34..536663b 100644
--- a/rules.js
+++ b/rules.js
@@ -450,6 +450,11 @@ function goto_tax() {
game.state = "tax"
}
+function goto_trade() {
+ init_command("Trade")
+ game.state = "trade"
+}
+
/* STATES */
states.eligible = {
@@ -505,6 +510,7 @@ states.command_decree = {
rally: goto_rally,
rebel: goto_rebel,
tax: goto_tax,
+ trade: goto_trade,
}
states.event_command = {
@@ -726,6 +732,23 @@ states.tax = {
}
}
+states.trade = {
+ // TODO : Add horses logic to trade
+ prompt() {
+ view.prompt = `Trade: Collect ${trade_count()} from Provinces with your presence`
+
+ gen_action_resources(BK)
+ },
+ resources(f) {
+ let t = trade_count()
+ add_resources(game.current, t)
+ logi_resources(BK, t)
+ game.decree = 0
+ game.state = "command_decree"
+ }
+}
+
+
/* COMMANDS */
function init_command(type) {
@@ -859,7 +882,7 @@ function gen_any_decree() {
// view.actions.campaign = can_campaign() ? 1 : 0
// view.actions.demand = can_demand() ? 1 : 0
} else if (game.current === BK) {
- // view.actions.trade = can_trade() ? 1 : 0
+ view.actions.trade = can_trade() ? 1 : 0
view.actions.build = can_build() ? 1 : 0
// view.actions.conspire = can_conspire() ? 1 : 0
} else if (game.current === VE) {
@@ -885,6 +908,17 @@ function tax_count() {
return count_pieces_on_map(VE, DISC) + game.prosperity[VE]
}
+function can_trade() {
+ return trade_count() > 0
+}
+
+function trade_count() {
+ let count = 0
+ for (let s = first_space; s <= last_province; ++s)
+ count += (count_pieces(s, BK, DISC) + count_pieces(s, BK, ELITE)) > 0 ? 1 : 0
+ return count
+}
+
/* TRIBUTARY AND REBELS */
function add_tributary(s) {