private void UpdateGarbageTrucks()
        {
            SkylinesOverwatch.Data data = SkylinesOverwatch.Data.Instance;
            Vehicle[]  vehicles         = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
            InstanceID instanceID       = new InstanceID();

            foreach (ushort id in data.VehiclesUpdated)
            {
                if (!data.IsHearse(id))
                {
                    continue;
                }

                Vehicle v = vehicles[id];

                if (!_landfills.ContainsKey(v.m_sourceBuilding))
                {
                    continue;
                }

                if (v.Info.m_vehicleAI.GetLocalizedStatus(id, ref v, out instanceID) != _collecting)
                {
                    continue;
                }

                ushort target = _landfills[v.m_sourceBuilding].AssignTarget(v);

                if (target != 0 && target != v.m_targetBuilding)
                {
                    v.Info.m_vehicleAI.SetTarget(id, ref vehicles[id], target);
                }
            }
        }
Esempio n. 2
0
        private void UpdateHearses()
        {
            SkylinesOverwatch.Data data = SkylinesOverwatch.Data.Instance;
            Vehicle[]  vehicles         = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
            InstanceID instanceID       = new InstanceID();

            foreach (ushort id in data.VehiclesUpdated)
            {
                if (!data.IsHearse(id))
                {
                    continue;
                }

                Vehicle v = vehicles[id];

                /*
                 * If a hearse is loading corpse, we will remove it from the vehicle grid,
                 * so other cars can pass it and more than one hearse can service a building.
                 * It doesn't really make sense that only one hearse can be at a high rise
                 * at a time.
                 */
                if ((v.m_flags & Vehicle.Flags.Stopped) != Vehicle.Flags.None)
                {
                    if (!_stopped.Contains(id))
                    {
                        Singleton <VehicleManager> .instance.RemoveFromGrid(id, ref vehicles[id], false);

                        _stopped.Add(id);
                    }

                    continue;
                }
                else
                {
                    _stopped.Remove(id);
                }

                if (!_cemeteries.ContainsKey(v.m_sourceBuilding))
                {
                    continue;
                }

                if (v.Info.m_vehicleAI.GetLocalizedStatus(id, ref v, out instanceID) != _collecting)
                {
                    continue;
                }

                ushort target = _cemeteries[v.m_sourceBuilding].AssignTarget(v);

                if (target != 0 && target != v.m_targetBuilding)
                {
                    v.Info.m_vehicleAI.SetTarget(id, ref vehicles[id], target);
                }
            }
        }
Esempio n. 3
0
        private void UpdateHearses()
        {
            SkylinesOverwatch.Data data = SkylinesOverwatch.Data.Instance;

            foreach (ushort vehicleID in data.VehiclesRemoved)
            {
                if (!data.IsHearse(vehicleID))
                {
                    continue;
                }

                if (_lasttargets.ContainsKey(vehicleID) &&
                    Helper.IsBuildingWithDead(_lasttargets[vehicleID]))
                {
                    foreach (ushort id in _cemeteries.Keys)
                    {
                        _cemeteries[id].AddPickup(_lasttargets[vehicleID]);
                    }
                }
                _oldtargets.Remove(vehicleID);
                if (_lasttargets.ContainsKey(vehicleID))
                {
                    _master.Remove(_lasttargets[vehicleID]);
                }
                _lasttargets.Remove(vehicleID);
                _lastchangetimes.Remove(vehicleID);
                _PathfindCount.Remove(vehicleID);
            }

            if (!SimulationManager.instance.SimulationPaused)
            {
                uint num1 = Singleton <SimulationManager> .instance.m_currentFrameIndex >> 4 & 7u;
                uint num2 = _lastProcessedFrame >> 4 & 7u;
                foreach (ushort vehicleID in data.VehiclesUpdated)
                {
                    if (!data.IsHearse(vehicleID))
                    {
                        continue;
                    }

                    Vehicle v = Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID];

                    if (!_cemeteries.ContainsKey(v.m_sourceBuilding))
                    {
                        continue;
                    }

                    if (v.m_flags.IsFlagSet(Vehicle.Flags.Stopped))
                    {
                        if (!_stopped.Contains(vehicleID))
                        {
                            Singleton <VehicleManager> .instance.RemoveFromGrid(vehicleID, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID], false);

                            _stopped.Add(vehicleID);
                        }
                        continue;
                    }

                    if (v.m_flags.IsFlagSet(Vehicle.Flags.Stopped) || v.m_flags.IsFlagSet(Vehicle.Flags.WaitingSpace) || v.m_flags.IsFlagSet(Vehicle.Flags.WaitingPath) || v.m_flags.IsFlagSet(Vehicle.Flags.WaitingLoading) || v.m_flags.IsFlagSet(Vehicle.Flags.WaitingCargo))
                    {
                        continue;
                    }
                    if (!v.m_flags.IsFlagSet(Vehicle.Flags.Spawned))
                    {
                        continue;
                    }
                    if (v.m_path == 0u)
                    {
                        continue;
                    }

                    _PathfindCount.Remove(vehicleID);

                    if (_stopped.Contains(vehicleID))
                    {
                        _stopped.Remove(vehicleID);
                    }
                    else if (!v.m_flags.IsFlagSet(Vehicle.Flags.WaitingTarget))
                    {
                        uint num3 = vehicleID & 7u;
                        if (num1 != num3 && num2 != num3)
                        {
                            _updated.Remove(vehicleID);
                            continue;
                        }
                        else if (_updated.Contains(vehicleID))
                        {
                            continue;
                        }
                    }

                    _updated.Add(vehicleID);

                    int vehicleStatus = GetHearseStatus(ref v);

                    if (vehicleStatus == VEHICLE_STATUS_HEARSE_RETURN && _lasttargets.ContainsKey(vehicleID))
                    {
                        if (Helper.IsBuildingWithDead(_lasttargets[vehicleID]))
                        {
                            foreach (ushort id in _cemeteries.Keys)
                            {
                                _cemeteries[id].AddPickup(_lasttargets[vehicleID]);
                            }
                        }
                        _lasttargets.Remove(vehicleID);
                        continue;
                    }
                    if (vehicleStatus != VEHICLE_STATUS_HEARSE_COLLECT && vehicleStatus != VEHICLE_STATUS_HEARSE_WAIT)
                    {
                        continue;
                    }

                    ushort target = _cemeteries[v.m_sourceBuilding].AssignTarget(vehicleID);

                    if (target != 0 && target != v.m_targetBuilding)
                    {
                        if (Helper.IsBuildingWithDead(v.m_targetBuilding))
                        {
                            foreach (ushort id in _cemeteries.Keys)
                            {
                                _cemeteries[id].AddPickup(v.m_targetBuilding);
                            }
                        }

                        _master.Remove(v.m_targetBuilding);
                        if (vehicleStatus == VEHICLE_STATUS_HEARSE_COLLECT)
                        {
                            _lasttargets[vehicleID] = v.m_targetBuilding;
                            if (_lastchangetimes.ContainsKey(vehicleID))
                            {
                                _lastchangetimes[vehicleID] = SimulationManager.instance.m_currentGameTime;
                            }
                            else
                            {
                                _lastchangetimes.Add(vehicleID, SimulationManager.instance.m_currentGameTime);
                            }
                        }
                        _CustomHearseAI.SetTarget(vehicleID, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID], target);
                    }
                    else
                    {
                        if (_master.ContainsKey(v.m_targetBuilding))
                        {
                            if (_master[v.m_targetBuilding].Vehicle != vehicleID)
                            {
                                _master[v.m_targetBuilding] = new Claimant(vehicleID, v.m_targetBuilding);
                            }
                        }
                        else
                        {
                            _master.Add(v.m_targetBuilding, new Claimant(vehicleID, v.m_targetBuilding));
                        }
                    }
                }
            }

            foreach (ushort vehicleID in data.Hearses)
            {
                if (Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_flags.IsFlagSet(Vehicle.Flags.WaitingPath))
                {
                    PathManager instance      = Singleton <PathManager> .instance;
                    byte        pathFindFlags = instance.m_pathUnits.m_buffer[(int)((UIntPtr)Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_path)].m_pathFindFlags;
                    if ((pathFindFlags & 4) != 0)
                    {
                        _PathfindCount.Remove(vehicleID);
                    }
                    else if ((pathFindFlags & 8) != 0)
                    {
                        int vehicleStatus = GetHearseStatus(ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID]);
                        if (_lasttargets.ContainsKey(vehicleID))
                        {
                            Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_flags &= ~Vehicle.Flags.WaitingPath;
                            Singleton <PathManager> .instance.ReleasePath(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_path);

                            Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_path = 0u;
                            _CustomHearseAI.SetTarget(vehicleID, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID], _lasttargets[vehicleID]);
                            _lasttargets.Remove(vehicleID);
                        }
                        else if ((vehicleStatus == VEHICLE_STATUS_HEARSE_WAIT || vehicleStatus == VEHICLE_STATUS_HEARSE_COLLECT) &&
                                 (Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_flags.IsFlagSet(Vehicle.Flags.Spawned)) &&
                                 _cemeteries.ContainsKey(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_sourceBuilding) &&
                                 (!_PathfindCount.ContainsKey(vehicleID) || _PathfindCount[vehicleID] < 20))
                        {
                            if (!_PathfindCount.ContainsKey(vehicleID))
                            {
                                _PathfindCount[vehicleID] = 0;
                            }
                            _PathfindCount[vehicleID]++;
                            ushort target = _cemeteries[Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_sourceBuilding].GetUnclaimedTarget(vehicleID);
                            if (target == 0)
                            {
                                _PathfindCount[vehicleID] = ushort.MaxValue;
                            }
                            else
                            {
                                if (Dispatcher._oldtargets != null)
                                {
                                    if (!Dispatcher._oldtargets.ContainsKey(vehicleID))
                                    {
                                        Dispatcher._oldtargets.Add(vehicleID, new HashSet <ushort>());
                                    }
                                    Dispatcher._oldtargets[vehicleID].Add(target);
                                }
                                Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_flags &= ~Vehicle.Flags.WaitingPath;
                                Singleton <PathManager> .instance.ReleasePath(Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_path);

                                Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID].m_path = 0u;
                                _CustomHearseAI.SetTarget(vehicleID, ref Singleton <VehicleManager> .instance.m_vehicles.m_buffer[vehicleID], target);
                            }
                        }
                    }
                }
            }
        }