diff --git a/bwapi4/AIModule.java b/bwapi4/AIModule.java index 62d67d3..ad9e0b6 100644 --- a/bwapi4/AIModule.java +++ b/bwapi4/AIModule.java @@ -1,136 +1,130 @@ package bwapi4; -import bwapi4.*; - -import java.util.Map; -import java.util.HashMap; -import java.util.Collection; -import java.util.List; +import bwapi4.BWEventListener; +/** + * This class receives all events from Broodwar. + * To process them, receive an AIModule's instance from {@link Mirror} and call {@link #setEventListener(bwapi.BWEventListener)} + * to set you own {@link BWEventListener listener}. + * There's also a stub class ({@link DefaultBWListener}) provided, so you don't have to implement all of the methods. + */ public class AIModule { + AIModule(){} + + private BWEventListener eventListener; + + public void setEventListener(BWEventListener eventListener) { + this.eventListener = eventListener; + } + public void onStart() { - onStart_native(pointer); + if (eventListener != null) { + eventListener.onStart(); + } } public void onEnd(boolean isWinner) { - onEnd_native(pointer, isWinner); + if (eventListener != null) { + eventListener.onEnd(isWinner); + } } public void onFrame() { - onFrame_native(pointer); + if (eventListener != null) { + eventListener.onFrame(); + } } public void onSendText(String text) { - onSendText_native(pointer, text); + if (eventListener != null) + { + eventListener.onSendText(text); + } } public void onReceiveText(Player player, String text) { - onReceiveText_native(pointer, player, text); + if (eventListener != null) { + eventListener.onReceiveText(player, text); + } } public void onPlayerLeft(Player player) { - onPlayerLeft_native(pointer, player); + if (eventListener != null) { + eventListener.onPlayerLeft(player); + } } public void onNukeDetect(Position target) { - onNukeDetect_native(pointer, target); + if (eventListener != null) { + eventListener.onNukeDetect(target); + } } public void onUnitDiscover(Unit unit) { - onUnitDiscover_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitDiscover(unit); + } } public void onUnitEvade(Unit unit) { - onUnitEvade_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitEvade(unit); + } } public void onUnitShow(Unit unit) { - onUnitShow_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitShow(unit); + } } public void onUnitHide(Unit unit) { - onUnitHide_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitHide(unit); + } } public void onUnitCreate(Unit unit) { - onUnitCreate_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitCreate(unit); + } } public void onUnitDestroy(Unit unit) { - onUnitDestroy_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitDestroy(unit); + } } public void onUnitMorph(Unit unit) { - onUnitMorph_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitMorph(unit); + } } public void onUnitRenegade(Unit unit) { - onUnitRenegade_native(pointer, unit); + if (eventListener != null) { + eventListener.onUnitRenegade(unit); + } } public void onSaveGame(String gameName) { - onSaveGame_native(pointer, gameName); + if (eventListener != null) { + eventListener.onSaveGame(gameName); + } } public void onUnitComplete(Unit unit) { - onUnitComplete_native(pointer, unit); - } - - - private static Map instances = new HashMap(); - - private AIModule(long pointer) { - this.pointer = pointer; - } - - private static AIModule get(long pointer) { - if (pointer == 0 ) { - return null; + if (eventListener != null) { + eventListener.onUnitComplete(unit); } - AIModule instance = instances.get(pointer); - if (instance == null ) { - instance = new AIModule(pointer); - instances.put(pointer, instance); - } - return instance; } - private long pointer; - - private native void onStart_native(long pointer); - - private native void onEnd_native(long pointer, boolean isWinner); - - private native void onFrame_native(long pointer); - - private native void onSendText_native(long pointer, String text); - - private native void onReceiveText_native(long pointer, Player player, String text); - - private native void onPlayerLeft_native(long pointer, Player player); - - private native void onNukeDetect_native(long pointer, Position target); - - private native void onUnitDiscover_native(long pointer, Unit unit); - - private native void onUnitEvade_native(long pointer, Unit unit); - - private native void onUnitShow_native(long pointer, Unit unit); - - private native void onUnitHide_native(long pointer, Unit unit); - - private native void onUnitCreate_native(long pointer, Unit unit); - - private native void onUnitDestroy_native(long pointer, Unit unit); - - private native void onUnitMorph_native(long pointer, Unit unit); - - private native void onUnitRenegade_native(long pointer, Unit unit); - - private native void onSaveGame_native(long pointer, String gameName); - - private native void onUnitComplete_native(long pointer, Unit unit); - + public void onPlayerDropped(Player player) { + if (eventListener != null) { + eventListener.onPlayerDropped(player); + } + } } diff --git a/bwapi4/BWEventListener.java b/bwapi4/BWEventListener.java new file mode 100644 index 0000000..6f9f031 --- /dev/null +++ b/bwapi4/BWEventListener.java @@ -0,0 +1,53 @@ +package bwapi4; + +import bwapi4.*; + +import java.util.Map; +import java.util.HashMap; +import java.util.Collection; +import java.util.List; + +/** + * Implement this interface and call {@link AIModule#setEventListener(bwapi.BWEventListener)} to receive all of the in game events. + */ +public interface BWEventListener { + + public void onStart(); + + public void onEnd(boolean isWinner); + + public void onFrame(); + + public void onSendText(String text); + + public void onReceiveText(Player player, String text); + + public void onPlayerLeft(Player player); + + public void onNukeDetect(Position target); + + public void onUnitDiscover(Unit unit); + + public void onUnitEvade(Unit unit); + + public void onUnitShow(Unit unit); + + public void onUnitHide(Unit unit); + + public void onUnitCreate(Unit unit); + + public void onUnitDestroy(Unit unit); + + public void onUnitMorph(Unit unit); + + public void onUnitRenegade(Unit unit); + + public void onSaveGame(String gameName); + + public void onUnitComplete(Unit unit); + + public void onPlayerDropped(Player player); + +} + + diff --git a/bwapi4/Color.java b/bwapi4/Color.java index b8b4d52..e15c22a 100644 --- a/bwapi4/Color.java +++ b/bwapi4/Color.java @@ -1,24 +1,28 @@ package bwapi4; -import bwapi4.*; - -import java.util.Map; +import java.lang.Override; import java.util.HashMap; -import java.util.Collection; -import java.util.List; +import java.util.Map; +/** + * Starcraft uses a 256 color palette to render everything, + * so the colors available for draw shapes using BWAPI is limited to the colors available in the Pallete. + * Several predefined colors from the pallete are provided. + */ public class Color { - public int red() { - return red_native(pointer); - } + private int r, g, b; - public int green() { - return green_native(pointer); - } - - public int blue() { - return blue_native(pointer); + /** + * Create a color using the color in the palette that is closest to the RGB color specified. This will check a number of colors in the pallet to see which is closest to the specified color so this function is relatively slow. + * @param r + * @param g + * @param b + */ + public Color(int r, int g, int b) { + this.r = r; + this.g = g; + this.b = b; } public static Color Red; @@ -45,32 +49,25 @@ public class Color { public static Color Grey; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Color)) return false; - private static Map instances = new HashMap(); + Color color = (Color) o; - private Color(long pointer) { - this.pointer = pointer; + if (b != color.b) return false; + if (g != color.g) return false; + if (r != color.r) return false; + + return true; } - private static Color get(long pointer) { - if (pointer == 0 ) { - return null; - } - Color instance = instances.get(pointer); - if (instance == null ) { - instance = new Color(pointer); - instances.put(pointer, instance); - } - return instance; + @Override + public int hashCode() { + int result = r; + result = 31 * result + g; + result = 31 * result + b; + return result; } - - private long pointer; - - private native int red_native(long pointer); - - private native int green_native(long pointer); - - private native int blue_native(long pointer); - - } diff --git a/bwapi4/DefaultBWListener.java b/bwapi4/DefaultBWListener.java new file mode 100644 index 0000000..76df50e --- /dev/null +++ b/bwapi4/DefaultBWListener.java @@ -0,0 +1,103 @@ +package bwapi4; + +import bwapi4.BWEventListener; +import bwapi4.Player; +import bwapi4.Position; +import bwapi4.Unit; + +/** + * A utility stub class providing a default implementation of {@link BWEventListener}, + * override it's methods if you want to handle only some events. + */ +public class DefaultBWListener implements BWEventListener { + + @Override + public void onStart() { + + } + + @Override + public void onEnd(boolean b) { + + } + + @Override + public void onFrame() { + + } + + @Override + public void onSendText(String s) { + + } + + @Override + public void onReceiveText(Player player, String s) { + + } + + @Override + public void onPlayerLeft(Player player) { + + } + + @Override + public void onNukeDetect(Position position) { + + } + + @Override + public void onUnitDiscover(Unit unit) { + + } + + @Override + public void onUnitEvade(Unit unit) { + + } + + @Override + public void onUnitShow(Unit unit) { + + } + + @Override + public void onUnitHide(Unit unit) { + + } + + @Override + public void onUnitCreate(Unit unit) { + + } + + @Override + public void onUnitDestroy(Unit unit) { + + } + + @Override + public void onUnitMorph(Unit unit) { + + } + + @Override + public void onUnitRenegade(Unit unit) { + + } + + @Override + public void onSaveGame(String s) { + + } + + @Override + public void onUnitComplete(Unit unit) { + + } + + @Override + public void onPlayerDropped(Player player) { + + } +} diff --git a/bwapi4/Game.java b/bwapi4/Game.java index dd609e0..0b30ed7 100644 --- a/bwapi4/Game.java +++ b/bwapi4/Game.java @@ -377,26 +377,14 @@ public class Game { printf_native(pointer, cstr_format); } - public void vPrintf(String cstr_format, Object ... args) { - vPrintf_native(pointer, cstr_format, args); - } - public void sendText(String cstr_format) { sendText_native(pointer, cstr_format); } - public void vSendText(String cstr_format, Object ... args) { - vSendText_native(pointer, cstr_format, args); - } - public void sendTextEx(boolean toAllies, String cstr_format) { sendTextEx_native(pointer, toAllies, cstr_format); } - public void vSendTextEx(boolean toAllies, String cstr_format, Object ... args) { - vSendTextEx_native(pointer, toAllies, cstr_format, args); - } - public boolean isInGame() { return isInGame_native(pointer); } @@ -477,10 +465,6 @@ public class Game { setTextSize_native(pointer, size); } - public void vDrawText(bwapi4.CoordinateType.Enum ctype, int x, int y, String cstr_format, Object ... arg) { - vDrawText_native(pointer, ctype, x, y, cstr_format, arg); - } - public void drawText(bwapi4.CoordinateType.Enum ctype, int x, int y, String cstr_format) { drawText_native(pointer, ctype, x, y, cstr_format); } @@ -1142,16 +1126,10 @@ public class Game { private native void printf_native(long pointer, String cstr_format); - private native void vPrintf_native(long pointer, String cstr_format, Object ... args); - private native void sendText_native(long pointer, String cstr_format); - private native void vSendText_native(long pointer, String cstr_format, Object ... args); - private native void sendTextEx_native(long pointer, boolean toAllies, String cstr_format); - private native void vSendTextEx_native(long pointer, boolean toAllies, String cstr_format, Object ... args); - private native boolean isInGame_native(long pointer); private native boolean isMultiplayer_native(long pointer); @@ -1192,8 +1170,6 @@ public class Game { private native void setTextSize_native(long pointer, bwapi4.Text.Size.Enum size); - private native void vDrawText_native(long pointer, bwapi4.CoordinateType.Enum ctype, int x, int y, String cstr_format, Object ... arg); - private native void drawText_native(long pointer, bwapi4.CoordinateType.Enum ctype, int x, int y, String cstr_format); private native void drawTextMap_native(long pointer, int x, int y, String cstr_format); diff --git a/bwapi4/Mirror.java b/bwapi4/Mirror.java new file mode 100644 index 0000000..1eaf4f2 --- /dev/null +++ b/bwapi4/Mirror.java @@ -0,0 +1,262 @@ +package bwapi4; + +import bwapi4.AIModule; +import bwapi4.BWEventListener; + +import java.io.*; +import java.io.File; +import java.lang.Exception; +import java.lang.UnsupportedOperationException; +import java.util.*; +import java.util.zip.*; + +/** + *

The API entry point. Standard use case:

+ *
    + *
  • Create a Mirror object and use {@link #getModule()} and then set an {@link AIModule}'s {@link BWEventListener}
    + *
  • Call {@link #startGame()} to init the API and connect to Broodwar, then launch Broodwar from ChaosLauncher.
  • + *
  • In you {@link BWEventListener#onStart()} method, receive the Game object by calling {@link #getGame()}
  • + *
+ *
+ * Example + *
+ *     {@code
+ *
+ *     mirror.getModule().setEventListener(new DefaultBWListener()
+ *     {
+ *            public void onStart() {
+ *                game = mirror.getGame();
+ *                self = game.self();
+ *                //initialization
+ *                ....
+ *            }
+ *
+ *           public void onUpdate() {
+ *               for (Unit myUnit : self.getUnits()) {
+ *                   //give orders to unit
+ *                   ...
+ *                }
+ *           }
+ *        });
+ *     }
+ *     mirror.startGame();
+ * 
+ + *

Note: The Game object is initialized during the {@link #startGame()} as well as other BWMirror API's constants. + * Do not use any API releated methods/fields prior to {@link #startGame()}.

+ + */ +public class Mirror { + + private Game game; + + private AIModule module = new AIModule(); + + private FrameCallback frameCallback; + + private static final boolean EXTRACT_JAR = true; + + private static final String VERSION = "2_0"; + + static { + String arch = System.getProperty("os.arch"); + String dllNames[] = {"bwapi_bridge" + VERSION, "gmp-vc90-mt", "mpfr-vc90-mt"}; + if(!arch.equals("x86")){ + throw new UnsupportedOperationException("BWMirror API supports only x86 architecture."); + } + try { + if (EXTRACT_JAR) { + System.setProperty("java.library.path", "."); + java.lang.reflect.Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); + fieldSysPath.setAccessible(true); + fieldSysPath.set(null, null); + + String path = Mirror.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + String decodedPath = java.net.URLDecoder.decode(path, "UTF-8"); + + for (String dllName : dllNames) { + String dllNameExt = dllName + ".dll"; + if (!new File(dllNameExt).exists()) { + JarResources jar = new JarResources(path); + byte[] correctDllData = jar.getResource(dllNameExt); + FileOutputStream funnyStream = new FileOutputStream(dllNameExt); + funnyStream.write(correctDllData); + funnyStream.close(); + } + } + } + } catch (Exception e) { + System.err.println("Failed to extract native libraries.\n" + e); + } + + System.loadLibrary(dllNames[0]); + + File dataDir = new File("bwapi-data/BWTA"); + if(!dataDir.exists()){ + try { + dataDir.mkdirs(); + } catch (Exception e) { + System.err.println("Unable to create /bwapi-data/BWTA folder, BWTA analysis will not be saved."); + } + } + } + + public Game getGame() { + return game; + } + + public AIModule getModule() { + return module; + } + + /** + * Starts the API, initializes all constants ( {@link UnitType}, {@link WeaponType} ) and the {@link Game} object. + * This method blocks until the end of game. + */ + public native void startGame(); + + private void update() { + if (frameCallback != null) { + frameCallback.update(); + } + } + + /*public void setFrameCallback(bwapi.Mirror.FrameCallback frameCallback) { + this.frameCallback = frameCallback; + } */ + + /** + * The simplest interface to receive update event from Broodwar. The {@link #update()} method is called once each frame. + * For a simple bot and implementation of this interface is enough, to receive all in game events, implement {@link BWEventListener}. + */ + /*public*/ private interface FrameCallback { + public void update(); + } + + @SuppressWarnings({"unchecked"}) + private static class JarResources { + + // external debug flag + public boolean debugOn = false; + + // jar resource mapping tables + private Hashtable htSizes = new Hashtable(); + private Hashtable htJarContents = new Hashtable(); + + // a jar file + private String jarFileName; + + /** + * creates a javabot.JarResources. It extracts all resources from a Jar + * into an internal hashtable, keyed by resource names. + * + * @param jarFileName a jar or zip file + */ + public JarResources(String jarFileName) { + this.jarFileName = jarFileName; + init(); + } + + /** + * Extracts a jar resource as a blob. + * + * @param name a resource name. + */ + public byte[] getResource(String name) { + return (byte[]) htJarContents.get(name); + } + + /** + * initializes internal hash tables with Jar file resources. + */ + private void init() { + try { + // extracts just sizes only. + ZipFile zf = new ZipFile(jarFileName); + Enumeration e = zf.entries(); + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + if (debugOn) { + System.out.println(dumpZipEntry(ze)); + } + htSizes.put(ze.getName(), new Integer((int) ze.getSize())); + } + zf.close(); + + // extract resources and put them into the hashtable. + FileInputStream fis = new FileInputStream(jarFileName); + BufferedInputStream bis = new BufferedInputStream(fis); + ZipInputStream zis = new ZipInputStream(bis); + ZipEntry ze = null; + while ((ze = zis.getNextEntry()) != null) { + if (ze.isDirectory()) { + continue; + } + if (debugOn) { + System.out.println( + "ze.getName()=" + ze.getName() + "," + "getSize()=" + ze.getSize() + ); + } + int size = (int) ze.getSize(); + // -1 means unknown size. + if (size == -1) { + size = ((Integer) htSizes.get(ze.getName())).intValue(); + } + byte[] b = new byte[(int) size]; + int rb = 0; + int chunk = 0; + while (((int) size - rb) > 0) { + chunk = zis.read(b, rb, (int) size - rb); + if (chunk == -1) { + break; + } + rb += chunk; + } + // add to internal resource hashtable + htJarContents.put(ze.getName(), b); + if (debugOn) { + System.out.println( + ze.getName() + " rb=" + rb + + ",size=" + size + + ",csize=" + ze.getCompressedSize() + ); + } + } + } catch (NullPointerException e) { + System.out.println("done."); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Dumps a zip entry into a string. + * + * @param ze a ZipEntry + */ + private String dumpZipEntry(ZipEntry ze) { + StringBuffer sb = new StringBuffer(); + if (ze.isDirectory()) { + sb.append("d "); + } else { + sb.append("f "); + } + if (ze.getMethod() == ZipEntry.STORED) { + sb.append("stored "); + } else { + sb.append("defalted "); + } + sb.append(ze.getName()); + sb.append("\t"); + sb.append("" + ze.getSize()); + if (ze.getMethod() == ZipEntry.DEFLATED) { + sb.append("/" + ze.getCompressedSize()); + } + return (sb.toString()); + } + + + } +} \ No newline at end of file diff --git a/bwapi4/Position.java b/bwapi4/Position.java index 296e717..b4efd8e 100644 --- a/bwapi4/Position.java +++ b/bwapi4/Position.java @@ -30,8 +30,6 @@ public class Position extends AbstractPoint{ public native double getLength(); - public native boolean hasPath(Position position); - public int getX() { return x; } diff --git a/bwapi4/PositionOrUnit.java b/bwapi4/PositionOrUnit.java index 06301cc..b371c13 100644 --- a/bwapi4/PositionOrUnit.java +++ b/bwapi4/PositionOrUnit.java @@ -1,58 +1,55 @@ package bwapi4; -import bwapi4.*; - -import java.util.Map; -import java.util.HashMap; -import java.util.Collection; -import java.util.List; +import java.lang.IllegalArgumentException; +import java.lang.Object; +import java.lang.Override; public class PositionOrUnit { - public boolean isUnit() { - return isUnit_native(pointer); + private Unit unit; + + private Position position; + + public PositionOrUnit(Unit unit){ + if(unit == null){ + throw new IllegalArgumentException("PositionOrUnit must not reference null!"); + }; + this.unit = unit; } - public Unit getUnit() { - return getUnit_native(pointer); + public PositionOrUnit(Position position){ + if(position == null){ + throw new IllegalArgumentException("PositionOrUnit must not reference null!"); + }; + this.position = position; } - public boolean isPosition() { - return isPosition_native(pointer); + public Unit getUnit(){ + return unit; } public Position getPosition() { - return getPosition_native(pointer); + return position; } - - private static Map instances = new HashMap(); - - private PositionOrUnit(long pointer) { - this.pointer = pointer; + public boolean isUnit(){ + return unit != null; } - private static PositionOrUnit get(long pointer) { - if (pointer == 0 ) { - return null; - } - PositionOrUnit instance = instances.get(pointer); - if (instance == null ) { - instance = new PositionOrUnit(pointer); - instances.put(pointer, instance); - } - return instance; + public boolean isPosition(){ + return position != null; } - private long pointer; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PositionOrUnit)) return false; - private native boolean isUnit_native(long pointer); + PositionOrUnit that = (PositionOrUnit) o; - private native Unit getUnit_native(long pointer); + if (position != null ? !position.equals(that.position) : that.position != null) return false; + if (unit != null ? !unit.equals(that.unit) : that.unit != null) return false; - private native boolean isPosition_native(long pointer); - - private native Position getPosition_native(long pointer); - - -} + return true; + } +} \ No newline at end of file diff --git a/bwapi4/TilePosition.java b/bwapi4/TilePosition.java index a5d85c3..711ee06 100644 --- a/bwapi4/TilePosition.java +++ b/bwapi4/TilePosition.java @@ -9,7 +9,7 @@ import java.util.Map; * These are called build tiles because buildability data is available at this resolution, and correspond to the tiles seen in game. * For example, a Command Center occupies an area of 4x3 build tiles. */ -public class TilePosition { +public class TilePosition extends AbstractPoint{ private int x, y; public TilePosition(int x, int y) { @@ -21,8 +21,6 @@ public class TilePosition { return "[" + x + ", " + y + "]"; } - public native boolean hasPath(TilePosition position); - public native boolean isValid(); public native TilePosition makeValid(); @@ -82,4 +80,8 @@ public class TilePosition { result = 31 * result + y; return result; } + + public TilePosition getPoint(){ + return this; + } } \ No newline at end of file diff --git a/bwapi4/Unitset.java b/bwapi4/Unitset.java index 122a85f..eda3f72 100644 --- a/bwapi4/Unitset.java +++ b/bwapi4/Unitset.java @@ -25,18 +25,6 @@ public class Unitset { return getLarva_native(pointer); } - public void setClientInfo(int clientInfo) { - setClientInfo_native(pointer, clientInfo); - } - - public void setClientInfo() { - setClientInfo_native(pointer); - } - - public void setClientInfo(int clientInfo, int index) { - setClientInfo_native(pointer, clientInfo, index); - } - public List getUnitsInRadius(int radius, UnitFilter pred) { return getUnitsInRadius_native(pointer, radius, pred); } @@ -278,12 +266,6 @@ public class Unitset { private native List getLarva_native(long pointer); - private native void setClientInfo_native(long pointer, int clientInfo); - - private native void setClientInfo_native(long pointer); - - private native void setClientInfo_native(long pointer, int clientInfo, int index); - private native List getUnitsInRadius_native(long pointer, int radius, UnitFilter pred); private native Unit getClosestUnit_native(long pointer, UnitFilter pred); diff --git a/bwapi4/Utils.java b/bwapi4/Utils.java new file mode 100644 index 0000000..1a6154c --- /dev/null +++ b/bwapi4/Utils.java @@ -0,0 +1,52 @@ +package bwapi4; + +import java.lang.String; +import java.lang.System; + +/** + * + */ +public class Utils { + + public static final byte Previous = 0x01; + public static final byte Cyan = 0x02; + public static final byte Yellow = 0x03; + public static final byte White = 0x04; + public static final byte Grey = 0x05; + public static final byte Red = 0x06; + public static final byte Green = 0x07; + public static final byte Red_P1 = 0x08; + public static final byte Tab = 0x09; + public static final byte Newline = 0x0A; + public static final byte Invisible_no_override = 0x0B; + public static final byte Remove_beyond = 0x0C; + public static final byte Clear_formatting = 0x0D; + public static final byte Blue = 0x0E; + public static final byte Teal = 0x0F; + public static final byte Purple = 0x10; + public static final byte Orange = 0x11; + public static final byte Right_Align = 0x12; + public static final byte Center_Align = 0x13; + public static final byte Invisible = 0x14; + public static final byte Brown = 0x15; + public static final byte White_p7 = 0x16; + public static final byte Yellow_p8 = 0x17; + public static final byte Green_p9 = 0x18; + public static final byte Brighter_Yellow = 0x19; + public static final byte Cyan_default = 0x1A; + public static final byte Pinkish = 0x1B; + public static final byte Dark_Cyan = 0x1C; + public static final byte Greygreen = 0x1D; + public static final byte Bluegrey = 0x1E; + public static final byte Turquoise = 0x1F; + + public static String formatText(String text, byte format){ + byte[] textData = text.getBytes(); + int textDataLength = text.length(); + + byte[] newTextData = new byte[textDataLength + 1]; + newTextData[0] = format; + System.arraycopy(textData, 0, newTextData, 1, textDataLength); + return new String(newTextData); + } +} \ No newline at end of file diff --git a/bwapi4/WalkPosition.java b/bwapi4/WalkPosition.java index c7696e8..22a35f6 100644 --- a/bwapi4/WalkPosition.java +++ b/bwapi4/WalkPosition.java @@ -4,7 +4,7 @@ import java.lang.Override; import java.util.HashMap; import java.util.Map; -public class WalkPosition { +public class WalkPosition extends AbstractPoint{ private int x, y; @@ -27,8 +27,6 @@ public class WalkPosition { public native double getLength(); - public native boolean hasPath(WalkPosition position); - public int getX() { return x; } @@ -80,4 +78,8 @@ public class WalkPosition { } private long pointer; + + public WalkPosition getPoint(){ + return this; + } } \ No newline at end of file diff --git a/c4/impl.cpp b/c4/impl.cpp index d78ed45..f210c8a 100644 --- a/c4/impl.cpp +++ b/c4/impl.cpp @@ -1,6 +1,8 @@ #include "../concat_header.h" #include #include +#include +#include #include #include #include "../BWTA_Result.h" @@ -63,86 +65,21 @@ jfieldID FindCachedField(JNIEnv * env, jclass clz, string name, string signature using namespace BWAPI; -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onStart_1native(JNIEnv * env, jobject obj, jlong pointer){ -AIModule* x_aIModule = (AIModule*)pointer; -x_aIModule->onStart(); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onEnd_1native(JNIEnv * env, jobject obj, jlong pointer, jboolean isWinner){ -AIModule* x_aIModule = (AIModule*)pointer; -x_aIModule->onEnd((bool)isWinner); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onFrame_1native(JNIEnv * env, jobject obj, jlong pointer){ -AIModule* x_aIModule = (AIModule*)pointer; -x_aIModule->onFrame(); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSendText_1native(JNIEnv * env, jobject obj, jlong pointer, jstring text){ -AIModule* x_aIModule = (AIModule*)pointer; -x_aIModule->onSendText(std::string(env->GetStringUTFChars(text, NULL))); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onReceiveText_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_player, jstring text){ -AIModule* x_aIModule = (AIModule*)pointer; -Player player = (Player)env->GetLongField(p_player, FindCachedField(env, env->GetObjectClass(p_player), "pointer", "J")); -x_aIModule->onReceiveText(player, std::string(env->GetStringUTFChars(text, NULL))); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onPlayerLeft_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_player){ -AIModule* x_aIModule = (AIModule*)pointer; -Player player = (Player)env->GetLongField(p_player, FindCachedField(env, env->GetObjectClass(p_player), "pointer", "J")); -x_aIModule->onPlayerLeft(player); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onNukeDetect_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ -AIModule* x_aIModule = (AIModule*)pointer; -Position target((int)env->GetIntField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "x", "I")), (int)env->GetIntField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "y", "I"))); -x_aIModule->onNukeDetect(target); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDiscover_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitDiscover(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitEvade_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitEvade(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitShow_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitShow(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitHide_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitHide(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitCreate_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitCreate(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDestroy_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitDestroy(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitMorph_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitMorph(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitRenegade_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitRenegade(unit); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSaveGame_1native(JNIEnv * env, jobject obj, jlong pointer, jstring gameName){ -AIModule* x_aIModule = (AIModule*)pointer; -x_aIModule->onSaveGame(std::string(env->GetStringUTFChars(gameName, NULL))); -} -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitComplete_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_unit){ -AIModule* x_aIModule = (AIModule*)pointer; -Unit unit = (Unit)env->GetLongField(p_unit, FindCachedField(env, env->GetObjectClass(p_unit), "pointer", "J")); -x_aIModule->onUnitComplete(unit); +PositionOrUnit convertPositionOrUnit(JNIEnv * env, jobject obj){ + jclass clz = FindCachedClass(env, "PositionOrUnit"); + jmethodID typeMethodId = FindCachedMethod(env, clz, "isUnit", "()Z"); + bool isUnit = (bool)env->CallBooleanMethod(obj, typeMethodId); + if(isUnit){ + jobject unitObj = env->CallObjectMethod(obj, FindCachedMethod(env, clz, "getUnit", "()Lbwapi4/Unit;")); + Unit unit = (Unit)env->GetLongField(unitObj, FindCachedField(env, env->GetObjectClass(unitObj), "unitObj", "J")); + return PositionOrUnit(unit); + } + jobject posObj = env->CallObjectMethod(obj, FindCachedMethod(env, clz, "getPosition", "()Lbwapi4/Position;")); + Position position((int)env->GetIntField(posObj, FindCachedField(env, env->GetObjectClass(posObj), "x", "I")), (int)env->GetIntField(posObj, FindCachedField(env, env->GetObjectClass(posObj), "y", "I"))); + return PositionOrUnit(position); } + + JNIEXPORT jint JNICALL Java_bwapi4_Bullet_getID_1native(JNIEnv * env, jobject obj, jlong pointer){ Bullet x_bullet = (Bullet)pointer; return x_bullet->getID(); @@ -236,18 +173,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Client_update_1native(JNIEnv * env, jobject o Client* x_client = (Client*)pointer; x_client->update(); } -JNIEXPORT jint JNICALL Java_bwapi4_Color_red_1native(JNIEnv * env, jobject obj, jlong pointer){ -Color x_color((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "r", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "g", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "b", "I"))); -return x_color.red(); -} -JNIEXPORT jint JNICALL Java_bwapi4_Color_green_1native(JNIEnv * env, jobject obj, jlong pointer){ -Color x_color((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "r", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "g", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "b", "I"))); -return x_color.green(); -} -JNIEXPORT jint JNICALL Java_bwapi4_Color_blue_1native(JNIEnv * env, jobject obj, jlong pointer){ -Color x_color((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "r", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "g", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "b", "I"))); -return x_color.blue(); -} JNIEXPORT jobject JNICALL Java_bwapi4_Event_getPosition_1native(JNIEnv * env, jobject obj, jlong pointer){ Event* x_evt = (Event*)pointer; Position cresult = x_evt->getPosition(); @@ -818,7 +743,7 @@ return x_game->isWalkable(walkX, walkY); } JNIEXPORT jboolean JNICALL Java_bwapi4_Game_isWalkable_1native__JLbwapi4_WalkPosition_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_position){ Game* x_game = (Game*)pointer; -WalkPosition position = (WalkPosition)env->GetLongField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "pointer", "J")); +WalkPosition position((int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "x", "I")), (int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "y", "I"))); return x_game->isWalkable(position); } JNIEXPORT jboolean JNICALL Java_bwapi4_Game_isBuildable_1native__JII(JNIEnv * env, jobject obj, jlong pointer, jint tileX, jint tileY){ @@ -995,29 +920,14 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_printf_1native(JNIEnv * env, jobject obj Game* x_game = (Game*)pointer; x_game->printf(std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str()); } -JNIEXPORT void JNICALL Java_bwapi4_Game_vPrintf_1native(JNIEnv * env, jobject obj, jlong pointer, jstring cstr_format, jobject p_...){ -Game* x_game = (Game*)pointer; -Object ... = (Object)env->GetLongField(p_..., FindCachedField(env, env->GetObjectClass(p_...), "pointer", "J")); -x_game->vPrintf(std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str(), ...); -} JNIEXPORT void JNICALL Java_bwapi4_Game_sendText_1native(JNIEnv * env, jobject obj, jlong pointer, jstring cstr_format){ Game* x_game = (Game*)pointer; x_game->sendText(std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str()); } -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendText_1native(JNIEnv * env, jobject obj, jlong pointer, jstring cstr_format, jobject p_...){ -Game* x_game = (Game*)pointer; -Object ... = (Object)env->GetLongField(p_..., FindCachedField(env, env->GetObjectClass(p_...), "pointer", "J")); -x_game->vSendText(std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str(), ...); -} JNIEXPORT void JNICALL Java_bwapi4_Game_sendTextEx_1native(JNIEnv * env, jobject obj, jlong pointer, jboolean toAllies, jstring cstr_format){ Game* x_game = (Game*)pointer; x_game->sendTextEx((bool)toAllies, std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str()); } -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendTextEx_1native(JNIEnv * env, jobject obj, jlong pointer, jboolean toAllies, jstring cstr_format, jobject p_...){ -Game* x_game = (Game*)pointer; -Object ... = (Object)env->GetLongField(p_..., FindCachedField(env, env->GetObjectClass(p_...), "pointer", "J")); -x_game->vSendTextEx((bool)toAllies, std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str(), ...); -} JNIEXPORT jboolean JNICALL Java_bwapi4_Game_isInGame_1native(JNIEnv * env, jobject obj, jlong pointer){ Game* x_game = (Game*)pointer; return x_game->isInGame(); @@ -1159,18 +1069,12 @@ x_game->setTextSize(); } JNIEXPORT void JNICALL Java_bwapi4_Game_setTextSize_1native__JLbwapi4_Text_Size_Enum_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_size){ Game* x_game = (Game*)pointer; -bwapi4.Text.Size.Enum size = (bwapi4.Text.Size.Enum)env->GetLongField(p_size, FindCachedField(env, env->GetObjectClass(p_size), "pointer", "J")); +Text::Size::Enum size; x_game->setTextSize(size); } -JNIEXPORT void JNICALL Java_bwapi4_Game_vDrawText_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jstring cstr_format, jobject p_...){ -Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); -Object ... = (Object)env->GetLongField(p_..., FindCachedField(env, env->GetObjectClass(p_...), "pointer", "J")); -x_game->vDrawText(ctype, x, y, std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str(), ...); -} JNIEXPORT void JNICALL Java_bwapi4_Game_drawText_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jstring cstr_format){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; x_game->drawText(ctype, x, y, std::string(env->GetStringUTFChars(cstr_format, NULL)).c_str()); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawTextMap_1native__JIILjava_lang_String_2(JNIEnv * env, jobject obj, jlong pointer, jint x, jint y, jstring cstr_format){ @@ -1202,13 +1106,13 @@ x_game->drawTextScreen(p, std::string(env->GetStringUTFChars(cstr_format, NULL)) } JNIEXPORT void JNICALL Java_bwapi4_Game_drawBox_1native__JLbwapi4_CoordinateType_Enum_2IIIILbwapi4_Color_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint left, jint top, jint right, jint bottom, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawBox(ctype, left, top, right, bottom, color); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawBox_1native__JLbwapi4_CoordinateType_Enum_2IIIILbwapi4_Color_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint left, jint top, jint right, jint bottom, jobject p_color, jboolean isSolid){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawBox(ctype, left, top, right, bottom, color, (bool)isSolid); } @@ -1286,13 +1190,13 @@ x_game->drawBoxScreen(leftTop, rightBottom, color, (bool)isSolid); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawTriangle_1native__JLbwapi4_CoordinateType_Enum_2IIIIIILbwapi4_Color_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint ax, jint ay, jint bx, jint by, jint cx, jint cy, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawTriangle(ctype, ax, ay, bx, by, cx, cy, color); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawTriangle_1native__JLbwapi4_CoordinateType_Enum_2IIIIIILbwapi4_Color_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint ax, jint ay, jint bx, jint by, jint cx, jint cy, jobject p_color, jboolean isSolid){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawTriangle(ctype, ax, ay, bx, by, cx, cy, color, (bool)isSolid); } @@ -1376,13 +1280,13 @@ x_game->drawTriangleScreen(a, b, c, color, (bool)isSolid); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawCircle_1native__JLbwapi4_CoordinateType_Enum_2IIILbwapi4_Color_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jint radius, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawCircle(ctype, x, y, radius, color); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawCircle_1native__JLbwapi4_CoordinateType_Enum_2IIILbwapi4_Color_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jint radius, jobject p_color, jboolean isSolid){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawCircle(ctype, x, y, radius, color, (bool)isSolid); } @@ -1454,13 +1358,13 @@ x_game->drawCircleScreen(p, radius, color, (bool)isSolid); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawEllipse_1native__JLbwapi4_CoordinateType_Enum_2IIIILbwapi4_Color_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jint xrad, jint yrad, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawEllipse(ctype, x, y, xrad, yrad, color); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawEllipse_1native__JLbwapi4_CoordinateType_Enum_2IIIILbwapi4_Color_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jint xrad, jint yrad, jobject p_color, jboolean isSolid){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawEllipse(ctype, x, y, xrad, yrad, color, (bool)isSolid); } @@ -1532,7 +1436,7 @@ x_game->drawEllipseScreen(p, xrad, yrad, color, (bool)isSolid); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawDot_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x, jint y, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawDot(ctype, x, y, color); } @@ -1571,7 +1475,7 @@ x_game->drawDotScreen(p, color); } JNIEXPORT void JNICALL Java_bwapi4_Game_drawLine_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_ctype, jint x1, jint y1, jint x2, jint y2, jobject p_color){ Game* x_game = (Game*)pointer; -bwapi4.CoordinateType.Enum ctype = (bwapi4.CoordinateType.Enum)env->GetLongField(p_ctype, FindCachedField(env, env->GetObjectClass(p_ctype), "pointer", "J")); +CoordinateType::Enum ctype; Color color((int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "r", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "g", "I")), (int)env->GetIntField(p_color, FindCachedField(env, env->GetObjectClass(p_color), "b", "I"))); x_game->drawLine(ctype, x1, y1, x2, y2, color); } @@ -1809,10 +1713,6 @@ Player toPlayer = (Player)env->GetLongField(p_toPlayer, FindCachedField(env, env Player fromPlayer = (Player)env->GetLongField(p_fromPlayer, FindCachedField(env, env->GetObjectClass(p_fromPlayer), "pointer", "J")); return x_game->getDamageTo(toType, fromType, toPlayer, fromPlayer); } -JNIEXPORT void JNICALL Java_bwapi4_GameWrapper_flush_1native(JNIEnv * env, jobject obj, jlong pointer){ -GameWrapper x_gameWrapper = (GameWrapper)pointer; -x_gameWrapper->flush(); -} JNIEXPORT jint JNICALL Java_bwapi4_Player_getID_1native(JNIEnv * env, jobject obj, jlong pointer){ Player x_player = (Player)pointer; return x_player->getID(); @@ -2121,14 +2021,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Playerset_setAlliance_1native__JZZ(JNIEnv * e Playerset* x_playerset = (Playerset*)pointer; x_playerset->setAlliance((bool)allies, (bool)alliedVictory); } -JNIEXPORT jboolean JNICALL Java_bwapi4_Point_isValid_1native(JNIEnv * env, jobject obj, jlong pointer){ -Point x_point = (Point)pointer; -return x_point->isValid(); -} -JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getLength_1native(JNIEnv * env, jobject obj, jlong pointer){ -Point x_point = (Point)pointer; -return x_point->getLength(); -} JNIEXPORT jboolean JNICALL Java_bwapi4_Position_isValid(JNIEnv * env, jobject obj){ Position x_position((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); return x_position.isValid(); @@ -2155,34 +2047,6 @@ JNIEXPORT jdouble JNICALL Java_bwapi4_Position_getLength(JNIEnv * env, jobject o Position x_position((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); return x_position.getLength(); } -JNIEXPORT jboolean JNICALL Java_bwapi4_Position_hasPath(JNIEnv * env, jobject obj, jobject p_position){ -Position x_position((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); -Position position((int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "x", "I")), (int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "y", "I"))); -return x_position.hasPath(position); -} -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isUnit_1native(JNIEnv * env, jobject obj, jlong pointer){ -PositionOrUnit x_positionOrUnit = (PositionOrUnit)pointer; -return x_positionOrUnit->isUnit(); -} -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getUnit_1native(JNIEnv * env, jobject obj, jlong pointer){ -PositionOrUnit x_positionOrUnit = (PositionOrUnit)pointer; -jlong resptr = (jlong)x_positionOrUnit->getUnit(); -jclass retcls = FindCachedClass(env, "bwapi4/Unit"); -jmethodID mid = FindCachedMethodStatic(env, retcls, "get", "(J)Lbwapi4/Unit;"); -return env->CallStaticObjectMethod(retcls, mid, resptr); -} -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isPosition_1native(JNIEnv * env, jobject obj, jlong pointer){ -PositionOrUnit x_positionOrUnit = (PositionOrUnit)pointer; -return x_positionOrUnit->isPosition(); -} -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getPosition_1native(JNIEnv * env, jobject obj, jlong pointer){ -PositionOrUnit x_positionOrUnit = (PositionOrUnit)pointer; -Position cresult = x_positionOrUnit->getPosition(); -jclass retcls = FindCachedClass(env, "bwapi/Position"); -jmethodID retConsID = FindCachedMethod(env, retcls, "", "(II)V"); -jobject result = env->NewObject(retcls, retConsID, cresult.x, cresult.y); -return result; -} JNIEXPORT jint JNICALL Java_bwapi4_Region_getID_1native(JNIEnv * env, jobject obj, jlong pointer){ Region x_region = (Region)pointer; return x_region->getID(); @@ -2286,11 +2150,6 @@ env->CallVoidMethod(result, addMethodID, elem); } return result; } -JNIEXPORT jboolean JNICALL Java_bwapi4_TilePosition_hasPath(JNIEnv * env, jobject obj, jobject p_position){ -TilePosition x_tilePosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); -TilePosition position((int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "x", "I")), (int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "y", "I"))); -return x_tilePosition.hasPath(position); -} JNIEXPORT jboolean JNICALL Java_bwapi4_TilePosition_isValid(JNIEnv * env, jobject obj){ TilePosition x_tilePosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); return x_tilePosition.isValid(); @@ -2411,12 +2270,12 @@ return x_unit->getResourceGroup(); } JNIEXPORT jint JNICALL Java_bwapi4_Unit_getDistance_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->getDistance(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_hasPath_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->hasPath(target); } JNIEXPORT jint JNICALL Java_bwapi4_Unit_getLastCommandFrame_1native(JNIEnv * env, jobject obj, jlong pointer){ @@ -3013,12 +2872,12 @@ return x_unit->issueCommand(command); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_attack_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->attack(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_attack_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean shiftQueueCommand){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->attack(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_build_1native__JLbwapi4_UnitType_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_type){ @@ -3063,7 +2922,7 @@ return x_unit->upgrade(upgrade); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_setRallyPoint_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->setRallyPoint(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_move_1native__JLbwapi4_Position_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ @@ -3208,12 +3067,12 @@ return x_unit->unloadAll(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_rightClick_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->rightClick(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_rightClick_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean shiftQueueCommand){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->rightClick(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_haltConstruction_1native(JNIEnv * env, jobject obj, jlong pointer){ @@ -3256,7 +3115,7 @@ return x_unit->useTech(tech); JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_useTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->useTech(tech, target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_placeCOP_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ @@ -3391,22 +3250,22 @@ return x_unit->canAttack((bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttack_1native__JLbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttack(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttack_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttack(target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttack_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttack(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttack_1native__JLbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttack(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JZ(JNIEnv * env, jobject obj, jlong pointer, jboolean checkCommandibilityGrouped){ @@ -3423,27 +3282,27 @@ return x_unit->canAttackGrouped((bool)checkCommandibilityGrouped, (bool)checkCom } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JLbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibilityGrouped){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttackGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibilityGrouped); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JLbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttackGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttackGrouped(target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttackGrouped(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackGrouped_1native__JLbwapi4_PositionOrUnit_2ZZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibilityGrouped, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canAttackGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibilityGrouped, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canAttackMove_1native__J(JNIEnv * env, jobject obj, jlong pointer){ @@ -3693,22 +3552,22 @@ return x_unit->canSetRallyPoint((bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canSetRallyPoint_1native__JLbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canSetRallyPoint(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canSetRallyPoint_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canSetRallyPoint(target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canSetRallyPoint_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canSetRallyPoint(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canSetRallyPoint_1native__JLbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canSetRallyPoint(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canSetRallyPosition_1native__J(JNIEnv * env, jobject obj, jlong pointer){ @@ -4099,22 +3958,22 @@ return x_unit->canRightClick((bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClick_1native__JLbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClick(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClick_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClick(target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClick_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClick(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClick_1native__JLbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClick(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JZ(JNIEnv * env, jobject obj, jlong pointer, jboolean checkCommandibilityGrouped){ @@ -4131,27 +3990,27 @@ return x_unit->canRightClickGrouped((bool)checkCommandibilityGrouped, (bool)chec } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JLbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibilityGrouped){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClickGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibilityGrouped); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JLbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClickGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClickGrouped(target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClickGrouped(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickGrouped_1native__JLbwapi4_PositionOrUnit_2ZZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean checkCanTargetUnit, jboolean checkCanIssueCommandType, jboolean checkCommandibilityGrouped, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canRightClickGrouped(target, (bool)checkCanTargetUnit, (bool)checkCanIssueCommandType, (bool)checkCommandibilityGrouped, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canRightClickPosition_1native__J(JNIEnv * env, jobject obj, jlong pointer){ @@ -4341,25 +4200,25 @@ return x_unit->canUseTechWithOrWithoutTarget(tech, (bool)checkCanIssueCommandTyp JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2ZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target, jboolean checkCanTargetUnit, jboolean checkTargetsType, jboolean checkCanIssueCommandType){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canUseTech(tech, target, (bool)checkCanTargetUnit, (bool)checkTargetsType, (bool)checkCanIssueCommandType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2ZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target, jboolean checkCanTargetUnit, jboolean checkTargetsType){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canUseTech(tech, target, (bool)checkCanTargetUnit, (bool)checkTargetsType); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target, jboolean checkCanTargetUnit){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canUseTech(tech, target, (bool)checkCanTargetUnit); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canUseTech(tech, target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech){ @@ -4370,7 +4229,7 @@ return x_unit->canUseTech(tech); JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2ZZZZ(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target, jboolean checkCanTargetUnit, jboolean checkTargetsType, jboolean checkCanIssueCommandType, jboolean checkCommandibility){ Unit x_unit = (Unit)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unit->canUseTech(tech, target, (bool)checkCanTargetUnit, (bool)checkTargetsType, (bool)checkCanIssueCommandType, (bool)checkCommandibility); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unit_canUseTechWithoutTarget_1native__JLbwapi4_TechType_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jboolean checkCanIssueCommandType){ @@ -4555,18 +4414,6 @@ env->CallVoidMethod(result, addMethodID, elem); } return result; } -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JI(JNIEnv * env, jobject obj, jlong pointer, jint clientInfo){ -Unitset* x_unitset = (Unitset*)pointer; -x_unitset->setClientInfo(clientInfo); -} -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__J(JNIEnv * env, jobject obj, jlong pointer){ -Unitset* x_unitset = (Unitset*)pointer; -x_unitset->setClientInfo(); -} -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JII(JNIEnv * env, jobject obj, jlong pointer, jint clientInfo, jint index){ -Unitset* x_unitset = (Unitset*)pointer; -x_unitset->setClientInfo(clientInfo, index); -} JNIEXPORT jobject JNICALL Java_bwapi4_Unitset_getUnitsInRadius_1native(JNIEnv * env, jobject obj, jlong pointer, jint radius, jobject p_pred){ Unitset* x_unitset = (Unitset*)pointer; UnitFilter pred = (UnitFilter)env->GetLongField(p_pred, FindCachedField(env, env->GetObjectClass(p_pred), "pointer", "J")); @@ -4606,12 +4453,12 @@ return x_unitset->issueCommand(command); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_attack_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unitset* x_unitset = (Unitset*)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->attack(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_attack_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean shiftQueueCommand){ Unitset* x_unitset = (Unitset*)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->attack(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_build_1native__JLbwapi4_UnitType_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_type){ @@ -4642,7 +4489,7 @@ return x_unitset->morph(type); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_setRallyPoint_1native(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unitset* x_unitset = (Unitset*)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->setRallyPoint(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_move_1native__JLbwapi4_Position_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ @@ -4777,12 +4624,12 @@ return x_unitset->unloadAll(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_rightClick_1native__JLbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_target){ Unitset* x_unitset = (Unitset*)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->rightClick(target); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_rightClick_1native__JLbwapi4_PositionOrUnit_2Z(JNIEnv * env, jobject obj, jlong pointer, jobject p_target, jboolean shiftQueueCommand){ Unitset* x_unitset = (Unitset*)pointer; -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->rightClick(target, (bool)shiftQueueCommand); } JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_haltConstruction_1native(JNIEnv * env, jobject obj, jlong pointer){ @@ -4825,43 +4672,39 @@ return x_unitset->useTech(tech); JNIEXPORT jboolean JNICALL Java_bwapi4_Unitset_useTech_1native__JLbwapi4_TechType_2Lbwapi4_PositionOrUnit_2(JNIEnv * env, jobject obj, jlong pointer, jobject p_tech, jobject p_target){ Unitset* x_unitset = (Unitset*)pointer; TechType tech = (TechType)env->GetLongField(p_tech, FindCachedField(env, env->GetObjectClass(p_tech), "pointer", "J")); -PositionOrUnit target = (PositionOrUnit)env->GetLongField(p_target, FindCachedField(env, env->GetObjectClass(p_target), "pointer", "J")); +PositionOrUnit target(convertPositionOrUnit(env, p_target )); return x_unitset->useTech(tech, target); } JNIEXPORT jboolean JNICALL Java_bwapi4_WalkPosition_isValid(JNIEnv * env, jobject obj){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -return x_walkPosition->isValid(); +WalkPosition x_walkPosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); +return x_walkPosition.isValid(); } JNIEXPORT jobject JNICALL Java_bwapi4_WalkPosition_makeValid(JNIEnv * env, jobject obj){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -jlong resptr = (jlong)x_walkPosition->makeValid(); +WalkPosition x_walkPosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); +WalkPosition cresult = x_walkPosition.makeValid(); jclass retcls = FindCachedClass(env, "bwapi4/WalkPosition"); -jmethodID mid = FindCachedMethodStatic(env, retcls, "get", "(J)Lbwapi4/WalkPosition;"); -return env->CallStaticObjectMethod(retcls, mid, resptr); +jmethodID retConsID = FindCachedMethod(env, retcls, "", "(II)V"); +jobject result = env->NewObject(retcls, retConsID, cresult.x, cresult.y); +return result; } JNIEXPORT jdouble JNICALL Java_bwapi4_WalkPosition_getDistance(JNIEnv * env, jobject obj, jobject p_position){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -WalkPosition position = (WalkPosition)env->GetLongField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "pointer", "J")); -return x_walkPosition->getDistance(position); +WalkPosition x_walkPosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); +WalkPosition position((int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "x", "I")), (int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "y", "I"))); +return x_walkPosition.getDistance(position); } JNIEXPORT jint JNICALL Java_bwapi4_WalkPosition_getApproxDistance(JNIEnv * env, jobject obj, jobject p_position){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -WalkPosition position = (WalkPosition)env->GetLongField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "pointer", "J")); -return x_walkPosition->getApproxDistance(position); +WalkPosition x_walkPosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); +WalkPosition position((int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "x", "I")), (int)env->GetIntField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "y", "I"))); +return x_walkPosition.getApproxDistance(position); } JNIEXPORT jdouble JNICALL Java_bwapi4_WalkPosition_getLength(JNIEnv * env, jobject obj){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -return x_walkPosition->getLength(); -} -JNIEXPORT jboolean JNICALL Java_bwapi4_WalkPosition_hasPath(JNIEnv * env, jobject obj, jobject p_position){ -WalkPosition x_walkPosition = (WalkPosition)pointer; -WalkPosition position = (WalkPosition)env->GetLongField(p_position, FindCachedField(env, env->GetObjectClass(p_position), "pointer", "J")); -return x_walkPosition->hasPath(position); +WalkPosition x_walkPosition((int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "x", "I")), (int)env->GetIntField(obj, FindCachedField(env, env->GetObjectClass(obj), "y", "I"))); +return x_walkPosition.getLength(); } void reconnect() { while (!BWAPIClient.connect()) { - Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds{ 1000 }); } } @@ -4878,9 +4721,6 @@ void println(const char * text){ } JNIEXPORT void JNICALL Java_bwapi_Mirror_startGame(JNIEnv * env, jobject obj){ -println("Attempting to init BWAPI..."); - BWAPI_init(); - println("BWAPI ready."); jclass cls; jmethodID getId; cls = env->FindClass("Lbwapi/BulletType;"); @@ -6414,7 +6254,7 @@ println("Connecting to Broodwar..."); jclass posCls = env->FindClass("Lbwapi/Position;"); jobject moduleObj = env->GetObjectField(obj, env->GetFieldID(cls, "module", "Lbwapi/AIModule;")); jclass moduleCls = env->GetObjectClass(moduleObj); - env->SetObjectField(obj, env->GetFieldID(cls, "game", "Lbwapi/Game;"), env->CallStaticObjectMethod(gamecls, env->GetStaticMethodID(gamecls, "get", "(J)Lbwapi/Game;"), (long)Broodwarptr)); + env->SetObjectField(obj, env->GetFieldID(cls, "game", "Lbwapi/Game;"), env->CallStaticObjectMethod(gamecls, env->GetStaticMethodID(gamecls, "get", "(J)Lbwapi/Game;"), (long)&Broodwar)); jmethodID updateMethodID = env->GetMethodID(env->GetObjectClass(obj), "update", "()V"); jmethodID matchStartCallback = env->GetMethodID(moduleCls, "onStart", "()V"); @@ -6436,17 +6276,16 @@ println("Connecting to Broodwar..."); jmethodID unitCompleteCallback = env->GetMethodID(moduleCls, "onUnitComplete", "(Lbwapi/Unit;)V"); jmethodID playerDroppedCallback = env->GetMethodID(moduleCls, "onPlayerDropped", "(Lbwapi/Player;)V"); while (true) { - if (Broodwarptr != NULL) { - println("Waiting..."); - while (!Broodwarptr->isInGame()) { - BWAPIClient.update(); - if (Broodwarptr == NULL) { - println("Match ended."); - return; - } - } - } + println("Waiting...");while ( !Broodwar->isInGame() ) + { + BWAPI::BWAPIClient.update(); + if (!BWAPI::BWAPIClient.isConnected()) + { + println("Reconnecting..."); + reconnect(); + } + } println("Game ready!!!"); while (Broodwar->isInGame()) { @@ -6521,7 +6360,7 @@ println("Connecting to Broodwar..."); println("Reconnecting..."); reconnect(); } - } +println("Match ended."); } } } diff --git a/compiled4/bwapi4/AIModule.class b/compiled4/bwapi4/AIModule.class index 62d94c7..047688a 100644 Binary files a/compiled4/bwapi4/AIModule.class and b/compiled4/bwapi4/AIModule.class differ diff --git a/compiled4/bwapi4/BWEventListener.class b/compiled4/bwapi4/BWEventListener.class new file mode 100644 index 0000000..860e123 Binary files /dev/null and b/compiled4/bwapi4/BWEventListener.class differ diff --git a/compiled4/bwapi4/Color.class b/compiled4/bwapi4/Color.class index 8ca1194..91b657b 100644 Binary files a/compiled4/bwapi4/Color.class and b/compiled4/bwapi4/Color.class differ diff --git a/compiled4/bwapi4/DefaultBWListener.class b/compiled4/bwapi4/DefaultBWListener.class new file mode 100644 index 0000000..9d47d20 Binary files /dev/null and b/compiled4/bwapi4/DefaultBWListener.class differ diff --git a/compiled4/bwapi4/Game.class b/compiled4/bwapi4/Game.class index e7521c8..0696b3b 100644 Binary files a/compiled4/bwapi4/Game.class and b/compiled4/bwapi4/Game.class differ diff --git a/compiled4/bwapi4/Mirror$FrameCallback.class b/compiled4/bwapi4/Mirror$FrameCallback.class new file mode 100644 index 0000000..dd0833b Binary files /dev/null and b/compiled4/bwapi4/Mirror$FrameCallback.class differ diff --git a/compiled4/bwapi4/Mirror$JarResources.class b/compiled4/bwapi4/Mirror$JarResources.class new file mode 100644 index 0000000..71b664a Binary files /dev/null and b/compiled4/bwapi4/Mirror$JarResources.class differ diff --git a/compiled4/bwapi4/Mirror.class b/compiled4/bwapi4/Mirror.class new file mode 100644 index 0000000..8f709be Binary files /dev/null and b/compiled4/bwapi4/Mirror.class differ diff --git a/compiled4/bwapi4/Point.class b/compiled4/bwapi4/Point.class index f617b9b..0047a4f 100644 Binary files a/compiled4/bwapi4/Point.class and b/compiled4/bwapi4/Point.class differ diff --git a/compiled4/bwapi4/Position.class b/compiled4/bwapi4/Position.class index a4aa9aa..b4d7a53 100644 Binary files a/compiled4/bwapi4/Position.class and b/compiled4/bwapi4/Position.class differ diff --git a/compiled4/bwapi4/PositionOrUnit.class b/compiled4/bwapi4/PositionOrUnit.class index 61e786d..c044650 100644 Binary files a/compiled4/bwapi4/PositionOrUnit.class and b/compiled4/bwapi4/PositionOrUnit.class differ diff --git a/compiled4/bwapi4/TilePosition.class b/compiled4/bwapi4/TilePosition.class index 2bd0d86..3851e18 100644 Binary files a/compiled4/bwapi4/TilePosition.class and b/compiled4/bwapi4/TilePosition.class differ diff --git a/compiled4/bwapi4/Unitset.class b/compiled4/bwapi4/Unitset.class index 35322b6..7a90d6e 100644 Binary files a/compiled4/bwapi4/Unitset.class and b/compiled4/bwapi4/Unitset.class differ diff --git a/compiled4/bwapi4/Utils.class b/compiled4/bwapi4/Utils.class new file mode 100644 index 0000000..8ec0284 Binary files /dev/null and b/compiled4/bwapi4/Utils.class differ diff --git a/compiled4/bwapi4/WalkPosition.class b/compiled4/bwapi4/WalkPosition.class index 620f79a..b28de49 100644 Binary files a/compiled4/bwapi4/WalkPosition.class and b/compiled4/bwapi4/WalkPosition.class differ diff --git a/concat_header4.h b/concat_header4.h index 5a80927..156ebfe 100644 --- a/concat_header4.h +++ b/concat_header4.h @@ -18,142 +18,6 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_AIModule - * Method: onStart_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onStart_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_AIModule - * Method: onEnd_native - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onEnd_1native - (JNIEnv *, jobject, jlong, jboolean); - -/* - * Class: bwapi4_AIModule - * Method: onFrame_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onFrame_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_AIModule - * Method: onSendText_native - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSendText_1native - (JNIEnv *, jobject, jlong, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onReceiveText_native - * Signature: (JLbwapi4/Player;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onReceiveText_1native - (JNIEnv *, jobject, jlong, jobject, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onPlayerLeft_native - * Signature: (JLbwapi4/Player;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onPlayerLeft_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onNukeDetect_native - * Signature: (JLbwapi4/Position;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onNukeDetect_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitDiscover_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDiscover_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitEvade_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitEvade_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitShow_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitShow_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitHide_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitHide_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitCreate_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitCreate_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitDestroy_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDestroy_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitMorph_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitMorph_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitRenegade_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitRenegade_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onSaveGame_native - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSaveGame_1native - (JNIEnv *, jobject, jlong, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onUnitComplete_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitComplete_1native - (JNIEnv *, jobject, jlong, jobject); - #ifdef __cplusplus } #endif @@ -325,6 +189,17 @@ extern "C" { } #endif #endif +/* Header for class bwapi4_BWEventListener */ + +#ifndef _Included_bwapi4_BWEventListener +#define _Included_bwapi4_BWEventListener +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif /* Header for class bwapi4_CenteredObject */ #ifndef _Included_bwapi4_CenteredObject @@ -386,30 +261,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Client_update_1native #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_Color - * Method: red_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_red_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Color - * Method: green_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_green_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Color - * Method: blue_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_blue_1native - (JNIEnv *, jobject, jlong); - #ifdef __cplusplus } #endif @@ -436,6 +287,17 @@ extern "C" { } #endif #endif +/* Header for class bwapi4_DefaultBWListener */ + +#ifndef _Included_bwapi4_DefaultBWListener +#define _Included_bwapi4_DefaultBWListener +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif /* Header for class bwapi4_Error */ #ifndef _Included_bwapi4_Error @@ -1306,14 +1168,6 @@ JNIEXPORT jboolean JNICALL Java_bwapi4_Game_canUpgrade_1native__JLbwapi4_Upgrade JNIEXPORT void JNICALL Java_bwapi4_Game_printf_1native (JNIEnv *, jobject, jlong, jstring); -/* - * Class: bwapi4_Game - * Method: vPrintf_native - * Signature: (JLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vPrintf_1native - (JNIEnv *, jobject, jlong, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: sendText_native @@ -1322,14 +1176,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_vPrintf_1native JNIEXPORT void JNICALL Java_bwapi4_Game_sendText_1native (JNIEnv *, jobject, jlong, jstring); -/* - * Class: bwapi4_Game - * Method: vSendText_native - * Signature: (JLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendText_1native - (JNIEnv *, jobject, jlong, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: sendTextEx_native @@ -1338,14 +1184,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_vSendText_1native JNIEXPORT void JNICALL Java_bwapi4_Game_sendTextEx_1native (JNIEnv *, jobject, jlong, jboolean, jstring); -/* - * Class: bwapi4_Game - * Method: vSendTextEx_native - * Signature: (JZLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendTextEx_1native - (JNIEnv *, jobject, jlong, jboolean, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: isInGame_native @@ -1506,14 +1344,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_setTextSize_1native__J JNIEXPORT void JNICALL Java_bwapi4_Game_setTextSize_1native__JLbwapi4_Text_Size_Enum_2 (JNIEnv *, jobject, jlong, jobject); -/* - * Class: bwapi4_Game - * Method: vDrawText_native - * Signature: (JLbwapi4/CoordinateType/Enum;IILjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vDrawText_1native - (JNIEnv *, jobject, jlong, jobject, jint, jint, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: drawText_native @@ -2494,6 +2324,49 @@ JNIEXPORT void JNICALL Java_bwapi4_InterfaceEvent_removeEvent_1native #ifdef __cplusplus extern "C" { #endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class bwapi4_Mirror_FrameCallback */ + +#ifndef _Included_bwapi4_Mirror_FrameCallback +#define _Included_bwapi4_Mirror_FrameCallback +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class bwapi4_Mirror_JarResources */ + +#ifndef _Included_bwapi4_Mirror_JarResources +#define _Included_bwapi4_Mirror_JarResources +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class bwapi4_Mirror */ + +#ifndef _Included_bwapi4_Mirror +#define _Included_bwapi4_Mirror +#ifdef __cplusplus +extern "C" { +#endif +#undef bwapi4_Mirror_EXTRACT_JAR +#define bwapi4_Mirror_EXTRACT_JAR 1L +/* + * Class: bwapi4_Mirror + * Method: startGame + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_bwapi4_Mirror_startGame + (JNIEnv *, jobject); + #ifdef __cplusplus } #endif @@ -3074,19 +2947,35 @@ extern "C" { #endif /* * Class: bwapi4_Point - * Method: isValid_native - * Signature: (J)Z + * Method: isValid + * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_bwapi4_Point_isValid_1native - (JNIEnv *, jobject, jlong); +JNIEXPORT jboolean JNICALL Java_bwapi4_Point_isValid + (JNIEnv *, jobject); /* * Class: bwapi4_Point - * Method: getLength_native - * Signature: (J)D + * Method: makeValid + * Signature: ()Lbwapi4/Point; */ -JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getLength_1native - (JNIEnv *, jobject, jlong); +JNIEXPORT jobject JNICALL Java_bwapi4_Point_makeValid + (JNIEnv *, jobject); + +/* + * Class: bwapi4_Point + * Method: getDistance + * Signature: (Lbwapi4/Point;)D + */ +JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getDistance + (JNIEnv *, jobject, jobject); + +/* + * Class: bwapi4_Point + * Method: getLength + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getLength + (JNIEnv *, jobject); #ifdef __cplusplus } @@ -3139,14 +3028,6 @@ JNIEXPORT jint JNICALL Java_bwapi4_Position_getApproxDistance JNIEXPORT jdouble JNICALL Java_bwapi4_Position_getLength (JNIEnv *, jobject); -/* - * Class: bwapi4_Position - * Method: hasPath - * Signature: (Lbwapi4/Position;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_Position_hasPath - (JNIEnv *, jobject, jobject); - #ifdef __cplusplus } #endif @@ -3169,38 +3050,6 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_PositionOrUnit - * Method: isUnit_native - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isUnit_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: getUnit_native - * Signature: (J)Lbwapi4/Unit; - */ -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getUnit_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: isPosition_native - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isPosition_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: getPosition_native - * Signature: (J)Lbwapi4/Position; - */ -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getPosition_1native - (JNIEnv *, jobject, jlong); - #ifdef __cplusplus } #endif @@ -3384,14 +3233,6 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_TilePosition - * Method: hasPath - * Signature: (Lbwapi4/TilePosition;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_TilePosition_hasPath - (JNIEnv *, jobject, jobject); - /* * Class: bwapi4_TilePosition * Method: isValid @@ -7186,30 +7027,6 @@ JNIEXPORT jobject JNICALL Java_bwapi4_Unitset_getInterceptors_1native JNIEXPORT jobject JNICALL Java_bwapi4_Unitset_getLarva_1native (JNIEnv *, jobject, jlong); -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JI - (JNIEnv *, jobject, jlong, jint); - -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__J - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (JII)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JII - (JNIEnv *, jobject, jlong, jint, jint); - /* * Class: bwapi4_Unitset * Method: getUnitsInRadius_native @@ -7671,6 +7488,79 @@ extern "C" { } #endif #endif +/* Header for class bwapi4_Utils */ + +#ifndef _Included_bwapi4_Utils +#define _Included_bwapi4_Utils +#ifdef __cplusplus +extern "C" { +#endif +#undef bwapi4_Utils_Previous +#define bwapi4_Utils_Previous 1L +#undef bwapi4_Utils_Cyan +#define bwapi4_Utils_Cyan 2L +#undef bwapi4_Utils_Yellow +#define bwapi4_Utils_Yellow 3L +#undef bwapi4_Utils_White +#define bwapi4_Utils_White 4L +#undef bwapi4_Utils_Grey +#define bwapi4_Utils_Grey 5L +#undef bwapi4_Utils_Red +#define bwapi4_Utils_Red 6L +#undef bwapi4_Utils_Green +#define bwapi4_Utils_Green 7L +#undef bwapi4_Utils_Red_P1 +#define bwapi4_Utils_Red_P1 8L +#undef bwapi4_Utils_Tab +#define bwapi4_Utils_Tab 9L +#undef bwapi4_Utils_Newline +#define bwapi4_Utils_Newline 10L +#undef bwapi4_Utils_Invisible_no_override +#define bwapi4_Utils_Invisible_no_override 11L +#undef bwapi4_Utils_Remove_beyond +#define bwapi4_Utils_Remove_beyond 12L +#undef bwapi4_Utils_Clear_formatting +#define bwapi4_Utils_Clear_formatting 13L +#undef bwapi4_Utils_Blue +#define bwapi4_Utils_Blue 14L +#undef bwapi4_Utils_Teal +#define bwapi4_Utils_Teal 15L +#undef bwapi4_Utils_Purple +#define bwapi4_Utils_Purple 16L +#undef bwapi4_Utils_Orange +#define bwapi4_Utils_Orange 17L +#undef bwapi4_Utils_Right_Align +#define bwapi4_Utils_Right_Align 18L +#undef bwapi4_Utils_Center_Align +#define bwapi4_Utils_Center_Align 19L +#undef bwapi4_Utils_Invisible +#define bwapi4_Utils_Invisible 20L +#undef bwapi4_Utils_Brown +#define bwapi4_Utils_Brown 21L +#undef bwapi4_Utils_White_p7 +#define bwapi4_Utils_White_p7 22L +#undef bwapi4_Utils_Yellow_p8 +#define bwapi4_Utils_Yellow_p8 23L +#undef bwapi4_Utils_Green_p9 +#define bwapi4_Utils_Green_p9 24L +#undef bwapi4_Utils_Brighter_Yellow +#define bwapi4_Utils_Brighter_Yellow 25L +#undef bwapi4_Utils_Cyan_default +#define bwapi4_Utils_Cyan_default 26L +#undef bwapi4_Utils_Pinkish +#define bwapi4_Utils_Pinkish 27L +#undef bwapi4_Utils_Dark_Cyan +#define bwapi4_Utils_Dark_Cyan 28L +#undef bwapi4_Utils_Greygreen +#define bwapi4_Utils_Greygreen 29L +#undef bwapi4_Utils_Bluegrey +#define bwapi4_Utils_Bluegrey 30L +#undef bwapi4_Utils_Turquoise +#define bwapi4_Utils_Turquoise 31L +#ifdef __cplusplus +} +#endif +#endif /* Header for class bwapi4_WalkPosition */ #ifndef _Included_bwapi4_WalkPosition @@ -7718,14 +7608,6 @@ JNIEXPORT jint JNICALL Java_bwapi4_WalkPosition_getApproxDistance JNIEXPORT jdouble JNICALL Java_bwapi4_WalkPosition_getLength (JNIEnv *, jobject); -/* - * Class: bwapi4_WalkPosition - * Method: hasPath - * Signature: (Lbwapi4/WalkPosition;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_WalkPosition_hasPath - (JNIEnv *, jobject, jobject); - #ifdef __cplusplus } #endif diff --git a/headers4/bwapi4_AIModule.h b/headers4/bwapi4_AIModule.h index c2f9575..ab9f473 100644 --- a/headers4/bwapi4_AIModule.h +++ b/headers4/bwapi4_AIModule.h @@ -7,142 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_AIModule - * Method: onStart_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onStart_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_AIModule - * Method: onEnd_native - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onEnd_1native - (JNIEnv *, jobject, jlong, jboolean); - -/* - * Class: bwapi4_AIModule - * Method: onFrame_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onFrame_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_AIModule - * Method: onSendText_native - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSendText_1native - (JNIEnv *, jobject, jlong, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onReceiveText_native - * Signature: (JLbwapi4/Player;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onReceiveText_1native - (JNIEnv *, jobject, jlong, jobject, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onPlayerLeft_native - * Signature: (JLbwapi4/Player;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onPlayerLeft_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onNukeDetect_native - * Signature: (JLbwapi4/Position;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onNukeDetect_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitDiscover_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDiscover_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitEvade_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitEvade_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitShow_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitShow_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitHide_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitHide_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitCreate_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitCreate_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitDestroy_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitDestroy_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitMorph_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitMorph_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onUnitRenegade_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitRenegade_1native - (JNIEnv *, jobject, jlong, jobject); - -/* - * Class: bwapi4_AIModule - * Method: onSaveGame_native - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onSaveGame_1native - (JNIEnv *, jobject, jlong, jstring); - -/* - * Class: bwapi4_AIModule - * Method: onUnitComplete_native - * Signature: (JLbwapi4/Unit;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_AIModule_onUnitComplete_1native - (JNIEnv *, jobject, jlong, jobject); - #ifdef __cplusplus } #endif diff --git a/headers4/bwapi4_BWEventListener.h b/headers4/bwapi4_BWEventListener.h new file mode 100644 index 0000000..0724944 --- /dev/null +++ b/headers4/bwapi4_BWEventListener.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_BWEventListener */ + +#ifndef _Included_bwapi4_BWEventListener +#define _Included_bwapi4_BWEventListener +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_Color.h b/headers4/bwapi4_Color.h index 85487c9..81072af 100644 --- a/headers4/bwapi4_Color.h +++ b/headers4/bwapi4_Color.h @@ -7,30 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_Color - * Method: red_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_red_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Color - * Method: green_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_green_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Color - * Method: blue_native - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_bwapi4_Color_blue_1native - (JNIEnv *, jobject, jlong); - #ifdef __cplusplus } #endif diff --git a/headers4/bwapi4_DefaultBWListener.h b/headers4/bwapi4_DefaultBWListener.h new file mode 100644 index 0000000..976e9cc --- /dev/null +++ b/headers4/bwapi4_DefaultBWListener.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_DefaultBWListener */ + +#ifndef _Included_bwapi4_DefaultBWListener +#define _Included_bwapi4_DefaultBWListener +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_Game.h b/headers4/bwapi4_Game.h index 506686e..62ccd7a 100644 --- a/headers4/bwapi4_Game.h +++ b/headers4/bwapi4_Game.h @@ -743,14 +743,6 @@ JNIEXPORT jboolean JNICALL Java_bwapi4_Game_canUpgrade_1native__JLbwapi4_Upgrade JNIEXPORT void JNICALL Java_bwapi4_Game_printf_1native (JNIEnv *, jobject, jlong, jstring); -/* - * Class: bwapi4_Game - * Method: vPrintf_native - * Signature: (JLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vPrintf_1native - (JNIEnv *, jobject, jlong, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: sendText_native @@ -759,14 +751,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_vPrintf_1native JNIEXPORT void JNICALL Java_bwapi4_Game_sendText_1native (JNIEnv *, jobject, jlong, jstring); -/* - * Class: bwapi4_Game - * Method: vSendText_native - * Signature: (JLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendText_1native - (JNIEnv *, jobject, jlong, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: sendTextEx_native @@ -775,14 +759,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_vSendText_1native JNIEXPORT void JNICALL Java_bwapi4_Game_sendTextEx_1native (JNIEnv *, jobject, jlong, jboolean, jstring); -/* - * Class: bwapi4_Game - * Method: vSendTextEx_native - * Signature: (JZLjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vSendTextEx_1native - (JNIEnv *, jobject, jlong, jboolean, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: isInGame_native @@ -943,14 +919,6 @@ JNIEXPORT void JNICALL Java_bwapi4_Game_setTextSize_1native__J JNIEXPORT void JNICALL Java_bwapi4_Game_setTextSize_1native__JLbwapi4_Text_Size_Enum_2 (JNIEnv *, jobject, jlong, jobject); -/* - * Class: bwapi4_Game - * Method: vDrawText_native - * Signature: (JLbwapi4/CoordinateType/Enum;IILjava/lang/String;[Ljava/lang/Object;)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Game_vDrawText_1native - (JNIEnv *, jobject, jlong, jobject, jint, jint, jstring, jobjectArray); - /* * Class: bwapi4_Game * Method: drawText_native diff --git a/headers4/bwapi4_Mirror.h b/headers4/bwapi4_Mirror.h new file mode 100644 index 0000000..f741dc7 --- /dev/null +++ b/headers4/bwapi4_Mirror.h @@ -0,0 +1,23 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_Mirror */ + +#ifndef _Included_bwapi4_Mirror +#define _Included_bwapi4_Mirror +#ifdef __cplusplus +extern "C" { +#endif +#undef bwapi4_Mirror_EXTRACT_JAR +#define bwapi4_Mirror_EXTRACT_JAR 1L +/* + * Class: bwapi4_Mirror + * Method: startGame + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_bwapi4_Mirror_startGame + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_Mirror_FrameCallback.h b/headers4/bwapi4_Mirror_FrameCallback.h new file mode 100644 index 0000000..71bfa54 --- /dev/null +++ b/headers4/bwapi4_Mirror_FrameCallback.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_Mirror_FrameCallback */ + +#ifndef _Included_bwapi4_Mirror_FrameCallback +#define _Included_bwapi4_Mirror_FrameCallback +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_Mirror_JarResources.h b/headers4/bwapi4_Mirror_JarResources.h new file mode 100644 index 0000000..803fe25 --- /dev/null +++ b/headers4/bwapi4_Mirror_JarResources.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_Mirror_JarResources */ + +#ifndef _Included_bwapi4_Mirror_JarResources +#define _Included_bwapi4_Mirror_JarResources +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_Point.h b/headers4/bwapi4_Point.h index ae67c38..5d334b9 100644 --- a/headers4/bwapi4_Point.h +++ b/headers4/bwapi4_Point.h @@ -9,19 +9,35 @@ extern "C" { #endif /* * Class: bwapi4_Point - * Method: isValid_native - * Signature: (J)Z + * Method: isValid + * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_bwapi4_Point_isValid_1native - (JNIEnv *, jobject, jlong); +JNIEXPORT jboolean JNICALL Java_bwapi4_Point_isValid + (JNIEnv *, jobject); /* * Class: bwapi4_Point - * Method: getLength_native - * Signature: (J)D + * Method: makeValid + * Signature: ()Lbwapi4/Point; */ -JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getLength_1native - (JNIEnv *, jobject, jlong); +JNIEXPORT jobject JNICALL Java_bwapi4_Point_makeValid + (JNIEnv *, jobject); + +/* + * Class: bwapi4_Point + * Method: getDistance + * Signature: (Lbwapi4/Point;)D + */ +JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getDistance + (JNIEnv *, jobject, jobject); + +/* + * Class: bwapi4_Point + * Method: getLength + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL Java_bwapi4_Point_getLength + (JNIEnv *, jobject); #ifdef __cplusplus } diff --git a/headers4/bwapi4_Position.h b/headers4/bwapi4_Position.h index 0ce0ea9..0c71c53 100644 --- a/headers4/bwapi4_Position.h +++ b/headers4/bwapi4_Position.h @@ -47,14 +47,6 @@ JNIEXPORT jint JNICALL Java_bwapi4_Position_getApproxDistance JNIEXPORT jdouble JNICALL Java_bwapi4_Position_getLength (JNIEnv *, jobject); -/* - * Class: bwapi4_Position - * Method: hasPath - * Signature: (Lbwapi4/Position;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_Position_hasPath - (JNIEnv *, jobject, jobject); - #ifdef __cplusplus } #endif diff --git a/headers4/bwapi4_PositionOrUnit.h b/headers4/bwapi4_PositionOrUnit.h index 08db275..bcd388d 100644 --- a/headers4/bwapi4_PositionOrUnit.h +++ b/headers4/bwapi4_PositionOrUnit.h @@ -7,38 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_PositionOrUnit - * Method: isUnit_native - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isUnit_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: getUnit_native - * Signature: (J)Lbwapi4/Unit; - */ -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getUnit_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: isPosition_native - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_PositionOrUnit_isPosition_1native - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_PositionOrUnit - * Method: getPosition_native - * Signature: (J)Lbwapi4/Position; - */ -JNIEXPORT jobject JNICALL Java_bwapi4_PositionOrUnit_getPosition_1native - (JNIEnv *, jobject, jlong); - #ifdef __cplusplus } #endif diff --git a/headers4/bwapi4_TilePosition.h b/headers4/bwapi4_TilePosition.h index 268685c..982f3a0 100644 --- a/headers4/bwapi4_TilePosition.h +++ b/headers4/bwapi4_TilePosition.h @@ -7,14 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: bwapi4_TilePosition - * Method: hasPath - * Signature: (Lbwapi4/TilePosition;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_TilePosition_hasPath - (JNIEnv *, jobject, jobject); - /* * Class: bwapi4_TilePosition * Method: isValid diff --git a/headers4/bwapi4_Unitset.h b/headers4/bwapi4_Unitset.h index 9d0d856..49ae414 100644 --- a/headers4/bwapi4_Unitset.h +++ b/headers4/bwapi4_Unitset.h @@ -39,30 +39,6 @@ JNIEXPORT jobject JNICALL Java_bwapi4_Unitset_getInterceptors_1native JNIEXPORT jobject JNICALL Java_bwapi4_Unitset_getLarva_1native (JNIEnv *, jobject, jlong); -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JI - (JNIEnv *, jobject, jlong, jint); - -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__J - (JNIEnv *, jobject, jlong); - -/* - * Class: bwapi4_Unitset - * Method: setClientInfo_native - * Signature: (JII)V - */ -JNIEXPORT void JNICALL Java_bwapi4_Unitset_setClientInfo_1native__JII - (JNIEnv *, jobject, jlong, jint, jint); - /* * Class: bwapi4_Unitset * Method: getUnitsInRadius_native diff --git a/headers4/bwapi4_Utils.h b/headers4/bwapi4_Utils.h new file mode 100644 index 0000000..8cc8d09 --- /dev/null +++ b/headers4/bwapi4_Utils.h @@ -0,0 +1,75 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class bwapi4_Utils */ + +#ifndef _Included_bwapi4_Utils +#define _Included_bwapi4_Utils +#ifdef __cplusplus +extern "C" { +#endif +#undef bwapi4_Utils_Previous +#define bwapi4_Utils_Previous 1L +#undef bwapi4_Utils_Cyan +#define bwapi4_Utils_Cyan 2L +#undef bwapi4_Utils_Yellow +#define bwapi4_Utils_Yellow 3L +#undef bwapi4_Utils_White +#define bwapi4_Utils_White 4L +#undef bwapi4_Utils_Grey +#define bwapi4_Utils_Grey 5L +#undef bwapi4_Utils_Red +#define bwapi4_Utils_Red 6L +#undef bwapi4_Utils_Green +#define bwapi4_Utils_Green 7L +#undef bwapi4_Utils_Red_P1 +#define bwapi4_Utils_Red_P1 8L +#undef bwapi4_Utils_Tab +#define bwapi4_Utils_Tab 9L +#undef bwapi4_Utils_Newline +#define bwapi4_Utils_Newline 10L +#undef bwapi4_Utils_Invisible_no_override +#define bwapi4_Utils_Invisible_no_override 11L +#undef bwapi4_Utils_Remove_beyond +#define bwapi4_Utils_Remove_beyond 12L +#undef bwapi4_Utils_Clear_formatting +#define bwapi4_Utils_Clear_formatting 13L +#undef bwapi4_Utils_Blue +#define bwapi4_Utils_Blue 14L +#undef bwapi4_Utils_Teal +#define bwapi4_Utils_Teal 15L +#undef bwapi4_Utils_Purple +#define bwapi4_Utils_Purple 16L +#undef bwapi4_Utils_Orange +#define bwapi4_Utils_Orange 17L +#undef bwapi4_Utils_Right_Align +#define bwapi4_Utils_Right_Align 18L +#undef bwapi4_Utils_Center_Align +#define bwapi4_Utils_Center_Align 19L +#undef bwapi4_Utils_Invisible +#define bwapi4_Utils_Invisible 20L +#undef bwapi4_Utils_Brown +#define bwapi4_Utils_Brown 21L +#undef bwapi4_Utils_White_p7 +#define bwapi4_Utils_White_p7 22L +#undef bwapi4_Utils_Yellow_p8 +#define bwapi4_Utils_Yellow_p8 23L +#undef bwapi4_Utils_Green_p9 +#define bwapi4_Utils_Green_p9 24L +#undef bwapi4_Utils_Brighter_Yellow +#define bwapi4_Utils_Brighter_Yellow 25L +#undef bwapi4_Utils_Cyan_default +#define bwapi4_Utils_Cyan_default 26L +#undef bwapi4_Utils_Pinkish +#define bwapi4_Utils_Pinkish 27L +#undef bwapi4_Utils_Dark_Cyan +#define bwapi4_Utils_Dark_Cyan 28L +#undef bwapi4_Utils_Greygreen +#define bwapi4_Utils_Greygreen 29L +#undef bwapi4_Utils_Bluegrey +#define bwapi4_Utils_Bluegrey 30L +#undef bwapi4_Utils_Turquoise +#define bwapi4_Utils_Turquoise 31L +#ifdef __cplusplus +} +#endif +#endif diff --git a/headers4/bwapi4_WalkPosition.h b/headers4/bwapi4_WalkPosition.h index 7031bfc..bb41010 100644 --- a/headers4/bwapi4_WalkPosition.h +++ b/headers4/bwapi4_WalkPosition.h @@ -47,14 +47,6 @@ JNIEXPORT jint JNICALL Java_bwapi4_WalkPosition_getApproxDistance JNIEXPORT jdouble JNICALL Java_bwapi4_WalkPosition_getLength (JNIEnv *, jobject); -/* - * Class: bwapi4_WalkPosition - * Method: hasPath - * Signature: (Lbwapi4/WalkPosition;)Z - */ -JNIEXPORT jboolean JNICALL Java_bwapi4_WalkPosition_hasPath - (JNIEnv *, jobject, jobject); - #ifdef __cplusplus } #endif diff --git a/manual-bwapi4/AIModule.java b/manual-bwapi4/AIModule.java new file mode 100644 index 0000000..ad9e0b6 --- /dev/null +++ b/manual-bwapi4/AIModule.java @@ -0,0 +1,130 @@ +package bwapi4; + +import bwapi4.BWEventListener; + +/** + * This class receives all events from Broodwar. + * To process them, receive an AIModule's instance from {@link Mirror} and call {@link #setEventListener(bwapi.BWEventListener)} + * to set you own {@link BWEventListener listener}. + * There's also a stub class ({@link DefaultBWListener}) provided, so you don't have to implement all of the methods. + */ +public class AIModule { + + AIModule(){} + + private BWEventListener eventListener; + + public void setEventListener(BWEventListener eventListener) { + this.eventListener = eventListener; + } + + public void onStart() { + if (eventListener != null) { + eventListener.onStart(); + } + } + + public void onEnd(boolean isWinner) { + if (eventListener != null) { + eventListener.onEnd(isWinner); + } + } + + public void onFrame() { + if (eventListener != null) { + eventListener.onFrame(); + } + } + + public void onSendText(String text) { + if (eventListener != null) + { + eventListener.onSendText(text); + } + } + + public void onReceiveText(Player player, String text) { + if (eventListener != null) { + eventListener.onReceiveText(player, text); + } + } + + public void onPlayerLeft(Player player) { + if (eventListener != null) { + eventListener.onPlayerLeft(player); + } + } + + public void onNukeDetect(Position target) { + if (eventListener != null) { + eventListener.onNukeDetect(target); + } + } + + public void onUnitDiscover(Unit unit) { + if (eventListener != null) { + eventListener.onUnitDiscover(unit); + } + } + + public void onUnitEvade(Unit unit) { + if (eventListener != null) { + eventListener.onUnitEvade(unit); + } + } + + public void onUnitShow(Unit unit) { + if (eventListener != null) { + eventListener.onUnitShow(unit); + } + } + + public void onUnitHide(Unit unit) { + if (eventListener != null) { + eventListener.onUnitHide(unit); + } + } + + public void onUnitCreate(Unit unit) { + if (eventListener != null) { + eventListener.onUnitCreate(unit); + } + } + + public void onUnitDestroy(Unit unit) { + if (eventListener != null) { + eventListener.onUnitDestroy(unit); + } + } + + public void onUnitMorph(Unit unit) { + if (eventListener != null) { + eventListener.onUnitMorph(unit); + } + } + + public void onUnitRenegade(Unit unit) { + if (eventListener != null) { + eventListener.onUnitRenegade(unit); + } + } + + public void onSaveGame(String gameName) { + if (eventListener != null) { + eventListener.onSaveGame(gameName); + } + } + + public void onUnitComplete(Unit unit) { + if (eventListener != null) { + eventListener.onUnitComplete(unit); + } + } + + public void onPlayerDropped(Player player) { + if (eventListener != null) { + eventListener.onPlayerDropped(player); + } + } + +} diff --git a/manual-bwapi4/BWEventListener.java b/manual-bwapi4/BWEventListener.java new file mode 100644 index 0000000..6f9f031 --- /dev/null +++ b/manual-bwapi4/BWEventListener.java @@ -0,0 +1,53 @@ +package bwapi4; + +import bwapi4.*; + +import java.util.Map; +import java.util.HashMap; +import java.util.Collection; +import java.util.List; + +/** + * Implement this interface and call {@link AIModule#setEventListener(bwapi.BWEventListener)} to receive all of the in game events. + */ +public interface BWEventListener { + + public void onStart(); + + public void onEnd(boolean isWinner); + + public void onFrame(); + + public void onSendText(String text); + + public void onReceiveText(Player player, String text); + + public void onPlayerLeft(Player player); + + public void onNukeDetect(Position target); + + public void onUnitDiscover(Unit unit); + + public void onUnitEvade(Unit unit); + + public void onUnitShow(Unit unit); + + public void onUnitHide(Unit unit); + + public void onUnitCreate(Unit unit); + + public void onUnitDestroy(Unit unit); + + public void onUnitMorph(Unit unit); + + public void onUnitRenegade(Unit unit); + + public void onSaveGame(String gameName); + + public void onUnitComplete(Unit unit); + + public void onPlayerDropped(Player player); + +} + + diff --git a/manual-bwapi4/Color.java b/manual-bwapi4/Color.java new file mode 100644 index 0000000..e15c22a --- /dev/null +++ b/manual-bwapi4/Color.java @@ -0,0 +1,73 @@ +package bwapi4; + +import java.lang.Override; +import java.util.HashMap; +import java.util.Map; + +/** + * Starcraft uses a 256 color palette to render everything, + * so the colors available for draw shapes using BWAPI is limited to the colors available in the Pallete. + * Several predefined colors from the pallete are provided. + */ +public class Color { + + private int r, g, b; + + /** + * Create a color using the color in the palette that is closest to the RGB color specified. This will check a number of colors in the pallet to see which is closest to the specified color so this function is relatively slow. + * @param r + * @param g + * @param b + */ + public Color(int r, int g, int b) { + this.r = r; + this.g = g; + this.b = b; + } + + public static Color Red; + + public static Color Blue; + + public static Color Teal; + + public static Color Purple; + + public static Color Orange; + + public static Color Brown; + + public static Color White; + + public static Color Yellow; + + public static Color Green; + + public static Color Cyan; + + public static Color Black; + + public static Color Grey; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Color)) return false; + + Color color = (Color) o; + + if (b != color.b) return false; + if (g != color.g) return false; + if (r != color.r) return false; + + return true; + } + + @Override + public int hashCode() { + int result = r; + result = 31 * result + g; + result = 31 * result + b; + return result; + } +} diff --git a/manual-bwapi4/DefaultBWListener.java b/manual-bwapi4/DefaultBWListener.java new file mode 100644 index 0000000..76df50e --- /dev/null +++ b/manual-bwapi4/DefaultBWListener.java @@ -0,0 +1,103 @@ +package bwapi4; + +import bwapi4.BWEventListener; +import bwapi4.Player; +import bwapi4.Position; +import bwapi4.Unit; + +/** + * A utility stub class providing a default implementation of {@link BWEventListener}, + * override it's methods if you want to handle only some events. + */ +public class DefaultBWListener implements BWEventListener { + + @Override + public void onStart() { + + } + + @Override + public void onEnd(boolean b) { + + } + + @Override + public void onFrame() { + + } + + @Override + public void onSendText(String s) { + + } + + @Override + public void onReceiveText(Player player, String s) { + + } + + @Override + public void onPlayerLeft(Player player) { + + } + + @Override + public void onNukeDetect(Position position) { + + } + + @Override + public void onUnitDiscover(Unit unit) { + + } + + @Override + public void onUnitEvade(Unit unit) { + + } + + @Override + public void onUnitShow(Unit unit) { + + } + + @Override + public void onUnitHide(Unit unit) { + + } + + @Override + public void onUnitCreate(Unit unit) { + + } + + @Override + public void onUnitDestroy(Unit unit) { + + } + + @Override + public void onUnitMorph(Unit unit) { + + } + + @Override + public void onUnitRenegade(Unit unit) { + + } + + @Override + public void onSaveGame(String s) { + + } + + @Override + public void onUnitComplete(Unit unit) { + + } + + @Override + public void onPlayerDropped(Player player) { + + } +} diff --git a/manual-bwapi4/Mirror.java b/manual-bwapi4/Mirror.java new file mode 100644 index 0000000..1eaf4f2 --- /dev/null +++ b/manual-bwapi4/Mirror.java @@ -0,0 +1,262 @@ +package bwapi4; + +import bwapi4.AIModule; +import bwapi4.BWEventListener; + +import java.io.*; +import java.io.File; +import java.lang.Exception; +import java.lang.UnsupportedOperationException; +import java.util.*; +import java.util.zip.*; + +/** + *

The API entry point. Standard use case:

+ *
    + *
  • Create a Mirror object and use {@link #getModule()} and then set an {@link AIModule}'s {@link BWEventListener}
    + *
  • Call {@link #startGame()} to init the API and connect to Broodwar, then launch Broodwar from ChaosLauncher.
  • + *
  • In you {@link BWEventListener#onStart()} method, receive the Game object by calling {@link #getGame()}
  • + *
+ *
+ * Example + *
+ *     {@code
+ *
+ *     mirror.getModule().setEventListener(new DefaultBWListener()
+ *     {
+ *            public void onStart() {
+ *                game = mirror.getGame();
+ *                self = game.self();
+ *                //initialization
+ *                ....
+ *            }
+ *
+ *           public void onUpdate() {
+ *               for (Unit myUnit : self.getUnits()) {
+ *                   //give orders to unit
+ *                   ...
+ *                }
+ *           }
+ *        });
+ *     }
+ *     mirror.startGame();
+ * 
+ + *

Note: The Game object is initialized during the {@link #startGame()} as well as other BWMirror API's constants. + * Do not use any API releated methods/fields prior to {@link #startGame()}.

+ + */ +public class Mirror { + + private Game game; + + private AIModule module = new AIModule(); + + private FrameCallback frameCallback; + + private static final boolean EXTRACT_JAR = true; + + private static final String VERSION = "2_0"; + + static { + String arch = System.getProperty("os.arch"); + String dllNames[] = {"bwapi_bridge" + VERSION, "gmp-vc90-mt", "mpfr-vc90-mt"}; + if(!arch.equals("x86")){ + throw new UnsupportedOperationException("BWMirror API supports only x86 architecture."); + } + try { + if (EXTRACT_JAR) { + System.setProperty("java.library.path", "."); + java.lang.reflect.Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); + fieldSysPath.setAccessible(true); + fieldSysPath.set(null, null); + + String path = Mirror.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + String decodedPath = java.net.URLDecoder.decode(path, "UTF-8"); + + for (String dllName : dllNames) { + String dllNameExt = dllName + ".dll"; + if (!new File(dllNameExt).exists()) { + JarResources jar = new JarResources(path); + byte[] correctDllData = jar.getResource(dllNameExt); + FileOutputStream funnyStream = new FileOutputStream(dllNameExt); + funnyStream.write(correctDllData); + funnyStream.close(); + } + } + } + } catch (Exception e) { + System.err.println("Failed to extract native libraries.\n" + e); + } + + System.loadLibrary(dllNames[0]); + + File dataDir = new File("bwapi-data/BWTA"); + if(!dataDir.exists()){ + try { + dataDir.mkdirs(); + } catch (Exception e) { + System.err.println("Unable to create /bwapi-data/BWTA folder, BWTA analysis will not be saved."); + } + } + } + + public Game getGame() { + return game; + } + + public AIModule getModule() { + return module; + } + + /** + * Starts the API, initializes all constants ( {@link UnitType}, {@link WeaponType} ) and the {@link Game} object. + * This method blocks until the end of game. + */ + public native void startGame(); + + private void update() { + if (frameCallback != null) { + frameCallback.update(); + } + } + + /*public void setFrameCallback(bwapi.Mirror.FrameCallback frameCallback) { + this.frameCallback = frameCallback; + } */ + + /** + * The simplest interface to receive update event from Broodwar. The {@link #update()} method is called once each frame. + * For a simple bot and implementation of this interface is enough, to receive all in game events, implement {@link BWEventListener}. + */ + /*public*/ private interface FrameCallback { + public void update(); + } + + @SuppressWarnings({"unchecked"}) + private static class JarResources { + + // external debug flag + public boolean debugOn = false; + + // jar resource mapping tables + private Hashtable htSizes = new Hashtable(); + private Hashtable htJarContents = new Hashtable(); + + // a jar file + private String jarFileName; + + /** + * creates a javabot.JarResources. It extracts all resources from a Jar + * into an internal hashtable, keyed by resource names. + * + * @param jarFileName a jar or zip file + */ + public JarResources(String jarFileName) { + this.jarFileName = jarFileName; + init(); + } + + /** + * Extracts a jar resource as a blob. + * + * @param name a resource name. + */ + public byte[] getResource(String name) { + return (byte[]) htJarContents.get(name); + } + + /** + * initializes internal hash tables with Jar file resources. + */ + private void init() { + try { + // extracts just sizes only. + ZipFile zf = new ZipFile(jarFileName); + Enumeration e = zf.entries(); + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + if (debugOn) { + System.out.println(dumpZipEntry(ze)); + } + htSizes.put(ze.getName(), new Integer((int) ze.getSize())); + } + zf.close(); + + // extract resources and put them into the hashtable. + FileInputStream fis = new FileInputStream(jarFileName); + BufferedInputStream bis = new BufferedInputStream(fis); + ZipInputStream zis = new ZipInputStream(bis); + ZipEntry ze = null; + while ((ze = zis.getNextEntry()) != null) { + if (ze.isDirectory()) { + continue; + } + if (debugOn) { + System.out.println( + "ze.getName()=" + ze.getName() + "," + "getSize()=" + ze.getSize() + ); + } + int size = (int) ze.getSize(); + // -1 means unknown size. + if (size == -1) { + size = ((Integer) htSizes.get(ze.getName())).intValue(); + } + byte[] b = new byte[(int) size]; + int rb = 0; + int chunk = 0; + while (((int) size - rb) > 0) { + chunk = zis.read(b, rb, (int) size - rb); + if (chunk == -1) { + break; + } + rb += chunk; + } + // add to internal resource hashtable + htJarContents.put(ze.getName(), b); + if (debugOn) { + System.out.println( + ze.getName() + " rb=" + rb + + ",size=" + size + + ",csize=" + ze.getCompressedSize() + ); + } + } + } catch (NullPointerException e) { + System.out.println("done."); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Dumps a zip entry into a string. + * + * @param ze a ZipEntry + */ + private String dumpZipEntry(ZipEntry ze) { + StringBuffer sb = new StringBuffer(); + if (ze.isDirectory()) { + sb.append("d "); + } else { + sb.append("f "); + } + if (ze.getMethod() == ZipEntry.STORED) { + sb.append("stored "); + } else { + sb.append("defalted "); + } + sb.append(ze.getName()); + sb.append("\t"); + sb.append("" + ze.getSize()); + if (ze.getMethod() == ZipEntry.DEFLATED) { + sb.append("/" + ze.getCompressedSize()); + } + return (sb.toString()); + } + + + } +} \ No newline at end of file diff --git a/manual-bwapi4/Position.java b/manual-bwapi4/Position.java index 296e717..b4efd8e 100644 --- a/manual-bwapi4/Position.java +++ b/manual-bwapi4/Position.java @@ -30,8 +30,6 @@ public class Position extends AbstractPoint{ public native double getLength(); - public native boolean hasPath(Position position); - public int getX() { return x; } diff --git a/manual-bwapi4/PositionOrUnit.java b/manual-bwapi4/PositionOrUnit.java new file mode 100644 index 0000000..b371c13 --- /dev/null +++ b/manual-bwapi4/PositionOrUnit.java @@ -0,0 +1,55 @@ +package bwapi4; + +import java.lang.IllegalArgumentException; +import java.lang.Object; +import java.lang.Override; + +public class PositionOrUnit { + + private Unit unit; + + private Position position; + + public PositionOrUnit(Unit unit){ + if(unit == null){ + throw new IllegalArgumentException("PositionOrUnit must not reference null!"); + }; + this.unit = unit; + } + + public PositionOrUnit(Position position){ + if(position == null){ + throw new IllegalArgumentException("PositionOrUnit must not reference null!"); + }; + this.position = position; + } + + public Unit getUnit(){ + return unit; + } + + public Position getPosition() { + return position; + } + + public boolean isUnit(){ + return unit != null; + } + + public boolean isPosition(){ + return position != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PositionOrUnit)) return false; + + PositionOrUnit that = (PositionOrUnit) o; + + if (position != null ? !position.equals(that.position) : that.position != null) return false; + if (unit != null ? !unit.equals(that.unit) : that.unit != null) return false; + + return true; + } +} \ No newline at end of file diff --git a/manual-bwapi4/TilePosition.java b/manual-bwapi4/TilePosition.java index a5d85c3..711ee06 100644 --- a/manual-bwapi4/TilePosition.java +++ b/manual-bwapi4/TilePosition.java @@ -9,7 +9,7 @@ import java.util.Map; * These are called build tiles because buildability data is available at this resolution, and correspond to the tiles seen in game. * For example, a Command Center occupies an area of 4x3 build tiles. */ -public class TilePosition { +public class TilePosition extends AbstractPoint{ private int x, y; public TilePosition(int x, int y) { @@ -21,8 +21,6 @@ public class TilePosition { return "[" + x + ", " + y + "]"; } - public native boolean hasPath(TilePosition position); - public native boolean isValid(); public native TilePosition makeValid(); @@ -82,4 +80,8 @@ public class TilePosition { result = 31 * result + y; return result; } + + public TilePosition getPoint(){ + return this; + } } \ No newline at end of file diff --git a/manual-bwapi4/Utils.java b/manual-bwapi4/Utils.java new file mode 100644 index 0000000..1a6154c --- /dev/null +++ b/manual-bwapi4/Utils.java @@ -0,0 +1,52 @@ +package bwapi4; + +import java.lang.String; +import java.lang.System; + +/** + * + */ +public class Utils { + + public static final byte Previous = 0x01; + public static final byte Cyan = 0x02; + public static final byte Yellow = 0x03; + public static final byte White = 0x04; + public static final byte Grey = 0x05; + public static final byte Red = 0x06; + public static final byte Green = 0x07; + public static final byte Red_P1 = 0x08; + public static final byte Tab = 0x09; + public static final byte Newline = 0x0A; + public static final byte Invisible_no_override = 0x0B; + public static final byte Remove_beyond = 0x0C; + public static final byte Clear_formatting = 0x0D; + public static final byte Blue = 0x0E; + public static final byte Teal = 0x0F; + public static final byte Purple = 0x10; + public static final byte Orange = 0x11; + public static final byte Right_Align = 0x12; + public static final byte Center_Align = 0x13; + public static final byte Invisible = 0x14; + public static final byte Brown = 0x15; + public static final byte White_p7 = 0x16; + public static final byte Yellow_p8 = 0x17; + public static final byte Green_p9 = 0x18; + public static final byte Brighter_Yellow = 0x19; + public static final byte Cyan_default = 0x1A; + public static final byte Pinkish = 0x1B; + public static final byte Dark_Cyan = 0x1C; + public static final byte Greygreen = 0x1D; + public static final byte Bluegrey = 0x1E; + public static final byte Turquoise = 0x1F; + + public static String formatText(String text, byte format){ + byte[] textData = text.getBytes(); + int textDataLength = text.length(); + + byte[] newTextData = new byte[textDataLength + 1]; + newTextData[0] = format; + System.arraycopy(textData, 0, newTextData, 1, textDataLength); + return new String(newTextData); + } +} \ No newline at end of file diff --git a/manual-bwapi4/WalkPosition.java b/manual-bwapi4/WalkPosition.java index c7696e8..22a35f6 100644 --- a/manual-bwapi4/WalkPosition.java +++ b/manual-bwapi4/WalkPosition.java @@ -4,7 +4,7 @@ import java.lang.Override; import java.util.HashMap; import java.util.Map; -public class WalkPosition { +public class WalkPosition extends AbstractPoint{ private int x, y; @@ -27,8 +27,6 @@ public class WalkPosition { public native double getLength(); - public native boolean hasPath(WalkPosition position); - public int getX() { return x; } @@ -80,4 +78,8 @@ public class WalkPosition { } private long pointer; + + public WalkPosition getPoint(){ + return this; + } } \ No newline at end of file diff --git a/out/production/InvokeGenerator/generator/CJavaPipeline$2.class b/out/production/InvokeGenerator/generator/CJavaPipeline$2.class index 34f7170..4574e27 100644 Binary files a/out/production/InvokeGenerator/generator/CJavaPipeline$2.class and b/out/production/InvokeGenerator/generator/CJavaPipeline$2.class differ diff --git a/out/production/InvokeGenerator/generator/CJavaPipeline.class b/out/production/InvokeGenerator/generator/CJavaPipeline.class index cd421c0..6d08f68 100644 Binary files a/out/production/InvokeGenerator/generator/CJavaPipeline.class and b/out/production/InvokeGenerator/generator/CJavaPipeline.class differ diff --git a/out/production/InvokeGenerator/generator/JavaContext.class b/out/production/InvokeGenerator/generator/JavaContext.class index 807e71e..14ccc31 100644 Binary files a/out/production/InvokeGenerator/generator/JavaContext.class and b/out/production/InvokeGenerator/generator/JavaContext.class differ diff --git a/out/production/InvokeGenerator/generator/c/Bind.class b/out/production/InvokeGenerator/generator/c/Bind.class index 2956d04..079d2c7 100644 Binary files a/out/production/InvokeGenerator/generator/c/Bind.class and b/out/production/InvokeGenerator/generator/c/Bind.class differ diff --git a/out/production/InvokeGenerator/generator/c/TypeTable.class b/out/production/InvokeGenerator/generator/c/TypeTable.class index 7f5e5cc..93173e5 100644 Binary files a/out/production/InvokeGenerator/generator/c/TypeTable.class and b/out/production/InvokeGenerator/generator/c/TypeTable.class differ diff --git a/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class b/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class index d85470f..17d1318 100644 Binary files a/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class and b/out/production/InvokeGenerator/generator/ccalls/CallImplementer.class differ diff --git a/out/production/InvokeGenerator/impl/CApiParser$1.class b/out/production/InvokeGenerator/impl/CApiParser$1.class index bdd9bd4..3489895 100644 Binary files a/out/production/InvokeGenerator/impl/CApiParser$1.class and b/out/production/InvokeGenerator/impl/CApiParser$1.class differ diff --git a/out/production/InvokeGenerator/impl/CApiParser.class b/out/production/InvokeGenerator/impl/CApiParser.class index ac5e139..4dfb570 100644 Binary files a/out/production/InvokeGenerator/impl/CApiParser.class and b/out/production/InvokeGenerator/impl/CApiParser.class differ diff --git a/src/generator/CJavaPipeline.java b/src/generator/CJavaPipeline.java index f5e79d3..5c6d79a 100644 --- a/src/generator/CJavaPipeline.java +++ b/src/generator/CJavaPipeline.java @@ -39,8 +39,8 @@ public class CJavaPipeline { * Classes from BWAPI 4 that don't need mirroring * Not used in mirroring BWAPI 3 */ - private static final List ignoredClasses = new ArrayList<>(Arrays.asList("Vectorset", "ConstVectorset", "VSetIterator", - "Interface", "RectangleArray", "UnitImpl", "PlayerImpl", "GameImpl", "BulletImpl", "ForceImpl", "TournamentModule", "RegionImpl", "SetContainer", "InterfaceEvent")); + private static final List ignoredClasses = new ArrayList<>(Arrays.asList("Vectorset", "ConstVectorset", "VSetIterator", "GameWrapper", + "Interface", "RectangleArray", "UnitImpl", "PlayerImpl", "GameImpl", "BulletImpl", "ForceImpl", "TournamentModule", "RegionImpl", "SetContainer", "InterfaceEvent", "PositionOrUnit", "Point")); private static final HashMap superClasses = new HashMap<>(); @@ -187,6 +187,8 @@ public class CJavaPipeline { callImplementer.setBwtaMode(pkg.packageName.equals("bwta")); javaContext.setPackageName(pkg.packageName); + callImplementer.notifyPackageStart(); + for (File file : new File(pkg.packageName).listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { diff --git a/src/generator/JavaContext.java b/src/generator/JavaContext.java index ffc1680..9e75c54 100644 --- a/src/generator/JavaContext.java +++ b/src/generator/JavaContext.java @@ -14,11 +14,11 @@ public class JavaContext { private HashMap javaToCType = new HashMap<>(); - private List valueTypes = Arrays.asList("Position", "TilePosition", "Color", "BWTA::RectangleArray"); + private List valueTypes = Arrays.asList("Position", "TilePosition", "WalkPosition", "Color", "BWTA::RectangleArray", "PositionOrUnit", "Point"); private List constantTypes = Arrays.asList("UnitType", "TechType", "UpgradeType", "Race", "UnitCommand", "WeaponType", "Order", "GameType", "Error"); - private List enumTypes = Arrays.asList("MouseButton", "Key"); + private List enumTypes = Arrays.asList("MouseButton", "Key", "bwapi4.Text.Size.Enum", "bwapi4.CoordinateType.Enum"); private List valueReturnTypes = Arrays.asList("UnitCommand", "Event"); @@ -85,7 +85,9 @@ public class JavaContext { } switch (variableType) { case "Position": + case "WalkPosition": case "TilePosition": + case "Point": return "(" + "(int)env->GetIntField(" + rawName + ", FindCachedField(env, env->GetObjectClass(" + rawName + "), \"x\", \"I\")), " + "(int)env->GetIntField(" + rawName + ", FindCachedField(env, env->GetObjectClass(" + rawName + "), \"y\", \"I\"))" + @@ -100,12 +102,20 @@ public class JavaContext { "(int)env->GetIntField(" + rawName + ", FindCachedField(env, env->GetObjectClass(" + rawName + "), \"g\", \"I\")), " + "(int)env->GetIntField(" + rawName + ", FindCachedField(env, env->GetObjectClass(" + rawName + "), \"b\", \"I\"))" + ");"; + case "PositionOrUnit": + return "(convertPositionOrUnit(env, " + rawName + " ));"; } return ";"; } public String copyJavaObjectToC(String variableType, String variableName, String rawName) { - return (variableType + " " + variableName) + copyFields(variableType, variableName, rawName); + String packageStrippedType = variableType; + if(packageStrippedType.startsWith("bwapi")){ + packageStrippedType = packageStrippedType.substring(packageStrippedType.indexOf(".") + 1); + } + packageStrippedType = packageStrippedType.replaceAll("\\.","::"); + + return (packageStrippedType + " " + variableName) + copyFields(packageStrippedType, variableName, rawName); } public String copyJavaObjectToC(String variableType, String variableName) { @@ -133,14 +143,16 @@ public class JavaContext { public String copyConstructor(String javaType) { switch (javaType) { case "TilePosition": + case "WalkPosition": case "Position": + case "Point": return "II"; case "Color": return "III"; case "Error": return "I"; default: - return ""; + throw new UnsupportedOperationException(); } } @@ -158,9 +170,9 @@ public class JavaContext { public String implementCopyReturn(String javaType, String fieldName) { switch (javaType) { case "TilePosition": - return ", "+fieldName+".x" + checkBWAPI3brackets() + - ", "+fieldName+".y" + checkBWAPI3brackets() ; case "Position": + case "WalkPosition": + case "Point": return ", "+fieldName+".x" + checkBWAPI3brackets() + ", "+fieldName+".y" + checkBWAPI3brackets() ; case "Color": diff --git a/src/generator/c/Bind.java b/src/generator/c/Bind.java index e248828..2446f06 100644 --- a/src/generator/c/Bind.java +++ b/src/generator/c/Bind.java @@ -5,6 +5,7 @@ import c.CDeclaration; import c.DeclarationType; import c.Field; import generator.CJavaPipeline; +import generator.JavaContext; import impl.ClassVariable; import java.io.PrintStream; @@ -21,6 +22,7 @@ public class Bind { private PrintStream out; + public void setOut(PrintStream out) { this.out = out; } @@ -31,13 +33,35 @@ public class Bind { out.println("\t\tprintln(\"BWAPI ready.\");"); } - private String broodwarPtrSuffix() { - if (!CJavaPipeline.isBWAPI3()) { - return "ptr"; + + private void implementConnectionRoutine() { + if (CJavaPipeline.isBWAPI3()) { + out.println(" if (Broodwar != NULL) {\n" + + "\t\t\t\tprintln(\"Waiting...\");\n" + + " while (!Broodwar->isInGame()) {\n" + + " BWAPIClient.update();\n" + + "\t\t\t\t\tif (Broodwar == NULL) {\n" + + " println(\"Match ended.\");\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n"); + } else { + out.println("\t\t\t\tprintln(\"Waiting...\");" + + "while ( !Broodwar->isInGame() )\n" + + " {\n" + + " BWAPI::BWAPIClient.update();\n" + + " if (!BWAPI::BWAPIClient.isConnected())\n" + + " {\n" + + " println(\"Reconnecting...\");\n" + + " reconnect();\n" + + " }\n" + + " }"); } - return ""; } + private void implementGameStart() { out.println("println(\"Connecting to Broodwar...\");\n" + "\t\treconnect();\n" + @@ -51,7 +75,7 @@ public class Bind { "\t\tjobject moduleObj = env->GetObjectField(obj, env->GetFieldID(cls, \"module\", \"Lbwapi/AIModule;\"));\n" + "\t\tjclass moduleCls = env->GetObjectClass(moduleObj);\n" + "\t\tenv->SetObjectField(obj, env->GetFieldID(cls, \"game\", \"Lbwapi/Game;\"), " + - "env->CallStaticObjectMethod(gamecls, env->GetStaticMethodID(gamecls, \"get\", \"(J)Lbwapi/Game;\"), (long)Broodwar" + broodwarPtrSuffix() + "));\n" + + "env->CallStaticObjectMethod(gamecls, env->GetStaticMethodID(gamecls, \"get\", \"(J)Lbwapi/Game;\"), (long)" + (CJavaPipeline.isBWAPI3() ? "" : "&") + "Broodwar));\n" + "\n" + "\t\tjmethodID updateMethodID = env->GetMethodID(env->GetObjectClass(obj), \"update\", \"()V\");"); @@ -74,24 +98,13 @@ public class Bind { "\t\tjmethodID unitCompleteCallback = env->GetMethodID(moduleCls, \"onUnitComplete\", \"(Lbwapi/Unit;)V\");\n" + "\t\tjmethodID playerDroppedCallback = env->GetMethodID(moduleCls, \"onPlayerDropped\", \"(Lbwapi/Player;)V\");"); - out.println( - "\t\twhile (true) {\n" + - " if (Broodwar" + broodwarPtrSuffix() + " != NULL) {\n" + - "\t\t\t\tprintln(\"Waiting...\");\n" + - " while (!Broodwar" + broodwarPtrSuffix() + "->isInGame()) {\n" + - " BWAPIClient.update();\n" + - "\t\t\t\t\tif (Broodwar" + broodwarPtrSuffix() + " == NULL) {\n" + - " println(\"Match ended.\");\n" + - " return;\n" + - " }\n" + - " }\n" + - " }\n" + - "\n" + - "\t\t\tprintln(\"Game ready!!!\");\n" + - "\n" + - "\t\t\twhile (Broodwar->isInGame()) {\n" + - "\t\t\t\t\n" + - "\t\t\t\tenv->CallVoidMethod(obj, updateMethodID);\n"); + out.println("\t\twhile (true) {\n"); + implementConnectionRoutine(); + out.println("\t\t\tprintln(\"Game ready!!!\");\n" + + "\n" + + "\t\t\twhile (Broodwar->isInGame()) {\n" + + "\t\t\t\t\n" + + "\t\t\t\tenv->CallVoidMethod(obj, updateMethodID);\n"); out.println("\n" + "\t\t\t\tfor(std::list::const_iterator it = Broodwar->getEvents().begin(); it!=Broodwar->getEvents().end(); it++)\n" + "\t\t\t\t {\n" + @@ -166,35 +179,51 @@ public class Bind { "\t\t\t\t\t\tprintln(\"Reconnecting...\");\n" + "\t\t\t\t\t\treconnect();\n" + "\t\t\t\t}\n" + + (CJavaPipeline.isBWAPI3() ? "" : "println(\"Match ended.\");") + "\t\t\t}\n" + "\t\t}"); } private void implementHelpers() { - out.println("void reconnect()\n" + - "{\n" + - "\twhile (!BWAPIClient.connect()) {\n" + - " Sleep(1000);\n" + - " }\n" + - "}\n" + - "\n" + - "\n" + - "\n" + + if (CJavaPipeline.isBWAPI3()) { + out.println("void reconnect()\n" + + "{\n" + + "\twhile (!BWAPIClient.connect()) {\n" + + " Sleep(1000);\n" + + " }\n" + + "}\n" + + "\n" + + "\n"); + } else { + out.println("void reconnect()\n" + + "{\n" + + "\twhile (!BWAPIClient.connect()) {\n" + + " std::this_thread::sleep_for(std::chrono::milliseconds{ 1000 });\n" + + " }\n" + + "}\n" + + "\n" + + "\n"); + } + + out.println( "void flushPrint(const char * text){\n" + - "\tprintf(text);\n" + - "\tfflush(stdout); \n" + - "}\n" + - "\n" + - "void println(const char * text){\n" + - "\tprintf(text);\n" + - "\tflushPrint(\"\\n\");\n" + - "}\n"); + "\tprintf(text);\n" + + "\tfflush(stdout); \n" + + "}\n" + + "\n" + + "void println(const char * text){\n" + + "\tprintf(text);\n" + + "\tflushPrint(\"\\n\");\n" + + "}\n"); + } private void implementMirrorInit(List declarationList) { implementHelpers(); out.println("JNIEXPORT void JNICALL Java_bwapi_Mirror_startGame(JNIEnv * env, jobject obj){"); - implementBWAPIInit(); + if (CJavaPipeline.isBWAPI3()) { + implementBWAPIInit(); + } implementVariablesBind(declarationList); implementGameStart(); out.println("}"); @@ -246,7 +275,7 @@ public class Bind { "env->GetStaticFieldID(cls, \"" + classVariable.getName() + "\", \"Lbwapi/" + classVariable.getType() + ";\"), " + "env->CallStaticObjectMethod(cls, getId, (jlong)&" + cValue + ")" + ");"); - if (cClass.getName().equals("Position") || cClass.getName().equals("TilePosition")) { + if (cClass.getName().equals("Position") || cClass.getName().equals("TilePosition") || cClass.getName().equals("WalkPosition") || cClass.getName().equals("Point")) { return; } out.println("table" + cClass.getName() + ".insert(std::pair(" + cValue + ".getID(), &" + cValue + "));"); diff --git a/src/generator/c/TypeTable.java b/src/generator/c/TypeTable.java index 21f29c2..e53fd94 100644 --- a/src/generator/c/TypeTable.java +++ b/src/generator/c/TypeTable.java @@ -33,7 +33,7 @@ public class TypeTable { } private void checkTypeTable(CClass cClass) { - if(cClass.getName().equals("Position") || cClass.getName().equals("TilePosition")){ + if(cClass.getName().equals("Position") || cClass.getName().equals("TilePosition") || cClass.getName().equals("WalkPosition") || cClass.getName().equals("Point")){ return; } for (Field field : cClass.getFields()) { diff --git a/src/generator/ccalls/CallImplementer.java b/src/generator/ccalls/CallImplementer.java index f449b69..14ea667 100644 --- a/src/generator/ccalls/CallImplementer.java +++ b/src/generator/ccalls/CallImplementer.java @@ -53,7 +53,7 @@ public class CallImplementer { out.print("#include \"../concat_header.h\"\n" + "#include \n" + "#include \n" + - (CJavaPipeline.isBWAPI3() ? "#include \n" : "") + + (CJavaPipeline.isBWAPI3() ? "#include \n" : "#include \n" + "#include \n") + "#include \n" + "#include \n" + "#include \"../BWTA_Result.h\"" + @@ -390,4 +390,20 @@ public class CallImplementer { public void setBwtaMode(boolean bwtaMode) { this.bwtaMode = bwtaMode; } + + public void notifyPackageStart(){ + out.println("PositionOrUnit convertPositionOrUnit(JNIEnv * env, jobject obj){ \n" + + "\tjclass clz = FindCachedClass(env, \"PositionOrUnit\");\n" + + "\tjmethodID typeMethodId = FindCachedMethod(env, clz, \"isUnit\", \"()Z\");\n" + + "\tbool isUnit = (bool)env->CallBooleanMethod(obj, typeMethodId);\n" + + "\tif(isUnit){\n" + + "\t\tjobject unitObj = env->CallObjectMethod(obj, FindCachedMethod(env, clz, \"getUnit\", \"()L" + javaContext.getPackageName() + "/Unit;\"));\n" + + "\t\tUnit unit = (Unit)env->GetLongField(unitObj, FindCachedField(env, env->GetObjectClass(unitObj), \"unitObj\", \"J\"));\n" + + "\t\treturn PositionOrUnit(unit);\n" + + "\t}\n" + + "\tjobject posObj = env->CallObjectMethod(obj, FindCachedMethod(env, clz, \"getPosition\", \"()L" + javaContext.getPackageName() + "/Position;\"));\n" + + "\t" + javaContext.copyJavaObjectToC("Position", "position", "posObj") + "\n" + + "\treturn PositionOrUnit(position);\n" + + "}\n\n"); + } } diff --git a/src/impl/CApiParser.java b/src/impl/CApiParser.java index bf57254..b0aaa30 100644 --- a/src/impl/CApiParser.java +++ b/src/impl/CApiParser.java @@ -261,6 +261,11 @@ public class CApiParser { } } + if(function.name.equals("setClientInfo")){ + System.err.println("function skipped - BWAPI4 set client info return (" + function.name + ")"); + return null; + } + if (matcher.group(F_REGEX_PARAMS) != null) { String paramsString = matcher.group(F_REGEX_PARAMS); String paramStrings[] = paramsString.split("\\,"); @@ -325,7 +330,12 @@ public class CApiParser { } // if (argType.equals("va_list")) { + if(function.name.startsWith("v")){ + System.err.println("BWAPI4 va_list function skipped : " + function.name); + return null; + } argType = "Object ..."; + continue; } @@ -381,6 +391,7 @@ public class CApiParser { return null; } + if (arg.length > 2 && arg[2].equals("=")) { function.args.add(new Param(argType, argName, arg[3])); } else {