예제 #1
0
        private static bool ProcessVisiting(ref TouristAI touristAI, uint citizenId, ref Citizen citizen)
        {
            CitizenActivityMonitor.LogActivity(citizenId, CitizenActivityMonitor.Activity.Visiting);

            if (!citizen.ValidVisitBuilding())
            {
                return(false);
            }

            var touristHotelSearchRadius = BuildingManager.BUILDINGGRID_CELL_SIZE * 4;
            var currentBuildingInstance  = citizen.VisitBuildingInstance().Value;
            var simulationManager        = SimulationManager.instance;

            if (citizen.Tired() || citizen.Tired(TimeSpan.FromHours(6)))
            {
                if (citizen.Tired() && citizen.InHotel())
                {
                    touristAI.GoToSleep(citizenId);

                    return(true);
                }

                var foundHotel = touristAI.FindHotel(citizenId, ref citizen, currentBuildingInstance, touristHotelSearchRadius);
                if (foundHotel != 0 && simulationManager.m_randomizer.Int32(10) < 8)
                {
                    var foundHotelInstance  = BuildingManager.instance.m_buildings.m_buffer[foundHotel];
                    var estimatedTravelTime = TravelTime.EstimateTravelTime(currentBuildingInstance, foundHotelInstance);

                    if (citizen.Tired(estimatedTravelTime))
                    {
                        touristAI.TryVisit(citizenId, ref citizen, foundHotel);

                        return(true);
                    }
                }
                else if (citizen.Tired())
                {
                    touristAI.LeaveTheCity(citizenId, ref citizen);

                    return(true);
                }
            }

            var goSomewhere = (simulationManager.m_randomizer.Int32(10) < 3 || citizen.InHotel()) && !citizen.AfraidOfGettingWet();

            if (goSomewhere)
            {
                var keepItLocal = simulationManager.m_randomizer.Int32(10) < 8;
                if (keepItLocal)
                {
                    var    ventureDistance      = (BuildingManager.BUILDINGGRID_CELL_SIZE * 2) + (simulationManager.m_randomizer.Int32(3) * BuildingManager.BUILDINGGRID_CELL_SIZE);
                    var    randomActivityNumber = simulationManager.m_randomizer.Int32(9);
                    ushort closeActivity        = 0;

                    if (randomActivityNumber < 3 || simulationManager.m_currentGameTime.Hour >= 21)
                    {
                        closeActivity = touristAI.FindLeisure(citizenId, ref citizen, currentBuildingInstance, ventureDistance);
                    }
                    else if (randomActivityNumber < 6)
                    {
                        closeActivity = touristAI.FindPark(citizenId, ref citizen, currentBuildingInstance, ventureDistance);
                    }
                    else
                    {
                        closeActivity = touristAI.FindShop(citizenId, ref citizen, currentBuildingInstance, ventureDistance);
                    }

                    if (closeActivity != 0)
                    {
                        var closeActivityBuilding = BuildingManager.instance.m_buildings.m_buffer[closeActivity];
                        if (!citizen.Tired(TravelTime.EstimateTravelTime(currentBuildingInstance, closeActivityBuilding)))
                        {
                            touristAI.TryVisit(citizenId, ref citizen, closeActivity);
                        }
                    }
                }
                else
                {
                    var goShopping = simulationManager.m_randomizer.Int32(10) < 5;
                    var extendedVentureDistance = BuildingManager.BUILDINGGRID_CELL_SIZE * 6;

                    if (goShopping)
                    {
                        touristAI.GoToAShop(citizenId, ref citizen, extendedVentureDistance);
                    }
                    else
                    {
                        touristAI.GoToAFunActivity(citizenId, ref citizen, citizen.GetBuilding(), extendedVentureDistance);
                    }
                }
            }
            else if (citizen.GettingWet())
            {
                CitizenActivityMonitor.LogActivity(citizenId, CitizenActivityMonitor.Activity.GettingWet);

                var hotel = touristAI.FindHotel(citizenId, ref citizen, currentBuildingInstance, touristHotelSearchRadius);
                if (hotel != 0)
                {
                    touristAI.TryVisit(citizenId, ref citizen, hotel);
                }
            }

            return(true);
        }
        private static bool ProcessActivity(ref ResidentAI residentAI, uint citizenId, ref Citizen citizen)
        {
            var simulationManager       = SimulationManager.instance;
            var ageGroup                = Citizen.GetAgeGroup(citizen.Age);
            var happiness               = Citizen.GetHappiness(citizen.m_health, citizen.m_wellbeing);
            var wealth                  = citizen.WealthLevel;
            var happinessLevel          = Citizen.GetHappinessLevel(happiness);
            var randomActivityNumber    = simulationManager.m_randomizer.Int32(100);
            var currentBuilding         = citizen.GetBuilding();
            var currentBuildingInstance = citizen.GetBuildingInstance();

            if (currentBuildingInstance.HasValue)
            {
                if (ageGroup <= Citizen.AgeGroup.Child || ageGroup > Citizen.AgeGroup.Adult)
                {
                    var ventureDistance = BuildingManager.BUILDINGGRID_CELL_SIZE * ((int)happinessLevel + 1);
                    var closeActivity   = randomActivityNumber < 50 ? residentAI.FindPark(citizenId, ref citizen, currentBuildingInstance.Value, ventureDistance) : residentAI.FindShop(citizenId, ref citizen, currentBuildingInstance.Value, ventureDistance);

                    if (closeActivity != 0)
                    {
                        var closeActivityBuilding = BuildingManager.instance.m_buildings.m_buffer[closeActivity];
                        if (!citizen.Tired(TravelTime.EstimateTravelTime(currentBuildingInstance.Value, closeActivityBuilding)))
                        {
                            residentAI.TryVisit(citizenId, ref citizen, closeActivity);
                        }
                    }

                    return(true);
                }
                else if (ageGroup <= Citizen.AgeGroup.Adult)
                {
                    if (randomActivityNumber < 90)
                    {
                        var    ventureDistance = (BuildingManager.BUILDINGGRID_CELL_SIZE * 1.5f) * ((int)happinessLevel + 1);
                        ushort closeActivity   = 0;

                        if (randomActivityNumber < 26 || simulationManager.m_currentGameTime.Hour >= 21)
                        {
                            closeActivity = residentAI.FindLeisure(citizenId, ref citizen, currentBuildingInstance.Value, ventureDistance);
                        }
                        else if (randomActivityNumber < 52)
                        {
                            closeActivity = residentAI.FindPark(citizenId, ref citizen, currentBuildingInstance.Value, ventureDistance);
                        }
                        else
                        {
                            closeActivity = residentAI.FindShop(citizenId, ref citizen, currentBuildingInstance.Value, ventureDistance);
                        }

                        if (closeActivity != 0)
                        {
                            var closeActivityBuilding = BuildingManager.instance.m_buildings.m_buffer[closeActivity];
                            if (!citizen.Tired(TravelTime.EstimateTravelTime(currentBuildingInstance.Value, closeActivityBuilding)))
                            {
                                residentAI.TryVisit(citizenId, ref citizen, closeActivity);
                            }
                        }
                    }
                    else
                    {
                        var goShopping = simulationManager.m_randomizer.Int32(10) < 5;
                        var extendedVentureDistance = BuildingManager.BUILDINGGRID_CELL_SIZE * 6;

                        if (goShopping)
                        {
                            residentAI.GoToAShop(citizenId, ref citizen, extendedVentureDistance);
                        }
                        else
                        {
                            residentAI.GoToAFunActivity(citizenId, ref citizen, currentBuilding, extendedVentureDistance);
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }