int AircraftClass::Mission_Attack() {
  switch(this->MissionStatus) {
    case 0:
      this->CanFire = 0;
      this->MissionStatus = this->Target ? 1 : 10;
      return 1;
      
    case 1:
      this->CanFire = 0;
      if(this->RemoveAmmo) {
        --this->CurrentAmmo;
        this->RemoveAmmo = 0;
      }
      if(!this->Target || !this->CurrentAmmo) {
        this->MissionStatus = 10;
        break;
      }
      
      this->SetDestination(this->ConvertTargetToDestination(this->Target), 1);
      this->MissionStatus = this->Destination ? 3 : 10;
      break;
      
    case 2:
      break; // ?
    
    case 3:
      if(this->RemoveAmmo) {
        --this->CurrentAmmo;
        this->RemoveAmmo = 0;
      }
      this->CanFire = 0;
      if(!this->Target || !this->CurrentAmmo) {
        this->MissionStatus = 10;
        return 1;
      }
      if(this->IsStrafe()) {
        if(this->DistanceFrom(this->Target) < this->GetWeapon(SLOT_PRIMARY)->Range) {
          this->MissionStatus = 4;
          return 1;
        }
        this->SetDestination(this->Target, 1);
        if(!this->Destination) {
          this->MissionStatus = 1;
          return 1;
        }
      } else if(this->IsFighter() || !this->Locomotion->IsMovingNow()) {
        this->MissionStatus = 4;
        return 1;
      }
      if(!this->Destination) {
        this->MissionStatus = 1;
        return 1;
      }

      int distance = this->DistanceFrom(this->Destination);
      if(distance < 512) {
        this->TurretFacing->TurnBy(World2D::FacingDifference(this, this->Target));
        if(distance >= 16) {
          return 1;
        }
        this->MissionStatus = 4;
        this->SetDestination(NULL, 1);
        return 1;
      }
      
      CoordStruct XYZ_Dest;
      this->Destination->GetCoords(&XYZ_Dest);
      
      CoordStruct XYZ_FLH = {0, 0, 0};
      this->GetFLH(&XYZ_FLH, SLOT_PRIMARY);

      this->TurretFacing->TurnBy(World2D::FacingDifference(XYZ_FLH, XYZ_Dest));
      return 1;

    case 4:
      if(!this->Target || !this->CurrentAmmo) {
        this->MissionStatus = 10;
        return 1;
      }
      if(!this->IsStrafe()) {
        this->Facing->TurnBy(World2D::FacingDifference(this, this->Target));
        this->TurretFacing->TurnBy(World2D::FacingDifference(this, this->Target));
      }

      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_ReadyToFire:
          this->RemoveAmmo = 1;
          for(int idx = 0; i < this->GetWeapon(this->SelectWeapon(this->Target))->WeaponType->Burst; ++i) {
            this->Fire(this->Target, this->SelectWeapon(this->Target));
          }
          
          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          if(this->IsStrafe()) {
            this->MissionStatus = 6;
            return this->GetWeapon(0)->WeaponType->ROF;
          }
          if(this->IsFighter()) {
            this->MissionStatus = this->CurrentAmmo > 0 ? 1 : 10;
            return this->GetWeapon(0)->WeaponType->ROF;
          }
          this->MissionStatus = 5;
          return 1;

        case fs_MustTurn:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            return 1;
          }
          if(!this->IsCloseEnoughToAttack(this->Target) || this->IsStrafe()) {
            this->MissionStatus = 1;
          } else if(this->IsFighter()) {
            this->MissionStatus = 4;
          } else {
            this->MissionStatus = RulesClass::Instance->CurleyShuffle ? 1 : 4;
          }
          return this->IsStrafe() ? 45 : 1;

        case fs_WaitForIt:
          return 1;

        case fs_DecloakFirst:
          this->Uncloak(0);
          return 1;

        case fs_NoAmmo:
        case fs_4:
        case fs_CantAffect:
        case fs_CantCommand:
        case fs_CantInterrupt:
        case fs_OutOfRange:
        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
          } else if(!this->IsStrafe()) {
            this->MissionStatus = 5;
          }
          return 1;
      }

    case 5:
      if(!this->Target) {
        this->MissionStatus = 10;
        return 1;
      }
      
      this->Facing->TurnBy(World2D::FacingDifference(this, this->Target));
      this->TurretFacing->TurnBy(World2D::FacingDifference(this, this->Target));

      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_ReadyToFire:
          this->Fire(this->Target, this->SelectWeapon(this->Target));
          
          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
          } else {
            this->MissionStatus = RulesClass::Instance->CurleyShuffle ? 1 : 4;
          }
          break;

        case fs_MustTurn:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            return 1;
          }
          if(!this->IsCloseEnoughToAttack(this->Target) || this->IsStrafe()) {
            this->MissionStatus = 1;
          } else {
            this->MissionStatus = RulesClass::Instance->CurleyShuffle ? 1 : 4;
          }
          if(this->IsStrafe()) {
            return 45;
          }
          break;

        case fs_WaitForIt:
          break;

        case fs_DecloakFirst:
          this->Uncloak(0);
          break;

        case fs_NoAmmo:
        case fs_4:
        case fs_CantAffect:
        case fs_CantCommand:
        case fs_CantInterrupt:
        case fs_OutOfRange:
        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            break;
          }
          if(this->CloseEnoughToAttack(this->Target)) {
            this->MissionStatus = 1;
            break;
          }
          this->MissionStatus = RulesClass::Instance->CurleyShuffle ? 1 : 4;
          break;
      }

    case 6:


      if(!this->Target) {
        this->MissionStatus = 10;
        return 1;
      }
      
      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_OutOfRange:
          this->SetDestination(this->Target, 1);

        case fs_ReadyToFire:
        case fs_MustTurn:
        case fs_DecloakFirst:
          this->Fire(this->Target, this->SelectWeapon(this->Target));

          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          this->SetDestination(this->Target, 1);

          this->MissionStatus = 7;
          return this->GetWeapon(0)->WeaponType->ROF;

        case fs_4:
        case fs_CantAffect:
        case fs_CantCommand:
        case fs_CantInterrupt:
        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            this->CanFire = 0;
          }
          return 1;
      }

    case 7:
      if(!this->Target) {
        this->MissionStatus = 10;
        return 1;
      }

      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_OutOfRange:
          this->SetDestination(this->Target, 1);

        case fs_ReadyToFire:
        case fs_MustTurn:
        case fs_DecloakFirst:
          this->Fire(this->Target, this->SelectWeapon(this->Target));

          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          this->SetDestination(this->Target, 1);

          this->MissionStatus = 8;
          return this->GetWeapon(0)->WeaponType->ROF;

        case fs_4:
        case fs_CantAffect:
        case fs_CantCommand:
        case fs_CantInterrupt:
        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            this->CanFire = 0;
          }
          return 1;
      }

    case 8:
      if(!this->Target) {
        this->MissionStatus = 10;
        return 1;
      }

      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_OutOfRange:
          this->SetDestination(this->Target, 1);

        case fs_ReadyToFire:
        case fs_MustTurn:
        case fs_DecloakFirst:
          this->Fire(this->Target, this->SelectWeapon(this->Target));

          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          this->SetDestination(this->Target, 1);

          this->MissionStatus = 9;
          return this->GetWeapon(0)->WeaponType->ROF;

        case fs_4:
        case fs_CantAffect:
        case fs_CantCommand:
        case fs_CantInterrupt:
        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            this->CanFire = 0;
          }
          return 1;
      }

    case 9:
      if(!this->Target) {
        this->MissionStatus = 10;
        return 1;
      }

      switch(this->GetFiringStateAgainst(this->Target, this->SelectWeapon(this->Target), 1)) {
        case fs_ReadyToFire:
        case fs_MustTurn:
        case fs_DecloakFirst:
        case fs_OutOfRange:
          this->Fire(this->Target, this->SelectWeapon(this->Target));

          CoordStruct XYZ_MyPos = this->Location;
          CoordStruct XYZ_TargetPos;
          this->Target->GetCoords(&XYZ_TargetPos);
          MapClass::Instance->GetCell(&XYZ_TargetPos)->ScatterContent(&XYZ_MyPos, 1, 0, 0);

          this->SetDestination(this->Target, 1);

          this->MissionStatus = 3;
          return (1024 + this->GetWeapon(0)->WeaponType->Range) / this->Type->Speed;

        default:
          if(!this->CurrentAmmo) {
            this->MissionStatus = 10;
            this->CanFire = 0;
          }
          return 1;
      }

    case 10:
      this->CanFire = 0;
      if(this->RemoveAmmo) {
        --this->CurrentAmmo;
        this->RemoveAmmo = 0;
      }
      if(!this->CurrentAmmo) {
        if(this->Spawned || this->Owner->IsHuman()) {
          this->SetTarget(NULL);
        }
      } else if(this->Target) {
        this->MissionStatus = 1;
        return 1;
      }
      this->CanFire = 0;
      this->SetDestination(MapClass::Instance->GetCell(MapClass::Instance->FindCellOnEdge(this->Owner->Edge)), 1);
      this->unknown_6D5 = 0;
      if(this->AirstrikeControl && this->CurrentAmmo) {
        this->QueueMission(mission_Retreat, 0);
        this->unknown_6D5 = 1;
        return 1;
      }
      this->AssumeMissionComplete(0, 1);
      this->unknown_6D5 = 1;
      return 1;
      
  }

  return FloatToInt(this->GetMissionData()->Rate * 900) + ScenarioClass::Instance->Randomizer->RandomRanged(0, 2);
}