Ejemplo n.º 1
0
        private void Update()
        {
            bool useThisDateBar = true;

            CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.GetOptionValue("CityTimeDateBar", ref useThisDateBar);

            if (useThisDateBar)
            {
                if (_oldDayProgressSprite != null)
                {
                    _oldDayProgressSprite.Hide();
                }

                if (_newDayProgressSprite != null)
                {
                    _newDayProgressSprite.Show();
                }
            }
            else
            {
                if (_oldDayProgressSprite != null)
                {
                    _oldDayProgressSprite.Show();
                }

                if (_newDayProgressSprite != null)
                {
                    _newDayProgressSprite.Hide();
                }
            }

            if (_newDayProgressSprite != null && _newDayProgressLabel != null)
            {
                SimulationManager _simulationManager = Singleton <SimulationManager> .instance;
                DateTime          _date       = CityEventManager.CITY_TIME;
                Color32           _barColour  = new Color32(199, 254, 115, 255);
                double            currentHour = _date.TimeOfDay.TotalHours;

                if (_simulationManager.SimulationPaused || _simulationManager.ForcedSimulationPaused)
                {
                    _barColour = new Color32(255, 115, 115, 255);
                }
                else if (CityEventManager.instance.EventTakingPlace())
                {
                    _barColour = new Color32(255, 230, 115, 255);
                }
                else if (GameEventHelpers.EventTakingPlace())
                {
                    _barColour = new Color32(220, 220, 220, 255);
                }

                _newDayProgressSprite.fillAmount = (float)currentHour / 24F;
                _newDayProgressSprite.color      = _barColour;
                _newDayProgressSprite.tooltip    = _date.ToString(Experiments.ExperimentsToggle.DateFormat, LocaleManager.cultureInfo);

                _newDayProgressLabel.text = _date.ToString(Experiments.ExperimentsToggle.NormalClock ? "dddd HH:mm" : "dddd hh:mm tt", LocaleManager.cultureInfo);

                if (CityEventManager.CITY_TIME - _lastTime >= new TimeSpan(0, 1, 0))
                {
                    UpdateEventBlocks();
                }

                _newDayProgressLabel.BringToFront();
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
                }
            }
        }