A2: Player figure and animation
The islander is built in headless Blender (tools/models/figure.py, `make figure`, `make art`) as twelve rigid parts with their origins at their joints: an oilskin coat, a sou'wester, sea boots, a bedding roll and the canvas wing-sail. Debian's Blender can't write glTF, so the figure is jointed rather than skinned. FigureRig hangs the parts on pivots, paints them from Palette with the coat in the player's own oilskin, and plays FigurePoses' hand-written key poses through one AnimationTree: idle, walk and run by speed, crouch and creep, air, skydive, glide, swim and aboard; long, short and carried holds; reload and use layers; fire, boathook swing, keg throw and building as one-shots; and a flinch when health drops. The chest takes a third of the pitch and the held item all of it. Figures animate from replicated state only: positions, look, health, the held item and the FLAG_ bits (reloading and using now reach mirrored players), with actions from FX. Every boathook swing is now a sim "swing" event, sent as a SHOT with no item, so misses are seen and heard; the new FX kind PLACE shows pieces placed. Protocol version 4. Tests: test_figure_rig (15), plus swing and PLACE cases in test_harvest and test_net_fx. make check passes (604 tests); make client-check passes. Captures: figure_states, figure_actions, figure_close (make figure-captures), client_glide and client_landed. Closes #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/figure_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureFigure" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
stage = "actions"
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/figure_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureFigure" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
stage = "close"
|
||||
@@ -0,0 +1,168 @@
|
||||
## Capture scenario for the player figure (A2), on seed 2's island in the real
|
||||
## MatchView. Each stage stands a row of figures, each frozen at a chosen moment of one
|
||||
## 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
|
||||
## 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.
|
||||
## - close: one figure holding the dock carbine, close up, three-quarter front.
|
||||
extends Node3D
|
||||
|
||||
@export var stage: String = "states"
|
||||
@export var match_seed: int = 2
|
||||
|
||||
## [label, item id or "", setup, seconds to run, action or ""]. Setup names a state.
|
||||
const STATES: Array = [
|
||||
["idle", "", "ground", 0.6, ""],
|
||||
["walk", "", "walk", 0.2, ""],
|
||||
["run", "", "run", 0.15, ""],
|
||||
["crouch", "", "crouch", 0.8, ""],
|
||||
["creep", "", "creep", 0.25, ""],
|
||||
["air", "", "air", 0.5, ""],
|
||||
["skydive", "", "skydive", 0.8, ""],
|
||||
["glide", "", "glide", 0.8, ""],
|
||||
["swim", "", "swim", 0.35, ""],
|
||||
]
|
||||
const ACTIONS: Array = [
|
||||
["long", "whalers_longgun", "ground", 0.6, ""],
|
||||
["short", "signal_revolver", "ground", 0.6, ""],
|
||||
["carry", "brine_tonic", "ground", 0.6, ""],
|
||||
["fire_long", "dock_carbine", "ground", 0.04, "fire_long"],
|
||||
["fire_short", "signal_revolver", "ground", 0.04, "fire_short"],
|
||||
["swing_back", "", "ground", 0.16, "swing"],
|
||||
["swing", "", "ground", 0.26, "swing"],
|
||||
["throw", "powder_keg", "ground", 0.2, "throw"],
|
||||
["build", "", "ground", 0.1, "build"],
|
||||
["reload", "dock_carbine", "reload", 0.5, ""],
|
||||
["use", "brine_tonic", "use", 0.5, ""],
|
||||
["flinch", "dock_carbine", "flinch", 0.06, ""],
|
||||
]
|
||||
|
||||
var sim: Simulation
|
||||
var view: MatchView
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
sim = Simulation.new(match_seed)
|
||||
var spot: Vector3 = _open_ground()
|
||||
var rows: Array = STATES if stage == "states" else ACTIONS
|
||||
if stage == "close":
|
||||
rows = [["close", "dock_carbine", "ground", 0.6, ""]]
|
||||
var players: Array[SimEntity] = []
|
||||
for index: int in rows.size():
|
||||
players.append(_stand(_at(spot, index, rows.size()), rows[index]))
|
||||
view = MatchView.new()
|
||||
view.setup(sim, 0)
|
||||
add_child(view)
|
||||
view.entities.animate_live = false
|
||||
view.sync()
|
||||
for index: int in rows.size():
|
||||
_pose(players[index], rows[index])
|
||||
var middle: Vector3 = _at(spot, (rows.size() - 1) * 0.5 + (1.0 if rows.size() > 1 else 0.0), rows.size())
|
||||
if stage == "close":
|
||||
view.look_from(middle + Vector3(-2.0, 1.55, 2.6), middle + Vector3(0.0, 1.0, 0.0))
|
||||
else:
|
||||
var back: float = 2.0 + rows.size() * 0.42
|
||||
view.look_from(middle + Vector3(-back, 1.7, back * 0.3), middle + Vector3(0.0, 1.0, 0.0))
|
||||
view.settle()
|
||||
|
||||
|
||||
func _at(spot: Vector3, index: float, count: int) -> Vector3:
|
||||
var at: Vector3 = spot + Vector3(0.0, 0.0, (index - (count - 1) * 0.5) * 1.5 + 1.0)
|
||||
at.y = sim.ground.terrain_height(at.x, at.z)
|
||||
return at
|
||||
|
||||
|
||||
func _stand(at: Vector3, row: Array) -> SimEntity:
|
||||
var player: SimEntity = sim.entities.find(sim.add_player())
|
||||
player.position = at
|
||||
player.drop_state = Drop.NONE
|
||||
player.on_ground = true
|
||||
player.health = 100
|
||||
player.yaw = 0
|
||||
var id: String = row[1]
|
||||
if id != "":
|
||||
player.slot_items[0] = ItemCatalog.code_of(id)
|
||||
player.slot_counts[0] = 1
|
||||
player.slot_tiers[0] = 2
|
||||
player.selected = 1
|
||||
else:
|
||||
player.selected = 0
|
||||
match String(row[2]):
|
||||
"walk":
|
||||
player.velocity = Vector3(0.0, 0.0, Tuning.WALK_SPEED)
|
||||
"run":
|
||||
player.velocity = Vector3(0.0, 0.0, Tuning.SPRINT_SPEED)
|
||||
"crouch":
|
||||
player.crouching = true
|
||||
"creep":
|
||||
player.crouching = true
|
||||
player.velocity = Vector3(0.0, 0.0, Tuning.CROUCH_SPEED)
|
||||
"air":
|
||||
player.on_ground = false
|
||||
player.position.y += 0.5
|
||||
"skydive":
|
||||
player.drop_state = Drop.FREEFALL
|
||||
player.on_ground = false
|
||||
player.position.y += 0.6
|
||||
"glide":
|
||||
player.drop_state = Drop.GLIDING
|
||||
player.on_ground = false
|
||||
player.position.y += 0.4
|
||||
"swim":
|
||||
player.swimming = true
|
||||
player.on_ground = false
|
||||
"aboard":
|
||||
player.drop_state = Drop.ABOARD
|
||||
player.on_ground = false
|
||||
"reload":
|
||||
player.reload_ticks = 10
|
||||
"use":
|
||||
player.use_ticks = 10
|
||||
return player
|
||||
|
||||
|
||||
func _pose(player: SimEntity, row: Array) -> void:
|
||||
var figure: FigureRig = view.entities.figure_of(player.id)
|
||||
# The barge's deck isn't drawn here: put the passenger back where it stands.
|
||||
figure.position = player.position
|
||||
figure.drive(player, 0.0)
|
||||
figure.drive(player, 1.0)
|
||||
figure.advance(0.0)
|
||||
if String(row[2]) == "flinch":
|
||||
figure.advance(0.4)
|
||||
player.health = 70
|
||||
figure.drive(player, 0.0)
|
||||
if String(row[4]) != "":
|
||||
figure.advance(0.4)
|
||||
figure.act(row[4])
|
||||
var left: float = float(row[3])
|
||||
while left > 0.0:
|
||||
var step: float = minf(left, 1.0 / 60.0)
|
||||
figure.advance(step)
|
||||
left -= step
|
||||
|
||||
|
||||
## Fairly flat, open ground above the sea near the middle of the island.
|
||||
func _open_ground() -> Vector3:
|
||||
var size: float = Tuning.WORLD_SIZE_METRES
|
||||
var best: Vector3 = Vector3(size * 0.5, 0.0, size * 0.5)
|
||||
for ring: int in 60:
|
||||
for step: int in 24:
|
||||
var angle: float = TAU * step / 24.0
|
||||
var x: float = size * 0.5 + cos(angle) * ring * 12.0
|
||||
var z: float = size * 0.5 + sin(angle) * ring * 12.0
|
||||
var feet: Vector3 = Vector3(x, sim.ground.terrain_height(x, z), z)
|
||||
if feet.y < sim.sea_level + 3.0 or sim.ground.terrain_normal(x, z).y < 0.985:
|
||||
continue
|
||||
if not sim.props.near(feet, 12.0).is_empty():
|
||||
continue
|
||||
var level: bool = true
|
||||
for dz: float in [-7.0, 0.0, 9.0]:
|
||||
if absf(sim.ground.terrain_height(x - 2.0, z + dz) - feet.y) > 0.8:
|
||||
level = false
|
||||
if level:
|
||||
return feet
|
||||
return best
|
||||
@@ -0,0 +1 @@
|
||||
uid://mbpyawoimo5k
|
||||
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://test/capture/figure_scene.gd" id="1"]
|
||||
|
||||
[node name="CaptureFigure" type="Node3D"]
|
||||
script = ExtResource("1")
|
||||
stage = "states"
|
||||
@@ -0,0 +1,254 @@
|
||||
extends TestCase
|
||||
|
||||
## A2: the player figure's parts and joints, its animations, and that it animates from
|
||||
## replicated state only: a client's mirrored entity (snapshot fields and FLAG_ bits)
|
||||
## and FX records.
|
||||
|
||||
var tree: SceneTree
|
||||
var figure: FigureRig
|
||||
var player: SimEntity
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
super.before_each()
|
||||
tree = Engine.get_main_loop() as SceneTree
|
||||
figure = FigureRig.new(Palette.OCHRE_RED)
|
||||
tree.root.add_child(figure)
|
||||
player = SimEntity.new(7, SimEntity.ARCHETYPE_PLAYER)
|
||||
player.health = 100
|
||||
player.on_ground = true
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
if is_instance_valid(figure):
|
||||
figure.free()
|
||||
FigureRig.clear()
|
||||
super.after_each()
|
||||
|
||||
|
||||
func test_every_part_is_built_from_the_generated_models() -> void:
|
||||
var layout: Dictionary = FigureRig.layout()
|
||||
assert_eq(layout.get("generator", ""), "tools/models/figure.py")
|
||||
for part: String in FigureRig.PART_JOINT:
|
||||
var mesh: ArrayMesh = FigureRig.part_mesh(part, Palette.OILSKIN)
|
||||
assert_not_null(mesh, "%s has a model" % part)
|
||||
if mesh == null:
|
||||
continue
|
||||
for surface: int in mesh.get_surface_count():
|
||||
var name: String = mesh.surface_get_name(surface)
|
||||
assert_true(name.begins_with("COAT") or FigureRig.COLOURS.has(name), "%s's %s is a Palette colour" % [part, name])
|
||||
assert_eq(FigureRig.colour_of("COAT", Palette.SEA_PAINT), Palette.SEA_PAINT, "the coat is the player's own")
|
||||
assert_eq(FigureRig.colour_of("SKIN", Palette.SEA_PAINT), Palette.SKIN)
|
||||
|
||||
|
||||
func test_standing_figure_is_player_sized_with_feet_on_the_ground() -> void:
|
||||
figure.drive(player, 0.0)
|
||||
figure.advance(0.0)
|
||||
var bounds: AABB = _bounds()
|
||||
assert_near(bounds.position.y, 0.0, 0.06, "feet at the origin")
|
||||
assert_near(bounds.end.y, Tuning.PLAYER_HEIGHT, 0.12, "as tall as the player's body")
|
||||
assert_true(bounds.size.x < 0.9 and bounds.size.z < 1.0, "no bigger round than a person with arms out: %s" % bounds.size)
|
||||
assert_true(figure.relative(figure.hand()).origin.x < 0.0, "the right hand is on the -X side")
|
||||
|
||||
|
||||
func test_crouching_brings_the_head_down_to_crouch_height() -> void:
|
||||
player.crouching = true
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.6)
|
||||
var top: float = _bounds().end.y
|
||||
assert_true(top < Tuning.CROUCH_HEIGHT + 0.2 and top > Tuning.CROUCH_HEIGHT - 0.35, "crouched head height %f" % top)
|
||||
|
||||
|
||||
func test_states_follow_the_replicated_flags() -> void:
|
||||
assert_eq(FigureRig.state_of(player, false), "ground")
|
||||
player.crouching = true
|
||||
assert_eq(FigureRig.state_of(player, false), "crouch")
|
||||
assert_eq(FigureRig.state_of(player, true), "air")
|
||||
player.swimming = true
|
||||
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]
|
||||
assert_eq(FigureRig.state_of(player, false), drop[1])
|
||||
|
||||
|
||||
func test_a_short_hop_off_the_ground_doesnt_flicker_into_the_air() -> void:
|
||||
player.on_ground = false
|
||||
figure.drive(player, 0.05)
|
||||
assert_eq(figure.state, "ground", "under AIR_DELAY")
|
||||
figure.drive(player, 0.1)
|
||||
assert_eq(figure.state, "air")
|
||||
player.on_ground = true
|
||||
figure.drive(player, 0.02)
|
||||
assert_eq(figure.state, "ground")
|
||||
|
||||
|
||||
func test_speed_comes_from_movement_when_velocity_isnt_replicated() -> void:
|
||||
# A mirrored player: only positions arrive, velocity stays zero.
|
||||
for step: int in 40:
|
||||
player.position = Vector3(0.0, 0.0, step * Tuning.WALK_SPEED / 30.0)
|
||||
figure.drive(player, 1.0 / 30.0)
|
||||
assert_near(figure.speed, Tuning.WALK_SPEED, 0.3)
|
||||
player.position += Vector3(80.0, 0.0, 0.0)
|
||||
figure.drive(player, 1.0 / 30.0)
|
||||
assert_true(figure.speed < Tuning.WALK_SPEED, "a teleport isn't a sprint")
|
||||
|
||||
|
||||
func test_walking_swings_the_legs_and_standing_still_doesnt() -> void:
|
||||
figure.drive(player, 0.0)
|
||||
var still: Array[float] = _leg_range(1.5)
|
||||
assert_true(still[1] - still[0] < 0.05, "idle legs barely move: %s" % [still])
|
||||
player.velocity = Vector3(0.0, 0.0, Tuning.SPRINT_SPEED)
|
||||
figure.drive(player, 0.0)
|
||||
var running: Array[float] = _leg_range(1.5)
|
||||
assert_true(running[1] - running[0] > 1.0, "running legs swing: %s" % [running])
|
||||
|
||||
|
||||
func test_every_state_poses_differently() -> void:
|
||||
var poses: Dictionary = {}
|
||||
var states: Array = [
|
||||
["ground", func() -> void: pass],
|
||||
["crouch", func() -> void: player.crouching = true],
|
||||
["swim", func() -> void: player.swimming = true],
|
||||
["skydive", func() -> void: player.drop_state = Drop.FREEFALL],
|
||||
["glide", func() -> void: player.drop_state = Drop.GLIDING],
|
||||
]
|
||||
for entry: Array in states:
|
||||
player = SimEntity.new(7, SimEntity.ARCHETYPE_PLAYER)
|
||||
player.on_ground = true
|
||||
(entry[1] as Callable).call()
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.8)
|
||||
assert_eq(figure.state, entry[0])
|
||||
poses[entry[0]] = _signature()
|
||||
for a: String in poses:
|
||||
for b: String in poses:
|
||||
if a < b:
|
||||
assert_true((poses[a] as Vector3).distance_to(poses[b]) > 0.15, "%s and %s look different" % [a, b])
|
||||
|
||||
|
||||
func test_glide_shows_the_sail_and_hides_the_held_item() -> void:
|
||||
player.drop_state = Drop.GLIDING
|
||||
player.on_ground = false
|
||||
figure.drive(player, 0.0)
|
||||
assert_true(figure.sail().visible)
|
||||
assert_false(figure.hand().visible)
|
||||
|
||||
|
||||
func test_fx_play_the_actions_on_the_upper_body() -> void:
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.3)
|
||||
var before: Quaternion = (figure.joints["shoulder_r"] as Node3D).quaternion
|
||||
figure.hear({"kind": NetFx.SHOT, "item": -1, "player": 7})
|
||||
assert_false(figure.acting(), "starts on the next step")
|
||||
_run(0.16)
|
||||
assert_true(figure.acting(), "a boathook swing plays")
|
||||
var during: Quaternion = (figure.joints["shoulder_r"] as Node3D).quaternion
|
||||
assert_true(before.angle_to(during) > 0.5, "the arm swings back")
|
||||
_run(0.6)
|
||||
assert_false(figure.acting(), "and finishes")
|
||||
figure.hear({"kind": NetFx.PLACE, "item": -1, "player": 7, "piece": 3})
|
||||
_run(0.1)
|
||||
assert_true(figure.acting(), "placing a piece plays the mallet")
|
||||
_run(0.6)
|
||||
figure.hear({"kind": NetFx.SHOT, "item": ItemCatalog.code_of("dock_carbine"), "player": 7})
|
||||
_run(0.05)
|
||||
assert_true(figure.acting(), "a shot kicks")
|
||||
|
||||
|
||||
func test_swimming_figures_dont_act() -> void:
|
||||
player.swimming = true
|
||||
figure.drive(player, 0.0)
|
||||
figure.hear({"kind": NetFx.SHOT, "item": -1, "player": 7})
|
||||
_run(0.1)
|
||||
assert_false(figure.acting())
|
||||
|
||||
|
||||
func test_losing_health_flinches_and_reloading_moves_the_left_arm() -> void:
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.3)
|
||||
player.health = 80
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.05)
|
||||
assert_true(figure.acting(), "a flinch")
|
||||
_run(0.5)
|
||||
player.slot_items = PackedInt32Array([ItemCatalog.code_of("dock_carbine")])
|
||||
player.slot_tiers = PackedInt32Array([1])
|
||||
player.selected = 1
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.4)
|
||||
var resting: Quaternion = (figure.joints["elbow_l"] as Node3D).quaternion
|
||||
player.reload_ticks = 1
|
||||
figure.drive(player, 0.0)
|
||||
_run(0.4)
|
||||
assert_true(resting.angle_to((figure.joints["elbow_l"] as Node3D).quaternion) > 0.4, "the left hand goes to the breech")
|
||||
|
||||
|
||||
func test_holds_by_item() -> void:
|
||||
assert_eq(FigureRig.hold_of(-1), "long", "the boathook in both hands")
|
||||
assert_eq(FigureRig.hold_of(ItemCatalog.code_of("whalers_longgun")), "long")
|
||||
assert_eq(FigureRig.hold_of(ItemCatalog.code_of("signal_revolver")), "short")
|
||||
assert_eq(FigureRig.hold_of(ItemCatalog.code_of("brine_tonic")), "carry")
|
||||
assert_eq(FigureRig.hold_of(ItemCatalog.code_of("powder_keg")), "carry")
|
||||
|
||||
|
||||
func test_the_held_item_points_along_the_look_whatever_the_arm_does() -> void:
|
||||
player.pitch = -PlayerCommand.PITCH_MAX / 3
|
||||
player.velocity = Vector3(0.0, 0.0, Tuning.SPRINT_SPEED)
|
||||
figure.drive(player, 0.0)
|
||||
var pitch: float = float(player.pitch) / PlayerCommand.PITCH_MAX * (PI * 0.5)
|
||||
for step: int in 20:
|
||||
_run(0.05)
|
||||
var muzzle: Vector3 = figure.hand_basis() * Vector3(0.0, 0.0, 1.0)
|
||||
assert_near(muzzle.y, sin(pitch), 0.02, "step %d" % step)
|
||||
assert_near(muzzle.x, 0.0, 0.02)
|
||||
|
||||
|
||||
func test_mirrored_players_carry_reload_and_use_flags() -> void:
|
||||
var record: PackedInt32Array = NetSnapshot.record_of(player)
|
||||
player.reload_ticks = 9
|
||||
record = NetSnapshot.record_of(player)
|
||||
assert_true(record[NetSnapshot.R_FLAGS] & NetSnapshot.FLAG_RELOADING != 0)
|
||||
|
||||
|
||||
func _run(seconds: float) -> void:
|
||||
var left: float = seconds
|
||||
while left > 0.0:
|
||||
var step: float = minf(left, 1.0 / 30.0)
|
||||
figure.advance(step)
|
||||
left -= step
|
||||
|
||||
|
||||
## The lowest and highest the right thigh turns over a time.
|
||||
func _leg_range(seconds: float) -> Array[float]:
|
||||
var low: float = INF
|
||||
var high: float = -INF
|
||||
var left: float = seconds
|
||||
while left > 0.0:
|
||||
figure.advance(1.0 / 30.0)
|
||||
left -= 1.0 / 30.0
|
||||
var turn: float = (figure.joints["hip_r"] as Node3D).rotation.x
|
||||
low = minf(low, turn)
|
||||
high = maxf(high, turn)
|
||||
return [low, high]
|
||||
|
||||
|
||||
## Where the head and both hands are, summed into one vector to compare poses.
|
||||
func _signature() -> Vector3:
|
||||
var head: Vector3 = figure.relative(figure.joints["neck"]).origin
|
||||
var hand_l: Vector3 = figure.relative(figure.joints["elbow_l"]).origin
|
||||
var knee: Vector3 = figure.relative(figure.joints["knee_r"]).origin
|
||||
return head * 1.0 + hand_l * 0.5 + knee * 0.25
|
||||
|
||||
|
||||
## The figure's drawn bounds, in its own space, from every part's mesh.
|
||||
func _bounds() -> AABB:
|
||||
var out: AABB = AABB()
|
||||
var first: bool = true
|
||||
for node: Node in figure.find_children("*", "MeshInstance3D", true, false):
|
||||
var part: MeshInstance3D = node
|
||||
if part.mesh == null or not part.is_visible_in_tree() or part.name == "sail":
|
||||
continue
|
||||
var box: AABB = figure.relative(part) * part.mesh.get_aabb()
|
||||
out = box if first else out.merge(box)
|
||||
first = false
|
||||
return out
|
||||
@@ -0,0 +1 @@
|
||||
uid://2s5dkcs4jit0
|
||||
@@ -91,20 +91,22 @@ func test_figures_hold_their_players_item_in_the_right_hand() -> void:
|
||||
var player: SimEntity = made[1]
|
||||
var view: EntityView = EntityView.new()
|
||||
view.setup(sim)
|
||||
var figure: Node3D = view.figure_of(player.id)
|
||||
var held: MeshInstance3D = figure.get_node("Hand/Held")
|
||||
var figure: FigureRig = view.figure_of(player.id)
|
||||
var held: MeshInstance3D = figure.held()
|
||||
assert_eq(held.mesh, ItemModels.model("whalers_longgun", 3))
|
||||
assert_true((figure.get_node("Hand") as Node3D).position.x < 0.0, "the right hand, on the figure's -X side")
|
||||
assert_true(figure.relative(figure.hand()).origin.x < 0.0, "the right hand, on the figure's -X side")
|
||||
player.selected = 0
|
||||
view.sync()
|
||||
assert_eq(held.mesh, ItemModels.model("boathook", 1), "the boathook when nothing else is held")
|
||||
player.pitch = PlayerCommand.PITCH_MAX / 2
|
||||
view.sync()
|
||||
var muzzle: Vector3 = (figure.get_node("Hand") as Node3D).transform.basis * Vector3(0.0, 0.0, 1.0)
|
||||
figure.drive(player, 0.1)
|
||||
figure.advance(0.1)
|
||||
var muzzle: Vector3 = figure.hand_basis() * Vector3(0.0, 0.0, 1.0)
|
||||
assert_true(muzzle.y > 0.5, "looking up points the item up")
|
||||
player.drop_state = Drop.GLIDING
|
||||
view.sync()
|
||||
assert_false((figure.get_node("Hand") as Node3D).visible, "both hands on the wing-sail")
|
||||
assert_false(figure.hand().visible, "both hands on the wing-sail")
|
||||
view.free()
|
||||
|
||||
|
||||
|
||||
@@ -48,14 +48,15 @@ func test_gliding_players_show_a_wing_sail() -> void:
|
||||
var view: MatchView = MatchView.new()
|
||||
view.setup(loop.sim, 1)
|
||||
var bot: SimEntity = loop.sim.entities.find(2)
|
||||
assert_false((view.entities.figure_of(2).get_node("Sail") as Node3D).visible)
|
||||
assert_false(view.entities.figure_of(2).sail().visible)
|
||||
var guard: int = 0
|
||||
while bot.drop_state != Drop.GLIDING and guard < 3000:
|
||||
loop.run_tick()
|
||||
guard += 1
|
||||
view.sync()
|
||||
view.entities.animate(0.1)
|
||||
assert_eq(bot.drop_state, Drop.GLIDING)
|
||||
assert_true((view.entities.figure_of(2).get_node("Sail") as Node3D).visible)
|
||||
assert_true(view.entities.figure_of(2).sail().visible)
|
||||
view.free()
|
||||
|
||||
|
||||
|
||||
+18
-3
@@ -1,6 +1,7 @@
|
||||
extends TestCase
|
||||
|
||||
## Issue N11: shots, impacts and swings on the wire (NetFx).
|
||||
## Issue N11: shots, impacts and swings on the wire (NetFx). A2 added boathook swings
|
||||
## that miss (a SHOT with no item) and pieces placed (PLACE), for the figures.
|
||||
|
||||
|
||||
func _records() -> Array[Dictionary]:
|
||||
@@ -9,6 +10,7 @@ func _records() -> Array[Dictionary]:
|
||||
{"kind": NetFx.IMPACT, "tick": 401, "player": 3, "item": 2, "position": Vector3(130.0, 11.0, 220.0), "hit": Weapons.HIT_PLAYER, "target": 700},
|
||||
{"kind": NetFx.HARVEST, "tick": 402, "player": 4, "item": -1, "position": Vector3(50.0, 9.0, 60.0), "prop": 12, "piece": 0},
|
||||
{"kind": NetFx.HARVEST, "tick": 402, "player": 5, "item": -1, "position": Vector3(51.0, 9.0, 61.0), "prop": -1, "piece": 33},
|
||||
{"kind": NetFx.PLACE, "tick": 402, "player": 6, "item": -1, "position": Vector3(52.0, 10.5, 62.5), "piece": 41},
|
||||
]
|
||||
|
||||
|
||||
@@ -18,8 +20,8 @@ func test_records_survive_the_trip() -> void:
|
||||
assert_false(message.is_empty())
|
||||
assert_eq(message["tick"], 402)
|
||||
var events: Array = message["events"]
|
||||
assert_eq(events.size(), 4)
|
||||
for index: int in 4:
|
||||
assert_eq(events.size(), 5)
|
||||
for index: int in 5:
|
||||
var sent: Dictionary = _records()[index]
|
||||
var got: Dictionary = events[index]
|
||||
for key: String in sent:
|
||||
@@ -64,3 +66,16 @@ func test_malformed_messages_are_refused() -> void:
|
||||
var bad_kind: PackedByteArray = bytes.duplicate()
|
||||
bad_kind[NetFx.HEADER_BYTES] = 9
|
||||
assert_true(NetFx.decode(bad_kind).is_empty(), "unknown kind")
|
||||
|
||||
|
||||
func test_swings_and_placed_pieces_from_the_simulation() -> void:
|
||||
var swing: Dictionary = NetFx.from_event({"type": "swing", "player": 9, "from": Vector3(1.0, 2.0, 3.0), "direction": Vector3.FORWARD}, 80)
|
||||
assert_eq(swing["kind"], NetFx.SHOT)
|
||||
assert_eq(swing["item"], -1, "a swing is a shot with no item")
|
||||
var placed: Dictionary = NetFx.from_event({"type": "piece_placed", "player": 9, "piece": 12, "kind": 0, "material": 0}, 80, {9: Vector3.ONE}, {12: Vector3(4.0, 5.0, 6.0)})
|
||||
assert_eq(placed["kind"], NetFx.PLACE)
|
||||
assert_eq(placed["piece"], 12)
|
||||
assert_eq(placed["position"], Vector3(4.0, 5.0, 6.0), "at the piece")
|
||||
var unknown: Dictionary = NetFx.from_event({"type": "piece_placed", "player": 9, "piece": 13}, 80, {9: Vector3.ONE})
|
||||
assert_eq(unknown["position"], Vector3.ONE, "at the builder, without the piece's centre")
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func test_a_hit_yields_the_props_material_and_damages_it() -> void:
|
||||
assert_eq(player.materials[Materials.DRIFTWOOD], Tuning.HARVEST_PER_HIT)
|
||||
assert_eq(player.materials[Materials.STONE], 0)
|
||||
assert_eq(sim.props.health[0], 200 - Tuning.HARVEST_DAMAGE)
|
||||
assert_eq(sim.events[0]["material"], Materials.DRIFTWOOD)
|
||||
assert_eq(_harvest(sim)["material"], Materials.DRIFTWOOD)
|
||||
|
||||
|
||||
func test_each_prop_kind_gives_its_own_material() -> void:
|
||||
@@ -93,7 +93,7 @@ func test_looking_away_misses() -> void:
|
||||
for _i: int in 1:
|
||||
sim.submit_command(1, PlayerCommand.from_input(sim.tick, Vector2.ZERO, PI, 0.0, PlayerCommand.BUTTON_FIRE))
|
||||
sim.step()
|
||||
hits += sim.events.size()
|
||||
hits += sim.events.filter(func(event: Dictionary) -> bool: return event["type"] != "swing").size()
|
||||
assert_eq(hits, 0)
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ func test_carry_cap_stops_gains_but_not_damage() -> void:
|
||||
player.materials[Materials.STONE] = Tuning.MATERIAL_CAP - 5
|
||||
_swing_for(sim, 1)
|
||||
assert_eq(player.materials[Materials.STONE], Tuning.MATERIAL_CAP)
|
||||
assert_eq(sim.events[0]["amount"], 5, "the event reports what was actually gained")
|
||||
assert_eq(_harvest(sim)["amount"], 5, "the event reports what was actually gained")
|
||||
_swing_for(sim, Harvest.swing_interval_ticks())
|
||||
assert_eq(player.materials[Materials.STONE], Tuning.MATERIAL_CAP, "never over the cap")
|
||||
assert_eq(sim.props.health[0], 400 - Tuning.HARVEST_DAMAGE * 2, "capped players still damage props")
|
||||
@@ -199,3 +199,30 @@ func test_harvesting_on_a_real_island_is_deterministic() -> void:
|
||||
assert_eq(gained, Tuning.HARVEST_PER_HIT * 2, "two swings at a real pine")
|
||||
hashes.append(sim.state_hash())
|
||||
assert_eq(hashes[0], hashes[1])
|
||||
|
||||
|
||||
## This tick's harvest event; every swing also makes a "swing" event before it.
|
||||
func _harvest(sim: Simulation) -> Dictionary:
|
||||
for event: Dictionary in sim.events:
|
||||
if event["type"] == "harvest":
|
||||
return event
|
||||
return {}
|
||||
|
||||
|
||||
func test_every_swing_reports_itself_hit_or_miss() -> void:
|
||||
var sim: Simulation = Simulation.new(5, SimGround.flat(0.0))
|
||||
var player: SimEntity = sim.entities.find(sim.add_player())
|
||||
player.drop_state = Drop.NONE
|
||||
player.on_ground = true
|
||||
player.position = Vector3(10.0, 0.0, 10.0)
|
||||
player.pitch = PlayerCommand.PITCH_MAX / 2
|
||||
var events: Array[Dictionary] = []
|
||||
Harvest.swing(player, sim.ground, sim.props, events, sim.structures)
|
||||
assert_eq(events.size(), 1, "a miss: %s" % [events])
|
||||
assert_eq(events[0]["type"], "swing")
|
||||
assert_eq(events[0]["player"], player.id)
|
||||
var direction: Vector3 = events[0]["direction"]
|
||||
assert_true(direction.y > 0.5, "along the look")
|
||||
Harvest.swing(player, sim.ground, sim.props, events, sim.structures)
|
||||
assert_eq(events.size(), 1, "not again until the boathook is ready")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user