Skip to content

Commit

Permalink
Merge pull request #5841 from SJuliez/aero-bombs-fs
Browse files Browse the repository at this point in the history
FighterSquadron updates
  • Loading branch information
Sleet01 authored Aug 4, 2024
2 parents 0f0d10d + 55b3d63 commit 887fff7
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 73 deletions.
44 changes: 44 additions & 0 deletions megamek/data/scenarios/Test Setups/AeroScen.mms
Original file line number Diff line number Diff line change
@@ -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
9 changes: 2 additions & 7 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 7 additions & 14 deletions megamek/src/megamek/common/FighterSquadron.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 40 additions & 36 deletions megamek/src/megamek/common/IAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.*;

import megamek.common.MovePath.MoveStepType;
import megamek.common.options.OptionsConstants;
import org.apache.logging.log4j.LogManager;

/**
Expand Down Expand Up @@ -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<String> set = getWeaponGroups().keySet();
Iterator<String> 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<String, Integer> 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<String> newSet = groups.keySet();
Iterator<String> 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<String> set = getWeaponGroups().keySet();
Iterator<String> 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<String, Integer> 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<String> newSet = groups.keySet();
Iterator<String> 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);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
24 changes: 13 additions & 11 deletions megamek/src/megamek/utilities/DebugEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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!");
}
Expand Down Expand Up @@ -100,7 +96,7 @@ public static String getEquipmentState(Entity entity) {
result.append("Transports:\n");
List<Transporter> 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");
}
Expand All @@ -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) {
Expand All @@ -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() { }
}

0 comments on commit 887fff7

Please sign in to comment.