Improving the NPC-object interaction AI

Discussion in 'Mechanics' started by AngleWyrm, Sep 2, 2017.

  1. AngleWyrm

    AngleWyrm Scruffy Nerf-Herder

    I've noticed that as the number of tenants in a village goes up there is an increase in lag. Also, as the number of objects that tenants can interact with goes up the performance goes down. I believe this is a substantial contributor to lag in the quest hubs, shopping centers and pre-designed towns.

    I get the feeling that each NPC is going through and considering a list of possible interactions, which results in an escalating number of possibilities as the number of NPCs and objects go up:
    [​IMG]
    The count of considerations in each complete pass is similar to a squaring function, which doesn't scale well. So what can be done to the design that will eliminate this escalating use of processing time?

    If/Then and Mapping
    The thought process If->Then is an atomic mapping of one situation to one outcome. When there are many such similar mappings of input->output its more efficient to use a dictionary lookup of key-value pairs. Instead of considering each situation in a list of possibilities, the present situation is passed to the dictionary which returns an outcome.

    For the curious, the speed of a string of if-then statements is proportional to the number of if-then statements, O(n). Dictionaries use a hash map lookup function which is done only once no matter how many entries are inside, and so their execution time is not proportional the number of items in the dictionary, O(1).

    So we have a situation where the number of considerations goes up much faster than the number of NPCs and objects, something similar to (vertexCount - 1)^2 in the above image, a relationship like a 2D area resulting from a pair of 1D measurements NPC count and Object count.

    Suggestion
    When the NPC is given an opportunity to consider interactions, make a single RNG roll on a table of all possible interactions. If there is some desire for priority sorting, give each table entry an integer count of outcome chances so that the RNG can resolve more than one return value to the same outcome.
     
    Last edited: Sep 3, 2017

Share This Page