Welcome to the second Developer Diary on how to use CS Event Engine in Vietnam 1.0. In the first part we talked about the latest CSEE version in CS Vietnam 1.0, now let us have a look how the new CSEE Lua library interacts with another Campaign Series gem: the Adaptive AI database.
Note: This is meant as an introductory blog about the coming features. There will be a complete CS Event Engine manual shipping out together with the game install.
Adaptive AI in a nutshell
Adaptive AI became available as of Campaign Series: Middle East 2.0. Here’s what our Lead programmer Berto wrote at the time, emphasis mine:
The Campaign Series AI — One size does not fit all!
Arabs did not fight the same way as Israelis. Jordanians outclassed the Egyptians, who outclassed the Syrians. Israel’s combat doctrines changed from 1948 to 1956 to 1967 to 1973 and beyond. The cocky Israelis at the beginning of the Yom Kippur War learned to give their revitalized Egyptian foes newfound respect and learned to change their ways. Adapt or die.
From nation to nation, from war to war, from year to year, even from one battle to the next — they all differed, so much evolved. But in the traditional Campaign Series, as in most (all?) war games, there is one and only one AI. Locked down tight. Mostly inaccessible to the scenario designer, much less to the player. Until now…
We have devised a new customizable AI System. Customizable by side, by nation, by scenario. Open to the scenario designer’s tweaking. Also to modder’s. We call this new system: “Adaptive AI.” As in: An AI that adapts to the side, the nation, the era, the individual scenario. (Not as in: Adapts real-time to changing game play circumstances. But that too will be implemented in future updates.)
The purposes of the Adaptive AI are:
- To coach the AI in ways and things it is too dumb to figure out by itself.
- To achieve game play “balance”.
- Not so much to improve the AI play as to better simulate actual combatant and scenario conditions.
- To achieve greater “realism” and “historical fidelity”.
- To add randomness.
- Thereby increasing replayability.
These cross purposes are often at odds with one another. Some Adaptive AI parameters will make the AI opponent “better”; others will make it “worse”. It all depends. Some players will like the increased uncertainty; others will not. It all depends. That’s why the Adaptive AI is optional. Select it or not as you wish.
Looking back at Adaptive AI: yes, it was static, required creating and adjusting scenario specific *.ai files, but at the same time: it truly opened the game parameter database for the scenario designers. If only it would have been easier to use…
Adaptive AI in Vietnam 1.0
Fast forward to CS: Vietnam 1.0, and the Adaptive Ai database itself got a thorough upgrade for Vietnam 1.0. At the time of writing this there’s a template file now with a slot for 200 adaptive AI parameters. So many new aspects the scenario designer can adjust on a per-scenario basis!
But what is completely new is the ability to access these parameters as the scenario plays on – from the CSEE Lua code, dynamically throughout the scenario play!
Now, the AI truly adapts itself as how the events take place during the play if the scenario designer so chooses. Have all the SAI controlled troops change their stance from a rear-guard action with Opportunity Fire set at sniping at long ranges to Ambush stance, where they only fire when they see the white of the eyes of their opponent! How cool is that!
Accessing AI parameters from CSEE Lua code
As a recap, here’s how the Adaptive AI was used with CS Middle East 2.0. See below for an example of how it worked at the time: first create a scenario specific *.ai file from the template, then tweak the parameters you want to change.
Here’s how some changes to Opportunity fire settings were made with CS: Middle East 2.0. A bit crude perhaps, but it got the job done:
So, what happens there, exactly? Here’s what the Sirte scenario specific AI file sets to play it out:
- opfire_sam2_helo_prob defines the likelihood Opportunity Fire kicks on against an aerial target. Think of this as SAM Radar noticing the target, and giving the firing co-ordinates to SAM batteries
- opfire_sam2_helolow_prob and opfire_sam2_helohigh_prob then define the likelihood the individual SAM battery being able to lock on to target, and to launch their missiles against the target.
In CS Vietnam 1.0, you can set those values you want changes within the scenario specific Lua file.
Here’s an example of how you set up Opportunity Fire values per generic level. This snippet shows just the part for setting Op Fire for all your armored units:
Let us look at available CSEE functions in detail. There’s one for setting a value anew and another one for increasing or decreasing the existing value per the parameter provided:
- set_adaptive_ai (side, nation, index, value)
- inc_adaptive_ai (side, nation, index, increment)
Here are the parameters, explained:
- side — “a”, “b”, or some function or expression evaluating to either of those side values
- nation — integer, or some function or expression evaluating to an integer; from 0 to 99
- index — integer, or some function or expression evaluating to an integer; from 0 to max Adaptive AI parameter #
- value — integer, -1 or greater
- increment — integer; 0, positive or negative
Let us then look at the first call from the code example:
- set_adaptive_ai (“nil”, FRENCH_NATION, 30, OP_MEDIUM)
And here’s what the parameters mean:
- “nil” – most AI parameters are set either per nation, or per side. Opportunity fire is per Nation, so side is not provided, ie. nil.
- FRENCH_NATION – there’s just two values for side, side “a” or side “b”. FRENCH_NATION is a variable with a value of “a”, used as a mnemonic and for ease of use. One could simply say “a” here as well.
- 30 – this is the Adaptive AI parameter index. 30 is for tanks firing at hard targets, 31 is for tanks firing at soft targets, etc. Parameters are explained in the manual, and in the Init-ai database file for baseline values.
- OP_MEDIUM – this is a mnemonic for a number value for medium range, ie. 2.
… and that’s all there is to access any of the circa 200 Adaptive AI parameters via CSEE Lua code, at any time, for any reason.
Here’s another example, this time from the CS: Middle East 3.0 early BETA. This is actually an equivalent of what was shown above per how these parameters were accessed via the *.ai files. This time, totally dynamic, with an ability to set and change these values per how the scenario play ebbs and flows.
To quote Berto again: Totally dynamic, no time restrictions whatsoever.
Thank you for reading this far!
In part 3 of the CSEE Developer Diary we will ber talking about how to program the computer opponent, or Scripted AI (SAI), to have a keen operational sense, in addition to how legacy AI handles the tactical situations.