Skip to content

Commit

Permalink
Merge pull request #4740 from Sleet01/fix_4739_custom_protomech_bay_d…
Browse files Browse the repository at this point in the history
…oes_not_load

Fix 4739 custom protomech bay does not load
  • Loading branch information
SJuliez authored Sep 4, 2023
2 parents b9deee9 + 4b02ca8 commit 7476cbf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
78 changes: 47 additions & 31 deletions megamek/src/megamek/client/ui/swing/lobby/LobbyMekPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static ScalingPopup getPopup(List<Entity> entities, List<Force> forces, ActionLi
popup.add(squadronMenu(clientGui, true, listener, joinedEntities));
}

if (accessibleProtomeks) {
if (allProtomeks) {
popup.add(protoMenu(clientGui, allProtomeks, listener, joinedEntities));
}

Expand Down Expand Up @@ -326,40 +326,56 @@ private static JMenu loadMenu(ClientGUI cg, boolean enabled, ActionListener list
private static JMenu protoMenu(ClientGUI cg, boolean enabled, ActionListener listener,
Collection<Entity> entities) {
JMenu menu = new JMenu("Load ProtoMek");
if (enabled && entities.stream().anyMatch(e -> e.hasETypeFlag(Entity.ETYPE_PROTOMECH))) {
Entity entity = entities.stream().filter(e -> e.hasETypeFlag(Entity.ETYPE_PROTOMECH)).findAny().get();
for (Entity loader: cg.getClient().getGame().getEntitiesVector()) {
if (!loader.hasETypeFlag(Entity.ETYPE_MECH) || !loader.canLoad(entity, false)) {
continue;
}
Transporter front = null;
Transporter rear = null;
for (Transporter t : loader.getTransports()) {
if (t instanceof ProtomechClampMount) {
if (((ProtomechClampMount) t).isRear()) {
rear = t;
} else {
front = t;
}
if(!(enabled || entities.stream().allMatch(e -> e.hasETypeFlag(Entity.ETYPE_PROTOMECH)))){
return menu;
}

Game game = cg.getClient().getGame();
Entity entity = entities.stream().filter(e -> e.hasETypeFlag(Entity.ETYPE_PROTOMECH)).findAny().get();
List<Entity> loaders = game.getEntitiesVector();

// Handle front and rear Magnetic Clamp Mounts
for (Entity loader: loaders) {
if (!loader.hasETypeFlag(Entity.ETYPE_MECH)) {
continue;
}
Transporter front = null;
Transporter rear = null;
for (Transporter t : loader.getTransports()) {
if (t instanceof ProtomechClampMount) {
if (((ProtomechClampMount) t).isRear()) {
rear = t;
} else {
front = t;
}
}
JMenu loaderMenu = new JMenu(loader.getShortName());
if ((front != null) && front.canLoad(entity)
&& ((entity.getWeightClass() < EntityWeightClass.WEIGHT_SUPER_HEAVY)
|| (rear == null) || rear.getLoadedUnits().isEmpty())) {
loaderMenu.add(menuItem("Onto Front", LMP_LOAD + "|" + loader.getId() + ":0" + enToken(entities), enabled, listener));
}
boolean frontUltra = (front != null)
&& front.getLoadedUnits().stream()
.anyMatch(l -> l.getWeightClass() == EntityWeightClass.WEIGHT_SUPER_HEAVY);
if ((rear != null) && rear.canLoad(entity) && !frontUltra) {
loaderMenu.add(menuItem("Onto Rear", LMP_LOAD + "|" + loader.getId() + ":1" + enToken(entities), enabled, listener));
}
if (loaderMenu.getItemCount() > 0) {
menu.add(loaderMenu);
}
}
JMenu loaderMenu = new JMenu(loader.getShortName());
if ((front != null) && front.canLoad(entity)
&& ((entity.getWeightClass() < EntityWeightClass.WEIGHT_SUPER_HEAVY)
|| (rear == null) || rear.getLoadedUnits().isEmpty())) {
loaderMenu.add(menuItem("Onto Front", LMP_LOAD + "|" + loader.getId() + ":0" + enToken(entities), enabled, listener));
}
boolean frontUltra = (front != null)
&& front.getLoadedUnits().stream()
.anyMatch(l -> l.getWeightClass() == EntityWeightClass.WEIGHT_SUPER_HEAVY);
if ((rear != null) && rear.canLoad(entity) && !frontUltra) {
loaderMenu.add(menuItem("Onto Rear", LMP_LOAD + "|" + loader.getId() + ":1" + enToken(entities), enabled, listener));
}
if (loaderMenu.getItemCount() > 0) {
menu.add(loaderMenu);
}
}

// Handle all other valid loaders, such as Dropships
loaders.stream()
.filter(e -> !e.isCapitalFighter(true))
.filter(e -> !entities.contains(e))
.filter(e -> canLoadAll(e, entities))
.forEach(e -> menu.add(menuItem(
"<HTML>" + e.getShortNameRaw() + idString(game, e.getId()),
LMP_LOAD + "|" + e.getId() + ":-1" + enToken(entities), enabled, listener)));

menu.setEnabled(enabled && (menu.getItemCount() > 0));
return menu;
}
Expand Down
6 changes: 3 additions & 3 deletions megamek/src/megamek/common/ProtomechBay.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean canLoad(Entity unit) {
if (doors <= loadedThisTurn) {
result = false;
}

// Return our result.
return result;
}
Expand Down Expand Up @@ -104,14 +104,14 @@ public String toString() {
bayNumber
);
}

public static TechAdvancement techAdvancement() {
return new TechAdvancement(TECH_BASE_CLAN).setClanAdvancement(3060, 3066, 3070)
.setClanApproximate(true, false, false).setTechRating(RATING_C)
.setAvailability(RATING_X, RATING_X, RATING_D, RATING_D)
.setStaticTechLevel(SimpleTechLevel.STANDARD);
}

@Override
public TechAdvancement getTechAdvancement() {
return ProtomechBay.techAdvancement();
Expand Down
3 changes: 3 additions & 0 deletions megamek/src/megamek/common/loaders/BLKFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,10 @@ protected void addTransports(Entity e) throws EntityLoadingException {
pbi = new ParsedBayInfo(numbers, usedBayNumbers);
e.addTransporter(new Bay(pbi.getSize(), pbi.getDoors(), pbi.getBayNumber()), isPod);
break;
case "protomekbay":
// Newer custom BLK handling
case "protomechbay":
// Backward compatibility
pbi = new ParsedBayInfo(numbers, usedBayNumbers);
e.addTransporter(new ProtomechBay(pbi.getSize(), pbi.getDoors(), pbi.getBayNumber()), isPod);
break;
Expand Down

0 comments on commit 7476cbf

Please sign in to comment.