Java AI how to find units queued by a factory

Java AI how to find units queued by a factory

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
Bla
Posts: 79
Joined: 25 Feb 2013, 14:44

Java AI how to find units queued by a factory

Post by Bla »

I know fac.getCurrentCommands().size() returns the number of units queued by the factory, but is there a way to get the UnitDefs of the units queued?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Java AI how to find units queued by a factory

Post by gajop »

You'll need to figure out the details yourself, but I suggest you check the command type, one of these should do it:

Code: Select all

cmd.getCommandId()
cmd.getId()
cmd.getType()
And when you know it's a build command, you should look for the unitdef id in one of these fields

Code: Select all

cmd.getOptions()
cmd.getParams()
PS: If it wasn't obvious, you get the cmd (Command) object by iterating through each item in the getCurrentCommands
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Java AI how to find units queued by a factory

Post by playerO1 »

You want get UnitDef list for what unit can build?
I using

Code: Select all

List<UnitDef> lst = unit.getDef().getBuildOptions();
for (UnitDef def:lst) {do some code};
But I found 1 bug: if one of def enabled only by upgrade (in TA by laboratory) then this UnitDef will be exist in this list. But how know that it enabled or disabled I don't know :?
If you mead about morph command then in this forum. People say that morph cmdID=31000 and for get unitDefID need cmdID-31000. I check it for TA is not true :( I try wrote it by hardcoded array, but it bad.
So who know how get unitDef for morphing (upgrade) command and get other param for morph (time, coast) ?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Java AI how to find units queued by a factory

Post by knorke »

TA=Tech Annihilation?
playerO1 wrote:If you mead about morph command then in this forum. People say that morph cmdID=31000 and for get unitDefID need cmdID-31000. I check it for TA is not true :( I try wrote it by hardcoded array, but it bad.
So who know how get unitDef for morphing (upgrade) command and get other param for morph (time, coast) ?
Morph-command is extra functionality created by modder via scripting, so (unlike move, fight, repair, .. = commands that come from engine) its commandID can be whatever number the modder chooses to use. Same for other custom-commands.
Some games keep a list of all cmdID in a config file like this:
http://code.google.com/p/zero-k/source/ ... cmds.h.lua
Tech Annihilation has no such file, instead cmdIDs are defined in the gadget-scripts that use them.
For example:
tech_annihilation-v2.27.3_6.sdz\luarules\gadgets\unit_morph.lua

Code: Select all

local CMD_MORPH_STOP = 32410
local CMD_MORPH = 31410
See the documentation on top of that file, it explains some things.

For morph time, cost, requirements etc see tech_annihilation-v2.27.3_6.sdz\luarules\configs\morph_defs.lua

Reading these things with Java AI might not be possible so maybe some hard-coded values can not be avoided.
(Depending on how the gadget is written, Lua AIs would have the same problem)
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Java AI how to find units queued by a factory

Post by Jools »

Slightly related: aren't most AI:s still done by defining buildlists and weights depending on map and size, like in how the mostly harmless AI was done in TA. Since it's a very good and non-cheating AI, has anyone considered benchmarking it for spring?
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Java AI how to find units queued by a factory

Post by Anarchid »

Reading these things with Java AI might not be possible so maybe some hard-coded values can not be avoided
Java AIs have access to the following:
- UnitRulesParams (only float values since interface was not updated when string values were introduced in 95.0)
- Unit CustomParams
- Lua Message Events

Java AIs can also use the following:
- Downloading your mod's config file from Github

Java AIs do not (i think) have access to the following:
- _G, GG and other internals of Lua states (but they can inject stuff into Lua in some ways that i don't understand). This is where morph defs live.
- GameRulesParams and TeamRulesParams (not supported by interface in any way)

Long story short, minimal cooperation from game developer (sending morph defs as skirmish AI message; putting it into unitrulesparams or customparams) should fix the issue.
Post Reply

Return to “AI”