LuaAI information
Moderators: hoijui, Moderators
LuaAI information
I'm looking to gather as much information as I can about LuaAI.
So far the only mod I know of that lets you choose a LuaAI opponent is Spring Tanks and currently that's crashing for me. Other than that I can find very little information. I'm hoping anyone who has any info on LuaAI can post it in this thread and i'll organise it for my Spring Lua Manual and the Wiki.
Starting with the "easy" stuff?
* What files are required in addition to /LuaAI.lua
* Is it synced or unsynced, widget or gadget?
* How do you choose a LuaAI opponent in Spring and in SpringLobby / TASClient?
* Is it shipped in the engine or do games supply their own copy?
* Does documentation exist anywhere?
* Is Tobi still around and supporting it?
I'll be able to answer some of these questions myself once I locate the relevant parts of code but right now anything is welcome.
So far the only mod I know of that lets you choose a LuaAI opponent is Spring Tanks and currently that's crashing for me. Other than that I can find very little information. I'm hoping anyone who has any info on LuaAI can post it in this thread and i'll organise it for my Spring Lua Manual and the Wiki.
Starting with the "easy" stuff?
* What files are required in addition to /LuaAI.lua
* Is it synced or unsynced, widget or gadget?
* How do you choose a LuaAI opponent in Spring and in SpringLobby / TASClient?
* Is it shipped in the engine or do games supply their own copy?
* Does documentation exist anywhere?
* Is Tobi still around and supporting it?
I'll be able to answer some of these questions myself once I locate the relevant parts of code but right now anything is welcome.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: LuaAI information
S44SpliFF wrote: Starting with the "easy" stuff?
* What files are required in addition to /LuaAI.lua
* Is it synced or unsynced, widget or gadget?
* How do you choose a LuaAI opponent in Spring and in SpringLobby / TASClient?
* Is it shipped in the engine or do games supply their own copy?
* Does documentation exist anywhere?
* Is Tobi still around and supporting it?
ZK
Evolution RTS (if you can call that an "AI", I mean it is, but it's very rudimentary)
CT (iirc)
1. Dunno
2. Unsynced (Primarily, can communicate with synced tho)
3. Add Bot button
4. Included in the game
5. Wiki but dunno exactly where
6. Yes
Re: LuaAI information
Thanks. I found the wiki entry
http://springrts.com/wiki/AI:Development:Lang:Lua
I managed to duplicate C.R.A.I.G as well and have it appear in the Add Bot list as a seperate A.I. It requires:
Note that changing the name of the AI and/or the mod can break this AI. For example it uses the mods shortName to find the config file LuaRules/Configs/craig/<modname>/buildorder.lua and if the file doesn't exist the AI will crash and the game will end immediately.
http://springrts.com/wiki/AI:Development:Lang:Lua
I managed to duplicate C.R.A.I.G as well and have it appear in the Add Bot list as a seperate A.I. It requires:
Code: Select all
LuaRules/Gadgets/craig.lua
LuaRules/Gadgets/craig/
LuaRules/Configs/craig/
Re: LuaAI information
That is just a Test that does nothing but fly the flagship around and build miners to harvest. ( http://www.youtube.com/watch?v=aOtnOEOtVTM )CT (iirc)
Afaik it is currently broken by changes to the game (units got renamed)
Kernel Panic has a Lua AI too.
Gadget and I think at least the initialise part must be synced. I guess the rest must be synced too. (otherwise local player changing his team or quitting would influence the AI?)* Is it synced or unsynced, widget or gadget?
What I found a bit problematic on first try, my AI wanted to order all units, not just the ones on his team. (power greedy bastard!)
So i added
Code: Select all
local uteam = Spring.GetUnitTeam (unit)
if (myTeam[uteam]==true) then
--do stuff
else
--not my unit
Included with game. LuaAIs outside games do not seem to be possible.Is it shipped in the engine or do games supply their own copy?
http://springrts.com/wiki/AI:Development:Lang:LuaDoes documentation exist anywhere?
http://springrts.com/phpbb/viewtopic.ph ... 6&p=229532
Basically just make a gadget and use functions from
http://springrts.com/wiki/Lua_SyncedRead#GetUnits
ie Spring.GetUnitNearestEnemy to get information and then use
Spring.GiveOrderToUnit from
http://springrts.com/wiki/Lua_SyncedCtrl#Give_Order to give commands to your units. (attack, move, build etc)
Commands are here: http://springrts.com/wiki/Lua_CMDs
Moving a unit to x,y,z:
Spring.GiveOrderToUnit(unitID, CMD.MOVE , {x,y,z }, {})
Making a unit attack an enemy:
Spring.GiveOrderToUnit(unitID, CMD.ATTACK , { enemy }, {})
Making a factory build something:
Spring.GiveOrderToUnit(unitID, -UnitDefNames["name of unit to build"].id, {}, {})
Notice the minus sign.
I think if you want a mobile builder to build something, the coordinates would go in the first {}
Using custom commands
Spring.GiveOrderToUnit(unitID,31210,{UnitDefNames["bmetaltruckdepot"].id},{})
The number 31210 is the commandID of the custom command. No idea how this exactly works but it must match the number in the gadget. (in this case, 31210 was the number for morph/deploying units)
(typing this post just doubled the documentation on Lua AI)
The AI from Spring Tanks is really basic but it is just two small file so maybe good example:
LuaRules\Gadgets\tp_AIbork.lua
LuaAI.lua (in root folder)
Re: LuaAI information
yeah. LuaAI's are synced. they run on every machine, and have to create equal results everywhere. native AIs are unsynced.
Re: LuaAI information
LuaAI's can run in synced (gadget) and/or unsynced (gadget/widget) code.
Re: LuaAI information
While it is possible to make an "AI widget" (ie like some helper widgets who order units around) would you also be able to add these AIs in the lobby?
And it does not really make sense or does it?
Oh and I was wondering, is there docu on this CallAsTeam thing?
I imagine it probally works something like Spring.CallAsTeam (Spring.GetNearestEnemy())
but how would it look like for callins ie UnitDestroyed?
Or would I just have to put the callin in unsynced part to prevent the AI from accidently cheating?
And it does not really make sense or does it?
Oh and I was wondering, is there docu on this CallAsTeam thing?
I imagine it probally works something like Spring.CallAsTeam (Spring.GetNearestEnemy())
but how would it look like for callins ie UnitDestroyed?
Or would I just have to put the callin in unsynced part to prevent the AI from accidently cheating?
Last edited by knorke on 19 Mar 2011, 12:46, edited 1 time in total.
Re: LuaAI information
How would it run in a widget? That would imply it has to latch on to at least one real player to act as its host right? Are you suggesting it could load as a gadget stub and then be 'remote controlled' by a widget? I think the concept might have some merits but I suspect it would be tricky to implement.
Re: LuaAI information
Pretty sure CRAIG is indeed a mix of synced/unsynced gadget code.Kloot wrote:LuaAI's can run in synced (gadget) and/or unsynced (gadget/widget) code.
Re: LuaAI information
No, that does not make sense. Lobbies only parse LuaAI.lua so players (teams) can select Lua AI's by name. They then pass that information to the engine (through script.txt), but any AI written as a gadget still has to check which teams actually want to run it (via Spring.GetTeamLuaAI), since gadgets are _always_ loaded for all players, unlike native AI's. Widgets can obviously just be (de)activated at will.knorke wrote:While it is possible to make an "AI widget" (ie like some helper widgets who order units around) would you also be able to add these AIs in the lobby?
And it does not really make sense or does it?
http://springrts.com/wiki/Lua_System#LuaGadgets_onlyknorke wrote: Oh and I was wondering, is there docu on this CallAsTeam thing?
I imagine it probally works something like Spring.CallAsTeam (Spring.GetNearestEnemy())
but how would it look like for callins ie UnitDestroyed?
Or would I just have to put the callin in unsynced part to prevent the AI from accidently cheating?
Ordinary callouts in synced gadgets already have full access, so this is mostly useful on the unsynced side to get around per-allyteam LOS viewing restrictions. The engine itself takes care of restricting information to unsynced callins (by only executing them for in-the-know teams), so an AI can't accidentally cheat that way unless events are being forwarded with SendToUnsynced and friends.
Re: LuaAI information
Correct.FLOZi wrote:Pretty sure CRAIG is indeed a mix of synced/unsynced gadget code.Kloot wrote:LuaAI's can run in synced (gadget) and/or unsynced (gadget/widget) code.
Synced part is just a small proxy that actually gives commands to units. The unsynced part does the actual work (on a single client only) and then sends messages to the synced part (on all clients).
Re: LuaAI information
How does CRAIG choose which client to run the unsynced part on?
Re: LuaAI information
ok, thanks.
So to really prevent the AI from accidently cheating, every GiveOrder(), GetUnit() etc would have to be "wrapped" with CallAsTeam ()?
Unless there is a way to somehow use CallAsTeam on the whole gadget?
It would be nice to have an option to have Lua AIs more "capsuled", at the moment it seems the AI maker has to pay attention to not to cheat (or even worse: given orders to enemy units) on his own?
So to really prevent the AI from accidently cheating, every GiveOrder(), GetUnit() etc would have to be "wrapped" with CallAsTeam ()?
Unless there is a way to somehow use CallAsTeam on the whole gadget?
My AI is all synced at the moment. So should I divide in sync/unsync and use callins only in unsynced?The engine itself takes care of restricting information to unsynced callins (by only executing them for in-the-know teams), so an AI can't accidentally cheat that way
It would be nice to have an option to have Lua AIs more "capsuled", at the moment it seems the AI maker has to pay attention to not to cheat (or even worse: given orders to enemy units) on his own?
Re: LuaAI information
It's based on the teamleader field in the startscript.SpliFF wrote:How does CRAIG choose which client to run the unsynced part on?
https://github.com/tvo/craig/blob/maste ... k.lua#L208
Re: LuaAI information
What exactly constitutes a 'team leader'? How would this handle FFA in the event of say.. 2 real PCs/players and 3 AI teams? It kind of sounds like if the AI is not on the same team as at least one human player it bails? That can't be right though or you wouldn't be able to vs it singleplayer.
For that matter I'm also a bit unsure how the gadget deals with more than 1 AI of the same type. Presumably then you'd have 1 gadget handling several teams and you would therefore have to segregate the data (like threatmaps) according (ie, teams[teamID].value) ?
If I call gl.Text() in the unsynced part of your gadget whose screen am I writing too? Everybodies? Just the 'team leader's ?
For that matter I'm also a bit unsure how the gadget deals with more than 1 AI of the same type. Presumably then you'd have 1 gadget handling several teams and you would therefore have to segregate the data (like threatmaps) according (ie, teams[teamID].value) ?
If I call gl.Text() in the unsynced part of your gadget whose screen am I writing too? Everybodies? Just the 'team leader's ?
Re: LuaAI information
I was wondering that too and did a test by putting this into the synced part of a Lua AI:SpliFF wrote:For that matter I'm also a bit unsure how the gadget deals with more than 1 AI of the same type. Presumably then you'd have 1 gadget handling several teams and you would therefore have to segregate the data (like threatmaps) according (ie, teams[teamID].value)
Code: Select all
counter = 0
function gadget:GameFrame(frame)
if (frame % 30 ==0) then
counter=counter+1
end
if ((frame-1) % 30 ==0) then
Spring.Echo ("counter=" .. counter)
end
[f=0000001] counter=1
[f=0000031] counter=2
[f=0000061] counter=3
[f=0000091] counter=4
[f=0000121] counter=5
[f=0000151] counter=6
[f=0000181] counter=7
[f=0000211] counter=8
[f=0000241] counter=9
[f=0000271] counter=10
So to me it seems it is just a gadget that is run only once and there is only one "space" for variables. So seperating with something like teams[teamID].value is needed.
Re: LuaAI information
Technically a LuaAI is nothing more than the functionality to mark a team as `running' a LuaAI, and a way to expose a list of LuaAIs to lobbies (unitsync, LuaAI.lua).
It is then up to an otherwise normal gadget to go through all teams, read this value and optionally do whatever it wants with it. (For example running an AI
)
It is then up to an otherwise normal gadget to go through all teams, read this value and optionally do whatever it wants with it. (For example running an AI

Re: LuaAI information
Ok, what would be a good way to "capsle" AI data so that multiple Lua AIs of the same type do not influence each other?
Writing every variable as blub[teamID] instead of just blub seems not so nice.
Writing every variable as blub[teamID] instead of just blub seems not so nice.
Re: LuaAI information
Use classes, and make one instance of a kind of context-class per AI team.
Re: LuaAI information
classes in mah lua? zomg. *googlegoog*