Exemple #1
0
            public static AmmoDescription CreateFrom(MyAmmoDefinition ammo)
            {
                if (string.IsNullOrWhiteSpace(ammo.DescriptionString))
                {
                    return(null);
                }

                AmmoDescription desc = new AmmoDescription();

                try
                {
                    XML_Amendments <AmmoDescription> ammender = new XML_Amendments <AmmoDescription>(desc);
                    ammender.primarySeparator = new char[] { ';' };
                    ammender.AmendAll(ammo.DescriptionString, true);
                    desc = ammender.Deserialize();
                    desc.CosAcquisitionAngle = (float)Math.Cos(desc.AcquisitionAngle);
                    return(desc);
                }
                catch (Exception ex)
                {
                    Logger.DebugNotify("Failed to load description for an ammo", 10000, Logger.severity.ERROR);
                    Logable Log = new Logable(ammo.Id.SubtypeName);
                    Log.AlwaysLog("Failed to load description for an ammo", Logger.severity.ERROR);
                    Log.AlwaysLog("Exception: " + ex, Logger.severity.ERROR);
                    return(null);
                }
            }
Exemple #2
0
        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;
                }
            }
        }
Exemple #3
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;
                }
            }
        }
Exemple #4
0
			public static AmmoDescription CreateFrom(MyAmmoDefinition ammo)
			{
				if (string.IsNullOrWhiteSpace(ammo.DescriptionString))
					return null;

				AmmoDescription desc = new AmmoDescription(ammo.Id.SubtypeName);
				try
				{
					XML_Amendments<AmmoDescription> ammender = new XML_Amendments<AmmoDescription>(desc);
					ammender.AmendAll(ammo.DescriptionString, true);
					return ammender.Deserialize();
				}
				catch (Exception ex)
				{
					Logger.debugNotify("Failed to load description for an ammo", 10000, Logger.severity.ERROR);
					desc.myLogger.alwaysLog("Failed to load description for an ammo", "CreateFrom()", Logger.severity.ERROR);
					desc.myLogger.alwaysLog("Exception: " + ex, "CreateFrom()", Logger.severity.ERROR);
					return null;
				}
			}
        private static WeaponDescription CreateFrom(MyCubeBlockDefinition definition)
        {
            if (string.IsNullOrWhiteSpace(definition.DescriptionString))
                return new WeaponDescription();

            WeaponDescription desc = new WeaponDescription();
            try
            {
                XML_Amendments<WeaponDescription> ammender = new XML_Amendments<WeaponDescription>(desc);
                ammender.AmendAll(definition.DescriptionString, true);
                return ammender.Deserialize();
            }
            catch (Exception ex)
            {
                Logger.debugNotify("Failed to load description for a weapon", 10000, Logger.severity.ERROR);
                Logger log = new Logger("WeaponDescription", () => definition.Id.ToString());
                log.alwaysLog("Failed to load description for a weapon", Logger.severity.ERROR);
                log.alwaysLog("Exception: " + ex, Logger.severity.ERROR);
                return new WeaponDescription();
            }
        }
Exemple #6
0
        private static Definition GetDefinition(IMyCubeBlock block)
        {
            Definition result;
            SerializableDefinitionId ID = block.BlockDefinition;

            if (AllDefinitions.TryGetValue(ID, out result))
            {
                staticLogger.debugLog("definition already loaded for " + ID);
                return(result);
            }

            staticLogger.debugLog("creating new definition for " + ID);
            result = new Definition();

            MyCubeBlockDefinition def = block.GetCubeBlockDefinition();

            if (def == null)
            {
                throw new NullReferenceException("no block definition found for " + block.getBestName());
            }

            if (string.IsNullOrWhiteSpace(def.DescriptionString))
            {
                staticLogger.debugLog("No description, using defaults for " + ID, Logger.severity.WARNING);
                result.Radar = true;
                AllDefinitions.Add(ID, result);
                return(result);
            }

            XML_Amendments <Definition> ammend = new XML_Amendments <Definition>(result);

            ammend.AmendAll(def.DescriptionString, true);
            result = ammend.Deserialize();

            //staticLogger.debugLog("new definition:\n" + MyAPIGateway.Utilities.SerializeToXML<Definition>(result), "GetDefinition()");
            AllDefinitions.Add(ID, result);
            return(result);
        }
Exemple #7
0
        private static WeaponDescription CreateFrom(MyCubeBlockDefinition definition)
        {
            if (string.IsNullOrWhiteSpace(definition.DescriptionString))
            {
                return(new WeaponDescription());
            }

            WeaponDescription desc = new WeaponDescription();

            try
            {
                XML_Amendments <WeaponDescription> ammender = new XML_Amendments <WeaponDescription>(desc);
                ammender.AmendAll(definition.DescriptionString, true);
                return(ammender.Deserialize());
            }
            catch (Exception ex)
            {
                Logger.DebugNotify("Failed to load description for a weapon", 10000, Logger.severity.ERROR);
                Logable Log = new Logable(definition.Id.ToString());
                Log.AlwaysLog("Failed to load description for a weapon", Logger.severity.ERROR);
                Log.AlwaysLog("Exception: " + ex, Logger.severity.ERROR);
                return(new WeaponDescription());
            }
        }