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); }
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]); } } } }
internal override void Display() { if (IsActive && ImGui.Begin("Ordnance Design")) { ImGui.Combo("Current Designs", ref _payloadSelectedIndex, _currentDesignNames, _currentDesignNames.Length); ImGui.NewLine(); BorderGroup.BeginBorder("Payload:"); if (ImGui.Combo("Payload type", ref _payloadSelectedIndex, _payload, _payload.Length)) { //_selectedPayload = _payloadTypes[_payloadSelectedIndex].GetAttribute<OrdnancePayloadAtb>(); _selectedComponentDesigns[_payloadTypes[_payloadSelectedIndex]] = _payloadCount; RefreshMass(); } if (ImGui.SliderInt("Payload Count", ref _payloadCount, 1, 100)) { _selectedComponentDesigns[_payloadTypes[_payloadSelectedIndex]] = _payloadCount; RefreshMass(); } var whmass = _payloadTypes[_payloadSelectedIndex].Mass * _payloadCount; ImGui.Text("Mass: " + Stringify.Mass(whmass)); //ImGui.Text("Payload Trigger Type: " + _selectedPayload.Trigger); BorderGroup.EndBoarder(); ImGui.NewLine(); BorderGroup.BeginBorder("Electronics Suite:"); if (ImGui.Combo("ElectronicsSuite", ref _electronicsSelectedIndex, _electronicsPackage, _electronicsPackage.Length)) { _selectedComponentDesigns[_eleccPackTypes[_electronicsSelectedIndex]] = 1; RefreshMass(); } var mass = _eleccPackTypes[_electronicsSelectedIndex].Mass; ImGui.Text("Mass: " + Stringify.Mass(mass)); BorderGroup.EndBoarder(); ImGui.NewLine(); BorderGroup.BeginBorder("Engine:"); if (ImGui.Combo("Engine Designs", ref _engineSelectedIndex, _engineDesigns, _engineDesigns.Length)) { ComponentDesign engineDesign = _engineTypes[_engineSelectedIndex]; _selectedComponentDesigns[engineDesign] = _engineCount; RefreshMass(); } if (ImGui.SliderInt("Engine Count", ref _engineCount, 1, 256)) { _selectedComponentDesigns[_engineTypes[_engineSelectedIndex]] = _engineCount; RefreshMass(); } var emass = _engineTypes[_engineSelectedIndex].Mass * _engineCount; ImGui.Text("Mass: " + Stringify.Mass(emass)); BorderGroup.EndBoarder(); ImGui.NewLine(); ImGui.Text("Total Mass: " + Stringify.Mass(_totalMass)); var enginedesign = _engineTypes[_engineSelectedIndex]; var atb = enginedesign.GetAttribute <NewtonionThrustAtb>(); double burnRate = atb.FuelBurnRate * _engineCount; double exaustVel = atb.ExhaustVelocity; double thrustNewtons = burnRate * exaustVel; double burnTime = _fuelKG / burnRate; double dv = OrbitMath.TsiolkovskyRocketEquation(_totalMass, _totalMass - _fuelKG, exaustVel); ImGui.Text("Burn Time: " + burnTime + "s"); ImGui.Text("Thrust: " + Stringify.Thrust(thrustNewtons)); ImGui.Text("DeltaV: " + Stringify.Velocity(dv)); ImGui.InputText("Design Name", _designName, (uint)_designName.Length); NewDesignButton(); } }
public void TestShipCreation() { ComponentDesigner engineDesigner;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction); //_engineSD = NameLookup.GetTemplateSD(_game, "Alcubierre Warp Drive"); //engineDesigner = new ComponentDesigner(_engineSD, _faction.GetDataBlob<FactionTechDB>()); //engineDesigner.ComponentDesignAttributes["Size"].SetValueFromInput(5); //size = 25 power. //_engineComponentDesign = engineDesigner.CreateDesign(_faction); _engineComponentDesign = DefaultStartFactory.DefaultWarpDesign(_game, _faction); _shipClass = DefaultStartFactory.DefaultShipDesign(_game, _faction); _ship = ShipFactory.CreateShip(_shipClass, _faction, _sol, _starSystem, "Testship"); ComponentInstancesDB instancesdb = _ship.GetDataBlob <ComponentInstancesDB>(); instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances1); int origionalEngineNumber = instances1.Count; WarpAbilityDB warpAbility = _ship.GetDataBlob <WarpAbilityDB>(); ShipInfoDB shipInfo = _ship.GetDataBlob <ShipInfoDB>(); WarpDriveAtb warpAtb = _engineComponentDesign.GetAttribute <WarpDriveAtb>(); double warpPower = warpAtb.WarpPower; Assert.AreEqual(warpPower * origionalEngineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower"); float tonnage1 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage1); Assert.AreEqual(expectedSpeed1, warpAbility.MaxSpeed, "Incorrect Max Speed"); EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign); instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances2); int add2engineNumber = instances2.Count; Assert.AreEqual(origionalEngineNumber + 1, add2engineNumber); Assert.AreEqual(warpPower * add2engineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower 2nd engine added"); float tonnage2 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage2); Assert.AreEqual(expectedSpeed2, warpAbility.MaxSpeed, "Incorrect Max Speed 2nd engine"); var energydb = _ship.GetDataBlob <EnergyGenAbilityDB>(); var energyMax = energydb.EnergyStoreMax[energydb.EnergyType.ID]; energydb.EnergyStored[energydb.EnergyType.ID] = energyMax; Assert.IsTrue(energyMax >= warpAbility.BubbleCreationCost, "Ship does not store enough energy for a succesfull warp bubble creation"); Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), 0); var posDB = _ship.GetDataBlob <PositionDB>(); var ralpos = posDB.RelativePosition_m; var targetPos = new Vector3(ralpos.X, ralpos.Y, ralpos.Z); targetPos.X += expectedSpeed2 * 60 * 60; //distance for an hours travel. WarpMoveCommand.CreateCommand( _game, _faction, _ship, _sol, targetPos, _ship.StarSysDateTime, new Vector3(0, 0, 0)); Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), expectedSpeed2, 1.0E-15); // _game.GameLoop.Ticklength = TimeSpan.FromSeconds(1); //_game.GameLoop.TimeStep(); StaticRefLib.ProcessorManager.GetProcessor <WarpMovingDB>().ProcessEntity(_ship, 1); var ralposNow = posDB.RelativePosition_m; var distance = Math.Abs((ralpos - ralposNow).Length()); Assert.AreEqual(distance, expectedSpeed2, 1.0E-15); }