Tech level and limiter scripts to JS

For AI and campaign script related discussions and questions
Post Reply
User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 937
Joined: 26 Sep 2016, 19:56

Tech level and limiter scripts to JS

Post by Berserk Cyborg »

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.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Post by Per »

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?
User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 937
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Post by Berserk Cyborg »

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: 937
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Post by Berserk Cyborg »

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

Edit: Now in d31f6a2c704ada8f46957a34279af78deafdeec7.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Post by Per »

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: 3780
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Post by Per »

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.
User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 937
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Post by Berserk Cyborg »

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: 937
Joined: 26 Sep 2016, 19:56

Re: Tech level and limiter scripts to JS

Post by Berserk Cyborg »

The limiting does not play nice with campaign transitions (Alpha to Beta). I thought structures were destroyed upon transition?
Alpha end.zip
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Tech level and limiter scripts to JS

Post by Per »

Berserk Cyborg wrote:The limiting does not play nice with campaign transitions (Alpha to Beta). I thought structures were destroyed upon transition?
Alpha end.zip
Ooops. Fixed in 9c272aa528bab38fb8d598a7f2676745ca347a4b. Structures are destroyed, but not the structure definitions - where the limits are stored now. Added a reset.
Post Reply