Exemple #1
0
        private DesignPart CreateDesignPart(ShipPartDNA dna)
        {
            #region Find ToolItem

            // Find the corresponding tool item
            List <PartToolItemBase> toolItems = _partToolItems.Where(o => o.PartType == dna.PartType).ToList();
            if (toolItems.Count == 0)
            {
                throw new ApplicationException("Couldn't find the tool item for \"" + dna.PartType + "\"");
            }

            // Narrow down to one
            PartToolItemBase toolItem = null;
            if (toolItems.Count == 1)           // if there's more than one, then it needs to be further filtered
            {
                toolItem = toolItems[0];
            }
            else if (dna.PartType == ConverterRadiationToEnergy.PARTTYPE)
            {
                #region ConverterRadiationToEnergy

                ConverterRadiationToEnergyDNA dnaCast = (ConverterRadiationToEnergyDNA)dna;

                List <PartToolItemBase> additionalFilter = toolItems.Where(o => ((ConverterRadiationToEnergyToolItem)o).Shape == dnaCast.Shape).ToList();
                if (additionalFilter.Count == 1)
                {
                    toolItem = additionalFilter[0];
                }

                #endregion
            }
            else if (dna.PartType == Thruster.PARTTYPE)
            {
                #region Thruster

                ThrusterDNA dnaCast = (ThrusterDNA)dna;
                if (dnaCast.ThrusterType == ThrusterType.Custom)
                {
                    // Make a new one with the dna's directions
                    toolItem = new ThrusterToolItem(editor1.Options, dnaCast.ThrusterDirections, "Custom");
                }
                else
                {
                    List <PartToolItemBase> additionalFilter = toolItems.Where(o => ((ThrusterToolItem)o).ThrusterType == dnaCast.ThrusterType).ToList();
                    if (additionalFilter.Count == 1)
                    {
                        toolItem = additionalFilter[0];
                    }
                }

                #endregion
            }
            else
            {
                throw new ApplicationException("Should have only found one tool item for this part type: " + dna.PartType);
            }

            if (toolItem == null)
            {
                throw new ApplicationException("Couldn't find the tool item for this part type: " + dna.PartType);
            }

            #endregion

            DesignPart retVal = new DesignPart(editor1.Options);
            retVal.Part2D = toolItem;

            retVal.Part3D = toolItem.GetNewDesignPart();
            retVal.Part3D.SetDNA(dna);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = retVal.Part3D.Model;
            retVal.Model   = visual;

            return(retVal);
        }
Exemple #2
0
        private static ShipPartDNA GetRandomPart(PartCreateChance part)
        {
            ShipPartDNA retVal = null;

            switch (part.PartType)
            {
            case Thruster.PARTTYPE:
                #region Thruster

                ThrusterDNA dnaThrust = new ThrusterDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),
                };

                dnaThrust.ThrusterType = UtilityCore.GetRandomEnum <ThrusterType>(new[] { ThrusterType.Two_Two_One, ThrusterType.Two_Two_Two });        // only want 2D thrusters
                if (dnaThrust.ThrusterType == ThrusterType.Custom)
                {
                    dnaThrust.ThrusterDirections = Enumerable.Range(0, StaticRandom.Next(2, 5)).
                                                   Select(o => Math3D.GetRandomVector_Circular_Shell(1)). // only want 2D thrusters
                                                   ToArray();
                }

                retVal = dnaThrust;

                #endregion
                break;

            case ConverterRadiationToEnergy.PARTTYPE:
                #region ConverterRadiationToEnergy

                ConverterRadiationToEnergyDNA dnaCon = new ConverterRadiationToEnergyDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),

                    Shape = UtilityCore.GetRandomEnum <SolarPanelShape>(),
                };

                retVal = dnaCon;

                #endregion
                break;

            default:
                #region default

                retVal = new ShipPartDNA()
                {
                    PartType    = part.PartType,
                    Orientation = Math3D.GetRandomRotation(),
                    Position    = new Point3D(),
                    Scale       = GetRandomScale(part.ScaleBase),
                };

                #endregion
                break;
            }

            return(retVal);
        }