public VehiclePrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _mapping = new PrefabMapping<ushort>();
        }
        public HumanPrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _mapping = new PrefabMapping<uint>();
        }
        public AnimalPrefabMapping()
        {
            _settings = Settings.Instance;
            _helper = Helper.Instance;
            _data = Data.Instance;

            _prefabs = new Dictionary<string, int>();
            LoadTrackedPrefabs();

            _mapping = new PrefabMapping<ushort>();
        }
        /*
         * Handles creation and removal of humans
         *
         * Note: Just because a human has been removed visually, it does not mean
         * it is removed as far as the game is concerned. The human is only truly removed
         * when the frame covers the human's id, and that's when we will remove the
         * human from our records.
         */
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated) return;

            if (!_helper.HumanMonitorSpinnable) return;

            if (!_settings.Enable._HumanMonitor) return;

            try
            {
                if (!_initialized)
                {
                    _data = Data.Instance;

                    _mapping = new HumanPrefabMapping();

                    _paused = false;

                    _instance = Singleton<CitizenManager>.instance;
                    _capacity = _instance.m_citizens.m_buffer.Length;

                    _id = (uint)_capacity;

                    for (int i = 0; i < _capacity; i++)
                        UpdateHuman((uint)i);

                    _lastProcessedFrame = GetFrame();

                    _initialized = true;
                    _helper.HumanMonitorSpun = true;
                    _helper.HumanMonitor = this;

                    _helper.NotifyPlayer("Human monitor initialized");
                }
                else if (!SimulationManager.instance.SimulationPaused)
                {
                    _data._HumansUpdated.Clear();
                    _data._HumansRemoved.Clear();

                    int end = GetFrame();

                    while (_lastProcessedFrame != end)
                    {
                        _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1);

                        int[] boundaries = GetFrameBoundaries();
                        uint id;

                        for (int i = boundaries[0]; i <= boundaries[1]; i++)
                        {
                            id = (uint)i;

                            if (UpdateHuman(id))
                                _data._HumansUpdated.Add(id);
                            else if (_data._Humans.Contains(id))
                            {
                                _data._HumansRemoved.Add(id);
                                RemoveHuman(id);
                            }
                        }
                    }
                }

                OutputDebugLog();
            }
            catch (Exception e)
            {
                string error = "Human monitor failed to initialize\r\n";
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                _helper.Log(error);

                _terminated = true;
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }
        /*
         * Handles creation and removal of animals
         *
         * Note: Just because a animal has been removed visually, it does not mean
         * it is removed as far as the game is concerned. The animal is only truly removed
         * when the frame covers the animal's id, and that's when we will remove the
         * animal from our records.
         */
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated) return;

            if (!_helper.AnimalMonitorSpinnable) return;

            if (!_settings.Enable._AnimalMonitor) return;

            try
            {
                if (!_initialized)
                {
                    _data = Data.Instance;

                    _mapping = new AnimalPrefabMapping();

                    _buildingsAnimals = new Dictionary<ushort, HashSet<ushort>>();

                    _paused = false;

                    _instance = Singleton<CitizenManager>.instance;
                    _capacity = _instance.m_instances.m_buffer.Length;

                    _id = (ushort)_capacity;

                    for (int i = 0; i < _capacity; i++)
                        UpdateAnimal((ushort)i);

                    _initialized = true;
                    _helper.AnimalMonitorSpun = true;
                    _helper.AnimalMonitor = this;

                    _helper.NotifyPlayer("Animal monitor initialized");
                }
                else if (_data.BuildingsUpdated.Length > 0)
                {
                    _data._AnimalsUpdated.Clear();
                    _data._AnimalsRemoved.Clear();

                    foreach (ushort building in _data._BuildingsUpdated)
                    {
                        ushort id = Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_targetCitizens;

                        while (id != 0)
                        {
                            if (UpdateAnimal(id))
                            {
                                _data._AnimalsUpdated.Add(id);
                                AddBuildingsAnimal(building, id);
                            }
                            else
                            {
                                _data._AnimalsRemoved.Add(id);

                                if (_data._Animals.Contains(id))
                                    RemoveAnimal(id);
                            }

                            id = _instance.m_instances.m_buffer[(int)id].m_nextTargetInstance;
                        }

                        CheckBuildingsAnimals(building);
                    }

                    foreach (ushort building in _data._BuildingsRemoved)
                        RemoveBuildingsAnimals(building);
                }

                OutputDebugLog();
            }
            catch (Exception e)
            {
                string error = "Animal monitor failed to initialize\r\n";
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                _helper.Log(error);

                _terminated = true;
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }
Exemple #6
0
        /*
         * Handles creation and removal of vehicles
         *
         * Note: Just because a vehicle has been removed visually, it does not mean
         * it is removed as far as the game is concerned. The vehicle is only truly removed
         * when the frame covers the vehicle's id, and that's when we will remove the
         * vehicle from our records.
         */
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            if (_terminated)
            {
                return;
            }

            if (!_helper.VehicleMonitorSpinnable)
            {
                return;
            }

            if (!_settings.Enable._VehicleMonitor)
            {
                return;
            }

            try
            {
                if (!_initialized)
                {
                    _data = Data.Instance;

                    _mapping = new VehiclePrefabMapping();

                    _paused = false;

                    _instance = Singleton <VehicleManager> .instance;
                    _capacity = _instance.m_vehicles.m_buffer.Length;

                    _id = (ushort)_capacity;

                    _initialized = true;
                    _helper.VehicleMonitorSpun = true;
                    _helper.VehicleMonitor     = this;

                    _helper.Log("Vehicle monitor initialized");
                }
                else if (!SimulationManager.instance.SimulationPaused)
                {
                    _data._VehiclesUpdated.Clear();
                    _data._VehiclesRemoved.Clear();

                    int end = GetFrame();

                    while (_lastProcessedFrame != end)
                    {
                        _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1);

                        int[]  boundaries = GetFrameBoundaries();
                        ushort id;

                        for (int i = boundaries[0]; i <= boundaries[1]; i++)
                        {
                            id = (ushort)i;

                            if (UpdateVehicle(id))
                            {
                                _data._VehiclesUpdated.Add(id);
                            }
                            else if (_data._Vehicles.Contains(id))
                            {
                                _data._VehiclesRemoved.Add(id);
                                RemoveVehicle(id);
                            }
                        }
                    }
                }

                OutputDebugLog();
            }
            catch (Exception e)
            {
                string error = "Vehicle monitor failed to initialize\r\n";
                error += String.Format("Error: {0}\r\n", e.Message);
                error += "\r\n";
                error += "==== STACK TRACE ====\r\n";
                error += e.StackTrace;

                _helper.Log(error);

                _terminated = true;
            }

            base.OnUpdate(realTimeDelta, simulationTimeDelta);
        }