예제 #1
0
        /// <summary>
        /// <para>Scripts that use UpdateManager and run on a server shall be added here.</para>
        /// </summary>
        private void RegisterScripts_Server()
        {
            #region Autopilot

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

            Action <IMyCubeBlock> construct = block => {
                if (ShipAutopilot.IsAutopilotBlock(block))
                {
                    var sca = new ShipAutopilot(block);
                    RegisterForUpdates(ShipAutopilot.UpdateFrequency, sca.Update, block);
                    RegisterForUpdates(100, sca.m_block.NetworkNode.Update100, block);
                    //RadarEquipment r = new RadarEquipment(block, apRadar, block);
                    //RegisterForUpdates(100, r.Update100, block);
                }
            };

            RegisterForBlock(typeof(MyObjectBuilder_Cockpit), construct);
            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl))
            {
                RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), construct);
            }

            #endregion

            #region Weapons

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowHacker))
            {
                RegisterForBlock(typeof(MyObjectBuilder_LandingGear), block => {
                    if (Hacker.IsHacker(block))
                    {
                        Hacker h = new Hacker(block);
                        RegisterForUpdates(10, h.Update10, block);
                    }
                });
            }
            else
            {
                Log.DebugLog("Hacker is disabled in settings");
            }

            #endregion

            #region Solar

            {
                SunProperties sun = new SunProperties();
                RegisterForUpdates(10, sun.Update10);
            }
            RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => {
                Solar s = new Solar(block);
                RegisterForUpdates(100, s.Update100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => {
                Solar s = new Solar(block);
                RegisterForUpdates(100, s.Update100, block);
            });

            #endregion

            RegisterForBlock(typeof(MyObjectBuilder_OreDetector), block => {
                var od = new OreDetector(block);
                RegisterForUpdates(1000, od.Update, block);
            });
        }
예제 #2
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(new MyObjectBuilderType[] { typeof(MyObjectBuilder_MotorStator), typeof(MyObjectBuilder_MotorAdvancedStator), typeof(MyObjectBuilder_MotorSuspension) },
                             block => RegisterForUpdates(100, (new StatorRotor.Stator(block)).Update, block));

            RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => {
                Piston.PistonBase pistonBase = new Piston.PistonBase(block);
                RegisterForUpdates(100, pistonBase.Update, 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);
                }
            });

            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

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                //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 (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl))
                {
                    RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct);
                }
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct);
            }

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAirResistanceBeta))
            {
                RegisterForGrid(grid => {
                    AeroEffects aero = new AeroEffects(grid);
                    RegisterForUpdates(1, aero.Update1, grid);
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        RegisterForUpdates(100, aero.Update100, grid);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), block => RegisterForUpdates(1, (new CockpitTerminal(block)).Update1, block));
            }

            #endregion

            #region Radar

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar))
            {
                RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForUpdates(100, RadarEquipment.UpdateAll);
            }

            #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 => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        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 => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        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 => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        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 => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        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
            {
                Log.DebugLog("Weapon Control is disabled", Logger.severity.INFO);
            }

            #endregion

            #region Solar

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => new Solar(block));
                RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => new Solar(block));
            }

            #endregion

            new ChatHandler();
            Globals.Update100();
            RegisterForUpdates(100, Globals.Update100);

            Action <IMyCubeBlock> act = (block) => MainCockpitFix.AddController((IMyShipController)block);
            RegisterForBlock(typeof(MyObjectBuilder_Cockpit), act);
            RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), act);
        }