Javascript API documentation

For AI and campaign script related discussions and questions
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

NoQ wrote:Suppose i store a droid in a global variable
Don't. You are not supposed to do that. What are you trying to do?

(You can store its id and then grab the droid using the id with the new droidFromId() function. But this would be a nasty hack. I am thinking about better ways to mark or select units over time.)
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

For example, set an attack target for an AI and make sure AI doesn't attack anything else unless this thing is destroyed (?)
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

If I create some groups and assign droids to them, then player saves the game and later loads the savegame, how do I find out what groups I had?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Also, how do I work out what structure limits are set - eg. if user has disabled building of laser satellite station, or limited number of factories to 2, etc? I don't want my AI to get stuck in a loop trying to build something that it can't build (or research something it can't build).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

aubergine wrote:Also, how do I work out what structure limits are set
viewtopic.php?f=5&t=8773#p92375
Per wrote:isStructureAvailable(structstat, player) and structureLimitReached(structstat, player) will both check structure limits for you.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

aubergine wrote:If I create some groups and assign droids to them, then player saves the game and later loads the savegame, how do I find out what groups I had?
All global variables are saved and restored. Groups are also saved and restored, keeping their group ID.

Do not try to store complicated objects on in global, though, as the save function is not terribly bright.
aubergine wrote:Also, how do I work out what structure limits are set - eg. if user has disabled building of laser satellite station, or limited number of factories to 2, etc? I don't want my AI to get stuck in a loop trying to build something that it can't build (or research something it can't build).
Check with isStructureAvailable()
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

I thought isStructureAvailable() first checks to see if it's researched, and only then checks to see if it can be built based on game settings? So before I research it, isStructureAvailable() will always return false for laser satellite station?

Example: If I have laser satellite station in my research path, will I be able to remove it from my research plans (ie. not bother researching it) if the current game doesn't allow laser satellite stations to be built?

Also, is it just global vars that are stored, or are const's also stored on game save? Does the save handle basic arrays and objects? What about functions? Is there a way to prevent something going in to the savegame?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Yes, isStructureAvailable() also checks research availability. There is currently no way to read out the building limits. I will get to that soon.

If I were you, I would not start worrying about how much a user might have screwed up the game by disabling various things. I suggest you make it run fine for the normal case first.

There is no need to save consts or functions, they are there next time the script runs. Basic arrays are saved. Objects may or may not be saved properly, not sure what the limits are, as I have not tested that much. My recommendation is not to put objects on global. The only way to prevent something from being saved is by keeping it local to a function.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Ah, good, I was hoping that functions and const's wouldn't get saved as that would put lots of cruft in to the savegame files.

I've been pondering using classes and possibly creating a jQuery-like syntax in my AI file - are there any issues with altering prototype chains for custom objects, etc?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

aubergine wrote:I've been pondering using classes and possibly creating a jQuery-like syntax in my AI file - are there any issues with altering prototype chains for custom objects, etc?
I don't really understand what you are asking.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

It's probably easier if I get my AI in to a working state and show you :)

Essentially, I'm working on an AI with possibly some unusual features:

* Slicing the map in to sectors and then deciding what needs to be done in each sector
* Ability to manage more than one base (eg. it might build a separate base around an oil resource or destroyed player)
* Ability to build and manage multiple outposts to better defend map sectors
* Ability to transfer control of droid groups between bases and outposts, and assist allies
* Automated command interaction between bases, outposts and allies
* Ability to attack targets from multiple directions at the same time
* Better management of system resources: reduce CPU load (I hope!)

Those are the main bits I'm working on at the moment. I'm robbing a fair bit of code from NoQ's nullbot, but adding lots of my own code and structuring things somewhat differently to make AI task management a bit easier to handle. My current task is to get a class-based version of nullbot and then extend it to the extra features I'm looking to develop.

Future plans include (mostly reliant on what features are added to the JS API):

* Ability to interact with human allies via in-game messages / beacons - similar to DyDo AI
* Ability to adapt (+/-) to enemy capabilities (in single player skirmishes) to provide a more balanced game
* Ability to create multi-player groups (between allied AI players) - eg. each AI ally contributing some VTOLs to a group and then one ally taking control of the entire group (even though it doesn't own all units in it)
* Ability to coordinate multi-AI attacks on a target, with target optionally defined by human player
* Ability to create 'survivor' trucks which hide in ally bases - if the AI main bases get destroyed, its survivor trucks give it a chance to rebuild somewhere safer or as a last resort donate it's remaining power/droids to an ally

By allowing scripting in JavaScript you've opened Pandora's Box :)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
lav_coyote25
Professional
Professional
Posts: 3434
Joined: 08 Aug 2006, 23:18

Re: Javascript API documentation

Post by lav_coyote25 »

aubergine wrote:
By allowing scripting in JavaScript you've opened Pandora's Box :)
just as long as you remember what happens to Pandora in the end we will all be ok.
User avatar
Rman Virgil
Professional
Professional
Posts: 3812
Joined: 25 Sep 2006, 01:06
Location: USA

Re: Javascript API documentation

Post by Rman Virgil »

.
aubergine wrote:It's probably easier if I get my AI in to a working state and show you :)

Essentially, I'm working on an AI with possibly some unusual features:

* Slicing the map in to sectors and then deciding what needs to be done in each sector
* Ability to manage more than one base (eg. it might build a separate base around an oil resource or destroyed player)
* Ability to build and manage multiple outposts to better defend map sectors
* Ability to transfer control of droid groups between bases and outposts, and assist allies
* Automated command interaction between bases, outposts and allies
* Ability to attack targets from multiple directions at the same time
* Better management of system resources: reduce CPU load (I hope!)

Those are the main bits I'm working on at the moment. I'm robbing a fair bit of code from NoQ's nullbot, but adding lots of my own code and structuring things somewhat differently to make AI task management a bit easier to handle. My current task is to get a class-based version of nullbot and then extend it to the extra features I'm looking to develop.

Future plans include (mostly reliant on what features are added to the JS API):

* Ability to interact with human allies via in-game messages / beacons - similar to DyDo AI
* Ability to adapt (+/-) to enemy capabilities (in single player skirmishes) to provide a more balanced game
* Ability to create multi-player groups (between allied AI players) - eg. each AI ally contributing some VTOLs to a group and then one ally taking control of the entire group (even though it doesn't own all units in it)
* Ability to coordinate multi-AI attacks on a target, with target optionally defined by human player
* Ability to create 'survivor' trucks which hide in ally bases - if the AI main bases get destroyed, its survivor trucks give it a chance to rebuild somewhere safer or as a last resort donate it's remaining power/droids to an ally

By allowing scripting in JavaScript you've opened Pandora's Box :)

In the end the Pandora's Box could very well transform into a cornucopia that propells WZ 2100 into the front ranks, finally, of elite RTSs while still maintaining its unique identity.

Let me unravel that comment some.

What you are proposing for your A.I. is gonna make it a VERY interesting and competitive A.I. - that much is clear.

The particulars of HOW it will accomplish that ALSO point to, and will demonstrate the viability of, a development direction for MP GPMs that will advance depth and breath of tactical game play like nothing else has done heretofore since 1999.

What I'm refering to in the last statement is the cognitive task ease of advanced maneuver (along with its associated situational awareness). And this is how I define "Advanced Maneuver": effective, simultaneous, command and control of at least 3 combat groups from coordinated, multiple vectors and varying velocities. (To translate from the A.I. context to MP capabilties would also require UI changes.)

I don't see anything else that has the definitive power to
"....propell WZ 2100 into the front ranks, finally, of elite RTSs while still maintaining its unique identity."
The best of good wishes in your seminal efforts. :D

- Regards, Rman. :hmm:
.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

NoQ wrote:For example, set an attack target for an AI and make sure AI doesn't attack anything else unless this thing is destroyed (?)
You can use bind() to call a function when the target is destroyed. You can also set a timer with that target as a passed in reference, which triggers until the object dies. Will this do the job?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Added new global const 'version' that gives version number of game. New object property 'health' that gives percentage damage to object (100% = no damage). Also new object properties 'armour' and 'thermal' that give kinetic and heat armour values, respectively.
Post Reply