TestBuildOrder

TestBuildOrder

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

Moderator: Moderators

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

TestBuildOrder

Post 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?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: TestBuildOrder

Post by jK »

did you tried Spring.Pos2BuildPos before calling Spring.TestBuildOrder?
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: TestBuildOrder

Post 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:
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: TestBuildOrder

Post by AF »

If you were to use shard instead it'd be as simple as:

Code: Select all

unit:Build("unitname")
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: TestBuildOrder

Post by troycheek »

Actually, it was playing around with Shard that inspired me to start working on the old Lua scripts again.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: TestBuildOrder

Post 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*
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: TestBuildOrder

Post by aegis »

AF wrote:unit:Build("unitname")
magically chooses the position?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: TestBuildOrder

Post 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
User avatar
troycheek
Posts: 80
Joined: 22 May 2009, 19:13

Re: TestBuildOrder

Post 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.
Post Reply

Return to “Lua Scripts”