// Start is called before the first frame update public void SetData(LeisureSector ls) { indexBarInvestment.GetComponent <IndexBarController>().IndexID = ls.Investment.ID; indexBarFun.GetComponent <IndexBarController>().IndexID = ls.Fun.ID; discoPanel.GetComponent <LeisureDisplayController>().SetData(ls.LeisureVenues[(int)Leisure.PLACE.DISCO]); gymPanel.GetComponent <LeisureDisplayController>().SetData(ls.LeisureVenues[(int)Leisure.PLACE.GYM]); parkLanePanel.GetComponent <LeisureDisplayController>().SetData(ls.LeisureVenues[(int)Leisure.PLACE.PARK]); cinemaPanel.GetComponent <LeisureDisplayController>().SetData(ls.LeisureVenues[(int)Leisure.PLACE.CINEMA]); }
public override string ToString() { string res = "City Part: " + CityPlace; res += "\nIndustry Sector: " + IndustrySector.ToString(); res += "\nTransport Sector: " + TransportSector.ToString(); res += "\nLeisure Sector: " + LeisureSector.ToString(); res += "\nNumber of people: " + Citizens.Count + " | Number of free houses: " + nonAllocatedHomes.Count; res += "\nFirst 5 citizens:\n=====================================================================\n"; int cont = 0; foreach (Citizen c in Citizens.Values) { res += c.ToString() + "\n"; if (++cont > 4) { break; } } return(res); }
void InitLeisureSector(FUN fun, SECTOR_INVESTMENT investment) { float investmentValue = 0f, funValue = 0; switch (fun) { case FUN.BORING: funValue = 0.25f; break; case FUN.ENJOYABLE: funValue = 0.5f; break; case FUN.ENTERTAINING: funValue = 0.75f; break; } switch (investment) { case SECTOR_INVESTMENT.LOW: investmentValue = 0.25f; break; case SECTOR_INVESTMENT.MEDIUM: investmentValue = 0.5f; break; case SECTOR_INVESTMENT.HIGH: investmentValue = 0.75f; break; } LeisureSector = new LeisureSector(investmentValue, funValue, CityPlace); }
public SCHEDULED_ACTIVITY[] ProcessDay() // TODO: Currently if the places where the citizen lives and works are different the time to travel { // is calculated without taking into the consideration the TransportSector of the place where he worls ResetDailySchedule(); // All hours are set to NONE int lastWorkHour = -1; if (acceptedJob.JobType == Job.TYPE.NONE) // If the citizen is unenployed { acceptedJob = city.CityParts[(int)LivingPlace].IndustrySector.GetWorkOffer(); if (acceptedJob.JobType == Job.TYPE.NONE) // If the citizen cannot find a job in his neightbourhood... { // tries a second time. This time can be in any part of the city acceptedJob = city.CityParts[(int)LivingPlace].IndustrySector.GetWorkOffer(); } } if (acceptedJob.JobType != Job.TYPE.NONE) // If the citizen has a job { for (int i = 0; i < acceptedJob.TimeRequiered; i++) // Sets the working hours in the schedule { int j = acceptedJob.Enter + i; if (j > 23) { j -= 24; } dailySchedule[j] = SCHEDULED_ACTIVITY.WORK; } // This parts calculates how mucha hours the citizen needs to travel to work int distanceToJob = 0; if (LivingPlace == acceptedJob.CityPlace) { distanceToJob += Math.Abs(acceptedJob.Coords.X - Home.X) + Math.Abs(acceptedJob.Coords.Y - Home.Y); // Manhatan distance } else { distanceToJob += acceptedJob.Coords.X + acceptedJob.Coords.Y + Home.X + Home.Y; } float enviromentalConmmitmentValue = Global.Values.citizenEnviromentalTransportPreferences[(int)enviromentalCommitment]; int transportHoursLimit = Global.Values.citizenTransportTimePreferences[(int)timeManagement]; if (transportHoursLimit > 24 - acceptedJob.TimeRequiered) { transportHoursLimit = 24 - acceptedJob.TimeRequiered; } float rand = Global.Methods.GetRandomPercentage(); TransportSector.TransportPlan transportPlan; if (rand < enviromentalConmmitmentValue) // If the citizen is pro-enviroment will probably choose the least polluting option { transportPlan = city.CityParts[(int)LivingPlace].TransportSector.GetLeastPolluting(distanceToJob, transportHoursLimit); } else // otherwise will choose between safety and speed { if (Health.GetIndexState() < Index.STATE.MEDIUM) // If the citizen's health is low, he will go for the safest option { transportPlan = city.CityParts[(int)LivingPlace].TransportSector.GetSafest(distanceToJob, transportHoursLimit); } else // if that's not the case, he will choose the fastest { transportPlan = city.CityParts[(int)LivingPlace].TransportSector.GeFastest(distanceToJob, transportHoursLimit); } } if (transportPlan.Transport == Transport.TYPE.NONE) // If the citizen can't go to work he gets sad, and A PANALTY { Happiness.ChangeIndexValue(Index.CHANGE.LOW_DROP); RemoveMoney(Global.Values.failingToWorkPenalty); ResetDailySchedule(); // If there is not transport there is not work either } else { // Using the transport has a cost in health Health.ChangeIndexValue(-(1 - transportPlan.Safety)); lastWorkHour = acceptedJob.Enter + acceptedJob.TimeRequiered; } // If the citizens has no transport plan (because there are not viable options) => transportPlan.TimeRequiered = -1 for (int i = 1; i < transportPlan.TimeRequiered + 1; i++) // Sets the moving to work hours in the schedule { int j = acceptedJob.Enter - i; if (j < 0) { j += 24; } dailySchedule[j] = SCHEDULED_ACTIVITY.MOVE_TO_WORK; } acceptedJob.RemainingDays--; if (acceptedJob.RemainingDays < 0) // The day 0 is included { acceptedJob = city.CityParts[(int)LivingPlace].IndustrySector.FreeWorkOffer(acceptedJob.Coords); } } LeisureSector.LeisurePlan leisurePlan = LeisureSector.GetNullPlan(); if (Health.GetIndexState() > Index.STATE.LOW) // If the citizen is not sick he will try to have fun { int firstAvailableHour = lastWorkHour + 1; int lastAvailableHour = acceptedJob.Enter - 1; if (lastWorkHour < 0) { firstAvailableHour = 0; lastAvailableHour = 23; } float rand = Global.Methods.GetRandomPercentage(); float moneyExpendingValue = Global.Values.citizenMoneyExpendingPreferences[(int)moneyManagement]; if (rand < moneyExpendingValue) { leisurePlan = city.CityParts[(int)LivingPlace].LeisureSector.GetCheapestPlan(Nature, firstAvailableHour, lastAvailableHour); } else { leisurePlan = city.CityParts[(int)LivingPlace].LeisureSector.GetMostSatisfyingPlan(Nature, firstAvailableHour, lastAvailableHour); } } if (leisurePlan.Place != Leisure.PLACE.NONE) { RemoveMoney(leisurePlan.Cost); Happiness.ChangeIndexValue(leisurePlan.Satisfaction); for (int i = 0; i < leisurePlan.TimeExpended; i++) { int j = leisurePlan.Enter + i; if (j > 23) { j -= 24; } dailySchedule[j] = SCHEDULED_ACTIVITY.HAVE_FUN; } } // If the citizen's schedule contains enough continious hours without activitys this ours become resting hours. Theese ones are healthy int continiousNoneActivutyHours = 0; int firstActivityHour = -1; for (int i = 0; i < 24; i++) { SCHEDULED_ACTIVITY s = dailySchedule[i]; if (s == SCHEDULED_ACTIVITY.NONE) { continiousNoneActivutyHours++; } else if (firstActivityHour < 0) { firstActivityHour = i; } if (continiousNoneActivutyHours == Global.Values.minContiniousHoursToRest) { for (int j = i; j > i - continiousNoneActivutyHours; j--) { dailySchedule[j] = SCHEDULED_ACTIVITY.REST; } continiousNoneActivutyHours = 0; } } if (continiousNoneActivutyHours + firstActivityHour + 1 >= Global.Values.minContiniousHoursToRest && firstActivityHour + 1 < Global.Values.minContiniousHoursToRest) { for (int i = 0; i < continiousNoneActivutyHours + firstActivityHour + 1; i++) { int j = continiousNoneActivutyHours + i; if (j > 23) { j -= 24; } dailySchedule[j] = SCHEDULED_ACTIVITY.REST; } } foreach (SCHEDULED_ACTIVITY s in dailySchedule) { if (s == SCHEDULED_ACTIVITY.REST) { Health.ChangeIndexValue(Global.Values.restingHourBonus); } } return(dailySchedule); }