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); }
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 void UpdateLocation(TouristAI thisAI, uint citizenID, ref Citizen person) { if (person.m_homeBuilding == 0 && person.m_workBuilding == 0 && (person.m_visitBuilding == 0 && person.m_instance == 0)) { Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); } else { switch (person.CurrentLocation) { case Citizen.Location.Home: Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); break; case Citizen.Location.Work: Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); break; case Citizen.Location.Visit: if (person.Dead || person.Sick || (int)person.m_visitBuilding == 0) { Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); break; } if (!person.Collapsed) { SimulationManager _simulationManager = Singleton <SimulationManager> .instance; BuildingManager _buildingManager = Singleton <BuildingManager> .instance; Building _currentBuilding = _buildingManager.m_buildings.m_buffer[person.m_visitBuilding]; BuildingInfo _buildingInfo = _currentBuilding.Info; float time = _simulationManager.m_currentDayTimeHour; bool visitingHours = time > _simulationManager.m_randomizer.Int32(6, 8) && time < _simulationManager.m_randomizer.Int32(18, 23); int reduceAmount = -100; if (_currentBuilding.Info.m_class.m_service != ItemClass.Service.Disaster || !_currentBuilding.m_flags.IsFlagSet(Building.Flags.Downgrading)) { if (_currentBuilding.m_flags.IsFlagSet(Building.Flags.Evacuating)) { FindEvacuationPlace(thisAI, citizenID, person.m_visitBuilding, GetEvacuationReason(thisAI, person.m_visitBuilding)); } 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, ResidentLocationHandler.StartMovingToEventTime); if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(ResidentLocationHandler.StartMovingToEventTime) && !_cityEvent.EventStartsWithin(ResidentLocationHandler.MaxMoveToEventTime)) { if ((person.m_instance != 0 || DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { 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; } } } else if (visitingHours) { int chance = _simulationManager.m_randomizer.Int32(10U); if (chance == 0 && (person.m_instance != 0 || DoRandomMove(thisAI))) { FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, GetLeavingReason(thisAI, citizenID, ref person)); } else if (chance > 7) { break; } else if (chance > 5) { if (person.m_instance != 0 || DoRandomMove(thisAI)) { FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, GetShoppingReason(thisAI)); } _buildingInfo.m_buildingAI.ModifyMaterialBuffer(person.m_visitBuilding, ref _buildingManager.m_buildings.m_buffer[person.m_visitBuilding], TransferManager.TransferReason.Shopping, ref reduceAmount); AddTouristVisit(thisAI, citizenID, person.m_visitBuilding); } else if (chance > 3) { if (person.m_instance != 0 || DoRandomMove(thisAI)) { FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, GetEntertainmentReason(thisAI)); } } else { _buildingInfo.m_buildingAI.ModifyMaterialBuffer(person.m_visitBuilding, ref _buildingManager.m_buildings.m_buffer[person.m_visitBuilding], TransferManager.TransferReason.Shopping, ref reduceAmount); AddTouristVisit(thisAI, citizenID, person.m_visitBuilding); } } else if (_buildingInfo.m_class.m_subService != ItemClass.SubService.CommercialTourist) //Not in a hotel { if (person.m_instance != 0 || DoRandomMove(thisAI)) { //Try find a hotel ushort foundHotel = _buildingManager.FindBuilding(_currentBuilding.m_position, 1000f, ItemClass.Service.Commercial, ItemClass.SubService.CommercialTourist, Building.Flags.Created | Building.Flags.Active, Building.Flags.Deleted); if (foundHotel != 0) { if (_simulationManager.m_randomizer.Int32(0, 10) > 2) { thisAI.StartMoving(citizenID, ref person, person.m_visitBuilding, foundHotel); person.SetVisitplace(citizenID, foundHotel, 0U); person.m_visitBuilding = foundHotel; AddTouristVisit(thisAI, citizenID, foundHotel); LoggingWrapper.Log("Tourist " + citizenID + " found hotel."); } else { LoggingWrapper.Log("Tourist " + citizenID + " found a hotel, but instead chose to go home."); FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, GetLeavingReason(thisAI, citizenID, ref person)); } } else { LoggingWrapper.Log("Tourist " + citizenID + " couldn't find a hotel, so is heading home instead."); FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, GetLeavingReason(thisAI, citizenID, ref person)); } } } } } } break; case Citizen.Location.Moving: if (person.Dead || person.Sick) { Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); break; } if ((int)person.m_vehicle != 0 || (int)person.m_instance != 0) { break; } Singleton <CitizenManager> .instance.ReleaseCitizen(citizenID); break; } } }