Esempio n. 1
0
  public void clearOptions() {
    for (Enumeration<IOptionGroup> i = options.getGroups(); i.hasMoreElements(); ) {
      IOptionGroup group = i.nextElement();

      for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements(); ) {
        IOption option = j.nextElement();

        option.clearValue();
      }
    }
  }
Esempio n. 2
0
  public void clearOptions(String grpKey) {
    for (Enumeration<IOptionGroup> i = options.getGroups(); i.hasMoreElements(); ) {
      IOptionGroup group = i.nextElement();

      if (!group.getKey().equalsIgnoreCase(grpKey)) {
        continue;
      }

      for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements(); ) {
        IOption option = j.nextElement();

        option.clearValue();
      }
    }
  }
Esempio n. 3
0
  public int countOptions() {
    int count = 0;

    for (Enumeration<IOptionGroup> i = options.getGroups(); i.hasMoreElements(); ) {
      IOptionGroup group = i.nextElement();
      for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements(); ) {
        IOption option = j.nextElement();

        if (option.booleanValue()) {
          count++;
        }
      }
    }

    return count;
  }
Esempio n. 4
0
  public int countOptions(String grpKey) {
    int count = 0;

    for (Enumeration<IOptionGroup> i = options.getGroups(); i.hasMoreElements(); ) {
      IOptionGroup group = i.nextElement();

      if (!group.getKey().equalsIgnoreCase(grpKey)) {
        continue;
      }

      for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements(); ) {
        IOption option = j.nextElement();

        if (option != null && option.booleanValue()) {
          count++;
        }
      }
    }

    return count;
  }
Esempio n. 5
0
  /**
   * Returns a string of all the option "codes" for this pilot, for a given group, using sep as the
   * separator
   */
  public String getOptionList(String sep, String grpKey) {
    StringBuffer adv = new StringBuffer();

    if (null == sep) {
      sep = "";
    }

    for (Enumeration<IOptionGroup> i = options.getGroups(); i.hasMoreElements(); ) {
      IOptionGroup group = i.nextElement();
      if (!group.getKey().equalsIgnoreCase(grpKey)) {
        continue;
      }
      for (Enumeration<IOption> j = group.getOptions(); j.hasMoreElements(); ) {
        IOption option = j.nextElement();

        if (option.booleanValue()) {
          if (adv.length() > 0) {
            adv.append(sep);
          }

          adv.append(option.getName());
          if ((option.getType() == IOption.STRING)
              || (option.getType() == IOption.CHOICE)
              || (option.getType() == IOption.INTEGER)) {
            adv.append(" ").append(option.stringValue());
          }
        }
      }
    }

    return adv.toString();
  }
Esempio n. 6
0
 public void decreaseEdge() {
   IOption edgeOption = getOptions().getOption("edge");
   edgeOption.setValue((Integer) edgeOption.getValue() - 1);
 }
Esempio n. 7
0
  /** updates fields for the unit */
  public void setEntity(Entity en) {

    if (en instanceof Infantry) {
      pilotL.setString(Messages.getString("PilotMapSet.pilotLAntiMech"));
    } else {
      pilotL.setString(Messages.getString("PilotMapSet.pilotL"));
    }
    nameL.setString(en.getCrew().getName());
    nickL.setString(en.getCrew().getNickname());
    pilotR.setString(Integer.toString(en.getCrew().getPiloting()));
    gunneryR.setString(Integer.toString(en.getCrew().getGunnery()));

    if (null != getPortrait(en.getCrew())) {
      portraitArea.setIdleImage(getPortrait(en.getCrew()));
    }

    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("rpg_gunnery")) {
      gunneryLR.setString(Integer.toString(en.getCrew().getGunneryL()));
      gunneryMR.setString(Integer.toString(en.getCrew().getGunneryM()));
      gunneryBR.setString(Integer.toString(en.getCrew().getGunneryB()));
      gunneryL.setVisible(false);
      gunneryR.setVisible(false);
      gunneryLL.setVisible(true);
      gunneryLR.setVisible(true);
      gunneryML.setVisible(true);
      gunneryMR.setVisible(true);
      gunneryBL.setVisible(true);
      gunneryBR.setVisible(true);
    } else {
      gunneryLL.setVisible(false);
      gunneryLR.setVisible(false);
      gunneryML.setVisible(false);
      gunneryMR.setVisible(false);
      gunneryBL.setVisible(false);
      gunneryBR.setVisible(false);
      gunneryL.setVisible(true);
      gunneryR.setVisible(true);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("toughness")) {
      toughBR.setString(Integer.toString(en.getCrew().getToughness()));
    } else {
      toughBL.setVisible(false);
      toughBR.setVisible(false);
    }
    if ((en.getGame() != null)
        && en.getGame().getOptions().booleanOption("individual_initiative")) {
      initBR.setString(Integer.toString(en.getCrew().getInitBonus()));
    } else {
      initBL.setVisible(false);
      initBR.setVisible(false);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("command_init")) {
      commandBR.setString(Integer.toString(en.getCrew().getCommandBonus()));
    } else {
      commandBL.setVisible(false);
      commandBR.setVisible(false);
    }
    hitsR.setString(en.getCrew().getStatusDesc());
    for (int i = 0; i < advantagesR.length; i++) {
      advantagesR[i].setString(""); // $NON-NLS-1$
    }
    int i = 0;
    for (Enumeration<IOptionGroup> advGroups = en.getCrew().getOptions().getGroups();
        advGroups.hasMoreElements(); ) {
      if (i >= (N_ADV - 1)) {
        advantagesR[i++].setString(Messages.getString("PilotMapSet.more"));
        break;
      }
      IOptionGroup advGroup = advGroups.nextElement();
      if (en.getCrew().countOptions(advGroup.getKey()) > 0) {
        advantagesR[i++].setString(advGroup.getDisplayableName());
        for (Enumeration<IOption> advs = advGroup.getOptions(); advs.hasMoreElements(); ) {
          if (i >= (N_ADV - 1)) {
            advantagesR[i++].setString("  " + Messages.getString("PilotMapSet.more"));
            break;
          }
          IOption adv = advs.nextElement();
          if (adv.booleanValue()) {
            advantagesR[i++].setString("  " + adv.getDisplayableNameWithValue());
          }
        }
      }
    }
  }
Esempio n. 8
0
  /** Host a game constructed from a scenario file */
  void scenario() {
    JFileChooser fc = new JFileChooser("data" + File.separatorChar + "scenarios");
    fc.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100);
    fc.setDialogTitle(Messages.getString("MegaMek.SelectScenarioDialog.title"));

    FileFilter filter =
        new FileFilter() {

          @Override
          public boolean accept(File f) {
            if (f.isDirectory()) {
              return true;
            }

            String ext = null;
            String s = f.getName();
            int i = s.lastIndexOf('.');

            if ((i > 0) && (i < (s.length() - 1))) {
              ext = s.substring(i + 1).toLowerCase();
            }

            if (ext != null) {
              if (ext.equalsIgnoreCase("mms")) {
                return true;
              }
              return false;
            }

            return false;
          }

          @Override
          public String getDescription() {
            return "MegaMek Scenario Files";
          }
        };
    fc.setFileFilter(filter);

    int returnVal = fc.showOpenDialog(frame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (fc.getSelectedFile() == null)) {
      // I want a file, y'know!
      return;
    }

    ScenarioLoader sl = new ScenarioLoader(fc.getSelectedFile());
    IGame g;
    try {
      g = sl.createGame();
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          frame,
          Messages.getString("MegaMek.HostScenarioAlert.message") + e.getMessage(),
          Messages.getString("MegaMek.HostScenarioAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$
      return;
    }

    // popup options dialog
    GameOptionsDialog god = new GameOptionsDialog(frame, g.getOptions(), false);
    god.update(g.getOptions());
    god.setEditable(true);
    god.setVisible(true);
    for (IBasicOption opt : god.getOptions()) {
      IOption orig = g.getOptions().getOption(opt.getName());
      orig.setValue(opt.getValue());
    }
    god = null;

    // popup planetry conditions dialog
    PlanetaryConditionsDialog pcd =
        new PlanetaryConditionsDialog(frame, g.getPlanetaryConditions());
    pcd.update(g.getPlanetaryConditions());
    pcd.setVisible(true);
    g.setPlanetaryConditions(pcd.getConditions());
    pcd = null;

    // get player types and colors set
    Player[] pa = new Player[g.getPlayersVector().size()];
    g.getPlayersVector().copyInto(pa);
    ScenarioDialog sd = new ScenarioDialog(frame, pa);
    sd.setVisible(true);
    if (!sd.bSet) {
      return;
    }

    // host with the scenario. essentially copied from host()
    HostDialog hd = new HostDialog(frame);
    boolean hasSlot = false;
    if (!("".equals(sd.localName))) {
      hasSlot = true;
    }
    hd.yourNameF.setText(sd.localName);
    hd.setVisible(true);
    // verify dialog data
    if ((hd.playerName == null) || (hd.serverPass == null) || (hd.port == 0)) {
      return;
    }
    sd.localName = hd.playerName;

    // Players should have to enter a non-blank, non-whitespace name.
    boolean foundValid = false;
    char[] nameChars = hd.playerName.toCharArray();
    for (int loop = 0; !foundValid && (loop < nameChars.length); loop++) {
      if (!Character.isWhitespace(nameChars[loop])) {
        foundValid = true;
      }
    }
    if (!foundValid) {
      JOptionPane.showMessageDialog(
          frame,
          Messages.getString("MegaMek.HostScenarioAlert1.message"),
          Messages.getString("MegaMek.HostScenarioAlert1.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$
      return;
    }

    // kick off a RNG check
    Compute.d6();

    // start server
    try {
      server = new Server(hd.serverPass, hd.port);
    } catch (IOException ex) {
      System.err.println("could not create server socket on port " + hd.port);
      StringBuffer error = new StringBuffer();
      error
          .append("Error: could not start server at localhost")
          .append(":")
          .append(hd.port)
          .append(" (")
          .append(ex.getMessage())
          .append(").");
      JOptionPane.showMessageDialog(
          frame,
          error.toString(),
          Messages.getString("MegaMek.HostGameAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
      return;
    }
    server.setGame(g);

    // apply any scenario damage
    sl.applyDamage(server);
    ClientGUI gui = null;
    if (!"".equals(sd.localName)) { // $NON-NLS-1$
      // initialize game
      client = new Client(hd.playerName, "localhost", hd.port); // $NON-NLS-1$
      gui = new ClientGUI(client, controller);
      controller.clientgui = gui;
      gui.initialize();
      if (!client.connect()) {
        StringBuffer error = new StringBuffer();
        error
            .append("Error: could not connect to server at localhost")
            .append(":")
            .append(hd.port)
            .append(".");
        JOptionPane.showMessageDialog(
            frame,
            error.toString(),
            Messages.getString("MegaMek.HostScenarioAlert.title"),
            JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
        frame.setVisible(false);
        client.die();
      }
    }
    optdlg = null;

    // calculate initial BV
    server.calculatePlayerBVs();

    // setup any bots
    for (int x = 0; x < pa.length; x++) {
      if (sd.playerTypes[x] == ScenarioDialog.T_BOT) {
        BotClient c = new TestBot(pa[x].getName(), "localhost", hd.port); // $NON-NLS-1$
        c.getGame().addGameListener(new BotGUI(c));
        if (!c.connect()) {
          // bots should never fail on connect
        }
      }
    }

    for (int x = 0; x < pa.length; x++) {
      if (sd.playerTypes[x] == ScenarioDialog.T_OBOT) {
        BotClient c =
            new Princess(pa[x].getName(), "localhost", hd.port, LogLevel.ERROR); // $NON-NLS-1$
        c.getGame().addGameListener(new BotGUI(c));
        if (!c.connect()) {
          // bots should never fail on connect
        }
      }
    }

    // If he didn't have a name when hasSlot was set, then the host should
    // be an observer.
    if (!hasSlot) {
      Enumeration<IPlayer> pE = server.getGame().getPlayers();
      while (pE.hasMoreElements()) {
        IPlayer tmpP = pE.nextElement();
        if (tmpP.getName().equals(sd.localName)) {
          tmpP.setObserver(true);
        }
      }
    }
    if (gui != null) {
      launch(gui.getFrame());
    }
  }