Skip to content

Commit

Permalink
Second round of LGTM fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Windchild292 committed Mar 1, 2022
1 parent 9b8f76c commit f3f7c02
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 172 deletions.
61 changes: 31 additions & 30 deletions megameklab/src/megameklab/ui/fighterAero/ASBuildView.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,15 @@ private void loadEquipmentTable() {
}

private boolean isEngineHeatSink(Mounted mount) {
if ((mount.getLocation() == Entity.LOC_NONE) &&
UnitUtil.isHeatSink(mount) && (engineHeatSinkCount > 0)) {
if(mount.getType().hasFlag(MiscType.F_COMPACT_HEAT_SINK) &&
mount.getType().hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) {
//only single compact HS should be used for engine sinks
return false;
}
if ((mount.getLocation() == Entity.LOC_NONE)
&& UnitUtil.isHeatSink(mount) && (engineHeatSinkCount > 0)
&& !(mount.getType().hasFlag(MiscType.F_COMPACT_HEAT_SINK)
&& mount.getType().hasFlag(MiscType.F_DOUBLE_HEAT_SINK))) {
engineHeatSinkCount--;
return engineHeatSinkCount >= 0;
return true;
} else {
return false;
}

return false;
}

public void refresh() {
Expand All @@ -217,9 +214,11 @@ public void refresh() {
}

private void removeAllListeners() {

}

private void addAllListeners() {

}

@Override
Expand Down Expand Up @@ -269,35 +268,40 @@ public void mousePressed(MouseEvent e) {

String[] locNames = getAero().getLocationNames();
// A list of the valid locations we can add the selected eq to
ArrayList<Integer> validLocs = new ArrayList<Integer>();
ArrayList<Integer> validLocs = new ArrayList<>();
// The number of possible locations, Aeros' have LOC_WINGS and LOC_FUSELAGE, which we
// want ot ignore for now, hence -2
int numLocs = getAero().locations() - 2;
// If it's a weapon, there are restrictions
if (eq.getType() instanceof WeaponType) {
int[] availSpace = TestAero.availableSpace(getAero());
int numWeapons[] = new int[availSpace.length];

for (Mounted m : getAero().getWeaponList()){
if (m.getLocation() != Aero.LOC_NONE){
numWeapons[m.getLocation()]++;
int[] availSpace = TestAero.availableSpace(getAero());

if (availSpace != null) {
int[] numWeapons = new int[availSpace.length];

for (Mounted m : getAero().getWeaponList()) {
if (m.getLocation() != Aero.LOC_NONE) {
numWeapons[m.getLocation()]++;
}
}
}
for (int loc = 0; loc < numLocs; loc++){
if ((numWeapons[loc]+1) < availSpace[loc]){
validLocs.add(loc);

for (int loc = 0; loc < numLocs; loc++) {
if ((numWeapons[loc] + 1) < availSpace[loc]) {
validLocs.add(loc);
}
}
}
// If it's not a weapon there are no space requirements
} else {
for (int loc = 0; loc < numLocs; loc++){
validLocs.add(loc);
for (int loc = 0; loc < numLocs; loc++) {
validLocs.add(loc);
}

if (!UnitUtil.isWeaponEnhancement(eq.getType())) {
validLocs.add(Aero.LOC_FUSELAGE);
}
}

// Add a menu item for each potential location
for (Integer location: validLocs) {
if (UnitUtil.isValidLocation(getAero(), eq.getType(), location)) {
Expand All @@ -321,7 +325,6 @@ public void actionPerformed(ActionEvent e) {
public void mouseReleased(MouseEvent e) {

}


/**
* When the user right-clicks on the equipment table, a context menu is
Expand All @@ -332,11 +335,9 @@ public void mouseReleased(MouseEvent e) {
* @param location
* @param selectedRow
*/
private void jMenuLoadComponent_actionPerformed(int location,
int selectedRow) {
Mounted eq = (Mounted)
equipmentTable.getModel().getValueAt(selectedRow,
CriticalTableModel.EQUIPMENT);
private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) {
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow,
CriticalTableModel.EQUIPMENT);
try {
getAero().addEquipment(eq, location, false);
} catch (Exception ex) {
Expand Down
4 changes: 2 additions & 2 deletions megameklab/src/megameklab/ui/mek/BMBuildView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022 - The MegaMek Team. All Rights Reserved.
* Copyright (c) 2008-2022 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMekLab.
*
Expand Down Expand Up @@ -115,7 +115,7 @@ private boolean isEngineHeatSink(Mounted mount) {
&& mount.getType().hasFlag(MiscType.F_DOUBLE_HEAT_SINK))
&& !mount.getType().hasFlag(MiscType.F_IS_DOUBLE_HEAT_SINK_PROTOTYPE)) {
engineHeatSinkCount--;
return engineHeatSinkCount >= 0;
return true;
} else {
return false;
}
Expand Down
47 changes: 22 additions & 25 deletions megameklab/src/megameklab/ui/supportVehicle/SVCrewView.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
* MegaMekLab
* Copyright (C) 2019 The MegaMek Team
* Copyright (c) 2019-2022 - The MegaMek Team. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This file is part of MekHQ.
*
* This program is distributed in the hope that it will be useful,
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package megameklab.ui.supportVehicle;

Expand All @@ -29,6 +29,7 @@
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.util.List;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.CopyOnWriteArrayList;

Expand Down Expand Up @@ -360,34 +361,34 @@ public void setFromEntity(Entity entity) {
for (Transporter t : entity.getTransports()) {
if (t instanceof PillionSeatCargoBay) {
if (entity.isPodMountedTransport(t)) {
podPillion += ((Bay) t).getCapacity();
podPillion += (int) Math.round(((Bay) t).getCapacity());
} else {
pillion += ((Bay) t).getCapacity();
pillion += (int) Math.round(((Bay) t).getCapacity());
}
} else if (t instanceof EjectionSeatCargoBay) {
if (entity.isPodMountedTransport(t)) {
podEjection += ((Bay) t).getCapacity();
podEjection += (int) Math.round(((Bay) t).getCapacity());
} else {
ejection += ((Bay) t).getCapacity();
ejection += (int) Math.round(((Bay) t).getCapacity());
}
} else if (t instanceof StandardSeatCargoBay) {
if (entity.isPodMountedTransport(t)) {
podStdSeats += ((Bay) t).getCapacity();
podStdSeats += (int) Math.round(((Bay) t).getCapacity());
} else {
stdSeats += ((Bay) t).getCapacity();
stdSeats += (int) Math.round(((Bay) t).getCapacity());
}
} else if (t instanceof FirstClassQuartersCargoBay) {
if (entity.isPodMountedTransport(t)) {
podFirstClass += ((Bay) t).getCapacity();
podFirstClass += (int) Math.round(((Bay) t).getCapacity());
} else {
firstClass += ((Bay) t).getCapacity();
firstClass += (int) Math.round(((Bay) t).getCapacity());
}
firstClassWeight += ((Bay) t).getWeight();
} else if (t instanceof SecondClassQuartersCargoBay) {
if (entity.isPodMountedTransport(t)) {
podSecondClass += ((Bay) t).getCapacity();
podSecondClass += (int) Math.round(((Bay) t).getCapacity());
} else {
secondClass += ((Bay) t).getCapacity();
secondClass += (int) Math.round(((Bay) t).getCapacity());
}
secondClassWeight += ((Bay) t).getWeight();
} else if (t instanceof CrewQuartersCargoBay) {
Expand Down Expand Up @@ -506,11 +507,7 @@ public void setFromEntity(Entity entity) {
*/
private int getSpinnerValue(JSpinner spinner) {
Integer val = (Integer) spinner.getValue();
if (null != val) {
return val;
} else {
return 0;
}
return Objects.requireNonNullElse(val, 0);
}

@Override
Expand Down
Loading

0 comments on commit f3f7c02

Please sign in to comment.