Staredit Network > Forums > Modding Assistance > Topic: AI won't defend it's main base
AI won't defend it's main base
Mar 28 2021, 8:20 pm
By: Pandut  

Mar 28 2021, 8:20 pm Pandut Post #1

I'm just a fish

I'm getting back into modding and picking up work on one of my old TCs, which I plan to include a working AI. I'm a pretty novice AI-scripter so I'm learning as I go. I'm running into an issue where the AI will not train units to defend it's main base when attacked. If an AI currently has no standing army, or is attacking another player, or it's defensive buildings are destroyed it will simply ... give up if it's main base is attacked. In AI vs AI games, I've observed dozens of time that the AI will have multiple unit production buildings and a massive resource bank, but still lose their main base because they don't fight back against an attack. Frustratingly, I've seen AI's lose their ENTIRE main base to 1 or 2 zergling-level enemies.

I've used defensebuild/use xy to effect for the AI to defend regions and expansions, but for some reason it doesn't apply to the main base.

All 3 of my race scripts follow the same format, here is my current Terran script:
Collapsable Box

I've tried before to run the defensebuild/use xy calls in a multirun but that would sometimes cause the AI to stop functioning entirely. I've also tried to compensate by having the AI train more units at a time, which works about 25% of the time. As said, I'm not the greatest Ai scripter so I don't have much of a clue what's happening.

Post has been edited 1 time(s), last time on Mar 28 2021, 8:27 pm by Pandut.



None.

Mar 28 2021, 9:46 pm IlyaSnopchenko Post #2

The Curious

First off the wise men say you need a wait(1) after start_town(). Not sure why but it's supposed to be important. :) I for one usually tend to just copy the regular campaign script header from the stock BW ones, believing it is done the way it is for a reason. :)

Second, I think you need more of the various defensebuild_xx / defenseuse_xx commands. You might also want to specify a max_force value. Max_force(1200) makes for a pretty strong defense response.

Calling also guard_all() is a kinda nuclear option for defense, making for very obstinate players. Implode() is also supposed to make the player defend more doggedly but I've never really tested it yet.

Also not sure why the need for such high upgrade/tech priority; 150 is way higher than default which is 30.

Post has been edited 1 time(s), last time on Mar 28 2021, 9:51 pm by IlyaSnopchenko.



Who am I, and why should I care?

Mar 29 2021, 6:34 am DarkenedFantasies Post #3

Roy's Secret Service

I haven't messed around with AI scripts in many months, but I do have some not-so-fond memories of the AI being quite janky without the benefits the AISE plugin has to offer.

Quote from IlyaSnopchenko
First off the wise men say you need a wait(1) after start_town(). Not sure why but it's supposed to be important. :)
I think you mean before start_town? If so, I believe it's only for "area town" scripts so that when the main town and area town scripts are run on the same frame (e.g. in the same trigger), the area towns are able to take ownership of the units in their location. I don't remember experiencing any issues when not using a wait 1 before or after start_town, but I'd have to look at that again to be completely certain since it's been a while I've experimented with AI scripts.




Mar 29 2021, 7:55 am IlyaSnopchenko Post #4

The Curious

Well, the standard header structure is:

start_campaign()
wait(1)
start_town()
defaultbuild_off()
default_min(0)
wait(1)
(Rip and tear until it's stop() :)

Expansions are like
start_town()
wait(1)
(do their stuff)

... But maybe I'm being dogmatic. :)
Anyway, I think Nekron will be better suited to explaining the intricacies of scripting. I am merely a disciple. :)



Who am I, and why should I care?

Mar 29 2021, 9:59 am Nekron Post #5



The "wait 1" thing is for areatowns only iirc, yeah. So it shouldn't matter if this script is melee.

Your defense is pretty heavy handed, requesting 8 marines or 4 vultures etc. at once is pretty hard for an AI that probably doesn't have infinite resources, and even if it did you would end up with insane amounts of marines everywhere the AI can place them :D Try to bump this down to 1 or 2, since this isn't the "max amount" the AI will want to use - it's the minimal amount it will try to send each time this type of defense is requested. You also have very few individual defenseuse commands in general, I think it's fairly possible that if the script wants _aa or _ag defense it will have nothing available at the time.

I would recommend making a smaller AI first, making it expand and defend with rines, bats - then making it attack, expand again, seeing if defense works etc. and debugging it adhoc each time something bad happens. If you're not familiar with this, you should take a look at this doc https://docs.google.com/document/d/1KXbIDuIBnacWwpJJxSQePmIhc1GKuEgRZxtf8cLi_Qo/edit?usp=sharing and read a little bit about defense/force values

Another thing that probably trashes any attemps your scripts could have at defending well is the insane 150 priority on upgrades and buildings
AI defense will only ever go up to something like 110, maybe 120? priority(and that's only in some central regions), and above that anything that you request that it can't immediately finish will take away resources from defense. If it'd get stuck with a priority 150 request, it might very well not defend at all, even if you have working defenseuse/build blocks and ample resources

Other than that - yea use AISE like DF mentioned, you're modding anyway https://github.com/neivv/aise




Mar 30 2021, 6:36 pm Pandut Post #6

I'm just a fish

Quote from IlyaSnopchenko
First off the wise men say you need a wait(1) after start_town(). Not sure why but it's supposed to be important. :) I for one usually tend to just copy the regular campaign script header from the stock BW ones, believing it is done the way it is for a reason. :)

Second, I think you need more of the various defensebuild_xx / defenseuse_xx commands. You might also want to specify a max_force value. Max_force(1200) makes for a pretty strong defense response.

Calling also guard_all() is a kinda nuclear option for defense, making for very obstinate players. Implode() is also supposed to make the player defend more doggedly but I've never really tested it yet.

Also not sure why the need for such high upgrade/tech priority; 150 is way higher than default which is 30.
I think the high priorities was me misremembering things I did in previous scripts lol. Dropping them down definitely stopped a lot of hold ups.

Quote from Nekron
The "wait 1" thing is for areatowns only iirc, yeah. So it shouldn't matter if this script is melee.

Your defense is pretty heavy handed, requesting 8 marines or 4 vultures etc. at once is pretty hard for an AI that probably doesn't have infinite resources, and even if it did you would end up with insane amounts of marines everywhere the AI can place them :D Try to bump this down to 1 or 2, since this isn't the "max amount" the AI will want to use - it's the minimal amount it will try to send each time this type of defense is requested. You also have very few individual defenseuse commands in general, I think it's fairly possible that if the script wants _aa or _ag defense it will have nothing available at the time.

I would recommend making a smaller AI first, making it expand and defend with rines, bats - then making it attack, expand again, seeing if defense works etc. and debugging it adhoc each time something bad happens. If you're not familiar with this, you should take a look at this doc https://docs.google.com/document/d/1KXbIDuIBnacWwpJJxSQePmIhc1GKuEgRZxtf8cLi_Qo/edit?usp=sharing and read a little bit about defense/force values

Another thing that probably trashes any attemps your scripts could have at defending well is the insane 150 priority on upgrades and buildings
AI defense will only ever go up to something like 110, maybe 120? priority(and that's only in some central regions), and above that anything that you request that it can't immediately finish will take away resources from defense. If it'd get stuck with a priority 150 request, it might very well not defend at all, even if you have working defenseuse/build blocks and ample resources

Other than that - yea use AISE like DF mentioned, you're modding anyway https://github.com/neivv/aise
Yeah, seems like a lot of the problems I had were user-related lol. I dropped down priorities for buildings/upgrades, and fleshed out the defensebuild/use xy calls and it seems to have fixed a lot of problems. Thanks for the help :D.

AISE sounds great, anything to help with removing jank from the AI but I have no idea how to actually get it set up. Are there instructions somewhere that I've missed?



None.

Mar 31 2021, 12:15 pm IlyaSnopchenko Post #7

The Curious

AISE method of usage depends on which version of SC you have. For SCR, which is the only one I have up-to-date knowledge of, you download AISE.DLL and put it in your mod under SAMASE\, then add its name to the PLUGINS text file.



Who am I, and why should I care?

Apr 1 2021, 8:42 am Nekron Post #8



For 1.16, you should just change aise.dll to aise.qpd (changing the extension manually is good enough) and add it to Firegraft as a plugin




Apr 1 2021, 11:42 am IlyaSnopchenko Post #9

The Curious

Actually until quite recently I had a mixture of DLL and QDP extensions for the plugins I've had. :)



Who am I, and why should I care?

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[11:25 pm]
lil-Inferno -- shut up Nude
[03:01 pm]
Oh_Man -- tell your mum I miss her
[07:02 am]
NudeRaider -- lil-Inferno
lil-Inferno shouted: guys can you please stop :wob: ing my mom bought me this new laptop and all the gifs are making it overheat and burn my legs
why would you lie on the Internet?
[2021-4-20. : 1:53 am]
RdeRenato -- xd
[2021-4-20. : 1:16 am]
KrayZee -- lil-Inferno
lil-Inferno shouted: guys can you please stop :wob: ing my mom bought me this new laptop and all the gifs are making it overheat and burn my legs
:wob: :wob: :wob: :wob: :wob: :wob: :wob: :wob: :wob: :wob: :wob:
[2021-4-20. : 1:13 am]
lil-Inferno -- guys can you please stop :wob: ing my mom bought me this new laptop and all the gifs are making it overheat and burn my legs
[2021-4-19. : 9:00 pm]
MTiger156 -- u
[2021-4-19. : 8:18 pm]
RdeRenato -- a
[2021-4-19. : 8:10 pm]
Moose -- tbh jjf, well played
[2021-4-19. : 5:25 pm]
Vrael -- :wob: ooh theres some nice :wob: going on up in hurr
Please log in to shout.


Members Online: C(a)HeK, Wing Zero, Roy, jun3hong, RdeRenato, Dem0n