## Capture scenario for visual effects (A7), on seed 2's island in the real MatchView. ## Effects are stepped by hand to a chosen moment (EffectsView.live off), so each ## picture shows the same instant every time. ## ## - fight: over the shoulder of a player firing a carbine at another 11 m off: the ## muzzle flash, the tracer on its way and the burst on the target, with the HUD's ## reticle and hit marker. ## - blast: a powder keg going off beside a stone wall, while a driftwood wall nearby ## comes down in dust, seen from the side. ## - work: the quieter effects together: a piece set down in a ring of dust, chips ## from a harvest swing, shots striking stone and ground, and a splash. ## - stress: 24 players emptying repeaters at a fort while kegs go off, with the ## effects pool at its largest budget; the capture's render line reports the draw ## calls, and the log line the particles alive against the budget. extends Node3D @export var stage: String = "fight" @export var match_seed: int = 2 const FRAME: float = 1.0 / 60.0 var sim: Simulation var view: MatchView var spot: Vector3 func _ready() -> void: sim = Simulation.new(match_seed) spot = _open_ground() var shooter: SimEntity = null var target: SimEntity = null var walls: Array[StructureSet.Piece] = [] match stage: "fight": shooter = _player(spot, "dock_carbine", 0) target = _player(spot + Vector3(1.2, 0.0, 11.0), "rivet_repeater", 32768) "blast": walls.append(_wall(spot + Vector3(0.0, 0.0, 6.0), Materials.STONE)) walls.append(_wall(spot + Vector3(-6.0, 0.0, 6.0), Materials.DRIFTWOOD)) "work": _player(spot + Vector3(-2.0, 0.0, 4.0), "", 0) walls.append(_wall(spot + Vector3(2.0, 0.0, 8.0), Materials.STONE)) "stress": for index: int in 6: walls.append(_wall(spot + Vector3(index * 4.0 - 10.0, 0.0, 16.0), index % 3)) for index: int in 24: _player(spot + Vector3(index * 1.2 - 14.0, 0.0, -2.0 - (index % 2) * 2.0), "rivet_repeater", 0) view = MatchView.new() view.setup(sim, 0) add_child(view) view.effects.live = false view.entities.animate_live = false view.sync() match stage: "fight": view.rig.aim_blend = 1.0 view.follow(shooter.id, deg_to_rad(2.0)) "blast": view.look_from(spot + Vector3(-4.0, 3.5, -10.0), spot + Vector3(-3.0, 1.6, 5.0)) "work": view.look_from(spot + Vector3(-5.0, 3.2, -4.5), spot + Vector3(0.5, 0.8, 5.0)) "stress": view.look_from(spot + Vector3(-22.0, 9.0, -14.0), spot + Vector3(0.0, 1.0, 8.0)) view.settle() view.entities.animate(0.5) view.effects.sync(sim, view.camera.global_position) await get_tree().process_frame match stage: "fight": _fight(shooter, target) "blast": _blast(walls) "work": _work(walls[0]) "stress": _stress(walls) var effects: EffectsView = view.effects print(JSON.stringify({"stage": stage, "particles": effects.particle_count(), "budget": effects.budget, "peak": effects.peak, "dropped": effects.dropped, "tracers": effects.tracer_count(), "lights": effects.light_count()})) func _fight(shooter: SimEntity, target: SimEntity) -> void: var eye: Vector3 = Harvest.eye(shooter) var chest: Vector3 = target.position + Vector3(0.0, 1.25, 0.0) var aim: Vector3 = (chest - eye).normalized() var records: Array[Dictionary] = [ {"kind": NetFx.SHOT, "tick": 10, "player": shooter.id, "item": ItemCatalog.code_of("dock_carbine"), "position": eye, "yaw": atan2(aim.x, aim.z), "pitch": asin(aim.y)}, {"kind": NetFx.IMPACT, "tick": 10, "player": shooter.id, "item": ItemCatalog.code_of("dock_carbine"), "position": chest - aim * 0.25, "hit": Weapons.HIT_PLAYER, "target": target.id}, ] view.effects.hear(records) view.effects.advance(0.025) var hud: Hud = Hud.new() add_child(hud) var state: HudState = HudState.new() state.playing = true state.reticle = true state.health = 100 state.hit = 0.85 hud.show_state(state) func _blast(walls: Array[StructureSet.Piece]) -> void: var at: Vector3 = spot + Vector3(-1.5, 0.0, 2.5) at.y = sim.ground.terrain_height(at.x, at.z) + 0.3 view.effects.hear([{"kind": NetFx.IMPACT, "tick": 10, "player": 1, "item": ItemCatalog.code_of("powder_keg"), "position": at, "hit": Weapons.HIT_NONE, "target": 0}] as Array[Dictionary]) view.effects.advance(0.08) sim.structures.remove(walls[1].id, sim.ground) view.sync() view.effects.advance(0.1) func _work(wall: StructureSet.Piece) -> void: var effects: EffectsView = view.effects var floor_at: Vector3 = spot + Vector3(-2.5, 0.0, 9.0) var g: float = Tuning.GRID_CELL_METRES var cell: Vector3i = Vector3i(floori(floor_at.x / g), floori(floor_at.y / Tuning.BUILD_LEVEL_METRES), floori(floor_at.z / g)) var placed: StructureSet.Piece = sim.structures.add(StructureSet.FLOOR, Materials.DRIFTWOOD, Vector4i(cell.x, cell.y, cell.z, StructureSet.SLOT_FLOOR), 0, 0, sim.tick, sim.ground) placed.build_ticks_left = 0 view.sync() var stone: Vector3 = wall.boxes[0].get_center() + Vector3(0.0, 0.4, -wall.boxes[0].size.z * 0.5) var ground: Vector3 = spot + Vector3(1.0, 0.0, 3.0) ground.y = sim.ground.terrain_height(ground.x, ground.z) var records: Array[Dictionary] = [ {"kind": NetFx.PLACE, "tick": 10, "player": 1, "item": -1, "position": placed.boxes[0].get_center(), "piece": placed.id}, {"kind": NetFx.HARVEST, "tick": 10, "player": 1, "item": -1, "position": spot + Vector3(-2.0, sim.ground.terrain_height(spot.x - 2.0, spot.z + 4.0) - spot.y, 4.0) + Vector3(0.0, 0.0, 0.8), "prop": -1, "piece": wall.id}, {"kind": NetFx.IMPACT, "tick": 10, "player": 1, "item": ItemCatalog.code_of("dock_carbine"), "position": stone + Vector3(1.2, 0.3, 0.0), "hit": Weapons.HIT_PIECE, "target": wall.id}, {"kind": NetFx.IMPACT, "tick": 10, "player": 1, "item": ItemCatalog.code_of("dock_carbine"), "position": ground, "hit": Weapons.HIT_TERRAIN, "target": 0}, ] effects.hear(records) var water: Vector3 = spot + Vector3(3.5, 0.0, 2.0) effects.splash(Vector3(water.x, sim.ground.terrain_height(water.x, water.z) + 0.05, water.z), 1.0) effects.advance(0.15) func _stress(walls: Array[StructureSet.Piece]) -> void: var effects: EffectsView = view.effects effects.budget = EffectsView.MAX_PARTICLES var shooters: Array[SimEntity] = [] for entity: SimEntity in sim.entities.entities(): if entity.archetype == SimEntity.ARCHETYPE_PLAYER: shooters.append(entity) var tick: int = 10 for frame: int in 90: var records: Array[Dictionary] = [] for shooter: SimEntity in shooters: var eye: Vector3 = Harvest.eye(shooter) var wall: StructureSet.Piece = walls[shooter.id % walls.size()] var to: Vector3 = wall.boxes[0].get_center() + Vector3(0.0, (shooter.id % 5) * 0.3 - 0.6, -wall.boxes[0].size.z * 0.5) var aim: Vector3 = (to - eye).normalized() records.append({"kind": NetFx.SHOT, "tick": tick, "player": shooter.id, "item": ItemCatalog.code_of("rivet_repeater"), "position": eye, "yaw": atan2(aim.x, aim.z), "pitch": asin(aim.y)}) records.append({"kind": NetFx.IMPACT, "tick": tick, "player": shooter.id, "item": ItemCatalog.code_of("rivet_repeater"), "position": to, "hit": Weapons.HIT_PIECE, "target": wall.id}) if frame % 15 == 0: var keg: Vector3 = spot + Vector3(frame * 0.2 - 8.0, 0.0, 12.0) keg.y = sim.ground.terrain_height(keg.x, keg.z) + 0.3 records.append({"kind": NetFx.IMPACT, "tick": tick, "player": shooters[0].id, "item": ItemCatalog.code_of("powder_keg"), "position": keg, "hit": Weapons.HIT_NONE, "target": 0}) effects.hear(records) effects.advance(FRAME) tick += 1 func _player(at: Vector3, item: String, yaw: int) -> SimEntity: var player: SimEntity = sim.entities.find(sim.add_player()) player.position = Vector3(at.x, sim.ground.terrain_height(at.x, at.z), at.z) player.drop_state = Drop.NONE player.on_ground = true player.health = 100 player.yaw = yaw if item != "": player.slot_items[0] = ItemCatalog.code_of(item) player.slot_counts[0] = 1 player.slot_tiers[0] = 1 player.selected = 1 return player func _wall(at: Vector3, material: int) -> StructureSet.Piece: var g: float = Tuning.GRID_CELL_METRES var y: float = sim.ground.terrain_height(at.x, at.z) var cell: Vector3i = Vector3i(floori(at.x / g), floori(y / Tuning.BUILD_LEVEL_METRES), floori(at.z / g)) var wall: StructureSet.Piece = sim.structures.add(StructureSet.WALL, material, Vector4i(cell.x, cell.y, cell.z, StructureSet.SLOT_WALL_Z), 0, 0, sim.tick, sim.ground) wall.build_ticks_left = 0 wall.health = wall.max_health return wall ## Fairly flat, open ground above the sea near the middle of the island. func _open_ground() -> Vector3: var size: float = Tuning.WORLD_SIZE_METRES 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, 16.0).is_empty(): continue var level: bool = true for dz: float in [-7.0, 0.0, 9.0, 16.0]: if absf(sim.ground.terrain_height(x - 2.0, z + dz) - feet.y) > 0.8: level = false # Open sky and a clear line down the range: not inside a building. var chest: Vector3 = feet + Vector3(0.0, 1.4, 0.0) if level and sim.ground.raycast(chest + Vector3(0.0, 30.0, 0.0), chest) >= 1.0 \ and sim.ground.raycast(chest, chest + Vector3(0.0, 0.0, 16.0)) >= 1.0 \ and sim.ground.raycast(chest + Vector3(-12.0, 0.0, 0.0), chest + Vector3(12.0, 0.0, 0.0)) >= 1.0: return feet return Vector3(size * 0.5, 0.0, size * 0.5)