diff --git a/src/megameklab/com/ui/BattleArmor/CriticalSuit.java b/src/megameklab/com/ui/BattleArmor/CriticalSuit.java index 5f3fd43a6fe..f0ef9faa12c 100644 --- a/src/megameklab/com/ui/BattleArmor/CriticalSuit.java +++ b/src/megameklab/com/ui/BattleArmor/CriticalSuit.java @@ -65,7 +65,7 @@ public boolean canAddMounted(int loc, Mounted m) { if (m.getType().isSpreadable()){ critsToAdd = 1; } else { - critsToAdd = m.getType().getCriticals(ba); + critsToAdd = m.getCriticals(); } int critsAvailable = 0; for (int c = 0; c < getNumCriticals(loc); c++) { @@ -99,7 +99,7 @@ public void addMounted(int loc, Mounted m){ if (m.getType().isSpreadable()){ critsToAdd = 1; } else { - critsToAdd = m.getType().getCriticals(ba); + critsToAdd = m.getCriticals(); } if (critsToAdd == 0){ return; diff --git a/src/megameklab/com/ui/Mek/views/BuildView.java b/src/megameklab/com/ui/Mek/views/BuildView.java index 8529e80dff4..780ed09b76f 100644 --- a/src/megameklab/com/ui/Mek/views/BuildView.java +++ b/src/megameklab/com/ui/Mek/views/BuildView.java @@ -116,7 +116,7 @@ private void loadEquipmentTable() { masterEquipmentList.clear(); engineHeatSinkCount = UnitUtil.getCriticalFreeHeatSinks(getMech(), getMech().hasCompactHeatSinks()); for (Mounted mount : getMech().getMisc()) { - if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount) && !(mount.getType().getCriticals(getMech()) == 0)) { + if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount) && !(mount.getCriticals() == 0)) { masterEquipmentList.add(mount); } } @@ -433,7 +433,7 @@ private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) { Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT); if (eq.getType().isSpreadable() || eq.isSplitable()) { if (getMech() instanceof LandAirMech) { - jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getType().getCriticals(getMech()), + jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getCriticals(), selectedRow); } else if (!(eq.getType() instanceof MiscType) || !eq.getType().hasFlag(MiscType.F_TARGCOMP)) { jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, 1, @@ -442,7 +442,7 @@ private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) { // Targetting computer is flagged as spreadable so the slots will be added one at a time when loaded, // since we don't have a way of indicating the number of slots until we know all the weapons. But // it's not really splittable, so we need to put add all the slots at once. - jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getType().getCriticals(getMech()), + jMenuLoadSplitComponent_actionPerformed(location, Entity.LOC_NONE, eq.getCriticals(), selectedRow); } return; diff --git a/src/megameklab/com/ui/Mek/views/SummaryView.java b/src/megameklab/com/ui/Mek/views/SummaryView.java index 5d6eb790a04..0e4fa90a807 100644 --- a/src/megameklab/com/ui/Mek/views/SummaryView.java +++ b/src/megameklab/com/ui/Mek/views/SummaryView.java @@ -343,7 +343,7 @@ else if (mt.hasFlag(MiscType.F_TSM) else if (mt.hasFlag(MiscType.F_JUMP_JET) || mt.hasFlag(MiscType.F_JUMP_BOOSTER)) { weightJJ += m.getTonnage(); - critJJ += mt.getCriticals(getMech()); + critJJ += m.getCriticals(); } else if (mt.hasFlag(MiscType.F_HEAT_SINK) || mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) { @@ -351,16 +351,16 @@ else if (mt.hasFlag(MiscType.F_HEAT_SINK) } else { weightEquip += m.getTonnage(); - critEquip += mt.getCriticals(getMech()); + critEquip += m.getCriticals(); } } for (Mounted m : getMech().getWeaponList()) { weightEquip += m.getTonnage(); - critEquip += m.getType().getCriticals(getMech()); + critEquip += m.getCriticals(); } for (Mounted m : getMech().getAmmo()) { weightEquip += m.getTonnage(); - critEquip += m.getType().getCriticals(getMech()); + critEquip += m.getCriticals(); } txtJumpTon.setText(Double.toString(weightJJ)); txtEnhanceTon.setText(Double.toString(weightEnhance)); diff --git a/src/megameklab/com/util/CriticalTableModel.java b/src/megameklab/com/util/CriticalTableModel.java index 44d4f1baeee..203c11de506 100644 --- a/src/megameklab/com/util/CriticalTableModel.java +++ b/src/megameklab/com/util/CriticalTableModel.java @@ -134,7 +134,7 @@ public String getColumnName(int col) { @Override public boolean isCellEditable(int row, int col) { return (col == SIZE) && (row >= 0) && (row < sortedEquipment.length) - && sortedEquipment[row].getType().isVariableTonnage(); + && sortedEquipment[row].getType().isVariableSize(); } @Override @@ -187,7 +187,7 @@ public Object getValueAt(int row, int col) { if (tableType == BUILDTABLE) { return UnitUtil.getCritsUsed(unit, crit.getType()); } - return crit.getType().getCriticals(unit); + return crit.getCriticals(); case EQUIPMENT: return crit; case HEAT: @@ -216,7 +216,16 @@ public Object getValueAt(int row, int col) { public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if ((columnIndex == SIZE) && (rowIndex >= 0) && (rowIndex < getRowCount())) { Mounted crit = sortedEquipment[rowIndex]; - crit.setSize(Double.parseDouble(aValue.toString())); + double newSize = Double.parseDouble(aValue.toString()); + double step = crit.getType().variableStepSize(); + newSize = Math.max(Math.floor(newSize / step) * step, step); + if ((crit.getType().variableMaxSize() != null) && (newSize > crit.getType().variableMaxSize())) { + newSize = crit.getType().variableMaxSize(); + } + if (crit.getSize() == newSize) { + return; + } + UnitUtil.resizeMount(crit, newSize); fireTableDataChanged(); } } diff --git a/src/megameklab/com/util/UnitUtil.java b/src/megameklab/com/util/UnitUtil.java index 5ff31bc4cbc..fa9813c8e16 100644 --- a/src/megameklab/com/util/UnitUtil.java +++ b/src/megameklab/com/util/UnitUtil.java @@ -1219,6 +1219,52 @@ public static void changeMountStatus(Entity unit, Mounted eq, int location, eq.setSecondLocation(secondaryLocation, rear); eq.setSplit(secondaryLocation > -1); } + + public static void resizeMount(Mounted mount, double newSize) { + mount.setSize(newSize); + if (mount.getLocation() == Entity.LOC_NONE) { + return; + } + final Entity entity = mount.getEntity(); + final int loc = mount.getLocation(); + int start = -1; + for (int slot = 0; slot < entity.getNumberOfCriticals(loc); slot++) { + CriticalSlot crit = entity.getCritical(loc, slot); + if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT) + && crit.getMount().equals(mount)) { + start = slot; + break; + } + } + removeCriticals(entity, mount); + compactCriticals(entity, loc); + if ((start < 0) || (entity.getEmptyCriticals(loc) < mount.getCriticals())) { + changeMountStatus(entity, mount, Entity.LOC_NONE, Entity.LOC_NONE, false); + try { + MechFileParser.postLoadInit(entity); + } catch (EntityLoadingException ignored) { + // We're not actually loading an Entity; we're fixing linked equipment + } + } else { + // If the number of criticals increases, we may need to shift existing criticals + // to make room. Since we checked for sufficient space and compacted the existing + // criticals we can be assured of not overrunning the array. + List toAdd = new ArrayList<>(); + for (int i = 0; i < mount.getCriticals(); i++) { + toAdd.add(new CriticalSlot(mount)); + } + int slot = start; + while (!toAdd.isEmpty()) { + CriticalSlot cs = entity.getCritical(loc, slot); + if (cs != null) { + toAdd.add(cs); + } + entity.setCritical(loc, slot, toAdd.get(0)); + toAdd.remove(0); + slot++; + } + } + } /** * Find unallocated ammo of the same type. Used by large aerospace units when removing ammo @@ -2150,11 +2196,11 @@ public static String getToolTipInfo(Entity unit, Mounted eq) { double infDamage = ((InfantryWeapon) eq.getType()) .getInfantryDamage(); sb.append(infDamage); - sb.append("
Range Class: " - + ((InfantryWeapon) eq.getType()).getInfantryRange()); + sb.append("
Range Class: "); + sb.append(((InfantryWeapon) eq.getType()).getInfantryRange()); } else { sb.append("
Crits: "); - sb.append(eq.getType().getCriticals(unit)); + sb.append(eq.getCriticals()); sb.append("
Mass: "); if (TestEntity.usesKgStandard(unit)) { sb.append(Math.round(eq.getTonnage() * 1000));