How to determine game structure limits?

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:

How to determine game structure limits?

Post by aubergine »

If the user disables any of the factories, how do I determine that in my script? Specifically, before I even try and build anything?

Knowing from the outset what sort of factories are available will obviously have an impact on research paths, build orders, and so on.

Tank Factory

This is what I have planned so far:

Code: Select all

var tanksDisabled = (!isStructureAvailable("A0LightFactory", me)) && (!enumStruct(me, FACTORY).length);
So, if there are no tank factories on the map, and tank factory isn't available to me, I know tank factories are disabled.

But, if the game us using baseType of CAMP_BASE or CAMP_WALLS, there might be pre-placed factories on the map meaning my AI will assume it can make tanks for the rest of the game -- when the factories are destroyed, they can't be rebuilt by the AI due to structure limits.

Cyborg Factory

Because I have to research Cyborg Factory before I can build one, it's not available at the very start of the game. So I can't see any way to determine from the outset if my AI will be able to build cyborgs.

VTOL Factory

Same issue as cyborg factory. I have no way of knowing at the start of the game if VTOLs are disabled. In addition, I'd also need to know if VTOL rearm pads are disabled (effectively making VTOLs pointless because I'd have to recycle then build new ones in order to "rearm" = too much pain).

Solution?

A getStructureLimits() function that returns an object with named keys (structure ids) and corresponding numeric values (limit set for that structure for this game) would completely solve the problem.

I could then do this during eventGameInit() or eventStartLevel():

Code: Select all

var structLimits = getStructureLimits();
var tanksEnabled    = structLimits["A0LightFactory"];
var cyborgsEnabled = structLimits["A0CyborgFactory"];
var vtolsEnabled     = structLimits["A0VTolFactory1"] && structLimits["A0VtolPad"];
I know it's a big ask, but would it be possible to add this for the 3.1 branch prior to final release? getDroidLimit() was added in 3.1 RC2... ;)
"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: How to determine game structure limits?

Post by Per »

Added to 3.1 branch: getStructureLimit(structure type[, player]) and getStructureCount(structure type[, player]). The latter is much faster than getting an enum of structures, and counting, since these numbers have already been crunched.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: How to determine game structure limits?

Post by aubergine »

Yay! That will make build orders much better :) Thanks Per!
"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: How to determine game structure limits?

Post by aubergine »

Would it be possible to change getStructureCount(structure type[, player]) to countStruct(player, structure type) ? That way it's less typing and easier to interchange with enumStruct(player, structure type). Allow ALL_PLAYERS, ALLIES, ENEMIES as valid options for 'player' param?

Also, any chance of something similar to count droids? countDroid(player[, droid type]) Main reason: rules.js currently has to enumDroid() for all players every few seconds to check if players are alive -- it only needs counts, not the verbose information for all droids.
"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: How to determine game structure limits?

Post by Per »

Renamed to countStruct(structure type[, player]) and added countDroid([player]). I wanted the optional parameter, and the game internals do not keep track of droid counts by type. It does count the number of construction-capable droids, though, so I guess I could expose that info through a countBuilders() or something, if desired.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: How to determine game structure limits?

Post by aubergine »

Yup, countBuilders() would be useful, AIs regularly need to determine number of trucks when deciding what to produce next at a tank/cyborg factory.
"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: How to determine game structure limits?

Post by aubergine »

Would it be possible to put player param first? That way if things change in future the params will be more consistent & also more like the enum*() param order.
"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: How to determine game structure limits?

Post by Per »

If player param is first, it can't be optional... I dislike having to put 'me' into function calls. (And yes, I somewhat dislike enum*() for that reason.)
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: How to determine game structure limits?

Post by aubergine »

Rather than defining a countBuilders() function, would it be worth just adapting the countDroids() function:

countDroids(droid type[, player])

Where droid type can be: DROID_ANY (counts all droids for player) or DROID_CONSTRUCT (only counts builders). Any other DROID_* constant would throw an error, and docs can state clearly that only DROID_ANY and DROID_CONSTRUCT can be used currently.
"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: How to determine game structure limits?

Post by Per »

Good idea. Implemented in def9fb81c34a7c6d3c343c659507ed1b6f40f5ee.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: How to determine game structure limits?

Post by aubergine »

Did you expose DROID_ANY to the JS env? I couldn't see it listed in qtscriptfuncs.cpp.
"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: How to determine game structure limits?

Post by Per »

aubergine wrote:Did you expose DROID_ANY to the JS env? I couldn't see it listed in qtscriptfuncs.cpp.
Oops. I thought it already was. Fixed in b782d21b5ed1d9b293e59317b99e09ac0786aa09.
Post Reply