aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit cd2240e242cce2bb478ff532d843f13d3fc10603
parent d6eeb37d331bbdd9987559ff5eb0feea82e9aed8
Author: anon <anon@example.com>
Date:   Thu, 29 Oct 2026 08:27:56 +0000

Supply ordinary ammunition through shared shop stock

Diffstat:
MTODO.md | 24+++++++++++++++++++++---
Adocs/ammunition-stock.md | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/ranged-weapons.md | 6+++++-
Mdocs/shops.md | 4+++-
Mserver/gamedata/shop_stock.yaml | 13+++++++++++++
Aserver/shop_ammunition_test.go | 190+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/shop_purchases_test.go | 2+-
7 files changed, 348 insertions(+), 6 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -48,7 +48,10 @@ through a shared loot profile. Useful equipment drops and purchasable stock stil need wider coverage. One authored training boss now supplies a provisional selected-quality equipment pool with ordinary qualified armor wear, earned level-4 training, sales and two-client cold recovery verified; -see [earned creature upgrades](docs/earned-creature-upgrade.md). The remaining +see [earned creature upgrades](docs/earned-creature-upgrade.md). Its normally +looted QL3 pistol now also passes earned skill training, funded ammunition +purchase, reload, a full-health kill and cold recovery through the shared rules; +see [ammunition supply](docs/ammunition-stock.md). The remaining connected native regression and corpse presentation audit are immediate gaps. A normally created Atrox Enforcer has now killed two ordinary Leets, recovered, collected cash, picked up a Monster Part, retained it across a server restart @@ -1232,6 +1235,20 @@ introduction and starting-item gameplay remain open below. ## Shops +- [x] [P0] Supply ordinary finite weapons with earned ammunition purchases. + Use the original 100-round packages and shared purchase/reload rules. Verify + a normally earned pistol, ordinary skill training, funded native purchase, + rejected wrong ammunition, actual reload/fire, item/round conservation and + page/server cold recovery. The four-package basic-weapon-template binding is + explicit provisional stock policy; recover exact historical membership + independently. See [ammunition supply](docs/ammunition-stock.md). + Ordinary native play spent 207 earned IP to equip the retained QL3 pistol, + declined/retried a 100-credit basket, bought two 100-round bullet packages and + one energy package, rejected wrong ammo, reloaded 20 rounds and killed a + full-health Leet in eight shots. All 28 prior items, the three new stacks, + 12 loaded rounds, remaining bullets 80/100, energy 100 and 141 credits survived + page reconnect and server restart. Six production supplier placements and + failed/ignored writes, failed COMMIT and retry have automated coverage. - [x] Supply a useful early-game purchase selection in an actual reachable shop. Establish a small target-period stock subset before completing all153 categories: an affordable supported equipment upgrade and the ammunition or @@ -1410,8 +1427,9 @@ introduction and starting-item gameplay remain open below. broad families, while tier descriptors differ; do not copy basic stock into advanced/superior or starter terminals. Regular recovery supplies now support reviewed QL1..200 families through shared use/interpolation; their historical - stock ranges and rotation remain unresolved. Four ordinary ammo definitions have - 100-round packages, but their exact booth bindings remain unresolved. Reuse + stock ranges and rotation remain unresolved. Four original 100-round ammo + packages now have a provisional basic-weapon/Budget supplier subset; exact + historical booth bindings remain unresolved. Reuse the item/vendor hashes, descriptors and placements in `local/charged-shop-research/catalog/README.md` and the period source audit. - [x] Sell one inventory item. Check: ownership and credits change once and diff --git a/docs/ammunition-stock.md b/docs/ammunition-stock.md @@ -0,0 +1,115 @@ +# Ordinary ammunition supply + +Basic weapon templates and the original Budget Ammunition Shop offer a bounded +four-package subset. Purchases use the existing package price, stack delivery, +inventory capacity and atomic ownership transaction. Reload uses the existing +ammo-type check and transfers rounds from the named inventory stack into the +equipped finite weapon. There is no ammo-vendor-specific Go branch. + +## Original item contracts + +All four complete 14.9.1 records are fixed QL1, native type51005, with +Can30=517 (including Stackable512) and package212=100. Price74 is the whole +package's base value. No function section appears on these definitions. + +| Template | Name | AmmoType420 | Package | Base price74 | +| --- | --- | --- | ---: | ---: | +| 21605 | Bullets | 2 | 100 | 25 | +| 21609 | Energy Weapon Ammo | 1 | 100 | 50 | +| 21613 | Shotgun Shells | 4 | 100 | 80 | +| 21601 | Flamethrower Ammunition | 3 | 100 | 80 | + +The original item payload hashes are: + +- 21605: `6c7e9a94defa736516b76322752214d105a66ab241532da316d34734068d5edf`. +- 21609: `04e786a601c045a5ef195532ed546a918672a6580d7f62bde51f28d8846e5573`. +- 21613: `fb68ccf050351fa0c2691fd78069ed1821a63e8aedeb91d38ae158c837a04b4d`. +- 21601: `efd5c6c9571c00ad211e4193a39320419f79c5285961c14f38c90ec9b2fa299c`. + +Fresh parsing by original resource key `(1000020, template)` exactly matches +the maintained catalog, including all sections and their offsets. The original +index SHA-256 is +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. +Flamethrower ammunition retains its additional original stat-modifier sections; +it is not an equipable weapon or an alternative energy-ammunition type. + +## Stock policy and evidence boundary + +Budget Ammunition Shop25885 explicitly describes selling budget ammunition. +Its sole authored placement,3221226898, is in Clan Registration1426. The +template itself has no faction Use criterion. Its raw category descriptors +do not establish an exact list of item IDs. Binding the four ordinary packages +is a bounded reconstruction of that stated category. + +Ordinary finite-weapon progression also needs a reachable supplier outside +registration. Basic weapon templates99478/99505/99572 therefore receive the +same explicit subset as provisional reconstruction policy. The original +records establish their identity, placement, faction criteria and prices; +their empty descriptions and opaque WLWL/WLLL descriptors do not prove ammo +membership. This change does not claim a recovered historical generator. + +| Vendor template | Original Use criterion | Buy modifier427 | Authored placements | +| --- | --- | ---: | --- | +| 99478 OT Basic Weapons | Omni | 100 | Omni basic room1183 | +| 99505 Clan Basic Weapons | Clan | 105 | Clan basic room1180 | +| 99572 Basic Weapons | None | 105 | Neutral basic room1186; Parnassos500; Newland Desert565 | +| 25885 Budget Ammunition Shop | None | 100 | Clan Registration1426 | + +The template binding includes the two outdoor Basic Weapons placements. +Advanced/superior, Engineer vendors and category-overlap vendors retain their +unresolved stock. Their categories and names are not aliases for this subset. +Exact original booth membership, ordering, refresh and additional ammunition +remain open. No QL generation is inferred from descriptors for these fixed-QL +packages. + +## Verification + +`server/shop_ammunition_test.go` exercises production vendors through ordinary +shop handlers. It checks all six placements, original faction access and exact +prices, four 100-round packages alongside an existing partial stack, stable +first-free identities, native grant quantities, repeated Accept and cold load. +Purchased energy, shell and flamethrower ammunition cannot reload a bullet +pistol; its purchased bullet stack fills the magazine once and retains the +remaining rounds after restart. Failed/ignored second-package writes and a +deferred failed COMMIT retain the complete basket for one successful retry. +The complete shop/reload/ranged race run passed 93 top-level tests and 285 +results, including the supported-stock and medical-terminal boundaries. + +The existing [shop package tests](shops.md) cover funds, capacity, cancellation, +partial packages and lost completion. Existing [ranged tests](ranged-weapons.md) +cover firing, depletion, reload deadlines, repeated requests, wrong sources, +empty stacks and transaction rollback. + +### Ordinary native progression + +An GPU WASM run used the existing level-4 Enforcer and its normally looted +QL3 Rusty Flechette instance 163. Rejected wear retained both that pistol and its +QL5 spare. Spending 207 earned IP through the native skills window raised raw +Pistol from 5 to 12 and Fling Shot from 5 to 7; the same QL3 pistol then equipped. + +The character walked through Backyard 11 and Omni1 Entertainment to the original +OT Basic Weapons terminal 3221554335 in basic room 1183. Its catalog displayed +the four packages. A basket containing two bullet packages and one energy +package quoted 100 credits. Decline retained all 28 prior items and 241 credits; +reopening and accepting delivered three separate 100-round instances 164..166, +retained every prior item and left 141 credits. + +Picking up energy ammunition and using it on the pistol displayed the native +`Ammo mismatch` rejection and emitted no reload request. Correct bullets sent +GenericCmd 5 with native source `(104,66)` and worn target `(101,6)`. Native stat 26 +and SQLite both became 20; source 164 retained 80 rounds. Page reconnect restored +the real identities, quantities and worn weapon. + +Back in training, eight authoritative projectile results dealt 14, 12, 8, 13, 28, +10, 5 and 10 damage to a full-health level-1 Leet. Each result decremented the +magazine once, ending at 12; the final transaction recorded HP 0 and owner 5's +corpse rights. This grey kill awarded no XP. Page reconnect and a +normal server restart preserved all 31 owned instances, the same worn QL3 +pistol, 12 loaded rounds, bullet stacks of 80/100, energy 100, 141 credits and the +trained skills. No gameplay fixtures or character/cash/item edits were used. +No native page errors occurred. Owned test browsers were closed; the sole LAN +preview keeps the default HTTPS 8443 and game ports. + +Original raw resources, vendor placements and opaque descriptors are retained +under `local/ammunition-stock/audit-2026/`. Runtime evidence and checks live +alongside that audit; fixtures and ordinary earned gameplay are kept explicit. diff --git a/docs/ranged-weapons.md b/docs/ranged-weapons.md @@ -8,7 +8,11 @@ so the native client can restore the inventory item. Main-hand weapon admission and ammunition now use shared catalog rules; [starter and catalog weapons](catalog-weapons.md) describes the scope and -unlimited-ammunition contract. The Flechette remains a regression fixture. +unlimited-ammunition contract. The exact-QL1 example above is a regression fixture. + +Original 100-round ammunition packages now have a provisional basic-weapon and +Budget-shop supplier subset. See [ammunition supply](ammunition-stock.md) for +the original package contracts, purchase checks and stock-policy limits. ## Catalog rules diff --git a/docs/shops.md b/docs/shops.md @@ -140,7 +140,9 @@ The basic faction/neutral templates 99481/99508/99574 repeat descriptor byte pai selects the three supported regular QL1 recovery definitions for basic terminals only. Family membership and the authored definitions support this inference; neither the descriptions nor opaque descriptors enumerate these exact IDs. -Advanced/superior, starter and ammunition stock remain unresolved. +Advanced/superior and starter medical stock remain unresolved. The separate +[ammunition supplier subset](ammunition-stock.md) retains the original 100-round +packages with explicitly provisional basic-weapon-template stock membership. The original Anarchy Arcanum treatment guide, updated 27 June 2003 and [captured 10 September 2003](https://web.archive.org/web/20030910134725id_/http://home.c2i.net:80/ellusion/pharmacy_treatment.html), diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml @@ -41,6 +41,19 @@ 99508: [{template: 25812, quality: 1}, {template: 85366, quality: 1}, {template: 25820, quality: 1}] 99574: [{template: 25812, quality: 1}, {template: 85366, quality: 1}, {template: 25820, quality: 1}] +# Ordinary ammunition: original fixed-QL, 100-round packages. The Budget shop +# explicitly sells ammunition; basic weapon-shop membership is provisional. +# This subset supplies finite early weapons; historical generation remains open. +# See docs/ammunition-stock.md for the source and policy boundary. +25885: &ordinary_ammunition + - {template: 21605, quality: 1} + - {template: 21609, quality: 1} + - {template: 21613, quality: 1} + - {template: 21601, quality: 1} +99478: *ordinary_ammunition +99505: *ordinary_ammunition +99572: *ordinary_ammunition + # Maps: the five original reader upgrades. Fixed subset, not recovered TIAM stock. # Shipped map-window help and original upgrade contracts; see docs/shops.md. 117649: [{template: 116683, quality: 1}, {template: 116684, quality: 1}, {template: 116685, quality: 1}, {template: 116692, quality: 1}, {template: 116694, quality: 1}] diff --git a/server/shop_ammunition_test.go b/server/shop_ammunition_test.go @@ -0,0 +1,190 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestShopAmmunitionProductionPackages(t *testing.T) { + for _, scenario := range []struct { + machine uint32 + side uint16 + credits uint32 + }{ + {3221554335, 2, 765}, {3223717020, 1, 754}, + {3222406306, 0, 754}, {3221226898, 1, 765}, + {3222012404, 0, 754}, {3221422645, 0, 754}, + } { + t.Run(fmt.Sprint(scenario.machine), func(t *testing.T) { + world, conn := newPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + machine := gamedata.ShopMachines[scenario.machine] + player.playfield, player.position = machine.Playfield, machine.Position + player.appearance = 0x115 | scenario.side<<9 + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51005, Template: 21605, Quality: 1, Slot: 64, Count: 7} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], scenario.machine) + + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + if client.shop == nil || !slices.Equal(client.shop.stock, []gamedata.ShopItem{ + {Template: 21605, Quality: 1}, {Template: 21609, Quality: 1}, + {Template: 21613, Quality: 1}, {Template: 21601, Quality: 1}, + }) { + t.Fatal("ammunition catalog unavailable", client.shop) + } + for index := range uint32(4) { + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, scenario.machine}, [2]uint32{111, index})[20:]); err != nil { + t.Fatal(err) + } + } + conn.packets = nil + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1].inventory + + expected := []ownedItem{ + {ID: 1, Type: 51005, Template: 21605, Quality: 1, Slot: 64, Count: 7}, + {ID: 2, Type: 51005, Template: 21605, Quality: 1, Slot: 65, Count: 100}, + {ID: 3, Type: 51005, Template: 21609, Quality: 1, Slot: 66, Count: 100}, + {ID: 4, Type: 51005, Template: 21613, Quality: 1, Slot: 67, Count: 100}, + {ID: 5, Type: 51005, Template: 21601, Quality: 1, Slot: 68, Count: 100}, + } + if cold.Credits != scenario.credits || player.inventory.Credits != scenario.credits || !slices.Equal(cold.Items, expected) || !slices.Equal(player.inventory.Items, expected) || world.nextItem != 5 { + t.Fatal("ammunition purchase lost package quantities, identity or price", cold) + } + if len(conn.packets) != 6 { + t.Fatal("repeated Accept duplicated delivery", len(conn.packets)) + } + for index, template := range []uint32{21605, 21609, 21613, 21601} { + packet := conn.packets[index+1] + if binary.BigEndian.Uint32(packet[16:20]) != 0x052e2f0c || binary.BigEndian.Uint32(packet[29:33]) != template || binary.BigEndian.Uint32(packet[41:45]) != 100 { + t.Fatal("native grant lost its ammunition package", template) + } + } + }) + } +} + +func TestShopPurchasedAmmunitionReloadRejectsOtherTypes(t *testing.T) { + world, _ := newPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51018, Template: 123742, Quality: 1, Slot: 6, Count: 1} + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + player.position = gamedata.ShopMachines[3221554335].Position + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221554335) + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + for index := range uint32(4) { + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221554335}, [2]uint32{111, index})[20:]); err != nil { + t.Fatal(err) + } + } + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil { + t.Fatal(err) + } + before := slices.Clone(player.inventory.Items) + + for index, slot := range []uint32{65, 66, 67} { + if err := world.handleReload(client, explicitReloadRequest(uint32(index+3), slot, 1)); err != nil { + t.Fatal(err) + } + if !slices.Equal(player.inventory.Items, before) || !client.reloadUntil.IsZero() { + t.Fatal("wrong purchased ammo changed rounds or recharge", slot) + } + } + reload := explicitReloadRequest(6, 64, 1) + if err := world.handleReload(client, reload); err != nil { + t.Fatal(err) + } + if err := world.handleReload(client, reload); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1].inventory + + expected := []ownedItem{ + {ID: 1, Type: 51018, Template: 123742, Quality: 1, Slot: 6, Count: 1, Ammo: 20}, + {ID: 2, Type: 51005, Template: 21605, Quality: 1, Slot: 64, Count: 80}, + {ID: 3, Type: 51005, Template: 21609, Quality: 1, Slot: 65, Count: 100}, + {ID: 4, Type: 51005, Template: 21613, Quality: 1, Slot: 66, Count: 100}, + {ID: 5, Type: 51005, Template: 21601, Quality: 1, Slot: 67, Count: 100}, + } + if cold.Credits != 765 || !slices.Equal(cold.Items, expected) || !slices.Equal(player.inventory.Items, expected) || world.nextItem != 5 { + t.Fatal("reload did not conserve purchased ammunition after restart", cold) + } +} + +func TestShopAmmunitionPurchaseFailureRetry(t *testing.T) { + for _, failure := range []string{"abort", "ignore", "commit"} { + t.Run(failure, func(t *testing.T) { + world, conn := newPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + player.position = gamedata.ShopMachines[3221554335].Position + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221554335) + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221554335}, [2]uint32{111, 0})[20:] + for range 2 { + if err := world.handleTrade(client, add); err != nil { + t.Fatal(err) + } + } + trigger := "CREATE TRIGGER reject_ammo BEFORE INSERT ON items WHEN NEW.id=3 BEGIN SELECT RAISE(ABORT, 'ammo'); END" + if failure == "ignore" { + trigger = "CREATE TRIGGER reject_ammo BEFORE INSERT ON items WHEN NEW.id=3 BEGIN SELECT RAISE(IGNORE); END" + } + if failure == "commit" { + if _, err := world.db.Exec("CREATE TABLE broken_ammo (id INTEGER REFERENCES items(id) DEFERRABLE INITIALLY DEFERRED)"); err != nil { + t.Fatal(err) + } + trigger = "CREATE TRIGGER reject_ammo AFTER INSERT ON items WHEN NEW.id=3 BEGIN INSERT INTO broken_ammo VALUES(9999999); END" + } + if _, err := world.db.Exec(trigger); err != nil { + t.Fatal(err) + } + conn.packets = nil + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] + + failed := world.handleTrade(client, accept) + rejected := newTestInventoryServer(t).characters[1].inventory + if failed == nil || rejected.Credits != 1000 || len(rejected.Items) != 1 || player.inventory.Credits != 1000 || len(player.inventory.Items) != 1 || world.nextItem != 1 || client.shop == nil || len(conn.packets) != 0 { + t.Fatal("failed ammunition purchase published a partial basket", failed, rejected) + } + if _, err := world.db.Exec("DROP TRIGGER reject_ammo"); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1].inventory + + if cold.Credits != 950 || len(cold.Items) != 3 || cold.Items[1] != (ownedItem{ID: 2, Type: 51005, Template: 21605, Quality: 1, Slot: 65, Count: 100}) || cold.Items[2] != (ownedItem{ID: 3, Type: 51005, Template: 21605, Quality: 1, Slot: 66, Count: 100}) || world.nextItem != 3 || !slices.Equal(cold.Items, player.inventory.Items) { + t.Fatal("ammunition retry lost or duplicated packages", cold) + } + }) + } +} diff --git a/server/shop_purchases_test.go b/server/shop_purchases_test.go @@ -85,7 +85,7 @@ func TestShopMedicalSubsetRetainsBasicTerminalBoundary(t *testing.T) { t.Fatal("basic medical stock changed", template) } } - for _, template := range []uint32{99482, 99483, 99509, 99529, 99575, 151975, 25885, 81799} { + for _, template := range []uint32{99482, 99483, 99509, 99529, 99575, 151975, 81799} { if len(gamedata.ShopStock[template]) != 0 { t.Fatal("basic medical subset leaked into an unresolved terminal", template) }