B9: Loot tables and containers

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>
This commit is contained in:
2026-11-11 20:16:20 -05:00
co-authored by Claude Opus 5.5
parent 0c6ad36105
commit 0013a81658
9 changed files with 677 additions and 6 deletions
+38 -4
View File
@@ -336,8 +336,42 @@ const LINE_PULL_LIFT: float = 4.0
# unless interrupted. `heal` restores health up to `heal_cap` (default full), `armor`
# adds armor up to PLAYER_MAX_ARMOR. An item that would do nothing can't be started.
const ITEMS: Dictionary = {
"sailcloth_bandage": {"heal": 25, "heal_cap": 75, "use_seconds": 3.0, "stack": 6, "rarity": 0},
"brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3, "rarity": 1},
"cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2, "rarity": 1},
"tar_patch": {"armor": 20, "use_seconds": 2.0, "stack": 5, "rarity": 0},
"sailcloth_bandage": {"heal": 25, "heal_cap": 75, "use_seconds": 3.0, "stack": 6, "rarity": 0, "loot": 3},
"brine_tonic": {"heal": 60, "use_seconds": 8.0, "stack": 3, "rarity": 1, "loot": 1},
"cork_vest": {"armor": 50, "use_seconds": 5.0, "stack": 2, "rarity": 1, "loot": 1},
"tar_patch": {"armor": 20, "use_seconds": 2.0, "stack": 5, "rarity": 0, "loot": 2},
}
# Loot. Every loot marker at a point of interest holds either a sea chest, with chance
# `chest`, or floor loot: `rolls` rolls on the source's category weights. Washed-up
# crates (props) hold one source "crate" roll each and spill it when broken. A weapon
# rolls its tier from `tiers` (weights, lowest tier first) and comes with
# LOOT_AMMO_WITH_WEAPON pickups of its ammunition. Within a category, an item's weight
# is LOOT_RARITY_WEIGHTS[rarity]. Consumables spawn `loot` of themselves (ITEMS), thrown
# weapons LOOT_THROWN_COUNT, and ammunition one pickup amount (AMMO).
const LOOT_SOURCES: Dictionary = {
"hamlet": {"chest": 0.3, "rolls": 2, "weapon": 50, "consumable": 25, "ammo": 15, "nothing": 10, "tiers": [55, 30, 12, 3]},
"dock": {"chest": 0.4, "rolls": 2, "weapon": 45, "consumable": 25, "ammo": 20, "nothing": 10, "tiers": [50, 32, 14, 4]},
"salt_works": {"chest": 0.3, "rolls": 2, "weapon": 45, "consumable": 30, "ammo": 15, "nothing": 10, "tiers": [55, 30, 12, 3]},
"quarry": {"chest": 0.4, "rolls": 2, "weapon": 45, "consumable": 20, "ammo": 25, "nothing": 10, "tiers": [50, 32, 14, 4]},
"lighthouse": {"chest": 0.6, "rolls": 2, "weapon": 50, "consumable": 25, "ammo": 20, "nothing": 5, "tiers": [35, 35, 22, 8]},
"shrine": {"chest": 0.8, "rolls": 2, "weapon": 55, "consumable": 25, "ammo": 15, "nothing": 5, "tiers": [20, 35, 30, 15]},
"crate": {"chest": 0.0, "rolls": 1, "weapon": 35, "consumable": 30, "ammo": 25, "nothing": 10, "tiers": [65, 27, 7, 1]},
}
## A sea chest holds this many weapons and consumables, and ammunition for each weapon
## plus LOOT_CHEST_EXTRA_AMMO random ammunition pickups. Its weapons roll their tier
## LOOT_CHEST_TIER_ROLLS times and keep the best.
const LOOT_CHEST_WEAPONS: int = 1
const LOOT_CHEST_CONSUMABLES: int = 1
const LOOT_CHEST_EXTRA_AMMO: int = 1
const LOOT_CHEST_TIER_ROLLS: int = 2
## If the rolls leave fewer weapons than this on floors and in chests, extra weapon
## rolls are added to floor spots in marker order: one per player in a full lobby.
const LOOT_MIN_POI_WEAPONS: int = SOLO_PLAYERS
const LOOT_RARITY_WEIGHTS: Array[int] = [6, 3, 1]
const LOOT_AMMO_WITH_WEAPON: int = 1
const LOOT_THROWN_COUNT: int = 2
## Interact opens a closed chest whose base is within this distance of the feet.
const CHEST_RANGE: float = 2.5
## Loot from one spot lands on a ring this far from it.
const LOOT_SCATTER_METRES: float = 0.7