Determine if unit will make metal from UnitDef
Moderators: hoijui, Moderators
Determine if unit will make metal from UnitDef
I am working on an AI side project using the Java interface. Nothing too serious yet. I am trying to do as much work as possible using the UnitDefs instead of hard coding. I know I will meet a limit on this, but I wanted to check about units that make metal. For the life of me, I cannot find a method in the UnitDef that will return this. When I go look at the units for BA, I also cannot find an obvious spot in there other than the description: "Converts...".
Is it possible to determine if a unit makes metal? I have checked getExtractsResource, getMakesResource, getResourceMake, and getUpkeep and find all 0 for the Metal resource.
Am I missing something?
Thanks!
Is it possible to determine if a unit makes metal? I have checked getExtractsResource, getMakesResource, getResourceMake, and getUpkeep and find all 0 for the Metal resource.
Am I missing something?
Thanks!
Re: Determine if unit will make metal from UnitDef
In the Lua Enviroment you have the UnitDef Table, which contains all the infos about a unit
there is also UnitDefNames, which is indexed by the Units name (instead of the defid).
you should find what you search there..
Example Usage Hitpoints of a Unit
there is also UnitDefNames, which is indexed by the Units name (instead of the defid).
you should find what you search there..
Example Usage Hitpoints of a Unit
Code: Select all
hp=UnitDefNames["cormex"].maxdamage
Re: Determine if unit will make metal from UnitDef
I never got to resources with Java-AI but seems getResourceMake should be correct.
Do you pass it valid resourceID?
Maybe this is helpful? (from abma's AI)
https://github.com/abma/AGAI/blob/maste ... .java#L168
https://github.com/abma/AGAI/blob/maste ... e.java#L58
Another thing is that some mods do not even use the engine-side-resource tags anymore and instead do that via Lua. So the unitDef might produce 0 metal, but the mod then does its own scripting which would be "unreadable" by AI.
For example in BA there is file LuaRules\Gadgets\energy_conversion.lua (or similiar name), not sure how much that replaces the metalmakers with its own logic. So maybe see the unit-files in the mod if they really have metalMake and similiar tags. ( http://springrts.com/wiki/Gamedev:UnitDefs#Resources )
Do you pass it valid resourceID?
Maybe this is helpful? (from abma's AI)
https://github.com/abma/AGAI/blob/maste ... .java#L168
https://github.com/abma/AGAI/blob/maste ... e.java#L58
Another thing is that some mods do not even use the engine-side-resource tags anymore and instead do that via Lua. So the unitDef might produce 0 metal, but the mod then does its own scripting which would be "unreadable" by AI.
For example in BA there is file LuaRules\Gadgets\energy_conversion.lua (or similiar name), not sure how much that replaces the metalmakers with its own logic. So maybe see the unit-files in the mod if they really have metalMake and similiar tags. ( http://springrts.com/wiki/Gamedev:UnitDefs#Resources )
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Determine if unit will make metal from UnitDef
@byronwall: To make things clear, the point is here that the amount of metal a unit makes/uses in a given gameframe can be controlled via lua, so it can depend on ingame factors and can vary. The (constant) values inside the unitdef are just one of the inputs into how much resources a unit actually makes/uses. The lua API gives access to the net values on the current gameframe with Spring.GetUnitResources; maybe there is an equivalent function for AIs.
Re: Determine if unit will make metal from UnitDef
This, however, would only work on already instantiated units. It would be of no use for the AI to determine if it's worth building the unit in the first place.The lua API gives access to the net values on the current gameframe with Spring.GetUnitResources; maybe there is an equivalent function for AIs.
The FieldBOT AI is supposedly capable of playing a rather different set of TA-like games on no-metal maps, so it must be able to discover metal makers prior to building them. The method for picking the best resource-producing unit is probably of most interest. Note that you might have to use google translate on the russian comments.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Determine if unit will make metal from UnitDef
It looks as though that method hardcodes information about the game. I suspect that this is the only viable option when trying to determine which eco-producing units are worth building.
edit: BA entirely reimplements metal making logic here http://imolarpg.dyndns.org/trac/balates ... ersion.lua, which is the reason you can't find it in those particular unitdefs. I guess other games do similar stuff too.
edit: BA entirely reimplements metal making logic here http://imolarpg.dyndns.org/trac/balates ... ersion.lua, which is the reason you can't find it in those particular unitdefs. I guess other games do similar stuff too.
Last edited by Silentwings on 12 Nov 2014, 20:35, edited 1 time in total.
Re: Determine if unit will make metal from UnitDef
Could try training it.Silentwings wrote:It looks as though that method hardcodes information about the game. I suspect that this is the only viable option when trying to determine which eco-producing units are worth building.
Re: Determine if unit will make metal from UnitDef
You should know that there are many ways a unit can "make metal": it can be a metal extractor, it can convert metal from energy, it can be an abandoned building under construction of it can be a builder reclaiming a wreck. Also every unit makes a little bit of metal just by being alive.
Re: Determine if unit will make metal from UnitDef
Thanks for all the responses. I will dig into the BA files to see what I can find. I was hoping to be able to assess the unit capabilities as much from the API as possible. It was working fine for all the other units I was trying on the resource front.
@knorke: I believe I was using the correct resource. I was iterating through (callback).getResources. It worked fine for the extractors and solar collectors all the others.
@Anarchid: I will look into that AI and see how much was hard coded there. Thanks for the link.
If it is necessary to hard code some game info into a config file or somewhere else for my AI to work, that's fine. Better to have it working.
Since I am just at the start here, would it be better to build this in lua instead of Java? Or will I face the same issues with information being set in game files outside of API calls?
@knorke: I believe I was using the correct resource. I was iterating through (callback).getResources. It worked fine for the extractors and solar collectors all the others.
@Anarchid: I will look into that AI and see how much was hard coded there. Thanks for the link.
If it is necessary to hard code some game info into a config file or somewhere else for my AI to work, that's fine. Better to have it working.
Since I am just at the start here, would it be better to build this in lua instead of Java? Or will I face the same issues with information being set in game files outside of API calls?
Re: Determine if unit will make metal from UnitDef
I have this problem too. I make special module (class) for detect some mod specification and translate some unique information to my bot.
I know that:
Some of mod developers contain info in "CustomParams" (it renamed on last SPring version, don't know new name), but until Spring 98 acess to this from java is breaking.
I know that:
- Balanced Anihilation (BA) and NOTA metal maker use LUA for make resources. Ower 70-80% of energy store resource convert to metal.
- Tech Anihilation (TA) metal maker use LUA too, but convert level can control by player ingame (widget), and same metal maker have different convertion effective.
- Evolution RTS use native metal maker - can get info from UnitDef.getMakesResource(Resource)
- Zero-K use LUA metal extractor - extractor extract and make metall by special math formul.
Some of mod developers contain info in "CustomParams" (it renamed on last SPring version, don't know new name), but until Spring 98 acess to this from java is breaking.
Last edited by playerO1 on 13 Nov 2014, 19:01, edited 1 time in total.
Re: Determine if unit will make metal from UnitDef
Instead of guessing it's better to ask each games developer how metal makers work. In principle the unitdef tags listed above control the resource production, but they can beSilentwings wrote: edit:BA entirely reimplements metal making logic here http://imolarpg.dyndns.org/trac/balates ... ersion.lua, which is the reason you can't find it in those particular unitdefs. I guess other games do similar stuff too.
We have made such a marvelous gadget that we guess everybody else must be using it.
Re: Determine if unit will make metal from UnitDef
Lua AI cannot be developed separately from the game they are run in, they are essentially part of the game rules; glorified gadgets in form and function. This means you will be tied to the game's developement process and its release cycle, and your AI will be distributed with the game archive.Since I am just at the start here, would it be better to build this in lua instead of Java? Or will I face the same issues with information being set in game files outside of API calls?
Lua AI's are implicitly cheating and sometimes it's a lot of work to make them not use unfair information.
Lua AI's do have a broader access to gadgetized game rules, but there is no guarantee (not all gadgets share information even to other gadgets).
There are probably less libraries available for the higher-end tasks for Lua than for Java, and you cannot add native bindings to a Lua AI.
Game rules specific data can be exposed to native (including Java) AI's using (Game,Unit,Team)RulesParams and CustomParams.
Native AIs can send "messages" to game rules via SendSkirmishAIMessage, but this is not implemented for the java interface, which in turn means it's available for C/C++ API only.
Re: Determine if unit will make metal from UnitDef
Depends whether you want a research project or something that can actually play all aspects of the game at hand.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Determine if unit will make metal from UnitDef
Actually it was written long ago by someone I never met. But...Jools wrote:We have made such a marvelous gadget that we guess everybody else must be using it.Silentwings wrote:blahblahblah
https://code.google.com/p/xta-springrts ... sion.lua#5 *coughcoughcough* It seems XTA, amongst others, does use an energy conversion gadget that is a modifed version the (old) BA gadget. Nonetheless, this is all just off-topic.
In Lua you will have an easier time with finding API calls; the Lua API is better documented and (as I understand it, no offence meant if I'm wrong ) has been maintained more actively in recent years. But as Anarchid pointed out there are other differences too.Since I am just at the start here, would it be better to build this in lua instead of Java? Or will I face the same issues with information being set in game files outside of API calls?
If you are interested in AI in its own right, and you have a decent amount of time, then I guess the C/C++/java AI wrappers would suit you best. If you are interested primarily in Spring games and are just making an AI for fun, then I think you'd find Lua AIs quicker and easier.
The energy->metal conversion gadget is http://imolarpg.dyndns.org/trac/balates ... ersion.lua. It contains the conversion ratios & capacties as a hardcoded list. If you would like that list to be exposed to Lua in general (and therefore accessible to a Lua AI) then just let me know.I will dig into the BA files to see what I can find.
That gadget controls all energy->metal conversion; it feeds newly converted metal straight into the teams resources (so there are no real time per-unit conversion stats, sorry!). There is also a widget http://imolarpg.dyndns.org/trac/balates ... ersion.lua that players can use to tell the gadget what level of conversion they want.
Metal extractors work in the "normal" way, using just the values from their unitdefs, and the same for all energy production.
Re: Determine if unit will make metal from UnitDef
Except it's not off-topic, because the xta one does not alter team resources via lua, it only turns on/off metal makers, so in xta you can use unitdef-tags. (That whole crap should be a widget anyway. Yes, this part is off-topic.)Silentwings wrote: It seems XTA, amongst others, does use an energy conversion gadget that is a modifed version the (old) BA gadget. Nonetheless, this is all just off-topic
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Determine if unit will make metal from UnitDef
@Jools:
The OP did just that; he asked about BA, to which I (as a BA developer) replied, moreover making it clear what part of my reply was BA specific and indicating as best I knew how to cope with games general. I personally have no interest or time to provide info on specifics of projects I don't work on (especially when it was not asked for) & imho in general often your replies to what appears to me as constructive discussion - in this and very many other threads - come across as intentionally offensive or simply derailments. I don't mean to cause any offence to you, but enough is enough and I will likely not read or reply to your posts in future.Jools wrote:Instead of guessing it's better to ask each games developer how metal makers work.Silentwings wrote: edit:BA entirely reimplements metal making logic here http://imolarpg.dyndns.org/trac/balates ... ersion.lua, which is the reason you can't find it in those particular unitdefs. I guess other games do similar stuff too.
We have made such a marvelous gadget that we guess everybody else must be using it.
Re: Determine if unit will make metal from UnitDef
I was just correcting incorrect or vague information, which in my opinion also came across as quite arrogant, hence the offensive response. Of course I would not react like this if this was the first time you write like this.Silentwings wrote:I guess other games do similar stuff too.
I don't have any problems with any other part of your response.
Re: Determine if unit will make metal from UnitDef
May i suggest GameRulesParams instead? Since 98.0, native AI's can read them, so it puts both gadget and native bots on equal footing at the same time-cost.If you would like that list to be exposed to Lua in general (and therefore accessible to a Lua AI) then just let me know.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Determine if unit will make metal from UnitDef
Aha, I guess this means that non-lua AIs cannot read GG? (I have never written one). So, yesGameRulesParams instead?
Re: Determine if unit will make metal from UnitDef
Yes, native AIs have no direct access to the Lua states.non-lua AIs cannot read GG
Communication is possible with SendSkirmishAIMessage / RecvSkirmishAIMessage, but for one-way
communication on modern engines, G/T/URP is the way.
(bonus point is that it also allows this data for widgets)