Javascript API documentation
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
A short heads up: I've shuffled the parameters for the addFeature() call, to make it similar to the order used in wzscript, and thus make porting simpler. I'm pretty sure nobody uses this function already, since it was broken and would crash until yesterday. But I'm saying just in case anyway.
I'm currently working on porting the cam1a campaign mission to javascript. I will say more about this when I am done.
I'm currently working on porting the cam1a campaign mission to javascript. I will say more about this when I am done.
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
I have added a new function:
hackMarkTiles([label | x, y[, x2, y2]])
It will mark tiles on the map with a pulsing red colour. You can pass it an area label, point coordinates, or area coordinates; or no parameters to clear all such marks.
It is mostly for debugging for now (hence the hack prefix), however I'm sure once you start playing with it, there will be a hundred follow up feature requests ...
It is, if I may say so, a pretty nifty little trick... 
hackMarkTiles([label | x, y[, x2, y2]])
It will mark tiles on the map with a pulsing red colour. You can pass it an area label, point coordinates, or area coordinates; or no parameters to clear all such marks.
It is mostly for debugging for now (hence the hack prefix), however I'm sure once you start playing with it, there will be a hundred follow up feature requests ...
-
aubergine
- Professional

- Posts: 3462
- Joined: 10 Oct 2010, 00:58
Re: Javascript API documentation
1. I'd like to be able to toggle individual tiles on and off without affecting other tiles.Per wrote:hackMarkTiles([label | x, y[, x2, y2]])
... however I'm sure once you start playing with it, there will be a hundred follow up feature requests ...
2. I'd like to be able to set the colour of the marking. For example, I want to create a heatmap of enemy threat level or most regularly travelled paths.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: Javascript API documentation
We still don't have a function for giving units or power to an ally?
Just wanted to use something like that (:
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
Added function donateObject(object, to) -- Donate a game object (currently restricted to droids) to another player. Returns true if donation was successful. May return false if this donation would push the receiving player over unit limits.NoQ wrote:We still don't have a function for giving units or power to an ally?Just wanted to use something like that (:
-
Emdek
- Regular

- Posts: 1329
- Joined: 24 Jan 2010, 13:14
- Location: Poland
Re: Javascript API documentation
So maybe there should be also function to check if we can donate it (like canDonateObject(object, to) returning boolean)?Per wrote:May return false if this donation would push the receiving player over unit limits.
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
The time has come, the high time, to destroy hatred in oneself.
Beware! Mad Qt Evangelist.
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
Added function donatePower(amount, to) -- pretty self-explanatory.
Semperfi-JS will now respond to 'donatetruck' and 'donatepower', if you are allied.
@Emdek - Just use getDroidLimit().
Semperfi-JS will now respond to 'donatetruck' and 'donatepower', if you are allied.
@Emdek - Just use getDroidLimit().
-
aubergine
- Professional

- Posts: 3462
- Joined: 10 Oct 2010, 00:58
Re: Javascript API documentation
Would it be possible to rename donateObject() to transferObject() as the associated event is eventObjectTransfer()
And then rename donatePower() to transferPower() to keep with same convention + the computer voice says "power transfered" too: https://warzone.atlassian.net/wiki/down ... ferred.ogg
Also, would it be possible to get an eventPowerTransfer(amount, from, to) -- AIs that carefully track power usage will benefit from knowing when they have a sudden influx or loss of power.
And then rename donatePower() to transferPower() to keep with same convention + the computer voice says "power transfered" too: https://warzone.atlassian.net/wiki/down ... ferred.ogg
Also, would it be possible to get an eventPowerTransfer(amount, from, to) -- AIs that carefully track power usage will benefit from knowing when they have a sudden influx or loss of power.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: Javascript API documentation
Yay thanks!
I'm still looking for a function similar to playerPower(), but taking debts into account. That is, if a player has $99 and currently struggling to build a factory and a lab, it should return -$101 rather than $99.
I'm still looking for a function similar to playerPower(), but taking debts into account. That is, if a player has $99 and currently struggling to build a factory and a lab, it should return -$101 rather than $99.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
Added function queuedPower(player) to return the amount of power queued up for production. So, myNetDebt = playerPower(me) - queuedPower(me);NoQ wrote:I'm still looking for a function similar to playerPower(), but taking debts into account. That is, if a player has $99 and currently struggling to build a factory and a lab, it should return -$101 rather than $99.
-
NoQ
- Special

- Posts: 6226
- Joined: 24 Dec 2009, 11:35
- Location: /var/zone
Re: Javascript API documentation
Thanks!
Whoops some bug: the AI's power doesn't reduce when he donates it.
Whoops some bug: the AI's power doesn't reduce when he donates it.
Maps | Tower Defense | NullBot AI | More NullBot AI | Scavs | More Scavs | Tilesets | Walkthrough | JSCam
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
Already fixedNoQ wrote:Whoops some bug: the AI's power doesn't reduce when he donates it.
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
The bind() function, which always said "This function is under construction and is subject to total change!", has been removed. It was true to its documentation in that respect, at least.
setTimer() and queue() can now take a string argument as their third argument, which will be passed on to the called function.
See 592854b6025d3b7ad66cdc9fe7af333f123fc9de for the gritty details.
I am considering the following changes to timers:
setTimer() and queue() can now take a string argument as their third argument, which will be passed on to the called function.
See 592854b6025d3b7ad66cdc9fe7af333f123fc9de for the gritty details.
I am considering the following changes to timers:
- A repeat timer will stop if it returns false. This is just a convenience which does the same as calling removeTimer() but shorter.
- If a timer is set (or "queued"), and a timer with the same name and arguments is already set, it will either replace it, if time to first invocation is shorter, or be dropped. The reason for this is that it is very easy to call timers too frequently without knowing it, causing lots of unnecessary CPU use, and checking each time is cumbersome. I discovered this when investigating CPU spikes in Semperfi-JS recently.
-
aubergine
- Professional

- Posts: 3462
- Joined: 10 Oct 2010, 00:58
Re: Javascript API documentation
Urg, how do we monitor enemy objects or features to detect when they are destroyed? I was looking to use this to have my attack groups switch to their next target when current target goes kaboom. I think ShadowWolf TJC was also planning to do similar.Per wrote:The bind() function, which always said "This function is under construction and is subject to total change!", has been removed. It was true to its documentation in that respect, at least.
Wooohooo!!!Per wrote:setTimer() and queue() can now take a string argument as their third argument, which will be passed on to the called function.
+1 to both of those ideas, they will make life much easier. I assume on the first item, about returning false, the timer will only be cancelled if the function returns an actual Boolean false, not a falsey value (eg. undefined and null are both falsey values).Per wrote: I am considering the following changes to timers:Feedback desired.
- A repeat timer will stop if it returns false. This is just a convenience which does the same as calling removeTimer() but shorter.
- If a timer is set (or "queued"), and a timer with the same name and arguments is already set, it will either replace it, if time to first invocation is shorter, or be dropped. The reason for this is that it is very easy to call timers too frequently without knowing it, causing lots of unnecessary CPU use, and checking each time is cumbersome. I discovered this when investigating CPU spikes in Semperfi-JS recently.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
-
Per
- Warzone 2100 Team Member

- Posts: 3780
- Joined: 03 Aug 2006, 19:39
Re: Javascript API documentation
1) I'm looking at removing the throttling on object death events. I will look a bit at load balancing events first, to ensure I'm not creating a monster. eventDestroyed() is not throttled. It can be used to monitor object destruction.aubergine wrote:Urg, how do we monitor enemy objects or features to detect when they are destroyed? I was looking to use this to have my attack groups switch to their next target when current target goes kaboom.
2) You can drop the objects to be monitored into a group. When the group loses members, you will get a group loss notification. I think this is usually what you want to do.
3) You can add a label to the object and poll it.
Yep.aubergine wrote:+1 to both of those ideas, they will make life much easier. I assume on the first item, about returning false, the timer will only be cancelled if the function returns an actual Boolean false, not a falsey value (eg. undefined and null are both falsey values).