public static bool ProcessVisit(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { if (ProcessGenerics(ref thisAI, citizenID, ref person)) { SimulationManager _simulation = Singleton <SimulationManager> .instance; WeatherManager _weatherManager = Singleton <WeatherManager> .instance; BuildingManager _buildingManager = Singleton <BuildingManager> .instance; ItemClass.Service service = ItemClass.Service.None; if (person.m_visitBuilding != 0) { service = _buildingManager.m_buildings.m_buffer[person.m_visitBuilding].Info.m_class.m_service; } if (service == ItemClass.Service.PoliceDepartment || service == ItemClass.Service.HealthCare) { if (person.m_homeBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); return(true); } } if (service == ItemClass.Service.Disaster) { if (_buildingManager.m_buildings.m_buffer[person.m_visitBuilding].m_flags.IsFlagSet(Building.Flags.Downgrading) && person.m_homeBuilding != 0 && person.m_vehicle == 0) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); } } else if (!GameEventHelpers.EventTakingPlace(person.m_visitBuilding) && !CityEventManager.instance.EventTakingPlace(person.m_visitBuilding) && !CityEventManager.instance.EventStartsWithin(person.m_visitBuilding, 2D)) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); bool eventOn = false; if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; eventOn = true; } } } if (!eventOn) { if (person.m_instance != 0 && _weatherManager.m_currentRain > 0 && _simulation.m_randomizer.Int32(0, 10) <= (_weatherManager.m_currentRain * 10)) { //It's raining, we're outside, and we need to go somewhere dry! if (person.m_workBuilding != 0 && !_simulation.m_isNightTime && !Chances.ShouldReturnFromWork(ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_workBuilding); LoggingWrapper.Log("Rain! Citizen " + citizenID + " is getting wet, and has decided to go back to work."); } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); LoggingWrapper.Log("Rain! Citizen " + citizenID + " is getting wet, and has decided to go home."); } person.SetVisitplace(citizenID, 0, 0U); } else if (person.m_workBuilding != 0 && (Chances.ShouldGoToWork(ref person) || ((Chances.LunchHour() || Chances.HoursSinceLunchHour(1.5f)) && Chances.ShouldGoToWork(ref person, true)))) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_workBuilding); person.SetVisitplace(citizenID, 0, 0U); LoggingWrapper.Log("Citizen " + citizenID + " was out and about but should've been at work. Going there now."); } else if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None) { if (person.m_visitBuilding == 0) { person.CurrentLocation = Citizen.Location.Home; } else { BuildingManager instance = Singleton <BuildingManager> .instance; BuildingInfo info = instance.m_buildings.m_buffer[person.m_visitBuilding].Info; int amountDelta = -100; info.m_buildingAI.ModifyMaterialBuffer(person.m_visitBuilding, ref instance.m_buildings.m_buffer[person.m_visitBuilding], TransferManager.TransferReason.Shopping, ref amountDelta); } return(true); } else if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && person.m_homeBuilding != 0 && person.m_vehicle == 0) { uint shouldStayPercent = 2; if (Chances.CanStayOut(ref person) && _simulation.m_randomizer.UInt32(100) < shouldStayPercent) { if (Chances.ShouldGoFindEntertainment(ref person)) { if (_simulation.m_isNightTime) { FindLeisure(ref thisAI, citizenID, ref person, person.m_visitBuilding); } else { NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); return(true); } } } } } person.m_flags &= Citizen.Flags.Unemployed | Citizen.Flags.Wealth | Citizen.Flags.Location | Citizen.Flags.NoElectricity | Citizen.Flags.NoWater | Citizen.Flags.NoSewage | Citizen.Flags.BadHealth | Citizen.Flags.Created | Citizen.Flags.Tourist | Citizen.Flags.Sick | Citizen.Flags.Dead | Citizen.Flags.Student | Citizen.Flags.MovingIn | Citizen.Flags.DummyTraffic | Citizen.Flags.Criminal | Citizen.Flags.Arrested | Citizen.Flags.Evacuating | Citizen.Flags.Collapsed | Citizen.Flags.Education1 | Citizen.Flags.Education2 | Citizen.Flags.Education3 | Citizen.Flags.Original | Citizen.Flags.CustomName; return(false); }
public static bool ProcessHome(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { CitizenManager _citizenManager = Singleton <CitizenManager> .instance; SimulationManager _simulation = Singleton <SimulationManager> .instance; if ((person.m_flags & Citizen.Flags.MovingIn) != Citizen.Flags.None) { _citizenManager.ReleaseCitizen(citizenID); } else if (ProcessGenerics(ref thisAI, citizenID, ref person)) { if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None && (!Chances.WorkDay(ref person) || _simulation.m_currentDayTimeHour > Chances.m_startWorkHour)) //Wants to go shopping { if (person.m_homeBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) //Person isn't already out and about { if (_simulation.m_isNightTime) { uint chance = _simulation.m_randomizer.UInt32(1000); if (chance < Chances.GoOutAtNight(person.Age) && NewResidentAI.DoRandomMove(thisAI)) { //Only go locally to find a shop at night FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_homeBuilding, 1000f); return(true); } } else if (NewResidentAI.DoRandomMove(thisAI)) { uint chance = _simulation.m_randomizer.UInt32(100); if (chance < 10) { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_homeBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_homeBuilding, NewResidentAI.GetShoppingReason(thisAI)); } return(true); } } } } else if (person.m_homeBuilding != 0 && person.m_instance != 0 && person.m_vehicle == 0 || NewResidentAI.DoRandomMove(thisAI)) //If the person is already out and about, or can move (based on entities already visible) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_homeBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; return(true); } } } else { if (person.m_workBuilding != 0 && !_simulation.m_isNightTime && !Chances.ShouldReturnFromWork(ref person)) { if (Chances.ShouldGoToWork(ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_homeBuilding, person.m_workBuilding); return(true); } } else { if (Chances.ShouldGoFindEntertainment(ref person)) { if (_simulation.m_isNightTime) { FindLeisure(ref thisAI, citizenID, ref person, person.m_homeBuilding); } else { NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_homeBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } } } } } return(false); }
public static bool ProcessWork(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { CitizenManager _citizenManager = Singleton <CitizenManager> .instance; BuildingManager _buildingManager = Singleton <BuildingManager> .instance; SimulationManager _simulation = Singleton <SimulationManager> .instance; if (ProcessGenerics(ref thisAI, citizenID, ref person)) { if (person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) //If the person is already out and about, or can move (based on entities already visible) { if (Chances.ShouldReturnFromWork(ref person)) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_workBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; } } } else { if (Chances.ShouldGoFindEntertainment(ref person)) { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_workBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } else { if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None) //Wants to go shopping { if (person.m_workBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) //Person isn't already out and about { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_workBuilding, NewResidentAI.GetShoppingReason(thisAI)); } } return(true); } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_workBuilding, person.m_homeBuilding); return(true); } } } } else if (Chances.ShouldGoToLunch(ref person) && person.m_workBuilding != 0) { //Try find somewhere close to eat ushort foundLunchPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 200f); if (foundLunchPlace != 0) { LoggingWrapper.Log("Citizen " + citizenID + " is heading out to eat for lunch at " + CityEventManager.CITY_TIME.ToShortTimeString() + "."); return(true); } else { LoggingWrapper.Log("Citizen " + citizenID + " wanted to head out for lunch, but there were no buildings close enough."); } } } } return(false); }