updates
This commit is contained in:
parent
0cba7f5ee0
commit
32ed347b58
172 changed files with 5464 additions and 582 deletions
112
engine/state.gd
112
engine/state.gd
|
|
@ -65,6 +65,58 @@ static func say(s: Dictionary, msg: String, meta := {}) -> void:
|
|||
s.log.append(line)
|
||||
|
||||
|
||||
## Records what just happened for the table to act out (godot-plan.md §3): `ev` is {k: kind, ...}.
|
||||
## Only a game made with `events` keeps them; TS has no events, so they stay out of conformance.
|
||||
static func emit(s: Dictionary, ev: Dictionary) -> void:
|
||||
var events = s.get("events")
|
||||
if events != null:
|
||||
events.append(ev)
|
||||
|
||||
|
||||
## Whether this game records events, to skip building ones nobody keeps.
|
||||
static func has_events(s: Dictionary) -> bool:
|
||||
return s.get("events") != null
|
||||
|
||||
|
||||
## Events from index `from` as `viewer` may see them: copies, with cards they can't see as -1 (the
|
||||
## other player's draws, and cards the other player takes into hand from a hidden pile).
|
||||
static func events_for(s: Dictionary, viewer: int, from := 0) -> Array:
|
||||
var out := []
|
||||
var events = s.get("events")
|
||||
if events == null:
|
||||
return out
|
||||
for i in range(maxi(0, from), events.size()):
|
||||
var ev: Dictionary = events[i].duplicate(true)
|
||||
var theirs: bool = ev.get("p", viewer) != viewer
|
||||
if theirs and (ev.k == "drew" or (ev.k == "hand" and ev.get("from") in ["deck", "serverPile", ""])):
|
||||
ev.card = -1
|
||||
elif theirs and ev.k == "pile" and ev.get("from") == "hand":
|
||||
ev.card = -1
|
||||
out.append(ev)
|
||||
return out
|
||||
|
||||
|
||||
## Folded Bandwidth events must equal the Bandwidth: when a change slipped past the helpers, one more
|
||||
## event makes up the difference. `before` is each player's Bandwidth at event `from`. Counted in
|
||||
## event_fixes, which tests expect to stay 0.
|
||||
static var event_fixes := 0
|
||||
|
||||
|
||||
static func reconcile_bandwidth(s: Dictionary, before: Array, from: int) -> void:
|
||||
var events = s.get("events")
|
||||
if events == null:
|
||||
return
|
||||
var have := before.duplicate()
|
||||
for i in range(from, events.size()):
|
||||
var ev: Dictionary = events[i]
|
||||
if ev.k == "bandwidth":
|
||||
have[ev.p] = ev.to
|
||||
for p in 2:
|
||||
if have[p] != s.players[p].bandwidth:
|
||||
event_fixes += 1
|
||||
emit(s, {"k": "bandwidth", "p": p, "from": have[p], "to": s.players[p].bandwidth})
|
||||
|
||||
|
||||
## The play-by-play as `viewer` may read it, or every line in full for null.
|
||||
static func log_for(s: Dictionary, viewer: Variant) -> Array:
|
||||
var out := []
|
||||
|
|
@ -374,14 +426,60 @@ static func reset_card(s: Dictionary, id: int) -> void:
|
|||
c.erase("pushedUntil")
|
||||
|
||||
|
||||
static func to_discard(s: Dictionary, id: int) -> void:
|
||||
## `from` and `why` only describe the move for events: from "hand", "play" (a location's Server or
|
||||
## Program), "worn" (Hardware), "stack", "slot" or "deck"; why "salvage", "played", "destroyed",
|
||||
## "captured", "discarded", ….
|
||||
static func to_discard(s: Dictionary, id: int, from := "", why := "") -> void:
|
||||
reset_card(s, id)
|
||||
s.players[owner_of(s, id)].discard.append(id)
|
||||
if has_events(s):
|
||||
emit(s, {"k": "discard", "p": owner_of(s, id), "card": id, "from": from, "why": why})
|
||||
|
||||
|
||||
static func to_hand(s: Dictionary, id: int) -> void:
|
||||
static func to_hand(s: Dictionary, id: int, from := "") -> void:
|
||||
reset_card(s, id)
|
||||
s.players[owner_of(s, id)].hand.append(id)
|
||||
if has_events(s):
|
||||
emit(s, {"k": "hand", "p": owner_of(s, id), "card": id, "from": from})
|
||||
|
||||
|
||||
## A Server, Program or Hardware card arriving on a location ("loc:C2") or an Anomaly
|
||||
## ("anomaly:0:1"), for events.
|
||||
static func emit_install(s: Dictionary, id: int, at: String) -> void:
|
||||
if has_events(s):
|
||||
emit(s, {"k": "install", "p": owner_of(s, id), "card": id, "at": at})
|
||||
|
||||
|
||||
## A card going into its owner's deck or Server pile ("deck", "serverPile"), for events.
|
||||
static func emit_pile(s: Dictionary, id: int, zone: String, from: String) -> void:
|
||||
if has_events(s):
|
||||
emit(s, {"k": "pile", "p": owner_of(s, id), "card": id, "zone": zone, "from": from})
|
||||
|
||||
|
||||
static func emit_moved(s: Dictionary, r: Dictionary, from: Variant, to: Variant) -> void:
|
||||
if not has_events(s) or from == to:
|
||||
return
|
||||
if from == null:
|
||||
emit(s, {"k": "placed", "ref": r.duplicate(), "loc": to})
|
||||
elif to == null:
|
||||
emit(s, {"k": "recalled", "ref": r.duplicate(), "from": from})
|
||||
else:
|
||||
emit(s, {"k": "moved", "ref": r.duplicate(), "from": from, "to": to})
|
||||
|
||||
|
||||
## The counters an Anomaly shows, for "counter" events: take them before a change and pass them to
|
||||
## emit_counters after it.
|
||||
static func counters_of(av: Dictionary) -> Dictionary:
|
||||
return {"infection": infection_of(av), "bugs": av.bugs, "damage": av.damage}
|
||||
|
||||
|
||||
static func emit_counters(s: Dictionary, r: Dictionary, before: Dictionary) -> void:
|
||||
if not has_events(s):
|
||||
return
|
||||
var now := counters_of(anomaly(s, r))
|
||||
for what in now:
|
||||
if now[what] != before[what]:
|
||||
emit(s, {"k": "counter", "ref": r.duplicate(), "what": what, "from": before[what], "to": now[what]})
|
||||
|
||||
|
||||
static func remove_from(list: Array, id: int) -> bool:
|
||||
|
|
@ -417,10 +515,18 @@ static func program_location(s: Dictionary, id: int) -> Variant:
|
|||
static func gain_bandwidth(s: Dictionary, p: int, n: int, key := "bandwidthFromEffects") -> void:
|
||||
if n <= 0:
|
||||
return
|
||||
s.players[p].bandwidth += n
|
||||
add_bandwidth(s, p, n)
|
||||
stat(s, key, p, n)
|
||||
|
||||
|
||||
## Changes a player's Bandwidth by `n` (negative to spend), with its event. No stats.
|
||||
static func add_bandwidth(s: Dictionary, p: int, n: int) -> void:
|
||||
var before: int = s.players[p].bandwidth
|
||||
s.players[p].bandwidth = before + n
|
||||
if n != 0 and has_events(s):
|
||||
emit(s, {"k": "bandwidth", "p": p, "from": before, "to": before + n})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
# Tasks and choices
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue