Not that I know of, but I haven't looked too far into it. You can of course have two separate AI players running separate AI's. You could then change them to have the same color, so part of the AI base could be melee, and the other part campaign. Perhaps you could even try switching ownership between their units (though I kinda doubt that'd work too well). I'm thinking it'd probably be easier to move from melee to campaign than the other way around, as it seems melee is more advanced/specialized. Also note that you can always enable script control for specific units so that the AI won't give them any orders, and instead you can order those units through triggers.
sad, my problem is that the campaign AI doesnt defend itself very well, i wanted to switch to melee as soon as their base gets attacked. now it seems i have to do it all by hand.
Yeah, defense isn't exposed to the editor or campaign AI. You're probably better off doing it manually if you can figure out an efficient way. Long story short, you won't be able to merge the two AI's without redoing the way melee attack waves handle in the first place, and even then I doubt all the hardcode running related to melee is going to play nicely with anything else you have going. It sure didn't for me.
Yeah, defense isn't exposed to the editor or campaign AI.
What are you talking about?! This entire topic makes little sense and sounds like people are not understanding how AI works in SC2.
At the core there is an "AI" system that can run for each player. This is what is enabled with the "AIStart" native and only works on players marked as computers (you cannot AIStart on humans, even if they leave or the slot was empty). Once the AI is started it will run all Tactical AI for all units it owns under its control (not units marked as trigger controlled, eg if you explicitly send them an order via triggers). It will also have a number of AI behaviours based on the flags you set, this includes if they ignore vision, use workers to defend, prioritize spawners (carrier over interceptors it spawns) and various other flags. At this stage the AI is nothing more than a reflexive shell, its units will cast abilities (which have tactical AI functions) but it will not do anything else (just stand there, like some RPG neutral creeps).
Unfortunately the AI really is not that intelligent as it actually needs to be told what to do (unlike a human which can pick up the game by playing). Basically you need to write up the AI think behaviour and setup what the AI should do.
The rest of the AI start functions declares towns, initializes various values and other things for future use. The main difference is that the Campaign AI initializer is designed to more efficiently identify existing assets and bullies while the melee AI is designed to have smarter tactical behaviour settings and initialize some template like values that are aimed at melee.
When the AI is started using the special melee initialization native it starts some form of periodic loop which calls various AI decision making functions. Some of these will identify if a base is threatened or under attack and will mobilize forces to protect it. Others will manage the AI's resources and assign them to certain purposes. There is a build decision system which decides what to build (usually decides at map initialization however it can change dynamically based on threats). Finally there is an overall progression to the functions called with simpler functions being called early game focusing on early threats, rushes and low tech units and more complicated functions being called late game focusing on harasses, high tech army composition, expansion management etc.
All these functions are in galaxy custom script and called by the galaxy virtual machine like all other triggers. Since most of the natives are available on GUI you can write your own GUI functions to do similar stuff to the melee thing loops except better optimized for your map.
For better defense (as an example) one could split the attack waves into an offensive and defensive force. When at base all units stick in the defensive force and are ordered to engage all threats. When an attack is desired half the defensive force could be turned offensive and that attack wave issued at some target. If the defensive force fails then the offensive attack wave could be issued back at the base to help neutralize the threat.
If your player is Terran then constructing a few Siege Tanks for the defensive group would be a good idea. Additionally for turtling one could order extra missile turrets (like 10 or 20) per base. Ravens also help as their point defense drones and detection are a valuable feature.
I'm not sure what your point is. You didn't exactly address anything I said. I haven't seen anyone make a functional defense script in the editor yet and universally everyone who I have ever asked about the subject has been clueless and told me it has never been done before, so presumably you want to take it out of melee. Which will require you to rewrite a good chunk of how melee works. This was also the approach JademusSreg worked with in 2012-2014. Calling waves from melee as functions for triggered waves does not work correctly, and if you use melee waves as a body your attack wave triggers will for the most part be ignored due to how melee works other than the training of units. I've tried to piece it together manually when I was still working with the game, but suffice to say I was unsuccessful.
A good chunk of melee is contained in natives, ergo, it's hardcoded.
There is melee AI, it's hardcoded and triggers have nearly no influence what it does and there is campaign which only executes tactical AI for units but no macro. you can replace the melee AI by replacing the script files in your map which i was very close to do but decided not to do because it wouldn't work either since i would need different melee AIs for different players (and difficulty is already in use). i decided to do all by hand with events (building destroyed i.e.).
You don't need to do different melee AI's for each player. Just replace the build order system with something that compares player number and map ID to determine their build. That is what we did to get player-specific AI (which also contained player-specific integers for things like how many units they grouped for attack waves, if they used drop attacks or not, etc).
Doing it by hand is the ideal way if you know how, though, and can make it perform well.
A good chunk of melee is contained in natives, ergo, it's hardcoded.
The AI scripts are located in the Liberty (WoL) and Swarm (HotS) mods. You can modify them by importing customized versions of the files over them using the import manager.
Quote:
There is melee AI, it's hardcoded and triggers have nearly no influence what it does and there is campaign which only executes tactical AI for units but no macro. you can replace the melee AI by replacing the script files in your map which i was very close to do but decided not to do because it wouldn't work either since i would need different melee AIs for different players (and difficulty is already in use). i decided to do all by hand with events (building destroyed i.e.).
It does work and is even pretty easy to do. Just you need to be able to write Galaxy script since currently I have no idea how to access the functionality directly from the trigger editor.
I admit some of what I posted previously was inaccurate as further studies have revealed. However a lot of the concepts are still there.
The AI operates similar to Tactical AI. The game engine calls various interface Galaxy functions directly during run time (no triggers involved). Unlike tactical AI functions, there is no apparent "function name" field for specifying these functions with respect to each race. I am currently unsure how it links the functions but I am inclined to believe it is done using by using the Race entry identifier as a suffix for various standard name functions (interface functions). All of these interface functions are entirely optional with all of them being able to function as stand alone components.
The AI interface consists of 3 core functions...
AIMelee : This function is responsible for the "Macro" think process of the AI. This is where build orders are defined. It is called periodically with a low frequency (usually once every second or so).
AIWaveThink : This function is responsible for the "Micro" think process of the AI. Specifically it manages attack waves. It is called periodically for each attack wave.
AINewUnit : This function is responsible for the allocation of units to tasks. Specifically it manages allocation of units to waves including separation of special purpose units to special purpose waves (eg diversions). It is called once for every new unit an AI gets.
I am still unsure how initialization occurs.
Since they share the same Galaxy virtual machine in theory one could port these function to the Trigger editor. One would just need a blank "Terran/Terran.galaxy" file for the Terrans as an example. It should then be possible to declare the function using Custom Script and then outsource the implementation to a GUI action.
Most of the complexity with the AI is to handle "melee stuff" which usually is irrelevant for Arcade games. For example difficulty sections add more advanced build orders which usually are inappropriate anyway or certain flags are set which make little difference. In the Terran AI there are dozens of build orders declared which involve units and numbers which might not at all be suited for an Arcade game. Invisible detection is also heavily built in, using units such as the Raven which might not be suitable (eg Science Vessel instead, or maybe there is no air or invisible anyway). Axing this stuff to a skeleton AI and you are left with actually not that much.
As an example I wanted to make a dumb cheating AI that would make 15 barracks and spam out Marines until it has 170. Although the map is quite broken (you need to type "ally" and "god" to survive, minerals will run out due to a data problem etc) you can observe that the AI will max out its main, construct sufficient supply depots for 200 supply cap and then proceed to spam out 170 Marines before sending it to attack (it usually attacks you for some stupid reason even though you are allied?). Lots of marines dying, lots of marines being produced. Test the map with Cheating (Insane) AI, I did not get around to removing a lot of the bloat of other difficulties as I was more interested in seeing the mechanics.
It might be easier to build based on the Campaign AI. It also has such a file and even recommends you overwrite it with the import manager in the comments. I will need to look into that at some stage.
The AI scripts are located in the Liberty (WoL) and Swarm (HotS) mods. You can modify them by importing customized versions of the files over them using the import manager.
I think you misunderstand me. I've worked with the AI for years. I've already gone through much of the things the OP is attempting to do. You don't need to explain that stuff to me. I am merely trying to explain to the OP in a simple format why it isn't an easy fix to apply melee defense functions to campaign.
The galaxy you speak of is heavily dependent on various natives that are contained in the executable. Things like various parameters in regards to how the melee drop attacks function, portions of threat evaluation, how it determines blueprints for stock construction blocks, the distancing and placement of waypoints for melee attack waves, and a bunch of other things I cannot immediately recall.
/edit
As for exposing the melee code to triggers, I think you can just "include" the files in the map and then use a gui wrapper with custom code pointing to them. I had to do that to get a difficulty-independent triggered attack wave for my tests which isn't normally available to the editor.
Because the AI function calls are internal (made by the game engine) and not done by triggers. My first statement about the system was incorrect, thus the follow up.
Since it is not possible to dynamically change the function that gets called, one has to place dynamic logic in it based on all the states you want it to support. In theory one could merge all 3 AIs together with such a statement.
The AI think ticks and handlers are not the only source of internal calls. All tactical AI functions are also called internally.
Any of you guys know what are the biggest performance sinks for the existing Melee AI? We've stripped a lot out of it, but the performance is still mindblowingly wretched. It makes any hope of a project I might want to make in sc2 a pipedream at best. Even just two computer players in a 256x256 map can drag the fps down to 7 for my reasonably modern hardware that can otherwise handle hundreds of thousands to millions of polies in this engine without issue. Adding another 3 Ai players doesn't make a noticeable difference, manually painting pathing made no difference, dropping unit counts (which weren't high to begin with) makes no difference, stripping tactical AI makes little difference (some are very bad, like spore colony, but most are insignificant). There's some kind of overhead that really hurts performance.
I've spent five years off and on trying to solve issues with the AI in this game which have all but crippled any desire I had to get involved with it beyond proof of concepts. I would love to put my designs to the test in a large campaign project, but it starts and ends with the AI's performance. I've long given up hope to find answers because, like I said, no one seemed to know anything. But if you know, I'd love to put it to the test.
/edit
I see. Unsurprising lack of response. Just wanted to check. Good day.
Dead thread maybe lol, but i found a solution to end the melee AI. (it does not end the loop the melee AI runs on, but it prevents it from doing anything.)
First you have to call the EndMeleeAI function as seen in the picture below (after having started the melee AI), next you can overwrite the MeleeAI.galaxy script (second attachment) to prevent the error message being displayed each time. (i modified it by adding "HI." to the beginning as a showcase it works)
Edit:
I tried to put wait functions to maybe slow down the loop as needed, but the problem is then everything stops as this is getting called on the "native" thread. So theres no way to make the loop wait like this unfortunately.
I also made it so that I overwrote the start melee AI function to just "return;" right away in BaseAI.galaxy. When using a extension mod I can in this way prevent the normal melee AI from getting started. And then I can call my own start AI functions as I please.
hello,
as the title says, is it possible somehow? any dirty work around?
Not that I know of, but I haven't looked too far into it. You can of course have two separate AI players running separate AI's. You could then change them to have the same color, so part of the AI base could be melee, and the other part campaign. Perhaps you could even try switching ownership between their units (though I kinda doubt that'd work too well). I'm thinking it'd probably be easier to move from melee to campaign than the other way around, as it seems melee is more advanced/specialized. Also note that you can always enable script control for specific units so that the AI won't give them any orders, and instead you can order those units through triggers.
sad, my problem is that the campaign AI doesnt defend itself very well, i wanted to switch to melee as soon as their base gets attacked. now it seems i have to do it all by hand.
Yeah, defense isn't exposed to the editor or campaign AI. You're probably better off doing it manually if you can figure out an efficient way. Long story short, you won't be able to merge the two AI's without redoing the way melee attack waves handle in the first place, and even then I doubt all the hardcode running related to melee is going to play nicely with anything else you have going. It sure didn't for me.
What are you talking about?! This entire topic makes little sense and sounds like people are not understanding how AI works in SC2.
At the core there is an "AI" system that can run for each player. This is what is enabled with the "AIStart" native and only works on players marked as computers (you cannot AIStart on humans, even if they leave or the slot was empty). Once the AI is started it will run all Tactical AI for all units it owns under its control (not units marked as trigger controlled, eg if you explicitly send them an order via triggers). It will also have a number of AI behaviours based on the flags you set, this includes if they ignore vision, use workers to defend, prioritize spawners (carrier over interceptors it spawns) and various other flags. At this stage the AI is nothing more than a reflexive shell, its units will cast abilities (which have tactical AI functions) but it will not do anything else (just stand there, like some RPG neutral creeps).
Unfortunately the AI really is not that intelligent as it actually needs to be told what to do (unlike a human which can pick up the game by playing). Basically you need to write up the AI think behaviour and setup what the AI should do.
The rest of the AI start functions declares towns, initializes various values and other things for future use. The main difference is that the Campaign AI initializer is designed to more efficiently identify existing assets and bullies while the melee AI is designed to have smarter tactical behaviour settings and initialize some template like values that are aimed at melee.
When the AI is started using the special melee initialization native it starts some form of periodic loop which calls various AI decision making functions. Some of these will identify if a base is threatened or under attack and will mobilize forces to protect it. Others will manage the AI's resources and assign them to certain purposes. There is a build decision system which decides what to build (usually decides at map initialization however it can change dynamically based on threats). Finally there is an overall progression to the functions called with simpler functions being called early game focusing on early threats, rushes and low tech units and more complicated functions being called late game focusing on harasses, high tech army composition, expansion management etc.
All these functions are in galaxy custom script and called by the galaxy virtual machine like all other triggers. Since most of the natives are available on GUI you can write your own GUI functions to do similar stuff to the melee thing loops except better optimized for your map.
For better defense (as an example) one could split the attack waves into an offensive and defensive force. When at base all units stick in the defensive force and are ordered to engage all threats. When an attack is desired half the defensive force could be turned offensive and that attack wave issued at some target. If the defensive force fails then the offensive attack wave could be issued back at the base to help neutralize the threat.
If your player is Terran then constructing a few Siege Tanks for the defensive group would be a good idea. Additionally for turtling one could order extra missile turrets (like 10 or 20) per base. Ravens also help as their point defense drones and detection are a valuable feature.
I'm not sure what your point is. You didn't exactly address anything I said. I haven't seen anyone make a functional defense script in the editor yet and universally everyone who I have ever asked about the subject has been clueless and told me it has never been done before, so presumably you want to take it out of melee. Which will require you to rewrite a good chunk of how melee works. This was also the approach JademusSreg worked with in 2012-2014. Calling waves from melee as functions for triggered waves does not work correctly, and if you use melee waves as a body your attack wave triggers will for the most part be ignored due to how melee works other than the training of units. I've tried to piece it together manually when I was still working with the game, but suffice to say I was unsuccessful.
A good chunk of melee is contained in natives, ergo, it's hardcoded.
There is melee AI, it's hardcoded and triggers have nearly no influence what it does and there is campaign which only executes tactical AI for units but no macro. you can replace the melee AI by replacing the script files in your map which i was very close to do but decided not to do because it wouldn't work either since i would need different melee AIs for different players (and difficulty is already in use). i decided to do all by hand with events (building destroyed i.e.).
You don't need to do different melee AI's for each player. Just replace the build order system with something that compares player number and map ID to determine their build. That is what we did to get player-specific AI (which also contained player-specific integers for things like how many units they grouped for attack waves, if they used drop attacks or not, etc).
Doing it by hand is the ideal way if you know how, though, and can make it perform well.
The AI scripts are located in the Liberty (WoL) and Swarm (HotS) mods. You can modify them by importing customized versions of the files over them using the import manager.
It does work and is even pretty easy to do. Just you need to be able to write Galaxy script since currently I have no idea how to access the functionality directly from the trigger editor.
I admit some of what I posted previously was inaccurate as further studies have revealed. However a lot of the concepts are still there.
The AI operates similar to Tactical AI. The game engine calls various interface Galaxy functions directly during run time (no triggers involved). Unlike tactical AI functions, there is no apparent "function name" field for specifying these functions with respect to each race. I am currently unsure how it links the functions but I am inclined to believe it is done using by using the Race entry identifier as a suffix for various standard name functions (interface functions). All of these interface functions are entirely optional with all of them being able to function as stand alone components.
The AI interface consists of 3 core functions...
I am still unsure how initialization occurs.
Since they share the same Galaxy virtual machine in theory one could port these function to the Trigger editor. One would just need a blank "Terran/Terran.galaxy" file for the Terrans as an example. It should then be possible to declare the function using Custom Script and then outsource the implementation to a GUI action.
Most of the complexity with the AI is to handle "melee stuff" which usually is irrelevant for Arcade games. For example difficulty sections add more advanced build orders which usually are inappropriate anyway or certain flags are set which make little difference. In the Terran AI there are dozens of build orders declared which involve units and numbers which might not at all be suited for an Arcade game. Invisible detection is also heavily built in, using units such as the Raven which might not be suitable (eg Science Vessel instead, or maybe there is no air or invisible anyway). Axing this stuff to a skeleton AI and you are left with actually not that much.
As an example I wanted to make a dumb cheating AI that would make 15 barracks and spam out Marines until it has 170. Although the map is quite broken (you need to type "ally" and "god" to survive, minerals will run out due to a data problem etc) you can observe that the AI will max out its main, construct sufficient supply depots for 200 supply cap and then proceed to spam out 170 Marines before sending it to attack (it usually attacks you for some stupid reason even though you are allied?). Lots of marines dying, lots of marines being produced. Test the map with Cheating (Insane) AI, I did not get around to removing a lot of the bloat of other difficulties as I was more interested in seeing the mechanics.
It might be easier to build based on the Campaign AI. It also has such a file and even recommends you overwrite it with the import manager in the comments. I will need to look into that at some stage.
I think you misunderstand me. I've worked with the AI for years. I've already gone through much of the things the OP is attempting to do. You don't need to explain that stuff to me. I am merely trying to explain to the OP in a simple format why it isn't an easy fix to apply melee defense functions to campaign.
The galaxy you speak of is heavily dependent on various natives that are contained in the executable. Things like various parameters in regards to how the melee drop attacks function, portions of threat evaluation, how it determines blueprints for stock construction blocks, the distancing and placement of waypoints for melee attack waves, and a bunch of other things I cannot immediately recall.
/edit
As for exposing the melee code to triggers, I think you can just "include" the files in the map and then use a gui wrapper with custom code pointing to them. I had to do that to get a difficulty-independent triggered attack wave for my tests which isn't normally available to the editor.
Based on what you guys have been saying, what's to stop you from doing something similar to the "stop trigger" action, then starting a different AI?
Because the AI function calls are internal (made by the game engine) and not done by triggers. My first statement about the system was incorrect, thus the follow up.
Since it is not possible to dynamically change the function that gets called, one has to place dynamic logic in it based on all the states you want it to support. In theory one could merge all 3 AIs together with such a statement.
The AI think ticks and handlers are not the only source of internal calls. All tactical AI functions are also called internally.
Any of you guys know what are the biggest performance sinks for the existing Melee AI? We've stripped a lot out of it, but the performance is still mindblowingly wretched. It makes any hope of a project I might want to make in sc2 a pipedream at best. Even just two computer players in a 256x256 map can drag the fps down to 7 for my reasonably modern hardware that can otherwise handle hundreds of thousands to millions of polies in this engine without issue. Adding another 3 Ai players doesn't make a noticeable difference, manually painting pathing made no difference, dropping unit counts (which weren't high to begin with) makes no difference, stripping tactical AI makes little difference (some are very bad, like spore colony, but most are insignificant). There's some kind of overhead that really hurts performance.
I've spent five years off and on trying to solve issues with the AI in this game which have all but crippled any desire I had to get involved with it beyond proof of concepts. I would love to put my designs to the test in a large campaign project, but it starts and ends with the AI's performance. I've long given up hope to find answers because, like I said, no one seemed to know anything. But if you know, I'd love to put it to the test.
/edit
I see. Unsurprising lack of response. Just wanted to check. Good day.
In reply to _ForgeUser4342312:
Dead thread maybe lol, but i found a solution to end the melee AI. (it does not end the loop the melee AI runs on, but it prevents it from doing anything.)
First you have to call the EndMeleeAI function as seen in the picture below (after having started the melee AI), next you can overwrite the MeleeAI.galaxy script (second attachment) to prevent the error message being displayed each time. (i modified it by adding "HI." to the beginning as a showcase it works)
Edit:
I tried to put wait functions to maybe slow down the loop as needed, but the problem is then everything stops as this is getting called on the "native" thread. So theres no way to make the loop wait like this unfortunately.
I also made it so that I overwrote the start melee AI function to just "return;" right away in BaseAI.galaxy. When using a extension mod I can in this way prevent the normal melee AI from getting started. And then I can call my own start AI functions as I please.