Skip to content

Commit

Permalink
Merge pull request #5373 from HoneySkull/2659_Quad_Turret_Arc
Browse files Browse the repository at this point in the history
Fix: #2659 - Mek Quad turret firing arc reflects turret rotation changes.
  • Loading branch information
HoneySkull authored Apr 18, 2024
2 parents 80ef433 + ad2e426 commit ff3fad8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions megamek/src/megamek/client/ui/swing/TurretFacingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,34 @@ public void actionPerformed(ActionEvent ae) {
} else {
locToChange = turret.getLocation();
}

Mounted firstMountedWeapon = null; // Take note of the first weapon mounted on this turret.
Mounted currentSelectedWeapon = null; // Take note of current selected weapon.
if (clientgui.getUnitDisplay() != null) {
currentSelectedWeapon = clientgui.getUnitDisplay().wPan.getSelectedWeapon();
}

for (Mounted weapon : mech.getWeaponList()) {
if ((weapon.getLocation() == locToChange) && weapon.isMechTurretMounted()) {
weapon.setFacing(facing);
clientgui.getClient().sendMountFacingChange(mech.getId(), mech.getEquipmentNum(weapon), facing);

// Tag the first mounted weapon as a backup option to refresh after the turret rotation.
if (firstMountedWeapon == null) {
firstMountedWeapon = weapon;
}

// If the currently selected weapon is in the turret, refresh it by default.
if (mech.getEquipmentNum(currentSelectedWeapon) == mech.getEquipmentNum(weapon)) {
firstMountedWeapon = currentSelectedWeapon;
}
}
}

// Select the mounted weapon in the unit display to refresh the firing arch.
if (clientgui.getUnitDisplay() != null) {
clientgui.getUnitDisplay().wPan.selectWeapon(mech.getEquipmentNum(firstMountedWeapon));
}
} else if (tank != null) {
tank.setDualTurretOffset(((6 - tank.getFacing()) + facing) % 6);
clientgui.getClient().sendUpdateEntity(tank);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,10 @@ private void setFieldOfFire(Mounted mounted) {
if (entity.isSecondaryArcWeapon(entity.getEquipmentNum(mounted))) {
facing = entity.getSecondaryFacing();
}
// If this is mech with turrets, check to see if the weapon is on a turret.
if ((entity instanceof Mech) && (entity.getEquipment(weaponId).isMechTurretMounted())) {
facing = mounted.getFacing();
}
// If this is a tank with dual turrets, check to see if the weapon is a second turret.
if ((entity instanceof Tank) &&
(entity.getEquipment(weaponId).getLocation() == ((Tank) entity).getLocTurret2())) {
Expand Down

0 comments on commit ff3fad8

Please sign in to comment.