Questions on 3.1.x JS API

For AI and campaign script related discussions and questions

Questions on 3.1.x JS API

Postby bendib » 30 Aug 2015, 01:29

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?
Image
User avatar
bendib
Regular
Regular
 
Posts: 1006
Joined: 29 Aug 2010, 05:22
Location: Imeuta

Re: Questions on 3.1.x JS API

Postby Per » 30 Aug 2015, 09:51

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).
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3651
Joined: 03 Aug 2006, 19:39

Re: Questions on 3.1.x JS API

Postby NoQ » 30 Aug 2015, 11:00

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
NoQ
Special
Special
 
Posts: 6105
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Questions on 3.1.x JS API

Postby bendib » 07 Sep 2015, 11:34

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.
Image
User avatar
bendib
Regular
Regular
 
Posts: 1006
Joined: 29 Aug 2010, 05:22
Location: Imeuta

Re: Questions on 3.1.x JS API

Postby NoQ » 07 Sep 2015, 18:22

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
NoQ
Special
Special
 
Posts: 6105
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Questions on 3.1.x JS API

Postby bendib » 08 Sep 2015, 05:20

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.
Image
User avatar
bendib
Regular
Regular
 
Posts: 1006
Joined: 29 Aug 2010, 05:22
Location: Imeuta


Return to Scripting