示例#1
0
        public RelayStorage(RelayNode primary)
        {
            this.m_logger = new Logger(GetType().Name, () => primary.LoggingName);
            this.PrimaryNode = primary;

            m_logger.debugLog("Created", Logger.severity.DEBUG);
        }
示例#2
0
        /// <summary>
        /// Creates a missile with homing and target finding capabilities.
        /// </summary>
        public GuidedMissile(IMyEntity missile, GuidedMissileLauncher launcher, out Target initialTarget)
            : base(missile, launcher.CubeBlock)
        {
            myLogger = new Logger("GuidedMissile", () => missile.getBestName(), () => m_stage.ToString());
            m_launcher = launcher;
            myAmmo = launcher.loadedAmmo;
            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;

            AllGuidedMissiles.Add(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;

            RelayStorage storage = launcher.m_relayPart.GetStorage();
            if (storage == null)
            {
                myLogger.debugLog("failed to get storage for launcher", Logger.severity.WARNING);
            }
            else
            {
                myLogger.debugLog("getting initial target from launcher", Logger.severity.DEBUG);
                GetLastSeenTarget(storage, myAmmo.MissileDefinition.MaxTrajectory);
            }
            initialTarget = CurrentTarget;

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

            Registrar.Add(missile, this);

            myLogger.debugLog("Options: " + Options + ", initial target: " + (myTarget == null ? "null" : myTarget.Entity.getBestName()));
            //myLogger.debugLog("AmmoDescription: \n" + MyAPIGateway.Utilities.SerializeToXML<Ammo.AmmoDescription>(myDescr), "GuidedMissile()");
        }
示例#3
0
        /// <summary>
        /// Checks for established connections between this node and another.
        /// </summary>
        /// <param name="other">the other node to check</param>
        /// <param name="id">the search id</param>
        /// <returns>true iff the nodes are connected.</returns>
        private bool IsConnectedTo(RelayNode other, int id)
        {
            m_lastSearchId = id;

            if (m_directConnect.Contains(other))
            {
                return(true);
            }

            foreach (RelayNode node in m_directConnect)
            {
                if (node.m_lastSearchId != id && node.IsConnectedTo(other, id))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Gets the NetworkStorage this client is connected to or null, if it is not connected to a storage.
        /// Always test against null, player may forget to put an antenna on the ship.
        /// </summary>
        /// <returns>The NetworkStorage this client is connected to or null.</returns>
        public RelayStorage GetStorage()
        {
            RelayNode    node  = GetNode();
            RelayStorage store = node != null ? node.Storage : null;

            Log.DebugLog("current storage: " + StorageName(m_storage) + ", new storage: " + StorageName(store), condition: m_storage != store);
            if (store != m_storage && m_messageHandler != null)
            {
                if (m_storage != null)
                {
                    m_storage.RemoveMessageHandler(m_block.EntityId);
                }
                if (store != null)
                {
                    store.AddMessageHandler(m_block.EntityId, m_messageHandler);
                }
            }
            m_storage = store;
            return(m_storage);
        }
示例#5
0
        /// <summary>
        /// Scripts that use UpdateManager and run on clients as well as on server shall be added here.
        /// </summary>
        private void RegisterScripts_ClientAndServer()
        {
            #region Attached

            RegisterForBlock(typeof(MyObjectBuilder_MotorStator), (block) => {
                StatorRotor.Stator stator = new StatorRotor.Stator(block);
                RegisterForUpdates(1, stator.Update10, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_MotorAdvancedStator), (block) => {
                StatorRotor.Stator stator = new StatorRotor.Stator(block);
                RegisterForUpdates(1, stator.Update10, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_MotorRotor), (block) => {
                new StatorRotor.Rotor(block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_MotorAdvancedRotor), (block) => {
                new StatorRotor.Rotor(block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => {
                Piston.PistonBase pistonBase = new Piston.PistonBase(block);
                RegisterForUpdates(100, pistonBase.Update, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_PistonTop), (block) => {
                new Piston.PistonTop(block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => {
                Connector conn = new Connector(block);
                RegisterForUpdates(10, conn.Update, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => {
                if (!Hacker.IsHacker(block))
                    new LandingGear(block);
            });

            #endregion

            #region Antenna Communication

            Action<IMyCubeBlock> nodeConstruct = block => {
                RelayNode node = new RelayNode(block);
                RegisterForUpdates(100, node.Update100, block);
            };

            RegisterForBlock(typeof(MyObjectBuilder_Beacon), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), nodeConstruct);

            RegisterForCharacter(character => {
                if (character.IsPlayer)
                {
                    RelayNode node = new RelayNode(character);
                    RegisterForUpdates(100, node.Update100, (IMyEntity)character);
                }
                new CharacterStateTracker(character);
            });

            RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), block => {
                ProgrammableBlock pb = new ProgrammableBlock(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                    RegisterForUpdates(100, pb.Update100, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_TextPanel), block => {
                TextPanel tp = new TextPanel(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                    RegisterForUpdates(100, tp.Update100, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_Projector), block => {
                Projector p = new Projector(block);
                if (MyAPIGateway.Session.Player != null)
                {
                    RegisterForUpdates(100, p.Update100, block);
                    RegisterForUpdates(1, p.Update1, block);
                }
            });

            if (MyAPIGateway.Session.Player != null)
                new Player();

            #endregion

            #region Autopilot

            RadarEquipment.Definition apRadar = new RadarEquipment.Definition()
            {
                Radar = true,
                LineOfSight = false,
                MaxTargets_Tracking = 3,
                MaxPowerLevel = 1000
            };

            Action<IMyCubeBlock> apConstruct = (block) => {
                if (ShipAutopilot.IsAutopilotBlock(block))
                {
                    nodeConstruct(block);
                    new AutopilotTerminal(block);
                    RadarEquipment r = new RadarEquipment(block, apRadar, block);
                    RegisterForUpdates(100, r.Update100, block);
                }
            };

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
                    RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct);
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct);
            }

            #endregion

            #region Radar
            // must come after nodes are created

            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowRadar))
            {
                RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => {
                    if (RadarEquipment.IsRadarOrJammer(block))
                    {
                        RadarEquipment r = new RadarEquipment(block);
                        RegisterForUpdates(100, r.Update100, block);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => {
                    if (RadarEquipment.IsRadarOrJammer(block))
                    {
                        RadarEquipment r = new RadarEquipment(block);
                        RegisterForUpdates(100, r.Update100, block);
                    }
                });
                //RegisterForEveryBlock((IMyCubeBlock block) => {
                //	if (RadarEquipment.IsRadarOrJammer(block))
                //	{
                //		RadarEquipment r = new RadarEquipment(block);
                //		RegisterForUpdates(100, r.Update100, block);
                //	}
                //});
            }

            #endregion

            #region Terminal Control

            RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_RadioAntenna), typeof(MyObjectBuilder_LaserAntenna) }, block => new ManualMessage(block));

            #endregion Terminal Control

            #region Weapon Control

            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowWeaponControl))
            {
                #region Turrets

                Action<IMyCubeBlock> constructor;
                if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                    constructor = block => {
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(t);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    };
                else
                    constructor = block => {
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                    };

                RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor);

                #endregion

                #region Fixed

                if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                {
                    constructor = block => {
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(w);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    };
                }
                else
                    constructor = block => {
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                    };

                RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor);

                #endregion

                // apparently missiles do not have their positions synced
                RegisterForUpdates(1, GuidedMissile.Update1);
                RegisterForUpdates(10, GuidedMissile.Update10);
                RegisterForUpdates(100, GuidedMissile.Update100);
            }
            else
                myLogger.debugLog("Weapon Control is disabled", Logger.severity.INFO);

            #endregion

            new ChatHandler();
        }
示例#6
0
        public RelayStorage(RelayNode primary)
        {
            this.PrimaryNode = primary;

            Log.DebugLog("Created", Logger.severity.DEBUG);
        }
示例#7
0
        private RelayNode GetNode()
        {
            if (Globals.UpdateCount < m_nextNodeSet)
                return value_node;
            m_nextNodeSet = Globals.UpdateCount + UpdateFrequency;

            RelayNode newNode = value_node;
            if (newNode == null || !IsConnected(newNode))
            {
                newNode = null;
                Registrar.ForEach<RelayNode>(node => {
                    if (node.Block != null && IsConnected(node))
                    {
                        newNode = node;
                        return true;
                    }
                    return false;
                });

                value_node = newNode;
            }

            return value_node;
        }
示例#8
0
 private bool IsConnected(RelayNode node)
 {
     return !node.Block.Closed && node.Block.IsWorking && m_block.canConsiderFriendly(node.Block) && AttachedGrid.IsGridAttached(m_block.CubeGrid, node.Block.CubeGrid, AttachedGrid.AttachmentKind.Terminal);
 }
示例#9
0
        /// <summary>
        /// Tests whether a connection is possible between this and another NetworkNode.
        /// </summary>
        /// <param name="other">Node to test connection to this.</param>
        private CommunicationType TestConnection(RelayNode other)
        {
            if (!this.m_ownerId().canConsiderFriendly(other.m_ownerId()))
            {
                if (this.m_comp_radio != null && other.m_comp_radio != null && this.m_comp_radio.CanBroadcastPositionTo(other.m_comp_radio) && other.Storage != null)
                    if (s_sendPositionTo.Add(other.Storage))
                        m_logger.debugLog("Hostile receiver in range: " + other.LoggingName + ", new storage: " + other.Storage.PrimaryNode.LoggingName);
                    else
                        m_logger.debugLog("Hostile receiver in range: " + other.LoggingName + ", existing storage: " + other.Storage.PrimaryNode.LoggingName);
                return CommunicationType.None;
            }

            // test block connection
            if (this.m_comp_blockAttach != null && other.m_comp_blockAttach != null &&
                this.m_comp_blockAttach.IsWorking && other.m_comp_blockAttach.IsWorking &&
                AttachedGrid.IsGridAttached(this.m_comp_blockAttach.CubeGrid, other.m_comp_blockAttach.CubeGrid, AttachedGrid.AttachmentKind.Terminal))
                return CommunicationType.TwoWay;

            // test laser
            if (this.m_comp_laser != null && other.m_comp_laser != null && this.m_comp_laser.IsConnectedTo(other.m_comp_laser))
                return CommunicationType.TwoWay;

            // test radio
            if (this.m_comp_radio != null && other.m_comp_radio != null)
            {
                // check radio antenna to radio antenna
                CommunicationType radioResult;
                radioResult = this.m_comp_radio.TestConnection(other.m_comp_radio);
                if (radioResult != CommunicationType.None)
                    return radioResult;

                // check beacon to radio antenna
                if (this.m_comp_radio.CanBroadcastPositionTo(other.m_comp_radio) && other.Storage != null)
                    if (s_sendPositionTo.Add(other.Storage))
                        m_logger.debugLog("Friendly receiver in range: " + other.LoggingName + ", new storage: " + other.Storage.PrimaryNode.LoggingName);
                    else
                        m_logger.debugLog("Friendly receiver in range: " + other.LoggingName + ", existing storage: " + other.Storage.PrimaryNode.LoggingName);
            }

            return CommunicationType.None;
        }
示例#10
0
        /// <summary>
        /// Checks for established connections between this node and another.
        /// </summary>
        /// <param name="other">the other node to check</param>
        /// <param name="id">the search id</param>
        /// <returns>true iff the nodes are connected.</returns>
        private bool IsConnectedTo(RelayNode other, int id)
        {
            m_lastSearchId = id;

            if (m_directConnect.Contains(other))
                return true;

            foreach (RelayNode node in m_directConnect)
                if (node.m_lastSearchId != id && node.IsConnectedTo(other, id))
                    return true;

            return false;
        }
示例#11
0
        /// <summary>
        /// Checks for established connections between this node and another.
        /// </summary>
        /// <param name="other">The other node to check</param>
        /// <returns>true iff the nodes are connected.</returns>
        private bool IsConnectedTo(RelayNode other)
        {
            if (this == other)
                return true;

            return IsConnectedTo(other, ++s_searchIdPool);
        }
示例#12
0
        /// <summary>
        /// Remove a network connection that data was pushed through.
        /// </summary>
        /// <param name="node">Node that was receiving data.</param>
        public void RemovePushTo(RelayNode node)
        {
            using (lock_pushTo_count.AcquireExclusiveUsing())
            {
                int count = m_pushTo_count[node];
                if (count == 1)
                    m_pushTo_count.Remove(node);
                else
                    m_pushTo_count[node] = count - 1;

                m_logger.debugLog("removed push to: " + node.LoggingName + ", count: " + (count - 1), Logger.severity.DEBUG);
            }
        }
示例#13
0
        /// <summary>
        /// Creates a new NetworkStorage with all the same LastSeen and Message. Used when nodes lose connection.
        /// </summary>
        /// <param name="primary">The node that will be the primary for the new storage.</param>
        /// <returns>A new storage that is a copy of this one.</returns>
        public RelayStorage Clone(RelayNode primary)
        {
            m_logger.debugLog("cloning, primary " + primary.LoggingName, Logger.severity.DEBUG);

            RelayStorage clone = new RelayStorage(primary);

            // locks need not be held on clone
            ForEachLastSeen(clone.m_lastSeen.Add);
            ForEachMessage(msg => clone.m_messages.Add(msg));

            return clone;
        }
示例#14
0
        /// <summary>
        /// Add a network connection that data will be pushed through.
        /// </summary>
        /// <param name="node">Node that will receive data.</param>
        public void AddPushTo(RelayNode node)
        {
            int count;
            using (lock_pushTo_count.AcquireExclusiveUsing())
            {
                if (!m_pushTo_count.TryGetValue(node, out count))
                    count = 0;
                m_pushTo_count[node] = count + 1;
            }

            m_logger.debugLog("added push to: " + node.LoggingName + ", count: " + (count + 1), Logger.severity.DEBUG);

            if (count != 0)
            {
                m_logger.debugLog("not first connection, no copy. count: " + count, Logger.severity.TRACE);
                return;
            }

            if (node.Storage == null)
            {
                m_logger.debugLog("target node has no storage, no copy. node: " + node.LoggingName, Logger.severity.TRACE);
                return;
            }

            if (node.Storage == this)
            {
                m_logger.debugLog("target node's storage is this, no copy. node: " + node.LoggingName, Logger.severity.TRACE);
                return;
            }

            foreach (RelayNode n in m_pushTo_count.Keys)
            {
                if (node == n || n.Storage == null)
                    continue;
                if (node.Storage == n.Storage)
                {
                    m_logger.debugLog("already pushing to storage, no copy. node: " + node.LoggingName + ", node.Storage: " + node.Storage.PrimaryNode.LoggingName +
                        ", n: " + n.LoggingName + ", n.Storage: " + n.Storage.PrimaryNode.LoggingName, Logger.severity.TRACE);
                    return;
                }
            }

            CopyTo(node.Storage);
        }
示例#15
0
 private bool IsConnected(RelayNode node)
 {
     return(!node.Block.Closed && node.Block.IsWorking && m_block.canConsiderFriendly(node.Block) && AttachedGrid.IsGridAttached(m_block.CubeGrid, node.Block.CubeGrid, AttachedGrid.AttachmentKind.Terminal));
 }
示例#16
0
 public ShipControllerBlock(IMyCubeBlock block)
 {
     m_logger = new Logger(GetType().Name, block);
     CubeBlock = block;
     Pseudo = new PseudoBlock(block);
     NetworkNode = new RelayNode(block);
     AutopilotTerminal = new AutopilotTerminal(block);
 }