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 »

vexed wrote:They had a reason for all that ugliness...
What was that reason?
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

I did some prelim planing for cam 4 porting and it looks like I need at least:
setScrollParams
addStructure
setDroidKills
addMessage
startMission
removeDroid

One function that would be nice would be:
droid GetDroidFromID(ID int)
but the new map embedded names functionality looks very cool so it would mostly be to make porting easier :wink:
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Implemented setScrollParams, addStructure and loadLevel (was startMission).

What is the purpose (use for) of setDroidKills?

I will need more time to implement addMessage(), as I wish to do that properly.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base
Contact:

Re: Javascript API documentation

Post by Goth Zagog-Thou »

setDroidKills was to make the Tac Sergeant a Sergeant when the campaign starts. :D
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

I'm looking for random() ...
upd: Found it, Math.random() :oops:
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

would orderDroidStatsLoc() be more intuitive if named orderDroidBuild() ?
"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 »

What's the difference between me and selectedPlayer - won't they always be the same?
"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 »

No. me == player running the script. selectedPlayer == player currently being controlled by the human player at this client. For AI scripts, it is usually always the case that me != selectedPlayer.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Does the droidCanReach() function use pathfinding (ignoring player structures) to find out if a droid can get from A to B? If so, would it be possible to instead of just returning true/false to return an object {accessible:<boolean>, dist:<distance>} ?

Reason: I plan on doing some checks with certain droid tasks to ensure they can get to destination from where they are, but often will also be doing distBetweenTwoPoints afterwards - it would be nice if, having already done hard work in droidCanReach(), I could get more accurate distance from droidCanReach() and thus not have to call distBetweenTwoPoints().
"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:Does the droidCanReach() function use pathfinding (ignoring player structures) to find out if a droid can get from A to B?
No. It uses cached data. So it is very fast, but somewhat limited.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

Does the cache include some info on distance of the path though? Even if it's not overly accurate, it would enable me to see if the actual path from A to B is much longer than distBetweenTwoPoints and act accordingly...

BTW, thanks for your patience & help!
"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 »

No, it does not.
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 orderDroidStatsLoc() be more intuitive if named orderDroidBuild() ?
Yes. Good idea. I have made the change, but left an alias for orderDroidStatsLoc to give you time to change your scripts.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

milo christiansen wrote: setDroidKills
droid GetDroidFromID(ID int)
I have added an 'experience' property to droids, and setDroidExperience(droid, experience) to set it. Note that in wzscript, the value passed in to setDroidKills() would get multiplied by 100, but not divided by the same amount when returned with getDroidKills()... Now it is not multiplied by anything, so you may need to change the value you intended to pass in. (The value is read with floating point precision.)

droidFromId(id) also added. Pass in an ID, get a droid out. If you feel the need to use this for new code, you are doing something wrong. Avoid using, please :-)
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Suppose i store a droid in a global variable, and this droid dies. How can a script notice that?
Post Reply