Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/engine/players.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ The host runs a pilot's command in each frame's pass and again in each step's pa
trigger fires in both. Every press, including the gun and power keys and the devices, acts
once, in the step's pass that uses it up.

A client also fires its own guns from the held trigger, so the shot leaves the muzzle at once,
and charges its own Nova Cannon, so the display's charge arc fills. Letting go spends the charge
on the client too, as the host's release does, and the host's beam then shows (`predictOwnGuns`).

Submitted commands advance locks on the game frame, including on a headless host. Local
single-player controls keep the existing camera and wormhole checks, button latches and input
order.
Expand All @@ -345,7 +349,8 @@ The host follows the original's rules for a multiplayer mission, an arena: CLOAK
there (`player_cloak_set`, `0x004153EA`), where the cloak is a power-up's, and SPECTRAL SHIELDS is
passed over (`0x00414E92`). ECM has no such test and works in every game. In a co-op mission all
three work, and the views carry whether each pilot's ship is cloaked, as they do in an arena with
power-ups.
power-ups. The host treats a ship's cloak as its cloak device's only outside an arena, so the
power-up's cloak and the Shadow's never use up the device's charge, and never end when it runs out.

The HUD and scripting instruments read the displayed participant's charges from the snapshot.
Local input keeps its existing device timing and presentation. The rules and original addresses
Expand Down Expand Up @@ -383,6 +388,10 @@ copy of the shot there and shows what single player shows: the shield's flare, t
or a component's sparks, or a Huge Gun's fireball (`guns.showImpact`). The client doesn't know the
face a shot crossed, so a component's sparks fly back along the shot's path.

A client doesn't test collisions either. When a pilot's ship knocks into something and its
shield takes the knock, the host sends the shield's flare to every client, which shows it as
single player does (`collision.knockFlare`).

Co-op taunts, missile warnings, kill remarks and friendly-fire warnings follow the affected
pilot's binding. The host keeps each warning's state and runs the `radio_say` hook. The receiving
radio applies the checks and deadlines for each type of line. See [Radio remarks](radio.md#remarks)
Expand Down
25 changes: 22 additions & 3 deletions src/engine/game/collision.zig
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,16 @@ fn knockDamage(world: gameobj.World, index: u16, struck: Quadrant, value: f32, d
if (state.shield_reserves.spare(struck, drain)) return;
}
if (object.shields.get(struck) < 0) return armorDamage(world, index, struck, value, attacker, .collision);
if (flare == .before) shield.flare(world, index, contact);
if (flare == .before) knockFlare(world, index, contact);
damage(world, index, struck, value, 1, attacker, .collision);
if (flare == .after) shield.flare(world, index, contact);
if (flare == .after) knockFlare(world, index, contact);
}

/// The shield of the object in slot `index` flares at `contact` (`shield.flare`), and a network
/// game's host sends the flare to its clients, which don't test collisions.
fn knockFlare(world: gameobj.World, index: u16, contact: Vector) void {
shield.flare(world, index, contact);
if (world.gun_effects != null) @as(guns.FlightEffect, .{ .knock = .{ .target = .of(world.objects, index), .at = contact } }).emit(world);
}

/// The game's difficulty (`0x00562F14`), which SET GAME DIFFICULTY starts at medium and steps
Expand Down Expand Up @@ -1463,7 +1470,17 @@ test knockDamage {
var mission: gameobj.testing.Mission = undefined;
try mission.init(gpa);
defer mission.deinit();
const world = mission.world();
// A host sends each flare to its clients.
const Sent = struct {
knocks: usize = 0,
fn send(context: *anyopaque, effect: guns.FlightEffect) void {
const sent: *@This() = @ptrCast(@alignCast(context));
if (effect == .knock) sent.knocks += 1;
}
};
var sent: Sent = .{};
var world = mission.world();
world.gun_effects = .{ .context = &sent, .send = Sent.send };
const player = try testing.ship(&mission, @splat(0), 100);
const other = try testing.ship(&mission, .{ 0, 0, 1000 }, 100);
const object = &mission.slot(player).object;
Expand All @@ -1482,12 +1499,14 @@ test knockDamage {
try std.testing.expectEqual(0, mission.objects.player_states[mission.objects.player].shield_reserves.fore);
try std.testing.expectEqual(35, object.shields.fore);
try std.testing.expectEqual(mission.clock.frame_start, bubble.struck);
try std.testing.expectEqual(1, sent.knocks);
// With the shield down the armour takes it, twice halved, and nothing flares.
bubble.struck = null;
object.shields.aft = -1;
knockDamage(world, player, .aft, 40, 40, other, .{ 0, 0, -100 }, .after);
try std.testing.expectEqual(40, object.armor.aft);
try std.testing.expectEqual(null, bubble.struck);
try std.testing.expectEqual(1, sent.knocks);
}

test armorDamage {
Expand Down
4 changes: 4 additions & 0 deletions src/engine/game/guns.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ pub const FlightEffect = union(enum(u8)) {
impact: Impact,
nova: Nova,
wall: @import("deathmatch.zig").Boundary.Impact,
knock: Knock,

pub const Shot = struct {
index: u8,
Expand All @@ -1347,6 +1348,9 @@ pub const FlightEffect = union(enum(u8)) {

pub const Nova = struct { owner: gameobj.ObjectRef, charge: f32, fired_at: i32 };

/// A shield that flared where its ship knocked into something (`collision.knockDamage`).
pub const Knock = struct { target: gameobj.ObjectRef, at: Vector };

pub const Sink = struct {
context: *anyopaque,
send: *const fn (*anyopaque, FlightEffect) void,
Expand Down
33 changes: 32 additions & 1 deletion src/engine/game/ship_devices.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,33 @@ test {
std.testing.refAllDecls(@This());
}

test "an arena's cloak spends none of the cloak device's charge" {
const gpa = std.testing.allocator;
var stage: cloak.testing.Cloaked = undefined;
try stage.init(gpa);
defer stage.deinit(gpa);
const slot = stage.slot();
const charges = &stage.mission.objects.player_states[stage.index].charges;
charges.getPtr(.cloak).setting = .off;
var world = stage.mission.world();
cloak.beginPowerUp(world, stage.index);

// Out of an arena, the host counts the cloak as the device's, and it runs dry.
charges.getPtr(.cloak).ticks = 1;
advance(world, stage.index, 10, .host);
try std.testing.expect(slot.cloak.?.going);

// In an arena, it is the power-up's or the Shadow's, and stays on.
slot.cloak = null;
slot.object.flags.cloaked = false;
cloak.beginPowerUp(world, stage.index);
world.damage_rules = .{ .arena = null };
charges.getPtr(.cloak).* = .{ .setting = .off, .ticks = 1 };
advance(world, stage.index, 10, .host);
try std.testing.expect(!slot.cloak.?.going);
try std.testing.expectEqual(.off, charges.get(.cloak).setting);
}

/// Local input keeps the existing charge rules. The host also checks each submitted activation.
pub const Control = enum { local, host };

Expand Down Expand Up @@ -143,9 +170,13 @@ pub fn advance(world: gameobj.World, index: u16, elapsed: i32, control: Control)
const charges = &all.player_states[index].charges;
if (charges.getPtr(.ecm).run(.ecm, elapsed)) input.setEcm(charges, object, false);

// The host reads the device's setting from the ship's cloak. In an arena the device never
// turns on (`toggle`), so a cloak there is the power-up's or the Shadow's and spends none of
// the device's charge, as the original's charge runs only while CLOAK SHIP has it on.
const cloaking = charges.getPtr(.cloak);
if (control == .host and cloaking.setting != .absent) {
cloaking.setting = if (slot.cloak) |active| (if (active.going) .off else .on) else .off;
const device_on = if (slot.cloak) |active| !active.going else false;
cloaking.setting = if (device_on and world.damage_rules != .arena) .on else .off;
}
if (cloaking.run(.cloak, elapsed)) switch (control) {
.local => cloak.set(world, index, false),
Expand Down
20 changes: 18 additions & 2 deletions src/engine/input.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2182,13 +2182,18 @@ fn fireGuns(world: gameobj.World, index: u16, held: bool, source: WeaponSource)
/// The client's held trigger for its own ship, fired through the same gun path single player
/// fires with: the bolt, its flash and its sound leave the muzzle at once, while the host alone
/// decides what the shot does and what firing costs (Overwatch GDC 2017). The cloak rule stays
/// out: that outcome is the host's word.
/// out: that outcome is the host's word. Letting go spends the Nova Cannon's charge, as the host's
/// release does (`guns.nova.release`), so the display's charge arc fills again from nothing. The
/// host's beam shows through its own effect.
pub fn predictOwnGuns(world: gameobj.World, index: u16, held: bool) void {
const all = world.objects;
const slot = &all.slots[index];
const object = &slot.object;
if (object.flags.stand_in or object.flags.disabled or object.flags.outOfFrame() or object.flags.jumping) return;
if (!held) return;
if (!held) {
object.nova_charge = 0;
return;
}
if (index == all.player) if (world.display) |display| {
_ = display.windows.open(.gunnery, false);
};
Expand Down Expand Up @@ -3486,6 +3491,17 @@ test "the burns last while their keys are held, and stop without fuel" {
try std.testing.expect(!object.reverse_thrust);
}

test "letting go of the trigger spends the client's Nova Cannon charge" {
const gpa = std.testing.allocator;
var stage: cloak.testing.Cloaked = undefined;
try stage.init(gpa);
defer stage.deinit(gpa);
const object = &stage.slot().object;
object.nova_charge = 1;
predictOwnGuns(stage.mission.world(), stage.index, false);
try std.testing.expectEqual(0, object.nova_charge);
}

test "the player's cloak" {
const gpa = std.testing.allocator;
var stage: cloak.testing.Cloaked = undefined;
Expand Down
1 change: 1 addition & 0 deletions src/openreliant/network/arena.zig
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ fn noteCombat(context: *anyopaque, effect: game.guns.FlightEffect) void {
if (shot.owner >= wire.slots and arena.mode.scenario() == null) return;
},
.nova => |beam| if (beam.owner.slot >= wire.slots) return,
.knock => |knock| if (knock.target.slot >= wire.slots) return,
.impact, .wall => {},
}
if (arena.combat_count == arena.combat.len) return;
Expand Down
1 change: 1 addition & 0 deletions src/openreliant/network/flight_frame.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ pub fn presentCombat(frame: *FlightFrame, effects: []const game.guns.FlightEffec
wall.present(scene);
if (wall.flare) frame.wall.add(wall);
},
.knock => |knock| if (frame.remoteShip(knock.target)) |index| game.shield.flare(scene, index, knock.at),
};
game.guns.frameReplicas(scene);
}
Expand Down
16 changes: 13 additions & 3 deletions src/openreliant/network/wire.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const Debrief = campaign.Debrief;
pub const DebriefChoice = campaign.DebriefChoice;
pub const NextMission = campaign.NextMission;
pub const CampaignCheckpoint = campaign.Checkpoint;
pub const revision: u16 = 46;
pub const revision: u16 = 47;
pub const Team = engine.game.players.ArenaTeam;

fn readTeam(reader: *std.Io.Reader) !Team {
Expand Down Expand Up @@ -1132,6 +1132,10 @@ fn writeCombat(w: *std.Io.Writer, combat: *const Combat) !void {
try w.writeInt(i32, shot.fired_at, .little);
} else try w.writeByte(guns.max_bullets);
},
.knock => |knock| {
try writeObject(w, knock.target);
try writePosition(w, knock.at);
},
}
}
}
Expand Down Expand Up @@ -1199,6 +1203,11 @@ fn readCombat(r: *std.Io.Reader) !Combat {
if (shot) |value| if (value.fired_at < 0) return error.InvalidCombat;
break :wall .{ .wall = .{ .at = at, .inward = inward, .started = started, .flare = flare, .shot = shot } };
},
.knock => knock: {
const target = try readObject(r);
if (target.slot >= slots) return error.InvalidCombat;
break :knock .{ .knock = .{ .target = target, .at = try readPosition(r) } };
},
};
}
return combat;
Expand Down Expand Up @@ -1884,12 +1893,13 @@ test "held primary input names one ship and adds no bytes when released" {

test "combat batches carry visual effects with bounded counts and pool indices" {
var buffer: [capacity]u8 = undefined;
var effects: Combat = .{ .count = 4 };
effects.entries[0..4].* = .{
var effects: Combat = .{ .count = 5 };
effects.entries[0..5].* = .{
.{ .shot = .{ .index = 4, .owner = slots, .kind = .turret_lasers, .fired_at = 84, .dies_at = 124, .origin = .{ 1, 2, 3 }, .velocity = .{ 0, 0, 1 } } },
.{ .impact = .{ .shot = 4, .fired_at = 84, .target = .{ .slot = 2, .reuse = 7 }, .at = .{ 1, 2, 20 }, .kind = .shield } },
.{ .nova = .{ .owner = .{ .slot = 2, .reuse = 7 }, .charge = 0.75, .fired_at = 85 } },
.{ .wall = .{ .at = .{ 100, 200, 300 }, .inward = .{ 1, 0, 0 }, .started = 86, .flare = true, .shot = .{ .index = 8, .fired_at = 82 } } },
.{ .knock = .{ .target = .{ .slot = 3, .reuse = 9 }, .at = .{ 5, 6, 7 } } },
};
const content = try (Message{ .combat = effects }).encode(&buffer);
const decoded = (try Message.decode(content)).combat;
Expand Down
Loading