示例#1
0
 public void Fire(ServerShip ship, bool isLeft, int number, int idTarget, Ecm jammer)
 {
     lock (m_locker)
     {
         if (ship.Missiles == 0)
         {
             return;
         }
         var target = Ships.ById(idTarget);
         if (target == null || isLeft != ship.IsLeftBoard(target))
         {
             return;
         }
         var board        = isLeft ? ship.Left : ship.Right;
         var missileClass = board.GetRack(number).MissileClass;
         if (!board.Fire(number))
         {
             return;
         }
         ship.Missiles--;
         int id      = Interlocked.Increment(ref IdNext);
         var missile = new Missile
         {
             Id           = id,
             Position     = ship.Position,
             Speed        = ship.Speed,
             Acceleration = ship.Acceleration,
         };
         var control = new MissileControl
         {
             Id          = id,
             Arrow       = missile,
             Origin      = ship,
             Target      = target,
             IdOrigin    = ship.Id,
             IdTarget    = target.Id,
             Jammer      = jammer,
             Thrust      = missileClass.Acceleration,
             Remaining   = missileClass.FlyTime,
             HitDistance = missileClass.HitDistance,
             Started     = Time.TotalSeconds,
         };
         Missiles.Add(id, control);
     }
 }
示例#2
0
文件: Program.cs 项目: zzfeed/GNFS
        static BigInteger EcmSandbox(BigInteger n, ulong bound, ulong curveCount)
        {
            Console.WriteLine(string.Format("n={0} ({1} digits)", n, n.ToString().Length));

            CurveGenerator g     = new CurveGenerator();
            BigInteger     gcd   = 1;
            var            timer = new Stopwatch();
            ulong          b1    = bound;
            ulong          b2    = b1 * 100;
            ulong          b3    = b2 + b1 * 100;

            timer.Start();
            var        curves = new Curve[curveCount];
            BigInteger factor = 1;

            curves = curves.Select(x =>
            {
                var c = g.GenerateMontgomeryCurve(n, out gcd);
                if (gcd > 1)
                {
                    factor = gcd;
                }
                return(c);
            }).ToArray();
            if (factor > 1)
            {
                Console.WriteLine("Factor found!");
                Console.WriteLine(factor);
                timer.Stop();
                Console.WriteLine(timer.Elapsed);
                return(factor);
            }
            else
            {
                var count = 0;
                Console.Write("\r{0}/{1} curves   ", count++, curveCount);
                foreach (var curve in curves)
                {
                    var ecm = new Ecm();
                    factor = ecm.Calculate(curve, b1, b2, b3);



                    if (n % factor != 0)
                    {
                        Console.WriteLine("ERROR!");
                    }
                    else if (factor > 1)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Factor found!");
                        Console.WriteLine(factor);
                        timer.Stop();
                        Console.WriteLine(timer.Elapsed);
                        break;
                    }
                    else
                    {
                        Console.Write("\r{0}/{1} curves   ", count++, curveCount);
                    }
                }
            }
            return(factor);
        }
示例#3
0
        public Result LoadDirectory(string path)
        {
            var returnResult = new Result(string.Format("Loading object data from \"{0}\"", path));

            path = PathUtil.EndWithPathSeperator(path);

            var subDirNames            = "";
            var subDirStructures       = "";
            var subDirBrain            = "";
            var subDirBody             = "";
            var subDirPropulsion       = "";
            var subDirBodyPropulsion   = "";
            var subDirConstruction     = "";
            var subDirSensor           = "";
            var subDirRepair           = "";
            var subDirTemplates        = "";
            var subDirWeapons          = "";
            var subDirEcm              = "";
            var subDirFeatures         = "";
            var subDirTexpages         = "";
            var subDirAssignWeapons    = "";
            var subDirStructureWeapons = "";
            var subDirPiEs             = "";

            subDirNames            = "messages".CombinePathWith("strings").CombinePathWith("names.txt");
            subDirStructures       = "stats".CombinePathWith("structures.txt");
            subDirBrain            = "stats".CombinePathWith("brain.txt");
            subDirBody             = "stats".CombinePathWith("body.txt");
            subDirPropulsion       = "stats".CombinePathWith("propulsion.txt");
            subDirBodyPropulsion   = "stats".CombinePathWith("bodypropulsionimd.txt");
            subDirConstruction     = "stats".CombinePathWith("construction.txt");
            subDirSensor           = "stats".CombinePathWith("sensor.txt");
            subDirRepair           = "stats".CombinePathWith("repair.txt");
            subDirTemplates        = "stats".CombinePathWith("templates.txt");
            subDirWeapons          = "stats".CombinePathWith("weapons.txt");
            subDirEcm              = "stats".CombinePathWith("ecm.txt");
            subDirFeatures         = "stats".CombinePathWith("features.txt");
            subDirPiEs             = "pies".CombinePathWith("", endWithPathSeparator: true);
            subDirTexpages         = "texpages".CombinePathWith("", endWithPathSeparator: true);
            subDirAssignWeapons    = "stats".CombinePathWith("assignweapons.txt");
            subDirStructureWeapons = "stats".CombinePathWith("structureweapons.txt");

            var commaFiles = new SimpleList <clsTextFile>();

            var dataNames = new clsTextFile
            {
                SubDirectory = subDirNames,
                UniqueField  = 0
            };

            returnResult.Add(dataNames.LoadNamesFile(path));
            if (!dataNames.CalcUniqueField())
            {
                returnResult.ProblemAdd("There are two entries for the same code in " + subDirNames + ".");
            }

            var dataStructures = new clsTextFile {
                SubDirectory = subDirStructures, FieldCount = 25
            };

            commaFiles.Add(dataStructures);

            var dataBrain = new clsTextFile {
                SubDirectory = subDirBrain, FieldCount = 9
            };

            commaFiles.Add(dataBrain);

            var dataBody = new clsTextFile {
                SubDirectory = subDirBody, FieldCount = 25
            };

            commaFiles.Add(dataBody);

            var dataPropulsion = new clsTextFile {
                SubDirectory = subDirPropulsion, FieldCount = 12
            };

            commaFiles.Add(dataPropulsion);

            var dataBodyPropulsion = new clsTextFile {
                SubDirectory = subDirBodyPropulsion, FieldCount = 5, UniqueField = -1
            };

            commaFiles.Add(dataBodyPropulsion);

            var dataConstruction = new clsTextFile {
                SubDirectory = subDirConstruction, FieldCount = 12
            };

            commaFiles.Add(dataConstruction);

            var dataSensor = new clsTextFile {
                SubDirectory = subDirSensor, FieldCount = 16
            };

            commaFiles.Add(dataSensor);

            var dataRepair = new clsTextFile {
                SubDirectory = subDirRepair, FieldCount = 14
            };

            commaFiles.Add(dataRepair);

            var dataTemplates = new clsTextFile {
                SubDirectory = subDirTemplates, FieldCount = 12
            };

            commaFiles.Add(dataTemplates);

            var dataEcm = new clsTextFile {
                SubDirectory = subDirEcm, FieldCount = 14
            };

            commaFiles.Add(dataEcm);

            var dataFeatures = new clsTextFile {
                SubDirectory = subDirFeatures, FieldCount = 11
            };

            commaFiles.Add(dataFeatures);

            var dataAssignWeapons = new clsTextFile {
                SubDirectory = subDirAssignWeapons, FieldCount = 5
            };

            commaFiles.Add(dataAssignWeapons);

            var dataWeapons = new clsTextFile {
                SubDirectory = subDirWeapons, FieldCount = 53
            };

            commaFiles.Add(dataWeapons);

            var dataStructureWeapons = new clsTextFile {
                SubDirectory = subDirStructureWeapons, FieldCount = 6
            };

            commaFiles.Add(dataStructureWeapons);

            foreach (var textFile in commaFiles)
            {
                var result = textFile.LoadCommaFile(path);
                returnResult.Add(result);
                if (!result.HasProblems)
                {
                    if (textFile.CalcIsFieldCountValid())
                    {
                        if (!textFile.CalcUniqueField())
                        {
                            returnResult.ProblemAdd("An entry in field " + Convert.ToString(textFile.UniqueField) + " was not unique for file " +
                                                    textFile.SubDirectory + ".");
                        }
                    }
                    else
                    {
                        returnResult.ProblemAdd("There were entries with the wrong number of fields for file " + textFile.SubDirectory + ".");
                    }
                }
            }

            if (returnResult.HasProblems)
            {
                return(returnResult);
            }

            //load texpages

            string[] texFiles = null;

            try
            {
                texFiles = Directory.GetFiles(path + subDirTexpages);
            }
            catch (Exception)
            {
                returnResult.WarningAdd("Unable to access texture pages.");
                texFiles = new string[0];
            }

            var    text   = "";
            Bitmap bitmap = null;

            foreach (var texFile in texFiles)
            {
                text = texFile;
                if (text.Substring(text.Length - 4, 4).ToLower() == ".png")
                {
                    var result = new Result(string.Format("Loading texture page \"{0}\"", text));
                    if (File.Exists(text))
                    {
                        SimpleResult bitmapResult = BitmapUtil.LoadBitmap(text, ref bitmap);
                        var          newPage      = new clsTexturePage();
                        if (bitmapResult.Success)
                        {
                            result.Take(BitmapUtil.BitmapIsGlCompatible(bitmap));
                            newPage.GLTexture_Num = BitmapUtil.CreateGLTexture(bitmap, 0);
                        }
                        else
                        {
                            result.WarningAdd(bitmapResult.Problem);
                        }
                        var instrPos2 = text.LastIndexOf(Path.DirectorySeparatorChar);
                        newPage.FileTitle = text.Substring(instrPos2 + 1, text.Length - 5 - instrPos2);

                        TexturePages.Add(newPage);
                    }
                    else
                    {
                        result.WarningAdd("Texture page missing (" + text + ").");
                    }
                    returnResult.Add(result);
                }
            }

            //load PIEs

            string[] pieFiles = null;
            var      pieList  = new SimpleList <clsPIE>();

            try
            {
                pieFiles = Directory.GetFiles(path + subDirPiEs);
            }
            catch (Exception)
            {
                returnResult.WarningAdd("Unable to access PIE files.");
                pieFiles = new string[0];
            }

            foreach (var tempLoopVar_Text in pieFiles)
            {
                text = tempLoopVar_Text;
                var splitPath = new sSplitPath(text);
                if (splitPath.FileExtension.ToLower() == "pie")
                {
                    var newPie = new clsPIE {
                        Path = text, LCaseFileTitle = splitPath.FileTitle.ToLower()
                    };
                    pieList.Add(newPie);
                }
            }

            //interpret stats

            clsAttachment attachment;
            clsAttachment baseAttachment;
            Body          body;
            Propulsion    propulsion;
            Weapon        weapon;
            Sensor        sensor;
            Ecm           ecm;

            string[] fields = null;

            //interpret body

            foreach (var tempLoopVar_Fields in dataBody.ResultData)
            {
                fields = tempLoopVar_Fields;
                body   = new Body();
                body.ObjectDataLink.Connect(Bodies);
                body.Code = fields[0];
                SetComponentName(dataNames.ResultData, body, returnResult);
                IOUtil.InvariantParse(fields[6], ref body.Hitpoints);
                body.Designable = fields[24] != "0";
                body.Attachment.Models.Add(GetModelForPIE(pieList, fields[7].ToLower(), returnResult));
            }

            //interpret propulsion

            foreach (var tempLoopVar_Fields in dataPropulsion.ResultData)
            {
                fields     = tempLoopVar_Fields;
                propulsion = new Propulsion(Bodies.Count);
                propulsion.ObjectDataLink.Connect(Propulsions);
                propulsion.Code = fields[0];
                SetComponentName(dataNames.ResultData, propulsion, returnResult);
                IOUtil.InvariantParse(fields[7], ref propulsion.HitPoints);
                //.Propulsions(Propulsion_Num).PIE = LCase(DataPropulsion.Entries(Propulsion_Num).FieldValues(8))
                propulsion.Designable = fields[11] != "0";
            }

            //interpret body-propulsions

            var bodyPropulsionPIEs = new BodyProp[Bodies.Count, Propulsions.Count];

            for (var A = 0; A <= Bodies.Count - 1; A++)
            {
                for (var B = 0; B <= Propulsions.Count - 1; B++)
                {
                    bodyPropulsionPIEs[A, B]          = new BodyProp();
                    bodyPropulsionPIEs[A, B].LeftPIE  = "0";
                    bodyPropulsionPIEs[A, B].RightPIE = "0";
                }
            }

            foreach (var tempLoopVar_Fields in dataBodyPropulsion.ResultData)
            {
                fields     = tempLoopVar_Fields;
                body       = FindBodyCode(fields[0]);
                propulsion = FindPropulsionCode(fields[1]);
                if (body != null && propulsion != null)
                {
                    if (fields[2] != "0")
                    {
                        bodyPropulsionPIEs[body.ObjectDataLink.ArrayPosition, propulsion.ObjectDataLink.ArrayPosition].LeftPIE = fields[2].ToLower();
                    }
                    if (fields[3] != "0")
                    {
                        bodyPropulsionPIEs[body.ObjectDataLink.ArrayPosition, propulsion.ObjectDataLink.ArrayPosition].RightPIE = fields[3].ToLower();
                    }
                }
            }

            //set propulsion-body PIEs

            for (var a = 0; a <= Propulsions.Count - 1; a++)
            {
                propulsion = Propulsions[a];
                for (var B = 0; B <= Bodies.Count - 1; B++)
                {
                    body = Bodies[B];
                    propulsion.Bodies[B].LeftAttachment = new clsAttachment();
                    propulsion.Bodies[B].LeftAttachment.Models.Add(GetModelForPIE(pieList, bodyPropulsionPIEs[B, a].LeftPIE, returnResult));
                    propulsion.Bodies[B].RightAttachment = new clsAttachment();
                    propulsion.Bodies[B].RightAttachment.Models.Add(GetModelForPIE(pieList, bodyPropulsionPIEs[B, a].RightPIE, returnResult));
                }
            }

            //interpret construction

            foreach (var tempLoopVar_Fields in dataConstruction.ResultData)
            {
                fields = tempLoopVar_Fields;
                Construct Construct = new Construct();
                Construct.ObjectDataLink.Connect(Constructors);
                Construct.TurretObjectDataLink.Connect(Turrets);
                Construct.Code = fields[0];
                SetComponentName(dataNames.ResultData, Construct, returnResult);
                Construct.Designable = fields[11] != "0";
                Construct.Attachment.Models.Add(GetModelForPIE(pieList, fields[8].ToLower(), returnResult));
            }

            //interpret weapons

            foreach (var tempLoopVar_Fields in dataWeapons.ResultData)
            {
                fields = tempLoopVar_Fields;
                weapon = new Weapon();
                weapon.ObjectDataLink.Connect(Weapons);
                weapon.TurretObjectDataLink.Connect(Turrets);
                weapon.Code = fields[0];
                SetComponentName(dataNames.ResultData, weapon, returnResult);
                IOUtil.InvariantParse(fields[7], ref weapon.HitPoints);
                weapon.Designable = fields[51] != "0";
                weapon.Attachment.Models.Add(GetModelForPIE(pieList, Convert.ToString(fields[8].ToLower()), returnResult));
                weapon.Attachment.Models.Add(GetModelForPIE(pieList, fields[9].ToLower(), returnResult));
            }

            //interpret sensor

            foreach (var tempLoopVar_Fields in dataSensor.ResultData)
            {
                fields = tempLoopVar_Fields;
                sensor = new Sensor();
                sensor.ObjectDataLink.Connect(Sensors);
                sensor.TurretObjectDataLink.Connect(Turrets);
                sensor.Code = fields[0];
                SetComponentName(dataNames.ResultData, sensor, returnResult);
                IOUtil.InvariantParse(fields[7], ref sensor.HitPoints);
                sensor.Designable = fields[15] != "0";
                switch (fields[11].ToLower())
                {
                case "turret":
                    sensor.Location = SensorLocationType.Turret;
                    break;

                case "default":
                    sensor.Location = SensorLocationType.Invisible;
                    break;

                default:
                    sensor.Location = SensorLocationType.Invisible;
                    break;
                }
                sensor.Attachment.Models.Add(GetModelForPIE(pieList, fields[8].ToLower(), returnResult));
                sensor.Attachment.Models.Add(GetModelForPIE(pieList, fields[9].ToLower(), returnResult));
            }

            //interpret repair

            foreach (var tempLoopVar_Fields in dataRepair.ResultData)
            {
                fields = tempLoopVar_Fields;
                Repair Repair = new Repair();
                Repair.ObjectDataLink.Connect(Repairs);
                Repair.TurretObjectDataLink.Connect(Turrets);
                Repair.Code = fields[0];
                SetComponentName(dataNames.ResultData, Repair, returnResult);
                Repair.Designable = fields[13] != "0";
                Repair.Attachment.Models.Add(GetModelForPIE(pieList, fields[9].ToLower(), returnResult));
                Repair.Attachment.Models.Add(GetModelForPIE(pieList, fields[10].ToLower(), returnResult));
            }

            //interpret brain

            foreach (var tempLoopVar_Fields in dataBrain.ResultData)
            {
                fields = tempLoopVar_Fields;
                Brain Brain = new Brain();
                Brain.ObjectDataLink.Connect(Brains);
                Brain.TurretObjectDataLink.Connect(Turrets);
                Brain.Code = fields[0];
                SetComponentName(dataNames.ResultData, Brain, returnResult);
                Brain.Designable = true;
                weapon           = FindWeaponCode(fields[7]);
                if (weapon != null)
                {
                    Brain.Weapon     = weapon;
                    Brain.Attachment = weapon.Attachment;
                }
            }

            //interpret ecm

            foreach (var tempLoopVar_Fields in dataEcm.ResultData)
            {
                fields = tempLoopVar_Fields;
                ecm    = new Ecm();
                ecm.ObjectDataLink.Connect(ECMs);
                ecm.TurretObjectDataLink.Connect(Turrets);
                ecm.Code = fields[0];
                SetComponentName(dataNames.ResultData, ecm, returnResult);
                IOUtil.InvariantParse(fields[7], ref ecm.HitPoints);
                ecm.Designable = false;
                ecm.Attachment.Models.Add(GetModelForPIE(pieList, fields[8].ToLower(), returnResult));
            }

            //interpret feature

            foreach (var tempLoopVar_Fields in dataFeatures.ResultData)
            {
                fields = tempLoopVar_Fields;
                FeatureTypeBase featureTypeBase = new FeatureTypeBase();
                featureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                featureTypeBase.FeatureType_ObjectDataLink.Connect(FeatureTypes);
                featureTypeBase.Code = fields[0];
                if (fields[7] == "OIL RESOURCE")   //type
                {
                    featureTypeBase.FeatureType = FeatureType.OilResource;
                }
                SetFeatureName(dataNames.ResultData, featureTypeBase, returnResult);
                if (!IOUtil.InvariantParse(fields[1], ref featureTypeBase.Footprint.X))
                {
                    returnResult.WarningAdd("Feature footprint-x was not an integer for " + featureTypeBase.Code + ".");
                }
                if (!IOUtil.InvariantParse(fields[2], ref featureTypeBase.Footprint.Y))
                {
                    returnResult.WarningAdd("Feature footprint-y was not an integer for " + featureTypeBase.Code + ".");
                }
                featureTypeBase.BaseAttachment = new clsAttachment();
                baseAttachment = featureTypeBase.BaseAttachment;
                text           = fields[6].ToLower();
                attachment     = baseAttachment.CreateAttachment();
                attachment.Models.Add(GetModelForPIE(pieList, text, returnResult));
            }

            //interpret structure

            foreach (var tempLoopVar_Fields in dataStructures.ResultData)
            {
                fields = tempLoopVar_Fields;
                var structureCode      = fields[0];
                var structureTypeText  = fields[1];
                var structurePiEs      = fields[21].ToLower().Split('@');
                var structureFootprint = new XYInt();
                var structureBasePie   = fields[22].ToLower();
                if (!IOUtil.InvariantParse(fields[5], ref structureFootprint.X))
                {
                    returnResult.WarningAdd("Structure footprint-x was not an integer for " + structureCode + ".");
                }
                if (!IOUtil.InvariantParse(fields[6], ref structureFootprint.Y))
                {
                    returnResult.WarningAdd("Structure footprint-y was not an integer for " + structureCode + ".");
                }
                if (structureTypeText != "WALL" || structurePiEs.GetLength(0) != 4)
                {
                    //this is NOT a generic wall
                    StructureTypeBase structureTypeBase = new StructureTypeBase();
                    structureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                    structureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes);
                    structureTypeBase.Code = structureCode;
                    SetStructureName(dataNames.ResultData, structureTypeBase, returnResult);
                    structureTypeBase.Footprint = structureFootprint;
                    switch (structureTypeText)
                    {
                    case "DEMOLISH":
                        structureTypeBase.StructureType = StructureType.Demolish;
                        break;

                    case "WALL":
                        structureTypeBase.StructureType = StructureType.Wall;
                        break;

                    case "CORNER WALL":
                        structureTypeBase.StructureType = StructureType.CornerWall;
                        break;

                    case "FACTORY":
                        structureTypeBase.StructureType = StructureType.Factory;
                        break;

                    case "CYBORG FACTORY":
                        structureTypeBase.StructureType = StructureType.CyborgFactory;
                        break;

                    case "VTOL FACTORY":
                        structureTypeBase.StructureType = StructureType.VTOLFactory;
                        break;

                    case "COMMAND":
                        structureTypeBase.StructureType = StructureType.Command;
                        break;

                    case "HQ":
                        structureTypeBase.StructureType = StructureType.HQ;
                        break;

                    case "DEFENSE":
                        structureTypeBase.StructureType = StructureType.Defense;
                        break;

                    case "POWER GENERATOR":
                        structureTypeBase.StructureType = StructureType.PowerGenerator;
                        break;

                    case "POWER MODULE":
                        structureTypeBase.StructureType = StructureType.PowerModule;
                        break;

                    case "RESEARCH":
                        structureTypeBase.StructureType = StructureType.Research;
                        break;

                    case "RESEARCH MODULE":
                        structureTypeBase.StructureType = StructureType.ResearchModule;
                        break;

                    case "FACTORY MODULE":
                        structureTypeBase.StructureType = StructureType.FactoryModule;
                        break;

                    case "DOOR":
                        structureTypeBase.StructureType = StructureType.DOOR;
                        break;

                    case "REPAIR FACILITY":
                        structureTypeBase.StructureType = StructureType.RepairFacility;
                        break;

                    case "SAT UPLINK":
                        structureTypeBase.StructureType = StructureType.DOOR;
                        break;

                    case "REARM PAD":
                        structureTypeBase.StructureType = StructureType.RearmPad;
                        break;

                    case "MISSILE SILO":
                        structureTypeBase.StructureType = StructureType.MissileSilo;
                        break;

                    case "RESOURCE EXTRACTOR":
                        structureTypeBase.StructureType = StructureType.ResourceExtractor;
                        break;

                    default:
                        structureTypeBase.StructureType = StructureType.Unknown;
                        break;
                    }

                    baseAttachment = structureTypeBase.BaseAttachment;
                    if (structurePiEs.GetLength(0) > 0)
                    {
                        baseAttachment.Models.Add(GetModelForPIE(pieList, structurePiEs[0], returnResult));
                    }
                    structureTypeBase.StructureBasePlate = GetModelForPIE(pieList, structureBasePie, returnResult);
                    if (baseAttachment.Models.Count == 1)
                    {
                        if (baseAttachment.Models[0].ConnectorCount >= 1)
                        {
                            XYZDouble connector        = baseAttachment.Models[0].Connectors[0];
                            var       StructureWeapons = default(SimpleList <string[]>);
                            StructureWeapons = GetRowsWithValue(dataStructureWeapons.ResultData, structureTypeBase.Code);
                            if (StructureWeapons.Count > 0)
                            {
                                weapon = FindWeaponCode(Convert.ToString(StructureWeapons[0][1]));
                            }
                            else
                            {
                                weapon = null;
                            }
                            ecm    = FindECMCode(fields[18]);
                            sensor = FindSensorCode(fields[19]);
                            if (weapon != null)
                            {
                                if (weapon.Code != "ZNULLWEAPON")
                                {
                                    attachment           = baseAttachment.CopyAttachment(weapon.Attachment);
                                    attachment.PosOffset = connector;
                                }
                            }
                            if (ecm != null)
                            {
                                if (ecm.Code != "ZNULLECM")
                                {
                                    attachment           = baseAttachment.CopyAttachment(ecm.Attachment);
                                    attachment.PosOffset = connector;
                                }
                            }
                            if (sensor != null)
                            {
                                if (sensor.Code != "ZNULLSENSOR")
                                {
                                    attachment           = baseAttachment.CopyAttachment(sensor.Attachment);
                                    attachment.PosOffset = connector;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //this is a generic wall
                    var newWall = new clsWallType();
                    newWall.WallType_ObjectDataLink.Connect(WallTypes);
                    newWall.Code = structureCode;
                    SetWallName(dataNames.ResultData, newWall, returnResult);
                    var wallBasePlate = GetModelForPIE(pieList, structureBasePie, returnResult);

                    var wallNum = 0;
                    for (wallNum = 0; wallNum <= 3; wallNum++)
                    {
                        var wallStructureTypeBase = new StructureTypeBase();
                        wallStructureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                        wallStructureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes);
                        wallStructureTypeBase.WallLink.Connect(newWall.Segments);
                        wallStructureTypeBase.Code = structureCode;
                        text = newWall.Name;
                        switch (wallNum)
                        {
                        case 0:
                            text += " - ";
                            break;

                        case 1:
                            text += " + ";
                            break;

                        case 2:
                            text += " T ";
                            break;

                        case 3:
                            text += " L ";
                            break;
                        }
                        wallStructureTypeBase.Name          = text;
                        wallStructureTypeBase.Footprint     = structureFootprint;
                        wallStructureTypeBase.StructureType = StructureType.Wall;

                        baseAttachment = wallStructureTypeBase.BaseAttachment;

                        text = structurePiEs[wallNum];
                        baseAttachment.Models.Add(GetModelForPIE(pieList, text, returnResult));
                        wallStructureTypeBase.StructureBasePlate = wallBasePlate;
                    }
                }
            }

            //interpret templates

            var turretConflictCount = 0;

            foreach (var tempLoopVar_Fields in dataTemplates.ResultData)
            {
                fields = tempLoopVar_Fields;
                var template = new DroidTemplate();
                template.UnitType_ObjectDataLink.Connect(UnitTypes);
                template.DroidTemplate_ObjectDataLink.Connect(DroidTemplates);
                template.Code = fields[0];
                SetTemplateName(dataNames.ResultData, template, returnResult);
                switch (fields[9])   //type
                {
                case "ZNULLDROID":
                    template.TemplateDroidType = App.TemplateDroidType_Null;
                    break;

                case "DROID":
                    template.TemplateDroidType = App.TemplateDroidType_Droid;
                    break;

                case "CYBORG":
                    template.TemplateDroidType = App.TemplateDroidType_Cyborg;
                    break;

                case "CYBORG_CONSTRUCT":
                    template.TemplateDroidType = App.TemplateDroidType_CyborgConstruct;
                    break;

                case "CYBORG_REPAIR":
                    template.TemplateDroidType = App.TemplateDroidType_CyborgRepair;
                    break;

                case "CYBORG_SUPER":
                    template.TemplateDroidType = App.TemplateDroidType_CyborgSuper;
                    break;

                case "TRANSPORTER":
                    template.TemplateDroidType = App.TemplateDroidType_Transporter;
                    break;

                case "PERSON":
                    template.TemplateDroidType = App.TemplateDroidType_Person;
                    break;

                default:
                    template.TemplateDroidType = null;
                    returnResult.WarningAdd("Template " + template.GetDisplayTextCode() + " had an unrecognised type.");
                    break;
                }
                var loadPartsArgs = new DroidDesign.sLoadPartsArgs();
                loadPartsArgs.Body       = FindBodyCode(fields[2]);
                loadPartsArgs.Brain      = FindBrainCode(fields[3]);
                loadPartsArgs.Construct  = FindConstructorCode(fields[4]);
                loadPartsArgs.ECM        = FindECMCode(fields[5]);
                loadPartsArgs.Propulsion = FindPropulsionCode(fields[7]);
                loadPartsArgs.Repair     = FindRepairCode(fields[8]);
                loadPartsArgs.Sensor     = FindSensorCode(fields[10]);
                var templateWeapons = GetRowsWithValue(dataAssignWeapons.ResultData, template.Code);
                if (templateWeapons.Count > 0)
                {
                    text = Convert.ToString(templateWeapons[0][1]);
                    if (text != "NULL")
                    {
                        loadPartsArgs.Weapon1 = FindWeaponCode(text);
                    }
                    text = Convert.ToString(templateWeapons[0][2]);
                    if (text != "NULL")
                    {
                        loadPartsArgs.Weapon2 = FindWeaponCode(text);
                    }
                    text = Convert.ToString(templateWeapons[0][3]);
                    if (text != "NULL")
                    {
                        loadPartsArgs.Weapon3 = FindWeaponCode(text);
                    }
                }
                if (!template.LoadParts(loadPartsArgs))
                {
                    if (turretConflictCount < 16)
                    {
                        returnResult.WarningAdd("Template " + template.GetDisplayTextCode() + " had multiple conflicting turrets.");
                    }
                    turretConflictCount++;
                }
            }
            if (turretConflictCount > 0)
            {
                returnResult.WarningAdd(turretConflictCount + " templates had multiple conflicting turrets.");
            }

            return(returnResult);
        }
示例#4
0
 public void Fire(bool isLeft, int number, int idTarget, Ecm jammer)
 {
     Universe.Fire(ship, isLeft, number, idTarget, jammer);
 }