public static void initContainerForRobocodeEngine(File robocodeHome, IBattleListener listener) { try { if (robocodeHome == null) { robocodeHome = FileUtil.getCwd(); } FileUtil.setCwd(robocodeHome); File robotsDir = FileUtil.getRobotsDir(); if (robotsDir == null) { throw new RuntimeException("No valid robot directory is specified"); } else if (!(robotsDir.exists() && robotsDir.isDirectory())) { throw new RuntimeException( '\'' + robotsDir.getAbsolutePath() + "' is not a valid robot directory"); } } catch (IOException e) { System.err.println(e); return; } // here we cross transition to EngineClassLoader classes using interface which is defined in // system classLoader RobocodeMainBase main = Container.getComponent(RobocodeMainBase.class); main.initForRobocodeEngine(listener); }
public void loadSetup(String[] args) { final String nosecMessage = "Robocode is running without a security manager.\n" + "Robots have full access to your system.\n" + "You should only run robots which you trust!"; final String exMessage = "Robocode is running in experimental mode.\n" + "Robots have access to their IRobotPeer interfaces.\n" + "You should only run robots which you trust!"; if (RobocodeProperties.isSecurityOff()) { Logger.logWarning(nosecMessage); } if (System.getProperty("EXPERIMENTAL", "false").equals("true")) { Logger.logWarning(exMessage); } setup.tps = properties.getOptionsBattleDesiredTPS(); // Disable canonical file path cache under Windows as it causes trouble when returning // paths with differently-capitalized file names. if (System.getProperty("os.name").toLowerCase().startsWith("windows ")) { System.setProperty("sun.io.useCanonCaches", "false"); } // Initialize the system property so the AWT does not use headless mode meaning that the // GUI (Awt and Swing) is enabled per default when running starting Robocode. // It might be set to true later, if the -nodisplay option is set (in the setEnableGUI method). // Read more about headless mode here: // http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ System.setProperty("java.awt.headless", "false"); for (int i = 0; i < args.length; i++) { String currentArg = args[i]; if (currentArg.equalsIgnoreCase("-cwd") && (i < args.length + 1)) { changeDirectory(args[i + 1]); i++; } else if (currentArg.equalsIgnoreCase("-battle") && (i < args.length + 1)) { setup.battleFilename = args[i + 1]; i++; } else if (currentArg.equalsIgnoreCase("-record") && (i < args.length + 1)) { setup.recordFilename = args[i + 1]; i++; } else if (currentArg.equalsIgnoreCase("-recordXML") && (i < args.length + 1)) { setup.recordXmlFilename = args[i + 1]; i++; } else if (currentArg.equalsIgnoreCase("-replay") && (i < args.length + 1)) { setup.replayFilename = args[i + 1]; i++; } else if (currentArg.equalsIgnoreCase("-results") && (i < args.length + 1)) { setup.resultsFilename = args[i + 1]; i++; } else if (currentArg.equalsIgnoreCase("-tps") && (i < args.length + 1)) { setup.tps = Integer.parseInt(args[i + 1]); if (setup.tps < 1) { Logger.logError("tps must be > 0"); System.exit(8); } i++; } else if (currentArg.equalsIgnoreCase("-minimize")) { setup.minimize = true; } else if (currentArg.equalsIgnoreCase("-nodisplay")) { if (windowManager != null) { windowManager.setEnableGUI(false); } if (soundManager != null) { soundManager.setEnableSound(false); } setup.tps = 10000; // set TPS to maximum } else if (currentArg.equalsIgnoreCase("-nosound")) { if (soundManager != null) { soundManager.setEnableSound(false); } } else if (currentArg.equals("-?") || currentArg.equalsIgnoreCase("-help")) { printUsage(); System.exit(0); } else { Logger.logError("Not understood: " + currentArg); printUsage(); System.exit(8); } } File robotsDir = FileUtil.getRobotsDir(); if (robotsDir == null) { System.err.println("No valid robot directory is specified"); System.exit(8); } else if (!(robotsDir.exists() && robotsDir.isDirectory())) { System.err.println('\'' + robotsDir.getAbsolutePath() + "' is not a valid robot directory"); System.exit(8); } // The Default Toolkit must be set as soon as we know if we are going to use headless mode or // not. // That is if the toolkit must be headless or not (GUI on/off). If we are running in headless // mode // from this point, a HeadlessException will be thrown if we access a AWT/Swing component. // Read more about headless mode here: // http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ Toolkit.getDefaultToolkit(); }