Java AI how to find units queued by a factory
Moderators: hoijui, Moderators
Java AI how to find units queued by a factory
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?
Re: Java AI how to find units queued by a factory
You'll need to figure out the details yourself, but I suggest you check the command type, one of these should do it:
And when you know it's a build command, you should look for the unitdef id in one of these fields
PS: If it wasn't obvious, you get the cmd (Command) object by iterating through each item in the getCurrentCommands
Code: Select all
cmd.getCommandId()
cmd.getId()
cmd.getType()
Code: Select all
cmd.getOptions()
cmd.getParams()
Re: Java AI how to find units queued by a factory
You want get UnitDef list for what unit can build?
I using
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) ?
I using
Code: Select all
List<UnitDef> lst = unit.getDef().getBuildOptions();
for (UnitDef def:lst) {do some code};

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

So who know how get unitDef for morphing (upgrade) command and get other param for morph (time, coast) ?
Re: Java AI how to find units queued by a factory
TA=Tech Annihilation?
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.luaSee 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)
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.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 trueI 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) ?
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
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)
Re: Java AI how to find units queued by a factory
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?
Re: Java AI how to find units queued by a factory
Java AIs have access to the following:Reading these things with Java AI might not be possible so maybe some hard-coded values can not be avoided
- 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.