コード例 #1
0
        public void RefreshData()
        {
            if (m_BuildingID == 0 || !OutsideConnectionSettingsManager.instance.SettingsDict.TryGetValue(m_BuildingID, out m_CachedSettings))
            {
                return;
            }

            var connectionAI = Utils.QueryBuildingAI(buildingID) as OutsideConnectionAI;

            if (connectionAI == null)
            {
                m_BuildingID     = 0;
                m_CachedSettings = null;
                return;
            }

            m_IsRefreshing = true;

            m_TransportTypeSprite.spriteName = Utils.GetSpriteNameForTransferReason(connectionAI.m_dummyTrafficReason);
            m_ConnectionNameTextfield.text   = m_CachedSettings.Name;

            m_DirectionLabel.text = Utils.GetStringForDirectionFlag(Utils.QueryBuilding(m_BuildingID).m_flags);

            m_IsRefreshing = false;
        }
コード例 #2
0
        public void SyncWithBuildingManager()
        {
            var typeCount       = new int[Utils.MaxEnumValue <TransferManager.TransferReason>() + 1];
            var oldSettingsDict = m_SettingsDict;

            m_SettingsDict = new Dictionary <ushort, OutsideConnectionSettings>();
            foreach (var buildingID in BuildingManager.instance.GetOutsideConnections())
            {
                var connectionAI = Utils.QueryBuildingAI(buildingID) as OutsideConnectionAI;
                if (connectionAI == null)
                {
                    continue;
                }

                var transferReason = connectionAI.m_dummyTrafficReason;

                OutsideConnectionSettings settings;
                if (oldSettingsDict.TryGetValue(buildingID, out settings))
                {
                    m_SettingsDict.Add(buildingID, settings);
                }
                else
                {
                    settings      = new OutsideConnectionSettings();
                    settings.Name = Utils.GetNameForTransferReason(transferReason) + "-Outside Connection " + (typeCount[(int)transferReason] + 1);
                    var building = Utils.QueryBuilding(buildingID);
                    settings.CurrentDirectionFlags  = building.m_flags & Building.Flags.IncomingOutgoing;
                    settings.OriginalDirectionFlags = settings.CurrentDirectionFlags;

                    ValidateOutsideConnectionSettings(buildingID, ref settings);

                    m_SettingsDict.Add(buildingID, settings);
                }
                ++typeCount[(int)transferReason];
            }
        }
コード例 #3
0
        private static void ValidateOutsideConnectionSettings(ushort buildingID, ref OutsideConnectionSettings settings)
        {
            var connectionAI = Utils.QueryBuildingAI(buildingID) as OutsideConnectionAI;

            if (settings.DummyTrafficFactor < 0)
            {
                settings.DummyTrafficFactor = connectionAI.m_dummyTrafficFactor;
            }

            if (settings.CargoCapacity < 0)
            {
                settings.CargoCapacity = connectionAI.m_cargoCapacity;
            }

            if (settings.ResidentCapacity < 0)
            {
                settings.ResidentCapacity = connectionAI.m_residentCapacity;
            }

            if (settings.TouristFactors == null || settings.TouristFactors.Length != 3)
            {
                settings.TouristFactors = Utils.GetTouristFactorsFromOutsideConnection(buildingID);
            }

            if (settings.ImportResourceRatio == null || settings.ImportResourceRatio.Length != Utils.ImportResources.Length ||
                settings.ImportResourceRatio.Aggregate((a, b) => b + a) != 10000)
            {
                settings.ImportResourceRatio = Utils.GetDefaultImportResourceRatio();
            }

            if (settings.ExportResourceRatio == null || settings.ExportResourceRatio.Length != Utils.ExportResources.Length ||
                settings.ExportResourceRatio.Aggregate((a, b) => b + a) != 10000)
            {
                settings.ExportResourceRatio = Utils.GetDefaultExportResourceRatio();
            }
        }
コード例 #4
0
        private static bool TryLoadData1(int version, ref Dictionary <ushort, OutsideConnectionSettings> settingsDict, ref byte[] buffer, ref int index)
        {
            var length = SerializableDataExtension.ReadInt32(buffer, ref index);

            for (int i = 0; i < length; ++i)
            {
                var curElementLength = SerializableDataExtension.ReadInt32(buffer, ref index);
                var indexBegin       = index;

                var settings   = new OutsideConnectionSettings();
                var buildingID = SerializableDataExtension.ReadUInt16(buffer, ref index);
                settings.NameMode             = (OutsideConnectionSettings.NameModeType)SerializableDataExtension.ReadUInt16(buffer, ref index);
                settings.SingleGenerationName = SerializableDataExtension.ReadString(buffer, ref index);

                var strCount = SerializableDataExtension.ReadUInt16(buffer, ref index);
                for (int j = 0; j < strCount; ++j)
                {
                    settings.RandomGenerationNames.Add(SerializableDataExtension.ReadString(buffer, ref index));
                }

                settings.CurrentDirectionFlags = (Building.Flags)SerializableDataExtension.ReadUInt16(buffer, ref index) & Building.Flags.IncomingOutgoing;
                settings.Name = SerializableDataExtension.ReadString(buffer, ref index);

                var flags = Utils.QueryBuilding(buildingID).m_flags;
                settings.OriginalDirectionFlags = flags & Building.Flags.IncomingOutgoing;
                flags &= (~Building.Flags.IncomingOutgoing) | settings.CurrentDirectionFlags;
                BuildingManager.instance.m_buildings.m_buffer[buildingID].m_flags = flags;

                if (2 <= version)
                {
                    settings.DummyTrafficFactor = SerializableDataExtension.ReadInt32(buffer, ref index);
                }

                if (3 <= version)
                {
                    // even if length is not equal 3, the data must be read from buffer
                    var touristFactorLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    var factors             = new int[touristFactorLength];
                    for (ushort k = 0; k < touristFactorLength; ++k)
                    {
                        factors[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.TouristFactors = factors;
                }

                if (4 <= version)
                {
                    var ratioLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    var ratios      = new int[ratioLength];
                    for (ushort k = 0; k < ratioLength; ++k)
                    {
                        ratios[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.ImportResourceRatio = ratios;

                    ratioLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    ratios      = new int[ratioLength];
                    for (ushort k = 0; k < ratioLength; ++k)
                    {
                        ratios[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.ExportResourceRatio = ratios;
                }

                if (5 <= version)
                {
                    settings.CargoCapacity    = SerializableDataExtension.ReadInt32(buffer, ref index);
                    settings.ResidentCapacity = SerializableDataExtension.ReadInt32(buffer, ref index);
                }

                ValidateOutsideConnectionSettings(buildingID, ref settings);

                if (settingsDict.ContainsKey(buildingID))
                {
                    Utils.LogWarning("Overrides existing outside connection with buildingID: " + buildingID);
                }
                settingsDict[buildingID] = settings;
            }
            return(true);
        }