Page 2 of 2

Re: what is an example of a good but simple Lua AI?

Posted: 12 Aug 2011, 17:54
by AF
knorke wrote:definitely.
Actually I think I once saw such file in zk?
Not sure if it was just a hand-written "note" or real config though.
Also not sure if Shard could read it?

Shard runs in a different Lua VM. Declaring a function or variable in gadget land makes it available in gadget land, Shard land is in a parallel universe as far as this analogy is concerned.

Luckily, thanks to entrepeneurial engine developers, and AF trickery, a small wormhole exists that eats strings in Shard land, deposits them in gadget land, then returns them home to shard land when the gadgets have finished molesting them with evil game logic devices.

Re: what is an example of a good but simple Lua AI?

Posted: 12 Aug 2011, 18:35
by knorke
well, then morph command ID is just one number.
it could even be hardcoded in the config, i dont think it will ever change.
hardly "nice" but not an obstacle either.
But more importantly, is it possible to make Shard work with CT? How so? is adding mining all that's needed?
well, like AF wrote in previous thread apearently you can somehow create empty tasklists for miners so that shard "leaves them alone" and just let the gadget AI controll them. Though for drones you would need some custom logic (like in schwarm ai) that makes them walk to rocks and deploy, then undeploy etc.
AF wrote:a small wormhole exists
the wormhole of recent advances?
So now it is that the same point like in the previous thread, who will make a shard config?

Re: what is an example of a good but simple Lua AI?

Posted: 13 Aug 2011, 20:23
by AF
Miners are interpreted as builders or attackers or w/e by shard, but this is overridable.
  • Create a new behaviour ( copy paste and rename an older one )
  • Remove all logic from it so it does absolutely nothing
  • In behaviours.lua, include your new behaviours lua file, and then assign it in the array to the miner unit ( bminer? )
Now when miners are built, they will be controlled by your new behaviour ( which does absolutely nothing ). So they will sit there forever ( unless you happen to have a gadget that makes miners mine, ah wait you do! ??? profit )

This, coupled with the build orders already present in the other CT AI should do 90% of the work, perhaps even make it mildly playable.

Re: what is an example of a good but simple Lua AI?

Posted: 14 Aug 2011, 21:19
by yanom
...i'm confused now. But it doesn't sound like I can make it work.

Re: what is an example of a good but simple Lua AI?

Posted: 16 Aug 2011, 02:01
by AF
yanom wrote:...i'm confused now. But it doesn't sound like I can make it work.

Which? I thought you were asking for an AI you could look at to figure out the high level logic?

Re: what is an example of a good but simple Lua AI?

Posted: 17 Aug 2011, 00:14
by yanom
well, that too, but then you got me interested in Shard itself, and now I'm wondering if it can be put to use for CT (drones faction).

Re: what is an example of a good but simple Lua AI?

Posted: 17 Aug 2011, 18:34
by AF
If you look in other threads there're clearer explanations of what steps are involved.

Morphing I can't explain in its entirety as I haven't looked at the morphing gadget. I can describe how to communicate with the morphing gadget, just not what needs to eb said to it.

Does the drones faction even require morphing to function?

Re: what is an example of a good but simple Lua AI?

Posted: 17 Aug 2011, 19:31
by knorke
AF wrote:Morphing I can't explain in its entirety as I haven't looked at the morphing gadget. I can describe how to communicate with the morphing gadget, just not what needs to eb said to it.
this:
knorke wrote:giving a morph order works like:
Spring.GiveOrderToUnit(unitID, 31210,{UnitDefNames["kdroneminingtower"].id},{"shift"})
you give the unit an order, like moving, attacking and whatever else there is. Just instead of CMD.MOVE it is that funny number. Now just need to know what Spring.GiveOrderToUnit is called in shard-Lua, if it exists.
Does the drones faction even require morphing to function?
yes

Re: what is an example of a good but simple Lua AI?

Posted: 19 Aug 2011, 15:59
by AF
knorke wrote:Now just need to know what Spring.GiveOrderToUnit is called in shard-Lua, if it exists.

Spring.GiveOrderToUnit lives in gadget land. It is a spring engine specific callout. It will not be appearing in the Shard APIs anytime soon, as its an ugly callout that locks me into the spring engine and its semantics and sets the precedent that I must hardcode every other spring gadget API into Shard ( which would require me to put gadgets in your game anyway defeating the point of the whole aversion tactic )

Shard was designed to be engine agnostic. It also would not have any way of determining of unit type A can morph, and if so what into.

To implement morphing, AI <-> Gadget communication is necessary.

All I can suggest at my end is doing something such as a behaviour that morphs a unit when finished building:

Code: Select all

-- MorphCruiserBehaviour.lua
MorphCruiserBehaviour = class(Behaviour)

function MorphCruiserBehaviour:Init()
	self.active = false
	id = self.unit:Internal():ID()
	--AF knows not what the gadget expects, but it probably includes a unit ID and a unit name of what shard needs it to morph into
	morphmessage = "unspecified gadget API"
	game:SendToContent(morphmessage)
end

Re: what is an example of a good but simple Lua AI?

Posted: 19 Aug 2011, 16:14
by AF
Though if it is absolutely paramount that you put the spring API call in shard, you can put in the effort and define the callout on Shards end, e.g.:

Code: Select all

function GiveOrderToUnit(parameters)
    message = "GiveOrderToUnit"..parameters -- serialiase parameters
    return game:sendToContent(message)
end
With a gadget at the other end in your game that actually executes the command given said parameters at the other end.

Re: what is an example of a good but simple Lua AI?

Posted: 19 Aug 2011, 17:26
by knorke
With a gadget at the other end in your game that actually executes the command given said parameters at the other end.
Thing is you are going to do such things, it will no longer be about a simple AI config but various programming things.
Which appearently nobody wants to do.

Just "morphing when unit is finished" has little use.
Drone engineers have to walk to a rock, deploy to stationary form, mine the rock, undeploy to mobile form when mining has finished, walk to next rock etc.
So you need functions such as getNearestRockPosition to know where to walk to etc.
That is kind of independ of the Lua API used, get all units in a radius around the miner unit and sort by distance.
The API function to get all units in a radius might be Spring.blabla or it might be Shard.blublub

I think you will need so much custom logic that in the end you could have just made everything a LuaAI. With the advantage of having at least a rudimentary docu ;)

Re: what is an example of a good but simple Lua AI?

Posted: 19 Aug 2011, 22:07
by AF
Hardly, all it requires is an API to acquire the information, after which one can write the necessary behaviours on Shards end. If your code is written well then it should be an issue. Shard already has APIs for finding units etc

This is what you need:
  • Which units can morph
  • Given unit type A, what units can this unit morph into
  • How long will this unit take to morph
  • A means of telling A to morph into B
  • A means of telling A to stop morphing ( if stop will not suffice )
  • An event to poll for if the unit finishes morphing ( if unit idle will not suffice )

Re: what is an example of a good but simple Lua AI?

Posted: 20 Aug 2011, 20:13
by yanom
AF wrote: Shard was designed to be engine agnostic.
What other engines (besides spring) is it used on?

Re: what is an example of a good but simple Lua AI?

Posted: 20 Aug 2011, 21:46
by AF
Partial support for starcraft broodwar was added, and there are extensions for one or two of my own game engines, but none are released as the starcraft API support wasn't complete and I wasn't happy, and the other bindings aren't really relevant to the wider community.