示例#1
1
        /// <summary>
        /// Creates a missile with homing and target finding capabilities.
        /// </summary>
        public GuidedMissile(IMyEntity missile, GuidedMissileLauncher launcher, Target initialTarget)
            : base(missile, launcher.CubeBlock)
        {
            m_launcher = launcher;
            myAmmo     = launcher.loadedAmmo;
            m_entity   = missile;
            m_owner    = launcher.CubeBlock.OwnerId;
            if (myAmmo.Description.HasAntenna)
            {
                myAntenna = new RelayNode(missile, () => m_owner, ComponentRadio.CreateRadio(missile, 0f));
            }
            TryHard = true;
            SEAD    = myAmmo.Description.SEAD;

            Static.AllGuidedMissiles.Add(this);
            Registrar.Add(MyEntity, this);
            MyEntity.OnClose += MyEntity_OnClose;

            acceleration      = myDescr.Acceleration + myAmmo.MissileDefinition.MissileAcceleration;
            addSpeedPerUpdate = myDescr.Acceleration * Globals.UpdateDuration;
            if (!(launcher.CubeBlock is Sandbox.ModAPI.Ingame.IMyLargeTurretBase))
            {
                m_rail = new RailData(Vector3D.Transform(MyEntity.GetPosition(), CubeBlock.WorldMatrixNormalizedInv));
            }

            Options = m_launcher.m_weaponTarget.Options.Clone();
            Options.TargetingRange = myAmmo.Description.TargetRange;

            SetTarget(initialTarget);

            if (myAmmo.RadarDefinition != null)
            {
                Log.DebugLog("Has a radar definiton");
                m_radar = new RadarEquipment(missile, myAmmo.RadarDefinition, launcher.CubeBlock);
                if (myAntenna == null)
                {
                    Log.DebugLog("Creating node for radar");
                    myAntenna = new RelayNode(missile, () => m_owner, null);
                }
            }

            Log.DebugLog("Options: " + Options + ", initial target: " + (CurrentTarget == null ? "null" : CurrentTarget.Entity.getBestName()) + ", entityId: " + missile.EntityId);
            //Log.DebugLog("AmmoDescription: \n" + MyAPIGateway.Utilities.SerializeToXML<Ammo.AmmoDescription>(myDescr), "GuidedMissile()");
        }
示例#2
0
        /// <summary>
        /// Create a RadarEquipment for an entity, with the specified definition and an owner block.
        /// </summary>
        public RadarEquipment(IMyEntity radarEntity, Definition radarDef, IMyCubeBlock relationsBlock)
        {
            this.Log = new Logger(() => RelationsBlock.CubeGrid.DisplayName, () => RelationsBlock.DisplayNameText, () => radarEntity.ToString());

            this.Entity         = radarEntity;
            this.RelationsBlock = relationsBlock;
            this.myDefinition   = radarDef;

            Registrar.Add(radarEntity, this);
            PowerLevel_Current = PowerLevel_Target = this.myDefinition.MaxPowerLevel;

            byte detectionTypes = 0;

            if (myDefinition.Radar)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Jamming > 0)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Radar > 0)
            {
                detectionTypes++;
            }
            if (detectionTypes > 1)
            {
                detectedObjects_hash = new Dictionary <IMyEntity, DetectedInfo>();
            }

            m_beaconLight = GetLight();

            Log.DebugLog("Radar equipment initialized, power level: " + PowerLevel_Current, Logger.severity.INFO);
        }
示例#3
0
        private AttachedGrid(IMyCubeGrid grid)
        {
            this.myGrid = grid;
            Registrar.Add(grid, this);

            Log.DebugLog("Initialized");
        }
示例#4
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;

            Registrar.Add(block, this);
        }
示例#5
0
        public GuidedMissileLauncher(WeaponTargeting weapon)
        {
            m_weaponTarget      = weapon;
            m_relayPart         = RelayClient.GetOrCreateRelayPart(m_weaponTarget.CubeBlock);
            this._initialTarget = NoTarget.Instance;

            MyWeaponBlockDefinition defn = (MyWeaponBlockDefinition)CubeBlock.GetCubeBlockDefinition();

            Vector3[] points        = new Vector3[3];
            Vector3   forwardAdjust = Vector3.Forward * WeaponDescription.GetFor(CubeBlock).MissileSpawnForward;

            points[0] = CubeBlock.LocalAABB.Min + forwardAdjust;
            points[1] = CubeBlock.LocalAABB.Max + forwardAdjust;
            points[2] = CubeBlock.LocalAABB.Min + Vector3.Up * defn.Size.Y * CubeBlock.CubeGrid.GridSize + forwardAdjust;

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

            Log.TraceLog("MissileSpawnBox: " + MissileSpawnBox);

            myInventory = ((MyEntity)CubeBlock).GetInventoryBase(0);

            Registrar.Add(weapon.CubeBlock, this);
            m_weaponTarget.GuidedLauncher = true;

            m_gameCooldownTime = TimeSpan.FromSeconds(60d / MyDefinitionManager.Static.GetWeaponDefinition(defn.WeaponDefinitionId).WeaponAmmoDatas[(int)MyAmmoType.Missile].RateOfFire);
            Log.TraceLog("m_gameCooldownTime: " + m_gameCooldownTime);

            CubeBlock.AppendingCustomInfo += CubeBlock_AppendingCustomInfo;
        }
示例#6
0
        private AutopilotCommands(IMyTerminalBlock block)
        {
            this.m_block = block;

            m_block.AppendingCustomInfo += m_block_AppendSyntaxErrors;

            Registrar.Add(block, this);
        }
示例#7
0
文件: Solar.cs 项目: zrisher/ARMS
        /// <param name="block">Must be an IMyTerminalBlock</param>
        public Solar(IMyCubeBlock block)
        {
            myBlock = block;
            (myBlock as IMyTerminalBlock).CustomNameChanged += Solar_CustomNameChanged;
            myBlock.OnClose += myBlock_OnClose;

            Registrar.Add(block, this);
        }
示例#8
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);
        }
示例#9
0
文件: RelayNode.cs 项目: zrisher/ARMS
        /// <summary>
        /// Create a NetworkNode for a missile. Update100() will have to be invoked by GuidedMissile.
        /// </summary>
        public RelayNode(IMyEntity missile, Func <long> ownerId, ComponentRadio radio)
        {
            this.m_debugName  = missile.getBestName;
            this.m_ownerId    = ownerId;
            this.m_entity     = missile;
            this.m_comp_radio = radio;

            Registrar.Add(missile, this);
        }
示例#10
0
文件: TextPanel.cs 项目: zrisher/ARMS
        public TextPanel(IMyCubeBlock block)
            : base(block)
        {
            m_textPanel     = block as Ingame.IMyTextPanel;
            myTermBlock     = block as IMyTerminalBlock;
            m_networkClient = new RelayClient(block);
            Log.DebugLog("init: " + m_block.DisplayNameText);

            Registrar.Add(block, this);
        }
示例#11
0
        public AeroEffects(IMyCubeGrid grid)
        {
            this.m_grid      = grid;
            this.m_cache     = CubeGridCache.GetFor(m_grid);
            this.m_profileAt = Globals.UpdateCount + ProfileWait;

            m_grid.OnBlockAdded   += OnBlockChange;
            m_grid.OnBlockRemoved += OnBlockChange;

            Registrar.Add(grid, this);
        }
示例#12
0
文件: Projector.cs 项目: zrisher/ARMS
        public Projector(IMyCubeBlock block)
        {
            if (Static == null)
            {
                throw new Exception("StaticVariables not loaded");
            }

            this.m_block     = (IMyProjector)block;
            this.m_netClient = new RelayClient(block);

            Registrar.Add(block, this);
        }
示例#13
0
        /// <summary>
        /// Create an OreDetector for the given block.
        /// </summary>
        /// <param name="oreDetector">The ore detector block.</param>
        public OreDetector(IMyCubeBlock oreDetector)
        {
            this.Block         = oreDetector;
            this.m_oreDetector = oreDetector as IMyOreDetector;
            this.m_netClient   = new RelayClient(oreDetector);

            float maxrange = ((MyOreDetectorDefinition)((MyCubeBlock)m_oreDetector).BlockDefinition).MaximumRange;

            m_maxRange = maxrange;

            Registrar.Add(Block, this);
        }
示例#14
0
文件: RelayNode.cs 项目: zrisher/ARMS
        /// <summary>
        /// Creates a NetworkNode for a character, checking radio communication.
        /// </summary>
        /// <param name="character">The character to create the NetworkNode for.</param>
        public RelayNode(IMyCharacter character)
        {
            IMyPlayer player = character.GetPlayer_Safe();

            this.m_debugName  = () => player.DisplayName;
            this.m_ownerId    = () => player.IdentityId;
            this.m_entity     = character as IMyEntity;
            this.m_player     = player;
            this.m_comp_radio = ComponentRadio.CreateRadio(character);

            Registrar.Add(character as IMyEntity, this);
        }
示例#15
0
        /// <summary>
        /// Create a RadarEquipment for a block, getting the definition from the block.
        /// </summary>
        public RadarEquipment(IMyCubeBlock block)
        {
            this.Log = new Logger(block);

            this.Entity         = block;
            this.RelationsBlock = block;
            this.myDefinition   = GetDefinition(block);

            Registrar.Add(block, this);

            TermBlock.OnClose += CustomInfoBlock_OnClose;

            TermBlock.AppendingCustomInfo += AppendingCustomInfo;

            UpdateTargetPowerLevel();
            PowerLevel_Current = Math.Min(PowerLevel_Target, myDefinition.MaxPowerLevel);
            MyAPIGateway.Utilities.InvokeOnGameThread(UpdatePowerConsumption);

            // maybe this is a bug fix?
            MyFunctionalBlock func = (MyFunctionalBlock)block;

            func.Enabled = false;
            func.Enabled = true;

            TermBlock.UpdateCustomInfo();

            byte detectionTypes = 0;

            if (myDefinition.Radar)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Jamming > 0)
            {
                detectionTypes++;
            }
            if (myDefinition.PassiveDetect_Radar > 0)
            {
                detectionTypes++;
            }
            if (detectionTypes > 1)
            {
                detectedObjects_hash = new Dictionary <IMyEntity, DetectedInfo>();
            }

            m_beaconLight = GetLight();

            Log.DebugLog("Radar equipment initialized, power level: " + PowerLevel_Current, Logger.severity.INFO);
        }
示例#16
0
文件: RelayNode.cs 项目: zrisher/ARMS
        /// <summary>
        /// Creates a NetworkNode for a block, checking block attachments, laser, and radio communication.
        /// </summary>
        /// <param name="block">The block to create the NetworkNode for.</param>
        public RelayNode(IMyCubeBlock block)
        {
            this.m_debugName        = () => block.DisplayNameText;
            this.m_ownerId          = () => block.OwnerId;
            this.m_entity           = block;
            this.m_comp_blockAttach = block;
            this.m_comp_radio       = ComponentRadio.TryCreateRadio(block);

            IMyLaserAntenna lAnt = block as IMyLaserAntenna;

            if (lAnt != null)
            {
                this.m_comp_laser = lAnt;
            }

            Registrar.Add(block, this);
        }
示例#17
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, HandleMessage);
            this.m_pathfinder = new Pathfinder(m_block);
            this.m_commands   = AutopilotCommands.GetOrCreate(m_block.Terminal);
            this.m_block.CubeBlock.OnClosing += CubeBlock_OnClosing;

            int start = block.DisplayNameText.IndexOf('[') + 1, end = block.DisplayNameText.IndexOf(']');

            if (start > 0 && end > start)
            {
                m_block.AutopilotTerminal.AutopilotCommandsText = 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.CustomName = (nameBefore + nameAfter).Trim();
            }

            Log.DebugLog("Created autopilot for: " + block.DisplayNameText);
            Registrar.Add(block, this);
        }
 public CharacterStateTracker(IMyCharacter character)
 {
     Registrar.Add((IMyEntity)character, this);
     character.OnMovementStateChanged += character_OnMovementStateChanged;
 }
示例#19
0
        public CockpitTerminal(IMyCubeBlock cockpit)
        {
            this.m_cockpit = (MyCockpit)cockpit;

            Registrar.Add(this.m_cockpit, this);
        }
示例#20
0
 protected void Register <TRequest>(Perform action) where TRequest : Request, new()
 {
     Registrar.Add(typeof(TRequest), action);
 }
示例#21
0
 public void Persist()
 {
     Registrar.Add("Customer", this);
 }
示例#22
0
        public ManualMessage(IMyCubeBlock block)
        {
            m_block = block;

            Registrar.Add(block, this);
        }
示例#23
0
 public void Persist()
 {
     Registrar.Add("Movies", Name);
 }