コード例 #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
ファイル: UniverseFactory.cs プロジェクト: andy-uq/Echo
        public void XmlTemplate()
        {
            var universe = new Universe();
            var factory = universe.ObjectFactory;

            foreach (AgentStatistic agentStat in Enum.GetValues(typeof (AgentStatistic)))
                factory.Agent.DefaultAgentStats[agentStat].SetValue(10);

            var factoryState = factory.Save();

            factory.Load(factoryState);
        }
コード例 #3
0
ファイル: State.cs プロジェクト: andy-uq/Echo
        public void SavePlayerState()
        {
            var universe = new Universe();
            PlayerCorporation corporation = universe.RegisterPlayerCorporation("andy", "AAAA", "*****@*****.**");

            var state = universe.SaveState();

            var reloaded = new Universe();
            reloaded.LoadState(state);

            Assert.AreEqual(universe.Players.Count, reloaded.Players.Count);
            Assert.AreEqual(corporation.ID, reloaded.Players[0].ID);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: Manufacture.cs プロジェクト: andy-uq/Echo
        public void BuildShip()
        {
            var universe = new Universe();
            var corp = new Corporation { Location = universe };
            var shipYard = new MockShipYard(universe, corp);

            var shipBlueprint = new ShipBlueprint {HardPoints = new[] {HardPoint.FactoryHardPoint(HardPointPosition.Front),}, BuildCost = 10, Speed = 20d, Location = shipYard, Owner = corp };
            shipBlueprint.Materials = new List<Material> {new Material(RefinedOre.RefinedOreID, "Refined Ore", 500)};
            shipBlueprint.Stats[ShipStatistic.HullIntegrity].SetValue(1000);
            shipBlueprint.Stats[ShipStatistic.Speed].SetValue(20);

            shipYard.Build(shipBlueprint);

            ulong tick = 0L;
            while ( shipYard.Ships.Count == 0 )
            {
                shipYard.Tick(tick);
                tick++;
            }
        }
コード例 #6
0
ファイル: UniverseFactory.cs プロジェクト: andy-uq/Echo
        public void Agent()
        {
            var templateXml = @"<universe nextTemplateID=""0"">
              <playercorporation templateID=""0"" startupEmployeeCount=""5"" startupCapital=""10000"" />
              <corporation templateID=""1"" startupEmployeeCount=""5"" startupCapital=""10000"" />
              <agent templateID=""2"">
            <stats variation=""0.5000"">
              <stat type=""Charisma"" value=""10"" current=""0"" />
              <stat type=""Intelligence"" value=""10"" current=""0"" />
              <stat type=""Perception"" value=""10"" current=""0"" />
              <stat type=""Memory"" value=""10"" current=""0"" />
              <stat type=""Willpower"" value=""10"" current=""0"" />
            </stats>
              </agent>
            </universe>";

            var universe = new Universe();

            var xdoc = new XmlDocument();
            xdoc.LoadXml(templateXml);

            var factory = universe.ObjectFactory;

            factory.Load(xdoc.SelectRootElement());
            foreach (AgentStatistic agentStat in Enum.GetValues(typeof(AgentStatistic)))
            {
                Assert.AreEqual(10, factory.Agent.DefaultAgentStats[agentStat].Value);
            }

            var corporation = new Corporation {Location = universe};

            var agent = factory.Agent.Create(corporation);
            foreach ( AgentStatistic agentStat in Enum.GetValues(typeof(AgentStatistic)) )
            {
                Assert.GreaterOrEqual(agent.Stats[agentStat].Value, 5);
                Assert.LessOrEqual(agent.Stats[agentStat].Value, 15);
            }
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: State.cs プロジェクト: andy-uq/Echo
        public void SaveAgent()
        {
            const string stateXml = @"<universe objectID=""0"" nextObjectID=""2"" currentTick=""0"">
              <corporations>
            <corporation objectID=""1"">
            <agents />
            </corporation>
              </corporations>
            </universe>";

            var xdoc = new XmlDocument();
            xdoc.LoadXml(stateXml);

            var universe = new Universe();
            universe.LoadState(xdoc.Select("universe"));

            Assert.AreEqual(1, universe.Corporations.Count);

            var corporation = universe.Corporations[0];
            var agent = corporation.Recruit();
            agent.Stats[AgentStatistic.Memory].SetValue(100);

            var state = universe.SaveState();

            var reloaded = new Universe();
            reloaded.LoadState(state);
            Assert.AreEqual(1, reloaded.Corporations.Count);

            var reloadedCorporation = reloaded.Corporations[0];
            Assert.AreEqual(corporation.Employees.Count, reloadedCorporation.Employees.Count);

            var reloadedAgent = reloadedCorporation.Employees[0];
            Assert.AreEqual(agent.ObjectID, reloadedAgent.ObjectID);

            Assert.AreEqual(agent.Stats[AgentStatistic.Memory].Value, reloadedAgent.Stats[AgentStatistic.Memory].Value);
        }
コード例 #9
0
ファイル: Global.asax.cs プロジェクト: andy-uq/Echo
        private void Initialise()
        {
            isShutdown = false;

            Rand.Initialise(0);
            universe = new Universe();

            dataPath = Server.MapPath("~/app_data");

            var templateFilename = Path.Combine(dataPath, "templates.xml");
            var stateFilename = Path.Combine(dataPath, "universe.xml");
            var date = DateTime.Now;

            if ( File.Exists(templateFilename) )
            {
                var templates = new XmlDocument();
                templates.Load(templateFilename);

                universe.ObjectFactory.Load(templates.SelectRootElement());
            }

            if ( File.Exists(stateFilename) )
            {
                string backupName = string.Format("{0:yyyyMd_HHmmss}_universe.xml", date);
                File.Copy(stateFilename, Path.Combine(dataPath, backupName));

                var state = new XmlDocument();
                state.Load(stateFilename);

                universe.LoadState(state.SelectRootElement());
            }

            dataWatcher = new FileSystemWatcher(dataPath, "*.xml");
            dataWatcher.Changed += UniverseChanged;
            dataWatcher.EnableRaisingEvents = true;

            isInitialised = true;
        }
コード例 #10
0
ファイル: HardPoints.cs プロジェクト: andy-uq/Echo
        public void TrackAnotherShip()
        {
            const double toDegrees = (0.5/Math.PI)*360d;

            var universe = new Universe();
            var ship = new Ship(new Corporation() { Location = universe }.Recruit()) { Name="GG", Speed = 0.5d, Location = universe };
            var track = new Ship(new Corporation() { Location = universe }.Recruit()) { Name="BG", Speed = 100d, UniversalCoordinates = new Vector(100, -1000, 0), Location = universe };

            var hardPoint = new HardPoint(ship, HardPointPosition.Right);

            ship.Destination = new Vector(0, 10, 0);
            track.Destination = new Vector(100, 1000, 0);

            ulong tick = 0;
            while (ship.HasDestination)
            {
                ship.Tick(tick);
                track.Tick(tick);

                Vector target = (track.UniversalCoordinates - ship.UniversalCoordinates);
                Console.WriteLine("Distance to target: {0:n2}, Hardpoint angle to target: {1:n2}* (delta: {2:n2}*)", target.Magnitude, Vector.Angle(hardPoint.Origin, target) * toDegrees, Vector.Angle(hardPoint.Orientation, target) * toDegrees);

                bool inRange = hardPoint.InRange(track);
                bool canTrack = hardPoint.CanTrack(track);

                bool isTracking = hardPoint.AimAt(track);
                Console.WriteLine("{0} {1} target {2}", ship.Name, isTracking ? "has" : "does not have", (inRange) ? (canTrack ? hardPoint.Inclination.ToString("n2")+"*" : "[Out of position]") : "[Out of range]");

                tick++;
            }
        }
コード例 #11
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};
            }
コード例 #12
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);
        }