Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
		/// <summary>
		/// <para>Scripts that use UpdateManager and run on a server shall be added here.</para>
		/// </summary>
		private void RegisterScripts_Server()
		{
			#region Autopilot

			if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
				RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), (IMyCubeBlock block) => {
					if (ShipController_Autopilot.IsAutopilotBlock(block))
					{
						var sca = new ShipController_Autopilot(block);
						RegisterForUpdates(ShipController_Autopilot.UpdateFrequency, sca.Update, block);
					}
				});
			RegisterForBlock(typeof(MyObjectBuilder_Cockpit), (IMyCubeBlock block) => {
				if (ShipController_Autopilot.IsAutopilotBlock(block))
				{
					var sca = new ShipController_Autopilot(block);
					RegisterForUpdates(ShipController_Autopilot.UpdateFrequency, sca.Update, block);
				}
			});

			#endregion

			#region Antenna Communication

			RegisterForBlock(typeof(MyObjectBuilder_Beacon), (IMyCubeBlock block) => {
				Beacon newBeacon = new Beacon(block);
				RegisterForUpdates(100, newBeacon.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_TextPanel), (IMyCubeBlock block) => {
				TextPanel newTextPanel = new TextPanel(block);
				RegisterForUpdates(100, newTextPanel.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), (IMyCubeBlock block) => {
				LaserAntenna newLA = new LaserAntenna(block);
				RegisterForUpdates(100, newLA.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), (IMyCubeBlock block) => {
				ProgrammableBlock newPB = new ProgrammableBlock(block);
				RegisterForUpdates(100, newPB.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (IMyCubeBlock block) => {
				RadioAntenna newRA = new RadioAntenna(block);
				RegisterForUpdates(100, newRA.UpdateAfterSimulation100, block);
			});
			RegisterForPlayer((player) => {
				Player p = new Player(player);
				RegisterForUpdates(100, p.Update100, player, Player.OnLeave);
			});
			if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
				RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), (IMyCubeBlock block) => {
					if (ShipController_Autopilot.IsAutopilotBlock(block))
						new ShipController(block);
					// Does not receive Updates
				});
			RegisterForBlock(typeof(MyObjectBuilder_Cockpit), (IMyCubeBlock block) => {
				if (ShipController_Autopilot.IsAutopilotBlock(block))
					new ShipController(block);
				// Does not receive Updates
			});

			#endregion

			#region Weapons

			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);
						}
					};

					RegisterForUpdates(1, GuidedMissile.Update1);
					RegisterForUpdates(10, GuidedMissile.Update10);
					RegisterForUpdates(100, GuidedMissile.Update100);
				}
				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

				#region Disruption

				RegisterForUpdates(10, EMP.Update);
				RegisterForUpdates(10, AirVentDepressurize.Update);
				RegisterForUpdates(10, DoorLock.Update);
				RegisterForUpdates(10, GravityReverse.Update);
				RegisterForUpdates(10, DisableTurret.Update);
				RegisterForUpdates(10, TraitorTurret.Update);

				RegisterForBlock(typeof(MyObjectBuilder_LandingGear), block => {
					if (Hacker.IsHacker(block))
					{
						Hacker h = new Hacker(block);
						RegisterForUpdates(10, h.Update10, block);
					}
				});

				#endregion
			}
			else
				myLogger.debugLog("Weapon Control is disabled", "RegisterScripts_Server()", Logger.severity.INFO);

			#endregion

			#region Solar

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

			#endregion

			#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) => {
				new LandingGear(block);
			});

			#endregion

			RegisterForBlock(typeof(MyObjectBuilder_OreDetector), block => {
				var od = new OreDetector(block);
				RegisterForUpdates(1000, od.Update, block);
			});

			RegisterForPlayerLeaves(UserSettings.OnPlayerLeave);
		}