Monday, April 16, 2012

AI Brain Hook: Will it work for your mods?

If I understand correctly the only thing keeping AI mods out of the Vault / Mod Manager is the inability to hook the lobby? If you guys have run into other limitations please let me know.



I am working on an interface to activate AI mods *after* the lobby. This should not be particularly difficult since the aibrain code *can* be hooked.



What I'm thinking is a simple mapping loaded from GetPreference('aimods') that maps each mod to the standard ones according to the hosts preferences. The concept is sound and I know it works because I've done it before (hooked an AI brain into the Human player one).



Anyway the point of this post is that I haven't gone through the code of anyone elses AI mod (and I don't have FA yet) and I don't have time to go through 60+ pages of mod threads so I don't know how extensively your mods hook the front-end and textures. Let me know if there's some limitation I've overlooked.|||Things keeping AI mods out of the vault:



1) Inability to hook anything in the lobby.

2) Inability to place files from the /mods directory into the proper /lua filepath.|||Could you elaborate on "proper /lua filepath". Do you mean shadowing? Could you also provide an example?|||Vault compatible mods have an internal filepath of /mods/name-of-mod



Gamedata mods use the /lua filepath.



To my knowledge (haven't fully tested it) aibuilder files and platoon template files have to be in \lua\AI\AIBuilders and \lua\AI\PlatoonTemplates respectively. So far as I know this is not possile with a Vault compatible mod.|||Ok, as a proof-of-concept I have rebuilt the Sorian AI 0.98c mod to make it Mod Vault compatible. I haven't added a menu yet, it just overrides the lobby choices with the 'sorian' personality. This is a first step towards introducing AI into multiplayer without a complicated install process or potential to break standard multiplayer or headaches with future patches.



The main catch is I wasn't able to pick up FA today so I had to emulate several functions to make it load in vanilla. It hooks in ok but crashes on BuildManager routines which are too complex for me to bother backporting. That's ok though, the fact that it gets that far shows that AI mods can be made vault compatible; either by mapping your archetypes over the standard ones or by presenting the game host with a mod selection dialog after the game is launched.



Technically there is nothing to prevent custom AIs from being loaded and unloaded at any time in the game - provided you take some care to record the handles of any forked monitoring threads for cleanup. I'm even pretty sure the engine will do this for you if the main ExecutePlan thread is killed. It depends a lot on whether you have blurred the lines between the "brain" and the threads controlling it. The more AI authors avoid modifying brain functions the better - as this will allow different AI mods to be loaded together.



I have uploaded the Sorian AI conversion here for anyone who wants to see how I did it. Remember it will only really work in FA and even that is an assumption but you should be able to iron out any bugs fairly quickly or use the code as a blueprint.



To activate the mod unzip it into your My Documents\My Games\GPG\SupremeCommander\Mods directory and then turn it on in the mod manager.|||I havent tried it yet, but has anyone verified if this worked?



(I will try later tonight).|||I didn't go ahead with the ingame AI chooser - instead I wrote a patch for shadow/hooking the lobby. It works but if you want to play with it I suggest waiting until Sunday. I'm going to release an update with an installer for the fiddly bits (the shadowing patch).



Technically this is not "vault-compatible" however there is only a once-off installation of the patch and then any mods dependent on the patch can be got via the vault. The patch has a start menu option to re-patch if you update/re-install SupCom or FA.



The patch only modifies lua files so it is quite safe. It is my preferred solution to frontend modding (over dropping things in gamedata) until GPG provide something better.



As far as AI goes I have written an 'AI Support' mod to simplify writing AI mods. It allows AI mods to be turned on and off in Mod Manager and they show up in the lobby automatically.

No comments:

Post a Comment