Ejemplo n.º 1
0
  public void Visit(Mech m) {
    // only the armor changes, so pass us off
    CurMech = m;
    ifMechLoadout l = CurMech.GetLoadout();
    MechArmor a = CurMech.GetArmor();

    // remove the old armor, if needed
    l.Remove(a);
    a.ResetPatchworkConfigs();

    // set the armor type
    a.SetHD();

    // place the armor
    a.Place(l);
    // check for and add any MechModifier
    if (a.GetMechModifier() != null) {
      CurMech.AddMechModifier(a.GetMechModifier());
    }
  }
  private void GetWeaponData() {
    ArrayList v = CurMech.GetLoadout().GetNonCore();
    ArrayList<ifWeapon> wep = new ArrayList<ifWeapon>();
    ArrayList<Ammunition> ammo = new ArrayList<Ammunition>();
    ArrayList<WeaponInfo> temp = new ArrayList<WeaponInfo>();
    int cols = 0;
    for (int i = 0; i < v.size(); i++) {
      if (v.get(i) instanceof ifWeapon) {
        ifWeapon w = (ifWeapon) v.get(i);
        // do we already have a weapon of this name in the ArrayList?
        boolean add = true;
        for (int x = 0; x < wep.size(); x++) {
          if (wep.get(x).LookupName().equals(w.LookupName())) {
            add = false;
          }
        }
        if (add) {
          wep.add(w);
          if (w.GetRangeLong() > cols) {
            cols = w.GetRangeLong();
          }
        }
      } else if (v.get(i) instanceof Ammunition) {
        Ammunition a = (Ammunition) v.get(i);
        // do we already have an ammo of this name in the ArrayList?
        boolean add = true;
        for (int x = 0; x < ammo.size(); x++) {
          if (ammo.get(x).LookupName().equals(a.LookupName())) {
            add = false;
          }
        }
        if (add) {
          ammo.add(a);
          if (a.GetLongRange() > cols) {
            cols = a.GetLongRange();
          }
        }
      }
    }

    // construct the data ArrayList
    for (int i = 0; i < wep.size(); i++) {
      ifWeapon w = wep.get(i);
      if (w.HasAmmo()) {
        boolean added = false;
        // search for other ammunition for this weapon.
        for (int x = ammo.size() - 1; x >= 0; x--) {
          Ammunition a = ammo.get(x);
          if (w.GetAmmoIndex() == a.GetAmmoIndex()) {
            temp.add(new WeaponInfo(w, a));
            ammo.remove(a);
            added = true;
          }
        }
        if (!added) {
          // add the weapon in by itself
          temp.add(new WeaponInfo(w));
        }
      } else {
        temp.add(new WeaponInfo(w));
      }
    }

    // sort the weapon info by range
    SortWeapons(temp);

    // turn the temporary ArrayList into an array
    cols += 1;
    data = new String[temp.size() * 2][cols];
    for (int i = 0; i < temp.size(); i++) {
      WeaponInfo w = temp.get(i);
      for (int x = 0; x < cols; x++) {
        if (x == 0) {
          data[i * 2][x] = w.GetName();
          data[i * 2 + 1][x] = "";
        } else {
          int tohit = w.GetToHit(x);
          if (CurMech.UsingTC()) {
            if (tohit != 12 && w.CanUseTC()) {
              tohit -= 1;
            }
          }
          if (tohit >= 0) {
            data[i * 2][x] = "+" + tohit;
          } else {
            data[i * 2][x] = "" + tohit;
          }
          data[i * 2 + 1][x] = "" + w.GetDamage(x);
        }
      }
    }
  }
  public void Visit(Mech m) throws Exception {
    CurMech = m;
    boolean CASEInstalled = false;
    boolean SChargerInstalled = false;
    Gyro g = CurMech.GetGyro();
    ifMechLoadout l = CurMech.GetLoadout();

    // see if we have CASE installed in the CT
    if (CurMech.HasCTCase()) {
      // remove it.  We may not be able to replace it, but we'll try
      CASEInstalled = true;
      CurMech.RemoveCTCase();
    }

    // see if we have a supercharger installed
    if (CurMech.GetLoadout().HasSupercharger()) {
      if (CurMech.GetLoadout().Find(CurMech.GetLoadout().GetSupercharger())
          == LocationIndex.MECH_LOC_CT) {
        SChargerInstalled = true;
        try {
          CurMech.GetLoadout().SetSupercharger(false, -1, -1);
        } catch (Exception e) {
          // wow, a problem removing it.  Log it for later.
          System.err.println(e.getMessage());
        }
      }
    }

    // We have to remove the engine as well as mess with the gyro here
    m.GetEngine().Remove(l);

    // remove the gyro crits
    g.Remove(l);

    // change the gyro
    g.SetStandard();

    // place the gyro
    if (!g.Place(l)) {
      throw new Exception("Standard Gyro cannot be allocated!");
    }

    // now replace the engine criticals
    if (!m.GetEngine().Place(l)) {
      throw new Exception(m.GetEngine().LookupName() + " cannot be allocated!");
    }

    // if we had CASE installed, try to replace it
    if (CASEInstalled) {
      // at this point, we don't care whether it happened or not since the
      // primary inhabitants of the CT are taken care of.
      try {
        CurMech.AddCTCase();
      } catch (Exception e) {
        // unhandled at this time.  write out a system error
        System.err.println(e.getMessage());
      }
    }

    // try to reinstall the Supercharger
    if (SChargerInstalled) {
      try {
        CurMech.GetLoadout().SetSupercharger(true, LocationIndex.MECH_LOC_CT, -1);
      } catch (Exception e) {
        System.err.println(e.getMessage());
      }
    }
  }