Tech level and limiter scripts to JS

For AI and campaign script related discussions and questions

Tech level and limiter scripts to JS

Postby Berserk Cyborg » 06 Dec 2017, 19:18

Doing even more WZScript to Javascript conversions. So now I have the tech level enablers and the limiter screen script working. The latter of which seems to need everything globally or it don't work. There was also a bunch of non-existent research in the tech files so I went and removed the unavailable ones

It does have a silent assert when loading a save because it can not find multilim.js. So I pose an interesting question: would it be possible to skip saving and loading a certain script?

Current work.
User avatar
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 340
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Postby Per » 06 Dec 2017, 21:08

Nice work.

There is hackDoNotSave(var name) to not save a particular global variable, but no way to prevent an entire script context from being saved.

Anything you load through the WRF / resource system will get its own script context, which will be saved and require some special handling for load. This is usually a bad idea, I think. Wouldn't it be easier to just include() some of this code from rules.js?

When it comes to limits... I don't really understand why this is in scripts in the first place? Shouldn't there just be some field in structure.json that says "let the player limit this building in the limits screen", eg "limitable": true or something?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Postby Berserk Cyborg » 06 Dec 2017, 23:52

Per wrote:Anything you load through the WRF / resource system will get its own script context, which will be saved and require some special handling for load. This is usually a bad idea, I think. Wouldn't it be easier to just include() some of this code from rules.js?
Maybe even better: Now I make it so the research is granted within eventGameInit() by adding a JS function called getMultiTechLevel() and moving the research definitions into camTechEnabler.js which is included with rules.js.

Per wrote:When it comes to limits... I don't really understand why this is in scripts in the first place? Shouldn't there just be some field in structure.json that says "let the player limit this building in the limits screen", eg "limitable": true or something?
That would make the most sense. Instead, the one and only purpose of those scripts were to set the structure limits of some structure. Using setStructureLimits() on player zero. All that magic starts in startLimitScreen() in multilimit.cpp.
User avatar
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 340
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Postby Berserk Cyborg » 10 Dec 2017, 19:10

Here is the tech level conversion. I'll leave this here for a quick review to spot any potential problems.

Edit: Now in d31f6a2c704ada8f46957a34279af78deafdeec7.
User avatar
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 340
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Postby Per » 12 Dec 2017, 02:59

Berserk Cyborg wrote:
Per wrote:When it comes to limits... I don't really understand why this is in scripts in the first place? Shouldn't there just be some field in structure.json that says "let the player limit this building in the limits screen", eg "limitable": true or something?
That would make the most sense. Instead, the one and only purpose of those scripts were to set the structure limits of some structure. Using setStructureLimits() on player zero. All that magic starts in startLimitScreen() in multilimit.cpp.

Ok, see my attempt to fix this in https://github.com/perim/warzone2100/co ... fbc9794fd6

This patch simplifies the code quite a bit, and allows us to set a default limit that is different from the maximum. I'm not sure if and how limits are used in campaign / tutorial, though.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Postby Per » 12 Dec 2017, 03:01

Berserk Cyborg wrote:Here is the tech level conversion. I'll leave this here for a quick review to spot any potential problems.

Edit: Now in d31f6a2c704ada8f46957a34279af78deafdeec7.

Looks good to me.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3649
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Postby Berserk Cyborg » 12 Dec 2017, 03:37

Per wrote:Ok, see my attempt to fix this in https://github.com/perim/warzone2100/co ... fbc9794fd6

This patch simplifies the code quite a bit, and allows us to set a default limit that is different from the maximum. I'm not sure if and how limits are used in campaign / tutorial, though.

Don't need data/mp/multiplay/script/multilim.slo in Potfiles.in anymore. Other than that looks good.

Campaign's rule.js calls setStructureLimits on eventStartLevel (should be the same amounts as multiplayer). Tutorial basically sets the max limits to 1 for the standard buildings in its eventStartLevel.
User avatar
Berserk Cyborg
Code contributor
Code contributor
 
Posts: 340
Joined: 26 Sep 2016, 19:56


Return to Scripting