Skip to content

SetAILevel

highv_priesthighv_priest Member Posts: 50
edited January 2018 in General Discussions NWN:EE
Can we get some confirmation from someone working on the source code of nwn whether this function does anything other than override the ability to use GetAILevel to determine if players are in a map(and/or fighting NPCs)?

EDIT = Like does this function actually modify CPU time given to the creature and such?

Comments

  • SherincallSherincall Member Posts: 387
    (don't actually have source access, but...)

    Each AI level has a separate list that objects are added to. What it roughly does is go through the highest priority list first, then the next one, and so on, until it runs out of time for AI updates this iteration.
    It always keeps track how much time has passed since an update for each list. Lower priority AI levels can have more time pass between update cycles (there's some aging algorithm). However once it decides to update an object, it completes the update.

    So at lower levels, the updates may not be as frequent, but when they happen the full CPU time is given.
  • highv_priesthighv_priest Member Posts: 50

    (don't actually have source access, but...)

    Each AI level has a separate list that objects are added to. What it roughly does is go through the highest priority list first, then the next one, and so on, until it runs out of time for AI updates this iteration.
    It always keeps track how much time has passed since an update for each list. Lower priority AI levels can have more time pass between update cycles (there's some aging algorithm). However once it decides to update an object, it completes the update.

    So at lower levels, the updates may not be as frequent, but when they happen the full CPU time is given.

    At what point would you notice a difference with this? I've had tons of handplaced AI on custom maps created that all fired their heartbeat at the exact same time as every other one(I know because I was doing some testing on it) and they ALWAYS fired it(they listed themselves as a number sequence and the server followed up with the highest number sequence). They even consistently fired it when I consumed virtually the entire process thread with an exponential increasing script loop.

    Some of the AI had different levels and some of the AI were on the same map as me(the player). Others were on different maps.

    Even towards the end of the exponential loop where my framerate became single digits, the heartbeats ALL still fired. I also tried experimenting with using random to have some of the creatures perform different activities ranging from moving to a random location, creating an item in their inventory, attacking one of the other creatures, and running a while loop to deal 1 point of damage to every single object in the area.

    Even still they all still fired their heartbeats.
  • SherincallSherincall Member Posts: 387
    edited January 2018
    I don't think it affects heartbeats. Looking at CNWSCreature::AIUpdate(), the only script it can run is the OnCombatRoundEnd, if the round has ended since the last time it was triggered.

    Other stuff it does (for creatures) is:
    - Perception list update
    - Update effects
    - Run whatever actions are queued
    - Combat handling, AOO, excited state, etc.
    - Spell slots update


    For performance, it might be a good idea to use GetAILevel and bail early in some HBs if it is lowered.

    EDIT: On the other hand, areas and placeables do run their HBs in the AIUpdate, so creatures likely do as well, I just missed it. Looking again..

    EDIT2: Yup, found it. It does to heartbeats as well. My guess is that the limits for all lists are <6 seconds, so any of those rare events like HB will fire. Best to wait for a dev to confirm.
  • highv_priesthighv_priest Member Posts: 50
    Yea I'd really like to know honestly how best to utilize this. I have one hell of a powerful AI that emulates player intelligence as best as I can get it, but it's very CPU intensive(reserved for enemies who are supposed to be a real strategic challenge). The problem I have is that when this intelligent AI is on a map and around the server is hundreds of simple AI also doing things it causes lag infrequently, but frequent enough to be an issue(basically ever), because the server's CPU is not capable of running the intelligent AI with so many simple AI also running at the same time, triggering the same frequent updates.

    When profiling it the intelligent AI is consuming a large amount of runtime, but the issue is that all those simple AI are also still using a lot of run time. Even with me streamlining it and making the simple AI utilize just 2 events(OnPerception, CombatRoundEnd) they are still an issue.

    Eventually I got around the issue by making all these AI slaves to their respective areas(utilizing a normal heartbeat), which would puppet their brainless bodies to do things and that was the only solid solution I found.

    Basically I'd much love if SetAILevel could be used somehow to make a genuine impact on the resource usage of an NPC, but I don't believe it does at this time.
  • ProlericProleric Member Posts: 1,269
    Putting it the other way round, if you issue an action to an NPC in a dormant area, it never happens any time soon unless you boost the AI level. So the function definitely does something important.
Sign In or Register to comment.