Central Build AI as lua widget!

Central Build AI as lua widget!

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Central Build AI as lua widget!

Post by troycheek »

Spring 0.79: The old group-AIs where removed altogether, because they had already been replaced by lua-scripts.
Since I couldn't locate the lua-script replacement for the old Central Build group-AI, I made one myself. I moved the download link and instructions to this post.

Wiki goodness about original Group AI: Central Build AI: A common non-hierarchical permanent build queue.

Please listen closely to the following instructions as some options have changed:

Central Build AI adds a small amount of intelligence to a group of mobile construction units ("Central Builders"). With one/some/all of the Central Builders selected, place a few build orders while holding the SHIFT key just as if you were setting up a regular build queue. These build orders will be transferred over to the Central Build queue and will display as ghosted images tagged with some debug numbers. Idle Central Builders should soon move to carry out the nearest build order in the central queue or assist other Central Builders with their build orders. If only one builder in the group can fulfill a certain build order, all other builders will automatically assist that one until it's finished.

Orders sent directly to Central Builders without SHIFT will be acted on immediately, perhaps canceling what the builder was working on at the time. Once the builder is idle again, it will rejoin the workforce.

Central Build AI can use either a custom build group or one of Spring's regular unit groups. Change line 33 local myGroupId = -1 to any number 0-9 to use that group number. You can then use the standard unit group controls. The custom group if keyed to the letter Q, but if you use Q for another purpose, you may select a new letter for CBAI by changing line 35 local hotkey = string.byte("q")

To place one or more builders in the Central Build custom group, select the builder(s) and press ctrl+[group]. If Central Build recognizes them as valid mobile builders, they should be tagged with "cb". To select the group at any time, press [group]. Pressing [group] twice will center the camera over the group.

If you don't see "cb" displayed on your builders in the Central Build group, check the widget selector (F11) to make sure that Central Build AI is listed and active. Widget has been written to work with any game running under the Spring Engine which uses mobile builders which can assist each other, but has only been tested with *A games.
Attachments
central_build_AI.lua
Central Build AI v1.1 - Replacement for old Central Build Group AI
(17.3 KiB) Downloaded 226 times
Last edited by troycheek on 21 Jul 2009, 00:59, edited 15 times in total.
Super Mario
Posts: 823
Joined: 21 Oct 2008, 02:54

Re: Central Build AI as lua script?

Post by Super Mario »

troycheek wrote:
Spring 0.79: The old group-AIs where removed altogether, because they had already been replaced by lua-scripts.
Can anyone tell me where to find a lua replacement for the old Central Build group-AI? I find I just can't concentrate on offense when I'm having to continuously shuffle my builders around manually.
Yea I just check the files and I can't seemed to find them anywhere.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Central Build AI as lua script?

Post by hoijui »

could you please explain what the central build AI did?
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

Central Build AI works like a "Common non-hierarchical permanent queue" for all the units in that CBAI. That is, unlike the "normal" queue you are used to in the default system, it does NOT have a queue "order", there is no 1st 2nd 3rd, just... orders... and any unit able to perform that build order will start to serve the request nearest to it. When, in a group of units, only one is capable of performing a build order, all the others will auto-guard that unit, until it finishes building. Adding things to the queue doesn't mean it will be performed after or before any other order. Several CBAI groups can be created to satisfy different build priorities. Cobbled from http://springrts.com/wiki/Central_Build_AI

In other words, I could define a group of three T1 builders at the start of a XTA game, assign them to the CBAI, and tell them to build 5 metal extractors, 2 metal makers, 10 solar collectors, and half a dozen missile towers at various locations around my base. I could then go back to micromanaging my flash rush while CBAI constructed those items, each builder starting its own construction, then moving on to another item in the list or assisting another nearby builder when finished, in no particular order but generally building from their current locations outward.

Later in the game, I could add some T2 builders to that CBAI group. If building something outside the capabilities of the T1 builders, those builders would just assist the T2 builders. That way, I wouldn't have to keep track of what builder could build what items or worry about idle builders getting lost and unused somewhere.

You could also give orders to individual members of the group. For example, build this solar immediately or move to this location. The individual would perform that action then rejoin the group. This was useful for a quick build or to move the builder out of harm's way. Sometimes the builder would barely start the action then rejoin the group before finishing, but I think that was a bug.

The CBAI appeared to start by simply cycling through the list of builders and assigning each one singly to the nearest new construction project within its capabilities. As builders became idle again, it would then assign them to new construction or to assist another builder in the CBAI, depending on which was nearer. Builders which couldn't build anything on the list would get assigned to assist other builders. All builders were doing something pretty much all the time, as long as there were any build items left.

I hope that explains it.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

Additional: You still had to specify the location of every single construction project to the Central Build AI, just in case I didn't make that clear. You couldn't just tell it to build three metal extractors and turn it loose. You had to tell it to build one extractor HERE, one HERE, and one over HERE. But then the CBAI would take over and decide which builder would build which extractor and in what order.

Also, another bonus was that the build queue was maintained as long as there was a single builder left alive in the build group, even if the builder couldn't build some of the items in the queue. If the last builder with a particular ability got taken out by a lucky air strike, I could add another one later and it could resume the queue.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

It's been a few weeks, so I guess nobody's going to reply saying "You can find a Central Build widget to replace the old Group AI right... over... there..." I also see that there was a similar request made about a year ago in this thread which ended when the OP was informed of the Group AI.

And since nobody else is working on this [pauses to listen for crickets] I'll be creating one myself. My previous lua experience had been limited to fiddling with trepan's metal maker widget. However, in the last few days I've managed to accomplish the following:
  • Further fiddling of trepan's metal maker to also control metal extractors with separate thresholds for extractors and makers. Now does exactly what I want it to and I'm happy with metal management for the first time since the Group AI went away.
  • Heavily altered CA's auto retreat widget to work with XTA and not require ca_layout. Retreating units even display a message saying they're retreating.
  • Added a list of my favorite XTA units to auto_skirm. Not much, I know, but I'm just proud of myself for figuring out how to drill into the XTA sdz and find the unit names.
  • Finally figured out what ca_layout was doing and why some widgets require it or IceUI. I even managed to make it look nicer in XTA. I eventually realized that in the statement I want to add a button to the UI to make Spring do stuff, the make Spring do stuff part is much easier than the add a button to the UI part. (Any chance that Spring.InsertUnitCmdDesc() and similar calls will start working in unsynced code any time soon? Didn't think so.)
  • Downloaded and examined pretty much every lua widget known to man. I even understand some of them. I've even realized that I know how to improve some of them.
So I figure I've at least got a shot at creating a Central Build widget. Details later.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Central Build AI as lua script?

Post by CarRepairer »

troycheek wrote:[*] Heavily altered CA's auto retreat widget to work with XTA and not require ca_layout. Retreating units even display a message saying they're retreating.
Just to clarify, you meant Retreat widget, not Autoretreat widget, as that is a different widget which automatically sets retreats.

I'm curious what you did to get it to work without calayout.

Also curious about why you said they now display a message when retreating, since they already do this by flashing the medic symbol. Or did you mean you added a console message.
smokingwreckage
Posts: 327
Joined: 09 Apr 2005, 11:40

Re: Central Build AI as lua script?

Post by smokingwreckage »

Retreat working without CAlayout? I am very interested indeed!
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

CarRepairer wrote:Just to clarify, you meant Retreat widget, not Autoretreat widget, as that is a different widget which automatically sets retreats.
cmd_retreat.lua
name = "Retreat",
desc = " v0.26 Place 'retreat zones' on the map and order units to retreat to them at desired HP percentages.",
author = "CarRepairer",

I've got about three of them laying around here somewhere, every one of them named "Retreat," but this is the one I was talking about. I've been thinking of it as "auto" because units retreat to the zones without me having to tell them to.
CarRepairer wrote:I'm curious what you did to get it to work without calayout.
I cheated. Without the proper layout and buttons to set HP percentages and retreat zones, I hardcoded at 50% damage and had units always retreat to the nearest nano tower set on patrol. However, I had a problem with land units wanting to retreat to the water nano just a bit too far offshore, so I changed it to units retreating back to just outside the factory that created them. I usually put a nano or two on patrol around the factories to assist, so the units still get repaired.

Anyway, while I started by altering your Retreat, it eventually reached the point where I scrapped the whole thing and started from scratch, using Retreat mostly as inspiration and as a source of code snippets for handling the really hard stuff.
CarRepairer wrote:Also curious about why you said they now display a message when retreating, since they already do this by flashing the medic symbol. Or did you mean you added a console message.
I was using CA's widgets with XTA, so the medic symbol was missing (blank box), but I was mostly bragging that I managed to add my own messages. I first added a console message ("Flash 409 is retreating!") but those got annoying so I figured out a way to use gl.text to put a little retreat message over the units (stealing heavily from BuildETA and Group Label to do so).

In other news, my Central Build widget has reached the point where I can issue a single build command at a time through my Commander and a Construction Vehicle will run off to actually do the building. I worked all day on that because if I couldn't figure out how to read the build queue of one unit and send those items to another, there was no use trying to code the rest of it.

Now, to throw out everything I've hacked together to get this far and build the foundations of a real program.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

smokingwreckage wrote:Retreat working without CAlayout? I am very interested indeed!
At this point, it's more the mutant offspring of Retreat than anything else. I've rewritten it so much there's not much left but the inspiration.

Limitations: Retreat limit hardcoded, currently 50%. It can be changed, but not in-game and not for individual units like the original. Retreat point for each unit fixed at just outside the factory that created it. This is generally away from the front lines and somewhere reachable by the unit, so that works out pretty good. The widget can only track units built in factories after it was started. If you stop the widget, it forgets how to retreat any current units. I've only tested it so far with XTA 9.58.

If you're still interested, I'll clean it up a bit and upload a copy here.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Central Build AI as lua script?

Post by CarRepairer »

troycheek wrote:I cheated.

...

I was using CA's widgets with XTA, so the medic symbol was missing (blank box), but I was mostly bragging that I managed to add my own messages.
Well here are some tips:

You can include calayoutlua in your spring/luaui folder, with a minor tweak here and there. I tested this with SA and managed to get retreat working - just to see if I could.

You can include the medic symbol in the appropriate folder in your luaui as well.

Instead of calayout, you can make your own floaty buttons. Not something that can be quickly thrown together, but with the work you already put into it, it might have been worth the effort to do this instead. But it's all a learning experience anyway so I'm sure it was productive in that sense.

You may have noticed I created luaui commands to retreat and place-retreat-zone, which can be bound to keys in uikeys.txt. I hardly ever actually click on that ambulance button, as I use my hotkey instead. So you could still use the retreat zones without the button with a bit of modification, again.

I'm glad to see someone interested in the widget outside of CA (it's not very popular among the pros :P). Ask me in lobby if you have any questions.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

CarRepairer wrote:You can include calayoutlua in your spring/luaui folder, with a minor tweak here and there. I tested this with SA and managed to get retreat working - just to see if I could. You can include the medic symbol in the appropriate folder in your luaui as well.
That's pretty much what I did for XTA, copying a couple of graphics files and redirecting others to files that already existed in XTA. I got everything to work (well, to look pretty much identical to the default XTA interface) except for the Dgun button for the Commander. (Yes, I know I usually hit the 'd' key, but its absence just bugs me.) Then I decided I was offended that one widget depended on another, that I'd prefer it if calayout restored the default layout when exited, etc. By the way, the more I learn about layouts and UI modification, the more I'm impressed by calayout, so don't take any of the above as criticism.
CarRepairer wrote:But it's all a learning experience anyway so I'm sure it was productive in that sense.
That hits the nail right on the head there. I'm actually learning a new programming language (or whatever lua is if not technically a programming language) which is a big deal for me seeing as I've got an Atari ST emulator so I can run old GFA BASIC programs I wrote to maintain my website.
CarRepairer wrote:You may have noticed I created luaui commands to retreat and place-retreat-zone, which can be bound to keys in uikeys.txt. I hardly ever actually click on that ambulance button, as I use my hotkey instead. So you could still use the retreat zones without the button with a bit of modification, again.
I did notice that, but then decided that I liked setting the retreat zones automatically (and retreating then returning to battle automatically). Just a personal preference, really, and your system is definitely better because it's user configurable instead of just hard coded the way I like it.
CarRepairer wrote:I'm glad to see someone interested in the widget outside of CA (it's not very popular among the pros :P).
That surprises me, because the Retreat widget is one of the things that I liked about CA. I just didn't play it much because the Central Build Group AI didn't seem to exist in CA (at least, I couldn't find it) and I was more used to XTA's units and UI anyway. Then Spring dropped the Group AI concept and here I am.

(I'm possibly mistaken, but I think I remember once using a version of XTA which had a CA-like Retreat function, then noticing it missing when I switched to a newer version of XTA. Or I may have just imagined it.)

I'm torn between tracking down an older version of Spring to research how CB Group AI behaved, or just program a CB widget to mimic the way I remember it behaving. My being the first and possibly only person to notice CB missing, I'm wondering if there's any need to exactly mirror the old functionality, since I might be the only person using it anyway.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Central Build AI as lua script?

Post by CarRepairer »

I think XTA possibly used an old version of retreat when it was a gadget, but it was not properly functional yet and I converted it to a widget anyway. I am only guessing because Noruas, an XTA dev, made a mod of his own called Zexy Annihilation that I tried which included the old retreat gadget.
smokingwreckage
Posts: 327
Joined: 09 Apr 2005, 11:40

Re: Central Build AI as lua script?

Post by smokingwreckage »

I love the retreat widget. It's great for team chicken/spacebugs bashing.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Central Build AI as lua script?

Post by Google_Frog »

CarRepairer wrote:I'm glad to see someone interested in the widget outside of CA (it's not very popular among the pros :P). Ask me in lobby if you have any questions.
That's because it doesn't actually help. Retreating units disrupt all the units behind them and often if they're in a bad situation they're dead anyway so they may as well fire a bit more. Often it causes units to clump into a big mess as the front ones try to move back and the back ones try to move forwards making them vulnerable to AOE.

It's a very good widget but unit size:cost and game wide damage:HP ratios make it not that useful in CA. Although it 's good for heavy gunships because they don't collide, are fast enough and have enough hp.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Central Build AI as lua script?

Post by CarRepairer »

If nothing else, I like setting it to units I leave idle somewhere when I am off doing something else. Coming back and finding someone shelling my units from a distance is not so bad when those units have retreated instead of sitting there taking abuse until they die. There are lots of little micro savers like that. Google is right though, it can be ineffective and annoying at times - I have a hotkey bound to cancel retreat (bind 'key' luaui retreat noretreat) for just such occasions.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI widget update

Post by troycheek »

I've been working on the Central Build AI widget quite a bit and have reached the point where I am reasonably confident that this thing might actually be released some day. Not soon, mind you, but eventually.

So far, I've managed to detect mobile builders among the units in a group, intercept any build orders issued to them, and stick those orders in a centralized build queue. I can display items from the queue on the map at their intended build locations in ghosted form with cute little text tags over them.

Edit: Having more than one builder selected when giving a build order meant multiple identical orders going into the common build queue. Now detects and removes those duplicates. Giving the same build order again at a later time now cancels that build.

I know how to send the build orders back to the builders but haven't worked out the best way to decide which builder gets which project, how to make builders who aren't actively building assist others, how to determine if the build was successful, things like that.

Still having problems figuring out which builders can reach which build locations. A ground vehicle or hovercraft might be closer just based on map coordinates, but a kbot or airplane from farther away might be able to actually reach a build location or at least take a shorter, faster path.
jorenm
Posts: 13
Joined: 01 Dec 2005, 03:57

Re: Central Build AI as lua script?

Post by jorenm »

I'm glad someone is working on this. This is a great feature.
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: Central Build AI as lua script?

Post by troycheek »

jorenm wrote:I'm glad someone is working on this. This is a great feature.
Good to hear you say so. I was beginning to think that I was the only one who missed Central Build GroupAI.

After another day of slinging code, I now have something that does what it's supposed to do much of the time. I can put build orders into the central queue and watch them get farmed out to the nearest members of the group. Idle members will assist nearby builds before going off to start their own projects farther away. Proof of concept, if nothing else. I need to go back and rewrite pretty much everything before this widget sees release.

And my record so far is about 24 minutes before Spring crashes back to the desktop. I didn't realize a Lua widget could crash Spring.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Central Build AI as lua script?

Post by imbaczek »

it _should_ not crash it, but you can always do something that your gfx drivers won't like with LuaOpenGL. submit infologs in any case or check them yourself on #buildserv with !translate command.
Post Reply

Return to “Lua Scripts”