class_name Describe ## Readable labels for actions, for people choosing them (describe.ts): the move list and prompts. ## Labels are written for the deciding player: "your" things are unmarked, the opponent's say whose ## they are. Nothing here names a card the decider can't see. ## Default for the `me` arguments: label for whoever decides now. Pass null for no viewer. const DECIDER := -1 const STEP_NAMES := {"deploy": "Deploy", "play": "Play", "attack": "Attack", "resolve": "Resolve", "playAgain": "Play again"} static var _paren_re := RegEx.create_from_string(" \\((.*)\\)$") ## "A2–B1" for a line id like "A2-B1". static func line_name(line: String) -> String: var l = GameMap.LINE_BY_ID.get(line) return "%s–%s" % [l.a, l.b] if l != null else line static func _me(s: Dictionary, me: Variant) -> Variant: return RulesEngine.decider(s) if me is int and me == DECIDER else me ## "Anomaly 2 (Glitch)", or "the copy of Anomaly 2 (Glitch)"; the opponent's say "North's". static func ref_name(s: Dictionary, r: Dictionary, me: Variant = DECIDER) -> String: me = _me(s, me) var n: int = State.original_of(r).slot var card: int = State.anomaly(s, r).card var nm := "face down" if card < 0 or not State.anomaly(s, State.original_of(r)).faceUp else State.name_of(s, card) var whose := "%s's " % State.player_name(r.player) if me != null and r.player != me else "" return ("%scopy of Anomaly %d (%s)" if r.slot > 4 else "%sAnomaly %d (%s)") % [whose, n, nm] ## Where a card is, for telling two same-named cards apart: " on C2", " on Anomaly 1 (Glitch)", ## " from hand". static func _card_where(s: Dictionary, id: int, me: Variant) -> String: var loc = State.program_location(s, id) if loc != null: return " on %s" % loc var r = State.wearer_of(s, id) if r != null: return " on %s" % ref_name(s, r, me) var pl: Dictionary = s.players[s.cards[id].owner] if pl.hand.has(id): return " from hand" if pl.discard.has(id): return " from the discard pile" return "" static func _card_name(s: Dictionary, id: int, me: Variant) -> String: if id < 0: return State.name_of(s, id) var owner: int = s.cards[id].owner var whose := "%s's " % State.player_name(owner) if me != null and owner != me else "" return "%s%s%s" % [whose, State.name_of(s, id), _card_where(s, id, me)] ## Execution and Ability arguments: "Anomaly 2 (Glitch) → C1", "destroy Overclocked CPU on …". static func describe_args(s: Dictionary, a: Dictionary, me: Variant = DECIDER, to_word := "at") -> String: me = _me(s, me) var parts := [] if a.get("heal", false): parts.append("heal this Anomaly") if a.get("ref") != null: parts.append(ref_name(s, a.ref, me)) if a.get("card") != null: var nm := _card_name(s, a.card, me) if a.get("mode"): parts.append("%s %s" % [a.mode, nm]) elif a.get("cards") != null: parts.append("swap out %s" % nm) else: parts.append(nm) if a.get("cards") != null and not a.cards.is_empty(): var names := ", ".join(a.cards.map(func(id): return _card_name(s, id, me))) parts.append("%s%s" % ["for " if a.get("card") != null else "", names]) if a.get("to"): parts.append("→ %s" % a.to if a.get("ref") != null else "%s %s" % [to_word, a.to]) if a.get("k") != null: parts.append("reroll dice showing %d or less" % a.k) return " ".join(parts) static func _gb(n: int) -> String: return " (%d Gb)" % n ## A label for one of the current legal actions, e.g. "Play Execute: Force Reboot on D2 (5 Gb)". static func describe_action(s: Dictionary, a: Dictionary) -> String: var me = RulesEngine.decider(s) if me == null: me = s.active var cost := RulesEngine.action_cost(s, a) match a.type: "end": if s.step == "playAgain": return "End command" if s.rules.commands.on else "End turn" if s.step == "attack": return "End Attack step and resolve" return "End %s step" % STEP_NAMES[s.step] "pass": return "Pass" "choose": var o = s.choice.options[a.index] if s.choice != null and a.index < s.choice.options.size() else null var label: String = o.label if o != null else "Option %d" % (a.index + 1) return label + (_gb(o.cost) if o != null and o.get("cost", 0) else "") "place": var r := State.ref(me, a.slot) var av := State.anomaly(s, r) if av.at == null: return "Place %s on %s" % [ref_name(s, r, me), a.to] return "Move %s %s → %s" % [ref_name(s, r, me), av.at, a.to] "recall": var r := State.ref(me, a.slot) var hurt := Query.health_of(s, r) - Query.health_left(s, r) if s.rules.health.on else 0 return "Recall %s from %s%s" % [ref_name(s, r, me), State.anomaly(s, r).at, ", healing %d" % hurt if hurt else ""] "advance": var r := State.ref(me, a.slot) return "Advance %s %s → %s" % [ref_name(s, r, me), State.anomaly(s, r).at, a.to] "attack": var r := State.ref(me, a.slot) return "Attack %s with %s from %s" % [a.to, ref_name(s, r, me), State.anomaly(s, r).at] "clearFirewall": return "Clear the Lv %d Firewall on %s%s" % [s.firewalls[a.line], line_name(a.line), _gb(cost)] "firewall": if s.firewalls.get(a.line, 0): return "Upgrade the Firewall on %s to Lv %d%s" % [line_name(a.line), a.level, _gb(cost)] return "Place a Lv %d Firewall on %s%s" % [a.level, line_name(a.line), _gb(cost)] "salvage": return "Salvage %s (+%d Gb)" % [State.name_of(s, a.card), State.def_of(s, a.card).bandwidth] "installHardware": return "Install %s on %s%s" % [State.name_of(s, a.card), ref_name(s, State.ref(me, a.slot), me), _gb(cost)] "recruit": var old := State.anomaly(s, State.ref(me, a.slot)) var retiring := ", retiring %s" % State.name_of(s, old.card) if old.card >= 0 else "" return "Recruit %s as Anomaly %d%s%s" % [State.name_of(s, a.card), a.slot, retiring, _gb(cost)] "buyAnomaly": var sale = RulesEngine.anomaly_for_sale(s, me) return "Buy Anomaly %d (face down)%s" % [a.slot, _gb(sale.price if sale != null else cost)] "installProgram": return "Install %s on %s%s" % [State.name_of(s, a.card), a.at, _gb(cost)] "play": # Packet Flood and Purge name the location they hit; it's the target unless Ghost Process widens it. var args_text := "" if a.args.get("to") == a.target and a.args.get("ref") == null: var shown: Dictionary = a.args.duplicate() shown.erase("to") args_text = describe_args(s, shown, me) else: args_text = describe_args(s, a.args, me) var on := " on %s" % a.target if a.target else "" var from := ", performed by %s" % a.from if a.from else "" return "Play %s%s%s%s%s" % [State.name_of(s, a.card), on, ": %s" % args_text if args_text else "", from, _gb(cost)] "activate": var src = RulesEngine.ability_source(s, a.card, a.name) var d := State.def_of(s, a.card) var label := "" if src != null and src.kind == "anomaly" and src.get("ref") != null: var ability_name: String = d.ability.name if d.has("ability") else a.name label = "%s (%s)" % [ability_name, _paren_re.sub(ref_name(s, src.ref, me), ", $1")] elif a.name != d.name: label = "%s (copied by %s)" % [a.name, d.name] else: label = a.name var where := "" if src != null and src.kind == "hardware" and src.get("ref") != null: where = " on %s" % ref_name(s, src.ref, me) elif src != null and src.kind != "anomaly" and src.at: where = " on %s" % src.at var args_text := describe_args(s, a.args, me, "→") var joined := "" if args_text: joined = (" " if args_text.begins_with("→") else ": ") + args_text return "Use %s%s%s%s" % [label, where, joined, _gb(cost) if cost else ""] return Util.fail("Unknown action type %s" % a.type)