Oddities with weight and price of gold

https://attnam.com/topics/Oddities-with-weight-and-price-of-gold-1

The Cathedral of Attnam > Trouble Shooting and Bugs

#1 Mar 12, 7:17 pm Hide

imaginarypowerunit

Hi,

I'm using v0.59 and I noticed that the math doesn't add up when comparing the weight of individual vs combined lumps of gold, and also when comparing the price of individual vs combined gold.

Maybe this is already a known issue but I did a quick search and didn't find any post related to this. I did a few experiments and I'm posting the results in case it's useful. For reference, I attached the save file that I used for the weight experiments.

Weight experiment #1
Lump of gold A = 28620g
Lump of gold B = 11500g
Expected weight of A + B = 40120g
Actual weight of A + B (2 lumps of gold) = 23000g (The combined weight is less than A + B. In fact, the combined weight is somehow less than A alone...)

Weight experiment #2 with 2 different lumps of gold
Lump of gold C = 21920g
Lump of gold D = 23500g
Expected weight of C + D = 45420g
Actual weight of C + D (2 lumps of gold) = 47000g (The combined weight is greater than C + D.)

Selling price experiment #1
Sell pile of 3 golden stones for a total of 177 gold:
"What a fine pile of 3 golden stones. I'll pay 177 gold pieces for them."

Sell the same 3 golden stones individually for a total of 531 gold.
"What a fine golden stone. I'll pay 177 gold pieces for it."
"What a fine golden stone. I'll pay 177 gold pieces for it."
"What a fine golden stone. I'll pay 177 gold pieces for it."

Selling price experiment #2
Sell pile of 3 lumps of gold for 775 gold:
"What a fine pile of 3 lumps of gold. I'll pay 775 gold pieces for them."

Sell the same 3 lumps of gold individually for 1656 gold.
"What a fine lump of gold, I'll pay 533 gold pieces for it."
"What a fine lump of gold, I'll pay 586 gold pieces for it."
"What a fine lump of gold, I'll pay 537 gold pieces for it."
Attached files
IVAN-v059-win_lumps_of_gold_test.7z (5.47 MB)
#2 Mar 12, 10:44 pm Hide

vasiliy

how exactly to reproduce that? i picked up gold lumps with your save, and everything working as expected. tried to sell them in Attnam, and of course, got only 96 gp for them, because that's all shopkeeper has left.
#3 Mar 12, 11:12 pm Hide

imaginarypowerunit

Hi vasiliy,

I attached screenshots showing the character:
1) picking up a lump of gold weighing 28620g, then
2) picking up another lump of gold weighing 11500g, then
3) opening the inventory to see the 2 lumps of gold weighing a total of 23000g.
#4 Mar 12, 11:27 pm Hide

imaginarypowerunit

And here's a screenshot showing the gold discrepancy. I blacked out most of the picture to avoid spoilers but you can see the text at the bottom. In the black market, I checked the price of 3 lumps combined: 808. Then I proceed to sell each lump individually for 502 + 360 + 584 = 1446 gold pieces.
#5 Mar 12, 11:34 pm Hide

vasiliy

ah, i see now, thank you!

in the inventory, this is purely visual bug, which is quite hard to fix — total inventory weight is right. the problem is that item piling expects exactly the same items, and uses the weight of the first item to calculate the overall weight. so the first picked up lump is used. list description is created by the separate method, so there is no way to set a custom weight there.

but total inventory weight is calculated without piling, so it is always correct.

and now i see how it affects shops: the same logic is applied for them: the price of the first item in the pile determines the total price. this is much bigger problem, but it is also easier to fix: we need to loop over the whole pile summing the prices, instead of using the simple multiplication.

thank you for noticing, this is great bug! i mean, most people will prolly won't notice it (i haven't — that's why it was never fixed.

SPOILER ALERT. Click here to see text.
sorry, red, i cannot fix it in vanilla right now. will try to make the patch later. basically, you need to pass `itemvector` to `room:ropItems()`, and calculate the proper price there — instead of passing only the first item and the amout. see this commit for the inspiration.
#6 Mar 13, 1:26 am Hide

imaginarypowerunit

I understand now, thanks for the explanation!
#7 Mar 13, 5:05 am Hide

vasiliy

actually, you can exploit the bug for your advantage: try to have the most expensive item first, and then you'll get more money than it should be possible!
#8 Mar 13, 5:11 am Hide

red_kangaroo

Oh wow, that's a big oversight.
#9 Mar 13, 6:22 am Hide

vasiliy

hard to notice, tho: boots, gauntlets, bottles, cans — they all pilled only if all items in the pile are exactly the same. i think that only stones and lumps are pilled regardless of their volume. the easier fix is to disable piling for them — this will clutter the inventory, but the other code will work as expected.
#10 Mar 13, 6:29 am Hide

vasiliy

p.s.: there is `WeightIsIrrelevant()` method for items, which returns `true` for lumps, stones and sticks. quick fix is to remove that method (or return `false` instead of `true`. this will turn off "wrong" piling.
#11 Jul 14, 1:19 am Hide

chaostrom

This is actually an old one, just nobody really bothered fixing it because it didn't make too big a difference in 0.50 where shops were rather insignificant. Things might be different now with the black market and all.