Questions on 3.1.x JS API

For AI and campaign script related discussions and questions
Post Reply
User avatar
bendib
Regular
Regular
Posts: 1011
Joined: 29 Aug 2010, 05:22
Location: Imeuta
Contact:

Questions on 3.1.x JS API

Post by bendib »

I've been reviewing the documentation here, and there are a few things I'm hoping devs can answer.

First, how do I find the coordinates of a truck's build order?
How do I order a droid to recycle?
How do I cancel droid production in a factory?
How do I scan for enemies in the player's field of vision?
Also known as Subsentient.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Questions on 3.1.x JS API

Post by Per »

Doesn't look like order coordinates have been added yet. Seems like something that should be.

The recycle order is in git master (future 3.2). Not sure why it has not been added to 3.1, but probably some reason.

There is currently no way to cancel droid production.

There are two ways to scan for enemies - passively and actively. The passive way is to listen for 'seen' and 'attacked' events, and react to those. The active way is to use enumRange() and enumArea(), but these only exist in git master (future 3.2).
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Questions on 3.1.x JS API

Post by NoQ »

enumStruct() and enumDroid() also support the visibility check; they scan the whole map and pick only visible stuff if the relevant optional argument is set. However, it may be impossible to achieve good performance with these functions, especially if you target high-oil and many objects are present on the map.

Seems hard to hack-backport DORDER_RECYCLE because you'd also need a function for order-without-arguments (that is, you need to get orderDroid() as well, because orderDroidLoc()/orderDroidObj() won't work).
User avatar
bendib
Regular
Regular
Posts: 1011
Joined: 29 Aug 2010, 05:22
Location: Imeuta
Contact:

Re: Questions on 3.1.x JS API

Post by bendib »

Got more questions. It seems that with timers, it might not be atomic? I hope there aren't two functions running at once? I'm having trouble tracking truck production. I've got a variable to track how many are being built, and a function to count how many exist, but I can't get it to work properly. When a droid is completed (using eventDroidBuilt), if it's a truck, TrucksBeingMade is decremented, and when one is sent to production, it's incremented. Before I implemented TrucksBeingMade, I had problems with factories creating too many trucks and becoming jammed. That can't be fixed because, after all, there is no way to abort factory production and no way to order droids to recycle.
Also known as Subsentient.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Questions on 3.1.x JS API

Post by NoQ »

Javascript has no threads, everything is atomic, and there's only one callback running at once.

For stuck on limit, in 3.2 there's getDroidProduction(factory), so that to see how many trucks, including in-production. On 3.1 i just limit trucks to less than 10, so that if all factories produce at once, they still don't get stuck. This also assumes limiting cyborg engineers (otherwise it should gave been 5), but i almost never make them anyway.
User avatar
bendib
Regular
Regular
Posts: 1011
Joined: 29 Aug 2010, 05:22
Location: Imeuta
Contact:

Re: Questions on 3.1.x JS API

Post by bendib »

Yeah, afraid I can't do that with my bot. RatBot is for high oil, and as such needs all 15 trucks. Running into a lot of strange, discouraging bugs with this thing, most of them not happening in skirmish, but only in multiplayer.
Also known as Subsentient.
Post Reply