|
4 | 4 | import bwapi.ClientData.GameData; |
5 | 5 | import bwapi.ClientData.Shape; |
6 | 6 |
|
| 7 | +import java.io.File; |
7 | 8 | import java.util.*; |
8 | 9 | import java.util.stream.Collectors; |
9 | 10 | import java.util.stream.IntStream; |
@@ -2269,16 +2270,145 @@ public void setFrameSkip(int frameSkip) { |
2269 | 2270 | addCommand(SetFrameSkip, frameSkip, 0); |
2270 | 2271 | } |
2271 | 2272 |
|
2272 | | - // If you need these please implement (see addCommand and make a PR to the github repo) |
2273 | | - // public boolean setAlliance(Player player, boolean allied); |
2274 | | - // public boolean setAlliance(Player player); |
2275 | | - // public boolean setAlliance(Player player, boolean allied, boolean alliedVictory); |
2276 | | - // public boolean setVision(Player player, boolean enabled); |
2277 | | - // public void setGUI(bool enabled); |
2278 | | - // public int getLastEventTime(); |
2279 | | - // public boolean setMap(final String cstr_mapFileName); |
2280 | | - // public boolean setRevealAll(); |
2281 | | - // public boolean setRevealAll(boolean reveal); |
| 2273 | + /** |
| 2274 | + * Sets the alliance state of the current player with the target player.</summary> |
| 2275 | + * |
| 2276 | + * @param player The target player to set alliance with. |
| 2277 | + * @param allied If true, the current player will ally the target player. If false, the current player |
| 2278 | + * will make the target player an enemy. This value is true by default. |
| 2279 | + * @param alliedVictory Sets the state of "allied victory". If true, the game will end in a victory if all |
| 2280 | + * allied players have eliminated their opponents. Otherwise, the game will only end if |
| 2281 | + * no other players are remaining in the game. This value is true by default. |
| 2282 | + */ |
| 2283 | + public boolean setAlliance(Player player, boolean allied, boolean alliedVictory) { |
| 2284 | + if (self() == null || isReplay() || player == self || player.equals(self())) { |
| 2285 | + return false; |
| 2286 | + } |
| 2287 | + |
| 2288 | + addCommand(CommandType.SetAllies, player.getID(), allied ? (alliedVictory ? 2 : 1) : 0); |
| 2289 | + return true; |
| 2290 | + } |
| 2291 | + |
| 2292 | + public boolean setAlliance(Player player, boolean allied) { |
| 2293 | + return setAlliance(player, allied, true); |
| 2294 | + } |
| 2295 | + |
| 2296 | + public boolean setAlliance(Player player) { |
| 2297 | + return setAlliance(player, true); |
| 2298 | + } |
| 2299 | + |
| 2300 | + /** |
| 2301 | + * In a game, this function sets the vision of the current BWAPI player with the |
| 2302 | + * target player. |
| 2303 | + * |
| 2304 | + * In a replay, this function toggles the visibility of the target player. |
| 2305 | + * |
| 2306 | + * @param player The target player to toggle vision. |
| 2307 | + * @param enabled The vision state. If true, and in a game, the current player will enable shared vision |
| 2308 | + * with the target player, otherwise it will unshare vision. If in a replay, the vision |
| 2309 | + * of the target player will be shown, otherwise the target player will be hidden. This |
| 2310 | + * value is true by default. |
| 2311 | + */ |
| 2312 | + public boolean setVision(Player player, boolean enabled) { |
| 2313 | + // Param check |
| 2314 | + if ( player == null) { |
| 2315 | + return false; |
| 2316 | + } |
| 2317 | + |
| 2318 | + if ( !isReplay() && (self() == null || player.equals(self()))) { |
| 2319 | + return false; |
| 2320 | + } |
| 2321 | + |
| 2322 | + addCommand(CommandType.SetVision, player.getID(), enabled ? 1 : 0); |
| 2323 | + return true; |
| 2324 | + } |
| 2325 | + |
| 2326 | + /** |
| 2327 | + * Checks if the GUI is enabled. |
| 2328 | + * |
| 2329 | + * The GUI includes all drawing functions of BWAPI, as well as screen updates from Broodwar. |
| 2330 | + * |
| 2331 | + * @return true if the GUI is enabled, and everything is visible, false if the GUI is disabled and drawing |
| 2332 | + * functions are rejected |
| 2333 | + * |
| 2334 | + * @see #setGUI |
| 2335 | + */ |
| 2336 | + boolean isGUIEnabled() { |
| 2337 | + return gameData.getHasGUI(); |
| 2338 | + } |
| 2339 | + |
| 2340 | + /** |
| 2341 | + * Sets the rendering state of the Starcraft GUI. |
| 2342 | + * |
| 2343 | + * This typically gives Starcraft a very low graphical frame rate and disables all drawing functionality in BWAPI. |
| 2344 | + * |
| 2345 | + * @param enabled A boolean value that determines the state of the GUI. Passing false to this function |
| 2346 | + * will disable the GUI, and true will enable it. |
| 2347 | + * |
| 2348 | + * @see #isGUIEnabled |
| 2349 | + */ |
| 2350 | + public void setGUI(boolean enabled) { |
| 2351 | + gameData.setHasGUI(enabled); |
| 2352 | + //queue up command for server so it also applies the change |
| 2353 | + addCommand(CommandType.SetGui, enabled ? 1 : 0, 0); |
| 2354 | + } |
| 2355 | + |
| 2356 | + /** |
| 2357 | + * Retrieves the amount of time (in milliseconds) that has elapsed when running the last AI |
| 2358 | + * module callback. |
| 2359 | + * |
| 2360 | + * This is used by tournament modules to penalize AI modules that use too |
| 2361 | + * much processing time. |
| 2362 | + * |
| 2363 | + * @return Time in milliseconds spent in last AI module call. Returns 0 When called from an AI module. |
| 2364 | + */ |
| 2365 | + public int getLastEventTime() { |
| 2366 | + return 0; |
| 2367 | + } |
| 2368 | + |
| 2369 | + /** |
| 2370 | + * Changes the map to the one specified. |
| 2371 | + * |
| 2372 | + * Once restarted, the game will load the map that was provided. |
| 2373 | + * Changes do not take effect unless the game is restarted. |
| 2374 | + * |
| 2375 | + * @param mapFileName A string containing the path and file name to the desired map. |
| 2376 | + * |
| 2377 | + * @return Returns true if the function succeeded and has changed the map. Returns false if the function failed, |
| 2378 | + * does not have permission from the tournament module, failed to find the map specified, or received an invalid |
| 2379 | + * parameter. |
| 2380 | + */ |
| 2381 | + public boolean setMap(final String mapFileName) { |
| 2382 | + if (mapFileName == null || mapFileName.length() >= 260 || mapFileName.charAt(0) == 0) { |
| 2383 | + return false; |
| 2384 | + } |
| 2385 | + |
| 2386 | + if (!(new File(mapFileName).exists())) { |
| 2387 | + return false; |
| 2388 | + } |
| 2389 | + |
| 2390 | + addCommand(CommandType.SetMap, client.addString(mapFileName), 0); |
| 2391 | + return true; |
| 2392 | + } |
| 2393 | + |
| 2394 | + /** |
| 2395 | + * Sets the state of the fog of war when watching a replay. |
| 2396 | + * |
| 2397 | + * @param reveal The state of the reveal all flag. If false, all fog of war will be enabled. If true, |
| 2398 | + * then the fog of war will be revealed. It is true by default. |
| 2399 | + */ |
| 2400 | + public boolean setRevealAll(boolean reveal) { |
| 2401 | + if ( !isReplay() ) { |
| 2402 | + return false; |
| 2403 | + } |
| 2404 | + addCommand(CommandType.SetRevealAll, reveal ? 1 : 0, 0); |
| 2405 | + return true; |
| 2406 | + } |
| 2407 | + |
| 2408 | + public boolean setRevealAll() { |
| 2409 | + return setRevealAll(true); |
| 2410 | + } |
| 2411 | + |
2282 | 2412 |
|
2283 | 2413 | /** |
2284 | 2414 | * Checks if there is a path from source to destination. This only checks |
|
0 commit comments