Skip to content

Commit

Permalink
Merge pull request #6291 from psikomonkie/issue-mekhq-4702-new-field-…
Browse files Browse the repository at this point in the history
…guns-from-mekhq-are-broken

Issue 6290: When setting internal for infantry restore field weapons if applicable.
  • Loading branch information
HammerGS authored Dec 20, 2024
2 parents 300f953 + 0c5fb20 commit 8ad58dc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions megamek/src/megamek/common/Infantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ public void setInternal(int val, int loc) {
if (loc == LOC_INFANTRY) {
activeTroopers = Math.max(val, 0);
damageFieldWeapons();
restoreUncrewedFieldWeapons();
}
}

Expand Down Expand Up @@ -896,6 +897,22 @@ public void damageOrRestoreFieldWeapons() {
}
}

/**
* Field guns that are hit (uncrewed) will be set
* to not hit if they have the appropriate number
* of active troopers. Field guns that are destroyed
* will not be un-hit.
*/
public void restoreUncrewedFieldWeapons() {
int totalCrewNeeded = 0;
for (Mounted<?> weapon : originalFieldWeapons()) {
totalCrewNeeded += requiredCrewForFieldWeapon((WeaponType) weapon.getType());
if (activeTroopers >= totalCrewNeeded && !weapon.isDestroyed()) {
weapon.setHit(false);
}
}
}

/**
* @return The crew required to operate the given field gun or field artillery
* weapon, TO:AUE p.123.
Expand Down

0 comments on commit 8ad58dc

Please sign in to comment.