コード例 #1
0
            public void Setup(List <IMyMotorStator> rotors, IngameTime ingameTime, DeadzoneProvider deadzoneProvider, string azimuthTag, string elevationTag)
            {
                this.deadzoneProvider = deadzoneProvider;
                this.ingameTime       = ingameTime;

                List <IMyMotorStator> elevation = rotors.Where(x => x.CustomName.Contains(elevationTag)).ToList();
                IMyMotorStator        azimuth   = rotors.First(x => x.CustomName.Contains(azimuthTag));

                defaultDir = azimuth.WorldMatrix.Forward;

                List <IMyMotorStator> cannonBases = Select(elevation);

                List <RotorControl.RotorReferencePair> elevationPairs = new List <RotorControl.RotorReferencePair>();

                for (int i = 0; i < elevation.Count; i++)
                {
                    elevationPairs.Add(new RotorControl.RotorReferencePair {
                        rotor = elevation[i], reference = cannonBases[i]
                    });
                }

                RotorControl.RotorReferencePair azimuthPair = new RotorControl.RotorReferencePair {
                    rotor = azimuth, reference = cannonBases[0]
                };

                rotorControl          = new RotorControl(azimuthPair, elevationPairs);
                rotorControl.onTarget = OnTarget;

                #region configuration
                turretConfig = new INISerializer("TurretConfig");

                turretConfig.AddValue("azimuthMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("elevationMultiplier", x => double.Parse(x), -1.0);
                turretConfig.AddValue("salvoSize", x => int.Parse(x), 3);
                turretConfig.AddValue("salvoTimeout", x => double.Parse(x), 2.5);

                if (rotorControl.azimuth.rotor.CustomData == "")
                {
                    string temp = rotorControl.azimuth.rotor.CustomData;
                    turretConfig.FirstSerialization(ref temp);
                    rotorControl.azimuth.rotor.CustomData = temp;
                }
                else
                {
                    turretConfig.DeSerialize(rotorControl.azimuth.rotor.CustomData);
                }
                #endregion

                foreach (var cannonbase in cannonBases)
                {
                    var launcher = new RotorLauncher(cannonbase, ingameTime, salvoTimeout);
                    launchers.Add(launcher);
                }
            }
コード例 #2
0
            private List <IMyMotorStator> Select(List <IMyMotorStator> elevation)
            {
                var tmplist = new List <IMyMotorStator>();

                for (int i = 0; i < elevation.Count; i++)
                {
                    var tmpRot = RotorLauncher.Selector(elevation[i].TopGrid);
                    if (tmpRot != null)
                    {
                        tmplist.Add(tmpRot);
                    }
                    else
                    {
                        elevation.RemoveAt(i);
                    }
                }
                return(tmplist);
            }