Beispiel #1
0
        public void Init()
        {
            NewGameSettings settings = new NewGameSettings();

            settings.MaxSystems = 5;

            _game = new Game(settings);
            StaticDataManager.LoadData("Pulsar4x", _game);
            _player  = _game.AddPlayer("Test Player");
            _faction = DefaultStartFactory.DefaultHumans(_game, _player, "Test Faction");

            _starSystem = _game.Systems.First <KeyValuePair <Guid, StarSystem> >().Value;
            _planets    = _starSystem.SystemManager.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>();

            _earth = _planets.Where <Entity>(planet => planet.GetDataBlob <NameDB>().GetName(_faction) == "Earth").First <Entity>();

            _ship             = _starSystem.SystemManager.GetAllEntitiesWithDataBlob <ShipInfoDB>().First <Entity>();
            _shipPropulsionDB = _ship.GetDataBlob <PropulsionDB>();
            _target           = _ship.Clone(_starSystem.SystemManager);

            _systems = new List <StarSystem>();

            foreach (KeyValuePair <Guid, StarSystem> kvp in _game.Systems)
            {
                _systems.Add(kvp.Value);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        void SetIconFor(PropulsionDB db)
        {
            int    maxSpeed        = db.MaximumSpeed / 10;
            int    totalEP         = db.TotalEnginePower / 25;
            PointF currentSpeed    = new PointF((float)db.CurrentVector.X, (float)db.CurrentVector.Y);
            float  currentSpeedLen = currentSpeed.Length / 10;

            Pen          enginePen  = new Pen(Colors.DarkGray);
            GraphicsPath enginePath = new GraphicsPath();

            enginePath.AddRectangle(-totalEP * 0.5f, 0, totalEP, maxSpeed);
            PenPathPair engine = new PenPathPair()
            {
                Pen = enginePen, Path = enginePath
            };

            _shapes.Add(engine);
        }
Beispiel #4
0
        public PenPathPair Thrust(PropulsionDB db)
        {
            //int maxFuel = db.FuelStorageCapicity / 10;

            int    maxSpeed        = db.MaximumSpeed / 10;
            int    totalEP         = db.TotalEnginePower / 25;
            PointF currentSpeed    = new PointF((float)db.CurrentVector.X, (float)db.CurrentVector.Y);
            float  currentSpeedLen = currentSpeed.Length / 10;

            Pen          thrustPen  = new Pen(Colors.OrangeRed);
            GraphicsPath thrustPath = new GraphicsPath();

            thrustPath.AddLine(-totalEP * 0.5f, maxSpeed, 0, maxSpeed + currentSpeedLen);
            thrustPath.AddLine(0, maxSpeed + currentSpeedLen, totalEP * 0.5f, maxSpeed);
            return(new PenPathPair()
            {
                Pen = thrustPen, Path = thrustPath
            });
        }
Beispiel #5
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction);

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

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

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

            Assert.True(_shipClass.GetDataBlob <OwnedDB>().OwnedByFaction == _faction);

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

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

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

            Assert.True(_ship.GetDataBlob <ComponentInstancesDB>().SpecificInstances.ContainsKey(_engineComponent));
            Assert.AreEqual(50, propulsion.TotalEnginePower, "Incorrect TotalEnginePower");
            float tonnage1       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage1);

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

            EntityManipulation.AddComponentToEntity(_ship, _engineComponent); //add second engine
            Assert.AreEqual(75, 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, "Incorrect Max Speed 2nd engine");
        }
Beispiel #6
0
        internal override void Display()
        {
            _isRunningFrame = true;
            if (IsActive)
            {
                SetFrameRateArray();
                if (ImGui.Begin("debug", ref IsActive))
                {
                    ImGui.Text(_state.CurrentSystemDateTime.ToString());
                    ImGui.Text("Cursor World Coordinate:");
                    var mouseWorldCoord = _state.Camera.MouseWorldCoordinate();
                    ImGui.Text("x" + mouseWorldCoord.X);
                    ImGui.SameLine();
                    ImGui.Text("y" + mouseWorldCoord.Y);

                    if (ImGui.CollapsingHeader("FrameRates", ImGuiTreeNodeFlags.CollapsingHeader))
                    {
                        //plot vars: (label, values, valueOffset, overlayText, scaleMin, scaleMax, graphSize, Stride)
                        //core game processing rate.
                        //ImGui.PlotHistogram("##GRHistogram", _gameRatesDisplay, 10, _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        //ImGui.PlotHistogram("##GRHistogram1", _gameRatesDisplay, 0 , _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        ImGui.PlotHistogram("Game Tick ##GTHistogram", _gameRates, _gameRateIndex, _currentGFPS.ToString(), 0f, largestGFPS, new ImVec2(248, 60), sizeof(float));
                        ImGui.PlotLines("Game Tick ##GTPlotlines", _gameRates, _gameRateIndex, _currentGFPS.ToString(), 0, largestGFPS, new ImVec2(248, 60), sizeof(float));
                        //current star system processing rate.
                        ImGui.PlotHistogram("System Tick ##STHistogram", _systemRates, _systemRateIndex, _currentSFPS.ToString(), 0f, 1f, new ImVec2(248, 60), sizeof(float));
                        ImGui.PlotLines("System Tick ##STPlotlines", _systemRates, _systemRateIndex, _currentSFPS.ToString(), 0, 1, new ImVec2(248, 60), sizeof(float));
                        //ui framerate
                        ImGui.PlotHistogram("Frame Rate ##FPSHistogram", _frameRates, _frameRateIndex, _currentFPS.ToString(), 0f, 10000, new ImVec2(248, 60), sizeof(float));
                    }

                    if (_state.LastClickedEntity.Name != null)
                    {
                        if (ImGui.CollapsingHeader("Selected Entity: " + _state.LastClickedEntity.Name + "###NameHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                        {
                            ImGui.Text(_state.LastClickedEntity.Entity.Guid.ToString());
                            if (_state.LastClickedEntity.Entity.HasDataBlob <PositionDB>())
                            {
                                var positiondb = _state.LastClickedEntity.Entity.GetDataBlob <PositionDB>();
                                var posv4      = positiondb.AbsolutePosition_AU;
                                ImGui.Text("x: " + posv4.X);
                                ImGui.Text("y: " + posv4.Y);
                                ImGui.Text("z: " + posv4.Z);
                                if (positiondb.Parent != null)
                                {
                                    ImGui.Text("Parent: " + positiondb.Parent.GetDataBlob <NameDB>().DefaultName);
                                    ImGui.Text("Dist: " + Distance.AuToKm(positiondb.RelativePosition_AU.Length()));
                                }
                            }
                            if (_state.LastClickedEntity.Entity.HasDataBlob <OrbitDB>())
                            {
                                if (ImGui.CollapsingHeader("OrbitDB: ###OrbitDBHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _state.LastClickedEntity.Entity.GetDataBlob <OrbitDB>();


                                    //if (_state.CurrentSystemDateTime != lastDate)
                                    //{
                                    pos        = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.CurrentSystemDateTime);
                                    truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.CurrentSystemDateTime);
                                    lastDate   = _state.CurrentSystemDateTime;
                                    //}

                                    ImGui.Text("x: " + pos.X);
                                    ImGui.Text("y: " + pos.Y);
                                    ImGui.Text("z: " + pos.Z);
                                    ImGui.Text("Eccentricity: " + orbitDB.Eccentricity);
                                    ImGui.Text("AoP:" + orbitDB.ArgumentOfPeriapsis);
                                    ImGui.Text("TrueAnomaly: " + truAnomoly);
                                    ImGui.Text("MeanMotion: " + orbitDB.MeanMotion);
                                    ImGui.Text("SOI Radius: " + Distance.AuToKm(GMath.GetSOI(_state.LastClickedEntity.Entity)));
                                    ImGui.Text("Orbital Period:" + orbitDB.OrbitalPeriod);
                                    ImGui.Text("SemiMajAxis: " + orbitDB.SemiMajorAxis);
                                    if (orbitDB.Parent != null)
                                    {
                                        ImGui.Text("Parent: " + orbitDB.Parent.GetDataBlob <NameDB>().DefaultName);
                                    }
                                    if (orbitDB.Children.Count > 0)
                                    {
                                        foreach (var item in orbitDB.Children)
                                        {
                                            ImGui.Text(item.GetDataBlob <NameDB>().DefaultName);
                                        }
                                    }
                                }
                            }
                            if (_state.LastClickedEntity.OrbitIcon != null)
                            {
                                if (ImGui.CollapsingHeader("OrbitIcon: ###OrbitIconHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _state.LastClickedEntity.Entity.GetDataBlob <OrbitDB>();

                                    string startRadian  = _state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians.ToString();
                                    string startDegrees = Angle.ToDegrees(_state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians).ToString();
                                    ImGui.Text("StartAngleRadians: " + startRadian);
                                    ImGui.Text("StartAngleDegrees: " + startDegrees);
                                }
                            }

                            if (_state.LastClickedEntity.Entity.HasDataBlob <PropulsionDB>())
                            {
                                if (ImGui.CollapsingHeader("Propulsion: ###PropulsionHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    PropulsionDB propulsionDB = _state.LastClickedEntity.Entity.GetDataBlob <PropulsionDB>();
                                    ImGui.Text("NonNewt Engine Power: " + propulsionDB.TotalEnginePower);
                                    ImGui.Text("Max Speed: " + propulsionDB.MaximumSpeed_MS);
                                    ImGui.Text("CurrentVector: " + propulsionDB.CurrentVectorMS);
                                    ImGui.Text("Current Speed: " + Vector4.Magnitude(propulsionDB.CurrentVectorMS));
                                    if (_state.LastClickedEntity.Entity.HasDataBlob <CargoStorageDB>())
                                    {
                                        var fuelsGuid = propulsionDB.FuelUsePerKM;
                                        var storage   = _state.LastClickedEntity.Entity.GetDataBlob <CargoStorageDB>();
                                        foreach (var fuelItemGuid in fuelsGuid.Keys)
                                        {
                                            var fuel = _state.Game.StaticData.GetICargoable(fuelItemGuid);
                                            ImGui.Text(fuel.Name);
                                            ImGui.SameLine();
                                            ImGui.Text(StorageSpaceProcessor.GetAmount(storage, fuel).ToString());
                                        }
                                    }
                                }
                                if (_state.LastClickedEntity.Entity.HasDataBlob <TranslateMoveDB>())
                                {
                                    var db = _state.LastClickedEntity.Entity.GetDataBlob <TranslateMoveDB>();
                                    if (ImGui.CollapsingHeader("Transit: ###TransitHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                    {
                                        ImGui.Text("EntryPoint " + db.TranslateEntryPoint_AU);
                                        ImGui.Text("ExitPoint  " + db.TranslationExitPoint_AU);
                                        ImGui.Text("EDA " + db.PredictedExitTime.ToString());
                                        double distance = Distance.DistanceBetween(db.TranslateEntryPoint_AU, db.TranslationExitPoint_AU);
                                        ImGui.Text("Distance " + distance + " AU");
                                        ImGui.SameLine();
                                        double distancekm = Distance.AuToKm(distance);
                                        ImGui.Text(distancekm.ToString() + " KM");
                                        var timeToTarget = db.PredictedExitTime - _state.CurrentSystemDateTime;
                                        ImGui.Text("Remaining TTT " + timeToTarget);
                                        var totalTime = db.PredictedExitTime - db.EntryDateTime;
                                        ImGui.Text("Total TTT  " + totalTime);
                                        double speed = ((distancekm * 1000) / totalTime.TotalSeconds);
                                        ImGui.Text("speed2 " + speed);
                                        ImGui.Text("LastDateTime: ");
                                        ImGui.Text(db.LastProcessDateTime.ToString());
                                        ImGui.Text("Time Since Last: ");
                                        var timelen = _state.CurrentSystemDateTime - db.LastProcessDateTime;
                                        ImGui.Text(timelen.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                //else IsActive = false;
                ImGui.End();
            }
            _isRunningFrame           = false;
            _dateChangeSinceLastFrame = false;
        }