//        [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 FieldView(
     WaterWarsController controller, Scene scene, Field field, Vector3 scale, AbstractView itemStoreView)
     : base(controller, scene, itemStoreView)
 {
     m_field = field;
     m_scale = scale;
 }
示例#3
0
        public void TestBuyPoint()
        {
            TestHelpers.InMethod();

            // The field class has already constructed Field.None, which conceptually belongs to BuyPoint.None
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(1));

            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1");

            // Both f1 and Field.None are attached to BuyPoint.None at this point
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(2));
            Assert.That(f1.BuyPoint, Is.EqualTo(BuyPoint.None));

            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010"));
            Assert.That(bp1.Fields.Count, Is.EqualTo(0));
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(2));

            f1.BuyPoint = bp1;

            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(1));
            Assert.That(bp1.Fields.Count, Is.EqualTo(1));
            Assert.That(f1.BuyPoint, Is.EqualTo(bp1));
        }
示例#4
0
 /// <summary>
 /// Buy a game asset
 /// </summary>
 /// <param name="f"></param>
 /// <param name="template"></param>
 /// <param name="level"></param>
 public AbstractGameAsset BuildGameAsset(
     Field f, AbstractGameAsset template, int level)
 {
     return m_controller.State.BuildGameAsset(f, template, level);
 }
示例#5
0
        /// <summary>
        /// Create a field view at the given position.
        /// </summary>
        /// <param name="field"></param>
        /// <param name="pos"></param>
        /// <returns></returns>            
        public FieldView CreateFieldView(Field f, Vector3 pos)
        {
            //            m_log.InfoFormat("[WATER WARS]: Placing field {0} at {1}", name, pos);

            FieldView fv = new FieldView(m_controller, m_scene, f, m_fieldViewScale, m_itemStoreView);
            fv.Initialize(pos);

            lock (m_fieldViews)
                m_fieldViews.Add(fv.Uuid, fv);

            return fv;
        }
示例#6
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;
        }
示例#7
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;
        }
        /// <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));
        }
        //        [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));
        }
示例#11
0
 public virtual AbstractGameAsset BuildGameAsset(Field f, AbstractGameAsset templateAsset, int level)
 {
     throw new NotImplementedException();
 }