Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/megameklab/com/ui/BattleArmor/CriticalSuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/megameklab/com/ui/Mek/views/BuildView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/megameklab/com/ui/Mek/views/SummaryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,24 @@ 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)) {
continue;
}
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));
Expand Down
15 changes: 12 additions & 3 deletions src/megameklab/com/util/CriticalTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
}
Expand Down
52 changes: 49 additions & 3 deletions src/megameklab/com/util/UnitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CriticalSlot> 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
Expand Down Expand Up @@ -2150,11 +2196,11 @@ public static String getToolTipInfo(Entity unit, Mounted eq) {
double infDamage = ((InfantryWeapon) eq.getType())
.getInfantryDamage();
sb.append(infDamage);
sb.append("<br>Range Class: "
+ ((InfantryWeapon) eq.getType()).getInfantryRange());
sb.append("<br>Range Class: ");
sb.append(((InfantryWeapon) eq.getType()).getInfantryRange());
} else {
sb.append("<br>Crits: ");
sb.append(eq.getType().getCriticals(unit));
sb.append(eq.getCriticals());
sb.append("<br>Mass: ");
if (TestEntity.usesKgStandard(unit)) {
sb.append(Math.round(eq.getTonnage() * 1000));
Expand Down