C++ AI: In-game drawing

C++ AI: In-game drawing

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

C++ AI: In-game drawing

Post by lamer »

How to draw debug data from C++ AI onto game view?

Recently I saw java AI that is capable of drawing its internal data (such as eco grid) onto warzone.
Some java AIs contain calls such as
callback.getMap().getDrawer().addPoint(unit.getPos(), "building defender");
And some even contain JFrame derivatives and work with java.awt.Graphics (have no idea whats that).

I did try to use AI interface methods with almost no effect:
callback->GetMap()->GetDrawer()->AddLine(commander->GetPos(), friendCommander->GetPos());
callback->GetMap()->GetDrawer()->AddNotification(commander->GetPos(), AIColor(0.9, 0.1, 0.1), 200);
callback->GetMap()->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
Only AddNotification made a 1 second ping on a minimap.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: C++ AI: In-game drawing

Post by lamer »

(engine version 97.0.1-2xx)
Got direct answer from AI developer.
AddLine and AddPoint should work, but infolog says
[f=0000129] Got message 31 from 0 claiming to be from 1
[f=0000129] Got message 31 from 0 claiming to be from 2
etc.

NETMSG_MAPDRAW = 31.
Will try to fix that.

JFrame and java.awt.Graphics are not related to spring (visualization done in other gui).
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: C++ AI: In-game drawing

Post by jK »

try /debugdrawai
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: C++ AI: In-game drawing

Post by lamer »

Looks like engine allows to draw only by playerID and not by teamID.
But function CAICallback::HandleCommand (commandId == AIHCAddMapPointId) passes teamID instead of playerID to CBaseNetProtocol::SendMapDrawPoint.

https://github.com/spring/spring/pull/121
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: C++ AI: In-game drawing

Post by lamer »

jK wrote:try /debugdrawai
/debugdrawai actually has no effect on
callback->GetMap()->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
You still need https://github.com/spring/spring/pull/121 workaround.
Actually a better fix required that allows to draw not by playerID but by teamID, and thats much more work.

But /debugdrawai intrigued me. Went to investigate it and found another drawer (GraphDrawer).
Looks like local drawer. Will play a bit more with it.
Last edited by lamer on 13 Aug 2014, 23:54, edited 1 time in total.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: C++ AI: In-game drawing

Post by lamer »

jK wrote:try /debugdrawai
Is there any example how to use springai::GraphDrawer and springai::GraphLine?
I tried to do on EVENT_INIT

Code: Select all

	GraphDrawer* drawer = callback->GetDebug()->GetGraphDrawer();
	drawer->SetPosition(0, 0);
	drawer->SetSize(map->GetWidth() * SQUARE_SIZE, map->GetHeight() * SQUARE_SIZE);
	GraphLine* line = drawer->GetGraphLine();
	line->SetColor(0, AIColor(0.9, 0.1, 0.1));
	line->SetLabel(0, "label");
and on EVENT_UPDATE

Code: Select all

//	map->GetDrawer()->AddPoint(commander->GetPos(), "Pinh!");
	GraphLine* line = callback->GetDebug()->GetGraphDrawer()->GetGraphLine();
	line->AddPoint(0, commander->GetPos().x, commander->GetPos().y);
But nothing rendered (with and without /debugdrawai). Using 97.0.1-208 engine.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: C++ AI: In-game drawing

Post by lamer »

/debugdrawai is fine and working, thanks, just had to look at E323AI sources to find out the proper use.
It uses flat screen coordinates (-1..1).
On EVENT_INIT

Code: Select all

	GraphDrawer* drawer = callback->GetDebug()->GetGraphDrawer();
	drawer->SetPosition(-0.6f, -0.6f);
	drawer->SetSize(0.8f, 0.8f);
	GraphLine* line = drawer->GetGraphLine();
	line->SetColor(0, AIColor(0.9, 0.1, 0.1));
	line->SetLabel(0, "label");
On EVENT_UPDATE

Code: Select all

	GraphLine* line = callback->GetDebug()->GetGraphDrawer()->GetGraphLine();
	line->AddPoint(0, -0.9, -0.9);
	line->AddPoint(0, 0.9, 0.9);
As spectator select affected AI and see graph.
Reference thread
Post Reply

Return to “AI”