Page 1 of 1

How to determine game structure limits?

Posted: 23 Oct 2012, 05:45
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... ;)

Re: How to determine game structure limits?

Posted: 27 Oct 2012, 23:13
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.

Re: How to determine game structure limits?

Posted: 27 Oct 2012, 23:48
by aubergine
Yay! That will make build orders much better :) Thanks Per!

Re: How to determine game structure limits?

Posted: 03 Nov 2012, 07:31
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.

Re: How to determine game structure limits?

Posted: 03 Nov 2012, 12:00
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.

Re: How to determine game structure limits?

Posted: 03 Nov 2012, 14:47
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.

Re: How to determine game structure limits?

Posted: 03 Nov 2012, 14:50
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.

Re: How to determine game structure limits?

Posted: 03 Nov 2012, 15:17
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.)

Re: How to determine game structure limits?

Posted: 04 Nov 2012, 01:12
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.

Re: How to determine game structure limits?

Posted: 05 Nov 2012, 00:27
by Per
Good idea. Implemented in def9fb81c34a7c6d3c343c659507ed1b6f40f5ee.

Re: How to determine game structure limits?

Posted: 05 Nov 2012, 02:36
by aubergine
Did you expose DROID_ANY to the JS env? I couldn't see it listed in qtscriptfuncs.cpp.

Re: How to determine game structure limits?

Posted: 05 Nov 2012, 19:32
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.