public static bool CanOperation(ushort buildingID, ref Building buildingData, bool userReject = true)
        {
            if ((MainDataStore.resourceCategory[buildingID] == 4) && userReject)
            {
                return(false);
            }

            if (ResourceBuildingAI.IsSpecialBuilding(buildingID))
            {
                return(false);
            }

            if (buildingData.Info.m_buildingAI is ParkBuildingAI)
            {
                return(false);
            }

            if (buildingData.Info.m_buildingAI is CampusBuildingAI)
            {
                return(false);
            }

            if (buildingData.Info.m_class.m_service == ItemClass.Service.Beautification)
            {
                return(false);
            }
            PlayerBuildingAI AI = buildingData.Info.m_buildingAI as PlayerBuildingAI;

            return(AI.RequireRoadAccess());
        }
Exemplo n.º 2
0
        public static bool IsGasBuilding(ushort id, bool fastCheck = true)
        {
            if (!fastCheck)
            {
                var buildingData = Singleton <BuildingManager> .instance.m_buildings.m_buffer[id];
                if (buildingData.Info.m_buildingAI is ParkBuildingAI)
                {
                    return(false);
                }

                if (buildingData.Info.m_buildingAI is CampusBuildingAI)
                {
                    return(false);
                }

                PlayerBuildingAI AI = buildingData.Info.m_buildingAI as PlayerBuildingAI;
                if (AI.RequireRoadAccess() == false)
                {
                    return(false);
                }
            }

            if (MainDataStore.resourceCategory[id] != 0)
            {
                return(true);
            }
            return(false);
        }
        public IEnumerator ScanForDisconnectedBuildings()
        {
            SearchProgress = 0.0f;
            BuildingManager bm = BuildingManager.instance;

            SearchStep       = 1.0f / bm.m_buildings.m_buffer.Length;
            SearchInProgress = true;
            DisconnectedBuildings.Clear();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("[BND] Scanning for disconnected buildings");
            sb.AppendLine("[BND] ");
            sb.AppendLine("[BND] =( Building ID )===( Location )=");
            sb.AppendLine();
            Building[] mBuffer        = bm.m_buildings.m_buffer;
            int        counter        = 0;
            MethodInfo findRoadAccess = typeof(PlayerBuildingAI).GetMethod("FindRoadAccess", BindingFlags.Instance | BindingFlags.NonPublic);

            for (uint i = 0; i < mBuffer.Length; i++)
            {
                Building building = mBuffer[i];

                if ((building.m_flags & Building.Flags.Created) != 0 && building.Info)
                {
                    if (building.Info.m_buildingAI is PlayerBuildingAI)
                    {
                        counter++;
                        PlayerBuildingAI buildingAI = building.Info.m_buildingAI as PlayerBuildingAI;
                        bool             connected  = true;
                        if ((building.m_flags & Building.Flags.Collapsed) == Building.Flags.None && buildingAI.RequireRoadAccess())
                        {
                            Vector3 position = buildingAI.m_info.m_zoningMode != BuildingInfo.ZoningMode.CornerLeft
                                ? (buildingAI.m_info.m_zoningMode != BuildingInfo.ZoningMode.CornerRight
                                    ? building.CalculateSidewalkPosition(0.0f, 4f)
                                    : building.CalculateSidewalkPosition(building.Width * -4f, 4f))
                                : building.CalculateSidewalkPosition(building.Width * 4f, 4f);
                            object[] args = { (ushort)i, building, position };
                            if (!(bool)findRoadAccess.Invoke(buildingAI, args))
                            {
                                connected = false;
                            }
                        }

                        if (!connected)
                        {
                            DisconnectedBuildings.Add(i, building.m_position);
                            sb.AppendLine("==(" + i + ")===(" + building.m_position + ")=");
                            sb.Append("building ")
                            .Append(" " + (building.Info ? building.Info.m_class.name : "") + " ")
                            .Append(building.m_flags.ToString())
                            .Append(" [name: ").Append(building.Info.name).Append("]");
                            sb.AppendLine("---------------------------------------");
                        }
                    }
                    else if ((building.m_flags & Building.Flags.RoadAccessFailed) != 0 || (building.m_problems & Notification.Problem.RoadNotConnected) != 0)
                    {
                        DisconnectedBuildings.Add(i, building.m_position);
                        sb.AppendLine("==(" + i + ")===(" + building.m_position + ")=");
                        sb.Append("building ")
                        .Append(" " + (building.Info ? building.Info.m_class.name : "") + " ")
                        .Append(building.m_flags.ToString())
                        .Append(" [name: ").Append(building.Info.name).Append("]");
                        sb.AppendLine("---------------------------------------");
                    }
                }

                SearchProgress = SearchStep * i;
                if (i % 128 == 0)
                {
                    yield return(null);
                }
            }

            SearchInProgress = false;
            Debug.Log("[BND] Disconnected building instances count: " + counter);
            Debug.Log("[BND] Scan report\n" + sb + "\n\n=======================================================");
        }