Zero-K Menu Unit Selector
Moderators: hoijui, Moderators
Zero-K Menu Unit Selector
Hi,
Main Question:
How do you use the new C++ wrapper to select a Unit(or option from a menu) in Zero-K or any other game that incorporates unit selection at the start of the game? I can use the cheat interface and simply give my AI a new commander, but I feel this is rather sloppy. It seems like there should be some way to send a command to the UI indicating a menu selection in some fashion... no?
So Far:
I am working on developing a C++ AI using the new C++ wrapper. I have successfully created a Visual Studio 2008 dll project which outputs compatible dll's, compiled test versions of my AI, and begun work on state-full finite state machines for my virtual players and character agents.
Currently I am working with the Zero-K game on the Aphophis_2 map. I have been unsuccessful at getting any other map or game to download.
I have also been unable to find any worth-while C++ documentation on the new C++ wrapper. If you have any suggestions on where to look, please enlighten me.
Thank You,
Scott
Main Question:
How do you use the new C++ wrapper to select a Unit(or option from a menu) in Zero-K or any other game that incorporates unit selection at the start of the game? I can use the cheat interface and simply give my AI a new commander, but I feel this is rather sloppy. It seems like there should be some way to send a command to the UI indicating a menu selection in some fashion... no?
So Far:
I am working on developing a C++ AI using the new C++ wrapper. I have successfully created a Visual Studio 2008 dll project which outputs compatible dll's, compiled test versions of my AI, and begun work on state-full finite state machines for my virtual players and character agents.
Currently I am working with the Zero-K game on the Aphophis_2 map. I have been unsuccessful at getting any other map or game to download.
I have also been unable to find any worth-while C++ documentation on the new C++ wrapper. If you have any suggestions on where to look, please enlighten me.
Thank You,
Scott
Re: Zero-K Menu Unit Selector
Look here to find more games/maps: http://springrts.com/wiki/Games & http://springrts.com/wiki/MapsI have been unsuccessful at getting any other map or game to download.
Even if your lobby fails to autodownload content it is as simple as copying the downloaded files into the games\ or maps\ folder.
(If it does not work I suggest you make a new thread about it)
To your original question:
It would require your C++ AI to interact with the Lua gamelogic scripts of the game. I am not sure if this is possible?
You would also need it for some other things like using jumpsets or to read the energy grid.
Re: Zero-K Menu Unit Selector
If I could find a download link that didn't use klobbby or the other downloader, i would.knorke wrote: it is as simple as copying the downloaded files into the games\ or maps\ folder.
I think I know how to make Lua calls from the C++ wrapper, but I haven't tried it yet. (COMMAND_CALL_LUA_RULES)knorke wrote: To your original question:
It would require your C++ AI to interact with the Lua gamelogic scripts of the game. I am not sure if this is possible?
You would also need it for some other things like using jumpsets or to read the energy grid.
Where would you suggest I look for these lua gamelogic scripts/jumpsets and energy grid scripts? Search comes up empty on the AI forum.
Re: Zero-K Menu Unit Selector
Most games have a download link on their homepage/forum for the .sdz file.If I could find a download link that didn't use klobbby or the other downloader, i would.
ie http://springfiles.com/spring/games/xta
just copy the .sdz file into games\
For maps it is the same. http://springfiles.com/spring/spring-maps
Not sure what you mean but you can unpack a spring game and find them in LuaRules\Gadgets.Where would you suggest I look for these lua gamelogic scripts/jumpsets and energy grid scripts?
You can also ask a games dev about their Lua more detailed questions in their forum or lobby chatchannel.
ie for zeroK:
http://springrts.com/phpbb/viewforum.php?f=42
and /join zk
Afaik nobody has yet published a C++ AI that interacts with a games Lua so not sure if there is an example for that.
Re: Zero-K Menu Unit Selector
http://code.google.com/p/zero-k/source/browse/trunk -- the entire source code of the zk project resides here (including extras such as devtools, website, etc.)
If you want to check out the subversion repository then you could also have all the files locally, as well as being able to make changes to game and test them out easily. You don't need zipped/compressed files for spring to use them, just rename with .sdd extension.
As for documentation, not much I can say about that... but if you join zkdev as knorke mentioned you'll generally be able to get someone's help
Maps: have you tried playing games on various maps? the easiest way to get new maps is just to set up a game on a new map, and zklobby will automatically download it for you.
unit_jumpjets.lua
unit_mex_overdrive.lua
and probably lots more
If you want to check out the subversion repository then you could also have all the files locally, as well as being able to make changes to game and test them out easily. You don't need zipped/compressed files for spring to use them, just rename with .sdd extension.
As for documentation, not much I can say about that... but if you join zkdev as knorke mentioned you'll generally be able to get someone's help
Maps: have you tried playing games on various maps? the easiest way to get new maps is just to set up a game on a new map, and zklobby will automatically download it for you.
(mods/zk/) LuaRules/GadgetsWhere would you suggest I look for these lua gamelogic scripts/jumpsets and energy grid scripts?
unit_jumpjets.lua
unit_mex_overdrive.lua
and probably lots more
Re: Zero-K Menu Unit Selector
The C++ AI Interface (as any of the other native AI Interfaces) only provides this single means of communication with Lua, which you mentioned. It only allows to communicate with gadgets (synced), not widgets (unsynced), which means you will very very likely have to alter the game yourself, at least slightly, to be able to do stuff like what you want to do. Shard uses the new C++ AI Interface, but i do not know if it makes use of communication with a games internal Lua (my guess would be no).
One thing you have to consider: when you use this stuff, your AI will be game dependent. If it will be ZK tailored, you may also consider writing a Lua AI from the start. I also recommend using the Java AI Interface, as it is more widely used, more tested, slightly better documented and because it allows for faster development and better error handling (or say, it supports non-crap languages
). Performance is not a problem. Most of the Java AI doc and the tutorial should basically be applicable to the C++ AI Interface as well, though.
One thing you have to consider: when you use this stuff, your AI will be game dependent. If it will be ZK tailored, you may also consider writing a Lua AI from the start. I also recommend using the Java AI Interface, as it is more widely used, more tested, slightly better documented and because it allows for faster development and better error handling (or say, it supports non-crap languages

Re: Zero-K Menu Unit Selector
Yes! Lua <-> C++ AI communication is possible
How does it work?
This API is not in active use by the majority of games and AIs, for various reasons.
But, you can see it being called in Shard. I've implemented a wrapper around it to expose the API call to Shards lua Environment, so it can be used as a basic reference.
The lasts tests I am aware of involving oksnoop worked and successfully passed a message from AI to lua gadget land, however little involvement has happened, since most AI devs lack the knowledge to advise on what needs to happen once the AIs message has reached the gadget, and those who've reached out when I've had time are normally not experienced ( at the time ).
You will almost certainly need involvement with the content developers, or mutators, even if you abandon the C++ Wrapper API
Almost all gadgets don't support AI communication because they were written before any AI capable of sending even the most basic of messages was written. The only exception appears to be a minor experiment by kloot with KAIK and SWIW, and the various lua AIs that live purely in gadget land.
A word of caution
Learn from the past. Make sure your AI is written flexibly enough to account for changes, or be easily modified and maintained.
The old AIs such as RAI and AAI etc, are suffering as a result of fundamental assumptions that they made, which no longer quite hold true. Engine developers make sure they still compile, and sometimes put in the odd bugfix, but they aren't to be relied on to fix behavioural logic, that's not their job and they're kind enough to caretake as it is.
How does it work?
- C++ AI prepares a string message
- This message is handed to an API call
- An event fires in synced lua gadget land
- Synced Gadgets receive a call in containing the message from the AI
- Synced gadgets can then return a string message of their own
- This message is then returned as the return value of the original C++ API call
This API is not in active use by the majority of games and AIs, for various reasons.
But, you can see it being called in Shard. I've implemented a wrapper around it to expose the API call to Shards lua Environment, so it can be used as a basic reference.
The lasts tests I am aware of involving oksnoop worked and successfully passed a message from AI to lua gadget land, however little involvement has happened, since most AI devs lack the knowledge to advise on what needs to happen once the AIs message has reached the gadget, and those who've reached out when I've had time are normally not experienced ( at the time ).
You will almost certainly need involvement with the content developers, or mutators, even if you abandon the C++ Wrapper API
Almost all gadgets don't support AI communication because they were written before any AI capable of sending even the most basic of messages was written. The only exception appears to be a minor experiment by kloot with KAIK and SWIW, and the various lua AIs that live purely in gadget land.
A word of caution
Learn from the past. Make sure your AI is written flexibly enough to account for changes, or be easily modified and maintained.
The old AIs such as RAI and AAI etc, are suffering as a result of fundamental assumptions that they made, which no longer quite hold true. Engine developers make sure they still compile, and sometimes put in the odd bugfix, but they aren't to be relied on to fix behavioural logic, that's not their job and they're kind enough to caretake as it is.
Re: Zero-K Menu Unit Selector
Perfect! I couldn't figure out what I was supposed to look for the first several times at the download sites. Now when I look at it, I can't believe I didn't see it right away...knorke wrote:Most games have a download link on their homepage/forum for the .sdz file.
This implies that the Lua environment the synced gadgets are running in is separate from the environment that unsynced gadgets are running in. Otherwise it would be simple enough to communicate with either... worse case would be to write a synced gadget that communicated with unsynced code.hoijui wrote:It only allows to communicate with gadgets (synced), not widgets (unsynced)
1) I am fully aware of the deficiencies of both C++ and Java. I have decided to use C++ specifically because its 'extra' needs. I also need to be able to illustrate the use and integration of C++ and LUA.hoijui wrote:I also recommend using the Java AI Interface, as it is more widely used, more tested, slightly better documented and because it allows for faster development and better error handling (or say, it supports non-crap languages). Performance is not a problem. Most of the Java AI doc and the tutorial should basically be applicable to the C++ AI Interface as well, though.
2) I have been using the Java tutorials.
Perfect. Thank you.AF wrote:How does it work?
Unfortunate. What, specifically, are you trying to make work?AF wrote:most AI devs lack the knowledge to advise on what needs to happen once the AIs message has reached the gadget, and those who've reached out when I've had time are normally not experienced ( at the time ).
I am only interested in writing an extensible AI. For now I may not write more than a HFSM, basic virtual player controls, generic character agent controls, lua integration and pathfinding(simple & group). In the future I may extend it to include an inference engine.AF wrote:Learn from the past. Make sure your AI is written flexibly enough to account for changes, or be easily modified and maintained.
Re: Zero-K Menu Unit Selector
To be specific, the Zero-K menu will have been created on top of the engine in lua using the toolsets and code of the Zero K team. So far I and the other AI devs I've talked with as far as I can remember, have no knowledge or experience.
Those people who do, have not been approached, nor have approached AI devs outside of their own circles.
These sorts of things as such are on a case by case basis, as theyre dependant on the implementation of the gadgets providing said features. What works for the Zero K commander choice will not be the same solution as say morphing etc
The reason most AI devs cant help you beyond that point however is because at that point, your no longer in an AI environment, your in gadget land, and you should be talking to content devs, and using the same APIs as game logic. You'd also need to ask questions of the codebase of each game you want to support, as there's a lot fo logic that is not derived from the engine, but written in gadgets that sit on top, and different games can have different implementations and versions.
Also because the code on the gadget side of the divide is synced, it requires the modification of the games archive, changing its hashes, and requiring you fork the game, or include your changes in the next release.
Those people who do, have not been approached, nor have approached AI devs outside of their own circles.
These sorts of things as such are on a case by case basis, as theyre dependant on the implementation of the gadgets providing said features. What works for the Zero K commander choice will not be the same solution as say morphing etc
The reason most AI devs cant help you beyond that point however is because at that point, your no longer in an AI environment, your in gadget land, and you should be talking to content devs, and using the same APIs as game logic. You'd also need to ask questions of the codebase of each game you want to support, as there's a lot fo logic that is not derived from the engine, but written in gadgets that sit on top, and different games can have different implementations and versions.
Also because the code on the gadget side of the divide is synced, it requires the modification of the games archive, changing its hashes, and requiring you fork the game, or include your changes in the next release.
Re: Zero-K Menu Unit Selector
So its a lack of a standard interface that game developers must implement to provide AI support?AF wrote:To be specific, the Zero-K menu will have been created on top of the engine in lua using the toolsets and code of the Zero K team. So far I and the other AI devs I've talked with as far as I can remember, have no knowledge or experience.
Secondary, semi-related question:
Are the synced and unsynced Lua code interpreted in the same environment? If they are then the two can interact.
Re: Zero-K Menu Unit Selector
not sure how that would look like.So its a lack of a standard interface that game developers must implement to provide AI support?
Say a command has a population limit like starcraft, ages of empires etc.
AIs will not "know" about it and not build new supply depots/houses but instead just try to make more tanks.
Such Lua gadget might look something like this (pseudo Lua):
Code: Select all
poplimit = {}
UnitCreated (unit, teamid)
if unit == house then poplimit[teamid] = poplimit[teamid] +5
end
UnitDestroyed (unit, teamid)
if unit == house then poplimit[teamid] = poplimit[teamid] -5
end
AllowUnitCreation (unit, teamid)
if poplimit[teamid] > #getUnits(teamid) then return false end
end
So how would an Lua <-> c++ AI interface for that look like?
The AI would have to read the poplimit table or just poplimit[myTeam] or something get a message "require more overlords"
Not sure if that is possible, I guess most game devs will happily include a
MakeTableReadableToAI (poplimit)
But there is imo not "standard" way to do it...
Re: Zero-K Menu Unit Selector
An AI would send a message to the engine to be passed to the games gadgets.
The gadgets would recieve the message at which point something happens, and a response is prepared.
Whatever happens would be lua code written using the gadget APIs not the AI APIs, and how it is built would depend highly upon wha tit was trying to do and what gadgets it had to interact with. It may be that gadgets will need extra methods and support to allow these things, and for the retrieval of information.
There would also need to be some definition of how messages/commands/requests from AIs for gadgets are formed.
At the moment my opinion is that they should take the form of serialised lua tables, with the intention that eventually the AI API would be able to aid in speeding it up and reducing the overhead.
With regards to the Zero-K commander selector, your best ebt is to experiment in making a gadget output messages to the console once it recieves an AI message, and then to talk to the Zero-k developers to ask how best to interface with their code.
The gadgets would recieve the message at which point something happens, and a response is prepared.
Whatever happens would be lua code written using the gadget APIs not the AI APIs, and how it is built would depend highly upon wha tit was trying to do and what gadgets it had to interact with. It may be that gadgets will need extra methods and support to allow these things, and for the retrieval of information.
There would also need to be some definition of how messages/commands/requests from AIs for gadgets are formed.
At the moment my opinion is that they should take the form of serialised lua tables, with the intention that eventually the AI API would be able to aid in speeding it up and reducing the overhead.
With regards to the Zero-K commander selector, your best ebt is to experiment in making a gadget output messages to the console once it recieves an AI message, and then to talk to the Zero-k developers to ask how best to interface with their code.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Zero-K Menu Unit Selector
if you cba to use rapid (which is, logically, quite stupid) you can get rapid games from:
http://packages.springrts.com/builds/
http://packages.springrts.com/builds/
Re: Zero-K Menu Unit Selector
any standard API for Lua stuff would have to be in Lua. it could be standard in the sense, that multiple/all games adhere to it, but not anything enforces through the engine.
this API(s) would have to be designed so they are easy to use by AIs (i would recommend, doing all communication through functions, or tables; not mixing, for example). knorkes example would probably require a population-limit API, which may only exist of a single function (or table).
it is possible to communicate with widgets (unsynced Lua) from the AI side, but not directly. synced code can ony come wiht the map or the game itsself, which is the problem there: you have to at least add one gadget to each game you want to use your AI with, that would route stuff between your AI and widgets (if that is what you need).
this API(s) would have to be designed so they are easy to use by AIs (i would recommend, doing all communication through functions, or tables; not mixing, for example). knorkes example would probably require a population-limit API, which may only exist of a single function (or table).
it is possible to communicate with widgets (unsynced Lua) from the AI side, but not directly. synced code can ony come wiht the map or the game itsself, which is the problem there: you have to at least add one gadget to each game you want to use your AI with, that would route stuff between your AI and widgets (if that is what you need).
Re: Zero-K Menu Unit Selector
Not sure if I understand correctly, you mean an population-limit API in the engine?hoijui wrote:knorkes example would probably require a population-limit API, which may only exist of a single function (or table).
I was thinking like
Like say a game has this population limit and also a upgrade/research system. Communication with AI might look like this on game site:AF wrote:An AI would send a message to the engine to be passed to the games gadgets.
The gadgets would recieve the message at which point something happens, and a response is prepared.
Code: Select all
gadget:RecieveAIMsg (teamID, p)
--AI wants to know about population limit:
if p[1] == "getPoplimit" then
Spring.SendAIMsg (poplimit[teamID])
end
--AI wants to buy an upgrade:
if p[1] == "buyUpgrade" then
local upgradeType = p[2]
if (teamCanBuyUpgrade (upgradeType) then
buyUpgradeForTeam (teamID, upgradeType)
else
buyUpgradeForTeam ("ERROR:can not buy this upgrade, requires blabla")
end
end
end
Code: Select all
if (money > 1000) {
sendGameMsg ("buyUpgrade", "superrockets");
}
Of course AI dev and game dev would have to decide on some protocol, ie that the message to get poplimit is "getPoplimit" and that when buying upgrades the first parameter is "buyUpgrade" and the second parameter is the name of the upgrade etc.
But I think that should be possible..
So Lua would need one new callin (RecieveAIMsg) and one new function (SendAIMsg) and the AI interface would need recieveGameMsg and sendGameMsg functions.
What exactly they would take as parameters I don't know..maybe just strings would be enough? You could pack tables into strings.
So basically a way for gadgets and AI to trade (string or whatever) messages.
Re: Zero-K Menu Unit Selector
this already exists (AI able to send stuff to gadget and receive a string in return). as you said, one had to agree on the names for example, like your "getPopLimit", but this should be decided by game devs, as in.. all/many of them, not just between one game's dev(s) and an AI dev, so it would be a more useful API.
Re: Zero-K Menu Unit Selector
this already exists (AI able to send stuff to gadget and receive a string in return)




I am astounded, that is the first time I hear that is possible.
How?
What are callins/functions? (mostly interessted on Lua side, can not find it in wiki)
ideally yes..but realisticly?this should be decided by game devs, as in.. all/many of them, not just between one game's dev(s) and an AI dev, so it would be a more useful API.
I think Lua is so diverse between games and the number of game devs and AI devs is low that it would always come down to highly indiviual solutions.
Not sure if somebody will sit down and make a superuniversal API if they just want to read a few values. Yes, it is more "dirty" but if results matter..
Re: Zero-K Menu Unit Selector
AIs can send gadgets strings, and those strings could be serialised tables or lua functions in string form, to be parsed and executed
Re: Zero-K Menu Unit Selector
yes, but where can i read about it?
Only know about http://springrts.com/wiki/Lua_UnsyncedC ... LuaMessage
but thats surely not it?
Only know about http://springrts.com/wiki/Lua_UnsyncedC ... LuaMessage
but thats surely not it?
Re: Zero-K Menu Unit Selector
It is done through event handling on the Lua side. I am unsure if there is a command that Lua can call that will send a message to the AI side. Thus far I am only aware of the AI side being able to raise an event in Lua synced gadget land. Then in Lua synced gadget land you can proceed to use theknorke wrote:yes, but where can i read about it?
Only know about http://springrts.com/wiki/Lua_UnsyncedC ... LuaMessage
but thats surely not it?
Code: Select all
SendToUnsynced
http://springrts.com/wiki/LuaCallinReturn
EDIT: I found the Lua callin. (I found it in the gadget.lua There doesn't appear to be any documentation on it. You just have to make some educated guesses.)
The gadget must implement the command:
Code: Select all
gadget:AICallIn(dataStr)