Пример #1
0
        public static IEnumerator UpdateCapacityUnits(ThreadBase t)
        {
            int count = 0;
            Array16 <Vehicle> vehicles = VehicleManager.instance.m_vehicles;

            for (uint i = 0; i < vehicles.m_buffer.Length; i++)
            {
                if ((vehicles.m_buffer[i].m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.Spawned)
                {
                    if (prefabUpdateUnits == null || vehicles.m_buffer[i].Info == prefabUpdateUnits)
                    {
                        int capacity = GetUnitsCapacity(vehicles.m_buffer[i].Info.m_vehicleAI);

                        if (capacity != -1)
                        {
                            CitizenUnit[] units = CitizenManager.instance.m_units.m_buffer;
                            uint          unit  = vehicles.m_buffer[i].m_citizenUnits;

                            int currentUnitCount = GetTotalUnitGroups(unit);
                            int newUnitCount     = Mathf.CeilToInt(capacity / 5f);

                            // Capacity reduced
                            if (newUnitCount < currentUnitCount)
                            {
                                // Get the first unit to remove
                                uint n = unit;
                                for (int j = 1; j < newUnitCount; j++)
                                {
                                    n = units[n].m_nextUnit;
                                }
                                // Releasing units excess
                                CitizenManager.instance.ReleaseUnits(units[n].m_nextUnit);
                                units[n].m_nextUnit = 0;

                                count++;
                            }
                            // Capacity increased
                            else if (newUnitCount > currentUnitCount)
                            {
                                // Get the last unit
                                uint n = unit;
                                while (units[n].m_nextUnit != 0)
                                {
                                    n = units[n].m_nextUnit;
                                }

                                // Creating missing units
                                int newCapacity = capacity - currentUnitCount * 5;
                                CitizenManager.instance.CreateUnits(out units[n].m_nextUnit, ref SimulationManager.instance.m_randomizer, 0, (ushort)i, 0, 0, 0, newCapacity, 0);

                                count++;
                            }
                        }
                    }
                }
                if (i % 256 == 255)
                {
                    yield return(null);
                }
            }
            prefabUpdateUnits = null;

            if (count > 0)
            {
                DebugUtils.Log("Modified capacity of " + count + " vehicle(s). Total unit count: " + CitizenManager.instance.m_unitCount + "/" + CitizenManager.MAX_UNIT_COUNT);
            }
        }
Пример #2
0
        public static void CheckForConflicts()
        {
            StringBuilder conflicts = new StringBuilder();

            foreach (string name in m_default.Keys)
            {
                VehicleOptions options = new VehicleOptions();
                options.SetPrefab(m_prefabs[name]);

                DefaultOptions modded = m_modded[name];
                DefaultOptions stored = m_default[name];

                StringBuilder details = new StringBuilder();

                if (modded.m_enabled != stored.m_enabled && options.enabled == stored.m_enabled)
                {
                    options.enabled = modded.m_enabled;
                    details.Append("enabled, ");
                }
                if (modded.m_addBackEngine != stored.m_addBackEngine && options.addBackEngine == stored.m_addBackEngine)
                {
                    options.addBackEngine = modded.m_addBackEngine;
                    details.Append("back engine, ");
                }
                if (modded.m_maxSpeed != stored.m_maxSpeed && options.maxSpeed == stored.m_maxSpeed)
                {
                    options.maxSpeed = modded.m_maxSpeed;
                    details.Append("max speed, ");
                }
                if (modded.m_acceleration != stored.m_acceleration && options.acceleration == stored.m_acceleration)
                {
                    options.acceleration = modded.m_acceleration;
                    details.Append("acceleration, ");
                }
                if (modded.m_braking != stored.m_braking && options.braking == stored.m_braking)
                {
                    options.braking = modded.m_braking;
                    details.Append("braking, ");
                }
                if (modded.m_turning != stored.m_turning && options.turning == stored.m_turning)
                {
                    options.turning = modded.m_turning;
                    details.Append("turning, ");
                }
                if (modded.m_springs != stored.m_springs && options.springs == stored.m_springs)
                {
                    options.springs = modded.m_springs;
                    details.Append("springs, ");
                }
                if (modded.m_dampers != stored.m_dampers && options.dampers == stored.m_dampers)
                {
                    options.dampers = modded.m_dampers;
                    details.Append("dampers, ");
                }
                if (modded.m_leanMultiplier != stored.m_leanMultiplier && options.leanMultiplier == stored.m_leanMultiplier)
                {
                    options.leanMultiplier = modded.m_leanMultiplier;
                    details.Append("leanMultiplier, ");
                }
                if (modded.m_nodMultiplier != stored.m_nodMultiplier && options.nodMultiplier == stored.m_nodMultiplier)
                {
                    options.nodMultiplier = modded.m_nodMultiplier;
                    details.Append("nodMultiplier, ");
                }
                if (modded.m_capacity != stored.m_capacity && options.capacity == stored.m_capacity)
                {
                    options.capacity = modded.m_capacity;
                    details.Append("capacity, ");
                }

                if (details.Length > 0)
                {
                    details.Length -= 2;
                    conflicts.AppendLine(options.name + ": " + details);
                }
            }

            if (conflicts.Length > 0)
            {
                VehicleOptions.UpdateTransfertVehicles();
                DebugUtils.Log("Conflicts detected (this message is harmless):" + Environment.NewLine + conflicts);
            }
        }