Original 14.9.1 shop price calculations
Target: anarchy-vanilla-14.9.1/kkr.dll, SHA-256
a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0.
REA Ghidra 12.1.2, profile
17fae9135c0f647ce7271e2b74936949ebe245320c1606a223c86bce0b2b7bed.
Addresses below use original image base 0x10000000. Lifted C uses base
0x36000000; add 0x26000000 to compare.
Observed client purchase quote
n3EngineClientAnarchy_t::N3Msg_ShopGetItemCost at 0x100262c0 resolves
the vending machine and local player, then calls FUN_100a9610.
N3Msg_GetShopItemStat at 0x10027060 also calls this function for stat74;
other stat requests use the underlying shop-entry lookup.
Define T(x) as CRT _ftol truncation toward zero, F01 as float32 0.01,
F025 as float32 0.025, D01 as binary64 0.01. The assembly gives:
base = T(stockItemPrice * terminalStat427 * D01)
discountPercent = min(T(playerComputerLiteracy * F025), 90)
buyQuote = base - T(discountPercent * base * F01)
The CL read is stat161, mode0, from the local player's skill subsystem. The terminal modifier read is stat427, mode2. No lower clamp is observed. The cap is 90 percent in this original client; later web sources describing an 80 percent cap do not override these original bytes.
Evidence: buy.json ev_848893ec597350ac1fd9cf4f10e316f91fdbf7c45d6ceac874fb9c4f4671477e;
buy-wrapper.json ev_8f4684e0e3afe53234b3ade2c5c02a0c05d8b4733b81bdf4d083fd57b46e594f;
get-shop-stat.json ev_cb37d9f99eb7454bc10b5f3883b1151ac3412aaa37c68896da203d1bebd27294.
Exact constants are preserved in initial-2/3/4.json:
- 0x101744a0 bytes cdcccc3c: F025 = 0.02500000037252902984619140625.
- 0x10170894 bytes 0ad7233c: F01 = 0.00999999977648258209228515625.
- 0x10170e80 bytes 7b14ae47e17a843f: D01 = 0.01000000000000000020816681711721685132943093776702880859375.
These details matter at integer boundaries. The inferred exact-decimal model
in tmp_arithmetic.py gives value10000/modifier100/CL40 -> 9901; CL3200 ->
2001; CL3600 and4000 -> 1001. This model is derived evidence, not an original
executable replay. _ftol import is IAT0x1016f284, reached by thunk0x1015fd8c.
Stock price and quality
FUN_100aa7b0 selects a shop tuple by the second word of the provided
identity (sequential shop-entry index). Each tuple has three words: quality,
low template ID, high template ID. Stat701 returns the quality directly;
other stats call FUN_100aa630.
That reader loads resource type1000020 for both endpoint IDs. For stat74 it
reads both endpoint prices and qualities, runs rounded linear interpolation
FUN_100eff20, then applies FUN_100f1320 to the interpolated price:
lo = min(endpointPrices)
hi = max(endpointPrices)
if prices equal, or interpolated equals either endpoint: return interpolated
return T(lo + (interpolated-lo)^2 / (hi-lo))
The same price curve is used for ordinary instantiated item stat74 by
FUN_100f0c80. Price interpolation is therefore not ordinary linear stat
interpolation. Other nonnumeric stats can use the nearer template endpoint.
Evidence: item-stat.json ev_426f71caa89641a1c8fb6ab47b677622cc07bd992755e07214a54b351e16ebaa; stock-stat.json ev_306e6cbbbe344b27751d7f8c70aabf8aa23b693eae169cce7944c4998a0d69f4; interpolate.json ev_8e74e096cabced73783a68d8f7822845dee9aa35efedfd48f6bca271bfae0bae; price-scale.json ev_3bca33cd977ee31ce2d449d48369cca7d6be731a195b1f5391a46f257f33ac13; instance-stat-price.json ev_aa7ad87b4229ff57be74817ae29c3d047aad7a61b5ba330daa379b467075d1df.
Selling and charges
The client has distinct calculations for staged sale quote, local accepted transfer, and pending net basket. They agree conceptually but have different integer rounding points. Do not collapse them into one exact formula without choosing which contract is being reconstructed.
FUN_100a99d0 handles accepted vending-machine transfers. For each offered
item it reads price74 (missing sentinel1234567890 becomes0), casts price to
float32, and divides by positive stat212 (max charges/package size) unless
the identity type is51018. The division result is again stored float32.
Let U be that resulting per-unit price, N the offered count, S terminalstat426:
base = T(N * U * S * D01)
markupPercent = T(CL * F025)
lineTotal = max(0, base + T(markupPercent * F01 * base))
No CL cap is observed in this function. Both simple-item and dynamic-item branches use this arrangement. Dynamic items additionally require stat8=-1.
FUN_100a9e20 computes a staged sale total for a UI caller0x10078060. It
normalizes price/charges similarly, but rounds the per-unit CL addition
before count and terminal modifier:
lineTotal = T((U + T(T(CL*F025)*U*F01)) * N * S * D01)
FUN_100a9f60 computes pending net basket cost. Existing sale items are
negative contributions of price74*S/100 plus CL markup; selected purchases
are positive buyQuote multiplied by signed16-bit selected count. Its direct
sale list does not show the charge normalization from the offered-item list.
Evidence: sell-stage.json ev_50d5389d0e78c2195155c556727b2150c1289263a204747719239d648fbcbf99; sell-quote.json ev_8824c58f2355519e447ea2d309084fd940705d3afb6bc4638ca93b8a1c2e0f8f; sell-direct.json ev_49207891b4790064b76a2a743f4f5c4c750a8a63f8d5f775ef55f43980c0ad96; their direct callers are preserved in the matching caller files.
Terminal defaults and effect names
FUN_100a8f40 initializes stat426=70 and427=100. Loaded terminal template
values supersede these defaults: for example checked-in original definitions
31021 Darren Gralech and31032 NT and Doc spells explicitly have426=5,427=100.
Use actual terminal definitions, not faction-name special cases.
StateParse_t::StateParse_t at0x1009fd40 registers:
- MakeVendorShop = 0xcf52 =53074.
- AddShopItem =0xcf33 =53043.
- AddACGShopItem =0xcf45 =53061.
Evidence: init-defaults.json ev_945aebdb5a30dffd6ba8b3cfc578b2aa467e23d0357b13c846b779cd297fa348; makevendor-effect.json ev_a9926ef69a99e2c3c8298dbb829cde53c4a97d489189679965e189e657dc4475.
Limits / unresolved questions
These are static observations of the shipped client, not captured historical server executions. Exact authoritative server caps/rounding, admission rules, faction/profession restrictions, and stock-generation/drop tables remain unproven. Prefer original client quote consistency for the reconstruction, but document it as the chosen server policy.
MakeVendorShop/AddShopItem string references only reached parser registration. The bounded investigation did not recover their executable effect handlers, argument layouts, or how they install426/427. The pricing reader exposes stock tuples and item resource IDs, not stock-code WLLL/etc generation algorithms. Those server-owned sources remain unresolved.
Later corroborating references (not14.9.1 server proof): https://forums-archive.anarchy-online.com/showthread.php?381823-Where-does-one-obtain-the-best-prices-when-selling-to-shops= (March2005 firsthand CL/faction-terminal tests); and https://wiki.aodb.us/wiki/Quantum_Forcefield_Technology (later wiki describes40CL steps and80% cap, which conflicts with this client's90%).
Original shipped OnOpenShop.txt describes staging an item in the shop window, then accepting, and warns buying an item back costs much more. This supports staged trade semantics but supplies no numerical authoritative formula.
Followup: sale admission and cash notification
Existing lifted original bytes in client/game/kkr.dll/lifted-0013.c,
sub_3601FB50, test NoDrop flag0x04000000 at original0x1001fce1. This rejects
ordinary NoDrop offers unless the trade peer casts to SimpleChar with byte
+0x1b4 set or the source identity type is111. An ordinary VendingMachine peer
does not receive the SimpleChar exception. This agrees with the independently
documented flag evidence in docs/reclaim.md.
Dynamic-item sale completion in FUN_100a99d0 reads stat8/mode2 and requires -1 at0x100a9b91..100a9b9d before transferring it. Simple static item branch does not make that read.
The vending completion branch of FUN_10077700 at0x100777b0..100777e4 calls FUN_100a99d0, clears the player's busy state, and returns before its ordinary player-trade cash61 update path. FUN_100a99d0 accumulates a sale price in a local variable but never applies it to player cash. Its tail clears the shop transaction list using FUN_1001e390 and removes the client entry using FUN_100aa190; both helpers only clear/release structures. Therefore action3 does not itself credit the local player's cash on the vending path. Send an authoritative absolute stat61 update with successful sale completion (using the current client's existing stat update route); it will not double-credit cash through this finalizer.
The completion interpretation above is a bounded static inspection of the original lifted bytes and preserved REA assembly/pseudocode, not execution.