예제 #1
0
        private PlatformState GetParts(WeaponComponent comp)
        {
            for (int i = 0; i < Structure.MuzzlePartNames.Length; i++)
            {
                _orderToCreate.Add(i);
            }

            if (Structure.PrimaryWeapon > 0)
            {
                var tmpPos = _orderToCreate[Structure.PrimaryWeapon];
                _orderToCreate[tmpPos] = _orderToCreate[0];
                _orderToCreate[0]      = tmpPos;
            }

            Parts.CheckSubparts();

            foreach (var i in _orderToCreate)
            {
                var          muzzlePartHash = Structure.MuzzlePartNames[i];
                WeaponSystem system;
                if (!Structure.WeaponSystems.TryGetValue(muzzlePartHash, out system))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid weapon system, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                var muzzlePartName = muzzlePartHash.String != "Designator" ? muzzlePartHash.String : system.ElevationPartName.String;

                MyEntity muzzlePartEntity;
                if (!Parts.NameToEntity.TryGetValue(muzzlePartName, out muzzlePartEntity))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid barrelPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }
                foreach (var part in Parts.NameToEntity)
                {
                    part.Value.OnClose += comp.SubpartClosed;
                    break;
                }

                //compatability with old configs of converted turrets
                var azimuthPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.AzimuthPartName.String) ? "MissileTurretBase1" : system.AzimuthPartName.String : system.AzimuthPartName.String;

                var elevationPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.ElevationPartName.String) ? "MissileTurretBarrels" : system.ElevationPartName.String : system.ElevationPartName.String;

                MyEntity azimuthPart = null;
                if (!Parts.NameToEntity.TryGetValue(azimuthPartName, out azimuthPart))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Weapon: {system.WeaponName} Invalid azimuthPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                MyEntity elevationPart = null;
                if (!Parts.NameToEntity.TryGetValue(elevationPartName, out elevationPart))
                {
                    Log.Line($"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) Invalid elevationPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                azimuthPart.NeedsWorldMatrix   = true;
                elevationPart.NeedsWorldMatrix = true;

                var weapon = Weapons[i] = new Weapon(muzzlePartEntity, system, i, comp, Parts, elevationPart, azimuthPart, azimuthPartName, elevationPartName);

                SetupUi(weapon);

                if (!comp.Debug && weapon.System.Values.HardPoint.Other.Debug)
                {
                    comp.Debug = true;
                }

                if (weapon.System.Values.HardPoint.Ai.TurretController)
                {
                    if (weapon.System.Values.HardPoint.Ai.PrimaryTracking && comp.TrackingWeapon == null)
                    {
                        comp.TrackingWeapon = weapon;
                    }

                    if (weapon.AvCapable && weapon.System.HardPointRotationSound)
                    {
                        RotationSound.Init(weapon.System.Values.HardPoint.Audio.HardPointRotationSound, false);
                    }
                }
            }
            _orderToCreate.Clear();

            CompileTurret(comp);

            State = PlatformState.Inited;

            return(State);
        }
        private PlatformState GetParts(WeaponComponent comp)
        {
            Parts.CheckSubparts();
            for (int i = 0; i < Structure.MuzzlePartNames.Length; i++)
            {
                var muzzlePartHash = Structure.MuzzlePartNames[i];
                var barrelCount    = Structure.WeaponSystems[muzzlePartHash].Barrels.Length;

                WeaponSystem system;
                if (!Structure.WeaponSystems.TryGetValue(muzzlePartHash, out system))
                {
                    Log.Line($"Invalid weapon system, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                var wepAnimationSet = comp.Session.CreateWeaponAnimationSet(system, Parts);

                var muzzlePartName = muzzlePartHash.String != "Designator" ? muzzlePartHash.String : system.ElevationPartName.String;


                MyEntity muzzlePartEntity;
                if (!Parts.NameToEntity.TryGetValue(muzzlePartName, out muzzlePartEntity))
                {
                    Log.Line($"Invalid barrelPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }
                foreach (var part in Parts.NameToEntity)
                {
                    part.Value.OnClose += comp.SubpartClosed;
                    break;
                }

                //compatability with old configs of converted turrets
                var azimuthPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.AzimuthPartName.String) ? "MissileTurretBase1" : system.AzimuthPartName.String : system.AzimuthPartName.String;

                var elevationPartName = comp.BaseType == Turret?string.IsNullOrEmpty(system.ElevationPartName.String) ? "MissileTurretBarrels" : system.ElevationPartName.String : system.ElevationPartName.String;

                MyEntity azimuthPart = null;
                if (!Parts.NameToEntity.TryGetValue(azimuthPartName, out azimuthPart))
                {
                    Log.Line($"Invalid azimuthPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                MyEntity elevationPart = null;
                if (!Parts.NameToEntity.TryGetValue(elevationPartName, out elevationPart))
                {
                    Log.Line($"Invalid elevationPart, I am crashing now Dave.");
                    State = PlatformState.Invalid;
                    return(State);
                }

                foreach (var triggerSet in wepAnimationSet)
                {
                    for (int j = 0; j < triggerSet.Value.Length; j++)
                    {
                        comp.AllAnimations.Add(triggerSet.Value[j]);
                    }
                }

                Weapons[i] = new Weapon(muzzlePartEntity, system, i, comp, wepAnimationSet)
                {
                    Muzzles     = new Muzzle[barrelCount],
                    Dummies     = new Dummy[barrelCount],
                    AzimuthPart = new PartInfo {
                        Entity = azimuthPart
                    },
                    ElevationPart = new PartInfo {
                        Entity = elevationPart
                    },
                    AzimuthOnBase = azimuthPart.Parent == comp.MyCube,
                    AiOnlyWeapon  = comp.BaseType != Turret || (azimuthPartName != "MissileTurretBase1" && elevationPartName != "MissileTurretBarrels" && azimuthPartName != "InteriorTurretBase1" && elevationPartName != "InteriorTurretBase2" && azimuthPartName != "GatlingTurretBase1" && elevationPartName != "GatlingTurretBase2")
                };

                var weapon = Weapons[i];
                SetupUi(weapon);

                if (!comp.Debug && weapon.System.Values.HardPoint.Other.Debug)
                {
                    comp.Debug = true;
                }

                if (weapon.System.Values.HardPoint.Ai.TurretController)
                {
                    if (weapon.System.Values.HardPoint.Ai.PrimaryTracking && comp.TrackingWeapon == null)
                    {
                        comp.TrackingWeapon = weapon;
                    }

                    if (weapon.AvCapable && weapon.System.HardPointRotationSound)
                    {
                        RotationSound.Init(weapon.System.Values.HardPoint.Audio.HardPointRotationSound, false);
                    }
                }
            }
            CompileTurret(comp);

            State = PlatformState.Inited;

            return(State);
        }