M7: Duos and revive
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>
This commit is contained in:
+25
-4
@@ -18,11 +18,19 @@ static func tick_limit() -> int:
|
||||
## count from the barge leaving. Each group (M6) adds up its bots' BotBrain.stats and
|
||||
## holds their "bots", "places" and "wins".
|
||||
##
|
||||
## With `team_size` 2 the match is duos (M7), and the result also has "downs",
|
||||
## "revives", "team_hits" (hits that did damage between teammates, which must be 0) and
|
||||
## "winner_teams" (how many teams the winners came from, which must be 1).
|
||||
##
|
||||
## With `split_builders`, only every other bot gathers and builds; the rest are the
|
||||
## control group. Bot difficulty also goes by turns of three, so both groups have each
|
||||
## level equally (within one bot).
|
||||
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1, split_builders: bool = false) -> Dictionary:
|
||||
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, null, difficulty)
|
||||
static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficulty: int = -1, split_builders: bool = false, team_size: int = 1) -> Dictionary:
|
||||
var rules: MatchRules = null
|
||||
if team_size > 1:
|
||||
rules = ServerLoop.immediate_rules(0, bots)
|
||||
rules.team_size = team_size
|
||||
var loop: ServerLoop = ServerLoop.new(seed_value, 0, bots, rules, difficulty)
|
||||
var flow: Match = loop.match_flow
|
||||
var level_of: Dictionary = {}
|
||||
for bot: BotBrain in loop.bots:
|
||||
@@ -31,6 +39,7 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
|
||||
"seed": seed_value, "finished": false, "winner": 0, "winner_difficulty": "",
|
||||
"timed_out": false, "causes": {}, "places": {}, "eliminations": {}, "shots": 0,
|
||||
"slow_ticks": [], "weapon_kills": {}, "death_seconds": [],
|
||||
"downs": 0, "revives": 0, "team_hits": 0, "winner_teams": 0,
|
||||
}
|
||||
var limit: int = tick_limit()
|
||||
var split: bool = false
|
||||
@@ -45,13 +54,25 @@ static func run_match(seed_value: int, bots: int = Tuning.SOLO_PLAYERS, difficul
|
||||
if Time.get_ticks_usec() - before > ServerLoop.TICK_BUDGET_USEC:
|
||||
result["slow_ticks"].append(loop.sim.tick)
|
||||
for event: Dictionary in loop.sim.events:
|
||||
if event["type"] == "shot":
|
||||
result["shots"] += 1
|
||||
match String(event["type"]):
|
||||
"shot":
|
||||
result["shots"] += 1
|
||||
"downed":
|
||||
result["downs"] += 1
|
||||
"revived":
|
||||
result["revives"] += 1
|
||||
"player_hit":
|
||||
if int(event["armor"]) + int(event["health"]) > 0 and loop.sim.are_teammates(loop.sim.entities.find(int(event["victim"])), loop.sim.entities.find(int(event["player"]))):
|
||||
result["team_hits"] += 1
|
||||
for event: Dictionary in flow.events:
|
||||
if event["type"] == "match_ended":
|
||||
result["timed_out"] = event["timed_out"]
|
||||
result["ticks"] = loop.sim.tick
|
||||
result["finished"] = flow.phase == Match.RESULTS
|
||||
var winner_teams: Dictionary = {}
|
||||
for handle: int in flow.winners:
|
||||
winner_teams[flow.team_of[handle]] = true
|
||||
result["winner_teams"] = winner_teams.size()
|
||||
if flow.winners.size() > 0:
|
||||
result["winner"] = flow.winners[0]
|
||||
result["winner_difficulty"] = level_of.get(flow.winners[0], "")
|
||||
|
||||
@@ -446,3 +446,66 @@ func test_a_bot_with_nothing_to_do_holds_its_ground() -> void:
|
||||
_run(roundi(Tuning.BOT_HOLD_SECONDS * 0.8) * TICKS)
|
||||
assert_true(me.position.distance_to(at) < 3.0, "and stays put while holding (moved %.1f m)" % me.position.distance_to(at))
|
||||
assert_true(at.distance_to(HOME) <= Tuning.BOT_ROAM_METRES + 5.0, "it didn't roam far (%.1f m)" % at.distance_to(HOME))
|
||||
|
||||
|
||||
# Duos (M7): bots as teammates.
|
||||
|
||||
func test_bots_never_target_or_shoot_a_teammate() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME, BotBrain.HARD)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
var mate: SimEntity = _player(HOME + Vector3(8.0, 0.0, 0.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
_pin(brain)
|
||||
_run(3 * TICKS)
|
||||
assert_eq(brain.target_id, 0, "a teammate in plain view isn't a target")
|
||||
assert_eq(int(shots_by.get(me.id, 0)), 0)
|
||||
assert_eq(mate.health, Tuning.PLAYER_MAX_HEALTH)
|
||||
|
||||
|
||||
func test_a_bot_goes_to_a_downed_teammate_and_revives_them() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
_arm(me)
|
||||
var mate: SimEntity = _player(HOME + Vector3(12.0, 0.0, 6.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
mate.health = 0
|
||||
_run(1)
|
||||
assert_true(mate.downed)
|
||||
var revived: Array[bool] = [false]
|
||||
var states: Dictionary = {}
|
||||
_run(20 * TICKS, func() -> bool:
|
||||
states[brain.state] = true
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == "revived" and event["by"] == me.id:
|
||||
revived[0] = true
|
||||
return revived[0])
|
||||
assert_true(states.has("revive"), "states: %s" % [states.keys()])
|
||||
assert_true(revived[0], "revived within 20 s (mate downed: %s, %.1f m apart)" % [mate.downed, me.position.distance_to(mate.position)])
|
||||
assert_false(mate.downed)
|
||||
assert_true(Simulation.is_standing(mate))
|
||||
|
||||
|
||||
func test_a_downed_bot_crawls_toward_its_standing_teammate() -> void:
|
||||
_setup()
|
||||
var brain: BotBrain = _bot(HOME)
|
||||
var me: SimEntity = sim.entities.find(brain.player_id)
|
||||
var mate: SimEntity = _player(HOME + Vector3(10.0, 0.0, 0.0))
|
||||
sim.set_team(me.id, 0)
|
||||
sim.set_team(mate.id, 0)
|
||||
_ready_world()
|
||||
me.health = 0
|
||||
_run(1)
|
||||
assert_true(me.downed)
|
||||
var before: float = me.position.distance_to(mate.position)
|
||||
_run(3 * TICKS)
|
||||
assert_eq(brain.state, "downed")
|
||||
var after: float = me.position.distance_to(mate.position)
|
||||
assert_near(before - after, 3.0 * Tuning.DOWNED_CRAWL_SPEED, 0.5, "crawled toward the teammate")
|
||||
assert_eq(int(shots_by.get(me.id, 0)), 0)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureClient" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
stage = "hud_downed"
|
||||
@@ -12,7 +12,9 @@
|
||||
## hud and hud_build (issue A9): once landed, the server hands the player a carbine, a
|
||||
## fowling piece and bandages, wounds them a little and takes three bots out in
|
||||
## different ways, so every part of the HUD has something to show; hud_build then goes
|
||||
## into build mode. Every stage draws the HUD as the client's HudState has it.
|
||||
## into build mode. hud_downed (issue M7) plays duos, with the first bot as the player's
|
||||
## crewmate, and after the hud staging a bot's shot downs the player. Every stage draws
|
||||
## the HUD as the client's HudState has it.
|
||||
extends Node3D
|
||||
|
||||
const DT: float = 1.0 / Tuning.TICK_RATE_HZ
|
||||
@@ -34,6 +36,8 @@ func _ready() -> void:
|
||||
rules.max_players = bots + 1
|
||||
rules.lobby_ticks = 6
|
||||
rules.countdown_ticks = 6
|
||||
if stage == "hud_downed":
|
||||
rules.team_size = Tuning.DUO_TEAM_SIZE
|
||||
_loop = ServerLoop.new(match_seed, 0, bots, rules)
|
||||
_net = NetServer.new()
|
||||
if _net.listen(0, HOST) != OK:
|
||||
@@ -68,7 +72,7 @@ func _ready() -> void:
|
||||
reached = me.drop_state == Drop.ABOARD and _session.game.prediction.next_tick > 3 * Tuning.TICK_RATE_HZ
|
||||
"glide":
|
||||
reached = me.drop_state == Drop.GLIDING
|
||||
"landed", "basin", "build", "build_refused", "hud", "hud_build":
|
||||
"landed", "basin", "build", "build_refused", "hud", "hud_build", "hud_downed":
|
||||
reached = me.drop_state == Drop.NONE
|
||||
if reached and since < 0:
|
||||
since = 0
|
||||
@@ -94,6 +98,11 @@ func _ready() -> void:
|
||||
return
|
||||
if stage == "hud_build" and _build_mode(true).is_empty():
|
||||
return
|
||||
if stage == "hud_downed":
|
||||
var downed_text: String = _down_player()
|
||||
if downed_text.is_empty():
|
||||
return
|
||||
basin_text += downed_text
|
||||
_session.hud.fade_feed = false
|
||||
_session.hud.show_state(_session.hud_state())
|
||||
_session.view.settle()
|
||||
@@ -139,7 +148,7 @@ func _stage_hud() -> String:
|
||||
var taken: int = 0
|
||||
for bot: int in flow.bot_handles.keys():
|
||||
var player: SimEntity = sim.entities.find(int(flow.entity_of.get(bot, 0)))
|
||||
if player == null or player.eliminated:
|
||||
if player == null or player.eliminated or sim.are_teammates(mine, player):
|
||||
continue
|
||||
player.health = 0
|
||||
player.last_cause = causes[taken]
|
||||
@@ -164,6 +173,35 @@ func _stage_hud() -> String:
|
||||
return " · %d of %d standing, %d feed lines" % [hud.standing, hud.total, hud.feed.size()]
|
||||
|
||||
|
||||
## Duos: a bot's shot takes the player's last health with their crewmate still up, so
|
||||
## they go down. Returns a caption line, or "" after reporting an error.
|
||||
func _down_player() -> String:
|
||||
var flow: Match = _loop.match_flow
|
||||
var sim: Simulation = _loop.sim
|
||||
var mine: SimEntity = sim.entities.find(int(flow.entity_of.get(_session.link.handle, 0)))
|
||||
var foe: SimEntity = null
|
||||
for bot: int in flow.bot_handles.keys():
|
||||
var player: SimEntity = sim.entities.find(int(flow.entity_of.get(bot, 0)))
|
||||
if player != null and not player.eliminated and not sim.are_teammates(mine, player):
|
||||
foe = player
|
||||
break
|
||||
if mine == null or foe == null or not sim.has_standing_teammate(mine):
|
||||
push_error("client capture: no foe, or no crewmate standing, to down the player")
|
||||
return ""
|
||||
mine.armor = 0
|
||||
Weapons.damage_player(sim, mine, mine.health, foe.id, false, ItemCatalog.code_of("dock_carbine"))
|
||||
for _round: int in Tuning.TICK_RATE_HZ:
|
||||
_game.poll()
|
||||
_loop.run_tick()
|
||||
_game.after_tick()
|
||||
_session.pump(DT)
|
||||
var hud: HudState = _session.hud_state()
|
||||
if not mine.downed or not hud.downed:
|
||||
push_error("client capture: the player isn't down (server %s, HUD %s)" % [mine.downed, hud.downed])
|
||||
return ""
|
||||
return " · downed, %d health to bleed" % mine.health
|
||||
|
||||
|
||||
## Stops the autoplay where the player stands and goes into build mode for a driftwood
|
||||
## wall, after the server has given the player plenty of materials or taken them all.
|
||||
## Returns a caption line, or "" after reporting an error.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## animation, seen from in front and to their right:
|
||||
##
|
||||
## - states: idle, walk, run, crouched, creeping, in the air, skydiving, gliding,
|
||||
## swimming. (Aboard the barge is the idle with the feet set wider; the deck
|
||||
## swimming, downed (M7). (Aboard the barge is the idle with the feet set wider; the deck
|
||||
## placement would pull it out of the row.)
|
||||
## - actions: carrying a longgun, a revolver and a tonic, firing each kind, a boathook
|
||||
## swing, a keg thrown, building, reloading, drinking and a flinch.
|
||||
@@ -24,6 +24,7 @@ const STATES: Array = [
|
||||
["skydive", "", "skydive", 0.8, ""],
|
||||
["glide", "", "glide", 0.8, ""],
|
||||
["swim", "", "swim", 0.35, ""],
|
||||
["downed", "", "downed", 0.5, ""],
|
||||
]
|
||||
const ACTIONS: Array = [
|
||||
["long", "whalers_longgun", "ground", 0.6, ""],
|
||||
@@ -114,6 +115,10 @@ func _stand(at: Vector3, row: Array) -> SimEntity:
|
||||
"swim":
|
||||
player.swimming = true
|
||||
player.on_ground = false
|
||||
"downed":
|
||||
player.downed = true
|
||||
player.crouching = true
|
||||
player.health = Tuning.DOWNED_HEALTH
|
||||
"aboard":
|
||||
player.drop_state = Drop.ABOARD
|
||||
player.on_ground = false
|
||||
|
||||
@@ -87,7 +87,11 @@ func test_states_follow_the_replicated_flags() -> void:
|
||||
player.crouching = true
|
||||
assert_eq(FigureRig.state_of(player, false), "crouch")
|
||||
assert_eq(FigureRig.state_of(player, true), "air")
|
||||
player.downed = true
|
||||
assert_eq(FigureRig.state_of(player, true), "downed", "M7: down on hands and knees")
|
||||
player.swimming = true
|
||||
assert_eq(FigureRig.state_of(player, true), "swim", "a downed swimmer still swims")
|
||||
player.downed = false
|
||||
assert_eq(FigureRig.state_of(player, true), "swim")
|
||||
for drop: Array in [[Drop.ABOARD, "aboard"], [Drop.FREEFALL, "skydive"], [Drop.GLIDING, "glide"]]:
|
||||
player.drop_state = drop[0]
|
||||
|
||||
@@ -201,3 +201,16 @@ func _texts(node: Node) -> Array[String]:
|
||||
for child: Node in node.get_children():
|
||||
found.append_array(_texts(child))
|
||||
return found
|
||||
|
||||
|
||||
func test_a_down_in_duos_travels_in_the_feed_and_reads_as_a_down() -> void:
|
||||
var entries: Array[Dictionary] = [
|
||||
{"victim": -3, "by": 1, "cause": "weapon", "item": -1, "place": 0, "tied": false, "downed": true, "victim_name": "Thole", "by_name": "Ada"},
|
||||
{"victim": -4, "by": 0, "cause": "fall", "item": -1, "place": 0, "tied": false, "downed": true, "victim_name": "Brine", "by_name": ""},
|
||||
]
|
||||
var told: Dictionary = NetFeed.decode(NetFeed.encode(3, 24, entries))
|
||||
assert_true(told["entries"][0]["downed"])
|
||||
var lines: Array[Dictionary] = HudState.feed_lines(told["entries"], 1)
|
||||
assert_eq(lines[0]["text"], "You knocked Thole down")
|
||||
assert_eq(lines[1]["text"], "Brine is down")
|
||||
assert_eq(HudState.feed_lines(told["entries"], -3)[0]["text"], "Ada knocked you down")
|
||||
|
||||
@@ -165,6 +165,7 @@ func test_the_own_block_round_trips_exactly() -> void:
|
||||
assert_eq(copy.stamina_ticks, 1234)
|
||||
assert_true(copy.swimming and not copy.on_ground)
|
||||
assert_eq(copy.drop_state, Drop.GLIDING)
|
||||
assert_false(copy.downed)
|
||||
assert_eq(back["self"]["water"], own["water"])
|
||||
assert_eq(back["self"]["water_mask"], 0b101010101)
|
||||
for length: int in bytes.size():
|
||||
@@ -176,3 +177,25 @@ func test_the_own_block_round_trips_exactly() -> void:
|
||||
assert_true(NetSnapshot.decode_snapshot(poisoned).is_empty(), "a NaN position")
|
||||
poisoned.encode_float(at, INF)
|
||||
assert_true(NetSnapshot.decode_snapshot(poisoned).is_empty(), "an infinite position")
|
||||
|
||||
|
||||
func test_downed_travels_in_the_record_and_the_own_block() -> void:
|
||||
var sim: Simulation = Simulation.new(3, SimGround.flat())
|
||||
var player: SimEntity = _player(sim, Vector3(100.0, 0.0, 100.0))
|
||||
player.downed = true
|
||||
player.crouching = true
|
||||
player.reload_ticks = 3
|
||||
var record: PackedInt32Array = NetSnapshot.record_of(player)
|
||||
assert_true(record[NetSnapshot.R_FLAGS] & NetSnapshot.FLAG_DOWNED != 0)
|
||||
var own: Dictionary = NetSnapshot.self_of(player, 0.0, 0)
|
||||
var bytes: PackedByteArray = NetSnapshot.encode_snapshot({"tick": 2, "sim_tick": 2, "own_id": player.id, "self": own}, PackedInt32Array(), [[player.id, NetSnapshot.full_mask(SimEntity.ARCHETYPE_PLAYER), record]])
|
||||
var back: Dictionary = NetSnapshot.decode_snapshot(bytes)
|
||||
assert_false(back.is_empty())
|
||||
var merged: PackedInt32Array = NetSnapshot.merge_record(PackedInt32Array(), SimEntity.ARCHETYPE_PLAYER, back["records"][0][2], back["records"][0][3])
|
||||
assert_eq(merged, record)
|
||||
var flags: int = merged[NetSnapshot.R_FLAGS]
|
||||
assert_true(flags & NetSnapshot.FLAG_DOWNED != 0, "in the record")
|
||||
assert_true(flags & NetSnapshot.FLAG_RELOADING != 0, "the low byte is still there")
|
||||
var copy: SimEntity = SimEntity.new(1, SimEntity.ARCHETYPE_PLAYER)
|
||||
NetSnapshot.apply_self(copy, back["self"])
|
||||
assert_true(copy.downed, "in the own block, so prediction crawls too")
|
||||
|
||||
@@ -153,3 +153,13 @@ func test_health_and_stop_options() -> void:
|
||||
assert_eq([config.health_port, config.health_bind, config.stop_file], [8080, "0.0.0.0", "/tmp/x"])
|
||||
assert_false(_parse(["--server", "--health-bind=localhost"]).is_valid())
|
||||
assert_false(_parse(["--server", "--health-port=70000"]).is_valid())
|
||||
|
||||
|
||||
func test_team_size_picks_solo_or_duos() -> void:
|
||||
assert_eq(_parse(["--server"]).team_size, 1, "solo by default")
|
||||
var duos: ServerConfig = _parse(["--server", "--team-size=2", "--bots=23", "--players=1"])
|
||||
assert_true(duos.is_valid(), str(duos.errors))
|
||||
assert_eq(duos.team_size, Tuning.DUO_TEAM_SIZE)
|
||||
assert_eq(duos.to_dictionary()["team_size"], 2)
|
||||
for bad: String in ["--team-size=0", "--team-size=3", "--team-size=two"]:
|
||||
assert_false(_parse(["--server", bad]).is_valid(), bad)
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
extends TestCase
|
||||
|
||||
## Duos from issue M7: going down instead of out while a teammate stands, crawling,
|
||||
## revives, bleeding out, a team eliminated when both are out, no friendly damage, and
|
||||
## team placement in a match.
|
||||
|
||||
const FEET: Vector3 = Vector3(100.0, 0.0, 100.0)
|
||||
const REVIVE_TICKS: int = roundi(Tuning.REVIVE_SECONDS * Tuning.TICK_RATE_HZ)
|
||||
|
||||
|
||||
## A flat world with four players in a row 1 m apart, facing +z: 1 and 2 on team 0,
|
||||
## 3 and 4 on team 1.
|
||||
func _sim() -> Simulation:
|
||||
var sim: Simulation = Simulation.new(77, SimGround.flat())
|
||||
for index: int in 4:
|
||||
var player: SimEntity = sim.entities.find(sim.add_player())
|
||||
player.position = FEET + Vector3(index * 1.0, 0.0, 0.0)
|
||||
player.on_ground = true
|
||||
sim.set_team(player.id, index / 2)
|
||||
return sim
|
||||
|
||||
|
||||
func _p(sim: Simulation, id: int) -> SimEntity:
|
||||
return sim.entities.find(id)
|
||||
|
||||
|
||||
## Steps once, with `buttons` and `move` for the players in `held`, and nothing else.
|
||||
func _step(sim: Simulation, held: Dictionary = {}, move: Vector2 = Vector2.ZERO) -> void:
|
||||
for id: int in [1, 2, 3, 4]:
|
||||
if not sim.entities.contains(id):
|
||||
continue
|
||||
var buttons: int = int(held.get(id, 0))
|
||||
var player: SimEntity = _p(sim, id)
|
||||
sim.submit_command(id, PlayerCommand.from_input(sim.tick, move if held.has(id) else Vector2.ZERO, 0.0, 0.0, buttons, player.selected))
|
||||
sim.step()
|
||||
|
||||
|
||||
func _events(sim: Simulation, kind: String) -> Array[Dictionary]:
|
||||
var found: Array[Dictionary] = []
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == kind:
|
||||
found.append(event)
|
||||
return found
|
||||
|
||||
|
||||
## Lands a lethal hit on `victim` from `attacker`, then steps.
|
||||
func _knock(sim: Simulation, victim: int, attacker: int) -> void:
|
||||
_p(sim, victim).health = 5
|
||||
_p(sim, victim).armor = 0
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, victim), 50, attacker), 5)
|
||||
_step(sim)
|
||||
|
||||
|
||||
func test_a_lethal_hit_downs_a_player_whose_teammate_stands() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
var downed: SimEntity = _p(sim, 1)
|
||||
assert_true(downed.downed, "down, not out")
|
||||
assert_false(downed.eliminated)
|
||||
assert_eq(downed.health, Tuning.DOWNED_HEALTH)
|
||||
var events: Array[Dictionary] = _events(sim, "downed")
|
||||
assert_eq(events.size(), 1)
|
||||
assert_eq(events[0]["player"], 1)
|
||||
assert_eq(events[0]["by"], 3)
|
||||
assert_eq(_events(sim, "eliminated").size(), 0)
|
||||
|
||||
|
||||
func test_a_player_with_no_team_or_no_teammate_standing_is_eliminated_outright() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
sim.set_team(1, -1)
|
||||
_knock(sim, 1, 3)
|
||||
assert_true(_p(sim, 1).eliminated, "no team: out")
|
||||
assert_false(_p(sim, 1).downed)
|
||||
# Player 2's teammate is out, so 2 has nobody to wait for either.
|
||||
_knock(sim, 2, 3)
|
||||
assert_true(_p(sim, 2).eliminated)
|
||||
|
||||
|
||||
func test_downed_players_crawl_and_cannot_fire_build_or_loot() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
Inventory.give(_p(sim, 1), ItemCatalog.code_of("dock_carbine"), 1)
|
||||
Inventory.give(_p(sim, 1), ItemCatalog.get_def(ItemCatalog.code_of("dock_carbine")).ammo_code, 20)
|
||||
_p(sim, 1).selected = 1
|
||||
_knock(sim, 1, 3)
|
||||
var start: Vector3 = _p(sim, 1).position
|
||||
var shots: int = 0
|
||||
for _tick: int in Tuning.TICK_RATE_HZ:
|
||||
_step(sim, {1: PlayerCommand.BUTTON_FIRE | PlayerCommand.BUTTON_SPRINT | PlayerCommand.BUTTON_JUMP}, Vector2(0.0, 1.0))
|
||||
shots += _events(sim, "shot").size()
|
||||
assert_true(_p(sim, 1).on_ground, "no jumping")
|
||||
assert_eq(shots, 0, "no firing")
|
||||
var crawled: float = _p(sim, 1).position.distance_to(start)
|
||||
assert_near(crawled, Tuning.DOWNED_CRAWL_SPEED, 0.1, "a second of crawling, sprint held")
|
||||
assert_true(_p(sim, 1).crouching, "low to the ground")
|
||||
_step(sim, {1: PlayerCommand.BUTTON_FIRE | PlayerCommand.BUTTON_BUILD})
|
||||
assert_eq(sim.structures.pieces.size(), 0, "no building")
|
||||
|
||||
|
||||
func test_a_teammate_holding_interact_revives_after_the_revive_time() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
for _tick: int in REVIVE_TICKS - 1:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed)
|
||||
assert_eq(_p(sim, 1).revive_ticks, REVIVE_TICKS - 1)
|
||||
assert_eq(_p(sim, 1).reviver, 2)
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_false(_p(sim, 1).downed, "back up")
|
||||
assert_eq(_p(sim, 1).health, Tuning.REVIVE_HEALTH)
|
||||
var revived: Array[Dictionary] = _events(sim, "revived")
|
||||
assert_eq(revived.size(), 1)
|
||||
assert_eq(revived[0]["by"], 2)
|
||||
|
||||
|
||||
func test_letting_go_or_moving_away_starts_the_revive_over() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
for _tick: int in 60:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
_step(sim)
|
||||
assert_eq(_p(sim, 1).revive_ticks, 0, "let go")
|
||||
_p(sim, 2).position = _p(sim, 1).position + Vector3(Tuning.REVIVE_RANGE + 0.5, 0.0, 0.0)
|
||||
for _tick: int in REVIVE_TICKS + 5:
|
||||
_step(sim, {2: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed, "out of reach")
|
||||
assert_eq(_p(sim, 1).revive_ticks, 0)
|
||||
|
||||
|
||||
func test_an_opponent_cannot_revive_and_a_downed_player_cannot_revive() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
_knock(sim, 4, 2)
|
||||
for _tick: int in REVIVE_TICKS + 5:
|
||||
_step(sim, {3: PlayerCommand.BUTTON_INTERACT, 4: PlayerCommand.BUTTON_INTERACT})
|
||||
assert_true(_p(sim, 1).downed, "3 is an opponent")
|
||||
assert_true(_p(sim, 3).health > 0 and not _p(sim, 3).downed)
|
||||
|
||||
|
||||
func test_a_downed_player_bleeds_out_credited_to_who_downed_them() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
var ticks: int = 0
|
||||
while not _p(sim, 1).eliminated and ticks < 2000:
|
||||
_step(sim)
|
||||
ticks += 1
|
||||
assert_true(_p(sim, 1).eliminated)
|
||||
assert_near(ticks, Tuning.DOWNED_HEALTH * Tuning.DOWNED_BLEED_INTERVAL_TICKS, Tuning.DOWNED_BLEED_INTERVAL_TICKS, "about 30 s")
|
||||
var out: Array[Dictionary] = _events(sim, "eliminated")
|
||||
assert_eq(out.size(), 1)
|
||||
assert_eq(out[0]["by"], 3)
|
||||
assert_eq(out[0]["cause"], "weapon")
|
||||
|
||||
|
||||
func test_hits_on_a_downed_player_finish_them() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
Weapons.damage_player(sim, _p(sim, 1), Tuning.DOWNED_HEALTH, 4)
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).eliminated)
|
||||
assert_eq(_events(sim, "eliminated")[0]["by"], 4)
|
||||
|
||||
|
||||
func test_the_team_is_out_when_both_are_down_or_out() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
assert_true(_p(sim, 1).downed)
|
||||
_knock(sim, 2, 4)
|
||||
assert_true(_p(sim, 2).eliminated, "nobody left to down for")
|
||||
assert_true(_p(sim, 1).eliminated, "and nobody left to revive 1")
|
||||
assert_eq(_events(sim, "eliminated").size(), 2)
|
||||
var credited: Dictionary = {}
|
||||
for event: Dictionary in _events(sim, "eliminated"):
|
||||
credited[event["player"]] = event["by"]
|
||||
assert_eq(credited, {1: 3, 2: 4})
|
||||
|
||||
|
||||
func test_teammates_falling_together_are_both_out() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_p(sim, 1).health = 0
|
||||
_p(sim, 2).health = 0
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).eliminated and _p(sim, 2).eliminated)
|
||||
assert_false(_p(sim, 1).downed or _p(sim, 2).downed)
|
||||
|
||||
|
||||
func test_no_friendly_damage_from_any_weapon() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 2), 30, 1), 0, "teammate")
|
||||
assert_eq(_p(sim, 2).health, Tuning.PLAYER_MAX_HEALTH)
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 3), 30, 1), 30, "opponent")
|
||||
assert_eq(Weapons.damage_player(sim, _p(sim, 1), 10, 1), 10, "yourself, as with your own keg")
|
||||
# A keg thrown into the team: the teammate beside the blast takes nothing.
|
||||
var keg: int = ItemCatalog.code_of("powder_keg")
|
||||
var def: ItemDef = ItemCatalog.get_def(keg)
|
||||
var before: int = _p(sim, 2).health
|
||||
Explosives.blast(sim, 1, def, 0, _p(sim, 2).position + Vector3(0.0, 0.3, 0.0))
|
||||
assert_eq(_p(sim, 2).health, before, "no blast damage to a teammate")
|
||||
assert_true(_p(sim, 3).health < Tuning.PLAYER_MAX_HEALTH - 30, "the opponent a metre further on is hurt")
|
||||
|
||||
|
||||
func test_a_downed_player_in_the_sea_still_drowns() -> void:
|
||||
var sim: Simulation = _sim()
|
||||
_knock(sim, 1, 3)
|
||||
sim.set_sea_level(5.0)
|
||||
for _tick: int in 3:
|
||||
_step(sim)
|
||||
assert_true(_p(sim, 1).swimming)
|
||||
var ticks: int = 0
|
||||
while not _p(sim, 1).eliminated and ticks < 1200:
|
||||
_step(sim)
|
||||
ticks += 1
|
||||
assert_true(_p(sim, 1).eliminated, "drowning takes the downed health")
|
||||
assert_true(ticks < Tuning.DOWNED_HEALTH * Tuning.DOWNED_BLEED_INTERVAL_TICKS, "sooner than bleeding out")
|
||||
|
||||
|
||||
func test_the_hash_tells_downed_and_revive_progress_apart() -> void:
|
||||
var a: Simulation = _sim()
|
||||
var b: Simulation = _sim()
|
||||
assert_eq(a.state_hash(), b.state_hash())
|
||||
_p(a, 1).downed = true
|
||||
assert_ne(a.state_hash(), b.state_hash())
|
||||
_p(b, 1).downed = true
|
||||
_p(b, 1).revive_ticks = 3
|
||||
assert_ne(a.state_hash(), b.state_hash())
|
||||
|
||||
|
||||
# Match: team placement.
|
||||
|
||||
func _rules() -> MatchRules:
|
||||
var rules: MatchRules = MatchRules.immediate()
|
||||
rules.max_players = 6
|
||||
rules.results_ticks = 2
|
||||
rules.team_size = Tuning.DUO_TEAM_SIZE
|
||||
return rules
|
||||
|
||||
|
||||
func _duos_match() -> Match:
|
||||
var m: Match = Match.new(4242, _rules())
|
||||
m.sim = Simulation.new(4242, SimGround.flat(20.0))
|
||||
m.join(1)
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.DROP)
|
||||
var index: int = 0
|
||||
for handle: int in m.participants:
|
||||
var player: SimEntity = m.sim.entities.find(m.entity_of[handle])
|
||||
player.drop_state = Drop.NONE
|
||||
player.position = Vector3(100.0 + index * 4.0, 20.0, 100.0)
|
||||
player.velocity = Vector3.ZERO
|
||||
player.on_ground = true
|
||||
index += 1
|
||||
m.sim.drop.finished = true
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.PLAY)
|
||||
return m
|
||||
|
||||
|
||||
func _mp(m: Match, handle: int) -> SimEntity:
|
||||
return m.sim.entities.find(m.entity_of[handle])
|
||||
|
||||
|
||||
func _place_of(m: Match, handle: int) -> int:
|
||||
for record: Dictionary in m.placements:
|
||||
if record["handle"] == handle:
|
||||
return int(record["place"])
|
||||
return 0
|
||||
|
||||
|
||||
func test_match_puts_each_pair_on_a_team_in_the_simulation() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
assert_eq(hs.size(), 6)
|
||||
for index: int in hs.size():
|
||||
assert_eq(m.team_of[hs[index]], index / 2)
|
||||
assert_eq(_mp(m, hs[index]).team, index / 2)
|
||||
|
||||
|
||||
func test_match_keeps_a_downed_team_alive_and_places_the_pair_together() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
_mp(m, hs[0]).health = 0
|
||||
_mp(m, hs[0]).last_attacker = m.entity_of[hs[2]]
|
||||
_mp(m, hs[0]).last_cause = SimEntity.CAUSE_WEAPON
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[0]).downed)
|
||||
assert_eq(_place_of(m, hs[0]), 0, "down isn't placed")
|
||||
assert_true(m.alive().has(hs[0]), "still in the match")
|
||||
var downs: Array[Dictionary] = []
|
||||
for event: Dictionary in m.events:
|
||||
if event["type"] == "downed":
|
||||
downs.append(event)
|
||||
assert_eq(downs.size(), 1)
|
||||
assert_eq(downs[0]["by"], hs[2])
|
||||
assert_true(bool(m.kill_feed[-1].get("downed", false)), "the down is in the feed")
|
||||
assert_eq(m.stats[hs[2]]["eliminations"], 0, "a down isn't an elimination yet")
|
||||
# The teammate falls: both are out, sharing the place below the two teams left.
|
||||
_mp(m, hs[1]).health = 0
|
||||
_mp(m, hs[1]).last_attacker = m.entity_of[hs[4]]
|
||||
_mp(m, hs[1]).last_cause = SimEntity.CAUSE_WEAPON
|
||||
m.step()
|
||||
assert_eq(_place_of(m, hs[0]), 5)
|
||||
assert_eq(_place_of(m, hs[1]), 5)
|
||||
assert_eq(m.stats[hs[2]]["eliminations"], 1, "credited to who downed them")
|
||||
assert_eq(m.stats[hs[4]]["eliminations"], 1)
|
||||
assert_eq(m.phase, Match.PLAY)
|
||||
# One of the next team goes down, then the other: the last team wins, both of them.
|
||||
_mp(m, hs[2]).health = 0
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[2]).downed)
|
||||
assert_eq(m.phase, Match.PLAY, "a downed player keeps the team in it")
|
||||
_mp(m, hs[3]).health = 0
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.RESULTS)
|
||||
assert_eq(m.winners, [hs[4], hs[5]] as Array[int])
|
||||
assert_eq(_place_of(m, hs[2]), 3)
|
||||
assert_eq(_place_of(m, hs[3]), 3)
|
||||
|
||||
|
||||
func test_match_tie_break_prefers_a_standing_team_over_a_downed_one() -> void:
|
||||
var m: Match = _duos_match()
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
# Teams 0 and 1 left, team 2 out.
|
||||
_mp(m, hs[4]).health = 0
|
||||
_mp(m, hs[5]).health = 0
|
||||
m.step()
|
||||
_mp(m, hs[0]).health = 0
|
||||
m.step()
|
||||
assert_true(_mp(m, hs[0]).downed)
|
||||
_mp(m, hs[1]).health = 1
|
||||
_mp(m, hs[2]).health = 1
|
||||
_mp(m, hs[3]).health = 1
|
||||
assert_eq(m._tie_break([hs[0], hs[2]] as Array[int]), hs[2], "standing beats downed, despite more health")
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2cresp6auksd
|
||||
@@ -48,8 +48,9 @@ func _saw(m: Match, type: String) -> bool:
|
||||
## The state a fresh simulation for match `index` should have just after it starts.
|
||||
func _reference_hash(m: Match, index: int, players: int) -> String:
|
||||
var sim: Simulation = Simulation.new(m.match_seed(index))
|
||||
for _index: int in players:
|
||||
sim.add_player()
|
||||
for player_index: int in players:
|
||||
# Solo: everyone on a team of their own, as Match sets them.
|
||||
sim.set_team(sim.add_player(), player_index)
|
||||
sim.start_drop()
|
||||
sim.start_tide()
|
||||
sim.place_loot()
|
||||
|
||||
@@ -278,6 +278,11 @@ func test_teammates_spectate_their_living_team() -> void:
|
||||
var hs: Array[int] = m.participants.duplicate()
|
||||
_eliminate(m, hs[0])
|
||||
m.step()
|
||||
assert_true(_player(m, hs[0]).downed, "duos: down first (M7)")
|
||||
assert_eq(m.spectate_target(hs[0]), 0, "a downed player isn't spectating")
|
||||
_eliminate(m, hs[0])
|
||||
m.step()
|
||||
assert_true(_player(m, hs[0]).eliminated, "finished off")
|
||||
assert_eq(m.spectate_target(hs[0]), hs[1], "with no eliminator, the teammate")
|
||||
|
||||
|
||||
|
||||
@@ -140,13 +140,17 @@ func test_settings_controls_change_and_save_the_settings() -> void:
|
||||
|
||||
func test_practice_and_join_say_what_was_asked() -> void:
|
||||
var asked: Array = []
|
||||
menus.practice_requested.connect(func(bots: int, difficulty: int) -> void: asked.append(["practice", bots, difficulty]))
|
||||
menus.practice_requested.connect(func(bots: int, difficulty: int, team_size: int) -> void: asked.append(["practice", bots, difficulty, team_size]))
|
||||
menus.join_requested.connect(func(host: String, port: int, player_name: String) -> void: asked.append(["join", host, port, player_name]))
|
||||
menus.show_screen("practice", false)
|
||||
menus._bots.value = 5
|
||||
menus._difficulty.select(1)
|
||||
_press("practice", "Set out")
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0])
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0, 1])
|
||||
menus._mode.select(1)
|
||||
_press("practice", "Set out")
|
||||
assert_eq(asked.pop_back(), ["practice", 5, 0, Tuning.DUO_TEAM_SIZE], "duos (M7)")
|
||||
assert_eq(menus.settings.practice_team_size, Tuning.DUO_TEAM_SIZE)
|
||||
menus.show_screen("join", false)
|
||||
menus._name.text = "Wren"
|
||||
menus._address.text = "not a port:x"
|
||||
|
||||
Reference in New Issue
Block a user