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; }
private double ExecuteRenovations() { var expenses = 0.0; foreach (var house in RealEstatePortfolio.Houses) { foreach (var renovationProjectType in RenovationProjectType.GetAll()) { if (!IsRenovationProjectExecuted(house, renovationProjectType) && Policy.DetermineExecutionRenovationProject(house, renovationProjectType)) { var project = new RenovationProject(renovationProjectType); expenses += project.Execute(house); _executedRenovationProjects[house].Add(renovationProjectType); } } } return(expenses); }