Example #1
0
 @Override
 public void updateConditionFromEntity(boolean checkForDestruction) {
   int priorHits = hits;
   if (null != unit) {
     Entity entity = unit.getEntity();
     for (int i = 0; i < entity.locations(); i++) {
       if (entity.getNumberOfCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT, i) > 0) {
         // check for missing equipment as well
         if (!unit.isSystemMissing(Mech.SYSTEM_COCKPIT, i)) {
           hits = entity.getDamagedCriticals(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT, i);
           break;
         } else {
           remove(false);
           return;
         }
       }
     }
     if (checkForDestruction
         && hits > priorHits
         && Compute.d6(2) < campaign.getCampaignOptions().getDestroyPartTarget()) {
       remove(false);
       return;
     }
   }
 }
Example #2
0
 /*
  * (non-Javadoc)
  *
  * @see
  * megamek.common.weapons.WeaponHandler#handleEntityDamage(megamek.common
  * .Entity, java.util.Vector, megamek.common.Building, int, int, int, int)
  */
 @Override
 protected void handleEntityDamage(
     Entity entityTarget,
     Vector<Report> vPhaseReport,
     Building bldg,
     int hits,
     int nCluster,
     int bldgAbsorbs) {
   super.handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs);
   if (!missed && ((entityTarget instanceof Mech) || (entityTarget instanceof Aero))) {
     Report r = new Report(3400);
     r.subject = subjectId;
     r.indent(2);
     int extraHeat = 0;
     // if this is a fighter squadron, we need to account for number of
     // weapons
     // should default to one for non squadrons
     for (int i = 0; i < nweaponsHit; i++) {
       extraHeat += Compute.d6();
     }
     if (entityTarget.getArmor(hit) > 0
         && (entityTarget.getArmorType(hit.getLocation()) == EquipmentType.T_ARMOR_REFLECTIVE)) {
       entityTarget.heatFromExternal += Math.max(1, extraHeat / 2);
       r.add(Math.max(1, extraHeat / 2));
       r.choose(true);
       r.messageId = 3406;
       r.add(extraHeat);
       r.add(EquipmentType.armorNames[entityTarget.getArmorType(hit.getLocation())]);
     } else if (entityTarget.getArmor(hit) > 0
         && (entityTarget.getArmorType(hit.getLocation())
             == EquipmentType.T_ARMOR_HEAT_DISSIPATING)) {
       entityTarget.heatFromExternal += extraHeat / 2;
       r.add(extraHeat / 2);
       r.choose(true);
       r.messageId = 3406;
       r.add(extraHeat);
       r.add(EquipmentType.armorNames[entityTarget.getArmorType(hit.getLocation())]);
     } else {
       entityTarget.heatFromExternal += extraHeat;
       r.add(extraHeat);
       r.choose(true);
     }
     vPhaseReport.addElement(r);
   }
 }
Example #3
0
 /*
  * (non-Javadoc)
  *
  * @see megamek.common.weapons.WeaponHandler#calcnCluster()
  */
 @Override
 protected int calcnCluster() {
   if ((target instanceof Mech) || (target instanceof Aero)) {
     bSalvo = false;
     return 1;
   }
   int toReturn = 5;
   if ((target instanceof Infantry) && !(target instanceof BattleArmor)) {
     toReturn = Compute.d6(2);
   }
   bSalvo = true;
   // pain shunted infantry get half damage
   if ((target instanceof Infantry)
       && ((Entity) target).getCrew().getOptions().booleanOption("pain_shunt")) {
     toReturn = Math.max(toReturn / 2, 1);
   }
   return toReturn;
 }
Example #4
0
 /*
  * (non-Javadoc)
  *
  * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector)
  */
 @Override
 protected int calcHits(Vector<Report> vPhaseReport) {
   int toReturn;
   // against mechs, 1 hit with 10 damage, plus heat
   if ((target instanceof Mech) || (target instanceof Aero)) {
     toReturn = 1;
     // otherwise, 10+2d6 damage
     // but fireresistant BA armor gets no damage from heat, and half the
     // normal one, so only 5 damage
   } else {
     if ((target instanceof BattleArmor) && ((BattleArmor) target).isFireResistant()) {
       toReturn = 5;
     } else {
       toReturn = 10 + Compute.d6(2);
     }
     if (bGlancing) {
       toReturn = (int) Math.floor(toReturn / 2.0);
     }
   }
   return toReturn;
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector,
  * megamek.common.Entity, boolean)
  */
 @Override
 protected boolean specialResolution(Vector<Report> vPhaseReport, Entity entityTarget) {
   boolean done = false;
   if (bMissed) {
     return done;
   }
   Report r = new Report(3700);
   int taserRoll = Compute.d6(2);
   r.add(taserRoll);
   r.newlines = 0;
   vPhaseReport.add(r);
   if (entityTarget.getWeight() > 100) {
     return done;
   }
   if (entityTarget instanceof BattleArmor) {
     r = new Report(3706);
     r.addDesc(entityTarget);
     // shut down for rest of scenario, so we actually kill it
     // TODO: fix for salvage purposes
     r.add(entityTarget.getLocationAbbr(hit));
     vPhaseReport.add(r);
     entityTarget.destroyLocation(hit.getLocation());
     // Check to see if the squad has been eliminated
     if (entityTarget.getTransferLocation(hit).getLocation() == Entity.LOC_DESTROYED) {
       vPhaseReport.addAll(server.destroyEntity(entityTarget, "all troopers eliminated", false));
     }
     done = true;
   } else if (entityTarget instanceof Mech) {
     if (((Mech) entityTarget).isIndustrial()) {
       if (taserRoll >= 8) {
         r = new Report(3705);
         r.addDesc(entityTarget);
         r.add(4);
         entityTarget.taserShutdown(4, false);
       } else {
         // suffer +2 to piloting and gunnery for 4 rounds
         r = new Report(3710);
         r.addDesc(entityTarget);
         r.add(2);
         r.add(4);
         entityTarget.setTaserInterference(2, 4, true);
       }
     } else {
       if (taserRoll >= 11) {
         r = new Report(3705);
         r.addDesc(entityTarget);
         r.add(3);
         vPhaseReport.add(r);
         entityTarget.taserShutdown(3, false);
       } else {
         r = new Report(3710);
         r.addDesc(entityTarget);
         r.add(2);
         r.add(3);
         vPhaseReport.add(r);
         entityTarget.setTaserInterference(2, 3, true);
       }
     }
   } else if ((entityTarget instanceof Protomech)
       || (entityTarget instanceof Tank)
       || (entityTarget instanceof Aero)) {
     if (taserRoll >= 8) {
       r = new Report(3705);
       r.addDesc(entityTarget);
       r.add(4);
       vPhaseReport.add(r);
       entityTarget.taserShutdown(4, false);
     } else {
       r = new Report(3710);
       r.addDesc(entityTarget);
       r.add(2);
       r.add(4);
       vPhaseReport.add(r);
       entityTarget.setTaserInterference(2, 4, false);
     }
   }
   return done;
 }
Example #6
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());
    }
  }
Example #7
0
  void loadGame() {
    JFileChooser fc = new JFileChooser("savegames");
    fc.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100);
    fc.setDialogTitle(Messages.getString("MegaMek.SaveGameDialog.title"));
    fc.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(File dir) {
            return ((dir.getName() != null)
                && (dir.getName().endsWith(".sav")
                    || dir.getName().endsWith(".sav.gz")
                    || dir.isDirectory())); // $NON-NLS-1$
          }

          @Override
          public String getDescription() {
            return "Savegames";
          }
        });
    int returnVal = fc.showOpenDialog(frame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (fc.getSelectedFile() == null)) {
      // I want a file, y'know!
      return;
    }
    HostDialog hd = new HostDialog(frame);
    hd.setVisible(true);
    if ((hd.playerName == null) || (hd.serverPass == null) || (hd.port == 0)) {
      return;
    }

    // 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.PlayerNameAlert1.message"),
          Messages.getString("MegaMek.PlayerNameAlert1.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$
      return;
    }

    // kick off a RNG check
    d6();
    // start server
    try {
      server = new Server(hd.serverPass, hd.port, hd.register, hd.register ? hd.metaserver : "");
    } 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;
    }
    if (!server.loadGame(fc.getSelectedFile())) {
      JOptionPane.showMessageDialog(
          frame,
          Messages.getString("MegaMek.LoadGameAlert.message"),
          Messages.getString("MegaMek.LoadGameAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$
      server.die();
      server = null;
      return;
    }
    client = new Client(hd.playerName, "localhost", hd.port); // $NON-NLS-1$
    ClientGUI gui = new ClientGUI(client, controller);
    controller.clientgui = gui;
    frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    gui.initialize();
    frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    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.HostGameAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
      frame.setVisible(false);
      client.die();
    }
    optdlg = null;

    // free some memory thats only needed in lounge
    // This normally happens in the deployment phase in Client, but
    // if we are loading a game, this phase may not be reached
    MechFileParser.dispose();
    RandomNameGenerator.getInstance().dispose();
    // We must do this last, as the name and unit generators can create
    // a new instance if they are running
    MechSummaryCache.dispose();

    launch(gui.getFrame());
  }
Example #8
0
  /** Start instances of both the client and the server. */
  void host() {
    HostDialog hd;
    hd = new HostDialog(frame);
    hd.setVisible(true);
    // verify dialog data
    if ((hd.playerName == null) || (hd.serverPass == null) || (hd.port == 0)) {
      return;
    }

    // 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.PlayerNameAlert.message"),
          Messages.getString("MegaMek.PlayerNameAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$
      return;
    }

    // kick off a RNG check
    d6();
    // start server
    try {
      server = new Server(hd.serverPass, hd.port, hd.register, hd.register ? hd.metaserver : "");
    } 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;
    }
    // initialize client
    client = new Client(hd.playerName, "localhost", hd.port); // $NON-NLS-1$
    ClientGUI gui = new ClientGUI(client, controller);
    controller.clientgui = gui;
    frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    gui.initialize();
    frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    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.HostGameAlert.title"),
          JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
      frame.setVisible(false);
      client.die();
    }
    launch(gui.getFrame());

    optdlg = null;
  }