コード例 #1
0
        /// <summary>
        /// Opens an outlet at a given position on a settlement (or a random one).
        /// </summary>
        public void OpenOutlet(Vector2 position = null)
        {
            //Need to generate a random position?
            if (position == null)
            {
                position = settlement.GetFreeRandomPosition();
            }
            else
            {
                //Check if the position is occupied.
                if (settlement.IsOccupied(position))
                {
                    throw new Exception("Cannot open an outlet there, the space is occupied.");
                }
            }

            //Sufficient balance?
            if (Balance < OutletCost)
            {
                throw new Exception("Cannot open an outlet, insufficient company balance.");
            }

            //Open the outlet.
            Balance -= Math.Round(OutletCost, 2);
            outlets.Add(new Outlet(settlement, this, position, OutletCapacity, DailyCost));

            //Log in the event chain.
            EventChain.AddEvent(new OutletCreateEvent()
            {
                Position = position,
                Capacity = OutletCapacity
            });
        }
コード例 #2
0
ファイル: Simulation.cs プロジェクト: c272/skeletron
        /// <summary>
        /// Adds a company to the simulation from a CompanyDefault.
        /// </summary>
        public void AddCompanyFromDefault(CompanyDefault company)
        {
            Companies.Add(new Company(Settlement,
                                      company.Name,
                                      company.Type,
                                      company.StartingBalance,
                                      Settlement.GetFreeRandomPosition(),
                                      currentFuelCost,
                                      Settings.Get.BaseCostForDelivery
                                      ));

            //Add outlets for that company at random positions.
            for (int i = 0; i < company.StartingOutlets; i++)
            {
                Companies.Last().OpenOutlet(Settlement.GetFreeRandomPosition());
            }
        }