flaing / jnibwapi

Automatically exported from code.google.com/p/jnibwapi
0 stars 0 forks source link

Training marines #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello guys. I ve faced a problem when training marines. After the built of 
barrack, i ve tried to train marines but the command it seems that doesnt work. 
I use the above code. 
I use the same code form when i trained terran_SCV and works fine.

THE CODE
for(Unit unit : bwapi.getMyUnits()) {
if(unit.getTypeID() == UnitTypes.Terran_Barracks.ordinal()){
if (bwapi.getSelf().getMinerals() >= 80 && barrackFlag == true) {

bwapi.train(unit.getID(), UnitTypes.Terran_Marine.ordinal());
System.out.println("print something");
}}}

Println works fine but the train command never operates.

Original issue reported on code.google.com by gio.1...@hotmail.com on 24 Oct 2011 at 9:29

GoogleCodeExporter commented 9 years ago
Hi, jnibwapi is very much a work in progress and has not been particularly 
active lately. I've been working with it and maintaining recently but I've only 
been working with zerg, so it's entirely possible that this is a bug in the 
current release (as with zerg only morph/build is necessary so I have not 
tested the train function).

I will attempt to replicate your problem and get back in touch with you.
u
Cheers,
Fobbah

Original comment by Fobbah on 25 Oct 2011 at 2:16

GoogleCodeExporter commented 9 years ago
Working on this issue now.

Original comment by Fobbah on 25 Oct 2011 at 4:37

GoogleCodeExporter commented 9 years ago
I've identified the source of the issue, a cheeky little bug:

JNIEXPORT void JNICALL Java_eisbot_proxy_JNIBWAPI_train(JNIEnv *env, jobject 
jObj, jint unitID, jint typeID){ 
    Unit* unit = Broodwar->getUnit(unitID);
    if (unit != NULL) {
        if (unitTypeMap[typeID] != NULL)
        {
            unit->train(unitTypeMap[typeID]);
        }
    }
}

As it happens, the type ID for a terran marine is zero, and the BWAPI::UnitType 
found in the unit type map was being implicitly cast to an integer to compare 
with NULL, causing the check for a valid unit type to incorrectly return false.

This code for type maps of various kinds is littered through the JNIBWAPI cpp 
code, so this issue is not limited to just the unit type for a marine, and 
would have caused all other BWAPI types used in the jni code to fail in the 
same way!

Great catch - I am marking this issue as duplicated and raising a new issue 
describing the greater extend of the problem. I expect to have a complete fix 
for the larger issue on the SVN tonight.

Cheers,
Fobbah

Original comment by Fobbah on 25 Oct 2011 at 5:15