Ejemplo n.º 1
0
        public void EndOfYear()
        {
            var expensesHouses = RealEstatePortfolio.EndOfYear();
            var earningsSales  = SellHouses();

            foreach (var newDevelopmentProjectType in NewDevelopmentProjectType.GetAll())
            {
                newDevelopmentProjectType.EndOfYear();
            }

            var expensesNewDevelopment = ExecuteNewDevelopmentProjects();

            foreach (var renovationProjectProjectType in RenovationProjectType.GetAll())
            {
                renovationProjectProjectType.EndOfYear();
            }

            var expensesRenovation = ExecuteRenovations();

            var expensesLoans = _loanPortfolio.EndOfYear();

            // If we have spent money we need to attract a new loan.
            var totalExpenses = expensesLoans + expensesHouses + AnnualCosts - _loanPortfolio.Cash - earningsSales + expensesNewDevelopment + expensesRenovation;

            if (totalExpenses > 0)
            {
                var previousDebt = _loanPortfolio.Debt;
                AttractLoan(totalExpenses);
                _loanPortfolio.Cash = 0;

                // Assert that a loan really has been attracted.
                Debug.Assert(Math.Abs(previousDebt + totalExpenses - _loanPortfolio.Debt) < 0.01);
            }
            else
            {
                _loanPortfolio.Cash = -totalExpenses;
            }

            CumulativeInflation *= Economy.Get(Series.PriceInflation) + 1;

            IsBankrupt |= SolvencyRatio < BankruptcyThreshold;
        }