예제 #1
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());
        }
예제 #2
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);
        }