public static void main(String[] args) {

    Logger.getRootLogger()
        .addAppender(
            new ConsoleAppender(
                new org.apache.log4j.PatternLayout("%d - %-5p - %-20c (%C [%L]) - %m%n")));
    GlobalOptions.setSelectedServer("de43");
    GlobalOptions.setSelectedProfile(new DummyProfile());
    DataHolder.getSingleton().loadData(false);
    try {
      //  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (Exception e) {
    }
    List<Village> selection = new LinkedList<Village>();
    for (int i = 0; i < 100; i++) {
      selection.add(DataHolder.getSingleton().getRandomVillage());
    }

    DSWorkbenchSelectionFrame.getSingleton().resetView();
    DSWorkbenchSelectionFrame.getSingleton().addVillages(selection);

    DSWorkbenchSelectionFrame.getSingleton().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DSWorkbenchSelectionFrame.getSingleton().setVisible(true);
  }
 /** Get thr unit icon for the provided ID */
 public static ImageIcon getUnitIcon(int pId, boolean pChecked) {
   if ((DataHolder.getSingleton().getUnits().size() == 9
           || DataHolder.getSingleton().getUnits().size() == 10)
       && pChecked) {
     // old style
     switch (pId) {
       case 0:
         return UNIT_ICONS.get(0);
       case 1:
         return UNIT_ICONS.get(1);
       case 2:
         return UNIT_ICONS.get(2);
       case 3:
         return UNIT_ICONS.get(4);
       case 4:
         return UNIT_ICONS.get(5);
       case 5:
         return UNIT_ICONS.get(7);
       case 6:
         return UNIT_ICONS.get(8);
       case 7:
         return UNIT_ICONS.get(9);
       case 8:
         return UNIT_ICONS.get(11);
       default:
         return UNIT_ICONS.get(12);
     }
   } else {
     return UNIT_ICONS.get(pId);
   }
 }
  private Hashtable<UnitHolder, Integer> getDefendingTroops() {
    Hashtable<String, Integer> units = new Hashtable<String, Integer>();
    if (jMedDef.isSelected()) {
      units.put("spear", getRandomValueInRange(1000, 2000));
      units.put("sword", getRandomValueInRange(1000, 2000));
      units.put("heavy", getRandomValueInRange(300, 500));
      units.put("spy", getRandomValueInRange(100, 200));
    } else if (jFullDef.isSelected()) {
      units.put("spear", getRandomValueInRange(5000, 6000));
      units.put("sword", getRandomValueInRange(5000, 6000));
      units.put("heavy", getRandomValueInRange(2000, 3000));
      units.put("spy", getRandomValueInRange(500, 800));
    } else if (jNoDef.isSelected()) {
      // add nothing
    }

    Hashtable<UnitHolder, Integer> result = TroopHelper.unitTableFromSerializableFormat(units);
    for (UnitHolder u : DataHolder.getSingleton().getUnits()) {
      if (!result.containsKey(u)) {
        result.put(u, 0);
      }
    }

    return result;
  }
  /** Get thr unit icon for the provided ID */
  public static BufferedImage getUnitImage(int pId, boolean pChecked) {

    if (DataHolder.getSingleton().getUnits().size() == 9 && pChecked) {
      // old style
      switch (pId) {
        case 0:
          return UNIT_IMAGES.get(0);
        case 1:
          return UNIT_IMAGES.get(1);
        case 2:
          return UNIT_IMAGES.get(2);
        case 3:
          return UNIT_IMAGES.get(4);
        case 4:
          return UNIT_IMAGES.get(5);
        case 5:
          return UNIT_IMAGES.get(7);
        case 6:
          return UNIT_IMAGES.get(8);
        case 7:
          return UNIT_IMAGES.get(9);
        case 8:
          return UNIT_IMAGES.get(11);
        default:
          return UNIT_IMAGES.get(12);
      }
    } else {
      return UNIT_IMAGES.get(pId);
    }
  }
Exemple #5
0
 @Override
 public void loadFromXml(Element pElement) {
   setVillage(
       DataHolder.getSingleton()
           .getVillagesById()
           .get(Integer.parseInt(pElement.getChild("village").getText())));
   setRange(Integer.parseInt(pElement.getChild("range").getText()));
 }
  /** @param args the command line arguments */
  public static void main(String args[]) {
    /*
     * Set the Nimbus look and feel
     */
    // <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
     * If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info :
          javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException ex) {
      java.util.logging.Logger.getLogger(SOSGenerator.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(SOSGenerator.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(SOSGenerator.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(SOSGenerator.class.getName())
          .log(java.util.logging.Level.SEVERE, null, ex);
    }
    // </editor-fold>
    Logger.getRootLogger()
        .addAppender(
            new ConsoleAppender(
                new org.apache.log4j.PatternLayout("%d - %-5p - %-20c (%C [%L]) - %m%n")));
    GlobalOptions.setSelectedServer("de43");
    ProfileManager.getSingleton().loadProfiles();
    GlobalOptions.setSelectedProfile(ProfileManager.getSingleton().getProfiles("de43")[0]);
    DataHolder.getSingleton().loadData(false);
    GlobalOptions.loadUserData();
    /*
     * Create and display the form
     */
    java.awt.EventQueue.invokeLater(
        new Runnable() {

          public void run() {
            new SOSGenerator().setVisible(true);
          }
        });
  }
  private void firePerformRegionSelectionEvent(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_firePerformRegionSelectionEvent
    if (evt.getSource() == jPerformSelection) {
      Point start = new Point((Integer) jStartX.getValue(), (Integer) jStartY.getValue());
      Point end = new Point((Integer) jEndX.getValue(), (Integer) jEndY.getValue());
      if (start.x < 0
          || end.x < 0
          || start.y > ServerSettings.getSingleton().getMapDimension().height
          || end.y > ServerSettings.getSingleton().getMapDimension().getHeight()) {
        showError("Ungültiger Start- oder Endpunkt");
      } else if ((Math.abs(end.x - start.x) * (end.y - start.y)) > 30000) {
        showError(
            "<html>Die angegebene Auswahl k&ouml;nnte mehr als 10.000 D&ouml;rfer umfassen.<br/>"
                + "Die Auswahl k&ouml;nnte so sehr lange dauern. Bitte verkleinere den gew&auml;hlten Bereich.");
      } else {
        List<Village> selection = DataHolder.getSingleton().getVillagesInRegion(start, end);
        addVillages(selection);
      }
    }

    jRegionSelectDialog.setVisible(false);
  } // GEN-LAST:event_firePerformRegionSelectionEvent
 @Override
 public void fireSelectionFinishedEvent(Point pStart, Point pEnd) {
   addVillages(DataHolder.getSingleton().getVillagesInRegion(pStart, pEnd));
 }
  private void generateSOS() {
    String plan = (String) jAttackPlan.getSelectedItem();
    int amount = Math.min(UIHelper.parseIntFromField(jAmount, 1), jAttack.getItemCount());
    SOSRequest sos = null;
    Tribe t = null;
    for (int i = 0; i < amount; i++) {
      Attack a = AttackManager.getSingleton().getManagedElement(plan, i);
      if (sos == null) {
        sos = new SOSRequest(a.getTarget().getTribe());
        t = a.getTarget().getTribe();
      }

      if (t != null && a.getTarget().getTribe().getId() == t.getId()) {
        TargetInformation info = sos.addTarget(a.getTarget());
        if (info.getTroops().isEmpty()) {
          Hashtable<UnitHolder, Integer> troops = getDefendingTroops();

          Enumeration<UnitHolder> keys = troops.keys();
          while (keys.hasMoreElements()) {
            UnitHolder key = keys.nextElement();
            info.addTroopInformation(key, troops.get(key));
          }
          info.setWallLevel(20);
        }
        if (jIncludeTypes.isSelected()) {
          info.addAttack(
              a.getSource(),
              a.getArriveTime(),
              a.getUnit(),
              a.getType() == Attack.FAKE_TYPE,
              a.getUnit().getPlainName().equals("snob"));
        } else {
          info.addAttack(a.getSource(), a.getArriveTime());
        }
      } else {
        System.err.println(
            "Tribe "
                + a.getTarget().getTribe()
                + "does not fit request tribe "
                + sos.getDefender());
      }
    }

    /**
     * [b]Dorf:[/b] [coord]112|87[/coord] [b]Wallstufe:[/b] 20 [b]Verteidiger:[/b] 23011 22928 0 266
     * 0 814 0 0 0
     *
     * <p>bäääng! [coord]282|306[/coord] --> Ankunftszeit: 11.10.11 14:37:57
     * [player]MrBlue76[/player]
     *
     * <p>[b]Dorf:[/b] [coord]114|84[/coord] [b]Wallstufe:[/b] 20 [b]Verteidiger:[/b] 9079 9080 0
     * 100 0 300 0 0 0
     *
     * <p>bäääng! [coord]318|272[/coord] --> Ankunftszeit: 11.10.11 14:42:49
     * [player]MrBlue76[/player] bäääng! [coord]211|345[/coord] --> Ankunftszeit: 11.10.11 16:45:37
     * [player]MrBlue76[/player]
     */
    Enumeration<Village> targets = sos.getTargets();
    StringBuilder b = new StringBuilder();
    SimpleDateFormat df;
    if (de.tor.tribes.util.ServerSettings.getSingleton().isMillisArrival()) {
      df = new SimpleDateFormat("dd.MM.yy HH:mm:ss:SSS");
    } else {
      df = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
    }
    while (targets.hasMoreElements()) {
      Village target = targets.nextElement();
      b.append("[b]Dorf:[/b] ").append(target.toBBCode()).append("\n");
      TargetInformation ti = sos.getTargetInformation(target);
      b.append("[b]Wallstufe:[/b] ").append(ti.getWallLevel()).append("\n");
      b.append("[b]Verteidiger:[/b] ");
      for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        b.append(ti.getTroops().get(unit)).append(" ");
      }
      b.append("\n\n");
      for (TimedAttack a : ti.getAttacks()) {
        if (jIncludeTypes.isSelected()) {
          if (a.isPossibleFake()) {
            b.append("Fake, ");
          } else {
            if (a.getUnit() != null) {
              if (a.getUnit().getPlainName().equals("axe")) {
                b.append("Axt, ");
              } else if (a.getUnit().getPlainName().equals("light")) {
                b.append("LKAV, ");
              } else if (a.getUnit().getPlainName().equals("snob")) {
                b.append("AG, ");
              } else if (a.getUnit().getPlainName().equals("heavy")) {
                b.append("SKAV, ");
              } else if (a.getUnit().getPlainName().equals("sword")) {
                b.append("Schwert, ");
              } else if (a.getUnit().getPlainName().equals("catapult")) {
                b.append("Kata, ");
              }
            }
          }
        }
        b.append(a.getSource().getName())
            .append(" ")
            .append(a.getSource().toBBCode())
            .append(" --> Ankunftszeit: ")
            .append(df.format(new Date(a.getlArriveTime())))
            .append(" ")
            .append(a.getSource().getTribe().toBBCode())
            .append("\n");
      }
      b.append("\n");
    }
    sendToClipboard(b.toString());
  }
  public static void doExport(File pHtmlFile, String pPlanName, List<Attack> pAttacks) {
    if (TEMPLATE_ERROR) {
      logger.warn("Skip writing HTML file due to TEMPLATE_ERROR flag");
      return;
    }
    SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    StringBuffer result = new StringBuffer();
    // append header
    result.append(replaceHeadFootVariables(HEADER, pPlanName, pAttacks));

    int cnt = 0;
    for (Attack a : pAttacks) {
      String b = BLOCK;
      // <editor-fold defaultstate="collapsed" desc="Replace DIV-IDs">
      if (cnt % 2 == 0) {
        b = b.replaceAll(DIV_CLASS, "odd_div");
      } else {
        b = b.replaceAll(DIV_CLASS, "even_div");
      }
      b = b.replaceAll(ID, Integer.toString(cnt));
      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace Unit Icons">
      UnitHolder unit = a.getUnit();
      b =
          b.replaceAll(
              UNIT,
              "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/"
                  + unit.getPlainName()
                  + ".png\">");

      switch (a.getType()) {
        case Attack.CLEAN_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/att.png\">");
            break;
          }
        case Attack.SNOB_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/snob.png\">");
            break;
          }
        case Attack.FAKE_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/fake.png\">");
            break;
          }
        case Attack.FAKE_DEFF_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE,
                    "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/def_fake.png\">");
            break;
          }
        case Attack.SUPPORT_TYPE:
          {
            b =
                b.replaceAll(
                    TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/ally.png\">");
            break;
          }
        default:
          {
            b = b.replaceAll(TYPE, "-");
            break;
          }
      }
      // </editor-fold>

      String baseURL = ServerManager.getServerURL(GlobalOptions.getSelectedServer()) + "/";

      // <editor-fold defaultstate="collapsed" desc=" replace source tribe and ally">
      Tribe sourceTribe = a.getSource().getTribe();
      String sourceTribeName = "";
      String sourceTribeLink = "";
      String sourceAllyName = "";
      String sourceAllyTag = "";
      String sourceAllyLink = "";
      String sourceVillageName = "";
      String sourceVillageCoord = "";
      String sourceVillageLink = "";

      if (sourceTribe == null) {
        // tribe is null, so it is a barbarian village
        sourceTribeName = "Barbaren";
        sourceAllyName = "Barbaren";
      } else {
        sourceTribeLink = baseURL;
        sourceTribeLink += "guest.php?screen=info_player&id=" + sourceTribe.getId();
        sourceTribeName = sourceTribe.getName();

        // replace source tribe
        Ally sourceAlly = sourceTribe.getAlly();
        if (sourceAlly == null) {
          // tribe has no ally
          sourceAllyName = "Kein Stamm";
        } else {
          // ally valid
          sourceAllyName = sourceAlly.getName();
          sourceAllyTag = sourceAlly.getTag();
          sourceAllyLink = baseURL;
          sourceAllyLink += "guest.php?screen=info_ally&id=" + sourceAlly.getId();
        }
      }
      // replace source village
      sourceVillageLink = baseURL;
      sourceVillageLink += "guest.php?screen=info_village&id=" + a.getSource().getId();
      sourceVillageName = a.getSource().getFullName();
      sourceVillageCoord = a.getSource().getCoordAsString();

      // replace values
      b = b.replaceAll(SOURCE_PLAYER_NAME, Matcher.quoteReplacement(sourceTribeName));
      b = b.replaceAll(SOURCE_PLAYER_LINK, sourceTribeLink);
      b = b.replaceAll(SOURCE_ALLY_NAME, Matcher.quoteReplacement(sourceAllyName));
      b = b.replaceAll(SOURCE_ALLY_TAG, Matcher.quoteReplacement(sourceAllyTag));
      b = b.replaceAll(SOURCE_ALLY_LINK, sourceAllyLink);
      b = b.replaceAll(SOURCE_VILLAGE_NAME, Matcher.quoteReplacement(sourceVillageName));
      b = b.replaceAll(SOURCE_VILLAGE_COORD, sourceVillageCoord);
      b = b.replaceAll(SOURCE_VILLAGE_LINK, sourceVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc=" replace target tribe and ally">
      Tribe targetTribe = a.getTarget().getTribe();
      String targetTribeName = "";
      String targetTribeLink = "";
      String targetAllyName = "";
      String targetAllyTag = "";
      String targetAllyLink = "";
      String targetVillageName = "";
      String targetVillageCoord = "";
      String targetVillageLink = "";

      if (targetTribe == null) {
        // tribe is null, so it is a barbarian village
        targetTribeName = "Barbaren";
        targetAllyName = "Barbaren";
      } else {
        targetTribeLink = baseURL;
        targetTribeLink += "guest.php?screen=info_player&id=" + targetTribe.getId();
        targetTribeName = targetTribe.getName();

        // replace source tribe
        Ally targetAlly = targetTribe.getAlly();
        if (targetAlly == null) {
          // tribe has no ally
          targetAllyName = "Kein Stamm";
        } else {
          // ally valid
          targetAllyName = targetAlly.getName();
          targetAllyTag = targetAlly.getTag();
          targetAllyLink = baseURL;
          targetAllyLink += "guest.php?screen=info_ally&id=" + targetAlly.getId();
        }
      }
      // replace source village
      targetVillageLink = baseURL;
      targetVillageLink += "guest.php?screen=info_village&id=" + a.getTarget().getId();
      targetVillageName = a.getTarget().getFullName();
      targetVillageCoord = a.getTarget().getCoordAsString();

      // replace values
      b = b.replaceAll(TARGET_PLAYER_NAME, Matcher.quoteReplacement(targetTribeName));
      b = b.replaceAll(TARGET_PLAYER_LINK, targetTribeLink);
      b = b.replaceAll(TARGET_ALLY_NAME, Matcher.quoteReplacement(targetAllyName));
      b = b.replaceAll(TARGET_ALLY_TAG, Matcher.quoteReplacement(targetAllyTag));
      b = b.replaceAll(TARGET_ALLY_LINK, targetAllyLink);
      b = b.replaceAll(TARGET_VILLAGE_NAME, Matcher.quoteReplacement(targetVillageName));
      b = b.replaceAll(TARGET_VILLAGE_COORD, targetVillageCoord);
      b = b.replaceAll(TARGET_VILLAGE_LINK, targetVillageLink);

      // </editor-fold>

      // <editor-fold defaultstate="collapsed" desc="Replace times and place URL">
      // replace arrive time
      String arrive = f.format(a.getArriveTime());
      b = b.replaceAll(ARRIVE_TIME, arrive);
      // replace send time
      long send =
          a.getArriveTime().getTime()
              - ((long)
                      DSCalculator.calculateMoveTimeInSeconds(
                          a.getSource(), a.getTarget(), a.getUnit().getSpeed())
                  * 1000);
      b = b.replaceAll(SEND_TIME, f.format(new Date(send)));
      // replace place link
      String placeURL = baseURL + "game.php?village=";
      int uvID = GlobalOptions.getSelectedProfile().getUVId();
      if (uvID >= 0) {
        placeURL = baseURL + "game.php?t=" + uvID + "&village=";
      }
      placeURL +=
          a.getSource().getId() + "&screen=place&mode=command&target=" + a.getTarget().getId();

      placeURL += "&type=0";

      StandardAttack stdAttack = StandardAttackManager.getSingleton().getElementByIcon(a.getType());
      for (UnitHolder u : DataHolder.getSingleton().getUnits()) {
        int amount = 0;
        if (stdAttack != null) {
          amount = stdAttack.getAmountForUnit(u, a.getSource());
        }
        placeURL += "&" + u.getPlainName() + "=" + amount;
      }

      b = b.replaceAll(PLACE, placeURL);
      // </editor-fold>

      result.append(b);
      cnt++;
    }

    // append footer
    result.append(replaceHeadFootVariables(FOOTER, pPlanName, pAttacks));
    try {
      FileWriter w = new FileWriter(pHtmlFile);
      w.write(result.toString());
      w.flush();
      w.close();
    } catch (Exception e) {
      logger.error("Failed writing HTML file", e);
    }
  }