Beispiel #1
0
        public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech)
        {
            var staticData = StaticRefLib.StaticData;

            TypeName = componentSD.Name;
            Name     = componentSD.Name;

            _design.ID          = Guid.NewGuid();
            MassFormula         = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData);
            VolumeFormula       = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData);
            CrewFormula         = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData);
            HTKFormula          = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData);
            ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData);
            BuildCostFormula    = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData);
            CreditCostFormula   = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData);
            ComponentMountType  = componentSD.MountType;
            IndustryType        = componentSD.IndustryTypeID;
            CargoTypeID         = componentSD.CargoTypeID;
            _design.CargoTypeID = componentSD.CargoTypeID;
            if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation))
            {
                _design.GuiHints = ConstructableGuiHints.CanBeInstalled;
            }
            if (!string.IsNullOrEmpty(componentSD.DescriptionFormula))
            {
                DescriptionFormula = new ChainedExpression(componentSD.DescriptionFormula, this, factionTech, staticData);
            }

            Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>();

            foreach (var kvp in componentSD.ResourceCostFormula)
            {
                if (staticData.CargoGoods.GetAny(kvp.Key) != null)
                {
                    resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech));
                }
                else //TODO: log don't crash.
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ResourceCostFormulas = resourceCostForulas;

            foreach (ComponentTemplateAttributeSD attrbSD in componentSD.ComponentAtbSDs)
            {
                ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this, attrbSD, factionTech);
                ComponentDesignAttributes.Add(designAttribute.Name, designAttribute);
                ComponentDesignAttributeList.Add(designAttribute);
            }

            EvalAll();
        }
        public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech)
        {
            var staticData = StaticRefLib.StaticData;

            TypeName            = componentSD.Name;
            Name                = componentSD.Name;
            Description         = componentSD.Description;
            _design.ID          = Guid.NewGuid();
            MassFormula         = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData);
            VolumeFormula       = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData);
            CrewFormula         = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData);
            HTKFormula          = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData);
            ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData);
            BuildCostFormula    = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData);
            CreditCostFormula   = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData);
            ComponentMountType  = componentSD.MountType;
            IndustryType        = componentSD.IndustryTypeID;
            CargoTypeID         = componentSD.CargoTypeID;
            _design.CargoTypeID = componentSD.CargoTypeID;
            if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation))
            {
                _design.GuiHints = ConstructableGuiHints.CanBeInstalled;
            }

            Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>();

            //Dictionary<Guid, ChainedExpression> mineralCostFormulas = new Dictionary<Guid, ChainedExpression>();
            //Dictionary<Guid, ChainedExpression> materalCostFormulas = new Dictionary<Guid, ChainedExpression>();
            //Dictionary<Guid, ChainedExpression> componentCostForulas = new Dictionary<Guid, ChainedExpression>();
            foreach (var kvp in componentSD.ResourceCostFormula)
            {
                /*
                 * if (staticData.CargoGoods.IsMaterial(kvp.Key))
                 * {
                 *  materalCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else if (staticData.ComponentTemplates.ContainsKey(kvp.Key))
                 * {
                 *  componentCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else if (staticData.CargoGoods.IsMineral(kvp.Key))
                 * {
                 *  mineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else //TODO: log don't crash.
                 *  throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                 *
                 */
                if (staticData.CargoGoods.GetAny(kvp.Key) != null)
                {
                    resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech));
                }
                else //TODO: log don't crash.
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ResourceCostFormulas = resourceCostForulas;
            //MineralCostFormulas = mineralCostFormulas;
            // MaterialCostFormulas = materalCostFormulas;
            //ComponentCostFormulas = componentCostForulas;

            foreach (ComponentTemplateAbilitySD abilitySD in componentSD.ComponentAbilitySDs)
            {
                ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this);

                if (abilitySD.Name == null) //TODO: Log this, and don't use this component instead of throwing.
                {
                    throw new Exception("Bad Static Data. Ability name is null");
                }

                designAttribute.Name        = abilitySD.Name;
                designAttribute.Description = abilitySD.Description;
                designAttribute.GuiHint     = abilitySD.GuiHint;

                if (abilitySD.AbilityFormula != null)
                {
                    designAttribute.Formula = new ChainedExpression(abilitySD.AbilityFormula, designAttribute, factionTech, staticData);
                }

                if (abilitySD.GuidDictionary != null)
                {
                    designAttribute.GuidDictionary = new Dictionary <object, ChainedExpression>();
                    if (designAttribute.GuiHint == GuiHint.GuiTechSelectionList)
                    {
                        foreach (var kvp in abilitySD.GuidDictionary)
                        {
                            if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString())))
                            {
                                TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())];
                                designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), designAttribute, factionTech, staticData));
                            }
                        }
                    }
                    else
                    {
                        foreach (var kvp in abilitySD.GuidDictionary)
                        {
                            designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, designAttribute, factionTech, staticData));
                        }
                    }
                }
                if (designAttribute.GuiHint == GuiHint.GuiSelectionMaxMin)
                {
                    designAttribute.MaxValueFormula  = new ChainedExpression(abilitySD.MaxFormula, designAttribute, factionTech, staticData);
                    designAttribute.MinValueFormula  = new ChainedExpression(abilitySD.MinFormula, designAttribute, factionTech, staticData);
                    designAttribute.StepValueFormula = new ChainedExpression(abilitySD.StepFormula, designAttribute, factionTech, staticData);
                }
                if (abilitySD.AbilityDataBlobType != null)
                {
                    designAttribute.DataBlobType = Type.GetType(abilitySD.AbilityDataBlobType);
                }

                ComponentDesignAttributes.Add(designAttribute.Name, designAttribute);

                //TODO: get rid of this once json data is rewritten to use names instead of indexes
                ComponentDesignAttributeList.Add(designAttribute);
            }

            EvalAll();
        }