Exemplo n.º 1
0
Arquivo: Ammo.cs Projeto: zrisher/ARMS
        private Ammo(MyAmmoMagazineDefinition ammoMagDef)
        {
            MyAmmoDefinition ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagDef.AmmoDefinitionId);

            this.AmmoDefinition     = ammoDef;
            this.MissileDefinition  = AmmoDefinition as MyMissileAmmoDefinition;
            this.MagazineDefinition = ammoMagDef;

            if (MissileDefinition != null && !MissileDefinition.MissileSkipAcceleration)
            {
                this.TimeToMaxSpeed     = (MissileDefinition.DesiredSpeed - MissileDefinition.MissileInitialSpeed) / MissileDefinition.MissileAcceleration;
                this.DistanceToMaxSpeed = (MissileDefinition.DesiredSpeed + MissileDefinition.MissileInitialSpeed) / 2 * TimeToMaxSpeed;
            }
            else
            {
                this.TimeToMaxSpeed     = 0;
                this.DistanceToMaxSpeed = 0;
            }

            Description = AmmoDescription.CreateFrom(AmmoDefinition);

            if (Description == null)
            {
                return;
            }

            if (Description.ClusterCooldown > 0f)
            {
                Log.DebugLog("Is a cluster missile");
                IsCluster = true;
            }
            if (!string.IsNullOrWhiteSpace(Description.Radar))
            {
                try
                {
                    RadarDefinition = new RadarEquipment.Definition();
                    XML_Amendments <RadarEquipment.Definition> ammender = new XML_Amendments <RadarEquipment.Definition>(RadarDefinition);
                    ammender.primarySeparator = new char[] { ',' };
                    ammender.AmendAll(Description.Radar, true);
                    RadarDefinition = ammender.Deserialize();
                    Log.DebugLog("Loaded description for radar", Logger.severity.DEBUG);
                }
                catch (Exception ex)
                {
                    Logger.DebugNotify("Failed to load radar description for an ammo", 10000, Logger.severity.ERROR);
                    Log.AlwaysLog("Failed to load radar description for an ammo", Logger.severity.ERROR);
                    Log.AlwaysLog("Exception: " + ex, Logger.severity.ERROR);
                    RadarDefinition = null;
                }
            }
        }
Exemplo n.º 2
0
        private Ammo(MyAmmoMagazineDefinition ammoMagDef)
        {
            MyAmmoDefinition ammoDef = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagDef.AmmoDefinitionId);
            this.myLogger = new Logger("Ammo", () => ammoMagDef.Id.ToString(), () => ammoDef.Id.ToString());

            this.AmmoDefinition = ammoDef;
            this.MissileDefinition = AmmoDefinition as MyMissileAmmoDefinition;
            this.MagazineDefinition = ammoMagDef;

            if (MissileDefinition != null && !MissileDefinition.MissileSkipAcceleration)
            {
                this.TimeToMaxSpeed = (MissileDefinition.DesiredSpeed - MissileDefinition.MissileInitialSpeed) / MissileDefinition.MissileAcceleration;
                this.DistanceToMaxSpeed = (MissileDefinition.DesiredSpeed + MissileDefinition.MissileInitialSpeed) / 2 * TimeToMaxSpeed;
            }
            else
            {
                this.TimeToMaxSpeed = 0;
                this.DistanceToMaxSpeed = 0;
            }

            Description = AmmoDescription.CreateFrom(AmmoDefinition);

            if (Description == null)
                return;

            if (Description.ClusterCooldown > 0f)
            {
                myLogger.debugLog("Is a cluster missile");
                IsCluster = true;
            }
            if (!string.IsNullOrWhiteSpace(Description.Radar))
            {
                try
                {
                    RadarDefinition = new RadarEquipment.Definition();
                    XML_Amendments<RadarEquipment.Definition> ammender = new XML_Amendments<RadarEquipment.Definition>(RadarDefinition);
                    ammender.primarySeparator = new char[] { ',' };
                    ammender.AmendAll(Description.Radar, true);
                    RadarDefinition = ammender.Deserialize();
                    myLogger.debugLog("Loaded description for radar", Logger.severity.DEBUG);
                }
                catch (Exception ex)
                {
                    Logger.debugNotify("Failed to load radar description for an ammo", 10000, Logger.severity.ERROR);
                    myLogger.alwaysLog("Failed to load radar description for an ammo", Logger.severity.ERROR);
                    myLogger.alwaysLog("Exception: " + ex, Logger.severity.ERROR);
                    RadarDefinition = null;
                }
            }
        }
Exemplo n.º 3
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
                myLogger.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);
            });

            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bImmortalMiner))
                new DamageHandler();
        }
Exemplo n.º 4
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();
        }