cataclysmbnteam / Cataclysm-BN

Cataclysm: Bright Nights, A fork/variant of Cataclysm:DDA by CleverRaven.
https://docs.cataclysmbn.org
Other
681 stars 267 forks source link

"X has nothing to give!" commonly occurs when asking for items after accepting a mission, even when an NPC has items in inventory #2662

Closed chaosvolt closed 3 months ago

chaosvolt commented 1 year ago

Describe the bug

When asking an NPC for a handout, most notably when accepting a mission for them and successfully getting them to give you stuff, they'll say they have nothing to give. This seems to occur most often with standard static NPCs like the evac merchant, and less often with starter/dynamic NPCs.

Steps To Reproduce

  1. Start off at the refugee center.
  2. Accept their first mission and ask for stuff.
  3. Assuming you have like 20 speech, get them to agree and see the mentioned message.
  4. Repeat this with your starting NPC in an evac shelter, they seem more likely to successfully give you stuff.

Screenshots

image

Versions and configuration

Additional context

So, I'd done a bit of poking around and some tests to try and find the cause. I came up stumped but it might help. First, the relevant functions seem to be, in order, npc::wants_to_sell -> npc_trading::init_selling -> talk_function::give_equipment. A cursory glance at npc::wants_to_sell indicates that's not the cause because the evac merchant should ALWAYS be returning true on that, as they're assigned to the shopkeeper status.

So one thing I tried was inserting a use of add_msg to npc_trading::init_selling to confirm that it was actually successfully finding items when it does this. It does even when it still fails to find anything to give: image

All signs point to the cause PROBABLY being something in alk_function::give_equipment (https://github.com/cataclysmbnteam/Cataclysm-BN/blob/upload/src/npctalk_funcs.cpp#L528), possibly this bit right here:

    std::vector<item_pricing> giving = npc_trading::init_selling( p );
    int chosen = -1;
    while( chosen == -1 && !giving.empty() ) {
        int index = rng( 0, giving.size() - 1 );
        if( giving[index].price < p.op_of_u.owed ) {
            chosen = index;
        } else {
            giving.erase( giving.begin() + index );
        }
    }

Now, I had a "wait a second" thought and for a briefly instant thought I had an easy JSON fix for this, but sadly that turned out to be a red herring. It SEEMS like something about NPC debt is failing to process right here. So you ever noticed that "because I'm helping you out" is probably the persuasion option literally everyone picks because the other dialogue options have utterly abysmal success rates even at 10 speech skill? Funny thing about that: https://github.com/cataclysmbnteam/Cataclysm-BN/blob/upload/data/json/npcs/TALK_COMMON_OTHER.json#L309

It's the only one of the bunch that doesn't call add_debt on a success. So I tried getting the evac merchant to gimme shit using one of the other options, again noting that the success rate is always annoyingly much lower than the option everyone picks. No dice, the message still triggers. So something weird is PROBABLY going on with the NPC trying to decide how much debt they need to resolve when giving you stuff, but it doesn't seem that it's MERELY a lack of starting debt on the NPC.

Or maybe it is a lack of starting debt and calling add_debt at the exact same time as give_equipment doesn't let the debt itself actually hit, I dunno.

olanti-p commented 1 year ago

Related to / dupe of #1252

scarf005 commented 1 year ago

image

looks like NPC opinion isn't correctly updated.