private static bool AddDistrictParkServiced(List <DistrictPark>[] array, int buildingId, DistrictPark districtPark)
        {
            if (!TransferManagerInfo.IsDistrictServicesBuilding(buildingId))
            {
                var buildingName = TransferManagerInfo.GetBuildingName(buildingId);
                Logger.LogWarning($"Constraints::AddDistrictParkServiced: Ignoring {districtPark.Name} restriction because {buildingName} ({buildingId}) is not a district services building.");
                return(false);
            }

            if (!districtPark.Exists)
            {
                Logger.LogWarning($"Constraints::AddDistrictParkServiced: Ignoring {districtPark.Name} restriction because this district/park does not exist.");
                return(false);
            }

            if (array[buildingId] == null)
            {
                array[buildingId] = new List <DistrictPark>();
            }

            if (!array[buildingId].Contains(districtPark))
            {
                array[buildingId].Add(districtPark);
            }

            return(true);
        }
        /// <summary>
        /// Add a supply chain link between the source and destination buildings.
        /// The supply chain link overrides all local area, all outside connections, and all district constraints.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        public static void AddSupplyChainConnection(ushort source, ushort destination)
        {
            if (!TransferManagerInfo.IsSupplyChainBuilding(source) || !TransferManagerInfo.IsSupplyChainBuilding(destination))
            {
                return;
            }

            if (!TransferManagerInfo.IsValidSupplyChainLink(source, destination))
            {
                Logger.Log($"Constraints::AddSupplyChainConnection: Could not add invalid supply chain link: source={source}, destination={destination}");
                return;
            }

            bool added = false;

            if (m_supplyDestinations[source] == null)
            {
                m_supplyDestinations[source] = new List <int>();
            }

            if (!m_supplyDestinations[source].Contains(destination))
            {
                added = true;
                m_supplyDestinations[source].Add(destination);
            }

            if (added)
            {
                var sourceBuildingName      = TransferManagerInfo.GetBuildingName(source);
                var destinationBuildingName = TransferManagerInfo.GetBuildingName(destination);
                Logger.Log($"Constraints::AddSupplyChainConnection: {sourceBuildingName} ({source}) => {destinationBuildingName} ({destination}) ...");
            }
        }
        /// <summary>
        /// Sets the internal supply reserve.
        /// </summary>
        /// <param name="buildingId"></param>
        /// <param name="amount">Must bet between 0 and 100.</param>
        public static void SetInternalSupplyReserve(int buildingId, int amount)
        {
            var buildingName = TransferManagerInfo.GetBuildingName(buildingId);

            Logger.LogVerbose($"Constraints::SetInternalSupplyReserve: {buildingName} ({buildingId}) => {amount} ...");

            m_buildingToInternalSupplyBuffer[buildingId] = COMath.Clamp(amount, 0, 100);
        }
 /// <summary>
 /// Allow the specified district or park to be serviced by the specified building
 /// </summary>
 /// <param name="buildingId"></param>
 /// <param name="districtPark"></param>
 public static void AddOutputDistrictParkServiced(int buildingId, DistrictPark districtPark)
 {
     if (AddDistrictParkServiced(m_outputBuildingToDistrictParkServiced, buildingId, districtPark))
     {
         var buildingName = TransferManagerInfo.GetBuildingName(buildingId);
         Logger.Log($"Constraints::AddOutputDistrictParkServiced: {buildingName} ({buildingId}) => {districtPark.Name} ...");
     }
 }
        public static void SetAllInputLocalAreas(int buildingId, bool status)
        {
            var buildingName = TransferManagerInfo.GetBuildingName(buildingId);

            Logger.LogVerbose($"Constraints::SetAllInputLocalAreas: {buildingName} ({buildingId}) => {status} ...");

            SetArrayStatus(m_inputBuildingToAllLocalAreas, buildingId, status);
        }
        public static void SetAllOutputOutsideConnections(int buildingId, bool status)
        {
            var buildingName = TransferManagerInfo.GetBuildingName(buildingId);

            Logger.LogVerbose($"Constraints::SetAllOutputOutsideConnections: {buildingName} ({buildingId}) => {status} ...");

            SetArrayStatus(m_outputBuildingToOutsideConnections, buildingId, status);
        }
        public static void SetBuildingUseDefaultVehicles(int buildingId, bool status)
        {
            var buildingName = TransferManagerInfo.GetBuildingName(buildingId);

            Logger.LogVerbose($"VehicleManagerMod::SetBuildingUseDefaultVehicles: {buildingName} ({buildingId}) => {status} ...");

            BuildingUseDefaultVehicles[buildingId] = status;
        }
        public static void AddCustomVehicle(int buildingId, int prefabIndex)
        {
            if (BuildingToVehicles[buildingId] == null)
            {
                BuildingToVehicles[buildingId] = new List <int>();
            }

            if (!BuildingToVehicles[buildingId].Contains(prefabIndex))
            {
                BuildingToVehicles[buildingId].Add(prefabIndex);

                var buildingName = TransferManagerInfo.GetBuildingName(buildingId);
                var prefabName   = PrefabNames[prefabIndex];
                Logger.Log($"VehicleManagerMod::AddCustomVehicle: {buildingName} ({buildingId}) => {prefabName} ...");
            }
        }
Example #9
0
        /// <summary>
        /// Lists all buildings that can be configured using ESD.
        /// </summary>
        /// <returns></returns>
        public static List <ushort> GetSupportedServiceBuildings()
        {
            var bs = new List <Building>();

            for (ushort buildingId = 0; buildingId < BuildingManager.MAX_BUILDING_COUNT; buildingId++)
            {
                if (TransferManagerInfo.IsDistrictServicesBuilding(buildingId))
                {
                    bs.Add(new Building
                    {
                        Name = TransferManagerInfo.GetBuildingName(buildingId),
                        Id   = buildingId
                    });
                }
            }

            bs.Sort();
            return(bs.Select(b => b.Id).ToList());
        }
        public static void RemoveCustomVehicle(int buildingId, int prefabIndex)
        {
            if (BuildingToVehicles[buildingId] == null)
            {
                return;
            }

            if (BuildingToVehicles[buildingId].Contains(prefabIndex))
            {
                BuildingToVehicles[buildingId].Remove(prefabIndex);

                var buildingName = TransferManagerInfo.GetBuildingName(buildingId);
                var prefabName   = PrefabNames[prefabIndex];
                Logger.Log($"VehicleManagerMod::RemoveCustomVehicle: {buildingName} ({buildingId}) => {prefabName} ...");
            }

            if (BuildingToVehicles[buildingId].Count == 0)
            {
                BuildingToVehicles[buildingId] = null;
            }
        }
        /// <summary>
        /// Load data from given object.
        /// </summary>
        /// <param name="data"></param>
        public static void LoadData(Serialization.Datav4 data)
        {
            Logger.Log($"Constraints::LoadData: version {data.Id}");
            Clear();

            var buildings = Utils.GetSupportedServiceBuildings();

            foreach (var building in buildings)
            {
                var name         = TransferManagerInfo.GetBuildingName(building);
                var buildingInfo = BuildingManager.instance.m_buildings.m_buffer[building].Info;
                var service      = buildingInfo.GetService();
                var subService   = buildingInfo.GetSubService();
                var ai           = buildingInfo.GetAI();

                Logger.Log($"Constraints::LoadData: buildingName={name}, buildingId={building}, service={service}, subService={subService}, ai={ai}");

                var restrictions1 = data.InputBuildingToAllLocalAreas[building];
                SetAllInputLocalAreas(building, restrictions1);

                var restrictions2 = data.InputBuildingToOutsideConnections[building];
                SetAllInputOutsideConnections(building, restrictions2);

                var restrictions3 = data.InputBuildingToDistrictServiced[building];
                if (restrictions3 != null)
                {
                    foreach (var districtPark in restrictions3)
                    {
                        AddInputDistrictParkServiced(building, DistrictPark.FromSerializedInt(districtPark));
                    }
                }

                var restrictions4 = data.OutputBuildingToAllLocalAreas[building];
                SetAllOutputLocalAreas(building, restrictions4);

                var restrictions5 = data.OutputBuildingToOutsideConnections[building];
                SetAllOutputOutsideConnections(building, restrictions5);

                var restrictions6 = data.OutputBuildingToDistrictServiced[building];
                if (restrictions6 != null)
                {
                    foreach (var districtPark in restrictions6)
                    {
                        AddOutputDistrictParkServiced(building, DistrictPark.FromSerializedInt(districtPark));
                    }
                }

                if (data.BuildingToInternalSupplyBuffer != null)
                {
                    var restrictions7 = data.BuildingToInternalSupplyBuffer[building];
                    SetInternalSupplyReserve(building, restrictions7);
                }

                if (data.BuildingToBuildingServiced != null)
                {
                    var restrictions8 = data.BuildingToBuildingServiced[building];
                    if (restrictions8 != null)
                    {
                        foreach (var destination in restrictions8)
                        {
                            AddSupplyChainConnection(building, (ushort)destination);
                        }
                    }
                }

                m_globalOutsideConnectionIntensity = data.GlobalOutsideConnectionIntensity;
                m_globalOutsideToOutsideMaxPerc    = data.GlobalOutsideToOutsideMaxPerc;

                Logger.Log("");
            }
        }
Example #12
0
        /// <summary>
        /// Helper method for displaying information, including district and supply chain constraints, about the
        /// building with given building id.
        /// </summary>
        /// <param name="building"></param>
        /// <returns></returns>
        private static string GetBuildingInfoText(ushort building)
        {
            var inputType = TransferManagerInfo.GetBuildingInputType(building);

            var txtItems = new List <string>();

            txtItems.Add($"{TransferManagerInfo.GetBuildingName(building)} ({building})");
            txtItems.Add(TransferManagerInfo.GetDistrictParkText(building));

            // Early return.  Rest of info pertains to building types that we deal with in the mod.
            if (!(TransferManagerInfo.IsDistrictServicesBuilding(building) || TransferManagerInfo.IsCustomVehiclesBuilding(building)))
            {
                return(string.Join("\n", txtItems.ToArray()));
            }

            txtItems.Add(TransferManagerInfo.GetBuildingInputTypeText(building));
            txtItems.Add(TransferManagerInfo.GetServicesText(building));

            if (!TransferManagerInfo.IsSupplyChainBuilding(building))
            {
                if (TransferManagerInfo.IsDistrictServicesBuilding(building))
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetOutputDistrictsServedText(building));
                }

                if (Settings.enableCustomVehicles &&
                    !VehicleManagerMod.BuildingUseDefaultVehicles[building] &&
                    VehicleManagerMod.BuildingToVehicles[building] != null &&
                    (inputType & InputType.VEHICLES) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetCustomVehiclesText(building));
                }

                return(string.Join("\n", txtItems.ToArray()));
            }

            if (Settings.enableIndustriesControl)
            {
                // From this point forth, we know this is a supply chain building ...
                txtItems.Add($"Supply Reserve: {Constraints.InternalSupplyBuffer(building)}");

                if ((inputType & InputType.INCOMING) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetSupplyBuildingSourcesText(building));
                }

                if ((inputType & InputType.OUTGOING) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetSupplyBuildingDestinationsText(building));
                }

                if (Settings.enableCustomVehicles &&
                    !VehicleManagerMod.BuildingUseDefaultVehicles[building] &&
                    VehicleManagerMod.BuildingToVehicles[building] != null &&
                    (inputType & InputType.VEHICLES) != InputType.NONE)
                {
                    txtItems.Add("");
                    txtItems.Add(TransferManagerInfo.GetCustomVehiclesText(building));
                }

                var problemText = TransferManagerInfo.GetSupplyBuildingProblemsText(building);
                if (problemText != string.Empty)
                {
                    txtItems.Add("");
                    txtItems.Add($"<<WARNING: Cannot find the following materials to procure!>>");
                    txtItems.Add(problemText);
                }
            }

            return(string.Join("\n", txtItems.ToArray()));
        }