コード例 #1
0
        public void AddMoney(DwarfBux money)
        {
            if (money == 0.0m)
            {
                return;
            }

            // In this case, we need to remove money from the economy.
            // This means that we first take money from treasuries. If there is any left,
            // we subtract it from the current money count.
            if (money < 0)
            {
                DwarfBux amountLeft = -money;
                foreach (Treasury treasury in Treasurys)
                {
                    DwarfBux amountToTake = System.Math.Min(treasury.Money, amountLeft);
                    treasury.Money -= amountToTake;
                    amountLeft     -= amountToTake;
                }
                return;
            }

            DwarfBux amountRemaining = money;

            foreach (Treasury treasury in Treasurys)
            {
                if (amountRemaining <= 0)
                {
                    break;
                }

                DwarfBux maxInTreasury = treasury.Voxels.Count * Treasury.MoneyPerPile - treasury.Money;
                DwarfBux amountToTake  = System.Math.Min(maxInTreasury, amountRemaining);

                amountRemaining -= amountToTake;
                treasury.Money  += amountToTake;
            }
            if (amountRemaining > 0 && RoomBuilder.DesignatedRooms.Count > 0)
            {
                World.MakeAnnouncement("We need more treasuries!");
                // Generate a number of coin piles.
                for (DwarfBux total = 0m; total < amountRemaining; total += 1024m)
                {
                    Zone    randomZone = Datastructures.SelectRandom(RoomBuilder.DesignatedRooms);
                    Vector3 point      = MathFunctions.RandVector3Box(randomZone.GetBoundingBox()) +
                                         new Vector3(0, 1.0f, 0);
                    CoinPile pile = EntityFactory.CreateEntity <CoinPile>("Coins Resource", point);
                    pile.Money = 1024m;

                    // Special case where we just need to add a little bit of money (less than 64 coins)
                    if (money - total < 1024m)
                    {
                        pile.Money = money - total;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Treasury.cs プロジェクト: Rod995/dwarfcorp
        public override void Destroy()
        {
            DwarfBux moneyLeft = Money;

            foreach (Body coinPile in Coins)
            {
                CoinPile coins = EntityFactory.CreateEntity <CoinPile>("Coins Resource", coinPile.Position);
                coins.Money = Math.Min(MoneyPerPile, moneyLeft);
                moneyLeft  -= coins.Money;
            }
            Faction.Economy.CurrentMoney -= Money;
            if (Faction != null)
            {
                Faction.Treasurys.Remove(this);
            }
            base.Destroy();
        }