Search in sources :

Example 1 with TripodMech

use of megamek.common.TripodMech in project megameklab by MegaMek.

the class DropTargetCriticalList method mousePressed.

public void mousePressed(MouseEvent e) {
    if (buildView) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            removeCrit();
        } else if (e.getButton() == MouseEvent.BUTTON3) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
                removeCrit();
                return;
            }
            int location = getCritLocation();
            JPopupMenu popup = new JPopupMenu();
            CriticalSlot cs = getCrit();
            final Mounted mount = getMounted();
            if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
                changeWeaponFacing(!mount.isRearMounted());
                return;
            }
            if (mount != null && (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
                changeOmniMounting(!mount.isOmniPodMounted());
                return;
            }
            if (mount != null && !((getUnit().getEntityType() & Entity.ETYPE_QUADVEE) == Entity.ETYPE_QUADVEE && mount.getType() instanceof MiscType && mount.getType().hasFlag(MiscType.F_TRACKS))) {
                JMenuItem info;
                if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
                    popup.setAutoscrolls(true);
                    info = new JMenuItem("Remove " + mount.getName());
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeCrit();
                        }
                    });
                    popup.add(info);
                }
                info = new JMenuItem("Delete " + mount.getName());
                info.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        removeMount();
                    }
                });
                if (!((getUnit() instanceof BattleArmor) && UnitUtil.isFixedLocationSpreadEquipment(mount.getType()))) {
                    popup.add(info);
                }
                // Allow making this a sort weapon
                if ((mount.getType() instanceof WeaponType) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
                    info = new JMenuItem("Mount as squad support weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(true);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Adding ammo as a squad support mount is slightly different
                if ((mount.getType() instanceof AmmoType) && !mount.getType().hasFlag(WeaponType.F_MISSILE) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
                    boolean enabled = false;
                    for (Mounted weapon : getUnit().getWeaponList()) {
                        WeaponType wtype = (WeaponType) weapon.getType();
                        if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(mount, wtype)) {
                            enabled = true;
                        }
                    }
                    info = new JMenuItem("Mount as squad support weapon");
                    info.setEnabled(enabled);
                    info.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(true);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Allow removing squad support weapon
                if (mount.isSquadSupportWeapon()) {
                    info = new JMenuItem("Remove squad support weapon mount");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(false);
                            // squad support weapon
                            for (Mounted ammo : getUnit().getAmmo()) {
                                ammo.setSquadSupportWeapon(false);
                            }
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Right-clicked on a DWP that has an attached weapon
                if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && mount.getLinked() != null) {
                    info = new JMenuItem("Remove attached weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            Mounted attached = mount.getLinked();
                            attached.setDWPMounted(false);
                            mount.setLinked(null);
                            mount.setLinkedBy(null);
                            attached.setLinked(null);
                            attached.setLinkedBy(null);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Right-clicked on a AP Mount that has an attached weapon
                if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && mount.getLinked() != null) {
                    info = new JMenuItem("Remove attached weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            Mounted attached = mount.getLinked();
                            attached.setAPMMounted(false);
                            mount.setLinked(null);
                            mount.setLinkedBy(null);
                            attached.setLinked(null);
                            attached.setLinkedBy(null);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                if ((mount.getLocation() != Mech.LOC_LARM) && (mount.getLocation() != Mech.LOC_RARM)) {
                    if (mount.getType() instanceof WeaponType) {
                        if (getUnit().hasWorkingMisc(MiscType.F_QUAD_TURRET, -1, mount.getLocation()) || getUnit().hasWorkingMisc(MiscType.F_SHOULDER_TURRET, -1, mount.getLocation()) || (getUnit().hasWorkingMisc(MiscType.F_HEAD_TURRET, -1, Mech.LOC_CT) && (mount.getLocation() == Mech.LOC_HEAD))) {
                            if (!mount.isMechTurretMounted()) {
                                info = new JMenuItem("Mount " + mount.getName() + " in Turret");
                                info.addActionListener(new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        changeTurretMount(true);
                                    }
                                });
                                popup.add(info);
                            } else {
                                info = new JMenuItem("Remove " + mount.getName() + " from Turret");
                                info.addActionListener(new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        changeTurretMount(false);
                                    }
                                });
                                popup.add(info);
                            }
                        }
                    }
                    if (!(getUnit() instanceof BattleArmor) && ((mount.getType() instanceof WeaponType) || ((mount.getType() instanceof MiscType) && mount.getType().hasFlag(MiscType.F_LIFTHOIST)))) {
                        if (!mount.isRearMounted()) {
                            info = new JMenuItem("Make " + mount.getName() + " Rear Facing");
                            info.addActionListener(new ActionListener() {

                                public void actionPerformed(ActionEvent e) {
                                    changeWeaponFacing(true);
                                }
                            });
                            popup.add(info);
                        } else {
                            info = new JMenuItem("Make " + mount.getName() + " Forward Facing");
                            info.addActionListener(new ActionListener() {

                                public void actionPerformed(ActionEvent e) {
                                    changeWeaponFacing(false);
                                }
                            });
                            popup.add(info);
                        }
                    }
                }
                // Allow number of shots selection
                if ((getUnit() instanceof BattleArmor) && mount.getType() instanceof AmmoType) {
                    AmmoType at = (AmmoType) mount.getType();
                    int maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT;
                    int stepSize = 1;
                    if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
                        maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT_TA;
                        stepSize = 2;
                    }
                    for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
                        if (i == mount.getBaseShotsLeft()) {
                            continue;
                        }
                        info = new JMenuItem("Set Shots: " + i);
                        final int shots = i;
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                mount.setShotsLeft(shots);
                                if (refresh != null) {
                                    refresh.refreshAll();
                                }
                            }
                        });
                        popup.add(info);
                    }
                }
                if (getUnit().isOmni() && !mount.getType().isOmniFixedOnly()) {
                    if (mount.isOmniPodMounted()) {
                        info = new JMenuItem("Change to fixed mount");
                        info.addActionListener(ev -> changeOmniMounting(false));
                        popup.add(info);
                    } else if (UnitUtil.canPodMount(getUnit(), mount)) {
                        info = new JMenuItem("Change to pod mount");
                        info.addActionListener(ev -> changeOmniMounting(true));
                        popup.add(info);
                    }
                }
            }
            if ((getUnit() instanceof BipedMech || getUnit() instanceof TripodMech) && ((location == Mech.LOC_LARM) || (location == Mech.LOC_RARM))) {
                boolean canHaveLowerArm = true;
                if (getUnit().isOmni()) {
                    int numCrits = getUnit().getNumberOfCriticals(location);
                    for (int slot = 0; slot < numCrits; slot++) {
                        CriticalSlot crit = getUnit().getCritical(location, slot);
                        if (crit == null) {
                            continue;
                        }
                        if (crit.getType() == CriticalSlot.TYPE_SYSTEM) {
                            continue;
                        }
                        Mounted m = crit.getMount();
                        if ((m.getType() instanceof GaussWeapon) || (m.getType() instanceof ACWeapon) || (m.getType() instanceof UACWeapon) || (m.getType() instanceof LBXACWeapon) || (m.getType() instanceof PPCWeapon)) {
                            canHaveLowerArm = false;
                        }
                    }
                }
                popup.addSeparator();
                popup.setAutoscrolls(true);
                if (canHaveLowerArm && ((getUnit().getCritical(location, 3) == null) || (getUnit().getCritical(location, 3).getType() != CriticalSlot.TYPE_SYSTEM))) {
                    JMenuItem info = new JMenuItem("Add Hand");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            addHand(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                } else if ((getUnit().getCritical(location, 3) != null) && (getUnit().getCritical(location, 3).getType() == CriticalSlot.TYPE_SYSTEM)) {
                    JMenuItem info = new JMenuItem("Remove Hand");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeHand(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                }
                if (canHaveLowerArm && ((getUnit().getCritical(location, 2) == null) || (getUnit().getCritical(location, 2).getType() != CriticalSlot.TYPE_SYSTEM))) {
                    JMenuItem info = new JMenuItem("Add Lower Arm");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            addArm(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                } else if ((getUnit().getCritical(location, 2) != null) && (getUnit().getCritical(location, 2).getType() == CriticalSlot.TYPE_SYSTEM)) {
                    JMenuItem info = new JMenuItem("Remove Lower Arm");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeArm(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                }
            }
            if (UnitUtil.isArmorable(cs) && !(getUnit() instanceof BattleArmor) && eSource.getTechManager().isLegal(Entity.getArmoredComponentTechAdvancement())) {
                popup.addSeparator();
                if (cs.isArmored()) {
                    JMenuItem info = new JMenuItem("Remove Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                } else if (!(getUnit() instanceof Mech && ((Mech) getUnit()).isSuperHeavy())) {
                    JMenuItem info = new JMenuItem("Add Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                }
            }
            if (popup.getComponentCount() > 0) {
                popup.show(this, e.getX(), e.getY());
            }
        }
    }
}
Also used : InputEvent(java.awt.event.InputEvent) ActionListener(java.awt.event.ActionListener) CritListCellRenderer(megameklab.com.util.CritListCellRenderer) CriticalSlot(megamek.common.CriticalSlot) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) BattleArmor(megamek.common.BattleArmor) JMenuItem(javax.swing.JMenuItem) BipedMech(megamek.common.BipedMech) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) TestBattleArmor(megamek.common.verifier.TestBattleArmor) MouseListener(java.awt.event.MouseListener) MechFileParser(megamek.common.MechFileParser) AmmoType(megamek.common.AmmoType) Mech(megamek.common.Mech) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) WeaponType(megamek.common.WeaponType) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) MiscType(megamek.common.MiscType) TripodMech(megamek.common.TripodMech) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) Entity(megamek.common.Entity) RefreshListener(megameklab.com.util.RefreshListener) TripodMech(megamek.common.TripodMech) CriticalSlot(megamek.common.CriticalSlot) ActionEvent(java.awt.event.ActionEvent) MiscType(megamek.common.MiscType) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) TripodMech(megamek.common.TripodMech) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) JMenuItem(javax.swing.JMenuItem) BipedMech(megamek.common.BipedMech) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 2 with TripodMech

use of megamek.common.TripodMech in project megameklab by MegaMek.

the class MainUI method createNewUnit.

@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
    int cockpit = Mech.COCKPIT_STANDARD;
    int at = EquipmentType.T_ARMOR_STANDARD;
    int st = EquipmentType.T_STRUCTURE_STANDARD;
    if (isPrimitive && isIndustrial) {
        cockpit = Mech.COCKPIT_PRIMITIVE_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    } else if (isPrimitive) {
        cockpit = Mech.COCKPIT_PRIMITIVE;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
    } else if (isIndustrial) {
        cockpit = Mech.COCKPIT_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_INDUSTRIAL;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    }
    if (entityType == Entity.ETYPE_TRIPOD_MECH) {
        setEntity(new TripodMech(Mech.GYRO_STANDARD, Mech.COCKPIT_TRIPOD));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_QUAD_MECH) {
        setEntity(new QuadMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        setEntity(new LandAirMech(Mech.GYRO_STANDARD, Mech.COCKPIT_STANDARD, LandAirMech.LAM_STANDARD));
        getEntity().setTechLevel(TechConstants.T_IS_ADVANCED);
        getEntity().setManualBV(-1);
    } else if (entityType == Entity.ETYPE_QUADVEE) {
        setEntity(new QuadVee(Mech.GYRO_STANDARD, QuadVee.MOTIVE_TRACK));
        getEntity().setTechLevel(TechConstants.T_CLAN_ADVANCED);
        UnitUtil.createSpreadMounts((Mech) getEntity(), EquipmentType.get("Tracks"));
        getEntity().setManualBV(-1);
    } else {
        // type == 0
        setEntity(new BipedMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    }
    Mech mech = (Mech) getEntity();
    getEntity().setWeight(25);
    if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        mech.setEngine(new Engine(75, Engine.NORMAL_ENGINE, 0));
        UnitUtil.updateJumpJets(((Mech) getEntity()), 3, Mech.JUMP_STANDARD);
    } else {
        mech.setEngine(new Engine(25, Engine.NORMAL_ENGINE, 0));
    }
    getEntity().setArmorType(at);
    getEntity().setArmorTechLevel(getEntity().getTechLevel());
    getEntity().setStructureType(st);
    mech.addGyro();
    mech.addEngineCrits();
    if (isPrimitive) {
        mech.addPrimitiveCockpit();
    } else if (isIndustrial) {
        mech.addIndustrialCockpit();
    } else if (Entity.ETYPE_QUADVEE == entityType) {
        mech.addQuadVeeCockpit();
    } else {
        mech.addCockpit();
    }
    UnitUtil.updateHeatSinks(mech, 10, "Single");
    getEntity().autoSetInternal();
    for (int loc = 0; loc < getEntity().locations(); loc++) {
        mech.initializeArmor(0, loc);
        mech.initializeRearArmor(0, loc);
    }
    if (null == oldEntity) {
        mech.setChassis("New");
        mech.setModel("Mek");
        mech.setYear(3145);
    } else {
        mech.setChassis(oldEntity.getChassis());
        mech.setModel(oldEntity.getModel());
        mech.setYear(Math.max(oldEntity.getYear(), mech.getConstructionTechAdvancement().getIntroductionDate()));
        mech.setSource(oldEntity.getSource());
        mech.setManualBV(oldEntity.getManualBV());
        SimpleTechLevel lvl = SimpleTechLevel.max(mech.getStaticTechLevel(), SimpleTechLevel.convertCompoundToSimple(oldEntity.getTechLevel()));
        mech.setTechLevel(lvl.getCompoundTechLevel(oldEntity.isClan()));
        mech.setMixedTech(oldEntity.isMixedTech());
    }
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) SimpleTechLevel(megamek.common.SimpleTechLevel) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) QuadVee(megamek.common.QuadVee) BipedMech(megamek.common.BipedMech) Engine(megamek.common.Engine) LandAirMech(megamek.common.LandAirMech)

Example 3 with TripodMech

use of megamek.common.TripodMech in project megameklab by MegaMek.

the class StatusBar method refresh.

public void refresh() {
    int heat = getMech().getHeatCapacity();
    double tonnage = getMech().getWeight();
    double currentTonnage;
    int bv = getMech().calculateBattleValue();
    int maxCrits;
    if (getMech() instanceof TripodMech) {
        maxCrits = 84;
    } else if (getMech() instanceof QuadMech) {
        maxCrits = 66;
    } else {
        maxCrits = 78;
    }
    int currentCrits = UnitUtil.countUsedCriticals(getMech());
    long currentCost = (long) Math.round(getMech().getCost(false));
    testEntity = new TestMech(getMech(), entityVerifier.mechOption, null);
    currentTonnage = testEntity.calculateWeight();
    currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getMech());
    double totalHeat = calculateTotalHeat();
    heatSink.setText("Heat: " + totalHeat + "/" + heat);
    heatSink.setToolTipText("Total Heat Generated/Total Heat Dissipated");
    if (totalHeat > heat) {
        heatSink.setForeground(Color.red);
    } else {
        heatSink.setForeground(Color.black);
    }
    tons.setText("Tonnage: " + currentTonnage + "/" + tonnage);
    tons.setToolTipText("Current Tonnage/Max Tonnage");
    if (currentTonnage > tonnage) {
        tons.setForeground(Color.red);
    } else {
        tons.setForeground(Color.black);
    }
    bvLabel.setText("BV: " + bv);
    bvLabel.setToolTipText("BV 2.0");
    cost.setText("Cost: " + formatter.format(currentCost) + " C-bills");
    crits.setText("Criticals: " + currentCrits + "/" + maxCrits);
    if (currentCrits > maxCrits) {
        crits.setForeground(Color.red);
    } else {
        crits.setForeground(Color.BLACK);
    }
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) TestMech(megamek.common.verifier.TestMech)

Example 4 with TripodMech

use of megamek.common.TripodMech in project megameklab by MegaMek.

the class UnitUtil method removeOmniArmActuators.

public static void removeOmniArmActuators(Mech mech) {
    if ((mech instanceof BipedMech) || (mech instanceof TripodMech)) {
        boolean leftACGaussPPC = false;
        boolean rightACGaussPPC = false;
        for (Mounted weapon : mech.getWeaponList()) {
            if ((weapon.getLocation() == Mech.LOC_LARM) && ((weapon.getType() instanceof ACWeapon) || (weapon.getType() instanceof GaussWeapon) || (weapon.getType() instanceof LBXACWeapon) || (weapon.getType() instanceof UACWeapon) || (weapon.getType() instanceof PPCWeapon))) {
                leftACGaussPPC = true;
            }
            if ((weapon.getLocation() == Mech.LOC_RARM) && ((weapon.getType() instanceof ACWeapon) || (weapon.getType() instanceof GaussWeapon) || (weapon.getType() instanceof LBXACWeapon) || (weapon.getType() instanceof UACWeapon) || (weapon.getType() instanceof PPCWeapon))) {
                rightACGaussPPC = true;
            }
        }
        if (leftACGaussPPC) {
            removeArm(mech, Mech.LOC_LARM);
            UnitUtil.compactCriticals(mech, Mech.LOC_LARM);
        }
        if (rightACGaussPPC) {
            removeArm(mech, Mech.LOC_RARM);
            UnitUtil.compactCriticals(mech, Mech.LOC_RARM);
        }
    }
}
Also used : TripodMech(megamek.common.TripodMech) Mounted(megamek.common.Mounted) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) BipedMech(megamek.common.BipedMech) HVACWeapon(megamek.common.weapons.autocannons.HVACWeapon) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) ACWeapon(megamek.common.weapons.autocannons.ACWeapon)

Example 5 with TripodMech

use of megamek.common.TripodMech in project megameklab by MegaMek.

the class UnitUtil method createSpreadMounts.

/**
 * create a Mounted and corresponding CriticalSlots for the passed in
 * <code>EquipmentType</code> on the passed in <code>Mech</code>
 *
 * @param unit
 * @param equip
 * @return
 */
public static Mounted createSpreadMounts(Mech unit, EquipmentType equip) {
    final String METHOD_NAME = "createSpreadMounts(Mech, EquipmentType)";
    // how many non-spreadable contiguous blocks of crits?
    int blocks = 0;
    boolean isMisc = equip instanceof MiscType;
    blocks = equip.getCriticals(unit);
    List<Integer> locations = new ArrayList<Integer>();
    if (isMisc) {
        if ((equip.hasFlag(MiscType.F_INDUSTRIAL_TSM) || equip.hasFlag(MiscType.F_TSM))) {
            // all crits user placeable
            for (int i = 0; i < equip.getCriticals(unit); i++) {
                locations.add(Entity.LOC_NONE);
            }
        } else if (equip.hasFlag(MiscType.F_ENVIRONMENTAL_SEALING)) {
            // 1 crit in each location
            for (int i = 0; i < unit.locations(); i++) {
                locations.add(i);
            }
        } else if (equip.hasFlag(MiscType.F_STEALTH)) {
            // 2 in arms, legs, side torsos
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            locations.add(Mech.LOC_LARM);
            locations.add(Mech.LOC_RARM);
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 6;
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                locations.add(Mech.LOC_CLEG);
                blocks++;
            }
        } else if (equip.hasFlag(MiscType.F_SCM)) {
            // 1 in arms, legs, side torsos
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            locations.add(Mech.LOC_LARM);
            locations.add(Mech.LOC_RARM);
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 6;
        } else if ((equip.hasFlag(MiscType.F_TRACKS) || equip.hasFlag(MiscType.F_TALON) || equip.hasFlag(MiscType.F_JUMP_BOOSTER))) {
            // 1 block in each leg
            locations.add(Mech.LOC_LLEG);
            locations.add(Mech.LOC_RLEG);
            if (unit instanceof QuadMech) {
                locations.add(Mech.LOC_LARM);
                locations.add(Mech.LOC_RARM);
            }
            blocks = (unit instanceof BipedMech ? 2 : 4);
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                locations.add(Mech.LOC_CLEG);
                blocks = 3;
            }
        } else if (equip.hasFlag(MiscType.F_PARTIAL_WING)) {
            // one block in each side torso
            locations.add(Mech.LOC_LT);
            locations.add(Mech.LOC_RT);
            blocks = 2;
        } else if ((equip.hasFlag(MiscType.F_VOIDSIG) || equip.hasFlag(MiscType.F_NULLSIG) || equip.hasFlag(MiscType.F_BLUE_SHIELD))) {
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                blocks++;
            }
            // 1 crit in each location, except the head
            for (int i = Mech.LOC_CT; i < unit.locations(); i++) {
                locations.add(i);
            }
        } else if (equip.hasFlag(MiscType.F_CHAMELEON_SHIELD)) {
            // Need to account for the center leg
            if (unit instanceof TripodMech) {
                blocks++;
            }
            // 1 crit in each location except head and CT
            for (int i = Mech.LOC_RT; i < unit.locations(); i++) {
                locations.add(i);
            }
        }
    }
    boolean firstBlock = true;
    Mounted mount = new Mounted(unit, equip);
    for (; blocks > 0; blocks--) {
        // how many crits per block?
        int crits = UnitUtil.getCritsUsed(unit, equip);
        for (int i = 0; i < crits; i++) {
            try {
                if (firstBlock || (locations.get(0) == Entity.LOC_NONE)) {
                    // create only one mount per equipment, for BV and stuff
                    addMounted(unit, mount, locations.get(0), false);
                    if (firstBlock) {
                        firstBlock = false;
                    }
                    if (locations.get(0) == Entity.LOC_NONE) {
                        // only user-placable spread stuff gets location
                        // none
                        // for those, we need to create a mount for each
                        // crit,
                        // otherwise we can't correctly let the user place
                        // them
                        // luckily, that only affects TSM, so BV works out
                        // correctly
                        mount = new Mounted(unit, equip);
                    }
                } else {
                    CriticalSlot cs = new CriticalSlot(mount);
                    if (!unit.addCritical(locations.get(0), cs)) {
                        UnitUtil.removeCriticals(unit, mount);
                        JOptionPane.showMessageDialog(null, "No room for equipment", mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
                        unit.getMisc().remove(mount);
                        unit.getEquipment().remove(mount);
                        return null;
                    }
                }
            } catch (LocationFullException lfe) {
                getLogger().log(UnitUtil.class, METHOD_NAME, lfe);
                JOptionPane.showMessageDialog(null, lfe.getMessage(), mount.getName() + " does not fit into " + unit.getLocationName(locations.get(0)), JOptionPane.INFORMATION_MESSAGE);
                unit.getMisc().remove(mount);
                unit.getEquipment().remove(mount);
                return null;
            }
        }
        locations.remove(0);
    }
    return mount;
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) CriticalSlot(megamek.common.CriticalSlot) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) BipedMech(megamek.common.BipedMech)

Aggregations

TripodMech (megamek.common.TripodMech)5 BipedMech (megamek.common.BipedMech)4 Mounted (megamek.common.Mounted)3 QuadMech (megamek.common.QuadMech)3 CriticalSlot (megamek.common.CriticalSlot)2 Mech (megamek.common.Mech)2 MiscType (megamek.common.MiscType)2 ACWeapon (megamek.common.weapons.autocannons.ACWeapon)2 LBXACWeapon (megamek.common.weapons.autocannons.LBXACWeapon)2 UACWeapon (megamek.common.weapons.autocannons.UACWeapon)2 GaussWeapon (megamek.common.weapons.gaussrifles.GaussWeapon)2 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 InputEvent (java.awt.event.InputEvent)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1