コード例 #1
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_WeaponDefinition;

            MyDebug.AssertDebug(ob != null);

            this.WeaponAmmoDatas      = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.NoAmmoSound          = new MySoundPair(ob.NoAmmoSoundName);
            this.ReloadSound          = new MySoundPair(ob.ReloadSoundName);
            this.DeviateShotAngle     = MathHelper.ToRadians(ob.DeviateShotAngle);
            this.ReleaseTimeAfterFire = ob.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan  = ob.MuzzleFlashLifeSpan;

            this.AmmoMagazinesId = new MyDefinitionId[ob.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                var ammoMagazine = ob.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(ammoMagazine.Type, ammoMagazine.Subtype);

                var        ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType     = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     errorMessage = null;
                switch (ammoType)
                {
                case MyAmmoType.HighSpeed:
                    MyDebug.AssertDebug(ob.ProjectileAmmoData != null, "No weapon ammo data specified for projectile ammo");
                    if (ob.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.HighSpeed] = new MyWeaponAmmoData(ob.ProjectileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                    break;

                case MyAmmoType.Missile:
                    MyDebug.AssertDebug(ob.MissileAmmoData != null, "No weapon ammo data specified for missile ammo");
                    if (ob.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.Missile] = new MyWeaponAmmoData(ob.MissileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    MyDefinitionErrors.Add(Context, errorMessage, TErrorSeverity.Critical);
                }
            }
        }
コード例 #2
0
 public void AddDefinitionSafe <T>(T definition, MyModContext context, string file)
     where T : MyDefinitionBase, V
 {
     if (definition.Id.TypeId != MyObjectBuilderType.Invalid)
     {
         this[definition.Id] = definition;
     }
     else
     {
         MyDefinitionErrors.Add(context, "Invalid definition id", ErrorSeverity.Error);
     }
 }
コード例 #3
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            var cbuilder = builder as MyObjectBuilder_CockpitDefinition;

            GlassModel    = cbuilder.GlassModel;
            InteriorModel = cbuilder.InteriorModel;

            CharacterAnimation = cbuilder.CharacterAnimation ?? cbuilder.CharacterAnimationFile;

            if (!String.IsNullOrEmpty(cbuilder.CharacterAnimationFile))
            {
                MyDefinitionErrors.Add(Context, "<CharacterAnimation> tag must contain animation name (defined in Animations.sbc) not the file: " + cbuilder.CharacterAnimationFile, TErrorSeverity.Error);
            }

            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(CharacterAnimation));

            OxygenCapacity = cbuilder.OxygenCapacity;
            IsPressurized  = cbuilder.IsPressurized;
        }
コード例 #4
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_CockpitDefinition definition = builder as MyObjectBuilder_CockpitDefinition;

            base.GlassModel    = definition.GlassModel;
            base.InteriorModel = definition.InteriorModel;
            string characterAnimation = definition.CharacterAnimation;

            this.CharacterAnimation = characterAnimation ?? definition.CharacterAnimationFile;
            if (!string.IsNullOrEmpty(definition.CharacterAnimationFile))
            {
                MyDefinitionErrors.Add(base.Context, "<CharacterAnimation> tag must contain animation name (defined in Animations.sbc) not the file: " + definition.CharacterAnimationFile, TErrorSeverity.Error, true);
            }
            this.OxygenCapacity = definition.OxygenCapacity;
            this.IsPressurized  = definition.IsPressurized;
            this.HasInventory   = definition.HasInventory;
            this.HUD            = definition.HUD;
            this.ScreenAreas    = (definition.ScreenAreas != null) ? definition.ScreenAreas.ToList <ScreenArea>() : null;
        }
コード例 #5
0
        private void InitMountPoints(MyObjectBuilder_CubeBlockDefinition def)
        {
            if (MountPoints != null)
            {
                return;
            }

            var center = (Size - 1) / 2;

            // Order of block sides: right, top, front, left, bottom, back
            // Right = +X;    Top = +Y; Front = +Z
            //  Left = -X; Bottom = -Y;  Back = -Z
            // Side origins are always in lower left when looking at the side from outside.
            const float OFFSET_CONST   = 0.001f;
            const float THICKNESS_HALF = 0.0004f;

            if (!Context.IsBaseGame)
            {
                if (def.MountPoints != null && def.MountPoints.Length == 0)
                {
                    def.MountPoints = null;
                    string msg = "Obsolete default definition of mount points in " + def.Id;
                    MyDefinitionErrors.Add(Context, msg, ErrorSeverity.Warning);
                }
            }

            if (def.MountPoints == null)
            {
                // If there are no mount points defined, cover whole walls.
                List <MountPoint> mps = new List <MountPoint>(6);
                Vector3I          normalRight, normalLeft, normalTop, normalBottom, normalFront, normalBack;
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[0], out normalRight);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[1], out normalTop);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[2], out normalFront);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[3], out normalLeft);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[4], out normalBottom);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[5], out normalBack);

                // Right and left walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.Z - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 0, Size, out s1);
                    TransformMountPointPosition(ref end, 0, Size, out e1);
                    TransformMountPointPosition(ref start, 3, Size, out s2);
                    TransformMountPointPosition(ref end, 3, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalRight
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalLeft
                    });
                }

                // Top and bottom walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Z - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 1, Size, out s1);
                    TransformMountPointPosition(ref end, 1, Size, out e1);
                    TransformMountPointPosition(ref start, 4, Size, out s2);
                    TransformMountPointPosition(ref end, 4, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalTop
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBottom
                    });
                }

                // Front and back walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 2, Size, out s1);
                    TransformMountPointPosition(ref end, 2, Size, out e1);
                    TransformMountPointPosition(ref start, 5, Size, out s2);
                    TransformMountPointPosition(ref end, 5, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalFront
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBack
                    });
                }

                MountPoints = mps.ToArray();
                return;
            }
            else
            {
                var mpBuilders = def.MountPoints;
                MountPoints = new MountPoint[mpBuilders.Length];
                for (int i = 0; i < MountPoints.Length; ++i)
                {
                    var mpBuilder = mpBuilders[i]; // 'mp' stands for mount point
                    // I shrink mounts points a little to avoid overlaps when they are very close.
                    var mpStart  = new Vector3((Vector2)mpBuilder.Start + OFFSET_CONST, THICKNESS_HALF);
                    var mpEnd    = new Vector3((Vector2)mpBuilder.End - OFFSET_CONST, -THICKNESS_HALF);
                    var sideIdx  = (int)mpBuilder.Side;
                    var mpNormal = Vector3I.Forward;
                    TransformMountPointPosition(ref mpStart, sideIdx, Size, out mpStart);
                    TransformMountPointPosition(ref mpEnd, sideIdx, Size, out mpEnd);
                    Vector3I.TransformNormal(ref mpNormal, ref m_mountPointTransforms[sideIdx], out mpNormal);
                    MountPoints[i].Start          = mpStart;
                    MountPoints[i].End            = mpEnd;
                    MountPoints[i].Normal         = mpNormal;
                    MountPoints[i].ExclusionMask  = mpBuilder.ExclusionMask;
                    MountPoints[i].PropertiesMask = mpBuilder.PropertiesMask;
                }
            }
        }
コード例 #6
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_WeaponDefinition definition = builder as MyObjectBuilder_WeaponDefinition;

            this.WeaponAmmoDatas = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.WeaponEffects   = new MyWeaponEffect[(definition.Effects == null) ? 0 : definition.Effects.Length];
            if (definition.Effects != null)
            {
                for (int j = 0; j < definition.Effects.Length; j++)
                {
                    this.WeaponEffects[j] = new MyWeaponEffect(definition.Effects[j].Action, definition.Effects[j].Dummy, definition.Effects[j].Particle, definition.Effects[j].Loop, definition.Effects[j].InstantStop);
                }
            }
            this.PhysicalMaterial      = MyStringHash.GetOrCompute(definition.PhysicalMaterial);
            this.UseDefaultMuzzleFlash = definition.UseDefaultMuzzleFlash;
            this.NoAmmoSound           = new MySoundPair(definition.NoAmmoSoundName, true);
            this.ReloadSound           = new MySoundPair(definition.ReloadSoundName, true);
            this.SecondarySound        = new MySoundPair(definition.SecondarySoundName, true);
            this.DeviateShotAngle      = MathHelper.ToRadians(definition.DeviateShotAngle);
            this.ReleaseTimeAfterFire  = definition.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan   = definition.MuzzleFlashLifeSpan;
            this.ReloadTime            = definition.ReloadTime;
            this.DamageMultiplier      = definition.DamageMultiplier;
            this.RangeMultiplier       = definition.RangeMultiplier;
            this.UseRandomizedRange    = definition.UseRandomizedRange;
            this.AmmoMagazinesId       = new MyDefinitionId[definition.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                MyObjectBuilder_WeaponDefinition.WeaponAmmoMagazine magazine = definition.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(magazine.Type, magazine.Subtype);
                MyAmmoMagazineDefinition ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     str      = null;
                if (ammoType == MyAmmoType.HighSpeed)
                {
                    if (definition.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[0] = new MyWeaponAmmoData(definition.ProjectileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                }
                else
                {
                    if (ammoType != MyAmmoType.Missile)
                    {
                        throw new NotImplementedException();
                    }
                    if (definition.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[1] = new MyWeaponAmmoData(definition.MissileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                }
                if (!string.IsNullOrEmpty(str))
                {
                    MyDefinitionErrors.Add(base.Context, str, TErrorSeverity.Critical, true);
                }
            }
        }
コード例 #7
0
        private void InitMountPoints(MyObjectBuilder_CubeBlockDefinition def)
        {
            if (MountPoints != null)
            {
                return;
            }

            var center = (Size - 1) / 2;


            if (!Context.IsBaseGame)
            {
                if (def.MountPoints != null && def.MountPoints.Length == 0)
                {
                    def.MountPoints = null;
                    string msg = "Obsolete default definition of mount points in " + def.Id;
                    MyDefinitionErrors.Add(Context, msg, ErrorSeverity.Warning);
                }
            }

            if (def.MountPoints == null)
            {
                // If there are no mount points defined, cover whole walls.
                List <MountPoint> mps = new List <MountPoint>(6);
                Vector3I          normalRight, normalLeft, normalTop, normalBottom, normalFront, normalBack;
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[0], out normalRight);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[1], out normalTop);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[2], out normalFront);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[3], out normalLeft);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[4], out normalBottom);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[5], out normalBack);

                // Right and left walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.Z - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 0, Size, out s1);
                    TransformMountPointPosition(ref end, 0, Size, out e1);
                    TransformMountPointPosition(ref start, 3, Size, out s2);
                    TransformMountPointPosition(ref end, 3, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalRight, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalLeft, Enabled = true
                    });
                }

                // Top and bottom walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Z - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 1, Size, out s1);
                    TransformMountPointPosition(ref end, 1, Size, out e1);
                    TransformMountPointPosition(ref start, 4, Size, out s2);
                    TransformMountPointPosition(ref end, 4, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalTop, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBottom, Enabled = true
                    });
                }

                // Front and back walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 2, Size, out s1);
                    TransformMountPointPosition(ref end, 2, Size, out e1);
                    TransformMountPointPosition(ref start, 5, Size, out s2);
                    TransformMountPointPosition(ref end, 5, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalFront, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBack, Enabled = true
                    });
                }

                MountPoints = mps.ToArray();
                return;
            }
            else
            {
                Debug.Assert(m_tmpMounts.Count == 0);
                SetMountPoints(ref MountPoints, def.MountPoints, m_tmpMounts);

                if (def.BuildProgressModels != null)
                {
                    for (int index = 0; index < def.BuildProgressModels.Count; ++index)
                    {
                        var defBuildProgressModel = BuildProgressModels[index];
                        if (defBuildProgressModel == null)
                        {
                            continue;
                        }

                        var obBuildProgressModel = def.BuildProgressModels[index];
                        if (obBuildProgressModel.MountPoints == null)
                        {
                            continue;
                        }

                        foreach (var mountPoint in obBuildProgressModel.MountPoints)
                        {
                            int sideId = (int)mountPoint.Side;
                            if (!m_tmpIndices.Contains(sideId))
                            {
                                m_tmpMounts.RemoveAll((mount) => { return((int)mount.Side == sideId); });
                                m_tmpIndices.Add(sideId);
                            }
                            m_tmpMounts.Add(mountPoint);
                        }
                        m_tmpIndices.Clear();
                        defBuildProgressModel.MountPoints = new MountPoint[m_tmpMounts.Count];
                        SetMountPoints(ref defBuildProgressModel.MountPoints, m_tmpMounts.ToArray(), null);
                    }
                }
                m_tmpMounts.Clear();
            }
        }