コード例 #1
0
 internal void Clean()
 {
     Targeting = null;
     FakeController.SlimBlock = null;
     MyCubeBocks.ClearImmediate();
     MostBlocks     = 0;
     PowerCheckTick = 0;
     SuspectedDrone = false;
     Powered        = false;
 }
コード例 #2
0
 internal void Clean()
 {
     Targeting = null;
     MyCubeBocks.ClearImmediate();
     MostBlocks = 0;
 }
コード例 #3
0
        /// <summary>
        /// target priority
        /// missiles - not implementing due to keen
        /// suites, decoys
        /// closest terminal block
        /// meteor
        /// </summary>
        private MyEntity TargetAcquisition()
        {
            MyGridTargeting targetingSystem = Block.CubeGrid.Components.Get <MyGridTargeting>();

            if (targetingSystem == null)
            {
                return(null);
            }

            List <MyEntity> targetSet = targetingSystem.TargetRoots;

            double   likelyTargetDistanceSqrd = double.MaxValue;
            MyEntity likelyTarget             = null;

            foreach (MyEntity ent in targetSet)
            {
                if (ent.Physics == null || !ent.Physics.Enabled)
                {
                    continue;
                }

                if (IsValidCharacter(ent as IMyCharacter))
                {
                    Vector3D characterPosition = ent.PositionComp.WorldVolume.Center + (ent.WorldMatrix.Up * 0.5f);
                    double   rangeSqrd         = (CubeBlock.WorldMatrix.Translation - characterPosition).LengthSquared();
                    if (rangeSqrd < MaximumRangeSqrd && rangeSqrd < likelyTargetDistanceSqrd && // is closest
                        IsPositionInTurretArch(characterPosition) &&                            // is in arch
                        IsTargetVisible(ent, characterPosition))                                // is visible
                    {
                        likelyTarget             = ent;
                        likelyTargetDistanceSqrd = rangeSqrd;
                    }
                }

                if (likelyTarget is IMyCharacter)
                {
                    continue;
                }

                MyCubeGrid grid = ent as MyCubeGrid;
                if (grid != null)
                {
                    if (grid.GridSizeEnum == MyCubeSize.Large)
                    {
                        if (!TargetLargeShips || (grid.IsStatic && !TargetStations))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!TargetSmallShips)
                        {
                            continue;
                        }
                    }

                    bool foundEnemyGrid = false;
                    if (grid.BigOwners.Count == 0 && TargetNeutrals)
                    {
                        foundEnemyGrid = true;
                    }

                    foreach (long owner in grid.BigOwners)
                    {
                        MyRelationsBetweenPlayerAndBlock relation = CubeBlock.GetUserRelationToOwner(owner);

                        if (relation == MyRelationsBetweenPlayerAndBlock.Enemies ||
                            TargetNeutrals && (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership))
                        {
                            foundEnemyGrid = true;
                        }
                    }

                    if (!foundEnemyGrid)
                    {
                        continue;
                    }

                    foreach (MyCubeBlock block in grid.GetFatBlocks())
                    {
                        if (likelyTarget is IMyDecoy)
                        {
                            break;
                        }

                        if (likelyTarget != null && !(block is IMyDecoy))
                        {
                            continue;
                        }

                        MyRelationsBetweenPlayerAndBlock relation = block.GetUserRelationToOwner(CubeBlock.OwnerId);

                        if (relation == MyRelationsBetweenPlayerAndBlock.Enemies ||
                            TargetNeutrals && (relation == MyRelationsBetweenPlayerAndBlock.Neutral || relation == MyRelationsBetweenPlayerAndBlock.NoOwnership))
                        {
                            Vector3D blockPosition = block.WorldMatrix.Translation;
                            double   rangeSqrd     = (CubeBlock.WorldMatrix.Translation - blockPosition).LengthSquared();
                            if (rangeSqrd < MaximumRangeSqrd &&
                                (rangeSqrd < likelyTargetDistanceSqrd || (block is IMyDecoy && !(likelyTarget is IMyDecoy))) &&
                                IsPositionInTurretArch(blockPosition) &&
                                IsTargetVisible(block, blockPosition))
                            {
                                likelyTarget             = block;
                                likelyTargetDistanceSqrd = rangeSqrd;
                            }
                        }
                    }
                }

                if (likelyTarget is IMyCubeBlock)
                {
                    continue;
                }

                if (ent is MyMeteor)
                {
                    if (!TargetMeteors)
                    {
                        continue;
                    }

                    double rangeSqrd = (CubeBlock.WorldMatrix.Translation - ent.WorldMatrix.Translation).LengthSquared();
                    if (rangeSqrd < MaximumRangeSqrd && rangeSqrd < likelyTargetDistanceSqrd)
                    {
                        if (IsTargetVisible(ent, ent.WorldMatrix.Translation))
                        {
                            likelyTarget             = ent;
                            likelyTargetDistanceSqrd = rangeSqrd;
                        }
                    }
                }
            }

            return(likelyTarget);
        }