Two-player teams, enforced by the simulation:
- Match puts every player on a team (SimEntity.team); Weapons.damage_player
refuses damage between teammates from every weapon, the boathook and blasts.
- A player whose health runs out with a teammate standing goes down instead of
out: 60 health to bleed (one point every half second), crawling at 1 m/s, no
firing, building, looting or items. Hits still take it; drowning too.
- A standing teammate within 2 m holding interact for 6 s revives them with 30
health. Letting go or moving away starts it over.
- Downed players are out when their health runs out again or when no teammate
is left standing, credited to whoever downed them. A team falls together and
shares its place; the tie-break puts standing ahead of downed.
- Downs and revives go through Match events and the kill feed ("X knocked Y
down"); the HUD says what to do while down.
Wire: FLAG_DOWNED in the player record and the own block (flags now u16),
so prediction crawls too. Protocol version 5.
Bots: never target a teammate, land with their teammate, regroup when they
stray past 30 m, crawl toward a standing teammate when down, go to revive a
downed teammate within 60 m when not in a fight, and turn from a downed target
to its standing teammate when it's in view.
Options: --team-size=2 on the server, --duos offline, and Solo/Duos under
Crew in the Practice menu. The figure has a downed crawl pose.
Tests: test_duos (downing, crawl, revive, interrupted revive, bleed-out,
finishing, team out, falling together, no friendly damage including kegs,
drowning while down, hash, match placement and tie-break), bots as teammates,
the downed flag on the wire, the feed, server and menu options. make
duo-matches plays 10 bot duos matches.
Closes #30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
4.0 KiB
GDScript
100 lines
4.0 KiB
GDScript
## The kill feed and the count of who is standing, on the wire, for the HUD (A9).
|
|
## Snapshots only carry players near the one a client watches, so the client can't
|
|
## count the living or see eliminations across the island by itself; the server tells
|
|
## everyone with a FEED message on the control channel (reliable) whenever someone is
|
|
## placed, and when a match begins.
|
|
##
|
|
## server -> FEED
|
|
## u8 type, u8 standing, u8 players in the match, u8 entry count, then entries:
|
|
## s32 victim handle, s32 eliminator handle (0 = none), u8 cause (CAUSES),
|
|
## u8 item code plus one (0 = none), u8 place, u8 flags (1 = tied, 2 = downed,
|
|
## not out: duos, M7),
|
|
## str victim name, str eliminator name,
|
|
## where str is u8 byte length then that many UTF-8 bytes (at most MAX_NAME_BYTES).
|
|
##
|
|
## The decoder returns an empty Dictionary for anything malformed and never raises.
|
|
class_name NetFeed
|
|
extends RefCounted
|
|
|
|
const MSG_FEED: int = 19
|
|
## How an entry came about, by the Match's cause names.
|
|
const CAUSES: Array[String] = ["none", "weapon", "fall", "drown", "tide", "left"]
|
|
const HEADER_BYTES: int = 4
|
|
const ENTRY_FIXED_BYTES: int = 12
|
|
const MAX_ENTRIES: int = 16
|
|
const MAX_NAME_BYTES: int = 32
|
|
const FLAG_TIED: int = 1
|
|
const FLAG_DOWNED: int = 2
|
|
|
|
|
|
## Encodes the count and `entries`, newest last. Each entry has "victim", "by",
|
|
## "cause" (a name in CAUSES), "item" (-1 none), "place", "tied", "downed", "victim_name"
|
|
## and "by_name". Only the newest MAX_ENTRIES are kept.
|
|
static func encode(standing: int, total: int, entries: Array[Dictionary]) -> PackedByteArray:
|
|
var out: StreamPeerBuffer = StreamPeerBuffer.new()
|
|
out.put_u8(MSG_FEED)
|
|
out.put_u8(clampi(standing, 0, 255))
|
|
out.put_u8(clampi(total, 0, 255))
|
|
var first: int = maxi(0, entries.size() - MAX_ENTRIES)
|
|
out.put_u8(entries.size() - first)
|
|
for index: int in range(first, entries.size()):
|
|
var entry: Dictionary = entries[index]
|
|
out.put_32(int(entry.get("victim", 0)))
|
|
out.put_32(int(entry.get("by", 0)))
|
|
out.put_u8(maxi(0, CAUSES.find(String(entry.get("cause", "none")))))
|
|
out.put_u8(clampi(int(entry.get("item", -1)) + 1, 0, 255))
|
|
out.put_u8(clampi(int(entry.get("place", 0)), 0, 255))
|
|
out.put_u8((FLAG_TIED if bool(entry.get("tied", false)) else 0) | (FLAG_DOWNED if bool(entry.get("downed", false)) else 0))
|
|
_put_name(out, String(entry.get("victim_name", "")))
|
|
_put_name(out, String(entry.get("by_name", "")))
|
|
return out.data_array
|
|
|
|
|
|
## {"standing", "total", "entries": Array[Dictionary]} with the fields encode() takes,
|
|
## or an empty Dictionary.
|
|
static func decode(bytes: PackedByteArray) -> Dictionary:
|
|
if bytes.size() < HEADER_BYTES or bytes[0] != MSG_FEED:
|
|
return {}
|
|
var count: int = bytes[3]
|
|
if count > MAX_ENTRIES:
|
|
return {}
|
|
var entries: Array[Dictionary] = []
|
|
var at: int = HEADER_BYTES
|
|
for _index: int in count:
|
|
if at + ENTRY_FIXED_BYTES > bytes.size():
|
|
return {}
|
|
var cause: int = bytes[at + 8]
|
|
if cause >= CAUSES.size():
|
|
return {}
|
|
var entry: Dictionary = {
|
|
"victim": bytes.decode_s32(at), "by": bytes.decode_s32(at + 4), "cause": CAUSES[cause],
|
|
"item": int(bytes[at + 9]) - 1, "place": int(bytes[at + 10]), "tied": bytes[at + 11] & FLAG_TIED != 0,
|
|
"downed": bytes[at + 11] & FLAG_DOWNED != 0,
|
|
}
|
|
at += ENTRY_FIXED_BYTES
|
|
var names: Array[String] = []
|
|
for _name: int in 2:
|
|
if at >= bytes.size():
|
|
return {}
|
|
var length: int = bytes[at]
|
|
if length > MAX_NAME_BYTES or at + 1 + length > bytes.size():
|
|
return {}
|
|
names.append(bytes.slice(at + 1, at + 1 + length).get_string_from_utf8())
|
|
at += 1 + length
|
|
entry["victim_name"] = names[0]
|
|
entry["by_name"] = names[1]
|
|
entries.append(entry)
|
|
if at != bytes.size():
|
|
return {}
|
|
return {"standing": int(bytes[1]), "total": int(bytes[2]), "entries": entries}
|
|
|
|
|
|
static func _put_name(out: StreamPeerBuffer, text: String) -> void:
|
|
var raw: PackedByteArray = text.to_utf8_buffer()
|
|
# Cut on a character boundary, never inside one.
|
|
while raw.size() > MAX_NAME_BYTES:
|
|
text = text.substr(0, text.length() - 1)
|
|
raw = text.to_utf8_buffer()
|
|
out.put_u8(raw.size())
|
|
out.put_data(raw)
|