private void ReleaseUnusedCitizenUnits()
        {
            Utils.Log((object)"Find and clear unused citizen units.");
            CitizenManager instance = Singleton <CitizenManager> .instance;
            int            num      = 0;

            for (int index = 0; index < instance.m_units.m_buffer.Length; ++index)
            {
                CitizenUnit citizenUnit = instance.m_units.m_buffer[index];
                if (citizenUnit.m_flags != CitizenUnit.Flags.None && (int)citizenUnit.m_building == 0 && ((int)citizenUnit.m_vehicle == 0 && (int)citizenUnit.m_goods == 0))
                {
                    ++num;
                    instance.m_units.m_buffer[index] = new CitizenUnit();
                    instance.m_units.ReleaseItem((uint)index);
                    Utils.LogToTxt((object)string.Format("CitizenUnit #{0} - Flags: {1} - Citizens: #{2} | #{3} | #{4} | #{5} | #{6}", (object)index, (object)citizenUnit.m_flags, (object)citizenUnit.m_citizen0, (object)citizenUnit.m_citizen1, (object)citizenUnit.m_citizen2, (object)citizenUnit.m_citizen3, (object)citizenUnit.m_citizen4));
                }
            }
            Utils.Log((object)("Cleared " + (object)num + " unused citizen units."));
        }
Пример #2
0
        private static void EnsureCitizenUnits(ushort vehicleID, ref Vehicle data, int passengerCount)
        {
            CitizenManager instance = Singleton <CitizenManager> .instance;
            uint           num      = 0;

            for (uint firstUnit = data.m_citizenUnits; (int)firstUnit != 0; firstUnit = instance.m_units.m_buffer[(int)firstUnit].m_nextUnit)
            {
                if ((instance.m_units.m_buffer[(int)firstUnit].m_flags & CitizenUnit.Flags.Vehicle) != CitizenUnit.Flags.None)
                {
                    passengerCount -= 5;
                }
                if (passengerCount < 0)
                {
                    Utils.LogToTxt((object)string.Format("ReleaseUnits for #{0}", (object)vehicleID));
                    instance.m_units.m_buffer[(int)num].m_nextUnit = 0U;
                    instance.ReleaseUnits(firstUnit);
                    return;
                }
                num = firstUnit;
            }
            if (passengerCount <= 0)
            {
                return;
            }
            Utils.LogToTxt((object)string.Format("CreateUnits for #{0}", (object)vehicleID));
            uint firstUnit1 = 0;

            if (!instance.CreateUnits(out firstUnit1, ref Singleton <SimulationManager> .instance.m_randomizer, (ushort)0, vehicleID, 0, 0, 0, passengerCount, 0))
            {
                return;
            }
            if ((int)num != 0)
            {
                instance.m_units.m_buffer[(int)num].m_nextUnit = firstUnit1;
            }
            else
            {
                data.m_citizenUnits = firstUnit1;
            }
        }