Jump to content
ProfTournesol

Create a wargame style mission with challenging enemy AI

Recommended Posts

Hi,

i'm regularly trying to make Wargame style missions (for my own historical mods most of the time), and i managed to command my own side, creating progressive reinforcements and involving the leader (not only "select and click", but also having to come close to the units to command them - no radio at those times), using various markers who indicate where are the units, and if they are fleeing or not, etc. (You can have a look at this Veni Vidi Vici wargame if you like : http://rapidshare.com/files/3643078955/VVV_WARGAME.Ancient_noe.rar)

BUT, i always find that the enemy AI is far from being challenging.

  • The most challenging i found is to divide the map in several areas, each areas being held by enemies, and each time you conquer an area, you gain reinforcements. Thus, you have to use your units cautiously, even more if the reinforcements are scarce. But in the end that's boring.
  • I tried to use guard triggers and waypoints, being well aware of this and this, but the problem is that it's quite easy to defeat the AI cause you only have to wait it at the guard trigger location, AI will send reinforcements that you can defeat one by one.

What i'm looking for is (probably a set of scripts or whatever) :

- an enemy AI that has to hold several positions BUT that tries to attack yours too ;

- an enemy AI that will try to send enough units to defeat you when you threaten one of their strongholds ;

- an enemy AI that will send scouts all over the map (i've got cavalry, i would like AI to use it as recon !) and try to challenge you as soon as possible.

So for example, if i threaten several enemy strongholds at the same time, enemy AI will defend only those he is able to, leaving the weakest ones (and less important one) and retreating carefully to defend the others.

Any thoughts ?

Thanks for reading :)

Share this post


Link to post
Share on other sites

Maybe try these scripts that kenoxite found? I think for the scouts the Walker Manager script would work.

If I said something stupid, apologize me, I've no idea about advanced singleplayer missions.

Share this post


Link to post
Share on other sites

For patrolling i usually use the ups script by Kronzky, which makes the units patrolling an area quite nicely. But there is no strategic purpose behind it, such as "hey, i found not only one unit, but several, maybe should i plan a raid against those units with other of my buddies units".

Share this post


Link to post
Share on other sites

I guess you've done already, but have you considered DAC? It does quite a lot of what you seem to need. Zone control, patrols, etc.

Apart from that, Drongo69 took several steps in that direction, particularly with Drongo's Toolkit. There the AI (of both sides) was able to recognize strategic locations (usually towns) and send and generate troops, the amount and quality based on their victory progress. Unfortunately, he left the OFP scene (at least temporarily) before developing it further, so I don't think he included more advanced behaviour like the ones you ask for. The AI will try to assault or defend a location, but without context (meaning, their decisions are mainly random).

Also, in CCE when the AI detects enemies (a player group) it pinpoints their last known location and enemy squads will go there to reinforce depending on their proximity and readability, which works similarly to the scout behaviour you mention, to some extent. Again, the checks are quite simple, and the AI can and will ask for reinforcements when the detected player group is simply flying over to a mission location, for example.

So, well, either you tweak DAC to fit your needs or you really need some custom scripts which, as you suggest, would mean to create a custom version of CTI/Warfare. I could give it a go if you like, although it's not a simple task. Particularly if you would like all this to be MP compatible.

Maybe try these scripts that kenoxite found? I think for the scouts the Walker Manager script would work.

Well, I actually made all those scripts myself :P

And I'm afraid that the walker manager is too dumb for what the Professor needs. It was mainly created to move around civilians after all. UPS is an excellent script and closer to what he requires, even with its drawbacks.

Edited by kenoxite

Share this post


Link to post
Share on other sites

I would start by googling articles (or even buying a book) about turn-based and realtime strategy game AI, written by some professional game programmers. It's a very complicated task, but you can probably also find some simple yet effective methods that would be suited for OFP's scripting limitations.

Share this post


Link to post
Share on other sites

As kenoxite said, Drongo's Toolkit has some AI based around securing objectives. I had some ideas like a master AI script that would assume a general posture of attacking or defending, based on how many objectives were currently held by each side. In an unreleased version the AI commander would send recon units first, then combat and support units behind those when assaulting an objective.

Even simple stuff like making a group wait until there were a few other friendly groups around before issuing them all the same order would be more challenging. Give a group a "Wait for reinforcements" order, give other groups a "Move to a group that is waiting for reinforcements" order and when the distance between them is short enough, order all groups to move to the same target.

Another idea would be to grant the AI "cheat" points (or command points or whatever you want to call them). So for example, every time they gather 10 resources, they get 1 command point. When these points cross a certain threshold the AI can use special attacks like spawning several groups at the same time and moving them together, etc. Basically like the special powers used in some RTS games.

Just a few ideas I've had when thinking about similar stuff.

Share this post


Link to post
Share on other sites

Thanks guys, that's very interesting. So basically :

  • AI could defend strongholds with guard triggers and WP (i know that it does prioritize GUARD triggers in the order you put them on the map, the first one being the most important, then send groups with GUARD WP to the nearest undefended ones, reorganizing them when groups are fleeing) ;

  • AI could send scouts (cavalry) randomly all over the map (with ups script for example), then, by attaching a "detected by" trigger to their leader for example, monitorize the amount of units detected and send reinforcements accordingly.

In an unreleased version the AI commander would send recon units first, then combat and support units behind those when assaulting an objective.

Mmm... that's very interesting. I could create separate combat groups with scouts (cavalry), assault groups (regular infantry) and support groups (reserve infantry). Would it be possible to have a look at this unreleased version ?

Share this post


Link to post
Share on other sites

Mmm... that's very interesting. I could create separate combat groups with scouts (cavalry), assault groups (regular infantry) and support groups (reserve infantry). Would it be possible to have a look at this unreleased version ?

There's no need to attach triggers. For something as simple as knowing how many enemies are close you could use a mix of a single trigger that keeps track of all the units and then either a single scripts that iterates through all the scout units that you need to apply the check to or run a script for each scout group.

Assuming you use a trigger activated by Anybody and named "allUnits" covering the mission area, you'd only need to check for this:

#loop
_myScouts =+ myScouts
_detectedEnemies = []
_n = 0
#nextScout
_scout = _myScouts select _n
_eGroup = grpNull
{ _eGroup = group _x; if ((_scout countEnemy (units _eGroup)) > 0) then {if (!(_eGroup in _detectedEnemies)) then { _detectedEnemies set [count _detectedEnemies, _eGroup ]}};} forEach list allUnits
~0.01
_n = _n + 1
?(_n < count _myScouts):goto "nextScout"

_n = 0
#countEnemies
?(_n >= count _detectedEnemies): goto "wait"
_enemy = leader (_detectedEnemies select _n)
format ["enemySighted%1",_n+1] setMarkerPos getPos _enemy; 
_n = _n + 1
goto "countEnemies"

#wait
~5
goto "loop"

The scripts goes through all the units added to the myScouts array, and checks if they are detecting an enemy unit. When a _scout detects enemies it adds the leader of the enemy group to the _detectedEnemies array. Once all the scouts have been checked then we go through all the detected enemies, and place an "enemySighted<number>" marker over the position of their leader (this assumes you have previously created, say, 10 markers named enemySighted1, enemySighted2, etc up to enemySighted10). We could expand that check in many ways. It could only place a marker if there's two groups together (say, less than 200m), as that should be considered a single threat, and not multiple ones.

This would only need a single trigger and a single script. The scout units would need to be previously added to a global var (myScouts) either in their init line in the map editor or when spawning them if done dynamically (myScouts set [count myScouts, leader group this]). And removed from the global array when they are killed or removed with deleteVehicle (this addEventHandler ["killed",{myScouts = myScouts - [leader group this]}]).

BTW, note that I haven't checked the code posted above, although it should work.

Edited by kenoxite
updated code so it now tracks groups and not group leaders and it will skip them if already added to the detected array

Share this post


Link to post
Share on other sites

Ok, first i didn't understand your script until i realized (thanks to the wiki) that countEnemy needs a level of knowledge to actually count an enemy unit. Thanks a lot, that will be useful for sure :)

For the second part (the markers one), i use a bunch of markers for each enemy group that follow those groups and appear on the map only when they are part of a big "detected by" trigger covering the whole map, then returns to an invisible state when not detected.

Share this post


Link to post
Share on other sites

I think a guard waypoint script hybrid would be the most elegant way, since you want to avoid micromanaging the groups. Just use scripting to move the groups' waypoints around according to the "big picture" as happens in an RTS. I believe groups tend to "retreat" towards their leader's original editor position (the invisible waypoint 0 in their waypoint array, which can be moved as such) so bear this in mine if you are going to make use of group morale mechanics.

You could try two philosophies with an RTS style AI script, first is to try to make them human like by tracking the number of units they know about (as detected by their side) then responding according to the disposition of known enemy units. The second way would be to have a more "godlike" AI that knows the entire game state and responds according to the player's current state (think of the Left4Dead AI director), this would give a more consistent challenge to the player but could get predictable without some randomisation.

Another way of doing it would be to run a separate FSM script for each AI group in the game that responds independently of the other groups on its side. This would allow you to put more intelligence into the group's decisions but can make the overall response disjointed since there would be no coordination with other groups.

Share this post


Link to post
Share on other sites
Ok, first i didn't understand your script until i realized (thanks to the wiki) that countEnemy needs a level of knowledge to actually count an enemy unit. Thanks a lot, that will be useful for sure :)

For the second part (the markers one), i use a bunch of markers for each enemy group that follow those groups and appear on the map only when they are part of a big "detected by" trigger covering the whole map, then returns to an invisible state when not detected.

I should have stressed the importance of countEnemy, as that's the the most important part of that script :P

And about the markers, I used that just as an example. You can replace that with whatever you want to do when enemies are detected.

I believe groups tend to "retreat" towards their leader's original editor position (the invisible waypoint 0 in their waypoint array, which can be moved as such) so bear this in mine if you are going to make use of group morale mechanics.

Yes, it seems the whole morale/fleeing mechanics is tied to group leaders. Both to their skill (which seems to be used to set the fleeing threshold) and to their original positions (as you mention, used as the place to go when fleeing).

Share this post


Link to post
Share on other sites

Mmm... that's very interesting. I could create separate combat groups with scouts (cavalry), assault groups (regular infantry) and support groups (reserve infantry). Would it be possible to have a look at this unreleased version ?

I can send you a copy, but I stopped work on it awhile ago. I have no idea how well it is working, how well-documented it is, etc.

Share this post


Link to post
Share on other sites
I can send you a copy, but I stopped work on it awhile ago. I have no idea how well it is working, how well-documented it is, etc.

Thanks, i'll just have a look to what way you followed to try and achieve this. Thanks to all of youy i've some better ideas now.

Share this post


Link to post
Share on other sites
Sorry for the delay, here is the WiP version of DT:

http://depositfiles.com/files/sdyqzwxkf

I really don't know what state it is in, so good luck. If you have any questions, I'll attempt to answer them.

Thanks a lot, i'll have a look ASAP. Everything i tried sofar is working nicely (commanding a large amount of troops with semi realistic way of giving order, having to come close to units' leaders to give them order, or send staff officer etc., seing friendly units markers all the time and enemy units markers only when detected) BUT i didn't succeed in scripting enemy AI better than what GUARD WP and triggers are doing by themselves. True that i'm not the best scripter around though...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×