Home » MODDING HQ 1.13 » v1.13 Coding Talk » AI light avoiding behavior
AI light avoiding behavior[message #302647]
|
Sun, 01 April 2012 17:46
|
|
hermano |
Messages:4
Registered:April 2012 |
|
|
Let me first say that I play JA2 since day one and only now had a look at your mod. It is really excellent in most aspects and I'm really enjoying it.
There is one big gripe for me however, the behavior of AI in nighttime combat in lighted areas. This can be mainly seen with militia but is probably true for enemies as well. On their way to their destination when stepping into a lighted tile they will turn around halfway and leave the lighted area, going back where they came from. Or, if they are already standing in light, they will leave the light, then turn around and continue to their destination, stepping back into the light. This will get them stuck in a continous loop where they will never reach a destination on the one hand and step into light every single turn on the other hand. It is horrible at Drassen airport where most are caught at the gates and only a tiny fraction of the militia will fight while the rest will waste your time and turn the combat into a frustrating experience.
It shouldn't be too hard to change this behaviour and I would be willing to put my time into it. I have not looked at the source yet, so I will have to guess right now. Since JA2 is from the nineties I expect it to use a variation of A* or some related pathfinding. If this is the case the problem could be solved easily by increasing the pathing cost for lighted tiles. This would solve the problem as they would stll continue running trough light if it was the only path available and otherwise avoid lighted tiles. The portion of the code that makes them leave light when they do not have a target destination could be left unchanged.
I hope I selected the right part of the forum for this post. Should I start looking at the code and implement a solution or would that be unwanted behaviour around here? I'm new to this forum and don't mean to offend anyone. Is someone in charge of AI behavior?
Report message to a moderator
|
Civilian
|
|
|
|
Re: AI light avoiding behavior[message #302650]
|
Sun, 01 April 2012 18:18
|
|
hermano |
Messages:4
Registered:April 2012 |
|
|
Thank you, DepressivesBrot. I'm downloading the sourcwes right now and will have at look at it. If I'm guessing right the changes should not be too big. I'll try not to lose my sanity, the little that is left at least .
Edit:
I will probably have something to show at the weekend, my free time this week is a bit limited. I first had to install Windows as VisualStudio would not work on wine. Installing and updating all that stuff was a waste of time and I currently really hate Microsoft and their products.
I had a look at the code and it shouldn't be much of a problem to change the pathing to avoid lighted areas. I'll have to put in a bit more effort as merc pathing will be affected as well, both in turn based and real time situations. This is a two-edged sword. It will be quite nice if mercs avoid stepping into light when sneaking around. On the other hand it would be annoying if you want them to run somewhere and the pathing would not give you a direct path when light is around. I think making the behaviour dependent on merc stance should be a good solution. Prone or crouched mercs will avoid lighted areas at night and will only path through it if the alternatives are to long or if you send them right into the light, while walking and running mercs will completely ignore lights for their paths.
Another byproduct would be that AI and mercs would avoid burning areas as these are lighted as well, if I remember correctly. This is also two-edged. On the one hand more intelligent behaviour will be nice, on the other hand those joke situations where enemy soldiers run repeatedly into burning areas and die horribly by the dozen will be a thing of the past.
I will report back when I have something to show.
[Updated on: Mon, 02 April 2012 17:39] by Moderator Report message to a moderator
|
Civilian
|
|
|
Re: AI light avoiding behavior[message #302882]
|
Fri, 06 April 2012 20:27
|
|
hermano |
Messages:4
Registered:April 2012 |
|
|
I had some time to code today and implemented a first version of light avoidance for pathing.
A light avoiding path will be computed under following conditions:
The map is aboveground, lightlevel is nighttime (so dusk/dawn are excluded),
for milita and enemies: regulars will avoid light under red and black status, elites will always avoid light, green milita and administrators will not avoid light
for mercs: prone and crouching mercs will avoid light, others will ignore light.
Pathing costs (not AP costs) for lighted tiles are doubled, so characters will usually chose an unlit path unless its AP costs are more than twice as big as those of a lit path. There should be no slowdown during daytime, in lighted areas during night the slowdown should be pretty much imperceptible.
I don't have time to test how these changes are working out today, I'll probably be able to run a few tests on monday. If everything works fine I'll post the changed files (PATHAI.h and PATHAI.cpp) and a compiled .exe here.
Report message to a moderator
|
Civilian
|
|
|
|
Re: AI light avoiding behavior[message #303096]
|
Mon, 09 April 2012 14:15
|
|
hermano |
Messages:4
Registered:April 2012 |
|
|
I have terrible news. The old notebook I've been working on died yesterday, it's CPU took its last breath. I do have a copy of the sourcecode and will post it here. My work on this project however will be halted for the foreseeable future. It would be great if someone would test these changes, or if someone knew someone else who would be willing to.
Let me explain what I changed about the code, it's just a few lines that should be easy to read, even for a c beginner, and are well documented. All changed parts can be found by searching for 'hermano'.
In PATHAI.cpp a copy of the function 'FindBestPath' named 'FindBestPathAvoidLight' has been added. This way slowdown of pathfinding in all circumstances where light avoidance will not be needed is prevented.
In 'FindBestPathAvoidLight' there is this line:
if( LightTrueLevel( newLoc, ubLevel ) < NORMAL_LIGHTLEVEL_NIGHT ) nextCost*=2;
doubling the path cost for all tiles with a light level higher than nighttime light level. Wether the factor two is a good solution will have to be tested, a factor of 1.5 might work well too.
The function 'PlotPath' in PATHAI.cpp was changed, as well. Here it is being decided if usual pathing or light avoiding pathing should be used. This should effect all instances of pathfinding.
In PATHAI.h a reference to 'FindBestPathAvoidLight' has been added.
In 'DecideAction.cpp' I tried to change AI light avoiding behaviour as mentioned by FlugEnte in the previous post. AI should not abort all actions and flee from light if it still has a path computed. I don't know the code well enough to state that the added clause
&& pSoldier->pathing.bPathStored == FALSE
will actually work as intended. I wanted to test this today.
That's it, as you see the changes are pretty minor and simple. The code compiled without problems, but I never got to test it, I'm sorry. As I added only a few lines I hope there will be no bugs, but as you know typos do happen. I'll check back to answer any questions. I hope somebody will have a look at this.
Files: Sources
The original files were taken from last weeks source SVN.
Edit: Found a bug, changed the line and reuploaded the files.
[Updated on: Mon, 09 April 2012 14:25] by Moderator Report message to a moderator
|
Civilian
|
|
|
|
|
|
|
Re: AI light avoiding behavior[message #327109]
|
Thu, 24 October 2013 21:43
|
|
Kriplo |
|
Messages:256
Registered:February 2008 Location: Zagreb - Croatia |
|
|
Thanks Bananarepublic,
Scheinworld already provide me with necessary files, forget to update topic.
Currently not working on this problem so who ever like could try to improve this.
Report message to a moderator
|
Master Sergeant
|
|
|
Goto Forum:
Current Time: Sat Nov 30 11:03:33 GMT+2 2024
Total time taken to generate the page: 0.01169 seconds
|