Esempio n. 1
0
//        [Test]
        public void TestExtraWaterOnParcel()
        {
            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 = 13, 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);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(13));
            Assert.That(p1.Water, Is.EqualTo(13));

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

            Assert.That(h1.WaterAllocated, Is.EqualTo(10));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(10));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(3));
            Assert.That(p1.Water, Is.EqualTo(3));
        }
Esempio n. 2
0
        /// <summary>
        /// Test a partial undo of allocated water
        /// </summary>
//        [Test]
        public void TestUndoPartial()
        {
            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, WaterRightsOwner = p1
            };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020"))
            {
                WaterAvailable = 8, WaterRightsOwner = p1
            };
            Field field1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "field1")
            {
                BuyPoint = bp1
            };
            Factory f1 = new Factory("Factory1", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1)
            {
                WaterUsage = 10, Field = field1
            };

            bp1.AddGameAsset(f1);

            allocator.ChangeAllocation(f1, p1, f1.WaterUsage);
            allocator.ChangeAllocation(f1, p1, 6);

            Assert.That(f1.WaterAllocated, Is.EqualTo(6));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(9));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
        }
Esempio n. 3
0
        public override AbstractGameAsset BuildGameAsset(Field f, AbstractGameAsset templateAsset, int level)
        {
            BuyPoint bp = f.BuyPoint;
            Player   p  = bp.DevelopmentRightsOwner;

            if (!p.Role.AllowedAssets.Contains(templateAsset))
            {
                throw new WaterWarsGameLogicException(
                          "[WATER WARS]: Player {0} tried to buy a {1} on {2} but this is not one of their allowed assets",
                          p.Name, templateAsset.Type, bp.Name);
            }

            AbstractGameAsset ga
                = m_controller.ModelFactory.CreateGameAsset(f, templateAsset, Vector3.Zero, level);

            int price = ga.ConstructionCostPerBuildStep;

            if (p.Money < price)
            {
                // TODO: Signal this to the player in-world in some way
                throw new WaterWarsGameLogicException(
                          "[WATER WARS]: Player {0} has {1}, not enough to starting building a {2} costing {3}",
                          p, p.Money, templateAsset.Type, price);
            }

            m_log.InfoFormat(
                "[WATER WARS]: Player {0} building a {1} on {2} in {3} for {4} (approx {5} each turn)",
                p.Name, ga.Type, bp.Name, bp.Location.RegionName, ga.ConstructionCost, price);

            p.Money -= price;
            p.BuildCostsThisTurn += price;
            ga.StepsBuilt++;
            ga.StepBuiltThisTurn = true;

            // We have to remove the field from the buy point - it is now attached to the game asset if we want it back
            // later on.  This is pretty nasty - fields and game assets should probably occupy specific slots on the
            // BuyPoint now.
            // NO!  The buy point has to be kept here since this is actually the only way that the game asset can
            // retrieve the field.
//            f.BuyPoint = null;

            bp.AddGameAsset(ga);

            m_controller.EventManager.TriggerGameAssetBuildStarted(ga);
            if (ga.IsBuilt)
            {
                m_controller.EventManager.TriggerGameAssetBuildCompleted(ga);
            }

            p.TriggerChanged();
            bp.TriggerChanged();

            // Don't trigger this change since we are deleting the field view
            //f.TriggerChanged();

            UpdateHudStatus(p);

            return(ga);
        }
Esempio n. 4
0
//        [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));
        }
Esempio n. 5
0
//        [Test]
        public void TestEnoughWaterWithMultipleOtherParcels()
        {
            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
            };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030"))
            {
                WaterAvailable = 4, 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(8));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(4));
            Assert.That(p1.Water, Is.EqualTo(22));

            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(0));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(0));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(2));
            Assert.That(p1.Water, Is.EqualTo(2));
        }
Esempio n. 6
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));
        }
Esempio n. 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));
        }