Multiplayer/Singleplayer AI

Modding, patches, etc., for anyone who speaks neither Polish nor Czech.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Multiplayer/Singleplayer AI

Post by Heike Steyer »

I had an idea of using the AI code from the Arab campaign to control AI in a multiplayer and also a singleplayer skirmish type map. (Of course, I take no credit for the maps, I just play them for fun :D) I just require the computer bases to do exactly what they do in the likes of ar4 and ar15a where the people stay in their respective buildings until required. (engineers repair/rebuild etc. and the soldiers in bunkers going to barracks if turret is dead) I tried to copy sections of the code but I kept running into errors, so if someone could help me it would be great, even if you just told me which parts needed to be take out it would be most helpful and much appreciated :)

Thanks!
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

The complete AI for controlling an entire base is at its core the same in all missions although it has been improved and refined in later missions as necessary. The AI in 15a_cont is by far the most advanced as it incorporates I think every aspect ever used and adds a little more. So I would recommend using that one.
Almost everything in module "Main" initializes the AI by "scanning" what is has available (buildings), as well as initializing variables and spawning personnel. The actual control code is in module "AI". You will probably need everything in there except for the mission specific stuff (takes a little effort to weed out), the code controlling when and how the AI attacks being a huge chunk of mission specific code. I usually write some notes about notable changes made to the AI in light of the specific mission but it's never complete and actually just meant as a note for myself.
Depending on your patience I can try to fit the AI for your needs. An alternative being I can root out the mission specific stuff and you can build/modify what you need yourself.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Well I suppose specifically what i would be looking for in the code would be that the people in the bases are relative to "initial level" or even just an option, I myself could just place the buildings and then for the engineers to repair them inside their base area, to rebuild them if they are destroyed and to collect crates inside area, for scientists to heal the injured people, for the soldiers in turrets to retreat to barracks (when available) when turret is destroyed and for mechanics to repair vehicles inside area but also when base is under attack to get inside vehicles and defend and to make more for an actual attack. So in a nutshell, the basics of the coding. What extra bits are present in ar15a that you mentioned? As i was only taking bits from ar4?

Thanks again
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

There's a 3000 lines difference between the AI in Ar04 and Ar15a_cont IIRC so there's a lot. Can't remember all of it but at counts stuff like
- Detecting being under attack by attack ground (had to made custom code for that).
- Firing of space/time shifting rockets (bazookers).
- Usage of soporific ammo (snipers).
- Code for controlling cargo bay and crane.
- Capabilities to handle all types of vehicles (manual, automatic, remote).
- Rebuilding of factory extensions as necessary (want to build a crane but don't have a non-combat extension? Dismantle an extension and build a non-combat ext).

Anyhow, I'll see about stripping the AI from 15a_cont for mission specific stuff. Then you can play around with it. But I probably won't get the time for it until the weekend.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Awh that would be fantastic! That's fine, take as much time as you need.
Thanks so much! :D
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

There you go. Took longer than I expected. There are quite a few things you have to modify/specify yourself but I've included explanation and guidelines along the way. The "attacking" logic will probably be the hardest to configure.
I've only tested it compiles so there may be some faults here and there.
Attachments
AI_clean.rar
(51.31 KiB) Downloaded 124 times
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Thanks again McBenn! This will help so much, much appreciated :D Can't thank you enough for this :)
Experience is the teacher of all things. - Julius Caesar
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Actually I have a problem with the enemies spawning, I have their bases all done out and accounted for but nothing is spawning? what am I missing?
For everytime [base] is written, am I supposed to replace that with my Ru/Ar/Am_base names?
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

I think I have covered everything you should and could change. Local variables like "base" is not one of them. I think the easiest is for you to upload your map so I can see what is going on (btw single player or multiplayer?). Do you rely on function "PrepareComputerSides" for the spawning?
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

I'm actually trying it on my map 'Showdown' that you helped me with before. At the moment I was trying to do it for multiplayer, but I was hoping in Singleplayer, to have a similar layout to Serpent's skirmish mod Fight with Bot with the options at the start of each map to choose nation, people etc. Yes I am relying on that for the spawning.
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

It can be caused by several things. The easiest way is for me to see the code. If you don't like to upload it here in the thread then PM it to me.
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Oh no I have no issue with uploading here, I have attached the map.
What I did was I added the modules into the bottom of each appropriate places (Main into Main, Functions into a new one etc.) and just made rough bases with buildings in an area.
I added in 3 bases, 1 of each nation to start. That's all I have done so far so hopefully you can find the issue I am having. I have left out little things such as mortar and bazooka special defenders areas. Also there is some conflict with some variables such as 'UnitDestroyed' and 'BaseCaptured'.

Thanks again
Attachments
Showdown (AI).rar
(307.19 KiB) Downloaded 113 times
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

Calling function "Init_AI" in the Starting-block was the first detail :P Next you hadn't specified "ai_human_pullback_hex". Remember if you want to use manual vehicles you also have to specify "ai_vehicle_pullback_hexes". Fixed the issue with the doubled events. An event can only be declared on place so I just changed the event declarations in module "AI" to functions and called them in the event declarations.
Attachments
Showdown (AI).rar
(328.7 KiB) Downloaded 127 times
User avatar
Heike Steyer
Soldier level 2
Soldier level 2
Posts: 47
Joined: Tue Oct 16, 2007 2:58 pm
Location: Kildare, Ireland

Re: Multiplayer/Singleplayer AI

Post by Heike Steyer »

Sorry for the long wait, I have been busy messing around with the code and might I say it is excellent! It is a much better and more thought out AI than even Alter's code and it helps with so many projects. I still don't have it perfect yet but am getting there, still having little issues such as 'base in area' but altogether it helps a tremendous amount! So thanks a million :D
Experience is the teacher of all things. - Julius Caesar
User avatar
McBenn
ArCamp Developer
Posts: 509
Joined: Tue Sep 04, 2012 4:30 pm

Re: Multiplayer/Singleplayer AI

Post by McBenn »

And there's plenty to play around with :) Altar use macros for their AI's usually but I decided to code an AI from scratch because then you can tune it to do exactly what you want. It has some costs in performance I later realized, though.
"base in area"?
Post Reply