//        [Test]
        /// <summary>
        /// Test correct behaviour occurs when the asset owner does not own the sitting parcel water rights
        /// </summary>
        public void TestAssetParcelWaterRightsNotOwned()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 10 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable = 18, WaterRightsOwner = p1 };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterAvailable = 14, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 20, Field = f1 };
            bp1.AddGameAsset(h1);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(18));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(14));
            Assert.That(p1.Water, Is.EqualTo(32));

            allocator.ChangeAllocation(h1, p1, h1.WaterUsage);

            Assert.That(h1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(0));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(12));
            Assert.That(p1.Water, Is.EqualTo(12));
        }
Пример #2
0
        public AbstractGameAsset CreateGameAsset(Field f, AbstractGameAsset template, Vector3 pos, int level)
        {
            UUID uuid = UUID.Random();

            AbstractGameAsset asset = null;
            string            name  = string.Format("{0} ({1})", template.InitialNames[level], f.Name);

            if (template is Factory)
            {
                asset = new Factory(name, uuid, pos, level);
            }
            else if (template is Houses)
            {
                asset = new Houses(name, uuid, pos, level);
            }
            else if (template is Crops)
            {
                asset = new Crops(name, uuid, pos, level);
            }
            else
            {
                throw new Exception(string.Format("Unrecognized asset type {0}", template));
            }

            asset.InitialNames = template.InitialNames;
            asset.ConstructionCostsPerBuildStep = template.ConstructionCostsPerBuildStep;
            asset.StepsToBuilds      = template.StepsToBuilds;
            asset.NormalRevenues     = template.NormalRevenues;
            asset.WaterUsages        = template.WaterUsages;
            asset.MaintenanceCosts   = template.MaintenanceCosts;
            asset.InitialTimesToLive = template.InitialTimesToLive;
            asset.TimeToLive         = asset.InitialTimesToLive[level];
            asset.Field = f;
            asset.Game  = m_controller.Game;

            int revenue = m_controller.EconomicDistributor.Allocate(asset.Game.EconomicActivity, asset);

            if (template is Houses)
            {
                asset.MarketPrice = revenue;
            }
            else
            {
                asset.RevenueThisTurn = revenue;
            }

            return(asset);
        }
Пример #3
0
        public AbstractGameAsset CreateGameAsset(Field f, AbstractGameAsset template, Vector3 pos, int level)
        {
            UUID uuid = UUID.Random();

            AbstractGameAsset asset = null;
            string name = string.Format("{0} ({1})", template.InitialNames[level], f.Name);

            if (template is Factory)
                asset = new Factory(name, uuid, pos, level);
            else if (template is Houses)
                asset = new Houses(name, uuid, pos, level);
            else if (template is Crops)
                asset = new Crops(name, uuid, pos, level);
            else
                throw new Exception(string.Format("Unrecognized asset type {0}", template));

            asset.InitialNames = template.InitialNames;
            asset.ConstructionCostsPerBuildStep = template.ConstructionCostsPerBuildStep;
            asset.StepsToBuilds = template.StepsToBuilds;
            asset.NormalRevenues = template.NormalRevenues;
            asset.WaterUsages = template.WaterUsages;
            asset.MaintenanceCosts = template.MaintenanceCosts;
            asset.InitialTimesToLive = template.InitialTimesToLive;
            asset.TimeToLive = asset.InitialTimesToLive[level];
            asset.Field = f;
            asset.Game = m_controller.Game;

            int revenue = m_controller.EconomicDistributor.Allocate(asset.Game.EconomicActivity, asset);
            if (template is Houses)
                asset.MarketPrice = revenue;
            else
                asset.RevenueThisTurn = revenue;

            return asset;
        }
Пример #4
0
        public void TestWaterAllocationToFullOnlyAsset()
        {
            TestHelpers.InMethod();

            Houses h1
                = new Houses("houses1", UUID.Parse("00000000-0000-0000-0000-000000001001"), Vector3.Zero)
                    { StepsToBuilds = new int[] { 0, 1 }, StepsBuilt = 1 };
            h1.WaterUsages = new int[] { 0, 4 };
            h1.Level = 1;

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            h1.WaterAllocated = 4;
            Assert.That(h1.WaterAllocated, Is.EqualTo(4));
            h1.WaterAllocated = 0;
            Assert.That(h1.WaterAllocated, Is.EqualTo(0));

            bool gotNegativeException = false;
            try
            {
                h1.WaterAllocated = -1;
            }
            catch (WaterWarsGameLogicException)
            {
                gotNegativeException = true;
            }

            Assert.That(gotNegativeException, Is.True);
            Assert.That(h1.WaterAllocated, Is.EqualTo(0));

            // Over allocation should fail
            Houses h2 = new Houses("houses2", UUID.Parse("00000000-0000-0000-0000-000000001002"), Vector3.Zero)
                { StepsToBuilds = new int[] { 0, 1 }, StepsBuilt = 1 };
            h2.WaterUsages = new int[] { 0, 4 };
            h2.Level = 1;

            bool gotOverException = false;
            try
            {
                h2.WaterAllocated = 5;
            }
            catch (WaterWarsGameLogicException)
            {
                gotOverException = true;
            }

            Assert.That(gotOverException, Is.True);
            Assert.That(h2.WaterAllocated, Is.EqualTo(0));

            // Partial allocation should fail
            Houses h3 = new Houses("houses3", UUID.Parse("00000000-0000-0000-0000-000000001003"), Vector3.Zero)
                { StepsToBuilds = new int[] { 0, 1 }, StepsBuilt = 1 };
            h3.WaterUsages = new int[] { 0, 4 };
            h3.Level = 1;

            bool gotPartialException = false;
            try
            {
                h3.WaterAllocated = 2;
            }
            catch (WaterWarsGameLogicException)
            {
                gotPartialException = true;
            }

            Assert.That(gotPartialException, Is.True);
            Assert.That(h3.WaterAllocated, Is.EqualTo(0));
        }
        //        [Test]
        public void TestUndoOwnsOtherParcelWaterRights()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 15, DevelopmentRightsOwner = p1 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable =  8, WaterRightsOwner = p1 };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterAvailable =  5, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 10, Field = f1 };
            bp1.AddGameAsset(h1);

            allocator.ChangeAllocation(h1, p1, h1.WaterUsage);
            allocator.ChangeAllocation(h1, p1, 0);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(15));

            // We take water from the richest parcel first.  But when we undo, water is distributed back evenly.
            Assert.That(bp2.WaterAvailable, Is.EqualTo(5));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(8));
        }
        //        [Test]
        public void TestNotEnoughWaterWithAnotherParcel()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 10, WaterRightsOwner = p1 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable =  8, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 25, Field = f1 };
            bp1.AddGameAsset(h1);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
            Assert.That(p1.Water, Is.EqualTo(18));

            bool exceptionThrown = false;
            try
            {
                allocator.ChangeAllocation(h1, p1, h1.WaterUsage);
            }
            catch (WaterWarsGameLogicException)
            {
                exceptionThrown = true;
            }

            Assert.That(exceptionThrown, Is.True);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
            Assert.That(p1.Water, Is.EqualTo(18));
        }
Пример #7
0
        public void TestChosenAssetType()
        {
            TestHelpers.InMethod();

            BuyPoint bp1 = new BuyPoint(UUID.Zero);
            Assert.That(bp1.ChosenGameAssetTemplate, Is.EqualTo(AbstractGameAsset.None));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(0));
            Assert.That(bp1.Factories.Count, Is.EqualTo(0));

            Factory f1
                = new Factory("factory1", UUID.Parse("00000000-0000-0000-0000-000000000101"), Vector3.Zero);
            bp1.AddGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            Factory f2
                = new Factory("factory2", UUID.Parse("00000000-0000-0000-0000-000000000201"), Vector3.Zero);
            bp1.AddGameAsset(f2);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            bool gotExpectedException = false;
            Houses h1 = new Houses("houses1", UUID.Parse("00000000-0000-0000-0000-000000001001"), Vector3.Zero);
            try
            {
                bp1.AddGameAsset(h1);
            }
            catch (Exception)
            {
                gotExpectedException = true;
            }

            Assert.That(gotExpectedException, Is.True);
            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            gotExpectedException = false;
            try
            {
                bp1.RemoveGameAsset(h1);
            }
            catch (Exception)
            {
                gotExpectedException = true;
            }

            Assert.That(gotExpectedException, Is.True);
            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            bp1.RemoveGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            bp1.RemoveGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            bp1.RemoveGameAsset(f2);

            Assert.That(bp1.ChosenGameAssetTemplate, Is.EqualTo(AbstractGameAsset.None));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(0));
            Assert.That(bp1.Factories.Count, Is.EqualTo(0));
        }