smilz0 / Left4Bots

Improvements for the L4D2 survivor bots
https://steamcommunity.com/sharedfiles/filedetails/?id=3022416274
34 stars 4 forks source link

[IMPROVEMENT] Manual Attack Optimization #94

Closed MutinCholer closed 3 months ago

MutinCholer commented 3 months ago

In #76, the problem with performance came down to the foreach loop calling the trace line function more often than it should even with other statements preceding it. While I initially suggested that the trace line function should be called only once, it turns out that it can cause the survivor bots to occasionally not shoot the common infected if the visible one is farther away than the closer one that cannot be seen as you have pointed out in the previous issue.

My new proposal would be to add all common infected to a local array and then sort all of the entities in the array from the closest to farthest distance before the trace line checks are performed in another foreach loop. This allows the next closest common infected to be targeted instead of ignoring the closer one that cannot be seen.

From my testing, the performance improvements can be quite massive when dealing with a lot of common infected at once. This is most noticeable in some custom campaigns that spawn way more common infected than necessary (especially in Glubtastic 3's train chapter).

Here are two videos showcasing the difference in performance using two different methods when faced with 200 common infected.

https://github.com/smilz0/Left4Bots/assets/64824187/01aac2f6-1f6d-47a9-b809-c8a88c0ff21a ^Old Method (Trace line in one foreach loop)

https://github.com/smilz0/Left4Bots/assets/64824187/d56156b4-a643-4a00-a955-daa31f9663de ^Proposed Method (Trace line in ordered foreach loop)

And here is the ZIP file containing the left4bots_afterload.nut file if you would like to take a look at it.

Manual Attack Optimization.zip

4512369781 commented 3 months ago

I did something similar, but I grouped the infected every 32 distances, then sorted them, and finally did tracing. Apparently your method is simpler and faster.

  1. minDist = 999999999; no need do this, just 'minDist = radius'.
  2. The priority of the tank should be higher than common infected, otherwise bots will ignore tank before killing all the common infected they can see it. But we also don't want to bots stuck on CI, so if tank is there, always kill CI in 120 radius first.
  3. About witch and tank, I think no needed to check is bots facing them, they always will look at it, just not shoot sometimes.
  4. Except common infected, don't check "m_lifeState", because special/boss infected will delete from the tables when they dead.
  5. Should build based on the latest version, v2.0 has bug in "Left4Bots.FindBotNearestEnemy" function.

my edit: edit.zip

smilz0 commented 3 months ago

Thanks guys, give me some time to test it.

smilz0 commented 3 months ago

Hey guys, i updated the /out version with this change but i made a little change to it. I removed minDist because i think in some cases it would have caused issues. Basically if the first checked infected was a close one, it was added to the array and minDist was updated with its distance but with the if "dist < minDist" all the next infected were going to be skipped. Now, most of the times the closer infected is likely to be visible to the bot so no problem, but if that infected was not visible that resulted in the bot not shooting any infected. Let me know if i made a mistake with this or i added any other bug.

Also, @MutinCholer can you add me on steam?