summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-03-13 00:33:27 +0100
committerTor Andersson <tor@ccxvii.net>2023-05-03 18:48:15 +0200
commitf72333d6145cd58d81a0486f21e0951be9c9d20b (patch)
tree3a0db034298687133accd89f24dba96152e92c5f
parent4317d7601dd599bfb14f1d4b6694ab020639a6bf (diff)
downloadandean-abyss-f72333d6145cd58d81a0486f21e0951be9c9d20b.tar.gz
Negotiation.
-rw-r--r--play.css1
-rw-r--r--play.html10
-rw-r--r--play.js30
-rw-r--r--rules.js234
4 files changed, 218 insertions, 57 deletions
diff --git a/play.css b/play.css
index c45d870..2de5536 100644
--- a/play.css
+++ b/play.css
@@ -178,6 +178,7 @@ path.tip { stroke: yellow; }
}
.token.shipment { background-color: #01904b; border-color: #01904b; box-shadow: 0 0 0 1px #002c00, 0px 1px 4px #0008; }
.token.shipment.action { box-shadow: 0 0 0 3px white; }
+.token.shipment.selected { box-shadow: 0 0 0 3px yellow; }
#token_total_support { background-color: #006cb7; border-color: #348cda #004d95 #004d95 #348cda; box-shadow: 0 0 0 1px #000d55, 0px 1px 4px #0008; }
#token_prop_card { background-color: #80643e; border-color: #a0835c #614721 #614721 #a0835c; box-shadow: 0 0 0 1px #291200, 0px 1px 4px #0008; }
diff --git a/play.html b/play.html
index c496a70..1ce6114 100644
--- a/play.html
+++ b/play.html
@@ -37,16 +37,14 @@
<div class="icon_button" onclick="toggle_pieces()"><img src="/images/earth-america.svg"></div>
<div class="icon_button" onclick="toggle_zoom()"><img src="/images/magnifying-glass.svg"></div>
<div class="icon_button" onclick="toggle_log()"><img src="/images/scroll-quill.svg"></div>
- <div id="trade_menu" class="menu">
+ <div id="negotiate_menu" class="menu hide">
<div class="menu_title"><img src="images/shaking-hands.svg"></div>
<div class="menu_popup">
- <div id="g_button" class="menu_item" onclick="send_action('g')">Government</div>
- <div id="f_button" class="menu_item" onclick="send_action('f')">FARC</div>
- <div id="a_button" class="menu_item" onclick="send_action('a')">AUC</div>
- <div id="c_button" class="menu_item" onclick="send_action('c')">Cartels</div>
+ <div id="remove_pieces_menu" class="menu_item" onclick="send_action('remove_pieces')">Remove Pieces</div>
+ <div id="ask_resources_menu" class="menu_item" onclick="send_action('ask_resources')">Ask for Resources...</div>
+ <div id="ask_shipment_menu" class="menu_item" onclick="send_action('ask_shipment')">Ask for Shipment...</div>
</div>
</div>
- <div id="remove_button" class="icon_button" onclick="send_action('remove')"><img src="images/back-forth.svg"></div>
</div>
<div id="prompt"></div>
<div id="actions"></div>
diff --git a/play.js b/play.js
index e9bcf42..79be8e4 100644
--- a/play.js
+++ b/play.js
@@ -146,6 +146,25 @@ let ui = {
],
}
+function action_menu_item(action) {
+ let menu = document.getElementById(action + "_menu")
+ if (view.actions && action in view.actions) {
+ menu.classList.toggle("hide", false)
+ menu.classList.toggle("disabled", view.actions[action] === 0)
+ return 1
+ } else {
+ menu.classList.toggle("hide", true)
+ return 0
+ }
+}
+
+function action_menu(menu, action_list) {
+ let x = 0
+ for (let action of action_list)
+ x |= action_menu_item(action)
+ menu.classList.toggle("hide", !x)
+}
+
function create(t, p, ...c) {
let e = document.createElement(t)
Object.assign(e, p)
@@ -906,12 +925,11 @@ function on_update() {
for (let i = 0; i < ui.pieces.length; ++i)
ui.pieces[i].classList.toggle("selected", view.who === i)
- action_button("remove", "Remove")
- // menu trade
- // action_button("trade", "Trade with Govt")
- // action_button("trade", "Trade with FARC")
- // action_button("trade", "Trade with AUC")
- // action_button("trade", "Trade with Cartels")
+ action_menu(document.getElementById("negotiate_menu"), [
+ "remove_pieces",
+ "ask_shipment",
+ "ask_resources"
+ ])
action_button("train", "Train")
action_button("patrol", "Patrol")
diff --git a/rules.js b/rules.js
index 4da376b..497ebf3 100644
--- a/rules.js
+++ b/rules.js
@@ -819,6 +819,10 @@ function drop_shipment(sh) {
game.shipments[sh] = (s << 2) | f
}
+function is_shipment_held(sh) {
+ return game.shipments[sh] >= 0
+}
+
function is_shipment_held_by_piece(sh, p) {
return game.shipments[sh] === p << 2
}
@@ -873,7 +877,7 @@ function has_dropped_shipments() {
return false
}
-function can_transfer_shipments() {
+function can_transfer_dropped_shipments() {
for (let sh = 0; sh < 4; ++sh)
if (is_shipment_dropped(sh))
if (has_any_guerrilla(get_dropped_shipment_space(sh)))
@@ -884,10 +888,10 @@ function can_transfer_shipments() {
function auto_transfer_dropped_shipments(s) {
for (let sh = 0; sh < 4; ++sh)
if (is_shipment_dropped(sh))
- auto_transfer_shipment(sh)
+ auto_transfer_dropped_shipments(sh)
}
-function auto_transfer_shipment(sh) {
+function auto_transfer_dropped_shipments(sh) {
let f = get_dropped_shipment_faction(sh)
let s = get_dropped_shipment_space(sh)
let a, b, p
@@ -1269,13 +1273,14 @@ function end_operation() {
// === REMOVE PIECES (VOLUNTARILY) ===
-function action_remove() {
+function action_remove_pieces() {
push_undo()
- game.save_state = game.state
- game.state = "remove"
+ game.transfer = game.state
+ game.state = "remove_pieces"
}
-states.remove = {
+states.remove_pieces = {
+ disable_negotiation: true,
prompt() {
view.prompt = "Remove pieces to Available Forces."
for (let p = first_piece[game.current][BASE]; p <= last_piece[game.current][BASE]; ++p)
@@ -1300,20 +1305,20 @@ states.remove = {
update_control()
},
done() {
- game.state = game.save_state
- delete game.save_state
+ game.state = game.transfer
+ game.transfer = 0
transfer_or_remove_shipments()
},
}
-// === CLAIM SHIPMENTS ===
+// === TRANSFER SHIPMENTS ===
function transfer_or_remove_shipments()
{
auto_transfer_dropped_shipments()
if (has_dropped_shipments()) {
- if (can_transfer_shipments())
- goto_transfer_shipments()
+ if (can_transfer_dropped_shipments())
+ goto_transfer_dropped_shipments()
else
remove_dropped_shipments()
}
@@ -1323,37 +1328,38 @@ function transfer_or_drug_bust_shipments()
{
auto_transfer_dropped_shipments()
if (has_dropped_shipments()) {
- if (can_transfer_shipments())
- goto_transfer_shipments()
+ if (can_transfer_dropped_shipments())
+ goto_transfer_dropped_shipments()
else
goto_drug_bust()
}
}
-function goto_transfer_shipments() {
+function goto_transfer_dropped_shipments() {
game.transfer = {
- active: game.active,
+ current: game.current,
state: game.state,
shipment: 0,
}
- resume_transfer_shipments()
+ resume_transfer_dropped_shipments()
}
-function resume_transfer_shipments() {
+function resume_transfer_dropped_shipments() {
for (let sh = 0; sh < 4; ++sh) {
if (is_shipment_dropped(sh)) {
- game.active = get_dropped_shipment_faction(sh)
- game.state = "transfer_shipment"
+ game.current = get_dropped_shipment_faction(sh)
+ game.state = "transfer_dropped_shipments"
game.transfer.shipment = sh
return
}
}
- game.active = game.active
+ game.current = game.transfer.current
game.state = game.transfer.state
game.transfer = 0
}
-states.transfer_shipment = {
+states.transfer_dropped_shipments = {
+ disable_negotiation: true,
prompt() {
view.prompt = "Transfer Shipment to another Guerrilla."
let s = get_dropped_shipment_space(game.transfer.shipment)
@@ -1367,7 +1373,7 @@ states.transfer_shipment = {
piece(p) {
push_undo()
place_shipment(game.transfer.shipment, p)
- resume_transfer_shipments()
+ resume_transfer_dropped_shipments()
},
}
@@ -1429,6 +1435,149 @@ states.ship = {
},
}
+// === NEGOTIATION ===
+
+function is_player_govt() {
+ return game.active === NAME_GOVT || game.active === NAME_GOVT_AUC
+}
+
+function is_player_farc() {
+ return game.active === NAME_FARC || game.active === NAME_FARC_CARTELS
+}
+
+function is_player_auc() {
+ return game.active === NAME_AUC || game.active === NAME_GOVT_AUC || game.active === NAME_AUC_CARTELS
+}
+
+function is_player_cartels() {
+ return game.active === NAME_CARTELS || game.active === NAME_FARC_CARTELS || game.active === NAME_AUC_CARTELS
+}
+
+function action_ask_resources() {
+ push_undo()
+ game.transfer = {
+ current: game.current,
+ state: game.state,
+ }
+ game.state = "ask_resources"
+}
+
+states.ask_resources = {
+ disable_negotiation: true,
+ prompt() {
+ view.prompt = "Ask another faction for resources?"
+ console.log("game.current", game.current)
+ if (!is_player_govt() && game.resources[GOVT] > 0)
+ gen_action_resources(GOVT)
+ if (!is_player_farc() && game.resources[FARC] > 0)
+ gen_action_resources(FARC)
+ if (!is_player_auc() && game.resources[AUC] > 0)
+ gen_action_resources(AUC)
+ if (!is_player_cartels() && game.resources[CARTELS] > 0)
+ gen_action_resources(CARTELS)
+ },
+ resources(faction) {
+ game.current = faction
+ game.state = "give_resources"
+ },
+}
+
+states.give_resources = {
+ disable_negotiation: true,
+ prompt() {
+ view.prompt = `${faction_name[game.transfer.current]} asked for Resources.`
+ if (game.resources[game.current] >= 1)
+ gen_action_resources(game.current)
+ view.actions.done = 1
+ },
+ resources(_) {
+ push_undo()
+ add_resources(game.current, -1)
+ add_resources(game.transfer.current, 1)
+ },
+ done() {
+ end_negotiation()
+ },
+}
+
+function action_ask_shipment() {
+ push_undo()
+ game.transfer = {
+ current: game.current,
+ state: game.state,
+ shipment: -1,
+ }
+ game.state = "ask_shipment"
+}
+
+function can_ask_shipment() {
+ for (let sh = 1; sh < 4; ++sh) {
+ if (is_shipment_held(sh)) {
+ let p = game.shipments[sh] >> 2
+ let s = game.pieces[p]
+ if (!is_player_farc() && is_farc_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ return true
+ if (!is_player_auc() && is_auc_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ return true
+ if (!is_player_cartels() && is_cartels_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ return true
+ }
+ }
+ return false
+}
+
+states.ask_shipment = {
+ disable_negotiation: true,
+ prompt() {
+ view.prompt = "Ask another faction to transfer shipment?"
+ for (let sh = 1; sh < 4; ++sh) {
+ if (is_shipment_held(sh)) {
+ let p = game.shipments[sh] >> 2
+ let s = game.pieces[p]
+ if (!is_player_farc() && is_farc_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ gen_action_shipment(sh)
+ if (!is_player_auc() && is_auc_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ gen_action_shipment(sh)
+ if (!is_player_cartels() && is_cartels_guerrilla(p) && has_piece(s, game.current, GUERRILLA))
+ gen_action_shipment(sh)
+ }
+ }
+ },
+ shipment(sh) {
+ let p = game.shipments[sh] >> 2
+ game.current = piece_faction(p)
+ game.state = "give_shipment"
+ game.transfer.shipment = sh
+ },
+}
+
+states.give_shipment = {
+ disable_negotiation: true,
+ prompt() {
+ view.prompt = `${faction_name[game.transfer.current]} asked for Shipment.`
+ view.selected_shipment = game.transfer.shipment
+ let sh = game.transfer.shipment
+ let p = game.shipments[sh] >> 2
+ let s = game.pieces[p]
+ gen_piece_in_space(s, game.transfer.current, GUERRILLA)
+ view.actions.done = 1
+ },
+ piece(p) {
+ push_undo()
+ place_shipment(game.transfer.shipment, p)
+ end_negotiation()
+ },
+ done() {
+ end_negotiation()
+ },
+}
+
+function end_negotiation() {
+ game.current = game.transfer.current
+ game.state = game.transfer.state
+ game.transfer = 0
+}
+
// === OPERATIONS ===
states.op = {
@@ -3846,31 +3995,20 @@ exports.view = function (state, role) {
view.actions = {}
view.who = game.who
- if (game.op) {
- view.actions.remove = 1
- /*
- if (game.active === "Government + AUC")
- view.actions.trade = [ FARC, CARTELS ]
- if (game.active === "FARC + Cartels")
- view.actions.trade = [ GOVT, AUC ]
- if (game.active === "AUC + Cartels")
- view.actions.trade = [ GOVT, FARC ]
- if (game.active === "Government")
- view.actions.trade = [ FARC, AUC, CARTELS ]
- if (game.active === "FARC")
- view.actions.trade = [ GOVT, AUC, CARTELS ]
- if (game.active === "AUC")
- view.actions.trade = [ GOVT, FARC, CARTELS ]
- if (game.active === "Cartels")
- view.actions.trade = [ GOVT, FARC, AUC ]
- */
- }
-
if (states[game.state])
states[game.state].prompt()
else
view.prompt = "Unknown state: " + game.state
+ if (!states[game.state].disable_negotiation) {
+ view.actions.remove_pieces = 1
+ view.actions.ask_resources = 1
+ if (can_ask_shipment())
+ view.actions.ask_shipment = 1
+ else
+ view.actions.ask_shipment = 0
+ }
+
if (view.actions.undo === undefined) {
if (game.undo && game.undo.length > 0)
view.actions.undo = 1
@@ -3895,8 +4033,14 @@ exports.action = function (state, role, action, arg) {
} else {
if (action === "undo" && game.undo && game.undo.length > 0)
pop_undo()
- else if (action === "remove")
- action_remove()
+ else if (action === "remove_pieces")
+ action_remove_pieces()
+ else if (action === "ask_resources")
+ action_ask_resources()
+ else if (action === "ask_shipment")
+ action_ask_shipment()
+ else if (action === "transfer")
+ action_transfer()
else if (game.op && action in special_activities)
special_activities[action](arg)
else