Campaign port to javascript

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

Campaign port to javascript

Post by Per »

As someone who reads the commit messages may have noticed, I just pushed the first working translation of wzscript code to javascript in the campaign. This means the cam1a level now runs mostly on javascript code, rather than wzscript code. The "opposition AI" still uses wzscript (see file cam1a-ai.slo), but from what I can tell, there is nothing technically difficult in that code, so the hurdles for porting should be mostly solved now.

I will post a detailed walk-through of the ported script to show you how it was done tomorrow, then I think we can discuss the API and general approach a bit before proceeding further. Then I will ask for help in porting the campaign, level by level. It is going to be a fair amount of work, and I will need help doing it. I will also open up discussion threads in the general forum for each level as they are ported, to request feedback for desired improvements to that level.

So please let me know if you wish to aid in this effort, and in what way you want to help.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Campaign port to javascript

Post by aubergine »

I was looking at the labels.ini and one thing I noticed was that the x, y, z2, y2 values aren't in tile co-ordinates, they seem to be in pixel co-ordinates?

Anyway, I'm keen to help - conversion to JS, documentation, etc.

I'd also be very interested to know if there are plans to make campaigns moddable - eg. so we can add whole new campaigns or update existing campaigns.

EDIT: Also, which scripting environment does the script run in? I notice from code comments it's separate to rules.js. Is it like the "extra" script you get in challenge games (so tied to player 0)?
"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: Campaign port to javascript

Post by Per »

Labels use world coordinates, which you get by multiplying map coordinates by 128.

Making it easier to add custom campaigns is high up on my TODO list.

The campaign scripts run as player zero, with each script in its own context.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base
Contact:

Re: Campaign port to javascript

Post by Goth Zagog-Thou »

This will make me extremely happy. Currently I need hacky ways to get things like Cam 4 working (hacky to the point where I won't release milestone builds!), and I'm uncomfortable with that method.

Thanks Per.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Campaign port to javascript

Post by aubergine »

Would it be possible to find out what hackAddMessage() and hackRemoveMessage() are actually doing and get that brought fully in to the JS API? From what I can see it's a mix of beacons and videos, so maybe all we need is a playVideo() function (as we already have beacon stuff)?
"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: Campaign port to javascript

Post by aubergine »

Code: Select all

setMissionTime(36000);
Am I correct in thinking that sets the mission time at 36 seconds? Or is the parameter in seconds (not milliseconds) in which case it's 10 minutes? As all other JS API functions that use times are done in milliseconds, would it be worth making this function use milliseconds as well so everything is consistent?
"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: Campaign port to javascript

Post by Per »

setMissionTime() sets time to 1/10 of a second, so 36000 = 10 * 60 * 60 = 1 hour.

Unless nobody objects, I will change it to seconds, since 1/10 of a second precision for this timer makes very little sense... I assume nobody is using this for any current mods right now, so the API change should not be noticed.
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: Campaign port to javascript

Post by Shadow Wolf TJC »

I don't know if this would count as an objection to the change or not, but if there's a getMissionTime() function, then perhaps we could have it return values as precise as 1/10th of a second, since that seems to be the limit on when everything in the game seems to get updated, including setTimer() calls?
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Campaign port to javascript

Post by NoQ »

+1 for switching to seconds.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Campaign port to javascript

Post by aubergine »

I'd prefer milliseconds so 100% of stuff in game is done in milliseconds, but seconds is also fine with me. Anything so long as it's not the weird 1/10th seconds heh.
"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: Campaign port to javascript

Post by Per »

It has been switched to seconds, and I also added a missionTime() function to return remaining time to mission end, in seconds. It will return some negative number if no mission timer is active.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Campaign port to javascript

Post by aubergine »

If no mission timer active, would it make more sense to return null or undefined?
"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: Campaign port to javascript

Post by aubergine »

Also, in keeping with conventions used elsewhere in JS API, could missionTime() be renamed to getMissionTime(), otherwise the function name is ambiguous (eg. it sounds like it could be used to set the mission time).
"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: Campaign port to javascript

Post by aubergine »

Sorry for multiple posts on same subject (is editing post preferred?)...

Here's how I'd like the function to work:

Code: Select all

var timeRemaining = getMissionTime(); // returns null if no timer, or num seconds remaining if timer active (could be 0 seconds left)

if (timeRemaining) {
  // do stuff, as we have > 0 seconds left
}
"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: Campaign port to javascript

Post by Per »

aubergine wrote:Also, in keeping with conventions used elsewhere in JS API, could missionTime() be renamed to getMissionTime(), otherwise the function name is ambiguous (eg. it sounds like it could be used to set the mission time).
Ok, done.
Post Reply