Seeded loot at every point of interest's loot markers, rolled once per match from the "loot" stream by LootSet.plan() and placed by Simulation.place_loot(). - Each marker holds a sea chest (chance by location) or floor loot (rolls on the location's weapon/consumable/ammo/nothing weights). Weapons roll a tier from the location's tier weights and come with their ammunition; chests hold a weapon (best of two tier rolls), a consumable and spare ammunition. - Interact opens the nearest closed chest in reach unless a pickup is nearer, and spills its contents as pickups. - Washed-up crate props hold one roll of the crate table and spill it when broken by any means. - If the rolls leave fewer POI weapons than LOOT_MIN_POI_WEAPONS (one per player in a full lobby), extra weapon rolls top up floor spots. - Chest and crate state is part of state_hash(). ServerLoop places loot. Tests: test_loot (12), including a statistics run of 1,000 loot seeds over four generated islands that checks tier shares against the tables, that shrines beat hamlets, and that every match has a weapon per player at POIs and 1.25 per player counting crates. Closes #23 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.6 KiB
GDScript
69 lines
2.6 KiB
GDScript
extends TestCase
|
|
|
|
|
|
func _run(match_seed: int, players: int, bots: int, ticks: int) -> ServerLoop:
|
|
var loop: ServerLoop = ServerLoop.new(match_seed, players, bots)
|
|
for _index: int in ticks:
|
|
loop.run_tick()
|
|
return loop
|
|
|
|
|
|
func test_creates_players_then_bots() -> void:
|
|
var loop: ServerLoop = ServerLoop.new(1, 2, 3)
|
|
var players: int = 0
|
|
for entity: SimEntity in loop.sim.entities.entities():
|
|
if entity.archetype == SimEntity.ARCHETYPE_PLAYER:
|
|
players += 1
|
|
assert_eq(players, 5)
|
|
assert_true(loop.sim.pickups.size() > 0, "the match's floor loot was placed")
|
|
assert_eq(loop.player_ids, [1, 2, 3, 4, 5] as Array[int])
|
|
assert_eq(loop.bots.size(), 3)
|
|
assert_eq(loop.bots[0].player_id, 3)
|
|
|
|
|
|
func test_records_one_timing_sample_per_tick() -> void:
|
|
var loop: ServerLoop = _run(7, 0, 4, 120)
|
|
assert_eq(loop.sim.tick, 120)
|
|
var stats: Dictionary = loop.timing_stats()
|
|
assert_eq(stats["ticks"], 120)
|
|
assert_true(stats["min_us"] <= stats["p50_us"])
|
|
assert_true(stats["p50_us"] <= stats["p95_us"])
|
|
assert_true(stats["p95_us"] <= stats["p99_us"])
|
|
assert_true(stats["p99_us"] <= stats["max_us"])
|
|
assert_eq(stats["budget_us"], ServerLoop.TICK_BUDGET_USEC)
|
|
|
|
|
|
func test_empty_stats() -> void:
|
|
assert_eq(ServerLoop.new(1, 0, 0).timing_stats(), {"ticks": 0})
|
|
|
|
|
|
func test_percentile_uses_nearest_rank() -> void:
|
|
var values: PackedInt64Array = PackedInt64Array(range(1, 101))
|
|
assert_eq(ServerLoop._percentile(values, 0.5), 50)
|
|
assert_eq(ServerLoop._percentile(values, 0.95), 95)
|
|
assert_eq(ServerLoop._percentile(values, 1.0), 100)
|
|
assert_eq(ServerLoop._percentile(PackedInt64Array([9]), 0.99), 9)
|
|
|
|
|
|
func test_bots_leap_and_humans_without_commands_stay_aboard() -> void:
|
|
# Every match starts on the drop carrier. A human who sends nothing rides it; the bot
|
|
# leaps at its own fixed moment and falls away.
|
|
var loop: ServerLoop = ServerLoop.new(99, 1, 1)
|
|
var human: SimEntity = loop.sim.entities.find(1)
|
|
var bot: SimEntity = loop.sim.entities.find(2)
|
|
assert_eq(human.drop_state, Drop.ABOARD)
|
|
assert_eq(bot.drop_state, Drop.ABOARD)
|
|
for _index: int in Tuning.TICK_RATE_HZ * 24:
|
|
loop.run_tick()
|
|
assert_eq(human.drop_state, Drop.ABOARD)
|
|
assert_true(human.position.distance_to(loop.sim.drop.barge_position(loop.sim.tick)) < 0.001)
|
|
assert_ne(bot.drop_state, Drop.ABOARD, "the bot should have leapt")
|
|
assert_true(bot.position.y < Tuning.BARGE_ALTITUDE - 20.0, "the bot should be falling, at %s" % bot.position)
|
|
|
|
|
|
func test_same_seed_gives_the_same_match() -> void:
|
|
var first: String = _run(2026, 2, 22, 300).sim.state_hash()
|
|
var second: String = _run(2026, 2, 22, 300).sim.state_hash()
|
|
assert_eq(first, second)
|
|
assert_ne(first, _run(2027, 2, 22, 300).sim.state_hash())
|