Example #1
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;
            }
        }
Example #2
0
        /// <summary>
        /// Check the household numbers
        /// </summary>
        /// <param name="buildings"></param>
        /// <param name="citizens"></param>
        /// <param name="i"></param>
        private void checkResidentialHouseholds(BuildingManager buildings, CitizenManager citizens, int i)
        {
            Building building = buildings.m_buildings.m_buffer[i];
            BuildingInfo info = building.Info;
            int width = building.Width;
            int length = building.Length;

            if ((info != null) && (info.m_buildingAI is ResidentialBuildingAI))
            {
                int modHomeCount = ((ResidentialBuildingAI)info.m_buildingAI).CalculateHomeCount(new ColossalFramework.Math.Randomizer(i), width, length);

                // If the modded home count is meant to be less than the original
                if (modHomeCount < Game_ResidentialAI.CalculateHomeCount(new ColossalFramework.Math.Randomizer(i), width, length, info.m_class.m_subService, info.m_class.m_level))
                {
                    int houseHoldCount = 0;
                    uint citizenIndex = building.m_citizenUnits;
                    while (houseHoldCount < modHomeCount)  // Fast forward
                    {
                        citizenIndex = citizens.m_units.m_buffer[(int)((UIntPtr)citizenIndex)].m_nextUnit;
                        houseHoldCount++;
                    }

                    // Disconnect the rest
                    while (citizenIndex != 0u)
                    {
                        CitizenUnit c = citizens.m_units.m_buffer[(int)((UIntPtr)citizenIndex)];

                        citizens.ReleaseUnits(citizenIndex);
                        citizenIndex = c.m_nextUnit;

                        // Reset the flags which could make the game think this group has connections to a home
                        c.m_nextUnit = 0u;
                        c.m_building = 0;
                        c.m_flags = CitizenUnit.Flags.None;
                    }
                }
            }
        }