Skip to content

Commit

Permalink
Merge pull request #3006 from NickAragua/figher_squadron_rework
Browse files Browse the repository at this point in the history
GitHub is being dumb for some reason, but changes applied. Fix #2988, Fix #2989.
  • Loading branch information
NickAragua authored Jul 12, 2021
2 parents 3c1b994 + ccf2e90 commit bd981d2
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 126 deletions.
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ private int[] getBombPayload(boolean isSpace, int limit) {
}
}

int numFighters = ce().getActiveSubEntities().orElse(Collections.emptyList()).size();
int numFighters = ce().getActiveSubEntities().size();
BombPayloadDialog bombsDialog = new BombPayloadDialog(
clientgui.frame,
Messages.getString("FiringDisplay.BombNumberDialog" + ".title"), //$NON-NLS-1$
Expand Down
3 changes: 1 addition & 2 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -4208,7 +4207,7 @@ private void dumpBombs() {
// bring up dialog to dump bombs, then make a control roll and report
// success or failure
// should update mp available
int numFighters = ce().getActiveSubEntities().orElse(Collections.emptyList()).size();
int numFighters = ce().getActiveSubEntities().size();
BombPayloadDialog dumpBombsDialog = new BombPayloadDialog(
clientgui.frame,
Messages.getString("MovementDisplay.BombDumpDialog.title"), //$NON-NLS-1$
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/lobby/LobbyActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void customizeMechs(Collection<Entity> entities) {

// Customizations to a Squadron can effect the fighters
if (entity instanceof FighterSquadron) {
entity.getSubEntities().ifPresent(ents -> ents.forEach(client::sendUpdateEntity));
entity.getSubEntities().forEach(client::sendUpdateEntity);
}
}
}
Expand Down Expand Up @@ -398,7 +398,7 @@ public void customizeMech(Entity entity) {

// Customizations to a Squadron can effect the fighters
if (entity instanceof FighterSquadron) {
entity.getSubEntities().ifPresent(ents -> updateCandidates.addAll(ents));
updateCandidates.addAll(entity.getSubEntities());
}

// Do we need to update the members of our C3 network?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

Expand Down Expand Up @@ -129,7 +128,7 @@ public Vector<BackGroundDrawer> getBackgroundDrawers() {
}

public void setEntity(Entity e) {
List<Entity> fighters = e.getSubEntities().orElse(Collections.emptyList());
List<Entity> fighters = e.getSubEntities();
for(int i = 0; i < max_size; ++ i) {
if(i < fighters.size()) {
final Entity fighter = fighters.get(i);
Expand Down
14 changes: 5 additions & 9 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.Vector;
Expand Down Expand Up @@ -15500,21 +15499,18 @@ public void setOriginalBuildYear(int year) {
*
* @return an optional collection of sub-entities, if this entity is considered a grouping of them.
*/
public Optional<List<Entity>> getSubEntities() {
return Optional.empty();
public List<Entity> getSubEntities() {
return Collections.emptyList();
}

/**
* The default implementation calls getSubEntities(), then filters them. This might not be
* the optimal code for many applications, so feel free to override both if needed.
* A list of all active sub-entities. In most cases, this is simply an empty list.
*
* @return an optional collection of sub-entities, if this entity is considered a grouping of them,
* pre-filtered to only contain active (non-destroyed and non-doomed) entities.
*/
public Optional<List<Entity>> getActiveSubEntities() {
return getSubEntities().map(
ents -> ents.stream().filter(
ent -> !(ent.isDestroyed() || ent.isDoomed())).collect(Collectors.toList()));
public List<Entity> getActiveSubEntities() {
return Collections.emptyList();
}

/**
Expand Down
Loading

0 comments on commit bd981d2

Please sign in to comment.