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"); }
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"); }
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"); }
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"); }
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")]; ComponentDesign infrastructureDesign = GenericComponentFactory.StaticToDesign(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>(), _game.Game.StaticData); Entity infrastructureEntity = GenericComponentFactory.DesignToDesignEntity(_game.Game, _game.HumanFaction, infrastructureDesign); EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureEntity); ReCalcProcessor.ReCalcAbilities(_game.EarthColony); }
public void CreateComponent() { GenericComponentFactory.DesignToDesignEntity(_gameVM.Game, _factionEntity, Design); }
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]; ComponentDesign infrastructureDesign = GenericComponentFactory.StaticToDesign(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>(), _game.Game.StaticData); Entity infrastructureEntity = GenericComponentFactory.DesignToDesignEntity(_game.Game, _game.HumanFaction, infrastructureDesign); 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, infrastructureEntity); } 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, infrastructureEntity); } 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]); } } } }