-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: NPCs drop excess items if overburdened, merchants pick up and renew inventory if restocking #3386
fix: NPCs drop excess items if overburdened, merchants pick up and renew inventory if restocking #3386
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
000e5da
The tests failed for this PR
|
that makes sense. I forgot to run tests and fix as I went. It's because this condition is true for the test if( activity.targets.empty() ) {
drop_invalid_inventory();
} so the test character is immediately dropping items once overburdened. |
I was using These tests pass again in #3387 |
Summary
SUMMARY: Bugfixes "NPCs drop items if overburdened instead of just overvolume, merchant restocking fix"
Purpose of change
Merchant NPCs in the Refugee Center,
Christopher Flood, Merchant
andMakayla Sanchez, Arsonist
, stay way overburdened even after callingdrop_invalid_inventory
because it was only able to drop items above volume limits. Combined with the checking for the"LIFT"
quality when overburdened inweight_carried_reduced_by
, a very slow check because it looks over all items in tiles (map and vehicle) withinPICKUP_RANGE
distance of the NPC, these two NPCs were using a lot of CPU time to do literally nothing but stand in place.This problem is mitigated in #3385 since these NPCs do not carry weapons a lot of the time. They're also relatively shielded from the monsters hidden within the Refugee Center so are unlikely to carry weapons unless things go very poorly for the building.
To go with dropping inventory when overburdened the NPC merchants also need to properly restock their wares. If they've dropped their inventory then on restocking their remaining undropped inventory will be deleted and replaced by whatever is generated as new stock. This can lead to an accumulation of items at and around the NPC as new items are stocked then spilled onto the floor. To fix this I have the NPC pick up nearby owned items before clearing the inventory and restocking.
To prevent an issue with the Arsonist, and any other NPC Merchants with the
"no_faction"
faction defined, where restocking items will not actually generate any due to the faction wealth being too low and thus delete the NPC's inventory without replacing with anything I have limited picking up, clearing, and finally replacing the inventory by requiring there be something to restock.Describe the solution
Dropping items by weight works very similarly to dropping items by volume. The primary difference is that it is not done within the
inventory
class but outside of it. There is no reason to make it a class method when all necessary functionality is available from outside of the class. By keeping NPCs from being overburdened as much as possible we prevent the costly"LIFT"
quality check in most cases.Picking up owned items prevents accumulation of items on the floor, and restricting it to if there are items replacing the old prevents the Arsonist from completely losing their stock. The Arsonist still will not ever restock but that makes some sense as they're a random fire starter, presumably without any backer and unknown means to produce more incendiary devices.
Picking up owned items is made a free action because they're about to get deleted and replaced, and then probably dropped onto the floor again which does take moves away from the merchant.
Describe alternatives you've considered
Instead of requiring new wares to allow deletion of old inventory the minimum
shop_value
could have been modified to allow some items, or allow generation of a few "free" items before they start deducting fromshop_value
.Testing
NPCs drop items when overburdened, and Merchants pick up nearby items properly when refreshing their stocks. Arsonist no longer deletes their inventory without replacing any of it.
Additional context
If the NPC drops items onto a vehicle tile they will not be picked up again when restocking inventory. I'm not sure if that would be desirable and erred on the side of minimizing the NPC's reach. These items picked up ARE about to get deleted so being a bit conservative seemed best.