Esempio n. 1
0
        protected override void Update100_Options_TargetingThread(TargetingOptions current)
        {
            if (CurrentControl == Control.Engager)
            {
                return;
            }

            //Log.DebugLog("Turret flag: " + current.FlagSet(TargetingFlags.Turret) + ", No motor turret: " + (MyMotorTurret == null) + ", CanControl = " + CanControl, "Update_Options()");
            if (current.FlagSet(TargetingFlags.Turret))
            {
                if (MyMotorTurret == null && CanControl)
                {
                    //Log.DebugLog("MotorTurret is now enabled", "Update_Options()", Logger.severity.INFO);
                    MyMotorTurret = new MotorTurret(CubeBlock, MyMotorTurret_OnStatorChange, 1, WeaponDefinition.RequiredAccuracyRadians);
                }
            }
            else
            {
                if (MyMotorTurret != null)
                {
                    //Log.DebugLog("MotorTurret is now disabled", "Update_Options()", Logger.severity.INFO);
                    MyMotorTurret.Dispose();
                    MyMotorTurret = null;                     // MyMotorTurret will not be updated, so it will be recreated later incase something weird happens to motors
                }
            }
        }
Esempio n. 2
0
		/// <summary>
		/// Fill CanTarget from turret
		/// </summary>
		protected override void Update_Options(TargetingOptions Options)
		{
			//Options. CanTarget = TargetType.None;
			MyObjectBuilder_TurretBase builder = CubeBlock.GetObjectBuilder_Safe() as MyObjectBuilder_TurretBase;
			if (builder.TargetMissiles)
				Options.CanTarget |= TargetType.Missile;
			if (builder.TargetMeteors)
				Options.CanTarget |= TargetType.Meteor;
			if (builder.TargetCharacters)
				Options.CanTarget |= TargetType.Character;
			if (builder.TargetMoving)
				Options.CanTarget |= TargetType.Moving;
			if (builder.TargetLargeGrids)
				Options.CanTarget |= TargetType.LargeGrid;
			if (builder.TargetSmallGrids)
				Options.CanTarget |= TargetType.SmallGrid;
			if (builder.TargetStations)
				Options.CanTarget |= TargetType.Station;

			if (myTurret is Ingame.IMyLargeInteriorTurret && myTurret.BlockDefinition.SubtypeName == "LargeInteriorTurret")
				Options.Flags |= TargetingFlags.Interior;

			Options.TargetingRange = myTurret.Range;

			//myLogger.debugLog("CanTarget = " + Options.CanTarget, "TargetOptionsFromTurret()");
		}
Esempio n. 3
0
		protected override void Update_Options(TargetingOptions current)
		{
			if (ControllingEngager)
				return;

			//myLogger.debugLog("Turret flag: " + current.FlagSet(TargetingFlags.Turret) + ", No motor turret: " + (MyMotorTurret == null) + ", CanControl = " + CanControl, "Update_Options()");
			if (current.FlagSet(TargetingFlags.Turret))
			{
				if (MyMotorTurret == null && CanControl)
				{
					myLogger.debugLog("Turret is now enabled", "Update_Options()", Logger.severity.INFO);
					MyMotorTurret = new MotorTurret(CubeBlock, MyMotorTurret_OnStatorChange);
					AllowedState = State.Targeting;
				}
			}
			else
			{
				if (MyMotorTurret != null)
				{
					myLogger.debugLog("Turret is now disabled", "Update_Options()", Logger.severity.INFO);
					MyMotorTurret = null; // MyMotorTurret will not be updated, so it will be recreated later incase something weird happens to motors
					AllowedState = State.GetOptions;
				}
			}
		}
Esempio n. 4
0
 /// <summary>
 /// Updates instructions if necessary.
 /// </summary>
 public void UpdateInstruction()
 {
     base.UpdateInstructions(null);
     if (!HasInstructions)
     {
         Options = new TargetingOptions();
     }
 }
Esempio n. 5
0
 public LastSeenTarget(LastSeen seen, IMyCubeBlock block = null)
 {
     m_lastSeen           = seen;
     m_block              = block;
     m_lastPostion        = m_lastSeen.LastKnownPosition;
     m_lastPositionUpdate = m_lastSeen.LastSeenAt;
     m_targetType         = TargetingOptions.GetTargetType(seen.Entity);
 }
Esempio n. 6
0
 public void Assimilate(TargetingOptions fallback, TargetType typeFlags, TargetingFlags optFlags, float range, Vector3D targetGolis, long targetEntityId, string[] blocksToTarget)
 {
     this.CanTarget      = typeFlags | fallback.CanTarget;
     this.Flags          = optFlags | fallback.Flags;
     this.TargetingRange = Math.Max(range, fallback.TargetingRange);
     this.TargetGolis    = targetGolis.IsValid() ? targetGolis : fallback.TargetGolis;
     this.TargetEntityId = targetEntityId > 0L ? targetEntityId : fallback.TargetEntityId;
     this.blocksToTarget = blocksToTarget ?? fallback.blocksToTarget;
 }
Esempio n. 7
0
        protected override bool ParseAll(string instructions)
        {
            CurrentIndex = -1;
            InstructFound = false;
            Options = new TargetingOptions();
            Errors.Clear();

            Parse(instructions);

            myLogger.debugLog("leaving, instruct found: " + InstructFound + ", error count: " + Errors.Count);
            return InstructFound || Errors.Count == 0;
        }
Esempio n. 8
0
		private bool OnInstruction(string instructions)
		{
			CurrentIndex = -1;
			InstructFound = false;
			Options = new TargetingOptions();
			Errors.Clear();
			m_monitor.Clear();

			Parse(instructions);

			return InstructFound;
		}
Esempio n. 9
0
        protected override bool ParseAll(string instructions)
        {
            CurrentIndex  = -1;
            InstructFound = false;
            Options       = new TargetingOptions();
            Errors.Clear();

            Parse(instructions);

            Log.TraceLog("leaving, instruct found: " + InstructFound + ", error count: " + Errors.Count);
            return(InstructFound || Errors.Count == 0);
        }
Esempio n. 10
0
        /// <summary>
        /// Updates instructions if necessary.
        /// </summary>
        public void UpdateInstruction()
        {
            if (Block.OwnedNPC())
            {
                if (FallBackInstruct == null)
                {
                    FallBackInstruct = ServerSettings.GetSettingString(ServerSettings.SettingName.sDefaultWeaponCommandsNPC);
                    if (string.IsNullOrWhiteSpace(FallBackInstruct))
                        FallBackInstruct = null;
                }
            }
            else
                FallBackInstruct = null;

            base.UpdateInstructions();
            if (!HasInstructions)
                Options = new TargetingOptions();
        }
Esempio n. 11
0
        public TargetingBase(IMyEntity entity, IMyCubeBlock controllingBlock)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (controllingBlock == null)
            {
                throw new ArgumentNullException("controllingBlock");
            }

            MyEntity  = entity;
            CubeBlock = (IMyUserControllableGun)controllingBlock;

            myTarget        = NoTarget.Instance;
            CurrentTarget   = myTarget;
            Options         = new TargetingOptions();
            entity.OnClose += Entity_OnClose;

            //Log.DebugLog("entity: " + MyEntity.getBestName() + ", block: " + CubeBlock.getBestName(), "TargetingBase()");
        }
Esempio n. 12
0
        public TargetingBase(IMyEntity entity, IMyCubeBlock controllingBlock)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");
            if (controllingBlock == null)
                throw new ArgumentNullException("controllingBlock");

            myLogger = new Logger("TargetingBase", entity);
            MyEntity = entity;
            CubeBlock = controllingBlock;
            FuncBlock = controllingBlock as IMyFunctionalBlock;

            myTarget = NoTarget.Instance;
            CurrentTarget = myTarget;
            Options = new TargetingOptions();
            entity.OnClose += obj => {
                if (WeaponsTargetingProjectile != null)
                    CurrentTarget = null;
            };

            //myLogger.debugLog("entity: " + MyEntity.getBestName() + ", block: " + CubeBlock.getBestName(), "TargetingBase()");
        }
Esempio n. 13
0
        /// <summary>
        /// Fill CanTarget from turret
        /// </summary>
        protected override void Update100_Options_TargetingThread(TargetingOptions Options)
        {
            MyLargeTurretBase turret = (MyLargeTurretBase)CubeBlock;

            SetFlag(turret.TargetMissiles, TargetType.Missile);
            SetFlag(turret.TargetMeteors, TargetType.Meteor);
            SetFlag(turret.TargetCharacters, TargetType.Character);
            SetFlag(turret.TargetLargeGrids, TargetType.LargeGrid);
            SetFlag(turret.TargetSmallGrids, TargetType.SmallGrid);
            SetFlag(turret.TargetStations, TargetType.Station);

            if (turret.TargetNeutrals)
            {
                Options.Flags &= ~TargetingFlags.IgnoreOwnerless;
            }
            else
            {
                Options.Flags |= TargetingFlags.IgnoreOwnerless;
            }

            Options.TargetingRange = myTurret.Range;

            //Log.DebugLog("CanTarget = " + Options.CanTarget, "TargetOptionsFromTurret()");
        }
Esempio n. 14
0
		/// <summary>
		/// Fill CanTarget from turret
		/// </summary>
		protected override void Update100_Options_TargetingThread(TargetingOptions Options)
		{
			if (TP_TargetMissiles.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.Missile;
			if (TP_TargetMeteors.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.Meteor;
			if (TP_TargetCharacters.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.Character;
			if (TP_TargetMoving.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.Moving;
			if (TP_TargetLargeGrids.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.LargeGrid;
			if (TP_TargetSmallGrids.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.SmallGrid;
			if (TP_TargetStations.GetValue(CubeBlock))
				Options.CanTarget |= TargetType.Station;

			if (myTurret.Range > Options.TargetingRange)
				Options.TargetingRange = myTurret.Range;

			if (myTurret is Ingame.IMyLargeInteriorTurret && myTurret.BlockDefinition.SubtypeName == "LargeInteriorTurret")
				Options.Flags |= TargetingFlags.Interior;

			//myLogger.debugLog("CanTarget = " + Options.CanTarget, "TargetOptionsFromTurret()");
		}
Esempio n. 15
0
 public void Assimilate(TargetingOptions fallback, TargetType typeFlags, TargetingFlags optFlags, float range, Vector3D? targetGolis, long? targetEntityId, string[] blocksToTarget)
 {
     this.CanTarget = typeFlags | fallback.CanTarget;
     this.Flags = optFlags | fallback.Flags;
     this.TargetingRange = Math.Max(range, fallback.TargetingRange);
     this.TargetGolis = targetGolis ?? fallback.TargetGolis;
     this.TargetEntityId = targetEntityId ?? fallback.TargetEntityId;
     this.blocksToTarget = blocksToTarget ?? fallback.blocksToTarget;
 }
Esempio n. 16
0
		/// <summary>Invoked on targeting thread, every 100 updates.</summary>
		protected abstract void Update_Options(TargetingOptions current);
Esempio n. 17
0
        /// <summary>
        /// Targets a LastSeen chosen from the given storage, will overrride current target.
        /// </summary>
        /// <param name="storage">NetworkStorage to get LastSeen from.</param>
        public void GetLastSeenTarget(RelayStorage storage, double range)
        {
            if (Globals.UpdateCount < m_nextLastSeenSearch)
            {
                return;
            }
            m_nextLastSeenSearch = Globals.UpdateCount + 100ul;

            if (storage == null)
            {
                //Log.DebugLog("no storage", "GetLastSeenTarget()", Logger.severity.INFO);
                return;
            }

            if (storage.LastSeenCount == 0)
            {
                //Log.DebugLog("no last seen in storage", "GetLastSeenTarget()", Logger.severity.DEBUG);
                return;
            }

            LastSeen     processing;
            IMyCubeBlock targetBlock;

            if (CurrentTarget.Entity != null && storage.TryGetLastSeen(CurrentTarget.Entity.EntityId, out processing) && processing.isRecent())
            {
                LastSeenTarget lst = myTarget as LastSeenTarget;
                if (lst != null && lst.Block != null && !lst.Block.Closed)
                {
                    Log.TraceLog("Updating current last seen target");
                    lst.Update(processing);
                    CurrentTarget = myTarget;
                    return;
                }

                if (ChooseBlock(processing, out targetBlock))
                {
                    Log.TraceLog("Updating current last seen, chose a new block");
                    myTarget      = new LastSeenTarget(processing, targetBlock);
                    CurrentTarget = myTarget;
                    return;
                }
            }

            if (Options.TargetEntityId > 0L)
            {
                if (storage.TryGetLastSeen(Options.TargetEntityId, out processing))
                {
                    Log.TraceLog("Got last seen for entity id");
                    ChooseBlock(processing, out targetBlock);
                    myTarget      = new LastSeenTarget(processing, targetBlock);
                    CurrentTarget = myTarget;
                }
                //else
                //	Log.DebugLog("failed to get last seen from entity id", "GetLastSeenTarget()");
                return;
            }

            processing  = null;
            targetBlock = null;

            if (SEAD)
            {
                throw new NotImplementedException();
                //float highestPowerLevel = 0f;

                //storage.ForEachLastSeen((LastSeen seen) => {
                //	if (seen.isRecent() && Options.CanTargetType(seen.Entity) && CanConsiderHostile(seen.Entity))
                //	{
                //		IMyCubeBlock block;
                //		float powerLevel;
                //		if (RadarEquipment_old.GetRadarEquipment(seen, out block, out powerLevel) && powerLevel > highestPowerLevel)
                //		{
                //			highestPowerLevel = powerLevel;
                //			processing = seen;
                //			targetBlock = block;
                //		}
                //	}
                //});
            }
            else
            {
                Vector3D   myPos       = ProjectilePosition();
                TargetType bestType    = TargetType.LowestPriority;
                double     maxRange    = range * range;
                double     closestDist = maxRange;

                storage.ForEachLastSeen(seen => {
                    TargetType typeOfSeen = TargetingOptions.GetTargetType(seen.Entity);
                    if (typeOfSeen <= bestType && Options.CanTargetType(typeOfSeen) && seen.isRecent() && CanConsiderHostile(seen.Entity))
                    {
                        IMyCubeBlock block;
                        if (!ChooseBlock(seen, out block) || !CheckWeaponsTargeting(typeOfSeen, seen.Entity))
                        {
                            return;
                        }

                        if (typeOfSeen == bestType && targetBlock != null && block == null)
                        {
                            return;
                        }

                        double dist = Vector3D.DistanceSquared(myPos, seen.LastKnownPosition);
                        if ((typeOfSeen < bestType && dist < maxRange) || dist < closestDist)
                        {
                            closestDist = dist;
                            bestType    = typeOfSeen;
                            processing  = seen;
                            targetBlock = block;
                        }
                    }
                });

                Log.DebugLog(() => "chose last seen with entity: " + processing.Entity.nameWithId() + ", block: " + targetBlock.getBestName() + ", type: " + bestType + ", distance squared: " + closestDist + ", position: " + processing.Entity.GetPosition(), condition: processing != null);
                Log.DebugLog("no last seen target found", condition: processing == null);
            }

            if (processing == null)
            {
                if (this is Guided.GuidedMissile)
                {
                    Log.TraceLog("GuidedMissile failed to get LastSeen target, keeping previous");
                    return;
                }

                //Log.DebugLog("failed to get a target from last seen", "GetLastSeenTarget()");
                myTarget      = NoTarget.Instance;
                CurrentTarget = myTarget;
            }
            else
            {
                myTarget      = new LastSeenTarget(processing, targetBlock);
                CurrentTarget = myTarget;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Fill CanTarget from turret
        /// </summary>
        protected override void Update100_Options_TargetingThread(TargetingOptions Options)
        {
            SetFlag(TP_TargetMissiles, TargetType.Missile);
            SetFlag(TP_TargetMeteors, TargetType.Meteor);
            SetFlag(TP_TargetCharacters, TargetType.Character);
            SetFlag(TP_TargetMoving, TargetType.Moving);
            SetFlag(TP_TargetLargeGrids, TargetType.LargeGrid);
            SetFlag(TP_TargetSmallGrids, TargetType.SmallGrid);
            SetFlag(TP_TargetStations, TargetType.Station);

            Options.TargetingRange = myTurret.Range;

            //myLogger.debugLog("CanTarget = " + Options.CanTarget, "TargetOptionsFromTurret()");
        }
Esempio n. 19
0
		private void Update100()
		{
			CheckCustomInfo();

			if (!CanControl)
			{
				myLogger.debugLog("cannot control", "Update100()");
				DefaultTargeting = true;
				Options.Flags = TargetingFlags.None;
				return;
			}

			IsFiringWeapon = TPro_Shoot.GetValue(CubeBlock);
			ClearBlacklist();

			//if (RunTargeting || GuidedLauncher)
			if ((CubeBlock.DisplayNameText.Contains("[") && CubeBlock.DisplayNameText.Contains("]")) || CubeBlock.OwnedNPC())
			{
				Interpreter.UpdateInstruction();
				if (Interpreter.Errors.Count <= InterpreterErrorCount)
				{
					if (Interpreter.Options == null)
						Options = new TargetingOptions();
					else
						Options = Interpreter.Options.Clone();
					InterpreterErrorCount = Interpreter.Errors.Count;
					//ArmsGuiWeapons.UpdateTerm(FuncBlock, Options);
					Update100_Options_TargetingThread(Options);
					myLogger.debugLog("updating Options, Error Count = " + Interpreter.Errors.Count + ", Options: " + Options, "Update100()");
				}
				else
					myLogger.debugLog("not updating Options, Error Count = " + Interpreter.Errors.Count, "Update100()");

				DefaultTargeting = false;
				WriteErrors(Interpreter.Errors);
			}
			else
			{
				myLogger.debugLog("Not running targeting", "Update100()");
				DefaultTargeting = true;
				//ArmsGuiWeapons.UpdateArmsEnabled(FuncBlock, Options);
			}
		}
Esempio n. 20
0
		/// <summary>Invoked on targeting thread, every 100 updates, if targeting is permitted.</summary>
		protected abstract void Update100_Options_TargetingThread(TargetingOptions current);