[AI] to what extent is the AI moddable ?

davidoux

Chieftain
Joined
Jun 15, 2014
Messages
3
Is the AI behavior only moddable via the
Gameplay/XML/AI files or is it possible to modify some lua scripts for more advanced editing ?

thanks
 
Almost all of the AI is coded in the DLL (C++ compiled code), and the XML permits "constants" within this defined behaviour to be tweaked. There is very little, if any, of the AI coded directly in Lua.

That's not to say that you can't use Lua to change the behaviour of the AI, but you are looking for ways around the base systems. For instance, you could step in at the beginning of every turn (via the GameEvents.PlayerDoTurn hook) and force all the AI cities to the production you calculate is most relevant, or you could hook GameEvents.CityCanConstruct to achieve similar results. You could then determine where all the AI units should be/doing/going and force then to do that via Lua. So while it's possible, some TCs have done it for CivV, it's not easy, as you are not making small/simple changes to existing code, but having to completely override large complex chunks of C++ in Lua
 
That said, some of the XML stuff mentioned by whoward is deceptively vital to AI functions. For example, all AI operations use formations set by MultiUnitFormations.xml, so you can alter the AI's unit composition (and positioning) by messing with values found in that file.

Also, while the a lot of the AI logic suffers quite a bit from finite-state syndrome (it can only be in a finite number of states usually representing extremes instead of along a continuum), the ones that don't can be improved quite a bit by simple XML tweaks. For example, the city specialization logic has a middle-of-the-road "general economic" specialization that's usually more likely to be selected than any other, specific specialization. If you turn up the AI's city specialization cycling frequency (via a value in GlobalAIDefines.xml), you can effectively get around the problem that the AI might "lock" a city into a non-ideal specialization for 20 or so turns. The fact that there's a middle-of-the-road specialization avoids the AI multiple personality disorder that you'd see if you did the same thing with, say, grand strategy cycling.
 
Back
Top Bottom