Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }