That was a lot of text! Took me a while to digest and answer.
PyroFire wrote: ↑Wed Dec 25, 2019 10:51 pm
find_ents_in_sphere() every tick could work too... but consider running that on 20~50 idle bots at the same time.
That's going to hurt in the frames.
The trouble with this mod is that it really isn't cheap UPS wise:
The biggest UPS hits are:
- Cars actively driving because it's Lua and on-tick. Having lots of vehicles is fine, just not all pathing and driving at once...
- Cars with a logistic sensor left parked in a logistic network zone for no reason. Remove the sensor or park cars outside the yellow zone once they've finished logistics requests.
I guess it can't be done differently.
And there is no on_entity_position_changed, so checking velocities every tick, while fine, would also have some complicated conditions, e.g. do we want to enter panic mode if the vehicle has been idle for a while, or only when the vehicle is already in a path, or whathaveyou.
There's more involved than it may appear, so you're back to hurting in the frames again at 20~50 bots.
Right, I still have to think that through. So far, something like the panic mode has been implemented for the train sensor (accelerate hard to get out of reach of approaching trains), but doesn't quite work -- I've seen stopped cars jumping to life when a train goes by and getting killed in the process. It's on my todo list, though.
Instead, why not just do a re-path with "panic mode" options? e.g. in a random-ish direction some distance forward of where the vehicle currently is, causing it to path around obstacles naturally. Combine your existing behavior, then after a short delay apply this "panic mode path". you don't get the path result instantly anyway, and you also want some delay before intelligent pathing kicks back in right?.
Not quite that easy. If the enemy sensor is present, the vehicle checks on every tick for enemies in a certain range around it. Enemies may chase it some way, so I can't know how far ahead I have to go until repathing is required.
This should result in a seamless illusion between "panic mode" driving and "getting back on track" that may give a more fluid and natural feeling to the ai's behavior, specifically unless it was mid-turn or about to hit something, it should maintain its speed and keep moving cleanly in most cases.
I'm willing to compromise, if necessary. In panic mode, things aren't rational. It seems appropriate that the vehicle goes off at top speed and bumps into things. If it hits a cliff, it may even go sporadically backwards for a while. I think it wouldn't hurt if it stopped completely to cool off a bit once it's out of danger. Currently, however, it doesn't stop but just accelerates against the cliff -- and thus can't be steered manually.
Interesting to note too, the "line intersections with cliffs" happens on the C++ level so it's a lot better than anything you could do with lua - the path result will or will not include a cliff (if there happens to be one) based on given collision masks.
An event for cliff collisions certainly would help. But I guess it couldn't be used for detecting water that prevents a car from moving (cliffs are entities, water should be tiles), right?
And we're kinda talking about tweaking the behavior of an AI anyway.
Why not just give some of that pathing intelligence to this panic mode state since it apparently needs it?
To be honest: I don't understand the code for moving vehicles completely yet. I've looked at parts of the code to fix some issues of it with one of my own mods, but it's not yet a week ago that I've been given collaborator status. So I'm taking it slow for now: getting some primitive panic mode working first, and refining it later on seems reasonable.
Anyway, thanks for the input! You've given me quite some material to think about, really appreciate it.