/// <summary> /// Ends the current day, and moves onto the next one. /// </summary> public void ProcessDayEnd() { //Gather the cumulative reputation for all companies. double totalReputation = 0; List <double> cumulativeReputation = new List <double>(); CompaniesClosedYesterday = new List <Company>(); foreach (var c in Companies) { totalReputation += c.Reputation; cumulativeReputation.Add(totalReputation); } //Loop over each house and see if they eat out, and if so, where. visits = new List <Tuple <Vector2, Vector2> >(); CalculateVisitsFromHouseholds(cumulativeReputation, totalReputation); //Process the end of the day for each company. for (int i = 0; i < Companies.Count; i++) { Companies[i].ProcessDayEnd(); //Is the company bankrupt? if (Companies[i].Balance < 0) { //Bankrupt the company, remove from list (log event). EventChain.AddEvent(new BankruptcyEvent() { CompanyName = Companies[i].Name, DaysLasted = DaysElapsed }); CompaniesClosedYesterday.Add(Companies[i]); Companies.RemoveAt(i); i--; } } //Only do random events if companies still exist. if (Companies.Count > 0) { //Choose the random events that will occur at this day end. double eventRand = Random.NextDouble(); if (eventRand < Settings.Get.BaseChanceOfRandomEvents) { //Random household addition event. eventRand = Random.NextDouble(); if (eventRand < Settings.Get.ChanceOfAddHouseholdsEvent) { ProcessAddHouseholdsEvent(); } //Random fuel cost change event. eventRand = Random.NextDouble(); if (eventRand < Settings.Get.ChanceOfChangeFuelCostEvent) { ProcessChangeFuelCostEvent(); } //Random reputation change event. eventRand = Random.NextDouble(); if (eventRand < Settings.Get.ChanceOfReputationChangeEvent) { ProcessChangeReputationEvent(); } //Random daily cost change event. eventRand = Random.NextDouble(); if (eventRand < Settings.Get.ChanceOfCostChangeEvent) { ProcessCostChangeEvent(); } } } //Process households leaving for the day. Settlement.ProcessLeavers(); //End this day's event chain, and start a new one. EventChain.Refresh(); //Draw the new map with updated positions and tracers, if the map is enabled. UpdateMap(); DaysElapsed++; }
public FoodTruck(Settlement s, Company c, Vector2 startPos, int capacity, double dailyCost) : base(s, c, startPos, capacity, dailyCost) { }
/// <summary> /// Calculates visits from households based on both reputation AND distance AND type of company. /// </summary> protected override void CalculateVisitsFromHouseholds(List <double> cumulativeReputation, double totalReputation) { for (int i = 0; i < Settlement.NumHouseholds; i++) { Household thisHouse = Settlement.GetHouseholdAtIndex(i); //Does this household eat out? if (!thisHouse.EatsOut()) { continue; } //Pick a type of restaurant to eat at. CompanyType picked = PickRestaurantType(); //Get outlets within a set boundary, of the selected type. double radius; switch (picked) { case CompanyType.Family: radius = Settings.Get.BalancedSim_TravelRadiusFamily; break; case CompanyType.FastFood: radius = Settings.Get.BalancedSim_TravelRadiusFastFood; break; case CompanyType.NamedChef: radius = Settings.Get.BalancedSim_TravelRadiusNamedChef; break; default: //Unknown company type. throw new Exception("Unknown company type to set travel radius for. Please update method."); } List <Outlet> outletsToPick = GetOutletsAround(thisHouse.Position, radius).Where(x => x.ParentCompany.Type == picked).ToList(); //Are there any outlets to visit? if (outletsToPick.Count == 0) { //Register a failed event. EventChain.AddEvent(new FailedToEatOutEvent() { Origin = thisHouse.Position, Radius = radius, OutletType = picked }); //This house is now done. continue; } //Get the companies that these outlets have. List <Company> companiesNearMe = new List <Company>(); foreach (var outlet in outletsToPick) { if (companiesNearMe.FindIndex(x => x.Name == outlet.ParentCompany.Name) == -1) { companiesNearMe.Add(outlet.ParentCompany); } } //Randomly roll on their reputation. double totalRep = companiesNearMe.Sum(x => x.Reputation); List <double> cumulativeRep = companiesNearMe.Select(x => x.Reputation).CumulativeSum().ToList(); double randomSelection = Random.NextDouble() * totalRep; Company selected = null; for (int k = 0; k < cumulativeRep.Count; k++) { if (randomSelection < cumulativeRep[k]) { selected = companiesNearMe[k]; break; } } //Successfully selected a company, visit! selected.AddVisitToNearestOutlet(thisHouse.Position, ref base.visits); } }