public void SetDesignSD(ComponentTemplateSD designSD)
        {
            Name        = designSD.Name;
            Description = designSD.Description;
            _ID         = designSD.ID;

            MassFormula    = designSD.MassFormula;
            VolumeFormula  = designSD.VolumeFormula;
            HTKFormula     = designSD.HTKFormula;
            CrewReqFormula = designSD.CrewReqFormula;
            MineralCostFormula.Clear();
            foreach (var item in designSD.MineralCostFormula)
            {
                MineralCostFormula.Add(new MineralFormulaVM(ParentVM, _staticData, item));
            }
            MineralCostFormula.Add(new MineralFormulaVM(ParentVM, _staticData));

            ResearchCostFormula   = designSD.ResearchCostFormula;
            CreditCostFormula     = designSD.CreditCostFormula;
            BuildPointCostFormula = designSD.BuildPointCostFormula;

            foreach (object value in Enum.GetValues(typeof(ComponentMountType)))
            {
                var currentValue = (ComponentMountType)value;
                if ((currentValue & designSD.MountType) != 0)
                {
                    MountType[currentValue] = true;
                }
            }
        }
        public void Init()
        {
            _game = new TestGame();
            StaticDataManager.LoadData("Pulsar4x", _game.Game);  // TODO: Figure out correct directory
            _entityManager = _game.Game.GlobalManager;



            // Initialize gas dictionary - haven't found a good way to look up gases without doing this
            _gasDictionary = new Dictionary <string, AtmosphericGasSD>();

            foreach (WeightedValue <AtmosphericGasSD> atmos in _game.Game.StaticData.AtmosphericGases)
            {
                _gasDictionary.Add(atmos.Value.ChemicalSymbol, atmos.Value);
            }


            _planetsList = new List <Entity>();
            _planetsList.Add(_game.Earth);

            _speciesList = new List <Entity>();
            _speciesList.Add(_game.HumanSpecies);
            //_speciesList.Add(_game.GreyAlienSpecies);

            // Set up colonies
            // @todo: add more colonies, especially ones with multiple species in one colony


            ComponentTemplateSD infrastructureSD       = _game.Game.StaticData.ComponentTemplates[new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb")];
            ComponentDesigner   infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());

            EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesigner.CreateDesign(_game.HumanFaction));

            ReCalcProcessor.ReCalcAbilities(_game.EarthColony);
        }
Exemple #3
0
        public void TestEngineComponentFactory()
        {
            ComponentTemplateSD componentTemplateSD = EngineComponentSD();

            ComponentDesigner designer = new ComponentDesigner(componentTemplateSD, _faction.GetDataBlob <FactionTechDB>());

            foreach (var ability in designer.ComponentDesignAttributes.Values)
            {
                if (ability.GuiHint == GuiHint.GuiTechSelectionList)
                {
                    List <Guid> selectionlist = ability.GuidDictionary.Keys.Cast <Guid>().ToList();
                    ability.SetValueFromGuidList(selectionlist[selectionlist.Count - 1]);
                }
                else if (ability.GuiHint == GuiHint.GuiSelectionMaxMin)
                {
                    ability.SetMax();
                    ability.SetValueFromInput(ability.MaxValue);
                }
                else
                {
                    ability.SetValue();
                }
            }

            designer.ComponentDesignAttributes["Size"].SetValueFromInput(250);

            ComponentDesign engineDesign = designer.CreateDesign(_faction);

            Assert.AreEqual(250, engineDesign.Mass);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(componentTemplateSD.ID, componentTemplateSD);
            StaticDataManager.ExportStaticData(componentsDict, "EngineComponentTest.json");
        }
Exemple #4
0
        public void TestCargoComponentCreation()
        {
            ComponentTemplateSD cargo = GeneralCargo();

            ComponentDesigner cargoDesigner = new ComponentDesigner(cargo, _faction.GetDataBlob <FactionTechDB>());

            cargoDesigner.ComponentDesignAttributes["Size"].SetValue();

            ComponentDesign cargoDesign = cargoDesigner.CreateDesign(_faction);

            bool hasAttribute = cargoDesign.TryGetAttribute <CargoStorageAtbDB>(out var attributeDB);

            Assert.IsTrue(hasAttribute);



            CargoTypeSD cargotype = _game.StaticData.CargoTypes[attributeDB.CargoTypeGuid];

            Assert.AreEqual(100, attributeDB.StorageCapacity);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(cargo.ID, cargo);
            StaticDataManager.ExportStaticData(componentsDict, "CargoComponentTest.json");
        }
Exemple #5
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;

            _engineSD    = _game.StaticData.ComponentTemplates[new Guid("E76BD999-ECD7-4511-AD41-6D0C59CA97E6")];
            engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);
            engineDesign.ComponentDesignAbilities[0].SetValueFromInput(5); //size = 25 power.
            //engineDesignDB.ComponentDesignAbilities[1]
            _engineComponent = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign);

            _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship");
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);

            Vector4 pos = new Vector4(0, 0, 0, 0);

            _ship = ShipFactory.CreateShip(_shipClass, _starSystem.SystemManager, _faction, pos, _starSystem, "Serial Peacemaker");
            PropulsionDB propulsion = _ship.GetDataBlob <PropulsionDB>();
            ShipInfoDB   shipInfo   = _ship.GetDataBlob <ShipInfoDB>();

            //Change in component cloning makes the next line's assumption untrue
            //Assert.True(_ship.GetDataBlob<ComponentInstancesDB>().SpecificInstances.ContainsKey(_engineComponent));
            Assert.AreEqual(50, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);

            EntityManipulation.AddComponentToEntity(_ship, _engineComponent);
            Assert.AreEqual(75, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);
        }
        public void TestEngineComponentFactory()
        {
            ComponentTemplateSD engine = EngineComponentSD();

            ComponentDesign design = GenericComponentFactory.StaticToDesign(engine, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);

            foreach (var ability in design.ComponentDesignAttributes)
            {
                if (ability.GuiHint == GuiHint.GuiTechSelectionList)
                {
                    List <Guid> selectionlist = ability.GuidDictionary.Keys.Cast <Guid>().ToList();
                    ability.SetValueFromGuidList(selectionlist[selectionlist.Count - 1]);
                }
                else if (ability.GuiHint == GuiHint.GuiSelectionMaxMin)
                {
                    ability.SetMax();
                    ability.SetValueFromInput(ability.MaxValue);
                }
                else
                {
                    ability.SetValue();
                }
            }

            design.ComponentDesignAttributes[0].SetValueFromInput(250);

            Entity engineEntity = GenericComponentFactory.DesignToDesignEntity(_game, _faction, design);

            Assert.AreEqual(250, engineEntity.GetDataBlob <ComponentInfoDB>().SizeInTons);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(engine.ID, engine);
            StaticDataManager.ExportStaticData(componentsDict, "EngineComponentTest.json");
        }
Exemple #7
0
        public static ComponentTemplateSD MineInstallation()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "Mine";
            component.Description = "Mines Resources";
            component.ID          = new Guid("F7084155-04C3-49E8-BF43-C7EF4BEFA550");

            component.MassFormula = "25000";

            component.VolumeFormula = "[Mass] / 2";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "50000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2d4b2866-aa4a-4b9a-b8aa-755fe509c0b3"), "60" },
                { new Guid("2ae2a928-3e14-45d5-befc-5bd6ed16ec0a"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;

            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();


            ComponentTemplateAbilitySD mineAbility = new ComponentTemplateAbilitySD();

            mineAbility.Name           = "MiningAmount";
            mineAbility.Description    = "";
            mineAbility.GuiHint        = GuiHint.None;
            mineAbility.GuidDictionary = new Dictionary <object, string>
            {
                { new Guid("08f15d35-ea1d-442f-a2e3-bde04c5c22e9"), "10" },
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "10" },
                { new Guid("b12acce2-7c7d-4acf-ad41-1c08093fcad8"), "10" },
                { new Guid("a03863a3-a364-45ff-8c7b-a4f7486bd710"), "10" },
                { new Guid("14a83fc3-04fd-4ea3-82f4-290995c4418e"), "10" },
                { new Guid("29b3797d-f9d7-4e73-a593-2b05bf4ef012"), "10" },
                { new Guid("5fdfb85c-fad2-4a48-8a75-04eb65dc9741"), "10" },
                { new Guid("2ae2a928-3e14-45d5-befc-5bd6ed16ec0a"), "10" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "10" },
                { new Guid("6a38b268-041f-4103-9d23-c13c1041cecd"), "10" },
                { new Guid("2d4b2866-aa4a-4b9a-b8aa-755fe509c0b3"), "10" }
            };
            mineAbility.AbilityDataBlobType = typeof(MineResourcesAtbDB).ToString();
            mineAbility.AbilityFormula      = "DataBlobArgs([GuidDict])";
            component.ComponentAbilitySDs.Add(mineAbility);

            return(component);
        }
Exemple #8
0
        public static ComponentTemplateSD Refinery()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "Refinery";
            component.Description = "Creates Research Points";
            component.ID          = new Guid("{90592586-0BD6-4885-8526-7181E08556B5}");

            component.MassFormula = "500000";

            component.VolumeFormula = "[Mass] / 2";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "1000000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "60" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;

            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();

            ComponentTemplateAbilitySD refinePointsAbility = new ComponentTemplateAbilitySD();

            refinePointsAbility.Name                = "RP Amount Per EconTick";
            refinePointsAbility.Description         = "";
            refinePointsAbility.GuiHint             = GuiHint.None;
            refinePointsAbility.AbilityDataBlobType = typeof(ResearchPointsAtbDB).ToString();
            refinePointsAbility.AbilityFormula      = "100";
            component.ComponentAbilitySDs.Add(refinePointsAbility);

            ComponentTemplateAbilitySD refineJobsAbility = new ComponentTemplateAbilitySD();

            refineJobsAbility.Name           = "RefineAbilitys";
            refineJobsAbility.Description    = "";
            refineJobsAbility.GuiHint        = GuiHint.None;
            refineJobsAbility.GuidDictionary = new Dictionary <object, string>
            {
                { new Guid("33E6AC88-0235-4917-A7FF-35C8886AAD3A"), "0" },
                { new Guid("6DA93677-EE08-4853-A8A5-0F46D93FE0EB"), "0" }
            };
            refineJobsAbility.AbilityDataBlobType = typeof(RefineResourcesAtbDB).ToString();
            refineJobsAbility.AbilityFormula      = "DataBlobArgs([GuidDict], Ability(0))";
            component.ComponentAbilitySDs.Add(refineJobsAbility);
            return(component);
        }
Exemple #9
0
        public void SetComponent(Guid componentGuid)
        {
            ComponentTemplateSD componentSD = _staticData.ComponentTemplates[componentGuid];

            Design = GenericComponentFactory.StaticToDesign(componentSD, _factionTech, _staticData);

            AbilityList = new List <ComponentAbilityDesignVM>();
            foreach (var componentAbility in Design.ComponentDesignAbilities)
            {
                AbilityList.Add(new ComponentAbilityDesignVM(this, componentAbility, _staticData));
            }
        }
Exemple #10
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 static ComponentTemplateSD GeneralCargo()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "General Storage";
            component.Description = "Stores General Cargo";
            component.ID          = new Guid("{30CD60F8-1DE3-4FAA-ACBA-0933EB84C199}");

            component.MassFormula = "500000";

            component.VolumeFormula = "[Mass] / 100";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "1000000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "60" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType           = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;
            component.ConstructionType    = ConstructionType.Installations | ConstructionType.ShipComponents;
            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();

            ComponentTemplateAbilitySD genralCargoAbility = new ComponentTemplateAbilitySD();

            genralCargoAbility.Name           = "Storage Capacity";
            genralCargoAbility.Description    = "";
            genralCargoAbility.GuiHint        = GuiHint.None;
            genralCargoAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(genralCargoAbility);

            ComponentTemplateAbilitySD generalCargoCapacityAbility = new ComponentTemplateAbilitySD();

            generalCargoCapacityAbility.Name                = "Construction Points";
            generalCargoCapacityAbility.Description         = "";
            generalCargoCapacityAbility.GuiHint             = GuiHint.None;
            generalCargoCapacityAbility.AbilityDataBlobType = typeof(CargoStorageAtbDB).ToString();
            generalCargoCapacityAbility.AbilityFormula      = "DataBlobArgs(Ability(0), GuidString('16b4c4f0-7292-4f4d-8fea-22103c70b288'))";
            component.ComponentAbilitySDs.Add(generalCargoCapacityAbility);

            return(component);
        }
        public void TestMineInstalationFactory()
        {
            ComponentTemplateSD mine = MineInstallation();

            ComponentDesign mineDesign = GenericComponentFactory.StaticToDesign(mine, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);

            mineDesign.ComponentDesignAttributes[0].SetValue();
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(_game, _faction, mineDesign);

            Assert.AreEqual(10, mineEntity.GetDataBlob <MineResourcesAtbDB>().ResourcesPerEconTick.Values.ElementAt(0));

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(mine.ID, mine);
            StaticDataManager.ExportStaticData(componentsDict, "MineComponentTest.json");
        }
Exemple #13
0
        public void TestMineInstalationFactory()
        {
            ComponentTemplateSD mine = MineInstallation();

            ComponentDesigner mineDesigner = new ComponentDesigner(mine, _faction.GetDataBlob <FactionTechDB>());

            mineDesigner.ComponentDesignAttributes["MiningAmount"].SetValue();
            ComponentDesign mineDesign = mineDesigner.CreateDesign(_faction);

            Assert.AreEqual(10, mineDesign.GetAttribute <MineResourcesAtbDB>().ResourcesPerEconTick.Values.ElementAt(0));

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(mine.ID, mine);
            StaticDataManager.ExportStaticData(componentsDict, "MineComponentTest.json");
        }
Exemple #14
0
        public void ExportComponents()
        {
            ComponentTemplateSD engine   = EngineComponentSD();
            ComponentTemplateSD mine     = MineInstallation();
            ComponentTemplateSD lab      = ResearchLab();
            ComponentTemplateSD refinery = Refinery();
            ComponentTemplateSD factory  = Factory();
            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(engine.ID, engine);
            componentsDict.Add(mine.ID, mine);
            componentsDict.Add(lab.ID, lab);
            componentsDict.Add(refinery.ID, refinery);
            componentsDict.Add(factory.ID, factory);
            StaticDataManager.ExportStaticData(componentsDict, "ComponentData.json");
        }
Exemple #15
0
        public void SaveToStaticData()
        {
            ComponentTemplateSD sd = new ComponentTemplateSD();

            sd.Name        = SelectedComponent.Name;
            sd.Description = SelectedComponent.Description;
            sd.ID          = Guid.Parse(SelectedComponent.ID);

            sd.MassFormula        = SelectedComponent.MassFormula;
            sd.HTKFormula         = SelectedComponent.HTKFormula;
            sd.CrewReqFormula     = SelectedComponent.CrewReqFormula;
            sd.MineralCostFormula = new Dictionary <Guid, string>();
            foreach (var item in SelectedComponent.MineralCostFormula)
            {
                if (item.MineralFormula != null)
                {
                    sd.MineralCostFormula.Add(item.Minerals.GetKey(), item.MineralFormula);
                }
            }
            sd.ResearchCostFormula   = SelectedComponent.ResearchCostFormula;
            sd.CreditCostFormula     = SelectedComponent.CreditCostFormula;
            sd.BuildPointCostFormula = SelectedComponent.BuildPointCostFormula;
            sd.MountType             = ComponentMountType.None;
            foreach (KeyValuePair <ComponentMountType, bool?> mountTypePair in SelectedComponent.MountType)
            {
                if (mountTypePair.Value != null && mountTypePair.Value == true)
                {
                    sd.MountType = sd.MountType | mountTypePair.Key;
                }
            }

            sd.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();
            foreach (var item in ComponentAbilitySDs)
            {
                sd.ComponentAbilitySDs.Add(item.CreateSD());
            }

            if (_staticData.ComponentTemplates.Keys.Contains(sd.ID))
            {
                _staticData.ComponentTemplates[sd.ID] = sd;
            }
            else
            {
                _staticData.ComponentTemplates.Add(sd.ID, sd);
            }
        }
Exemple #16
0
        public void TestFactoryComponentCreation()
        {
            ComponentTemplateSD factory = Factory();

            ComponentDesigner facDesigner = new ComponentDesigner(factory, _faction.GetDataBlob <FactionTechDB>());

            facDesigner.ComponentDesignAttributes["Instalation Construction Points"].SetValue();
            ComponentDesign facDesign = facDesigner.CreateDesign(_faction);

            ConstructionAtbDB attributeDB = facDesign.GetAttribute <ConstructionAtbDB>();

            Assert.AreEqual(100, attributeDB.ConstructionPoints[ConstructionType.ShipComponents]);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(factory.ID, factory);
            StaticDataManager.ExportStaticData(componentsDict, "FactoryComponentTest.json");
        }
        public void TestFactoryComponentCreation()
        {
            ComponentTemplateSD factory = Factory();

            ComponentDesign facDesign = GenericComponentFactory.StaticToDesign(factory, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);

            facDesign.ComponentDesignAttributes[0].SetValue();
            Entity facDesignEntity = GenericComponentFactory.DesignToDesignEntity(_game, _faction, facDesign);

            ConstructionAtbDB attributeDB = facDesignEntity.GetDataBlob <ConstructionAtbDB>();

            Assert.AreEqual(100, attributeDB.ConstructionPoints[ConstructionType.ShipComponents]);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(factory.ID, factory);
            StaticDataManager.ExportStaticData(componentsDict, "FactoryComponentTest.json");
        }
Exemple #18
0
        public static ComponentTemplateSD ResearchLab()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "ResearchLab";
            component.Description = "Creates Research Points";
            component.ID          = new Guid("C203B7CF-8B41-4664-8291-D20DFE1119EC");

            component.MassFormula = "500000";

            component.VolumeFormula = "[Mass] / 2";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "1000000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "60" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;

            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();


            ComponentTemplateAbilitySD researchPointsAbility = new ComponentTemplateAbilitySD();

            researchPointsAbility.Name                = "RP Amount Per EconTick";
            researchPointsAbility.Description         = "";
            researchPointsAbility.GuiHint             = GuiHint.None;
            researchPointsAbility.AbilityDataBlobType = typeof(ResearchPointsAtbDB).ToString();
            researchPointsAbility.AbilityFormula      = "DataBlobArgs(20)";
            component.ComponentAbilitySDs.Add(researchPointsAbility);

            return(component);
        }
Exemple #19
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction);

            _engineSD    = NameLookup.GetTemplateSD(_game, "Engine");
            engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);
            engineDesign.ComponentDesignAttributes[0].SetValueFromInput(5); //size = 25 power.

            _engineComponentDesign = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign);

            _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship");

            Assert.True(_shipClass.FactionOwner == _faction.Guid);


            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign);
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign);

            Vector3 pos = new Vector3(0, 0, 0);
            int     designEngineNumber = _shipClass.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid);

            Assert.AreEqual(2, designEngineNumber);
            _ship = ShipFactory.CreateShip(_shipClass, _starSystem, _faction, pos, _starSystem, "Serial Peacemaker");
            Assert.AreEqual(designEngineNumber, _ship.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid), "Number of engine components not the same as design");

            PropulsionAbilityDB propulsion = _ship.GetDataBlob <PropulsionAbilityDB>();
            ShipInfoDB          shipInfo   = _ship.GetDataBlob <ShipInfoDB>();

            Assert.AreEqual(500000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower");
            float tonnage1       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage1);

            Assert.AreEqual(expectedSpeed1, propulsion.MaximumSpeed_MS, "Incorrect Max Speed");

            EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign); //add second engine
            Assert.AreEqual(750000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower 2nd engine added");
            float tonnage2       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage2);

            Assert.AreEqual(expectedSpeed2, propulsion.MaximumSpeed_MS, "Incorrect Max Speed 2nd engine");
        }
        public void TestCargoComponentCreation()
        {
            ComponentTemplateSD cargo = GeneralCargo();

            ComponentDesign cargoDesign = GenericComponentFactory.StaticToDesign(cargo, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);

            cargoDesign.ComponentDesignAttributes[0].SetValue();
            Entity cargoEntity = GenericComponentFactory.DesignToDesignEntity(_game, _faction, cargoDesign);

            CargoStorageAtbDB attributeDB = cargoEntity.GetDataBlob <CargoStorageAtbDB>();


            CargoTypeSD cargotype = _game.StaticData.CargoTypes[attributeDB.CargoTypeGuid];

            Assert.AreEqual(100, attributeDB.StorageCapacity);

            Dictionary <Guid, ComponentTemplateSD> componentsDict = new Dictionary <Guid, ComponentTemplateSD>();

            componentsDict.Add(cargo.ID, cargo);
            StaticDataManager.ExportStaticData(componentsDict, "CargoComponentTest.json");
        }
Exemple #21
0
        public static ComponentTemplateSD Factory()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "Factory";
            component.Description = "Constructs Facilities, Fighters Ammo and Components";
            component.ID          = new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}");

            component.MassFormula = "500000";

            component.VolumeFormula = "[Mass] / 2";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "1000000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "60" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;

            component.ConstructionType = ConstructionType.Installations;

            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();


            ComponentTemplateAbilitySD instalationConstructionAbility = new ComponentTemplateAbilitySD();

            instalationConstructionAbility.Name           = "Instalation Construction Points";
            instalationConstructionAbility.Description    = "";
            instalationConstructionAbility.GuiHint        = GuiHint.GuiTextDisplay;
            instalationConstructionAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(instalationConstructionAbility);

            ComponentTemplateAbilitySD shipComponentsConstructionAbility = new ComponentTemplateAbilitySD();

            shipComponentsConstructionAbility.Name           = "Component Construction Points";
            shipComponentsConstructionAbility.Description    = "";
            shipComponentsConstructionAbility.GuiHint        = GuiHint.GuiTextDisplay;
            shipComponentsConstructionAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(shipComponentsConstructionAbility);


            ComponentTemplateAbilitySD shipConstructionAbility = new ComponentTemplateAbilitySD();

            shipConstructionAbility.Name           = "Ship Construction Points";
            shipConstructionAbility.Description    = "";
            shipConstructionAbility.GuiHint        = GuiHint.GuiTextDisplay;
            shipConstructionAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(shipConstructionAbility);

            ComponentTemplateAbilitySD fighterConstructionAbility = new ComponentTemplateAbilitySD();

            fighterConstructionAbility.Name           = "Fighter Construction Points";
            fighterConstructionAbility.Description    = "";
            fighterConstructionAbility.GuiHint        = GuiHint.GuiTextDisplay;
            fighterConstructionAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(fighterConstructionAbility);

            ComponentTemplateAbilitySD ammoConstructionAbility = new ComponentTemplateAbilitySD();

            ammoConstructionAbility.Name           = "Ordnance Construction Points";
            ammoConstructionAbility.Description    = "";
            ammoConstructionAbility.GuiHint        = GuiHint.GuiTextDisplay;
            ammoConstructionAbility.AbilityFormula = "100";
            component.ComponentAbilitySDs.Add(ammoConstructionAbility);

            ComponentTemplateAbilitySD atbconstructor = new ComponentTemplateAbilitySD();

            atbconstructor.Name           = "Construction Points";
            atbconstructor.Description    = "";
            atbconstructor.GuiHint        = GuiHint.None;
            atbconstructor.GuidDictionary = new Dictionary <object, string>()
            {
                { "Installations", "Ability(0)" },
                { "ShipComponents", "Ability(1)" },
                { "Ships", "Ability(2)" },
                { "Fighters", "Ability(3)" },
                { "Ordnance", "Ability(4)" }
            };
            atbconstructor.AbilityDataBlobType = typeof(ConstructionAtbDB).ToString();
            atbconstructor.AbilityFormula      = "DataBlobArgs(EnumDict('Pulsar4X.ECSLib.ConstructionType'))";
            component.ComponentAbilitySDs.Add(atbconstructor);

            return(component);
        }
        public static ComponentTemplateSD GeneralCargo()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name = "General Storage";
            component.DescriptionFormula = "Stores General Cargo";
            component.ID = new Guid("{30CD60F8-1DE3-4FAA-ACBA-0933EB84C199}");

            component.MassFormula = "500000";

            component.VolumeFormula = "[Mass] / 100";

            component.HTKFormula = "[Mass]";

            component.CrewReqFormula = "1000000";

            component.ResearchCostFormula = "0";

            component.BuildPointCostFormula = "[Mass]";

            component.ResourceCostFormula = new Dictionary <Guid, string> {
                { new Guid("2dfc78ea-f8a4-4257-bc04-47279bf104ef"), "60" },
                { new Guid("c3bcb597-a2d1-4b12-9349-26586c8a921c"), "60" }
            };

            component.CreditCostFormula = "120";

            component.MountType = ComponentMountType.PlanetInstallation | ComponentMountType.ShipCargo;
            //component.IndustryTypeID = IndustryType.Installations | IndustryType.ShipComponents;
            component.ComponentAtbSDs = new List <ComponentTemplateAttributeSD>();

            ComponentTemplateAttributeSD genralCargoAttribute = new ComponentTemplateAttributeSD();

            genralCargoAttribute.Name = "Size";
            genralCargoAttribute.DescriptionFormula = "";
            genralCargoAttribute.GuiHint            = GuiHint.GuiTextDisplay;
            genralCargoAttribute.AttributeFormula   = "100";
            component.ComponentAtbSDs.Add(genralCargoAttribute);

            ComponentTemplateAttributeSD rate = new ComponentTemplateAttributeSD();

            rate.Name = "Transfer Rate";
            rate.DescriptionFormula = "";
            rate.GuiHint            = GuiHint.GuiTextDisplay;
            rate.AttributeFormula   = "50000";
            component.ComponentAtbSDs.Add(rate);

            ComponentTemplateAttributeSD range = new ComponentTemplateAttributeSD();

            range.Name = "Transfer Dv Range";
            range.DescriptionFormula = "";
            range.GuiHint            = GuiHint.GuiTextDisplay;
            range.AttributeFormula   = "50000";
            component.ComponentAtbSDs.Add(range);

            ComponentTemplateAttributeSD generalCargoCapacityAttribute = new ComponentTemplateAttributeSD();

            generalCargoCapacityAttribute.Name = "Construction Points";
            generalCargoCapacityAttribute.DescriptionFormula = "";
            generalCargoCapacityAttribute.GuiHint            = GuiHint.None;
            generalCargoCapacityAttribute.AttributeType      = typeof(VolumeStorageAtb).ToString();
            generalCargoCapacityAttribute.AttributeFormula   = "AtbConstrArgs(Ability(0), GuidString('16b4c4f0-7292-4f4d-8fea-22103c70b288'), Ability(1), Ability(2))";
            component.ComponentAtbSDs.Add(generalCargoCapacityAttribute);

            return(component);
        }
Exemple #23
0
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.MassPerUnit, shipDesign.VolumePerUnit);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            StaticDataStore   staticdata = StaticRefLib.StaticData;
            ComponentDesigner fireControlDesigner;
            ComponentDesign   integratedfireControl;


            ComponentTemplateSD bfcSD = staticdata.ComponentTemplates[new Guid("33fcd1f5-80ab-4bac-97be-dbcae19ab1a0")];

            fireControlDesigner      = new ComponentDesigner(bfcSD, ownerFaction.GetDataBlob <FactionTechDB>());
            fireControlDesigner.Name = "Bridge Computer Systems";
            fireControlDesigner.ComponentDesignAttributes["Range"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Tracking Speed"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Size vs Range"].SetValueFromInput(0);

            //return fireControlDesigner.CreateDesign(faction);
            integratedfireControl = fireControlDesigner.CreateDesign(ownerFaction);
            ownerFaction.GetDataBlob <FactionTechDB>().IncrementLevel(integratedfireControl.TechID);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            EntityManipulation.AddComponentToEntity(ship, integratedfireControl, 1);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>())
            {
                NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship);
            }



            return(ship);
        }
Exemple #24
0
        public static ComponentTemplateSD EngineComponentSD()
        {
            ComponentTemplateSD component = new ComponentTemplateSD();

            component.Name        = "Engine";
            component.Description = "Moves a ship";
            component.ID          = new Guid("E76BD999-ECD7-4511-AD41-6D0C59CA97E6");

            component.MassFormula   = "Ability(0)";
            component.VolumeFormula = "[Mass] / 2";
            component.HTKFormula    = "Max(1, [Mass] / 100)";

            component.CrewReqFormula = "[Mass]";

            component.ResearchCostFormula = "[Mass] * 10";

            component.BuildPointCostFormula = "[Mass]";

            component.MineralCostFormula = new Dictionary <Guid, string> {
                { new Guid("2d4b2866-aa4a-4b9a-b8aa-755fe509c0b3"), "[Mass] * 8" }
            };

            component.CreditCostFormula = "[Mass]";

            component.MountType = ComponentMountType.ShipComponent | ComponentMountType.ShipCargo | ComponentMountType.Fighter;

            component.ComponentAbilitySDs = new List <ComponentTemplateAbilitySD>();

            ComponentTemplateAbilitySD SizeFormula0 = new ComponentTemplateAbilitySD();

            SizeFormula0.Name           = "Size";
            SizeFormula0.Description    = "Size of this engine in Tons";
            SizeFormula0.GuiHint        = GuiHint.GuiSelectionMaxMin;
            SizeFormula0.AbilityFormula = "250";
            SizeFormula0.MaxFormula     = "2500";
            SizeFormula0.MinFormula     = "1";
            SizeFormula0.StepFormula    = "1";
            component.ComponentAbilitySDs.Add(SizeFormula0);

            ComponentTemplateAbilitySD engineTypeAbility1 = new ComponentTemplateAbilitySD();

            engineTypeAbility1.Name           = "Engine Type";
            engineTypeAbility1.Description    = "Type of engine Tech";
            engineTypeAbility1.GuiHint        = GuiHint.GuiTechSelectionList;
            engineTypeAbility1.GuidDictionary = new Dictionary <object, string>
            {
                { new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c"), "" },
                { new Guid("c827d369-3f16-43ef-b112-7d5bcafb74c7"), "" },
                { new Guid("db6818f3-99e9-46c1-b903-f3af978c38b2"), "" },
                { new Guid("f3f10e56-9345-40cc-af42-342e7240355d"), "" }
                //new Guid("58d047e6-c567-4db6-8c76-bfd4a201af94"),
                //new Guid("bd75bf88-1dad-4022-b401-acdf05ab73f8"),
                //new Guid("042ce9d4-5a2c-4d8e-9ae4-be059920839c"),
                //new Guid("93611831-9183-484a-9920-13b39d64e272"),
                //new Guid("32eda0ab-c117-4224-b148-6c9d0e474296"),
                //new Guid("cbb1a7ce-3c26-4b5b-abd7-9a99c670d68d"),
                //new Guid("6e34cc46-0693-4676-b0ca-f076fb36acaf"),
                //new Guid("9bb4d1c4-680f-4c98-b927-337654073575"),
                //new Guid("c9587310-f7dd-45d0-ac4c-b6f59a1e1897")
            };
            engineTypeAbility1.AbilityFormula = "TechData('f3f10e56-9345-40cc-af42-342e7240355d')";

            component.ComponentAbilitySDs.Add(engineTypeAbility1);

            ComponentTemplateAbilitySD enginePowerEfficency2 = new ComponentTemplateAbilitySD();

            enginePowerEfficency2.Name           = "Engine Consumption vs Power";
            enginePowerEfficency2.Description    = "More Powerfull engines are less efficent for a given size";
            enginePowerEfficency2.GuiHint        = GuiHint.GuiSelectionMaxMin;
            enginePowerEfficency2.AbilityFormula = "1";
            enginePowerEfficency2.MaxFormula     = "TechData('b8ef73c7-2ef0-445e-8461-1e0508958a0e')";
            enginePowerEfficency2.MinFormula     = "TechData('08fa4c4b-0ddb-4b3a-9190-724d715694de')";
            enginePowerEfficency2.StepFormula    = "0.1";
            component.ComponentAbilitySDs.Add(enginePowerEfficency2);

            ComponentTemplateAbilitySD enginePowerAbility3 = new ComponentTemplateAbilitySD();

            enginePowerAbility3.Name           = "Engine Power";
            enginePowerAbility3.Description    = "Move Power for ship";
            enginePowerAbility3.GuiHint        = GuiHint.GuiTextDisplay;
            enginePowerAbility3.AbilityFormula = "Ability(1) * [Mass] * Ability(2)";
            component.ComponentAbilitySDs.Add(enginePowerAbility3);

            ComponentTemplateAbilitySD enginePowerDBArgs4 = new ComponentTemplateAbilitySD();

            enginePowerDBArgs4.Name                = "Engine Powerdb";
            enginePowerDBArgs4.Description         = "Move Power for ship";
            enginePowerDBArgs4.GuiHint             = GuiHint.None;
            enginePowerDBArgs4.AbilityDataBlobType = typeof(WarpDriveAtb).ToString();
            enginePowerDBArgs4.AbilityFormula      = "DataBlobArgs(Ability(3))";
            component.ComponentAbilitySDs.Add(enginePowerDBArgs4);

            ComponentTemplateAbilitySD fuelConsumptionTechMod5 = new ComponentTemplateAbilitySD();

            fuelConsumptionTechMod5.Name           = "Fuel Consumption";
            fuelConsumptionTechMod5.Description    = "From Tech";
            fuelConsumptionTechMod5.GuiHint        = GuiHint.None;
            fuelConsumptionTechMod5.AbilityFormula = "TechData('8557acb9-c764-44e7-8ee4-db2c2cebf0bc') * Pow(Ability(2), 2.25)";
            component.ComponentAbilitySDs.Add(fuelConsumptionTechMod5);

            ComponentTemplateAbilitySD fuelConsumptionFinalCalc6 = new ComponentTemplateAbilitySD();

            fuelConsumptionFinalCalc6.Name           = "Fuel Consumptioncalc";
            fuelConsumptionFinalCalc6.Description    = "Fuel Consumption Calc";
            fuelConsumptionFinalCalc6.GuiHint        = GuiHint.GuiTextDisplay;
            fuelConsumptionFinalCalc6.AbilityFormula = "Ability(3) - Ability(3) * [Mass] * 0.002 * Ability(5)";
            component.ComponentAbilitySDs.Add(fuelConsumptionFinalCalc6);

            ComponentTemplateAbilitySD fuelConsumptionArgsDB7 = new ComponentTemplateAbilitySD();

            fuelConsumptionArgsDB7.Name                = "Fuel Consumptiondb";
            fuelConsumptionArgsDB7.Description         = "";
            fuelConsumptionArgsDB7.GuiHint             = GuiHint.None;
            fuelConsumptionArgsDB7.AbilityDataBlobType = typeof(ResourceConsumptionAtbDB).ToString();
            fuelConsumptionArgsDB7.AbilityFormula      = "DataBlobArgs(GuidString('33e6ac88-0235-4917-a7ff-35c8886aad3a'), Ability(6), 1)";
            component.ComponentAbilitySDs.Add(fuelConsumptionArgsDB7);

            ComponentTemplateAbilitySD thermalReduction8 = new ComponentTemplateAbilitySD();

            thermalReduction8.Name           = "Thermal Signature Reduction";
            thermalReduction8.Description    = "";
            thermalReduction8.GuiHint        = GuiHint.GuiSelectionMaxMin;
            thermalReduction8.AbilityFormula = "0";
            thermalReduction8.MinFormula     = "0";
            thermalReduction8.MaxFormula     = "0.5";
            thermalReduction8.StepFormula    = "0.1";
            component.ComponentAbilitySDs.Add(thermalReduction8);

            ComponentTemplateAbilitySD sensorSigDisplay9 = new ComponentTemplateAbilitySD();

            sensorSigDisplay9.Name           = "Thermal Signature";
            sensorSigDisplay9.Description    = "";
            sensorSigDisplay9.GuiHint        = GuiHint.GuiTextDisplay;
            sensorSigDisplay9.AbilityFormula = "Ability(3) * Ability(8)";
            component.ComponentAbilitySDs.Add(sensorSigDisplay9);

            ComponentTemplateAbilitySD sensorSigDBArgs10 = new ComponentTemplateAbilitySD();

            sensorSigDBArgs10.Name                = "Sensor Signaturedb";
            sensorSigDBArgs10.Description         = "";
            sensorSigDBArgs10.GuiHint             = GuiHint.None;
            sensorSigDBArgs10.AbilityDataBlobType = typeof(SensorSignatureAtbDB).ToString();
            sensorSigDBArgs10.AbilityFormula      = "DataBlobArgs(Ability(9),0)";
            component.ComponentAbilitySDs.Add(sensorSigDBArgs10);

            return(component);
        }
        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();
        }
        private void testPlanetAndSpecies(Entity planet, Entity species)
        {
            long[] basePop = new long[] { 0, 5, 10, 100, 999, 1000, 10000, 100000, 10000000 };
            long[] infrastructureAmounts = new long[] { 0, 1, 5, 100 };
            Dictionary <Entity, long> newPop, returnedPop;

            int i, j, k;

            Guid infGUID = new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb");
            ComponentTemplateSD infrastructureSD = _game.Game.StaticData.ComponentTemplates[infGUID];


            ComponentDesigner infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());
            ComponentDesign   infrastructureDesign   = infrastructureDesigner.CreateDesign(_game.HumanFaction);

            Dictionary <Entity, long> pop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;


            // Single iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);


                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    //var infrastuctures = _game.EarthColony.GetDataBlob<ComponentInstancesDB>().SpecificInstances[infrastructureEntity].Where(inf => inf.DesignEntity.HasDataBlob<LifeSupportAbilityDB>());

                    returnedPop = calcGrowthIteration(_game.EarthColony, newPop);
                    PopulationProcessor.GrowPopulation(_game.EarthColony);

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(returnedPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }


            // Multiple iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);

                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    for (k = 0; k < 10; k++)
                    {
                        newPop = calcGrowthIteration(_game.EarthColony, newPop);
                        PopulationProcessor.GrowPopulation(_game.EarthColony);
                    }

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(newPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }
        }
 /// <summary>
 /// Constructor for VM filled with componentSD
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="gameData"></param>
 /// <param name="designSD"></param>
 public ComponentTemplateMainPropertiesVM(ComponentTemplateParentVM parent, GameVM gameData, ComponentTemplateSD designSD) : this(parent, gameData)
 {
     SetDesignSD(designSD);
 }