Page 1 of 1

TestBuildOrder

Posted: 01 Apr 2010, 23:28
by troycheek
I'm laying the groundwork on a replacement for a Lua Skirmish AI that I was working on last year when it achieved sentience and committed suicide (or I accidentally deleted it while moving some files, I forget which).

Currently, to find a valid build location for a given unitDef, I start at some initial position (say, the current position of my Commander) then work outward checking every position to see if I can build there. When blocking = Spring.TestBuildOrder(ud,x,y,z,0) returns blocking>1, I know I've found a valid build position. I can then Spring.GiveOrderToUnitMap(comm,-ud,{x,y,z,0},{"shift"}) or something like that. I'm pretty sure this is how I did it before.

However, I noticed that some items in my build list (Kbot Lab, for instance) were not always getting built, so I added some debug stuff and found that sometimes TestBuildOrder was returning 2 for locations too uneven for such a large structure. The actual build order would fail (silently). In other words, TestBuildOrder was telling me that a location had passed the test build when it hadn't.

Has anyone else noticed a problem like this? Am I using these statements correctly? Is there an easier way to do this in Lua?

Re: TestBuildOrder

Posted: 01 Apr 2010, 23:34
by jK
did you tried Spring.Pos2BuildPos before calling Spring.TestBuildOrder?

Re: TestBuildOrder

Posted: 01 Apr 2010, 23:48
by troycheek
Good suggestion. I am doing that already. Thanks for the quick reply.

Actually, I found the problem. I'd accidentally left a hardcoded number in a place where there should have been a variable. I was always checking for valid build positions for solar collectors, then trying to build a kbot lab in that spot. :oops:

Re: TestBuildOrder

Posted: 04 Apr 2010, 09:06
by AF
If you were to use shard instead it'd be as simple as:

Code: Select all

unit:Build("unitname")

Re: TestBuildOrder

Posted: 07 Apr 2010, 02:37
by troycheek
Actually, it was playing around with Shard that inspired me to start working on the old Lua scripts again.

Re: TestBuildOrder

Posted: 07 Apr 2010, 05:08
by AF
Competition eh?

*Troy is sleeping tight in bed with his teddy bear when the Cookie Brigade arrive on the scene. Dressed in disguise as evil bannanas they quickly proceed to troys computer, before downloading all content regarding the mysterious lua scripts of old. Vanishing into the mist as quickly as they came, the uber mega hyper ultra giga super thunder cookie of doom is summoned, promptly squishing the entire house and several adjacent blocks. All inhabitants are put in jamjars and reclaimed for future fillings of vacant wells*

Re: TestBuildOrder

Posted: 07 Apr 2010, 05:54
by aegis
AF wrote:unit:Build("unitname")
magically chooses the position?

Re: TestBuildOrder

Posted: 07 Apr 2010, 07:57
by AF
closestbuildsite, there are other versions that take a position etc So you can choose how much you want shard to figure out for you and how much you want to hand it yourself

Re: TestBuildOrder

Posted: 09 Apr 2010, 15:09
by troycheek
AF wrote:Competition eh?
Maybe. Right now my Lua AI is just in the playing around stage. It's more a stub that builds stuff and turns it over to the half a dozen or so Helper AIs that I use when I play anyway (auto skirmish, auto harass, auto retreat, auto commander d-gun/capture/reclaim, modified factory guard, modified metal maker controller, etc). I'm spending more time and effort improving the helpers than anything else.