Exemple #1
0
        /// <summary>
        /// Fills validTarget_*
        /// </summary>
        private bool getValidTargets()
        {
            List <IMyEntity> entitiesInRange = null;
            BoundingSphereD  range           = new BoundingSphereD(turretPosition, myTurretBase.Range + 200);

            MainLock.UsingShared(() => { entitiesInRange = MyAPIGateway.Entities.GetEntitiesInSphere(ref range); });

            validTarget_missile   = new List <IMyEntity>();
            validTarget_meteor    = new List <IMyEntity>();
            validTarget_character = new List <IMyEntity>();
            validTarget_block     = new List <IMyEntity>();
            validTarget_CubeGrid  = new List <IMyEntity>();
            ObstructingGrids      = new List <IMyEntity>();

            if (!possibleTargets())
            {
                myLogger.debugLog("no possible targets", "getValidTargets()", Logger.severity.WARNING);
                return(false);
            }
            //if (EnemyNear)
            //	myLogger.debugLog("enemy near", "getValidTargets()");

            //myLogger.debugLog("initial entity count is " + entitiesInRange.Count, "getValidTargets()");

            foreach (IMyEntity entity in entitiesInRange)
            {
                if (entity.Transparent)                 // part of a ship / station being pasted
                {
                    continue;
                }

                IMyCubeBlock asBlock = entity as IMyCubeBlock;
                if (asBlock != null)
                {
                    if (asBlock.IsWorking && enemyNear() && targetGridFlagSet(asBlock.CubeGrid) && myCubeBlock.canConsiderHostile(asBlock))
                    {
                        validTarget_block.Add(entity);
                    }
                    continue;
                }
                IMyCubeGrid asGrid = entity as IMyCubeGrid;
                if (asGrid != null)
                {
                    if (myCubeBlock.canConsiderHostile(asGrid))
                    {
                        if (targetMoving && enemyNear() && targetGridFlagSet(asGrid))
                        {
                            validTarget_CubeGrid.Add(entity);
                        }
                    }
                    else                     // not hostile
                    {
                        ObstructingGrids.Add(entity);
                    }
                    continue;
                }
                if (entity is IMyMeteor)
                {
                    if (targetMeteors)
                    {
                        validTarget_meteor.Add(entity);
                    }
                    continue;
                }
                IMyPlayer asPlayer = entity as IMyPlayer;
                if (asPlayer != null)
                {
                    if (targetCharacters)
                    {
                        IMyPlayer matchingPlayer = (entity as IMyCharacter).GetPlayer_Safe();
                        if (myCubeBlock.canConsiderHostile(matchingPlayer.PlayerID))
                        {
                            validTarget_character.Add(entity);
                        }
                    }
                    continue;
                }
                if (entity is IMyFloatingObject || entity is IMyVoxelMap)
                {
                    continue;
                }

                // entity could be missile
                if (targetMissiles && enemyNear() && entity.ToString().StartsWith("MyMissile"))
                {
                    validTarget_missile.Add(entity);
                }
            }

            //myLogger.debugLog("target counts = " + validTarget_missile.Count + ", " + validTarget_meteor.Count + ", " + validTarget_character.Count + ", " + validTarget_block.Count, "getValidTargets()");
            return(validTarget_missile.Count > 0 || validTarget_meteor.Count > 0 || validTarget_character.Count > 0 || validTarget_block.Count > 0 || validTarget_CubeGrid.Count > 0);
        }
Exemple #2
0
        private void JamRadar()
        {
            ClearJamming();

            MathHelper.Clamp(PowerRatio_Jammer, 0f, 1f);

            float effectivePowerLevel = PowerLevel_Current * myDefinition.SignalEnhance;

            if (effectivePowerLevel <= 0)
            {
                Log.DebugLog("no power for jamming");
                return;
            }

            //int allowedTargets = MathHelper.Floor(myDefinition.MaxTargets_Jamming * PowerRatio_Jammer);

            //Log.DebugLog("jamming power level: " + effectivePowerLevel + ", allowedTargets: " + allowedTargets, "JamRadar()");

            // collect targets
            Registrar.ForEach((RadarEquipment otherDevice) => {
                if (!otherDevice.IsRadar || !otherDevice.IsWorking)
                {
                    return;
                }

                if (SignalCannotReach(otherDevice.Entity, effectivePowerLevel))
                {
                    return;
                }

                bool notHostile = !RelationsBlock.canConsiderHostile(otherDevice.RelationsBlock);
                if (notHostile && myDefinition.JamIncidental == 0f)
                {
                    Log.DebugLog("cannot jam a friendly: " + otherDevice.Entity.getBestName(), Logger.severity.TRACE);
                    return;
                }

                float distance       = Vector3.Distance(Entity.GetCentre(), otherDevice.Entity.GetCentre());
                float signalStrength = effectivePowerLevel - distance;

                if (signalStrength > 0)
                {
                    if (notHostile)
                    {
                        Log.DebugLog("adding friendly: " + otherDevice.Entity.getBestName(), Logger.severity.TRACE);
                        jamming_friendly.Add(signalStrength, otherDevice);
                    }
                    else
                    {
                        Log.DebugLog("adding enemy: " + otherDevice.Entity.getBestName(), Logger.severity.TRACE);
                        jamming_enemy.Add(signalStrength, otherDevice);
                    }
                }
            });

            // apply jamming
            if (jamming_enemy.Count == 0)
            {
                Log.DebugLog("no targets to jam", Logger.severity.TRACE);
                jamming_friendly.Clear();

                PowerRatio_Jammer = 0f;
                return;
            }

            // Up to MaximumTargets, radars will be deliberately jammed. Others will be incidentally jammed
            deliberateJamming = 0;

            foreach (var pair in jamming_enemy)
            {
                if (deliberateJamming < myDefinition.MaxTargets_Jamming)
                {
                    Log.DebugLog("jamming enemy: " + pair.Value.Entity.getBestName() + ", strength: " + pair.Key, Logger.severity.TRACE);
                    pair.Value.beingJammedBy.Add(this, pair.Key);
                    deliberateJamming++;
                }
                else
                {
                    Log.DebugLog("incidentally jamming enemy: " + pair.Value.Entity.getBestName() + ", strength: " + pair.Key * myDefinition.JamIncidental, Logger.severity.TRACE);
                    pair.Value.beingJammedBy.Add(this, pair.Key * myDefinition.JamIncidental);
                }
            }

            PowerRatio_Jammer = (float)deliberateJamming / (float)myDefinition.MaxTargets_Jamming;
            Log.DebugLog("PowerRatio_Jammer: " + PowerRatio_Jammer, Logger.severity.TRACE);

            foreach (var pair in jamming_friendly)
            {
                Log.DebugLog("incidentally jamming friendly: " + pair.Value.Entity.getBestName() + ", strength: " + pair.Key * myDefinition.JamIncidental, Logger.severity.TRACE);
                pair.Value.beingJammedBy.Add(this, pair.Key * myDefinition.JamIncidental);
            }
        }