Example #1
0
        public Orbiter(Mover mover, AllNavigationSettings navSet, string entity)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_navBlock = m_navSet.Settings_Current.NavigationBlock;

            switch (entity.LowerRemoveWhitespace())
            {
                case "asteroid":
                    SetOrbitClosestVoxel(true);
                    CalcFakeOrbitSpeedForce();
                    m_logger.debugLog("Orbiting asteroid: " + OrbitEntity.getBestName(), Logger.severity.INFO);
                    break;
                case "planet":
                    SetOrbitClosestVoxel(false);
                    OrbitSpeed = (float)Math.Sqrt((OrbitEntity as MyPlanet).GetGravityMultiplier(m_navBlock.WorldPosition) * 9.81f * Altitude);
                    if (OrbitSpeed < 1f)
                        CalcFakeOrbitSpeedForce();
                    m_logger.debugLog("Orbiting planet: " + OrbitEntity.getBestName(), Logger.severity.INFO);
                    break;
                default:
                    m_gridFinder = new GridFinder(navSet, mover.Block, entity, mustBeRecent: true);
                    m_logger.debugLog("Searching for a grid: " + entity, Logger.severity.INFO);
                    break;
            }

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
        }
Example #2
0
        public Grinder(Mover mover, AllNavigationSettings navSet, float maxRange)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, () => m_controlBlock.CubeGrid.DisplayName, () => m_stage.ToString());
            this.m_startPostion = m_controlBlock.CubeBlock.GetPosition();
            this.m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;
            m_navGrind = navBlock.Block is Ingame.IMyShipGrinder
                ? new MultiBlock<MyObjectBuilder_ShipGrinder>(navBlock.Block)
                : new MultiBlock<MyObjectBuilder_ShipGrinder>(() => m_mover.Block.CubeGrid);

            if (m_navGrind.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working grinders", Logger.severity.INFO);
                return;
            }

            m_grinderOffset = m_navGrind.Block.GetLengthInDirection(m_navGrind.Block.GetFaceDirection()[0]) * 0.5f + 2.5f;
            if (m_navSet.Settings_Current.DestinationRadius > m_longestDimension)
            {
                m_logger.debugLog("Reducing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + m_longestDimension, Logger.severity.DEBUG);
                m_navSet.Settings_Task_NavRot.DestinationRadius = m_longestDimension;
            }

            this.m_finder = new GridFinder(m_navSet, mover.Block, maxRange);
            this.m_finder.GridCondition = GridCondition;

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
            m_navSet.Settings_Task_NavRot.NavigatorRotator = this;
        }
Example #3
0
        public Hacker(IMyCubeBlock block)
        {
            m_logger = new Logger(GetType().Name, block);
            m_hackBlock = block as IMyLandingGear;

            m_logger.debugLog("created for: " + block.DisplayNameText);
            m_logger.debugLog(!IsHacker(block), "Not a hacker", Logger.severity.FATAL);
        }
Example #4
0
        public Cluster(List<IMyEntity> missiles, IMyEntity launcher)
        {
            m_logger = new Logger(GetType().Name);

            Vector3 centre = Vector3.Zero;
            foreach (IMyEntity miss in missiles)
                centre += miss.GetPosition();
            centre /= missiles.Count;

            float masterDistSq = float.MaxValue;
            foreach (IMyEntity miss in missiles)
            {
                float distSq = Vector3.DistanceSquared(centre, miss.GetPosition());
                if (distSq < masterDistSq)
                {
                    Master = miss;
                    masterDistSq = distSq;
                }
            }

            masterVelocity = Master.Physics.LinearVelocity;

            // master must initially have same orientation as launcher or rail will cause a rotation
            MatrixD masterMatrix = launcher.WorldMatrix;
            masterMatrix.Translation = Master.WorldMatrix.Translation;
            MainLock.UsingShared(() => Master.WorldMatrix = masterMatrix);

            Vector3 masterPos = Master.GetPosition();
            MatrixD masterInv = Master.WorldMatrixNormalizedInv;
            float Furthest = 0f;
            Slaves = new List<IMyEntity>(missiles.Count - 1);
            SlaveOffsets = new List<Vector3>(missiles.Count - 1);
            foreach (IMyEntity miss in missiles)
            {
                if (miss == Master)
                    continue;
                Slaves.Add(miss);
                SlaveOffsets.Add(Vector3.Transform(miss.GetPosition(), masterInv));
                float distSq = Vector3.DistanceSquared(miss.GetPosition(), masterPos);
                m_logger.debugLog("slave: " + miss + ", offset: " + SlaveOffsets[SlaveOffsets.Count - 1], Logger.severity.TRACE);
                if (distSq > Furthest)
                    Furthest = distSq;
            }
            Furthest = (float)Math.Sqrt(Furthest);
            for (int i = 0; i < SlaveOffsets.Count; i++)
                SlaveOffsets[i] = SlaveOffsets[i] / Furthest;

            MinOffMult = Furthest * 2f;
            OffsetMulti = Furthest * 1e6f; // looks pretty
            m_logger.debugLog("created new cluster, missiles: " + missiles.Count + ", slaves: " + Slaves.Count + ", offsets: " + SlaveOffsets.Count + ", furthest: " + Furthest, Logger.severity.DEBUG);
        }
Example #5
0
        private Ammo(MyAmmoMagazineDefinition ammoMagDef)
        {
            MyAmmoDefinition ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagDef.AmmoDefinitionId);
            this.myLogger = new Logger("Ammo", () => ammoMagDef.Id.ToString(), () => ammoDef.Id.ToString());

            this.AmmoDefinition = ammoDef;
            this.MissileDefinition = AmmoDefinition as MyMissileAmmoDefinition;
            this.MagazineDefinition = ammoMagDef;

            if (MissileDefinition != null && !MissileDefinition.MissileSkipAcceleration)
            {
                this.TimeToMaxSpeed = (MissileDefinition.DesiredSpeed - MissileDefinition.MissileInitialSpeed) / MissileDefinition.MissileAcceleration;
                this.DistanceToMaxSpeed = (MissileDefinition.DesiredSpeed + MissileDefinition.MissileInitialSpeed) / 2 * TimeToMaxSpeed;
            }
            else
            {
                this.TimeToMaxSpeed = 0;
                this.DistanceToMaxSpeed = 0;
            }

            Description = AmmoDescription.CreateFrom(AmmoDefinition);

            if (Description == null)
                return;

            if (Description.ClusterCooldown > 0f)
            {
                myLogger.debugLog("Is a cluster missile");
                IsCluster = true;
            }
            if (!string.IsNullOrWhiteSpace(Description.Radar))
            {
                try
                {
                    RadarDefinition = new RadarEquipment.Definition();
                    XML_Amendments<RadarEquipment.Definition> ammender = new XML_Amendments<RadarEquipment.Definition>(RadarDefinition);
                    ammender.primarySeparator = new char[] { ',' };
                    ammender.AmendAll(Description.Radar, true);
                    RadarDefinition = ammender.Deserialize();
                    myLogger.debugLog("Loaded description for radar", Logger.severity.DEBUG);
                }
                catch (Exception ex)
                {
                    Logger.debugNotify("Failed to load radar description for an ammo", 10000, Logger.severity.ERROR);
                    myLogger.alwaysLog("Failed to load radar description for an ammo", Logger.severity.ERROR);
                    myLogger.alwaysLog("Exception: " + ex, Logger.severity.ERROR);
                    RadarDefinition = null;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Creates a GridFinder to find an enemy grid based on distance.
        /// </summary>
        public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, float maxRange = 0f)
        {
            this.m_logger = new Logger(GetType().Name, controller.CubeBlock);

            m_logger.debugLog(navSet == null, "navSet == null", Logger.severity.FATAL);
            m_logger.debugLog(controller == null, "controller == null", Logger.severity.FATAL);
            m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", Logger.severity.FATAL);

            this.m_controlBlock = controller;
            //this.m_enemies = new List<LastSeen>();

            this.MaximumRange = maxRange;
            this.m_navSet = navSet;
            this.m_mustBeRecent = true;
        }
		public GuidedMissileLauncher(WeaponTargeting weapon)
		{
			m_weaponTarget = weapon;
			FuncBlock = CubeBlock as IMyFunctionalBlock;
			myLogger = new Logger("GuidedMissileLauncher", CubeBlock);

			var defn = CubeBlock.GetCubeBlockDefinition();

			Vector3[] points = new Vector3[3];
			points[0] = CubeBlock.LocalAABB.Min;
			points[1] = CubeBlock.LocalAABB.Max;
			points[2] = CubeBlock.LocalAABB.Min + Vector3.Up * CubeBlock.GetCubeBlockDefinition().Size.Y * CubeBlock.CubeGrid.GridSize;

			MissileSpawnBox = BoundingBox.CreateFromPoints(points);
			if (m_weaponTarget.myTurret != null)
			{
				myLogger.debugLog("original box: " + MissileSpawnBox, "GuidedMissileLauncher()");
				MissileSpawnBox.Inflate(CubeBlock.CubeGrid.GridSize * 2f);
			}

			myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()");

			myInventory = (CubeBlock as Interfaces.IMyInventoryOwner).GetInventory(0);

			m_weaponTarget.AllowedState = WeaponTargeting.State.GetOptions;
			Registrar.Add(weapon.FuncBlock, this);
		}
Example #8
0
        public RelayStorage(RelayNode primary)
        {
            this.m_logger = new Logger(GetType().Name, () => primary.LoggingName);
            this.PrimaryNode = primary;

            m_logger.debugLog("Created", Logger.severity.DEBUG);
        }
Example #9
0
		public Turret(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("Turret", block);
			Registrar.Add(CubeBlock, this);

			if (TP_TargetMissiles == null)
			{
				myLogger.debugLog("Filling Terminal Properties", "Turret()", Logger.severity.INFO);
				IMyTerminalBlock term = CubeBlock as IMyTerminalBlock;
				TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool();
				TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool();
				TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool();
				TP_TargetMoving = term.GetProperty("TargetMoving").AsBool();
				TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool();
				TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool();
				TP_TargetStations = term.GetProperty("TargetStations").AsBool();
			}

			// definition limits
			MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition;

			if (definition == null)
				throw new NullReferenceException("definition");

			minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f);
			maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees);
			minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees);
			maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees);

			Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360;

			// speeds are in rads per ms (from S.E. source)
			speedElevation = definition.ElevationSpeed * 100f / 6f;
			speedAzimuth = definition.RotationSpeed * 100f / 6f;

			setElevation = myTurret.Elevation;
			setAzimuth = myTurret.Azimuth;

			//if (CubeBlock.OwnedNPC() && s_npcHasOpts && ArmsGuiWeapons.GetPropertyValue(myTurret, ref ArmsGuiWeapons.TP_ARMS_Control))
			//	myTurret.ApplyAction("ARMS_Control");
			//if (myTurret is Ingame.IMyLargeInteriorTurret && myTurret.BlockDefinition.SubtypeName == "LargeInteriorTurret" && !ArmsGuiWeapons.GetPropertyValue(myTurret, ref ArmsGuiWeapons.TP_Interior_Turret))
			//	myTurret.ApplyAction("Interior_Turret");

			myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()");
			myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()");
		}
Example #10
0
        private AttachedGrid(IMyCubeGrid grid)
        {
            this.myLogger = new Logger("AttachedGrid", () => grid.DisplayName);
            this.myGrid = grid;
            Registrar.Add(grid, this);

            myLogger.debugLog("Initialized");
        }
Example #11
0
		public Beacon(IMyCubeBlock block)
		{
			CubeBlock = block;
			myBeacon = block as Ingame.IMyBeacon;
			myLogger = new Logger("Beacon", CubeBlock);

			myLogger.debugLog("init as beacon: " + CubeBlock.BlockDefinition.SubtypeName, "Init()", Logger.severity.TRACE);
		}
Example #12
0
		/// <summary>
		/// Creates a GridFinder to find an enemy grid based on distance.
		/// </summary>
		public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, float maxRange = 0f)
		{
			this.m_logger = new Logger(GetType().Name + " enemy", controller.CubeBlock);

			m_logger.debugLog(navSet == null, "navSet == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller == null, "controller == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", "GridFinder()", Logger.severity.FATAL);

			this.m_controlBlock = controller;
			this.m_enemies = new List<LastSeen>();

			if (!Registrar.TryGetValue(controller.CubeBlock.EntityId, out this.m_controller))
				throw new NullReferenceException("ShipControllerBlock is not a ShipController");

			this.MaximumRange = maxRange;
			this.m_navSet = navSet;
			this.m_mustBeRecent = true;
		}
Example #13
0
		public FixedWeapon(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("FixedWeapon", block);
			Registrar.Add(CubeBlock, this);
			myLogger.debugLog("Initialized", "FixedWeapon()");

			AllowFighterControl = WeaponDescription.GetFor(block).AllowFighterControl;
		}
Example #14
0
		public Cluster(List<IMyEntity> missiles)
		{
			m_logger = new Logger(GetType().Name);

			Vector3 centre = Vector3.Zero;
			foreach (IMyEntity miss in missiles)
				centre += miss.GetPosition();
			centre /= missiles.Count;

			float masterDistSq = float.MaxValue;
			foreach (IMyEntity miss in missiles)
			{
				float distSq = Vector3.DistanceSquared(centre, miss.GetPosition());
				if (distSq < masterDistSq)
				{
					Master = miss;
					masterDistSq = distSq;
				}
			}

			Vector3 masterPos = Master.GetPosition();
			MatrixD masterInv = Master.WorldMatrixNormalizedInv;
			float Furthest = 0f;
			Slaves = new List<IMyEntity>(missiles.Count - 1);
			SlaveOffsets = new List<Vector3>(missiles.Count - 1);
			foreach (IMyEntity miss in missiles)
			{
				if (miss == Master)
					continue;
				Slaves.Add(miss);
				SlaveOffsets.Add(Vector3.Transform(miss.GetPosition(), masterInv));
				float distSq = Vector3.DistanceSquared(miss.GetPosition(), masterPos);
				m_logger.debugLog("slave: " + miss + ", offset: " + SlaveOffsets[SlaveOffsets.Count - 1], "Cluster()", Logger.severity.TRACE);
				if (distSq > Furthest)
					Furthest = distSq;
			}
			Furthest = (float)Math.Sqrt(Furthest);
			for (int i = 0; i < SlaveOffsets.Count; i++)
				SlaveOffsets[i] = SlaveOffsets[i] / Furthest;

			OffsetMulti = 1f;
			m_logger.debugLog("created new cluster, missiles: " + missiles.Count + ", slaves: " + Slaves.Count + ", offsets: " + SlaveOffsets.Count + ", furthest: " + Furthest, "Cluster()", Logger.severity.DEBUG);
		}
Example #15
0
			public VoxelData(Ingame.IMyOreDetector oreDetector, IMyVoxelBase voxel, float maxRange)
			{
				this.m_logger = new Logger(GetType().Name, () => oreDetector.CubeGrid.DisplayName, () => oreDetector.DisplayNameText, () => voxel.ToString());
				this.m_oreDetector = oreDetector;
				this.m_voxel = voxel;
				this.m_storage.Resize(new Vector3I(QUERY_STEP, QUERY_STEP, QUERY_STEP));
				this.m_maxRange = maxRange;

				m_logger.debugLog("Created for voxel at " + voxel.PositionLeftBottomCorner, "VoxelData()");
			}
Example #16
0
        /// <summary>
        /// Creates a GridFinder to find a friendly grid based on its name.
        /// </summary>
        public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, string targetGrid, string targetBlock = null,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent, bool mustBeRecent = false)
        {
            this.m_logger = new Logger(GetType().Name, controller.CubeBlock);

            m_logger.debugLog(navSet == null, "navSet == null", Logger.severity.FATAL);
            m_logger.debugLog(controller == null, "controller == null", Logger.severity.FATAL);
            m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", Logger.severity.FATAL);
            m_logger.debugLog(targetGrid == null, "targetGrid == null", Logger.severity.FATAL);

            this.m_targetGridName = targetGrid.LowerRemoveWhitespace();
            if (targetBlock != null)
                this.m_targetBlockName = targetBlock.LowerRemoveWhitespace();
            this.m_controlBlock = controller;
            this.m_allowedAttachment = allowedAttachment;
            this.MaximumRange = float.MaxValue;
            this.m_navSet = navSet;
            this.m_mustBeRecent = mustBeRecent;
        }
Example #17
0
        public MinerVoxel(Mover mover, AllNavigationSettings navSet, byte[] OreTargets)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_state.ToString());
            this.OreTargets = OreTargets;

            // get blocks
            var cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            var allDrills = cache.GetBlocksOfType(typeof(MyObjectBuilder_Drill));
            if (allDrills == null || allDrills.Count == 0)
            {
                m_logger.debugLog("No Drills!", "MinerVoxel()", Logger.severity.INFO);
                return;
            }
            if (MyAPIGateway.Session.CreativeMode)
                foreach (IMyShipDrill drill in allDrills)
                    if (drill.UseConveyorSystem)
                        drill.ApplyAction("UseConveyor");

            // if a drill has been chosen by player, use it
            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;
            if (navBlock.Block is IMyShipDrill)
                m_navDrill = new MultiBlock<MyObjectBuilder_Drill>(navBlock.Block);
            else
                m_navDrill = new MultiBlock<MyObjectBuilder_Drill>(m_mover.Block.CubeGrid);

            if (m_navDrill.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working drills", "MinerVoxel()", Logger.severity.INFO);
                return;
            }

            var detectors = cache.GetBlocksOfType(typeof(MyObjectBuilder_OreDetector));
            if (detectors != null)
            {
                if (!Registrar.TryGetValue(detectors[0].EntityId, out m_oreDetector))
                    m_logger.debugLog("failed to get ore detector from block", "MinerVoxel()", Logger.severity.FATAL);
            }
            else
            {
                m_logger.debugLog("No ore detector, no ore for you", "MinerVoxel()", Logger.severity.INFO);
                return;
            }

            m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();
            if (m_navSet.Settings_Current.DestinationRadius > m_longestDimension)
            {
                m_logger.debugLog("Reducing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + m_longestDimension, "MinerVoxel()", Logger.severity.DEBUG);
                m_navSet.Settings_Task_NavRot.DestinationRadius = m_longestDimension;
            }

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;
            m_state = State.GetTarget;
        }
Example #18
0
		/// <summary>
		/// Creates a GridFinder to find a friendly grid based on its name.
		/// </summary>
		public GridFinder(AllNavigationSettings navSet, ShipControllerBlock controller, string targetGrid, string targetBlock = null,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent)
		{
			this.m_logger = new Logger(GetType().Name + " friendly", controller.CubeBlock);

			m_logger.debugLog(navSet == null, "navSet == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller == null, "controller == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(controller.CubeBlock == null, "controller.CubeBlock == null", "GridFinder()", Logger.severity.FATAL);
			m_logger.debugLog(targetGrid == null, "targetGrid == null", "GridFinder()", Logger.severity.FATAL);

			if (!Registrar.TryGetValue(controller.CubeBlock.EntityId, out this.m_controller))
				throw new NullReferenceException("ShipControllerBlock is not a ShipController");
			this.m_targetGridName = targetGrid.LowerRemoveWhitespace();
			if (targetBlock != null)
				this.m_targetBlockName = targetBlock.LowerRemoveWhitespace();
			this.m_controlBlock = controller;
			this.m_allowedAttachment = allowedAttachment;
			this.MaximumRange = float.MaxValue;
			this.m_navSet = navSet;
		}
Example #19
0
		protected AttachableBlockBase(IMyCubeBlock block, AttachedGrid.AttachmentKind kind)
		{
			myLogger = new Logger("AttachableBlockBase", block);
			AttachmentKind = kind;
			myBlock = block;

			myLogger.debugLog("Created for: " + block.DisplayNameText, "AttachableBlockBase()");

			block.OnClose += Detach;
			Registrar.Add(this.myBlock, this);
		}
Example #20
0
        public MinerVoxel(Mover mover, AllNavigationSettings navSet, byte[] OreTargets)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_state.ToString());
            this.OreTargets = OreTargets;

            // get blocks
            var cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            var allDrills = cache.GetBlocksOfType(typeof(MyObjectBuilder_Drill));
            if (allDrills == null || allDrills.Count == 0)
            {
                m_logger.debugLog("No Drills!", Logger.severity.INFO);
                return;
            }

            // if a drill has been chosen by player, use it
            PseudoBlock navBlock = m_navSet.Settings_Current.NavigationBlock;
            if (navBlock.Block is IMyShipDrill)
                m_navDrill = new MultiBlock<MyObjectBuilder_Drill>(navBlock.Block);
            else
                m_navDrill = new MultiBlock<MyObjectBuilder_Drill>(() => m_mover.Block.CubeGrid);

            if (m_navDrill.FunctionalBlocks == 0)
            {
                m_logger.debugLog("no working drills", Logger.severity.INFO);
                return;
            }

            m_longestDimension = m_controlBlock.CubeGrid.GetLongestDim();

            m_navSet.Settings_Task_NavRot.NavigatorMover = this;

            // check for currently touching voxel, usually resume from save
            BoundingSphereD nearby = new BoundingSphereD(m_navDrill.WorldPosition, m_longestDimension * 4d);
            List<MyVoxelBase> nearbyVoxels = new List<MyVoxelBase>();
            MyGamePruningStructure.GetAllVoxelMapsInSphere(ref nearby, nearbyVoxels);

            foreach (MyVoxelBase voxel in nearbyVoxels)
                // skip planet physics, ship should be near planet as well
                if (voxel is IMyVoxelMap || voxel is MyPlanet)
                {
                    m_logger.debugLog("near a voxel, escape first", Logger.severity.DEBUG);
                    m_targetVoxel = voxel;
                    m_state = State.Mining_Escape;
                    var setLevel = m_navSet.GetSettingsLevel(AllNavigationSettings.SettingsLevelName.NavMove);
                    setLevel.IgnoreAsteroid = true;
                    setLevel.SpeedTarget = 1f;
                    return;
                }

            m_state = State.GetTarget;
        }
Example #21
0
        public Shopper(AllNavigationSettings navSet, IMyCubeGrid grid, Dictionary<string, int> shopList)
        {
            this.m_logger = new Logger(GetType().Name, grid);
            this.m_navSet = navSet;
            this.m_shoppingList = shopList;
            this.m_grid = grid;

            this.m_currentTask = Return;

            foreach (var pair in m_shoppingList)
                m_logger.debugLog("Item: " + pair.Key + ", amount: " + pair.Value);
        }
Example #22
0
        public Turret(IMyCubeBlock block)
            : base(block)
        {
            myLogger = new Logger("Turret", block);
            Registrar.Add(CubeBlock, this);

            if (TP_TargetMissiles == null)
            {
                myLogger.debugLog("Filling Terminal Properties", Logger.severity.INFO);
                IMyTerminalBlock term = CubeBlock as IMyTerminalBlock;
                TP_TargetMissiles = term.GetProperty("TargetMissiles").AsBool();
                TP_TargetMeteors = term.GetProperty("TargetMeteors").AsBool();
                TP_TargetCharacters = term.GetProperty("TargetCharacters").AsBool();
                TP_TargetMoving = term.GetProperty("TargetMoving").AsBool();
                TP_TargetLargeGrids = term.GetProperty("TargetLargeShips").AsBool();
                TP_TargetSmallGrids = term.GetProperty("TargetSmallShips").AsBool();
                TP_TargetStations = term.GetProperty("TargetStations").AsBool();
            }

            // definition limits
            MyLargeTurretBaseDefinition definition = CubeBlock.GetCubeBlockDefinition() as MyLargeTurretBaseDefinition;

            if (definition == null)
                throw new NullReferenceException("definition");

            minElevation = Math.Max(MathHelper.ToRadians(definition.MinElevationDegrees), -0.6f);
            maxElevation = MathHelper.ToRadians(definition.MaxElevationDegrees);
            minAzimuth = MathHelper.ToRadians(definition.MinAzimuthDegrees);
            maxAzimuth = MathHelper.ToRadians(definition.MaxAzimuthDegrees);

            Can360 = Math.Abs(definition.MaxAzimuthDegrees - definition.MinAzimuthDegrees) >= 360;

            // speeds are in rads per ms (from S.E. source)
            speedElevation = definition.ElevationSpeed * 100f / 6f;
            speedAzimuth = definition.RotationSpeed * 100f / 6f;

            setElevation = myTurret.Elevation;
            setAzimuth = myTurret.Azimuth;

            // subparts for turrets form a chain
            var subparts = ((MyCubeBlock)CubeBlock).Subparts;
            while (subparts.Count != 0)
            {
                m_barrel = subparts.FirstPair().Value;
                subparts = m_barrel.Subparts;
            }

            //myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()");
            //myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()");
        }
        public GuidedMissileLauncher(FixedWeapon weapon)
        {
            myFixed = weapon;
            FuncBlock = CubeBlock as IMyFunctionalBlock;
            myLogger = new Logger("GuidedMissileLauncher", CubeBlock);

            MissileSpawnBox = CubeBlock.LocalAABB;

            // might need this again for shorter range missiles
            //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Min + CubeBlock.LocalMatrix.Forward * 10f);
            //MissileSpawnBox = MissileSpawnBox.Include(MissileSpawnBox.Max + CubeBlock.LocalMatrix.Forward * 10f);

            myLogger.debugLog("MissileSpawnBox: " + MissileSpawnBox, "GuidedMissileLauncher()");

            myInventory = (CubeBlock as Interfaces.IMyInventoryOwner).GetInventory(0);

            myFixed.AllowedState = WeaponTargeting.State.GetOptions;
            Registrar.Add(weapon.FuncBlock, this);
        }
Example #24
0
        public UnLander(Mover mover, AllNavigationSettings navSet, PseudoBlock unlandBlock = null)
            : base(mover, navSet)
        {
            this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock);
            this.m_unlandBlock = unlandBlock ?? m_navSet.Settings_Current.LandingBlock ?? m_navSet.LastLandingBlock;

            if (this.m_unlandBlock == null)
            {
                m_logger.debugLog("No unland block", "UnLander()", Logger.severity.INFO);
                return;
            }
            m_logger.debugLog(this.m_unlandBlock.Block == null, "Unland block is missing Block property", "UnLander()", Logger.severity.FATAL);

            IMyLandingGear asGear = m_unlandBlock.Block as IMyLandingGear;
            if (asGear != null)
            {
                m_attachedEntity = asGear.GetAttachedEntity();
                m_logger.debugLog("m_attachedEntity: " + m_attachedEntity, "UnLander()");
                if (m_attachedEntity == null)
                {
                    m_logger.debugLog("Not attached: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                    return;
                }
                m_logger.debugLog("Got attached entity from Landing Gear : " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.DEBUG);
            }
            else
            {
                Ingame.IMyShipConnector asConn = m_unlandBlock.Block as Ingame.IMyShipConnector;
                if (asConn != null)
                {
                    m_logger.debugLog("connector", "UnLander()");
                    Ingame.IMyShipConnector other = asConn.OtherConnector;
                    if (other == null)
                    {
                        m_logger.debugLog("Not connected: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                        return;
                    }
                    m_logger.debugLog("Got attached connector from Connector : " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.DEBUG);
                    m_attachedEntity = other.CubeGrid;
                }
                else
                {
                    m_logger.debugLog("Cannot unland block: " + m_unlandBlock.Block.DisplayNameText, "UnLander()", Logger.severity.INFO);
                    return;
                }
            }

            IMyCubeBlock block = this.m_unlandBlock.Block;
            if (block is IMyLandingGear)
                MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                    (block as IMyFunctionalBlock).RequestEnable(true);
                    if ((block.GetObjectBuilderCubeBlock() as MyObjectBuilder_LandingGear).AutoLock)
                        asGear.ApplyAction("Autolock");
                }, m_logger);

            Vector3D attachOffset = m_unlandBlock.Block.GetPosition() - m_attachedEntity.GetPosition();
            Vector3 leaveDirection = m_unlandBlock.WorldMatrix.Backward;
            m_detatchedOffset = attachOffset + leaveDirection * 20f;
            m_logger.debugLog("m_detatchedOffset: " + m_detatchedOffset, "UnLander()", Logger.severity.DEBUG);

            m_navSet.Settings_Task_NavMove.NavigatorMover = this;
            m_navSet.Settings_Task_NavMove.NavigatorRotator = this;
        }
Example #25
0
		public Pathfinder(IMyCubeGrid grid, AllNavigationSettings navSet, Mover mover)
		{
			grid.throwIfNull_argument("grid");
			m_grid = grid;
			m_logger = new Logger("Pathfinder", () => grid.DisplayName, () => m_pathState.ToString(), () => m_rotateState.ToString());
			m_pathChecker = new PathChecker(grid);
			m_rotateChecker = new RotateChecker(grid);
			m_navSet = navSet;
			m_mover = mover;
			m_logger.debugLog("Initialized, grid: " + grid.DisplayName, "Pathfinder()");
		}
Example #26
0
		/// <summary>
		/// Creates a missile with homing and target finding capabilities.
		/// </summary>
		public GuidedMissile(IMyEntity missile, IMyCubeBlock firedBy, TargetingOptions opt, Ammo ammo, LastSeen initialTarget = null, bool isSlave = false)
			: base(missile, firedBy)
		{
			myLogger = new Logger("GuidedMissile", () => missile.getBestName(), () => m_stage.ToString());
			myAmmo = ammo;
			myDescr = ammo.Description;
			if (ammo.Description.HasAntenna)
				myAntenna = new MissileAntenna(missile);
			TryHard = true;

			AllGuidedMissiles.Add(this);
			AddMissileOwner(MyEntity, CubeBlock.OwnerId);
			MyEntity.OnClose += MyEntity_OnClose;

			if (myAmmo.IsCluster && !isSlave)
				myCluster = new Cluster(myAmmo.MagazineDefinition.Capacity - 1);
			accelerationPerUpdate = (myDescr.Acceleration + myAmmo.MissileDefinition.MissileAcceleration) / 60f;
			addSpeedPerUpdate = myDescr.Acceleration / 60f;

			Options = opt;
			Options.TargetingRange = ammo.Description.TargetRange;
			myTargetSeen = initialTarget;

			myLogger.debugLog("Options: " + Options, "GuidedMissile()");
			//myLogger.debugLog("AmmoDescription: \n" + MyAPIGateway.Utilities.SerializeToXML<Ammo.AmmoDescription>(myDescr), "GuidedMissile()");
		}
Example #27
0
		public FlyToGrid(Mover mover, AllNavigationSettings navSet, string targetGrid,
			AttachedGrid.AttachmentKind allowedAttachment = AttachedGrid.AttachmentKind.Permanent)
			: base(mover, navSet)
		{
			this.m_logger = new Logger(GetType().Name, m_controlBlock.CubeBlock, () => m_landingState.ToString());
			this.m_targetBlock = m_navSet.Settings_Current.DestinationBlock;
			string blockName = m_targetBlock == null ? null : m_targetBlock.BlockName;
			this.m_gridFinder = new GridFinder(m_navSet, m_mover.Block, targetGrid, blockName, allowedAttachment);
			this.m_contBlock = m_navSet.Settings_Commands.NavigationBlock;

			PseudoBlock landingBlock = m_navSet.Settings_Current.LandingBlock;
			m_navBlock = landingBlock ?? m_navSet.Settings_Current.NavigationBlock;

			if (landingBlock != null)
			{
				if (landingBlock.Block is IMyFunctionalBlock)
					m_landingState = LandingState.Approach;
				else
				{
					m_logger.debugLog("landingBlock is not functional, player error? : " + landingBlock.Block.DisplayNameText, "FlyToGrid()", Logger.severity.INFO);
					m_landingState = LandingState.None;
				}

				if (m_targetBlock == null)
				{
					if (!(landingBlock.Block is IMyLandingGear))
					{
						m_logger.debugLog("cannot land block without a target", "FlyToGrid()", Logger.severity.INFO);
						m_landingState = LandingState.None;
					}
					else
					{
						m_logger.debugLog("golden retriever mode enabled", "FlyToGrid()", Logger.severity.INFO);
						m_landGearWithoutTargetBlock = true;
					}
				}
				else if (landingBlock.Block is Ingame.IMyShipConnector)
				{
					m_gridFinder.BlockCondition = block => {
						Ingame.IMyShipConnector connector = block as Ingame.IMyShipConnector;
						return connector != null && (!connector.IsConnected || connector.OtherConnector == m_navBlock.Block);
					};
					m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.GetFaceDirection()[0]);
				}
				else if (landingBlock.Block is IMyShipMergeBlock)
				{
					m_gridFinder.BlockCondition = block => block is IMyShipMergeBlock;
					m_landingDirection = m_targetBlock.Forward ?? Base6Directions.GetFlippedDirection(landingBlock.Block.GetFaceDirection()[0]);
					(landingBlock.Block as IMyShipMergeBlock).BeforeMerge += MergeBlock_BeforeMerge;
				}
				else if (m_targetBlock.Forward.HasValue)
					m_landingDirection = m_targetBlock.Forward.Value;
				else
				{
					m_logger.debugLog("Player failed to specify landing direction and it could not be determined.", "FlyToGrid()", Logger.severity.INFO);
					m_landingState = LandingState.None;
				}

				if (m_landingState != LandingState.None)
				{
					float minDestRadius = m_controlBlock.CubeGrid.GetLongestDim() * 5f;
					if (m_navSet.Settings_Current.DestinationRadius < minDestRadius)
					{
						m_logger.debugLog("Increasing DestinationRadius from " + m_navSet.Settings_Current.DestinationRadius + " to " + minDestRadius, "FlyToGrid()", Logger.severity.DEBUG);
						m_navSet.Settings_Task_NavRot.DestinationRadius = minDestRadius;
					}

					new UnLander(mover, navSet, landingBlock);

					m_landingHalfSize = landingBlock.Block.GetLengthInDirection(landingBlock.Block.LocalMatrix.GetClosestDirection(landingBlock.LocalMatrix.Forward)) * 0.5f;
					m_logger.debugLog("m_landing direction: " + m_landingDirection + ", m_landingBlockSize: " + m_landingHalfSize, "FlyToGrid()");
				}
			}

			m_navSet.Settings_Task_NavMove.NavigatorMover = this;
		}
Example #28
0
        public void Start(Builder_Disruption builder)
        {
            this.m_logger = new Logger(GetType().Name);
            this.m_effectOwner = builder.EffectOwner;

            for (int index = 0; index < builder.Affected_Blocks.Length; index++)
            {
                IMyEntity entity;
                if (!MyAPIGateway.Entities.TryGetEntityById(builder.Affected_Blocks[index], out entity) || !(entity is IMyCubeBlock))
                {
                    m_logger.debugLog("Block is not in world: " + builder.Affected_Blocks[index], Logger.severity.WARNING);
                    continue;
                }
                IMyCubeBlock block  = (IMyCubeBlock)entity;
                StartEffect(block);
                // save/load will change ownership from long.MinValue to 0L
                ((MyCubeBlock)block).ChangeOwner(m_effectOwner, MyOwnershipShareModeEnum.Faction);
                m_affected.Add(block, builder.Affected_Owner[index]);

                block.SetDamageEffect(true);
            }

            if (m_affected.Count != 0)
            {
                m_logger.debugLog("Added old effect from builder");
                m_expire = builder.Expires.ToTimeSpan();
                UpdateManager.Register(UpdateFrequency, UpdateEffect);
                AllDisruptions.Add(this);
            }
        }
Example #29
0
        /// <summary>
        /// Adds a disruption effect to a grid.
        /// </summary>
        /// <param name="grid">Grid that will be disrupted</param>
        /// <param name="duration">Duration of disruption</param>
        /// <param name="strength">Strength of disruption (in hackyness)</param>
        /// <param name="effectOwner">The owner of the disruption.</param>
        public void Start(IMyCubeGrid grid, TimeSpan duration, ref float strength, long effectOwner)
        {
            this.m_logger = new Logger(GetType().Name, () => grid.DisplayName);

            if (strength < MinCost)
            {
                m_logger.debugLog("strength: " + strength + ", below minimum: " + MinCost);
                return;
            }

            CubeGridCache cache = CubeGridCache.GetFor(grid);
            float applied = 0;
            if (!EffectOwnerCanAccess)
                effectOwner = long.MinValue;
            m_effectOwner = effectOwner;
            foreach (MyObjectBuilderType type in BlocksAffected)
            {
                var blockGroup = cache.GetBlocksOfType(type);
                if (blockGroup != null && blockGroup.Count != 0)
                {
                    foreach (IMyCubeBlock block in blockGroup.OrderBy(OrderBy))
                    {
                        if (!block.IsWorking || m_allAffected.Contains(block))
                        {
                            m_logger.debugLog("cannot disrupt: " + block);
                            continue;
                        }
                        float cost = BlockCost(block);
                        if (cost > strength)
                        {
                            m_logger.debugLog("cannot disrupt block: " + block + ", cost: " + cost + " is greater than strength available: " + strength);
                            continue;
                        }

                        StartEffect(block);
                        m_logger.debugLog("disrupting: " + block + ", cost: " + cost + ", remaining strength: " + strength);
                        strength -= cost;
                        applied += cost;
                        MyCubeBlock cubeBlock = block as MyCubeBlock;
                        MyIDModule idMod = new MyIDModule() { Owner = cubeBlock.IDModule.Owner, ShareMode = cubeBlock.IDModule.ShareMode };
                        m_affected.Add(block, idMod);
                        m_allAffected.Add(block);

                        block.SetDamageEffect(true);
                        cubeBlock.ChangeOwner(effectOwner, MyOwnershipShareModeEnum.Faction);

                        if (strength < MinCost)
                            goto FinishedBlocks;
                    }
                }
                else
                    m_logger.debugLog("no blocks of type: " + type);
            }
            FinishedBlocks:
            if (m_affected.Count != 0)
            {
                m_logger.debugLog("Added new effect, strength: " + applied);
                m_expire = Globals.ElapsedTime.Add(duration);

                UpdateManager.Register(UpdateFrequency, UpdateEffect); // don't unregister on grid close, blocks can still be valid
                AllDisruptions.Add(this);
            }
        }
Example #30
0
		public EnemyFinder(Mover mover, AllNavigationSettings navSet)
			: base(navSet, mover.Block)
		{
			this.m_logger = new Logger(GetType().Name, mover.Block.CubeBlock, () => CurrentResponse.Response.ToString());
			this.m_mover = mover;
			this.m_navSet = navSet;

			m_logger.debugLog("Initialized", "EnemyFinder()");
		}