Author Topic: AAA Flak artillery in Megamek?  (Read 2618 times)

HMS_Swiftsure

  • Master Sergeant
  • *
  • Posts: 276
AAA Flak artillery in Megamek?
« on: 13 February 2012, 15:50:34 »
Thanks to, uh, another thread, I wanted to see what AAA Flak looked like out of long toms or similar tube artillery.  It seemed like Megamek had no such option, and was going to leave it at that when I saw some hits on google - looked like an artillery flak elevation bug fix in .27

This leads me to believe one of two things:  Flak is in MM and I'm just too dumb to figure it out, or it's being worked on.  Am I missing something?

Thanks!

BeeRockxs

  • BattleTech Volunteer
  • Warrant Officer
  • *
  • Posts: 459
Re: AAA Flak artillery in Megamek?
« Reply #1 on: 13 February 2012, 16:44:05 »
Fire an artillery weapon directly at a VTOL.

HMS_Swiftsure

  • Master Sergeant
  • *
  • Posts: 276
Re: AAA Flak artillery in Megamek?
« Reply #2 on: 14 February 2012, 02:26:03 »
Aaahhh.  See, I was targeting aerospace driven by Princess.  There was my error.

[edit] TO 185 seems to indicate that artillery can target "airborne ground units (VTOL Vehicles, WiGEs, and units expending VTOL MPs such as infantry) as well as airborne aerospace units.

So I figured I'd break out the source code and try babbys first attempt at coding java.

It was less than successful.

I found the artillery flak line in WeaponAttackAction.java:

Code: [Select]
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.VTOL)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

Okay, cool, so it's looking at only VTOLs for EntityMovementMode.  So I thought I'd get clever and add the others.

Code: [Select]
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.VTOL)
                || (te.getMovementMode() == IEntityMovementMode.AERODYNE)
                || (te.getMovementMode() == IEntityMovementMode.AIRMECH)
                || (te.getMovementMode() == IEntityMovementMode.AEROSPACE)
                || (te.getMovementMode() == IEntityMovementMode.SPHEROID)
|| (te.getMovementMode() == IEntityMovementMode.WIGE))
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

As you can imagine, it didn't like that.  No idea why not, again, babbys first java.

So I figured I'd get real clever and just spam these boolean things.

Code: [Select]
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.VTOL)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == IEntityMovementMode.AERODYNE)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.AIRMECH)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.AEROSPACE)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.SPHEROID)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.WIGE)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

Hoooboy it REALLY didn't like that.

I hope you have gotten a chuckle out of watching this noob stumble around code like a drunk monkey.
« Last Edit: 14 February 2012, 03:06:50 by HMS_Swiftsure »

BeeRockxs

  • BattleTech Volunteer
  • Warrant Officer
  • *
  • Posts: 459
Re: AAA Flak artillery in Megamek?
« Reply #3 on: 14 February 2012, 07:12:15 »

I found the artillery flak line in WeaponAttackAction.java:

Code: [Select]
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.VTOL)
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

Okay, cool, so it's looking at only VTOLs for EntityMovementMode.  So I thought I'd get clever and add the others.

Code: [Select]
        boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (te.getMovementMode() == EntityMovementMode.VTOL)
                || (te.getMovementMode() == IEntityMovementMode.AERODYNE)
                || (te.getMovementMode() == IEntityMovementMode.AIRMECH)
                || (te.getMovementMode() == IEntityMovementMode.AEROSPACE)
                || (te.getMovementMode() == IEntityMovementMode.SPHEROID)
|| (te.getMovementMode() == IEntityMovementMode.WIGE))
&& (te.getElevation() > 0)
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

As you can imagine, it didn't like that.  No idea why not, again, babbys first java.

That's the right approach. The problem is that Aero units don't use elevation, but altitude, and so the te.getElevation() > 0 check does not work for them.

HMS_Swiftsure

  • Master Sergeant
  • *
  • Posts: 276
Re: AAA Flak artillery in Megamek?
« Reply #4 on: 14 February 2012, 11:42:18 »
Her... er... hrm.

That's a pickle.

Is there a generic "is flying" or "is not on ground" method that would be shared between vtol/aero?

BeeRockxs

  • BattleTech Volunteer
  • Warrant Officer
  • *
  • Posts: 459
Re: AAA Flak artillery in Megamek?
« Reply #5 on: 14 February 2012, 13:02:50 »
There's no shared one, for the ASF movementmodes, you should use Entity#isAirborne, and instead of the elevation check, use Entity#isAirborneVTOLorWIGE, and also check for the WiGE movement mode.
So overall, the code should look like this:

 boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (((te.getMovementMode() == EntityMovementMode.VTOL || te.getMovementMode() == EntityMovementMode.WIGE) && te.isAirborneVTOLorWIGE)
                      || ((te.getMovementMode() == IEntityMovementMode.AERODYNE
                           || te.getMovementMode() == IEntityMovementMode.AIRMECH
                           || te.getMovementMode() == IEntityMovementMode.AEROSPACE
                           || te.getMovementMode() == IEntityMovementMode.SPHEROID) && te.isAirborne())
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));

HMS_Swiftsure

  • Master Sergeant
  • *
  • Posts: 276
Re: AAA Flak artillery in Megamek?
« Reply #6 on: 14 February 2012, 21:02:04 »
BeeRockxs, thank you so much for picking up this question and dealing with my code noob self.  This is why megamek devs are awesome.

I entered the code as provided, and ran into compile errors.  It is Java after all.  It's purpose in life wouldn't be complete without throwing some errors.

Here's the result of the build attempt.  I'd futz with it some more, but the girl must be woo'd.  Hallmark day and all.

Code: [Select]
src\megamek\common\actions\WeaponAttackAction.java:266: error: ')' expected
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD));
                                                                                 ^
src\megamek\common\actions\WeaponAttackAction.java:261: error: cannot find symbol
                && (((te.getMovementMode() == EntityMovementMode.VTOL || te.getMovementMode() == E

  symbol:   variable isAirborneVTOLorWIGE
  location: variable te of type Entity
src\megamek\common\actions\WeaponAttackAction.java:262: error: cannot find symbol
                || ((te.getMovementMode() == IEntityMovementMode.AERODYNE
                                             ^
  symbol:   variable IEntityMovementMode
  location: class WeaponAttackAction
src\megamek\common\actions\WeaponAttackAction.java:263: error: cannot find symbol
                || te.getMovementMode() == IEntityMovementMode.AIRMECH
                                           ^
  symbol:   variable IEntityMovementMode
  location: class WeaponAttackAction
src\megamek\common\actions\WeaponAttackAction.java:264: error: cannot find symbol
                || te.getMovementMode() == IEntityMovementMode.AEROSPACE
                                           ^
  symbol:   variable IEntityMovementMode
  location: class WeaponAttackAction
src\megamek\common\actions\WeaponAttackAction.java:265: error: cannot find symbol
                || te.getMovementMode() == IEntityMovementMode.SPHEROID) && te.isAirborne())
                                           ^
  symbol:   variable IEntityMovementMode
  location: class WeaponAttackAction
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
1 warning

Be back later to futz some more.

BeeRockxs

  • BattleTech Volunteer
  • Warrant Officer
  • *
  • Posts: 459
Re: AAA Flak artillery in Megamek?
« Reply #7 on: 15 February 2012, 05:24:01 »
Right, a ')' is missing at the end, and you'll need to change the references to "IEntityMovementMode" to "EntityMovementMode".

HMS_Swiftsure

  • Master Sergeant
  • *
  • Posts: 276
Re: AAA Flak artillery in Megamek?
« Reply #8 on: 15 February 2012, 11:33:26 »
Cool, that buttoned up most of the compile errors except the first.

Code: [Select]
  src\megamek\common\actions\WeaponAttackAction.java:261: error: cannot find symbol
                && (((te.getMovementMode() == EntityMovementMode.VTOL || te.getMovementMode() == EntityMovementMode.WIGE) && te.isAirborneVTOLorWIGE)
                                                                                                                               ^
  symbol:   variable isAirborneVTOLorWIGE
  location: variable te of type Entity
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
1 warning

[edit] Okay, added a () the end of te.isAirborneVTOLorWIGE.  This either just made it happy and will fail in-game, or it'll work fine.  Will post results.
[edit2] Welp, that seems to have worked.  Interesting note, field artillery gunners can target VTOLs, but not aerospace proper.  This might be working as per the rules, though, since infantry cannot attack aerospace.  All in all, it's definitely an improvement.  Thanks, bee!  Here's the code as compiled that seems to work:
Code: [Select]
boolean isArtilleryFLAK = isArtilleryDirect && (target.getTargetType() == Targetable.TYPE_ENTITY)
                && (((te.getMovementMode() == EntityMovementMode.VTOL || te.getMovementMode() == EntityMovementMode.WIGE) && te.isAirborneVTOLorWIGE())
                || ((te.getMovementMode() == EntityMovementMode.AERODYNE
                || te.getMovementMode() == EntityMovementMode.AIRMECH
                || te.getMovementMode() == EntityMovementMode.AEROSPACE
                || te.getMovementMode() == EntityMovementMode.SPHEROID) && te.isAirborne())
                && (usesAmmo && (atype.getMunitionType() == AmmoType.M_STANDARD)));
« Last Edit: 15 February 2012, 12:24:37 by HMS_Swiftsure »