Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5204: Fighter Squadron weapon crits and group damage application #5251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions megamek/src/megamek/common/AeroSpaceFighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,28 @@ public boolean isSpheroid() {
return false;
}

@Override
public boolean isBomber() {
return true;
}

@Override
public boolean isFighter() {
return true;
}

@Override
public boolean isAerospaceFighter() {
return true;
}

/**
* Damage a capital fighter's weapons. WeaponGroups are damaged by critical hits.
* This matches up the individual fighter's weapons and critical slots and damages those
* for MHQ resolution
* @param loc - Int corresponding to the location struck
* Method to enable mass location damaging, mainly for Fighter Squadrons
* @param loc that every fighter in the squadron needs to damage, for MekHQ tracking
*/
public void damageCapFighterWeapons(int loc) {
for (Mounted weapon : weaponList) {
if (weapon.getLocation() == loc) {
public void damageLocation(int loc) {
weaponList.stream().filter(x -> x.getLocation() == loc).forEach(
(weapon)-> {
//Damage the weapon
weapon.setHit(true);
//Damage the critical slot
Expand All @@ -78,22 +91,7 @@ public void damageCapFighterWeapons(int loc) {
}
}
}
}
}

@Override
public boolean isBomber() {
return true;
}

@Override
public boolean isFighter() {
return true;
}

@Override
public boolean isAerospaceFighter() {
return true;
);
}

@Override
Expand Down
30 changes: 30 additions & 0 deletions megamek/src/megamek/common/FighterSquadron.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ public void load(Entity unit, boolean checkFalse, int bayNumber) throws IllegalA
// Add the unit to our squadron.
fighters.add(unit.getId());
}
// FighterSquadrons should handle this collectively
unit.setTransportId(id);

if (!getGame().getPhase().isLounge()) {
computeSquadronBombLoadout(); // this calls updateWeaponGroups() and loadAllWeapons()
Expand All @@ -646,6 +648,7 @@ public boolean unload(Entity unit) {
loadAllWeapons();
}
updateSkills();
unit.setTransportId(Entity.NONE);
return success;
}

Expand Down Expand Up @@ -750,4 +753,31 @@ public boolean isFighter() {
public boolean isCapitalScale() {
return true;
}

/** Override of Entity method.
* This needs to be set or we can't do a reverse lookup from a Capital Fighter to its Squadron.
* @param transportId - the <code>int</code> ID of our transport. The ID is
* <b>not</b> validated. This value should be
* <code>Entity.NONE</code> if this unit has been unloaded.
*/
@Override
public void setTransportId(int transportId) {
fighters.stream().map(fid -> game.getEntity(fid))
.forEach(f -> f.setTransportId(transportId));
}

/**
* Damage a capital fighter's weapons. WeaponGroups are damaged by critical hits.
* This matches up the individual fighter's weapons and critical slots and damages those
* for MHQ resolution
* @param loc - Int corresponding to the location struck
*/
public void damageCapFighterWeapons(int loc) {
for (int fid: fighters) {
AeroSpaceFighter fighter = (AeroSpaceFighter) game.getEntity(fid);
fighter.damageLocation(loc);

}
}

}
9 changes: 5 additions & 4 deletions megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25137,12 +25137,13 @@ private Vector<Report> applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in
}
}
case Aero.CRIT_WEAPON:
if (aero.isCapitalFighter()) {
FighterSquadron cf = (FighterSquadron) aero;
FighterSquadron cf = (FighterSquadron) game.getEntity(aero.getTransportId());
if (aero.isCapitalFighter() && cf != null) {
// The Squadron should be set as the "transport" of the Squadron members, but may be null
boolean destroyAll = false;
// CRIT_WEAPON damages the capital fighter/squadron's weapon groups
// Go ahead and map damage for the fighter's weapon criticals for MHQ
// resolution.
// TODO: Go ahead and map damage for the fighters' weapon criticals for MHQ resolution.
// (Currently this is not working as the Capital Fighter has no weapons of its own, only groups.
cf.damageCapFighterWeapons(loc);
if ((loc == Aero.LOC_NOSE) || (loc == Aero.LOC_AFT)) {
destroyAll = true;
Expand Down
Loading