Esempio n. 1
0
        public override string GetDebugString(ushort buildingID, ref Building data)
        {
            string text = base.GetDebugString(buildingID, ref data);

            TransferManager.TransferReason[] incomingResources = m_incomingResources;
            TransferManager.TransferReason   transferReason    = TransferManager.TransferReason.Shopping;
            var marketBuffer = MarketBuffers[buildingID];

            for (int i = 0; i < incomingResources.Length; i++)
            {
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                if (incomingResources[i] != TransferManager.TransferReason.None)
                {
                    base.CalculateGuestVehicles(buildingID, ref data, incomingResources[i], ref num, ref num2, ref num3, ref num4);
                    text = StringUtils.SafeFormat("{0}\n{1}: {2} (+{3})", new object[]
                    {
                        text,
                        incomingResources[i].ToString(),
                        marketBuffer.inputAmountBuffer[i],
                        num2
                    });
                }
                if (transferReason != TransferManager.TransferReason.None)
                {
                    text = StringUtils.SafeFormat("{0}\n{1}: {2}", new object[]
                    {
                        text,
                        transferReason.ToString(),
                        marketBuffer.outputAmountBuffer[i]
                    });
                }
            }
            return(text);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the service vehicle.
        /// </summary>
        /// <param name="serviceBuildingId">The service building identifier.</param>
        /// <param name="material">The material.</param>
        /// <param name="targetBuildingId">The target building identifier.</param>
        /// <param name="targetCitizenId">The target citizen identifier.</param>
        /// <param name="vehicleId">The vehicle identifier.</param>
        /// <returns>
        /// The vehicle information.
        /// </returns>
        /// <exception cref="System.NotImplementedException">Target citizen not implemented yet.</exception>
        /// <exception cref="System.InvalidOperationException">Hospital assigments reuires target citizen.</exception>
        /// <exception cref="System.ArgumentException">Unhandled material.</exception>
        /// <exception cref="ArgumentException">Unhandled material.</exception>
        public static VehicleInfo CreateServiceVehicle(ushort serviceBuildingId, TransferManager.TransferReason material, ushort targetBuildingId, uint targetCitizenId, out ushort vehicleId)
        {
            if (targetCitizenId != 0)
            {
                throw new NotImplementedException("Target citizen not implemented yet");
            }

            vehicleId = 0;

            VehicleManager manager = Singleton <VehicleManager> .instance;

            ColossalFramework.Math.Randomizer randomizer = Singleton <SimulationManager> .instance.m_randomizer;

            Building building = BuildingHelper.GetBuilding(serviceBuildingId);

            if (building.Info.m_buildingAI is HospitalAI && targetCitizenId == 0)
            {
                throw new InvalidOperationException("Hospital assigments reuires target citizen");
            }

            VehicleInfo info = manager.GetRandomVehicleInfo(ref randomizer, building.Info.m_class.m_service, building.Info.m_class.m_subService, building.Info.m_class.m_level);

            if (info == null)
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "GetRandomVehicleInfo", "no vehicle");
                return(null);
            }

            bool transferToSource;
            bool transferToTarget;

            switch (material)
            {
            case TransferManager.TransferReason.Dead:
                transferToSource = true;
                transferToTarget = false;
                break;

            case TransferManager.TransferReason.DeadMove:
                transferToSource = false;
                transferToTarget = true;
                break;

            case TransferManager.TransferReason.Garbage:
                transferToSource = true;
                transferToTarget = false;
                break;

            case TransferManager.TransferReason.GarbageMove:
                transferToSource = false;
                transferToTarget = true;
                break;

            default:
                throw new ArgumentException("Unhandled material: " + material.ToString());
            }

            if (!manager.CreateVehicle(out vehicleId, ref randomizer, info, building.m_position, material, transferToSource, transferToTarget))
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "CreateVehicle", "not created");
                return(null);
            }

            info.m_vehicleAI.SetSource(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], serviceBuildingId);

            if (targetBuildingId != 0 && !AssignTarget(vehicleId, ref manager.m_vehicles.m_buffer[vehicleId], material, targetBuildingId, 0))
            {
                Log.Debug(typeof(VehicleKeeper), "CreateVehicle", "SetTarget", "target not set");
                return(null);
            }

            return(info);
        }
        public static float GetResourcePrice(TransferManager.TransferReason material)
        {
            //Need to sync with RealCity mod
            float num;

            if (!RealConstructionThreading.reduceVehicle)
            {
                switch (material)
                {
                case TransferManager.TransferReason.Petrol:
                    num = 3f; break;

                case TransferManager.TransferReason.Food:
                    num = 1.5f; break;

                case TransferManager.TransferReason.Lumber:
                    num = 2f; break;

                case TransferManager.TransferReason.Coal:
                    num = 2.5f; break;

                default: DebugLog.LogToFileOnly("Error: Unknow material in RealConstruction = " + material.ToString()); num = 0f; break;
                }
            }
            else
            {
                switch (material)
                {
                case TransferManager.TransferReason.Petrol:
                    num = 3f * RealConstructionThreading.reduceCargoDiv; break;

                case TransferManager.TransferReason.Food:
                    num = 1.5f * RealConstructionThreading.reduceCargoDiv; break;

                case TransferManager.TransferReason.Lumber:
                    num = 2f * RealConstructionThreading.reduceCargoDiv; break;

                case TransferManager.TransferReason.Coal:
                    num = 2.5f * RealConstructionThreading.reduceCargoDiv; break;

                default: DebugLog.LogToFileOnly("Error: Unknow material in RealConstruction = " + material.ToString()); num = 0f; break;
                }
            }
            return((float)(UniqueFacultyAI.IncreaseByBonus(UniqueFacultyAI.FacultyBonus.Science, 100) / 100f) * num);
        }
        private void SetupRates(BuildingAI ai, Building building, InstanceID instanceId, ref float widestWidth)
        {
            bool _ = ai.GetFireParameters(instanceId.Building, ref building, out FireHazard, out int _,
                                          out FireTolerance);

            switch (SelectedBuilding.m_class.m_service)
            {
            case ItemClass.Service.Industrial:
            {
                var industrialAI = (IndustrialBuildingAI)ai;


                ElectricityConsumption = industrialAI.GetElectricityRate(instanceId.Building, ref building);
                WaterConsumption       = industrialAI.GetWaterRate(instanceId.Building, ref building);
                IncomeAccumulation     = industrialAI.GetResourceRate(instanceId.Building, ref building,
                                                                      EconomyManager.Resource.PrivateIncome);
                GarbageAccumulation = industrialAI.GetGarbageRate(instanceId.Building, ref building);
                LevelUpInfo         =
                    industrialAI.GetLevelUpInfo(instanceId.Building, ref building, out LevelUpProgress);

                Pollution = industrialAI.GetResourceRate(instanceId.Building, ref building,
                                                         NaturalResourceManager.Resource.Pollution);
                NoisePollution = industrialAI.GetResourceRate(instanceId.Building, ref building,
                                                              ImmaterialResourceManager.Resource.NoisePollution);

                var transferMethod = industrialAI.GetType().GetMethod("GetOutgoingTransferReason",
                                                                      BindingFlags.Instance | BindingFlags.NonPublic);

                _transferReason = (TransferManager.TransferReason)transferMethod.Invoke(industrialAI, null);

                ProducedProduct = _transferReason.ToString();
            }
            break;

            case ItemClass.Service.Commercial:
            {
                var commercialAI = (CommercialBuildingAI)ai;

                LevelUpInfo =
                    commercialAI.GetLevelUpInfo(instanceId.Building, ref building, out LevelUpProgress);


                Pollution = commercialAI.GetResourceRate(instanceId.Building, ref building,
                                                         NaturalResourceManager.Resource.Pollution);
                NoisePollution = commercialAI.GetResourceRate(instanceId.Building, ref building,
                                                              ImmaterialResourceManager.Resource.NoisePollution);


                ElectricityConsumption = commercialAI.GetElectricityRate(instanceId.Building, ref building);
                WaterConsumption       = commercialAI.GetWaterRate(instanceId.Building, ref building);
                IncomeAccumulation     = commercialAI.GetResourceRate(instanceId.Building, ref building,
                                                                      EconomyManager.Resource.PrivateIncome);
                GarbageAccumulation = commercialAI.GetGarbageRate(instanceId.Building, ref building);

                IncomingResource = commercialAI.m_incomingResource.ToString();

                var transferMethod = commercialAI.GetType().GetMethod("GetOutgoingTransferReason",
                                                                      BindingFlags.Instance | BindingFlags.NonPublic);

                _transferReason = (TransferManager.TransferReason)transferMethod.Invoke(commercialAI, null);

                ProducedProduct = _transferReason.ToString();
            }
            break;

            case ItemClass.Service.Residential:
            {
                var residentialAI = (ResidentialBuildingAI)ai;

/*
 *                      ElectricityConsumption = residentialAI.GetElectricityRate(instanceId.Building, ref building);
 *                      WaterConsumption = residentialAI.GetWaterRate(instanceId.Building, ref building);
 *                      IncomeAccumulation = residentialAI.GetResourceRate(instanceId.Building, ref building,
 *                          EconomyManager.Resource.PrivateIncome);
 *                      GarbageAccumulation = residentialAI.GetGarbageRate(instanceId.Building, ref building);
 */

                residentialAI.GetConsumptionRates(SelectedBuilding.GetClassLevel(),
                                                  new Randomizer(instanceId.Building), 100, out ElectricityConsumption, out WaterConsumption,
                                                  out SewageAccumulation, out GarbageAccumulation, out IncomeAccumulation, out MailAccumulation);

                LevelUpInfo =
                    residentialAI.GetLevelUpInfo(instanceId.Building, ref building, out LevelUpProgress);


                Pollution = residentialAI.GetResourceRate(instanceId.Building, ref building,
                                                          NaturalResourceManager.Resource.Pollution);
                NoisePollution = residentialAI.GetResourceRate(instanceId.Building, ref building,
                                                               ImmaterialResourceManager.Resource.NoisePollution);
            }
            break;
            }


            Dictionary <string, int> _consumptionRates = new Dictionary <string, int>
            {
                { "Electricity Consumption", ElectricityConsumption },
                { "Water Consumption", WaterConsumption },
                { "Sewage Accumulation", SewageAccumulation },
                { "Garbage Accumulation", GarbageAccumulation },
                { "Income Accumulation", IncomeAccumulation },
                { "Pollution", Pollution },
                { "Noise Pollution", NoisePollution },
                { "Fire Hazard", FireHazard },
                { "Fire Tolerance", FireTolerance },
                { "Mail Accumulation", MailAccumulation }
            };


            foreach (var kvp in _consumptionRates)
            {
                var label = AddUIComponent <UILabel>();
                label.name          = kvp.Key + "Label";
                label.text          = kvp.Key;
                label.textScale     = 0.9f;
                label.isInteractive = false;

                Inputs.Add(UiUtils.CreateInfoField(this, kvp.Key, kvp.Value));
                _labels.Add(label);

                if (label.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6 > widestWidth)
                {
                    widestWidth = label.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6;
                }
            }

            if (!string.IsNullOrEmpty(IncomingResource))
            {
                var resourceLabel = AddUIComponent <UILabel>();
                resourceLabel.name          = "IncomingResourceLabel";
                resourceLabel.text          = "Incoming Resource";
                resourceLabel.textScale     = 0.9f;
                resourceLabel.isInteractive = false;

                Inputs.Add(UiUtils.CreateInfoField(this, "IncomingResource", -201, IncomingResource));
                _labels.Add(resourceLabel);


                if (resourceLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6 > widestWidth)
                {
                    widestWidth = resourceLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6;
                }
            }

            if (!string.IsNullOrEmpty(ProducedProduct))
            {
                var producedLabel = AddUIComponent <UILabel>();
                producedLabel.name          = "OutgoingResource";
                producedLabel.text          = "Outgoing Resource";
                producedLabel.textScale     = 0.9f;
                producedLabel.isInteractive = false;

                Inputs.Add(UiUtils.CreateInfoField(this, "OutgoingResource", -201, ProducedProduct));
                _labels.Add(producedLabel);


                if (producedLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6 > widestWidth)
                {
                    widestWidth = producedLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6;
                }
            }
        }
 public override string GetLocalizedStatus(ushort vehicleID, ref Vehicle data, out InstanceID target)
 {
     if ((data.m_flags & Vehicle.Flags.TransferToTarget) != 0)
     {
         ushort targetBuilding = data.m_targetBuilding;
         if ((data.m_flags & Vehicle.Flags.GoingBack) != 0)
         {
             target = InstanceID.Empty;
             TransferManager.TransferReason transferType = (TransferManager.TransferReason)data.m_transferType;
             if (transferType == (TransferManager.TransferReason) 113)
             {
                 return(Localization.Get("FOR_FUEL"));
             }
             return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CARGOTRUCK_RETURN"));
         }
         if ((data.m_flags & Vehicle.Flags.WaitingTarget) != 0)
         {
             target = InstanceID.Empty;
             return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CARGOTRUCK_UNLOAD"));
         }
         if (targetBuilding != 0)
         {
             Building.Flags flags = Singleton <BuildingManager> .instance.m_buildings.m_buffer[targetBuilding].m_flags;
             TransferManager.TransferReason transferType = (TransferManager.TransferReason)data.m_transferType;
             if ((data.m_flags & Vehicle.Flags.Exporting) != 0 || (flags & Building.Flags.IncomingOutgoing) != 0)
             {
                 target = InstanceID.Empty;
                 if (transferType == (TransferManager.TransferReason) 113)
                 {
                     return(Localization.Get("FOR_FUEL"));
                 }
                 return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CARGOTRUCK_EXPORT", transferType.ToString()));
             }
             if ((data.m_flags & Vehicle.Flags.Importing) != 0)
             {
                 target          = InstanceID.Empty;
                 target.Building = targetBuilding;
                 if (transferType == (TransferManager.TransferReason) 113)
                 {
                     return(Localization.Get("FOR_FUEL"));
                 }
                 return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CARGOTRUCK_IMPORT", transferType.ToString()));
             }
             target          = InstanceID.Empty;
             target.Building = targetBuilding;
             if (transferType == (TransferManager.TransferReason) 110)
             {
                 return(Localization.Get("TRANSFER_CONSTRUCTION"));
             }
             else if (transferType == (TransferManager.TransferReason) 111)
             {
                 return(Localization.Get("TRANSFER_OPERATION"));
             }
             else if (transferType == (TransferManager.TransferReason) 113)
             {
                 return(Localization.Get("FOR_FUEL"));
             }
             else
             {
                 return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CARGOTRUCK_DELIVER", transferType.ToString()));
             }
         }
     }
     target = InstanceID.Empty;
     return(ColossalFramework.Globalization.Locale.Get("VEHICLE_STATUS_CONFUSED"));
 }
        public static float GetResourcePrice(TransferManager.TransferReason material)
        {
            //Need to sync with RealCity mod
            if (RealGasStationThreading.reduceVehicle)
            {
                switch (material)
                {
                case TransferManager.TransferReason.Petrol:
                    return(3f);

                case TransferManager.TransferReason.Food:
                    return(1.5f);

                case TransferManager.TransferReason.Lumber:
                    return(2f);

                case TransferManager.TransferReason.Coal:
                    return(2.5f);

                default: DebugLog.LogToFileOnly("Error: Unknow material in RealGasStation = " + material.ToString()); return(0f);
                }
            }
            else
            {
                switch (material)
                {
                case TransferManager.TransferReason.Petrol:
                    return(3f * RealGasStationThreading.reduceCargoDiv);

                case TransferManager.TransferReason.Food:
                    return(1.5f * RealGasStationThreading.reduceCargoDiv);

                case TransferManager.TransferReason.Lumber:
                    return(2f * RealGasStationThreading.reduceCargoDiv);

                case TransferManager.TransferReason.Coal:
                    return(2.5f * RealGasStationThreading.reduceCargoDiv);

                default: DebugLog.LogToFileOnly("Error: Unknow material in RealGasStation = " + material.ToString()); return(0f);
                }
            }
        }