Page 13 of 21
Re: Java AI Interface for Spring
Posted: 14 Jul 2009, 00:10
by cranphin
Hmm, question :)
Just to have a base to mess about with I'm porting tiny bits of Kaik :)
What I'm trying to do now is this:
Code: Select all
boolean haveClearShot = true;
TraceRayAICommand traceRayAICommand = new TraceRayAICommand(commander.getPos(), new AIFloat3(targetDir),maxRange,commander.getUnitId(),-1,0);
cb.getEngine().handleCommand(AICommandWrapper.COMMAND_TO_ID_ENGINE,
-1, traceRayAICommand);
if (traceRayAICommand.hitUID != -1) {
haveClearShot =Unit.getInstance(cb,traceRayAICommand.hitUID).getAllyTeam() !=
cb.getGame().getMyAllyTeam();
}
But this fails because Unit.getInstance(cb,someid) is not public (probably with good reason XD).
What would the correct way be to achieve this ? :)
Or is it necessary to extend JavaOOAI first to support this ? :)
Cheers!
Re: Java AI Interface for Spring
Posted: 14 Jul 2009, 00:27
by hoijui
traceRayAICommand.hitUID should be a Unit, not an int.. this is a fial of the java interface, and i have to adjust it.
Re: Java AI Interface for Spring
Posted: 14 Jul 2009, 00:43
by cranphin
hoijui wrote:traceRayAICommand.hitUID should be a Unit, not an int.. this is a fail of the java interface, and i have to adjust it.
What is the best way for me to get around this in the meantime ?
If there is any ? :)
Cheers!
Re: Java AI Interface for Spring
Posted: 14 Jul 2009, 17:22
by hoijui
i noticed that there is no OO equivalent to commands, and therefore.. it cant be a fix, but has to be a .. relatively big change. am not very motivated to do it soon.
a workaround is changing the generated sources to make the method you tried to use public instead of protected.
Re: Java AI Interface for Spring
Posted: 14 Jul 2009, 21:47
by LoidThanead
If you extends AbstractOOAI (or just implement OOAI) you can keep a list of units using the unitCreated() method. Just keep a map of unit ID's to unit's by keeping track of the units that are created and destroyed. (Use unitCreated() and unitDestroyed()).
Note that this only works for friendly units - you don't get a unitDestroyed() event for enemy units that are destroyed out of radar and line of sight.
Or you could try looping through callback.getFriendlyUnits() or callback.getEnemyUnits().
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 03:09
by cranphin
Hi!
Two more things I noticed :)
If I want to use Java colors, I need to do this:
Code: Select all
AIFloat3 myColor = new AIFloat3(color);
myColor.x /= 255;
myColor.y /= 255;
myColor.z /= 255;
This is a small mistake in AIFloat color constructor, java uses 0-255, spring uses 0.0 - 1.0 :)
And, when using a figureGroupId '0' like this, I think it's supposed to return a new group id in the ret_.. value, but it seems not to do this (it just returns what you set):
Code: Select all
CreateLineFigureDrawerAICommand lineCommand = new CreateLineFigureDrawerAICommand(from, to, 2.0f, false, 5, 0, 0);
this.ai.cb.getEngine().handleCommand(AICommandWrapper.COMMAND_TO_ID_ENGINE, -1, lineCommand);
int retGroup = lineCommand.ret_newFigureGroupId; // This is always 0 with the above code.
// This doesn't work well if the id is always 0.
SetColorFigureDrawerAICommand setColorCommand = new SetColorFigureDrawerAICommand(lineCommand.ret_newFigureGroupId, myColor, 1.0f);
I haven't been able to figure out why this doesn't work, mayby you have an idea :)
Otherwise, things seem pretty stable, I get some crashes when I use an invalid ID for some methods, but I can solve that in my code :)
Cheers!
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 03:11
by cranphin
LoidThanead wrote:If you extends AbstractOOAI (or just implement OOAI) you can keep a list of units using the unitCreated() method. Just keep a map of unit ID's to unit's by keeping track of the units that are created and destroyed. (Use unitCreated() and unitDestroyed()).
Note that this only works for friendly units - you don't get a unitDestroyed() event for enemy units that are destroyed out of radar and line of sight.
Or you could try looping through callback.getFriendlyUnits() or callback.getEnemyUnits().
This is all hacks, in which case my hack is easier

Ultimatly we need s neater system/fix to handle this, and until then making the method I mentioned public works :)
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 10:52
by hoijui
last two issues should be fixed now though untested (as my pc still freezes most times i run spring, because of graphics driver issues).
* AIFloat3(Color)
* return values of commands
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 13:34
by cranphin
hoijui wrote:last two issues should be fixed now though untested (as my pc still freezes most times i run spring, because of graphics driver issues).
* AIFloat3(Color)
* return values of commands
That's a shame about the video card issues!
Any hope of sorting that out sometime ?
Is there a place to get this updated version? is it just the jars or more ? :)
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 15:12
by R-TEAM
Hi,
i use ATM the spring 0.79+ build exe from the "E323AI" thread and
i musst say -> THANKS to the devs
The specular light on Water is now in right angle to the virtual Sun
on my ATI card - and it looks a little bit Faster ....
Have after 4 or 5 games no new bugs found.
So maybe test this or a newer Version .....
Regards
R-TEAM
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 22:03
by cranphin
Another tiny thing that could use improving :)
AIFloat3 would benefit a lot from a:
- Copy constructor (to copy one AIFloat3 from another).
- equals method (which uses x,y,z).
- hashCode method (not really needed, but good to implement if equals is overriden!).
I can write up the code for this if you'd prefer :)
Cheers!
In fact, I better add it straight away :)
Code: Select all
public AIFloat3(final AIFloat3 float3) {
this.x = float3.x;
this.y = float3.y;
this.z = float3.z;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Float.floatToIntBits(x);
result = prime * result + Float.floatToIntBits(y);
result = prime * result + Float.floatToIntBits(z);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
AIFloat3 other = (AIFloat3) obj;
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
return false;
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
return false;
if (Float.floatToIntBits(z) != Float.floatToIntBits(other.z))
return false;
return true;
}
Re: Java AI Interface for Spring
Posted: 19 Jul 2009, 23:52
by hoijui
thanks cranphin!

yeah.. makes sense to have all this in there.
id in spring master now.
yeah its just the jars that change (from a users perspective). i dont know how you test things.. you seemed to have been able to use latest spring master so far... you can compile yourself, or for windows, get buildbot builds, if you dont do that already.
the graphics issue...
the only way to solve it would be to downgrade ubuntu to 8.10 or.. possibly 8.04 even, and then use fglrx. my card is and never was well supported on linux, but now its getting worse, and jsut using old drivers does not work as they dont work with recent xorg versions...
i may downgrade once.. but now i am too lazy.
Re: Java AI Interface for Spring
Posted: 20 Jul 2009, 22:54
by cranphin
Hmm, it's a pity Unit.getCurrentCommands() seems to use old style command structures, confusing when the command in handleCommand are new style command structures :)
Guess that's how the 'new AI interface' currently works tho, has anyone ever considered changing that ? :)
Anyone I can bother about that ?
Cheers :)
Re: Java AI Interface for Spring
Posted: 21 Jul 2009, 10:14
by hoijui
it would be quite a hassle to change it, and honestly, i think you should not really ever need this method anyway.
the only time it theoretically could make sense, is when the user controlls the same team as your AI, and he gives an order to a unit, and you want ot analyze that command....
but even for this scenario i see no good use. you will just wait till the unit is idle again, and then possibly use it again.
you know yourself what ocmmands you gave it, and you get the unitIdle event when it has no commands left.
i agree it would be nicer, but it also a quite expensive method, and the end result of making it more compatible would be slower AIs with no more functionality then there could be otherwise. maybe i should remove this callback alltogether?
Re: Java AI Interface for Spring
Posted: 21 Jul 2009, 21:10
by cranphin
hoijui wrote:it would be quite a hassle to change it, and honestly, i think you should not really ever need this method anyway.
the only time it theoretically could make sense, is when the user controlls the same team as your AI, and he gives an order to a unit, and you want ot analyze that command....
but even for this scenario i see no good use. you will just wait till the unit is idle again, and then possibly use it again.
you know yourself what ocmmands you gave it, and you get the unitIdle event when it has no commands left.
i agree it would be nicer, but it also a quite expensive method, and the end result of making it more compatible would be slower AIs with no more functionality then there could be otherwise. maybe i should remove this callback alltogether?
Well, I'm only mentioning it, was curious :)
KAIK uses this method, which is why I noticed it. I'm not sure how or why they use it, and if it's needed tho :)
I think you're analysis is correct, as long as it's in the new c interface I'd recommend keeping it in the Java interface also tho :)
I think.. :)
Re: Java AI Interface for Spring
Posted: 22 Jul 2009, 10:40
by LoidThanead
The method could be interesting if you want to design a 'helper' AI. As in, an AI that takes general orders from a human player, like 'attack' or 'defend this position.'
You would want to see which units are available, and not currently in use by the human player before trying to do something with them.
You also might want to see what they are doing to try and assist them.
Re: Java AI Interface for Spring
Posted: 22 Jul 2009, 19:06
by LoidThanead
In the latest Java interface version (the one I got from Buildserv just now) seems to have replaced unitCreated(Unit unit, int builder) with unitCreated(Unit unit). Is this deliberate? If so, why?
Re: Java AI Interface for Spring
Posted: 23 Jul 2009, 12:14
by hoijui
it should have changed from unitCreated(Unit unit, int builder) to unitCreated(Unit unit, Unit builder) (some time ago already, though). It looks ok in my local generted sources from today. this did not change sime some days.
i just checked the sources i have from my 3 days old install fro mthe buildbot, it looks right there too. Though, it still contianed the old sources (the ones in the com.clan_sy.spring package, instead of com.springrts). maybe you were looking at these, where it would still be as you found it, i guess.
I dont know of any other explanation. I did a !rebuild clean-yes yesterday, so i hope the old sources are gone for good now.
Re: Java AI Interface for Spring
Posted: 24 Jul 2009, 00:39
by cranphin
Yay I've got part of kaik ported XD
It kinda works , the part atleast :)
I'm seeing one issue atm. too late to debug now, but I'm losing a -lot- of memory :)
Using some jdk6 tools (jhat) it seems that all the memory goes to a HUGE (100000 items) hashmap in the field:
com.sun.jna.Structure: static field reading
(So the static field com.sun.jna.Structure.reading)
No idea why that is, I'll try to investigate, mayby I'm just holding references to objects myself or so :)
But, if anyone has any ideas, they're very welcome :)
Besides that, it does work tho ^___^
Oh, I'm using the latest -release- spring btw, (..1.2).
The way I handle 'fixes' is I modify and recompile the AIInterface.jar as I need it

It'll probably mean the ai is broken with the next version of spring, but I'll fix it then
Cheers!
Re: Java AI Interface for Spring
Posted: 24 Jul 2009, 00:42
by cranphin
Btw. the manifest.mf suggest spring uses JNA 3.0.9 b0.
The lastest version is 3.2.0.
Would it be a good idea to upgrade ? :)
(They mention performance improvements :) ).
Cheers!