private void CreateTestUniverse()
        {
            _game = new Game(new NewGameSettings {
                GameName = "Pathfinding Test Game", StartDateTime = DateTime.Now, MaxSystems = 10
            });
            _pathfindingManager = new PathfindingManager(_game);

            _testPlayer = _game.AddPlayer("TestPlayer");
            _authToken  = new AuthenticationToken(_testPlayer.ID);

            _humanFaction = DefaultStartFactory.DefaultHumans(_game, _testPlayer, "TestHumanFaction");

            List <StarSystem> systems = _game.GetSystems(new AuthenticationToken(_game.SpaceMaster.ID));
            var factionInfoDB         = _humanFaction.GetDataBlob <FactionInfoDB>();

            List <StarSystem> testPlayerSystems = _game.GetSystems(_authToken);

            StarSystem starSystem;
            StarSystem sol = testPlayerSystems[0];
            Random     RNG = new Random();

            do
            {
                starSystem = systems[RNG.Next(systems.Count - 1)];
            } while (starSystem == sol);

            factionInfoDB.KnownSystems.Add(starSystem.Guid);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        internal TestGame(int numSystems = 10)
        {
            GameSettings = new  NewGameSettings {
                GameName = "Unit Test Game", MaxSystems = numSystems, CreatePlayerFaction = false
            };

            Game = new Game(GameSettings);

            // add a faction:
            HumanFaction = FactionFactory.CreateFaction(Game, "New Terran Utopian Empire");

            // add a species:
            HumanSpecies = SpeciesFactory.CreateSpeciesHuman(HumanFaction, Game.GlobalManager);

            // add another faction:
            GreyAlienFaction = FactionFactory.CreateFaction(Game, "The Grey Empire");
            // Add another species:
            GreyAlienSpecies = SpeciesFactory.CreateSpeciesHuman(GreyAlienFaction, Game.GlobalManager);

            // Greys Name the Humans.
            HumanSpecies.GetDataBlob <NameDB>().SetName(GreyAlienFaction.Guid, "Stupid Terrans");
            // Humans name the Greys.
            GreyAlienSpecies.GetDataBlob <NameDB>().SetName(HumanFaction.Guid, "Space bugs");


            StarSystemFactory starfac = new StarSystemFactory(Game);

            Sol         = starfac.CreateSol(Game);
            Earth       = NameLookup.GetFirstEntityWithName(Sol, "Earth"); //Sol.Entities[3]; //should be fourth entity created
            EarthColony = ColonyFactory.CreateColony(HumanFaction, HumanSpecies, Earth);

            DefaultEngineDesign = DefaultStartFactory.DefaultThrusterDesign(Game, HumanFaction);
            DefaultWeaponDesign = DefaultStartFactory.DefaultSimpleLaser(Game, HumanFaction);
            DefaultShipDesign   = DefaultStartFactory.DefaultShipDesign(Game, HumanFaction);

            Vector3 position = Earth.GetDataBlob <PositionDB>().AbsolutePosition_AU;

            DefaultShip = ShipFactory.CreateShip(DefaultShipDesign, HumanFaction, position, Earth, Sol, "Serial Peacemaker");
            Sol.SetDataBlob(DefaultShip.ID, new TransitableDB());
        }
        public void StarSystemImportExport()
        {
            _game        = TestingUtilities.CreateTestUniverse(10);
            _smAuthToken = new AuthenticationToken(_game.SpaceMaster);

            Assert.NotNull(_game);

            // Choose a procedural system.
            List <StarSystem> systems = _game.GetSystems(_smAuthToken);
            var        rand           = new Random();
            int        systemIndex    = rand.Next(systems.Count - 1);
            StarSystem system         = systems[systemIndex];

            ImportExportSystem(system);

            //Now do the same thing, but with Sol.
            DefaultStartFactory.DefaultHumans(_game, "Humans");

            systems = _game.GetSystems(_smAuthToken);
            system  = systems[systems.Count - 1];
            ImportExportSystem(system);
        }
Exemple #5
0
        internal static Game CreateTestUniverse(int numSystems, DateTime testTime, bool generateDefaultHumans = false)
        {
            var gamesettings = new NewGameSettings {
                GameName = "Unit Test Game", StartDateTime = testTime, MaxSystems = numSystems, DefaultSolStart = generateDefaultHumans, CreatePlayerFaction = false
            };

            var game = new Game(gamesettings);

            var smAuthToken = new AuthenticationToken(game.SpaceMaster);

            // Systems are currently generated in the Game Constructor.
            // Later, Systems will be initialized in the game constructor, but not actually generated until player discovery.
            //game.GenerateSystems(smAuthToken, numSystems);

            // add a faction:
            Entity humanFaction = FactionFactory.CreateFaction(game, "New Terran Utopian Empire");

            // add a species:
            Entity humanSpecies = SpeciesFactory.CreateSpeciesHuman(humanFaction, game.GlobalManager);

            // add another faction:
            Entity greyAlienFaction = FactionFactory.CreateFaction(game, "The Grey Empire");
            // Add another species:
            Entity greyAlienSpecies = SpeciesFactory.CreateSpeciesHuman(greyAlienFaction, game.GlobalManager);

            // Greys Name the Humans.
            humanSpecies.GetDataBlob <NameDB>().SetName(greyAlienFaction.Guid, "Stupid Terrans");
            // Humans name the Greys.
            greyAlienSpecies.GetDataBlob <NameDB>().SetName(humanFaction.Guid, "Space bugs");
            //TODO Expand the "Test Universe" to cover more datablobs and entities. And ships. Etc.

            if (generateDefaultHumans)
            {
                DefaultStartFactory.DefaultHumans(game, "Humans");
            }

            return(game);
        }
Exemple #6
0
        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);
        }