Javascript API documentation

For AI and campaign script related discussions and questions
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Yup - having it be LASERSAT or something like that would be good.

Would it be worth merging startPositions and playerData to make them more consistent with other things?

enumPlayers(); // return array of player objects

And a player object would have following properties (similar to base object, extended with some player specific stuff):

.id = (integer) player position on map (eg. 0..10)
.x, .y and .z = x,y,z of start position for player
.type = PLAYER
.playerType = HUMAN || AI || SCAVENGER || EMPTY
.player = (integer) player ID (same as .id I assume?)
.ai = If .playerType == AI then the id of the AI being used (useful for inter-AI comms at a later date)
.difficulty = (only applicable to AI players) EASY || MEDIUM || HARD || INSANE
.colour = colour of player (I assume this is a string? is it localised or i18n keyword?)
.team = team that the player is currently in (is this numeric or char or string?)
.selected = (boolean) true if player[id] == selectedPlayer
.name = (string) name of player, AI, "Scavengers" or undefined as applicable considering .playerType

I think this would improve overall consistency of the API. (: The existing startPositions and playerData could remain as alternate ways of accessing the info.

Also, global array "derrickPositions" - wouldn't this be better named "oilPositions"? (and isn't derrick spelt wrong?)
"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 »

.droidType = DROID_TRANSPORTER: how do I know what sort of transporter (cyborg or heavy)?

How do I get droids to dis/embark a transporter?
"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 »

eventObjectSeen() - does this get called for starting units as well?
"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 »

Would it be possible to add a third optional parameter to the queue function so that I can have an array of arguments passed to my queued functions?

Code: Select all

queue(sFunc[, oObj[, bApply]]);
Where:

* sFunc = (string) name of function to call
* oObj = (object or primative) an object to pass to the function as first parameter
* bApply = (boolean) if true, and oObj is an array, apply oObj as arguments array to the function

Code: Select all

// pseudo code - I've used JS here as I understand JS better, but
// I'm using it to describe the sort of thing the C++ code would do

// invoke a queued function
if (sFunc in global && global[sFunc] instanceof Function) {
   global[sFunc][(bApply && oObj instanceof Array) ? "apply" : "call"](global,oObj);
}
In cases where I want multiple params passed to a queued function, this will avoid the need to create crufty activation objects / closures (which is what I'm currently doing).
"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:
Also, global array "derrickPositions" - wouldn't this be better named "oilPositions"? (and isn't derrick spelt wrong?)

nope. see : http://en.wikipedia.org/wiki/Derrick
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Damn, I need to go fix lots of spelling mistakes in my code - I'd been spelling it "derrik" for some reason :( *slaps forehead*
"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:Damn, I need to go fix lots of spelling mistakes in my code - I'd been spelling it "derrik" for some reason :( *slaps forehead*

there is a derrik and it is also usable see: http://www.thinkbabynames.com/meaning/1/Derrik " people's ruler". :)
stiv
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 876
Joined: 18 Jul 2008, 04:41
Location: 45N 86W

Re: Javascript API documentation

Post by stiv »

If you want to be pedantic, the WZ 'oil derrick' thingie is actually a pump jack, a device for extracting oil. A derrick is used for drilling.
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:eventObjectSeen() - does this get called for starting units as well?
It does not get called for your own units.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

I've added stattype LASSAT for the laser satellite, DORDER_EMBARK for embarking on a transport, and DORDER_DISEMBARK for getting the transport to unload somewhere.
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:Would it be possible to add a third optional parameter to the queue function so that I can have an array of arguments passed to my queued functions?
Possible, certainly. But I am not sure why you'd want to do that. Something tells me you are trying to do something that is not a very good idea...? I suspect that passing lots of data between the C++ side and the Javascript side of things is expensive, at least compared to keeping the data on the Javascript side.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Per wrote:
aubergine wrote:eventObjectSeen() - does this get called for starting units as well?
It does not get called for your own units.
I see it also only includes things that my sensors see - so I assume it won't tell me when allies sensors detect something?
Per wrote:I've added stattype LASSAT for the laser satellite, DORDER_EMBARK for embarking on a transport, and DORDER_DISEMBARK for getting the transport to unload somewhere.
Awesome! Thanks :) How do I know what sort of transport I'm working with (eg. I don't think I can get tanks on the smaller cyborg transport)?
Per wrote:
aubergine wrote:Would it be possible to add a third optional parameter to the queue function so that I can have an array of arguments passed to my queued functions?
Possible, certainly. But I am not sure why you'd want to do that. Something tells me you are trying to do something that is not a very good idea...? I suspect that passing lots of data between the C++ side and the Javascript side of things is expensive, at least compared to keeping the data on the Javascript side.
I'm not intending on sending huge objects or anything, I just find my code easier to read if queued functions could have named parameters, rather than having to pick at properties in an object that's passed in as first and only parameter. An arguments object will be created whatever happens, even if there is no object/parameters.
"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 »

Added new event eventObjectTransfer(object, from) that is called when objects are transferred between players (eg due to Nexus Link). Also new feature property .damageable that tells whether it can be destroyed or not.

I consider that eventObjectSeen() does not trigger for allies seeing things a bug, but it is not trivially fixed.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Per wrote:Added new event eventObjectTransfer(object, from) that is called when objects are transferred between players (eg due to Nexus Link). Also new feature property .damageable that tells whether it can be destroyed or not.
Awesome! Thanks!
Per wrote:I consider that eventObjectSeen() does not trigger for allies seeing things a bug, but it is not trivially fixed.
I can work round this for now with a timer that enums what each ally can see every 10-15 seconds.
"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 »

NoQ wrote:Also, i tried the challenges with custom AIs again, and i have a feeling that two AIs at once are running for the player for which an external AI is specified.
Paradigm shift: i just noticed that in the challenge in question not only player_2 (at position 4) and player_3 (at position 6) are controlled by both AIs simultaneously, but also pink (at position 2) and cyan (at position 7) are not controlled by any AI at all (just remaining idle). So probably just some of the Nexus AIs get applied to a wrong player.
Post Reply