Merchants won’t carry anything

I’ve tried to trade with the merchant at the refugee centre, I had a spare acetylene torch but trying to sell it I got a message that he can’t carry all that. Is there a way to fix that?

Not currently. The problem is that NPCs only trade what they can carry. It wouldn’t be too hard to fix that in the C++ code, and if you know how to program I can point you to the relevant sections, but no one has fixed it yet.

I can try to do it. You can point us both.

1 Like

The NPC trading code is in src/npctrade.cpp.

It needs a lot of code clean-up but it mostly works so polishing it has been low priority for me.

The weight and volume of stuff that the NPC can trade is set on lines 191-192

    units::volume volume_left = p.volume_capacity() - p.volume_carried();
    units::mass weight_left = p.weight_capacity() - p.weight_carried();

your trading inventory is set in init_buying() on lines 79-115, and the NPC’s trading inventory is set in init_selling() on lines 48-67.

and the code to transfer inventory is inventory_exchange() at the top of the file.

if you compare init_buying() to init_selling(), you’ll notice that you add items from the ground an adjacent vehicle to your inventory, but the NPC does not. 90% of the time, that’s appropriate, but shopkeepers should be allowed to sell inventory from the ground.

You can check if an npc &guy is a shopkeeper with guy.mission == NPC_MISSION_SHOPKEEP.

So what needs to happen is init_selling(), there needs to be check for p.mission == NPC_MISSION_SHOPKEEP, and if it is true, the NPC adds inventory from the ground. Lines 191-192 need a similar check that lets the shopkeeper carry an unlimited amount of inventory, something like:

if( p.mission == NPC_MISSION_SHOPKEEP() ) {
    volume_left += 8000_liters;
    mass_left += 8000_kilograms;
}

and shopkeepers should use p.i_add_or_drop( it, true ); in inventory_exchange() except you’ll need to rewrite inventory_exchange() and that entire logic quite a bit; probably break it into two functions: one that removes items from inventory and one that adds them; both should use the inventory accessors from character.h instead of manipulating the inventories directly.

Thanks for volunteering to do this!