Staredit Network > Forums > Modding Discussion > Topic: Defining AI commands and functions
Defining AI commands and functions
Jun 21 2017, 8:49 pm
By: Pr0nogo
Pages: < 1 « 2 3 4 5 >
 

Mar 25 2019, 7:45 pm IlyaSnopchenko Post #61

The Curious

Another question here: is there any way to detect if an allied computer player's particular unit is under attack? I've got some vague ideas that it could be done in a roundabout way by ordering some other unit owned by that player to do something to the attacked unit using idle_orders with flags, and then detecting that action somehow, but is there a more straight way?



Trial and error... mostly error.

Mar 25 2019, 10:28 pm Nekron Post #62



I don't think there's any other way




Mar 26 2019, 12:01 am Pr0nogo Post #63



Eventually we'll have a player-specific combat check as a jump command, something like combat operator quantity attackedPlayerId attackerPlayerId area block, but until then you'll have to detect through idle_orders.




Mar 26 2019, 7:22 am IlyaSnopchenko Post #64

The Curious

Got it, thanks folks. You can't be slower than me anyway lol. I don't insist on having a particular unit detected, just the general state of being under attack - the same as when a human player has his units under fire and receives a general alert. The situation in question is defending an allied hero while they are doing a "channeling" (timed) on a mission objective, very similar to the final mission of TFT where Illidan/Arthas are capturing runestones or whatever they are. :) I thought that adding a "under attack" message would be a nice icing on the cake - generally the player has units around to defend, but a couple of times I or my co-author ended having that hero killed off offscreen. :)

Another question I got currently:
Is there any specific reason I might want to use allies_watch / try_townpoint combination in a multirun to have a computer player to create an expansion town instead of just using expand? In the script I've been currently writing, I was internally debating how to do this, but decided to use allies_watch / try_townpoint just for the heck of it. :) Of course if it fails or causes a malfunction I'll roll back to expand.

Post has been edited 1 time(s), last time on Mar 26 2019, 7:30 am by IlyaSnopchenko.



Trial and error... mostly error.

Mar 26 2019, 7:35 am Nekron Post #65



expand is for random expansions, allies_watch is for specific ones




Mar 26 2019, 7:51 am IlyaSnopchenko Post #66

The Curious

Quote from Nekron
expand is for random expansions, allies_watch is for specific ones
Yeah, I saw what you did in ZB6x scripts in UED AI Project. :) Neat trick of course. So unless there are other hidden implications I'll keep the routine I have now, and decide later when I get a map done for the AI Script I'm writing now (yeah... I created the script before the actual map, talk about being crazy).



Trial and error... mostly error.

Mar 27 2019, 9:14 am IlyaSnopchenko Post #67

The Curious

I have a few more questions regarding the AI Script I'm now writing. I've done a fair share of those in my lifetime but I've never had one give me so much grief, and mostly for unknown reasons.

What can cause the AI Script to completely "forget" about building supply providers? During the first test run I was puzzled as to why the script just stopped progressing after awhile and noticed that the hangup was around the time when three queens were to be trained as guards, but the computer never built any overlords apart from a couple he was given. To remedy that quickly, I used the "food for thought" cheat and lo, it started running again. OK, in the next version I did specifically instruct this one to build overlords and supply depots, but that's not how I remember the AI Scripts to behave - they are building pylons/overlords/supply depots as much as they need. I can't even be sure he rebuilds them now if they get destroyed.

What can cause an AI Script to ignore a multirun thread (into which I put most of the upgrades so that they would be done at their own pace, independent of build and attack routine, once the AI builds most of the buildings it needs?) I need to test this but it started after I added a wait_upgrades() opcode before the stop() that terminates this thread, but I can't be sure there's a cause/effect relation here. Even before that, the computer would not apparently run the whole extent of that thread as I noticed his ground upgrades topped out at 3/2 and air upgrades at 2/1. No there are no upgrade restrictions in the map as I just took a random melee map and modified it placing three players on the map - myself, a computer ally with the AI in question and a ho-hum computer player as a punching bag. :)

I tried to have the computer expand but it completely ignored the first expansion order and the second came out broken - the computer would build a hatchery and even invoke the multirun I created to build the defensive structures, but would not mine - he'd send a few drones but they'd just hang out around the sunken colonies and not do anything. I thought I messed up something with try_townpoint/allies_watch structure (I used it so that in the map where this script is eventually supposed to be used I can control which expansions he takes instead of going somewhere random) but with expand it doesn't get any better.



Trial and error... mostly error.

Mar 27 2019, 10:06 am Nekron Post #68



Quote
What can cause the AI Script to completely "forget" about building supply providers? During the first test run I was puzzled as to why the script just stopped progressing after awhile and noticed that the hangup was around the time when three queens were to be trained as guards, but the computer never built any overlords apart from a couple he was given. To remedy that quickly, I used the "food for thought" cheat and lo, it started running again. OK, in the next version I did specifically instruct this one to build overlords and supply depots, but that's not how I remember the AI Scripts to behave - they are building pylons/overlords/supply depots as much as they need. I can't even be sure he rebuilds them now if they get destroyed.
Non-campaign AIs and campaign terran wont rebuild supply at all by themselves, campaing protoss will rebuild as much as they need to power buildings if there are unpowered ones on the map, campaign zerg will build 0 or 3 or 5 overlords as transports depending on whether check_transports or transports_off was set. For computer players to build supply, you must tell them to build it with build, player_need, farms_timing or farms_notiming commands. If the AI has 1 supply missing but wants a 2 supply unit and has farms_notiming, it will hang up. I see you mention building supply depots and overlords - if you have a 2-race AI, farms_timing will only work on the player slot's race, and for the rest of the supply you will have to request it with build/player_need.


Quote
What can cause an AI Script to ignore a multirun thread (into which I put most of the upgrades so that they would be done at their own pace, independent of build and attack routine, once the AI builds most of the buildings it needs?) I need to test this but it started after I added a wait_upgrades() opcode before the stop() that terminates this thread, but I can't be sure there's a cause/effect relation here. Even before that, the computer would not apparently run the whole extent of that thread as I noticed his ground upgrades topped out at 3/2 and air upgrades at 2/1. No there are no upgrade restrictions in the map as I just took a random melee map and modified it placing three players on the map - myself, a computer ally with the AI in question and a ho-hum computer player as a punching bag. :)

Nothing. The AI never ignores anything that it runs, it might however be unable to execute something because of map and script mistakes. Sounds like a priority issue, if you send me the map and a pastebin of the script I can take a look.

Quote
I tried to have the computer expand but it completely ignored the first expansion order and the second came out broken - the computer would build a hatchery and even invoke the multirun I created to build the defensive structures, but would not mine - he'd send a few drones but they'd just hang out around the sunken colonies and not do anything. I thought I messed up something with try_townpoint/allies_watch structure (I used it so that in the map where this script is eventually supposed to be used I can control which expansions he takes instead of going somewhere random) but with expand it doesn't get any better.

Sounds like a broken resarea. Turn on resarea preview in SCMDraft and take a look. Otherwise, might be caused by poorly written town threads and priority issues

Refusing to expand can be also related to enemy units present in the resarea
If its broken it would look something like this (start locs hijack everything away from the town)





Mar 28 2019, 7:07 am IlyaSnopchenko Post #69

The Curious

Really, this script of mine is a gift that keeps on giving. :) Yesterday I was able to make it expand for the first time but it somehow doesn't run the full extent of the build order (so it can't get one of the attacks in place because it requires one of the highest tech buildings), as well as executing not nearly all of the defensebuild orders. Besides, a previously working multirun for defensive construction ended up working only partially. I'll try to rewrite it again and paste then if problems persist.

Good thing is, its first attack dented the punchbag enemy AI pretty badly and the second one finished it off. But that's not how the script is going to be used when I create that mission where it's intended to go. So far I'm only using an altered melee map for testing.

Never had this much trouble with any script, even dual-race of any conceivable combinations. :)

EDIT: I just love this.
https://pastebin.com/HesFVg3Q
I tried making 2 test maps out of Blizzard stock maps, thinking that the first one had not enough space. Well, here's the second, large one.

It mostly attacks fine (never got the chance to test the last - looped - attack as it'd wiped out the enemy computer out before that could happen :)) but tops out at 2/1 terran infantry upgrades (2/2 zerg ones) consistently, and doesn't seem to do those armor/weapon upgrades slated to be done further down the script. Line 158 is evidently where the cutoff is. All the other upgrades (except maybe mana) are all done as its ultras are fully stacked and it has been using plague.

I however removed all the commands to produce supply, so you'll have to use "food for thought" cheat right away. After I did away with them at least the script does build everything else it's ordered to so there's no hangup due to him not being able to build a science facility/physics lab for some reason. Expanding does still come out broken no matter the map (I've tried both) and which expansion he tries to claim - it's different every time.

The defense multirun still works only half and half: it does build turrets but not bunkers and not the zerg defenses (although in the earlier versions it did that).

Attachments:
Nightshade-AITest.scx
Hits: 1 Size: 203.2kb

Post has been edited 4 time(s), last time on Mar 28 2019, 8:19 am by IlyaSnopchenko.



Trial and error... mostly error.

Mar 28 2019, 9:47 am Nekron Post #70



This is a response from my phone, ill take a more nuanced look at it in a few hours.

For starters, you missed wait 1 after start_campaign's header. Start campaign is not needed, but the wait absolutely is. 2., use x=y in pyai, writing full names is a pain. 3. Multi race ais use a random worker for starting new bases. COMPLETELY random, doesnt check for race. So you either need to build both townhalls or dont expand, im not even sure if buiding both works consistently. 4. Build bunkers and turrets is instantenous and practically ignored if there is something of equal/higher priority, AND it leaves no permament requests. Use wait_bunkers/turrets to make it make sure theyre built.

Post has been edited 1 time(s), last time on Mar 28 2019, 6:40 pm by Nekron.




Mar 28 2019, 12:08 pm IlyaSnopchenko Post #71

The Curious

Thanks! I'll try building both because that was what I was thinking originally. Interestingly just once the terran expansion worked fine, they built a nuke silo and started throwing nukes around too, as ordered. I'll try adding wait_xxx too.

I also deleted the start_campaign() which was originally there while troubleshooting, thinking that it might answer some of the issues. Apparently it didn't and I just kinda forgot to put it back. Actually the script used to be a lot more nuanced in the first few iterations but I deleted some peripheral stuff so that I could exclude any possible extraneous influence. So many caveats I wasn't aware of; I dug up my scripts from the last time around (2003-5) and they were a lot more straightforward but still work (under 1.16.1 tho) very reliably.

P.S. Maybe I need to add a tougher punching bag AI because the one I'm using now (PB6A or something) gets wiped out by 2nd attack, 3rd tops...



Trial and error... mostly error.

Mar 28 2019, 6:40 pm Nekron Post #72



I missed this when first looking at the script this morning, but way, way, WAY too much happens at once right after the game starts, try separating the each sequence with a wait of some kind. Build command doesn't wait. Also calling build_bunkers and turrets at once seems to crash the game for me sometimes with the debug plugins on, lol. Start_campaign does nothing in UMS games, but the header structure is important since both wait(1)s are important when assigning AI structures during game setup. It's a pain troubleshooting something so condensed, but I think the issues will be immensely easier to find once you separate each section by something tangible - for example, after building an academy, train some firebats and wait for an firebat attack. Everything works until that point? Great, you don't have to debug. An upgrade that should have been researched by then is missing? Something before that point is amiss.




Mar 28 2019, 7:09 pm IlyaSnopchenko Post #73

The Curious

Thanks.

In the start the main problem I saw was inconsistent action by the SCVs, they all (or mostly) freeze until the hatcheries are built while the drones work fine (?!). That, and the defense multirun still looks bugged - it either does nothing, or works just partially (last time around they built 2 creep colonies and called it a day). Interestingly enough when an expansion sequence (the one that worked...) invoked it, it worked fine.

I'll do something about the starting part, thanks. It needs some hard set train stuff anyway because only a few of the defensebuild opcodes are apparently being run anyway - the AI gets some marines and that was pretty much it.

So far the only hangup remaining is the expansion. During my last test run, the second expansion worked well (the one that has a Comsat), the other... they built a Hatchery and a bunker, even sent a bunch of guards there but did not mine. Looks like a big and rotten lottery, that one. Apparently the malfunction of the expand opcode somehow kicks the upgrades out of whack too - I noticed that the player stops doing upgrades (so some level 3 upgrades are not done, nor the mana upgrades I tucked at the end) right when the expansion debacle happens. It'd be a pity if I can't figure it out because it looks like a neat sequence. Maybe if I decide later that it absolutely has to happen I'll simulate it with targeted build orders and then running a separate area town script, who knows. Or try a "create_script" opcode, I never got around to learning about it.

Interestingly enough when I wrote a T/Z AI in the days of yore (two actually, one air and one general purpose) I ran into some kind of trouble with their building stuff, so I just gave them everything from the get go and decided that if they lose something it'd mean they're being hammered into oblivion anyway, so rebuilding was no big deal. :) Unfortunately here I need the AI to build up from very little (though by the looks of how it builds up the base I kinda wish it didn't bother because it makes an awful convoluted mess of its base and there's actually very little one can do about this).

T/P AI also had some odd issues (though I can't really remember what they were as I scrapped the map these scripts were meant for and never really got to run them through the rigorous testing.

Post has been edited 2 time(s), last time on Mar 28 2019, 7:24 pm by IlyaSnopchenko.



Trial and error... mostly error.

Mar 28 2019, 8:13 pm Pr0nogo Post #74



What's stopping you from declaring base_layout locations and having the AI respect them? Does it not work with multiracial AIs? It's a little buggy in the public build but it's being fixed by iquare atm, and with a utility that dumps coordinates for easy scripting, there's no reason not to get used to using it now.




Mar 28 2019, 8:35 pm IlyaSnopchenko Post #75

The Curious

Quote from Pr0nogo
What's stopping you from declaring base_layout locations and having the AI respect them? Does it not work with multiracial AIs? It's a little buggy in the public build but it's being fixed by iquare atm, and with a utility that dumps coordinates for easy scripting, there's no reason not to get used to using it now.
I thought it only works in 1.16? (that's what the manual states, anyway) I'm on 1.22
If it's not so, that'd be a godsend for me for whenever I write AIs that need to build up, if I can tell them where to build I can have them stop insulting my aesthetic senses by something like this. :)

Attachments:
SCScrnShot_032819_004133.png
Hits: 1 Size: 1777.78kb



Trial and error... mostly error.

Mar 28 2019, 8:47 pm Pr0nogo Post #76



Oh, yes, it's limited to 1.16.1. There's no valid reason to be using any other version though, so when you change over you can use tools from 2019 instead of 1996.




Mar 28 2019, 8:51 pm Nekron Post #77



You're free to use whichever version you'd like and both have recent tools.

The SCVs freezing thing is because SCVs will try to repair Zerg units and structures ^_^ there is a fix for that on 1.16 but it's tied to a limits mod and on 1.20 there's nothing.

Defensebuild doesn't train an active garrison, it tells the AI what to build if it *needs* defenses. And it doesn't always need them, certainly not if it's not attacked. Your best shot at having a garrison is having guards.

Yeah having a unfulfilled building request (player wants hatchery/cc, doesnt build it because of worker mismanagement) will screw up upgrades.

Building bases from scratch will always be a little bit of a pain without base_layout (and yes its 1.16 only), but you can do it if the thread is well managed and there's enough space.

Here's a sample script that builds from nothing in a format that has historically worked very well for me - https://pastebin.com/raw/5a69ULJF
Here's a sample T/Z script that builds from nothing in Omega - https://pastebin.com/raw/0yJi66rC

Post has been edited 1 time(s), last time on Mar 28 2019, 11:03 pm by Voyager7456. Reason: Regardless of merit of Pronogo's opinions on 1.16.1, please refr




Mar 28 2019, 9:24 pm IlyaSnopchenko Post #78

The Curious

Not sure I like to be causing conflicts among the members...

Re: the T/Z script, yeah, I remember that one. I did check out your work after all. :) That one was pretty evil. :cecil: But it did not expand, did it?

In the latest iteration I've caused my own script to cease working again after a while (around the spot it should go into the second half of tier 2... armory / spire etc. *sigh* Looks like I'll have to start fixing that instead of progressing.



Trial and error... mostly error.

Mar 28 2019, 9:27 pm Nekron Post #79



Nope, it does not expand, the map has another AI that requires free expansions.




Mar 28 2019, 9:33 pm Pr0nogo Post #80



You are indeed free to use less functional versions, but you do so to the detriment of your work. The only alternative is to heavily abuse create_script to create regional subtowns which has its own set of significant issues, is not consistent, and may not work with multiracial AIs (especially with the expansion worker issue Nekron described above).




Options
Pages: < 1 « 2 3 4 5 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[10:41 am]
v9bettel -- Nice
[01:39 am]
Ultraviolet -- no u elky skeleton guy, I'll use em better
[10:50 pm]
Vrael -- Ultraviolet
Ultraviolet shouted: How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
hey cut it out I'm getting all the minerals
[10:11 pm]
Ultraviolet -- :P
[10:11 pm]
Ultraviolet -- How about you all send me your minerals instead of washing them into the gambling void? I'm saving up for a new name color and/or glow
[2024-4-17. : 11:50 pm]
O)FaRTy1billion[MM] -- nice, now i have more than enough
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- if i don't gamble them away first
[2024-4-17. : 11:49 pm]
O)FaRTy1billion[MM] -- o, due to a donation i now have enough minerals to send you minerals
[2024-4-17. : 3:26 am]
O)FaRTy1billion[MM] -- i have to ask for minerals first tho cuz i don't have enough to send
[2024-4-17. : 1:53 am]
Vrael -- bet u'll ask for my minerals first and then just send me some lousy vespene gas instead
Please log in to shout.


Members Online: storuswhes, Roy