diff --git a/megamek/data/scenarios/Test Setups/AeroScen.mms b/megamek/data/scenarios/Test Setups/AeroScen.mms new file mode 100644 index 00000000000..55a8c7470e3 --- /dev/null +++ b/megamek/data/scenarios/Test Setups/AeroScen.mms @@ -0,0 +1,44 @@ +MMSVersion: 2 +name: Sky Battle Test +description: Aero Fighter Test Setup on a terrain-less low atmo map + +map: + type: sky + width: 36 + height: 19 + +factions: + - name: Epsilon Galaxy Flight + camo: Clans/Coyote/Epsilon Galaxy.jpg + + units: + - fullname: Cheetah F-11 + at: [2, 12] + facing: 1 + altitude: 6 + velocity: 3 + crew: + name: Marianne O'Brien + gunnery: 4 + piloting: 4 + portrait: Female/Aerospace Pilot/ASF_F_2.png + + - fullname: Cheetah F-11 + at: [3, 17] + facing: 1 + velocity: 2 + crew: + name: Giulia DeMarco + gunnery: 3 + piloting: 5 + portrait: Female/Aerospace Pilot/ASF_F_3.png + + - name: OpFor + camo: Corporations/Star Corps.png + units: + - fullname: Cheetah F-11 + at: [ 32, 8 ] + facing: 4 + - fullname: Cheetah F-11 + at: [ 34, 8 ] + facing: 4 \ No newline at end of file diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index d185b0dc021..ba1d09ff9ec 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -14228,13 +14228,8 @@ public double getAlternateCost() { */ public boolean isTrapped() { if (getTransportId() != Entity.NONE) { - Entity transport = game.getEntity(getTransportId()); - if (transport == null) { - transport = game.getOutOfGameEntity(getTransportId()); - } - if (transport.isDestroyed()) { - return true; - } + Entity transport = game.getEntityFromAllSources(getTransportId()); + return (transport != null) && transport.isDestroyed(); } return false; } diff --git a/megamek/src/megamek/common/FighterSquadron.java b/megamek/src/megamek/common/FighterSquadron.java index a975daf6524..5142cb450bb 100644 --- a/megamek/src/megamek/common/FighterSquadron.java +++ b/megamek/src/megamek/common/FighterSquadron.java @@ -506,26 +506,19 @@ public void applyBombs() { * TODO: Make this into a generic "clean up bomb loadout" method */ public void computeSquadronBombLoadout() { - // Remove any currently equipped bombs - for (Mounted bomb : bombList) { - equipmentList.remove(bomb); - } - bombList.clear(); + clearBombs(); // Find out what bombs everyone has - for (int btype = 0; btype < BombType.B_NUM; btype++) { - // This is smallest number of such a bomb + for (int bombType = 0; bombType < BombType.B_NUM; bombType++) { + int finalBombType = bombType; int maxBombCount = 0; for (Entity fighter : getSubEntities()) { - int bombCount = 0; - for (Mounted m : fighter.getBombs()) { - if (((BombType) m.getType()).getBombType() == btype) { - bombCount++; - } - } + int bombCount = (int) fighter.getBombs().stream() + .filter(m -> m.getType().getBombType() == finalBombType) + .count(); maxBombCount = Math.max(bombCount, maxBombCount); } - extBombChoices[btype] = maxBombCount; + extBombChoices[bombType] = maxBombCount; } // Now that we know our bomb choices, load 'em diff --git a/megamek/src/megamek/common/IAero.java b/megamek/src/megamek/common/IAero.java index 69867e91019..9060caac715 100644 --- a/megamek/src/megamek/common/IAero.java +++ b/megamek/src/megamek/common/IAero.java @@ -18,6 +18,7 @@ import java.util.*; import megamek.common.MovePath.MoveStepType; +import megamek.common.options.OptionsConstants; import org.apache.logging.log4j.LogManager; /** @@ -196,43 +197,46 @@ default boolean requiresFuel() { * Refresh the capital fighter weapons groups. */ default void updateWeaponGroups() { - // first we need to reset all the weapons in our existing mounts to zero - // until proven otherwise - Set set = getWeaponGroups().keySet(); - Iterator iter = set.iterator(); - while (iter.hasNext()) { - String key = iter.next(); - ((Entity) this).getEquipment(getWeaponGroups().get(key)).setNWeapons(0); - } - // now collect a hash of all the same weapons in each location by id - Map groups = groupWeaponsByLocation(); - // now we just need to traverse the hash and either update our existing - // equipment or add new ones if there is none - Set newSet = groups.keySet(); - Iterator newIter = newSet.iterator(); - while (newIter.hasNext()) { - String key = newIter.next(); - if (null != getWeaponGroups().get(key)) { - // then this equipment is already loaded, so we just need to - // correctly update the number of weapons - ((Entity) this).getEquipment(getWeaponGroups().get(key)).setNWeapons(groups.get(key)); - } else { - // need to add a new weapon - String name = key.split(":")[0]; - int loc = Integer.parseInt(key.split(":")[1]); - EquipmentType etype = EquipmentType.get(name); - Mounted newmount; - if (etype != null) { - try { - newmount = ((Entity) this).addWeaponGroup(etype, loc); - newmount.setNWeapons(groups.get(key)); - getWeaponGroups().put(key, ((Entity) this).getEquipmentNum(newmount)); - } catch (LocationFullException ex) { - LogManager.getLogger().error("Unable to compile weapon groups", ex); - return; + if ((this instanceof Entity entity) && (entity.game != null) + && entity.game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_CAPITAL_FIGHTER)) { + // first we need to reset all the weapons in our existing mounts to zero + // until proven otherwise + Set set = getWeaponGroups().keySet(); + Iterator iter = set.iterator(); + while (iter.hasNext()) { + String key = iter.next(); + ((Entity) this).getEquipment(getWeaponGroups().get(key)).setNWeapons(0); + } + // now collect a hash of all the same weapons in each location by id + Map groups = groupWeaponsByLocation(); + // now we just need to traverse the hash and either update our existing + // equipment or add new ones if there is none + Set newSet = groups.keySet(); + Iterator newIter = newSet.iterator(); + while (newIter.hasNext()) { + String key = newIter.next(); + if (null != getWeaponGroups().get(key)) { + // then this equipment is already loaded, so we just need to + // correctly update the number of weapons + ((Entity) this).getEquipment(getWeaponGroups().get(key)).setNWeapons(groups.get(key)); + } else { + // need to add a new weapon + String name = key.split(":")[0]; + int loc = Integer.parseInt(key.split(":")[1]); + EquipmentType etype = EquipmentType.get(name); + Mounted newmount; + if (etype != null) { + try { + newmount = ((Entity) this).addWeaponGroup(etype, loc); + newmount.setNWeapons(groups.get(key)); + getWeaponGroups().put(key, ((Entity) this).getEquipmentNum(newmount)); + } catch (LocationFullException ex) { + LogManager.getLogger().error("Unable to compile weapon groups", ex); + return; + } + } else if (!"0".equals(name)) { + ((Entity) this).addFailedEquipment(name); } - } else if (!"0".equals(name)) { - ((Entity) this).addFailedEquipment(name); } } } diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index a43a22b3b21..a3f388e17a5 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -29145,15 +29145,17 @@ private void receiveSquadronAdd(Packet c, int connIndex) { if (null != fighter) { formerCarriers.addAll(ServerLobbyHelper.lobbyUnload(game, List.of(fighter))); fs.load(fighter, false); - fs.autoSetMaxBombPoints(); fighter.setTransportId(fs.getId()); - // If this is the lounge, we want to configure bombs - if (getGame().getPhase().isLounge()) { - ((IBomber) fighter).setBombChoices(fs.getExtBombChoices()); - } entityUpdate(fighter.getId()); } } + fs.updateSkills(); + fs.updateWeaponGroups(); + fs.updateSensors(); + fs.autoSetMaxBombPoints(); + if (!getGame().getPhase().isLounge()) { + fs.applyBombs(); + } if (!formerCarriers.isEmpty()) { send(new Packet(PacketCommand.ENTITY_MULTIUPDATE, formerCarriers)); } diff --git a/megamek/src/megamek/utilities/DebugEntity.java b/megamek/src/megamek/utilities/DebugEntity.java index 08129be4d79..988d0d20936 100644 --- a/megamek/src/megamek/utilities/DebugEntity.java +++ b/megamek/src/megamek/utilities/DebugEntity.java @@ -23,18 +23,14 @@ import java.awt.datatransfer.StringSelection; import java.util.List; -import megamek.common.CriticalSlot; -import megamek.common.Entity; -import megamek.common.Infantry; -import megamek.common.Mech; -import megamek.common.Protomech; -import megamek.common.Transporter; +import megamek.common.*; import megamek.common.equipment.WeaponMounted; /** * This class is for debugging Entity with respect to the internal state of * equipment. */ +@SuppressWarnings("unused") // for debugging use public final class DebugEntity { /** @@ -71,7 +67,7 @@ public static String getEquipmentState(Entity entity) { result.append("Equipment:\n"); for (int i = 0; i < entity.getEquipment().size(); i++) { - result.append("[" + i + "] ").append(entity.getEquipment(i)).append("\n"); + result.append("[").append(i).append("] ").append(entity.getEquipment(i)).append("\n"); if (entity != entity.getEquipment(i).getEntity()) { result.append("Different Entity!"); } @@ -100,7 +96,7 @@ public static String getEquipmentState(Entity entity) { result.append("Transports:\n"); List transports = entity.getTransports(); for (int i = 0; i < transports.size(); i++) { - result.append("[" + i + "] ").append(transports.get(i)).append("\n"); + result.append("[").append(i).append("] ").append(transports.get(i)).append("\n"); } result.append("\n"); } @@ -111,7 +107,7 @@ public static String getEquipmentState(Entity entity) { for (int slot = 0; slot < entity.getNumberOfCriticals(location); slot++) { CriticalSlot criticalSlot = entity.getCritical(location, slot); if (criticalSlot != null) { - result.append("[" + slot + "] ").append(criticalSlot); + result.append("[").append(slot).append("] ").append(criticalSlot); if (criticalSlot.getType() == 0) { result.append(" ("); if (entity instanceof Mech) { @@ -129,9 +125,15 @@ public static String getEquipmentState(Entity entity) { result.append("\nAn exception was encountered here. ").append(e.getMessage()); } + if (entity instanceof FighterSquadron fighterSquadron) { + for (Entity fighter : fighterSquadron.getLoadedUnits()) { + result.append("\n\n"); + result.append(getEquipmentState(fighter)); + } + } + return result.toString(); } - private DebugEntity() { - } + private DebugEntity() { } }