SetAILevel
highv_priest
Member Posts: 50
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?
EDIT = Like does this function actually modify CPU time given to the creature and such?
0
Comments
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.
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.
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.
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.