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:
@@ -62,11 +62,11 @@ func _ready() -> void:
|
||||
menus.show_screen("main", false)
|
||||
|
||||
|
||||
## Starts an offline match against bots.
|
||||
func start_practice(bots: int, difficulty: int) -> void:
|
||||
## Starts an offline match against bots, solo or in duos (`team_size` 2, M7).
|
||||
func start_practice(bots: int, difficulty: int, team_size: int = 1) -> void:
|
||||
var match_seed: int = int(Time.get_unix_time_from_system() * 1000.0) & 0x7FFFFFFF
|
||||
var practice: ClientSession = ClientSession.new()
|
||||
practice.play_offline(match_seed, bots, null, difficulty)
|
||||
practice.play_offline(match_seed, bots, LocalServer.offline_rules(bots, team_size), difficulty)
|
||||
_begin(practice)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## tidewall the main menu (with a window)
|
||||
## tidewall --offline an offline match against bots
|
||||
## tidewall --connect=HOST[:PORT] join a server
|
||||
## options: --name=NAME --seed=N --bots=N (offline) --autoplay
|
||||
## options: --name=NAME --seed=N --bots=N (offline) --duos (offline) --autoplay
|
||||
## --client-seconds=N quit after N seconds, saying what happened
|
||||
## tidewall --browse [--list=HOST[:PORT]]... [--lan-target=ADDRESS]... [--lan-port=N]
|
||||
## print the servers found on the LAN and in list
|
||||
@@ -25,6 +25,8 @@ var player_name: String = DEFAULT_NAME
|
||||
var match_seed: int = 0
|
||||
var has_seed: bool = false
|
||||
var bots: int = DEFAULT_BOTS
|
||||
## Offline in duos (M7) with --duos: the player and the first bot are a team.
|
||||
var team_size: int = 1
|
||||
var autoplay: bool = false
|
||||
## Quit after this many seconds; 0 runs until the window is closed.
|
||||
var seconds: float = 0.0
|
||||
@@ -43,7 +45,7 @@ var errors: Array[String] = []
|
||||
|
||||
## Every option parse() knows, by name.
|
||||
const OPTIONS: Array[String] = [
|
||||
"--offline", "--autoplay", "--browse", "--list", "--lan-port", "--lan-target",
|
||||
"--offline", "--autoplay", "--duos", "--browse", "--list", "--lan-port", "--lan-target",
|
||||
"--connect", "--name", "--seed", "--bots", "--client-seconds",
|
||||
]
|
||||
|
||||
@@ -73,6 +75,8 @@ static func parse(args: PackedStringArray) -> ClientConfig:
|
||||
config.asked = true
|
||||
"--autoplay":
|
||||
config.autoplay = true
|
||||
"--duos":
|
||||
config.team_size = Tuning.DUO_TEAM_SIZE
|
||||
"--browse":
|
||||
config.asked = true
|
||||
config.browse = true
|
||||
@@ -120,6 +124,8 @@ static func parse(args: PackedStringArray) -> ClientConfig:
|
||||
_:
|
||||
if arg.begins_with("--"):
|
||||
config.errors.append("unknown option '%s'" % arg)
|
||||
if config.team_size > 1 and not config.host.is_empty():
|
||||
config.errors.append("--duos is for an offline match; a server decides its own teams")
|
||||
if config.browse and not config.host.is_empty():
|
||||
config.errors.append("--browse and --connect can't be used together")
|
||||
return config
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ func _ready() -> void:
|
||||
_session.input.autoplay = _config.autoplay
|
||||
if _config.host.is_empty():
|
||||
var match_seed: int = _config.match_seed if _config.has_seed else int(Time.get_unix_time_from_system() * 1000.0) & 0x7FFFFFFF
|
||||
_session.play_offline(match_seed, _config.bots)
|
||||
_session.play_offline(match_seed, _config.bots, LocalServer.offline_rules(_config.bots, _config.team_size))
|
||||
else:
|
||||
var error: Error = _session.connect_to(_config.host, _config.port, _config.player_name)
|
||||
if error != OK:
|
||||
|
||||
+110
-3
@@ -178,6 +178,8 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
return PlayerCommand.from_input(sim.tick, Vector2.ZERO, 0.0, 0.0)
|
||||
if me.drop_state != Drop.NONE:
|
||||
return _drop(sim, grid, world)
|
||||
if me.downed:
|
||||
return _crawl(sim, world, me)
|
||||
_count_building(world, me)
|
||||
_sense(sim, world, me)
|
||||
_check_tide(sim, world, me)
|
||||
@@ -205,6 +207,8 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
and not _fleeing and not retreating and not covering and distance <= Tuning.BOT_BRAWL_METRES and provoked)
|
||||
var interact: bool = false
|
||||
var walk: bool = true
|
||||
var patient: SimEntity = _patient(sim, world, me) if not me.swimming else null
|
||||
var tending: bool = false
|
||||
|
||||
# Where to go.
|
||||
_direct_on = false
|
||||
@@ -234,6 +238,14 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
elif brawling:
|
||||
state = "brawl"
|
||||
_stop()
|
||||
elif patient != null:
|
||||
# A teammate is down (M7): get to them and hold interact until they're up.
|
||||
state = "revive"
|
||||
if me.position.distance_to(patient.position) <= Tuning.REVIVE_RANGE * 0.75:
|
||||
_stop()
|
||||
tending = true
|
||||
else:
|
||||
_go(patient.position, Tuning.REVIVE_RANGE * 0.5)
|
||||
elif target != null and armed:
|
||||
state = "chase"
|
||||
_go(_last_seen, 3.0)
|
||||
@@ -361,6 +373,14 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
chosen_material = _piece_material
|
||||
if _piece_kind != StructureSet.RAMP:
|
||||
direction = Vector2.ZERO
|
||||
if tending:
|
||||
var to_patient: Vector2 = Vector2(patient.position.x - me.position.x, patient.position.z - me.position.z)
|
||||
if to_patient.length() > 0.05:
|
||||
yaw = atan2(to_patient.x, to_patient.y)
|
||||
pitch = 0.0
|
||||
direction = Vector2.ZERO
|
||||
buttons = PlayerCommand.BUTTON_INTERACT
|
||||
chosen_material = 0
|
||||
_track_fight(sim, world, me, buttons)
|
||||
var forward: Vector2 = Vector2(sin(yaw), cos(yaw))
|
||||
var right: Vector2 = Vector2(-cos(yaw), sin(yaw))
|
||||
@@ -368,6 +388,64 @@ func think(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
return PlayerCommand.from_input(sim.tick, move, yaw, pitch, buttons, selection, chosen_material)
|
||||
|
||||
|
||||
# Duos (M7)
|
||||
|
||||
## The nearest standing teammate, or null.
|
||||
func _standing_teammate(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
|
||||
if me == null or me.team < 0:
|
||||
return null
|
||||
var best: SimEntity = null
|
||||
var best_gap: float = INF
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if not Simulation.is_standing(other) or not sim.are_teammates(me, other) or other.drop_state != Drop.NONE:
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap < best_gap:
|
||||
best = other
|
||||
best_gap = gap
|
||||
return best
|
||||
|
||||
|
||||
## The nearest downed teammate within Tuning.BOT_REVIVE_METRES, or null.
|
||||
func _patient(sim: Simulation, world: BotWorld, me: SimEntity) -> SimEntity:
|
||||
var best: SimEntity = null
|
||||
var best_gap: float = Tuning.BOT_REVIVE_METRES * Tuning.BOT_REVIVE_METRES
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if other == null or not other.downed or other.eliminated or not sim.are_teammates(me, other):
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap <= best_gap:
|
||||
best = other
|
||||
best_gap = gap
|
||||
return best
|
||||
|
||||
|
||||
## Downed: crawl straight for the nearest standing teammate, and stop beside them.
|
||||
func _crawl(sim: Simulation, world: BotWorld, me: SimEntity) -> PlayerCommand:
|
||||
state = "downed"
|
||||
_stop()
|
||||
_forget_target()
|
||||
var yaw: float = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU
|
||||
var move: Vector2 = Vector2.ZERO
|
||||
var nearest: SimEntity = null
|
||||
var nearest_gap: float = INF
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if not Simulation.is_standing(other) or not sim.are_teammates(me, other):
|
||||
continue
|
||||
var gap: float = me.position.distance_squared_to(other.position)
|
||||
if gap < nearest_gap:
|
||||
nearest = other
|
||||
nearest_gap = gap
|
||||
if nearest != null and nearest_gap > Tuning.REVIVE_RANGE * Tuning.REVIVE_RANGE * 0.25:
|
||||
var to: Vector2 = Vector2(nearest.position.x - me.position.x, nearest.position.z - me.position.z)
|
||||
yaw = atan2(to.x, to.y)
|
||||
move = Vector2(0.0, 1.0)
|
||||
return PlayerCommand.from_input(sim.tick, move, yaw, 0.0)
|
||||
|
||||
|
||||
# Movement goals
|
||||
|
||||
func _go(goal: Vector3, radius: float) -> void:
|
||||
@@ -388,6 +466,13 @@ func _stop() -> void:
|
||||
## Rides the barge to within reach of a loot marker near its route, then glides to it.
|
||||
func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
state = "drop"
|
||||
var rider: SimEntity = sim.entities.find(player_id)
|
||||
if _landing < 0 and rider != null and rider.team >= 0 and world.team_landings.has(rider.team):
|
||||
# Duos (M7): land with the teammate who already chose.
|
||||
_landing = int(world.team_landings[rider.team])
|
||||
_marker = _landing
|
||||
_marker_since = sim.tick
|
||||
_go(world.markers[_landing], 2.0)
|
||||
if _landing < 0 and not world.markers.is_empty() and sim.drop != null:
|
||||
var rng: RandomNumberGenerator = nav.stream(sim)
|
||||
var a: Vector2 = Vector2(sim.drop.start.x, sim.drop.start.z)
|
||||
@@ -413,6 +498,8 @@ func _drop(sim: Simulation, grid: NavGrid, world: BotWorld) -> PlayerCommand:
|
||||
best_crowd = crowd
|
||||
_landing = pick
|
||||
world.landings.append(world.markers[_landing])
|
||||
if rider != null and rider.team >= 0:
|
||||
world.team_landings[rider.team] = _landing
|
||||
_marker = _landing
|
||||
_marker_since = sim.tick
|
||||
_go(world.markers[_landing], 2.0)
|
||||
@@ -455,6 +542,18 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
|
||||
elif tick - _last_seen_tick > roundi(Tuning.BOT_MEMORY_SECONDS * TICKS):
|
||||
_forget_target()
|
||||
target = null
|
||||
if target != null and target.downed and target_visible:
|
||||
# Duos (M7): a downed target can't shoot back, but its teammate can. Turn on the
|
||||
# teammate if they're in view; otherwise finish the job.
|
||||
for other_id: int in world.player_ids:
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if Simulation.is_standing(other) and other.drop_state == Drop.NONE and sim.are_teammates(target, other) \
|
||||
and me.position.distance_to(other.position) <= minf(_sight, Tuning.BOT_ENGAGE_METRES) and _can_see(sim, world, me, other, false):
|
||||
target_id = other.id
|
||||
_acquired_tick = tick
|
||||
_last_seen = other.position
|
||||
_last_seen_tick = tick
|
||||
return
|
||||
if target != null and target_visible:
|
||||
return
|
||||
# Look for someone new, nearest first, with a few sight lines at most.
|
||||
@@ -463,7 +562,7 @@ func _sense(sim: Simulation, world: BotWorld, me: SimEntity) -> void:
|
||||
if other_id == player_id or other_id == target_id:
|
||||
continue
|
||||
var other: SimEntity = sim.entities.find(other_id)
|
||||
if other == null or other.eliminated or other.drop_state != Drop.NONE:
|
||||
if other == null or other.eliminated or other.drop_state != Drop.NONE or sim.are_teammates(me, other):
|
||||
continue
|
||||
# A bot picks out a new opponent only this close; one who shoots it first is
|
||||
# fought at any range it can see (H3).
|
||||
@@ -974,10 +1073,18 @@ func _hunt(sim: Simulation, world: BotWorld) -> void:
|
||||
if arrived and not _holding:
|
||||
_holding = true
|
||||
_hunt_until = sim.tick + roundi(Tuning.BOT_HOLD_SECONDS * TICKS)
|
||||
var me: SimEntity = sim.entities.find(player_id)
|
||||
var mate: SimEntity = _standing_teammate(sim, world, me)
|
||||
var strayed: bool = mate != null and me.position.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES
|
||||
if strayed and (_holding or _hunt_goal.distance_to(mate.position) > Tuning.BOT_REGROUP_METRES * 0.5):
|
||||
# Duos (M7): too far from the teammate to help them up; go back to them.
|
||||
_holding = false
|
||||
_hunt_until = sim.tick
|
||||
if (not _goal_set and not _holding) or sim.tick >= _hunt_until:
|
||||
var phase: int = sim.tide.phase_at(sim.tick) if sim.tide != null else 0
|
||||
var me: SimEntity = sim.entities.find(player_id)
|
||||
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, me.position, Tuning.BOT_ROAM_METRES)
|
||||
var around: Vector3 = mate.position if strayed else me.position
|
||||
var radius: float = Tuning.BOT_REGROUP_METRES * 0.3 if strayed else Tuning.BOT_ROAM_METRES
|
||||
_hunt_goal = world.random_safe_near(nav.stream(sim), phase, around, radius)
|
||||
_hunt_until = sim.tick + 40 * TICKS
|
||||
_holding = false
|
||||
_go(_hunt_goal, 4.0)
|
||||
|
||||
@@ -44,6 +44,9 @@ var phase_tops: Array[Vector3] = []
|
||||
var walkable: PackedByteArray = PackedByteArray()
|
||||
## Where bots have chosen to land this match, so later bots can spread out (H3).
|
||||
var landings: Array[Vector3] = []
|
||||
## Duos (M7): team -> the marker index its first bot chose to land at, so its
|
||||
## teammate lands there too.
|
||||
var team_landings: Dictionary = {}
|
||||
## Victim entity ID -> attacker entity ID, for hits landed during the last tick.
|
||||
var attackers: Dictionary = {}
|
||||
## Builder entity ID -> the kinds of the pieces it placed during the last tick (M6).
|
||||
|
||||
@@ -176,9 +176,9 @@ func hear(records: Array[Dictionary]) -> void:
|
||||
|
||||
|
||||
## Puts the held item's model in the figure's hand; the figure points it where the
|
||||
## player looks. Nothing is held aboard the barge, falling, gliding or swimming.
|
||||
## player looks. Nothing is held aboard the barge, falling, gliding, swimming or down.
|
||||
func _hold(figure: FigureRig, entity: SimEntity) -> void:
|
||||
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated
|
||||
var busy: bool = entity.drop_state != Drop.NONE or entity.swimming or entity.eliminated or entity.downed
|
||||
figure.hand().visible = not busy
|
||||
if busy:
|
||||
return
|
||||
|
||||
@@ -231,6 +231,22 @@ static func _clips() -> Dictionary:
|
||||
[0.0, swim], [0.325, swim_pull], [0.65, mirror(swim)], [0.975, mirror(swim_pull)],
|
||||
]]
|
||||
|
||||
# Downed in duos (M7): on hands and knees, head up, crawling a hand and knee at a time.
|
||||
var downed: Dictionary = {
|
||||
"hips": Vector3(78, 0, 0), "waist": Vector3(-4, 0, 0), "neck": Vector3(-52, 0, 0),
|
||||
"shoulder_r": Vector3(-84, 0, -6), "elbow_r": Vector3(-8, 0, 0),
|
||||
"shoulder_l": Vector3(-84, 0, 6), "elbow_l": Vector3(-8, 0, 0),
|
||||
"hip_r": Vector3(-78, 0, -4), "knee_r": Vector3(92, 0, 0),
|
||||
"hip_l": Vector3(-78, 0, 4), "knee_l": Vector3(92, 0, 0), "lift": Vector3(0, -0.5, 0),
|
||||
}
|
||||
var downed_reach: Dictionary = over(downed, {
|
||||
"shoulder_r": Vector3(-104, 0, -6), "hip_l": Vector3(-64, 0, 4), "knee_l": Vector3(84, 0, 0),
|
||||
"waist": Vector3(-4, 6, 0),
|
||||
})
|
||||
clips["downed"] = [1.6, true, [
|
||||
[0.0, downed], [0.4, downed_reach], [0.8, downed], [1.2, mirror(downed_reach)],
|
||||
]]
|
||||
|
||||
# How the held item is carried (arms only).
|
||||
# Long things at the chest, the right hand at the grip and the left reaching
|
||||
# along to the fore-end.
|
||||
|
||||
@@ -55,7 +55,7 @@ const COLOURS: Dictionary = {
|
||||
}
|
||||
const COAT_SHADE: float = 0.28
|
||||
## The states of `move`, in input order.
|
||||
const STATES: Array[String] = ["ground", "crouch", "air", "skydive", "glide", "swim", "aboard"]
|
||||
const STATES: Array[String] = ["ground", "crouch", "air", "skydive", "glide", "swim", "aboard", "downed"]
|
||||
const HOLDS: Array[String] = ["long", "short", "carry"]
|
||||
const ACTIONS: Array[String] = ["fire_long", "fire_short", "swing", "throw", "build"]
|
||||
## How long a figure must be off the ground before it's drawn in the air, so steps
|
||||
@@ -304,6 +304,9 @@ static func state_of(entity: SimEntity, airborne: bool) -> String:
|
||||
return "glide"
|
||||
if entity.swimming:
|
||||
return "swim"
|
||||
if entity.downed:
|
||||
# Duos (M7): down on hands and knees, crawling.
|
||||
return "downed"
|
||||
if airborne:
|
||||
return "air"
|
||||
return "crouch" if entity.crouching else "ground"
|
||||
|
||||
@@ -71,6 +71,10 @@ var practice_bots: int = Tuning.SOLO_PLAYERS - 1:
|
||||
var practice_difficulty: int = -1:
|
||||
set(value):
|
||||
practice_difficulty = clampi(value, -1, Tuning.BOT_DIFFICULTIES.size() - 1)
|
||||
## Practice solo (1) or in duos with a bot teammate (Tuning.DUO_TEAM_SIZE), M7.
|
||||
var practice_team_size: int = 1:
|
||||
set(value):
|
||||
practice_team_size = clampi(value, 1, Tuning.DUO_TEAM_SIZE)
|
||||
|
||||
|
||||
func shadow_distance() -> float:
|
||||
@@ -118,6 +122,7 @@ func save(path: String = DEFAULT_PATH) -> Error:
|
||||
config.set_value("player", "last_server", last_server)
|
||||
config.set_value("practice", "bots", practice_bots)
|
||||
config.set_value("practice", "difficulty", practice_difficulty)
|
||||
config.set_value("practice", "team_size", practice_team_size)
|
||||
return config.save(path)
|
||||
|
||||
|
||||
@@ -144,6 +149,7 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
|
||||
settings.last_server = String(server_value).strip_edges().left(255)
|
||||
settings.practice_bots = _int(config, "practice", "bots", settings.practice_bots)
|
||||
settings.practice_difficulty = _int(config, "practice", "difficulty", settings.practice_difficulty)
|
||||
settings.practice_team_size = _int(config, "practice", "team_size", settings.practice_team_size)
|
||||
return settings
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ const FONT_SMALL: int = 13
|
||||
const FONT_BODY: int = 16
|
||||
const FONT_TITLE: int = 22
|
||||
const MARGIN: float = 18.0
|
||||
## Shown while downed in duos (M7).
|
||||
const DOWN_TEXT: String = "DOWN · bleeding out · crawl to your crewmate, who can haul you up with interact"
|
||||
|
||||
var state: HudState = HudState.new()
|
||||
|
||||
@@ -24,6 +26,8 @@ var _vitals: Vitals
|
||||
var _hotbar: HBoxContainer
|
||||
var _materials: VBoxContainer
|
||||
var _build: Label
|
||||
## Down in duos (M7): what to do about it, above the hotbar.
|
||||
var _down: Label
|
||||
var _reticle: Reticle
|
||||
var _hurt: HurtEdge
|
||||
## When a feed line was first shown (msec), so lines fade after HudState.FEED_SECONDS.
|
||||
@@ -90,6 +94,14 @@ func _init() -> void:
|
||||
_build.size = Vector2(520.0, 24.0)
|
||||
_build.position = Vector2(-260.0, -112.0 - MARGIN - 30.0)
|
||||
add_child(_build)
|
||||
_down = _label(FONT_BODY, Palette.WARNING)
|
||||
_down.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
|
||||
_down.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_down.size = Vector2(720.0, 24.0)
|
||||
_down.position = Vector2(-360.0, -112.0 - MARGIN - 30.0)
|
||||
_down.text = DOWN_TEXT
|
||||
_down.visible = false
|
||||
add_child(_down)
|
||||
|
||||
_materials = VBoxContainer.new()
|
||||
_materials.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
|
||||
@@ -157,6 +169,7 @@ func show_state(shown: HudState) -> void:
|
||||
var count: int = shown.materials[code] if code < shown.materials.size() else 0
|
||||
(_materials.get_child(code) as Label).text = "%s %d" % [Materials.NAMES[code].replace("_", " ").capitalize(), count]
|
||||
|
||||
_down.visible = shown.playing and shown.downed
|
||||
_build.visible = shown.playing and not shown.build.is_empty()
|
||||
if _build.visible:
|
||||
var build: Dictionary = shown.build
|
||||
|
||||
@@ -25,6 +25,8 @@ var standing: int = 0
|
||||
var total: int = 0
|
||||
## Lines for the kill feed, oldest first: {"text", "you"}.
|
||||
var feed: Array[Dictionary] = []
|
||||
## Down in duos (M7): crawling, bleeding, waiting for a crewmate to haul them up.
|
||||
var downed: bool = false
|
||||
## True when the aiming reticle is shown: playing, on foot or swimming.
|
||||
var reticle: bool = false
|
||||
## Hit feedback (A7, HitFeedback): the marker for a shot that struck someone and the
|
||||
@@ -50,9 +52,11 @@ static func from_client(game: ClientGame, input: ClientInput, own_handle: int, f
|
||||
state.playing = true
|
||||
state.health = drawn.health if drawn != null else me.health
|
||||
state.armor = drawn.armor if drawn != null else me.armor
|
||||
state.reticle = me.drop_state == Drop.NONE
|
||||
state.reticle = me.drop_state == Drop.NONE and not me.downed
|
||||
state.downed = me.downed
|
||||
_fill_carried(state, me)
|
||||
state.build = build_of(input.build_mode, input.build_kind, input.material, me.materials)
|
||||
if not me.downed:
|
||||
state.build = build_of(input.build_mode, input.build_kind, input.material, me.materials)
|
||||
return state
|
||||
|
||||
|
||||
@@ -78,9 +82,11 @@ static func from_match(flow: Match, handle: int, build_mode: bool = false, build
|
||||
state.playing = true
|
||||
state.health = me.health
|
||||
state.armor = me.armor
|
||||
state.reticle = me.drop_state == Drop.NONE
|
||||
state.reticle = me.drop_state == Drop.NONE and not me.downed
|
||||
state.downed = me.downed
|
||||
_fill_carried(state, me)
|
||||
state.build = build_of(build_mode, build_kind, material, me.materials)
|
||||
if not me.downed:
|
||||
state.build = build_of(build_mode, build_kind, material, me.materials)
|
||||
return state
|
||||
|
||||
|
||||
@@ -112,7 +118,10 @@ static func feed_lines(entries: Array[Dictionary], own_handle: int) -> Array[Dic
|
||||
var by_is_you: bool = int(entry.get("by", 0)) == own_handle and own_handle != 0
|
||||
var victim: String = "You" if victim_is_you else String(entry.get("victim_name", "Someone"))
|
||||
var by: String = "You" if by_is_you else String(entry.get("by_name", ""))
|
||||
lines.append({"text": feed_text(victim, by, String(entry.get("cause", "none")), int(entry.get("item", -1)), victim_is_you), "you": victim_is_you or by_is_you})
|
||||
var text: String = feed_text(victim, by, String(entry.get("cause", "none")), int(entry.get("item", -1)), victim_is_you)
|
||||
if bool(entry.get("downed", false)):
|
||||
text = downed_text(victim, by, victim_is_you)
|
||||
lines.append({"text": text, "you": victim_is_you or by_is_you})
|
||||
return lines
|
||||
|
||||
|
||||
@@ -136,6 +145,13 @@ static func feed_text(victim: String, by: String, cause: String, item: int, vict
|
||||
return "%s is out" % victim
|
||||
|
||||
|
||||
## A down in duos (M7): the player isn't out until they bleed out or their team falls.
|
||||
static func downed_text(victim: String, by: String, victim_is_you: bool) -> String:
|
||||
if not by.is_empty() and by != victim:
|
||||
return "%s knocked %s down" % [by, "you" if victim_is_you else victim]
|
||||
return "%s %s down" % [victim, "are" if victim_is_you else "is"]
|
||||
|
||||
|
||||
## "flintlock_pistol" -> "Flintlock Pistol".
|
||||
static func item_name(id: String) -> String:
|
||||
return id.replace("_", " ").capitalize()
|
||||
|
||||
@@ -147,6 +147,7 @@ func _show_player(entity: SimEntity, record: PackedInt32Array, shown: Dictionary
|
||||
entity.crouching = flags & NetSnapshot.FLAG_CROUCHING != 0
|
||||
entity.swimming = flags & NetSnapshot.FLAG_SWIMMING != 0
|
||||
entity.eliminated = flags & NetSnapshot.FLAG_ELIMINATED != 0
|
||||
entity.downed = flags & NetSnapshot.FLAG_DOWNED != 0
|
||||
entity.drop_state = (flags >> NetSnapshot.FLAG_DROP_SHIFT) & 3
|
||||
# Only whether they last, for drawing: the ticks left aren't replicated.
|
||||
entity.reload_ticks = 1 if flags & NetSnapshot.FLAG_RELOADING != 0 else 0
|
||||
|
||||
@@ -15,7 +15,7 @@ class_name ClientPrediction
|
||||
extends RefCounted
|
||||
|
||||
## The flags movement reads and changes.
|
||||
const _MOVEMENT_FLAGS: int = NetSnapshot.FLAG_ON_GROUND | NetSnapshot.FLAG_SWIMMING | NetSnapshot.FLAG_ELIMINATED | (3 << NetSnapshot.FLAG_DROP_SHIFT)
|
||||
const _MOVEMENT_FLAGS: int = NetSnapshot.FLAG_ON_GROUND | NetSnapshot.FLAG_SWIMMING | NetSnapshot.FLAG_ELIMINATED | NetSnapshot.FLAG_DOWNED | (3 << NetSnapshot.FLAG_DROP_SHIFT)
|
||||
## Predicted ticks kept to compare with the server: four seconds.
|
||||
const HISTORY_TICKS: int = 120
|
||||
|
||||
|
||||
+7
-4
@@ -7,7 +7,8 @@
|
||||
## 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),
|
||||
## 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).
|
||||
##
|
||||
@@ -23,11 +24,12 @@ 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", "victim_name" and
|
||||
## "by_name". Only the newest MAX_ENTRIES are kept.
|
||||
## "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)
|
||||
@@ -42,7 +44,7 @@ static func encode(standing: int, total: int, entries: Array[Dictionary]) -> Pac
|
||||
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)
|
||||
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
|
||||
@@ -67,6 +69,7 @@ static func decode(bytes: PackedByteArray) -> Dictionary:
|
||||
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] = []
|
||||
|
||||
@@ -16,7 +16,7 @@ class_name NetProtocol
|
||||
extends RefCounted
|
||||
|
||||
## Raised whenever the wire format changes in a way old clients can't read.
|
||||
const VERSION: int = 4
|
||||
const VERSION: int = 5
|
||||
const MAGIC: String = "TDWL"
|
||||
const CHANNEL_CONTROL: int = 0
|
||||
## Unreliable game traffic: commands up, snapshots down.
|
||||
|
||||
+10
-5
@@ -38,8 +38,8 @@ const MATCH_BYTES: int = 14
|
||||
## told. Exact, not quantized, so a prediction made from it matches the server's to the
|
||||
## bit: position and velocity (three f32 each, which is all a Vector3 holds), the water
|
||||
## level around the player (f64), which of the nine flood cells around the player that
|
||||
## water reaches (u16), swimming stamina in ticks (u16) and the player's FLAG_ bits (u8).
|
||||
const SELF_BYTES: int = 37
|
||||
## water reaches (u16), swimming stamina in ticks (u16) and the player's FLAG_ bits (u16).
|
||||
const SELF_BYTES: int = 38
|
||||
## Every bit of the nine-cell water mask.
|
||||
const WATER_EVERYWHERE: int = 0x1FF
|
||||
## The most commands one INPUT may carry. Clients send fewer; see Tuning.
|
||||
@@ -80,6 +80,8 @@ const FLAG_ELIMINATED: int = 1 << 3
|
||||
const FLAG_DROP_SHIFT: int = 4
|
||||
const FLAG_RELOADING: int = 1 << 6
|
||||
const FLAG_USING: int = 1 << 7
|
||||
## Down, not out (duos, M7): crawling and waiting for a teammate.
|
||||
const FLAG_DOWNED: int = 1 << 8
|
||||
|
||||
const _U8: int = 0
|
||||
const _S8: int = 1
|
||||
@@ -89,7 +91,7 @@ const _WIDTH: Array[int] = [1, 1, 2, 4]
|
||||
|
||||
## Per archetype: the wire type of every record index.
|
||||
const _TYPES: Dictionary = {
|
||||
SimEntity.ARCHETYPE_PLAYER: [_U8, _U16, _U16, _U16, _U16, _S8, _U8, _U8, _U8, _U8],
|
||||
SimEntity.ARCHETYPE_PLAYER: [_U8, _U16, _U16, _U16, _U16, _S8, _U8, _U8, _U16, _U8],
|
||||
SimEntity.ARCHETYPE_PICKUP: [_U8, _U16, _U16, _U16, _U8, _U16, _U8],
|
||||
SimEntity.ARCHETYPE_PROJECTILE: [_U8, _U16, _U16, _U16, _U8, _U32],
|
||||
}
|
||||
@@ -157,6 +159,8 @@ static func flags_of(entity: SimEntity) -> int:
|
||||
flags |= FLAG_RELOADING
|
||||
if entity.use_ticks > 0:
|
||||
flags |= FLAG_USING
|
||||
if entity.downed:
|
||||
flags |= FLAG_DOWNED
|
||||
return flags
|
||||
|
||||
|
||||
@@ -180,6 +184,7 @@ static func apply_self(player: SimEntity, own: Dictionary) -> void:
|
||||
player.crouching = flags & FLAG_CROUCHING != 0
|
||||
player.swimming = flags & FLAG_SWIMMING != 0
|
||||
player.eliminated = flags & FLAG_ELIMINATED != 0
|
||||
player.downed = flags & FLAG_DOWNED != 0
|
||||
player.drop_state = (flags >> FLAG_DROP_SHIFT) & 3
|
||||
|
||||
|
||||
@@ -257,7 +262,7 @@ static func encode_snapshot(header: Dictionary, removed: PackedInt32Array, recor
|
||||
out.put_double(own["water"])
|
||||
out.put_u16(int(own["water_mask"]) & WATER_EVERYWHERE)
|
||||
out.put_u16(clampi(int(own["stamina"]), 0, 65535))
|
||||
out.put_u8(int(own["flags"]) & 0xFF)
|
||||
out.put_u16(int(own["flags"]) & 0xFFFF)
|
||||
out.put_u8(removed.size())
|
||||
for entity_id: int in removed:
|
||||
_put_varint(out, entity_id)
|
||||
@@ -325,7 +330,7 @@ static func decode_snapshot(bytes: PackedByteArray) -> Dictionary:
|
||||
"water": bytes.decode_double(at + 24),
|
||||
"water_mask": bytes.decode_u16(at + 32) & WATER_EVERYWHERE,
|
||||
"stamina": bytes.decode_u16(at + 34),
|
||||
"flags": bytes[at + 36],
|
||||
"flags": bytes.decode_u16(at + 36),
|
||||
}
|
||||
for value: float in [own["position"].x, own["position"].y, own["position"].z, own["velocity"].x, own["velocity"].y, own["velocity"].z, own["water"]]:
|
||||
if not is_finite(value):
|
||||
|
||||
@@ -55,10 +55,11 @@ func _ready() -> void:
|
||||
if not config.has_seed:
|
||||
config.match_seed = _fresh_seed()
|
||||
Engine.max_fps = 0 if config.unthrottled else REALTIME_MAX_FPS
|
||||
var rules: MatchRules = null
|
||||
var rules: MatchRules = ServerLoop.immediate_rules(config.players, config.bots)
|
||||
if config.listen:
|
||||
rules = MatchRules.new()
|
||||
rules.fill_with_bots = config.bots > 0
|
||||
rules.team_size = config.team_size
|
||||
loop = ServerLoop.new(config.match_seed, config.players, config.bots, rules, config.bot_difficulty)
|
||||
if config.listen:
|
||||
var net: NetServer = NetServer.new()
|
||||
|
||||
@@ -17,6 +17,16 @@ var _accumulator: float = 0.0
|
||||
var _greeted: bool = false
|
||||
|
||||
|
||||
## Rules for an offline match of one person and `bots` bots on teams of `team_size`:
|
||||
## null for solo, which ServerLoop starts at once with its own rules.
|
||||
static func offline_rules(bots: int, team_size: int) -> MatchRules:
|
||||
if team_size <= 1:
|
||||
return null
|
||||
var rules: MatchRules = ServerLoop.immediate_rules(1, bots)
|
||||
rules.team_size = team_size
|
||||
return rules
|
||||
|
||||
|
||||
## A match of one person and `bots` bots. With `rules` null it starts at once, and a
|
||||
## new one starts after each one's results. `difficulty` is every bot's, as an index
|
||||
## into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
|
||||
|
||||
@@ -119,7 +119,7 @@ func after_tick() -> void:
|
||||
feed_changes = PackedByteArray()
|
||||
own_changes.clear()
|
||||
for event: Dictionary in flow.events:
|
||||
if event["type"] == "placed" or event["type"] == "match_started":
|
||||
if event["type"] in ["placed", "match_started", "downed", "revived"]:
|
||||
feed_changed = true
|
||||
if event["type"] == "phase":
|
||||
changed = true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Command-line configuration for a headless server.
|
||||
##
|
||||
## tools/godot.sh -- --server [--listen] [--port=N] [--seed=N] [--players=N] [--bots=N]
|
||||
## [--bot-difficulty=mixed|easy|normal|hard] [--ticks=N]
|
||||
## [--bot-difficulty=mixed|easy|normal|hard] [--team-size=1|2] [--ticks=N]
|
||||
## [--unthrottled] [--log-every=N] [--matches=N] [--world-hash-every=N]
|
||||
## [--name=NAME] [--list=HOST[:PORT]]... [--no-lan]
|
||||
## [--health-port=N] [--health-bind=ADDRESS] [--stop-file=PATH]
|
||||
@@ -24,6 +24,9 @@
|
||||
## A listening server answers LAN discovery on its port plus one unless `--no-lan`,
|
||||
## and registers with each `--list` server (see ListServer) under `--name`.
|
||||
##
|
||||
## `--team-size=2` plays duos (M7): pairs in join order, who can't hurt each other and
|
||||
## go down instead of out while their teammate stands. 1, solo, is the default.
|
||||
##
|
||||
## Unknown or malformed arguments are errors, so a typo can't silently run the wrong
|
||||
## match. See `parse()`.
|
||||
class_name ServerConfig
|
||||
@@ -46,6 +49,8 @@ var port: int = DEFAULT_PORT
|
||||
## Idle player slots, for a server that isn't listening.
|
||||
var players: int = 0
|
||||
var bots: int = 0
|
||||
## Players on a team: 1 for solo, Tuning.DUO_TEAM_SIZE for duos.
|
||||
var team_size: int = 1
|
||||
## Every bot's difficulty, as an index into Tuning.BOT_DIFFICULTIES, or -1 to mix them.
|
||||
var bot_difficulty: int = -1
|
||||
## Ticks to run before exiting. 0 runs until the process is stopped.
|
||||
@@ -107,6 +112,7 @@ func to_dictionary() -> Dictionary:
|
||||
"port": port,
|
||||
"players": players,
|
||||
"bots": bots,
|
||||
"team_size": team_size,
|
||||
"bot_difficulty": "mixed" if bot_difficulty < 0 else String(Tuning.BOT_DIFFICULTIES[bot_difficulty]["name"]),
|
||||
"ticks": ticks,
|
||||
"matches": matches,
|
||||
@@ -147,6 +153,9 @@ func _parse_one(arg: String) -> void:
|
||||
"--bots":
|
||||
if _check_int(key, value):
|
||||
bots = value.to_int()
|
||||
"--team-size":
|
||||
if _check_int(key, value):
|
||||
team_size = value.to_int()
|
||||
"--ticks":
|
||||
if _check_int(key, value):
|
||||
ticks = value.to_int()
|
||||
@@ -260,6 +269,8 @@ func _validate() -> void:
|
||||
)
|
||||
if listen and players > 0:
|
||||
errors.append("--players is for a server that isn't listening; with --listen, people join over the network")
|
||||
if team_size < 1 or team_size > Tuning.DUO_TEAM_SIZE:
|
||||
errors.append("--team-size must be 1 (solo) or %d (duos), got %d" % [Tuning.DUO_TEAM_SIZE, team_size])
|
||||
if ticks < 0:
|
||||
errors.append("--ticks can't be negative")
|
||||
if log_every < 0:
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
## - Falloff: full damage at the middle, down linearly to Tuning.BLAST_EDGE_FACTOR of it
|
||||
## at the edge, times the charge's tier.
|
||||
## - Players take `damage`, armor first, credited to the thrower. The thrower takes
|
||||
## Tuning.BLAST_SELF_FACTOR of theirs. Everyone else takes it all: there are no
|
||||
## teammates in solo, and duos (M7) will apply one team rule to every weapon.
|
||||
## Tuning.BLAST_SELF_FACTOR of theirs. Everyone else takes it all, except the thrower's
|
||||
## teammates, who take none (Weapons.damage_player's team rule).
|
||||
## - Pieces and props take `structure_damage`. A breakwater is a piece, so a charge can
|
||||
## breach one and let the sea in.
|
||||
## Everything a blast reaches is worked out before any of it is applied, in ID order,
|
||||
|
||||
+32
-2
@@ -222,6 +222,7 @@ func step() -> void:
|
||||
DROP, PLAY:
|
||||
sim.step()
|
||||
_collect_damage()
|
||||
_collect_downs()
|
||||
_collect_eliminations()
|
||||
if phase == DROP and sim.drop.finished:
|
||||
_enter(PLAY)
|
||||
@@ -252,6 +253,7 @@ func _start() -> void:
|
||||
entity_of[handle] = entity_id
|
||||
handle_of[entity_id] = handle
|
||||
team_of[handle] = index / size
|
||||
sim.set_team(entity_id, index / size)
|
||||
stats[handle] = {"eliminations": 0, "damage_dealt": 0, "damage_taken": 0}
|
||||
_match_size = participants.size()
|
||||
_roster = participants.duplicate()
|
||||
@@ -279,6 +281,32 @@ func _collect_damage() -> void:
|
||||
_last_weapon[victim] = int(event.get("item", -1))
|
||||
|
||||
|
||||
## Reports downs and revives (M7) by handle: {"type": "downed", "handle", "by", "cause",
|
||||
## "item"} and {"type": "revived", "handle", "by"}. Downs also go in the kill feed, marked
|
||||
## "downed".
|
||||
func _collect_downs() -> void:
|
||||
for event: Dictionary in sim.events:
|
||||
if not handle_of.has(event.get("player", 0)):
|
||||
continue
|
||||
var handle: int = handle_of[event["player"]]
|
||||
if event["type"] == "downed":
|
||||
var by: int = int(handle_of.get(event["by"], 0))
|
||||
var record: Dictionary = {
|
||||
"type": "downed", "handle": handle, "by": by, "cause": String(event["cause"]),
|
||||
"item": int(_last_weapon.get(handle, -1)) if by != 0 else -1, "tick": sim.tick,
|
||||
}
|
||||
events.append(record)
|
||||
var entry: Dictionary = record.duplicate()
|
||||
entry.erase("type")
|
||||
entry["downed"] = true
|
||||
entry["place"] = 0
|
||||
entry["tied"] = false
|
||||
entry["left"] = false
|
||||
kill_feed.append(entry)
|
||||
elif event["type"] == "revived":
|
||||
events.append({"type": "revived", "handle": handle, "by": int(handle_of.get(event["by"], 0))})
|
||||
|
||||
|
||||
## Places everyone the simulation eliminated this tick. They share the best place of
|
||||
## the range they fall into: with five standing and two falling together, both are 4th.
|
||||
func _collect_eliminations() -> void:
|
||||
@@ -377,8 +405,8 @@ func _check_finished() -> void:
|
||||
events.append({"type": "match_ended", "match": current_seed(), "winners": winners.duplicate(), "timed_out": timed_out})
|
||||
|
||||
|
||||
## The best of `handles` by the tie-break: most health, then highest feet, then the
|
||||
## earliest to join. With `worst`, the worst instead.
|
||||
## The best of `handles` by the tie-break: standing over downed, most health, then
|
||||
## highest feet, then the earliest to join. With `worst`, the worst instead.
|
||||
func _tie_break(handles: Array[int], worst: bool = false) -> int:
|
||||
var chosen: int = handles[0]
|
||||
for handle: int in handles:
|
||||
@@ -393,6 +421,8 @@ func _tie_break(handles: Array[int], worst: bool = false) -> int:
|
||||
func _beats(a: int, b: int) -> bool:
|
||||
var pa: SimEntity = sim.entities.find(entity_of[a])
|
||||
var pb: SimEntity = sim.entities.find(entity_of[b])
|
||||
if pa.downed != pb.downed:
|
||||
return pb.downed
|
||||
if pa.health != pb.health:
|
||||
return pa.health > pb.health
|
||||
if not is_equal_approx(pa.position.y, pb.position.y):
|
||||
|
||||
@@ -21,6 +21,11 @@ static func step(player: SimEntity, command: PlayerCommand, ground: SimGround, s
|
||||
player.crouching = command.is_pressed(PlayerCommand.BUTTON_CROUCH)
|
||||
wants_jump = command.is_pressed(PlayerCommand.BUTTON_JUMP) and not player.crouching
|
||||
wish = _wish_velocity(command, player.crouching)
|
||||
if player.downed:
|
||||
# Downed (M7): low to the ground and crawling, with no jump or sprint.
|
||||
player.crouching = true
|
||||
wants_jump = false
|
||||
wish = wish.limit_length(Tuning.DOWNED_CRAWL_SPEED)
|
||||
|
||||
if player.drop_state == Drop.ABOARD:
|
||||
# Riders move with the barge; Simulation places them.
|
||||
@@ -228,6 +233,10 @@ static func _swim(player: SimEntity, command: PlayerCommand, ground: SimGround,
|
||||
speed = Tuning.SWIM_SPRINT_SPEED
|
||||
if not has_stamina:
|
||||
speed *= Tuning.SWIM_EXHAUSTED_FACTOR
|
||||
if player.downed:
|
||||
# A downed swimmer paddles at a crawl and can't dive.
|
||||
speed = minf(speed, Tuning.DOWNED_CRAWL_SPEED)
|
||||
diving = false
|
||||
var velocity: Vector3 = move * speed
|
||||
|
||||
var float_depth: float = Tuning.SWIM_FLOAT_DEPTH if has_stamina else Tuning.SWIM_EXHAUSTED_DEPTH
|
||||
|
||||
@@ -63,6 +63,14 @@ var prev_buttons: int = 0
|
||||
var view_quarters: int = 0
|
||||
## Set once health reaches 0. Eliminated players take no more commands.
|
||||
var eliminated: bool = false
|
||||
## The player's team, set by Match; -1 for none. Players on the same team can't hurt
|
||||
## each other, and a player with a teammate standing goes down instead of out (M7).
|
||||
var team: int = -1
|
||||
## Down but not out: crawling, bleeding health, waiting for a teammate. See Simulation.
|
||||
var downed: bool = false
|
||||
## Ticks a teammate has spent reviving this downed player without a break, and who.
|
||||
var revive_ticks: int = 0
|
||||
var reviver: int = 0
|
||||
## The player who last damaged this one, or 0.
|
||||
var last_attacker: int = 0
|
||||
## What dealt this player's most recent damage: one of the CAUSE_ constants. The cause
|
||||
|
||||
+137
-9
@@ -62,6 +62,8 @@ var _planned_levels: PackedFloat32Array = PackedFloat32Array()
|
||||
var _destroyed_checked: int = 0
|
||||
## Player entity IDs, ascending.
|
||||
var _players: Array[int] = []
|
||||
## Downed players someone worked on reviving this tick.
|
||||
var _tended: Dictionary = {}
|
||||
|
||||
|
||||
## Generates the island from the seed, unless `world` is given. Tests that don't care
|
||||
@@ -107,6 +109,51 @@ func add_player() -> int:
|
||||
return player.id
|
||||
|
||||
|
||||
## Puts a player on a team. Players on one team can't hurt each other, and go down
|
||||
## instead of out while a teammate stands (M7). Match sets every player's team.
|
||||
func set_team(player_id: int, team: int) -> void:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player != null:
|
||||
player.team = team
|
||||
|
||||
|
||||
## Whether `a` and `b` are different players on the same team.
|
||||
func are_teammates(a: SimEntity, b: SimEntity) -> bool:
|
||||
return a != null and b != null and a.id != b.id and a.team >= 0 and a.team == b.team
|
||||
|
||||
|
||||
## On their feet: in the match, not eliminated, not downed, health left.
|
||||
static func is_standing(player: SimEntity) -> bool:
|
||||
return player != null and not player.eliminated and not player.downed and player.health > 0
|
||||
|
||||
|
||||
## Whether any teammate of `player` is standing.
|
||||
func has_standing_teammate(player: SimEntity) -> bool:
|
||||
if player.team < 0:
|
||||
return false
|
||||
for other_id: int in _players:
|
||||
var other: SimEntity = entities.find(other_id)
|
||||
if are_teammates(player, other) and is_standing(other):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## The nearest downed teammate within Tuning.REVIVE_RANGE of `player`, or null. Ties go
|
||||
## to the lower ID.
|
||||
func revivable_teammate(player: SimEntity) -> SimEntity:
|
||||
var best: SimEntity = null
|
||||
var best_distance: float = Tuning.REVIVE_RANGE * Tuning.REVIVE_RANGE
|
||||
for other_id: int in _players:
|
||||
var other: SimEntity = entities.find(other_id)
|
||||
if not are_teammates(player, other) or not other.downed or other.eliminated:
|
||||
continue
|
||||
var distance: float = player.position.distance_squared_to(other.position)
|
||||
if distance <= best_distance and (best == null or distance < best_distance):
|
||||
best = other
|
||||
best_distance = distance
|
||||
return best
|
||||
|
||||
|
||||
## Removes a player and any commands queued for it.
|
||||
func remove_player(player_id: int) -> void:
|
||||
entities.remove(player_id)
|
||||
@@ -204,6 +251,7 @@ func step() -> void:
|
||||
drop.ride(player, command, tick)
|
||||
else:
|
||||
_apply_command(player, command)
|
||||
_advance_downed()
|
||||
Weapons.advance_projectiles(self)
|
||||
_spill_broken_crates()
|
||||
_check_eliminations()
|
||||
@@ -220,12 +268,20 @@ func step() -> void:
|
||||
func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
|
||||
var water: float = water_level_at(player.position)
|
||||
Movement.step(player, command, ground, water)
|
||||
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT)
|
||||
var sprinting: bool = command != null and command.is_pressed(PlayerCommand.BUTTON_SPRINT) and not player.downed
|
||||
Water.update(player, water_level_at(player.position), drown_dps, sprinting)
|
||||
if player.action_cooldown > 0:
|
||||
player.action_cooldown -= 1
|
||||
if command != null:
|
||||
Weapons.note_view(player, command, tick)
|
||||
if player.downed:
|
||||
# Crawling is all a downed player can do.
|
||||
player.prev_buttons = command.buttons if command != null else 0
|
||||
return
|
||||
if command != null and command.is_pressed(PlayerCommand.BUTTON_INTERACT) and _tend(player):
|
||||
# Reviving takes both hands: no looting, firing or building meanwhile.
|
||||
player.prev_buttons = command.buttons
|
||||
return
|
||||
Weapons.update(player)
|
||||
Consumables.update(self, player, command)
|
||||
var held: int = command.buttons if command != null else 0
|
||||
@@ -273,19 +329,87 @@ func _spill_broken_crates() -> void:
|
||||
events.append({"type": "crate_spilled", "prop": prop, "pickups": ids})
|
||||
|
||||
|
||||
## Marks players whose health reached 0 as eliminated, and drops what they carried.
|
||||
## A standing player holding interact works on reviving the nearest downed teammate in
|
||||
## range. Returns true if there was one. Revives on the REVIVE_SECONDS-th tick in a row.
|
||||
func _tend(player: SimEntity) -> bool:
|
||||
if player.drop_state != Drop.NONE or player.swimming:
|
||||
return false
|
||||
var patient: SimEntity = revivable_teammate(player)
|
||||
if patient == null:
|
||||
return false
|
||||
if patient.reviver != player.id:
|
||||
patient.revive_ticks = 0
|
||||
patient.reviver = player.id
|
||||
patient.revive_ticks += 1
|
||||
_tended[patient.id] = true
|
||||
if patient.revive_ticks >= roundi(Tuning.REVIVE_SECONDS * Tuning.TICK_RATE_HZ):
|
||||
patient.downed = false
|
||||
patient.health = Tuning.REVIVE_HEALTH
|
||||
patient.revive_ticks = 0
|
||||
patient.reviver = 0
|
||||
events.append({"type": "revived", "player": patient.id, "by": player.id})
|
||||
return true
|
||||
|
||||
|
||||
## Downed players bleed, and a revive nobody worked on this tick starts over.
|
||||
func _advance_downed() -> void:
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if not player.downed or player.eliminated:
|
||||
continue
|
||||
if not _tended.has(player_id):
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
if tick % Tuning.DOWNED_BLEED_INTERVAL_TICKS == 0:
|
||||
player.health = maxi(player.health - 1, 0)
|
||||
_tended.clear()
|
||||
|
||||
|
||||
## Players whose health reached 0 go down if a teammate is still standing, and are
|
||||
## eliminated otherwise, dropping what they carried. Downed players are eliminated once
|
||||
## their health runs out again, or once no teammate is left standing to revive them.
|
||||
## The blow that downed them is what eliminated them, credited to who struck it.
|
||||
func _check_eliminations() -> void:
|
||||
var out: Array[SimEntity] = []
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player.eliminated or player.health > 0:
|
||||
continue
|
||||
player.eliminated = true
|
||||
player.velocity = Vector3.ZERO
|
||||
events.append({
|
||||
"type": "eliminated", "player": player_id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
Inventory.drop_all(self, player)
|
||||
if not player.downed and player.drop_state == Drop.NONE and has_standing_teammate(player):
|
||||
player.downed = true
|
||||
player.health = Tuning.DOWNED_HEALTH
|
||||
player.armor = 0
|
||||
player.reload_ticks = 0
|
||||
player.use_ticks = 0
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
events.append({
|
||||
"type": "downed", "player": player_id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
else:
|
||||
out.append(player)
|
||||
for player: SimEntity in out:
|
||||
_eliminate(player)
|
||||
# A downed player with nobody left to revive them is out.
|
||||
for player_id: int in _players:
|
||||
var player: SimEntity = entities.find(player_id)
|
||||
if player.downed and not player.eliminated and not has_standing_teammate(player):
|
||||
_eliminate(player)
|
||||
|
||||
|
||||
func _eliminate(player: SimEntity) -> void:
|
||||
player.eliminated = true
|
||||
player.health = 0
|
||||
player.velocity = Vector3.ZERO
|
||||
player.downed = false
|
||||
player.revive_ticks = 0
|
||||
player.reviver = 0
|
||||
events.append({
|
||||
"type": "eliminated", "player": player.id, "by": player.last_attacker,
|
||||
"cause": SimEntity.CAUSE_NAMES[player.last_cause],
|
||||
})
|
||||
Inventory.drop_all(self, player)
|
||||
|
||||
|
||||
## Moves the sea surface, and spreads the flood for it at once. Takes effect on the
|
||||
@@ -369,6 +493,10 @@ func state_hash() -> String:
|
||||
buffer.put_32(entity.prev_buttons)
|
||||
buffer.put_u8(1 if entity.eliminated else 0)
|
||||
buffer.put_64(entity.view_quarters)
|
||||
buffer.put_32(entity.team)
|
||||
buffer.put_u8(1 if entity.downed else 0)
|
||||
buffer.put_32(entity.revive_ticks)
|
||||
buffer.put_32(entity.reviver)
|
||||
buffer.put_32(entity.last_attacker)
|
||||
buffer.put_u8(entity.last_cause)
|
||||
buffer.put_32(entity.item)
|
||||
|
||||
@@ -58,6 +58,20 @@ const DUO_TEAMS: int = 12
|
||||
const DUO_TEAM_SIZE: int = 2
|
||||
const REVIVE_SECONDS: float = 6.0
|
||||
|
||||
# Duos: downed, revive and bleed-out (M7). See Simulation.
|
||||
## A player whose health runs out while a teammate is still standing goes down instead
|
||||
## of out, with this much health to bleed. Hits on a downed player take it, too.
|
||||
const DOWNED_HEALTH: int = 60
|
||||
## A downed player loses one health this often, so bleeding out takes 30 seconds.
|
||||
const DOWNED_BLEED_INTERVAL_TICKS: int = 15
|
||||
## Downed players crawl: no jumping, sprinting, firing, building or using items.
|
||||
const DOWNED_CRAWL_SPEED: float = 1.0
|
||||
## A standing teammate holding interact within this distance (feet to feet) revives a
|
||||
## downed one in REVIVE_SECONDS. Letting go or moving away starts it over.
|
||||
const REVIVE_RANGE: float = 2.0
|
||||
## Health a revived player gets up with.
|
||||
const REVIVE_HEALTH: int = 30
|
||||
|
||||
# Match flow, in seconds. See Match and MatchRules, which can override each one.
|
||||
## The lobby counts down once this many participants have joined.
|
||||
const MATCH_MIN_PLAYERS: int = 1
|
||||
@@ -265,6 +279,11 @@ const BOT_STUCK_REPATHS: int = 3
|
||||
## Each bot re-checks its remaining path against grid changes this often, in ticks.
|
||||
const BOT_PATH_CHECK_TICKS: int = 15
|
||||
|
||||
## Duos (M7): a bot goes to revive a downed teammate this close, unless it's in a fight.
|
||||
const BOT_REVIVE_METRES: float = 60.0
|
||||
## Duos: a roaming bot this far from its teammate heads back to them.
|
||||
const BOT_REGROUP_METRES: float = 30.0
|
||||
|
||||
# Bot brains. Bots loot, fight, heal and keep ahead of the tide with only what a player
|
||||
# would know: what they can see, the map's points of interest, and the tide forecast.
|
||||
## Per difficulty: `reaction` is seconds between first seeing an opponent and firing,
|
||||
|
||||
+5
-1
@@ -269,10 +269,14 @@ static func _pull(sim: Simulation, player: SimEntity, point: Vector3, speed: flo
|
||||
|
||||
|
||||
## Takes `amount` from armor, then health. Returns the damage actually done. `item` is
|
||||
## the weapon's item code, or -1, for the kill feed.
|
||||
## the weapon's item code, or -1, for the kill feed. Every weapon, the boathook and
|
||||
## blasts come through here, so this is the one team rule: nobody can hurt a teammate
|
||||
## (M7). Hurting yourself, as with your own keg, still counts.
|
||||
static func damage_player(sim: Simulation, victim: SimEntity, amount: int, attacker: int, headshot: bool = false, item: int = -1) -> int:
|
||||
if victim == null or victim.eliminated or amount <= 0:
|
||||
return 0
|
||||
if attacker != 0 and sim.are_teammates(victim, sim.entities.find(attacker)):
|
||||
return 0
|
||||
var to_armor: int = mini(victim.armor, amount)
|
||||
victim.armor -= to_armor
|
||||
var to_health: int = mini(victim.health, amount - to_armor)
|
||||
|
||||
+9
-2
@@ -9,7 +9,7 @@
|
||||
class_name Menus
|
||||
extends Control
|
||||
|
||||
signal practice_requested(bots: int, difficulty: int)
|
||||
signal practice_requested(bots: int, difficulty: int, team_size: int)
|
||||
signal join_requested(host: String, port: int, player_name: String)
|
||||
signal resume_requested
|
||||
signal leave_requested
|
||||
@@ -41,6 +41,7 @@ var _binding_note: Label
|
||||
## Practice.
|
||||
var _bots: SpinBox
|
||||
var _difficulty: OptionButton
|
||||
var _mode: OptionButton
|
||||
## Join.
|
||||
var _name: LineEdit
|
||||
var _address: LineEdit
|
||||
@@ -360,6 +361,10 @@ func _build_practice() -> void:
|
||||
for index: int in Tuning.BOT_DIFFICULTIES.size():
|
||||
_difficulty.add_item(String(Tuning.BOT_DIFFICULTIES[index]["name"]).capitalize(), index + 1)
|
||||
_row(column, "Bot skill", _difficulty)
|
||||
_mode = OptionButton.new()
|
||||
_mode.add_item("Solo", 1)
|
||||
_mode.add_item("Duos, with a bot crewmate", Tuning.DUO_TEAM_SIZE)
|
||||
_row(column, "Crew", _mode)
|
||||
_button(column, "Set out", _start_practice)
|
||||
_button(column, "Back", back)
|
||||
|
||||
@@ -367,8 +372,9 @@ func _build_practice() -> void:
|
||||
func _start_practice() -> void:
|
||||
settings.practice_bots = int(_bots.value)
|
||||
settings.practice_difficulty = _difficulty.selected - 1
|
||||
settings.practice_team_size = _mode.get_item_id(_mode.selected)
|
||||
save_settings()
|
||||
practice_requested.emit(settings.practice_bots, settings.practice_difficulty)
|
||||
practice_requested.emit(settings.practice_bots, settings.practice_difficulty, settings.practice_team_size)
|
||||
|
||||
|
||||
func _build_join() -> void:
|
||||
@@ -580,6 +586,7 @@ func _build_results() -> void:
|
||||
func _refresh_controls() -> void:
|
||||
_bots.value = settings.practice_bots
|
||||
_difficulty.selected = settings.practice_difficulty + 1
|
||||
_mode.selected = maxi(_mode.get_item_index(settings.practice_team_size), 0)
|
||||
_name.text = settings.player_name
|
||||
if _address.text.is_empty():
|
||||
_address.text = settings.last_server
|
||||
|
||||
Reference in New Issue
Block a user