public boolean isElevationValid(int assumedElevation,IHex hex){
  int assumedAlt=assumedElevation + hex.surface();
  if (getMovementMode() == EntityMovementMode.VTOL) {
    if ((this instanceof Infantry) && (hex.containsTerrain(Terrains.BUILDING) || hex.containsTerrain(Terrains.WOODS) || hex.containsTerrain(Terrains.JUNGLE))) {
      return ((assumedElevation <= 50) && (assumedAlt >= hex.floor()));
    }
 else     if (hex.containsTerrain(Terrains.WOODS) || hex.containsTerrain(Terrains.WATER) || hex.containsTerrain(Terrains.JUNGLE)) {
      return ((assumedElevation <= 50) && (assumedAlt > hex.ceiling()));
    }
    return ((assumedElevation <= 50) && (assumedAlt >= hex.ceiling()));
  }
 else   if ((getMovementMode() == EntityMovementMode.SUBMARINE) || ((getMovementMode() == EntityMovementMode.INF_UMU) && hex.containsTerrain(Terrains.WATER)) || ((getMovementMode() == EntityMovementMode.QUAD_SWIM) && hasUMU())|| ((getMovementMode() == EntityMovementMode.BIPED_SWIM) && hasUMU())) {
    return ((assumedAlt >= hex.floor()) && (assumedAlt <= hex.surface()));
  }
 else   if ((getMovementMode() == EntityMovementMode.HYDROFOIL) || (getMovementMode() == EntityMovementMode.NAVAL)) {
    return assumedAlt == hex.surface();
  }
 else   if (getMovementMode() == EntityMovementMode.WIGE) {
    return (assumedAlt >= hex.floor());
  }
 else {
    if (hex.containsTerrain(Terrains.ICE) || ((getMovementMode() == EntityMovementMode.HOVER) && hex.containsTerrain(Terrains.WATER))) {
      if (assumedAlt == hex.surface()) {
        return true;
      }
    }
    if (hex.containsTerrain(Terrains.WATER) && (assumedAlt < hex.surface()) && !(this instanceof Mech)&& !(this instanceof Protomech)) {
      return false;
    }
    if (assumedAlt == hex.floor()) {
      return true;
    }
    if (hex.containsTerrain(Terrains.BRIDGE)) {
      if (assumedElevation == hex.terrainLevel(Terrains.BRIDGE_ELEV)) {
        return true;
      }
    }
    if (hex.containsTerrain(Terrains.BUILDING)) {
      if ((assumedAlt < 0) && (hex.depth(true) > 0)) {
        return true;
      }
      if ((this instanceof Mech) || (this instanceof Protomech) || (this instanceof Infantry)) {
        if ((assumedAlt >= (hex.surface() - hex.depth(true))) && (assumedAlt <= hex.ceiling())) {
          return true;
        }
      }
    }
  }
  return false;
}

public boolean isElevationValid ( int assumedElevation , IHex hex ) { int assumedAlt = assumedElevation + hex . surface ( ) ; if ( getMovementMode ( ) == EntityMovementMode . VTOL ) { if ( ( this instanceof Infantry ) && ( hex . containsTerrain ( Terrains . BUILDING ) || hex . containsTerrain ( Terrains . WOODS ) || hex . containsTerrain ( Terrains . JUNGLE ) ) ) { return ( ( assumedElevation <= 50 ) && ( assumedAlt >= hex . floor ( ) ) ) ; } else if ( hex . containsTerrain ( Terrains . WOODS ) || hex . containsTerrain ( Terrains . WATER ) || hex . containsTerrain ( Terrains . JUNGLE ) ) { return ( ( assumedElevation <= 50 ) && ( assumedAlt > hex . ceiling ( ) ) ) ; } return ( ( assumedElevation <= 50 ) && ( assumedAlt >= hex . ceiling ( ) ) ) ; } else if ( ( getMovementMode ( ) == EntityMovementMode . SUBMARINE ) || ( ( getMovementMode ( ) == EntityMovementMode . INF_UMU ) && hex . containsTerrain ( Terrains . WATER ) ) || ( ( getMovementMode ( ) == EntityMovementMode . QUAD_SWIM ) && hasUMU ( ) ) || ( ( getMovementMode ( ) == EntityMovementMode . BIPED_SWIM ) && hasUMU ( ) ) ) { return ( ( assumedAlt >= hex . floor ( ) ) && ( assumedAlt <= hex . surface ( ) ) ) ; } else if ( ( getMovementMode ( ) == EntityMovementMode . HYDROFOIL ) || ( getMovementMode ( ) == EntityMovementMode . NAVAL ) ) { return assumedAlt == hex . surface ( ) ; } else if ( getMovementMode ( ) == EntityMovementMode . WIGE ) { return ( assumedAlt >= hex . floor ( ) ) ; } else { if ( hex . containsTerrain ( Terrains . ICE ) || ( ( getMovementMode ( ) == EntityMovementMode . HOVER ) && hex . containsTerrain ( Terrains . WATER ) ) ) { if ( assumedAlt == hex . surface ( ) ) { return true ; } } if ( hex . containsTerrain ( Terrains . WATER ) && ( assumedAlt < hex . surface ( ) ) && ! ( this instanceof Mech ) && ! ( this instanceof Protomech ) ) { return false ; } if ( assumedAlt == hex . floor ( ) ) { return true ; } if ( hex . containsTerrain ( Terrains . BRIDGE ) ) { if ( assumedElevation == hex . terrainLevel ( Terrains . BRIDGE_ELEV ) ) { return true ; } } if ( hex . containsTerrain ( Terrains . BUILDING ) ) { if ( ( assumedAlt < 0 ) && ( hex . depth ( true ) > 0 ) ) { return true ; } if ( ( this instanceof Mech ) || ( this instanceof Protomech ) || ( this instanceof Infantry ) ) { if ( ( assumedAlt >= ( hex . surface ( ) - hex . depth ( true ) ) ) && ( assumedAlt <= hex . ceiling ( ) ) ) { return true ; } } } } return false ; }
check if this entity can legally occupy the requested elevation . does not check stacking , only terrain limitations
