public override void SimulationStep(ushort buildingID, ref Building buildingData, ref Building.Frame frameData)
        {
            base.SimulationStep(buildingID, ref buildingData, ref frameData);
            if (Singleton <SimulationManager> .instance.m_randomizer.Int32(10U) == 0)
            {
                DistrictManager instance = Singleton <DistrictManager> .instance;
                byte            district = instance.GetDistrict(buildingData.m_position);
                ushort          num      = instance.m_districts.m_buffer[(int)district].m_Style;
                if ((int)num > 0 && (int)num - 1 < instance.m_Styles.Length)
                {
                    DistrictStyle districtStyle = instance.m_Styles[(int)num - 1];
                    if (districtStyle != null && (UnityEngine.Object) this.m_info.m_class != (UnityEngine.Object)null && (districtStyle.AffectsService(this.m_info.GetService(), this.m_info.GetSubService(), this.m_info.m_class.m_level) && !districtStyle.Contains(this.m_info)) && (int)Singleton <ZoneManager> .instance.m_lastBuildIndex == (int)Singleton <SimulationManager> .instance.m_currentBuildIndex)
                    {
                        buildingData.m_flags |= Building.Flags.Demolishing;
                        ++Singleton <SimulationManager> .instance.m_currentBuildIndex;
                    }
                }
            }
            if ((buildingData.m_flags & Building.Flags.ZonesUpdated) != Building.Flags.None)
            {
                SimulationManager instance = Singleton <SimulationManager> .instance;
                if ((int)buildingData.m_fireIntensity != 0 || instance.m_randomizer.Int32(10U) != 0 || (int)Singleton <ZoneManager> .instance.m_lastBuildIndex != (int)instance.m_currentBuildIndex)
                {
                    return;
                }
                buildingData.m_flags &= ~Building.Flags.ZonesUpdated;
                if (buildingData.CheckZoning(this.m_info.m_class.GetZone(), this.m_info.m_class.GetSecondaryZone()))
                {
                    return;
                }
                buildingData.m_flags |= Building.Flags.Demolishing;
                PrivateBuildingAIDetour.CheckNearbyBuildingZones(buildingData.m_position);
                ++instance.m_currentBuildIndex;
            }
            else
            {
                if ((buildingData.m_flags & (Building.Flags.Abandoned | Building.Flags.Downgrading)) == Building.Flags.None || (int)buildingData.m_majorProblemTimer != (int)byte.MaxValue && (buildingData.m_flags & Building.Flags.Abandoned) != Building.Flags.None)
                {
                    return;
                }
                SimulationManager instance1 = Singleton <SimulationManager> .instance;
                ZoneManager       instance2 = Singleton <ZoneManager> .instance;
                int num1;
                switch (this.m_info.m_class.m_service)
                {
                case ItemClass.Service.Residential:
                    num1 = instance2.m_actualResidentialDemand;
                    break;

                case ItemClass.Service.Commercial:
                    num1 = instance2.m_actualCommercialDemand;
                    break;

                case ItemClass.Service.Industrial:
                    num1 = instance2.m_actualWorkplaceDemand;
                    break;

                case ItemClass.Service.Office:
                    num1 = instance2.m_actualWorkplaceDemand;
                    break;

                default:
                    num1 = 0;
                    break;
                }
                if (instance1.m_randomizer.Int32(100U) >= num1 || (int)instance2.m_lastBuildIndex != (int)instance1.m_currentBuildIndex || (double)Singleton <TerrainManager> .instance.WaterLevel(VectorUtils.XZ(buildingData.m_position)) > (double)buildingData.m_position.y)
                {
                    return;
                }
                ItemClass.SubService subService = this.m_info.m_class.m_subService;
                ItemClass.Level      level      = ItemClass.Level.Level1;
                int width = buildingData.Width;
                int num2  = buildingData.Length;
                if (this.m_info.m_class.m_service == ItemClass.Service.Industrial)
                {
                    ZoneBlock.GetIndustryType(buildingData.m_position, out subService, out level);
                }
                else if (this.m_info.m_class.m_service == ItemClass.Service.Commercial)
                {
                    ZoneBlock.GetCommercialType(buildingData.m_position, this.m_info.m_class.GetZone(), width, num2, out subService, out level);
                }
                DistrictManager instance3          = Singleton <DistrictManager> .instance;
                byte            district           = instance3.GetDistrict(buildingData.m_position);
                ushort          num3               = instance3.m_districts.m_buffer[(int)district].m_Style;
                BuildingInfo    randomBuildingInfo = Singleton <BuildingManager> .instance.GetRandomBuildingInfo(ref Singleton <SimulationManager> .instance.m_randomizer, this.m_info.m_class.m_service, subService, level, width, num2, this.m_info.m_zoningMode, (int)num3);

                if (randomBuildingInfo == null)
                {
                    return;
                }
                buildingData.m_flags |= Building.Flags.Demolishing;
                float num4 = buildingData.m_angle + 1.570796f;
                float num5;
                if (this.m_info.m_zoningMode == BuildingInfo.ZoningMode.CornerLeft && randomBuildingInfo.m_zoningMode == BuildingInfo.ZoningMode.CornerRight)
                {
                    num5 = num4 - 1.570796f;
                    num2 = width;
                }
                else if (this.m_info.m_zoningMode == BuildingInfo.ZoningMode.CornerRight && randomBuildingInfo.m_zoningMode == BuildingInfo.ZoningMode.CornerLeft)
                {
                    num5 = num4 + 1.570796f;
                    num2 = width;
                }
                ushort building;
                if (Singleton <BuildingManager> .instance.CreateBuilding(out building, ref Singleton <SimulationManager> .instance.m_randomizer, randomBuildingInfo, buildingData.m_position, buildingData.m_angle, num2, Singleton <SimulationManager> .instance.m_currentBuildIndex))
                {
                    ++Singleton <SimulationManager> .instance.m_currentBuildIndex;
                    switch (this.m_info.m_class.m_service)
                    {
                    case ItemClass.Service.Residential:
                        instance2.m_actualResidentialDemand = Mathf.Max(0, instance2.m_actualResidentialDemand - 5);
                        break;

                    case ItemClass.Service.Commercial:
                        instance2.m_actualCommercialDemand = Mathf.Max(0, instance2.m_actualCommercialDemand - 5);
                        break;

                    case ItemClass.Service.Industrial:
                        instance2.m_actualWorkplaceDemand = Mathf.Max(0, instance2.m_actualWorkplaceDemand - 5);
                        break;

                    case ItemClass.Service.Office:
                        instance2.m_actualWorkplaceDemand = Mathf.Max(0, instance2.m_actualWorkplaceDemand - 5);
                        break;
                    }
                }
                ++instance1.m_currentBuildIndex;
            }
        }
        public BuildingInfo GetRandomBuildingInfo(ref Randomizer r, ItemClass.Service service, ItemClass.SubService subService, ItemClass.Level level, int width, int length, BuildingInfo.ZoningMode zoningMode, int style)
        {
            getPrivates();

            if (!m_buildingsRefreshed)
            {
                CODebugBase <LogChannel> .Error(LogChannel.Core, "Random buildings not refreshed yet!");

                return(null);
            }
            int num = GetAreaIndex(service, subService, level, width, length, zoningMode);
            FastList <ushort> fastList;

            if (style > 0)
            {
                style--;
                DistrictStyle districtStyle = Singleton <DistrictManager> .instance.m_Styles[style];
                if (style <= m_styleBuildings.Length && m_styleBuildings[style] != null && m_styleBuildings[style].Count > 0 && districtStyle.AffectsService(service, subService, level))
                {
                    if (m_styleBuildings[style].ContainsKey(num))
                    {
                        fastList = m_styleBuildings[style][num];
                    }
                    else
                    {
                        fastList = null;
                    }
                }
                else
                {
                    fastList = m_areaBuildings[num];
                }
            }
            else
            {
                fastList = m_areaBuildings[num];
            }
            if (fastList == null)
            {
                return(null);
            }
            if (fastList.m_size == 0)
            {
                return(null);
            }

            num = r.Int32((uint)fastList.m_size);
            BuildingInfo retVal = PrefabCollection <BuildingInfo> .GetPrefab((uint)fastList.m_buffer[num]);

            float heightLimit = getHeightLimit(service, subService, AI_PrivateBuilding.highRiseBan);

            AI_PrivateBuilding.highRiseBan = false;

            // Height limits are on all buildings which are reaosnably expected to have really tall buildings
            while (retVal.m_size.y > heightLimit)
            {
                Debugging.writeDebugToFile(retVal.m_size.y + " > " + heightLimit);
                num = r.Int32((uint)fastList.m_size);
                // num++ % fastList.m_size - Maybe to just go through the list
                retVal = PrefabCollection <BuildingInfo> .GetPrefab((uint)fastList.m_buffer[num]);
            }

            return(retVal);
        } // end