示例#1
0
文件: Travel.cs 项目: andy-uq/Echo
        public void JumpGates()
        {
            var universe = new Universe();

            var sol = new SolarSystem { Name = "Sol", Location = universe };
            var outOfSol = new JumpGate(sol);
            sol.OrbitSun(outOfSol, 45d);

            var alphaCentauri = new SolarSystem {Name = "Alpha Centauri", UniversalCoordinates = new Vector(1000d, 0, 0), Location = universe };

            var intoAlphaCentauri = new JumpGate(alphaCentauri);
            alphaCentauri.OrbitSun(intoAlphaCentauri, 45d);

            outOfSol.ConnectsTo = intoAlphaCentauri;

            var ship = new Ship(new Agent(new Corporation())) {Speed = 2d };
            sol.EnterSystem(ship, outOfSol.LocalCoordinates);

            Assert.AreEqual(sol, ship.SolarSystem);
            Assert.AreEqual(outOfSol.UniversalCoordinates, ship.UniversalCoordinates);

            CollectionAssert.Contains(sol.Objects, ship);
            CollectionAssert.DoesNotContain(alphaCentauri.Objects, ship);

            outOfSol.Jump(ship);

            Assert.AreEqual(alphaCentauri, ship.SolarSystem);
            CollectionAssert.DoesNotContain(sol.Objects, ship);
            CollectionAssert.Contains(alphaCentauri.Objects, ship);

            Assert.AreEqual(intoAlphaCentauri.UniversalCoordinates, ship.UniversalCoordinates);
        }
示例#2
0
文件: Travel.cs 项目: andy-uq/Echo
        public void IntraSolarSystem()
        {
            var universe = new Universe();
            var sol = new SolarSystem { Location = universe };

            var ship = new Ship(new Agent(new Corporation())) {Speed = 2d, Name = "S1" };
            sol.EnterSystem(ship, new Vector(10, 0, 0));

            ship.Destination = Vector.Zero;

            for (int i=10; i >= 0; i-=2)
            {
                Assert.AreEqual(i, ship.DistanceToDestination, "Ship is heading in the wrong direction!");
                ship.Tick((uint )i);
            }
        }
示例#3
0
文件: Orbits.cs 项目: andy-uq/Echo
        public void Orbiting()
        {
            Rand.Initialise(0);
            var sol = new SolarSystem();

            var earth = new Planet(sol);
            sol.OrbitSun(earth, 365d);

            var moon = new Moon(earth);
            earth.AddSatellite(moon, 28d);

            double earthOrbitRadius = (earth.UniversalCoordinates - sol.UniversalCoordinates).Magnitude;
            double moonOrbitRadius = (moon.UniversalCoordinates - earth.UniversalCoordinates).Magnitude;

            for (uint i=0; i <= 365; i++)
            {
                sol.Tick(i);

                Assert.AreEqual(earthOrbitRadius, (earth.UniversalCoordinates - sol.UniversalCoordinates).Magnitude, "Earth hit escape velocity!");
                Assert.AreEqual(moonOrbitRadius, (moon.UniversalCoordinates - earth.UniversalCoordinates).Magnitude, "Moon hit escape velocity!");

                Console.WriteLine("{0:n4},{1:n4},{2:n4},{3:n4}", earth.UniversalCoordinates.X, earth.UniversalCoordinates.Y, moon.UniversalCoordinates.X, moon.UniversalCoordinates.Y);
            }
        }
示例#4
0
文件: Travel.cs 项目: andy-uq/Echo
        public void MoveToJumpGate()
        {
            var universe = new Universe();
            var starCluster = new StarCluster();
            universe.AddStarCluster(starCluster);

            var sol = new SolarSystem { Name = "Sol" };
            starCluster.AddSolarSystem(sol);

            var alphaCentauri = new SolarSystem { Name = "Alpha Centauri", UniversalCoordinates = new Vector(1.6E9d, 0, 0)};
            starCluster.AddSolarSystem(alphaCentauri);

            var outOfSol = new JumpGate(sol);
            sol.OrbitSun(outOfSol, 45d);

            var intoAlphaCentauri = new JumpGate(alphaCentauri);
            alphaCentauri.OrbitSun(intoAlphaCentauri, 45d);

            outOfSol.ConnectsTo = intoAlphaCentauri;

            var ship = new Ship(new Agent(new Corporation())) { Speed = 20d };
            sol.EnterSystem(ship, new Vector(100d, 0, 0));

            ship.SetTask(new ShipTask(outOfSol, delegate { outOfSol.Jump(ship); return true; }));

            ulong tick = 0L;
            while (ship.SolarSystem == sol)
            {
                Assert.Less(tick, 1000L, "Ship took more than 1000 days to reach the jump gate.");

                starCluster.Tick(tick);
                tick++;
            }

            Console.WriteLine("Ship took {0} days to reach its destination which was a distance of {1:n0}km", tick, (intoAlphaCentauri.UniversalCoordinates - sol.UniversalCoordinates).Magnitude);
        }
示例#5
0
文件: Trade.cs 项目: andy-uq/Echo
            public TestCase()
            {
                Universe = new Universe();

                Seller = new Corporation {Name = "Seller", Location = Universe };
                Buyer = new Corporation {Name = "Buyer", Location = Universe };

                var starCluster = new StarCluster();
                Universe.AddStarCluster(starCluster);

                var sol = new SolarSystem();
                starCluster.AddSolarSystem(sol);

                Refinery = new Refinery(sol, Seller);
                sol.OrbitSun(Refinery, 100d);

                var m1 = new Ship(Seller.Recruit()) {Name = "M1"};
                sol.EnterSystem(m1, Refinery.LocalCoordinates);
                Refinery.Dock(m1);

                var m2 = new Ship(Buyer.Recruit()) {Name = "M2"};
                sol.EnterSystem(m2, Refinery.LocalCoordinates);
                Refinery.Dock(m2);

                this.item = new Ore {Quantity = 1000, Location = Refinery, Owner = Seller};
            }
示例#6
0
 public AsteroidBelt(SolarSystem solarSystem)
     : base(solarSystem)
 {
 }
示例#7
0
文件: Travel.cs 项目: andy-uq/Echo
        public void RefineOre()
        {
            Rand.Initialise(0);

            var universe = new Universe();
            var sol = new SolarSystem { Location = universe };

            var corporation = new Corporation() { Location = universe };
            var mPilot = corporation.Recruit();
            var tPilot = corporation.Recruit();

            var asteroidBelt = new AsteroidBelt(sol) {Richness = 100};
            sol.OrbitSun(asteroidBelt, 100d);

            var refinery = new Refinery(sol, corporation) {OreProcessedPerTick = 5, Efficiency = 2.5d };
            sol.OrbitSun(refinery, 200d);

            var manufactory = new Manufactory(sol, corporation);
            sol.OrbitSun(manufactory, 400d);

            var m1 = new Ship(mPilot) { Speed = 5d, CargoHoldSize = 100d, Name = "M1", UniversalCoordinates = refinery.UniversalCoordinates };
            refinery.Dock(m1);

            var t1 = new Ship(tPilot) { Speed = 5d, CargoHoldSize = 10d, Name = "T1", UniversalCoordinates = refinery.UniversalCoordinates };
            refinery.Dock(t1);

            var start = new ShipTask(asteroidBelt, (ship, target) => asteroidBelt.Mine(ship));
            start = start.Join(refinery, (ship, target) => refinery.UnloadOre(ship)).Join(start);

            refinery.Undock(m1, mPilot);
            m1.SetTask(start);

            start = new ShipTask(refinery, (ship, target) => { refinery.LoadRefinedOre(ship); return ship.Cargo.Count > 0 && ship.Cargo[0].Quantity > 50; });
            start = start.Join(manufactory, (ship, target) => manufactory.UnloadRefinedOre(ship)).Join(start);

            refinery.Undock(t1, tPilot);
            t1.SetTask(start);

            CollectionAssert.Contains(sol.Objects, m1);
            CollectionAssert.Contains(sol.Objects, t1);

            ulong tick = 0L;
            while ( manufactory.OreRemaining < 100 )
            {
                Assert.Less(tick, 1000, "Ssytem took more than 1000 days to complete the task.  {0:n0} products manufactured", manufactory.ProductCount);

                sol.Tick(tick);
                tick++;
            }

            Console.WriteLine("System took {0} days to manufacture {1:n0} items", tick, manufactory.ProductCount);
            Console.WriteLine("The refinery had {0:n0} unprocessed ore", refinery.UnrefinedOre);
            Console.WriteLine("The manufactory has {0:n0} unprocessed ore for building", manufactory.OreRemaining);
        }
示例#8
0
 public void AddSolarSystem(SolarSystem solarSystem)
 {
     solarSystems.Add(solarSystem);
     Extent = Math.Max(Extent, solarSystem.LocalCoordinates.Magnitude + solarSystem.Extent);
 }
示例#9
0
文件: Planet.cs 项目: andy-uq/Echo
 public Planet(SolarSystem orbiting)
     : base(orbiting)
 {
 }