Esempio n. 1
0
        /// <summary>
        /// Creates a Logger that gets the context and states from block and supplied function.
        /// </summary>
        /// <param name="calling_class">the name of the class this Logger belongs to</param>
        /// <param name="block">The block to get context and states from</param>
        /// <param name="default_secondary">the secondary state used when one is not supplied to alwaysLog() or debugLog()</param>
        public Logger(string calling_class, IMyCubeBlock block, Func<string> default_secondary = null)
        {
            this.m_classname = calling_class;

            if (block == null)
            {
                f_context = () => "Null block";
                return;
            }

            this.f_context = () => {
                IMyCubeGrid grid = block.CubeGrid;
                if (grid == null)
                    return "Null grid";
                return grid.DisplayName + " - " + grid.EntityId;
            };

            if (default_secondary == null)
            {
                this.f_state_primary = () => block.DefinitionDisplayNameText;
                this.f_state_secondary = () => block.getNameOnly() + " - " + block.EntityId;
            }
            else
            {
                this.f_state_primary = () => block.getNameOnly() + " - " + block.EntityId;
                this.f_state_secondary = default_secondary;
            }
        }
Esempio n. 2
0
        public ManualMessage(IMyCubeBlock block)
        {
            m_logger = new Logger(GetType().Name, block);
            m_block = block;

            Registrar.Add(block, this);
        }
Esempio n. 3
0
 public DirectionWorld ToWorld(IMyCubeBlock block)
 {
     Vector3 result;
     Matrix orientation = block.WorldMatrix.GetOrientation();
     Vector3.Transform(ref vector, ref orientation, out result);
     return new DirectionWorld() { vector = result };
 }
Esempio n. 4
0
 public LastSeenTarget(LastSeen seen, IMyCubeBlock block = null)
 {
     m_lastSeen = seen;
     m_block = block;
     m_lastPostion = m_lastSeen.LastKnownPosition;
     m_lastPositionUpdate = m_lastSeen.LastSeenAt;
 }
Esempio n. 5
0
		public ProgrammableBlock(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("Programmable block", () => CubeBlock.CubeGrid.DisplayName);
			myProgBlock = CubeBlock as Ingame.IMyProgrammableBlock;
			Registrar.Add(CubeBlock, this);
		}
Esempio n. 6
0
		/// <param name="block">Must be an IMyTerminalBlock</param>
		public Solar(IMyCubeBlock block)
		{
			myBlock = block;
			myLogger = new Logger("Solar", block);
			(myBlock as IMyTerminalBlock).CustomNameChanged += Solar_CustomNameChanged;
			myBlock.OnClose += myBlock_OnClose;
		}
Esempio n. 7
0
 public static bool IsHacker(IMyCubeBlock block)
 {
     if (!(block is IMyLandingGear))
         return false;
     string descr = block.GetCubeBlockDefinition().DescriptionString;
     return descr != null && descr.ToLower().Contains("hacker");
 }
Esempio n. 8
0
        /// <summary>
        /// Creates an Autopilot for the given ship controller.
        /// </summary>
        /// <param name="block">The ship controller to use</param>
        public ShipAutopilot(IMyCubeBlock block)
        {
            this.m_block = new ShipControllerBlock(block);
            this.m_logger = new Logger(GetType().Name, block);
            this.m_interpreter = new Interpreter(m_block);

            this.m_block.CubeBlock.OnClosing += CubeBlock_OnClosing;

            ((MyCubeBlock)block).ResourceSink.SetRequiredInputFuncByType(new MyDefinitionId(typeof(MyObjectBuilder_GasProperties), "Electricity"), PowerRequired);

            if (Saver.Instance.LoadOldVersion(69))
            {
                int start = block.DisplayNameText.IndexOf('[') + 1, end = block.DisplayNameText.IndexOf(']');
                if (start > 0 && end > start)
                {
                    m_block.AutopilotTerminal.AutopilotCommands = new StringBuilder(block.DisplayNameText.Substring(start, end - start).Trim());
                    int lengthBefore = start - 1;
                    string nameBefore = lengthBefore > 0 ? m_block.Terminal.DisplayNameText.Substring(0, lengthBefore) : string.Empty;
                    end++;
                    int lengthAfter  = m_block.Terminal.DisplayNameText.Length - end;
                    string nameAfter = lengthAfter > 0 ? m_block.Terminal.DisplayNameText.Substring(end, lengthAfter) : string.Empty;
                    m_block.Terminal.SetCustomName((nameBefore + nameAfter).Trim());
                }
            }

            m_logger.debugLog("Created autopilot for: " + block.DisplayNameText);

            Registrar.Add(block, this);
        }
Esempio n. 9
0
 public MotorTurret(IMyCubeBlock block, StatorChangeHandler handler)
 {
     this.FaceBlock = block;
     this.myLogger = new Logger("MotorTurret", block);
     this.OnStatorChange = handler;
     this.SetupStators();
 }
Esempio n. 10
0
		public ShipController(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("ShipController", () => CubeBlock.CubeGrid.DisplayName);
			myController = CubeBlock as Ingame.IMyShipController;
			Registrar.Add(CubeBlock, this);
		}
Esempio n. 11
0
        public Vector3 ToBlock(IMyCubeBlock block)
        {
            if (direction_block.HasValue && CubeBlock == block)
            {
                return direction_block.Value;
            }

            Vector3 result = Vector3.PositiveInfinity;
            if (block.CubeGrid == CubeGrid && direction_local.HasValue)
            {
                MatrixD Transform = Matrix.Invert(block.LocalMatrix).GetOrientation();
                result = Vector3.Transform(direction_local.Value, Transform);
            }
            else
            {
                MatrixD Transform = block.WorldMatrixNormalizedInv.GetOrientation();
                result = Vector3.Transform(ToWorld(), Transform);
            }

            if (CubeBlock == null)
            {
                CubeBlock = block;
                direction_block = result;
            }
            return result;
        }
Esempio n. 12
0
 public static RelativeDirection3F FromBlock(IMyCubeBlock block, Vector3 blockDirection)
 {
     RelativeDirection3F result = new RelativeDirection3F(block.CubeGrid);
     result.direction_block = blockDirection;
     result.CubeBlock = block;
     return result;
 }
Esempio n. 13
0
		public LaserAntenna(IMyCubeBlock block)
			: base(block)
		{
			myLaserAntenna = CubeBlock as Ingame.IMyLaserAntenna;
			myLogger = new Logger("LaserAntenna", () => CubeBlock.CubeGrid.DisplayName);
			Registrar.Add(block, this);
		}
Esempio n. 14
0
		protected BlockInstructions(IMyTerminalBlock block)
		{
			m_logger = new Logger("BlockInstructions", block as IMyCubeBlock);
			m_block = block as IMyCubeBlock;

			block.CustomNameChanged += BlockChange;
		}
Esempio n. 15
0
			public Stator(IMyCubeBlock block)
				: base(block, AttachedGrid.AttachmentKind.Motor)
			{
				this.myLogger = new Logger("Stator", block);
				this.myStator = block as IMyMotorStator;
				Registrar.Add(this.myStator, this);
			}
Esempio n. 16
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);
            missile.OnClose += missile_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()");
        }
Esempio n. 17
0
 public void Update(LastSeen seen, IMyCubeBlock block = null)
 {
     m_lastSeen = seen;
     if (block != null)
         m_block = block;
     m_lastPostion = m_lastSeen.LastKnownPosition;
     m_lastPositionUpdate = m_lastSeen.LastSeenAt;
 }
Esempio n. 18
0
		public InterpreterWeapon(IMyCubeBlock block)
			: base(block as IMyTerminalBlock)
		{
			this.Block = block;
			this.Grid = block.CubeGrid;

			myLogger = new Logger("InterpreterWeapon", () => Grid.DisplayName, () => Block.DefinitionDisplayNameText, () => Block.getNameOnly());
		}
Esempio n. 19
0
        /// <summary>
        /// Use GetOrCreateRelayPart if client may already exist.
        /// </summary>
        public RelayClient(IMyCubeBlock block, Action<Message> messageHandler = null)
        {
            this.m_block = block;
            this.m_messageHandler = messageHandler;
            this.m_logger = new Logger(GetType().Name, block);

            Registrar.Add(block, this);
        }
Esempio n. 20
0
        public InterpreterWeapon(IMyCubeBlock block)
            : base(block)
        {
            this.Block = block;
            this.Grid = block.CubeGrid;

            myLogger = new Logger("InterpreterWeapon", () => Grid.DisplayName, () => Block.DefinitionDisplayNameText, () => Block.getNameOnly()) { MinimumLevel = Logger.severity.INFO };
        }
Esempio n. 21
0
 public void SetLauncherReference(IMyCubeBlock launcherReference,
                                  Base6Directions.Direction direction = Base6Directions.Direction.Forward)
 {
     LauncherReferencePoint = launcherReference.GetPosition();
     var forward3I = launcherReference.Position + Base6Directions.GetIntVector(launcherReference.Orientation.TransformDirection(direction));
     var forwardPoint = launcherReference.CubeGrid.GridIntegerToWorld(forward3I);
     LauncherReferenceDirection = Vector3D.Normalize(forwardPoint - LauncherReferencePoint);
 }
Esempio n. 22
0
		/// <summary>
		/// create from a vector relative to a block (including block orientation)
		/// <para>Use to create a position vector from a block.</para>
		/// </summary>
		/// <param name="IsPosition">If true, the resultant RelativeVector3F represents a position. If false, it represents a direction</param>
		public static RelativeVector3F createFromBlock(Vector3 fromBlock, IMyCubeBlock block)
		{
			RelativeVector3F result = new RelativeVector3F();
			result.value__block = fromBlock;
			result.cubeGrid = block.CubeGrid;
			result.cubeBlock = block;
			return result;
		}
Esempio n. 23
0
		protected override int StartEffect(IMyCubeBlock block, int strength)
		{
			IMyDoor door = block as IMyDoor;
			m_logger.debugLog("Locking: " + block.DisplayNameText + ", remaining strength: " + (strength - 1), "StartEffect()");
			if (door.Open)
				door.ApplyAction("Open_Off");
			return MinCost;
		}
Esempio n. 24
0
		public InterpreterWeapon(IMyCubeBlock block)
		{
			this.Block = block;
			this.Grid = block.CubeGrid;
			this.m_instructions = new BlockInstructions(block as IMyTerminalBlock, OnInstruction);

			myLogger = new Logger("InterpreterWeapon", () => Grid.DisplayName, () => Block.DefinitionDisplayNameText, () => Block.getNameOnly());
		}
Esempio n. 25
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);
        }
		public ShipControllerBlock(IMyCubeBlock block)
		{
			m_logger = new Logger(GetType().Name, block);
			Controller = block as MyShipController;
			CubeBlock = block;
			Terminal = block as IMyTerminalBlock;
			Pseudo = new PseudoBlock(block);
		}
Esempio n. 27
0
 protected override int EndEffect(IMyCubeBlock block, int strength)
 {
     m_logger.debugLog("No longer depressurizing: " + block.DisplayNameText + ", remaining strength: " + (strength - 1), "EndEffect()");
     Ingame.IMyAirVent airVent = block as Ingame.IMyAirVent;
     if (airVent.IsDepressurizing)
         airVent.ApplyAction("Depressurize");
     return 1;
 }
Esempio n. 28
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);
		}
Esempio n. 29
0
		public Turret(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("Turret", () => block.CubeGrid.DisplayName, () => block.DefinitionDisplayNameText, () => block.getNameOnly());
			Registrar.Add(CubeBlock, this);
			//myLogger.debugLog("definition limits = " + definition.MinElevationDegrees + ", " + definition.MaxElevationDegrees + ", " + definition.MinAzimuthDegrees + ", " + definition.MaxAzimuthDegrees, "Turret()");
			//myLogger.debugLog("radian limits = " + minElevation + ", " + maxElevation + ", " + minAzimuth + ", " + maxAzimuth, "Turret()");
		}
Esempio n. 30
0
 /// <summary>
 /// Do not forget to call this!
 /// </summary>
 protected Receiver(IMyCubeBlock block)
 {
     //(new Logger(null, "Receiver")).log("init", "DelayedInit()", Logger.severity.TRACE);
     this.CubeBlock = block;
     CubeBlock.CubeGrid.OnBlockOwnershipChanged += CubeGrid_OnBlockOwnershipChanged;
     EnemyNear            = false;
     myLogger             = new Logger("Receiver", () => CubeBlock.CubeGrid.DisplayName);
     CubeBlock.OnClosing += Close;
 }
Esempio n. 31
0
        //Dr. Novikov snippet: http://forums.keenswh.com/threads/snippet-get-block-health.7368130/
        public float GetMyTerminalBlockHealth(ref IMyCubeBlock block)
        {
            IMySlimBlock slimblock      = block.CubeGrid.GetCubeBlock(block.Position);
            float        MaxIntegrity   = slimblock.MaxIntegrity;
            float        BuildIntegrity = slimblock.BuildIntegrity;
            float        CurrentDamage  = slimblock.CurrentDamage;

            return((BuildIntegrity - CurrentDamage) / MaxIntegrity);
        }
Esempio n. 32
0
 public MyRepairInfo(IMyTerminalBlock welder, IMyCubeBlock damagedBlock, float welderDamagedDistance)
 {
     Welder                = welder;
     DamagedBlock          = damagedBlock;
     CreateDate            = DateTime.UtcNow;
     Timeout               = false;
     Done                  = false;
     WelderDamagedDistance = welderDamagedDistance;
 }
Esempio n. 33
0
        private int GetBeamCount(IMyCubeBlock b)
        {
            if (GetYard(b) == null)
            {
                return(3);
            }

            return(ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId).BeamCount);
        }
Esempio n. 34
0
        public static bool EntityOver(IMyCubeBlock block, MyDetectedEntityInfo entity)
        {
            Vector3D center = block.GetPosition();
            Vector3D min    = center - new Vector3D(1.25);
            Vector3D max    = center + new Vector3D(1.25);

            return(VectorCompare(entity.Position, min, new DoubleComparisons.GreaterOrEqual()) &&
                   VectorCompare(entity.Position, max, new DoubleComparisons.LessOrEqual()));
        }
Esempio n. 35
0
        MatrixD GetBlock2WorldTransform(IMyCubeBlock blk)
        {
            Matrix blk2grid;

            blk.Orientation.GetMatrix(out blk2grid);
            return(blk2grid *
                   MatrixD.CreateTranslation(((Vector3D) new Vector3D(blk.Min + blk.Max)) / 2.0) *
                   GetGrid2WorldTransform(blk.CubeGrid));
        }
Esempio n. 36
0
        public override bool Update(BasePilot owner, ref Vector3D linearV, ref Vector3D angularV)
        {
            IMyCubeBlock reference = Reference ?? owner.Controller;
            MatrixD      wm        = reference.WorldMatrix;

            Goal.Update(owner.elapsedTime);
            Vector3D currentGoalPos  = Goal.Position;
            Vector3D direction       = currentGoalPos - wm.Translation;
            double   distance        = direction.Normalize();
            double   target_distance = distance;
            double   diff;

            if (!Vector3D.IsZero(Approach))
            {
                Vector3D minusApproach = -Approach;
                diff = owner.RotationAid.Rotate(owner.elapsedTime,
                                                Approach, Facing,
                                                wm.GetDirectionVector(ReferenceForward),
                                                wm.GetDirectionVector(ReferenceUp),
                                                ref angularV);
                PlaneD   alignment  = new PlaneD(wm.Translation, minusApproach);
                Vector3D alignedPos = alignment.Intersection(ref currentGoalPos, ref minusApproach);
                Vector3D correction = alignedPos - wm.Translation;
                if (!Vector3D.IsZero(correction, PositionEpsilon)) //are we on approach vector?
                {                                                  //no - let's move there
                    direction = correction;
                    distance  = direction.Normalize();
                }
                //otherwise, we can keep our current direction
            }
            else
            {
                diff = owner.RotationAid.Rotate(owner.elapsedTime,
                                                direction, Facing,
                                                wm.GetDirectionVector(ReferenceForward),
                                                wm.GetDirectionVector(ReferenceUp),
                                                ref angularV);
            }
            //rotate the ship to face it
            if (diff > OrientationEpsilon) //we still need to rotate
            {
                linearV = Goal.Velocity;   //match velocities with our target, then.
            }
            else //we are good
            {
                //how quickly can we go, assuming we still need to stop at the end?
                double accel               = owner.GetMaxAccelerationFor(-direction);
                double braking_time        = Math.Sqrt(2 * distance / accel);
                double acceptable_velocity = Math.Min(VelocityUsage * accel * braking_time, MaxLinearSpeed);
                //extra slowdown when close to the target
                acceptable_velocity = Math.Min(acceptable_velocity, distance);
                //moving relative to the target
                linearV  = direction * acceptable_velocity + Goal.Velocity;
                angularV = Vector3D.Zero;
            }
            return(Lock.TryLockIn(distance) || (target_distance < PositionEpsilon));
        }
Esempio n. 37
0
        private bool GetLockEnabled(IMyCubeBlock b)
        {
            if (GetYard(b) == null)
            {
                return(false);
            }

            return(ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId).AdvancedLocking);
        }
Esempio n. 38
0
        public Sloped5xRailGuide(IMyCubeBlock cubeBlock) : base(cubeBlock)
        {
            // it's a slope, so it's rotated around the center
            var angle = Math.Acos(5 / Math.Sqrt(5 * 5 + 1 * 1));

            // diagonal rail is half a block up from straight rail
            this.adjustMatrix   = MatrixD.CreateTranslation(0, -1.25, 0) * MatrixD.CreateRotationZ(-angle);
            this.unadjustMatrix = MatrixD.Invert(this.adjustMatrix);
        }
Esempio n. 39
0
        private float GetWeldSpeed(IMyCubeBlock b)
        {
            if (GetYard(b) == null)
            {
                return(0.1f);
            }

            return(ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId).WeldMultiplier);
        }
Esempio n. 40
0
        /// <summary>
        /// create from a vector relative to a block (including block orientation)
        /// </summary>
        public static RelativeVector3F createFromBlock(Vector3 fromBlock, IMyCubeBlock block)
        {
            RelativeVector3F result = new RelativeVector3F();

            result.value__block = fromBlock;
            result.cubeGrid     = block.CubeGrid;
            result.cubeBlock    = block;
            return(result);
        }
        public void EnableGrid(IMyCubeGrid grid)
        {
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks);

            lock (GridDisabled)
            {
                if (!GridBlocksDisabled.ContainsKey(grid.EntityId))
                {
                    if (GridDisabled.Contains(grid.EntityId))
                    {
                        GridDisabled.Remove(grid.EntityId);
                    }

                    return;
                }
            }

            HashSet <long> disabledBlocks = GridBlocksDisabled[grid.EntityId];

            foreach (IMySlimBlock block in blocks)
            {
                if (block.FatBlock == null)
                {
                    continue;
                }

                IMyCubeBlock cubeBlock = block.FatBlock;

                if (!(cubeBlock is IMyFunctionalBlock))
                {
                    continue;
                }

                if (!disabledBlocks.Contains(cubeBlock.EntityId))
                {
                    continue;
                }

                if (!FunctionalBlockEntity.GetState(cubeBlock))
                {
                    FunctionalBlockEntity.SetState(cubeBlock, true);
                    _enableCount++;
                }
            }

            lock (GridDisabled)
            {
                if (GridDisabled.Contains(grid.EntityId))
                {
                    GridDisabled.Remove(grid.EntityId);
                }

                GridBlocksDisabled.Remove(grid.EntityId);
            }
        }
Esempio n. 42
0
        private bool GetGuideEnabled(IMyCubeBlock b)
        {
            if (GetYard(b) == null)
            {
                return(true);
            }

            return(ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId).GuideEnabled);
        }
Esempio n. 43
0
        private long GetBuildPattern(IMyCubeBlock b)
        {
            if (GetYard(b) == null)
            {
                return(0);
            }

            return((long)ShipyardSettings.Instance.GetYardSettings(b.CubeGrid.EntityId).BuildPattern);
        }
Esempio n. 44
0
    public void SetLauncherReference(IMyCubeBlock launcherReference,
                                     Base6Directions.Direction direction = Base6Directions.Direction.Forward)
    {
        LauncherReferencePoint = launcherReference.GetPosition();
        var forward3I    = launcherReference.Position + Base6Directions.GetIntVector(launcherReference.Orientation.TransformDirection(direction));
        var forwardPoint = launcherReference.CubeGrid.GridIntegerToWorld(forward3I);

        LauncherReferenceDirection = Vector3D.Normalize(forwardPoint - LauncherReferencePoint);
    }
Esempio n. 45
0
        public ProgrammableBlock(IMyCubeBlock block)
            : base(block)
        {
            m_progBlock     = block as IMyProgrammableBlock;
            m_networkClient = new RelayClient(block, HandleMessage);

            Log.DebugLog("initialized");
            Registrar.Add(block, this);
        }
Esempio n. 46
0
        private bool collect_findBestHostile(IMySlimBlock slim, string blockContains)
        {
            IMyCubeBlock Fatblock = slim.FatBlock;

            return(Fatblock != null &&          // not armour
                   Fatblock.IsWorking &&              // ignore inactive hostile blocks
                   owner.currentRCblock.canConsiderHostile(Fatblock) &&              // block must be hostile
                   Fatblock.DefinitionDisplayNameText.looseContains(blockContains));                // must contain blockContains
        }
Esempio n. 47
0
        public override void ParallelUpdate(List <IMyCubeGrid> gridList, List <IMySlimBlock> blocks)
        {
            using (Lock.AcquireExclusiveUsing())
            {
                PotentialTargetList.Clear();
            }

            var remoteList = new HashSet <IMySlimBlock>();

            if (!IsEnabled())
            {
                return;
            }

            foreach (var block in blocks)
            {
                AddPotentialBlock(block);
            }

            foreach (var beaconBlock in NaniteConstructionManager.BeaconList.Where(x => x is NaniteBeaconConstruct && Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), x.BeaconBlock.GetPosition()) < m_maxDistance * m_maxDistance))
            {
                IMyCubeBlock item = (IMyCubeBlock)beaconBlock.BeaconBlock;
                MyRelationsBetweenPlayerAndBlock relation = item.GetUserRelationToOwner(m_constructionBlock.ConstructionBlock.OwnerId);
                if (!(relation == MyRelationsBetweenPlayerAndBlock.Owner || relation == MyRelationsBetweenPlayerAndBlock.FactionShare || (MyAPIGateway.Session.CreativeMode && relation == MyRelationsBetweenPlayerAndBlock.NoOwnership)))
                {
                    continue;
                }

                if (!((IMyFunctionalBlock)item).Enabled)
                {
                    continue;
                }

                List <IMyCubeGrid>  beaconGridList = GridHelper.GetGridGroup((IMyCubeGrid)item.CubeGrid);
                List <IMySlimBlock> beaconBlocks   = new List <IMySlimBlock>();
                foreach (var grid in beaconGridList)
                {
                    grid.GetBlocks(beaconBlocks);
                }

                foreach (var block in beaconBlocks)
                {
                    if (AddPotentialBlock(block, true))
                    {
                        remoteList.Add(block);
                    }
                }
            }

            CheckAreaBeacons();

            using (m_remoteLock.AcquireExclusiveUsing())
            {
                m_remoteTargets = remoteList;
            }
        }
Esempio n. 48
0
        private void on_block_added(IMySlimBlock block)
        {
            check_disposed();
            IMyCubeBlock entity = block.FatBlock;

            if (entity != null)
            {
                var controller      = entity as IMyControllableEntity;
                var ship_controller = entity as IMyShipController;
                if (controller != null && ship_controller != null)
                {
                    var controller_terminal = (IMyTerminalBlock)controller;

                    controller_terminal.AppendingCustomInfo += gravity_and_physics.list_current_elements;
                    _ship_controllers.Add(controller);
                    session_handler.sample_controller(ship_controller);

                    var RC_block = entity as IMyRemoteControl;
                    if (RC_block != null)
                    {
                        _RC_blocks.Add(RC_block);
                    }
                    return;
                }

                var thruster = entity as IMyThrust;
                if (thruster != null)
                {
                    _ECU.assign_thruster(thruster);
                    session_handler.sample_thruster(thruster);
                    thruster.AppendingCustomInfo += thruster_and_grid_tagger.show_thrust_limit;
                    ++_num_thrusters;
                    return;
                }

                var gyro = entity as IMyGyro;
                if (gyro != null)
                {
                    _ECU.assign_gyroscope(gyro);
                    return;
                }

                var PB = entity as IMyProgrammableBlock;
                if (PB != null)
                {
                    session_handler.sample_PB(PB);
                    return;
                }

                var jump_drive = entity as IMyJumpDrive;
                if (jump_drive != null)
                {
                    _jump_drives.Add(jump_drive);
                }
            }
        }
Esempio n. 49
0
        bool CollectParts(IMyTerminalBlock block, IMyCubeBlock reference)
        {
            if (reference.CubeGrid.EntityId != block.CubeGrid.EntityId)
            {
                return(false);
            }

            if (block is IMyGyro)
            {
                Drive.AddGyro((IMyGyro)block);
            }

            if (block is IMySmallGatlingGun)
            {
                Gats.Add((IMySmallGatlingGun)block);
            }

            if (block is IMyCameraBlock)
            {
                Cameras.Add((IMyCameraBlock)block);
            }

            if (block is IMyMotorStator)
            {
                TurretRotor = (IMyMotorStator)block;
            }

            if (block is IMyLargeTurretBase)
            {
                Designator = (IMyLargeTurretBase)block;
            }

            if (block is IMyThrust)
            {
                Drive.AddEngine(new HoverEngineDriver((IMyThrust)block));
            }

            if (block is IMyRadioAntenna)
            {
                Antenna = (IMyRadioAntenna)block;
            }

            if (block is IMyBeacon)
            {
                ((IMyBeacon)block).Enabled = false;
            }

            if (block is IMyShipController)
            {
                Controller = (IMyShipController)block;
                Controller.TryGetPlanetPosition(out PlanetPos);
                Drive.Controller = Controller;
            }

            return(false);
        }
Esempio n. 50
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_generator = Entity as IMyAssembler;
            m_parent    = Entity as IMyCubeBlock;
            builder     = objectBuilder;

            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            terminalBlock = Entity as IMyTerminalBlock;
        }
        void OnWorkingChange(IMyCubeBlock block)
        {
            if (block.IsWorking == false || block.IsFunctional == false)
            {
                IsWorking = false;
                return;
            }

            IsWorking = true;
        }
Esempio n. 52
0
        private static bool IsControlledBy(this IMyCubeBlock block, string factionTag)
        {
            var faction = MyAPIGateway.Session.Factions.TryGetFactionByTag(factionTag);

            if (faction == null)
            {
                return(false);
            }
            return(block.OwnerId == faction.FounderId);
        }
Esempio n. 53
0
 public TextPanel(IMyCubeBlock block)
 {
     myCubeBlock = block;
     myTextPanel = block as Ingame.IMyTextPanel;
     myTermBlock = block as IMyTerminalBlock;
     myLogger    = new Logger("TextPanel", () => myCubeBlock.CubeGrid.DisplayName, () => myCubeBlock.getNameOnly());
     myLogger.debugLog("init: " + myCubeBlock.DisplayNameText, "DelayedInit()");
     myTermBlock.CustomNameChanged += TextPanel_CustomNameChanged;
     myTermBlock.OnClosing         += Close;
 }
Esempio n. 54
0
            private IMyTextPanel GetPanel(IMyCubeBlock reference, Vector3I pos)
            {
                IMySlimBlock slim = reference.CubeGrid.GetCubeBlock(pos);

                if (slim == null)
                {
                    return(null);
                }
                return(slim.FatBlock as IMyTextPanel);
            }
Esempio n. 55
0
    static Vector3 AlignTo(Vector3 pos, IMyCubeBlock reference)
    {
        Matrix rotation;

        reference.Orientation.GetMatrix(out rotation);
        rotation = Matrix.Invert(rotation);
        var res = Vector3.Transform(pos, rotation);

        return(res);
    }
Esempio n. 56
0
        public bool IsEnabled(IMyCubeBlock block)
        {
            Init();
            if (_action != null && _parent.HasEntity)
            {
                return(_action.IsEnabled((Sandbox.ModAPI.IMyCubeBlock)_parent.Entity));
            }

            return(false);
        }
Esempio n. 57
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_generator = Entity as Sandbox.ModAPI.IMyCargoContainer;
            m_parent    = Entity as IMyCubeBlock;
            builder     = objectBuilder;

            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; //|= MyEntityUpdateEnum.EACH_FRAME

            terminalBlock = Entity as Sandbox.ModAPI.IMyTerminalBlock;
        }
Esempio n. 58
0
 public static bool landingDirectionLocal(IMyCubeBlock block, out Base6Directions.Direction?result)
 {
     Base6Directions.Direction?intermediate;
     if (!landingDirection(block, out intermediate))
     {
         result = null;
         return(false);
     }
     return(getDirFromOri(block.Orientation, (Base6Directions.Direction)intermediate, out result));
 }
Esempio n. 59
0
        public LaserAntenna(IMyCubeBlock block)
            : base(block)
        {
            myLaserAntenna = CubeBlock as Ingame.IMyLaserAntenna;
            myLogger       = new Logger("LaserAntenna", () => CubeBlock.CubeGrid.DisplayName);
            value_registry.Add(this);

            //log("init as antenna: " + CubeBlock.BlockDefinition.SubtypeName, "Init()", Logger.severity.TRACE);
            //EnforcedUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME;
        }
Esempio n. 60
-1
		public RadioAntenna(IMyCubeBlock block)
			: base(block)
		{
			myLogger = new Logger("RadioAntenna", () => CubeBlock.CubeGrid.DisplayName);
			myRadioAntenna = CubeBlock as Ingame.IMyRadioAntenna;
			Registrar.Add(myRadioAntenna, this);
		}