Adaptive AI settings and Lua

Post new scenarios and mods here to share with other gamers.

Moderator: Campaign Series Matrix Edition Development Group

Post Reply
User avatar
Crossroads
Posts: 18151
Joined: Sun Jul 05, 2009 8:57 am

Adaptive AI settings and Lua

Post by Crossroads »

Want to have scenario specific settings for Adaptive AI for a new scenario you are putting together?

There's two ways to approach this.

Add a scenario specific *.ai file

First, you can create a scenario specific *.ai file, where the "*" part must exactly match the scenario file you have created. For instance: IC_510529_DR1_Ninh_Binh.scn -> IC_510529_DR1_Ninh_Binh.ai

In that *.ai file, override the Side specific and / or Nation specific values you want to alter with values you want to use. Just fill those values, on scenario specific ai files it is recommended to have all unchanged values as "-1" ie. "no change".

I put together a boilerplate for that, to be made available in 1.01, also attached to this post.

Pros: Just add the *.ai file, change the values you want to alter. That's it.
Cons: Static, *.ai file is read once scenario loads, those values then stick for the whole game play

Change AAI parameters from scenario specific *.lua file

With this approach, you'd call a CSEE api for setting the parameters you want to change:
FUNCTION

set_adaptive_ai (side, nation, index, value)

DESCRIPTION

Sets the Adaptive AI value for the given index, and side or nation.

If nation is -1, set the side parameter value. Otherwise, set the nation parameter value.

INPUTS

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

Look for examples on how to do that from for instance all Day River lua files: for instance IC_510529_DR1_Ninh_Binh.lua. I do them in static manner at on_startup() by calling a custome init_aai_settings() function that is at the end of the lua file. You can alter AAI settings at any stage of gameplay though, this is dynamic.

For example:
-- # 45 [ n] AI_oplimit_otherfiring_othertarget
set_adaptive_ai ("nil", FRENCH_NATION, 45, OP_MEDIUM)
set_adaptive_ai ("nil", VIETNAMESE_NATIONAL_ARMY_NATION, 45, OP_MEDIUM)
set_adaptive_ai ("nil", VIET_MINH_NATION, 45, OP_SHORT)

I find it helpful that I first copy the parameter info from the init.ai file, to also document what's happening. Then just provide the Side and or Nation ID, you can hardcore "a" or "b" for Side, or Nation ID such as 10 for US, or use declared values. All Nation names can be found from user.lua.

Pros: this is fully dynamic, you can change any parameters for instance Op Fire settings on a fly
Cons: Lua file and some programming required


I hope this helps, sorry for lack of documentatio at this stage on AAI or Lua for that matter, we will remedy this with documentation over the coming weeks.

Any questions, please let us know!

_scenario_boilerplate.ai attached below.
Attachments
_scenario_..lerplate.zip
(885 Bytes) Downloaded 24 times
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < v2.00.03 Remastered Edition (May 20, 2025)
CS: Middle East 1948-1985 < v3.00.03 Remastered Edition (May 20, 2025)
TomWalton
Posts: 33
Joined: Thu May 17, 2007 4:52 pm

RE: Adaptive AI settings and Lua

Post by TomWalton »

Interesting! What would be really great (no rush ;-)!) would be to have a couple of really, really simple step-by-step video tutorials for those of us who are pretty much complete beginners at this...

As with all the Campaign Series games, amazing that the game even comes with editors, though this of course is a step up!
User avatar
Crossroads
Posts: 18151
Joined: Sun Jul 05, 2009 8:57 am

RE: Adaptive AI settings and Lua

Post by Crossroads »

Berto's in process of writing a CSEE Lua manual, but that will take some time, with 1.01 UPDATE having priority. Agreed, a video tutorial would be nice too. Stay tuned!
Visit us at: Campaign Series Legion
---
CS: Vietnam 1948-1967 < v2.00.03 Remastered Edition (May 20, 2025)
CS: Middle East 1948-1985 < v3.00.03 Remastered Edition (May 20, 2025)
Post Reply

Return to “Scenario Design and Modding”