Example #1
0
        public override void UndoUseWater(AbstractGameAsset a)
        {
            if (!a.CanBeAllocatedWater)
            {
                throw new WaterWarsGameLogicException(
                          string.Format(
                              "Attempt made to undo allocate water on asset {0} but this asset type does not allow water allocation",
                              a.Name));
            }

            if (!a.IsBuilt)
            {
                throw new WaterWarsGameLogicException(
                          "{0} tried to undo allocate water on asset {1} but it is only partially built",
                          a.OwnerName, a.Name);
            }

            Player   p  = a.Field.BuyPoint.DevelopmentRightsOwner;
            BuyPoint bp = a.Field.BuyPoint;

            m_log.InfoFormat(
                "[WATER WARS]: {0} undoing use of {1} on {2} at {3} in {4}",
                p.Name, WaterWarsUtils.GetWaterUnitsText(a.WaterAllocated), a.Name, bp.Name, bp.Location.RegionName);

            m_controller.WaterAllocator.ChangeAllocation(a, p, 0);
            m_controller.EventManager.TriggerWaterUsed(a, p, 0);
            a.TriggerChanged();
            bp.TriggerChanged();
            p.TriggerChanged();

            UpdateHudStatus(p);
        }
Example #2
0
        protected override void PostStartState()
        {
            // Perform economic activity
            Game.EconomicActivity = m_controller.EconomicGenerator.Generate(Game);

            lock (Game.GameAssets)
            {
                Dictionary <AbstractGameAsset, int> allocation
                    = m_controller.EconomicDistributor.Allocate(Game.EconomicActivity, Game.GameAssets.Values);

                foreach (AbstractGameAsset ga in allocation.Keys)
                {
                    // Messy.  This will need to come out as a separate Dictionary of market prices from the allocator
                    // or perhaps another source (MarketPricer?)
                    if (ga.Type == AbstractGameAssetType.Houses)
                    {
                        ga.MarketPrice = allocation[ga];
                    }
                    else
                    {
                        ga.RevenueThisTurn = allocation[ga];
                    }
                }
            }

            // Perform water activity
            RainfallTotal = m_controller.RainfallGenerator.Generate(Game);

            m_controller.EventManager.TriggerWaterGenerated(RainfallTotal);

            m_log.InfoFormat(
                "[WATER WARS]: Generated {0} over {1} parcels",
                WaterWarsUtils.GetWaterUnitsText(RainfallTotal), Game.BuyPoints.Count);

            List <Player> players;

            lock (Game.Players)
                players = Game.Players.Values.ToList();

            Dictionary <Player, int> waterAllocated
                = m_controller.WaterDistributor.Allocate(RainfallTotal, players, Game.BuyPoints.Values);

            foreach (Player p in waterAllocated.Keys)
            {
                p.WaterReceived = waterAllocated[p];
                p.Water        += p.WaterReceived;

                m_log.InfoFormat(
                    "[WATER WARS]: Allocated {0} to {1}", WaterWarsUtils.GetWaterUnitsText(p.WaterReceived), p.Name);

                m_controller.EventManager.TriggerWaterAllocated(p, p.WaterReceived);

                // We'll leave it up to the following Water State (or possibly Reset State) to trigger the general
                // player data change event
//                p.TriggerChanged();
            }

            EndState(new WaterStageState(m_controller));
        }
Example #3
0
 protected void UpdateLabel()
 {
     if (m_controller.Game.State == GameStateType.Build)
     {
         LabelBehaviour.Text = string.Format("Rights owned\n{0}", WaterWarsUtils.GetWaterUnitsText(m_waterEntitlement));
     }
     else
     {
         LabelBehaviour.Text = string.Format("Available for use\n{0}", WaterWarsUtils.GetWaterUnitsText(m_water));
     }
 }
Example #4
0
        public override void GiveWaterRights(Player p, int amount)
        {
            m_log.InfoFormat("[WATER WARS]: Giving rights to {0} to {1}", WaterWarsUtils.GetWaterUnitsText(amount), p.Name);

            p.WaterEntitlement += amount;

            m_controller.EventManager.TriggerWaterRightsGiven(p, amount);

            p.TriggerChanged();

            // FIXME: Should be done via event subscription.
            UpdateHudStatus(p);
        }
        protected void AskBuyer()
        {
            SendDialog(
                m_buyer,
                string.Format(
                    "Would you like to buy the rights to {0} from {1} for {2}{3}?",
                    WaterWarsUtils.GetWaterUnitsText(m_amount), m_seller.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice),
                YES_NO_OPTIONS, ProcessBuyer);

            SendAlert(
                m_seller,
                string.Format(
                    "Offer to sell rights for {0} to {1} for {2}{3} has been sent",
                    WaterWarsUtils.GetWaterUnitsText(m_amount), m_buyer.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice));
        }
        protected void ProcessBuyer(OSChatMessage chat)
        {
            m_log.InfoFormat(
                "[WATER WARS]: Processing reply {0} for {1} selling to {2}", chat.Message, m_seller, m_buyer);

            bool accepted = false;

            if (YES_OPTION == chat.Message)
            {
                if (m_buyer.Money >= m_salePrice)
                {
                    accepted = true;
                }
                else
                {
                    SendAlert(m_buyer, "You don't have enough money to accept that offer!");
                }
            }

            if (accepted)
            {
                m_controller.State.SellWaterRights(m_buyer, m_seller, m_amount, m_salePrice);

                SendAlert(
                    m_seller,
                    string.Format(
                        "You successfully sold rights to {0} to {1} for {2}{3}",
                        WaterWarsUtils.GetWaterUnitsText(m_amount), m_buyer.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice));

                SendAlert(
                    m_buyer,
                    string.Format(
                        "You successfully bought the rights to {0} from {1} for {2}{3}",
                        WaterWarsUtils.GetWaterUnitsText(m_amount), m_seller.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice));
            }
            else
            {
                m_controller.EventManager.TriggerWaterRightsSold(m_buyer, m_seller, m_amount, m_salePrice, false);

                SendAlert(
                    m_seller,
                    string.Format(
                        "{0} declined your offer to sell them rights to {1} for {2}{3}",
                        m_buyer.Name, WaterWarsUtils.GetWaterUnitsText(m_amount), WaterWarsConstants.MONEY_UNIT, m_salePrice));
            }
        }
Example #7
0
        public override void SellWaterRights(Player buyer, Player seller, int amount, int salePrice)
        {
            if (buyer.Money < salePrice)
            {
                throw new WaterWarsGameLogicException(
                          string.Format(
                              "Player {0} tried to buy {1} water rights from {2} for {3} but they only have {4}",
                              buyer, amount, seller, salePrice, buyer.Money));
            }

            if (seller.WaterEntitlement < amount)
            {
                throw new WaterWarsGameLogicException(
                          string.Format(
                              "Player {0} tried to sell {1} water rights to {2} but they only have {3}",
                              seller, amount, buyer, WaterWarsUtils.GetWaterUnitsText(seller.WaterEntitlement)));
            }

            m_log.InfoFormat(
                "[WATER WARS]: Player {0} selling {1} water rights to {2} for {3}",
                seller, amount, buyer, salePrice);

            buyer.Money -= salePrice;
            buyer.WaterRightsCostsThisTurn += salePrice;
            seller.Money += salePrice;
            seller.WaterRightsRevenueThisTurn += salePrice;
            buyer.WaterEntitlement            += amount;
            seller.WaterEntitlement           -= amount;

            m_controller.EventManager.TriggerWaterRightsSold(buyer, seller, amount, salePrice, true);

            buyer.TriggerChanged();
            seller.TriggerChanged();

            // FIXME: Should be done via event subscription.
            UpdateHudStatus(buyer);
            UpdateHudStatus(seller);

            m_controller.Events.PostToAll(
                string.Format(SELL_WATER_RIGHTS_CRAWL_MSG, seller.Name, WaterWarsUtils.GetWaterUnitsText(amount), buyer.Name),
                EventLevel.Crawl);
        }
Example #8
0
        public override void SellWater(Player seller, Player buyer, int water, int price)
        {
            if (seller.Water < water)
            {
                throw new WaterWarsGameLogicException(
                          string.Format(
                              "{0} only has {1} but is trying to sell {2} to {3}",
                              seller, WaterWarsUtils.GetWaterUnitsText(seller.Water), WaterWarsUtils.GetWaterUnitsText(water), buyer));
            }

            if (buyer.Money < price)
            {
                throw new WaterWarsGameLogicException(
                          string.Format(
                              "{0} only has {1} but {2} is trying to sell them water for {3}",
                              buyer, buyer.Money, seller, price));
            }

            m_log.InfoFormat(
                "[WATER WARS]: {0} selling {1} to {2} for {3}",
                seller.Name, WaterWarsUtils.GetWaterUnitsText(water), buyer.Name, price);

            seller.Money                += price;
            buyer.Money                 -= price;
            buyer.WaterCostsThisTurn    += price;
            seller.WaterRevenueThisTurn += price;
            seller.Water                -= water;
            buyer.Water                 += water;

            m_controller.EventManager.TriggerWaterSold(buyer, seller, water, price, true);
            buyer.TriggerChanged();
            seller.TriggerChanged();

            UpdateHudStatus(seller);
            UpdateHudStatus(buyer);

            m_controller.Events.PostToAll(
                string.Format(
                    SELL_WATER_CRAWL_MSG, seller.Name, WaterWarsUtils.GetWaterUnitsText(water), buyer.Name),
                EventLevel.Crawl);
        }
Example #9
0
        protected override void StartState()
        {
            base.StartState();

            // We do not provide a forecast for the next water phase during the current water phase.
            Game.Forecast.Economic = null;
            Game.Forecast.Water    = "Available next build phase";

            List <Player> players;

            lock (Game.Players)
                players = Game.Players.Values.ToList();

            foreach (Player p in players)
            {
                m_controller.Events.Post(
                    p,
                    string.Format(FEED_RAINFALL_MSG, WaterWarsUtils.GetWaterUnitsText(p.WaterReceived)),
                    EventLevel.Alert);
            }

            UpdateAllStatus();
        }
Example #10
0
        public override void UseWater(AbstractGameAsset a, Player p, int amount)
        {
            BuyPoint bp = a.Field.BuyPoint;

            if (bp.DevelopmentRightsOwner != p)
            {
                throw new WaterWarsGameLogicException(
                          "{0} tried to allocate water on asset {1} but development rights are owned by {2}",
                          p, a, bp.DevelopmentRightsOwner);
            }

            if (!a.CanBeAllocatedWater)
            {
                throw new WaterWarsGameLogicException(
                          "{0} tried to allocate water on asset {1} but this asset type does not allow water allocation",
                          p.Name, a.Name);
            }

            if (!a.IsBuilt)
            {
                throw new WaterWarsGameLogicException(
                          "{0} tried to allocate water on asset {1} but it is only partially built",
                          p.Name, a.Name);
            }

            m_log.InfoFormat(
                "[WATER WARS]: {0} using {1} on {2} at {3} in {4}",
                p.Name, WaterWarsUtils.GetWaterUnitsText(amount), a.Name, bp.Name, bp.Location.RegionName);

            m_controller.WaterAllocator.ChangeAllocation(a, p, amount);
            m_controller.EventManager.TriggerWaterUsed(a, p, amount);
            a.TriggerChanged();
            bp.TriggerChanged();
            p.TriggerChanged();

            UpdateHudStatus(p);
        }