Javascript API documentation

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

Re: Javascript API documentation

Post by aubergine »

Another ponder for the "WZ is the browser" concept: localStorage and sessionStorage objects.

* localStorage = stuff that will persist between games, eg. so an AI can store it's understanding of a human player
* sessionStorage = stuff that will persist for the session (game) eg. go in to the saved game file
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
dak180
Trained
Trained
Posts: 288
Joined: 01 Nov 2009, 23:58
Location: Keeper of the Mac Builds

Re: Javascript API documentation

Post by dak180 »

aubergine wrote:Also, out of interest, do you know what JS version (or ECMA-262 Edition) is used in WZ? (or what JS engine, eg. SpiderMonkey, Rhino, etc)

From my current dabbling it seems like Rhino or SpiderMonkey - eg. __proto__ exposed to JS scripts (which is awesome!)
I think what you want is http://developer.qt.nokia.com/doc/qt-4. ... cript.html.

You are on a mac right? Because the mac versions currently us the qt frameworks from version 4.7.2.
User:dak180
Keeper of the Mac Builds
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Qt currently uses the SquirrelFish engine from Webkit (made by Apple). Qt5 will use the v8 engine (made by Google), so we will probably change to that when we switch to Qt5 (one day... do not hold your breath).

As to the way game objects were implemented, this was a fundamental design decision that was made very early in the process. There are advantages and disadvantages to both methods (getters/setters vs snapshots). While you can in theory keep state more easily up to date with getters/setters, in practice this is very difficult, since the actual state underneath is more often than not merely queued up for sync and done later. You also need a lot more code to implement the same things. Snapshots keep the underlying code and concepts very simple. The snapshots are also in no way a "doubling the RAM usage" of the internal data, as the snapshot representation is far simpler. The initial cost of making a snapshot list is more expensive than making an initial list in a getter/setter approach, but access into that list is far cheaper.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Ok, one last thing. How are we supposed to use the laser satellite?
Once this is solved, i'll be satisfied enough to release a fully functionan "nullbot" version (:
User avatar
lav_coyote25
Professional
Professional
Posts: 3434
Joined: 08 Aug 2006, 23:18

Re: Javascript API documentation

Post by lav_coyote25 »

NoQ wrote:Ok, one last thing. How are we supposed to use the laser satellite?
Once this is solved, i'll be satisfied enough to release a fully functionan "nullbot" version (:
well, i read somewhere it was not all that great, damaged electronics on the ground prevented it from being used as it was meant to be used. if i had my way, 1 shot per hour or two. very expensive research and time wise, make it unappetizing to use. just going by the game play.
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:Ok, one last thing. How are we supposed to use the laser satellite?
Once this is solved, i'll be satisfied enough to release a fully functionan "nullbot" version (:
Then I better get on it! :)

New event added: eventStructureReady(structure), for now it only triggers for the lassat being fully charged. It only triggers once, so if not ready, keep a timer to check for new opportunities.

New function added: activateStructure(structure, target), for now it only fires the lassat.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Per wrote:I've added the ability to add scripts to challenges now.
Does Nexus AI get selected automatically if no AI is specified in the challenge ini file? Is it possible to use old-style slo/vlo AIs for challenges?

Also, i'm having a problem. I created the following ini file:

Code: Select all

[challenge]
Name = "Startup [Semperfi]"
Difficulty = "Medium"
Map = "Sk-Startup"
MaxPlayers = 2
Scavengers = false
Bases = 2
Power = 700
Description = "Defeat the Semperfi."

[player_1]
team = 1

[player_2]
name = "Enemy"
team = 2
difficulty = "Insane"
position = 1
ai = semperfi.js
But it says

Code: Select all

info    |03:37:42: [openLoadFile] file semperfi.js could not be opened: File not found
info    |03:37:42: [openLoadFile] Assert in Warzone: frame.cpp:166 (!"unable to open file"), last script event: '<none>'
error   |03:37:42: [loadPlayerScript] Failed to read script file "semperfi.js"
Also, even though i specified the difficulty as "Insane", it is still showing up as "Medium".
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, Nexus is default. No, there is no way to specify any other non-javascript AI.

Your problem is due to a change made after I initially announced the feature. You need to provide a path to the AI. In this case, you should write "multiplay/skirmish/semperfi.js" (iirc). This allows you to distribute AI files along with the challenge, if you wish.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Thanks, it helped (:
Hmm, but the difficulty setting still doesn't work, even in the built-in challenges.
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:Hmm, but the difficulty setting still doesn't work, even in the built-in challenges.
Right. Fixed.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Ok, so how do i make the AI react on chat messages and beacons (and also produce some)? All those "help me!!!", "bug off", etc (:

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.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Javascript API documentation

Post by aubergine »

What stattype is the Laser Satellite building?
"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 structured clone algorithm be useful for persisting variables in 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 »

aubergine wrote:What stattype is the Laser Satellite building?
DEFENSE - for no good reason, other than this is what it is in the C++ code. I could change it into some special type when passing it to javascript...
Post Reply