CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.33k stars 4.14k forks source link

NPC shops steadily stock less things over time #57688

Closed Nerezza closed 2 years ago

Nerezza commented 2 years ago

Describe the bug

Currently in my (test) playthrough I've noticed a problem with the ref center, Hub 01, and the Hub free merchants where they haven't restocked as expected since I first visited their stores, even though over a season has passed since that time.

The ref center's tool supplies have ~disappeared~ dwindled over time and not been replaced. (Oops, 2am in the morning accidental hyperbole)

I only remember Hub 01 only restocking one or two armor pieces once, during their first restock in this playthrough. The armor pieces for sale have been the same for literally an entire season. This means I'm still wearing prototype greaves because they've still yet to stock any greaves to replace them with, for an entire season.

The free merchants at Hub 01 are similar, they've mostly kept the same stock between restocks.

The only thing I've noticed is strange about this is that the stock of their respective currencies just keeps soaring higher, and that Rubik (who notably lacks any currency aside from their shiny farthing collection) restocks as intended.

My best guess is that shops currently try to restock based off the sum value of their stocked goods, and somehow the shops that stock currencies ended up with a logic that chooses to overstock their own currency rather than restock their items.

Steps to reproduce

Only way to reproduce is to watch the stock of NPC shops for a long period, a season at least.

Expected behavior

Shop stock should be rotating so that after a season you won't see an item category with literally the same items it had at the start of the season. Currency in a shop probably shouldn't steadily rise during a playthrough, too.

Screenshots

No response

Versions and configuration

Additional context

No response

andrei8l commented 2 years ago

Regarding the currency thing: currently items are consumed at a fixed rate of 5/day. So after 7 days, only 35 merch is consumed, but Smokes' restock adds 200-300. I want to improve this eventually with per-item (or per-group) consumption rates, but that's for after 0.G.

~I was not able to reproduce your tool issue with Smokes. Can you provide a save for that?~

Hub 01 Intercom has not been updated to use rigid groups so its restocks tend to be lackluster. That's JSON only and can be done easily for 0.G

Nerezza commented 2 years ago

I've tracked down the likely cause of this bug to this function: https://github.com/CleverRaven/Cataclysm-DDA/blob/7a89bbe73a1902729c311addc5ea4cccccdec69f/src/npc.cpp#L2017

It appears that NPCs whose faction has a currency will first of all stock more currency, then they add shopkeeper_item_group groups with the rigid flag on them (false by default) and then they try to fill the rest of their shop's "value quota" with any non-rigid groups listed.

Aside from not having a currency to stock, Rubik's item groups are all rigid-true so Rubik ALWAYS restocks no matter how much value is in their store.

Then there's Hub 01 which has no rigid groups and stops restocking the shopkeeper item groups as the store probably constantly has too much value in it.

This is beyond me to fix tbqh, I'm just going to set store item groups to rigid in my local files for now to bypass this issue so I can focus on other things.

Nerezza commented 2 years ago

Regarding the currency thing: currently items are consumed at a fixed rate of 5/day. So after 7 days, only 35 merch is consumed, but Smokes' restock adds 200-300. I want to improve this eventually with per-item (or per-group) consumption rates, but that's for after 0.G.

I was not able to reproduce your tool issue with Smokes. Can you provide a save for that?

Hub 01 Intercom has not been updated to use rigid groups so its restocks tend to be lackluster. That's JSON only and can be done easily for 0.G

Sorry, it's nearly 2am for me and I let myself put some unintentional hyperbole on the Smokes stock. I should've said "dwindled over time" instead and I'll change that.

Speaking of I did a quick investigation and found that Smokes only stocks 1 tool every restock which is probably the reason my tool supply dwindled. 13 restocks a season means only 13 new tools per season, meanwhile Smokes is constantly removing tools from stock.

andrei8l commented 2 years ago

Oh, I see the issue with Smokes now. He fills up the utility shelf with glass shards so there's no room for anything else

Nerezza commented 2 years ago

Might need to set rigid to true on every shopkeeper item group too, so that they all restock reliably for 0.G stable. I'm worried that will make their inventories explode again though.

andrei8l commented 2 years ago

Not necessarily. Rubik and the isolated artisans had item spawns defined in JSON, which I assumed to represent the desired state of the shop, so I updated their shopkeeper groups to match.

I do think the other merchants need to be rebalanced (especially the free merchant in Hub 01's parking lot), but just adding rigid to their current item groups is not the solution.

stubkan commented 2 years ago

It is not a space issue, I dont think. I made sure there is tons of space by replacing his 20L garbage can and other limited space with warehouse shelving. I just had this bug strike again on my 4th visit to smokes and he still has tons of room left, but no longer shows new items or items I trade to him. He does get stock and he does delete old stock.

This smokes has 3700 merch (2300 before restock) and 3600 glass shards and a limited selection of others. It is possible that it stopped refilling or listing the inventory when it hit a couple thousand trash items. I'll have a look at the code.

andrei8l commented 2 years ago

There's no loot zone over the garbage can. It's an item number issue (there's a limit of 4096 items per tile) and I know that because I debugged it.

stubkan commented 2 years ago

No, dont think its space issue, smokes can access any item around him (traders access via zones and pick up distance in the code) and items will spill over onto the tiles around him when they spawn. This smokes has plenty of free space still around him. Part of his current stock is currently where the trash can used to be and is accessible.

andrei8l commented 2 years ago

and items will spill over onto the tiles around him when they spawn

Nope. There is no spill over. Items that don't fit are discarded. I wrote this code. You're maybe thinking of legacy traders spawned before #56720 that get a 3x3 fallback zone. If you're seeing a different behavior then please post your save file.

stubkan commented 2 years ago

When a tile gets too many items, it spills over to another tile - You can spawn in more than 20 logs, maybe 50 and see that occur for yourself.

image

I just read your PR that was supposed to make traders keep items only at their feet? Its not what is happening, that may be the problem? Since your code is checking only at his feet, ignoring what is around him?