Page 30 of 42
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 30 Jul 2013, 11:44
by AF
The call map:GetMetalSpots() will now cause the spots to be recalculated by the engine, the function already exists and otherwise returns the same value, but this line will need uncommenting:
https://github.com/Tarendai/Shard/blob/ ... i.lua#L223
It will also require a new build of shard.dll/so
note that it is currently untested, I don't have a compiler setup here
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 03:51
by PepeAmpere
yuritch wrote:Is it possible to have Shard re-calculate metal spot positions in runtime? Metal map can be changed on the fly, but Shard always sees the spots as they were on load time.
This post describes the problem a bit more.
I can provide simple (a bit silly) lua script which returns array with positions of mex spots, which is used by my Lua AI. Dont spend with that metal map update to much time, the update is needed just once before game starts (in GamePreload()).
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 04:08
by abma
AF wrote:It will also require a new build of shard.dll/so
note that it is currently untested, I don't have a compiler setup here
current development version already contains the patches:
http://springrts.com/dl/buildbot/defaul ... -g29ba410/
validation test went fine, so it should work in general...
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 10:41
by AF
PepeAmpere wrote:yuritch wrote:Is it possible to have Shard re-calculate metal spot positions in runtime? Metal map can be changed on the fly, but Shard always sees the spots as they were on load time.
This post describes the problem a bit more.
I can provide simple (a bit silly) lua script which returns array with positions of mex spots, which is used by my Lua AI. Dont spend with that metal map update to much time, the update is needed just once before game starts (in GamePreload()).
The problem is that your LuaAI is in the equivalent of an alternate universe, Shard doesn't share the same Lua instance, it has its own, nor does it use the same APIs ( though it can do both if a little work is done ), so it has no access to your data structures.
Neither is there direct access to the metalmap. Also there's nothing stopping the spots being grabbed in frame 5 and reused, there's already a spot handler object in the AI to store the data, and put code to do the caching on frame 5.
If you want Shard running inside the Gagdet/Widget/Game based LuaAI environment you will need to create a bootstrapping routine to start the AI object off, and pass it the needed events, then modify api.lua to call the spring APIs rather than the Shard APIs if they're present. You'll find 2 or 3 functions have already been imlemented in this way as an example for those interested
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 19:39
by PepeAmpere
Ok, i get it now, i was offering the script just for a case, that module for NOTA works somehow on the same level as lua AI (and hold some own data structure), and its just connected with the magic box (Shard) outside of the game doing all AI thinking via interface. From your post i get the metal data structure is outside of the game.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 21:43
by yuritch
With Shard it's the other way around. All the magic thinking is done by lua code, Shard itself is just an interface. Gadget lua AI can do all that and more, since it has full access to game state (Shard is rather limited in what it provides to lua side).
However, gadget AI requires modification of the game archive, while Shard does not.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 01 Aug 2013, 22:10
by AF
If there's something specific you'd like exposing I can look into it, some things are trivial to add, others are a bit more complicated.
Since going through and adding them all one by one is tedious, I've never gone through to add full coverage, but if you require something I can add it. Afterall it doesn't hurt to ask?
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 02 Aug 2013, 11:28
by yuritch
Things that I personally couldn't get from Shard and had to use pre-set lists for:
- unit's build range
- check if the unit is a ground unit / aircraft / ship / whatever
There's probably a few more, can't remember at this time.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 02 Aug 2013, 15:38
by PepeAmpere
Sorry i have a silly question: Is possible for that NOTA Shard module to look in UnitDefs or not?
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 02 Aug 2013, 15:47
by AF
PepeAmpere wrote:Sorry i have a silly question: Is possible for that NOTA Shard module to look in UnitDefs or not?
Different universes remember, though there is an API for communication between the two, I'm not aware of anybody who makes use of it though or examples outside of this thread ( dont ask me which page its on ).
Calling the API call in Shard with a string parameter will make the engine fire off an AI event in gadgets so that the gadget can craft a response.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 13 Aug 2013, 21:10
by yuritch
Is it possible to use two different Shard configs in one game at once? As in Bot#1 with config#1 VS Bot#2 with config#2. So the two Shards just read configs from different folders.
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 13 Aug 2013, 21:16
by AF
hmmm, you could copy the Shard AI and give it a new name or a different version, then pick the 2 versions to fight eachother. You just need to modify the folder name and the associated AIInfo.lua
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 05:20
by raaar
i'm making a shard config for TA factions and want to add interaction with human teammates through chat or widget, for example:
"AI ATTACK" - forces AI to throw ground/mixed attack force at closest biggest cluster of enemies
"AI AIR ATTACK" - forces AI to throw air attack force at closest smallest cluster of enemies
"AI RETREAT" - forces AI to retreat attack force to base
haven't been able to get communication between shard and a gadget to work
-------------- ai code
Code: Select all
function AttackHandler:GetHumanTask()
local data = game:SendToContent(game:GetTeamID())
game:SendToConsole("AI : data from gadget="..data)
end
function AttackHandler:Update()
local f = game:Frame()
(...)
if math.mod(f,60) == 8 then
self:GetHumanTask()
end
end
--------------- gadget code
Code: Select all
function gadget:AICallIn(data)
Spring.Echo("gadget : data from AI="..tostring(data))
return "AI bla"
end
during the game this outputs:
...
[f=0032048] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=`8
[f=0032108] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=`8
[f=0032168] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=`8
...
regardless of whether the gadget is enabled or not, and doesn't output anything from the gadget side.
Are you sure that part of the api is working?
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 14:49
by AF
That's because you can't send messages via chat, AI chat messages are not the same as gadget chat messages, an AI chat message is simply outputted to the console, it's not sent across the network, so it's completely unsynced. Gadget chat messages on the other hand are a different system.
Instead I would suggest you use the direct AI <-> gadget communication. This way you can send it directly as a string to the lua environment the gadget runs in, and build a proxy allowing you to add actual buttons and UI controls like in other games.
You will need to do some research to get that working though. I've not got a 100% verified example that works, and not many people have touched those APIs. Look at sendtogame in api.lua on the Shard side of things
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 17:06
by raaar
but that's exactly what i was trying to do. Have the AI communicate with a gadget with the API you provided.
The code was testing ai<->gadget communication, and it doesn't seem to be working.
it seems that i should be seeing
...
gadget : data from AI=<AI player id>
AI : data from gadget=AI Bla
...
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 17:46
by AF
Ah sorry I misread, right now your failing code is the best example available of how todo this. I have not got a test case to test this functionality at the moment ( never really did have one ), I doubt even the engine Developers know if the API it depends on works or not, nobody knows if the way I'm calling it is correct or not either, and nobody has made an effort to understand why that's the case or if its the case
Put simply, I don't know
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 20:50
by raaar
facepalm.jpg
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 21:21
by Kloot
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 26 Aug 2013, 23:33
by AF
Kloot wrote:This example is for AI's using the legacy C++ interface (figuring out how to translate it to your wrapper of choice is left as an exercise):
Shard does not use the legacy interface. Here is the equivalant call in the C++ API:
https://github.com/Tarendai/Shard/blob/ ... e.cpp#L127
Noting that function widget:RecvSkirmishAIMessage(aiTeam, aiMessage) doesn't match the AICallIn method being used in the example which Im sure has been indicated by another dev, jk comes to mind but I'd need to trawl this thread again to check
Re: Shard 0.35RC2 & 0.31.1 Not So Ballsey
Posted: 27 Aug 2013, 04:41
by raaar
not yet working
----------- ai code
Code: Select all
function AttackHandler:GetHumanTask()
local data = game:SendToContent("GET_HUMAN_TASK")
game:SendToConsole("AI : data from gadget="..tostring(data))
end
----------- gadget code
Code: Select all
--UNSYNCED CODE
if (not gadgetHandler:IsSyncedCode()) then
function gadget:RecvSkirmishAIMessage(aiTeam,aiMessage)
Spring.Echo("gadget : data from AI="..aiTeam.." / "..tostring(aiMessage))
return "TEST RESPONSE"
end
end
output in game log shows gadget successfully getting data from AI, but the AI grabs junk instead of the return value, apparently:
...
[f=0001928] gadget : data from AI=0 / GET_HUMAN_TASK
[f=0001928] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=”#^w
[f=0001988] gadget : data from AI=0 / GET_HUMAN_TASK
[f=0001988] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=”#^w
[f=0002048] gadget : data from AI=0 / GET_HUMAN_TASK
[f=0002048] <SkirmishAI: Shard dev (team 0)>: AI : data from gadget=”#^w
...